clif.cpp 740 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426
  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. nullpo_retv( bl );
  1216. nullpo_retv( ud );
  1217. map_session_data* sd;
  1218. status_change* sc = status_get_sc( bl );
  1219. struct view_data* vd = status_get_viewdata( bl );
  1220. struct packet_unit_walking p;
  1221. int g_id = status_get_guild_id(bl);
  1222. sd = BL_CAST(BL_PC, bl);
  1223. p.PacketType = unit_walkingType;
  1224. #if PACKETVER >= 20091103
  1225. p.PacketLength = sizeof(p);
  1226. #endif
  1227. #if PACKETVER >= 20071106
  1228. p.objecttype = clif_bl_type( bl, true );
  1229. #endif
  1230. #if PACKETVER >= 20131223
  1231. p.AID = bl->id;
  1232. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1233. #else
  1234. p.GID = bl->id;
  1235. #endif
  1236. p.speed = status_get_speed(bl);
  1237. p.bodyState = (sc) ? sc->opt1 : 0;
  1238. p.healthState = (sc) ? sc->opt2 : 0;
  1239. p.effectState = (sc) ? sc->option : 0;
  1240. p.job = vd->class_;
  1241. p.head = vd->hair_style;
  1242. p.weapon = vd->weapon;
  1243. p.accessory = vd->head_bottom;
  1244. p.moveStartTime = client_tick(gettick());
  1245. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1246. p.shield = vd->shield;
  1247. #endif
  1248. p.accessory2 = vd->head_top;
  1249. p.accessory3 = vd->head_mid;
  1250. p.headpalette = vd->hair_color;
  1251. p.bodypalette = vd->cloth_color;
  1252. p.headDir = (sd) ? sd->head_dir : 0;
  1253. #if PACKETVER >= 20101124
  1254. p.robe = vd->robe;
  1255. #endif
  1256. p.GUID = g_id;
  1257. p.GEmblemVer = status_get_emblem_id(bl);
  1258. p.honor = (sd) ? sd->status.manner : 0;
  1259. p.virtue = (sc) ? sc->opt3 : 0;
  1260. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1261. p.sex = vd->sex;
  1262. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1263. p.xSize = p.ySize = (sd) ? 5 : 0;
  1264. p.clevel = clif_setlevel(bl);
  1265. #if PACKETVER >= 20080102
  1266. p.font = (sd) ? sd->status.font : 0;
  1267. #endif
  1268. #if PACKETVER >= 20120221
  1269. 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 ) ) ){
  1270. p.maxHP = status_get_max_hp(bl);
  1271. p.HP = status_get_hp(bl);
  1272. } else {
  1273. p.maxHP = -1;
  1274. p.HP = -1;
  1275. }
  1276. if( bl->type == BL_MOB ){
  1277. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1278. }else if( bl->type == BL_PET ){
  1279. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1280. }else{
  1281. p.isBoss = BOSSTYPE_NONE;
  1282. }
  1283. #endif
  1284. #if PACKETVER >= 20150513
  1285. p.body = vd->body_style;
  1286. #endif
  1287. /* Might be earlier, this is when the named item bug began */
  1288. #if PACKETVER >= 20131223
  1289. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1290. #endif
  1291. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1292. // if disguised, send the info to self
  1293. if( disguised( bl ) ){
  1294. #if PACKETVER >= 20091103
  1295. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1296. #if PACKETVER >= 20131223
  1297. p.AID = disguised_bl_id( bl->id );
  1298. #else
  1299. p.GID = disguised_bl_id( bl->id );
  1300. #endif
  1301. #else
  1302. p.GID = disguised_bl_id( bl->id );
  1303. #endif
  1304. clif_send(&p,sizeof(p),bl,SELF);
  1305. }
  1306. }
  1307. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1308. /// 01b0 <id>.L <type>.B <value>.L
  1309. /// type:
  1310. /// unused
  1311. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, map_session_data *sd)
  1312. {
  1313. nullpo_retv(bl);
  1314. if(!pcdb_checkid(class_))
  1315. {// player classes yield missing sprites
  1316. unsigned char buf[16];
  1317. WBUFW(buf,0)=0x1b0;
  1318. WBUFL(buf,2)=bl->id;
  1319. WBUFB(buf,6)=type;
  1320. WBUFL(buf,7)=class_;
  1321. clif_send(buf,packet_len(0x1b0),(sd == nullptr ? bl : &(sd->bl)),target);
  1322. }
  1323. }
  1324. void clif_servantball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1325. struct PACKET_ZC_SPIRITS p = {};
  1326. p.PacketType = HEADER_ZC_SPIRITS;
  1327. p.AID = sd.bl.id;
  1328. p.num = sd.servantball;
  1329. if( target == nullptr ){
  1330. target = &sd.bl;
  1331. }
  1332. clif_send( &p, sizeof( p ), target, send_target );
  1333. }
  1334. void clif_abyssball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1335. struct PACKET_ZC_SPIRITS p = {};
  1336. p.PacketType = HEADER_ZC_SPIRITS;
  1337. p.AID = sd.bl.id;
  1338. p.num = sd.abyssball;
  1339. if( target == nullptr ){
  1340. target = &sd.bl;
  1341. }
  1342. clif_send( &p, sizeof( p ), target, send_target );
  1343. }
  1344. /// Notifies the client of an object's Millenium Shields.
  1345. static void clif_millenniumshield_single( map_session_data& sd, map_session_data& tsd ){
  1346. #if PACKETVER >= 20081126
  1347. status_change_entry* sce = sd.sc.getSCE( SC_MILLENNIUMSHIELD );
  1348. if( sce == nullptr ){
  1349. return;
  1350. }
  1351. PACKET_ZC_MILLENNIUMSHIELD packet{};
  1352. packet.packetType = HEADER_ZC_MILLENNIUMSHIELD;
  1353. packet.aid = sd.bl.id;
  1354. packet.num = sce->val2;
  1355. packet.state = 0;
  1356. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  1357. #endif
  1358. }
  1359. /*==========================================
  1360. * Kagerou/Oboro amulet spirit
  1361. *------------------------------------------*/
  1362. static void clif_spiritcharm_single( map_session_data& sd, map_session_data& tsd ){
  1363. #if PACKETVER >= 20111102
  1364. if( sd.spiritcharm_type == CHARM_TYPE_NONE ){
  1365. return;
  1366. }
  1367. if( sd.spiritcharm <= 0 ){
  1368. return;
  1369. }
  1370. PACKET_ZC_SPIRITS_ATTRIBUTE packet{};
  1371. packet.packetType = HEADER_ZC_SPIRITS_ATTRIBUTE;
  1372. packet.aid = sd.bl.id;
  1373. packet.spiritsType = static_cast<decltype(packet.spiritsType)>(sd.spiritcharm_type);
  1374. packet.num = static_cast<decltype(packet.num)>(sd.spiritcharm);
  1375. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  1376. #endif
  1377. }
  1378. /*==========================================
  1379. * Enchanting Shadow / Shadow Scar Spirit
  1380. *------------------------------------------*/
  1381. void clif_enchantingshadow_spirit(unit_data &ud) {
  1382. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1383. PACKET_ZC_TARGET_SPIRITS p = {};
  1384. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1385. p.GID = ud.bl->id;
  1386. p.unknown_val = 0;
  1387. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1388. clif_send(&p, sizeof(p), ud.bl, AREA);
  1389. #endif
  1390. }
  1391. /*==========================================
  1392. * Run when player changes map / refreshes
  1393. * Tells its client to display all weather settings being used by this map
  1394. *------------------------------------------*/
  1395. static void clif_weather_check(map_session_data *sd)
  1396. {
  1397. int16 m = sd->bl.m;
  1398. int fd = sd->fd;
  1399. if (map_getmapflag(m, MF_SNOW)
  1400. || map_getmapflag(m, MF_CLOUDS)
  1401. || map_getmapflag(m, MF_FOG)
  1402. || map_getmapflag(m, MF_FIREWORKS)
  1403. || map_getmapflag(m, MF_SAKURA)
  1404. || map_getmapflag(m, MF_LEAVES)
  1405. || map_getmapflag(m, MF_CLOUDS2))
  1406. {
  1407. if (map_getmapflag(m, MF_SNOW))
  1408. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1409. if (map_getmapflag(m, MF_CLOUDS))
  1410. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1411. if (map_getmapflag(m, MF_CLOUDS2))
  1412. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1413. if (map_getmapflag(m, MF_FOG))
  1414. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1415. if (map_getmapflag(m, MF_FIREWORKS)) {
  1416. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1417. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1418. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1419. }
  1420. if (map_getmapflag(m, MF_SAKURA))
  1421. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1422. if (map_getmapflag(m, MF_LEAVES))
  1423. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1424. }
  1425. }
  1426. /**
  1427. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1428. **/
  1429. void clif_weather(int16 m)
  1430. {
  1431. struct s_mapiterator* iter;
  1432. map_session_data *sd=nullptr;
  1433. iter = mapit_getallusers();
  1434. for( sd = (map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (map_session_data*)mapit_next(iter) )
  1435. {
  1436. if( sd->bl.m == m )
  1437. clif_weather_check(sd);
  1438. }
  1439. mapit_free(iter);
  1440. }
  1441. /**
  1442. * Hide a NPC from the effects of Maya Purple card.
  1443. * @param bl: Block data
  1444. * @return True if NPC is disabled or false otherwise
  1445. */
  1446. static inline bool clif_npc_mayapurple(block_list *bl) {
  1447. nullpo_retr(false, bl);
  1448. if (bl->type == BL_NPC) {
  1449. npc_data *nd = map_id2nd(bl->id);
  1450. // TODO: Confirm if waitingroom cause any special cases
  1451. if (/* nd->chat_id == 0 && */ nd->is_invisible)
  1452. return true;
  1453. }
  1454. return false;
  1455. }
  1456. /**
  1457. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1458. **/
  1459. int clif_spawn( struct block_list *bl, bool walking ){
  1460. struct view_data *vd;
  1461. vd = status_get_viewdata(bl);
  1462. if( !vd || vd->class_ == JT_INVISIBLE )
  1463. return 0;
  1464. // Hide NPC from Maya Purple card
  1465. if (clif_npc_mayapurple(bl))
  1466. return 0;
  1467. if( bl->type == BL_NPC && !vd->dead_sit ){
  1468. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1469. }else{
  1470. clif_spawn_unit( bl, AREA_WOS );
  1471. }
  1472. if (vd->cloth_color)
  1473. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1474. if (vd->body_style)
  1475. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1476. switch (bl->type)
  1477. {
  1478. case BL_PC:
  1479. {
  1480. TBL_PC *sd = ((TBL_PC*)bl);
  1481. if (sd->spiritball > 0)
  1482. clif_spiritball(&sd->bl);
  1483. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  1484. clif_millenniumshield(&sd->bl, sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2);
  1485. if (sd->soulball > 0)
  1486. clif_soulball(sd);
  1487. if (sd->servantball > 0)
  1488. clif_servantball( *sd );
  1489. if (sd->abyssball > 0)
  1490. clif_abyssball( *sd );
  1491. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1492. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1493. else if(sd->state.size==SZ_MEDIUM)
  1494. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1495. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1496. clif_sendbgemblem_area(sd);
  1497. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1498. clif_spiritcharm(sd);
  1499. if (sd->status.robe)
  1500. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1501. clif_efst_status_change_sub(bl, bl, AREA);
  1502. clif_hat_effects( *sd, sd->bl, AREA );
  1503. }
  1504. break;
  1505. case BL_MOB:
  1506. {
  1507. TBL_MOB *md = ((TBL_MOB*)bl);
  1508. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1509. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1510. else if(md->special_state.size==SZ_MEDIUM)
  1511. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1512. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1513. clif_summon_init(*md);
  1514. }
  1515. break;
  1516. case BL_NPC:
  1517. {
  1518. TBL_NPC *nd = ((TBL_NPC*)bl);
  1519. if( nd->size == SZ_BIG )
  1520. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1521. else if( nd->size == SZ_MEDIUM )
  1522. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1523. clif_efst_status_change_sub(bl, bl, AREA);
  1524. clif_progressbar_npc_area(nd);
  1525. }
  1526. break;
  1527. case BL_PET:
  1528. if (vd->head_bottom)
  1529. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1530. break;
  1531. }
  1532. return 0;
  1533. }
  1534. /// Sends information about owned homunculus to the client . [orn]
  1535. /// 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)
  1536. /// 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)
  1537. void clif_hominfo( map_session_data *sd, struct homun_data *hd, int flag ){
  1538. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1539. nullpo_retv( sd );
  1540. nullpo_retv( hd );
  1541. struct status_data *status = &hd->battle_status;
  1542. struct PACKET_ZC_PROPERTY_HOMUN p;
  1543. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1544. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1545. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1546. 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 );
  1547. p.level = hd->homunculus.level;
  1548. p.hunger = hd->homunculus.hunger;
  1549. p.intimacy = hd->homunculus.intimacy / 100;
  1550. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1551. p.itemId = 0; // equip id
  1552. #endif
  1553. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1554. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1555. p.hit = status->hit;
  1556. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1557. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1558. }else{
  1559. p.crit = status->cri / 10;
  1560. }
  1561. #ifdef RENEWAL
  1562. p.def = status->def + status->def2;
  1563. p.mdef = status->mdef + status->mdef2;
  1564. #else
  1565. p.def = status->def + status->vit;
  1566. p.mdef = status->mdef;
  1567. #endif
  1568. p.flee = status->flee;
  1569. p.amotion = (flag) ? 0 : status->amotion;
  1570. #if PACKETVER >= 20141016
  1571. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1572. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1573. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1574. p.hp = status->hp / ( status->max_hp / 100 );
  1575. p.maxHp = 100;
  1576. }else{
  1577. p.hp = status->hp;
  1578. p.maxHp = status->max_hp;
  1579. }
  1580. #else
  1581. if( status->max_hp > INT16_MAX ){
  1582. p.hp = status->hp / ( status->max_hp / 100 );
  1583. p.maxHp = 100;
  1584. }else{
  1585. p.hp = status->hp;
  1586. p.maxHp = status->max_hp;
  1587. }
  1588. #endif
  1589. if( status->max_sp > INT16_MAX ){
  1590. p.sp = status->sp / ( status->max_sp / 100 );
  1591. p.maxSp = 100;
  1592. }else{
  1593. p.sp = status->sp;
  1594. p.maxSp = status->max_sp;
  1595. }
  1596. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1597. p.exp = hd->homunculus.exp;
  1598. p.expNext = hd->exp_next;
  1599. #else
  1600. p.exp = (uint32)hd->homunculus.exp;
  1601. p.expNext = (uint32)hd->exp_next;
  1602. #endif
  1603. switch( hom_class2type( hd->homunculus.class_ ) ){
  1604. case HT_REG:
  1605. case HT_EVO:
  1606. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1607. p.expNext = 0;
  1608. }
  1609. break;
  1610. case HT_S:
  1611. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1612. p.expNext = 0;
  1613. }
  1614. break;
  1615. }
  1616. p.skillPoints = hd->homunculus.skillpts;
  1617. p.range = status_get_range( &hd->bl );
  1618. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1619. #endif
  1620. }
  1621. /// Notification about a change in homunuculus' state.
  1622. /// 0230 <type>.B <state>.B <id>.L <data>.L (ZC_CHANGESTATE_MER)
  1623. /// type:
  1624. /// unused
  1625. /// state:
  1626. /// 0 = pre-init
  1627. /// 1 = intimacy
  1628. /// 2 = hunger
  1629. /// 3 = accessory?
  1630. /// ? = ignored
  1631. void clif_send_homdata( homun_data& hd, e_hom_state2 state ){
  1632. #if PACKETVER >= 20050523
  1633. if( hd.master == nullptr ){
  1634. return;
  1635. }
  1636. uint32 param;
  1637. switch( state ){
  1638. case SP_ACK:
  1639. param = 0;
  1640. break;
  1641. case SP_INTIMATE:
  1642. // TODO: Why is something like this here? [Lemongrass]
  1643. if( hd.homunculus.class_ == hd.homunculusDB->evo_class && hom_intimacy_intimacy2grade( hd.homunculus.intimacy ) >= HOMGRADE_LOYAL ){
  1644. hom_calc_skilltree( &hd );
  1645. }
  1646. param = hd.homunculus.intimacy / 100;
  1647. break;
  1648. case SP_HUNGRY:
  1649. param = hd.homunculus.hunger;
  1650. break;
  1651. default:
  1652. return;
  1653. }
  1654. PACKET_ZC_CHANGESTATE_MER packet{};
  1655. packet.packetType = HEADER_ZC_CHANGESTATE_MER;
  1656. packet.type = 0;
  1657. packet.state = state;
  1658. packet.gid = hd.bl.id;
  1659. packet.data = param;
  1660. clif_send( &packet, sizeof( packet ), &hd.master->bl, SELF );
  1661. #endif
  1662. }
  1663. void clif_homskillinfoblock( homun_data& hd ){
  1664. #if PACKETVER >= 20050530
  1665. map_session_data* sd = hd.master;
  1666. if( sd == nullptr ){
  1667. return;
  1668. }
  1669. PACKET_ZC_HOSKILLINFO_LIST* packet = reinterpret_cast<PACKET_ZC_HOSKILLINFO_LIST*>(packet_buffer);
  1670. packet->packetType = HEADER_ZC_HOSKILLINFO_LIST;
  1671. packet->packetLength = sizeof( *packet );
  1672. for(int i = 0, count = 0; i < MAX_HOMUNSKILL; i++) {
  1673. int id = hd.homunculus.hskill[i].id;
  1674. if (id != 0) {
  1675. int combo = (hd.homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1676. short idx = hom_skill_get_index(id);
  1677. if (idx == -1)
  1678. continue;
  1679. packet->skills[count].id = id;
  1680. packet->skills[count].inf = (combo) ? INF_SELF_SKILL : skill_get_inf(id);
  1681. packet->skills[count].unknown = 0;
  1682. packet->skills[count].level = hd.homunculus.hskill[idx].lv;
  1683. packet->skills[count].sp = skill_get_sp(id,hd.homunculus.hskill[idx].lv);
  1684. packet->skills[count].range = skill_get_range2(&hd.bl,id,hd.homunculus.hskill[idx].lv,false);
  1685. safestrncpy(packet->skills[count].name, skill_get_name(id), NAME_LENGTH);
  1686. 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;
  1687. packet->packetLength += sizeof( packet->skills[0] );
  1688. count++;
  1689. }
  1690. }
  1691. clif_send( packet, packet->packetLength, &sd->bl, SELF );
  1692. #endif
  1693. }
  1694. void clif_homskillup( homun_data& hd, uint16 skill_id ){
  1695. #if PACKETVER >= 20050531
  1696. short idx = hom_skill_get_index( skill_id );
  1697. if( idx == -1 ){
  1698. return;
  1699. }
  1700. map_session_data* sd = hd.master;
  1701. if( sd == nullptr ){
  1702. return;
  1703. }
  1704. PACKET_ZC_HOSKILLINFO_UPDATE packet{};
  1705. packet.packetType = HEADER_ZC_HOSKILLINFO_UPDATE;
  1706. packet.skill_id = skill_id;
  1707. packet.Level = hd.homunculus.hskill[idx].lv;
  1708. packet.SP = skill_get_sp(skill_id,hd.homunculus.hskill[idx].lv);
  1709. packet.AttackRange = skill_get_range2(&hd.bl,skill_id,hd.homunculus.hskill[idx].lv,false);
  1710. 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;
  1711. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  1712. #endif
  1713. }
  1714. /// Result of request to feed a homun/merc.
  1715. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1716. /// result:
  1717. /// 0 = failure
  1718. /// 1 = success
  1719. void clif_hom_food( map_session_data& sd, int32 foodid, bool success ){
  1720. PACKET_ZC_FEED_MER packet{};
  1721. packet.packetType = HEADER_ZC_FEED_MER;
  1722. packet.result = success;
  1723. packet.itemId = client_nameid( foodid );
  1724. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1725. }
  1726. /// Notifies the client, that it is walking.
  1727. /// 0087 <walk start time>.L <walk data>.6B (ZC_NOTIFY_PLAYERMOVE)
  1728. void clif_walkok( map_session_data& sd ){
  1729. PACKET_ZC_NOTIFY_PLAYERMOVE packet{};
  1730. packet.packetType = HEADER_ZC_NOTIFY_PLAYERMOVE;
  1731. packet.moveStartTime = client_tick(gettick());
  1732. WBUFPOS2(packet.moveData, 0, sd.bl.x, sd.bl.y, sd.ud.to_x, sd.ud.to_y, 8, 8);
  1733. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1734. }
  1735. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1736. status_change *sc = nullptr;
  1737. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1738. clif_ally_only = true;
  1739. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1740. if(vd->cloth_color)
  1741. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1742. if(vd->body_style)
  1743. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1744. switch(bl->type) {
  1745. case BL_PC:
  1746. {
  1747. TBL_PC *sd = ((TBL_PC*)bl);
  1748. // clif_movepc(sd);
  1749. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1750. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1751. else if(sd->state.size==SZ_MEDIUM)
  1752. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1753. if (sd->status.robe)
  1754. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1755. }
  1756. break;
  1757. case BL_MOB:
  1758. {
  1759. TBL_MOB *md = ((TBL_MOB*)bl);
  1760. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1761. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1762. else if(md->special_state.size==SZ_MEDIUM)
  1763. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1764. }
  1765. break;
  1766. case BL_PET:
  1767. if(vd->head_bottom) // needed to display pet equip properly
  1768. clif_pet_equip_area((TBL_PET*)bl);
  1769. break;
  1770. }
  1771. clif_ally_only = false;
  1772. }
  1773. /// Notifies clients in an area, that an other visible object is walking.
  1774. /// 0086 <id>.L <walk data>.6B <walk start time>.L (ZC_NOTIFY_MOVE)
  1775. /// Note: unit must not be self
  1776. void clif_move(struct unit_data *ud)
  1777. {
  1778. struct view_data* vd;
  1779. struct block_list* bl = ud->bl;
  1780. status_change *sc = nullptr;
  1781. PACKET_ZC_NOTIFY_MOVE packet{};
  1782. packet.packetType = HEADER_ZC_NOTIFY_MOVE;
  1783. vd = status_get_viewdata(bl);
  1784. if (!vd )
  1785. return;
  1786. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1787. else if( vd->class_ == JT_INVISIBLE ){
  1788. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1789. if(disguised(bl)) {
  1790. packet.gid = disguised_bl_id(bl->id);
  1791. WBUFPOS2(packet.moveData, 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8);
  1792. packet.moveStartTime = client_tick(gettick());
  1793. clif_send(&packet, sizeof(packet), bl, SELF);
  1794. }
  1795. return;
  1796. }
  1797. // Hide NPC from Maya Purple card
  1798. if (clif_npc_mayapurple(bl))
  1799. return;
  1800. if (ud->state.speed_changed) {
  1801. // Since we don't know how to update the speed of other objects,
  1802. // use the old walk packet to update the data.
  1803. ud->state.speed_changed = 0;
  1804. clif_move2(bl, vd, ud);
  1805. return;
  1806. }
  1807. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1808. clif_ally_only = true;
  1809. packet.gid = bl->id;
  1810. WBUFPOS2(packet.moveData,0,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1811. packet.moveStartTime = client_tick(gettick());
  1812. clif_send(&packet, sizeof(packet), bl, AREA_WOS);
  1813. if (disguised(bl)) {
  1814. packet.gid = disguised_bl_id(bl->id);
  1815. clif_send(&packet, sizeof(packet), bl, SELF);
  1816. }
  1817. clif_ally_only = false;
  1818. }
  1819. /*==========================================
  1820. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1821. *------------------------------------------*/
  1822. static TIMER_FUNC(clif_delayquit){
  1823. map_session_data *sd = nullptr;
  1824. //Remove player from map server
  1825. if ((sd = map_id2sd(id)) != nullptr && sd->fd == 0) //Should be a disconnected player.
  1826. map_quit(sd);
  1827. return 0;
  1828. }
  1829. /*==========================================
  1830. *
  1831. *------------------------------------------*/
  1832. void clif_quitsave(int fd,map_session_data *sd) {
  1833. if (!battle_config.prevent_logout ||
  1834. sd->canlog_tick == 0 ||
  1835. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1836. map_quit(sd);
  1837. else if (session_isValid(sd->fd)) {
  1838. //Disassociate session from player (session is deleted after this function was called)
  1839. //And set a timer to make him quit later.
  1840. session[sd->fd]->session_data = nullptr;
  1841. sd->fd = 0;
  1842. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1843. }
  1844. }
  1845. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1846. /// 0091 <map name>.16B <x>.W <y>.W
  1847. void clif_changemap( map_session_data& sd, short m, uint16 x, uint16 y ){
  1848. PACKET_ZC_NPCACK_MAPMOVE packet{};
  1849. packet.packetType = HEADER_ZC_NPCACK_MAPMOVE;
  1850. mapindex_getmapname_ext(map_mapid2mapname(m), packet.mapName);
  1851. packet.xPos = x;
  1852. packet.yPos = y;
  1853. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1854. }
  1855. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1856. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1857. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE_DOMAIN)
  1858. void clif_changemapserver( map_session_data& sd, const char* map, uint16 x, uint16 y, uint32 ip, uint16 port ){
  1859. PACKET_ZC_NPCACK_SERVERMOVE packet{};
  1860. packet.packetType = HEADER_ZC_NPCACK_SERVERMOVE;
  1861. mapindex_getmapname_ext(map, packet.mapName);
  1862. packet.xPos = x;
  1863. packet.yPos = y;
  1864. packet.ip = htonl(ip);
  1865. packet.port = ntows(htons(port)); // [!] LE byte order here [!]
  1866. #if PACKETVER >= 20170315
  1867. safestrncpy( packet.domain, "", sizeof( packet.domain ) );
  1868. #endif
  1869. #ifdef DEBUG
  1870. 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 );
  1871. #endif
  1872. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1873. }
  1874. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1875. /// This function combines both calls and allows to simplify the calling code
  1876. void clif_blown(struct block_list *bl)
  1877. {
  1878. clif_slide(bl, bl->x, bl->y);
  1879. clif_fixpos( *bl );
  1880. }
  1881. /// Visually moves(slides) a character to x,y. If the target cell
  1882. /// isn't walkable, the char doesn't move at all. If the char is
  1883. /// sitting it will stand up.
  1884. /// 0088 <id>.L <x>.W <y>.W (ZC_STOPMOVE)
  1885. void clif_fixpos( block_list& bl ){
  1886. PACKET_ZC_STOPMOVE packet = {};
  1887. packet.packetType = HEADER_ZC_STOPMOVE;
  1888. packet.AID = bl.id;
  1889. packet.xPos = bl.x;
  1890. packet.yPos = bl.y;
  1891. clif_send( &packet, sizeof( packet ), &bl, AREA);
  1892. if( disguised( &bl ) ){
  1893. packet.AID = disguised_bl_id( bl.id );
  1894. clif_send( &packet, sizeof( packet ), &bl, SELF );
  1895. }
  1896. }
  1897. /// Displays the buy/sell dialog of an NPC shop.
  1898. /// 00c4 <shop id>.L (ZC_SELECT_DEALTYPE)
  1899. void clif_npcbuysell( map_session_data& sd, npc_data& nd ){
  1900. PACKET_ZC_SELECT_DEALTYPE packet{};
  1901. packet.packetType = HEADER_ZC_SELECT_DEALTYPE;
  1902. packet.npcId = nd.bl.id;
  1903. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1904. }
  1905. /// Presents list of items, that can be bought in an NPC shop.
  1906. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1907. void clif_buylist( map_session_data& sd, npc_data& nd ){
  1908. PACKET_ZC_PC_PURCHASE_ITEMLIST* p = reinterpret_cast<PACKET_ZC_PC_PURCHASE_ITEMLIST*>( packet_buffer );
  1909. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1910. p->packetLength = sizeof( *p );
  1911. for( int i = 0, count = 0, discount = npc_shop_discount( &nd ); i < nd.u.shop.count; i++ ){
  1912. int val = nd.u.shop.shop_item[i].value;
  1913. p->items[count].price = val;
  1914. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( &sd, val ) : val;
  1915. p->items[count].itemType = itemtype( nd.u.shop.shop_item[i].nameid );
  1916. p->items[count].itemId = client_nameid( nd.u.shop.shop_item[i].nameid );
  1917. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1918. std::shared_ptr<item_data> id = item_db.find(nd.u.shop.shop_item[i].nameid);
  1919. p->items[count].viewSprite = id->look;
  1920. p->items[count].location = pc_equippoint_sub( &sd, id.get() );
  1921. #endif
  1922. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  1923. count++;
  1924. }
  1925. clif_send( p, p->packetLength, &sd.bl, SELF );
  1926. }
  1927. /// Presents list of items, that can be sold to an NPC shop.
  1928. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }* (ZC_PC_SELL_ITEMLIST)
  1929. void clif_selllist( map_session_data& sd){
  1930. if( !sd.npc_shopid ){
  1931. return;
  1932. }
  1933. npc_data* nd = map_id2nd( sd.npc_shopid );
  1934. if( nd == nullptr ){
  1935. return;
  1936. }
  1937. PACKET_ZC_PC_SELL_ITEMLIST *packet = reinterpret_cast<PACKET_ZC_PC_SELL_ITEMLIST*>(packet_buffer);
  1938. packet->packetType = HEADER_ZC_PC_SELL_ITEMLIST;
  1939. packet->packetLength = sizeof( *packet );
  1940. for( int i = 0, c = 0; i < MAX_INVENTORY; i++ ){
  1941. if( sd.inventory.u.items_inventory[i].nameid <= 0 ){
  1942. continue;
  1943. }
  1944. if( sd.inventory_data[i] == nullptr ){
  1945. continue;
  1946. }
  1947. if( !pc_can_sell_item( &sd, &sd.inventory.u.items_inventory[i], nd->subtype ) ){
  1948. continue;
  1949. }
  1950. int price;
  1951. if( battle_config.rental_item_novalue && sd.inventory.u.items_inventory[i].expire_time ){
  1952. price = 0;
  1953. }else{
  1954. price = sd.inventory_data[i]->value_sell;
  1955. if( price < 0 ){
  1956. continue;
  1957. }
  1958. }
  1959. packet->items[c].index = client_index(i);
  1960. packet->items[c].price = price;
  1961. packet->items[c].overcharge = pc_modifysellvalue( &sd, price );
  1962. packet->packetLength += sizeof( packet->items[0] );
  1963. c++;
  1964. }
  1965. clif_send( packet, packet->packetLength, &sd.bl, SELF );
  1966. }
  1967. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1968. /// 09d4
  1969. void clif_parse_NPCShopClosed(int fd, map_session_data *sd) {
  1970. // TODO: State tracking?
  1971. sd->npc_shopid = 0;
  1972. }
  1973. /**
  1974. * Presents list of items, that can be sold to a Market shop.
  1975. * @author: Ind and Yommy
  1976. **/
  1977. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1978. void clif_npc_market_open(map_session_data *sd, struct npc_data *nd) {
  1979. #if PACKETVER >= 20131223
  1980. nullpo_retv( sd );
  1981. nullpo_retv( nd );
  1982. if( sd->state.trading ){
  1983. return;
  1984. }
  1985. int fd = sd->fd;
  1986. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1987. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1988. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1989. int count = 0;
  1990. for( int i = 0; i < nd->u.shop.count; i++ ){
  1991. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1992. if( !item->nameid ){
  1993. continue;
  1994. }
  1995. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  1996. if( !id ){
  1997. continue;
  1998. }
  1999. p->list[count].nameid = client_nameid( item->nameid );
  2000. p->list[count].type = itemtype( item->nameid );
  2001. p->list[count].price = item->value;
  2002. p->list[count].qty = item->qty;
  2003. p->list[count].weight = id->weight;
  2004. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2005. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2006. #endif
  2007. count++;
  2008. }
  2009. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  2010. WFIFOSET( fd, p->packetLength );
  2011. sd->state.trading = 1;
  2012. #endif
  2013. }
  2014. /// Closes the Market shop window.
  2015. void clif_parse_NPCMarketClosed(int fd, map_session_data *sd) {
  2016. nullpo_retv(sd);
  2017. sd->npc_shopid = 0;
  2018. sd->state.trading = 0;
  2019. }
  2020. /// Purchase item from Market shop.
  2021. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2022. void clif_npc_market_purchase_ack( map_session_data& sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2023. #if PACKETVER >= 20131223
  2024. struct npc_data *nd = map_id2nd( sd.npc_shopid );
  2025. if( nd == nullptr ){
  2026. return;
  2027. }
  2028. PACKET_ZC_NPC_MARKET_PURCHASE_RESULT* p = reinterpret_cast<PACKET_ZC_NPC_MARKET_PURCHASE_RESULT*>( packet_buffer );
  2029. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2030. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2031. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2032. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2033. #else
  2034. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2035. #endif
  2036. if( res == e_purchase_result::PURCHASE_SUCCEED ){
  2037. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2038. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2039. // Not found
  2040. if( j == nd->u.shop.count ){
  2041. continue;
  2042. }
  2043. p->list[count].ITID = client_nameid( list[i].nameid );
  2044. p->list[count].qty = list[i].qty;
  2045. p->list[count].price = nd->u.shop.shop_item[j].value;
  2046. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->list[0] ) );
  2047. count++;
  2048. }
  2049. }
  2050. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2051. #endif
  2052. }
  2053. /// Purchase item from Market shop.
  2054. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2055. void clif_parse_NPCMarketPurchase(int fd, map_session_data *sd) {
  2056. #if PACKETVER >= 20131223
  2057. nullpo_retv( sd );
  2058. if( !sd->npc_shopid ){
  2059. return;
  2060. }
  2061. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2062. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2063. std::vector<s_npc_buy_list> items;
  2064. items.reserve( count );
  2065. for( int i = 0; i < count; i++ ){
  2066. s_npc_buy_list item = {};
  2067. item.nameid = p->list[i].ITID;
  2068. item.qty = p->list[i].qty;
  2069. items.push_back( item );
  2070. }
  2071. e_purchase_result res = npc_buylist( sd, items );
  2072. clif_npc_market_purchase_ack( *sd, res, items );
  2073. #endif
  2074. }
  2075. /// Displays an NPC dialog message.
  2076. /// 00b4 <packet len>.W <npc id>.L <message>.?B (ZC_SAY_DIALOG)
  2077. /// Client behavior (dialog window):
  2078. /// - disable mouse targeting
  2079. /// - open the dialog window
  2080. /// - set npcid of dialog window (0 by default)
  2081. /// - if set to clear on next mes, clear contents
  2082. /// - append this text
  2083. void clif_scriptmes( map_session_data& sd, uint32 npcid, const char *mes ){
  2084. PACKET_ZC_SAY_DIALOG* p = reinterpret_cast<PACKET_ZC_SAY_DIALOG*>( packet_buffer );
  2085. int16 length = (int16)( strlen( mes ) + 1 );
  2086. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2087. p->PacketLength = sizeof( *p ) + length;
  2088. p->NpcID = npcid;
  2089. safestrncpy( p->message, mes, length );
  2090. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2091. }
  2092. /// Adds a 'next' button to an NPC dialog.
  2093. /// 00b5 <npc id>.L (ZC_WAIT_DIALOG)
  2094. /// Client behavior (dialog window):
  2095. /// - disable mouse targeting
  2096. /// - open the dialog window
  2097. /// - add 'next' button
  2098. /// When 'next' is pressed:
  2099. /// - 00B9 <npcid of dialog window>.L
  2100. /// - set to clear on next mes
  2101. /// - remove 'next' button
  2102. void clif_scriptnext( map_session_data& sd, uint32 npcid ){
  2103. struct PACKET_ZC_WAIT_DIALOG p = {};
  2104. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2105. p.NpcID = npcid;
  2106. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2107. }
  2108. /// Adds a 'close' button to an NPC dialog.
  2109. /// 00b6 <npc id>.L (ZC_CLOSE_DIALOG)
  2110. /// Client behavior:
  2111. /// - if dialog window is open:
  2112. /// - remove 'next' button
  2113. /// - add 'close' button
  2114. /// - else:
  2115. /// - enable mouse targeting
  2116. /// - close the dialog window
  2117. /// - close the menu window
  2118. /// When 'close' is pressed:
  2119. /// - enable mouse targeting
  2120. /// - close the dialog window
  2121. /// - close the menu window
  2122. /// - 0146 <npcid of dialog window>.L
  2123. void clif_scriptclose( map_session_data& sd, uint32 npcid ){
  2124. PACKET_ZC_CLOSE_DIALOG packet{};
  2125. packet.packetType = HEADER_ZC_CLOSE_DIALOG;
  2126. packet.npcId = npcid;
  2127. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2128. }
  2129. /**
  2130. * Close script when player is idle
  2131. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2132. * @author [Ind/Hercules]
  2133. * @param sd : player pointer
  2134. * @param npcid : npc gid to close
  2135. */
  2136. void clif_scriptclear( map_session_data& sd, int npcid ){
  2137. struct PACKET_ZC_CLEAR_DIALOG p = {};
  2138. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2139. p.GID = npcid;
  2140. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2141. }
  2142. void clif_sendfakenpc( map_session_data& sd, uint32 npcid ){
  2143. sd.state.using_fake_npc = 1;
  2144. // Code below is a copy of clif_set_unit_idle
  2145. struct packet_idle_unit p;
  2146. p.PacketType = idle_unitType;
  2147. #if PACKETVER >= 20091103
  2148. p.PacketLength = sizeof(p);
  2149. p.objecttype = 0x1; // NPC_TYPE
  2150. #endif
  2151. #if PACKETVER >= 20131223
  2152. p.AID = npcid;
  2153. p.GID = 0;
  2154. #else
  2155. p.GID = npcid;
  2156. #endif
  2157. p.speed = 0;
  2158. p.bodyState = 0;
  2159. p.healthState = 0;
  2160. p.effectState = 0;
  2161. p.job = JT_HIDDEN_NPC;
  2162. p.head = 0;
  2163. p.weapon = 0;
  2164. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  2165. p.shield = 0;
  2166. #endif
  2167. p.accessory = 0;
  2168. p.accessory2 = 0;
  2169. p.accessory3 = 0;
  2170. p.headpalette = 0;
  2171. p.bodypalette = 0;
  2172. p.headDir = 0;
  2173. #if PACKETVER >= 20101124
  2174. p.robe = 0;
  2175. #endif
  2176. p.GUID = 0;
  2177. p.GEmblemVer = 0;
  2178. p.honor = 0;
  2179. p.virtue = 0;
  2180. p.isPKModeON = 0;
  2181. p.sex = SEX_FEMALE;
  2182. WBUFPOS( &p.PosDir[0], 0, sd.bl.x, sd.bl.y, sd.ud.dir );
  2183. p.xSize = p.ySize = 5;
  2184. p.state = 0;
  2185. p.clevel = 0;
  2186. #if PACKETVER >= 20080102
  2187. p.font = 0;
  2188. #endif
  2189. #if PACKETVER >= 20120221
  2190. p.maxHP = -1;
  2191. p.HP = -1;
  2192. #endif
  2193. #if PACKETVER >= 20150513
  2194. p.body = 0;
  2195. #endif
  2196. /* Might be earlier, this is when the named item bug began */
  2197. #if PACKETVER >= 20131223
  2198. safestrncpy( p.name, "", NAME_LENGTH);
  2199. #endif
  2200. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2201. }
  2202. /// Displays an NPC dialog menu.
  2203. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B (ZC_MENU_LIST)
  2204. /// Client behavior:
  2205. /// - disable mouse targeting
  2206. /// - close the menu window
  2207. /// - open the menu window
  2208. /// - add options to the menu (separated in the text by ":")
  2209. /// - set npcid of menu window
  2210. /// - if dialog window is open:
  2211. /// - remove 'next' button
  2212. /// When 'ok' is pressed:
  2213. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2214. /// - close the menu window
  2215. /// When 'cancel' is pressed:
  2216. /// - 00B8 <npcid of menu window>.L <-1>.B
  2217. /// - enable mouse targeting
  2218. /// - close a bunch of windows...
  2219. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2220. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2221. /// TODO investigate behavior of other windows [FlavioJS]
  2222. void clif_scriptmenu( map_session_data& sd, uint32 npcid, const char* mes ){
  2223. struct block_list *bl = nullptr;
  2224. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2225. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2226. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2227. clif_sendfakenpc( sd, npcid );
  2228. // String length + 1 byte for zero termination
  2229. size_t mes_length = strlen( mes ) + 1;
  2230. PACKET_ZC_MENU_LIST* packet = reinterpret_cast<PACKET_ZC_MENU_LIST*>( packet_buffer );
  2231. packet->packetType = HEADER_ZC_MENU_LIST;
  2232. packet->packetLength = sizeof( PACKET_ZC_MENU_LIST );
  2233. packet->npcId = npcid;
  2234. safestrncpy( packet->menu, mes, mes_length );
  2235. packet->packetLength += static_cast<decltype(packet->packetLength)>( mes_length );
  2236. clif_send( packet, packet->packetLength, &sd.bl, SELF );
  2237. }
  2238. /// Displays an NPC dialog input box for numbers.
  2239. /// 0142 <npc id>.L (ZC_OPEN_EDITDLG)
  2240. /// Client behavior (inputnum window):
  2241. /// - if npcid exists in the client:
  2242. /// - open the inputnum window
  2243. /// - set npcid of inputnum window
  2244. /// When 'ok' is pressed:
  2245. /// - if inputnum window has text:
  2246. /// - if npcid exists in the client:
  2247. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2248. /// - close inputnum window
  2249. void clif_scriptinput( map_session_data& sd, uint32 npcid ){
  2250. struct block_list *bl = nullptr;
  2251. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2252. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2253. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2254. clif_sendfakenpc( sd, npcid );
  2255. PACKET_ZC_OPEN_EDITDLG packet{};
  2256. packet.packetType = HEADER_ZC_OPEN_EDITDLG;
  2257. packet.npcId = npcid;
  2258. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2259. }
  2260. /// Displays an NPC dialog input box for strings.
  2261. /// 01d4 <npc id>.L (ZC_OPEN_EDITDLGSTR)
  2262. /// Client behavior (inputstr window):
  2263. /// - if npcid is 0 or npcid exists in the client:
  2264. /// - open the inputstr window
  2265. /// - set npcid of inputstr window
  2266. /// When 'ok' is pressed:
  2267. /// - if inputstr window has text and isn't an insult(manner.txt):
  2268. /// - if npcid is 0 or npcid exists in the client:
  2269. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2270. /// - close inputstr window
  2271. void clif_scriptinputstr( map_session_data& sd, uint32 npcid ){
  2272. struct block_list *bl = nullptr;
  2273. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2274. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2275. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2276. clif_sendfakenpc( sd, npcid );
  2277. PACKET_ZC_OPEN_EDITDLGSTR packet{};
  2278. packet.packetType = HEADER_ZC_OPEN_EDITDLGSTR;
  2279. packet.npcId = npcid;
  2280. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2281. }
  2282. /// Marks a position on client's minimap.
  2283. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L (ZC_COMPASS)
  2284. /// npc id:
  2285. /// is ignored in the client
  2286. /// type:
  2287. /// 0 = display mark for 15 seconds
  2288. /// 1 = display mark until dead or teleported
  2289. /// 2 = remove mark
  2290. /// color:
  2291. /// 0x00RRGGBB
  2292. void clif_viewpoint( map_session_data& sd, uint32 npc_id, int type, uint16 x, uint16 y, int id, uint32 color ){
  2293. PACKET_ZC_COMPASS packet{};
  2294. packet.packetType = HEADER_ZC_COMPASS;
  2295. packet.npcId = npc_id;
  2296. packet.type = type;
  2297. packet.xPos = x;
  2298. packet.yPos = y;
  2299. packet.id = id;
  2300. packet.color = color;
  2301. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2302. }
  2303. /// Displays an illustration image.
  2304. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2305. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2306. /// type:
  2307. /// 0 = bottom left corner
  2308. /// 1 = bottom middle
  2309. /// 2 = bottom right corner
  2310. /// 3 = middle of screen, inside a movable window
  2311. /// 4 = middle of screen, movable with a close button, chrome-less
  2312. /// 255 = clear all displayed cutins
  2313. void clif_cutin( map_session_data& sd, const char* image, int type ){
  2314. PACKET_ZC_SHOW_IMAGE packet{};
  2315. packet.packetType = HEADER_ZC_SHOW_IMAGE;
  2316. safestrncpy(packet.image, image, sizeof(packet.image));
  2317. packet.type = type;
  2318. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2319. }
  2320. /*==========================================
  2321. * Fills in card data from the given item and into the buffer. [Skotlex]
  2322. *------------------------------------------*/
  2323. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2324. nullpo_retv( buf );
  2325. // Blank data
  2326. if( item == nullptr ){
  2327. buf->card[0] = 0;
  2328. buf->card[1] = 0;
  2329. buf->card[2] = 0;
  2330. buf->card[3] = 0;
  2331. return;
  2332. }
  2333. // Pet eggs
  2334. if( item->card[0] == CARD0_PET ){
  2335. buf->card[0] = 0;
  2336. buf->card[1] = 0;
  2337. // Pet intimacy
  2338. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2339. buf->card[2] = item->card[3] >> 1;
  2340. // Pet renamed flag
  2341. buf->card[3] = item->card[3] & 1;
  2342. return;
  2343. }
  2344. // Forged/created items
  2345. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2346. buf->card[0] = item->card[0];
  2347. buf->card[1] = item->card[1];
  2348. buf->card[2] = item->card[2];
  2349. buf->card[3] = item->card[3];
  2350. return;
  2351. }
  2352. int i = 0, j;
  2353. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2354. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2355. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2356. }
  2357. // Normal items.
  2358. for( int k = 0; k < 4; k++, i++ ){
  2359. if( item->card[i] > 0 ){
  2360. buf->card[k] = client_nameid( item->card[i] );
  2361. }else{
  2362. buf->card[k] = 0;
  2363. }
  2364. }
  2365. }
  2366. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2367. /// A maximum of 5 random options can be supported.
  2368. static void clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item& it ){
  2369. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2370. if( it.option[i].id ){
  2371. buf[i].index = it.option[i].id; // OptIndex
  2372. buf[i].value = it.option[i].value; // Value
  2373. buf[i].param = it.option[i].param; // Param1
  2374. }else{
  2375. buf[i].index = 0;
  2376. buf[i].value = 0;
  2377. buf[i].param = 0;
  2378. }
  2379. }
  2380. #if MAX_ITEM_RDM_OPT < 5
  2381. for( ; i < 5; i++ ){
  2382. buf[i].index = 0; // OptIndex
  2383. buf[i].value = 0; // Value
  2384. buf[i].param = 0; // Param1
  2385. }
  2386. #endif
  2387. }
  2388. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2389. /// 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)
  2390. /// 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)
  2391. /// 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)
  2392. /// 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)
  2393. /// 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)
  2394. /// 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)
  2395. void clif_additem( map_session_data *sd, int n, int amount, unsigned char fail ){
  2396. nullpo_retv( sd );
  2397. int fd = sd->fd;
  2398. if( !session_isActive( fd ) ){
  2399. return;
  2400. }
  2401. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2402. if( fail ){
  2403. p = {};
  2404. }else{
  2405. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2406. return;
  2407. }
  2408. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2409. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2410. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2411. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2412. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2413. p.location = pc_equippoint(sd,n);
  2414. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2415. #if PACKETVER >= 20061218
  2416. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2417. #if PACKETVER >= 20071002
  2418. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2419. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2420. */
  2421. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2422. #if PACKETVER >= 20150226
  2423. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[n] );
  2424. #if PACKETVER >= 20160921
  2425. p.favorite = ( sd->inventory.u.items_inventory[n].favorite != 0 ) ? 1 : 0;
  2426. p.look = sd->inventory_data[n]->look;
  2427. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2428. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2429. #endif
  2430. #endif
  2431. #endif
  2432. #endif
  2433. #endif
  2434. }
  2435. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2436. p.Index = client_index( n );
  2437. p.count = amount;
  2438. p.result = fail;
  2439. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2440. }
  2441. /// Notifies the client, that an inventory item was deleted or dropped.
  2442. /// 00af <index>.W <amount>.W (ZC_ITEM_THROW_ACK)
  2443. void clif_dropitem( map_session_data& sd, int index, int amount ){
  2444. PACKET_ZC_ITEM_THROW_ACK packet{};
  2445. packet.packetType = HEADER_ZC_ITEM_THROW_ACK;
  2446. packet.index = client_index( index );
  2447. packet.count = amount;
  2448. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2449. }
  2450. /// Notifies the client, that an inventory item was deleted.
  2451. /// 07fa <delete type>.W <index>.W <amount>.W (ZC_DELETE_ITEM_FROM_BODY)
  2452. /// delete type:
  2453. /// 0 = Normal
  2454. /// 1 = Item used for a skill
  2455. /// 2 = Refine failed
  2456. /// 3 = Material changed
  2457. /// 4 = Moved to storage
  2458. /// 5 = Moved to cart
  2459. /// 6 = Item sold
  2460. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2461. void clif_delitem( map_session_data& sd, int index, int amount, short reason ){
  2462. #if PACKETVER >= 20091117
  2463. PACKET_ZC_DELETE_ITEM_FROM_BODY packet{};
  2464. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_BODY;
  2465. packet.deleteType = reason;
  2466. packet.index = client_index( index );
  2467. packet.count = amount;
  2468. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2469. #else
  2470. clif_dropitem( sd, index, amount );
  2471. #endif
  2472. }
  2473. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2474. nullpo_retv( p );
  2475. nullpo_retv( it );
  2476. nullpo_retv( id );
  2477. p->index = idx;
  2478. p->ITID = client_nameid( it->nameid );
  2479. p->type = itemtype( it->nameid );
  2480. #if PACKETVER < 20120925
  2481. p->IsIdentified = it->identify ? 1 : 0;
  2482. #endif
  2483. p->location = eqp_pos;
  2484. p->WearState = it->equip;
  2485. #if PACKETVER < 20120925
  2486. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2487. #endif
  2488. p->RefiningLevel = it->refine;
  2489. clif_addcards( &p->slot, it );
  2490. #if PACKETVER >= 20071002
  2491. p->HireExpireDate = it->expire_time;
  2492. #endif
  2493. #if PACKETVER >= 20080102
  2494. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2495. #endif
  2496. #if PACKETVER >= 20100629
  2497. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2498. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2499. #endif
  2500. #if PACKETVER >= 20120925
  2501. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2502. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2503. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2504. p->Flag.SpareBits = 0;
  2505. #endif
  2506. #if PACKETVER >= 20150226
  2507. clif_add_random_options( p->option_data, *it );
  2508. // Client ingores the value anyway and recalculates it
  2509. p->option_count = 0;
  2510. #endif
  2511. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2512. p->grade = it->enchantgrade;
  2513. #endif
  2514. }
  2515. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2516. nullpo_retv(p);
  2517. nullpo_retv(i);
  2518. nullpo_retv(id);
  2519. p->index = idx;
  2520. p->ITID = client_nameid( i->nameid );
  2521. p->type = itemtype( i->nameid );
  2522. #if PACKETVER < 20120925
  2523. p->IsIdentified = i->identify ? 1 : 0;
  2524. #endif
  2525. p->count = i->amount;
  2526. p->WearState = id->equip;
  2527. #if PACKETVER >= 5
  2528. clif_addcards( &p->slot, i );
  2529. #endif
  2530. #if PACKETVER >= 20080102
  2531. p->HireExpireDate = i->expire_time;
  2532. #endif
  2533. #if PACKETVER >= 20120925
  2534. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2535. p->Flag.PlaceETCTab = ( i->favorite != 0 ) ? 1 : 0;
  2536. p->Flag.SpareBits = 0;
  2537. #endif
  2538. }
  2539. static void clif_inventoryStart( map_session_data *sd, e_inventory_type type, const char *name ){
  2540. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2541. nullpo_retv(sd);
  2542. nullpo_retv(name);
  2543. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2544. memset(buf, 0, sizeof(buf));
  2545. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2546. p->packetType = HEADER_ZC_INVENTORY_START;
  2547. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2548. p->invType = type;
  2549. #endif
  2550. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2551. int strLen = (int)safestrnlen(name, 24) + 1;
  2552. if (strLen > 24)
  2553. strLen = 24;
  2554. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2555. p->packetLength = len;
  2556. safestrncpy(p->name, name, strLen);
  2557. #else
  2558. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2559. safestrncpy(p->name, name, NAME_LENGTH);
  2560. #endif
  2561. clif_send( p, len, &sd->bl, SELF );
  2562. #endif
  2563. }
  2564. static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
  2565. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2566. nullpo_retv(sd);
  2567. struct PACKET_ZC_INVENTORY_END p;
  2568. p.packetType = HEADER_ZC_INVENTORY_END;
  2569. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2570. p.invType = type;
  2571. #endif
  2572. p.flag = 0;
  2573. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2574. #endif
  2575. }
  2576. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2577. void clif_inventorylist( map_session_data *sd ){
  2578. nullpo_retv( sd );
  2579. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2580. e_inventory_type type = INVTYPE_INVENTORY;
  2581. clif_inventoryStart( sd, type, "" );
  2582. #endif
  2583. static struct packet_itemlist_normal itemlist_normal;
  2584. static struct packet_itemlist_equip itemlist_equip;
  2585. int equip = 0;
  2586. int normal = 0;
  2587. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2588. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2589. continue;
  2590. }
  2591. // Non-stackable (Equippable)
  2592. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2593. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2594. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2595. itemlist_equip.PacketType = inventorylistequipType;
  2596. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2597. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2598. itemlist_equip.invType = type;
  2599. #endif
  2600. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2601. equip = 0;
  2602. }
  2603. // Stackable (Normal)
  2604. }else{
  2605. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2606. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2607. itemlist_normal.PacketType = inventorylistnormalType;
  2608. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2609. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2610. itemlist_normal.invType = type;
  2611. #endif
  2612. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2613. normal = 0;
  2614. }
  2615. }
  2616. }
  2617. if( normal ){
  2618. itemlist_normal.PacketType = inventorylistnormalType;
  2619. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2620. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2621. itemlist_normal.invType = type;
  2622. #endif
  2623. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2624. }
  2625. if( sd->equip_index[EQI_AMMO] >= 0 )
  2626. clif_arrowequip( *sd );
  2627. if( equip ) {
  2628. itemlist_equip.PacketType = inventorylistequipType;
  2629. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2630. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2631. itemlist_equip.invType = type;
  2632. #endif
  2633. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2634. }
  2635. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2636. clif_inventoryEnd( sd, type );
  2637. #endif
  2638. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2639. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2640. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2641. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr )
  2642. continue;
  2643. if ( sd->inventory.u.items_inventory[i].favorite != 0 )
  2644. clif_favorite_item( *sd, i );
  2645. }
  2646. #endif
  2647. }
  2648. //Required when items break/get-repaired. Only sends equippable item list.
  2649. void clif_equiplist( map_session_data *sd ){
  2650. // TODO: implement again => only send equip part
  2651. clif_inventorylist( sd );
  2652. }
  2653. void clif_storagelist(map_session_data* sd, struct item* items, int items_length, const char *storename){
  2654. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2655. e_inventory_type type = INVTYPE_STORAGE;
  2656. clif_inventoryStart( sd, type, storename );
  2657. #endif
  2658. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2659. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2660. int equip = 0;
  2661. int normal = 0;
  2662. for( int i = 0; i < items_length; i++ ){
  2663. if( items[i].nameid == 0 ){
  2664. continue;
  2665. }
  2666. struct item_data* id = itemdb_search( items[i].nameid );
  2667. // Non-stackable (Equippable)
  2668. if( !itemdb_isstackable2( id ) ){
  2669. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2670. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2671. storage_itemlist_equip.PacketType = storageListEquipType;
  2672. 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 ) );
  2673. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2674. storage_itemlist_equip.invType = type;
  2675. #elif PACKETVER >= 20120925
  2676. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2677. #endif
  2678. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2679. equip = 0;
  2680. }
  2681. // Stackable (Normal)
  2682. }else{
  2683. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2684. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2685. storage_itemlist_normal.PacketType = storageListNormalType;
  2686. 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 ) );
  2687. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2688. storage_itemlist_normal.invType = type;
  2689. #elif PACKETVER >= 20120925
  2690. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2691. #endif
  2692. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2693. normal = 0;
  2694. }
  2695. }
  2696. }
  2697. if( normal ){
  2698. storage_itemlist_normal.PacketType = storageListNormalType;
  2699. 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 ) );
  2700. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2701. storage_itemlist_normal.invType = type;
  2702. #elif PACKETVER >= 20120925
  2703. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2704. #endif
  2705. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2706. }
  2707. if( equip ) {
  2708. storage_itemlist_equip.PacketType = storageListEquipType;
  2709. 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 ) );
  2710. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2711. storage_itemlist_equip.invType = type;
  2712. #elif PACKETVER >= 20120925
  2713. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2714. #endif
  2715. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2716. }
  2717. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2718. clif_inventoryEnd( sd, type );
  2719. #endif
  2720. }
  2721. void clif_cartlist( map_session_data *sd ){
  2722. nullpo_retv( sd );
  2723. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2724. e_inventory_type type = INVTYPE_CART;
  2725. clif_inventoryStart( sd, type, "" );
  2726. #endif
  2727. static struct packet_itemlist_normal itemlist_normal;
  2728. static struct packet_itemlist_equip itemlist_equip;
  2729. int normal = 0;
  2730. int equip = 0;
  2731. for( int i = 0; i < MAX_CART; i++ ){
  2732. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2733. continue;
  2734. }
  2735. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2736. // Non-stackable (Equippable)
  2737. if( !itemdb_isstackable2(id) ){
  2738. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2739. // Stackable (Normal)
  2740. }else{
  2741. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2742. }
  2743. }
  2744. if( normal ){
  2745. itemlist_normal.PacketType = cartlistnormalType;
  2746. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2747. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2748. itemlist_normal.invType = type;
  2749. #endif
  2750. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2751. }
  2752. if( equip ){
  2753. itemlist_equip.PacketType = cartlistequipType;
  2754. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2755. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2756. itemlist_equip.invType = type;
  2757. #endif
  2758. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2759. }
  2760. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2761. clif_inventoryEnd( sd, type );
  2762. #endif
  2763. }
  2764. /// Removes cart.
  2765. /// 012b (ZC_CARTOFF)
  2766. /// Client behaviour:
  2767. /// Closes the cart storage and removes all it's items from memory.
  2768. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2769. void clif_clearcart(int fd)
  2770. {
  2771. PACKET_ZC_CARTOFF packet{};
  2772. packet.packetType = HEADER_ZC_CARTOFF;
  2773. socket_send<PACKET_ZC_CARTOFF>(fd, packet);
  2774. }
  2775. /// Sends XY location to all other guild members
  2776. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2777. void clif_guild_xy( map_session_data& sd ){
  2778. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2779. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2780. packet.aid = sd.status.account_id;
  2781. packet.xPos = sd.bl.x;
  2782. packet.yPos = sd.bl.y;
  2783. clif_send(&packet, sizeof(packet), &sd.bl, GUILD_SAMEMAP_WOS);
  2784. }
  2785. /// Sends XY location to a specific guild member
  2786. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2787. void clif_guild_xy_single( map_session_data& sd, map_session_data& tsd ){
  2788. if( sd.bg_id ){
  2789. return;
  2790. }
  2791. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2792. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2793. packet.aid = sd.status.account_id;
  2794. packet.xPos = sd.bl.x;
  2795. packet.yPos = sd.bl.y;
  2796. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  2797. }
  2798. /// Removes XY location from all other guild members
  2799. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2800. void clif_guild_xy_remove( map_session_data& sd ){
  2801. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2802. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2803. packet.aid = sd.status.account_id;
  2804. packet.xPos = -1;
  2805. packet.yPos = -1;
  2806. clif_send( &packet, sizeof( packet ), &sd.bl, GUILD_SAMEMAP_WOS );
  2807. }
  2808. /*==========================================
  2809. * Load castle list for guild UI. [Asheraf] / [Balfear]
  2810. *------------------------------------------*/
  2811. void clif_guild_castle_list(map_session_data& sd){
  2812. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2813. auto &g = sd.guild;
  2814. if (g == nullptr)
  2815. return;
  2816. int castle_count = guild_checkcastles(g->guild);
  2817. if( castle_count <= 0 ){
  2818. return;
  2819. }
  2820. PACKET_ZC_GUILD_AGIT_INFO* p = reinterpret_cast<PACKET_ZC_GUILD_AGIT_INFO*>( packet_buffer );
  2821. p->packetType = HEADER_ZC_GUILD_AGIT_INFO;
  2822. p->packetLength = sizeof( *p );
  2823. int i = 0;
  2824. for (const auto& gc : castle_db) {
  2825. if (gc.second->guild_id == g->guild.guild_id && gc.second->client_id) {
  2826. p->castle_list[i] = static_cast<int8>( gc.second->client_id );
  2827. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->castle_list[0] ) );
  2828. ++i;
  2829. }
  2830. }
  2831. clif_send(p, p->packetLength, &sd.bl, SELF);
  2832. #endif
  2833. }
  2834. /*==========================================
  2835. * Send castle info Economy/Defence. [Asheraf] / [Balfear]
  2836. *------------------------------------------*/
  2837. void clif_guild_castleinfo(map_session_data& sd, std::shared_ptr<guild_castle> castle ){
  2838. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2839. if( castle->client_id == 0 ){
  2840. return;
  2841. }
  2842. struct PACKET_ZC_REQ_ACK_AGIT_INVESTMENT p = {};
  2843. p.packetType = HEADER_ZC_REQ_ACK_AGIT_INVESTMENT;
  2844. p.castle_id = static_cast<int8>( castle->client_id );
  2845. p.economy = castle->economy;
  2846. p.defense = castle->defense;
  2847. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2848. #endif
  2849. }
  2850. /*==========================================
  2851. * Show teleport request result. [Asheraf] / [Balfear]
  2852. *------------------------------------------*/
  2853. void clif_guild_castle_teleport_res(map_session_data& sd, enum e_siege_teleport_result result){
  2854. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2855. struct PACKET_ZC_REQ_ACK_MOVE_GUILD_AGIT p = {};
  2856. p.packetType = HEADER_ZC_REQ_ACK_MOVE_GUILD_AGIT;
  2857. p.result = static_cast<int16>( result );
  2858. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2859. #endif
  2860. }
  2861. /*==========================================
  2862. * Request castle info. [Asheraf] / [Balfear]
  2863. *------------------------------------------*/
  2864. void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){
  2865. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2866. const struct PACKET_CZ_REQ_AGIT_INVESTMENT* p = (struct PACKET_CZ_REQ_AGIT_INVESTMENT*)RFIFOP(fd, 0);
  2867. auto &g = sd->guild;
  2868. if (g == nullptr)
  2869. return;
  2870. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2871. if (gc == nullptr)
  2872. return;
  2873. if (gc->guild_id != g->guild.guild_id)
  2874. return;
  2875. clif_guild_castleinfo(*sd, gc);
  2876. #endif
  2877. }
  2878. /*==========================================
  2879. * Teleport to castle. [Asheraf] / [Balfear]
  2880. *------------------------------------------*/
  2881. void clif_parse_guild_castle_teleport_request(int fd, map_session_data* sd){
  2882. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2883. const struct PACKET_CZ_REQ_MOVE_GUILD_AGIT* p = (struct PACKET_CZ_REQ_MOVE_GUILD_AGIT*)RFIFOP(fd, 0);
  2884. auto &g = sd->guild;
  2885. if (g == nullptr)
  2886. return;
  2887. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2888. if (gc == nullptr)
  2889. return;
  2890. if (!gc->warp_enabled)
  2891. return;
  2892. if (gc->guild_id != g->guild.guild_id)
  2893. return;
  2894. if (map_getmapflag(sd->bl.m, MF_GVG_CASTLE)
  2895. || map_getmapflag(sd->bl.m, MF_NOTELEPORT)
  2896. || map_getmapflag(sd->bl.m, MF_NOWARP))
  2897. return;
  2898. uint32 zeny = gc->zeny;
  2899. switch( gc->type ){
  2900. case WOE_FIRST_EDITION:
  2901. if( agit_flag ){
  2902. zeny = gc->zeny_siege;
  2903. }
  2904. break;
  2905. case WOE_SECOND_EDITION:
  2906. if( agit2_flag ){
  2907. zeny = gc->zeny_siege;
  2908. }
  2909. break;
  2910. case WOE_THIRD_EDITION:
  2911. if( agit3_flag ){
  2912. zeny = gc->zeny_siege;
  2913. }
  2914. break;
  2915. }
  2916. if (zeny && pc_payzeny(sd, zeny, LOG_TYPE_OTHER)) {
  2917. clif_guild_castle_teleport_res(*sd, SIEGE_TP_NOT_ENOUGH_ZENY);
  2918. return;
  2919. }
  2920. pc_setpos(sd, gc->mapindex, gc->warp_x, gc->warp_y, CLR_OUTSIGHT);
  2921. #endif
  2922. }
  2923. /*==========================================
  2924. *
  2925. *------------------------------------------*/
  2926. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2927. map_session_data* sd = va_arg( ap, map_session_data* );
  2928. map_session_data* tsd = BL_CAST( BL_PC, bl );
  2929. nullpo_ret(sd);
  2930. nullpo_ret(tsd);
  2931. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2932. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2933. }
  2934. return 0;
  2935. }
  2936. /*==========================================
  2937. * Server tells all players that are allowed to view HP bars
  2938. * and are nearby 'sd' that 'sd' hp bar was updated.
  2939. *------------------------------------------*/
  2940. static int clif_hpmeter(map_session_data *sd)
  2941. {
  2942. nullpo_ret(sd);
  2943. 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);
  2944. return 0;
  2945. }
  2946. /**
  2947. * Send HP bar update to others.
  2948. * @param sd: Player invoking update
  2949. */
  2950. void clif_update_hp(map_session_data &sd) {
  2951. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2952. clif_hpmeter(&sd);
  2953. if (!battle_config.party_hp_mode && sd.status.party_id)
  2954. clif_party_hp( sd );
  2955. if (sd.bg_id)
  2956. clif_bg_hp(&sd);
  2957. }
  2958. /// Notifies client of a character parameter change.
  2959. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2960. static void clif_par_change(map_session_data& sd, uint16 varId, int count) {
  2961. PACKET_ZC_PAR_CHANGE packet{};
  2962. packet.PacketType = HEADER_ZC_PAR_CHANGE;
  2963. packet.varID = varId;
  2964. packet.count = count;
  2965. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2966. }
  2967. /// Notifies client of a character parameter change.
  2968. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2969. static void clif_longpar_change(map_session_data& sd, uint16 varId, int amount) {
  2970. PACKET_ZC_LONGPAR_CHANGE packet{};
  2971. packet.PacketType = HEADER_ZC_LONGPAR_CHANGE;
  2972. packet.varID = varId;
  2973. packet.amount = amount;
  2974. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2975. }
  2976. /// Notifies client of a character parameter change.
  2977. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2978. static void clif_zc_status_change(map_session_data& sd, uint16 status_id, uint8 value) {
  2979. PACKET_ZC_STATUS_CHANGE packet{};
  2980. packet.PacketType = HEADER_ZC_STATUS_CHANGE;
  2981. packet.statusID = status_id;
  2982. packet.value = value;
  2983. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2984. }
  2985. /// Notifies client of a character parameter change.
  2986. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2987. static void clif_cartcount( map_session_data& sd ){
  2988. PACKET_ZC_NOTIFY_CARTITEM_COUNTINFO packet{};
  2989. packet.PacketType = HEADER_ZC_NOTIFY_CARTITEM_COUNTINFO;
  2990. packet.curCount = sd.cart_num;
  2991. packet.maxCount = MAX_CART;
  2992. packet.curWeight = sd.cart_weight;
  2993. packet.maxWeight = sd.cart_weight_max;
  2994. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2995. }
  2996. /// Tells the client how far it is allowed to attack (weapon range)
  2997. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2998. static void clif_attackrange( map_session_data& sd, int16 range ){
  2999. PACKET_ZC_ATTACK_RANGE packet{};
  3000. packet.PacketType = HEADER_ZC_ATTACK_RANGE;
  3001. packet.currentAttRange = range;
  3002. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3003. }
  3004. /// Notifies client of a character parameter change.
  3005. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  3006. static void clif_couplestatus(map_session_data& sd, uint32 status_type, int32 defaultStatus, int32 plusStatus) {
  3007. PACKET_ZC_COUPLESTATUS packet{};
  3008. packet.PacketType = HEADER_ZC_COUPLESTATUS;
  3009. packet.statusType = status_type;
  3010. packet.defaultStatus = defaultStatus;
  3011. packet.plusStatus = plusStatus;
  3012. clif_send(&packet, sizeof(packet), &sd.bl, SELF);
  3013. }
  3014. /// Notifies client of a character parameter change.
  3015. /// 0acb <var id>.W <value>.Q (ZC_LONGLONGPAR_CHANGE)
  3016. static void clif_longlongpar_change(map_session_data& sd, uint16 varId, int64 amount) {
  3017. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  3018. PACKET_ZC_LONGLONGPAR_CHANGE packet{};
  3019. packet.PacketType = HEADER_ZC_LONGLONGPAR_CHANGE;
  3020. packet.varID = varId;
  3021. packet.amount = amount;
  3022. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3023. #endif
  3024. }
  3025. /// Notifies client of a character parameter change.
  3026. void clif_updatestatus( map_session_data& sd, enum _sp type ){
  3027. switch(type){
  3028. case SP_WEIGHT:
  3029. pc_updateweightstatus(&sd);
  3030. clif_par_change(sd, type, sd.weight);
  3031. break;
  3032. case SP_MAXWEIGHT:
  3033. clif_par_change(sd, type, sd.max_weight);
  3034. break;
  3035. case SP_SPEED:
  3036. clif_par_change(sd, type, sd.battle_status.speed);
  3037. break;
  3038. case SP_BASELEVEL:
  3039. clif_par_change(sd, type, sd.status.base_level);
  3040. break;
  3041. case SP_JOBLEVEL:
  3042. clif_par_change(sd, type, sd.status.job_level);
  3043. break;
  3044. case SP_KARMA:
  3045. // Adding this back, I wonder if the client intercepts this - [Lance]
  3046. clif_par_change(sd, type, sd.status.karma);
  3047. break;
  3048. case SP_MANNER:
  3049. clif_par_change(sd, type, sd.status.manner);
  3050. break;
  3051. case SP_STATUSPOINT:
  3052. clif_par_change(sd, type, sd.status.status_point);
  3053. break;
  3054. case SP_SKILLPOINT:
  3055. clif_par_change(sd, type, sd.status.skill_point);
  3056. break;
  3057. case SP_HIT:
  3058. clif_par_change(sd, type, sd.battle_status.hit);
  3059. break;
  3060. case SP_FLEE1:
  3061. clif_par_change(sd, type, sd.battle_status.flee);
  3062. break;
  3063. case SP_FLEE2:
  3064. clif_par_change(sd, type, sd.battle_status.flee2/10);
  3065. break;
  3066. case SP_MAXHP:
  3067. clif_par_change(sd, type, sd.battle_status.max_hp);
  3068. break;
  3069. case SP_MAXSP:
  3070. clif_par_change(sd, type, sd.battle_status.max_sp);
  3071. break;
  3072. case SP_HP:
  3073. // On officials the HP never go below 1, even if you die [Lemongrass]
  3074. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  3075. if (sd.battle_status.hp == 0) {
  3076. clif_par_change(sd, type, (sd.class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd.battle_status.max_hp/2);
  3077. } else {
  3078. clif_par_change(sd, type, sd.battle_status.hp);
  3079. }
  3080. break;
  3081. case SP_SP:
  3082. clif_par_change(sd, type, sd.battle_status.sp);
  3083. break;
  3084. case SP_ASPD:
  3085. clif_par_change(sd, type, sd.battle_status.amotion);
  3086. break;
  3087. case SP_ATK1:
  3088. clif_par_change(sd, type, pc_leftside_atk(&sd));
  3089. break;
  3090. case SP_DEF1:
  3091. clif_par_change(sd, type, pc_leftside_def(&sd));
  3092. break;
  3093. case SP_MDEF1:
  3094. clif_par_change(sd, type, pc_leftside_mdef(&sd));
  3095. break;
  3096. case SP_ATK2:
  3097. clif_par_change(sd, type, pc_rightside_atk(&sd));
  3098. break;
  3099. case SP_DEF2:
  3100. clif_par_change(sd, type, pc_rightside_def(&sd));
  3101. break;
  3102. case SP_MDEF2: {
  3103. //negative check (in case you have something like Berserk active)
  3104. int mdef2 = pc_rightside_mdef(&sd);
  3105. #ifndef RENEWAL
  3106. clif_par_change(sd, type, mdef2 < 0 ? 0 : mdef2);
  3107. #else
  3108. clif_par_change(sd, type, mdef2);
  3109. #endif
  3110. }
  3111. break;
  3112. case SP_CRITICAL:
  3113. clif_par_change(sd, type, sd.battle_status.cri/10);
  3114. break;
  3115. case SP_MATK1:
  3116. clif_par_change(sd, type, pc_rightside_matk(&sd));
  3117. break;
  3118. case SP_MATK2:
  3119. clif_par_change(sd, type, pc_leftside_matk(&sd));
  3120. break;
  3121. case SP_ZENY:
  3122. clif_longpar_change(sd, type, sd.status.zeny);
  3123. break;
  3124. #if PACKETVER >= 20170830
  3125. case SP_BASEEXP:
  3126. clif_longlongpar_change(sd, type, client_exp(sd.status.base_exp));
  3127. break;
  3128. case SP_JOBEXP:
  3129. clif_longlongpar_change(sd, type, client_exp(sd.status.job_exp));
  3130. break;
  3131. case SP_NEXTBASEEXP:
  3132. clif_longlongpar_change(sd, type, client_exp(pc_nextbaseexp(&sd)));
  3133. break;
  3134. case SP_NEXTJOBEXP:
  3135. clif_longlongpar_change(sd, type, client_exp(pc_nextjobexp(&sd)));
  3136. break;
  3137. #else
  3138. case SP_BASEEXP:
  3139. clif_par_change(sd, type, client_exp(sd.status.base_exp));
  3140. break;
  3141. case SP_JOBEXP:
  3142. clif_par_change(sd, type, client_exp(sd.status.job_exp));
  3143. break;
  3144. case SP_NEXTBASEEXP:
  3145. clif_par_change(sd, type, client_exp(pc_nextbaseexp(&sd)));
  3146. break;
  3147. case SP_NEXTJOBEXP:
  3148. clif_par_change(sd, type, client_exp(pc_nextjobexp(&sd)));
  3149. break;
  3150. #endif
  3151. /**
  3152. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3153. **/
  3154. case SP_USTR:
  3155. case SP_UAGI:
  3156. case SP_UVIT:
  3157. case SP_UINT:
  3158. case SP_UDEX:
  3159. case SP_ULUK:
  3160. clif_zc_status_change(sd, static_cast<uint16>(type), static_cast<uint8>(pc_need_status_point(&sd, type-SP_USTR+SP_STR, 1)));
  3161. break;
  3162. case SP_ATTACKRANGE:
  3163. clif_attackrange( sd, sd.battle_status.rhw.range );
  3164. break;
  3165. case SP_STR:
  3166. clif_couplestatus(sd, type, sd.status.str, sd.battle_status.str - sd.status.str);
  3167. break;
  3168. case SP_AGI:
  3169. clif_couplestatus(sd, type, sd.status.agi, sd.battle_status.agi - sd.status.agi);
  3170. break;
  3171. case SP_VIT:
  3172. clif_couplestatus(sd, type, sd.status.vit, sd.battle_status.vit - sd.status.vit);
  3173. break;
  3174. case SP_INT:
  3175. clif_couplestatus(sd, type, sd.status.int_, sd.battle_status.int_ - sd.status.int_);
  3176. break;
  3177. case SP_DEX:
  3178. clif_couplestatus(sd, type, sd.status.dex, sd.battle_status.dex - sd.status.dex);
  3179. break;
  3180. case SP_LUK:
  3181. clif_couplestatus(sd, type, sd.status.luk, sd.battle_status.luk - sd.status.luk);
  3182. break;
  3183. case SP_CARTINFO:
  3184. clif_cartcount( sd );
  3185. break;
  3186. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3187. case SP_AP:
  3188. clif_par_change( sd, SP_AP, sd.battle_status.ap );
  3189. break;
  3190. case SP_TRAITPOINT:
  3191. clif_par_change( sd, SP_TRAITPOINT, sd.status.trait_point );
  3192. break;
  3193. case SP_MAXAP:
  3194. clif_par_change( sd, SP_MAXAP, sd.battle_status.max_ap );
  3195. break;
  3196. case SP_POW:
  3197. clif_couplestatus( sd, SP_POW, sd.status.pow, sd.battle_status.pow - sd.status.pow );
  3198. break;
  3199. case SP_STA:
  3200. clif_couplestatus( sd, SP_STA, sd.status.sta, sd.battle_status.sta - sd.status.sta );
  3201. break;
  3202. case SP_WIS:
  3203. clif_couplestatus( sd, SP_WIS, sd.status.wis, sd.battle_status.wis - sd.status.wis );
  3204. break;
  3205. case SP_SPL:
  3206. clif_couplestatus( sd, SP_SPL, sd.status.spl, sd.battle_status.spl - sd.status.spl );
  3207. break;
  3208. case SP_CON:
  3209. clif_couplestatus( sd, SP_CON, sd.status.con, sd.battle_status.con - sd.status.con );
  3210. break;
  3211. case SP_CRT:
  3212. clif_couplestatus( sd, SP_CRT, sd.status.crt, sd.battle_status.crt - sd.status.crt );
  3213. break;
  3214. case SP_UPOW:
  3215. case SP_USTA:
  3216. case SP_UWIS:
  3217. case SP_USPL:
  3218. case SP_UCON:
  3219. case SP_UCRT:
  3220. clif_zc_status_change( sd, static_cast<uint16>( type ), static_cast<uint8>( pc_need_trait_point( &sd, type - SP_UPOW + SP_POW, 1 ) ) );
  3221. break;
  3222. case SP_PATK:
  3223. clif_par_change( sd, SP_PATK, sd.battle_status.patk );
  3224. break;
  3225. case SP_SMATK:
  3226. clif_par_change( sd, SP_SMATK, sd.battle_status.smatk );
  3227. break;
  3228. case SP_RES:
  3229. clif_par_change( sd, SP_RES, sd.battle_status.res );
  3230. break;
  3231. case SP_MRES:
  3232. clif_par_change( sd, SP_MRES, sd.battle_status.mres );
  3233. break;
  3234. case SP_HPLUS:
  3235. clif_par_change( sd, SP_HPLUS, sd.battle_status.hplus );
  3236. break;
  3237. case SP_CRATE:
  3238. clif_par_change( sd, SP_CRATE, sd.battle_status.crate );
  3239. break;
  3240. #else
  3241. case SP_AP:
  3242. case SP_TRAITPOINT:
  3243. case SP_MAXAP:
  3244. case SP_POW:
  3245. case SP_STA:
  3246. case SP_WIS:
  3247. case SP_SPL:
  3248. case SP_CON:
  3249. case SP_CRT:
  3250. case SP_UPOW:
  3251. case SP_USTA:
  3252. case SP_UWIS:
  3253. case SP_USPL:
  3254. case SP_UCON:
  3255. case SP_UCRT:
  3256. case SP_PATK:
  3257. case SP_SMATK:
  3258. case SP_RES:
  3259. case SP_MRES:
  3260. case SP_HPLUS:
  3261. case SP_CRATE:
  3262. // 4th job status are not supported by older clients
  3263. return;
  3264. #endif
  3265. default:
  3266. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3267. return;
  3268. }
  3269. // Additional update packets that should be sent right after
  3270. switch( type ){
  3271. case SP_BASELEVEL:
  3272. if( sd.status.party_id ){
  3273. struct party_data* p;
  3274. int i;
  3275. if( ( p = party_search( sd.status.party_id ) ) != nullptr ){
  3276. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd.status.char_id);
  3277. if( i < MAX_PARTY ){
  3278. p->party.member[i].lv = sd.status.base_level;
  3279. clif_party_job_and_level( sd );
  3280. }
  3281. }
  3282. }
  3283. break;
  3284. case SP_HP:
  3285. clif_update_hp( sd );
  3286. break;
  3287. }
  3288. }
  3289. /// Notifies client of a parameter change of an another player.
  3290. /// 01ab <account id>.L <var id>.W <value>.L (ZC_PAR_CHANGE_USER)
  3291. /// var id:
  3292. /// SP_MANNER
  3293. /// ?
  3294. void clif_changemanner( map_session_data& sd ) {
  3295. PACKET_ZC_PAR_CHANGE_USER packet{};
  3296. packet.packetType = HEADER_ZC_PAR_CHANGE_USER;
  3297. packet.gid = sd.bl.id;
  3298. packet.type = static_cast<decltype(packet.type)>(SP_MANNER);
  3299. packet.value = sd.status.manner;
  3300. clif_send( &packet, sizeof( packet ), &sd.bl, AREA_WOS );
  3301. }
  3302. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3303. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3304. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3305. struct PACKET_ZC_SPRITE_CHANGE p;
  3306. p.packetType = sendLookType;
  3307. p.AID = id;
  3308. p.type = type;
  3309. p.val = val;
  3310. #if PACKETVER >= 4
  3311. p.val2 = val2;
  3312. #endif
  3313. clif_send( &p, sizeof( p ), bl, target );
  3314. }
  3315. /// Updates sprite/style properties of an object.
  3316. void clif_changelook(struct block_list *bl, int type, int val) {
  3317. map_session_data* sd;
  3318. status_change* sc;
  3319. struct view_data* vd;
  3320. enum send_target target = AREA;
  3321. int val2 = 0;
  3322. nullpo_retv(bl);
  3323. sd = BL_CAST(BL_PC, bl);
  3324. sc = status_get_sc(bl);
  3325. vd = status_get_viewdata(bl);
  3326. if( vd ) //temp hack to let Warp Portal change appearance
  3327. switch(type) {
  3328. case LOOK_WEAPON:
  3329. if (sd) {
  3330. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3331. val = vd->weapon;
  3332. }
  3333. else
  3334. vd->weapon = val;
  3335. break;
  3336. case LOOK_SHIELD:
  3337. if (sd) {
  3338. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3339. val = vd->shield;
  3340. }
  3341. else
  3342. vd->shield = val;
  3343. break;
  3344. case LOOK_BASE:
  3345. if (!sd)
  3346. break;
  3347. if ( val == JT_INVISIBLE )
  3348. return;
  3349. if (sd->sc.option&OPTION_COSTUME)
  3350. vd->weapon = vd->shield = 0;
  3351. if (!vd->cloth_color)
  3352. break;
  3353. if (sd) {
  3354. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3355. vd->cloth_color = 0;
  3356. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3357. vd->cloth_color = 0;
  3358. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3359. vd->cloth_color = 0;
  3360. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3361. vd->cloth_color = 0;
  3362. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3363. vd->cloth_color = 0;
  3364. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3365. vd->body_style = 0;
  3366. }
  3367. break;
  3368. case LOOK_HAIR:
  3369. vd->hair_style = val;
  3370. break;
  3371. case LOOK_HEAD_BOTTOM:
  3372. vd->head_bottom = val;
  3373. break;
  3374. case LOOK_HEAD_TOP:
  3375. vd->head_top = val;
  3376. break;
  3377. case LOOK_HEAD_MID:
  3378. vd->head_mid = val;
  3379. break;
  3380. case LOOK_HAIR_COLOR:
  3381. vd->hair_color = val;
  3382. break;
  3383. case LOOK_CLOTHES_COLOR:
  3384. if (val && sd) {
  3385. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3386. val = 0;
  3387. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3388. val = 0;
  3389. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3390. val = 0;
  3391. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3392. val = 0;
  3393. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3394. val = 0;
  3395. }
  3396. vd->cloth_color = val;
  3397. break;
  3398. case LOOK_SHOES:
  3399. #if PACKETVER > 3
  3400. if (sd) {
  3401. int n;
  3402. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3403. if(sd->inventory_data[n]->view_id > 0)
  3404. val = sd->inventory_data[n]->view_id;
  3405. else
  3406. val = sd->inventory.u.items_inventory[n].nameid;
  3407. } else
  3408. val = 0;
  3409. }
  3410. #endif
  3411. //Shoes? No packet uses this....
  3412. break;
  3413. case LOOK_BODY:
  3414. // unknown purpose
  3415. break;
  3416. case LOOK_ROBE:
  3417. #if PACKETVER < 20110111
  3418. return;
  3419. #else
  3420. vd->robe = val;
  3421. #endif
  3422. break;
  3423. case LOOK_BODY2:
  3424. #if PACKETVER < 20150513
  3425. return;
  3426. #else
  3427. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3428. val = 0;
  3429. vd->body_style = val;
  3430. #endif
  3431. break;
  3432. }
  3433. // prevent leaking the presence of GM-hidden objects
  3434. if( sc && sc->option&OPTION_INVISIBLE )
  3435. target = SELF;
  3436. #if PACKETVER < 4
  3437. if (target != SELF && bl->type == BL_NPC && (((TBL_NPC*)bl)->is_invisible))
  3438. target = SELF;
  3439. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3440. #else
  3441. if (bl->type != BL_NPC) {
  3442. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3443. type = LOOK_WEAPON;
  3444. val = (vd ? vd->weapon : 0);
  3445. val2 = (vd ? vd->shield : 0);
  3446. }
  3447. if (disguised(bl)) {
  3448. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3449. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3450. } else
  3451. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3452. } else
  3453. unit_refresh(bl);
  3454. #endif
  3455. }
  3456. //Sends a change-base-look packet required for traps as they are triggered.
  3457. void clif_changetraplook(struct block_list *bl,int val) {
  3458. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3459. }
  3460. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3461. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3462. clif_sprite_change(bl, id, type, val, 0, target);
  3463. }
  3464. /// Character status (ZC_STATUS).
  3465. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3466. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3467. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3468. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3469. void clif_initialstatus( map_session_data& sd ) {
  3470. PACKET_ZC_STATUS packet{};
  3471. packet.packetType = HEADER_ZC_STATUS;
  3472. packet.point = min(sd.status.status_point, INT16_MAX);
  3473. packet.str = min(sd.status.str, UINT8_MAX);
  3474. packet.standardStr = pc_need_status_point( &sd, SP_STR, 1 );
  3475. packet.agi = min(sd.status.agi, UINT8_MAX);
  3476. packet.standardAgi = pc_need_status_point( &sd, SP_AGI,1 );
  3477. packet.vit = min(sd.status.vit, UINT8_MAX);
  3478. packet.standardVit = pc_need_status_point( &sd, SP_VIT,1 );
  3479. packet.int_ = min(sd.status.int_, UINT8_MAX);
  3480. packet.standardInt = pc_need_status_point( &sd, SP_INT,1 );
  3481. packet.dex = min(sd.status.dex, UINT8_MAX);
  3482. packet.standardDex = pc_need_status_point( &sd, SP_DEX,1 );
  3483. packet.luk = min(sd.status.luk, UINT8_MAX);
  3484. packet.standardLuk = pc_need_status_point( &sd, SP_LUK,1 );
  3485. packet.attPower = pc_leftside_atk( &sd );
  3486. packet.refiningPower = pc_rightside_atk( &sd );
  3487. packet.max_mattPower = pc_rightside_matk( &sd );
  3488. packet.min_mattPower = pc_leftside_matk( &sd );
  3489. packet.itemdefPower = pc_leftside_def( &sd );
  3490. packet.plusdefPower = pc_rightside_def( &sd );
  3491. packet.mdefPower = pc_leftside_mdef( &sd );
  3492. #ifdef RENEWAL
  3493. packet.plusmdefPower = pc_rightside_mdef( &sd );
  3494. #else
  3495. // Negative check for Frenzy'ed characters.
  3496. packet.plusmdefPower = std::max( pc_rightside_mdef( &sd ), 0 );
  3497. #endif
  3498. packet.hitSuccessValue = sd.battle_status.hit;
  3499. packet.avoidSuccessValue = sd.battle_status.flee;
  3500. packet.plusAvoidSuccessValue = sd.battle_status.flee2 / 10;
  3501. packet.criticalSuccessValue = sd.battle_status.cri / 10;
  3502. packet.ASPD = sd.battle_status.amotion;
  3503. packet.plusASPD = 0;
  3504. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3505. clif_updatestatus(sd, SP_STR);
  3506. clif_updatestatus(sd, SP_AGI);
  3507. clif_updatestatus(sd, SP_VIT);
  3508. clif_updatestatus(sd, SP_INT);
  3509. clif_updatestatus(sd, SP_DEX);
  3510. clif_updatestatus(sd, SP_LUK);
  3511. clif_updatestatus(sd, SP_ATTACKRANGE);
  3512. clif_updatestatus(sd, SP_ASPD);
  3513. #ifdef RENEWAL
  3514. clif_updatestatus(sd, SP_POW);
  3515. clif_updatestatus(sd, SP_STA);
  3516. clif_updatestatus(sd, SP_WIS);
  3517. clif_updatestatus(sd, SP_SPL);
  3518. clif_updatestatus(sd, SP_CON);
  3519. clif_updatestatus(sd, SP_CRT);
  3520. clif_updatestatus(sd, SP_PATK);
  3521. clif_updatestatus(sd, SP_SMATK);
  3522. clif_updatestatus(sd, SP_RES);
  3523. clif_updatestatus(sd, SP_MRES);
  3524. clif_updatestatus(sd, SP_HPLUS);
  3525. clif_updatestatus(sd, SP_CRATE);
  3526. clif_updatestatus(sd, SP_TRAITPOINT);
  3527. clif_updatestatus(sd, SP_AP);
  3528. clif_updatestatus(sd, SP_MAXAP);
  3529. clif_updatestatus(sd, SP_UPOW);
  3530. clif_updatestatus(sd, SP_USTA);
  3531. clif_updatestatus(sd, SP_UWIS);
  3532. clif_updatestatus(sd, SP_USPL);
  3533. clif_updatestatus(sd, SP_UCON);
  3534. clif_updatestatus(sd, SP_UCRT);
  3535. #endif
  3536. }
  3537. /// Marks an ammunition item in inventory as equipped.
  3538. /// 013c <index>.W (ZC_EQUIP_ARROW)
  3539. void clif_arrowequip( map_session_data& sd ) {
  3540. #if PACKETVER >= 20121128
  3541. clif_status_change(&sd.bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3542. #endif
  3543. PACKET_ZC_EQUIP_ARROW packet{};
  3544. packet.packetType = HEADER_ZC_EQUIP_ARROW;
  3545. // Inventory index of the arrow
  3546. packet.index = client_index( sd.equip_index[EQI_AMMO] );
  3547. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3548. }
  3549. /// Ammunition action message.
  3550. /// 013b <type>.W (ZC_ACTION_FAILURE)
  3551. /// type:
  3552. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3553. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3554. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3555. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3556. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3557. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3558. void clif_arrow_fail( map_session_data& sd, e_action_failure type ) {
  3559. PACKET_ZC_ACTION_FAILURE packet{};
  3560. packet.packetType = HEADER_ZC_ACTION_FAILURE;
  3561. packet.type = static_cast<decltype(packet.type)>(type);
  3562. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3563. }
  3564. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3565. /// 01ad <packet len>.W { <name id>.W }*
  3566. void clif_arrow_create_list( map_session_data& sd ){
  3567. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  3568. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3569. p->packetLength = sizeof( *p );
  3570. int count = 0;
  3571. for (const auto &it : skill_arrow_db) {
  3572. t_itemid nameid = it.second->nameid;
  3573. if( !item_db.exists( nameid ) ){
  3574. continue;
  3575. }
  3576. int index = pc_search_inventory( &sd, nameid );
  3577. if( index < 0 ){
  3578. continue;
  3579. }
  3580. if( sd.inventory.u.items_inventory[index].equip ){
  3581. continue;
  3582. }
  3583. if( !sd.inventory.u.items_inventory[index].identify ){
  3584. continue;
  3585. }
  3586. p->items[count].itemId = client_nameid( nameid );
  3587. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  3588. count++;
  3589. }
  3590. clif_send( p, p->packetLength, &sd.bl, SELF );
  3591. if( count > 0 ){
  3592. sd.menuskill_id = AC_MAKINGARROW;
  3593. sd.menuskill_val = count;
  3594. }
  3595. }
  3596. /// Notifies the client, about the result of an status change request.
  3597. /// 00bc <status id>.W <result>.B <value>.B (ZC_STATUS_CHANGE_ACK)
  3598. /// status id:
  3599. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3600. /// result:
  3601. /// 0 = failure
  3602. /// 1 = success
  3603. void clif_statusupack( map_session_data& sd, int32 type, bool success, int32 val ) {
  3604. PACKET_ZC_STATUS_CHANGE_ACK packet{};
  3605. packet.packetType = HEADER_ZC_STATUS_CHANGE_ACK;
  3606. packet.sp = static_cast<decltype(packet.sp)>(type);
  3607. packet.ok = success;
  3608. packet.value = cap_value(val, 0, UINT8_MAX);
  3609. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3610. }
  3611. /// Notifies the client about the result of a request to equip an item.
  3612. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3613. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3614. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3615. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3616. /// @ok: //inversed forv2 v5
  3617. /// 0 = failure
  3618. /// 1 = success
  3619. /// 2 = failure due to low level
  3620. void clif_equipitemack( map_session_data& sd, uint8 flag, int index, int pos ){
  3621. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3622. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3623. p.index = client_index( index );
  3624. p.wearLocation = pos;
  3625. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3626. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3627. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3628. }else{
  3629. p.wItemSpriteNumber = 0;
  3630. }
  3631. #endif
  3632. p.result = flag;
  3633. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3634. }
  3635. /// Notifies the client about the result of a request to take off an item.
  3636. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3637. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3638. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3639. /// @ok : //inversed for v2 v5
  3640. /// 0 = failure
  3641. /// 1 = success
  3642. void clif_unequipitemack(map_session_data *sd,int n,int pos,int ok)
  3643. {
  3644. int fd, header, offs = 0;
  3645. #if PACKETVER >= 20130000
  3646. header = 0x99a;
  3647. ok = ok ? 0 : 1;
  3648. #elif PACKETVER >= 20110824
  3649. header = 0x8d1;
  3650. ok = ok ? 0 : 1;
  3651. #else
  3652. header = 0xac;
  3653. #endif
  3654. nullpo_retv(sd);
  3655. fd=sd->fd;
  3656. WFIFOHEAD(fd, packet_len(header));
  3657. WFIFOW(fd,offs+0) = header;
  3658. WFIFOW(fd,offs+2) = n+2;
  3659. #if PACKETVER >= 20130000
  3660. WFIFOL(fd,offs+4) = pos;
  3661. offs += 2;
  3662. #else
  3663. WFIFOW(fd,offs+4) = pos;
  3664. #endif
  3665. WFIFOB(fd,offs+6) = ok;
  3666. WFIFOSET(fd, packet_len(header));
  3667. }
  3668. /// Notifies clients in the area about an special/visual effect.
  3669. /// 019b <id>.L <effect id>.L (ZC_NOTIFY_EFFECT)
  3670. /// effect id:
  3671. /// 0 = base level up
  3672. /// 1 = job level up
  3673. /// 2 = refine failure
  3674. /// 3 = refine success
  3675. /// 4 = game over
  3676. /// 5 = pharmacy success
  3677. /// 6 = pharmacy failure
  3678. /// 7 = base level up (super novice)
  3679. /// 8 = job level up (super novice)
  3680. /// 9 = base level up (taekwon)
  3681. void clif_misceffect( block_list& bl, e_notify_effect type ){
  3682. PACKET_ZC_NOTIFY_EFFECT packet{};
  3683. packet.packetType = HEADER_ZC_NOTIFY_EFFECT;
  3684. packet.aid = bl.id;
  3685. packet.effectId = static_cast<decltype(packet.effectId)>(type);
  3686. clif_send( &packet, sizeof( packet ), &bl, AREA );
  3687. }
  3688. /// Notifies clients in the area of a state change.
  3689. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3690. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3691. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3692. nullpo_retv( bl );
  3693. status_change* sc = status_get_sc( bl );
  3694. //How can an option change if there's no sc?
  3695. if( sc == nullptr ){
  3696. return;
  3697. }
  3698. map_session_data* sd = BL_CAST( BL_PC, bl );
  3699. struct PACKET_ZC_STATE_CHANGE p;
  3700. p.packetType = HEADER_ZC_STATE_CHANGE;
  3701. p.AID = bl->id;
  3702. p.bodyState = sc->opt1;
  3703. p.healthState = sc->opt2;
  3704. p.effectState = sc->option;
  3705. p.isPKModeON = sd ? sd->status.karma : false;
  3706. if( target == nullptr ){
  3707. if( disguised( bl ) ){
  3708. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3709. p.AID = disguised_bl_id( p.AID );
  3710. clif_send( &p, sizeof( p ), bl, SELF );
  3711. p.AID = disguised_bl_id( p.AID );
  3712. p.effectState = OPTION_INVISIBLE;
  3713. clif_send( &p, sizeof( p ), bl, SELF );
  3714. }else{
  3715. clif_send( &p, sizeof( p ), bl, AREA );
  3716. }
  3717. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3718. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3719. if( sc->getSCE(SC_PROVOKE) ){
  3720. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3721. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3722. }
  3723. }else{
  3724. if( disguised( bl ) ){
  3725. p.AID = disguised_bl_id( p.AID );
  3726. clif_send( &p, sizeof( p ), target, SELF );
  3727. p.AID = disguised_bl_id( p.AID );
  3728. p.effectState = OPTION_INVISIBLE;
  3729. clif_send( &p, sizeof( p ), target, SELF );
  3730. }else{
  3731. clif_send( &p, sizeof( p ), target, SELF );
  3732. }
  3733. }
  3734. }
  3735. /// Displays status change effects on NPCs/monsters.
  3736. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L (ZC_NPC_SHOWEFST_UPDATE)
  3737. void clif_changeoption2( block_list& bl ){
  3738. status_change *sc = status_get_sc(&bl);
  3739. if (!sc)
  3740. return; //How can an option change if there's no sc?
  3741. PACKET_ZC_NPC_SHOWEFST_UPDATE packet{};
  3742. packet.packetType = HEADER_ZC_NPC_SHOWEFST_UPDATE;
  3743. packet.gid = bl.id;
  3744. packet.effectState = sc->option;
  3745. packet.level = clif_setlevel(&bl);
  3746. packet.showEFST = sc->opt3;
  3747. if (disguised(&bl)) {
  3748. clif_send( &packet, sizeof( packet ), &bl, AREA_WOS );
  3749. packet.gid = disguised_bl_id( bl.id );
  3750. clif_send( &packet, sizeof( packet ), &bl, SELF );
  3751. packet.gid = bl.id;
  3752. packet.effectState = OPTION_INVISIBLE;
  3753. clif_send( &packet, sizeof( packet ), &bl, SELF );
  3754. } else {
  3755. clif_send( &packet, sizeof( packet ), &bl, AREA );
  3756. }
  3757. }
  3758. /// Notifies the client about the result of an item use request.
  3759. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3760. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3761. void clif_useitemack( map_session_data *sd, int index, int amount, bool ok ){
  3762. nullpo_retv( sd );
  3763. int fd = sd->fd;
  3764. if( !session_isActive( fd ) ){
  3765. return;
  3766. }
  3767. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3768. return;
  3769. }
  3770. struct PACKET_ZC_USE_ITEM_ACK p;
  3771. p.packetType = useItemAckType;
  3772. p.index = index + 2;
  3773. #if PACKETVER > 3
  3774. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3775. p.AID = sd->bl.id;
  3776. #endif
  3777. p.amount = amount;
  3778. p.result = ok;
  3779. if( !ok ){
  3780. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3781. }else{
  3782. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3783. }
  3784. }
  3785. /// Inform client whether chatroom creation was successful or not.
  3786. /// 00d6 <flag>.B (ZC_ACK_CREATE_CHATROOM)
  3787. /// flag:
  3788. /// 0 = Room has been successfully created (opens chat room)
  3789. /// 1 = Room limit exceeded
  3790. /// 2 = Same room already exists
  3791. void clif_createchat( map_session_data& sd, e_create_chatroom flag ){
  3792. PACKET_ZC_ACK_CREATE_CHATROOM packet{};
  3793. packet.packetType = HEADER_ZC_ACK_CREATE_CHATROOM;
  3794. packet.flag = static_cast<decltype(packet.flag)>(flag);
  3795. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3796. }
  3797. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3798. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3799. /// type:
  3800. /// 0 = private (password protected)
  3801. /// 1 = public
  3802. /// 2 = arena (npc waiting room)
  3803. /// 3 = PK zone (non-clickable)
  3804. void clif_dispchat(struct chat_data* cd, int fd)
  3805. {
  3806. unsigned char buf[128];
  3807. uint8 type;
  3808. if( cd == nullptr || cd->owner == nullptr )
  3809. return;
  3810. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3811. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3812. : 1;
  3813. WBUFW(buf, 0) = 0xd7;
  3814. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3815. WBUFL(buf, 4) = cd->owner->id;
  3816. WBUFL(buf, 8) = cd->bl.id;
  3817. WBUFW(buf,12) = cd->limit;
  3818. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3819. WBUFB(buf,16) = type;
  3820. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3821. if( session_isActive(fd) ) {
  3822. WFIFOHEAD(fd,WBUFW(buf,2));
  3823. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3824. WFIFOSET(fd,WBUFW(buf,2));
  3825. } else {
  3826. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3827. }
  3828. }
  3829. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3830. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3831. /// type:
  3832. /// 0 = private (password protected)
  3833. /// 1 = public
  3834. /// 2 = arena (npc waiting room)
  3835. /// 3 = PK zone (non-clickable)
  3836. void clif_changechatstatus(struct chat_data* cd)
  3837. {
  3838. unsigned char buf[128];
  3839. uint8 type;
  3840. if( cd == nullptr || cd->usersd[0] == nullptr )
  3841. return;
  3842. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3843. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3844. : 1;
  3845. WBUFW(buf, 0) = 0xdf;
  3846. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3847. WBUFL(buf, 4) = cd->owner->id;
  3848. WBUFL(buf, 8) = cd->bl.id;
  3849. WBUFW(buf,12) = cd->limit;
  3850. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3851. WBUFB(buf,16) = type;
  3852. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3853. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3854. }
  3855. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3856. /// 00d8 <chat id>.L
  3857. void clif_clearchat(struct chat_data *cd,int fd)
  3858. {
  3859. unsigned char buf[32];
  3860. nullpo_retv(cd);
  3861. WBUFW(buf,0) = 0xd8;
  3862. WBUFL(buf,2) = cd->bl.id;
  3863. if( session_isActive(fd) ) {
  3864. WFIFOHEAD(fd,packet_len(0xd8));
  3865. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3866. WFIFOSET(fd,packet_len(0xd8));
  3867. } else {
  3868. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3869. }
  3870. }
  3871. /// Displays messages regarding join chat failures.
  3872. /// 00da <result>.B (ZC_REFUSE_ENTER_ROOM)
  3873. /// result:
  3874. /// 0 = room full
  3875. /// 1 = wrong password
  3876. /// 2 = kicked
  3877. /// 3 = success (no message)
  3878. /// 4 = no enough zeny
  3879. /// 5 = too low level
  3880. /// 6 = too high level
  3881. /// 7 = unsuitable job class
  3882. void clif_joinchatfail( map_session_data& sd, e_refuse_enter_room result ){
  3883. PACKET_ZC_REFUSE_ENTER_ROOM packet{};
  3884. packet.packetType = HEADER_ZC_REFUSE_ENTER_ROOM;
  3885. packet.result = static_cast<decltype(packet.result)>(result);
  3886. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3887. }
  3888. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3889. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3890. /// role:
  3891. /// 0 = owner (menu)
  3892. /// 1 = normal
  3893. void clif_joinchatok(map_session_data *sd,struct chat_data* cd)
  3894. {
  3895. int fd;
  3896. int i,t;
  3897. nullpo_retv(sd);
  3898. nullpo_retv(cd);
  3899. fd = sd->fd;
  3900. if (!session_isActive(fd))
  3901. return;
  3902. t = (int)(cd->owner->type == BL_NPC);
  3903. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3904. WFIFOW(fd, 0) = 0xdb;
  3905. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3906. WFIFOL(fd, 4) = cd->bl.id;
  3907. if(cd->owner->type == BL_NPC){
  3908. WFIFOL(fd, 30) = 1;
  3909. WFIFOL(fd, 8) = 0;
  3910. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3911. for (i = 0; i < cd->users; i++) {
  3912. WFIFOL(fd, 8+(i+1)*28) = 1;
  3913. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3914. }
  3915. }else{
  3916. for (i = 0; i < cd->users; i++) {
  3917. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3918. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3919. }
  3920. }
  3921. WFIFOSET(fd, WFIFOW(fd, 2));
  3922. }
  3923. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3924. /// 00dc <users>.W <name>.24B
  3925. void clif_addchat(struct chat_data* cd,map_session_data *sd)
  3926. {
  3927. unsigned char buf[29];
  3928. nullpo_retv(sd);
  3929. nullpo_retv(cd);
  3930. WBUFW(buf, 0) = 0xdc;
  3931. WBUFW(buf, 2) = cd->users;
  3932. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3933. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3934. }
  3935. /// Announce the new owner (ZC_ROLE_CHANGE).
  3936. /// 00e1 <role>.L <nick>.24B
  3937. /// role:
  3938. /// 0 = owner (menu)
  3939. /// 1 = normal
  3940. void clif_changechatowner(struct chat_data* cd, map_session_data* sd)
  3941. {
  3942. unsigned char buf[64];
  3943. nullpo_retv(sd);
  3944. nullpo_retv(cd);
  3945. WBUFW(buf, 0) = 0xe1;
  3946. WBUFL(buf, 2) = 1;
  3947. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3948. WBUFW(buf,30) = 0xe1;
  3949. WBUFL(buf,32) = 0;
  3950. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3951. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3952. }
  3953. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3954. /// 00dd <users>.W <nick>.24B <flag>.B
  3955. /// flag:
  3956. /// 0 = left
  3957. /// 1 = kicked
  3958. void clif_leavechat(struct chat_data* cd, map_session_data* sd, bool flag)
  3959. {
  3960. unsigned char buf[32];
  3961. nullpo_retv(sd);
  3962. nullpo_retv(cd);
  3963. WBUFW(buf, 0) = 0xdd;
  3964. WBUFW(buf, 2) = cd->users-1;
  3965. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3966. WBUFB(buf,28) = flag;
  3967. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3968. }
  3969. /// Opens a trade request window from char 'name'.
  3970. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3971. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3972. void clif_traderequest(map_session_data* sd, const char* name)
  3973. {
  3974. int fd = sd->fd;
  3975. #if PACKETVER < 6
  3976. WFIFOHEAD(fd,packet_len(0xe5));
  3977. WFIFOW(fd,0) = 0xe5;
  3978. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3979. WFIFOSET(fd,packet_len(0xe5));
  3980. #else
  3981. map_session_data* tsd = map_id2sd(sd->trade_partner);
  3982. if( !tsd ) return;
  3983. WFIFOHEAD(fd,packet_len(0x1f4));
  3984. WFIFOW(fd,0) = 0x1f4;
  3985. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3986. WFIFOL(fd,26) = tsd->status.char_id;
  3987. WFIFOW(fd,30) = tsd->status.base_level;
  3988. WFIFOSET(fd,packet_len(0x1f4));
  3989. #endif
  3990. }
  3991. /// Reply to a trade-request.
  3992. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3993. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3994. /// result:
  3995. /// 0 = Char is too far
  3996. /// 1 = Character does not exist
  3997. /// 2 = Trade failed
  3998. /// 3 = Accept
  3999. /// 4 = Cancel
  4000. /// 5 = Busy
  4001. void clif_tradestart(map_session_data* sd, uint8 type)
  4002. {
  4003. int fd = sd->fd;
  4004. map_session_data* tsd = map_id2sd(sd->trade_partner);
  4005. if( PACKETVER < 6 || !tsd ) {
  4006. WFIFOHEAD(fd,packet_len(0xe7));
  4007. WFIFOW(fd,0) = 0xe7;
  4008. WFIFOB(fd,2) = type;
  4009. WFIFOSET(fd,packet_len(0xe7));
  4010. } else {
  4011. WFIFOHEAD(fd,packet_len(0x1f5));
  4012. WFIFOW(fd,0) = 0x1f5;
  4013. WFIFOB(fd,2) = type;
  4014. WFIFOL(fd,3) = tsd->status.char_id;
  4015. WFIFOW(fd,7) = tsd->status.base_level;
  4016. WFIFOSET(fd,packet_len(0x1f5));
  4017. }
  4018. }
  4019. /// Notifies the client about an item from other player in current trade.
  4020. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4021. /// 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)
  4022. /// 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)
  4023. void clif_tradeadditem( map_session_data* sd, map_session_data* tsd, int index, int amount ){
  4024. nullpo_retv( sd );
  4025. nullpo_retv( tsd );
  4026. int fd = tsd->fd;
  4027. if( !session_isActive( fd ) ){
  4028. return;
  4029. }
  4030. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4031. if( index ){
  4032. index = server_index( index );
  4033. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4034. return;
  4035. }
  4036. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4037. #if PACKETVER >= 20100223
  4038. p.itemType = sd->inventory_data[index]->type;
  4039. #endif
  4040. p.identified = sd->inventory.u.items_inventory[index].identify;
  4041. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4042. p.refine = sd->inventory.u.items_inventory[index].refine;
  4043. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4044. #if PACKETVER >= 20150226
  4045. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[index] );
  4046. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4047. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4048. p.look = sd->inventory_data[index]->look;
  4049. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4050. #endif
  4051. #endif
  4052. }else{
  4053. p = {};
  4054. }
  4055. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4056. p.amount = amount;
  4057. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4058. }
  4059. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4060. /// 00ea <index>.W <result>.B
  4061. /// result:
  4062. /// 0 = success
  4063. /// 1 = overweight
  4064. /// 2 = trade canceled
  4065. void clif_tradeitemok(map_session_data& sd, int index, e_exitem_add_result result)
  4066. {
  4067. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4068. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4069. p.index = client_index(index);
  4070. p.result = static_cast<uint8>(result);
  4071. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4072. }
  4073. /// Notifies the client about finishing one side of the current trade.
  4074. /// 00ec <who>.B (ZC_CONCLUDE_EXCHANGE_ITEM)
  4075. /// who:
  4076. /// 0 = self
  4077. /// 1 = other player
  4078. void clif_tradedeal_lock( map_session_data& sd, bool who ){
  4079. PACKET_ZC_CONCLUDE_EXCHANGE_ITEM packet{};
  4080. packet.packetType = HEADER_ZC_CONCLUDE_EXCHANGE_ITEM;
  4081. packet.who = who;
  4082. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4083. }
  4084. /// Notifies the client about the trade being canceled.
  4085. /// 00ee (ZC_CANCEL_EXCHANGE_ITEM)
  4086. void clif_tradecancelled( map_session_data& sd ){
  4087. PACKET_ZC_CANCEL_EXCHANGE_ITEM packet{};
  4088. packet.packetType = HEADER_ZC_CANCEL_EXCHANGE_ITEM;
  4089. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4090. }
  4091. /// Result of a trade.
  4092. /// 00f0 <result>.B (ZC_EXEC_EXCHANGE_ITEM)
  4093. /// result:
  4094. /// 0 = success
  4095. /// 1 = failure
  4096. void clif_tradecompleted( map_session_data& sd ){
  4097. PACKET_ZC_EXEC_EXCHANGE_ITEM packet{};
  4098. packet.packetType = HEADER_ZC_EXEC_EXCHANGE_ITEM;
  4099. packet.result = 0;
  4100. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4101. }
  4102. /// Resets the trade window on the send side.
  4103. /// 00f1 (ZC_EXCHANGEITEM_UNDO)
  4104. /// NOTE: Unknown purpose. Items are not removed until the window is
  4105. /// refreshed (ex. by putting another item in there).
  4106. void clif_tradeundo( map_session_data& sd ){
  4107. PACKET_ZC_EXCHANGEITEM_UNDO packet{};
  4108. packet.packetType = HEADER_ZC_EXCHANGEITEM_UNDO;
  4109. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4110. }
  4111. /// Updates storage total amount.
  4112. /// 00f2 <current count>.W <max count>.W (ZC_NOTIFY_STOREITEM_COUNTINFO)
  4113. void clif_updatestorageamount( map_session_data& sd, uint16 amount, uint16 max_amount ){
  4114. PACKET_ZC_NOTIFY_STOREITEM_COUNTINFO packet{};
  4115. packet.packetType = HEADER_ZC_NOTIFY_STOREITEM_COUNTINFO;
  4116. packet.amount = amount;
  4117. packet.max_amount = max_amount;
  4118. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4119. }
  4120. /// Notifies the client of an item being added to the storage.
  4121. /// 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)
  4122. /// 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)
  4123. /// 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)
  4124. void clif_storageitemadded( map_session_data* sd, struct item* i, int index, int amount ){
  4125. nullpo_retv( sd );
  4126. nullpo_retv( i );
  4127. int fd = sd->fd;
  4128. if( !session_isActive( fd ) ){
  4129. return;
  4130. }
  4131. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4132. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4133. p.index = client_storage_index( index ); // index
  4134. p.amount = amount; // amount
  4135. p.itemId = client_nameid( i->nameid ); // id
  4136. #if PACKETVER >= 5
  4137. p.itemType = itemtype( i->nameid ); //type
  4138. #endif
  4139. p.identified = i->identify; //identify flag
  4140. p.damaged = i->attribute; // attribute
  4141. p.refine = i->refine; //refine
  4142. clif_addcards( &p.slot, i );
  4143. #if PACKETVER_MAIN_NUM >= 20140813 || PACKETVER_RE_NUM >= 20140402 || defined(PACKETVER_ZERO)
  4144. clif_add_random_options( p.option_data, *i );
  4145. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20221024
  4146. p.grade = i->enchantgrade;
  4147. #endif
  4148. #endif
  4149. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4150. }
  4151. /// Notifies the client of an item being deleted from the storage.
  4152. /// 00f6 <index>.W <amount>.L (ZC_DELETE_ITEM_FROM_STORE)
  4153. void clif_storageitemremoved( map_session_data& sd, uint16 index, uint32 amount ){
  4154. PACKET_ZC_DELETE_ITEM_FROM_STORE packet{};
  4155. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_STORE;
  4156. packet.index = client_storage_index(index);
  4157. packet.amount = amount;
  4158. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4159. }
  4160. /// Closes storage.
  4161. /// 00f8 (ZC_CLOSE_STORE)
  4162. void clif_storageclose( map_session_data& sd ){
  4163. PACKET_ZC_CLOSE_STORE packet{};
  4164. packet.packetType = HEADER_ZC_CLOSE_STORE;
  4165. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4166. }
  4167. /// Notifies clients in an area of a player's souls.
  4168. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4169. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4170. /// 0b73 <id>.L <amount>.W (ZC_SOULENERGY)
  4171. void clif_soulball( map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4172. #if PACKETVER_MAIN_NUM >= 20200414 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20200506
  4173. struct PACKET_ZC_SOULENERGY p = {};
  4174. p.PacketType = HEADER_ZC_SOULENERGY;
  4175. #else
  4176. struct PACKET_ZC_SPIRITS p = {};
  4177. p.PacketType = HEADER_ZC_SPIRITS;
  4178. #endif
  4179. p.AID = sd->bl.id;
  4180. p.num = sd->soulball;
  4181. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4182. }
  4183. /*==========================================
  4184. * Server tells 'sd' player client the abouts of 'dstsd' player
  4185. *------------------------------------------*/
  4186. static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
  4187. {
  4188. struct block_list *d_bl;
  4189. int i;
  4190. if( dstsd->chatID ) {
  4191. struct chat_data *cd = nullptr;
  4192. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4193. clif_dispchat(cd,sd->fd);
  4194. } else if( dstsd->state.vending )
  4195. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4196. else if( dstsd->state.buyingstore )
  4197. clif_buyingstore_entry( *dstsd, &sd->bl );
  4198. if(dstsd->spiritball > 0)
  4199. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4200. clif_millenniumshield_single( *dstsd, *sd );
  4201. clif_spiritcharm_single( *dstsd, *sd );
  4202. if (dstsd->soulball > 0)
  4203. clif_soulball( dstsd, &sd->bl, SELF );
  4204. if (dstsd->servantball > 0)
  4205. clif_servantball( *dstsd, &sd->bl, SELF );
  4206. if (dstsd->abyssball > 0)
  4207. clif_abyssball( *dstsd, &sd->bl, SELF );
  4208. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4209. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4210. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4211. )
  4212. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4213. // display link (sd - dstsd) to sd
  4214. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4215. if( i < MAX_DEVOTION )
  4216. clif_devotion(&sd->bl, sd);
  4217. // display links (dstsd - devotees) to sd
  4218. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4219. if( i < MAX_DEVOTION )
  4220. clif_devotion(&dstsd->bl, sd);
  4221. // display link (dstsd - crusader) to sd
  4222. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != nullptr )
  4223. clif_devotion(d_bl, sd);
  4224. }
  4225. void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
  4226. struct unit_data *ud;
  4227. struct view_data *vd;
  4228. bool option = false;
  4229. unsigned int option_val = 0;
  4230. vd = status_get_viewdata(bl);
  4231. if (!vd || vd->class_ == JT_INVISIBLE)
  4232. return;
  4233. // Hide NPC from Maya Purple card
  4234. if (clif_npc_mayapurple(bl))
  4235. return;
  4236. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4237. // Do not send anything
  4238. return;
  4239. }
  4240. ud = unit_bl2ud(bl);
  4241. if( ud && ud->walktimer != INVALID_TIMER ){
  4242. clif_set_unit_walking( bl, sd, ud, SELF );
  4243. }else{
  4244. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4245. }
  4246. if (vd->cloth_color)
  4247. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4248. if (vd->body_style)
  4249. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4250. switch (bl->type)
  4251. {
  4252. case BL_PC:
  4253. {
  4254. TBL_PC* tsd = (TBL_PC*)bl;
  4255. clif_getareachar_pc(sd, tsd);
  4256. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4257. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4258. else if(tsd->state.size==SZ_MEDIUM)
  4259. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4260. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4261. clif_sendbgemblem_single(sd->fd,tsd);
  4262. if ( tsd->status.robe )
  4263. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4264. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4265. clif_hat_effects( *sd, tsd->bl, SELF );
  4266. }
  4267. break;
  4268. case BL_MER: // Devotion Effects
  4269. if( ((TBL_MER*)bl)->devotion_flag )
  4270. clif_devotion(bl, sd);
  4271. break;
  4272. case BL_NPC:
  4273. {
  4274. TBL_NPC* nd = (TBL_NPC*)bl;
  4275. if( nd->chat_id )
  4276. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4277. if( nd->size == SZ_BIG )
  4278. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4279. else if( nd->size == SZ_MEDIUM )
  4280. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4281. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4282. clif_progressbar_npc(nd, sd);
  4283. }
  4284. break;
  4285. case BL_MOB:
  4286. {
  4287. TBL_MOB* md = (TBL_MOB*)bl;
  4288. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4289. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4290. else if(md->special_state.size==SZ_MEDIUM)
  4291. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4292. #if PACKETVER >= 20120404
  4293. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4294. int i;
  4295. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4296. if( md->dmglog[i].id == sd->status.char_id )
  4297. clif_monster_hp_bar(md, sd->fd);
  4298. }
  4299. #endif
  4300. }
  4301. break;
  4302. case BL_PET:
  4303. if (vd->head_bottom)
  4304. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4305. break;
  4306. }
  4307. }
  4308. //Modifies the type of damage according to status changes [Skotlex]
  4309. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4310. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4311. {
  4312. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4313. }
  4314. /*==========================================
  4315. * Estimates walk delay based on the damage criteria. [Skotlex]
  4316. *------------------------------------------*/
  4317. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4318. {
  4319. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4320. return 0;
  4321. if (bl->type == BL_PC) {
  4322. if (battle_config.pc_walk_delay_rate != 100)
  4323. delay = delay*battle_config.pc_walk_delay_rate/100;
  4324. } else
  4325. if (battle_config.walk_delay_rate != 100)
  4326. delay = delay*battle_config.walk_delay_rate/100;
  4327. if (div_ > 1) //Multi-hit skills mean higher delays.
  4328. delay += battle_config.multihit_delay*(div_-1);
  4329. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4330. }
  4331. /*========================================== [Playtester]
  4332. * Returns hallucination damage the client displays
  4333. *------------------------------------------*/
  4334. static int clif_hallucination_damage()
  4335. {
  4336. int digit = rnd() % 5 + 1;
  4337. switch (digit)
  4338. {
  4339. case 1:
  4340. return (rnd() % 10);
  4341. case 2:
  4342. return (rnd() % 100);
  4343. case 3:
  4344. return (rnd() % 1000);
  4345. case 4:
  4346. return (rnd() % 10000);
  4347. }
  4348. return (rnd() % 32767);
  4349. }
  4350. #define DEFAULT_ANIMATION_SPEED 432
  4351. /// Sends a 'damage' packet (src performs action on dst)
  4352. /// 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)
  4353. /// 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)
  4354. /// 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)
  4355. /// type:
  4356. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4357. /// 1 = pick up item
  4358. /// 2 = sit down
  4359. /// 3 = stand up
  4360. /// 4 = damage (endure)
  4361. /// 5 = (splash?)
  4362. /// 6 = (skill?)
  4363. /// 7 = (repeat damage?)
  4364. /// 8 = multi-hit damage
  4365. /// 9 = multi-hit damage (endure)
  4366. /// 10 = critical hit
  4367. /// 11 = lucky dodge
  4368. /// 12 = (touch skill?)
  4369. /// 13 = multi-hit critical
  4370. 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)
  4371. {
  4372. unsigned char buf[34];
  4373. status_change *sc;
  4374. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4375. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4376. #if PACKETVER < 20071113
  4377. const int cmd = 0x8a;
  4378. int offset = 0;
  4379. #elif PACKETVER < 20131223
  4380. const int cmd = 0x2e1;
  4381. int offset = 2;
  4382. #else
  4383. const int cmd = 0x8c8;
  4384. int offset = 3;
  4385. #endif
  4386. nullpo_ret(src);
  4387. nullpo_ret(dst);
  4388. if (type != DMG_MULTI_HIT_CRITICAL)
  4389. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4390. sc = status_get_sc(dst);
  4391. if(sc && sc->count) {
  4392. if(sc->getSCE(SC_HALLUCINATION)) {
  4393. damage = clif_hallucination_damage();
  4394. if(damage2) damage2 = clif_hallucination_damage();
  4395. }
  4396. }
  4397. // Calculate what sdelay to send to the client so it applies damage at the same time as the server
  4398. if (battle_config.synchronize_damage && src->type == BL_MOB) {
  4399. // When a clif_damage packet is sent to the client it will also send "sdelay" (amotion) as value.
  4400. // The client however does not interpret this value as AttackMotion but incorrectly as an inverted
  4401. // animation speed modifier, with 432 standing for 1x animation speed.
  4402. // The client will ignore all values above 432, but lower values will speed up the animation.
  4403. // 216 for example means play the animation at double the speed. 108 is quadruple speed.
  4404. // Each monster has an attack animation and may define the frame in the attack animation on which
  4405. // it displays the damage and makes the target flinch / stop. If the damage frame is undefined,
  4406. // it instead displays the damage / flinch / stop at the beginning of the second to last frame.
  4407. // We define the time after which the damage frame shows at 1x speed as clientamotion.
  4408. uint16 clientamotion = std::max((uint16)1, status_get_clientamotion(src));
  4409. // Knowing when the damage frame happens in the animation allows us to synchronize the timing
  4410. // between client and server using the formula below.
  4411. sdelay = sdelay * DEFAULT_ANIMATION_SPEED / clientamotion;
  4412. // Hint: If amotion is larger than clientamotion this results in a value above 432 which makes the
  4413. // client display the attack at 1x speed. In this case we need to shorten the delay damage timer
  4414. // on the server to clientamotion ms instead (see battle_delay_damage).
  4415. sdelay = std::min(sdelay, DEFAULT_ANIMATION_SPEED);
  4416. }
  4417. WBUFW(buf,0) = cmd;
  4418. WBUFL(buf,2) = src->id;
  4419. WBUFL(buf,6) = dst->id;
  4420. WBUFL(buf,10) = client_tick(tick);
  4421. WBUFL(buf,14) = sdelay;
  4422. WBUFL(buf,18) = ddelay;
  4423. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4424. #if PACKETVER < 20071113
  4425. WBUFW(buf,22) = damage ? div : 0;
  4426. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4427. #else
  4428. WBUFL(buf, 22) = damage ? div : 0;
  4429. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4430. #endif
  4431. } else {
  4432. #if PACKETVER < 20071113
  4433. WBUFW(buf,22) = min(damage, INT16_MAX);
  4434. WBUFW(buf,27+offset) = damage2;
  4435. #else
  4436. WBUFL(buf,22) = damage;
  4437. WBUFL(buf,27+offset) = damage2;
  4438. #endif
  4439. }
  4440. #if PACKETVER >= 20131223
  4441. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4442. #endif
  4443. WBUFW(buf,24+offset) = div;
  4444. WBUFB(buf,26+offset) = type;
  4445. if(disguised(dst)) {
  4446. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4447. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4448. clif_send(buf, packet_len(cmd), dst, SELF);
  4449. } else
  4450. clif_send(buf, packet_len(cmd), dst, AREA);
  4451. if(disguised(src)) {
  4452. WBUFL(buf,2) = disguised_bl_id( src->id );
  4453. if (disguised(dst))
  4454. WBUFL(buf,6) = dst->id;
  4455. #if PACKETVER < 20071113
  4456. if(damage > 0) WBUFW(buf,22) = -1;
  4457. if(damage2 > 0) WBUFW(buf,27) = -1;
  4458. #else
  4459. if(damage > 0) WBUFL(buf,22) = -1;
  4460. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4461. #endif
  4462. clif_send(buf,packet_len(cmd),src,SELF);
  4463. }
  4464. if(src == dst) {
  4465. unit_setdir(src, unit_getdir(src));
  4466. }
  4467. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4468. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4469. //Return adjusted can't walk delay for further processing.
  4470. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4471. }
  4472. /*==========================================
  4473. * src picks up dst
  4474. *------------------------------------------*/
  4475. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4476. {
  4477. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4478. unsigned char buf[32];
  4479. nullpo_retv(src);
  4480. nullpo_retv(dst);
  4481. WBUFW(buf, 0) = 0x8a;
  4482. WBUFL(buf, 2) = src->id;
  4483. WBUFL(buf, 6) = dst->id;
  4484. WBUFB(buf,26) = 1;
  4485. clif_send(buf, packet_len(0x8a), src, AREA);
  4486. }
  4487. /*==========================================
  4488. * inform clients in area that `bl` is sitting
  4489. *------------------------------------------*/
  4490. void clif_sitting(struct block_list* bl)
  4491. {
  4492. unsigned char buf[32];
  4493. nullpo_retv(bl);
  4494. WBUFW(buf, 0) = 0x8a;
  4495. WBUFL(buf, 2) = bl->id;
  4496. WBUFB(buf,26) = 2;
  4497. clif_send(buf, packet_len(0x8a), bl, AREA);
  4498. if(disguised(bl)) {
  4499. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4500. clif_send(buf, packet_len(0x8a), bl, SELF);
  4501. }
  4502. }
  4503. /*==========================================
  4504. * inform clients in area that `bl` is standing
  4505. *------------------------------------------*/
  4506. void clif_standing(struct block_list* bl)
  4507. {
  4508. unsigned char buf[32];
  4509. nullpo_retv(bl);
  4510. WBUFW(buf, 0) = 0x8a;
  4511. WBUFL(buf, 2) = bl->id;
  4512. WBUFB(buf,26) = 3;
  4513. clif_send(buf, packet_len(0x8a), bl, AREA);
  4514. if(disguised(bl)) {
  4515. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4516. clif_send(buf, packet_len(0x8a), bl, SELF);
  4517. }
  4518. }
  4519. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4520. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4521. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4522. {
  4523. unsigned char buf[32];
  4524. WBUFW(buf,0) = 0x192;
  4525. WBUFW(buf,2) = x;
  4526. WBUFW(buf,4) = y;
  4527. WBUFW(buf,6) = type;
  4528. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4529. if( session_isActive(fd) )
  4530. {
  4531. WFIFOHEAD(fd,packet_len(0x192));
  4532. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4533. WFIFOSET(fd,packet_len(0x192));
  4534. }
  4535. else
  4536. {
  4537. struct block_list dummy_bl;
  4538. dummy_bl.type = BL_NUL;
  4539. dummy_bl.x = x;
  4540. dummy_bl.y = y;
  4541. dummy_bl.m = m;
  4542. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4543. }
  4544. }
  4545. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4546. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4547. void clif_getareachar_item( map_session_data* sd,struct flooritem_data* fitem ){
  4548. nullpo_retv( sd );
  4549. nullpo_retv( fitem );
  4550. struct PACKET_ZC_ITEM_ENTRY p;
  4551. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4552. p.AID = fitem->bl.id;
  4553. p.itemId = client_nameid( fitem->item.nameid );
  4554. p.identify = fitem->item.identify;
  4555. p.x = fitem->bl.x;
  4556. p.y = fitem->bl.y;
  4557. p.amount = fitem->item.amount;
  4558. p.subX = fitem->subx;
  4559. p.subY = fitem->suby;
  4560. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4561. }
  4562. /// Notifes client about Graffiti
  4563. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4564. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4565. unsigned char buf[128];
  4566. nullpo_retv(bl);
  4567. nullpo_retv(unit);
  4568. WBUFW(buf, 0) = 0x1c9;
  4569. WBUFL(buf, 2) = unit->bl.id;
  4570. WBUFL(buf, 6) = unit->group->src_id;
  4571. WBUFW(buf,10) = unit->bl.x;
  4572. WBUFW(buf,12) = unit->bl.y;
  4573. WBUFB(buf,14) = unit->group->unit_id;
  4574. WBUFB(buf,15) = 1;
  4575. WBUFB(buf,16) = 1;
  4576. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4577. clif_send(buf,packet_len(0x1c9),bl,target);
  4578. }
  4579. /// Notifies the client of a skill unit.
  4580. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4581. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4582. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4583. /// 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)
  4584. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4585. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4586. unsigned char buf[128];
  4587. nullpo_retv(bl);
  4588. nullpo_retv(unit);
  4589. if (bl->type == BL_PC)
  4590. fd = ((TBL_PC*)bl)->fd;
  4591. if (unit->group->state.guildaura)
  4592. return;
  4593. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4594. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4595. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4596. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4597. else
  4598. unit_id = unit->group->unit_id;
  4599. if (!visible)
  4600. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4601. #if PACKETVER >= 3
  4602. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4603. clif_graffiti(bl, unit, target);
  4604. return;
  4605. }
  4606. #endif
  4607. #if PACKETVER <= 20120702
  4608. header = 0x011f;
  4609. //#if PACKETVER < 20110718
  4610. // header = 0x011f;
  4611. //#elif PACKETVER < 20121212
  4612. // header = 0x08c7;
  4613. #elif PACKETVER < 20130731
  4614. header = 0x099f;
  4615. #else
  4616. header = 0x09ca;
  4617. #endif
  4618. len = packet_len(header);
  4619. WBUFW(buf,pos) = header;
  4620. if (header != 0x011f) {
  4621. WBUFW(buf, pos+2) = len;
  4622. pos += 2;
  4623. }
  4624. WBUFL(buf,pos+2) = unit->bl.id;
  4625. WBUFL(buf,pos+6) = unit->group->src_id;
  4626. WBUFW(buf,pos+10) = unit->bl.x;
  4627. WBUFW(buf,pos+12) = unit->bl.y;
  4628. switch (header) {
  4629. case 0x011f:
  4630. WBUFB(buf,pos+14) = unit_id;
  4631. WBUFB(buf,pos+15) = visible;
  4632. break;
  4633. case 0x08c7:
  4634. WBUFB(buf,pos+14) = unit_id;
  4635. WBUFW(buf,pos+15) = unit->range;
  4636. WBUFB(buf,pos+17) = visible;
  4637. break;
  4638. case 0x099f:
  4639. WBUFL(buf,pos+14) = unit_id;
  4640. WBUFW(buf,pos+18) = unit->range;
  4641. WBUFB(buf,pos+20) = visible;
  4642. break;
  4643. case 0x09ca:
  4644. WBUFL(buf,pos+14) = unit_id;
  4645. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4646. WBUFB(buf,pos+19) = visible;
  4647. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4648. break;
  4649. }
  4650. clif_send(buf, len, bl, target);
  4651. if (unit->group->skill_id == WZ_ICEWALL)
  4652. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4653. }
  4654. /// 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)
  4655. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4656. unsigned char buf[128];
  4657. nullpo_retv(bl);
  4658. WBUFW(buf, 0) = 0x09ca;
  4659. WBUFW(buf, 2) = packet_len(0x09ca);
  4660. WBUFL(buf, 4) = 1000;
  4661. WBUFL(buf, 8) = 2000;
  4662. WBUFW(buf, 12) = x;
  4663. WBUFW(buf, 14) = y;
  4664. WBUFL(buf, 16) = unit_id;
  4665. WBUFB(buf, 20) = (unsigned char)range;
  4666. WBUFB(buf, 21) = 1;
  4667. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4668. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4669. }
  4670. /// Server tells client to remove unit of id 'unit->bl.id'
  4671. /// 0120 <id>.L (ZC_SKILL_DISAPPEAR)
  4672. static void clif_clearchar_skillunit( skill_unit& unit, map_session_data& sd ){
  4673. PACKET_ZC_SKILL_DISAPPEAR packet{};
  4674. packet.packetType = HEADER_ZC_SKILL_DISAPPEAR;
  4675. packet.GID = unit.bl.id;
  4676. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4677. if( unit.group && unit.group->skill_id == WZ_ICEWALL ){
  4678. clif_changemapcell( sd.fd, unit.bl.m, unit.bl.x, unit.bl.y, unit.val2, SELF );
  4679. }
  4680. }
  4681. /// Removes a skill unit.
  4682. /// 0120 <id>.L (ZC_SKILL_DISAPPEAR)
  4683. void clif_skill_delunit( skill_unit& unit ){
  4684. PACKET_ZC_SKILL_DISAPPEAR packet{};
  4685. packet.packetType = HEADER_ZC_SKILL_DISAPPEAR;
  4686. packet.GID = unit.bl.id;
  4687. clif_send( &packet, sizeof( packet ), &unit.bl, AREA );
  4688. }
  4689. /// Sent when an object gets ankle-snared.
  4690. /// 01ac <id>.L (ZC_SKILL_UPDATE)
  4691. /// Only affects units with class [139,153] client-side.
  4692. void clif_skillunit_update( block_list& bl ){
  4693. PACKET_ZC_SKILL_UPDATE packet{};
  4694. packet.packetType = HEADER_ZC_SKILL_UPDATE;
  4695. packet.GID = bl.id;
  4696. clif_send( &packet, sizeof( packet ), &bl, AREA );
  4697. }
  4698. /*==========================================
  4699. *
  4700. *------------------------------------------*/
  4701. static int clif_getareachar(struct block_list* bl,va_list ap)
  4702. {
  4703. map_session_data *sd;
  4704. nullpo_ret(bl);
  4705. sd=va_arg(ap,map_session_data*);
  4706. if (!clif_session_isValid(sd))
  4707. return 0;
  4708. switch(bl->type){
  4709. case BL_ITEM:
  4710. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4711. break;
  4712. case BL_SKILL:
  4713. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4714. break;
  4715. default:
  4716. if(&sd->bl == bl)
  4717. break;
  4718. clif_getareachar_unit(sd,bl);
  4719. break;
  4720. }
  4721. return 0;
  4722. }
  4723. /*==========================================
  4724. * tbl has gone out of view-size of bl
  4725. *------------------------------------------*/
  4726. int clif_outsight(struct block_list *bl,va_list ap)
  4727. {
  4728. struct block_list *tbl;
  4729. struct view_data *vd;
  4730. TBL_PC *sd, *tsd;
  4731. tbl=va_arg(ap,struct block_list*);
  4732. if(bl == tbl) return 0;
  4733. sd = BL_CAST(BL_PC, bl);
  4734. tsd = BL_CAST(BL_PC, tbl);
  4735. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4736. nullpo_ret(bl);
  4737. switch(bl->type){
  4738. case BL_PC:
  4739. if(sd->vd.class_ != JT_INVISIBLE)
  4740. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4741. if(sd->chatID){
  4742. struct chat_data *cd;
  4743. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4744. if(cd->usersd[0]==sd)
  4745. clif_dispchat(cd,tsd->fd);
  4746. }
  4747. if(sd->state.vending)
  4748. clif_closevendingboard(bl,tsd->fd);
  4749. if(sd->state.buyingstore)
  4750. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4751. break;
  4752. case BL_ITEM:
  4753. clif_clearflooritem( *reinterpret_cast<flooritem_data*>( bl ), tsd );
  4754. break;
  4755. case BL_SKILL:
  4756. clif_clearchar_skillunit( *((skill_unit *)bl), *tsd );
  4757. break;
  4758. case BL_NPC:
  4759. if(!(((TBL_NPC*)bl)->is_invisible))
  4760. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4761. break;
  4762. default:
  4763. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4764. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4765. break;
  4766. }
  4767. }
  4768. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4769. nullpo_ret(tbl);
  4770. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4771. clif_clearchar_skillunit( *((skill_unit *)tbl), *sd );
  4772. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4773. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->is_invisible)))
  4774. clif_clearunit_single( tbl->id, CLR_OUTSIGHT, *sd );
  4775. }
  4776. return 0;
  4777. }
  4778. /*==========================================
  4779. * tbl has come into view of bl
  4780. *------------------------------------------*/
  4781. int clif_insight(struct block_list *bl,va_list ap)
  4782. {
  4783. struct block_list *tbl;
  4784. TBL_PC *sd, *tsd;
  4785. tbl=va_arg(ap,struct block_list*);
  4786. if (bl == tbl) return 0;
  4787. sd = BL_CAST(BL_PC, bl);
  4788. tsd = BL_CAST(BL_PC, tbl);
  4789. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4790. switch(bl->type){
  4791. case BL_ITEM:
  4792. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4793. break;
  4794. case BL_SKILL:
  4795. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4796. break;
  4797. default:
  4798. clif_getareachar_unit(tsd,bl);
  4799. break;
  4800. }
  4801. }
  4802. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4803. clif_getareachar_unit(sd,tbl);
  4804. }
  4805. return 0;
  4806. }
  4807. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4808. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4809. void clif_skillinfoblock(map_session_data *sd)
  4810. {
  4811. int fd;
  4812. int i,len,id;
  4813. nullpo_retv(sd);
  4814. fd = sd->fd;
  4815. if (!session_isActive(fd))
  4816. return;
  4817. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4818. WFIFOW(fd,0) = 0x10f;
  4819. bool haveCallPartnerSkill = false;
  4820. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4821. {
  4822. if( (id = sd->status.skill[i].id) != 0 )
  4823. {
  4824. // workaround for bugreport:5348
  4825. if (len + 37 > 8192)
  4826. break;
  4827. // skip WE_CALLPARTNER and send it in special way
  4828. if (id == WE_CALLPARTNER) {
  4829. haveCallPartnerSkill = true;
  4830. continue;
  4831. }
  4832. WFIFOW(fd,len) = id;
  4833. WFIFOL(fd,len+2) = skill_get_inf(id);
  4834. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4835. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4836. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4837. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4838. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4839. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4840. else
  4841. WFIFOB(fd,len+36) = 0;
  4842. len += 37;
  4843. }
  4844. }
  4845. WFIFOW(fd,2)=len;
  4846. WFIFOSET(fd,len);
  4847. // adoption fix
  4848. if (haveCallPartnerSkill) {
  4849. clif_addskill(sd, WE_CALLPARTNER);
  4850. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4851. }
  4852. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4853. for ( ; i < MAX_SKILL; i++)
  4854. {
  4855. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4856. {
  4857. clif_addskill(sd, id);
  4858. clif_skillinfo(sd, id, 0);
  4859. }
  4860. }
  4861. }
  4862. /**
  4863. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4864. **/
  4865. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4866. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4867. void clif_addskill(map_session_data *sd, int skill_id)
  4868. {
  4869. nullpo_retv(sd);
  4870. int fd = sd->fd;
  4871. uint16 idx = skill_get_index(skill_id);
  4872. if (!session_isActive(fd) || !idx)
  4873. return;
  4874. if( sd->status.skill[idx].id <= 0 )
  4875. return;
  4876. WFIFOHEAD(fd, packet_len(0x111));
  4877. WFIFOW(fd,0) = 0x111;
  4878. WFIFOW(fd,2) = skill_id;
  4879. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4880. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4881. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4882. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4883. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4884. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4885. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4886. else
  4887. WFIFOB(fd,38) = 0;
  4888. WFIFOSET(fd,packet_len(0x111));
  4889. }
  4890. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4891. /// 0441 <skill id>.W
  4892. void clif_deleteskill(map_session_data *sd, int skill_id, bool skip_infoblock)
  4893. {
  4894. #if PACKETVER >= 20081217
  4895. nullpo_retv(sd);
  4896. int fd = sd->fd;
  4897. uint16 idx = skill_get_index(skill_id);
  4898. if (!session_isActive(fd) || !idx)
  4899. return;
  4900. WFIFOHEAD(fd,packet_len(0x441));
  4901. WFIFOW(fd,0) = 0x441;
  4902. WFIFOW(fd,2) = skill_id;
  4903. WFIFOSET(fd,packet_len(0x441));
  4904. #endif
  4905. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4906. if (!skip_infoblock)
  4907. #endif
  4908. clif_skillinfoblock(sd);
  4909. }
  4910. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4911. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4912. void clif_skillup(map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4913. nullpo_retv(sd);
  4914. int fd = sd->fd;
  4915. uint16 idx = skill_get_index(skill_id);
  4916. if (!session_isActive(fd) || !idx)
  4917. return;
  4918. WFIFOHEAD(fd, packet_len(0x10e));
  4919. WFIFOW(fd, 0) = 0x10e;
  4920. WFIFOW(fd, 2) = skill_id;
  4921. WFIFOW(fd, 4) = lv;
  4922. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4923. WFIFOW(fd, 8) = range;
  4924. WFIFOB(fd, 10) = upgradable;
  4925. WFIFOSET(fd, packet_len(0x10e));
  4926. }
  4927. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4928. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4929. void clif_skillinfo(map_session_data *sd,int skill_id, int inf)
  4930. {
  4931. nullpo_retv(sd);
  4932. const int fd = sd->fd;
  4933. uint16 idx = skill_get_index(skill_id);
  4934. if (!session_isActive(fd) || !idx)
  4935. return;
  4936. WFIFOHEAD(fd,packet_len(0x7e1));
  4937. WFIFOW(fd,0) = 0x7e1;
  4938. WFIFOW(fd,2) = skill_id;
  4939. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4940. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4941. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4942. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4943. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4944. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4945. else
  4946. WFIFOB(fd,14) = 0;
  4947. WFIFOSET(fd,packet_len(0x7e1));
  4948. }
  4949. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4950. #if PACKETVER >= 20151223
  4951. if( !battle_config.show_skill_scale ){
  4952. return;
  4953. }
  4954. struct PACKET_ZC_SKILL_SCALE p;
  4955. p.PacketType = skillscale;
  4956. p.AID = src_id;
  4957. p.skill_id = skill_id;
  4958. p.skill_lv = skill_lv;
  4959. p.x = x;
  4960. p.y = y;
  4961. p.casttime = casttime;
  4962. if( disguised( bl ) ){
  4963. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4964. p.AID = disguised_bl_id( bl->id );
  4965. clif_send( &p, sizeof( p ), bl, SELF );
  4966. }else{
  4967. clif_send( &p, sizeof( p ), bl, AREA );
  4968. }
  4969. #endif
  4970. }
  4971. /// Notifies clients in area, that an object is about to use a skill.
  4972. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4973. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4974. /// property:
  4975. /// 0 = Yellow cast aura
  4976. /// 1 = Water elemental cast aura
  4977. /// 2 = Earth elemental cast aura
  4978. /// 3 = Fire elemental cast aura
  4979. /// 4 = Wind elemental cast aura
  4980. /// 5 = Poison elemental cast aura
  4981. /// 6 = Holy elemental cast aura
  4982. /// ? = like 0
  4983. /// is disposable:
  4984. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4985. /// 1 = no text
  4986. 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)
  4987. {
  4988. #if PACKETVER < 20091124
  4989. const int cmd = 0x13e;
  4990. #else
  4991. const int cmd = 0x7fb;
  4992. #endif
  4993. unsigned char buf[32];
  4994. WBUFW(buf,0) = cmd;
  4995. WBUFL(buf,2) = src_id;
  4996. WBUFL(buf,6) = dst_id;
  4997. WBUFW(buf,10) = dst_x;
  4998. WBUFW(buf,12) = dst_y;
  4999. WBUFW(buf,14) = skill_id;
  5000. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5001. WBUFL(buf,20) = casttime;
  5002. #if PACKETVER >= 20091124
  5003. WBUFB(buf,24) = 0; // isDisposable
  5004. #endif
  5005. if (disguised(bl)) {
  5006. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5007. WBUFL(buf,2) = disguised_bl_id( src_id );
  5008. clif_send(buf,packet_len(cmd), bl, SELF);
  5009. } else
  5010. clif_send(buf,packet_len(cmd), bl, AREA);
  5011. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5012. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5013. }
  5014. }
  5015. /// Notifies clients in area, that an object canceled casting.
  5016. /// 01b9 <id>.L (ZC_DISPEL)
  5017. void clif_skillcastcancel( block_list& bl ){
  5018. PACKET_ZC_DISPEL packet{};
  5019. packet.packetType = HEADER_ZC_DISPEL;
  5020. packet.gid = bl.id;
  5021. clif_send( &packet, sizeof(PACKET_ZC_DISPEL), &bl, AREA );
  5022. }
  5023. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5024. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5025. /// num (only used when skill id = NV_BASIC and cause = 0):
  5026. /// 0 = "skill failed" MsgStringTable[159]
  5027. /// 1 = "no emotions" MsgStringTable[160]
  5028. /// 2 = "no sit" MsgStringTable[161]
  5029. /// 3 = "no chat" MsgStringTable[162]
  5030. /// 4 = "no party" MsgStringTable[163]
  5031. /// 5 = "no shout" MsgStringTable[164]
  5032. /// 6 = "no PKing" MsgStringTable[165]
  5033. /// 7 = "no alligning" MsgStringTable[383]
  5034. /// ? = ignored
  5035. /// cause:
  5036. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5037. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5038. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5039. /// "skill failed" MsgStringTable[204] (otherwise)
  5040. /// ... = @see enum useskill_fail_cause
  5041. /// ? = ignored
  5042. ///
  5043. /// if(result!=0) doesn't display any of the previous messages
  5044. /// Note: when this packet is received an unknown flag is always set to 0,
  5045. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5046. void clif_skill_fail( map_session_data& sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5047. if(battle_config.display_skill_fail&1)
  5048. return; //Disable all skill failed messages
  5049. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd.state.showdelay)
  5050. return; //Disable delay failed messages
  5051. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5052. return;
  5053. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5054. return;
  5055. struct PACKET_ZC_ACK_TOUSESKILL p;
  5056. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5057. p.skillId = skill_id;
  5058. p.btype = btype;
  5059. p.itemId = itemId;
  5060. p.flag = 0; // 0 - failed
  5061. p.cause = cause;
  5062. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  5063. }
  5064. /// Skill cooldown display icon.
  5065. /// 043d <skill ID>.W <tick>.L (ZC_SKILL_POSTDELAY)
  5066. void clif_skill_cooldown( map_session_data &sd, uint16 skill_id, t_tick tick ){
  5067. #if PACKETVER_MAIN_NUM >= 20081112 || PACKETVER_RE_NUM >= 20081111 || defined(PACKETVER_ZERO)
  5068. PACKET_ZC_SKILL_POSTDELAY packet{};
  5069. packet.PacketType = HEADER_ZC_SKILL_POSTDELAY;
  5070. packet.SKID = skill_id;
  5071. packet.DelayTM = client_tick(tick);
  5072. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5073. #endif
  5074. }
  5075. /// Skill attack effect and damage.
  5076. /// 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)
  5077. /// 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)
  5078. 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)
  5079. {
  5080. unsigned char buf[64];
  5081. status_change *sc;
  5082. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5083. nullpo_ret(src);
  5084. nullpo_ret(dst);
  5085. type = clif_calc_delay(type,div,damage,ddelay);
  5086. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5087. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5088. damage = clif_hallucination_damage();
  5089. }
  5090. #if PACKETVER < 3
  5091. WBUFW(buf,0)=0x114;
  5092. WBUFW(buf,2)=skill_id;
  5093. WBUFL(buf,4)=src->id;
  5094. WBUFL(buf,8)=dst->id;
  5095. WBUFL(buf,12)=client_tick(tick);
  5096. WBUFL(buf,16)=sdelay;
  5097. WBUFL(buf,20)=ddelay;
  5098. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5099. WBUFW(buf,24)=damage?div:0;
  5100. } else {
  5101. WBUFW(buf,24)=damage;
  5102. }
  5103. WBUFW(buf,26)=skill_lv;
  5104. WBUFW(buf,28)=div;
  5105. WBUFB(buf,30)=type;
  5106. if (disguised(dst)) {
  5107. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5108. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5109. clif_send(buf,packet_len(0x114),dst,SELF);
  5110. } else
  5111. clif_send(buf,packet_len(0x114),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. WBUFW(buf,24)=-1;
  5118. clif_send(buf,packet_len(0x114),src,SELF);
  5119. }
  5120. #else
  5121. WBUFW(buf,0)=0x1de;
  5122. WBUFW(buf,2)=skill_id;
  5123. WBUFL(buf,4)=src->id;
  5124. WBUFL(buf,8)=dst->id;
  5125. WBUFL(buf,12)=client_tick(tick);
  5126. WBUFL(buf,16)=sdelay;
  5127. WBUFL(buf,20)=ddelay;
  5128. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5129. WBUFL(buf,24)=damage?div:0;
  5130. } else {
  5131. WBUFL(buf,24)=damage;
  5132. }
  5133. WBUFW(buf,28)=skill_lv;
  5134. WBUFW(buf,30)=div;
  5135. // For some reason, late 2013 and newer clients have
  5136. // a issue that causes players and monsters to endure
  5137. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5138. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5139. #if PACKETVER < 20131223
  5140. WBUFB(buf,32)=type;
  5141. #else
  5142. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5143. #endif
  5144. if (disguised(dst)) {
  5145. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5146. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5147. clif_send(buf,packet_len(0x1de),dst,SELF);
  5148. } else
  5149. clif_send(buf,packet_len(0x1de),dst,AREA);
  5150. if(disguised(src)) {
  5151. WBUFL(buf,4)=disguised_bl_id(src->id);
  5152. if (disguised(dst))
  5153. WBUFL(buf,8)=dst->id;
  5154. if(damage > 0)
  5155. WBUFL(buf,24)=-1;
  5156. clif_send(buf,packet_len(0x1de),src,SELF);
  5157. }
  5158. #endif
  5159. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5160. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5161. }
  5162. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5163. /// 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
  5164. /*
  5165. 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)
  5166. {
  5167. unsigned char buf[64];
  5168. status_change *sc;
  5169. nullpo_ret(src);
  5170. nullpo_ret(dst);
  5171. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5172. type = clif_calc_delay(type,div,damage,ddelay);
  5173. sc = status_get_sc(dst);
  5174. if(sc && sc->count) {
  5175. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5176. damage = clif_hallucination_damage();
  5177. }
  5178. WBUFW(buf,0)=0x115;
  5179. WBUFW(buf,2)=skill_id;
  5180. WBUFL(buf,4)=src->id;
  5181. WBUFL(buf,8)=dst->id;
  5182. WBUFL(buf,12)=client_tick(tick);
  5183. WBUFL(buf,16)=sdelay;
  5184. WBUFL(buf,20)=ddelay;
  5185. WBUFW(buf,24)=dst->x;
  5186. WBUFW(buf,26)=dst->y;
  5187. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5188. WBUFW(buf,28)=damage?div:0;
  5189. } else {
  5190. WBUFW(buf,28)=damage;
  5191. }
  5192. WBUFW(buf,30)=skill_lv;
  5193. WBUFW(buf,32)=div;
  5194. WBUFB(buf,34)=type;
  5195. clif_send(buf,packet_len(0x115),src,AREA);
  5196. if(disguised(src)) {
  5197. WBUFL(buf,4)=disguised_bl_id(src->id);
  5198. if(damage > 0)
  5199. WBUFW(buf,28)=-1;
  5200. clif_send(buf,packet_len(0x115),src,SELF);
  5201. }
  5202. if (disguised(dst)) {
  5203. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5204. if (disguised(src))
  5205. WBUFL(buf,4)=src->id;
  5206. else if(damage > 0)
  5207. WBUFW(buf,28)=-1;
  5208. clif_send(buf,packet_len(0x115),dst,SELF);
  5209. }
  5210. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5211. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5212. }
  5213. */
  5214. /// Non-damaging skill effect
  5215. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5216. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5217. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5218. {
  5219. unsigned char buf[17];
  5220. #if PACKETVER < 20130731
  5221. const int cmd = 0x11a;
  5222. #else
  5223. const int cmd = 0x9cb;
  5224. #endif
  5225. int offset = 0;
  5226. bool success = ( tick != 0 );
  5227. nullpo_ret(dst);
  5228. WBUFW(buf,0) = cmd;
  5229. WBUFW(buf,2) = skill_id;
  5230. #if PACKETVER < 20130731
  5231. WBUFW(buf,4) = min(heal, INT16_MAX);
  5232. #else
  5233. WBUFL(buf,4) = min(heal, INT32_MAX);
  5234. offset += 2;
  5235. #endif
  5236. WBUFL(buf,6+offset) = dst->id;
  5237. WBUFL(buf,10+offset) = src ? src->id : 0;
  5238. WBUFB(buf,14+offset) = success;
  5239. if (disguised(dst)) {
  5240. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5241. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5242. clif_send(buf, packet_len(cmd), dst, SELF);
  5243. } else
  5244. clif_send(buf, packet_len(cmd), dst, AREA);
  5245. if(src && disguised(src)) {
  5246. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5247. if (disguised(dst))
  5248. WBUFL(buf,6+offset) = dst->id;
  5249. clif_send(buf, packet_len(cmd), src, SELF);
  5250. }
  5251. return success;
  5252. }
  5253. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5254. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5255. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5256. {
  5257. unsigned char buf[32];
  5258. nullpo_retv(src);
  5259. WBUFW(buf,0)=0x117;
  5260. WBUFW(buf,2)=skill_id;
  5261. WBUFL(buf,4)=src->id;
  5262. WBUFW(buf,8)=val;
  5263. WBUFW(buf,10)=x;
  5264. WBUFW(buf,12)=y;
  5265. WBUFL(buf,14)=client_tick(tick);
  5266. if(disguised(src)) {
  5267. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5268. WBUFL(buf,4)=disguised_bl_id(src->id);
  5269. clif_send(buf,packet_len(0x117),src,SELF);
  5270. } else
  5271. clif_send(buf,packet_len(0x117),src,AREA);
  5272. }
  5273. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5274. /// 011c <skill id>.W { <map name>.16B }*4
  5275. 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 ){
  5276. int fd;
  5277. nullpo_retv(sd);
  5278. fd = sd->fd;
  5279. WFIFOHEAD(fd,packet_len(0x11c));
  5280. WFIFOW(fd,0) = 0x11c;
  5281. WFIFOW(fd,2) = skill_id;
  5282. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5283. if( strcmp( "", map1 ) != 0 ){
  5284. mapindex_getmapname_ext( map1, WFIFOCP( fd, 4 ) );
  5285. }
  5286. if( strcmp( "", map2 ) != 0 ){
  5287. mapindex_getmapname_ext( map2, WFIFOCP( fd, 20 ) );
  5288. }
  5289. if( strcmp( "", map3 ) != 0 ){
  5290. mapindex_getmapname_ext( map3, WFIFOCP( fd, 36 ) );
  5291. }
  5292. if( strcmp( "", map4 ) != 0 ){
  5293. mapindex_getmapname_ext( map4, WFIFOCP( fd, 52 ) );
  5294. }
  5295. WFIFOSET(fd,packet_len(0x11c));
  5296. sd->menuskill_id = skill_id;
  5297. if (skill_id == AL_WARP) {
  5298. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5299. sd->state.workinprogress = WIP_DISABLE_ALL;
  5300. } else
  5301. sd->menuskill_val = skill_lv;
  5302. }
  5303. /// Memo message.
  5304. /// 011e <type>.B (ZC_ACK_REMEMBER_WARPPOINT)
  5305. /// type:
  5306. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5307. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5308. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5309. ///
  5310. /// @param sd Who receives the message
  5311. /// @param type What message
  5312. void clif_skill_memomessage( map_session_data& sd, e_ack_remember_warppoint_result result ){
  5313. PACKET_ZC_ACK_REMEMBER_WARPPOINT packet{};
  5314. packet.packetType = HEADER_ZC_ACK_REMEMBER_WARPPOINT;
  5315. packet.type = static_cast<decltype(packet.type)>(result);
  5316. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5317. }
  5318. /// Teleport message.
  5319. /// 0189 <type>.W (ZC_NOTIFY_MAPINFO)
  5320. /// type:
  5321. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5322. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5323. /// 2 = "This skill cannot be used in this area"
  5324. /// 3 = "This item cannot be used in this area"
  5325. ///
  5326. /// @param sd Who receives the message
  5327. /// @param type What message
  5328. void clif_skill_teleportmessage( map_session_data& sd, e_notify_mapinfo_result result ){
  5329. PACKET_ZC_NOTIFY_MAPINFO packet{};
  5330. packet.packetType = HEADER_ZC_NOTIFY_MAPINFO;
  5331. packet.type = static_cast<decltype(packet.type)>(result);
  5332. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5333. }
  5334. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5335. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5336. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5337. void clif_skill_estimation(map_session_data *sd,struct block_list *dst)
  5338. {
  5339. struct status_data *status;
  5340. unsigned char buf[64];
  5341. int i, fix;
  5342. nullpo_retv(sd);
  5343. nullpo_retv(dst);
  5344. if( dst->type != BL_MOB )
  5345. return;
  5346. status = status_get_status_data(dst);
  5347. WBUFW(buf, 0)=0x18c;
  5348. WBUFW(buf, 2)=status_get_class(dst);
  5349. WBUFW(buf, 4)=status_get_lv(dst);
  5350. WBUFW(buf, 6)=status->size;
  5351. WBUFL(buf, 8)=status->hp;
  5352. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5353. +(battle_config.estimation_type&2?status->def2:0);
  5354. WBUFW(buf,14)=status->race;
  5355. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5356. +(battle_config.estimation_type&2?status->mdef2:0);
  5357. WBUFW(buf,18)= status->def_ele;
  5358. for(i=0;i<9;i++)
  5359. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5360. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5361. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5362. }
  5363. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5364. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5365. /// material id:
  5366. /// unused by the client
  5367. void clif_skill_produce_mix_list( map_session_data *sd, int skill_id, int trigger ){
  5368. nullpo_retv(sd);
  5369. int fd = sd->fd;
  5370. if( !session_isActive( fd ) ){
  5371. return;
  5372. }
  5373. if (sd->menuskill_id == skill_id)
  5374. return; //Avoid resending the menu twice or more times...
  5375. if (skill_id == GC_CREATENEWPOISON)
  5376. skill_id = GC_RESEARCHNEWPOISON;
  5377. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5378. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5379. p->packetType = 0x18d;
  5380. int count = 0;
  5381. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5382. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5383. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5384. )
  5385. {
  5386. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5387. p->items[count].material[0] = 0;
  5388. p->items[count].material[1] = 0;
  5389. p->items[count].material[2] = 0;
  5390. count++;
  5391. }
  5392. }
  5393. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5394. WFIFOSET( fd, p->packetLength );
  5395. if( count > 0 ){
  5396. sd->menuskill_id = skill_id;
  5397. sd->menuskill_val = trigger;
  5398. return;
  5399. }
  5400. }
  5401. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5402. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5403. /// mk type:
  5404. /// 1 = cooking
  5405. /// 2 = arrow
  5406. /// 3 = elemental
  5407. /// 4 = GN_MIX_COOKING
  5408. /// 5 = GN_MAKEBOMB
  5409. /// 6 = GN_S_PHARMACY
  5410. /// 7 = MT_M_MACHINE - Unconfirmed
  5411. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5412. void clif_cooking_list( map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5413. nullpo_retv( sd );
  5414. // Avoid resending the menu twice or more times...
  5415. if( sd->menuskill_id == skill_id ){
  5416. return;
  5417. }
  5418. int fd = sd->fd;
  5419. if( !session_isActive( fd ) ){
  5420. return;
  5421. }
  5422. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5423. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5424. p->packetType = 0x25a;
  5425. p->makeItem = list_type; // list type
  5426. int count = 0;
  5427. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5428. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5429. continue;
  5430. }
  5431. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5432. count++;
  5433. }
  5434. if( count > 0 || skill_id == AM_PHARMACY ){
  5435. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5436. WFIFOSET( fd, p->packetLength );
  5437. sd->menuskill_id = skill_id;
  5438. sd->menuskill_val = trigger;
  5439. sd->menuskill_val2 = qty; // amount.
  5440. }else{
  5441. clif_menuskill_clear(sd);
  5442. #if PACKETVER >= 20090922
  5443. clif_msg_skill( sd, skill_id, MSI_SKILL_INVENTORY_KINDCNT_OVER);
  5444. #else
  5445. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5446. WFIFOSET( fd, p->packetLength );
  5447. #endif
  5448. }
  5449. }
  5450. /// Notifies clients of a status change.
  5451. /// 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)]
  5452. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5453. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5454. /// @param bl Sends packet to clients around this object
  5455. /// @param id ID of object that has this effect
  5456. /// @param type Status icon see enum efst_type
  5457. /// @param flag 1:Active, 0:Deactive
  5458. /// @param tick Duration in ms
  5459. /// @param val1
  5460. /// @param val2
  5461. /// @param val3
  5462. 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)
  5463. {
  5464. unsigned char buf[32];
  5465. if (type == EFST_BLANK) //It shows nothing on the client...
  5466. return;
  5467. if (type == EFST_POSTDELAY && tick == 0)
  5468. return;
  5469. nullpo_retv(bl);
  5470. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5471. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5472. tick = 200;
  5473. #if PACKETVER >= 20120618
  5474. if (flag && battle_config.display_status_timers)
  5475. WBUFW(buf,0) = 0x983;
  5476. else
  5477. #elif PACKETVER >= 20090121
  5478. if (flag && battle_config.display_status_timers)
  5479. WBUFW(buf,0) = 0x43f;
  5480. else
  5481. #endif
  5482. WBUFW(buf,0) = 0x196;
  5483. WBUFW(buf,2) = type;
  5484. WBUFL(buf,4) = id;
  5485. WBUFB(buf,8) = flag;
  5486. #if PACKETVER >= 20120618
  5487. if (flag && battle_config.display_status_timers) {
  5488. if (tick <= 0)
  5489. tick = 9999; // this is indeed what official servers do
  5490. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5491. WBUFL(buf,13) = client_tick(tick);
  5492. WBUFL(buf,17) = val1;
  5493. WBUFL(buf,21) = val2;
  5494. WBUFL(buf,25) = val3;
  5495. }
  5496. #elif PACKETVER >= 20090121
  5497. if (flag && battle_config.display_status_timers) {
  5498. if (tick <= 0)
  5499. tick = 9999; // this is indeed what official servers do
  5500. WBUFL(buf,9) = client_tick(tick);
  5501. WBUFL(buf,13) = val1;
  5502. WBUFL(buf,17) = val2;
  5503. WBUFL(buf,21) = val3;
  5504. }
  5505. #endif
  5506. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5507. }
  5508. /* Sends status effect to clients around the bl
  5509. * @param bl Object that has the effect
  5510. * @param type Status icon see enum efst_type
  5511. * @param flag 1:Active, 0:Deactive
  5512. * @param tick Duration in ms
  5513. * @param val1
  5514. * @param val2
  5515. * @param val3
  5516. */
  5517. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5518. map_session_data *sd = nullptr;
  5519. if (type == EFST_BLANK) //It shows nothing on the client...
  5520. return;
  5521. if (type == EFST_POSTDELAY && tick == 0)
  5522. return;
  5523. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5524. return;
  5525. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5526. // Older clients display normal riding icon.
  5527. if (type == EFST_MADOGEAR)
  5528. type = EFST_RIDING;
  5529. #endif
  5530. nullpo_retv(bl);
  5531. sd = BL_CAST(BL_PC, bl);
  5532. // Check if current bl type is in the returned bitmask and only send status changes that actually matter to the client
  5533. if (!(status_efst_get_bl_type(static_cast<efst_type>(type)) & bl->type))
  5534. return;
  5535. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5536. }
  5537. /**
  5538. * Send any active EFST to those around.
  5539. * @param tbl: Unit to send the packet to
  5540. * @param bl: Objects walking into view
  5541. * @param target: Client send type
  5542. */
  5543. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5544. unsigned char i;
  5545. struct sc_display_entry **sc_display;
  5546. unsigned char sc_display_count;
  5547. bool spheres_sent;
  5548. nullpo_retv(bl);
  5549. switch( bl->type ){
  5550. case BL_PC: {
  5551. map_session_data* sd = (map_session_data*)bl;
  5552. sc_display = sd->sc_display;
  5553. sc_display_count = sd->sc_display_count;
  5554. spheres_sent = !sd->state.connect_new;
  5555. }
  5556. break;
  5557. case BL_NPC: {
  5558. struct npc_data* nd = (struct npc_data*)bl;
  5559. sc_display = nd->sc_display;
  5560. sc_display_count = nd->sc_display_count;
  5561. spheres_sent = true;
  5562. }
  5563. break;
  5564. default:
  5565. return;
  5566. }
  5567. for (i = 0; i < sc_display_count; i++) {
  5568. enum sc_type type = sc_display[i]->type;
  5569. status_change *sc = status_get_sc(bl);
  5570. const struct TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : nullptr);
  5571. t_tick tick = 0;
  5572. if (td)
  5573. tick = DIFF_TICK(td->tick, gettick());
  5574. // Status changes that need special handling
  5575. switch( type ){
  5576. case SC_SPHERE_1:
  5577. case SC_SPHERE_2:
  5578. case SC_SPHERE_3:
  5579. case SC_SPHERE_4:
  5580. case SC_SPHERE_5:
  5581. if( spheres_sent ){
  5582. target = AREA_WOS;
  5583. }
  5584. break;
  5585. case SC_HELLS_PLANT:
  5586. if( sc && sc->getSCE(type) ){
  5587. tick = sc->getSCE(type)->val4;
  5588. }
  5589. break;
  5590. }
  5591. #if PACKETVER > 20120418
  5592. 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);
  5593. #else
  5594. 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);
  5595. #endif
  5596. }
  5597. }
  5598. /// Notifies the client when a player enters the screen with an active EFST.
  5599. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5600. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5601. 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) {
  5602. #if PACKETVER >= 20111108
  5603. unsigned char buf[32];
  5604. #if PACKETVER >= 20120618
  5605. const int cmd = 0x984;
  5606. #elif PACKETVER >= 20111108
  5607. const int cmd = 0x8ff;
  5608. #endif
  5609. int offset = 0;
  5610. if (type == EFST_BLANK)
  5611. return;
  5612. nullpo_retv(bl);
  5613. if (tick <= 0)
  5614. tick = 9999;
  5615. WBUFW(buf,offset + 0) = cmd;
  5616. WBUFL(buf,offset + 2) = tid;
  5617. WBUFW(buf,offset + 6) = type;
  5618. #if PACKETVER >= 20111108
  5619. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5620. #if PACKETVER >= 20120618
  5621. WBUFL(buf,offset + 12) = client_tick(tick);
  5622. offset += 4;
  5623. #endif
  5624. WBUFL(buf,offset + 12) = val1;
  5625. WBUFL(buf,offset + 16) = val2;
  5626. WBUFL(buf,offset + 20) = val3;
  5627. #endif
  5628. clif_send(buf,packet_len(cmd),bl,target);
  5629. #endif
  5630. }
  5631. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5632. /// 008e <packet len>.W <message>.?B
  5633. void clif_displaymessage(const int fd, const char* mes)
  5634. {
  5635. nullpo_retv(mes);
  5636. if( session_isActive( fd ) ){
  5637. char *message, *line;
  5638. message = aStrdup(mes);
  5639. line = strtok(message, "\n");
  5640. while(line != nullptr) {
  5641. #if PACKETVER == 20141022
  5642. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5643. /** so we redirect to ZC_NPC_CHAT **/
  5644. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5645. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5646. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5647. if (len > 0) {
  5648. WFIFOHEAD(fd, 13 + len);
  5649. WFIFOW(fd, 0) = 0x2C1;
  5650. WFIFOW(fd, 2) = 13 + len;
  5651. WFIFOL(fd, 4) = 0;
  5652. WFIFOL(fd, 8) = color;
  5653. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5654. WFIFOSET(fd, WFIFOW(fd, 2));
  5655. }
  5656. #else
  5657. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5658. int16 len;
  5659. len = static_cast<decltype(len)>( strnlen(line, CHAT_SIZE_MAX) );
  5660. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5661. WFIFOHEAD(fd, 5 + len);
  5662. WFIFOW(fd,0) = 0x8e;
  5663. WFIFOW(fd,2) = 5 + len; // 4 + len + nullptr teminate
  5664. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5665. WFIFOSET(fd, 5 + len);
  5666. }
  5667. #endif
  5668. line = strtok(nullptr, "\n");
  5669. }
  5670. aFree(message);
  5671. }
  5672. }
  5673. /// Send broadcast message in yellow or blue without font formatting.
  5674. /// 009a <packet len>.W <message>.?B (ZC_BROADCAST)
  5675. void clif_broadcast(struct block_list* bl, const char* mes, size_t len, int type, enum send_target target)
  5676. {
  5677. nullpo_retv(mes);
  5678. if (len < 2)
  5679. return;
  5680. PACKET_ZC_BROADCAST* p = reinterpret_cast<PACKET_ZC_BROADCAST*>( packet_buffer );
  5681. p->packetType = HEADER_ZC_BROADCAST;
  5682. p->PacketLength = sizeof( *p );
  5683. if( ( type&BC_BLUE ) != 0 ){
  5684. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5685. const char* color = "blue";
  5686. size_t length = strlen( color );
  5687. strcpy( p->message, color );
  5688. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  5689. strncpy( &p->message[length], mes, len );
  5690. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5691. }else if( ( type&BC_WOE ) != 0 ){
  5692. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5693. const char* color = "ssss";
  5694. size_t length = strlen( color );
  5695. strcpy( p->message, color );
  5696. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  5697. strncpy( &p->message[length], mes, len );
  5698. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5699. }else{
  5700. strncpy( p->message, mes, len );
  5701. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5702. }
  5703. clif_send( p, p->PacketLength, bl, target );
  5704. }
  5705. /*==========================================
  5706. * Displays a message on a 'bl' to all it's nearby clients
  5707. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5708. *------------------------------------------*/
  5709. void clif_GlobalMessage( block_list& bl, const char* message, enum send_target target ){
  5710. nullpo_retv(message);
  5711. int16 len = (int16)( strlen( message ) + 1 );
  5712. if( len > CHAT_SIZE_MAX ) {
  5713. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5714. len = CHAT_SIZE_MAX;
  5715. }
  5716. PACKET_ZC_NOTIFY_CHAT* p = reinterpret_cast<PACKET_ZC_NOTIFY_CHAT*>( packet_buffer );
  5717. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5718. p->PacketLength = sizeof( *p );
  5719. p->GID = bl.id;
  5720. safestrncpy( p->Message, message, len );
  5721. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5722. clif_send( p, p->PacketLength, &bl, target );
  5723. }
  5724. /// Send broadcast message with font formatting.
  5725. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5726. 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)
  5727. {
  5728. nullpo_retv(mes);
  5729. if (len < 2)
  5730. return;
  5731. PACKET_ZC_BROADCAST2* p = reinterpret_cast<PACKET_ZC_BROADCAST2*>( packet_buffer );
  5732. p->packetType = HEADER_ZC_BROADCAST2;
  5733. p->PacketLength = sizeof( *p );
  5734. p->fontColor = fontColor;
  5735. p->fontType = fontType;
  5736. p->fontSize = fontSize;
  5737. p->fontAlign = fontAlign;
  5738. p->fontY = fontY;
  5739. strncpy( p->message, mes, len );
  5740. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5741. clif_send( p, p->PacketLength, bl, target );
  5742. }
  5743. /*
  5744. * Display *msg to all *users in channel
  5745. */
  5746. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5747. DBIterator *iter;
  5748. map_session_data *user;
  5749. unsigned short msg_len = 0, len = 0;
  5750. unsigned char buf[CHAT_SIZE_MAX];
  5751. if (!channel || !msg)
  5752. return;
  5753. msg_len = (unsigned short)(strlen(msg) + 1);
  5754. if( msg_len > sizeof(buf)-12 ) {
  5755. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5756. msg_len = sizeof(buf)-12;
  5757. }
  5758. WBUFW(buf,0) = 0x2C1;
  5759. WBUFW(buf,2) = (len = msg_len + 12);
  5760. WBUFL(buf,4) = 0;
  5761. WBUFL(buf,8) = color;
  5762. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5763. iter = db_iterator(channel->users);
  5764. for( user = (map_session_data *)dbi_first(iter); dbi_exists(iter); user = (map_session_data *)dbi_next(iter) ) {
  5765. clif_send(buf, len, &user->bl, SELF);
  5766. }
  5767. dbi_destroy(iter);
  5768. }
  5769. /// Displays heal effect.
  5770. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5771. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5772. /// var id:
  5773. /// 5 = HP (SP_HP)
  5774. /// 7 = SP (SP_SP)
  5775. /// ? = ignored
  5776. void clif_heal( map_session_data& sd, int32 type, uint32 val ) {
  5777. PACKET_ZC_RECOVERY packet{};
  5778. packet.packetType = HEADER_ZC_RECOVERY;
  5779. packet.type = static_cast<decltype(packet.type)>(type);
  5780. packet.amount = std::min( static_cast<decltype(packet.amount)>( val ), std::numeric_limits<decltype(packet.amount)>::max() );
  5781. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5782. }
  5783. /// Displays resurrection effect.
  5784. /// 0148 <id>.L <type>.W (ZC_RESURRECTION)
  5785. /// type:
  5786. /// ignored
  5787. void clif_resurrection( block_list& bl ){
  5788. PACKET_ZC_RESURRECTION packet{};
  5789. packet.packetType = HEADER_ZC_RESURRECTION;
  5790. packet.gid = bl.id;
  5791. packet.type = 0;
  5792. clif_send( &packet, sizeof( packet ), &bl, AREA );
  5793. if (disguised(&bl)) {
  5794. clif_spawn(&bl);
  5795. }
  5796. }
  5797. /// Sets the map property
  5798. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5799. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5800. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5801. {
  5802. #if PACKETVER >= 20121010
  5803. short cmd = 0x99b;
  5804. unsigned char buf[8];
  5805. #else
  5806. short cmd = 0x199;
  5807. unsigned char buf[4];
  5808. #endif
  5809. WBUFW(buf,0)=cmd;
  5810. WBUFW(buf,2)=property;
  5811. #if PACKETVER >= 20121010
  5812. struct map_data *mapdata = map_getmapdata(bl->m);
  5813. map_session_data *sd = BL_CAST(BL_PC, bl);
  5814. WBUFL(buf,4) = ((mapdata->getMapFlag(MF_PVP) || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5815. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5816. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5817. ((mapdata->getMapFlag(MF_FORCEMINEFFECT) || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5818. ((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
  5819. ((mapdata->getMapFlag(MF_PVP))<<5)| // COUNT_PK - Show the PvP counter
  5820. ((mapdata->getMapFlag(MF_PARTYLOCK))<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5821. ((mapdata->getMapFlag(MF_BATTLEGROUND))<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5822. ((mapdata->getMapFlag(MF_NOCOSTUME))<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5823. ((!mapdata->getMapFlag(MF_NOUSECART))<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5824. ((!mapdata->getMapFlag(MF_NOSUNMOONSTARMIRACLE))<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5825. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5826. #endif
  5827. clif_send(buf,packet_len(cmd),bl,t);
  5828. }
  5829. /// Set the map type.
  5830. /// 01d6 <type>.W (ZC_NOTIFY_MAPPROPERTY2)
  5831. void clif_map_type( map_session_data& sd, e_map_type type ){
  5832. PACKET_ZC_NOTIFY_MAPPROPERTY2 packet{};
  5833. packet.packetType = HEADER_ZC_NOTIFY_MAPPROPERTY2;
  5834. packet.type = static_cast<decltype(packet.type)>(type);
  5835. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5836. }
  5837. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5838. /// 019a <id>.L <ranking>.L <total>.L
  5839. void clif_pvpset(map_session_data *sd,int pvprank,int pvpnum,int type)
  5840. {
  5841. if(type == 2) {
  5842. int fd = sd->fd;
  5843. WFIFOHEAD(fd,packet_len(0x19a));
  5844. WFIFOW(fd,0) = 0x19a;
  5845. WFIFOL(fd,2) = sd->bl.id;
  5846. WFIFOL(fd,6) = pvprank;
  5847. WFIFOL(fd,10) = pvpnum;
  5848. WFIFOSET(fd,packet_len(0x19a));
  5849. } else {
  5850. unsigned char buf[32];
  5851. WBUFW(buf,0) = 0x19a;
  5852. WBUFL(buf,2) = sd->bl.id;
  5853. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5854. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5855. else
  5856. WBUFL(buf,6) = pvprank;
  5857. WBUFL(buf,10) = pvpnum;
  5858. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5859. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5860. else if(!type)
  5861. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5862. else
  5863. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5864. }
  5865. }
  5866. /*==========================================
  5867. *
  5868. *------------------------------------------*/
  5869. void clif_map_property_mapall(int map_idx, enum map_property property)
  5870. {
  5871. struct block_list bl;
  5872. bl.id = 0;
  5873. bl.type = BL_NUL;
  5874. bl.m = map_idx;
  5875. clif_map_property( &bl, property, ALL_SAMEMAP );
  5876. }
  5877. /// Notifies the client about the result of a refine attempt.
  5878. /// 0188 <result>.W <index>.W <refine>.W (ZC_ACK_ITEMREFINING)
  5879. /// result:
  5880. /// 0 = success
  5881. /// 1 = failure
  5882. /// 2 = downgrade
  5883. /// 3 = failure (?)
  5884. void clif_refine( map_session_data& sd, uint16 index, e_ack_itemrefining result ){
  5885. PACKET_ZC_ACK_ITEMREFINING packet{};
  5886. packet.packetType = HEADER_ZC_ACK_ITEMREFINING;
  5887. packet.result = static_cast<decltype(packet.result)>(result);
  5888. packet.index = client_index( index );
  5889. packet.value = static_cast<decltype(packet.value)>( sd.inventory.u.items_inventory[index].refine );
  5890. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5891. }
  5892. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5893. /// 0223 <result>.L <nameid>.W
  5894. /// result:
  5895. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5896. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5897. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5898. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5899. void clif_upgrademessage( map_session_data* sd, int result, t_itemid item_id ){
  5900. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5901. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5902. p.result = result;
  5903. p.itemId = client_nameid( item_id );
  5904. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5905. }
  5906. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5907. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5908. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5909. void clif_wis_message(map_session_data* sd, const char* nick, const char* mes, size_t mes_len, int gmlvl){
  5910. PACKET_ZC_WHISPER* p = reinterpret_cast<PACKET_ZC_WHISPER*>( packet_buffer );
  5911. p->PacketType = HEADER_ZC_WHISPER;
  5912. p->PacketLength = sizeof( *p );
  5913. safestrncpy( p->sender, nick, NAME_LENGTH );
  5914. safestrncpy( p->message, mes, mes_len );
  5915. p->PacketLength += static_cast<decltype( p->PacketLength )>( mes_len );
  5916. #if PACKETVER >= 20091104
  5917. map_session_data* ssd = map_nick2sd(nick, false);
  5918. // If it is not a message from the server or a player from another map-server
  5919. if( ssd != nullptr ){
  5920. gmlvl = pc_get_group_level(ssd);
  5921. }
  5922. p->isAdmin = (gmlvl == 99) ? 1 : 0;
  5923. #if PACKETVER_MAIN_NUM >= 20131204 || PACKETVER_RE_NUM >= 20131120 || defined(PACKETVER_ZERO)
  5924. if( ssd != nullptr ){
  5925. p->senderGID = ssd->bl.id;
  5926. }else{
  5927. p->senderGID = 0;
  5928. }
  5929. #endif
  5930. #endif
  5931. clif_send( p, p->PacketLength, &sd->bl, SELF );
  5932. }
  5933. /// Inform the player about the result of his whisper action
  5934. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5935. /// 09df <result>.B <CID>.L (ZC_ACK_WHISPER02).
  5936. /// result:
  5937. /// 0 = success to send whisper
  5938. /// 1 = target character is not loged in
  5939. /// 2 = ignored by target
  5940. /// 3 = everyone ignored by target
  5941. void clif_wis_end( map_session_data& sd, e_ack_whisper result ){
  5942. PACKET_ZC_ACK_WHISPER packet{};
  5943. packet.packetType = HEADER_ZC_ACK_WHISPER;
  5944. packet.result = static_cast<decltype(packet.result)>(result);
  5945. #if PACKETVER >= 20131223
  5946. packet.CID = sd.status.char_id;
  5947. #endif
  5948. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5949. }
  5950. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5951. /// 0194 <char id>.L <name>.24B
  5952. /// 0af7 <flag>.W <char id>.L <name>.24B
  5953. void clif_solved_charname(int fd, int charid, const char* name)
  5954. {
  5955. #if PACKETVER >= 20180221
  5956. WFIFOHEAD(fd,packet_len(0xaf7));
  5957. WFIFOW(fd,0) = 0xaf7;
  5958. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5959. WFIFOL(fd,4) = charid;
  5960. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5961. WFIFOSET(fd,packet_len(0x0af7));
  5962. #else
  5963. WFIFOHEAD(fd,packet_len(0x194));
  5964. WFIFOW(fd,0)=0x194;
  5965. WFIFOL(fd,2)=charid;
  5966. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5967. WFIFOSET(fd,packet_len(0x194));
  5968. #endif
  5969. }
  5970. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5971. /// 017b <packet len>.W { <name id>.W }*
  5972. void clif_use_card(map_session_data *sd,int idx)
  5973. {
  5974. int i,c,ep;
  5975. int fd=sd->fd;
  5976. nullpo_retv(sd);
  5977. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5978. return;
  5979. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5980. return; //Avoid parsing invalid item indexes (no card/no item)
  5981. ep=sd->inventory_data[idx]->equip;
  5982. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5983. WFIFOW(fd,0)=0x17b;
  5984. for(i=c=0;i<MAX_INVENTORY;i++){
  5985. int j;
  5986. if(sd->inventory_data[i] == nullptr)
  5987. continue;
  5988. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5989. continue;
  5990. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5991. continue;
  5992. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5993. continue;
  5994. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5995. continue;
  5996. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5997. continue;
  5998. 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.
  5999. continue;
  6000. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6001. if( j == sd->inventory_data[i]->slots ) // No room
  6002. continue;
  6003. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6004. continue;
  6005. WFIFOW(fd,4+c*2)=i+2;
  6006. c++;
  6007. }
  6008. if( !c ) return; // no item is available for card insertion
  6009. WFIFOW(fd,2)=4+c*2;
  6010. WFIFOSET(fd,WFIFOW(fd,2));
  6011. }
  6012. /// Notifies the client about the result of item carding/composition.
  6013. /// 017d <equip index>.W <card index>.W <result>.B (ZC_ACK_ITEMCOMPOSITION)
  6014. /// result:
  6015. /// 0 = success
  6016. /// 1 = failure
  6017. void clif_insert_card( map_session_data& sd, int32 idx_equip, int32 idx_card, bool failure ){
  6018. PACKET_ZC_ACK_ITEMCOMPOSITION packet{};
  6019. packet.packetType = HEADER_ZC_ACK_ITEMCOMPOSITION;
  6020. packet.equipIndex = client_index( idx_equip );
  6021. packet.cardIndex = client_index( idx_card );
  6022. packet.result = failure;
  6023. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6024. }
  6025. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6026. /// 0177 <packet len>.W { <index>.W }*
  6027. void clif_item_identify_list(map_session_data *sd)
  6028. {
  6029. int i,c;
  6030. int fd;
  6031. nullpo_retv(sd);
  6032. fd=sd->fd;
  6033. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6034. WFIFOW(fd,0)=0x177;
  6035. for(i=c=0;i<MAX_INVENTORY;i++){
  6036. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6037. WFIFOW(fd,c*2+4)=client_index(i);
  6038. c++;
  6039. }
  6040. }
  6041. if(c > 0) {
  6042. WFIFOW(fd,2)=c*2+4;
  6043. WFIFOSET(fd,WFIFOW(fd,2));
  6044. sd->menuskill_id = MC_IDENTIFY;
  6045. sd->menuskill_val = c;
  6046. sd->state.workinprogress = WIP_DISABLE_ALL;
  6047. }
  6048. }
  6049. /// Notifies the client about the result of a item identify request.
  6050. /// 0179 <index>.W <result>.B (ZC_ACK_ITEMIDENTIFY)
  6051. /// result:
  6052. /// 0 = success
  6053. /// 1 = failure
  6054. void clif_item_identified( map_session_data& sd, int32 idx, bool failure ){
  6055. PACKET_ZC_ACK_ITEMIDENTIFY packet{};
  6056. packet.packetType = HEADER_ZC_ACK_ITEMIDENTIFY;
  6057. packet.index = client_index( idx );
  6058. packet.result = failure;
  6059. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6060. }
  6061. /// Presents a list of items that can be repaired.
  6062. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6063. void clif_item_repair_list( map_session_data& sd, map_session_data& dstsd, uint16 lv ){
  6064. PACKET_ZC_REPAIRITEMLIST* p = reinterpret_cast<PACKET_ZC_REPAIRITEMLIST*>( packet_buffer );
  6065. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6066. p->packetLength = sizeof( *p );
  6067. size_t c = 0;
  6068. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  6069. 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)){
  6070. p->items[c].index = static_cast<decltype( p->items[0].index )>( i );
  6071. p->items[c].itemId = client_nameid( dstsd.inventory.u.items_inventory[i].nameid );
  6072. p->items[c].refine = dstsd.inventory.u.items_inventory[i].refine;
  6073. clif_addcards( &p->items[c].slot, &dstsd.inventory.u.items_inventory[i] );
  6074. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  6075. c++;
  6076. }
  6077. }
  6078. if( c > 0 ){
  6079. clif_send( p, p->packetLength, &sd.bl, SELF );
  6080. sd.menuskill_id = BS_REPAIRWEAPON;
  6081. sd.menuskill_val = dstsd.bl.id;
  6082. sd.menuskill_val2 = lv;
  6083. }else{
  6084. clif_skill_fail( sd, sd.ud.skill_id );
  6085. }
  6086. }
  6087. /// Notifies the client about the result of a item repair request.
  6088. /// 01fe <index>.W <result>.B (ZC_ACK_ITEMREPAIR)
  6089. /// index:
  6090. /// ignored (inventory index)
  6091. /// result:
  6092. /// 0 = Item repair success.
  6093. /// 1 = Item repair failure.
  6094. void clif_item_repaireffect( map_session_data& sd, int32 idx, bool failure ){
  6095. PACKET_ZC_ACK_ITEMREPAIR packet{};
  6096. packet.packetType = HEADER_ZC_ACK_ITEMREPAIR;
  6097. packet.index = client_index( idx );
  6098. packet.result = failure;
  6099. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6100. }
  6101. /// Displays a message, that an equipment got damaged.
  6102. /// 02bb <equip location>.W <account id>.L (ZC_EQUIPITEM_DAMAGED)
  6103. void clif_item_damaged( map_session_data& sd, uint16 position ){
  6104. PACKET_ZC_EQUIPITEM_DAMAGED packet{};
  6105. packet.packetType = HEADER_ZC_EQUIPITEM_DAMAGED;
  6106. packet.equipLocation = position;
  6107. packet.GID = sd.bl.id;
  6108. // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6109. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6110. }
  6111. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6112. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6113. void clif_item_refine_list( map_session_data& sd ){
  6114. PACKET_ZC_NOTIFY_WEAPONITEMLIST* p = reinterpret_cast<PACKET_ZC_NOTIFY_WEAPONITEMLIST*>( packet_buffer );
  6115. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6116. p->packetLength = sizeof( *p );
  6117. uint16 skill_lv = pc_checkskill( &sd, WS_WEAPONREFINE );
  6118. int refine_item[MAX_WEAPON_LEVEL];
  6119. refine_item[0] = pc_search_inventory( &sd, ITEMID_PHRACON );
  6120. refine_item[1] = pc_search_inventory( &sd, ITEMID_EMVERETARCON );
  6121. refine_item[2] = refine_item[3] = pc_search_inventory( &sd, ITEMID_ORIDECON );
  6122. #ifdef RENEWAL
  6123. refine_item[4] = -1;
  6124. #endif
  6125. int count = 0;
  6126. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6127. if( sd.inventory.u.items_inventory[i].nameid > 0 && sd.inventory.u.items_inventory[i].refine < skill_lv &&
  6128. sd.inventory_data[i] != nullptr && sd.inventory_data[i]->type == IT_WEAPON &&
  6129. sd.inventory.u.items_inventory[i].identify && sd.inventory_data[i]->weapon_level >= 1 &&
  6130. refine_item[sd.inventory_data[i]->weapon_level - 1] != -1 && !( sd.inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6131. p->items[count].index = client_index( i );
  6132. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  6133. p->items[count].refine = sd.inventory.u.items_inventory[i].refine;
  6134. clif_addcards( &p->items[count].slot, &sd.inventory.u.items_inventory[i] );
  6135. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  6136. count++;
  6137. }
  6138. }
  6139. clif_send( p, p->packetLength, &sd.bl, SELF );
  6140. if( count > 0 ){
  6141. sd.menuskill_id = WS_WEAPONREFINE;
  6142. sd.menuskill_val = skill_lv;
  6143. }
  6144. }
  6145. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6146. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6147. void clif_item_skill( map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6148. nullpo_retv( sd );
  6149. struct PACKET_ZC_AUTORUN_SKILL p;
  6150. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6151. p.skill_id = skill_id;
  6152. p.skill_type = skill_get_inf( skill_id );
  6153. p.skill_lv = skill_lv;
  6154. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6155. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6156. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6157. p.up_flag = false;
  6158. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6159. }
  6160. /// Adds an item to character's cart.
  6161. /// 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)
  6162. /// 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)
  6163. /// 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)
  6164. void clif_cart_additem( map_session_data *sd, int n, int amount ){
  6165. nullpo_retv( sd );
  6166. int fd = sd->fd;
  6167. if( !session_isActive( fd ) ){
  6168. return;
  6169. }
  6170. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6171. return;
  6172. }
  6173. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6174. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6175. p.index = client_index( n );
  6176. p.amount = amount;
  6177. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6178. #if PACKETVER >= 5
  6179. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6180. #endif
  6181. p.identified = sd->cart.u.items_cart[n].identify;
  6182. p.damaged = sd->cart.u.items_cart[n].attribute;
  6183. p.refine = sd->cart.u.items_cart[n].refine;
  6184. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6185. #if PACKETVER >= 20150226
  6186. clif_add_random_options( p.option_data, sd->cart.u.items_cart[n] );
  6187. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6188. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6189. #endif
  6190. #endif
  6191. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6192. }
  6193. /// Acknowledge an item have been added to cart
  6194. /// 012c <result>.B (ZC_ACK_ADDITEM_TO_CART)
  6195. /// result:
  6196. /// 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6197. /// 1 = ADDITEM_TO_CART_FAIL_COUNT
  6198. void clif_cart_additem_ack( map_session_data& sd, e_ack_additem_to_cart flag ){
  6199. PACKET_ZC_ACK_ADDITEM_TO_CART packet{};
  6200. packet.packetType = HEADER_ZC_ACK_ADDITEM_TO_CART;
  6201. packet.result = static_cast<decltype(packet.result)>(flag);
  6202. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6203. }
  6204. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6205. void clif_bank_open( map_session_data& sd ){
  6206. #if PACKETVER >= 20130717
  6207. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6208. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6209. p.unknown = 0;
  6210. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6211. #endif
  6212. }
  6213. /*
  6214. * Request to Open the banking system
  6215. * 09B6 <aid>L (CZ_REQ_OPEN_BANKING)
  6216. */
  6217. void clif_parse_BankOpen(int fd, map_session_data* sd) {
  6218. #if PACKETVER >= 20130717
  6219. PACKET_CZ_REQ_OPEN_BANKING* p = (PACKET_CZ_REQ_OPEN_BANKING*)RFIFOP( fd, 0 );
  6220. //TODO check if preventing trade or stuff like that
  6221. //also mark something in case char ain't available for saving, should we check now ?
  6222. nullpo_retv(sd);
  6223. if( !battle_config.feature_banking ) {
  6224. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6225. return;
  6226. }
  6227. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6228. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6229. return;
  6230. }
  6231. else {
  6232. if(sd->status.account_id == p->AID){
  6233. sd->state.banking = 1;
  6234. //request save ?
  6235. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6236. //on succes open bank ?
  6237. clif_bank_open( *sd );
  6238. }
  6239. }
  6240. #endif
  6241. }
  6242. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6243. void clif_bank_close( map_session_data& sd ){
  6244. #if PACKETVER >= 20130717
  6245. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6246. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6247. p.unknown = 0;
  6248. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6249. #endif
  6250. }
  6251. /*
  6252. * Request to close the banking system
  6253. * 09B8 <aid>L (CZ_REQ_CLOSE_BANKING)
  6254. */
  6255. void clif_parse_BankClose(int fd, map_session_data* sd) {
  6256. #if PACKETVER >= 20130717
  6257. PACKET_CZ_REQ_CLOSE_BANKING* p = (PACKET_CZ_REQ_CLOSE_BANKING*)RFIFOP( fd, 0 );
  6258. nullpo_retv(sd);
  6259. if( !battle_config.feature_banking ) {
  6260. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6261. //still allow to go trough to not stuck player if we have disable it while they was in
  6262. }
  6263. if(sd->status.account_id == p->AID){
  6264. sd->state.banking = 0;
  6265. clif_bank_close( *sd );
  6266. }
  6267. #endif
  6268. }
  6269. /*
  6270. * Display how much we got in bank (I suppose)
  6271. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6272. */
  6273. void clif_Bank_Check( map_session_data& sd ){
  6274. #if PACKETVER >= 20130717
  6275. struct PACKET_ZC_BANKING_CHECK p = {};
  6276. p.packetType = HEADER_ZC_BANKING_CHECK;
  6277. p.money = sd.bank_vault;
  6278. p.reason = 0;
  6279. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6280. #endif
  6281. }
  6282. /*
  6283. * Requesting the data in bank
  6284. * 09AB <aid>L (CZ_REQ_BANKING_CHECK)
  6285. */
  6286. void clif_parse_BankCheck(int fd, map_session_data* sd) {
  6287. #if PACKETVER >= 20130717
  6288. PACKET_CZ_REQ_BANKING_CHECK* p = (PACKET_CZ_REQ_BANKING_CHECK*)RFIFOP( fd, 0 );
  6289. nullpo_retv(sd);
  6290. if( !battle_config.feature_banking ) {
  6291. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6292. return;
  6293. }
  6294. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6295. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6296. return;
  6297. }
  6298. else {
  6299. if(sd->status.account_id == p->AID) //since we have it let check it for extra security
  6300. clif_Bank_Check( *sd );
  6301. }
  6302. #endif
  6303. }
  6304. /*
  6305. * Acknowledge of deposit some money in bank
  6306. 09A8 <Reason>W <Money>Q <balance>L (ZC_ACK_BANKING_DEPOSIT)
  6307. */
  6308. void clif_bank_deposit( map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6309. #if PACKETVER >= 20130717
  6310. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6311. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6312. p.money = sd.bank_vault;
  6313. p.zeny = sd.status.zeny;
  6314. p.reason = reason;
  6315. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6316. #endif
  6317. }
  6318. /*
  6319. * Request saving some money in bank
  6320. * @author : original [Yommy/Hercules]
  6321. * 09A7 <AID>L <Money>L (CZ_REQ_BANKING_DEPOSIT)
  6322. */
  6323. void clif_parse_BankDeposit(int fd, map_session_data* sd) {
  6324. #if PACKETVER >= 20130717
  6325. PACKET_CZ_REQ_BANKING_DEPOSIT* p = (PACKET_CZ_REQ_BANKING_DEPOSIT*)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_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,p->zeny));
  6338. clif_bank_deposit( *sd, reason );
  6339. }
  6340. }
  6341. #endif
  6342. }
  6343. /*
  6344. * Acknowledge of withdrawing some money from bank
  6345. * 09AA <Reason>W <Money>Q <balance>L (ZC_ACK_BANKING_WITHDRAW)
  6346. */
  6347. void clif_bank_withdraw( map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6348. #if PACKETVER >= 20130717
  6349. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6350. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6351. p.reason = reason;
  6352. p.money = sd.bank_vault;
  6353. p.zeny = sd.status.zeny;
  6354. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6355. #endif
  6356. }
  6357. /*
  6358. * Request Withdrawing some money from bank
  6359. * 09A9 <AID>L <Money>L (CZ_REQ_BANKING_WITHDRAW)
  6360. */
  6361. void clif_parse_BankWithdraw(int fd, map_session_data* sd) {
  6362. #if PACKETVER >= 20130717
  6363. PACKET_CZ_REQ_BANKING_WITHDRAW* p = (PACKET_CZ_REQ_BANKING_WITHDRAW*)RFIFOP( fd, 0 );
  6364. nullpo_retv(sd);
  6365. if( !battle_config.feature_banking ) {
  6366. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6367. return;
  6368. }
  6369. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6370. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6371. return;
  6372. }
  6373. else {
  6374. if(sd->status.account_id == p->AID){
  6375. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,p->zeny));
  6376. clif_bank_withdraw( *sd, reason );
  6377. }
  6378. }
  6379. #endif
  6380. }
  6381. /// Deletes an item from character's cart.
  6382. /// 0125 <index>.W <amount>.L (ZC_DELETE_ITEM_FROM_CART)
  6383. void clif_cart_delitem( map_session_data& sd, int32 index, int32 amount ){
  6384. PACKET_ZC_DELETE_ITEM_FROM_CART packet{};
  6385. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_CART;
  6386. packet.index = client_index( index );
  6387. packet.amount = amount;
  6388. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6389. }
  6390. /// Opens the shop creation menu.
  6391. /// 012d <num>.W (ZC_OPENSTORE)
  6392. /// num:
  6393. /// number of allowed item slots
  6394. void clif_openvendingreq( map_session_data& sd, uint16 num ){
  6395. PACKET_ZC_OPENSTORE packet{};
  6396. packet.packetType = HEADER_ZC_OPENSTORE;
  6397. packet.num = num;
  6398. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6399. }
  6400. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6401. /// 0131 <owner id>.L <message>.80B
  6402. void clif_showvendingboard( map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6403. if( tbl == nullptr ){
  6404. tbl = &sd.bl;
  6405. target = AREA_WOS;
  6406. }
  6407. struct PACKET_ZC_STORE_ENTRY p = {};
  6408. p.packetType = HEADER_ZC_STORE_ENTRY;
  6409. p.makerAID = sd.status.account_id;
  6410. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6411. clif_send( &p, sizeof( p ), tbl, target );
  6412. }
  6413. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6414. /// 0132 <owner id>.L
  6415. void clif_closevendingboard(struct block_list* bl, int fd)
  6416. {
  6417. unsigned char buf[16];
  6418. nullpo_retv(bl);
  6419. WBUFW(buf,0) = 0x132;
  6420. WBUFL(buf,2) = bl->id;
  6421. if( session_isActive(fd) ) {
  6422. WFIFOHEAD(fd,packet_len(0x132));
  6423. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6424. WFIFOSET(fd,packet_len(0x132));
  6425. } else {
  6426. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6427. }
  6428. }
  6429. /// Sends a list of items in a shop.
  6430. /// 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)
  6431. /// 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)
  6432. void clif_vendinglist( map_session_data* sd, map_session_data* vsd ){
  6433. nullpo_retv( sd );
  6434. nullpo_retv( vsd );
  6435. nullpo_retv( vsd->vending );
  6436. int fd = sd->fd;
  6437. if( !session_isActive( fd ) ){
  6438. return;
  6439. }
  6440. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6441. WFIFOHEAD( fd, len );
  6442. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6443. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6444. p->packetLength = len;
  6445. p->AID = vsd->status.account_id;
  6446. #if PACKETVER >= 20100105
  6447. p->venderId = vsd->vender_id;
  6448. #endif
  6449. for( int i = 0; i < vsd->vend_num; i++ ){
  6450. int index = vsd->vending[i].index;
  6451. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6452. p->items[i].price = vsd->vending[i].value;
  6453. p->items[i].amount = vsd->vending[i].amount;
  6454. p->items[i].index = client_index( index );
  6455. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6456. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6457. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6458. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6459. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6460. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6461. #if PACKETVER >= 20150226
  6462. clif_add_random_options( p->items[i].option_data, vsd->cart.u.items_cart[index] );
  6463. #if PACKETVER >= 20160921
  6464. p->items[i].location = pc_equippoint_sub( sd, data );
  6465. p->items[i].viewSprite = data->look;
  6466. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6467. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6468. #endif
  6469. #endif
  6470. #endif
  6471. }
  6472. WFIFOSET( fd, len );
  6473. }
  6474. /// Shop purchase failure.
  6475. /// 0135 <index>.W <amount>.W <result>.B (ZC_PC_PURCHASE_RESULT_FROMMC)
  6476. /// result:
  6477. /// 0 = success
  6478. /// 1 = not enough zeny
  6479. /// 2 = overweight
  6480. /// 4 = out of stock
  6481. /// 5 = "cannot use an npc shop while in a trade"
  6482. /// 6 = Because the store information was incorrect the item was not purchased.
  6483. /// 7 = No sales information.
  6484. void clif_buyvending( map_session_data& sd, uint16 index, uint16 amount, e_pc_purchase_result_frommc result ){
  6485. PACKET_ZC_PC_PURCHASE_RESULT_FROMMC packet{};
  6486. packet.packetType = HEADER_ZC_PC_PURCHASE_RESULT_FROMMC;
  6487. packet.index = client_index( index );
  6488. packet.amount = amount;
  6489. packet.result = static_cast<decltype(packet.result)>(result);
  6490. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6491. }
  6492. /// Show's vending player its list of items for sale.
  6493. /// 0a28 <result>.B (ZC_ACK_OPENSTORE2)
  6494. /// result:
  6495. /// 0 = Success
  6496. /// 1 = Failed
  6497. void clif_openvending_ack( map_session_data& sd, bool failure ){
  6498. #if PACKETVER >= 20141022
  6499. PACKET_ZC_ACK_OPENSTORE2 packet{};
  6500. packet.packetType = HEADER_ZC_ACK_OPENSTORE2;
  6501. packet.result = failure;
  6502. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6503. #endif
  6504. }
  6505. /// Shop creation success.
  6506. /// 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)
  6507. void clif_openvending( map_session_data* sd, int id, struct s_vending* vending ){
  6508. nullpo_retv( sd );
  6509. nullpo_retv( vending );
  6510. int fd = sd->fd;
  6511. if( !session_isActive( fd ) ){
  6512. return;
  6513. }
  6514. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6515. WFIFOHEAD( fd, len );
  6516. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6517. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6518. p->packetLength = len;
  6519. p->AID = id;
  6520. for( int i = 0; i < sd->vend_num; i++ ) {
  6521. int index = vending[i].index;
  6522. p->items[i].price = vending[i].value;
  6523. p->items[i].index = client_index( index );
  6524. p->items[i].amount = vending[i].amount;
  6525. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6526. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6527. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6528. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6529. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6530. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6531. #if PACKETVER >= 20150226
  6532. clif_add_random_options( p->items[i].option_data, sd->cart.u.items_cart[index] );
  6533. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6534. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6535. #endif
  6536. #endif
  6537. }
  6538. WFIFOSET( fd, len );
  6539. clif_openvending_ack( *sd, false );
  6540. }
  6541. /// Inform merchant that someone has bought an item.
  6542. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE)
  6543. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2)
  6544. void clif_vendingreport( map_session_data& sd, uint16 index, uint16 amount, uint32 char_id, int32 zeny ){
  6545. PACKET_ZC_DELETEITEM_FROM_MCSTORE packet{};
  6546. packet.packetType = HEADER_ZC_DELETEITEM_FROM_MCSTORE;
  6547. packet.index = client_index( index );
  6548. packet.amount = amount;
  6549. // TODO : not sure for client date [Napster]
  6550. #if PACKETVER >= 20141016
  6551. packet.buyerCID = char_id;
  6552. packet.date = client_tick( time(nullptr) );
  6553. packet.zeny = zeny;
  6554. #endif
  6555. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6556. }
  6557. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6558. /// 00fa <result>.B
  6559. /// result:
  6560. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6561. /// 1 = MsgStringTable[78]="party name already exists"
  6562. /// 2 = MsgStringTable[79]="already in a party"
  6563. /// 3 = cannot organize parties on this map
  6564. /// ? = nothing
  6565. void clif_party_created( map_session_data& sd, int result ){
  6566. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6567. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6568. p.result = result;
  6569. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6570. }
  6571. /// Adds new member to a party.
  6572. /// 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)
  6573. /// 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)
  6574. /// 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)
  6575. /// role:
  6576. /// 0 = leader
  6577. /// 1 = normal
  6578. /// state:
  6579. /// 0 = connected
  6580. /// 1 = disconnected
  6581. void clif_party_member_info( struct party_data& party, map_session_data& sd ){
  6582. int id = party_getmemberid( &party, &sd );
  6583. if( id < 0 ){
  6584. return;
  6585. }
  6586. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6587. p.packetType = partymemberinfo;
  6588. p.AID = sd.status.account_id;
  6589. #if PACKETVER >= 20171207
  6590. p.GID = sd.status.char_id;
  6591. #endif
  6592. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6593. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6594. p.class_ = sd.status.class_;
  6595. p.baseLevel = sd.status.base_level;
  6596. #endif
  6597. p.x = sd.bl.x;
  6598. p.y = sd.bl.y;
  6599. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6600. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6601. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6602. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6603. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6604. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6605. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6606. }
  6607. /// Sends party information (ZC_GROUP_LIST).
  6608. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6609. /// role:
  6610. /// 0 = leader
  6611. /// 1 = normal
  6612. /// state:
  6613. /// 0 = connected
  6614. /// 1 = disconnected
  6615. /// 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
  6616. void clif_party_info( struct party_data& party, map_session_data* sd ){
  6617. send_target target;
  6618. if( sd == nullptr ){
  6619. sd = party_getavailablesd( &party );
  6620. if( sd == nullptr ){
  6621. // Nobody is online to notify
  6622. return;
  6623. }
  6624. // Send to whole party
  6625. target = PARTY;
  6626. }else{
  6627. // Send only to self
  6628. target = SELF;
  6629. }
  6630. PACKET_ZC_GROUP_LIST* p = reinterpret_cast<PACKET_ZC_GROUP_LIST*>( packet_buffer );
  6631. p->packetType = partyinfo;
  6632. p->packetLen = sizeof( *p );
  6633. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6634. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6635. struct party_member& m = party.party.member[i];
  6636. if( m.account_id == 0 ){
  6637. continue;
  6638. }
  6639. PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6640. member.AID = m.account_id;
  6641. #if PACKETVER >= 20171207
  6642. member.GID = m.char_id;
  6643. #endif
  6644. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6645. mapindex_getmapname_ext( m.map, member.mapName );
  6646. member.leader = ( m.leader ) ? 0 : 1;
  6647. member.offline = ( m.online ) ? 0 : 1;
  6648. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6649. member.class_ = m.class_;
  6650. member.baseLevel = m.lv;
  6651. #endif
  6652. p->packetLen += static_cast<decltype(p->packetLen)>( sizeof( member ) );
  6653. c++;
  6654. }
  6655. clif_send( p, p->packetLen, &sd->bl, target );
  6656. }
  6657. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6658. /// 02c9 <flag>.B
  6659. /// flag:
  6660. /// 0 = allow party invites
  6661. /// 1 = auto-deny party invites
  6662. void clif_partyinvitationstate( map_session_data& sd ){
  6663. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6664. struct PACKET_ZC_PARTY_CONFIG p = {};
  6665. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6666. p.denyPartyInvites = sd.status.disable_partyinvite;
  6667. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6668. #endif
  6669. }
  6670. /// Party invitation request.
  6671. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6672. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6673. void clif_party_invite( map_session_data& sd, map_session_data& tsd ){
  6674. struct party_data* party = party_search( sd.status.party_id );
  6675. if( party == nullptr ){
  6676. return;
  6677. }
  6678. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6679. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6680. p.GRID = party->party.party_id;
  6681. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6682. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6683. }
  6684. /// Party invite result.
  6685. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6686. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6687. /// result=0 : char is already in a party -> MsgStringTable[80]
  6688. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6689. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6690. /// result=3 : party is full -> MsgStringTable[83]
  6691. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6692. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6693. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6694. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6695. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6696. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6697. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6698. void clif_party_invite_reply( map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6699. #if PACKETVER < 20070904
  6700. if( reply == PARTY_REPLY_OFFLINE ){
  6701. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6702. return;
  6703. }
  6704. #endif
  6705. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6706. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6707. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6708. p.result = reply;
  6709. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6710. }
  6711. /// Updates party settings.
  6712. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6713. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6714. /// exp option:
  6715. /// 0 = exp sharing disabled
  6716. /// 1 = exp sharing enabled
  6717. /// 2 = cannot change exp sharing
  6718. ///
  6719. /// flag:
  6720. /// 0 = send to party
  6721. /// 1 = send to sd
  6722. void clif_party_option(struct party_data *p,map_session_data *sd,int flag)
  6723. {
  6724. unsigned char buf[16];
  6725. #if PACKETVER < 20090603
  6726. const int cmd = 0x101;
  6727. #else
  6728. const int cmd = 0x7d8;
  6729. #endif
  6730. nullpo_retv(p);
  6731. if(!sd && flag==0){
  6732. int i;
  6733. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6734. if (i < MAX_PARTY)
  6735. sd = p->data[i].sd;
  6736. }
  6737. if(!sd) return;
  6738. WBUFW(buf,0)=cmd;
  6739. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6740. #if PACKETVER >= 20090603
  6741. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6742. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6743. #endif
  6744. if(flag==0)
  6745. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6746. else
  6747. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6748. }
  6749. /**
  6750. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6751. * @param sd Send the notification for this player
  6752. * @param account_id Account ID of kicked member
  6753. * @param name Name of kicked member
  6754. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6755. * @param target Send target
  6756. **/
  6757. void clif_party_withdraw( map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6758. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6759. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6760. p.AID = account_id;
  6761. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6762. p.result = result;
  6763. clif_send( &p, sizeof( p ), &sd.bl, target );
  6764. }
  6765. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6766. /// 0109 <packet len>.W <account id>.L <message>.?B
  6767. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, size_t len ){
  6768. map_session_data* sd = party_getavailablesd( &party );
  6769. if( sd == nullptr ){
  6770. return;
  6771. }
  6772. if (len > CHAT_SIZE_MAX) {
  6773. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6774. len = CHAT_SIZE_MAX;
  6775. }
  6776. PACKET_ZC_NOTIFY_CHAT_PARTY* p = reinterpret_cast<PACKET_ZC_NOTIFY_CHAT_PARTY*>( packet_buffer );
  6777. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6778. p->PacketLength = sizeof( *p );
  6779. p->AID = account_id;
  6780. safestrncpy( p->chatMsg, mes, len );
  6781. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  6782. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6783. }
  6784. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6785. /// 0107 <account id>.L <x>.W <y>.W
  6786. void clif_party_xy( map_session_data& sd ){
  6787. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6788. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6789. p.AID = sd.status.account_id;
  6790. p.xPos = sd.bl.x;
  6791. p.yPos = sd.bl.y;
  6792. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6793. }
  6794. /*==========================================
  6795. * Sends x/y dot to a single fd. [Skotlex]
  6796. *------------------------------------------*/
  6797. void clif_party_xy_single( map_session_data& sd, map_session_data& tsd ){
  6798. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6799. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6800. p.AID = sd.status.account_id;
  6801. p.xPos = sd.bl.x;
  6802. p.yPos = sd.bl.y;
  6803. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6804. }
  6805. /// Updates HP bar of a party member.
  6806. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6807. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6808. void clif_party_hp( map_session_data& sd ){
  6809. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6810. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6811. p.AID = sd.status.account_id;
  6812. #if PACKETVER < 20100119
  6813. // To correctly display the %hp bar. [Skotlex]
  6814. if( sd.battle_status.max_hp > INT16_MAX ){
  6815. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6816. p.maxhp = 100;
  6817. }else{
  6818. p.hp = sd.battle_status.hp;
  6819. p.maxhp = sd.battle_status.max_hp;
  6820. }
  6821. #else
  6822. p.hp = sd.battle_status.hp;
  6823. p.maxhp = sd.battle_status.max_hp;
  6824. #endif
  6825. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6826. }
  6827. /// Notifies the party members of a character's death or revival.
  6828. /// 0AB2 <GID>.L <dead>.B
  6829. void clif_party_dead( map_session_data& sd ){
  6830. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6831. struct PACKET_ZC_GROUP_ISALIVE p = {};
  6832. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6833. p.AID = sd.status.account_id;
  6834. p.isDead = pc_isdead( &sd );
  6835. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6836. #endif
  6837. }
  6838. /// Updates the job and level of a party member
  6839. /// 0abd <account id>.L <job>.W <level>.W
  6840. void clif_party_job_and_level( map_session_data& sd ){
  6841. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  6842. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  6843. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  6844. p.AID = sd.status.account_id;
  6845. p.job = sd.status.class_;
  6846. p.level = sd.status.base_level;
  6847. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6848. #endif
  6849. }
  6850. /*==========================================
  6851. * Sends HP bar to a single fd. [Skotlex]
  6852. *------------------------------------------*/
  6853. void clif_hpmeter_single( map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  6854. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6855. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6856. p.AID = id;
  6857. #if PACKETVER < 20100119
  6858. // To correctly display the %hp bar. [Skotlex]
  6859. if( maxhp > INT16_MAX ){
  6860. p.hp = hp / ( maxhp / 100 );
  6861. p.maxhp = 100;
  6862. }else{
  6863. p.hp = hp;
  6864. p.maxhp = maxhp;
  6865. }
  6866. #else
  6867. p.hp = hp;
  6868. p.maxhp = maxhp;
  6869. #endif
  6870. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6871. }
  6872. /// Notifies the client, that it's attack target is too far.
  6873. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W (ZC_ATTACK_FAILURE_FOR_DISTANCE)
  6874. void clif_movetoattack( map_session_data& sd, block_list& bl ){
  6875. PACKET_ZC_ATTACK_FAILURE_FOR_DISTANCE packet{};
  6876. packet.PacketType = HEADER_ZC_ATTACK_FAILURE_FOR_DISTANCE;
  6877. packet.targetAID = bl.id;
  6878. packet.targetXPos = bl.x;
  6879. packet.targetYPos = bl.y;
  6880. packet.xPos = sd.bl.x;
  6881. packet.yPos = sd.bl.y;
  6882. packet.currentAttRange = sd.battle_status.rhw.range;
  6883. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6884. }
  6885. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6886. /// 018f <result>.W <name id>.W
  6887. /// result:
  6888. /// 0 = success
  6889. /// 1 = failure
  6890. /// 2 = success (alchemist)
  6891. /// 3 = failure (alchemist)
  6892. void clif_produceeffect(map_session_data* sd,int flag, t_itemid nameid){
  6893. nullpo_retv( sd );
  6894. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6895. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6896. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6897. p.result = flag;
  6898. p.itemId = client_nameid( nameid );
  6899. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6900. }
  6901. /// Initiates the pet taming process.
  6902. /// 019e (ZC_START_CAPTURE)
  6903. void clif_catch_process( map_session_data& sd ){
  6904. PACKET_ZC_START_CAPTURE packet{};
  6905. packet.PacketType = HEADER_ZC_START_CAPTURE;
  6906. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6907. }
  6908. /// Displays the result of a pet taming attempt.
  6909. /// 01a0 <result>.B (ZC_TRYCAPTURE_MONSTER)
  6910. /// 0 = failure
  6911. /// 1 = success
  6912. void clif_pet_roulette( map_session_data& sd, bool success ){
  6913. PACKET_ZC_TRYCAPTURE_MONSTER packet{};
  6914. packet.PacketType = HEADER_ZC_TRYCAPTURE_MONSTER;
  6915. packet.result = success;
  6916. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6917. }
  6918. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6919. /// 01a6 <packet len>.W { <index>.W }*
  6920. void clif_sendegg(map_session_data *sd)
  6921. {
  6922. int i,n=0,fd;
  6923. nullpo_retv(sd);
  6924. fd=sd->fd;
  6925. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6926. clif_displaymessage(fd, msg_txt(sd,666));
  6927. return;
  6928. }
  6929. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6930. WFIFOW(fd,0)=0x1a6;
  6931. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6932. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ||
  6933. sd->inventory_data[i]->type != IT_PETEGG ||
  6934. sd->inventory.u.items_inventory[i].amount <= 0)
  6935. continue;
  6936. WFIFOW(fd,n*2+4)=client_index(i);
  6937. n++;
  6938. }
  6939. WFIFOW(fd,2)=4+n*2;
  6940. WFIFOSET(fd,WFIFOW(fd,2));
  6941. sd->menuskill_id = SA_TAMINGMONSTER;
  6942. sd->menuskill_val = -1;
  6943. }
  6944. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6945. /// 01a4 <type>.B <id>.L <data>.L
  6946. /// type:
  6947. /// 0 = pre-init (data = 0)
  6948. /// 1 = intimacy (data = 0~4)
  6949. /// 2 = hunger (data = 0~4)
  6950. /// 3 = accessory
  6951. /// 4 = performance (data = 1~3: normal, 4: special)
  6952. /// 5 = hairstyle
  6953. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6954. ///
  6955. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6956. void clif_send_petdata(map_session_data* sd, struct pet_data* pd, int type, int param)
  6957. {
  6958. uint8 buf[16];
  6959. nullpo_retv(pd);
  6960. WBUFW(buf,0) = 0x1a4;
  6961. WBUFB(buf,2) = type;
  6962. WBUFL(buf,3) = pd->bl.id;
  6963. WBUFL(buf,7) = param;
  6964. if (sd)
  6965. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6966. else
  6967. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6968. }
  6969. /// Pet's base data (ZC_PROPERTY_PET).
  6970. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6971. void clif_send_petstatus(map_session_data *sd)
  6972. {
  6973. int fd;
  6974. struct s_pet *pet;
  6975. nullpo_retv(sd);
  6976. nullpo_retv(sd->pd);
  6977. fd=sd->fd;
  6978. pet = &sd->pd->pet;
  6979. WFIFOHEAD(fd,packet_len(0x1a2));
  6980. WFIFOW(fd,0)=0x1a2;
  6981. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6982. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6983. WFIFOW(fd,27)=pet->level;
  6984. WFIFOW(fd,29)=pet->hungry;
  6985. WFIFOW(fd,31)=pet->intimate;
  6986. WFIFOW(fd,33)=pet->equip;
  6987. #if PACKETVER >= 20081126
  6988. WFIFOW(fd,35)=pet->class_;
  6989. #endif
  6990. WFIFOSET(fd,packet_len(0x1a2));
  6991. }
  6992. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6993. /// 01aa <id>.L <data>.L
  6994. /// data:
  6995. /// @see CZ_PET_ACT.
  6996. void clif_pet_emotion(struct pet_data *pd,int param)
  6997. {
  6998. unsigned char buf[16];
  6999. nullpo_retv(pd);
  7000. memset(buf,0,packet_len(0x1aa));
  7001. WBUFW(buf,0)=0x1aa;
  7002. WBUFL(buf,2)=pd->bl.id;
  7003. WBUFL(buf,6)=param;
  7004. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7005. }
  7006. /// Result of request to feed a pet.
  7007. /// 01a3 <result>.B <name id>.W (ZC_FEED_PET)
  7008. /// result:
  7009. /// 0 = failure
  7010. /// 1 = success
  7011. void clif_pet_food( map_session_data& sd, int32 foodid, bool success ){
  7012. PACKET_ZC_FEED_PET packet{};
  7013. packet.packetType = HEADER_ZC_FEED_PET;
  7014. packet.result = success;
  7015. packet.itemId = client_nameid( foodid );
  7016. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  7017. }
  7018. /// Send pet auto feed info.
  7019. void clif_pet_autofeed_status(map_session_data* sd, bool force) {
  7020. #if PACKETVER >= 20141008
  7021. nullpo_retv(sd);
  7022. if (force || battle_config.pet_autofeed_always) {
  7023. // Always send ON or OFF
  7024. if (sd->pd && battle_config.feature_pet_autofeed) {
  7025. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7026. }
  7027. else {
  7028. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7029. }
  7030. }
  7031. else {
  7032. // Only send when enabled
  7033. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7034. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7035. }
  7036. }
  7037. #endif
  7038. }
  7039. /// Presents a list of skills that can be auto-spelled.
  7040. /// 01cd { <skill id>.L }*7 (ZC_AUTOSPELLLIST)
  7041. void clif_autospell( map_session_data& sd, uint16 skill_lv ){
  7042. struct s_autospell_requirement{
  7043. uint16 skill_id;
  7044. uint16 required_autospell_skill_lv;
  7045. };
  7046. #ifdef RENEWAL
  7047. const std::vector<s_autospell_requirement> autospell_skills = {
  7048. { MG_FIREBOLT, 0 },
  7049. { MG_COLDBOLT, 0 },
  7050. { MG_LIGHTNINGBOLT, 0 },
  7051. { MG_SOULSTRIKE, 3 },
  7052. { MG_FIREBALL, 3 },
  7053. { WZ_EARTHSPIKE, 6 },
  7054. { MG_FROSTDIVER, 6 },
  7055. { MG_THUNDERSTORM, 9 },
  7056. { WZ_HEAVENDRIVE, 9 }
  7057. };
  7058. #else
  7059. const std::vector<s_autospell_requirement> autospell_skills = {
  7060. { MG_NAPALMBEAT, 0 },
  7061. { MG_COLDBOLT, 1 },
  7062. { MG_FIREBOLT, 1 },
  7063. { MG_LIGHTNINGBOLT, 1 },
  7064. { MG_SOULSTRIKE, 4 },
  7065. { MG_FIREBALL, 7 },
  7066. { MG_FROSTDIVER, 9 },
  7067. };
  7068. #endif
  7069. #if PACKETVER_MAIN_NUM >= 20181128 || PACKETVER_RE_NUM >= 20181031
  7070. PACKET_ZC_AUTOSPELLLIST* p = reinterpret_cast<PACKET_ZC_AUTOSPELLLIST*>( packet_buffer );
  7071. p->packetType = HEADER_ZC_AUTOSPELLLIST;
  7072. p->packetLength = sizeof( *p );
  7073. size_t count = 0;
  7074. for( const s_autospell_requirement& requirement : autospell_skills ){
  7075. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7076. p->skills[count++] = requirement.skill_id;
  7077. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->skills[0] ) );
  7078. }
  7079. }
  7080. clif_send( p, p->packetLength, &sd.bl, SELF );
  7081. #elif PACKETVER_MAIN_NUM >= 20090406 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_SAK_NUM >= 20080618
  7082. PACKET_ZC_AUTOSPELLLIST p = {};
  7083. p.packetType = HEADER_ZC_AUTOSPELLLIST;
  7084. size_t count = 0;
  7085. for( const s_autospell_requirement& requirement : autospell_skills ){
  7086. if( count == ARRAYLENGTH( p.skills ) ){
  7087. break;
  7088. }
  7089. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7090. p.skills[count++] = requirement.skill_id;
  7091. }else{
  7092. p.skills[count++] = 0;
  7093. }
  7094. }
  7095. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7096. #endif
  7097. sd.menuskill_id = SA_AUTOSPELL;
  7098. sd.menuskill_val = skill_lv;
  7099. }
  7100. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7101. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7102. void clif_devotion(struct block_list *src, map_session_data *tsd)
  7103. {
  7104. unsigned char buf[56];
  7105. nullpo_retv(src);
  7106. memset(buf,0,packet_len(0x1cf));
  7107. WBUFW(buf,0) = 0x1cf;
  7108. WBUFL(buf,2) = src->id;
  7109. if( src->type == BL_MER )
  7110. {
  7111. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7112. if( md && md->master && md->devotion_flag )
  7113. WBUFL(buf,6) = md->master->bl.id;
  7114. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7115. }
  7116. else
  7117. {
  7118. int i;
  7119. map_session_data *sd = BL_CAST(BL_PC,src);
  7120. if( sd == nullptr )
  7121. return;
  7122. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7123. WBUFL(buf,6+4*i) = sd->devotion[i];
  7124. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7125. }
  7126. if( tsd )
  7127. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7128. else
  7129. clif_send(buf, packet_len(0x1cf), src, AREA);
  7130. }
  7131. /// Notifies the client of an object's spirits.
  7132. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7133. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7134. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7135. nullpo_retv( bl );
  7136. struct PACKET_ZC_SPIRITS p = {};
  7137. p.PacketType = HEADER_ZC_SPIRITS;
  7138. p.AID = bl->id;
  7139. switch( bl->type ){
  7140. case BL_PC:
  7141. p.num = ( (map_session_data*)bl )->spiritball;
  7142. break;
  7143. case BL_HOM:
  7144. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7145. break;
  7146. }
  7147. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7148. }
  7149. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7150. /// 01d2 <account id>.L <delay>.L
  7151. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7152. {
  7153. unsigned char buf[32];
  7154. nullpo_retv(bl);
  7155. WBUFW(buf,0)=0x1d2;
  7156. WBUFL(buf,2)=bl->id;
  7157. WBUFL(buf,6)=client_tick(wait);
  7158. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7159. }
  7160. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7161. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7162. /// flag:
  7163. /// 0 = inactive
  7164. /// 1 = active
  7165. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7166. {
  7167. unsigned char buf[32];
  7168. nullpo_retv(src);
  7169. WBUFW(buf,0)=0x1d1;
  7170. WBUFL(buf,2)=src->id;
  7171. WBUFL(buf,6)=dst_id;
  7172. WBUFL(buf,10)=active;
  7173. clif_send(buf,packet_len(0x1d1),src,AREA);
  7174. }
  7175. /// MVP effect (ZC_MVP).
  7176. /// 010c <account id>.L
  7177. void clif_mvp_effect(map_session_data *sd)
  7178. {
  7179. unsigned char buf[16];
  7180. nullpo_retv(sd);
  7181. WBUFW(buf,0)=0x10c;
  7182. WBUFL(buf,2)=sd->bl.id;
  7183. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7184. }
  7185. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7186. /// 010a <name id>.W
  7187. void clif_mvp_item( map_session_data *sd, t_itemid nameid ){
  7188. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7189. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7190. p.itemId = client_nameid( nameid );
  7191. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7192. }
  7193. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7194. /// 010b <exp>.L
  7195. void clif_mvp_exp(map_session_data *sd, t_exp exp) {
  7196. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7197. if (battle_config.mvp_exp_reward_message) {
  7198. char e_msg[CHAT_SIZE_MAX];
  7199. sprintf(e_msg, msg_txt(sd, 717), exp);
  7200. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7201. }
  7202. #else
  7203. int fd;
  7204. nullpo_retv(sd);
  7205. fd = sd->fd;
  7206. WFIFOHEAD(fd, packet_len(0x10b));
  7207. WFIFOW(fd,0) = 0x10b;
  7208. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7209. WFIFOSET(fd, packet_len(0x10b));
  7210. #endif
  7211. }
  7212. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7213. /// 010d
  7214. ///
  7215. /// "You are the MVP, but cannot obtain the reward because
  7216. /// you are overweight."
  7217. void clif_mvp_noitem(map_session_data* sd)
  7218. {
  7219. int fd = sd->fd;
  7220. WFIFOHEAD(fd,packet_len(0x10d));
  7221. WFIFOW(fd,0) = 0x10d;
  7222. WFIFOSET(fd,packet_len(0x10d));
  7223. }
  7224. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7225. /// 0167 <result>.B
  7226. /// result:
  7227. /// 0 = "Guild has been created."
  7228. /// 1 = "You are already in a Guild."
  7229. /// 2 = "That Guild Name already exists."
  7230. /// 3 = "You need the neccessary item to create a Guild."
  7231. void clif_guild_created(map_session_data *sd,int flag)
  7232. {
  7233. int fd;
  7234. nullpo_retv(sd);
  7235. fd=sd->fd;
  7236. WFIFOHEAD(fd,packet_len(0x167));
  7237. WFIFOW(fd,0)=0x167;
  7238. WFIFOB(fd,2)=flag;
  7239. WFIFOSET(fd,packet_len(0x167));
  7240. }
  7241. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7242. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7243. /// mode:
  7244. /// &0x01 = allow invite
  7245. /// &0x10 = allow expel
  7246. void clif_guild_belonginfo( map_session_data& sd ){
  7247. if( sd.guild == nullptr ){
  7248. return;
  7249. }
  7250. const auto &guild = sd.guild->guild;
  7251. int position = guild_getposition(sd);
  7252. if( position < 0 ){
  7253. return;
  7254. }
  7255. struct PACKET_ZC_UPDATE_GDID p = {};
  7256. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7257. p.guildId = guild.guild_id;
  7258. p.emblemVersion = guild.emblem_id;
  7259. p.mode = guild.position[position].mode;
  7260. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7261. p.interSid = 0; // InterSID (unknown purpose)
  7262. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7263. #if PACKETVER_MAIN_NUM >= 20220216
  7264. p.masterGID = guild.member[0].char_id;
  7265. #endif
  7266. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7267. }
  7268. /// Guild member login notice.
  7269. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7270. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7271. /// status:
  7272. /// 0 = offline
  7273. /// 1 = online
  7274. void clif_guild_memberlogin_notice(const struct mmo_guild &g,int idx,int flag)
  7275. {
  7276. unsigned char buf[64];
  7277. map_session_data* sd;
  7278. WBUFW(buf, 0)=0x1f2;
  7279. WBUFL(buf, 2)=g.member[idx].account_id;
  7280. WBUFL(buf, 6)=g.member[idx].char_id;
  7281. WBUFL(buf,10)=flag;
  7282. if( ( sd = g.member[idx].sd ) != nullptr )
  7283. {
  7284. WBUFW(buf,14) = sd->status.sex;
  7285. WBUFW(buf,16) = sd->status.hair;
  7286. WBUFW(buf,18) = sd->status.hair_color;
  7287. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7288. }
  7289. else if( ( sd = guild_getavailablesd(g) ) != nullptr )
  7290. {
  7291. WBUFW(buf,14) = 0;
  7292. WBUFW(buf,16) = 0;
  7293. WBUFW(buf,18) = 0;
  7294. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7295. }
  7296. }
  7297. // Function `clif_guild_memberlogin_notice` sends info about
  7298. // logins and logouts of a guild member to the rest members.
  7299. // But at the 1st time (after a player login or map changing)
  7300. // the client won't show the message.
  7301. // So I suggest use this function for sending "first-time-info"
  7302. // to some player on entering the game or changing location.
  7303. // At next time the client would always show the message.
  7304. // The function sends all the statuses in the single packet
  7305. // to economize traffic. [LuzZza]
  7306. void clif_guild_send_onlineinfo(map_session_data *sd)
  7307. {
  7308. unsigned char buf[14*128];
  7309. int i, count=0, p_len;
  7310. nullpo_retv(sd);
  7311. p_len = packet_len(0x16d);
  7312. auto &g = sd->guild;
  7313. if (!g)
  7314. return;
  7315. for(i=0; i<g->guild.max_member; i++) {
  7316. if(g->guild.member[i].account_id > 0 &&
  7317. g->guild.member[i].account_id != sd->status.account_id) {
  7318. WBUFW(buf,count*p_len) = 0x16d;
  7319. WBUFL(buf,count*p_len+2) = g->guild.member[i].account_id;
  7320. WBUFL(buf,count*p_len+6) = g->guild.member[i].char_id;
  7321. WBUFL(buf,count*p_len+10) = g->guild.member[i].online;
  7322. count++;
  7323. }
  7324. }
  7325. clif_send(buf, p_len*count, &sd->bl, SELF);
  7326. }
  7327. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7328. /// 014e <menu flag>.L
  7329. /// menu flag:
  7330. /// 0x00 = Basic Info (always on)
  7331. /// &0x01 = Member manager
  7332. /// &0x02 = Positions
  7333. /// &0x04 = Skills
  7334. /// &0x10 = Expulsion list
  7335. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7336. /// &0x80 = Notice
  7337. void clif_guild_masterormember(map_session_data *sd)
  7338. {
  7339. int fd;
  7340. nullpo_retv(sd);
  7341. fd=sd->fd;
  7342. WFIFOHEAD(fd,packet_len(0x14e));
  7343. WFIFOW(fd,0) = 0x14e;
  7344. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7345. WFIFOSET(fd,packet_len(0x14e));
  7346. }
  7347. /// Guild basic information (Territories [Valaris])
  7348. /// 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)
  7349. /// 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)
  7350. /// 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)
  7351. void clif_guild_basicinfo( map_session_data& sd ){
  7352. if( sd.guild == nullptr ){
  7353. return;
  7354. }
  7355. const auto &guild = sd.guild->guild;
  7356. struct PACKET_ZC_GUILD_INFO p = {};
  7357. p.PacketType = HEADER_ZC_GUILD_INFO;
  7358. p.GDID = guild.guild_id;
  7359. p.level = guild.guild_lv;
  7360. p.userNum = guild.connect_member;
  7361. p.maxUserNum = guild.max_member;
  7362. p.userAverageLevel = guild.average_lv;
  7363. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7364. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7365. p.point = 0; // Tax Points
  7366. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7367. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7368. p.emblemVersion = guild.emblem_id;
  7369. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7370. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( guild ) ), sizeof( p.manageLand ) );
  7371. p.zeny = 0;
  7372. #if PACKETVER >= 20200902
  7373. p.masterGID = guild.member[0].char_id; // leader
  7374. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7375. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7376. p.masterGID = guild.member[0].char_id; // leader
  7377. #else
  7378. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7379. #endif
  7380. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7381. }
  7382. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7383. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7384. void clif_guild_allianceinfo(map_session_data *sd)
  7385. {
  7386. int fd,i,c;
  7387. nullpo_retv(sd);
  7388. auto &g = sd->guild;
  7389. if (!g)
  7390. return;
  7391. fd = sd->fd;
  7392. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7393. WFIFOW(fd, 0)=0x14c;
  7394. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7395. struct guild_alliance *a=&g->guild.alliance[i];
  7396. if(a->guild_id>0){
  7397. WFIFOL(fd,c*32+4)=a->opposition;
  7398. WFIFOL(fd,c*32+8)=a->guild_id;
  7399. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7400. c++;
  7401. }
  7402. }
  7403. WFIFOW(fd, 2)=c*32+4;
  7404. WFIFOSET(fd,WFIFOW(fd,2));
  7405. }
  7406. /// Guild member manager information
  7407. /// 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)
  7408. /// state:
  7409. /// 0 = offline
  7410. /// 1 = online
  7411. /// memo:
  7412. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7413. /// 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)
  7414. void clif_guild_memberlist( map_session_data& sd ){
  7415. if( sd.guild == nullptr ){
  7416. return;
  7417. }
  7418. const auto &guild = sd.guild->guild;
  7419. PACKET_ZC_MEMBERMGR_INFO* p = reinterpret_cast<PACKET_ZC_MEMBERMGR_INFO*>( packet_buffer );
  7420. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7421. p->packetLength = sizeof( *p );
  7422. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7423. const auto &member = guild.member[i];
  7424. if( member.account_id == 0 ){
  7425. continue;
  7426. }
  7427. GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7428. member_info.AID = member.account_id;
  7429. member_info.GID = member.char_id;
  7430. member_info.head = member.hair;
  7431. member_info.headPalette = member.hair_color;
  7432. member_info.sex = member.gender;
  7433. member_info.job = member.class_;
  7434. member_info.level = member.lv;
  7435. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7436. member_info.currentState = member.online;
  7437. member_info.positionID = member.position;
  7438. #if PACKETVER >= 20200902
  7439. member_info.lastLoginTime = member.last_login;
  7440. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7441. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7442. member_info.lastLoginTime = member.last_login;
  7443. #else
  7444. 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.
  7445. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7446. #endif
  7447. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( member_info ) );
  7448. c++;
  7449. }
  7450. clif_send( p, p->packetLength, &sd.bl, SELF );
  7451. }
  7452. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7453. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7454. void clif_guild_positionnamelist(map_session_data *sd)
  7455. {
  7456. int i,fd;
  7457. nullpo_retv(sd);
  7458. auto &g = sd->guild;
  7459. if (!g)
  7460. return;
  7461. fd = sd->fd;
  7462. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7463. WFIFOW(fd, 0)=0x166;
  7464. for(i=0;i<MAX_GUILDPOSITION;i++){
  7465. WFIFOL(fd,i*28+4)=i;
  7466. safestrncpy(WFIFOCP(fd,i*28+8),g->guild.position[i].name,NAME_LENGTH);
  7467. }
  7468. WFIFOW(fd,2)=i*28+4;
  7469. WFIFOSET(fd,WFIFOW(fd,2));
  7470. }
  7471. /// Guild position information (ZC_POSITION_INFO).
  7472. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7473. /// mode:
  7474. /// &0x01 = allow invite
  7475. /// &0x10 = allow expel
  7476. /// ranking:
  7477. /// TODO
  7478. void clif_guild_positioninfolist(map_session_data *sd)
  7479. {
  7480. int i,fd;
  7481. nullpo_retv(sd);
  7482. auto &g = sd->guild;
  7483. if (!g)
  7484. return;
  7485. fd = sd->fd;
  7486. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7487. WFIFOW(fd, 0)=0x160;
  7488. for(i=0;i<MAX_GUILDPOSITION;i++){
  7489. struct guild_position *p=&g->guild.position[i];
  7490. WFIFOL(fd,i*16+ 4)=i;
  7491. WFIFOL(fd,i*16+ 8)=p->mode;
  7492. WFIFOL(fd,i*16+12)=i;
  7493. WFIFOL(fd,i*16+16)=p->exp_mode;
  7494. }
  7495. WFIFOW(fd, 2)=i*16+4;
  7496. WFIFOSET(fd,WFIFOW(fd,2));
  7497. }
  7498. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7499. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7500. /// mode:
  7501. /// &0x01 = allow invite
  7502. /// &0x10 = allow expel
  7503. /// ranking:
  7504. /// TODO
  7505. void clif_guild_positionchanged(const struct mmo_guild &g,int idx)
  7506. {
  7507. // FIXME: This packet is intended to update the clients after a
  7508. // commit of position info changes, not sending one packet per
  7509. // position.
  7510. map_session_data *sd;
  7511. unsigned char buf[128];
  7512. WBUFW(buf, 0)=0x174;
  7513. WBUFW(buf, 2)=44; // packet len
  7514. // GUILD_REG_POSITION_INFO{
  7515. WBUFL(buf, 4)=idx;
  7516. WBUFL(buf, 8)=g.position[idx].mode;
  7517. WBUFL(buf,12)=idx;
  7518. WBUFL(buf,16)=g.position[idx].exp_mode;
  7519. safestrncpy(WBUFCP(buf,20),g.position[idx].name,NAME_LENGTH);
  7520. // }*
  7521. if( (sd=guild_getavailablesd(g))!=nullptr )
  7522. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7523. }
  7524. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7525. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7526. void clif_guild_memberpositionchanged(const struct mmo_guild &g, int idx)
  7527. {
  7528. // FIXME: This packet is intended to update the clients after a
  7529. // commit of member position assignment changes, not sending one
  7530. // packet per position.
  7531. map_session_data *sd;
  7532. unsigned char buf[64];
  7533. WBUFW(buf, 0)=0x156;
  7534. WBUFW(buf, 2)=16; // packet len
  7535. // MEMBER_POSITION_INFO{
  7536. WBUFL(buf, 4)=g.member[idx].account_id;
  7537. WBUFL(buf, 8)=g.member[idx].char_id;
  7538. WBUFL(buf,12)=g.member[idx].position;
  7539. // }*
  7540. if( (sd=guild_getavailablesd(g))!=nullptr )
  7541. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7542. }
  7543. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7544. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7545. void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g)
  7546. {
  7547. int fd = sd.fd;
  7548. if( g.emblem_len <= 0 )
  7549. return;
  7550. WFIFOHEAD(fd,g.emblem_len+12);
  7551. WFIFOW(fd,0)=0x152;
  7552. WFIFOW(fd,2)=g.emblem_len+12;
  7553. WFIFOL(fd,4)=g.guild_id;
  7554. WFIFOL(fd,8)=g.emblem_id;
  7555. memcpy(WFIFOP(fd,12),g.emblem_data,g.emblem_len);
  7556. WFIFOSET(fd,WFIFOW(fd,2));
  7557. }
  7558. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7559. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7560. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7561. void clif_guild_emblem_area(struct block_list* bl)
  7562. {
  7563. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7564. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7565. PACKET_ZC_CHANGE_GUILD p{};
  7566. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7567. p.guild_id = status_get_guild_id(bl);
  7568. p.emblem_id = status_get_emblem_id(bl);
  7569. p.AID = bl->id;
  7570. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7571. }
  7572. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7573. /// 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 }*
  7574. void clif_guild_skillinfo(map_session_data* sd)
  7575. {
  7576. int fd;
  7577. int i,c;
  7578. nullpo_retv(sd);
  7579. auto &g = sd->guild;
  7580. if (!g)
  7581. return;
  7582. fd = sd->fd;
  7583. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7584. WFIFOW(fd,0) = 0x0162;
  7585. WFIFOW(fd,4) = g->guild.skill_point;
  7586. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7587. {
  7588. if(g->guild.skill[i].id > 0 && guild_check_skill_require(g->guild, g->guild.skill[i].id))
  7589. {
  7590. int id = g->guild.skill[i].id;
  7591. int p = 6 + c*37;
  7592. WFIFOW(fd,p+0) = id;
  7593. WFIFOL(fd,p+2) = skill_get_inf(id);
  7594. WFIFOW(fd,p+6) = g->guild.skill[i].lv;
  7595. WFIFOW(fd,p+8) = skill_get_sp(id, g->guild.skill[i].lv);
  7596. WFIFOW(fd,p+10) = skill_get_range(id, g->guild.skill[i].lv);
  7597. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7598. WFIFOB(fd,p+36)= (g->guild.skill[i].lv < guild_skill_get_max(id) && sd == g->guild.member[0].sd) ? 1 : 0;
  7599. c++;
  7600. }
  7601. }
  7602. WFIFOW(fd,2) = 6 + c*37;
  7603. WFIFOSET(fd,WFIFOW(fd,2));
  7604. }
  7605. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7606. /// 016f <subject>.60B <notice>.120B
  7607. void clif_guild_notice(map_session_data* sd)
  7608. {
  7609. nullpo_retv(sd);
  7610. auto &g = sd->guild;
  7611. int fd = sd->fd;
  7612. if ( !session_isActive(fd) )
  7613. return;
  7614. if(g->guild.mes1[0] == '\0' && g->guild.mes2[0] == '\0')
  7615. return;
  7616. WFIFOHEAD(fd,packet_len(0x16f));
  7617. WFIFOW(fd,0) = 0x16f;
  7618. memcpy(WFIFOP(fd,2), g->guild.mes1, MAX_GUILDMES1);
  7619. memcpy(WFIFOP(fd,62), g->guild.mes2, MAX_GUILDMES2);
  7620. WFIFOSET(fd,packet_len(0x16f));
  7621. }
  7622. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7623. /// 016a <guild id>.L <guild name>.24B
  7624. void clif_guild_invite(const map_session_data &sd, const struct mmo_guild &g)
  7625. {
  7626. int fd = sd.fd;
  7627. WFIFOHEAD(fd,packet_len(0x16a));
  7628. WFIFOW(fd,0)=0x16a;
  7629. WFIFOL(fd,2)=g.guild_id;
  7630. safestrncpy(WFIFOCP(fd,6),g.name,NAME_LENGTH);
  7631. WFIFOSET(fd,packet_len(0x16a));
  7632. }
  7633. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7634. /// 0169 <answer>.B
  7635. /// answer:
  7636. /// 0 = Already in guild.
  7637. /// 1 = Offer rejected.
  7638. /// 2 = Offer accepted.
  7639. /// 3 = Guild full.
  7640. void clif_guild_inviteack(map_session_data *sd,int flag)
  7641. {
  7642. int fd;
  7643. nullpo_retv(sd);
  7644. fd=sd->fd;
  7645. WFIFOHEAD(fd,packet_len(0x169));
  7646. WFIFOW(fd,0)=0x169;
  7647. WFIFOB(fd,2)=flag;
  7648. WFIFOSET(fd,packet_len(0x169));
  7649. }
  7650. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7651. /// 015a <char name>.24B <reason>.40B
  7652. void clif_guild_leave(map_session_data *sd,const char *name,const char *mes)
  7653. {
  7654. unsigned char buf[128];
  7655. nullpo_retv(sd);
  7656. WBUFW(buf, 0)=0x15a;
  7657. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7658. memcpy(WBUFP(buf,26),mes,40);
  7659. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7660. }
  7661. /// Notifies clients of a guild of an expelled member.
  7662. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7663. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7664. void clif_guild_expulsion(map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7665. {
  7666. unsigned char buf[128];
  7667. #if PACKETVER < 20100803
  7668. const unsigned short cmd = 0x15c;
  7669. #else
  7670. const unsigned short cmd = 0x839;
  7671. #endif
  7672. nullpo_retv(sd);
  7673. WBUFW(buf,0) = cmd;
  7674. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7675. safestrncpy(WBUFCP(buf,26), mes, 40);
  7676. #if PACKETVER < 20100803
  7677. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7678. #endif
  7679. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7680. }
  7681. /// Guild expulsion list (ZC_BAN_LIST).
  7682. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7683. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7684. void clif_guild_expulsionlist(map_session_data* sd)
  7685. {
  7686. #if PACKETVER < 20100803
  7687. const int offset = NAME_LENGTH*2+40;
  7688. #else
  7689. const int offset = NAME_LENGTH+40;
  7690. #endif
  7691. int fd, i, c = 0;
  7692. nullpo_retv(sd);
  7693. auto &g = sd->guild;
  7694. if (!g)
  7695. return;
  7696. fd = sd->fd;
  7697. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7698. WFIFOW(fd,0) = 0x163;
  7699. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7700. {
  7701. struct guild_expulsion* e = &g->guild.expulsion[i];
  7702. if( e->account_id > 0 )
  7703. {
  7704. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7705. #if PACKETVER < 20100803
  7706. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7707. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7708. #else
  7709. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7710. #endif
  7711. c++;
  7712. }
  7713. }
  7714. WFIFOW(fd,2) = 4 + c*offset;
  7715. WFIFOSET(fd,WFIFOW(fd,2));
  7716. }
  7717. /// Guild chat message (ZC_GUILD_CHAT).
  7718. /// 017f <packet len>.W <message>.?B
  7719. void clif_guild_message(const struct mmo_guild &g,uint32 account_id,const char *mes,int len)
  7720. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7721. map_session_data *sd;
  7722. uint8 buf[256];
  7723. if( len == 0 )
  7724. {
  7725. return;
  7726. }
  7727. else if( len > sizeof(buf)-5 )
  7728. {
  7729. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g.guild_id);
  7730. len = sizeof(buf)-5;
  7731. }
  7732. WBUFW(buf, 0) = 0x17f;
  7733. WBUFW(buf, 2) = len + 5;
  7734. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7735. if ((sd = guild_getavailablesd(g)) != nullptr)
  7736. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7737. }
  7738. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7739. /// 0171 <inviter account id>.L <guild name>.24B
  7740. void clif_guild_reqalliance(map_session_data *sd,uint32 account_id,const char *name)
  7741. {
  7742. int fd;
  7743. nullpo_retv(sd);
  7744. fd=sd->fd;
  7745. WFIFOHEAD(fd,packet_len(0x171));
  7746. WFIFOW(fd,0)=0x171;
  7747. WFIFOL(fd,2)=account_id;
  7748. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7749. WFIFOSET(fd,packet_len(0x171));
  7750. }
  7751. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7752. /// 0173 <answer>.B
  7753. /// answer:
  7754. /// 0 = Already allied.
  7755. /// 1 = You rejected the offer.
  7756. /// 2 = You accepted the offer.
  7757. /// 3 = They have too any alliances.
  7758. /// 4 = You have too many alliances.
  7759. /// 5 = Alliances are disabled.
  7760. void clif_guild_allianceack(map_session_data *sd,int flag)
  7761. {
  7762. int fd;
  7763. nullpo_retv(sd);
  7764. fd=sd->fd;
  7765. WFIFOHEAD(fd,packet_len(0x173));
  7766. WFIFOW(fd,0)=0x173;
  7767. WFIFOL(fd,2)=flag;
  7768. WFIFOSET(fd,packet_len(0x173));
  7769. }
  7770. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7771. /// 0184 <other guild id>.L <relation>.L
  7772. /// relation:
  7773. /// 0 = Ally
  7774. /// 1 = Enemy
  7775. void clif_guild_delalliance(map_session_data *sd,int guild_id,int flag)
  7776. {
  7777. nullpo_retv(sd);
  7778. int fd = sd->fd;
  7779. if ( !session_isActive(fd) )
  7780. return;
  7781. WFIFOHEAD(fd,packet_len(0x184));
  7782. WFIFOW(fd,0)=0x184;
  7783. WFIFOL(fd,2)=guild_id;
  7784. WFIFOL(fd,6)=flag;
  7785. WFIFOSET(fd,packet_len(0x184));
  7786. }
  7787. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7788. /// 0181 <result>.B
  7789. /// result:
  7790. /// 0 = Antagonist has been set.
  7791. /// 1 = Guild has too many Antagonists.
  7792. /// 2 = Already set as an Antagonist.
  7793. /// 3 = Antagonists are disabled.
  7794. void clif_guild_oppositionack(map_session_data *sd,int flag)
  7795. {
  7796. int fd;
  7797. nullpo_retv(sd);
  7798. fd=sd->fd;
  7799. WFIFOHEAD(fd,packet_len(0x181));
  7800. WFIFOW(fd,0)=0x181;
  7801. WFIFOB(fd,2)=flag;
  7802. WFIFOSET(fd,packet_len(0x181));
  7803. }
  7804. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7805. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7806. /*
  7807. void clif_guild_allianceadded(struct guild *g,int idx)
  7808. {
  7809. unsigned char buf[64];
  7810. WBUFW(buf,0)=0x185;
  7811. WBUFL(buf,2)=g->alliance[idx].opposition;
  7812. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7813. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7814. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7815. }
  7816. */
  7817. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7818. /// 015e <reason>.L
  7819. /// 0 = success
  7820. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7821. /// 2 = there are still members in the guild
  7822. void clif_guild_broken(map_session_data *sd,int flag)
  7823. {
  7824. int fd;
  7825. nullpo_retv(sd);
  7826. fd=sd->fd;
  7827. WFIFOHEAD(fd,packet_len(0x15e));
  7828. WFIFOW(fd,0)=0x15e;
  7829. WFIFOL(fd,2)=flag;
  7830. WFIFOSET(fd,packet_len(0x15e));
  7831. }
  7832. /// Displays emotion on an object (ZC_EMOTION).
  7833. /// 00c0 <id>.L <type>.B
  7834. /// type:
  7835. /// enum emotion_type
  7836. void clif_emotion(struct block_list *bl,int type)
  7837. {
  7838. unsigned char buf[8];
  7839. nullpo_retv(bl);
  7840. WBUFW(buf,0)=0xc0;
  7841. WBUFL(buf,2)=bl->id;
  7842. WBUFB(buf,6)=type;
  7843. clif_send(buf,packet_len(0xc0),bl,AREA);
  7844. }
  7845. /// Displays the contents of a talkiebox trap.
  7846. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7847. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7848. nullpo_retv( bl );
  7849. nullpo_retv( talkie );
  7850. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7851. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7852. p.aid = bl->id;
  7853. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7854. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7855. }
  7856. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7857. /// 01ea <id>.L
  7858. void clif_wedding_effect(struct block_list *bl)
  7859. {
  7860. unsigned char buf[6];
  7861. nullpo_retv(bl);
  7862. WBUFW(buf,0) = 0x1ea;
  7863. WBUFL(buf,2) = bl->id;
  7864. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7865. }
  7866. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7867. /// 01e6 <partner name>.24B
  7868. void clif_callpartner(map_session_data& sd)
  7869. {
  7870. PACKET_ZC_COUPLENAME p = { 0 };
  7871. p.packetType = HEADER_ZC_COUPLENAME;
  7872. if( sd.status.partner_id ) {
  7873. map_session_data *p_sd = pc_get_partner(&sd);
  7874. if (p_sd != nullptr && !p_sd->state.autotrade)
  7875. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  7876. else
  7877. p.name[0] = 0;
  7878. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7879. p.name[0] = 0;
  7880. }
  7881. clif_send(&p, sizeof(p), &sd.bl, AREA);
  7882. }
  7883. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7884. /// 01e4
  7885. /// This packet while still implemented by the client is no longer being officially used.
  7886. /*
  7887. void clif_marriage_process(map_session_data *sd)
  7888. {
  7889. int fd;
  7890. nullpo_retv(sd);
  7891. fd=sd->fd;
  7892. WFIFOHEAD(fd,packet_len(0x1e4));
  7893. WFIFOW(fd,0)=0x1e4;
  7894. WFIFOSET(fd,packet_len(0x1e4));
  7895. }
  7896. */
  7897. /// Notice of divorce (ZC_DIVORCE).
  7898. /// 0205 <partner name>.24B
  7899. void clif_divorced(map_session_data* sd, const char* name)
  7900. {
  7901. int fd;
  7902. nullpo_retv(sd);
  7903. fd=sd->fd;
  7904. WFIFOHEAD(fd,packet_len(0x205));
  7905. WFIFOW(fd,0)=0x205;
  7906. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7907. WFIFOSET(fd, packet_len(0x205));
  7908. }
  7909. /// Marriage proposal (ZC_REQ_COUPLE).
  7910. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7911. /// This packet while still implemented by the client is no longer being officially used.
  7912. /*
  7913. void clif_marriage_proposal(int fd, map_session_data *sd, map_session_data* ssd)
  7914. {
  7915. nullpo_retv(sd);
  7916. WFIFOHEAD(fd,packet_len(0x1e2));
  7917. WFIFOW(fd,0) = 0x1e2;
  7918. WFIFOL(fd,2) = ssd->status.account_id;
  7919. WFIFOL(fd,6) = ssd->status.char_id;
  7920. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7921. WFIFOSET(fd, packet_len(0x1e2));
  7922. }
  7923. */
  7924. /*==========================================
  7925. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7926. *------------------------------------------*/
  7927. void clif_disp_message(struct block_list* src, const char* mes, size_t len, enum send_target target)
  7928. {
  7929. unsigned char buf[256];
  7930. if( len == 0 ) {
  7931. return;
  7932. } else if( len > sizeof(buf)-5 ) {
  7933. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7934. len = sizeof(buf)-5;
  7935. }
  7936. WBUFW(buf, 0) = 0x17f;
  7937. WBUFW(buf, 2) = static_cast<int16>( len + 5 );
  7938. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7939. clif_send(buf, WBUFW(buf,2), src, target);
  7940. }
  7941. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7942. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7943. /// 00cd <result>.B
  7944. /// result:
  7945. /// 0 = failure
  7946. /// 1 = success
  7947. void clif_GM_kickack(map_session_data *sd, int id)
  7948. {
  7949. int fd;
  7950. nullpo_retv(sd);
  7951. fd = sd->fd;
  7952. WFIFOHEAD(fd,packet_len(0xcd));
  7953. WFIFOW(fd,0) = 0xcd;
  7954. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7955. WFIFOSET(fd, packet_len(0xcd));
  7956. }
  7957. void clif_GM_kick(map_session_data *sd, map_session_data *tsd)
  7958. {
  7959. nullpo_retv(tsd);
  7960. if (sd == nullptr)
  7961. tsd->state.keepshop = true;
  7962. if (session_isActive(tsd->fd))
  7963. clif_authfail_fd(tsd->fd, 15);
  7964. else
  7965. map_quit(tsd);
  7966. if (sd)
  7967. clif_GM_kickack(sd, tsd->status.account_id);
  7968. }
  7969. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7970. /// 014a <result>.L
  7971. /// result:
  7972. /// 0 = "A manner point has been successfully aligned."
  7973. /// 1 = MP_FAILURE_EXHAUST
  7974. /// 2 = MP_FAILURE_ALREADY_GIVING
  7975. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7976. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7977. /// 5 = "You got a good point from %s."
  7978. void clif_manner_message(map_session_data* sd, uint32 type)
  7979. {
  7980. int fd;
  7981. nullpo_retv(sd);
  7982. fd = sd->fd;
  7983. WFIFOHEAD(fd,packet_len(0x14a));
  7984. WFIFOW(fd,0) = 0x14a;
  7985. WFIFOL(fd,2) = type;
  7986. WFIFOSET(fd, packet_len(0x14a));
  7987. }
  7988. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7989. /// 014b <type>.B <GM name>.24B
  7990. /// type:
  7991. /// 0 = positive (unmute)
  7992. /// 1 = negative (mute)
  7993. void clif_GM_silence(map_session_data* sd, map_session_data* tsd, uint8 type)
  7994. {
  7995. int fd;
  7996. nullpo_retv(sd);
  7997. nullpo_retv(tsd);
  7998. fd = tsd->fd;
  7999. WFIFOHEAD(fd,packet_len(0x14b));
  8000. WFIFOW(fd,0) = 0x14b;
  8001. WFIFOB(fd,2) = type;
  8002. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8003. WFIFOSET(fd, packet_len(0x14b));
  8004. }
  8005. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8006. /// 00d1 <type>.B <result>.B
  8007. /// type:
  8008. /// 0 = /ex (deny)
  8009. /// 1 = /in (allow)
  8010. /// result:
  8011. /// 0 = success
  8012. /// 1 = failure
  8013. /// 2 = too many blocks
  8014. void clif_wisexin(map_session_data *sd,int type,int flag)
  8015. {
  8016. int fd;
  8017. nullpo_retv(sd);
  8018. fd=sd->fd;
  8019. WFIFOHEAD(fd,packet_len(0xd1));
  8020. WFIFOW(fd,0)=0xd1;
  8021. WFIFOB(fd,2)=type;
  8022. WFIFOB(fd,3)=flag;
  8023. WFIFOSET(fd,packet_len(0xd1));
  8024. }
  8025. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8026. /// 00d2 <type>.B <result>.B
  8027. /// type:
  8028. /// 0 = /exall (deny)
  8029. /// 1 = /inall (allow)
  8030. /// result:
  8031. /// 0 = success
  8032. /// 1 = failure
  8033. void clif_wisall(map_session_data *sd,int type,int flag)
  8034. {
  8035. int fd;
  8036. nullpo_retv(sd);
  8037. fd=sd->fd;
  8038. WFIFOHEAD(fd,packet_len(0xd2));
  8039. WFIFOW(fd,0)=0xd2;
  8040. WFIFOB(fd,2)=type;
  8041. WFIFOB(fd,3)=flag;
  8042. WFIFOSET(fd,packet_len(0xd2));
  8043. }
  8044. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8045. /// 07fe <bgm>.24B
  8046. void clif_playBGM( map_session_data& sd, const char* name ){
  8047. #if PACKETVER_MAIN_NUM >= 20220504
  8048. PACKET_ZC_PLAY_NPC_BGM* p = reinterpret_cast<PACKET_ZC_PLAY_NPC_BGM*>( packet_buffer );
  8049. size_t length = strlen( name ) + 1;
  8050. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8051. p->PacketLength = sizeof( *p );
  8052. p->playType = 0; // TODO: implement, send loop for the time being
  8053. safestrncpy( p->bgm, name, length );
  8054. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  8055. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8056. #elif PACKETVER >= 20091201
  8057. PACKET_ZC_PLAY_NPC_BGM p = {};
  8058. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8059. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8060. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8061. #endif
  8062. }
  8063. /// Plays/stops a wave sound (ZC_SOUND).
  8064. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8065. /// file name:
  8066. /// relative to data\wav
  8067. /// act:
  8068. /// 0 = play (once)
  8069. /// 1 = play (repeat, does not work)
  8070. /// 2 = stops all sound instances of file name (does not work)
  8071. /// term:
  8072. /// unknown purpose, only relevant to act = 1
  8073. /// npc id:
  8074. /// The accustic direction of the sound is determined by the
  8075. /// relative position of the NPC to the player (3D sound).
  8076. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8077. struct PACKET_ZC_SOUND p = {};
  8078. p.PacketType = HEADER_ZC_SOUND;
  8079. safestrncpy( p.name, name, sizeof( p.name ) );
  8080. p.act = type;
  8081. p.term = 0; // TODO: implement
  8082. p.AID = bl.id;
  8083. clif_send( &p, sizeof( p ), &bl, target );
  8084. }
  8085. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8086. /// 01f3 <id>.L <effect id>.L
  8087. /// effect id:
  8088. /// @see doc/effect_list.txt
  8089. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8090. {
  8091. unsigned char buf[24];
  8092. nullpo_retv(bl);
  8093. memset(buf, 0, packet_len(0x1f3));
  8094. WBUFW(buf,0) = 0x1f3;
  8095. WBUFL(buf,2) = bl->id;
  8096. WBUFL(buf,6) = type;
  8097. clif_send(buf, packet_len(0x1f3), bl, target);
  8098. if (disguised(bl)) {
  8099. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8100. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8101. }
  8102. }
  8103. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8104. {
  8105. WFIFOHEAD(fd,10);
  8106. WFIFOW(fd,0) = 0x1f3;
  8107. WFIFOL(fd,2) = bl->id;
  8108. WFIFOL(fd,6) = type;
  8109. WFIFOSET(fd,10);
  8110. }
  8111. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8112. /// 0284 <id>.L <effect id>.L <num data>.L
  8113. /// effect id:
  8114. /// @see doc/effect_list.txt
  8115. /// num data:
  8116. /// effect-dependent value
  8117. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8118. {
  8119. uint8 buf[14];
  8120. WBUFW(buf,0) = 0x284;
  8121. WBUFL(buf,2) = bl->id;
  8122. WBUFL(buf,6) = effect_id;
  8123. WBUFL(buf,10) = num;
  8124. clif_send(buf, packet_len(0x284), bl, target);
  8125. if( disguised(bl) )
  8126. {
  8127. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8128. clif_send(buf, packet_len(0x284), bl, SELF);
  8129. }
  8130. }
  8131. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8132. {
  8133. #if PACKETVER >= 20181002
  8134. nullpo_retv( bl_src );
  8135. nullpo_retv( bl_target );
  8136. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8137. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8138. p.aid = bl_src->id;
  8139. p.effectId = effect;
  8140. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8141. if( disguised(bl_src) )
  8142. {
  8143. p.aid = disguised_bl_id( bl_src->id );
  8144. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8145. }
  8146. #endif
  8147. }
  8148. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8149. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8150. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, map_session_data *sd) {
  8151. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8152. uint8 buf[CHAT_SIZE_MAX];
  8153. nullpo_retv(bl);
  8154. if (msg_len > sizeof(buf) - 12) {
  8155. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8156. msg_len = sizeof(buf) - 12;
  8157. }
  8158. if (rgb2bgr)
  8159. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8160. WBUFW(buf,0) = 0x2C1;
  8161. WBUFW(buf,2) = msg_len + 12;
  8162. WBUFL(buf,4) = bl->id;
  8163. WBUFL(buf,8) = color;
  8164. memcpy(WBUFCP(buf,12), msg, msg_len);
  8165. clif_send(buf, WBUFW(buf,2), (sd == nullptr ? bl : &(sd->bl)), type);
  8166. }
  8167. /**
  8168. * Notifies the client that the storage window is still open
  8169. *
  8170. * Should only be used in cases where the client closed the
  8171. * storage window without server's consent
  8172. */
  8173. void clif_refresh_storagewindow(map_session_data *sd) {
  8174. // Notify the client that the storage is open
  8175. if( sd->state.storage_flag == 1 ) {
  8176. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8177. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8178. clif_updatestorageamount(*sd, sd->storage.amount, sd->storage.max_amount);
  8179. }
  8180. // Notify the client that the gstorage is open otherwise it will
  8181. // remain locked forever and nobody will be able to access it
  8182. if( sd->state.storage_flag == 2 ) {
  8183. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8184. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8185. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8186. else {
  8187. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8188. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8189. clif_updatestorageamount(*sd, gstor->amount, gstor->max_amount);
  8190. }
  8191. }
  8192. // Notify the client that the premium storage is open
  8193. if (sd->state.storage_flag == 3) {
  8194. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8195. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8196. clif_updatestorageamount(*sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8197. }
  8198. }
  8199. // refresh the client's screen, getting rid of any effects
  8200. void clif_refresh(map_session_data *sd)
  8201. {
  8202. nullpo_retv(sd);
  8203. clif_changemap( *sd, sd->bl.m, sd->bl.x, sd->bl.y );
  8204. clif_inventorylist(sd);
  8205. clif_equipswitch_list(sd);
  8206. if(pc_iscarton(sd)) {
  8207. clif_cartlist(sd);
  8208. clif_updatestatus(*sd,SP_CARTINFO);
  8209. }
  8210. clif_updatestatus(*sd,SP_WEIGHT);
  8211. clif_updatestatus(*sd,SP_MAXWEIGHT);
  8212. clif_updatestatus(*sd,SP_STR);
  8213. clif_updatestatus(*sd,SP_AGI);
  8214. clif_updatestatus(*sd,SP_VIT);
  8215. clif_updatestatus(*sd,SP_INT);
  8216. clif_updatestatus(*sd,SP_DEX);
  8217. clif_updatestatus(*sd,SP_LUK);
  8218. #ifdef RENEWAL
  8219. clif_updatestatus(*sd,SP_POW);
  8220. clif_updatestatus(*sd,SP_STA);
  8221. clif_updatestatus(*sd,SP_WIS);
  8222. clif_updatestatus(*sd,SP_SPL);
  8223. clif_updatestatus(*sd,SP_CON);
  8224. clif_updatestatus(*sd,SP_CRT);
  8225. #endif
  8226. if (sd->spiritball)
  8227. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8228. clif_millenniumshield_single( *sd, *sd );
  8229. clif_spiritcharm_single( *sd, *sd );
  8230. if (sd->soulball)
  8231. clif_soulball( sd, &sd->bl, SELF );
  8232. if (sd->servantball)
  8233. clif_servantball( *sd, &sd->bl, SELF );
  8234. if (sd->abyssball)
  8235. clif_abyssball( *sd, &sd->bl, SELF );
  8236. if (sd->vd.cloth_color)
  8237. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8238. if (sd->vd.body_style)
  8239. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8240. if(hom_is_active(sd->hd))
  8241. clif_send_homdata( *sd->hd, SP_ACK );
  8242. if( sd->md ) {
  8243. clif_mercenary_info(sd);
  8244. clif_mercenary_skillblock(sd);
  8245. }
  8246. if( sd->ed )
  8247. clif_elemental_info(sd);
  8248. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8249. clif_weather_check(sd);
  8250. if( sd->chatID )
  8251. chat_leavechat(sd,0);
  8252. if( sd->state.vending )
  8253. clif_openvending(sd, sd->bl.id, sd->vending);
  8254. if( pc_issit(sd) )
  8255. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8256. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8257. clif_clearunit_single( sd->bl.id, CLR_DEAD, *sd );
  8258. else
  8259. clif_changed_dir(&sd->bl, SELF);
  8260. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8261. //Issue #2143
  8262. //Cancel Trading State
  8263. if (sd->state.trading)
  8264. trade_tradecancel(sd);
  8265. //Cancel Buying/Selling State
  8266. if (sd->state.buyingstore)
  8267. buyingstore_close(sd);
  8268. mail_clear(sd);
  8269. clif_loadConfirm( sd );
  8270. if( disguised(&sd->bl) ) {/* refresh-da */
  8271. short disguise = sd->disguise;
  8272. pc_disguise(sd, 0);
  8273. pc_disguise(sd, disguise);
  8274. }
  8275. clif_refresh_storagewindow(sd);
  8276. }
  8277. /// Updates the object's (bl) name on client.
  8278. /// Used to update when a char leaves a party/guild. [Skotlex]
  8279. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8280. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8281. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8282. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8283. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8284. nullpo_retv( src );
  8285. nullpo_retv( bl );
  8286. switch( bl->type ){
  8287. case BL_PC: {
  8288. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8289. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8290. packet.gid = bl->id;
  8291. map_session_data *sd = (map_session_data *)bl;
  8292. //Requesting your own "shadow" name. [Skotlex]
  8293. if( src == bl && target == SELF && sd->disguise ){
  8294. packet.gid = -bl->id;
  8295. }
  8296. if( sd->fakename[0] ) {
  8297. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8298. clif_send( &packet, sizeof(packet), src, target );
  8299. return;
  8300. }
  8301. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8302. party_data *p = nullptr;
  8303. if( sd->status.party_id ){
  8304. p = party_search( sd->status.party_id );
  8305. }
  8306. // do not display party unless the player is also in a guild
  8307. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8308. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8309. }
  8310. if( sd->guild ){
  8311. int position;
  8312. // Will get the position of the guild the player is in
  8313. position = guild_getposition(*sd);
  8314. safestrncpy( packet.guild_name, sd->guild->guild.name, NAME_LENGTH );
  8315. safestrncpy( packet.position_name, sd->guild->guild.position[position].name, NAME_LENGTH );
  8316. }else if( sd->clan ){
  8317. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8318. }
  8319. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8320. packet.title_id = sd->status.title_id; // Title ID
  8321. #endif
  8322. clif_send(&packet, sizeof(packet), src, target);
  8323. }
  8324. break;
  8325. //[blackhole89]
  8326. case BL_HOM:
  8327. case BL_MER:
  8328. case BL_PET:
  8329. case BL_NPC:
  8330. case BL_ELEM: {
  8331. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8332. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8333. packet.gid = bl->id;
  8334. switch (bl->type) {
  8335. case BL_HOM:
  8336. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8337. break;
  8338. case BL_MER:
  8339. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8340. break;
  8341. case BL_PET:
  8342. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8343. break;
  8344. case BL_NPC:
  8345. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8346. break;
  8347. case BL_ELEM:
  8348. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8349. break;
  8350. }
  8351. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8352. unit_data *ud = unit_bl2ud(bl);
  8353. if (ud != nullptr) {
  8354. memcpy(packet.title, ud->title, NAME_LENGTH);
  8355. packet.groupId = ud->group_id;
  8356. }
  8357. #endif
  8358. clif_send(&packet, sizeof(packet), src, target);
  8359. }
  8360. break;
  8361. case BL_MOB: {
  8362. mob_data *md = (mob_data *)bl;
  8363. if( md->guardian_data && md->guardian_data->guild_id ){
  8364. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8365. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8366. packet.gid = bl->id;
  8367. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8368. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8369. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8370. clif_send(&packet, sizeof(packet), src, target);
  8371. }else if( battle_config.show_mob_info ){
  8372. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8373. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8374. packet.gid = bl->id;
  8375. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8376. char mobhp[50], *str_p = mobhp;
  8377. if( battle_config.show_mob_info&4 ){
  8378. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8379. }
  8380. if( battle_config.show_mob_info&1 ){
  8381. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8382. }
  8383. if( battle_config.show_mob_info&2 ){
  8384. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8385. }
  8386. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8387. if( str_p != mobhp ){
  8388. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8389. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8390. }
  8391. clif_send(&packet, sizeof(packet), src, target);
  8392. } else {
  8393. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8394. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8395. packet.gid = bl->id;
  8396. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8397. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8398. unit_data *ud = unit_bl2ud(bl);
  8399. if (ud != nullptr) {
  8400. memcpy(packet.title, ud->title, NAME_LENGTH);
  8401. packet.groupId = ud->group_id;
  8402. }
  8403. #endif
  8404. clif_send(&packet, sizeof(packet), src, target);
  8405. }
  8406. }
  8407. break;
  8408. case BL_CHAT:
  8409. case BL_SKILL:
  8410. // Newer clients request this, but do not need an answer
  8411. return;
  8412. default:
  8413. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8414. return;
  8415. }
  8416. }
  8417. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8418. /// 01ff <id>.L <x>.W <y>.W
  8419. ///
  8420. /// Visually moves(instant) a character to x,y. The char moves even
  8421. /// when the target cell isn't walkable. If the char is sitting it
  8422. /// stays that way.
  8423. void clif_slide(struct block_list *bl, int x, int y)
  8424. {
  8425. unsigned char buf[10];
  8426. nullpo_retv(bl);
  8427. WBUFW(buf, 0) = 0x01ff;
  8428. WBUFL(buf, 2) = bl->id;
  8429. WBUFW(buf, 6) = x;
  8430. WBUFW(buf, 8) = y;
  8431. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8432. if( disguised(bl) )
  8433. {
  8434. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8435. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8436. }
  8437. }
  8438. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8439. /// 008d <packet len>.W <id>.L <message>.?B
  8440. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8441. {
  8442. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8443. int16 len_mes;
  8444. len_mes = static_cast<decltype(len_mes)>( strlen(mes) + 1 ); //Account for \0
  8445. if (len_mes > sizeof(buf)-8) {
  8446. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8447. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8448. }
  8449. // send message to others
  8450. if (flag == AREA) {
  8451. WBUFW(buf,0) = 0x8d;
  8452. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8453. WBUFL(buf,4) = bl->id;
  8454. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8455. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8456. }
  8457. // send back message to the speaker
  8458. if( bl->type == BL_PC ) {
  8459. WBUFW(buf,0) = 0x8e;
  8460. WBUFW(buf, 2) = len_mes + 4;
  8461. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8462. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8463. }
  8464. }
  8465. /*==========================
  8466. * Minimap fix [Kevin]
  8467. * Remove dot from minimap
  8468. *--------------------------*/
  8469. void clif_party_xy_remove(map_session_data* sd)
  8470. {
  8471. nullpo_retv(sd);
  8472. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8473. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8474. p.AID = sd->status.account_id;
  8475. p.xPos = -1;
  8476. p.yPos = -1;
  8477. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8478. }
  8479. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8480. /// 0215 <msg id>.L
  8481. /// msg id:
  8482. /// 0x15 = End all negative status (PA_GOSPEL)
  8483. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8484. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8485. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8486. /// 0x19 = All stats +20 (PA_GOSPEL)
  8487. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8488. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8489. /// 0x1e = DEF +25% (PA_GOSPEL)
  8490. /// 0x1f = ATK +100% (PA_GOSPEL)
  8491. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8492. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8493. /// ? = nothing
  8494. void clif_gospel_info(map_session_data *sd, int type)
  8495. {
  8496. int fd=sd->fd;
  8497. WFIFOHEAD(fd,packet_len(0x215));
  8498. WFIFOW(fd,0)=0x215;
  8499. WFIFOL(fd,2)=type;
  8500. WFIFOSET(fd, packet_len(0x215));
  8501. }
  8502. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8503. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8504. /// result:
  8505. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8506. /// star:
  8507. /// 0 = Place of the Sun
  8508. /// 1 = Place of the Moon
  8509. /// 2 = Place of the Stars
  8510. /// 1 = Star Gladiator %s's %s: <mapname>
  8511. /// star:
  8512. /// 0 = Place of the Sun
  8513. /// 1 = Place of the Moon
  8514. /// 2 = Place of the Stars
  8515. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8516. /// star:
  8517. /// 0 = Target of the Sun
  8518. /// 1 = Target of the Moon
  8519. /// 2 = Target of the Stars
  8520. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8521. /// star:
  8522. /// 0 = Monster of the Sun
  8523. /// 1 = Monster of the Moon
  8524. /// 2 = Monster of the Stars
  8525. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8526. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8527. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8528. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8529. /// 40 = Target HP : <monster_id used as HP>
  8530. void clif_starskill(map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8531. {
  8532. int fd = sd->fd;
  8533. WFIFOHEAD(fd,packet_len(0x20e));
  8534. WFIFOW(fd,0) = 0x20e;
  8535. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8536. WFIFOL(fd,26) = monster_id;
  8537. WFIFOB(fd,30) = star;
  8538. WFIFOB(fd,31) = result;
  8539. WFIFOSET(fd,packet_len(0x20e));
  8540. }
  8541. /*==========================================
  8542. * Info about Star Glaldiator save map [Komurka]
  8543. * type: 1: Information, 0: Map registered
  8544. *------------------------------------------*/
  8545. void clif_feel_info(map_session_data* sd, unsigned char feel_level, unsigned char type)
  8546. {
  8547. char mapname[MAP_NAME_LENGTH_EXT];
  8548. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8549. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8550. }
  8551. /*==========================================
  8552. * Info about Star Glaldiator hate mob [Komurka]
  8553. * type: 1: Register mob, 0: Information.
  8554. *------------------------------------------*/
  8555. void clif_hate_info(map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8556. {
  8557. if( pcdb_checkid(class_) ) {
  8558. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8559. } else if( mobdb_checkid(class_) ) {
  8560. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8561. } else {
  8562. 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);
  8563. }
  8564. }
  8565. /*==========================================
  8566. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8567. *------------------------------------------*/
  8568. void clif_mission_info(map_session_data *sd, int mob_id, unsigned char progress)
  8569. {
  8570. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8571. }
  8572. /*==========================================
  8573. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8574. *------------------------------------------*/
  8575. void clif_feel_hate_reset(map_session_data *sd)
  8576. {
  8577. clif_starskill(sd, "", 0, 0, 30);
  8578. }
  8579. /// Send out reply to configuration change
  8580. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8581. /// type: see enum e_config_type
  8582. /// value:
  8583. /// false = disabled
  8584. /// true = enabled
  8585. void clif_configuration( map_session_data* sd, enum e_config_type type, bool enabled ){
  8586. int fd;
  8587. nullpo_retv(sd);
  8588. fd = sd->fd;
  8589. WFIFOHEAD(fd, packet_len(0x2d9));
  8590. WFIFOW(fd, 0) = 0x2d9;
  8591. WFIFOL(fd, 2) = type;
  8592. WFIFOL(fd, 6) = enabled;
  8593. WFIFOSET(fd, packet_len(0x2d9));
  8594. }
  8595. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8596. /// 02da <open equip window>.B
  8597. /// open equip window:
  8598. /// 0 = disabled
  8599. /// 1 = enabled
  8600. void clif_equipcheckbox(map_session_data* sd)
  8601. {
  8602. int fd;
  8603. nullpo_retv(sd);
  8604. fd = sd->fd;
  8605. WFIFOHEAD(fd, packet_len(0x2da));
  8606. WFIFOW(fd, 0) = 0x2da;
  8607. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8608. WFIFOSET(fd, packet_len(0x2da));
  8609. }
  8610. /// Sends info about a player's equipped items.
  8611. /// 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)
  8612. /// 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)
  8613. /// 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)
  8614. /// 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)
  8615. /// 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)
  8616. /// 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)
  8617. void clif_viewequip_ack( map_session_data& sd, map_session_data& tsd ){
  8618. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8619. PACKET_ZC_EQUIPWIN_MICROSCOPE* p = reinterpret_cast<PACKET_ZC_EQUIPWIN_MICROSCOPE*>( packet_buffer );
  8620. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8621. p->PacketLength = sizeof( *p );
  8622. safestrncpy( p->characterName, tsd.status.name, NAME_LENGTH );
  8623. p->job = tsd.status.class_;
  8624. p->head = tsd.vd.hair_style;
  8625. p->accessory = tsd.vd.head_bottom;
  8626. p->accessory2 = tsd.vd.head_mid;
  8627. p->accessory3 = tsd.vd.head_top;
  8628. #if PACKETVER >= 20110111
  8629. p->robe = tsd.vd.robe;
  8630. #endif
  8631. p->headpalette = tsd.vd.hair_color;
  8632. p->bodypalette = tsd.vd.cloth_color;
  8633. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8634. p->body2 = tsd.vd.body_style;
  8635. #endif
  8636. p->sex = tsd.vd.sex;
  8637. for( int i = 0, equip = 0; i < EQI_MAX; i++ ){
  8638. int k = tsd.equip_index[i];
  8639. if( k >= 0 ){
  8640. if( tsd.inventory.u.items_inventory[k].nameid == 0 || tsd.inventory_data[k] == nullptr ){ // Item doesn't exist
  8641. continue;
  8642. }
  8643. if( !tsd.inventory.u.items_inventory[k].equip ){
  8644. continue;
  8645. }
  8646. if( !itemdb_isequip2( tsd.inventory_data[k] ) ){ // Is not equippable
  8647. continue;
  8648. }
  8649. clif_item_equip( client_index( k ), &p->list[equip], &tsd.inventory.u.items_inventory[k], tsd.inventory_data[k], pc_equippoint( &tsd, k ) );
  8650. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->list[0] ) );
  8651. equip++;
  8652. }
  8653. }
  8654. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8655. #endif
  8656. }
  8657. /// Display msgstringtable.txt string (ZC_MSG).
  8658. /// 0291 <message>.W
  8659. void clif_msg(map_session_data* sd, unsigned short id)
  8660. {
  8661. int fd;
  8662. nullpo_retv(sd);
  8663. fd = sd->fd;
  8664. WFIFOHEAD(fd, packet_len(0x291));
  8665. WFIFOW(fd, 0) = 0x291;
  8666. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8667. WFIFOSET(fd, packet_len(0x291));
  8668. }
  8669. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8670. /// 0x7e2 <message>.W <value>.L
  8671. void clif_msg_value(map_session_data* sd, unsigned short id, int value)
  8672. {
  8673. int fd = sd->fd;
  8674. WFIFOHEAD(fd, packet_len(0x7e2));
  8675. WFIFOW(fd,0) = 0x7e2;
  8676. WFIFOW(fd,2) = id;
  8677. WFIFOL(fd,4) = value;
  8678. WFIFOSET(fd, packet_len(0x7e2));
  8679. }
  8680. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8681. /// 07e6 <skill id>.W <msg id>.L
  8682. ///
  8683. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8684. /// "[SkillName] Message"
  8685. void clif_msg_skill(map_session_data* sd, uint16 skill_id, int msg_id)
  8686. {
  8687. int fd = sd->fd;
  8688. WFIFOHEAD(fd, packet_len(0x7e6));
  8689. WFIFOW(fd,0) = 0x7e6;
  8690. WFIFOW(fd,2) = skill_id;
  8691. WFIFOL(fd,4) = msg_id;
  8692. WFIFOSET(fd, packet_len(0x7e6));
  8693. }
  8694. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8695. /// 09cd <msg id>.W <color>.L
  8696. void clif_msg_color( map_session_data *sd, uint16 msg_id, uint32 color ){
  8697. nullpo_retv(sd);
  8698. int fd = sd->fd;
  8699. WFIFOHEAD(fd, packet_len(0x9cd));
  8700. WFIFOW(fd, 0) = 0x9cd;
  8701. WFIFOW(fd, 2) = msg_id;
  8702. WFIFOL(fd, 4) = color;
  8703. WFIFOSET(fd, packet_len(0x9cd));
  8704. }
  8705. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8706. /// Returns true if the packet was parsed successfully.
  8707. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8708. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8709. static bool clif_process_message(map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8710. const char* seperator = " : ";
  8711. int fd;
  8712. struct s_packet_db* info;
  8713. uint16 packetLength, inputLength;
  8714. const char *input, *name, *message;
  8715. size_t nameLength, messageLength;
  8716. fd = sd->fd;
  8717. info = &packet_db[RFIFOW(fd,0)];
  8718. packetLength = RFIFOW(fd,info->pos[0]);
  8719. input = RFIFOCP(fd,info->pos[1]);
  8720. // basic structure check for the 4-byte header
  8721. if( packetLength < 4 ){
  8722. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8723. return false;
  8724. }else{
  8725. inputLength = packetLength - 4;
  8726. }
  8727. // process <name> part of the packet
  8728. if( whisperFormat ) {
  8729. // name has fixed width
  8730. if( inputLength < NAME_LENGTH + 1 ) {
  8731. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8732. return false;
  8733. }
  8734. name = input;
  8735. // validate name
  8736. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8737. // only restriction is that the name must be zero-terminated
  8738. if( name[nameLength] != '\0' ) {
  8739. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8740. return false;
  8741. }
  8742. message = input + NAME_LENGTH;
  8743. messageLength = inputLength - NAME_LENGTH;
  8744. }else{
  8745. // name and message are separated by ' : '
  8746. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8747. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8748. // check if there's enough data provided
  8749. if( inputLength < nameLength + seperatorLength + 1 ){
  8750. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8751. return false;
  8752. }
  8753. name = input;
  8754. // validate name
  8755. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8756. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8757. {
  8758. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8759. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8760. set_eof(sd->fd); // Just kick them out to correct it.
  8761. return false;
  8762. }
  8763. message = input + nameLength + seperatorLength;
  8764. messageLength = inputLength - nameLength - seperatorLength;
  8765. }
  8766. #if PACKETVER < 20151001
  8767. // the declared length must match real length
  8768. if( messageLength != strnlen(message, messageLength)+1 ) {
  8769. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8770. return false;
  8771. }
  8772. // verify <message> part of the packet
  8773. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8774. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8775. return false;
  8776. }
  8777. #else
  8778. // No zero termination anymore
  8779. messageLength += 1;
  8780. #endif
  8781. // messages mustn't be too long
  8782. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8783. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8784. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8785. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8786. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8787. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8788. return false;
  8789. }
  8790. // If it is not a whisper message, set the name to the fakename of the player
  8791. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8792. strcpy( out_name, sd->fakename );
  8793. }else{
  8794. safestrncpy( out_name, name, nameLength + 1 );
  8795. }
  8796. safestrncpy( out_message, message, messageLength );
  8797. if( whisperFormat ){
  8798. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8799. out_full_message[nameLength] = '\0';
  8800. }else{
  8801. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8802. }
  8803. if( is_atcommand( fd, sd, out_message, 1 ) )
  8804. return false;
  8805. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8806. return false; //no "chatting" while muted.
  8807. if( battle_config.min_chat_delay ) { //[Skotlex]
  8808. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8809. return false;
  8810. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8811. }
  8812. if (battle_config.idletime_option&IDLE_CHAT)
  8813. sd->idletime = last_tick;
  8814. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8815. sd->idletime_hom = last_tick;
  8816. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8817. sd->idletime_mer = last_tick;
  8818. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8819. return true;
  8820. }
  8821. /**
  8822. * Displays a message if the player enters a PK Zone (during pk_mode)
  8823. * @param sd: Player data
  8824. */
  8825. inline void clif_pk_mode_message(map_session_data * sd)
  8826. {
  8827. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8828. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8829. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8830. char output[CHAT_SIZE_MAX];
  8831. // 1504: You've entered a PK Zone (safe until level %d).
  8832. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8833. battle_config.pk_min_level);
  8834. clif_showscript(&sd->bl, output, SELF);
  8835. } else {
  8836. // 1503: You've entered a PK Zone.
  8837. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8838. }
  8839. }
  8840. return;
  8841. }
  8842. // ---------------------
  8843. // clif_parse_wanttoconnect
  8844. // ---------------------
  8845. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8846. // error codes:
  8847. // 0 - Success
  8848. // 1 - Unknown packet_ver
  8849. // 2 - Invalid account_id
  8850. // 3 - Invalid char_id
  8851. // 4 - Invalid login_id1 (reserved)
  8852. // 5 - Invalid client_tick (reserved)
  8853. // 6 - Invalid sex
  8854. // Only the first 'invalid' error that appears is used.
  8855. static int clif_parse_WantToConnection_sub(int fd)
  8856. {
  8857. int value; //Value is used to temporarily store account/char_id/sex
  8858. //By default, start searching on the default one.
  8859. uint16 cmd = RFIFOW(fd, 0);
  8860. int16 packet_len;
  8861. packet_len = static_cast<decltype(packet_len)>( RFIFOREST( fd ) );
  8862. // FIXME: If the packet is not received at once, this will FAIL.
  8863. // Figure out, when it happens, that only part of the packet is
  8864. // received, or fix the function to be able to deal with that
  8865. // case.
  8866. if( packet_len != packet_db[cmd].len )
  8867. return 1; /* wrong length */
  8868. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8869. return 2; /* invalid account_id */
  8870. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8871. return 3; /* invalid char_id */
  8872. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8873. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8874. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8875. return 6; /* invalid sex */
  8876. else
  8877. return 0;
  8878. }
  8879. /// Request to connect to map-server.
  8880. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8881. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8882. /// There are various variants of this packet, some of them have padding between fields.
  8883. void clif_parse_WantToConnection(int fd, map_session_data* sd)
  8884. {
  8885. struct block_list* bl;
  8886. struct auth_node* node;
  8887. int cmd, account_id, char_id, login_id1, sex, err;
  8888. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8889. if (sd) {
  8890. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8891. return;
  8892. }
  8893. cmd = RFIFOW(fd, 0);
  8894. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8895. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8896. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8897. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8898. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8899. err = clif_parse_WantToConnection_sub(fd);
  8900. if( err ){ // connection rejected
  8901. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8902. err == 1 ? "." :
  8903. err == 2 ? ", possibly for having an invalid account_id." :
  8904. err == 3 ? ", possibly for having an invalid char_id." :
  8905. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8906. err == 4 ? ", possibly for having an invalid login_id1." :
  8907. err == 5 ? ", possibly for having an invalid client_tick." :
  8908. */
  8909. err == 6 ? ", possibly for having an invalid sex." :
  8910. ". ERROR invalid error code"));
  8911. WFIFOHEAD(fd,packet_len(0x6a));
  8912. WFIFOW(fd,0) = 0x6a;
  8913. WFIFOB(fd,2) = err;
  8914. WFIFOSET(fd,packet_len(0x6a));
  8915. #ifdef DUMP_INVALID_PACKET
  8916. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8917. #endif
  8918. RFIFOSKIP(fd, RFIFOREST(fd));
  8919. set_eof(fd);
  8920. return;
  8921. }
  8922. if( !global_core->is_running() ){ // not allowed
  8923. clif_authfail_fd(fd,1);// server closed
  8924. return;
  8925. }
  8926. //Check for double login.
  8927. bl = map_id2bl(account_id);
  8928. if(bl && bl->type != BL_PC) {
  8929. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8930. WFIFOHEAD(fd,packet_len(0x6a));
  8931. WFIFOW(fd,0) = 0x6a;
  8932. WFIFOB(fd,2) = 3; // Rejected by server
  8933. WFIFOSET(fd,packet_len(0x6a));
  8934. set_eof(fd);
  8935. return;
  8936. }
  8937. if (bl ||
  8938. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8939. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8940. {
  8941. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8942. return;
  8943. }
  8944. CREATE(sd, TBL_PC, 1);
  8945. new(sd) map_session_data();
  8946. sd->fd = fd;
  8947. #ifdef PACKET_OBFUSCATION
  8948. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8949. #endif
  8950. session[fd]->session_data = sd;
  8951. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8952. #if PACKETVER < 20070521
  8953. WFIFOHEAD(fd,4);
  8954. WFIFOL(fd,0) = sd->bl.id;
  8955. WFIFOSET(fd,4);
  8956. #else
  8957. WFIFOHEAD(fd,packet_len(0x283));
  8958. WFIFOW(fd,0) = 0x283;
  8959. WFIFOL(fd,2) = sd->bl.id;
  8960. WFIFOSET(fd,packet_len(0x283));
  8961. #endif
  8962. chrif_authreq(sd,false);
  8963. }
  8964. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8965. /// 007d
  8966. void clif_parse_LoadEndAck(int fd,map_session_data *sd)
  8967. {
  8968. bool guild_notice = false;
  8969. if(sd->bl.prev != nullptr)
  8970. return;
  8971. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8972. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8973. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8974. sd->state.connect_new = 0;
  8975. return;
  8976. }
  8977. if (sd->state.rewarp) { //Rewarp player.
  8978. sd->state.rewarp = 0;
  8979. clif_changemap( *sd, sd->bl.m, sd->bl.x, sd->bl.y );
  8980. return;
  8981. }
  8982. sd->state.warping = 0;
  8983. // look
  8984. #if PACKETVER < 4
  8985. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8986. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8987. #else
  8988. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8989. #endif
  8990. pc_set_costume_view(sd);
  8991. if(sd->vd.cloth_color)
  8992. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8993. if(sd->vd.body_style)
  8994. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8995. // item
  8996. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8997. pc_checkitem(sd);
  8998. clif_equipswitch_list(sd);
  8999. // cart
  9000. if(pc_iscarton(sd)) {
  9001. clif_cartlist(sd);
  9002. clif_updatestatus(*sd,SP_CARTINFO);
  9003. }
  9004. // weight
  9005. clif_updatestatus(*sd,SP_WEIGHT);
  9006. clif_updatestatus(*sd,SP_MAXWEIGHT);
  9007. // guild
  9008. // (needs to go before clif_spawn() to show guild emblems correctly)
  9009. if(sd->status.guild_id)
  9010. guild_send_memberinfoshort(sd,1);
  9011. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9012. if(battle_config.pc_invincible_time > 0) {
  9013. if(mapdata_flag_gvg(mapdata))
  9014. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9015. else
  9016. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9017. }
  9018. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9019. map_spawnmobs(sd->bl.m);
  9020. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9021. mapdata->users_pvp++;
  9022. }
  9023. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9024. // reset the callshop flag if the player changes map
  9025. sd->state.callshop = 0;
  9026. if(map_addblock(&sd->bl))
  9027. return;
  9028. clif_spawn(&sd->bl);
  9029. // Party
  9030. // (needs to go after clif_spawn() to show hp bars correctly)
  9031. if(sd->status.party_id) {
  9032. party_send_movemap(sd);
  9033. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9034. }
  9035. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9036. if(!pc_isinvisible(sd) && mapdata->getMapFlag(MF_PVP)) {
  9037. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9038. if (!mapdata->getMapFlag(MF_PVP_NOCALCRANK))
  9039. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9040. sd->pvp_rank = 0;
  9041. sd->pvp_lastusers = 0;
  9042. sd->pvp_point = 5;
  9043. sd->pvp_won = 0;
  9044. sd->pvp_lost = 0;
  9045. }
  9046. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9047. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9048. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9049. else if (mapdata->getMapFlag(MF_GVG_DUNGEON))
  9050. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9051. else if( mapdata_flag_gvg(mapdata) )
  9052. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9053. else
  9054. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9055. // info about nearby objects
  9056. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9057. 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);
  9058. // pet
  9059. if( sd->pd ) {
  9060. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9061. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9062. pet_return_egg( sd, sd->pd );
  9063. } else {
  9064. if(map_addblock(&sd->pd->bl))
  9065. return;
  9066. clif_spawn(&sd->pd->bl);
  9067. clif_send_petdata(sd,sd->pd,0,0);
  9068. clif_send_petstatus(sd);
  9069. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9070. }
  9071. }
  9072. //homunculus [blackhole89]
  9073. if( hom_is_active(sd->hd) ) {
  9074. if(map_addblock(&sd->hd->bl))
  9075. return;
  9076. clif_spawn(&sd->hd->bl);
  9077. clif_send_homdata( *sd->hd, SP_ACK );
  9078. clif_hominfo(sd,sd->hd,1);
  9079. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9080. clif_homskillinfoblock( *sd->hd );
  9081. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9082. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9083. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9084. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9085. }
  9086. if( sd->md ) {
  9087. if(map_addblock(&sd->md->bl))
  9088. return;
  9089. clif_spawn(&sd->md->bl);
  9090. clif_mercenary_info(sd);
  9091. clif_mercenary_skillblock(sd);
  9092. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9093. }
  9094. if( sd->ed ) {
  9095. if (map_addblock(&sd->ed->bl))
  9096. return;
  9097. clif_spawn(&sd->ed->bl);
  9098. clif_elemental_info(sd);
  9099. clif_elemental_updatestatus(sd,SP_HP);
  9100. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9101. clif_elemental_updatestatus(sd,SP_SP);
  9102. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9103. }
  9104. if(sd->state.connect_new) {
  9105. int lv;
  9106. guild_notice = true;
  9107. clif_skillinfoblock(sd);
  9108. clif_hotkeys_send(sd,0);
  9109. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9110. clif_hotkeys_send(sd,1);
  9111. #endif
  9112. clif_updatestatus(*sd,SP_BASEEXP);
  9113. clif_updatestatus(*sd,SP_NEXTBASEEXP);
  9114. clif_updatestatus(*sd,SP_JOBEXP);
  9115. clif_updatestatus(*sd,SP_NEXTJOBEXP);
  9116. clif_updatestatus(*sd,SP_SKILLPOINT);
  9117. clif_initialstatus( *sd );
  9118. if (sd->sc.option&OPTION_FALCON)
  9119. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9120. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9121. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9122. else if (sd->sc.option&OPTION_WUGRIDER)
  9123. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9124. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9125. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9126. if(sd->status.manner < 0)
  9127. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9128. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9129. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9130. if(sd->bl.m == sd->feel_map[0].m
  9131. || sd->bl.m == sd->feel_map[1].m
  9132. || sd->bl.m == sd->feel_map[2].m)
  9133. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9134. }
  9135. if(sd->pd && sd->pd->pet.intimate > 900)
  9136. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9137. if(hom_is_active(sd->hd))
  9138. hom_init_timers(sd->hd);
  9139. if (night_flag && mapdata->getMapFlag(MF_NIGHTENABLED)) {
  9140. sd->state.night = 1;
  9141. clif_status_load(&sd->bl, EFST_SKE, 1);
  9142. }
  9143. // Notify everyone that this char logged in [Skotlex].
  9144. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9145. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9146. //Login Event
  9147. npc_script_event(sd, NPCE_LOGIN);
  9148. }
  9149. // Set facing direction before check below to update client
  9150. if (battle_config.spawn_direction)
  9151. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9152. } else {
  9153. //For some reason the client "loses" these on warp/map-change.
  9154. clif_updatestatus(*sd,SP_STR);
  9155. clif_updatestatus(*sd,SP_AGI);
  9156. clif_updatestatus(*sd,SP_VIT);
  9157. clif_updatestatus(*sd,SP_INT);
  9158. clif_updatestatus(*sd,SP_DEX);
  9159. clif_updatestatus(*sd,SP_LUK);
  9160. #ifdef RENEWAL
  9161. clif_updatestatus(*sd,SP_POW);
  9162. clif_updatestatus(*sd,SP_STA);
  9163. clif_updatestatus(*sd,SP_WIS);
  9164. clif_updatestatus(*sd,SP_SPL);
  9165. clif_updatestatus(*sd,SP_CON);
  9166. clif_updatestatus(*sd,SP_CRT);
  9167. #endif
  9168. // abort currently running script
  9169. sd->state.using_fake_npc = 0;
  9170. sd->state.menu_or_input = 0;
  9171. sd->npc_menu = 0;
  9172. if(sd->npc_id)
  9173. npc_event_dequeue(sd);
  9174. }
  9175. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9176. clif_partyinvitationstate( *sd );
  9177. #if PACKETVER >= 20070918
  9178. clif_equipcheckbox(sd);
  9179. #endif
  9180. clif_pet_autofeed_status(sd,false);
  9181. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9182. #if PACKETVER >= 20170920
  9183. if( battle_config.homunculus_autofeed_always ){
  9184. // Always send ON or OFF
  9185. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9186. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9187. }else{
  9188. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9189. }
  9190. }else{
  9191. // Only send when enabled
  9192. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9193. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9194. }
  9195. }
  9196. #endif
  9197. clif_reputation_list( *sd );
  9198. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9199. clif_guild_notice(sd); // Displays after VIP
  9200. guild_notice = false; // Do not display it twice
  9201. }
  9202. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9203. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9204. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->getMapFlag(MF_BATTLEGROUND))) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->getMapFlag(MF_BATTLEGROUND))))
  9205. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9206. }
  9207. if( night_flag && mapdata->getMapFlag(MF_NIGHTENABLED) )
  9208. { //Display night.
  9209. if( !sd->state.night )
  9210. {
  9211. sd->state.night = 1;
  9212. clif_status_load(&sd->bl, EFST_SKE, 1);
  9213. }
  9214. }
  9215. else if( sd->state.night )
  9216. { //Clear night display.
  9217. sd->state.night = 0;
  9218. clif_status_load(&sd->bl, EFST_SKE, 0);
  9219. }
  9220. if( mapdata->getMapFlag(MF_BATTLEGROUND) )
  9221. {
  9222. clif_map_type( *sd, MAPTYPE_BATTLEFIELD ); // Battleground Mode
  9223. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9224. clif_bg_updatescore_single(sd);
  9225. }
  9226. if( mapdata->getMapFlag(MF_ALLOWKS) && !mapdata_flag_ks(mapdata) )
  9227. {
  9228. char output[128];
  9229. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9230. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9231. }
  9232. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9233. mapdata->hpmeter_visible++;
  9234. sd->state.hpmeter_visible = 1;
  9235. }
  9236. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9237. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9238. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9239. #ifdef VIP_ENABLE
  9240. if (!sd->state.connect_new &&
  9241. !sd->vip.disableshowrate &&
  9242. sd->state.pmap != sd->bl.m &&
  9243. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->getMapFlag(MF_BEXP)
  9244. )
  9245. {
  9246. clif_display_pinfo( *sd );
  9247. }
  9248. #endif
  9249. // Instances do not need their own channels
  9250. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->getMapFlag(MF_NOMAPCHANNELAUTOJOIN) )
  9251. channel_mjoin(sd); //join new map
  9252. clif_pk_mode_message(sd);
  9253. }
  9254. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9255. clif_guild_notice(sd); // Displays at end
  9256. }
  9257. mail_clear(sd);
  9258. /* Guild Aura Init */
  9259. if( sd->guild && sd->state.gmaster_flag ) {
  9260. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP));
  9261. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS));
  9262. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD));
  9263. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES));
  9264. }
  9265. if( sd->state.vending ) { /* show we have a vending */
  9266. clif_openvending(sd,sd->bl.id,sd->vending);
  9267. clif_showvendingboard( *sd );
  9268. }
  9269. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9270. if(!sd->state.autotrade && mapdata->getMapFlag(MF_LOADEVENT)) // Lance
  9271. npc_script_event(sd, NPCE_LOADMAP);
  9272. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9273. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9274. if (sd->sc.opt2) //Client loses these on warp.
  9275. clif_changeoption(&sd->bl);
  9276. 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)) {
  9277. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9278. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9279. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9280. }
  9281. clif_weather_check(sd);
  9282. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9283. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9284. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9285. else
  9286. sd->areanpc.clear();
  9287. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9288. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9289. pc_setdead(sd);
  9290. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9291. if(pc_isdead(sd))
  9292. clif_clearunit_area( sd->bl, CLR_DEAD );
  9293. else {
  9294. skill_usave_trigger(sd);
  9295. if (battle_config.spawn_direction)
  9296. clif_changed_dir(&sd->bl, SELF);
  9297. }
  9298. // Trigger skill effects if you appear standing on them
  9299. if(!battle_config.pc_invincible_time)
  9300. skill_unit_move(&sd->bl,gettick(),1);
  9301. pc_show_questinfo_reinit(sd);
  9302. pc_show_questinfo(sd);
  9303. #if PACKETVER >= 20150513
  9304. if( sd->mail.inbox.unread ){
  9305. clif_Mail_new(sd, 0, nullptr, nullptr);
  9306. }
  9307. #endif
  9308. sd->state.connect_new = 0;
  9309. sd->state.changemap = false;
  9310. }
  9311. /// Server's tick (ZC_NOTIFY_TIME).
  9312. /// 007f <time>.L
  9313. void clif_notify_time(map_session_data* sd, t_tick time)
  9314. {
  9315. int fd = sd->fd;
  9316. WFIFOHEAD(fd,packet_len(0x7f));
  9317. WFIFOW(fd,0) = 0x7f;
  9318. WFIFOL(fd,2) = client_tick(time);
  9319. WFIFOSET(fd,packet_len(0x7f));
  9320. }
  9321. /// Request for server's tick.
  9322. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9323. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9324. /// There are various variants of this packet, some of them have padding between fields.
  9325. void clif_parse_TickSend(int fd, map_session_data *sd)
  9326. {
  9327. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9328. clif_notify_time(sd, gettick());
  9329. }
  9330. /// Sends hotkey bar.
  9331. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9332. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9333. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9334. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9335. void clif_hotkeys_send( map_session_data *sd, int tab ){
  9336. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9337. nullpo_retv( sd );
  9338. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9339. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9340. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9341. if( tab == 0 ){
  9342. p.rotate = sd->status.hotkey_rowshift;
  9343. }else{
  9344. p.rotate = sd->status.hotkey_rowshift2;
  9345. }
  9346. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9347. p.tab = tab;
  9348. #endif
  9349. #endif
  9350. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9351. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9352. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9353. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9354. }
  9355. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9356. #endif
  9357. }
  9358. /// Request to update a position on the hotkey row bar
  9359. void clif_parse_HotkeyRowShift( int fd, map_session_data *sd ){
  9360. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9361. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9362. if( p->tab == 0 ){
  9363. sd->status.hotkey_rowshift = p->rowshift;
  9364. }else{
  9365. sd->status.hotkey_rowshift2 = p->rowshift;
  9366. }
  9367. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9368. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9369. sd->status.hotkey_rowshift = p->rowshift;
  9370. #endif
  9371. }
  9372. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9373. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9374. void clif_parse_Hotkey(int fd, map_session_data *sd) {
  9375. #ifdef HOTKEY_SAVING
  9376. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9377. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9378. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9379. if( idx >= MAX_HOTKEYS_DB ){
  9380. return;
  9381. }
  9382. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9383. sd->status.hotkeys[idx].id = p->hotkey.id;
  9384. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9385. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9386. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9387. const unsigned short idx = p->index;
  9388. if( idx >= MAX_HOTKEYS_DB ){
  9389. return;
  9390. }
  9391. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9392. sd->status.hotkeys[idx].id = p->hotkey.id;
  9393. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9394. #endif
  9395. #endif
  9396. }
  9397. /// Displays cast-like progress bar (ZC_PROGRESS).
  9398. /// 02f0 <color>.L <time>.L
  9399. void clif_progressbar(map_session_data * sd, unsigned long color, unsigned int second)
  9400. {
  9401. int fd = sd->fd;
  9402. WFIFOHEAD(fd,packet_len(0x2f0));
  9403. WFIFOW(fd,0) = 0x2f0;
  9404. WFIFOL(fd,2) = color;
  9405. WFIFOL(fd,6) = second;
  9406. WFIFOSET(fd,packet_len(0x2f0));
  9407. }
  9408. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9409. /// 02f2
  9410. void clif_progressbar_abort(map_session_data * sd)
  9411. {
  9412. int fd = sd->fd;
  9413. WFIFOHEAD(fd,packet_len(0x2f2));
  9414. WFIFOW(fd,0) = 0x2f2;
  9415. WFIFOSET(fd,packet_len(0x2f2));
  9416. }
  9417. /// Notification from the client, that the progress bar has reached 100%.
  9418. /// 02f1 (CZ_PROGRESS)
  9419. void clif_parse_progressbar(int fd, map_session_data * sd){
  9420. // No progressbar active, ignore it
  9421. if( !sd->progressbar.npc_id ){
  9422. return;
  9423. }
  9424. int npc_id = sd->progressbar.npc_id;
  9425. bool closing = false;
  9426. // Check if the progress was canceled
  9427. if( gettick() < sd->progressbar.timeout && sd->st ){
  9428. closing = true;
  9429. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9430. // If a message window was open, offer a close button to the user
  9431. if( sd->st->mes_active ){
  9432. clif_scriptclose( *sd, npc_id );
  9433. }
  9434. }
  9435. sd->progressbar.npc_id = 0;
  9436. sd->progressbar.timeout = 0;
  9437. sd->state.workinprogress = WIP_DISABLE_NONE;
  9438. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9439. sd->idletime = last_tick;
  9440. }
  9441. npc_scriptcont(sd, npc_id, closing);
  9442. }
  9443. /// Displays cast-like progress bar on a NPC
  9444. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9445. void clif_progressbar_npc( struct npc_data *nd, map_session_data* sd ){
  9446. #if PACKETVER >= 20130821
  9447. unsigned char buf[14];
  9448. if( nd->progressbar.timeout > 0 ){
  9449. WBUFW(buf,0) = 0x9d1;
  9450. WBUFL(buf,2) = nd->bl.id;
  9451. WBUFL(buf,6) = nd->progressbar.color;
  9452. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9453. if( sd ){
  9454. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9455. }else{
  9456. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9457. }
  9458. }
  9459. #endif
  9460. }
  9461. /// Request to walk to a certain position on the current map.
  9462. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9463. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9464. /// There are various variants of this packet, some of them have padding between fields.
  9465. void clif_parse_WalkToXY(int fd, map_session_data *sd)
  9466. {
  9467. short x, y;
  9468. if (pc_isdead(sd)) {
  9469. clif_clearunit_area( sd->bl, CLR_DEAD );
  9470. return;
  9471. }
  9472. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9473. ; //You CAN walk on this OPT1 value.
  9474. else if (sd->progressbar.npc_id) {
  9475. clif_progressbar_abort(sd);
  9476. return; // First walk attempt cancels the progress bar
  9477. } else if (pc_cant_act(sd))
  9478. return;
  9479. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9480. return;
  9481. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, nullptr);
  9482. //A move command one cell west is only valid if the target cell is free
  9483. if(battle_config.official_cell_stack_limit > 0
  9484. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9485. return;
  9486. // Cloaking wall check is actually updated when you click to process next movement
  9487. // not when you move each cell. This is official behaviour.
  9488. if (sd->sc.getSCE(SC_CLOAKING))
  9489. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9490. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9491. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9492. pc_delinvincibletimer(sd);
  9493. //Set last idle time... [Skotlex]
  9494. if (battle_config.idletime_option&IDLE_WALK)
  9495. sd->idletime = last_tick;
  9496. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9497. sd->idletime_hom = last_tick;
  9498. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9499. sd->idletime_mer = last_tick;
  9500. unit_walktoxy(&sd->bl, x, y, 4);
  9501. }
  9502. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9503. /// 018b <result>.W
  9504. /// result:
  9505. /// 0 = disconnect (quit)
  9506. /// 1 = cannot disconnect (wait 10 seconds)
  9507. /// ? = ignored
  9508. void clif_disconnect_ack(map_session_data* sd, short result)
  9509. {
  9510. int fd = sd->fd;
  9511. WFIFOHEAD(fd,packet_len(0x18b));
  9512. WFIFOW(fd,0) = 0x18b;
  9513. WFIFOW(fd,2) = result;
  9514. WFIFOSET(fd,packet_len(0x18b));
  9515. }
  9516. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9517. /// 018a <type>.W
  9518. /// type:
  9519. /// 0 = quit
  9520. void clif_parse_QuitGame(int fd, map_session_data *sd)
  9521. {
  9522. /* Rovert's prevent logout option fixed [Valaris] */
  9523. 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) &&
  9524. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9525. {
  9526. pc_damage_log_clear(sd,0);
  9527. clif_disconnect_ack(sd, 0);
  9528. flush_fifo( fd );
  9529. if( battle_config.drop_connection_on_quit ){
  9530. set_eof( fd );
  9531. }
  9532. } else {
  9533. clif_disconnect_ack(sd, 1);
  9534. }
  9535. }
  9536. /// Requesting unit's name.
  9537. /// 0094 <id>.L (CZ_REQNAME)
  9538. /// 0368 <id>.L (CZ_REQNAME2)
  9539. /// There are various variants of this packet, some of them have padding between fields.
  9540. void clif_parse_GetCharNameRequest(int fd, map_session_data *sd)
  9541. {
  9542. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9543. struct block_list* bl;
  9544. //status_change *sc;
  9545. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9546. id = sd->bl.id;
  9547. bl = map_id2bl(id);
  9548. if( bl == nullptr )
  9549. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9550. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9551. return; // Block namerequests past view range
  9552. // 'see people in GM hide' cheat detection
  9553. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9554. sc = status_get_sc(bl);
  9555. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9556. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9557. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9558. ) {
  9559. char gm_msg[256];
  9560. 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);
  9561. ShowWarning(gm_msg);
  9562. // information is sent to all online GMs
  9563. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9564. return;
  9565. }
  9566. */
  9567. clif_name(&sd->bl,bl,SELF);
  9568. }
  9569. /// Validates and processes global messages
  9570. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9571. /// There are various variants of this packet.
  9572. void clif_parse_GlobalMessage(int fd, map_session_data* sd)
  9573. {
  9574. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9575. size_t length;
  9576. // validate packet and retrieve name and message
  9577. if( !clif_process_message(sd, false, name, message, output ) )
  9578. return;
  9579. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9580. channel_send(sd->gcbind,sd,message);
  9581. return;
  9582. }
  9583. // send message to others (using the send buffer for temp. storage)
  9584. clif_GlobalMessage( sd->bl, output, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC );
  9585. length = strlen(output) + 1;
  9586. // send back message to the speaker
  9587. WFIFOHEAD(fd,4+length);
  9588. WFIFOW(fd,0) = 0x8e;
  9589. WFIFOW(fd,2) = (uint16)(4+length);
  9590. safestrncpy(WFIFOCP(fd,4), output, length );
  9591. WFIFOSET(fd, WFIFOW(fd,2));
  9592. #ifdef PCRE_SUPPORT
  9593. // trigger listening npcs
  9594. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9595. #endif
  9596. // Chat logging type 'O' / Global Chat
  9597. 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);
  9598. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9599. }
  9600. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9601. /// Request to warp to a map on given coordinates.
  9602. /// 0140 <map name>.16B <x>.W <y>.W
  9603. void clif_parse_MapMove(int fd, map_session_data *sd)
  9604. {
  9605. char command[MAP_NAME_LENGTH_EXT+25];
  9606. char* map_name;
  9607. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9608. map_name = RFIFOCP(fd,info->pos[0]);
  9609. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9610. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9611. RFIFOW(fd,info->pos[1]), //x
  9612. RFIFOW(fd,info->pos[2])); //y
  9613. is_atcommand(fd, sd, command, 1);
  9614. }
  9615. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9616. /// 009c <id>.L <head dir>.W <dir>.B
  9617. /// head dir:
  9618. /// 0 = straight
  9619. /// 1 = turned CW
  9620. /// 2 = turned CCW
  9621. /// dir:
  9622. /// 0 = north
  9623. /// 1 = northwest
  9624. /// 2 = west
  9625. /// 3 = southwest
  9626. /// 4 = south
  9627. /// 5 = southeast
  9628. /// 6 = east
  9629. /// 7 = northeast
  9630. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9631. {
  9632. unsigned char buf[64];
  9633. WBUFW(buf,0) = 0x9c;
  9634. WBUFL(buf,2) = bl->id;
  9635. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9636. WBUFB(buf,8) = unit_getdir(bl);
  9637. clif_send(buf, packet_len(0x9c), bl, target);
  9638. if (disguised(bl)) {
  9639. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9640. WBUFW(buf,6) = 0;
  9641. clif_send(buf, packet_len(0x9c), bl, SELF);
  9642. }
  9643. }
  9644. /// Request to change own body and head direction.
  9645. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9646. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9647. /// There are various variants of this packet, some of them have padding between fields.
  9648. void clif_parse_ChangeDir(int fd, map_session_data *sd)
  9649. {
  9650. unsigned char headdir, dir;
  9651. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9652. headdir = RFIFOB(fd,info->pos[0]);
  9653. dir = RFIFOB(fd,info->pos[1]);
  9654. pc_setdir(sd, dir, headdir);
  9655. clif_changed_dir(&sd->bl, AREA_WOS);
  9656. }
  9657. /// Request to show an emotion (CZ_REQ_EMOTION).
  9658. /// 00bf <type>.B
  9659. /// type:
  9660. /// @see enum emotion_type
  9661. void clif_parse_Emotion(int fd, map_session_data *sd){
  9662. if( sd == nullptr ){
  9663. return;
  9664. }
  9665. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9666. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9667. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9668. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9669. return;
  9670. }
  9671. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9672. if (sd->emotionlasttime + 1 >= time(nullptr)) { // not more than 1 per second
  9673. sd->emotionlasttime = time(nullptr);
  9674. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9675. return;
  9676. }
  9677. sd->emotionlasttime = time(nullptr);
  9678. if (battle_config.idletime_option&IDLE_EMOTION)
  9679. sd->idletime = last_tick;
  9680. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9681. sd->idletime_hom = last_tick;
  9682. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9683. sd->idletime_mer = last_tick;
  9684. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9685. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9686. return;
  9687. }
  9688. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9689. emoticon = rnd()%6+ET_DICE1;
  9690. }
  9691. clif_emotion(&sd->bl, emoticon);
  9692. } else
  9693. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9694. }
  9695. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9696. /// 00c2 <count>.L
  9697. void clif_user_count(map_session_data* sd, int count)
  9698. {
  9699. int fd = sd->fd;
  9700. WFIFOHEAD(fd,packet_len(0xc2));
  9701. WFIFOW(fd,0) = 0xc2;
  9702. WFIFOL(fd,2) = count;
  9703. WFIFOSET(fd,packet_len(0xc2));
  9704. }
  9705. /// /w /who (CZ_REQ_USER_COUNT).
  9706. /// Request to display amount of currently connected players.
  9707. /// 00c1
  9708. void clif_parse_HowManyConnections(int fd, map_session_data *sd)
  9709. {
  9710. clif_user_count(sd, map_getusers());
  9711. }
  9712. void clif_parse_ActionRequest_sub( map_session_data& sd, int action_type, int target_id, t_tick tick ){
  9713. if (pc_isdead(&sd)) {
  9714. clif_clearunit_area(sd.bl, CLR_DEAD);
  9715. return;
  9716. }
  9717. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9718. if (action_type != 0x00 && action_type != 0x07) {
  9719. if (sd.sc.cant.interact)
  9720. return;
  9721. pc_stop_walking(&sd, 1);
  9722. }
  9723. pc_stop_attack(&sd);
  9724. if(target_id<0 && -target_id == sd.bl.id) // for disguises [Valaris]
  9725. target_id = sd.bl.id;
  9726. switch(action_type)
  9727. {
  9728. case 0x00: // once attack
  9729. case 0x07: // continuous attack
  9730. if( pc_cant_act(&sd) )
  9731. return;
  9732. if (!battle_config.sdelay_attack_enable && pc_checkskill(&sd, SA_FREECAST) <= 0) {
  9733. if (DIFF_TICK(tick, sd.ud.canact_tick) < 0) {
  9734. clif_skill_fail( sd, 1, USESKILL_FAIL_SKILLINTERVAL );
  9735. return;
  9736. }
  9737. }
  9738. pc_delinvincibletimer(&sd);
  9739. if (battle_config.idletime_option&IDLE_ATTACK)
  9740. sd.idletime = last_tick;
  9741. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9742. sd.idletime_hom = last_tick;
  9743. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9744. sd.idletime_mer = last_tick;
  9745. unit_attack(&sd.bl, target_id, action_type != 0);
  9746. break;
  9747. case 0x02: // sitdown
  9748. if (battle_config.basic_skill_check && pc_checkskill(&sd, NV_BASIC) < 3 && pc_checkskill(&sd, SU_BASIC_SKILL) < 1) {
  9749. clif_skill_fail( sd, 1, USESKILL_FAIL_LEVEL, 2 );
  9750. break;
  9751. }
  9752. if(pc_issit(&sd)) {
  9753. //Bugged client? Just refresh them.
  9754. clif_sitting(&sd.bl);
  9755. return;
  9756. }
  9757. if (sd.ud.skilltimer != INVALID_TIMER || (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING))
  9758. break;
  9759. if (sd.sc.count && (
  9760. sd.sc.getSCE(SC_DANCING) ||
  9761. (sd.sc.getSCE(SC_GRAVITATION) && sd.sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9762. )) //No sitting during these states either.
  9763. break;
  9764. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9765. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9766. break;
  9767. }
  9768. if (battle_config.idletime_option&IDLE_SIT)
  9769. sd.idletime = last_tick;
  9770. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9771. sd.idletime_hom = last_tick;
  9772. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9773. sd.idletime_mer = last_tick;
  9774. pc_setsit(&sd);
  9775. skill_sit(&sd, true);
  9776. clif_sitting(&sd.bl);
  9777. break;
  9778. case 0x03: // standup
  9779. if (!pc_issit(&sd)) {
  9780. //Bugged client? Just refresh them.
  9781. clif_standing(&sd.bl);
  9782. return;
  9783. }
  9784. if (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING)
  9785. break;
  9786. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9787. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9788. break;
  9789. }
  9790. if (pc_setstand(&sd, false)) {
  9791. if (battle_config.idletime_option&IDLE_SIT)
  9792. sd.idletime = last_tick;
  9793. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9794. sd.idletime_hom = last_tick;
  9795. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9796. sd.idletime_mer = last_tick;
  9797. skill_sit(&sd, false);
  9798. clif_standing(&sd.bl);
  9799. }
  9800. break;
  9801. }
  9802. }
  9803. /// Request for an action.
  9804. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9805. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9806. /// action:
  9807. /// 0 = attack
  9808. /// 1 = pick up item
  9809. /// 2 = sit down
  9810. /// 3 = stand up
  9811. /// 7 = continous attack
  9812. /// 12 = (touch skill?)
  9813. /// There are various variants of this packet, some of them have padding between fields.
  9814. void clif_parse_ActionRequest(int fd, map_session_data *sd)
  9815. {
  9816. if( sd == nullptr ){
  9817. return;
  9818. }
  9819. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9820. clif_parse_ActionRequest_sub( *sd,
  9821. RFIFOB(fd,info->pos[1]),
  9822. RFIFOL(fd,info->pos[0]),
  9823. gettick()
  9824. );
  9825. }
  9826. /// Response to the death/system menu (CZ_RESTART).
  9827. /// 00b2 <type>.B
  9828. /// type:
  9829. /// 0 = restart (respawn)
  9830. /// 1 = char-select (disconnect)
  9831. void clif_parse_Restart(int fd, map_session_data *sd)
  9832. {
  9833. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9834. case 0x00:
  9835. pc_respawn(sd,CLR_OUTSIGHT);
  9836. break;
  9837. case 0x01:
  9838. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9839. 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) &&
  9840. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9841. { //Send to char-server for character selection.
  9842. pc_damage_log_clear(sd,0);
  9843. chrif_charselectreq(sd, session[fd]->client_addr);
  9844. } else {
  9845. clif_disconnect_ack(sd, 1);
  9846. }
  9847. break;
  9848. }
  9849. }
  9850. /// Validates and processes whispered messages (CZ_WHISPER).
  9851. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9852. void clif_parse_WisMessage(int fd, map_session_data* sd)
  9853. {
  9854. map_session_data* dstsd;
  9855. int i;
  9856. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9857. // validate packet and retrieve name and message
  9858. if( !clif_process_message( sd, true, target, message, output ) )
  9859. return;
  9860. // Chat logging type 'W' / Whisper
  9861. 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);
  9862. //-------------------------------------------------------//
  9863. // Lordalfa - Paperboy - To whisper NPC commands //
  9864. //-------------------------------------------------------//
  9865. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9866. {
  9867. char* str = target+4; //Skip the NPC: string part.
  9868. struct npc_data* npc;
  9869. if ((npc = npc_name2id(str))) {
  9870. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9871. char *split;
  9872. char event[EVENT_NAME_LENGTH];
  9873. str = message;
  9874. // skip codepage indicator, if detected
  9875. if( str[0] == '|' && strlen(str) >= 4 )
  9876. str += 3;
  9877. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9878. split = strchr(str,'#');
  9879. if( split == nullptr ) { // use the remaining string
  9880. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9881. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9882. split_data[i][0] = '\0';
  9883. break;
  9884. }
  9885. *split = '\0';
  9886. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9887. str = split+1;
  9888. }
  9889. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9890. char variablename[CHAT_SIZE_MAX];
  9891. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9892. set_var_str( sd, variablename, split_data[i] );
  9893. }
  9894. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9895. npc_event(sd,event,0); // Calls the NPC label
  9896. return;
  9897. }
  9898. } else if( target[0] == '#' ) {
  9899. struct Channel *channel = nullptr;
  9900. char* chname = target;
  9901. channel = channel_name2channel(chname,sd,3);
  9902. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9903. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9904. channel_send(channel,sd,message);
  9905. }
  9906. else if( channel->pass[0] == '\0') { //no pass needed
  9907. if (channel_join(channel,sd)==0)
  9908. channel_send(channel,sd,message); //join success
  9909. }
  9910. else {
  9911. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9912. }
  9913. return;
  9914. }
  9915. }
  9916. // searching destination character
  9917. dstsd = map_nick2sd(target,false);
  9918. if (dstsd == nullptr || strcmp(dstsd->status.name, target) != 0) {
  9919. // player is not on this map-server
  9920. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9921. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9922. // and if we ask for 'Test', we must not contact 'test' player
  9923. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9924. intif_wis_message(sd, target, message, strlen(message) + 1);
  9925. return;
  9926. }
  9927. // if player ignores everyone
  9928. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9929. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9930. clif_wis_end( *sd, ACKWHISPER_TARGET_OFFLINE );
  9931. else
  9932. clif_wis_end( *sd, ACKWHISPER_ALL_IGNORED );
  9933. return;
  9934. }
  9935. // if player is autotrading
  9936. if (dstsd->state.autotrade == 1){
  9937. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9938. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9939. return;
  9940. }
  9941. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9942. // if player ignores the source character
  9943. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9944. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9945. clif_wis_end( *sd, ACKWHISPER_IGNORED );
  9946. return;
  9947. }
  9948. }
  9949. // notify sender of success
  9950. clif_wis_end( *sd, ACKWHISPER_SUCCESS );
  9951. // Normal message
  9952. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9953. }
  9954. /// /b /nb (CZ_BROADCAST).
  9955. /// Request to broadcast a message on whole server.
  9956. /// 0099 <packet len>.W <text>.?B 00
  9957. void clif_parse_Broadcast(int fd, map_session_data* sd) {
  9958. char command[CHAT_SIZE_MAX+11];
  9959. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9960. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9961. char* msg = RFIFOCP(fd,info->pos[1]);
  9962. // as the length varies depending on the command used, just block unreasonably long strings
  9963. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9964. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9965. is_atcommand(fd, sd, command, 1);
  9966. }
  9967. /// Request to pick up an item.
  9968. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9969. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9970. /// There are various variants of this packet, some of them have padding between fields.
  9971. void clif_parse_TakeItem(int fd, map_session_data *sd)
  9972. {
  9973. struct flooritem_data *fitem;
  9974. int map_object_id;
  9975. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9976. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9977. do {
  9978. if (pc_isdead(sd)) {
  9979. clif_clearunit_area( sd->bl, CLR_DEAD );
  9980. break;
  9981. }
  9982. if (fitem == nullptr || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9983. break;
  9984. if (pc_cant_act(sd))
  9985. break;
  9986. if (!pc_takeitem(sd, fitem))
  9987. break;
  9988. return;
  9989. } while (0);
  9990. // Client REQUIRES a fail packet or you can no longer pick items.
  9991. clif_additem(sd,0,0,6);
  9992. }
  9993. /// Request to drop an item.
  9994. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9995. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9996. /// There are various variants of this packet, some of them have padding between fields.
  9997. void clif_parse_DropItem(int fd, map_session_data *sd){
  9998. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9999. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10000. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10001. for(;;) {
  10002. if (pc_isdead(sd))
  10003. break;
  10004. if (pc_cant_act2(sd) || sd->npc_id)
  10005. break;
  10006. if (sd->sc.cant.drop)
  10007. break;
  10008. if (!pc_dropitem(sd, item_index, item_amount))
  10009. break;
  10010. if (battle_config.idletime_option&IDLE_DROPITEM)
  10011. sd->idletime = last_tick;
  10012. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10013. sd->idletime_hom = last_tick;
  10014. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10015. sd->idletime_mer = last_tick;
  10016. return;
  10017. }
  10018. //Because the client does not like being ignored.
  10019. clif_dropitem( *sd, item_index, 0 );
  10020. }
  10021. /// Request to use an item.
  10022. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10023. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10024. /// There are various variants of this packet, some of them have padding between fields.
  10025. void clif_parse_UseItem(int fd, map_session_data *sd)
  10026. {
  10027. int n;
  10028. if (pc_isdead(sd)) {
  10029. clif_clearunit_area( sd->bl, CLR_DEAD );
  10030. return;
  10031. }
  10032. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10033. clif_msg(sd, MSI_BUSY);
  10034. return;
  10035. }
  10036. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10037. if (battle_config.idletime_option&IDLE_USEITEM)
  10038. sd->idletime = last_tick;
  10039. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10040. sd->idletime_hom = last_tick;
  10041. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10042. sd->idletime_mer = last_tick;
  10043. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10044. if(n <0 || n >= MAX_INVENTORY)
  10045. return;
  10046. if (!pc_useitem(sd,n))
  10047. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10048. }
  10049. /// Request to equip an item
  10050. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10051. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10052. void clif_parse_EquipItem(int fd,map_session_data *sd)
  10053. {
  10054. int index;
  10055. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10056. if(pc_isdead(sd)) {
  10057. clif_clearunit_area( sd->bl, CLR_DEAD );
  10058. return;
  10059. }
  10060. index = RFIFOW(fd,info->pos[0])-2;
  10061. if (index < 0 || index >= MAX_INVENTORY)
  10062. return; //Out of bounds check.
  10063. if((sd->npc_id && !sd->npc_item_flag) || (sd->state.block_action & PCBLOCK_EQUIP)) {
  10064. clif_msg_color( sd, MSI_CAN_NOT_EQUIP_ITEM, color_table[COLOR_RED] );
  10065. return;
  10066. } else if (sd->state.storage_flag || sd->sc.opt1)
  10067. ; //You can equip/unequip stuff while storage is open/under status changes
  10068. else if (pc_cant_act2(sd))
  10069. return;
  10070. if(!sd->inventory.u.items_inventory[index].identify) {
  10071. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10072. return;
  10073. }
  10074. if(!sd->inventory_data[index])
  10075. return;
  10076. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10077. pet_equipitem(sd,index);
  10078. return;
  10079. }
  10080. if (battle_config.idletime_option&IDLE_USEITEM)
  10081. sd->idletime = last_tick;
  10082. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10083. sd->idletime_hom = last_tick;
  10084. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10085. sd->idletime_mer = last_tick;
  10086. //Client doesn't send the position for ammo.
  10087. if(sd->inventory_data[index]->type == IT_AMMO)
  10088. pc_equipitem(sd,index,EQP_AMMO);
  10089. else {
  10090. int req_pos;
  10091. #if PACKETVER >= 20120925
  10092. req_pos = RFIFOL(fd,info->pos[1]);
  10093. #else
  10094. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10095. #endif
  10096. pc_equipitem(sd,index,req_pos);
  10097. }
  10098. }
  10099. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10100. /// 00ab <index>.W
  10101. void clif_parse_UnequipItem(int fd,map_session_data *sd)
  10102. {
  10103. int index;
  10104. if(pc_isdead(sd)) {
  10105. clif_clearunit_area( sd->bl, CLR_DEAD );
  10106. return;
  10107. }
  10108. if((sd->npc_id && !sd->npc_item_flag) || (sd->state.block_action & PCBLOCK_EQUIP)) {
  10109. clif_msg_color( sd, MSI_CAN_NOT_EQUIP_ITEM, color_table[COLOR_RED] );
  10110. return;
  10111. } else if (sd->state.storage_flag || sd->sc.opt1)
  10112. ; //You can equip/unequip stuff while storage is open/under status changes
  10113. else if (pc_cant_act2(sd))
  10114. return;
  10115. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10116. if (battle_config.idletime_option&IDLE_USEITEM)
  10117. sd->idletime = last_tick;
  10118. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10119. sd->idletime_hom = last_tick;
  10120. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10121. sd->idletime_mer = last_tick;
  10122. pc_unequipitem(sd,index,1);
  10123. }
  10124. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10125. /// 0090 <id>.L <type>.B
  10126. /// type:
  10127. /// 1 = click
  10128. void clif_parse_NpcClicked(int fd,map_session_data *sd)
  10129. {
  10130. if( sd == nullptr ){
  10131. return;
  10132. }
  10133. struct block_list *bl;
  10134. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10135. if(pc_isdead(sd)) {
  10136. clif_clearunit_area( sd->bl, CLR_DEAD );
  10137. return;
  10138. }
  10139. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10140. #ifdef RENEWAL
  10141. clif_msg( sd, MSI_BUSY);
  10142. #endif
  10143. return;
  10144. }
  10145. if( sd->state.mail_writing )
  10146. return;
  10147. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10148. //type = RFIFOB(fd,info->pos[1]);
  10149. if (!bl) return;
  10150. switch (bl->type) {
  10151. case BL_MOB:
  10152. case BL_PC:
  10153. clif_parse_ActionRequest_sub( *sd, 0x07, bl->id, gettick() );
  10154. break;
  10155. case BL_NPC:
  10156. #ifdef RENEWAL
  10157. 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
  10158. clif_msg(sd, MSI_BUSY);
  10159. break;
  10160. }
  10161. #endif
  10162. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10163. struct npc_data* nd = (struct npc_data*)bl;
  10164. // Progressbar is running
  10165. if( nd->progressbar.timeout > 0 ){
  10166. return;
  10167. }
  10168. npc_click(sd,nd);
  10169. }
  10170. break;
  10171. }
  10172. }
  10173. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10174. /// 00c5 <id>.L <type>.B
  10175. /// type:
  10176. /// 0 = buy
  10177. /// 1 = sell
  10178. void clif_parse_NpcBuySellSelected(int fd,map_session_data *sd)
  10179. {
  10180. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10181. if (sd->state.trading)
  10182. return;
  10183. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10184. }
  10185. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10186. /// 00ca <result>.B
  10187. /// result:
  10188. /// 0 = "The deal has successfully completed."
  10189. /// 1 = "You do not have enough zeny."
  10190. /// 2 = "You are over your Weight Limit."
  10191. /// 3 = "Out of the maximum capacity, you have too many items."
  10192. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10193. /// 10 = "Props open-air store sales will be traded in RODEX"
  10194. /// 11 = "The exchange failed."
  10195. /// 12 = "The exchange was well done."
  10196. /// 13 = "The item is already sold and out of stock."
  10197. /// 14 = "There is not enough goods to exchange."
  10198. void clif_npc_buy_result( map_session_data* sd, e_purchase_result result ){
  10199. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10200. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10201. p.result = (uint8)result;
  10202. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10203. }
  10204. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10205. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10206. void clif_parse_NpcBuyListSend( int fd, map_session_data* sd ){
  10207. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10208. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10209. e_purchase_result result;
  10210. if( sd->state.trading || !sd->npc_shopid )
  10211. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10212. else{
  10213. std::vector<s_npc_buy_list> items = {};
  10214. items.reserve( n );
  10215. for( uint16 i = 0; i < n; i++ ){
  10216. s_npc_buy_list item = {};
  10217. item.nameid = p->items[i].itemId;
  10218. item.qty = p->items[i].amount;
  10219. items.push_back( item );
  10220. }
  10221. result = npc_buylist( sd, items );
  10222. }
  10223. sd->npc_shopid = 0; //Clear shop data.
  10224. clif_npc_buy_result(sd, result);
  10225. }
  10226. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10227. /// 00cb <result>.B
  10228. /// result:
  10229. /// 0 = "The deal has successfully completed."
  10230. /// 1 = "The deal has failed."
  10231. void clif_npc_sell_result(map_session_data* sd, unsigned char result)
  10232. {
  10233. int fd = sd->fd;
  10234. WFIFOHEAD(fd,packet_len(0xcb));
  10235. WFIFOW(fd,0) = 0xcb;
  10236. WFIFOB(fd,2) = result;
  10237. WFIFOSET(fd,packet_len(0xcb));
  10238. }
  10239. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10240. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10241. void clif_parse_NpcSellListSend(int fd,map_session_data *sd)
  10242. {
  10243. int fail=0,n;
  10244. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10245. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10246. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10247. if (sd->state.trading || !sd->npc_shopid)
  10248. fail = 1;
  10249. else
  10250. fail = npc_selllist(sd, n, p->sellList);
  10251. sd->npc_shopid = 0; //Clear shop data.
  10252. clif_npc_sell_result(sd, fail);
  10253. }
  10254. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10255. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10256. /// type:
  10257. /// 0 = private
  10258. /// 1 = public
  10259. void clif_parse_CreateChatRoom(int fd, map_session_data* sd)
  10260. {
  10261. if( sd == nullptr ){
  10262. return;
  10263. }
  10264. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10265. int len = RFIFOW(fd,info->pos[0])-15;
  10266. int limit = RFIFOW(fd,info->pos[1]);
  10267. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10268. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10269. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10270. char s_password[CHATROOM_PASS_SIZE];
  10271. char s_title[CHATROOM_TITLE_SIZE];
  10272. if (sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM)
  10273. return;
  10274. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10275. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 3 );
  10276. return;
  10277. }
  10278. if( npc_isnear(&sd->bl) ) {
  10279. // uncomment to send msg_txt.
  10280. //char output[150];
  10281. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10282. //clif_displaymessage(sd->fd, output);
  10283. clif_skill_fail( *sd, 1, USESKILL_FAIL_THERE_ARE_NPC_AROUND );
  10284. return;
  10285. }
  10286. if( len <= 0 )
  10287. return; // invalid input
  10288. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10289. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10290. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10291. }
  10292. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10293. /// 00d9 <chat ID>.L <passwd>.8B
  10294. void clif_parse_ChatAddMember(int fd, map_session_data* sd){
  10295. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10296. int chatid = RFIFOL(fd,info->pos[0]);
  10297. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10298. chat_joinchat(sd,chatid,password);
  10299. }
  10300. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10301. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10302. /// type:
  10303. /// 0 = private
  10304. /// 1 = public
  10305. void clif_parse_ChatRoomStatusChange(int fd, map_session_data* sd){
  10306. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10307. int len = RFIFOW(fd,info->pos[0])-15;
  10308. int limit = RFIFOW(fd,info->pos[1]);
  10309. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10310. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10311. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10312. char s_password[CHATROOM_PASS_SIZE];
  10313. char s_title[CHATROOM_TITLE_SIZE];
  10314. if( len <= 0 )
  10315. return; // invalid input
  10316. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10317. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10318. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10319. }
  10320. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10321. /// 00e0 <role>.L <nick>.24B
  10322. /// role:
  10323. /// 0 = owner
  10324. /// 1 = normal
  10325. void clif_parse_ChangeChatOwner(int fd, map_session_data* sd)
  10326. {
  10327. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10328. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10329. }
  10330. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10331. /// 00e2 <name>.24B
  10332. void clif_parse_KickFromChat(int fd,map_session_data *sd)
  10333. {
  10334. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10335. }
  10336. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10337. /// 00e3
  10338. void clif_parse_ChatLeave(int fd, map_session_data* sd)
  10339. {
  10340. chat_leavechat(sd,0);
  10341. }
  10342. //Handles notifying asker and rejecter of what has just ocurred.
  10343. //Type is used to determine the correct msg_txt to use:
  10344. //0:
  10345. static void clif_noask_sub(map_session_data *sd, map_session_data *tsd, int type)
  10346. {
  10347. const char* msg;
  10348. char output[256];
  10349. // Your request has been rejected by autoreject option.
  10350. msg = msg_txt(sd,392);
  10351. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10352. //Notice that a request was rejected.
  10353. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10354. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10355. }
  10356. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10357. /// 00e4 <account id>.L
  10358. void clif_parse_TradeRequest(int fd,map_session_data *sd)
  10359. {
  10360. map_session_data *t_sd;
  10361. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10362. if(!sd->chatID && pc_cant_act(sd))
  10363. return; //You can trade while in a chatroom.
  10364. if(t_sd){
  10365. // @noask [LuzZza]
  10366. if(t_sd->state.noask) {
  10367. clif_noask_sub(sd, t_sd, 0);
  10368. return;
  10369. }
  10370. if (t_sd->state.mail_writing) {
  10371. int old = sd->trade_partner;
  10372. // Fake trading
  10373. sd->trade_partner = t_sd->status.account_id;
  10374. clif_tradestart(sd, 5);
  10375. // Restore old state
  10376. sd->trade_partner = old;
  10377. return;
  10378. }
  10379. }
  10380. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10381. clif_skill_fail( *sd, 1 );
  10382. return;
  10383. }
  10384. trade_traderequest(sd,t_sd);
  10385. }
  10386. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10387. /// 00e6 <result>.B
  10388. /// result:
  10389. /// 3 = accepted
  10390. /// 4 = rejected
  10391. void clif_parse_TradeAck(int fd,map_session_data *sd)
  10392. {
  10393. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10394. }
  10395. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10396. /// 00e8 <index>.W <amount>.L
  10397. void clif_parse_TradeAddItem(int fd,map_session_data *sd)
  10398. {
  10399. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10400. short index = RFIFOW(fd,info->pos[0]);
  10401. int amount = RFIFOL(fd,info->pos[1]);
  10402. if( index == 0 )
  10403. trade_tradeaddzeny(sd, amount);
  10404. else
  10405. trade_tradeadditem(sd, server_index(index), (short)amount);
  10406. }
  10407. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10408. /// 00eb
  10409. void clif_parse_TradeOk(int fd,map_session_data *sd)
  10410. {
  10411. trade_tradeok(sd);
  10412. }
  10413. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10414. /// 00ed
  10415. void clif_parse_TradeCancel(int fd,map_session_data *sd)
  10416. {
  10417. trade_tradecancel(sd);
  10418. }
  10419. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10420. /// 00ef
  10421. void clif_parse_TradeCommit(int fd,map_session_data *sd)
  10422. {
  10423. trade_tradecommit(sd);
  10424. }
  10425. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10426. /// 0118
  10427. void clif_parse_StopAttack(int fd,map_session_data *sd)
  10428. {
  10429. pc_stop_attack(sd);
  10430. if (sd) sd->ud.state.attack_continue = 0;
  10431. }
  10432. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10433. /// 0126 <index>.W <amount>.L
  10434. void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
  10435. if (pc_istrading(sd) || !pc_iscarton(sd) || pc_cant_act2(sd))
  10436. return;
  10437. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10438. return;
  10439. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10440. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10441. }
  10442. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10443. /// 0127 <index>.W <amount>.L
  10444. void clif_parse_GetItemFromCart(int fd,map_session_data *sd)
  10445. {
  10446. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10447. if (!pc_iscarton(sd) || pc_cant_act2(sd))
  10448. return;
  10449. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10450. return;
  10451. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10452. }
  10453. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10454. /// 012a
  10455. void clif_parse_RemoveOption(int fd,map_session_data *sd)
  10456. {
  10457. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10458. #ifdef NEW_CARTS
  10459. && sd->sc.getSCE(SC_PUSH_CART) )
  10460. pc_setcart(sd,0);
  10461. #else
  10462. )
  10463. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10464. #endif
  10465. else // priority to remove this option before we can clear cart
  10466. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10467. }
  10468. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10469. /// 097f <Length>.W <identity>.L <type>.B
  10470. void clif_SelectCart(map_session_data *sd) {
  10471. #if PACKETVER >= 20150826
  10472. int i = 0, carts = 3;
  10473. int fd = sd->fd;
  10474. WFIFOHEAD(fd,8 + carts);
  10475. WFIFOW(fd,0) = 0x97f;
  10476. WFIFOW(fd,2) = 8 + carts;
  10477. WFIFOL(fd,4) = sd->status.account_id;
  10478. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10479. for( i = 0; i < carts; i++ ) {
  10480. WFIFOB(fd,8 + i) = 10 + i;
  10481. }
  10482. WFIFOSET(fd,8 + carts);
  10483. #endif
  10484. }
  10485. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10486. /// 0980 <identity>.L <type>.B
  10487. void clif_parse_SelectCart(int fd,map_session_data *sd) {
  10488. #if PACKETVER >= 20150826
  10489. int type;
  10490. // Check identity
  10491. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10492. return;
  10493. type = (int)RFIFOB(fd,6);
  10494. // Check type
  10495. if( type < 10 || type > 12 )
  10496. return;
  10497. pc_setcart(sd, type);
  10498. #endif
  10499. }
  10500. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10501. /// 01af <num>.W
  10502. void clif_parse_ChangeCart(int fd,map_session_data *sd)
  10503. {// TODO: State tracking?
  10504. int type;
  10505. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10506. return;
  10507. #ifdef RENEWAL
  10508. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10509. clif_msg(sd, MSI_BUSY);
  10510. return;
  10511. }
  10512. #endif
  10513. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10514. if(
  10515. #ifdef NEW_CARTS
  10516. #if PACKETVER >= 20191106
  10517. (type == 13 && sd->status.base_level > 100) ||
  10518. #endif
  10519. (type == 9 && sd->status.base_level > 130) ||
  10520. (type == 8 && sd->status.base_level > 120) ||
  10521. (type == 7 && sd->status.base_level > 110) ||
  10522. (type == 6 && sd->status.base_level > 100) ||
  10523. #endif
  10524. (type == 5 && sd->status.base_level > 90) ||
  10525. (type == 4 && sd->status.base_level > 80) ||
  10526. (type == 3 && sd->status.base_level > 65) ||
  10527. (type == 2 && sd->status.base_level > 40) ||
  10528. (type == 1))
  10529. pc_setcart(sd, type);
  10530. }
  10531. /// Request to increase status (CZ_STATUS_CHANGE).
  10532. /// 00bb <status id>.W <amount>.B
  10533. /// status id:
  10534. /// SP_STR ~ SP_LUK
  10535. /// amount:
  10536. /// Old clients always send 1 for this, even when using /str+ and the like.
  10537. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10538. void clif_parse_StatusUp(int fd,map_session_data *sd)
  10539. {
  10540. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10541. if( increase_amount < 0 ) {
  10542. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10543. fd, increase_amount);
  10544. }
  10545. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10546. }
  10547. /// Request to increase trait status.
  10548. /// 0b24 <status id>.W <amount>.W
  10549. /// status id:
  10550. /// SP_POW ~ SP_CON
  10551. /// amount:
  10552. /// The amount to increase the trait status
  10553. void clif_parse_traitstatus_up( int fd, map_session_data *sd ){
  10554. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10555. struct PACKET_CZ_ADVANCED_STATUS_CHANGE* p = (struct PACKET_CZ_ADVANCED_STATUS_CHANGE*)RFIFOP( fd, 0 );
  10556. if( p->amount < 0 ){
  10557. 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 );
  10558. return;
  10559. }
  10560. pc_traitstatusup( sd, p->type, p->amount );
  10561. #endif
  10562. }
  10563. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10564. /// 0112 <skill id>.W
  10565. void clif_parse_SkillUp(int fd,map_session_data *sd)
  10566. {
  10567. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10568. }
  10569. 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)
  10570. {
  10571. int lv;
  10572. if( !hd )
  10573. return;
  10574. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10575. clif_emotion(&hd->bl, ET_THINK);
  10576. return;
  10577. }
  10578. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10579. target_id = hd->bl.id;
  10580. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10581. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10582. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10583. clif_emotion(&hd->bl, ET_THINK);
  10584. if (hd->master)
  10585. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10586. return;
  10587. }
  10588. lv = hom_checkskill(hd, skill_id);
  10589. if( skill_lv > lv )
  10590. skill_lv = lv;
  10591. if( skill_lv )
  10592. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10593. }
  10594. 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)
  10595. {
  10596. int lv;
  10597. if( !hd )
  10598. return;
  10599. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10600. clif_emotion(&hd->bl, ET_THINK);
  10601. return;
  10602. }
  10603. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10604. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10605. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10606. clif_emotion(&hd->bl, ET_THINK);
  10607. if (hd->master)
  10608. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10609. return;
  10610. }
  10611. #ifdef RENEWAL
  10612. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10613. #else
  10614. if (hd->sc.getSCE(SC_BASILICA))
  10615. #endif
  10616. return;
  10617. lv = hom_checkskill(hd, skill_id);
  10618. if( skill_lv > lv )
  10619. skill_lv = lv;
  10620. if( skill_lv )
  10621. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10622. }
  10623. 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)
  10624. {
  10625. int lv;
  10626. if( !md )
  10627. return;
  10628. if( skill_isNotOk_mercenary(skill_id, *md) )
  10629. return;
  10630. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10631. target_id = md->bl.id;
  10632. if( md->ud.skilltimer != INVALID_TIMER )
  10633. {
  10634. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10635. }
  10636. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10637. return;
  10638. lv = mercenary_checkskill(md, skill_id);
  10639. if( skill_lv > lv )
  10640. skill_lv = lv;
  10641. if( skill_lv )
  10642. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10643. }
  10644. 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)
  10645. {
  10646. int lv;
  10647. if( !md )
  10648. return;
  10649. if( skill_isNotOk_mercenary(skill_id, *md) )
  10650. return;
  10651. if( md->ud.skilltimer != INVALID_TIMER )
  10652. return;
  10653. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10654. {
  10655. if (md->master)
  10656. clif_skill_fail( *md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10657. return;
  10658. }
  10659. #ifdef RENEWAL
  10660. if (md->sc.getSCE(SC_BASILICA_CELL))
  10661. #else
  10662. if (md->sc.getSCE(SC_BASILICA))
  10663. #endif
  10664. return;
  10665. lv = mercenary_checkskill(md, skill_id);
  10666. if( skill_lv > lv )
  10667. skill_lv = lv;
  10668. if( skill_lv )
  10669. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10670. }
  10671. void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10672. if( sd == nullptr ){
  10673. return;
  10674. }
  10675. t_tick tick = gettick();
  10676. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10677. int inf = skill_get_inf(skill_id);
  10678. if (inf&INF_GROUND_SKILL || !inf)
  10679. return; //Using a ground/passive skill on a target? WRONG.
  10680. if (sd->state.block_action & PCBLOCK_SKILL) {
  10681. clif_msg(sd, MSI_BUSY);
  10682. return;
  10683. }
  10684. if( SKILL_CHK_HOMUN(skill_id) ) {
  10685. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10686. return;
  10687. }
  10688. if( SKILL_CHK_MERC(skill_id) ) {
  10689. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10690. return;
  10691. }
  10692. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10693. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10694. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10695. sd->idletime = last_tick;
  10696. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10697. sd->idletime_hom = last_tick;
  10698. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10699. sd->idletime_mer = last_tick;
  10700. if( sd->npc_id ){
  10701. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10702. #ifdef RENEWAL
  10703. clif_msg( sd, MSI_BUSY);
  10704. #endif
  10705. return;
  10706. }
  10707. }
  10708. if ((pc_cant_act2(sd) || sd->chatID) &&
  10709. skill_id != RK_REFRESH &&
  10710. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10711. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10712. return;
  10713. if( pc_issit(sd) )
  10714. return;
  10715. if( skill_isNotOk(skill_id, *sd) )
  10716. return;
  10717. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10718. target_id = sd->bl.id; // never trust the client
  10719. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10720. target_id = sd->bl.id;
  10721. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10722. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10723. return;
  10724. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10725. if( sd->skillitem != skill_id ) {
  10726. clif_skill_fail( *sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10727. return;
  10728. }
  10729. }
  10730. if( sd->sc.option&OPTION_COSTUME )
  10731. return;
  10732. #ifndef RENEWAL
  10733. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10734. return; // On basilica only caster can use Basilica again to stop it.
  10735. #endif
  10736. if( sd->menuskill_id ) {
  10737. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10738. clif_menuskill_clear(sd); //Cancel pet capture.
  10739. }else if( sd->menuskill_id == SG_FEEL ){
  10740. clif_menuskill_clear( sd ); // Cancel selection
  10741. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10742. return; //Can't use skills while a menu is open.
  10743. }
  10744. if( sd->skillitem == skill_id ) {
  10745. if( skill_lv != sd->skillitemlv )
  10746. skill_lv = sd->skillitemlv;
  10747. if( !(inf&INF_SELF_SKILL) )
  10748. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10749. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10750. return;
  10751. }
  10752. sd->skillitem = sd->skillitemlv = 0;
  10753. if( SKILL_CHK_GUILD(skill_id) ) {
  10754. if (sd->guild && sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING)
  10755. skill_lv = guild_checkskill(sd->guild->guild, skill_id);
  10756. else
  10757. skill_lv = 0;
  10758. } else {
  10759. if( skill_id != ALL_EQSWITCH ){
  10760. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10761. }
  10762. }
  10763. pc_delinvincibletimer(sd);
  10764. if( skill_lv )
  10765. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10766. }
  10767. /// Request to use a targeted skill.
  10768. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10769. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10770. /// There are various variants of this packet, some of them have padding between fields.
  10771. void clif_parse_UseSkillToId( int fd, map_session_data *sd ){
  10772. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10773. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10774. }
  10775. /*==========================================
  10776. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10777. *------------------------------------------*/
  10778. static void clif_parse_UseSkillToPosSub( int fd, map_session_data& sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo ){
  10779. t_tick tick = gettick();
  10780. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10781. return; //Using a target skill on the ground? WRONG.
  10782. if (sd.state.block_action & PCBLOCK_SKILL) {
  10783. clif_msg(&sd, MSI_BUSY);
  10784. return;
  10785. }
  10786. if( SKILL_CHK_HOMUN(skill_id) ) {
  10787. clif_parse_UseSkillToPos_homun(sd.hd, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10788. return;
  10789. }
  10790. if( SKILL_CHK_MERC(skill_id) ) {
  10791. clif_parse_UseSkillToPos_mercenary(sd.md, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10792. return;
  10793. }
  10794. if( pc_hasprogress( &sd, WIP_DISABLE_SKILLITEM ) ){
  10795. #ifdef RENEWAL
  10796. clif_msg( &sd, MSI_BUSY);
  10797. #endif
  10798. return;
  10799. }
  10800. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10801. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10802. sd.idletime = last_tick;
  10803. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10804. sd.idletime_hom = last_tick;
  10805. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10806. sd.idletime_mer = last_tick;
  10807. if( skill_isNotOk(skill_id, sd) )
  10808. return;
  10809. if( skillmoreinfo != -1 ) {
  10810. if( pc_issit(&sd) ) {
  10811. clif_skill_fail( sd, skill_id );
  10812. return;
  10813. }
  10814. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10815. safestrncpy(sd.message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10816. }
  10817. if( sd.ud.skilltimer != INVALID_TIMER )
  10818. return;
  10819. if( DIFF_TICK(tick, sd.ud.canact_tick) < 0 ) {
  10820. if( sd.skillitem != skill_id ) {
  10821. clif_skill_fail( sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10822. return;
  10823. }
  10824. }
  10825. if( sd.sc.option&OPTION_COSTUME )
  10826. return;
  10827. #ifndef RENEWAL
  10828. if( sd.sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd.sc.getSCE(SC_BASILICA)->val4 != sd.bl.id) )
  10829. return; // On basilica only caster can use Basilica again to stop it.
  10830. #endif
  10831. if( sd.menuskill_id ) {
  10832. if( sd.menuskill_id == SA_TAMINGMONSTER ) {
  10833. clif_menuskill_clear(&sd); //Cancel pet capture.
  10834. }else if( sd.menuskill_id == SG_FEEL ){
  10835. clif_menuskill_clear( &sd ); // Cancel selection
  10836. } else if( sd.menuskill_id != SA_AUTOSPELL )
  10837. return; //Can't use skills while a menu is open.
  10838. }
  10839. pc_delinvincibletimer(&sd);
  10840. if( sd.skillitem == skill_id ) {
  10841. if( skill_lv != sd.skillitemlv )
  10842. skill_lv = sd.skillitemlv;
  10843. unit_skilluse_pos(&sd.bl, x, y, skill_id, skill_lv);
  10844. } else {
  10845. int lv;
  10846. sd.skillitem = sd.skillitemlv = 0;
  10847. if( (lv = pc_checkskill(&sd, skill_id)) > 0 ) {
  10848. if( skill_lv > lv )
  10849. skill_lv = lv;
  10850. unit_skilluse_pos(&sd.bl, x, y, skill_id,skill_lv);
  10851. }
  10852. }
  10853. }
  10854. /// Request to use a ground skill.
  10855. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10856. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10857. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10858. /// There are various variants of this packet, some of them have padding between fields.
  10859. void clif_parse_UseSkillToPos(int fd, map_session_data *sd)
  10860. {
  10861. if( sd == nullptr ){
  10862. return;
  10863. }
  10864. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10865. if (pc_cant_act(sd))
  10866. return;
  10867. if (pc_issit(sd))
  10868. return;
  10869. clif_parse_UseSkillToPosSub(fd, *sd,
  10870. RFIFOW(fd,info->pos[0]), //skill lv
  10871. RFIFOW(fd,info->pos[1]), //skill num
  10872. RFIFOW(fd,info->pos[2]), //pos x
  10873. RFIFOW(fd,info->pos[3]), //pos y
  10874. // TODO: find out what this is intended to do
  10875. //RFIFOB(fd, info->pos[4])
  10876. -1 //Skill more info.
  10877. );
  10878. }
  10879. /// Request to use a ground skill with text.
  10880. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10881. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10882. /// There are various variants of this packet, some of them have padding between fields.
  10883. void clif_parse_UseSkillToPosMoreInfo(int fd, map_session_data *sd)
  10884. {
  10885. if( sd == nullptr ){
  10886. return;
  10887. }
  10888. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10889. if (pc_cant_act(sd))
  10890. return;
  10891. if (pc_issit(sd))
  10892. return;
  10893. clif_parse_UseSkillToPosSub(fd, *sd,
  10894. RFIFOW(fd,info->pos[0]), //Skill lv
  10895. RFIFOW(fd,info->pos[1]), //Skill num
  10896. RFIFOW(fd,info->pos[2]), //pos x
  10897. RFIFOW(fd,info->pos[3]), //pos y
  10898. info->pos[4] //skill more info
  10899. );
  10900. }
  10901. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10902. /// 011b <skill id>.W <map name>.16B
  10903. void clif_parse_UseSkillMap(int fd, map_session_data* sd)
  10904. {
  10905. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10906. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10907. char map_name[MAP_NAME_LENGTH];
  10908. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10909. sd->state.workinprogress = WIP_DISABLE_NONE;
  10910. if(skill_id != sd->menuskill_id)
  10911. return;
  10912. //It is possible to use teleport with the storage window open bugreport:8027
  10913. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10914. clif_menuskill_clear(sd);
  10915. return;
  10916. }
  10917. pc_delinvincibletimer(sd);
  10918. skill_castend_map(sd,skill_id,map_name);
  10919. }
  10920. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10921. /// 011d
  10922. void clif_parse_RequestMemo(int fd,map_session_data *sd)
  10923. {
  10924. if (!pc_isdead(sd))
  10925. pc_memo(sd,-1);
  10926. }
  10927. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10928. /// 018e <name id>.W { <material id>.W }*3
  10929. void clif_parse_ProduceMix(int fd,map_session_data *sd){
  10930. if( sd == nullptr ){
  10931. return;
  10932. }
  10933. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10934. switch( sd->menuskill_id ) {
  10935. case -1:
  10936. case AM_PHARMACY:
  10937. case RK_RUNEMASTERY:
  10938. case GC_RESEARCHNEWPOISON:
  10939. break;
  10940. default:
  10941. return;
  10942. }
  10943. if (pc_istrading(sd)) {
  10944. //Make it fail to avoid shop exploits where you sell something different than you see.
  10945. clif_skill_fail( *sd, sd->ud.skill_id );
  10946. clif_menuskill_clear(sd);
  10947. return;
  10948. }
  10949. int produce_idx;
  10950. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10951. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10952. clif_menuskill_clear(sd);
  10953. }
  10954. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10955. /// 025b <mk type>.W <name id>.W
  10956. /// mk type:
  10957. /// 1 = cooking
  10958. /// 2 = arrow
  10959. /// 3 = elemental
  10960. /// 4 = GN_MIX_COOKING
  10961. /// 5 = GN_MAKEBOMB
  10962. /// 6 = GN_S_PHARMACY
  10963. /// 7 = MT_M_MACHINE - Unconfirmed
  10964. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  10965. void clif_parse_Cooking(int fd,map_session_data *sd) {
  10966. if( sd == nullptr ){
  10967. return;
  10968. }
  10969. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10970. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10971. short food_idx = -1;
  10972. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10973. return;
  10974. if (pc_istrading(sd)) {
  10975. //Make it fail to avoid shop exploits where you sell something different than you see.
  10976. clif_skill_fail( *sd, sd->ud.skill_id );
  10977. clif_menuskill_clear(sd);
  10978. return;
  10979. }
  10980. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10981. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10982. clif_menuskill_clear(sd);
  10983. }
  10984. /// Answer to repair weapon item selection dialog
  10985. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10986. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10987. void clif_parse_RepairItem( int fd, map_session_data *sd ){
  10988. if( sd == nullptr ){
  10989. return;
  10990. }
  10991. // Hercules has wrong date -> use correct one here
  10992. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10993. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  10994. #else
  10995. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  10996. #endif
  10997. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10998. return;
  10999. if (pc_istrading(sd)) {
  11000. //Make it fail to avoid shop exploits where you sell something different than you see.
  11001. clif_skill_fail( *sd, sd->ud.skill_id );
  11002. clif_menuskill_clear(sd);
  11003. return;
  11004. }
  11005. skill_repairweapon( *sd, p->item.index );
  11006. clif_menuskill_clear(sd);
  11007. }
  11008. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11009. /// 0222 <index>.L
  11010. void clif_parse_WeaponRefine( int fd, map_session_data *sd ){
  11011. if( sd == nullptr ){
  11012. return;
  11013. }
  11014. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11015. return;
  11016. if (pc_istrading(sd)) {
  11017. //Make it fail to avoid shop exploits where you sell something different than you see.
  11018. clif_skill_fail( *sd, sd->ud.skill_id );
  11019. clif_menuskill_clear(sd);
  11020. return;
  11021. }
  11022. skill_weaponrefine( *sd, server_index( RFIFOL( fd, 2 ) ) );
  11023. clif_menuskill_clear(sd);
  11024. }
  11025. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11026. /// 00b8 <npc id>.L <choice>.B
  11027. /// choice:
  11028. /// 1~254 = menu item
  11029. /// 255 = cancel
  11030. /// NOTE: If there were more than 254 items in the list, choice
  11031. /// overflows to choice%256.
  11032. void clif_parse_NpcSelectMenu(int fd,map_session_data *sd){
  11033. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11034. int npc_id = RFIFOL(fd,info->pos[0]);
  11035. uint8 select = RFIFOB(fd,info->pos[1]);
  11036. #ifdef SECURE_NPCTIMEOUT
  11037. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11038. return;
  11039. #endif
  11040. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11041. TBL_NPC* nd = map_id2nd(npc_id);
  11042. 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);
  11043. clif_GM_kick(nullptr,sd);
  11044. return;
  11045. }
  11046. sd->npc_menu = select;
  11047. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11048. sd->idletime = last_tick;
  11049. }
  11050. npc_scriptcont(sd,npc_id, false);
  11051. }
  11052. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11053. /// 00b9 <npc id>.L
  11054. void clif_parse_NpcNextClicked(int fd,map_session_data *sd)
  11055. {
  11056. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11057. sd->idletime = last_tick;
  11058. }
  11059. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11060. }
  11061. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11062. /// 0143 <npc id>.L <value>.L
  11063. void clif_parse_NpcAmountInput(int fd,map_session_data *sd){
  11064. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11065. int npcid = RFIFOL(fd,info->pos[0]);
  11066. int amount = (int)RFIFOL(fd,info->pos[1]);
  11067. sd->npc_amount = amount;
  11068. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11069. sd->idletime = last_tick;
  11070. }
  11071. npc_scriptcont(sd, npcid, false);
  11072. }
  11073. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11074. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11075. void clif_parse_NpcStringInput(int fd, map_session_data* sd){
  11076. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11077. int message_len = RFIFOW(fd,info->pos[0])-8;
  11078. int npcid = RFIFOL(fd,info->pos[1]);
  11079. const char* message = RFIFOCP(fd,info->pos[2]);
  11080. if( message_len <= 0 )
  11081. return; // invalid input
  11082. #if PACKETVER >= 20151001
  11083. message_len++;
  11084. #endif
  11085. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11086. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11087. sd->idletime = last_tick;
  11088. }
  11089. npc_scriptcont(sd, npcid, false);
  11090. }
  11091. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11092. /// 0146 <npc id>.L
  11093. void clif_parse_NpcCloseClicked(int fd,map_session_data *sd)
  11094. {
  11095. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11096. return;
  11097. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11098. sd->idletime = last_tick;
  11099. }
  11100. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11101. }
  11102. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11103. /// 0178 <index>.W
  11104. /// index:
  11105. /// -1 = cancel
  11106. void clif_parse_ItemIdentify(int fd,map_session_data *sd) {
  11107. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11108. if (sd->menuskill_id != MC_IDENTIFY)
  11109. return;
  11110. // Ignore the request
  11111. // - Invalid item index
  11112. // - Invalid item ID or item doesn't exist
  11113. // - Item is already identified
  11114. if (idx < 0 || idx >= MAX_INVENTORY ||
  11115. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == nullptr ||
  11116. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11117. sd->state.workinprogress = WIP_DISABLE_NONE;
  11118. clif_menuskill_clear(sd);
  11119. return;
  11120. }
  11121. skill_identify(sd, idx);
  11122. clif_menuskill_clear(sd);
  11123. }
  11124. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11125. /// 01ae <name id>.W
  11126. void clif_parse_SelectArrow(int fd,map_session_data *sd) {
  11127. if( sd == nullptr ){
  11128. return;
  11129. }
  11130. if (pc_istrading(sd)) {
  11131. //Make it fail to avoid shop exploits where you sell something different than you see.
  11132. clif_skill_fail( *sd, sd->ud.skill_id );
  11133. clif_menuskill_clear(sd);
  11134. return;
  11135. }
  11136. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11137. switch (sd->menuskill_id) {
  11138. case AC_MAKINGARROW:
  11139. skill_arrow_create(sd,p->itemId);
  11140. break;
  11141. case SA_CREATECON:
  11142. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11143. break;
  11144. case GC_POISONINGWEAPON:
  11145. skill_poisoningweapon(*sd,p->itemId);
  11146. break;
  11147. case NC_MAGICDECOY:
  11148. skill_magicdecoy(*sd,p->itemId);
  11149. break;
  11150. }
  11151. clif_menuskill_clear(sd);
  11152. }
  11153. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11154. /// 01ce <skill id>.L
  11155. void clif_parse_AutoSpell(int fd,map_session_data *sd)
  11156. {
  11157. if (sd->menuskill_id != SA_AUTOSPELL)
  11158. return;
  11159. sd->state.workinprogress = WIP_DISABLE_NONE;
  11160. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11161. clif_menuskill_clear(sd);
  11162. }
  11163. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11164. /// 017a <card index>.W
  11165. void clif_parse_UseCard(int fd,map_session_data *sd)
  11166. {
  11167. if (sd->state.trading != 0)
  11168. return;
  11169. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11170. }
  11171. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11172. /// 017c <card index>.W <equip index>.W
  11173. void clif_parse_InsertCard(int fd,map_session_data *sd)
  11174. {
  11175. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11176. if (sd->state.trading != 0)
  11177. return;
  11178. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11179. }
  11180. /// Request of character's name by char ID.
  11181. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11182. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11183. /// There are various variants of this packet, some of them have padding between fields.
  11184. void clif_parse_SolveCharName(int fd, map_session_data *sd)
  11185. {
  11186. int charid;
  11187. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11188. map_reqnickdb(sd, charid);
  11189. }
  11190. /// /resetskill /resetstate (CZ_RESET).
  11191. /// Request to reset stats or skills.
  11192. /// 0197 <type>.W
  11193. /// type:
  11194. /// 0 = state
  11195. /// 1 = skill
  11196. void clif_parse_ResetChar(int fd, map_session_data *sd) {
  11197. char cmd[15];
  11198. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11199. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11200. else
  11201. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11202. is_atcommand(fd, sd, cmd, 1);
  11203. }
  11204. /// /lb /nlb (CZ_LOCALBROADCAST).
  11205. /// Request to broadcast a message on current map.
  11206. /// 019c <packet len>.W <text>.?B
  11207. void clif_parse_LocalBroadcast(int fd, map_session_data* sd)
  11208. {
  11209. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11210. char command[CHAT_SIZE_MAX+16];
  11211. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11212. char* msg = RFIFOCP(fd,info->pos[1]);
  11213. // as the length varies depending on the command used, just block unreasonably long strings
  11214. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11215. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11216. is_atcommand(fd, sd, command, 1);
  11217. }
  11218. /// Request to move an item from inventory to storage.
  11219. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11220. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11221. /// There are various variants of this packet, some of them have padding between fields.
  11222. void clif_parse_MoveToKafra(int fd, map_session_data *sd)
  11223. {
  11224. int item_index, item_amount;
  11225. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11226. if (pc_istrading(sd))
  11227. return;
  11228. item_index = RFIFOW(fd,info->pos[0])-2;
  11229. item_amount = RFIFOL(fd,info->pos[1]);
  11230. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11231. return;
  11232. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11233. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  11234. return;
  11235. }
  11236. if (sd->state.storage_flag == 1)
  11237. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11238. else
  11239. if (sd->state.storage_flag == 2)
  11240. storage_guild_storageadd(sd, item_index, item_amount);
  11241. else if (sd->state.storage_flag == 3)
  11242. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11243. }
  11244. /// Request to move an item from storage to inventory.
  11245. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11246. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11247. /// There are various variants of this packet, some of them have padding between fields.
  11248. void clif_parse_MoveFromKafra(int fd,map_session_data *sd)
  11249. {
  11250. int item_index, item_amount;
  11251. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11252. item_index = RFIFOW(fd,info->pos[0])-1;
  11253. item_amount = RFIFOL(fd,info->pos[1]);
  11254. if (sd->state.storage_flag == 1)
  11255. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11256. else if(sd->state.storage_flag == 2)
  11257. storage_guild_storageget(sd, item_index, item_amount);
  11258. else if(sd->state.storage_flag == 3)
  11259. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11260. }
  11261. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11262. /// 0129 <index>.W <amount>.L
  11263. void clif_parse_MoveToKafraFromCart(int fd, map_session_data *sd){
  11264. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11265. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11266. int amount = RFIFOL(fd,info->pos[1]);
  11267. if( sd->state.vending )
  11268. return;
  11269. if (!pc_iscarton(sd))
  11270. return;
  11271. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11272. return;
  11273. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11274. return;
  11275. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11276. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  11277. return;
  11278. }
  11279. if (sd->state.storage_flag == 1)
  11280. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11281. else if (sd->state.storage_flag == 2)
  11282. storage_guild_storageaddfromcart(sd, idx, amount);
  11283. else if (sd->state.storage_flag == 3)
  11284. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11285. }
  11286. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11287. /// 0128 <index>.W <amount>.L
  11288. void clif_parse_MoveFromKafraToCart(int fd, map_session_data *sd){
  11289. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11290. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11291. int amount = RFIFOL(fd,info->pos[1]);
  11292. if( sd->state.vending )
  11293. return;
  11294. if (!pc_iscarton(sd))
  11295. return;
  11296. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11297. return;
  11298. if (sd->state.storage_flag == 1)
  11299. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11300. else
  11301. if (sd->state.storage_flag == 2)
  11302. storage_guild_storagegettocart(sd, idx, amount);
  11303. else if (sd->state.storage_flag == 3)
  11304. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11305. }
  11306. /// Request to close storage (CZ_CLOSE_STORE).
  11307. /// 00f7
  11308. void clif_parse_CloseKafra(int fd, map_session_data *sd)
  11309. {
  11310. if( sd->state.storage_flag == 1 )
  11311. storage_storageclose(sd);
  11312. else
  11313. if( sd->state.storage_flag == 2 )
  11314. storage_guild_storageclose(sd);
  11315. else if( sd->state.storage_flag == 3 )
  11316. storage_premiumStorage_close(sd);
  11317. }
  11318. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11319. /// 023a <info>.W
  11320. /// info:
  11321. /// 0 = password has not been set yet
  11322. /// 1 = storage is password-protected
  11323. /// 8 = too many wrong passwords
  11324. /// ? = ignored
  11325. /// NOTE: This packet is only available on certain non-kRO clients.
  11326. void clif_storagepassword(map_session_data* sd, short info)
  11327. {
  11328. int fd = sd->fd;
  11329. WFIFOHEAD(fd,packet_len(0x23a));
  11330. WFIFOW(fd,0) = 0x23a;
  11331. WFIFOW(fd,2) = info;
  11332. WFIFOSET(fd,packet_len(0x23a));
  11333. }
  11334. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11335. /// 023b <type>.W <password>.16B <new password>.16B
  11336. /// type:
  11337. /// 2 = change password
  11338. /// 3 = check password
  11339. /// NOTE: This packet is only available on certain non-kRO clients.
  11340. void clif_parse_StoragePassword(int fd, map_session_data *sd){ //@TODO
  11341. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11342. // int type = RFIFOW(fd,info->pos[0]);
  11343. // char* password = RFIFOP(fd,info->pos[1]);
  11344. // char* new_password = RFIFOP(fd,info->pos[2]);
  11345. // storage_changepass(sd,password,new_password);
  11346. }
  11347. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11348. /// 023c <result>.W <error count>.W
  11349. /// result:
  11350. /// 4 = password change success
  11351. /// 5 = password change failure
  11352. /// 6 = password check success
  11353. /// 7 = password check failure
  11354. /// 8 = too many wrong passwords
  11355. /// ? = ignored
  11356. /// NOTE: This packet is only available on certain non-kRO clients.
  11357. void clif_storagepassword_result(map_session_data* sd, short result, short error_count)
  11358. {
  11359. int fd = sd->fd;
  11360. WFIFOHEAD(fd,packet_len(0x23c));
  11361. WFIFOW(fd,0) = 0x23c;
  11362. WFIFOW(fd,2) = result;
  11363. WFIFOW(fd,4) = error_count;
  11364. WFIFOSET(fd,packet_len(0x23c));
  11365. }
  11366. /// Party creation request
  11367. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11368. void clif_parse_CreateParty(int fd, map_session_data *sd){
  11369. if( sd == nullptr ){
  11370. return;
  11371. }
  11372. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11373. name[NAME_LENGTH-1] = '\0';
  11374. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11375. clif_displaymessage(fd, msg_txt(sd,227));
  11376. return;
  11377. }
  11378. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11379. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11380. return;
  11381. }
  11382. party_create(sd,name,0,0);
  11383. }
  11384. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11385. void clif_parse_CreateParty2(int fd, map_session_data *sd){
  11386. if( sd == nullptr ){
  11387. return;
  11388. }
  11389. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11390. char* name = RFIFOCP(fd,info->pos[0]);
  11391. int item1 = RFIFOB(fd,info->pos[1]);
  11392. int item2 = RFIFOB(fd,info->pos[2]);
  11393. name[NAME_LENGTH-1] = '\0';
  11394. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11395. clif_displaymessage(fd, msg_txt(sd,227));
  11396. return;
  11397. }
  11398. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11399. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11400. return;
  11401. }
  11402. party_create(sd,name,item1,item2);
  11403. }
  11404. /// Party invitation request
  11405. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11406. void clif_parse_PartyInvite(int fd, map_session_data *sd)
  11407. {
  11408. map_session_data *t_sd;
  11409. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11410. clif_displaymessage(fd, msg_txt(sd,227));
  11411. return;
  11412. }
  11413. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11414. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11415. clif_noask_sub(sd, t_sd, 1);
  11416. return;
  11417. }
  11418. party_invite(sd, t_sd);
  11419. }
  11420. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11421. void clif_parse_PartyInvite2(int fd, map_session_data *sd){
  11422. map_session_data *t_sd;
  11423. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11424. name[NAME_LENGTH-1] = '\0';
  11425. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11426. clif_displaymessage(fd, msg_txt(sd,227));
  11427. return;
  11428. }
  11429. t_sd = map_nick2sd(name,false);
  11430. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11431. clif_noask_sub(sd, t_sd, 1);
  11432. return;
  11433. }
  11434. party_invite(sd, t_sd);
  11435. }
  11436. /// Party invitation reply
  11437. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11438. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11439. /// flag:
  11440. /// 0 = reject
  11441. /// 1 = accept
  11442. void clif_parse_ReplyPartyInvite(int fd,map_session_data *sd)
  11443. {
  11444. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11445. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11446. RFIFOL(fd,info->pos[1]));
  11447. }
  11448. //(CZ_PARTY_JOIN_REQ_ACK)
  11449. void clif_parse_ReplyPartyInvite2(int fd,map_session_data *sd)
  11450. {
  11451. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11452. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11453. RFIFOB(fd,info->pos[1]));
  11454. }
  11455. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11456. /// 0100
  11457. void clif_parse_LeaveParty(int fd, map_session_data *sd)
  11458. {
  11459. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11460. clif_displaymessage(fd, msg_txt(sd,227));
  11461. return;
  11462. }
  11463. party_leave(sd);
  11464. }
  11465. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11466. /// 0103 <account id>.L <char name>.24B
  11467. void clif_parse_RemovePartyMember(int fd, map_session_data *sd)
  11468. {
  11469. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11470. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11471. clif_displaymessage(fd, msg_txt(sd,227));
  11472. return;
  11473. }
  11474. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11475. RFIFOCP(fd,info->pos[1]));
  11476. }
  11477. /// Request to change party options.
  11478. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11479. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11480. void clif_parse_PartyChangeOption(int fd, map_session_data *sd)
  11481. {
  11482. struct party_data *p;
  11483. int i,expflag;
  11484. int cmd = RFIFOW(fd,0);
  11485. struct s_packet_db* info = &packet_db[cmd];
  11486. if( !sd->status.party_id )
  11487. return;
  11488. p = party_search(sd->status.party_id);
  11489. if( p == nullptr )
  11490. return;
  11491. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11492. if( i == MAX_PARTY )
  11493. return; //Shouldn't happen
  11494. if( !p->party.member[i].leader )
  11495. return;
  11496. expflag = RFIFOL(fd,info->pos[0]);
  11497. if(cmd == 0x0102){ //Client can't change the item-field
  11498. party_changeoption(sd, expflag, p->party.item);
  11499. }
  11500. else {
  11501. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11502. party_changeoption(sd, expflag, itemflag);
  11503. }
  11504. }
  11505. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11506. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11507. void clif_parse_PartyMessage(int fd, map_session_data* sd){
  11508. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11509. // validate packet and retrieve name and message
  11510. if( !clif_process_message( sd, false, name, message, output ) )
  11511. return;
  11512. party_send_message(sd, output, strlen(output) + 1 );
  11513. }
  11514. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11515. /// 07da <account id>.L
  11516. void clif_parse_PartyChangeLeader(int fd, map_session_data* sd){
  11517. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),nullptr);
  11518. }
  11519. /// Party Booking in KRO [Spiria]
  11520. ///
  11521. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11522. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11523. void clif_parse_PartyBookingRegisterReq(int fd, map_session_data* sd){
  11524. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11525. short level = RFIFOW(fd,info->pos[0]);
  11526. short mapid = RFIFOW(fd,info->pos[1]);
  11527. int idxpbj = info->pos[2];
  11528. short job[MAX_PARTY_BOOKING_JOBS];
  11529. int i;
  11530. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11531. job[i] = RFIFOB(fd,idxpbj+i*2);
  11532. party_booking_register(sd, level, mapid, job);
  11533. }
  11534. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11535. /// 0803 <result>.W
  11536. /// result:
  11537. /// 0 = success
  11538. /// 1 = failure
  11539. /// 2 = already registered
  11540. void clif_PartyBookingRegisterAck(map_session_data *sd, int flag)
  11541. {
  11542. int fd = sd->fd;
  11543. WFIFOHEAD(fd,packet_len(0x803));
  11544. WFIFOW(fd,0) = 0x803;
  11545. WFIFOW(fd,2) = flag;
  11546. WFIFOSET(fd,packet_len(0x803));
  11547. }
  11548. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11549. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11550. void clif_parse_PartyBookingSearchReq(int fd, map_session_data* sd){
  11551. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11552. short level = RFIFOW(fd,info->pos[0]);
  11553. short mapid = RFIFOW(fd,info->pos[1]);
  11554. short job = RFIFOW(fd,info->pos[2]);
  11555. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11556. short resultcount = RFIFOW(fd,info->pos[4]);
  11557. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11558. }
  11559. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11560. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11561. /// more results:
  11562. /// 0 = no
  11563. /// 1 = yes
  11564. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11565. {
  11566. int i, j;
  11567. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11568. struct party_booking_ad_info *pb_ad;
  11569. WFIFOHEAD(fd,size*count + 5);
  11570. WFIFOW(fd,0) = 0x805;
  11571. WFIFOW(fd,2) = size*count + 5;
  11572. WFIFOB(fd,4) = more_result;
  11573. for(i=0; i<count; i++)
  11574. {
  11575. pb_ad = results[i];
  11576. WFIFOL(fd,i*size+5) = pb_ad->index;
  11577. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11578. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11579. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11580. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11581. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11582. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11583. }
  11584. WFIFOSET(fd,WFIFOW(fd,2));
  11585. }
  11586. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11587. /// 0806
  11588. void clif_parse_PartyBookingDeleteReq(int fd, map_session_data* sd)
  11589. {
  11590. if(party_booking_delete(sd))
  11591. clif_PartyBookingDeleteAck(sd, 0);
  11592. }
  11593. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11594. /// 0807 <result>.W
  11595. /// result:
  11596. /// 0 = success
  11597. /// 1 = success (auto-removed expired ad)
  11598. /// 2 = failure
  11599. /// 3 = nothing registered
  11600. void clif_PartyBookingDeleteAck(map_session_data* sd, int flag)
  11601. {
  11602. int fd = sd->fd;
  11603. WFIFOHEAD(fd,packet_len(0x807));
  11604. WFIFOW(fd,0) = 0x807;
  11605. WFIFOW(fd,2) = flag;
  11606. WFIFOSET(fd,packet_len(0x807));
  11607. }
  11608. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11609. /// 0808 { <job>.W }*6
  11610. void clif_parse_PartyBookingUpdateReq(int fd, map_session_data* sd)
  11611. {
  11612. short job[MAX_PARTY_BOOKING_JOBS];
  11613. int i;
  11614. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11615. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11616. job[i] = RFIFOW(fd,idxpbu+i*2);
  11617. party_booking_update(sd, job);
  11618. }
  11619. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11620. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11621. void clif_PartyBookingInsertNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11622. {
  11623. int i;
  11624. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11625. if(pb_ad == nullptr) return;
  11626. WBUFW(buf,0) = 0x809;
  11627. WBUFL(buf,2) = pb_ad->index;
  11628. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11629. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11630. WBUFW(buf,34) = pb_ad->p_detail.level;
  11631. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11632. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11633. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11634. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11635. }
  11636. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11637. /// 080a <index>.L { <job>.W }*6
  11638. void clif_PartyBookingUpdateNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11639. {
  11640. int i;
  11641. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11642. if(pb_ad == nullptr) return;
  11643. WBUFW(buf,0) = 0x80a;
  11644. WBUFL(buf,2) = pb_ad->index;
  11645. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11646. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11647. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11648. }
  11649. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11650. /// 080b <index>.L
  11651. void clif_PartyBookingDeleteNotify(map_session_data* sd, int index)
  11652. {
  11653. uint8 buf[6];
  11654. WBUFW(buf,0) = 0x80b;
  11655. WBUFL(buf,2) = index;
  11656. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11657. }
  11658. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11659. /// 012e
  11660. void clif_parse_CloseVending(int fd, map_session_data* sd)
  11661. {
  11662. vending_closevending(sd);
  11663. }
  11664. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11665. /// 0130 <account id>.L
  11666. void clif_parse_VendingListReq(int fd, map_session_data* sd)
  11667. {
  11668. if( sd->npc_id ) {// using an NPC
  11669. return;
  11670. }
  11671. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11672. }
  11673. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11674. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11675. void clif_parse_PurchaseReq(int fd, map_session_data* sd){
  11676. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11677. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11678. // whether it fails or not, the buy window is closed
  11679. sd->vended_id = 0;
  11680. }
  11681. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11682. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11683. void clif_parse_PurchaseReq2(int fd, map_session_data* sd){
  11684. #if PACKETVER >= 20100105
  11685. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11686. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11687. // whether it fails or not, the buy window is closed
  11688. sd->vended_id = 0;
  11689. #endif
  11690. }
  11691. /// Confirm or cancel the shop preparation window.
  11692. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11693. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11694. /// result:
  11695. /// 0 = canceled
  11696. /// 1 = open
  11697. void clif_parse_OpenVending(int fd, map_session_data* sd){
  11698. if( sd == nullptr ){
  11699. return;
  11700. }
  11701. int cmd = RFIFOW(fd,0);
  11702. struct s_packet_db* info = &packet_db[cmd];
  11703. short len = (short)RFIFOW(fd,info->pos[0]);
  11704. const char* message = RFIFOCP(fd,info->pos[1]);
  11705. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11706. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11707. len -= 84;
  11708. }
  11709. else { //(CZ_REQ_OPENSTORE2)
  11710. bool flag;
  11711. len -= 85;
  11712. flag = RFIFOB(fd,info->pos[2]) != 0;
  11713. if (!flag) {
  11714. sd->state.prevend = 0;
  11715. sd->state.workinprogress = WIP_DISABLE_NONE;
  11716. }
  11717. }
  11718. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11719. return;
  11720. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11721. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11722. return;
  11723. }
  11724. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11725. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11726. return;
  11727. }
  11728. if( message[0] == '\0' ) // invalid input
  11729. return;
  11730. vending_openvending(*sd, message, data, len/8, nullptr);
  11731. }
  11732. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11733. /// 0165 <char id>.L <guild name>.24B
  11734. void clif_parse_CreateGuild(int fd,map_session_data *sd){
  11735. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11736. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11737. name[NAME_LENGTH-1] = '\0';
  11738. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11739. clif_displaymessage(fd, msg_txt(sd,228));
  11740. return;
  11741. }
  11742. if(sd->clan){
  11743. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11744. return;
  11745. }
  11746. guild_create(sd, name);
  11747. }
  11748. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11749. /// 014d
  11750. void clif_parse_GuildCheckMaster(int fd, map_session_data *sd)
  11751. {
  11752. clif_guild_masterormember(sd);
  11753. }
  11754. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11755. /// 014f <type>.L
  11756. /// type:
  11757. /// 0 = basic info
  11758. /// 1 = member manager
  11759. /// 2 = positions
  11760. /// 3 = skills
  11761. /// 4 = expulsion list
  11762. /// 5 = unknown (GM_ALLGUILDLIST)
  11763. /// 6 = notice
  11764. void clif_parse_GuildRequestInfo(int fd, map_session_data *sd)
  11765. {
  11766. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11767. if( !sd->status.guild_id && !sd->bg_id )
  11768. return;
  11769. switch( type )
  11770. {
  11771. case 0: // Basic Information Guild, hostile alliance information
  11772. clif_guild_basicinfo( *sd );
  11773. clif_guild_allianceinfo(sd);
  11774. clif_guild_castle_list(*sd);
  11775. break;
  11776. case 1: // Members list, list job title
  11777. clif_guild_positionnamelist(sd);
  11778. clif_guild_memberlist( *sd );
  11779. break;
  11780. case 2: // List job title, title information list
  11781. clif_guild_positionnamelist(sd);
  11782. clif_guild_positioninfolist(sd);
  11783. break;
  11784. case 3: // Skill list
  11785. clif_guild_skillinfo(sd);
  11786. break;
  11787. case 4: // Expulsion list
  11788. clif_guild_expulsionlist(sd);
  11789. break;
  11790. default:
  11791. ShowError("clif: guild request info: unknown type %d\n", type);
  11792. break;
  11793. }
  11794. }
  11795. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11796. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11797. void clif_parse_GuildChangePositionInfo(int fd, map_session_data *sd)
  11798. {
  11799. int i;
  11800. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11801. int len = RFIFOW(fd,info->pos[0]);
  11802. int idxgpos = info->pos[1];
  11803. if(!sd->state.gmaster_flag)
  11804. return;
  11805. for(i = idxgpos; i < len; i += 40 ){
  11806. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11807. }
  11808. }
  11809. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11810. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11811. void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){
  11812. if(!sd->state.gmaster_flag)
  11813. return;
  11814. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11815. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11816. for( int16 i = 0; i < entries; i++ ){
  11817. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11818. // Guild leadership change
  11819. if( entry.position == 0 ){
  11820. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11821. clif_msg( sd, MSI_IMPOSSIBLE_CHANGE_GUILD_MASTER_IN_SIEGE_TIME );
  11822. return;
  11823. }
  11824. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->guild.last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11825. clif_msg( sd, MSI_IMPOSSIBLE_CHANGE_GUILD_MASTER_NOT_TIME );
  11826. return;
  11827. }
  11828. guild_gm_change( sd->status.guild_id, entry.CID );
  11829. // No further entries will be processed - the requesting player lost his guild master status
  11830. return;
  11831. }else if( entry.position > 0 ){
  11832. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11833. }
  11834. }
  11835. }
  11836. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11837. /// 0151 <guild id>.L
  11838. void clif_parse_GuildRequestEmblem(int fd,map_session_data *sd)
  11839. {
  11840. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11841. auto g = guild_search(guild_id);
  11842. if (g)
  11843. clif_guild_emblem(*sd, g->guild);
  11844. }
  11845. /// Validates data of a guild emblem (compressed bitmap)
  11846. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11847. EMBVALIDATE_SUCCESS = 0,
  11848. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11849. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  11850. };
  11851. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11852. {
  11853. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11854. unsigned long buf_len = sizeof(buf);
  11855. int offset = 0;
  11856. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11857. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11858. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11859. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11860. ))
  11861. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11862. if(inter_config.emblem_transparency_limit != 100) {
  11863. int i, transcount = 1, tmp[3];
  11864. for(i = offset; i < buf_len-1; i++) {
  11865. int j = i%3;
  11866. tmp[j] = RBUFL(buf,i);
  11867. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11868. transcount++;
  11869. }
  11870. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  11871. return EMBVALIDATE_ERR_TRANSPARENCY;
  11872. }
  11873. return EMBVALIDATE_SUCCESS;
  11874. }
  11875. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11876. /// 0153 <packet len>.W <emblem data>.?B
  11877. void clif_parse_GuildChangeEmblem(int fd,map_session_data *sd){
  11878. if( sd == nullptr ){
  11879. return;
  11880. }
  11881. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11882. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11883. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11884. int emb_val=0;
  11885. if( !emblem_len || !sd->state.gmaster_flag )
  11886. return;
  11887. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  11888. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11889. return;
  11890. }
  11891. emb_val = clif_validate_emblem(emblem, emblem_len);
  11892. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11893. 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);
  11894. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11895. return;
  11896. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11897. char output[128];
  11898. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  11899. 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"
  11900. return;
  11901. }
  11902. guild_change_emblem( *sd, emblem_len, (const char*)emblem );
  11903. }
  11904. /// Request to update the guild emblem id
  11905. /// 0b46 <guild id>.L <version>.L
  11906. void clif_parse_GuildChangeEmblem2(int fd, map_session_data* sd) {
  11907. if( sd == nullptr ){
  11908. return;
  11909. }
  11910. #if PACKETVER >= 20190724
  11911. const PACKET_CZ_REQ_ADD_NEW_EMBLEM* p = (PACKET_CZ_REQ_ADD_NEW_EMBLEM*)RFIFOP(fd, 0);
  11912. auto &g = sd->guild;
  11913. if (!g || g->guild.guild_id != p->guild_id)
  11914. return;
  11915. if (!sd->state.gmaster_flag)
  11916. return;
  11917. if (!inter_config.emblem_woe_change && is_agit_start()) {
  11918. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11919. return;
  11920. }
  11921. guild_change_emblem_version( *sd, p->version );
  11922. #endif
  11923. }
  11924. /// Guild notice update request (CZ_GUILD_NOTICE).
  11925. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11926. void clif_parse_GuildChangeNotice(int fd, map_session_data* sd){
  11927. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11928. int guild_id = RFIFOL(fd,info->pos[0]);
  11929. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11930. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11931. if(!sd->state.gmaster_flag)
  11932. return;
  11933. // compensate for some client defects when using multilanguage mode
  11934. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11935. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11936. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11937. guild_change_notice(sd, guild_id, msg1, msg2);
  11938. }
  11939. // Helper function for guild invite functions
  11940. int clif_sub_guild_invite(int fd, map_session_data *sd, map_session_data *t_sd)
  11941. {
  11942. if (t_sd == nullptr) // not online or does not exist
  11943. return 1;
  11944. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11945. clif_displaymessage(fd, msg_txt(sd,228));
  11946. return 1;
  11947. }
  11948. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11949. clif_noask_sub(sd, t_sd, 2);
  11950. return 1;
  11951. }
  11952. // Players in a clan can not join a guild
  11953. if(t_sd && t_sd->clan){
  11954. return 1;
  11955. }
  11956. guild_invite(sd, t_sd);
  11957. return 0;
  11958. }
  11959. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11960. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11961. void clif_parse_GuildInvite(int fd,map_session_data *sd){
  11962. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11963. map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11964. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11965. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11966. if (clif_sub_guild_invite(fd, sd, t_sd))
  11967. return;
  11968. }
  11969. /// Guild invite request (/guildinvite)
  11970. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11971. void
  11972. clif_parse_GuildInvite2(int fd, map_session_data *sd) {
  11973. map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11974. if (clif_sub_guild_invite(fd, sd, t_sd))
  11975. return;
  11976. }
  11977. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11978. /// 016b <guild id>.L <answer>.L
  11979. /// answer:
  11980. /// 0 = refuse
  11981. /// 1 = accept
  11982. void clif_parse_GuildReplyInvite(int fd,map_session_data *sd){
  11983. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11984. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11985. RFIFOL(fd,info->pos[1]));
  11986. }
  11987. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11988. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11989. void clif_parse_GuildLeave(int fd,map_session_data *sd){
  11990. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11991. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11992. clif_displaymessage(fd, msg_txt(sd,228));
  11993. return;
  11994. }
  11995. if( sd->bg_id ) {
  11996. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11997. return;
  11998. }
  11999. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12000. RFIFOL(fd,info->pos[1]),
  12001. RFIFOL(fd,info->pos[2]),
  12002. RFIFOCP(fd,info->pos[3]));
  12003. }
  12004. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12005. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12006. void clif_parse_GuildExpulsion(int fd,map_session_data *sd){
  12007. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12008. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12009. { // Guild locked.
  12010. clif_displaymessage(fd, msg_txt(sd,228));
  12011. return;
  12012. }
  12013. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12014. RFIFOL(fd,info->pos[1]),
  12015. RFIFOL(fd,info->pos[2]),
  12016. RFIFOCP(fd,info->pos[3]));
  12017. }
  12018. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12019. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12020. void clif_parse_GuildMessage(int fd, map_session_data* sd){
  12021. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12022. // validate packet and retrieve name and message
  12023. if( !clif_process_message( sd, false, name, message, output ) )
  12024. return;
  12025. if( sd->bg_id )
  12026. bg_send_message(sd, output, strlen(output) );
  12027. else
  12028. guild_send_message(sd, output, strlen(output) );
  12029. }
  12030. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12031. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12032. void clif_parse_GuildRequestAlliance(int fd, map_session_data *sd)
  12033. {
  12034. map_session_data *t_sd;
  12035. if(!sd->state.gmaster_flag)
  12036. return;
  12037. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12038. clif_displaymessage(fd, msg_txt(sd,228));
  12039. return;
  12040. }
  12041. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12042. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12043. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12044. // @noask [LuzZza]
  12045. if(t_sd && t_sd->state.noask) {
  12046. clif_noask_sub(sd, t_sd, 3);
  12047. return;
  12048. }
  12049. guild_reqalliance(sd,t_sd);
  12050. }
  12051. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12052. /// 0172 <inviter account id>.L <answer>.L
  12053. /// answer:
  12054. /// 0 = refuse
  12055. /// 1 = accept
  12056. void clif_parse_GuildReplyAlliance(int fd, map_session_data *sd){
  12057. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12058. guild_reply_reqalliance(sd,
  12059. RFIFOL(fd,info->pos[0]),
  12060. RFIFOL(fd,info->pos[1]));
  12061. }
  12062. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12063. /// 0183 <opponent guild id>.L <relation>.L
  12064. /// relation:
  12065. /// 0 = Ally
  12066. /// 1 = Enemy
  12067. void clif_parse_GuildDelAlliance(int fd, map_session_data *sd){
  12068. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12069. if(!sd->state.gmaster_flag)
  12070. return;
  12071. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12072. clif_displaymessage(fd, msg_txt(sd,228));
  12073. return;
  12074. }
  12075. guild_delalliance(sd,
  12076. RFIFOL(fd,info->pos[0]),
  12077. RFIFOL(fd,info->pos[1]));
  12078. }
  12079. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12080. /// 0180 <account id>.L
  12081. void clif_parse_GuildOpposition(int fd, map_session_data *sd)
  12082. {
  12083. map_session_data *t_sd;
  12084. if(!sd->state.gmaster_flag)
  12085. return;
  12086. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12087. clif_displaymessage(fd, msg_txt(sd,228));
  12088. return;
  12089. }
  12090. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12091. // @noask [LuzZza]
  12092. if(t_sd && t_sd->state.noask) {
  12093. clif_noask_sub(sd, t_sd, 4);
  12094. return;
  12095. }
  12096. guild_opposition(sd,t_sd);
  12097. }
  12098. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12099. /// 015d <key>.40B
  12100. /// key:
  12101. /// now guild name; might have been (intended) email, since the
  12102. /// field name and size is same as the one in CH_DELETE_CHAR.
  12103. void clif_parse_GuildBreak(int fd, map_session_data *sd)
  12104. {
  12105. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12106. clif_displaymessage(fd, msg_txt(sd,228));
  12107. return;
  12108. }
  12109. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12110. }
  12111. /// Pet
  12112. ///
  12113. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12114. /// 01a1 <type>.B
  12115. /// type:
  12116. /// 0 = pet information
  12117. /// 1 = feed
  12118. /// 2 = performance
  12119. /// 3 = return to egg
  12120. /// 4 = unequip accessory
  12121. void clif_parse_PetMenu(int fd, map_session_data *sd){
  12122. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12123. }
  12124. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12125. /// 019f <id>.L
  12126. void clif_parse_CatchPet(int fd, map_session_data *sd){
  12127. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12128. }
  12129. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12130. /// 01a7 <index>.W
  12131. void clif_parse_SelectEgg(int fd, map_session_data *sd){
  12132. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12133. return;
  12134. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12135. clif_menuskill_clear(sd);
  12136. }
  12137. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12138. /// 01a9 <data>.L
  12139. /// data:
  12140. /// is either emotion (@see enum emotion_type) or a compound value
  12141. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12142. /// entry (given in parentheses) in data\pettalktable.xml
  12143. /// act id:
  12144. /// 0 = feeding
  12145. /// 1 = hunting
  12146. /// 2 = danger
  12147. /// 3 = dead
  12148. /// 4 = normal (stand)
  12149. /// 5 = special performance (perfor_s)
  12150. /// 6 = level up (levelup)
  12151. /// 7 = performance 1 (perfor_1)
  12152. /// 8 = performance 2 (perfor_2)
  12153. /// 9 = performance 3 (perfor_3)
  12154. /// 10 = log-in greeting (connect)
  12155. /// hungry value:
  12156. /// 0 = very hungry (hungry)
  12157. /// 1 = hungry (bit_hungry)
  12158. /// 2 = satisfied (noting)
  12159. /// 3 = stuffed (full)
  12160. /// 4 = full (so_full)
  12161. void clif_parse_SendEmotion(int fd, map_session_data *sd)
  12162. {
  12163. if(sd->pd)
  12164. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12165. }
  12166. /// Request to change pet's name (CZ_RENAME_PET).
  12167. /// 01a5 <name>.24B
  12168. void clif_parse_ChangePetName(int fd, map_session_data *sd)
  12169. {
  12170. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12171. }
  12172. /// /kill (CZ_DISCONNECT_CHARACTER).
  12173. /// Request to disconnect a character.
  12174. /// 00cc <account id>.L
  12175. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12176. void clif_parse_GMKick(int fd, map_session_data *sd)
  12177. {
  12178. struct block_list *target;
  12179. int tid;
  12180. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12181. target = map_id2bl(tid);
  12182. if (!target) {
  12183. clif_GM_kickack(sd, 0);
  12184. return;
  12185. }
  12186. switch (target->type) {
  12187. case BL_PC:
  12188. {
  12189. char command[NAME_LENGTH+6];
  12190. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12191. is_atcommand(fd, sd, command, 1);
  12192. }
  12193. break;
  12194. /**
  12195. * This one does not invoke any atcommand, so we need to check for permissions.
  12196. */
  12197. case BL_MOB:
  12198. {
  12199. char command[100];
  12200. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12201. clif_GM_kickack(sd, 0);
  12202. return;
  12203. }
  12204. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12205. log_atcommand(sd, command);
  12206. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12207. }
  12208. break;
  12209. case BL_NPC:
  12210. {
  12211. struct npc_data* nd = (struct npc_data *)target;
  12212. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12213. npc_unload_duplicates(nd);
  12214. npc_unload(nd,true);
  12215. npc_read_event_script();
  12216. }
  12217. }
  12218. break;
  12219. default:
  12220. clif_GM_kickack(sd, 0);
  12221. }
  12222. }
  12223. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12224. /// Request to disconnect all characters.
  12225. /// 00ce
  12226. void clif_parse_GMKickAll(int fd, map_session_data* sd) {
  12227. char cmd[15];
  12228. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12229. is_atcommand(fd, sd, cmd, 1);
  12230. }
  12231. /// /remove (CZ_REMOVE_AID).
  12232. /// Request to warp to a character with given login ID.
  12233. /// 01ba <account name>.24B
  12234. /// /shift (CZ_SHIFT).
  12235. /// Request to warp to a character with given name.
  12236. /// 01bb <char name>.24B
  12237. void clif_parse_GMShift(int fd, map_session_data *sd)
  12238. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12239. char *player_name;
  12240. char command[NAME_LENGTH+8];
  12241. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12242. player_name[NAME_LENGTH-1] = '\0';
  12243. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12244. is_atcommand(fd, sd, command, 1);
  12245. }
  12246. /// /remove (CZ_REMOVE_AID_SSO).
  12247. /// Request to warp to a character with given account ID.
  12248. /// 0843 <account id>.L
  12249. void clif_parse_GMRemove2(int fd, map_session_data* sd)
  12250. {
  12251. uint32 account_id;
  12252. map_session_data* pl_sd;
  12253. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12254. if( (pl_sd = map_id2sd(account_id)) != nullptr ) {
  12255. char command[NAME_LENGTH+8];
  12256. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12257. is_atcommand(fd, sd, command, 1);
  12258. }
  12259. }
  12260. /// /recall (CZ_RECALL).
  12261. /// Request to summon a player with given login ID to own position.
  12262. /// 01bc <account name>.24B
  12263. /// /summon (CZ_RECALL_GID).
  12264. /// Request to summon a player with given name to own position.
  12265. /// 01bd <char name>.24B
  12266. void clif_parse_GMRecall(int fd, map_session_data *sd)
  12267. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12268. char *player_name;
  12269. char command [NAME_LENGTH+8];
  12270. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12271. player_name[NAME_LENGTH-1] = '\0';
  12272. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12273. is_atcommand(fd, sd, command, 1);
  12274. }
  12275. /// /recall (CZ_RECALL_SSO).
  12276. /// Request to summon a player with given account ID to own position.
  12277. /// 0842 <account id>.L
  12278. void clif_parse_GMRecall2(int fd, map_session_data* sd)
  12279. {
  12280. uint32 account_id;
  12281. map_session_data* pl_sd;
  12282. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12283. if( (pl_sd = map_id2sd(account_id)) != nullptr ) {
  12284. char command[NAME_LENGTH+8];
  12285. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12286. is_atcommand(fd, sd, command, 1);
  12287. }
  12288. }
  12289. /// /item /monster (CZ_ITEM_CREATE).
  12290. /// Request to execute GM commands.
  12291. /// Usage:
  12292. /// /item n - summon n monster or acquire n item/s
  12293. /// /item money - grants 2147483647 zenies
  12294. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12295. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12296. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12297. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12298. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12299. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12300. /// 013f <item/mob name>.24B
  12301. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12302. void clif_parse_GM_Item_Monster(int fd, map_session_data *sd)
  12303. {
  12304. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12305. int mob_id = 0;
  12306. StringBuf command;
  12307. char *str;
  12308. //#if PACKETVER >= 20131218
  12309. // char str[100];
  12310. //#else
  12311. // char str[24];
  12312. //#endif
  12313. str = RFIFOCP(fd,info->pos[0]);
  12314. if (!str || str[0] == '\0')
  12315. return;
  12316. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12317. return;
  12318. trim(str);
  12319. // Zeny
  12320. if( strcmpi(str, "money") == 0 ) {
  12321. StringBuf_Init(&command);
  12322. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12323. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12324. StringBuf_Destroy(&command);
  12325. return;
  12326. }
  12327. std::shared_ptr<item_data> id = item_db.searchname( str );
  12328. // Item
  12329. if( id ){
  12330. StringBuf_Init(&command);
  12331. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12332. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12333. }else{
  12334. if (id->flag.guid)
  12335. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12336. else
  12337. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12338. }
  12339. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12340. StringBuf_Destroy(&command);
  12341. return;
  12342. }
  12343. // Monster
  12344. if ((mob_id = mobdb_searchname(str)) == 0)
  12345. mob_id = mobdb_checkid(atoi(str));
  12346. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12347. if( mob != nullptr ) {
  12348. StringBuf_Init(&command);
  12349. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12350. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12351. StringBuf_Destroy(&command);
  12352. return;
  12353. }
  12354. }
  12355. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12356. /// 019d <effect state>.L
  12357. /// effect state:
  12358. /// TODO: Any OPTION_* ?
  12359. void clif_parse_GMHide(int fd, map_session_data *sd) {
  12360. char cmd[6];
  12361. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12362. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12363. is_atcommand(fd, sd, cmd, 1);
  12364. }
  12365. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12366. /// 0149 <account id>.L <type>.B <value>.W
  12367. /// type:
  12368. /// 0 = positive points
  12369. /// 1 = negative points
  12370. /// 2 = self mute (+10 minutes)
  12371. void clif_parse_GMReqNoChat(int fd,map_session_data *sd)
  12372. {
  12373. int id, type, value;
  12374. map_session_data *dstsd;
  12375. char command[NAME_LENGTH+15];
  12376. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12377. id = RFIFOL(fd,info->pos[0]);
  12378. type = RFIFOB(fd,info->pos[1]);
  12379. value = RFIFOW(fd,info->pos[2]);
  12380. if( type == 0 )
  12381. value = -value;
  12382. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12383. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12384. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12385. return;
  12386. dstsd = map_id2sd(id);
  12387. if( dstsd == nullptr )
  12388. return;
  12389. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12390. is_atcommand(fd, sd, command, 1);
  12391. }
  12392. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12393. /// GM adjustment of a player's manner value by -60.
  12394. /// 0212 <char name>.24B
  12395. void clif_parse_GMRc(int fd, map_session_data* sd)
  12396. {
  12397. char command[NAME_LENGTH+15];
  12398. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12399. name[NAME_LENGTH-1] = '\0';
  12400. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12401. is_atcommand(fd, sd, command, 1);
  12402. }
  12403. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12404. /// 01e0 <account id>.L <account name>.24B
  12405. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12406. {
  12407. WFIFOHEAD(fd,packet_len(0x1e0));
  12408. WFIFOW(fd,0) = 0x1e0;
  12409. WFIFOL(fd,2) = account_id;
  12410. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12411. WFIFOSET(fd,packet_len(0x1e0));
  12412. }
  12413. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12414. /// 01df <account id>.L
  12415. //! TODO: Figure out how does this actually work
  12416. void clif_parse_GMReqAccountName(int fd, map_session_data *sd)
  12417. {
  12418. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12419. /*
  12420. char query[30];
  12421. safesnprintf(query,sizeof(query),"%d", account_id);
  12422. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12423. */
  12424. clif_account_name(fd, account_id, "");
  12425. }
  12426. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12427. /// GM single cell type change request.
  12428. /// 0198 <x>.W <y>.W <type>.W
  12429. /// type:
  12430. /// 0 = not walkable
  12431. /// 1 = walkable
  12432. void clif_parse_GMChangeMapType(int fd, map_session_data *sd)
  12433. {
  12434. int x,y,type;
  12435. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12436. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12437. return;
  12438. x = RFIFOW(fd,info->pos[0]);
  12439. y = RFIFOW(fd,info->pos[1]);
  12440. type = RFIFOW(fd,info->pos[2]);
  12441. map_setgatcell(sd->bl.m,x,y,type);
  12442. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12443. //FIXME: once players leave the map, the client 'forgets' this information.
  12444. }
  12445. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12446. /// Request to allow/deny whispers from a nick.
  12447. /// 00cf <nick>.24B <type>.B
  12448. /// type:
  12449. /// 0 = (/ex nick) deny speech from nick
  12450. /// 1 = (/in nick) allow speech from nick
  12451. void clif_parse_PMIgnore(int fd, map_session_data* sd)
  12452. {
  12453. char* nick;
  12454. uint8 type;
  12455. int i;
  12456. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12457. nick = RFIFOCP(fd,info->pos[0]);
  12458. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12459. type = RFIFOB(fd,info->pos[1]);
  12460. if( type == 0 ) { // Add name to ignore list (block)
  12461. if (strcmp(wisp_server_name, nick) == 0) {
  12462. clif_wisexin(sd, type, 1); // fail
  12463. return;
  12464. }
  12465. // try to find a free spot, while checking for duplicates at the same time
  12466. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12467. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12468. clif_wisexin(sd, type, 2); // too many blocks
  12469. return;
  12470. }
  12471. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12472. clif_wisexin(sd, type, 0); // Aegis reports success.
  12473. return;
  12474. }
  12475. //Insert in position i
  12476. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12477. } else { // Remove name from ignore list (unblock)
  12478. // find entry
  12479. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12480. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12481. clif_wisexin(sd, type, 1); // fail
  12482. return;
  12483. }
  12484. // move everything one place down to overwrite removed entry
  12485. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12486. // wipe last entry
  12487. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12488. }
  12489. clif_wisexin(sd, type, 0); // success
  12490. }
  12491. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12492. /// Request to allow/deny all whispers.
  12493. /// 00d0 <type>.B
  12494. /// type:
  12495. /// 0 = (/exall) deny all speech
  12496. /// 1 = (/inall) allow all speech
  12497. void clif_parse_PMIgnoreAll(int fd, map_session_data *sd)
  12498. {
  12499. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12500. if( type == 0 ) {// Deny all
  12501. if( sd->state.ignoreAll ) {
  12502. flag = 1; // fail
  12503. } else {
  12504. sd->state.ignoreAll = 1;
  12505. flag = 0; // success
  12506. }
  12507. } else {//Unblock everyone
  12508. if( sd->state.ignoreAll ) {
  12509. sd->state.ignoreAll = 0;
  12510. flag = 0; // success
  12511. } else {
  12512. if (sd->ignore[0].name[0] != '\0')
  12513. { //Wipe the ignore list.
  12514. memset(sd->ignore, 0, sizeof(sd->ignore));
  12515. flag = 0; // success
  12516. } else {
  12517. flag = 1; // fail
  12518. }
  12519. }
  12520. }
  12521. clif_wisall(sd, type, flag);
  12522. }
  12523. /// Whisper ignore list (ZC_WHISPER_LIST).
  12524. /// 00d4 <packet len>.W { <char name>.24B }*
  12525. void clif_PMIgnoreList(map_session_data* sd)
  12526. {
  12527. int i, fd = sd->fd;
  12528. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12529. WFIFOW(fd,0) = 0xd4;
  12530. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12531. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12532. }
  12533. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12534. WFIFOSET(fd,WFIFOW(fd,2));
  12535. }
  12536. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12537. /// 00d3
  12538. void clif_parse_PMIgnoreList(int fd,map_session_data *sd)
  12539. {
  12540. clif_PMIgnoreList(sd);
  12541. }
  12542. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12543. /// 01e7
  12544. void clif_parse_NoviceDoriDori(int fd, map_session_data *sd)
  12545. {
  12546. if (sd->state.doridori) return;
  12547. switch (sd->class_&MAPID_UPPERMASK) {
  12548. case MAPID_SOUL_LINKER:
  12549. case MAPID_STAR_GLADIATOR:
  12550. case MAPID_TAEKWON:
  12551. if (!sd->state.rest)
  12552. break;
  12553. [[fallthrough]];
  12554. case MAPID_SUPER_NOVICE:
  12555. case MAPID_SUPER_BABY:
  12556. case MAPID_SUPER_NOVICE_E:
  12557. case MAPID_SUPER_BABY_E:
  12558. sd->state.doridori=1;
  12559. break;
  12560. }
  12561. }
  12562. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12563. /// 01ed
  12564. /// Note: This packet is caused by 7 lines of any text, followed by
  12565. /// the prayer and an another line of any text. The prayer is
  12566. /// defined by lines 790~793 in data\msgstringtable.txt
  12567. /// "Dear angel, can you hear my voice?"
  12568. /// "I am" (space separated player name) "Super Novice~"
  12569. /// "Help me out~ Please~ T_T"
  12570. void clif_parse_NoviceExplosionSpirits(int fd, map_session_data *sd)
  12571. {
  12572. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12573. t_exp next = pc_nextbaseexp(sd);
  12574. if( next ) {
  12575. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12576. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12577. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12578. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12579. }
  12580. }
  12581. }
  12582. }
  12583. /// Friends List
  12584. ///
  12585. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12586. /// 0206 <account id>.L <char id>.L <state>.B
  12587. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12588. /// state:
  12589. /// 0 = online
  12590. /// 1 = offline
  12591. void clif_friendslist_toggle(map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12592. {
  12593. int i, fd = sd->fd;
  12594. //Seek friend.
  12595. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12596. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12597. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12598. return; //Not found
  12599. WFIFOHEAD(fd,packet_len(0x206));
  12600. WFIFOW(fd, 0) = 0x206;
  12601. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12602. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12603. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12604. #if PACKETVER >= 20180221
  12605. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12606. #endif
  12607. WFIFOSET(fd, packet_len(0x206));
  12608. }
  12609. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12610. int clif_friendslist_toggle_sub(map_session_data *sd,va_list ap)
  12611. {
  12612. uint32 account_id, char_id, online;
  12613. account_id = va_arg(ap, int);
  12614. char_id = va_arg(ap, int);
  12615. online = va_arg(ap, int);
  12616. clif_friendslist_toggle(sd, account_id, char_id, online);
  12617. return 0;
  12618. }
  12619. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12620. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12621. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12622. void clif_friendslist_send( map_session_data& sd ){
  12623. PACKET_ZC_FRIENDS_LIST* p = reinterpret_cast<PACKET_ZC_FRIENDS_LIST*>( packet_buffer );
  12624. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12625. p->PacketLength = sizeof( *p );
  12626. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12627. PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12628. f.AID = sd.status.friends[i].account_id;
  12629. f.CID = sd.status.friends[i].char_id;
  12630. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12631. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12632. #endif
  12633. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( f ) );
  12634. c++;
  12635. }
  12636. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12637. // Sending the online players
  12638. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12639. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12640. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12641. }
  12642. }
  12643. }
  12644. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12645. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12646. /// result:
  12647. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12648. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12649. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12650. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12651. void clif_friendslist_reqack(map_session_data *sd, map_session_data *f_sd, int type)
  12652. {
  12653. int fd;
  12654. nullpo_retv(sd);
  12655. fd = sd->fd;
  12656. WFIFOHEAD(fd,packet_len(0x209));
  12657. WFIFOW(fd,0) = 0x209;
  12658. WFIFOW(fd,2) = type;
  12659. if (f_sd) {
  12660. WFIFOL(fd,4) = f_sd->status.account_id;
  12661. WFIFOL(fd,8) = f_sd->status.char_id;
  12662. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12663. }
  12664. WFIFOSET(fd, packet_len(0x209));
  12665. }
  12666. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12667. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12668. void clif_friendlist_req(map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12669. {
  12670. int fd = sd->fd;
  12671. WFIFOHEAD(fd,packet_len(0x207));
  12672. WFIFOW(fd,0) = 0x207;
  12673. WFIFOL(fd,2) = account_id;
  12674. WFIFOL(fd,6) = char_id;
  12675. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12676. WFIFOSET(fd,packet_len(0x207));
  12677. }
  12678. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12679. /// 0202 <name>.24B
  12680. void clif_parse_FriendsListAdd(int fd, map_session_data *sd)
  12681. {
  12682. map_session_data *f_sd;
  12683. int i;
  12684. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12685. // Friend doesn't exist (no player with this name)
  12686. if (f_sd == nullptr) {
  12687. clif_displaymessage(fd, msg_txt(sd,3));
  12688. return;
  12689. }
  12690. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12691. return;
  12692. }
  12693. // ensure that the request player's friend list is not full
  12694. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12695. if( i == MAX_FRIENDS ){
  12696. clif_friendslist_reqack(sd, f_sd, 2);
  12697. return;
  12698. }
  12699. // @noask [LuzZza]
  12700. if(f_sd->state.noask) {
  12701. clif_noask_sub(sd, f_sd, 5);
  12702. return;
  12703. }
  12704. // Friend already exists
  12705. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12706. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12707. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12708. return;
  12709. }
  12710. }
  12711. f_sd->friend_req = sd->status.char_id;
  12712. sd->friend_req = f_sd->status.char_id;
  12713. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12714. }
  12715. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12716. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12717. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12718. /// reply:
  12719. /// 0 = rejected
  12720. /// 1 = accepted
  12721. void clif_parse_FriendsListReply(int fd, map_session_data *sd)
  12722. {
  12723. map_session_data *f_sd;
  12724. uint32 account_id;
  12725. char reply;
  12726. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12727. account_id = RFIFOL(fd,info->pos[0]);
  12728. //char_id = RFIFOL(fd,info->pos[1]);
  12729. #if PACKETVER < 6
  12730. reply = RFIFOB(fd,info->pos[2]);
  12731. #else
  12732. reply = RFIFOL(fd,info->pos[2]);
  12733. #endif
  12734. if( sd->bl.id == account_id ) {// adding oneself as friend
  12735. return;
  12736. }
  12737. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12738. if (f_sd == nullptr)
  12739. return;
  12740. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12741. clif_friendslist_reqack(f_sd, sd, 1);
  12742. else {
  12743. int i;
  12744. // Find an empty slot
  12745. for (i = 0; i < MAX_FRIENDS; i++)
  12746. if (f_sd->status.friends[i].char_id == 0)
  12747. break;
  12748. if (i == MAX_FRIENDS) {
  12749. clif_friendslist_reqack(f_sd, sd, 2);
  12750. return;
  12751. }
  12752. f_sd->status.friends[i].account_id = sd->status.account_id;
  12753. f_sd->status.friends[i].char_id = sd->status.char_id;
  12754. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12755. clif_friendslist_reqack(f_sd, sd, 0);
  12756. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12757. if (battle_config.friend_auto_add) {
  12758. // Also add f_sd to sd's friendlist.
  12759. for (i = 0; i < MAX_FRIENDS; i++) {
  12760. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12761. return; //No need to add anything.
  12762. if (sd->status.friends[i].char_id == 0)
  12763. break;
  12764. }
  12765. if (i == MAX_FRIENDS) {
  12766. clif_friendslist_reqack(sd, f_sd, 2);
  12767. return;
  12768. }
  12769. sd->status.friends[i].account_id = f_sd->status.account_id;
  12770. sd->status.friends[i].char_id = f_sd->status.char_id;
  12771. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12772. clif_friendslist_reqack(sd, f_sd, 0);
  12773. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12774. }
  12775. }
  12776. }
  12777. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12778. /// 0203 <account id>.L <char id>.L
  12779. void clif_parse_FriendsListRemove(int fd, map_session_data *sd)
  12780. {
  12781. map_session_data *f_sd = nullptr;
  12782. uint32 account_id, char_id;
  12783. int i, j;
  12784. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12785. account_id = RFIFOL(fd,info->pos[0]);
  12786. char_id = RFIFOL(fd,info->pos[1]);
  12787. // Search friend
  12788. for (i = 0; i < MAX_FRIENDS &&
  12789. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12790. if (i == MAX_FRIENDS) {
  12791. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12792. return;
  12793. }
  12794. //remove from friend's list first
  12795. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12796. for (i = 0; i < MAX_FRIENDS &&
  12797. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12798. if (i != MAX_FRIENDS) {
  12799. // move all chars up
  12800. for(j = i + 1; j < MAX_FRIENDS; j++)
  12801. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12802. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12803. //should the guy be notified of some message? we should add it here if so
  12804. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12805. WFIFOW(f_sd->fd,0) = 0x20a;
  12806. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12807. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12808. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12809. }
  12810. } else { //friend not online -- ask char server to delete from his friendlist
  12811. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12812. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12813. return;
  12814. }
  12815. }
  12816. // We can now delete from original requester
  12817. for (i = 0; i < MAX_FRIENDS &&
  12818. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12819. // move all chars up
  12820. for(j = i + 1; j < MAX_FRIENDS; j++)
  12821. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12822. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12823. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12824. WFIFOHEAD(fd,packet_len(0x20a));
  12825. WFIFOW(fd,0) = 0x20a;
  12826. WFIFOL(fd,2) = account_id;
  12827. WFIFOL(fd,6) = char_id;
  12828. WFIFOSET(fd, packet_len(0x20a));
  12829. }
  12830. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12831. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12832. void clif_PVPInfo(map_session_data* sd)
  12833. {
  12834. int fd = sd->fd;
  12835. WFIFOHEAD(fd,packet_len(0x210));
  12836. WFIFOW(fd,0) = 0x210;
  12837. WFIFOL(fd,2) = sd->status.char_id;
  12838. WFIFOL(fd,6) = sd->status.account_id;
  12839. WFIFOL(fd,10) = sd->pvp_won; // times won
  12840. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12841. WFIFOL(fd,18) = sd->pvp_point;
  12842. WFIFOSET(fd, packet_len(0x210));
  12843. }
  12844. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12845. /// 020f <char id>.L <account id>.L
  12846. void clif_parse_PVPInfo(int fd,map_session_data *sd)
  12847. {
  12848. // TODO: Is there a way to use this on an another player (char/acc id)?
  12849. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12850. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12851. clif_PVPInfo(sd);
  12852. }
  12853. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12854. /// 0254 <which>.B
  12855. /// which: (unused atm for security purpose)
  12856. /// 0 = sun
  12857. /// 1 = moon
  12858. /// 2 = star
  12859. void clif_parse_FeelSaveOk(int fd,map_session_data *sd)
  12860. {
  12861. int i;
  12862. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12863. if (sd->menuskill_id != SG_FEEL)
  12864. return;
  12865. i = sd->menuskill_val-1;
  12866. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12867. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12868. sd->feel_map[i].m = sd->bl.m;
  12869. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12870. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12871. // clif_misceffect2(&sd->bl, 0x1b0);
  12872. // clif_misceffect2(&sd->bl, 0x21f);
  12873. clif_feel_info(sd, i, 0);
  12874. clif_menuskill_clear(sd);
  12875. }
  12876. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12877. /// 0253 <which>.B
  12878. /// which:
  12879. /// 0 = sun
  12880. /// 1 = moon
  12881. /// 2 = star
  12882. void clif_feel_req(int fd, map_session_data *sd, uint16 skill_lv)
  12883. {
  12884. WFIFOHEAD(fd,packet_len(0x253));
  12885. WFIFOW(fd,0)=0x253;
  12886. WFIFOB(fd,2)=TOB(skill_lv-1);
  12887. WFIFOSET(fd, packet_len(0x253));
  12888. sd->menuskill_id = SG_FEEL;
  12889. sd->menuskill_val = skill_lv;
  12890. }
  12891. /// Request to change homunculus' name (CZ_RENAME_MER).
  12892. /// 0231 <name>.24B
  12893. void clif_parse_ChangeHomunculusName(int fd, map_session_data *sd){
  12894. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12895. }
  12896. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12897. /// 0234 <id>.L
  12898. void clif_parse_HomMoveToMaster(int fd, map_session_data *sd){
  12899. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12900. struct block_list *bl = nullptr;
  12901. struct unit_data *ud = nullptr;
  12902. if( sd->md && sd->md->bl.id == id )
  12903. bl = &sd->md->bl;
  12904. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12905. bl = &sd->hd->bl; // Moving Homunculus
  12906. else
  12907. return;
  12908. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12909. ud = unit_bl2ud(bl);
  12910. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12911. }
  12912. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12913. /// 0232 <id>.L <position data>.3B
  12914. void clif_parse_HomMoveTo(int fd, map_session_data *sd){
  12915. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12916. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12917. struct block_list *bl = nullptr;
  12918. short x, y;
  12919. RFIFOPOS(fd, info->pos[1], &x, &y, nullptr);
  12920. if( sd->md && sd->md->bl.id == id )
  12921. bl = &sd->md->bl; // Moving Mercenary
  12922. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12923. bl = &sd->hd->bl; // Moving Homunculus
  12924. else
  12925. return;
  12926. unit_walktoxy(bl, x, y, 4);
  12927. }
  12928. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12929. /// 0233 <id>.L <target id>.L <action>.B
  12930. /// action:
  12931. /// always 0
  12932. void clif_parse_HomAttack(int fd,map_session_data *sd)
  12933. {
  12934. struct block_list *bl = nullptr;
  12935. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12936. int id = RFIFOL(fd,info->pos[0]);
  12937. int target_id = RFIFOL(fd,info->pos[1]);
  12938. int action_type = RFIFOB(fd,info->pos[2]);
  12939. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12940. bl = &sd->hd->bl;
  12941. else if( sd->md && sd->md->bl.id == id )
  12942. bl = &sd->md->bl;
  12943. else return;
  12944. unit_stop_attack(bl);
  12945. unit_attack(bl, target_id, action_type != 0);
  12946. }
  12947. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12948. /// 022d <type>.W <command>.B
  12949. /// type:
  12950. /// always 0
  12951. /// command:
  12952. /// 0 = homunculus information
  12953. /// 1 = feed
  12954. /// 2 = delete
  12955. void clif_parse_HomMenu(int fd, map_session_data *sd)
  12956. { //[orn]
  12957. int cmd = RFIFOW(fd,0);
  12958. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12959. if(!hom_is_active(sd->hd))
  12960. return;
  12961. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12962. }
  12963. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12964. /// 0292
  12965. void clif_parse_AutoRevive(int fd, map_session_data *sd)
  12966. {
  12967. pc_revive_item(sd);
  12968. }
  12969. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12970. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12971. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12972. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12973. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12974. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12975. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12976. void clif_check(int fd, map_session_data* pl_sd)
  12977. {
  12978. WFIFOHEAD(fd,packet_len(0x214));
  12979. WFIFOW(fd, 0) = 0x214;
  12980. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12981. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12982. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12983. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12984. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12985. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12986. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12987. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12988. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12989. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12990. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12991. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12992. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12993. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12994. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12995. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12996. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12997. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12998. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12999. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13000. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13001. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13002. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13003. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13004. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13005. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13006. WFIFOSET(fd,packet_len(0x214));
  13007. }
  13008. /// /check (CZ_REQ_STATUS_GM).
  13009. /// Request character's status values.
  13010. /// 0213 <char name>.24B
  13011. void clif_parse_Check(int fd, map_session_data *sd)
  13012. {
  13013. char charname[NAME_LENGTH];
  13014. map_session_data* pl_sd;
  13015. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13016. return;
  13017. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13018. if( ( pl_sd = map_nick2sd(charname,false) ) == nullptr || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13019. {
  13020. return;
  13021. }
  13022. clif_check(fd, pl_sd);
  13023. }
  13024. /// MAIL SYSTEM
  13025. /// By Zephyrus
  13026. ///
  13027. /// Notification about the result of adding an item to mail
  13028. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13029. /// result:
  13030. /// 0 = success
  13031. /// 1 = failure
  13032. /// 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)
  13033. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13034. /// result:
  13035. /// 0 = success
  13036. /// 1 = over weight
  13037. /// 2 = fatal error
  13038. void clif_Mail_setattachment( map_session_data* sd, int index, int amount, uint8 flag ){
  13039. int fd = sd->fd;
  13040. #if PACKETVER < 20150513
  13041. WFIFOHEAD(fd,packet_len(0x255));
  13042. WFIFOW(fd,0) = 0x255;
  13043. WFIFOW(fd,2) = index;
  13044. WFIFOB(fd,4) = flag;
  13045. WFIFOSET(fd,packet_len(0x255));
  13046. #else
  13047. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13048. if( flag ){
  13049. memset( &p, 0, sizeof( p ) );
  13050. }else{
  13051. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13052. p.index = index;
  13053. p.count = amount;
  13054. p.itemId = client_nameid( item->nameid );
  13055. p.type = itemtype( item->nameid );
  13056. p.IsIdentified = item->identify ? 1 : 0;
  13057. p.IsDamaged = item->attribute ? 1 : 0;
  13058. p.refiningLevel = item->refine;
  13059. clif_addcards( &p.slot, item );
  13060. clif_add_random_options( p.optionData, *item );
  13061. p.weight = 0;
  13062. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13063. if( sd->mail.item[i].nameid == 0 ){
  13064. continue;
  13065. }
  13066. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13067. }
  13068. p.favorite = ( item->favorite != 0 ) ? 1 : 0;
  13069. p.location = pc_equippoint( sd, server_index( index ) );
  13070. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13071. p.grade = item->enchantgrade;
  13072. #endif
  13073. }
  13074. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13075. p.result = flag;
  13076. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13077. #endif
  13078. }
  13079. /// Notification about the result of retrieving a mail attachment
  13080. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13081. /// result:
  13082. /// 0 = success
  13083. /// 1 = failure
  13084. /// 2 = too many items
  13085. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13086. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13087. void clif_mail_getattachment(map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13088. #if PACKETVER < 20150513
  13089. int fd = sd->fd;
  13090. WFIFOHEAD(fd,packet_len(0x245));
  13091. WFIFOW(fd,0) = 0x245;
  13092. WFIFOB(fd,2) = result;
  13093. WFIFOSET(fd,packet_len(0x245));
  13094. #else
  13095. switch( type ){
  13096. case MAIL_ATT_ITEM:
  13097. case MAIL_ATT_ZENY:
  13098. break;
  13099. default:
  13100. return;
  13101. }
  13102. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13103. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13104. p.MailID = msg->id;
  13105. p.opentype = msg->type;
  13106. p.result = result;
  13107. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13108. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13109. #endif
  13110. }
  13111. /// Notification about the result of sending a mail
  13112. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13113. /// result:
  13114. /// 0 = success
  13115. /// 1 = recipinent does not exist
  13116. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13117. void clif_Mail_send(map_session_data* sd, enum mail_send_result result){
  13118. #if PACKETVER < 20150513
  13119. int fd = sd->fd;
  13120. WFIFOHEAD(fd,packet_len(0x249));
  13121. WFIFOW(fd,0) = 0x249;
  13122. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13123. WFIFOSET(fd,packet_len(0x249));
  13124. #else
  13125. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13126. p.PacketType = rodexwriteresult;
  13127. p.result = result;
  13128. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13129. #endif
  13130. }
  13131. /// Notification about the result of deleting a mail.
  13132. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13133. /// result:
  13134. /// 0 = success
  13135. /// 1 = failure
  13136. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13137. void clif_mail_delete( map_session_data* sd, struct mail_message *msg, bool success ){
  13138. #if PACKETVER < 20150513
  13139. int fd = sd->fd;
  13140. WFIFOHEAD(fd, packet_len(0x257));
  13141. WFIFOW(fd,0) = 0x257;
  13142. WFIFOL(fd,2) = msg->id;
  13143. WFIFOW(fd,6) = !success;
  13144. WFIFOSET(fd, packet_len(0x257));
  13145. #else
  13146. // This is only a success notification
  13147. if( success ){
  13148. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13149. p.PacketType = rodexdelete;
  13150. p.opentype = msg->type;
  13151. p.MailID = msg->id;
  13152. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13153. }
  13154. #endif
  13155. }
  13156. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13157. /// 0274 <mail id>.L <result>.W
  13158. /// result:
  13159. /// 0 = success
  13160. /// 1 = failure
  13161. void clif_Mail_return(int fd, int mail_id, short fail)
  13162. {
  13163. WFIFOHEAD(fd,packet_len(0x274));
  13164. WFIFOW(fd,0) = 0x274;
  13165. WFIFOL(fd,2) = mail_id;
  13166. WFIFOW(fd,6) = fail;
  13167. WFIFOSET(fd,packet_len(0x274));
  13168. }
  13169. /// Notification about new mail.
  13170. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13171. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13172. void clif_Mail_new(map_session_data* sd, int mail_id, const char *sender, const char *title){
  13173. #if PACKETVER < 20150513
  13174. int fd = sd->fd;
  13175. WFIFOHEAD(fd,packet_len(0x24a));
  13176. WFIFOW(fd,0) = 0x24a;
  13177. WFIFOL(fd,2) = mail_id;
  13178. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13179. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13180. WFIFOSET(fd,packet_len(0x24a));
  13181. #else
  13182. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13183. p.PacketType = rodexicon;
  13184. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13185. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13186. #endif
  13187. }
  13188. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13189. /// 0260 <type>.L
  13190. /// type:
  13191. /// 0 = open
  13192. /// 1 = close
  13193. void clif_Mail_window(int fd, int flag)
  13194. {
  13195. WFIFOHEAD(fd,packet_len(0x260));
  13196. WFIFOW(fd,0) = 0x260;
  13197. WFIFOL(fd,2) = flag;
  13198. WFIFOSET(fd,packet_len(0x260));
  13199. }
  13200. /// Lists mails stored in inbox.
  13201. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13202. /// read:
  13203. /// 0 = unread
  13204. /// 1 = read
  13205. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13206. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13207. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13208. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13209. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13210. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13211. void clif_Mail_refreshinbox(map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13212. #if PACKETVER < 20150513
  13213. int fd = sd->fd;
  13214. struct mail_data *md = &sd->mail.inbox;
  13215. struct mail_message *msg;
  13216. int len, i, j;
  13217. len = 8 + (73 * md->amount);
  13218. WFIFOHEAD(fd,len);
  13219. WFIFOW(fd,0) = 0x240;
  13220. WFIFOW(fd,2) = len;
  13221. WFIFOL(fd,4) = md->amount;
  13222. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13223. {
  13224. msg = &md->msg[i];
  13225. if (msg->id < 1)
  13226. continue;
  13227. WFIFOL(fd,8+73*j) = msg->id;
  13228. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13229. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13230. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13231. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13232. j++;
  13233. }
  13234. WFIFOSET(fd,len);
  13235. if( md->full ) {// TODO: is this official?
  13236. char output[100];
  13237. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13238. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13239. }
  13240. #else
  13241. int fd = sd->fd;
  13242. struct mail_data *md = &sd->mail.inbox;
  13243. struct mail_message *msg;
  13244. int i, j, k, offset, titleLength;
  13245. uint8 mailType, amount, remaining;
  13246. uint32 now = (uint32)time(nullptr);
  13247. #if PACKETVER >= 20170419
  13248. int cmd = 0xac2;
  13249. #elif PACKETVER >= 20160601
  13250. int cmd = 0xa7d;
  13251. #else
  13252. int cmd = 0x9f0;
  13253. #endif
  13254. if( battle_config.mail_daily_count ){
  13255. mail_refresh_remaining_amount(sd);
  13256. }
  13257. #if PACKETVER >= 20170419
  13258. // Always send all
  13259. i = md->amount;
  13260. #else
  13261. // If a starting mail id was sent
  13262. if( mailID != 0 ){
  13263. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13264. // Unknown mail
  13265. if( i == md->amount ){
  13266. // Ignore the request for now
  13267. return; // TODO: Should we just show the first page instead?
  13268. }
  13269. // It was actually the oldest/first mail, there is no further page
  13270. if( i == 0 ){
  13271. return;
  13272. }
  13273. // We actually want the next/older mail
  13274. i -= 1;
  13275. }else{
  13276. i = md->amount;
  13277. }
  13278. #endif
  13279. // Count the remaining mails from the starting mail or the beginning
  13280. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13281. for( j = i, remaining = 0; j >= 0; j-- ){
  13282. msg = &md->msg[j];
  13283. if (msg->id < 1)
  13284. continue;
  13285. #if PACKETVER < 20170419
  13286. if (msg->type != type)
  13287. continue;
  13288. #endif
  13289. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13290. continue;
  13291. remaining++;
  13292. }
  13293. #if PACKETVER >= 20170419
  13294. // Always send all
  13295. amount = remaining;
  13296. #else
  13297. if( remaining > MAIL_PAGE_SIZE ){
  13298. amount = MAIL_PAGE_SIZE;
  13299. }else{
  13300. amount = remaining;
  13301. }
  13302. #endif
  13303. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13304. WFIFOW(fd, 0) = cmd;
  13305. #if PACKETVER >= 20170419
  13306. WFIFOB(fd, 4) = 1; // Unknown
  13307. offset = 5;
  13308. #else
  13309. WFIFOB(fd, 4) = type;
  13310. WFIFOB(fd, 5) = amount;
  13311. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13312. offset = 7;
  13313. #endif
  13314. for( amount = 0; i >= 0; i-- ){
  13315. msg = &md->msg[i];
  13316. if (msg->id < 1)
  13317. continue;
  13318. #if PACKETVER < 20170419
  13319. if (msg->type != type)
  13320. continue;
  13321. #endif
  13322. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13323. continue;
  13324. #if PACKETVER >= 20170419
  13325. WFIFOB(fd, offset) = msg->type;
  13326. offset += 1;
  13327. #endif
  13328. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13329. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13330. mailType = MAIL_TYPE_TEXT; // Normal letter
  13331. if( msg->zeny > 0 ){
  13332. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13333. }
  13334. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13335. if( msg->item[k].nameid > 0 ){
  13336. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13337. break;
  13338. }
  13339. }
  13340. #if PACKETVER >= 20170419
  13341. // If it came from an npc?
  13342. if( !msg->send_id ){
  13343. mailType |= MAIL_TYPE_NPC;
  13344. }
  13345. #endif
  13346. WFIFOB(fd, offset + 9) = mailType;
  13347. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13348. #if PACKETVER < 20170419
  13349. // How much time has passed since you received the mail
  13350. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13351. offset += 4;
  13352. #endif
  13353. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13354. if( msg->scheduled_deletion > 0 ){
  13355. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13356. }else{
  13357. // Fake the scheduled deletion to one year in the future
  13358. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13359. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13360. }
  13361. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13362. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13363. offset += 40 + titleLength;
  13364. }
  13365. WFIFOW(fd, 2) = (int16)offset;
  13366. WFIFOSET(fd, offset);
  13367. #endif
  13368. }
  13369. /// Mail inbox list request.
  13370. /// 023f (CZ_MAIL_GET_LIST)
  13371. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13372. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13373. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13374. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13375. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13376. void clif_parse_Mail_refreshinbox(int fd, map_session_data *sd){
  13377. if( mail_invalid_operation( sd ) ){
  13378. return;
  13379. }
  13380. #if PACKETVER < 20150513
  13381. struct mail_data* md = &sd->mail.inbox;
  13382. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13383. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13384. else
  13385. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13386. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13387. mail_removezeny(sd, false);
  13388. #else
  13389. int cmd = RFIFOW(fd, 0);
  13390. #if PACKETVER < 20170419
  13391. uint8 openType = RFIFOB(fd, 2);
  13392. uint64 mailId = RFIFOQ(fd, 3);
  13393. #else
  13394. uint8 openType;
  13395. uint64 mailId = RFIFOQ(fd, 2);
  13396. int i;
  13397. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13398. if( i == MAIL_MAX_INBOX ){
  13399. openType = MAIL_INBOX_NORMAL;
  13400. mailId = 0;
  13401. }else{
  13402. openType = sd->mail.inbox.msg[i].type;
  13403. mailId = 0;
  13404. }
  13405. #endif
  13406. switch( openType ){
  13407. case MAIL_INBOX_NORMAL:
  13408. case MAIL_INBOX_ACCOUNT:
  13409. case MAIL_INBOX_RETURNED:
  13410. break;
  13411. default:
  13412. // Unknown type: ignore request
  13413. return;
  13414. }
  13415. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13416. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13417. return;
  13418. }
  13419. // If it is not a next page request
  13420. if( cmd != 0x9ee ){
  13421. mailId = 0;
  13422. }
  13423. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13424. #endif
  13425. }
  13426. /// Opens a mail
  13427. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13428. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13429. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13430. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13431. /// { }*n
  13432. // TODO: Packet description => for repeated block
  13433. void clif_Mail_read( map_session_data *sd, int mail_id ){
  13434. int i, fd = sd->fd;
  13435. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13436. if( i == MAIL_MAX_INBOX ) {
  13437. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13438. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13439. return;
  13440. } else {
  13441. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13442. struct item *item;
  13443. int16 msg_len;
  13444. msg_len = static_cast<decltype(msg_len)>( strlen(msg->body) );
  13445. if( msg_len == 0 ) {
  13446. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13447. msg_len = static_cast<decltype(msg_len)>( strlen(msg->body) );
  13448. }
  13449. #if PACKETVER < 20150513
  13450. item = &msg->item[0];
  13451. int16 len = 101 + msg_len;
  13452. WFIFOHEAD(fd,len);
  13453. WFIFOW(fd,0) = 0x242;
  13454. WFIFOW(fd,2) = len;
  13455. WFIFOL(fd,4) = msg->id;
  13456. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13457. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13458. WFIFOL(fd,72) = 0;
  13459. WFIFOL(fd,76) = msg->zeny;
  13460. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13461. if( item->nameid && data != nullptr ) {
  13462. WFIFOL(fd,80) = item->amount;
  13463. WFIFOW(fd,84) = client_nameid( item->nameid );
  13464. WFIFOW(fd,86) = itemtype( item->nameid );
  13465. WFIFOB(fd,88) = item->identify;
  13466. WFIFOB(fd,89) = item->attribute;
  13467. WFIFOB(fd,90) = item->refine;
  13468. WFIFOW(fd,91) = item->card[0];
  13469. WFIFOW(fd,93) = item->card[1];
  13470. WFIFOW(fd,95) = item->card[2];
  13471. WFIFOW(fd,97) = item->card[3];
  13472. } else // no item, set all to zero
  13473. memset(WFIFOP(fd,80), 0x00, 19);
  13474. WFIFOB(fd,99) = (unsigned char)msg_len;
  13475. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13476. WFIFOSET(fd,len);
  13477. #else
  13478. msg_len += 1; // Zero Termination
  13479. PACKET_ZC_ACK_READ_RODEX* p = reinterpret_cast<PACKET_ZC_ACK_READ_RODEX*>( packet_buffer );
  13480. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13481. p->PacketLength = sizeof( *p );
  13482. p->opentype = msg->type;
  13483. p->MailID = msg->id;
  13484. p->TextcontentsLength = static_cast<decltype(p->TextcontentsLength)>( msg_len );
  13485. p->zeny = msg->zeny;
  13486. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13487. p->PacketLength += p->TextcontentsLength;
  13488. p->ItemCnt = 0;
  13489. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13490. item = &msg->item[j];
  13491. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13492. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13493. PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = reinterpret_cast<PACKET_ZC_ACK_READ_RODEX_SUB*>( WBUFP( p, p->PacketLength ) );
  13494. mailitem->ITID = client_nameid( item->nameid );
  13495. mailitem->count = item->amount;
  13496. mailitem->type = itemtype( item->nameid );
  13497. mailitem->IsIdentified = item->identify ? 1 : 0;
  13498. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13499. mailitem->refiningLevel = item->refine;
  13500. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13501. mailitem->viewSprite = data->look;
  13502. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13503. clif_addcards( &mailitem->slot, item );
  13504. clif_add_random_options( mailitem->option_data, *item );
  13505. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13506. mailitem->grade = item->enchantgrade;
  13507. #endif
  13508. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( *mailitem ) );
  13509. p->ItemCnt++;
  13510. }
  13511. }
  13512. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13513. #endif
  13514. if (msg->status == MAIL_UNREAD) {
  13515. msg->status = MAIL_READ;
  13516. intif_Mail_read(mail_id);
  13517. clif_parse_Mail_refreshinbox(fd, sd);
  13518. sd->mail.inbox.unread--;
  13519. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13520. }
  13521. }
  13522. }
  13523. /// Request to open a mail.
  13524. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13525. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13526. void clif_parse_Mail_read(int fd, map_session_data *sd){
  13527. #if PACKETVER < 20150513
  13528. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13529. #else
  13530. //uint8 openType = RFIFOB(fd, 2);
  13531. int mail_id = (int)RFIFOQ(fd, 3);
  13532. #endif
  13533. if( mail_id <= 0 )
  13534. return;
  13535. if( mail_invalid_operation(sd) )
  13536. return;
  13537. clif_Mail_read(sd, mail_id);
  13538. }
  13539. /// Allow a player to begin writing a mail
  13540. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13541. void clif_send_Mail_beginwrite_ack( map_session_data *sd, char* name, bool success ){
  13542. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13543. p.PacketType = rodexopenwrite;
  13544. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13545. p.result = success;
  13546. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13547. }
  13548. /// Request to start writing a mail
  13549. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13550. void clif_parse_Mail_beginwrite( int fd, map_session_data *sd ){
  13551. char name[NAME_LENGTH];
  13552. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13553. if( mail_invalid_operation( sd ) ){
  13554. return;
  13555. }
  13556. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13557. clif_send_Mail_beginwrite_ack(sd, name, false);
  13558. return;
  13559. }
  13560. mail_clear(sd);
  13561. sd->state.mail_writing = true;
  13562. clif_send_Mail_beginwrite_ack(sd, name,true);
  13563. }
  13564. /// Notification that the client cancelled writing a mail
  13565. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13566. void clif_parse_Mail_cancelwrite( int fd, map_session_data *sd ){
  13567. sd->state.mail_writing = false;
  13568. }
  13569. /// Give the client information about the recipient, if available
  13570. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13571. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13572. void clif_Mail_Receiver_Ack( map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13573. #if PACKETVER >= 20141119
  13574. PACKET_ZC_CHECKNAME p = { 0 };
  13575. p.PacketType = HEADER_ZC_CHECKNAME;
  13576. p.CharId = char_id;
  13577. p.Class = class_;
  13578. p.BaseLevel = level;
  13579. #if PACKETVER >= 20160302
  13580. strncpy(p.Name, name, NAME_LENGTH);
  13581. #endif
  13582. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13583. #endif
  13584. }
  13585. /// Request information about the recipient
  13586. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13587. void clif_parse_Mail_Receiver_Check(int fd, map_session_data *sd) {
  13588. #if PACKETVER >= 20140423
  13589. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13590. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13591. #else
  13592. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13593. #endif
  13594. static char name[NAME_LENGTH];
  13595. if( mail_invalid_operation( sd ) ){
  13596. return;
  13597. }
  13598. safestrncpy(name, p->Name, NAME_LENGTH);
  13599. intif_mail_checkreceiver(sd, name);
  13600. #endif
  13601. }
  13602. /// Request to receive mail's attachment.
  13603. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13604. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13605. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13606. void clif_parse_Mail_getattach( int fd, map_session_data *sd ){
  13607. int i;
  13608. struct mail_message* msg;
  13609. #if PACKETVER < 20150513
  13610. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13611. int attachment = MAIL_ATT_ALL;
  13612. #else
  13613. uint16 packet_id = RFIFOW(fd, 0);
  13614. int mail_id = (int)RFIFOQ(fd, 2);
  13615. //int openType = RFIFOB(fd, 10);
  13616. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13617. #endif
  13618. if( !chrif_isconnected() )
  13619. return;
  13620. if( mail_id <= 0 )
  13621. return;
  13622. if( mail_invalid_operation(sd) )
  13623. return;
  13624. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13625. if( i == MAIL_MAX_INBOX )
  13626. return;
  13627. msg = &sd->mail.inbox.msg[i];
  13628. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13629. attachment &= ~MAIL_ATT_ZENY;
  13630. }
  13631. if( attachment&MAIL_ATT_ITEM ){
  13632. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13633. // No items were found
  13634. if( i == MAIL_MAX_ITEM ){
  13635. attachment &= ~MAIL_ATT_ITEM;
  13636. }
  13637. }
  13638. // Either no attachment requested at all or there are no zeny or items in the mail
  13639. if( attachment == MAIL_ATT_NONE ){
  13640. return;
  13641. }
  13642. if( attachment&MAIL_ATT_ZENY ){
  13643. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13644. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13645. return;
  13646. }else{
  13647. // Store the pending zeny (required for the "retrieve all" feature)
  13648. sd->mail.pending_zeny += msg->zeny;
  13649. // To make sure another request fails
  13650. msg->zeny = 0;
  13651. }
  13652. }
  13653. if( attachment&MAIL_ATT_ITEM ){
  13654. int slots = 0, totalweight = 0;
  13655. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13656. struct item* item = &msg->item[i];
  13657. if( item->nameid > 0 && item->amount > 0 ){
  13658. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13659. if(data == nullptr)
  13660. continue;
  13661. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13662. case CHKADDITEM_NEW:
  13663. slots += data->inventorySlotNeeded( item->amount );
  13664. break;
  13665. case CHKADDITEM_OVERAMOUNT:
  13666. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13667. return;
  13668. }
  13669. totalweight += data->weight * item->amount;
  13670. }
  13671. }
  13672. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13673. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13674. return;
  13675. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13676. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13677. return;
  13678. }
  13679. // To make sure another request fails
  13680. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13681. // Store the pending weight (required for the "retrieve all" feature)
  13682. sd->mail.pending_weight += totalweight;
  13683. // Store the pending slots (required for the "retrieve all" feature)
  13684. sd->mail.pending_slots += slots;
  13685. }
  13686. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13687. }
  13688. /// Request to delete a mail.
  13689. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13690. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13691. void clif_parse_Mail_delete(int fd, map_session_data *sd){
  13692. #if PACKETVER < 20150513
  13693. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13694. #else
  13695. //int openType = RFIFOB(fd, 2);
  13696. int mail_id = (int)RFIFOQ(fd, 3);
  13697. #endif
  13698. int i, j;
  13699. if( !chrif_isconnected() )
  13700. return;
  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) {
  13707. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13708. // can't delete mail without removing zeny first
  13709. if( msg->zeny > 0 ){
  13710. clif_mail_delete(sd, msg, false);
  13711. return;
  13712. }
  13713. // can't delete mail without removing attachment(s) first
  13714. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13715. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13716. clif_mail_delete(sd, msg, false);
  13717. return;
  13718. }
  13719. }
  13720. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13721. sd->mail.inbox.unread--;
  13722. clif_Mail_new(sd,0,nullptr,nullptr);
  13723. }
  13724. }
  13725. }
  13726. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13727. /// 0273 <mail id>.L <receive name>.24B
  13728. void clif_parse_Mail_return(int fd, map_session_data *sd){
  13729. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13730. struct PACKET_CZ_RODEX_RETURN* p = (struct PACKET_CZ_RODEX_RETURN*)RFIFOP( fd, 0 );
  13731. //ShowDump( p, sizeof( p ) );
  13732. int mail_id = p->msgId;
  13733. // not supported for now
  13734. return;
  13735. #else
  13736. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13737. #endif
  13738. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13739. int i;
  13740. if( mail_id <= 0 )
  13741. return;
  13742. if( mail_invalid_operation(sd) )
  13743. return;
  13744. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13745. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13746. intif_Mail_return(sd->status.char_id, mail_id);
  13747. else
  13748. clif_Mail_return(sd->fd, mail_id, 1);
  13749. }
  13750. /// Request to add an item or Zeny to mail.
  13751. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13752. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13753. void clif_parse_Mail_setattach(int fd, map_session_data *sd){
  13754. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13755. uint16 idx = RFIFOW(fd,info->pos[0]);
  13756. #if PACKETVER < 20150513
  13757. int amount = RFIFOL(fd,info->pos[1]);
  13758. #else
  13759. int amount = RFIFOW(fd,info->pos[1]);
  13760. #endif
  13761. unsigned char flag;
  13762. if( !chrif_isconnected() )
  13763. return;
  13764. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13765. return;
  13766. if (sd->inventory_data[server_index(idx)] == nullptr)
  13767. return;
  13768. if( mail_invalid_operation( sd ) ){
  13769. return;
  13770. }
  13771. flag = mail_setitem(sd, idx, amount);
  13772. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13773. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  13774. }else{
  13775. clif_Mail_setattachment(sd,idx,amount,flag);
  13776. }
  13777. }
  13778. /// Remove an item from a mail
  13779. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13780. void clif_mail_removeitem( map_session_data* sd, bool success, int index, int amount ){
  13781. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13782. p.PacketType = rodexremoveitem;
  13783. p.result = success;
  13784. p.index = index;
  13785. p.cnt = amount;
  13786. int total = 0;
  13787. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13788. if( sd->mail.item[i].nameid == 0 ){
  13789. break;
  13790. }
  13791. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13792. }
  13793. p.weight = total;
  13794. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13795. }
  13796. /// Request to reset mail item and/or Zeny
  13797. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13798. /// type:
  13799. /// 0 = reset all
  13800. /// 1 = remove item
  13801. /// 2 = remove zeny
  13802. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13803. void clif_parse_Mail_winopen(int fd, map_session_data *sd)
  13804. {
  13805. #if PACKETVER < 20150513
  13806. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13807. if (type == 0 || type == 1)
  13808. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13809. if (type == 0 || type == 2)
  13810. mail_removezeny(sd, false);
  13811. #else
  13812. uint16 index = RFIFOW(fd, 2);
  13813. uint16 count = RFIFOW(fd, 4);
  13814. mail_removeitem(sd,0,index,count);
  13815. #endif
  13816. }
  13817. /// Request to send mail
  13818. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13819. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13820. /// 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)
  13821. void clif_parse_Mail_send(int fd, map_session_data *sd){
  13822. #if PACKETVER < 20150513
  13823. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13824. if( !chrif_isconnected() )
  13825. return;
  13826. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13827. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13828. return;
  13829. }
  13830. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13831. #else
  13832. uint16 length = RFIFOW(fd, 2);
  13833. if( length < 0x3e ){
  13834. ShowWarning("Too short...\n");
  13835. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13836. return;
  13837. }
  13838. if( mail_invalid_operation( sd ) ){
  13839. return;
  13840. }
  13841. // Forged request without a begin writing packet?
  13842. if( !sd->state.mail_writing ){
  13843. return; // Ignore it
  13844. }
  13845. char receiver[NAME_LENGTH];
  13846. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13847. // char sender[NAME_LENGTH];
  13848. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13849. uint64 zeny = RFIFOQ(fd, 52);
  13850. uint16 titleLength = RFIFOW(fd, 60);
  13851. uint16 textLength = RFIFOW(fd, 62);
  13852. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13853. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13854. char title[MAIL_TITLE_LENGTH];
  13855. char text[MAIL_BODY_LENGTH];
  13856. #if PACKETVER <= 20160330
  13857. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13858. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13859. #else
  13860. // 64 = <char id>.L
  13861. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13862. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13863. #endif
  13864. if( zeny > 0 ){
  13865. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13866. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13867. return;
  13868. }
  13869. }
  13870. mail_send(sd, receiver, title, text, realTextLength);
  13871. #endif
  13872. }
  13873. /// AUCTION SYSTEM
  13874. /// By Zephyrus
  13875. ///
  13876. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13877. /// 025f <type>.L
  13878. /// type:
  13879. /// 0 = open
  13880. /// 1 = close
  13881. void clif_Auction_openwindow(map_session_data *sd)
  13882. {
  13883. int fd = sd->fd;
  13884. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13885. return;
  13886. if( !battle_config.feature_auction )
  13887. return;
  13888. WFIFOHEAD(fd,packet_len(0x25f));
  13889. WFIFOW(fd,0) = 0x25f;
  13890. WFIFOL(fd,2) = 0;
  13891. WFIFOSET(fd,packet_len(0x25f));
  13892. }
  13893. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13894. /// 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 }*
  13895. void clif_Auction_results(map_session_data *sd, short count, short pages, uint8 *buf)
  13896. {
  13897. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13898. struct auction_data auction;
  13899. WFIFOHEAD(fd,12 + (count * 83));
  13900. WFIFOW(fd,0) = 0x252;
  13901. WFIFOW(fd,2) = 12 + (count * 83);
  13902. WFIFOL(fd,4) = pages;
  13903. WFIFOL(fd,8) = count;
  13904. for( i = 0; i < count; i++ ) {
  13905. int k = 12 + (i * 83);
  13906. memcpy(&auction, RBUFP(buf,i * len), len);
  13907. WFIFOL(fd,k) = auction.auction_id;
  13908. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13909. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13910. WFIFOL(fd,30+k) = auction.type;
  13911. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13912. WFIFOB(fd,36+k) = auction.item.identify;
  13913. WFIFOB(fd,37+k) = auction.item.attribute;
  13914. WFIFOB(fd,38+k) = auction.item.refine;
  13915. WFIFOW(fd,39+k) = auction.item.card[0];
  13916. WFIFOW(fd,41+k) = auction.item.card[1];
  13917. WFIFOW(fd,43+k) = auction.item.card[2];
  13918. WFIFOW(fd,45+k) = auction.item.card[3];
  13919. WFIFOL(fd,47+k) = auction.price;
  13920. WFIFOL(fd,51+k) = auction.buynow;
  13921. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13922. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13923. }
  13924. WFIFOSET(fd,WFIFOW(fd,2));
  13925. }
  13926. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13927. /// 0256 <index>.W <result>.B
  13928. /// result:
  13929. /// 0 = success
  13930. /// 1 = failure
  13931. static void clif_Auction_setitem(int fd, int index, bool fail)
  13932. {
  13933. WFIFOHEAD(fd,packet_len(0x256));
  13934. WFIFOW(fd,0) = 0x256;
  13935. WFIFOW(fd,2) = index;
  13936. WFIFOB(fd,4) = fail;
  13937. WFIFOSET(fd,packet_len(0x256));
  13938. }
  13939. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13940. /// 024b <type>.W
  13941. /// type:
  13942. /// 0 = create (any other action in auction window)
  13943. /// 1 = cancel (cancel pressed on register tab)
  13944. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13945. void clif_parse_Auction_cancelreg(int fd, map_session_data *sd){
  13946. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13947. if( sd->auction.amount > 0 )
  13948. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13949. sd->auction.amount = 0;
  13950. }
  13951. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13952. /// 024c <index>.W <count>.L
  13953. void clif_parse_Auction_setitem(int fd, map_session_data *sd){
  13954. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13955. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13956. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13957. if( !battle_config.feature_auction )
  13958. return;
  13959. if( sd->auction.amount > 0 )
  13960. sd->auction.amount = 0;
  13961. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13962. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13963. return;
  13964. }
  13965. 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.
  13966. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13967. return;
  13968. }
  13969. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  13970. 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) )
  13971. { // Consumable or pets are not allowed
  13972. clif_Auction_setitem(sd->fd, idx, true);
  13973. return;
  13974. }
  13975. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13976. !sd->inventory.u.items_inventory[idx].identify ||
  13977. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13978. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13979. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13980. clif_Auction_setitem(sd->fd, idx, true);
  13981. return;
  13982. }
  13983. sd->auction.index = idx;
  13984. sd->auction.amount = amount;
  13985. clif_Auction_setitem(fd, idx + 2, false);
  13986. }
  13987. /// Result from an auction action (ZC_AUCTION_RESULT).
  13988. /// 0250 <result>.B
  13989. /// result:
  13990. /// 0 = You have failed to bid into the auction
  13991. /// 1 = You have successfully bid in the auction
  13992. /// 2 = The auction has been canceled
  13993. /// 3 = An auction with at least one bidder cannot be canceled
  13994. /// 4 = You cannot register more than 5 items in an auction at a time
  13995. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13996. /// 6 = You have won the auction
  13997. /// 7 = You have failed to win the auction
  13998. /// 8 = You do not have enough Zeny
  13999. /// 9 = You cannot place more than 5 bids at a time
  14000. void clif_Auction_message(int fd, unsigned char flag)
  14001. {
  14002. WFIFOHEAD(fd,packet_len(0x250));
  14003. WFIFOW(fd,0) = 0x250;
  14004. WFIFOB(fd,2) = flag;
  14005. WFIFOSET(fd,packet_len(0x250));
  14006. }
  14007. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14008. /// 025e <result>.W
  14009. /// result:
  14010. /// 0 = You have ended the auction
  14011. /// 1 = You cannot end the auction
  14012. /// 2 = Auction ID is incorrect
  14013. void clif_Auction_close(int fd, unsigned char flag)
  14014. {
  14015. WFIFOHEAD(fd,packet_len(0x25e));
  14016. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14017. WFIFOW(fd,2) = flag;
  14018. WFIFOSET(fd,packet_len(0x25e));
  14019. }
  14020. /// Request to add an auction (CZ_AUCTION_ADD).
  14021. /// 024d <now money>.L <max money>.L <delete hour>.W
  14022. void clif_parse_Auction_register(int fd, map_session_data *sd)
  14023. {
  14024. struct auction_data auction;
  14025. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14026. if( !battle_config.feature_auction )
  14027. return;
  14028. auction.price = RFIFOL(fd,info->pos[0]);
  14029. auction.buynow = RFIFOL(fd,info->pos[1]);
  14030. auction.hours = RFIFOW(fd,info->pos[2]);
  14031. // Invalid Situations...
  14032. if( sd->auction.amount < 1 ) {
  14033. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14034. return;
  14035. }
  14036. if( auction.price >= auction.buynow ) {
  14037. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14038. return;
  14039. }
  14040. if( auction.hours < 1 || auction.hours > 48 ) {
  14041. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14042. return;
  14043. }
  14044. // Auction checks...
  14045. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14046. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14047. clif_Auction_message(fd, 2); // The auction has been canceled
  14048. return;
  14049. }
  14050. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14051. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14052. return;
  14053. }
  14054. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14055. auction.buynow = battle_config.auction_maximumprice;
  14056. if( auction.price >= auction.buynow )
  14057. auction.price = auction.buynow - 1;
  14058. }
  14059. auction.auction_id = 0;
  14060. auction.seller_id = sd->status.char_id;
  14061. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14062. auction.buyer_id = 0;
  14063. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14064. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14065. {
  14066. clif_Auction_message(fd, 2); // The auction has been canceled
  14067. return;
  14068. }
  14069. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14070. if( id == nullptr )
  14071. { // Just in case
  14072. clif_Auction_message(fd, 2); // The auction has been canceled
  14073. return;
  14074. }
  14075. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14076. auction.type = id->type;
  14077. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14078. auction.item.amount = 1;
  14079. auction.timestamp = 0;
  14080. if( !intif_Auction_register(&auction) )
  14081. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14082. else
  14083. {
  14084. int zeny = auction.hours*battle_config.auction_feeperhour;
  14085. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14086. sd->auction.amount = 0;
  14087. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION);
  14088. }
  14089. }
  14090. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14091. /// 024e <auction id>.L
  14092. void clif_parse_Auction_cancel(int fd, map_session_data *sd){
  14093. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14094. intif_Auction_cancel(sd->status.char_id, auction_id);
  14095. }
  14096. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14097. /// 025d <auction id>.L
  14098. void clif_parse_Auction_close(int fd, map_session_data *sd){
  14099. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14100. intif_Auction_close(sd->status.char_id, auction_id);
  14101. }
  14102. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14103. /// 024f <auction id>.L <money>.L
  14104. void clif_parse_Auction_bid(int fd, map_session_data *sd){
  14105. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14106. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14107. int bid = RFIFOL(fd,info->pos[1]);
  14108. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14109. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14110. return;
  14111. }
  14112. if( bid <= 0 )
  14113. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14114. else if( bid > sd->status.zeny )
  14115. clif_Auction_message(fd, 8); // You do not have enough zeny
  14116. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14117. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14118. else {
  14119. pc_payzeny(sd, bid, LOG_TYPE_AUCTION);
  14120. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14121. }
  14122. }
  14123. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14124. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14125. /// search type:
  14126. /// 0 = armor
  14127. /// 1 = weapon
  14128. /// 2 = card
  14129. /// 3 = misc
  14130. /// 4 = name search
  14131. /// 5 = auction id search
  14132. void clif_parse_Auction_search(int fd, map_session_data* sd){
  14133. char search_text[NAME_LENGTH];
  14134. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14135. short type = RFIFOW(fd,info->pos[0]);
  14136. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14137. int page = RFIFOW(fd,info->pos[3]);
  14138. if( !battle_config.feature_auction )
  14139. return;
  14140. clif_parse_Auction_cancelreg(fd, sd);
  14141. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14142. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14143. }
  14144. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14145. /// 025c <type>.W
  14146. /// type:
  14147. /// 0 = sell (own auctions)
  14148. /// 1 = buy (own bids)
  14149. void clif_parse_Auction_buysell(int fd, map_session_data* sd)
  14150. {
  14151. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14152. if( !battle_config.feature_auction )
  14153. return;
  14154. clif_parse_Auction_cancelreg(fd, sd);
  14155. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14156. }
  14157. /// CASH/POINT SHOP
  14158. ///
  14159. void clif_cashshop_open( map_session_data* sd, int tab ){
  14160. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14161. nullpo_retv( sd );
  14162. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14163. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14164. p.cashPoints = sd->cashPoints;
  14165. p.kafraPoints = sd->kafraPoints;
  14166. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14167. p.tab = tab;
  14168. #endif
  14169. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14170. #endif
  14171. }
  14172. void clif_parse_cashshop_open_request( int fd, map_session_data* sd ){
  14173. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14174. nullpo_retv( sd );
  14175. int tab = 0;
  14176. #if PACKETVER >= 20191224
  14177. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14178. tab = p->tab;
  14179. #endif
  14180. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14181. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14182. return;
  14183. }
  14184. sd->state.cashshop_open = true;
  14185. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14186. clif_cashshop_open( sd, tab );
  14187. #endif
  14188. }
  14189. void clif_parse_cashshop_close( int fd, map_session_data* sd ){
  14190. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14191. sd->state.cashshop_open = false;
  14192. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14193. // No need to do anything here
  14194. #endif
  14195. }
  14196. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14197. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14198. void clif_parse_CashShopReqTab(int fd, map_session_data *sd) {
  14199. #if PACKETVER_MAIN_NUM >= 20100824 || PACKETVER_RE_NUM >= 20100824 || defined(PACKETVER_ZERO)
  14200. PACKET_CZ_REQ_SE_CASH_TAB_CODE* p_in = reinterpret_cast<PACKET_CZ_REQ_SE_CASH_TAB_CODE*>( RFIFOP( fd, 0 ) );
  14201. // TODO: most likely wrong answer packet. Most likely HEADER_ZC_ACK_SE_CASH_ITEM_LIST (0x847) would be correct [Lemongrass]
  14202. // [4144] packet exists only in 2011 and was dropped after
  14203. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14204. std::shared_ptr<s_cash_item_tab> tab = cash_shop_db.find( static_cast<e_cash_shop_tab>( p_in->tab ) );
  14205. if( tab == nullptr ){
  14206. return;
  14207. }
  14208. // Skip empty tabs, the client only expects filled ones
  14209. if( tab->items.empty() ){
  14210. return;
  14211. }
  14212. #if !(PACKETVER_SUPPORTS_SALES)
  14213. if( tab->tab == CASHSHOP_TAB_SALE ){
  14214. return;
  14215. }
  14216. #endif
  14217. PACKET_ZC_ACK_SE_CASH_ITEM_LIST2* p = reinterpret_cast<PACKET_ZC_ACK_SE_CASH_ITEM_LIST2*>( packet_buffer );
  14218. p->packetType = HEADER_ZC_ACK_SE_CASH_ITEM_LIST2;
  14219. p->packetLength = sizeof( *p );
  14220. p->tab = tab->tab;
  14221. p->count = 0;
  14222. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14223. p->items[p->count].itemId = client_nameid( item->nameid );
  14224. p->items[p->count].price = item->price;
  14225. p->packetLength += static_cast<decltype>(p->packetLength)>( sizeof( p->items[0] ) );
  14226. p->count++;
  14227. }
  14228. clif_send( p, p->packetLength, &sd->bl, SELF );
  14229. #endif
  14230. #endif
  14231. }
  14232. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14233. void clif_cashshop_list( map_session_data& sd ){
  14234. for( const auto& pair : cash_shop_db ){
  14235. std::shared_ptr<s_cash_item_tab> tab = pair.second;
  14236. // Skip empty tabs, the client only expects filled ones
  14237. if( tab->items.empty() ){
  14238. continue;
  14239. }
  14240. #if !(PACKETVER_SUPPORTS_SALES)
  14241. if( tab->tab == CASHSHOP_TAB_SALE ){
  14242. continue;
  14243. }
  14244. #endif
  14245. PACKET_ZC_ACK_SCHEDULER_CASHITEM* p = reinterpret_cast<PACKET_ZC_ACK_SCHEDULER_CASHITEM*>( packet_buffer );
  14246. p->packetType = HEADER_ZC_ACK_SCHEDULER_CASHITEM;
  14247. p->packetLength = sizeof( *p );
  14248. p->count = 0;
  14249. p->tabNum = tab->tab;
  14250. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14251. p->items[p->count].itemId = client_nameid( item->nameid );
  14252. p->items[p->count].price = item->price;
  14253. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14254. struct item_data* id = itemdb_search( item->nameid );
  14255. if( id == nullptr ){
  14256. p->items[p->count].location = 0;
  14257. p->items[p->count].viewSprite = 0;
  14258. }else{
  14259. p->items[p->count].location = pc_equippoint_sub( &sd, id );
  14260. p->items[p->count].viewSprite = id->look;
  14261. }
  14262. #endif
  14263. p->count++;
  14264. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  14265. if( ( static_cast<size_t>( p->packetLength ) + sizeof( p->items[0] ) ) >= INT16_MAX ){
  14266. // Send current data
  14267. clif_send( p, p->packetLength, &sd.bl, SELF );
  14268. // Start a new packet
  14269. p->count = 0;
  14270. p->packetLength = sizeof( *p );
  14271. }
  14272. }
  14273. clif_send( p, p->packetLength, &sd.bl, SELF );
  14274. }
  14275. }
  14276. void clif_parse_cashshop_list_request( int fd, map_session_data* sd ){
  14277. if( !sd->status.cashshop_sent ) {
  14278. clif_cashshop_list( *sd );
  14279. #if PACKETVER_SUPPORTS_SALES
  14280. sale_notify_login(sd);
  14281. #endif
  14282. sd->status.cashshop_sent = true;
  14283. }
  14284. }
  14285. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14286. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14287. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14288. void clif_cashshop_show( map_session_data& sd, npc_data& nd ){
  14289. sd.npc_shopid = nd.bl.id;
  14290. int cost[2] = { 0, 0 };
  14291. npc_shop_currency_type( &sd, &nd, cost, true );
  14292. PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = reinterpret_cast<PACKET_ZC_PC_CASH_POINT_ITEMLIST*>( packet_buffer );
  14293. p->packetType = HEADER_ZC_PC_CASH_POINT_ITEMLIST;
  14294. p->packetLength = sizeof( *p );
  14295. p->cashPoints = cost[0];
  14296. #if PACKETVER >= 20070711
  14297. p->kafraPoints = cost[1];
  14298. #endif
  14299. for( int i = 0; i < nd.u.shop.count; i++ ) {
  14300. struct item_data* id = itemdb_search( nd.u.shop.shop_item[i].nameid );
  14301. p->items[i].price = nd.u.shop.shop_item[i].value;
  14302. p->items[i].discountPrice = nd.u.shop.shop_item[i].value; // Discount Price
  14303. p->items[i].itemType = itemtype( id->nameid );
  14304. p->items[i].itemId = client_nameid( id->nameid );
  14305. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14306. p->items[i].location = pc_equippoint_sub( &sd, id );
  14307. p->items[i].viewSprite = id->look;
  14308. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14309. #endif
  14310. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  14311. }
  14312. clif_send( p, p->packetLength, &sd.bl, SELF );
  14313. }
  14314. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14315. /// 0289 <cash point>.L <error>.W
  14316. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14317. /// error:
  14318. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14319. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14320. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14321. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14322. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14323. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14324. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14325. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14326. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14327. void clif_cashshop_ack(map_session_data* sd, int error)
  14328. {
  14329. int fd, cost[2] = { 0, 0 };
  14330. struct npc_data *nd;
  14331. nullpo_retv(sd);
  14332. fd = sd->fd;
  14333. nd = map_id2nd(sd->npc_shopid);
  14334. npc_shop_currency_type(sd, nd, cost, false);
  14335. WFIFOHEAD(fd, packet_len(0x289));
  14336. WFIFOW(fd,0) = 0x289;
  14337. WFIFOL(fd,2) = cost[0];
  14338. #if PACKETVER < 20070711
  14339. WFIFOW(fd,6) = TOW(error);
  14340. #else
  14341. WFIFOL(fd,6) = cost[1];
  14342. WFIFOW(fd,10) = TOW(error);
  14343. #endif
  14344. WFIFOSET(fd, packet_len(0x289));
  14345. }
  14346. void clif_cashshop_result( map_session_data *sd, t_itemid item_id, uint16 result ){
  14347. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14348. nullpo_retv( sd );
  14349. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet = {};
  14350. packet.packetType = HEADER_ZC_SE_PC_BUY_CASHITEM_RESULT;
  14351. if( item_id != 0 ){
  14352. packet.itemId = client_nameid( item_id );
  14353. }else{
  14354. packet.itemId = 0;
  14355. }
  14356. packet.result = result;
  14357. packet.cashPoints = sd->cashPoints;
  14358. packet.kafraPoints = sd->kafraPoints;
  14359. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  14360. #endif
  14361. }
  14362. /// Request to buy item(s) from cash shop.
  14363. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14364. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14365. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14366. void clif_parse_npccashshop_buy( int fd, map_session_data *sd ){
  14367. nullpo_retv( sd );
  14368. if( sd->state.trading || !sd->npc_shopid ){
  14369. clif_cashshop_ack( sd, 1 );
  14370. return;
  14371. }
  14372. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14373. #if PACKETVER < 20070711
  14374. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14375. #elif PACKETVER < 20101116
  14376. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14377. #else
  14378. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14379. 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 ){
  14380. 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 );
  14381. return;
  14382. }
  14383. std::vector<s_npc_buy_list> item_list = {};
  14384. item_list.reserve( p->count );
  14385. for( int i = 0; i < p->count; i++ ){
  14386. s_npc_buy_list item = {};
  14387. item.nameid = p->items[i].itemId;
  14388. item.qty = p->items[i].amount;
  14389. item_list.push_back( item );
  14390. }
  14391. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14392. #endif
  14393. }
  14394. /// Request to buy item(s) from cash shop.
  14395. /// 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)
  14396. void clif_parse_cashshop_buy( int fd, map_session_data *sd ){
  14397. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14398. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14399. 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 ){
  14400. 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 );
  14401. return;
  14402. }
  14403. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14404. }
  14405. /// Adoption System
  14406. ///
  14407. /// Adoption message (ZC_BABYMSG).
  14408. /// 0216 <msg>.L
  14409. /// msg:
  14410. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14411. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14412. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14413. void clif_Adopt_reply(map_session_data *sd, int type)
  14414. {
  14415. int fd = sd->fd;
  14416. WFIFOHEAD(fd,6);
  14417. WFIFOW(fd,0) = 0x216;
  14418. WFIFOL(fd,2) = type;
  14419. WFIFOSET(fd,6);
  14420. }
  14421. /// Adoption confirmation (ZC_REQ_BABY).
  14422. /// 01f6 <account id>.L <char id>.L <name>.B
  14423. void clif_Adopt_request(map_session_data *sd, map_session_data *src, int p_id)
  14424. {
  14425. int fd = sd->fd;
  14426. WFIFOHEAD(fd,34);
  14427. WFIFOW(fd,0) = 0x1f6;
  14428. WFIFOL(fd,2) = src->status.account_id;
  14429. WFIFOL(fd,6) = p_id;
  14430. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14431. WFIFOSET(fd,34);
  14432. }
  14433. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14434. /// 01f9 <account id>.L
  14435. void clif_parse_Adopt_request(int fd, map_session_data *sd)
  14436. {
  14437. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14438. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14439. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14440. {
  14441. tsd->adopt_invite = sd->status.account_id;
  14442. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14443. }
  14444. }
  14445. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14446. /// 01f7 <account id>.L <char id>.L <answer>.L
  14447. /// answer:
  14448. /// 0 = rejected
  14449. /// 1 = accepted
  14450. void clif_parse_Adopt_reply(int fd, map_session_data *sd){
  14451. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14452. int p1_id = RFIFOL(fd,info->pos[0]);
  14453. int p2_id = RFIFOL(fd,info->pos[1]);
  14454. int result = RFIFOL(fd,info->pos[2]);
  14455. map_session_data* p1_sd = map_id2sd(p1_id);
  14456. map_session_data* p2_sd = map_id2sd(p2_id);
  14457. int pid = sd->adopt_invite;
  14458. sd->adopt_invite = 0;
  14459. if( p1_sd == nullptr || p2_sd == nullptr )
  14460. return; // Both players need to be online
  14461. if( pid != p1_sd->status.account_id )
  14462. return; // Incorrect values
  14463. if( result == 0 )
  14464. return; // Rejected
  14465. pc_adoption(p1_sd, p2_sd, sd);
  14466. }
  14467. /// Convex Mirror
  14468. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B (ZC_BOSS_INFO)
  14469. /// infoType:
  14470. /// BOSS_INFO_NOT = No boss on this map.
  14471. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14472. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14473. /// BOSS_INFO_DEAD = Boss is dead.
  14474. void clif_bossmapinfo( map_session_data& sd, mob_data* md, e_bossmap_info flag ){
  14475. PACKET_ZC_BOSS_INFO p = {};
  14476. p.packetType = HEADER_ZC_BOSS_INFO;
  14477. p.type = flag;
  14478. switch (flag) {
  14479. case BOSS_INFO_NOT:
  14480. // No data required
  14481. break;
  14482. case BOSS_INFO_ALIVE_WITHMSG:
  14483. [[fallthrough]];
  14484. case BOSS_INFO_ALIVE:
  14485. p.x = md->bl.x;
  14486. p.y = md->bl.y;
  14487. break;
  14488. case BOSS_INFO_DEAD: {
  14489. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14490. unsigned int seconds;
  14491. int hours, minutes;
  14492. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14493. hours = seconds / (60 * 60);
  14494. seconds = seconds - (60 * 60 * hours);
  14495. minutes = seconds / 60;
  14496. p.minHours = hours;
  14497. p.minMinutes = minutes;
  14498. break;
  14499. }
  14500. }
  14501. if( md != nullptr ){
  14502. safestrncpy( p.name, md->db->jname.c_str(), sizeof( p.name ) );
  14503. }
  14504. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  14505. }
  14506. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14507. /// 02d6 <account id>.L
  14508. void clif_parse_ViewPlayerEquip(int fd, map_session_data* sd)
  14509. {
  14510. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14511. map_session_data* tsd = map_id2sd(aid);
  14512. if (!tsd)
  14513. return;
  14514. if (sd->bl.m != tsd->bl.m)
  14515. return;
  14516. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14517. clif_viewequip_ack( *sd, *tsd );
  14518. else
  14519. clif_msg(sd, MSI_OPEN_EQUIPEDITEM_REFUSED);
  14520. }
  14521. /// Request to a configuration.
  14522. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14523. /// type: see enum e_config_type
  14524. /// flag:
  14525. /// false = disabled
  14526. /// true = enabled
  14527. void clif_parse_configuration( int fd, map_session_data* sd ){
  14528. int cmd = RFIFOW(fd,0);
  14529. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14530. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14531. switch( type ){
  14532. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14533. sd->status.show_equip = flag;
  14534. break;
  14535. case CONFIG_CALL:
  14536. sd->status.disable_call = flag;
  14537. break;
  14538. case CONFIG_PET_AUTOFEED:
  14539. // Player can not click this if he does not have a pet
  14540. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14541. return;
  14542. }
  14543. sd->pd->pet.autofeed = flag;
  14544. break;
  14545. case CONFIG_HOMUNCULUS_AUTOFEED:
  14546. // Player can not click this if he does not have a homunculus or it is vaporized
  14547. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14548. return;
  14549. }
  14550. sd->hd->homunculus.autofeed = flag;
  14551. break;
  14552. default:
  14553. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14554. return;
  14555. }
  14556. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14557. }
  14558. /// Request to change party invitation tick.
  14559. /// value:
  14560. /// 0 = disabled (triggered by /accept)
  14561. /// 1 = enabled (triggered by /refuse)
  14562. void clif_parse_PartyTick( int fd, map_session_data* sd ){
  14563. PACKET_CZ_PARTY_CONFIG* p = (PACKET_CZ_PARTY_CONFIG*)RFIFOP( fd, 0 );
  14564. sd->status.disable_partyinvite = p->refuseInvite;
  14565. clif_partyinvitationstate( *sd );
  14566. }
  14567. /// Questlog System [Kevin] [Inkfish]
  14568. ///
  14569. /**
  14570. * Safe check to init packet len & quest num for player.
  14571. * @param def_len
  14572. * @param info_len Length of each quest info.
  14573. * @param avail_quests Avail quests that player has.
  14574. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14575. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14576. **/
  14577. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14578. (*limit_out) = (0xFFFF - def_len) / info_len;
  14579. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14580. (*len_out) = ((*limit_out) * info_len) + def_len;
  14581. }
  14582. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14583. std::string race_name;
  14584. switch( objective->race ){
  14585. case RC_FORMLESS: race_name = "Formless"; break;
  14586. case RC_UNDEAD: race_name = "Undead"; break;
  14587. case RC_BRUTE: race_name = "Brute"; break;
  14588. case RC_PLANT: race_name = "Plant"; break;
  14589. case RC_INSECT: race_name = "Insect"; break;
  14590. case RC_FISH: race_name = "Fish"; break;
  14591. case RC_DEMON: race_name = "Demon"; break;
  14592. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14593. case RC_ANGEL: race_name = "Angel"; break;
  14594. case RC_DRAGON: race_name = "Dragon"; break;
  14595. default:
  14596. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14597. [[fallthrough]];
  14598. case RC_ALL: race_name = ""; break;
  14599. }
  14600. std::string size_name;
  14601. switch( objective->size ){
  14602. case SZ_SMALL: size_name = "Small"; break;
  14603. case SZ_MEDIUM: size_name = "Medium"; break;
  14604. case SZ_BIG: size_name = "Large"; break;
  14605. default:
  14606. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14607. [[fallthrough]];
  14608. case SZ_ALL: size_name = ""; break;
  14609. }
  14610. std::string ele_name;
  14611. switch( objective->element ){
  14612. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14613. case ELE_WATER: ele_name = "Water Element"; break;
  14614. case ELE_EARTH: ele_name = "Earth Element"; break;
  14615. case ELE_FIRE: ele_name = "Fire Element"; break;
  14616. case ELE_WIND: ele_name = "Wind Element"; break;
  14617. case ELE_POISON: ele_name = "Poison Element"; break;
  14618. case ELE_HOLY: ele_name = "Holy Element"; break;
  14619. case ELE_DARK: ele_name = "Shadow Element"; break;
  14620. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14621. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14622. default:
  14623. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14624. [[fallthrough]];
  14625. case ELE_ALL: ele_name = ""; break;
  14626. }
  14627. std::string str;
  14628. if( !objective->map_name.empty() ){
  14629. str += objective->map_name;
  14630. }
  14631. if( !race_name.empty() ){
  14632. if( !str.empty() ){
  14633. str += ", ";
  14634. }
  14635. str += race_name;
  14636. }
  14637. if( !size_name.empty() ){
  14638. if( !str.empty() ){
  14639. str += ", ";
  14640. }
  14641. str += size_name;
  14642. }
  14643. if( !ele_name.empty() ){
  14644. if( !str.empty() ){
  14645. str += ", ";
  14646. }
  14647. str += ele_name;
  14648. }
  14649. return str;
  14650. }
  14651. /// Sends list of all quest states
  14652. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14653. /// 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)
  14654. /// 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)
  14655. void clif_quest_send_list(map_session_data *sd)
  14656. {
  14657. nullpo_retv(sd);
  14658. int fd = sd->fd;
  14659. int i;
  14660. int offset = 8;
  14661. int limit = 0;
  14662. #if PACKETVER >= 20141022
  14663. #if PACKETVER >= 20150513
  14664. int size = 22 + NAME_LENGTH;
  14665. #else
  14666. int size = 10 + NAME_LENGTH;
  14667. #endif
  14668. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14669. WFIFOHEAD(fd,i);
  14670. #if PACKETVER >= 20150513
  14671. WFIFOW(fd, 0) = 0x9f8;
  14672. #else
  14673. WFIFOW(fd, 0) = 0x97a;
  14674. #endif
  14675. WFIFOL(fd, 4) = limit;
  14676. for (i = 0; i < limit; i++) {
  14677. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14678. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14679. offset += 4;
  14680. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14681. offset++;
  14682. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14683. offset += 4;
  14684. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14685. offset += 4;
  14686. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14687. offset += 2;
  14688. if (!qi->objectives.empty()) {
  14689. std::shared_ptr<s_mob_db> mob;
  14690. for (int j = 0; j < qi->objectives.size(); j++) {
  14691. mob = mob_db.find(qi->objectives[j]->mob_id);
  14692. e_race race = qi->objectives[j]->race;
  14693. e_size size = qi->objectives[j]->size;
  14694. e_element element = qi->objectives[j]->element;
  14695. #if PACKETVER >= 20150513
  14696. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14697. offset += 4;
  14698. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14699. offset += 4;
  14700. #endif
  14701. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14702. offset += 4;
  14703. #if PACKETVER >= 20150513
  14704. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14705. offset += 2;
  14706. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14707. offset += 2;
  14708. #endif
  14709. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14710. offset += 2;
  14711. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14712. offset += 2;
  14713. if (mob && qi->objectives[j]->mob_id > 0)
  14714. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14715. else
  14716. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14717. offset += NAME_LENGTH;
  14718. }
  14719. }
  14720. }
  14721. WFIFOW(fd, 2) = offset;
  14722. WFIFOSET(fd, offset);
  14723. #else
  14724. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14725. WFIFOHEAD(fd,i);
  14726. WFIFOW(fd, 0) = 0x2b1;
  14727. WFIFOL(fd, 4) = limit;
  14728. for (i = 0; i < limit; i++) {
  14729. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14730. offset += 4;
  14731. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14732. offset += 1;
  14733. }
  14734. WFIFOW(fd, 2) = offset;
  14735. WFIFOSET(fd, offset);
  14736. #endif
  14737. }
  14738. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14739. /// 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
  14740. void clif_quest_send_mission(map_session_data *sd)
  14741. {
  14742. nullpo_retv(sd);
  14743. int fd = sd->fd;
  14744. int limit = 0;
  14745. int len = sd->avail_quests*104+8;
  14746. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14747. WFIFOHEAD(fd, len);
  14748. WFIFOW(fd, 0) = 0x2b2;
  14749. WFIFOW(fd, 2) = len;
  14750. WFIFOL(fd, 4) = limit;
  14751. for (int i = 0; i < limit; i++) {
  14752. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14753. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14754. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14755. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14756. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14757. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14758. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14759. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14760. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14761. if (mob && qi->objectives[j]->mob_id > 0)
  14762. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14763. else
  14764. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14765. }
  14766. }
  14767. WFIFOSET(fd, len);
  14768. }
  14769. /// Notification about a new quest
  14770. /// 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)
  14771. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14772. /// 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)
  14773. void clif_quest_add(map_session_data *sd, struct quest *qd)
  14774. {
  14775. nullpo_retv(sd);
  14776. nullpo_retv(qd);
  14777. int fd = sd->fd;
  14778. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14779. if (!qi)
  14780. return;
  14781. #if PACKETVER >= 20150513
  14782. int cmd = 0x9f9;
  14783. #else
  14784. int cmd = 0x2b3;
  14785. #endif
  14786. WFIFOHEAD(fd, packet_len(cmd));
  14787. WFIFOW(fd, 0) = cmd;
  14788. WFIFOL(fd, 2) = qd->quest_id;
  14789. WFIFOB(fd, 6) = qd->state;
  14790. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14791. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14792. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14793. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14794. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14795. e_race race = qi->objectives[i]->race;
  14796. e_size size = qi->objectives[i]->size;
  14797. e_element element = qi->objectives[i]->element;
  14798. #if PACKETVER >= 20150513
  14799. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14800. offset += 4;
  14801. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14802. offset += 4;
  14803. #endif
  14804. 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
  14805. offset += 4;
  14806. #if PACKETVER >= 20150513
  14807. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14808. offset += 2;
  14809. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14810. offset += 2;
  14811. #endif
  14812. WFIFOW(fd, offset) = qd->count[i];
  14813. offset += 2;
  14814. if (mob && qi->objectives[i]->mob_id > 0)
  14815. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14816. else
  14817. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14818. offset += NAME_LENGTH;
  14819. }
  14820. WFIFOSET(fd, packet_len(cmd));
  14821. #if PACKETVER >= 20150513
  14822. int16 len;
  14823. len = static_cast<decltype(len)>( 4 + qi->objectives.size() * 12 );
  14824. WFIFOHEAD(fd, len);
  14825. WFIFOW(fd, 0) = 0x8fe;
  14826. WFIFOW(fd, 2) = len;
  14827. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14828. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14829. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14830. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14831. WFIFOW(fd, offset + 10) = qd->count[i];
  14832. }
  14833. WFIFOSET(fd, len);
  14834. #endif
  14835. }
  14836. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14837. /// 02b4 <quest id>.L
  14838. void clif_quest_delete(map_session_data *sd, int quest_id)
  14839. {
  14840. int fd = sd->fd;
  14841. WFIFOHEAD(fd, packet_len(0x2b4));
  14842. WFIFOW(fd, 0) = 0x2b4;
  14843. WFIFOL(fd, 2) = quest_id;
  14844. WFIFOSET(fd, packet_len(0x2b4));
  14845. }
  14846. /// Notification of an update to the hunting mission counter
  14847. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14848. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14849. void clif_quest_update_objective(map_session_data *sd, struct quest *qd)
  14850. {
  14851. int fd = sd->fd;
  14852. int offset = 6;
  14853. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14854. int16 len;
  14855. len = static_cast<decltype(len)>( qi->objectives.size() * 12 + 6 );
  14856. #if PACKETVER >= 20150513
  14857. int cmd = 0x9fa;
  14858. #else
  14859. int cmd = 0x2b5;
  14860. #endif
  14861. WFIFOHEAD(fd, len);
  14862. WFIFOW(fd, 0) = cmd;
  14863. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14864. for (int i = 0; i < qi->objectives.size(); i++) {
  14865. WFIFOL(fd, offset) = qd->quest_id;
  14866. offset += 4;
  14867. #if PACKETVER >= 20150513
  14868. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14869. offset += 4;
  14870. #else
  14871. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14872. offset += 4;
  14873. #endif
  14874. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14875. offset += 2;
  14876. WFIFOW(fd, offset) = qd->count[i];
  14877. offset += 2;
  14878. }
  14879. WFIFOW(fd, 2) = offset;
  14880. WFIFOSET(fd, offset);
  14881. }
  14882. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14883. /// 02b6 <quest id>.L <active>.B
  14884. void clif_parse_questStateAck(int fd, map_session_data *sd)
  14885. {
  14886. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14887. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14888. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14889. }
  14890. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14891. /// 02b7 <quest id>.L <active>.B
  14892. void clif_quest_update_status(map_session_data *sd, int quest_id, bool active)
  14893. {
  14894. int fd = sd->fd;
  14895. WFIFOHEAD(fd, packet_len(0x2b7));
  14896. WFIFOW(fd, 0) = 0x2b7;
  14897. WFIFOL(fd, 2) = quest_id;
  14898. WFIFOB(fd, 6) = active;
  14899. WFIFOSET(fd, packet_len(0x2b7));
  14900. }
  14901. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14902. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14903. /// effect:
  14904. /// 0 = none
  14905. /// 1 = exclamation mark icon
  14906. /// 2 = question mark icon
  14907. /// color:
  14908. /// 0 = yellow
  14909. /// 1 = orange
  14910. /// 2 = green
  14911. /// 3 = purple
  14912. void clif_quest_show_event(map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14913. {
  14914. #if PACKETVER >= 20090218
  14915. nullpo_retv(sd);
  14916. nullpo_retv(bl);
  14917. int fd = sd->fd;
  14918. WFIFOHEAD(fd, packet_len(0x446));
  14919. WFIFOW(fd, 0) = 0x446;
  14920. WFIFOL(fd, 2) = bl->id;
  14921. WFIFOW(fd, 6) = bl->x;
  14922. WFIFOW(fd, 8) = bl->y;
  14923. WFIFOW(fd, 10) = effect;
  14924. WFIFOW(fd, 12) = color;
  14925. WFIFOSET(fd, packet_len(0x446));
  14926. #endif
  14927. }
  14928. /// Mercenary System
  14929. ///
  14930. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14931. /// 02a2 <var id>.W <value>.L
  14932. void clif_mercenary_updatestatus(map_session_data *sd, int type)
  14933. {
  14934. s_mercenary_data *md;
  14935. struct status_data *status;
  14936. int fd;
  14937. if( !clif_session_isValid(sd) || (md = sd->md) == nullptr )
  14938. return;
  14939. fd = sd->fd;
  14940. status = &md->battle_status;
  14941. WFIFOHEAD(fd,packet_len(0x2a2));
  14942. WFIFOW(fd,0) = 0x2a2;
  14943. WFIFOW(fd,2) = type;
  14944. switch( type ) {
  14945. case SP_ATK1:
  14946. {
  14947. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14948. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14949. }
  14950. break;
  14951. case SP_MATK1:
  14952. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14953. break;
  14954. case SP_HIT:
  14955. WFIFOL(fd,4) = status->hit;
  14956. break;
  14957. case SP_CRITICAL:
  14958. WFIFOL(fd,4) = status->cri/10;
  14959. break;
  14960. case SP_DEF1:
  14961. WFIFOL(fd,4) = status->def;
  14962. break;
  14963. case SP_MDEF1:
  14964. WFIFOL(fd,4) = status->mdef;
  14965. break;
  14966. case SP_MERCFLEE:
  14967. WFIFOL(fd,4) = status->flee;
  14968. break;
  14969. case SP_ASPD:
  14970. WFIFOL(fd,4) = status->amotion;
  14971. break;
  14972. case SP_HP:
  14973. WFIFOL(fd,4) = status->hp;
  14974. break;
  14975. case SP_MAXHP:
  14976. WFIFOL(fd,4) = status->max_hp;
  14977. break;
  14978. case SP_SP:
  14979. WFIFOL(fd,4) = status->sp;
  14980. break;
  14981. case SP_MAXSP:
  14982. WFIFOL(fd,4) = status->max_sp;
  14983. break;
  14984. case SP_MERCKILLS:
  14985. WFIFOL(fd,4) = md->mercenary.kill_count;
  14986. break;
  14987. case SP_MERCFAITH:
  14988. WFIFOL(fd,4) = mercenary_get_faith(md);
  14989. break;
  14990. }
  14991. WFIFOSET(fd,packet_len(0x2a2));
  14992. }
  14993. /// Mercenary base status data (ZC_MER_INIT).
  14994. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14995. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14996. /// <calls>.L <kills>.L <atk range>.W
  14997. void clif_mercenary_info(map_session_data *sd)
  14998. {
  14999. int fd;
  15000. s_mercenary_data *md;
  15001. struct status_data *status;
  15002. int atk;
  15003. if( !clif_session_isValid(sd) || (md = sd->md) == nullptr )
  15004. return;
  15005. fd = sd->fd;
  15006. status = &md->battle_status;
  15007. WFIFOHEAD(fd,packet_len(0x29b));
  15008. WFIFOW(fd,0) = 0x29b;
  15009. WFIFOL(fd,2) = md->bl.id;
  15010. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15011. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15012. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15013. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15014. WFIFOW(fd,10) = status->hit;
  15015. WFIFOW(fd,12) = status->cri/10;
  15016. WFIFOW(fd,14) = status->def;
  15017. WFIFOW(fd,16) = status->mdef;
  15018. WFIFOW(fd,18) = status->flee;
  15019. WFIFOW(fd,20) = status->amotion;
  15020. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15021. WFIFOW(fd,46) = md->db->lv;
  15022. WFIFOL(fd,48) = status->hp;
  15023. WFIFOL(fd,52) = status->max_hp;
  15024. WFIFOL(fd,56) = status->sp;
  15025. WFIFOL(fd,60) = status->max_sp;
  15026. WFIFOL(fd,64) = client_tick(time(nullptr) + (mercenary_get_lifetime(md) / 1000));
  15027. WFIFOW(fd,68) = mercenary_get_faith(md);
  15028. WFIFOL(fd,70) = mercenary_get_calls(md);
  15029. WFIFOL(fd,74) = md->mercenary.kill_count;
  15030. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15031. WFIFOSET(fd,packet_len(0x29b));
  15032. }
  15033. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15034. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15035. void clif_mercenary_skillblock(map_session_data *sd)
  15036. {
  15037. s_mercenary_data *md;
  15038. int fd, len = 4;
  15039. if( sd == nullptr || (md = sd->md) == nullptr )
  15040. return;
  15041. fd = sd->fd;
  15042. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15043. WFIFOW(fd,0) = 0x29d;
  15044. for (const auto &it : md->db->skill) {
  15045. uint16 id = it.first;
  15046. if (!SKILL_CHK_MERC(id))
  15047. continue;
  15048. uint16 lv = it.second;
  15049. WFIFOW(fd,len) = id;
  15050. WFIFOL(fd,len+2) = skill_get_inf(id);
  15051. WFIFOW(fd,len+6) = lv;
  15052. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15053. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15054. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15055. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15056. len += 37;
  15057. }
  15058. WFIFOW(fd,2) = len;
  15059. WFIFOSET(fd,len);
  15060. }
  15061. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15062. /// 029f <command>.B
  15063. /// 1 = mercenary information
  15064. /// 2 = delete
  15065. void clif_parse_mercenary_action(int fd, map_session_data* sd)
  15066. {
  15067. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15068. if( sd->md == nullptr )
  15069. return;
  15070. if( option == 2 ) mercenary_delete(sd->md, 2);
  15071. }
  15072. /// Notification about the remaining time of a rental item.
  15073. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15074. void clif_rental_time( map_session_data* sd, t_itemid nameid, int seconds ){
  15075. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15076. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15077. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15078. p.itemId = client_nameid( nameid );
  15079. p.seconds = seconds;
  15080. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15081. }
  15082. /// Deletes a rental item from client's inventory.
  15083. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15084. void clif_rental_expired( map_session_data* sd, int index, t_itemid nameid ){
  15085. // '<ItemName>' item has been deleted from the Inventory
  15086. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15087. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15088. p.index = client_index( index );
  15089. p.itemId = client_nameid( nameid );
  15090. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15091. }
  15092. /// Book Reading (ZC_READ_BOOK).
  15093. /// 0294 <book id>.L <page>.L
  15094. void clif_readbook(int fd, int book_id, int page)
  15095. {
  15096. WFIFOHEAD(fd,packet_len(0x294));
  15097. WFIFOW(fd,0) = 0x294;
  15098. WFIFOL(fd,2) = book_id;
  15099. WFIFOL(fd,6) = page;
  15100. WFIFOSET(fd,packet_len(0x294));
  15101. }
  15102. /// Battlegrounds
  15103. ///
  15104. /// Updates HP bar of a camp member.
  15105. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15106. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15107. void clif_bg_hp(map_session_data *sd) {
  15108. #if PACKETVER < 20140613
  15109. unsigned char buf[34];
  15110. const int cmd = 0x2e0;
  15111. #else
  15112. unsigned char buf[14];
  15113. const int cmd = 0xa0e;
  15114. #endif
  15115. nullpo_retv(sd);
  15116. WBUFW(buf,0) = cmd;
  15117. WBUFL(buf,2) = sd->status.account_id;
  15118. #if PACKETVER < 20140613
  15119. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15120. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15121. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15122. WBUFW(buf,32) = 100;
  15123. } else {
  15124. WBUFW(buf,30) = sd->battle_status.hp;
  15125. WBUFW(buf,32) = sd->battle_status.max_hp;
  15126. }
  15127. #else
  15128. if( sd->battle_status.max_hp > INT32_MAX ) {
  15129. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15130. WBUFL(buf,10) = 100;
  15131. } else {
  15132. WBUFL(buf,6) = sd->battle_status.hp;
  15133. WBUFL(buf,10) = sd->battle_status.max_hp;
  15134. }
  15135. #endif
  15136. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15137. }
  15138. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15139. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15140. void clif_bg_xy(map_session_data *sd)
  15141. {
  15142. unsigned char buf[36];
  15143. nullpo_retv(sd);
  15144. WBUFW(buf,0)=0x2df;
  15145. WBUFL(buf,2)=sd->status.account_id;
  15146. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15147. WBUFW(buf,30)=sd->status.class_;
  15148. WBUFW(buf,32)=sd->bl.x;
  15149. WBUFW(buf,34)=sd->bl.y;
  15150. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15151. }
  15152. void clif_bg_xy_remove(map_session_data *sd)
  15153. {
  15154. unsigned char buf[36];
  15155. nullpo_retv(sd);
  15156. WBUFW(buf,0)=0x2df;
  15157. WBUFL(buf,2)=sd->status.account_id;
  15158. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15159. WBUFW(buf,30)=0;
  15160. WBUFW(buf,32)=-1;
  15161. WBUFW(buf,34)=-1;
  15162. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15163. }
  15164. /// Notifies clients of a battleground message.
  15165. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15166. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, size_t len ){
  15167. map_session_data *sd = bg_getavailablesd( bg );
  15168. if( sd == nullptr ){
  15169. return;
  15170. }
  15171. // limit length
  15172. len = zmin( len + 1, CHAT_SIZE_MAX );
  15173. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15174. WBUFW(buf,0) = 0x2dc;
  15175. WBUFW(buf,2) = static_cast<int16>( len + NAME_LENGTH + 8 );
  15176. WBUFL(buf,4) = src_id;
  15177. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15178. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15179. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15180. }
  15181. /// Validates and processes battlechat messages.
  15182. /// All messages that are sent after enabling battleground chat with /battlechat.
  15183. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15184. void clif_parse_BattleChat(int fd, map_session_data* sd){
  15185. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15186. if( !clif_process_message( sd, false, name, message, output ) )
  15187. return;
  15188. bg_send_message(sd, output, strlen(output) );
  15189. }
  15190. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15191. /// 02de <camp A points>.W <camp B points>.W
  15192. void clif_bg_updatescore(int16 m)
  15193. {
  15194. struct block_list bl;
  15195. unsigned char buf[6];
  15196. struct map_data *mapdata = map_getmapdata(m);
  15197. bl.id = 0;
  15198. bl.type = BL_NUL;
  15199. bl.m = m;
  15200. WBUFW(buf,0) = 0x2de;
  15201. WBUFW(buf,2) = mapdata->bgscore_lion;
  15202. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15203. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15204. }
  15205. void clif_bg_updatescore_single(map_session_data *sd)
  15206. {
  15207. int fd;
  15208. nullpo_retv(sd);
  15209. fd = sd->fd;
  15210. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15211. WFIFOHEAD(fd,packet_len(0x2de));
  15212. WFIFOW(fd,0) = 0x2de;
  15213. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15214. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15215. WFIFOSET(fd,packet_len(0x2de));
  15216. }
  15217. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15218. /// 02dd <account id>.L <name>.24B <camp>.W
  15219. void clif_sendbgemblem_area(map_session_data *sd)
  15220. {
  15221. unsigned char buf[33];
  15222. nullpo_retv(sd);
  15223. WBUFW(buf, 0) = 0x2dd;
  15224. WBUFL(buf,2) = sd->bl.id;
  15225. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15226. WBUFW(buf,30) = sd->bg_id;
  15227. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15228. }
  15229. void clif_sendbgemblem_single(int fd, map_session_data *sd)
  15230. {
  15231. nullpo_retv(sd);
  15232. WFIFOHEAD(fd,32);
  15233. WFIFOW(fd,0) = 0x2dd;
  15234. WFIFOL(fd,2) = sd->bl.id;
  15235. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15236. WFIFOW(fd,30) = sd->bg_id;
  15237. WFIFOSET(fd,packet_len(0x2dd));
  15238. }
  15239. /// Battlegrounds queue incoming apply request from client.
  15240. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15241. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15242. void clif_parse_bg_queue_apply_request(int fd, map_session_data *sd)
  15243. {
  15244. if (!battle_config.feature_bgqueue)
  15245. return;
  15246. nullpo_retv(sd);
  15247. short type = RFIFOW(fd,2);
  15248. char name[NAME_LENGTH];
  15249. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15250. if (sd->bg_queue_id > 0) {
  15251. //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);
  15252. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15253. return;
  15254. } else if (type == 1) // Solo
  15255. bg_queue_join_solo(name, sd);
  15256. else if (type == 2) // Party
  15257. bg_queue_join_party(name, sd);
  15258. else if (type == 4) // Guild
  15259. bg_queue_join_guild(name, sd);
  15260. else {
  15261. 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);
  15262. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15263. return;
  15264. }
  15265. }
  15266. /// Outgoing battlegrounds queue apply result.
  15267. /// Result types: @see e_bg_queue_apply_ack
  15268. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15269. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, map_session_data *sd)
  15270. {
  15271. nullpo_retv(sd);
  15272. int fd = sd->fd;
  15273. WFIFOHEAD(fd, packet_len(0x8d8));
  15274. WFIFOW(fd,0) = 0x8d8;
  15275. WFIFOB(fd,2) = result;
  15276. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15277. WFIFOSET(fd, packet_len(0x8d8));
  15278. }
  15279. /// Outgoing battlegrounds queue apply notification.
  15280. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15281. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15282. void clif_bg_queue_apply_notify(const char *name, map_session_data *sd)
  15283. {
  15284. nullpo_retv(sd);
  15285. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15286. if (queue == nullptr) {
  15287. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15288. return;
  15289. }
  15290. int fd = sd->fd;
  15291. WFIFOHEAD(fd, packet_len(0x8d9));
  15292. WFIFOW(fd,0) = 0x8d9;
  15293. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15294. WFIFOL(fd,2+NAME_LENGTH) = static_cast<int32>( queue->teama_members.size() + queue->teamb_members.size() );
  15295. WFIFOSET(fd, packet_len(0x8d9));
  15296. }
  15297. /// Battlegrounds queue outgoing cancel result.
  15298. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15299. void clif_bg_queue_cancel_result(bool success, const char *name, map_session_data *sd)
  15300. {
  15301. nullpo_retv(sd);
  15302. int fd = sd->fd;
  15303. WFIFOHEAD(fd, packet_len(0x8d8));
  15304. WFIFOW(fd,0) = 0x8db;
  15305. WFIFOB(fd,2) = success;
  15306. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15307. WFIFOSET(fd, packet_len(0x8d8));
  15308. }
  15309. /// Battlegrounds queue incoming cancel request from client.
  15310. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15311. void clif_parse_bg_queue_cancel_request(int fd, map_session_data *sd)
  15312. {
  15313. if (!battle_config.feature_bgqueue)
  15314. return;
  15315. nullpo_retv(sd);
  15316. bool success;
  15317. if (sd->bg_queue_id > 0) {
  15318. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15319. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15320. 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.
  15321. else
  15322. success = bg_queue_leave(sd);
  15323. } else {
  15324. 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);
  15325. success = false;
  15326. }
  15327. char name[NAME_LENGTH];
  15328. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15329. clif_bg_queue_cancel_result(success, name, sd);
  15330. }
  15331. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15332. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15333. void clif_bg_queue_lobby_notify(const char *name, map_session_data *sd)
  15334. {
  15335. nullpo_retv(sd);
  15336. int fd = sd->fd;
  15337. WFIFOHEAD(fd, packet_len(0x8df));
  15338. WFIFOW(fd,0) = 0x8df;
  15339. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15340. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15341. WFIFOSET(fd, packet_len(0x8df));
  15342. }
  15343. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15344. /// Result types: 1(Accept), 2(Decline).
  15345. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15346. void clif_parse_bg_queue_lobby_reply(int fd, map_session_data *sd)
  15347. {
  15348. nullpo_retv(sd);
  15349. if(sd->bg_queue_id > 0) {
  15350. uint8 result = RFIFOB(fd, 2);
  15351. if(result == 1) { // Accept
  15352. bg_queue_on_accept_invite(sd);
  15353. } else if(result == 2) { // Decline
  15354. bg_queue_leave(sd);
  15355. clif_bg_queue_entry_init(sd);
  15356. }
  15357. }
  15358. }
  15359. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15360. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15361. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, map_session_data *sd)
  15362. {
  15363. nullpo_retv(sd);
  15364. int fd = sd->fd;
  15365. WFIFOHEAD(fd, packet_len(0x8e1));
  15366. WFIFOW(fd,0) = 0x8e1;
  15367. WFIFOB(fd,2) = result;
  15368. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15369. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15370. WFIFOSET(fd, packet_len(0x8e1));
  15371. }
  15372. /// Battlegrounds queue incoming queue number request from client.
  15373. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15374. void clif_parse_bg_queue_request_queue_number(int fd, map_session_data *sd)
  15375. {
  15376. nullpo_retv(sd);
  15377. char name[NAME_LENGTH];
  15378. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15379. clif_bg_queue_apply_notify(name, sd);
  15380. }
  15381. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15382. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15383. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15384. void clif_bg_queue_entry_init(map_session_data *sd)
  15385. {
  15386. nullpo_retv(sd);
  15387. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15388. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15389. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15390. }
  15391. /// Custom Fonts (ZC_NOTIFY_FONT).
  15392. /// 02ef <account_id>.L <font id>.W
  15393. void clif_font(map_session_data *sd)
  15394. {
  15395. #if PACKETVER >= 20080102
  15396. unsigned char buf[8];
  15397. nullpo_retv(sd);
  15398. WBUFW(buf,0) = 0x2ef;
  15399. WBUFL(buf,2) = sd->bl.id;
  15400. WBUFW(buf,6) = sd->status.font;
  15401. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15402. #endif
  15403. }
  15404. /// Required to start the instancing information window on Client
  15405. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15406. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15407. void clif_instance_create(int instance_id, int num)
  15408. {
  15409. #if PACKETVER >= 20071128
  15410. map_session_data *sd = nullptr;
  15411. enum send_target target = PARTY;
  15412. unsigned char buf[65];
  15413. instance_getsd(instance_id, sd, &target);
  15414. if (!sd)
  15415. return;
  15416. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15417. if (!db)
  15418. return;
  15419. WBUFW(buf,0) = 0x2cb;
  15420. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15421. WBUFW(buf,63) = num;
  15422. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15423. #endif
  15424. return;
  15425. }
  15426. /// To announce Instancing queue creation if no maps available
  15427. /// S 0x2cc <Standby Position>.W
  15428. void clif_instance_changewait(int instance_id, int num)
  15429. {
  15430. #if PACKETVER >= 20071128
  15431. map_session_data *sd = nullptr;
  15432. enum send_target target = PARTY;
  15433. unsigned char buf[4];
  15434. instance_getsd(instance_id, sd, &target);
  15435. if (!sd)
  15436. return;
  15437. WBUFW(buf,0) = 0x2cc;
  15438. WBUFW(buf,2) = num;
  15439. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15440. #endif
  15441. return;
  15442. }
  15443. /// Notify the current status to members
  15444. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15445. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15446. {
  15447. #if PACKETVER >= 20071128
  15448. map_session_data *sd = nullptr;
  15449. enum send_target target = PARTY;
  15450. unsigned char buf[71];
  15451. instance_getsd(instance_id, sd, &target);
  15452. if (!sd)
  15453. return;
  15454. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15455. if (!db)
  15456. return;
  15457. WBUFW(buf,0) = 0x2cd;
  15458. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15459. WBUFL(buf,63) = limit1;
  15460. WBUFL(buf,67) = limit2;
  15461. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15462. #endif
  15463. return;
  15464. }
  15465. /// Notify a status change to members
  15466. /// S 0x2ce <Message ID>.L
  15467. /// 0 = Notification (EnterLimitDate update?)
  15468. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15469. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15470. /// 3 = The Memorial Dungeon has been removed.
  15471. /// 4 = Create failure (removes the instance window)
  15472. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15473. {
  15474. #if PACKETVER >= 20071128
  15475. map_session_data *sd = nullptr;
  15476. enum send_target target = PARTY;
  15477. unsigned char buf[10];
  15478. instance_getsd(instance_id, sd, &target);
  15479. if (!sd)
  15480. return;
  15481. WBUFW(buf,0) = 0x2ce;
  15482. WBUFL(buf,2) = type;
  15483. WBUFL(buf,6) = limit;
  15484. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15485. #endif
  15486. return;
  15487. }
  15488. /// Destroy an instance from the status window
  15489. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15490. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15491. {
  15492. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15493. return;
  15494. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15495. switch (p->command) {
  15496. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15497. instance_destroy_command(sd);
  15498. break;
  15499. }
  15500. }
  15501. void clif_instance_info( map_session_data& sd ){
  15502. if( sd.instance_id > 0 ){
  15503. instance_reqinfo( &sd, sd.instance_id );
  15504. }
  15505. if( sd.status.party_id > 0 ){
  15506. struct party_data* p = party_search( sd.status.party_id );
  15507. if( p != nullptr && p->instance_id > 0 ){
  15508. instance_reqinfo( &sd, p->instance_id );
  15509. }
  15510. }
  15511. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15512. instance_reqinfo( &sd, sd.guild->instance_id );
  15513. }
  15514. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15515. instance_reqinfo( &sd, sd.clan->instance_id );
  15516. }
  15517. }
  15518. /// Notifies clients about item picked up by a party member.
  15519. /// 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)
  15520. void clif_party_show_picker( map_session_data* sd, struct item* item_data ){
  15521. #if PACKETVER >= 20071002
  15522. nullpo_retv( sd );
  15523. nullpo_retv( item_data );
  15524. struct item_data* id = itemdb_search( item_data->nameid );
  15525. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15526. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15527. p.AID = sd->status.account_id;
  15528. p.itemId = client_nameid( item_data->nameid );
  15529. p.identified = item_data->identify;
  15530. p.damaged = item_data->attribute;
  15531. p.refine = item_data->refine;
  15532. clif_addcards( &p.slot, item_data );
  15533. p.location = id->equip; // equip location
  15534. p.itemType = itemtype( id->nameid ); // item type
  15535. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15536. p.grade = item_data->enchantgrade;
  15537. #endif
  15538. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15539. #endif
  15540. }
  15541. /** Display gained exp.
  15542. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15543. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15544. * amount: INT32_MIN ~ INT32_MAX
  15545. * var id:
  15546. * SP_BASEEXP, SP_JOBEXP
  15547. * exp type:
  15548. * 0 = normal exp gained/lost
  15549. * 1 = quest exp gained/lost
  15550. * @param sd Player
  15551. * @param exp EXP value gained/loss
  15552. * @param type SP_BASEEXP, SP_JOBEXP
  15553. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15554. * @param lost True:if losing EXP
  15555. */
  15556. void clif_displayexp(map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15557. {
  15558. int fd;
  15559. int offset;
  15560. #if PACKETVER >= 20170830
  15561. int cmd = 0xacc;
  15562. #else
  15563. int cmd = 0x7f6;
  15564. #endif
  15565. nullpo_retv(sd);
  15566. fd = sd->fd;
  15567. WFIFOHEAD(fd, packet_len(cmd));
  15568. WFIFOW(fd,0) = cmd;
  15569. WFIFOL(fd,2) = sd->bl.id;
  15570. #if PACKETVER >= 20170830
  15571. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15572. offset = 4;
  15573. #else
  15574. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15575. offset = 0;
  15576. #endif
  15577. WFIFOW(fd,10+offset) = type;
  15578. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15579. WFIFOSET(fd,packet_len(cmd));
  15580. }
  15581. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15582. /// type:
  15583. /// 0 = Displays 'value' for 5 seconds.
  15584. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15585. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15586. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15587. /// value:
  15588. /// 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).
  15589. void clif_showdigit(map_session_data* sd, unsigned char type, int value)
  15590. {
  15591. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15592. WFIFOW(sd->fd,0) = 0x1b1;
  15593. WFIFOB(sd->fd,2) = type;
  15594. WFIFOL(sd->fd,3) = value;
  15595. WFIFOSET(sd->fd, packet_len(0x1b1));
  15596. }
  15597. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15598. /// 021d <state>.L
  15599. /// state:
  15600. /// 0 = Full effects
  15601. /// 1 = Reduced effects
  15602. ///
  15603. /// NOTE: The state is used on Aegis for sending skill unit packet
  15604. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15605. /// whenever possible. Due to the way the decision check is
  15606. /// constructed, this state tracking was rendered useless,
  15607. /// as the only skill unit, that is sent with 0x1c9 is
  15608. /// Graffiti.
  15609. void clif_parse_LessEffect(int fd, map_session_data* sd){
  15610. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15611. sd->state.lesseffect = ( isLess != 0 );
  15612. }
  15613. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15614. void clif_parse_ItemListWindowSelected(int fd, map_session_data* sd) {
  15615. if( sd == nullptr ){
  15616. return;
  15617. }
  15618. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15619. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15620. int type = RFIFOL(fd,info->pos[1]);
  15621. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15622. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15623. if( sd->state.trading || sd->npc_shopid )
  15624. return;
  15625. if( flag == 0 || n == 0) {
  15626. clif_menuskill_clear(sd);
  15627. return; // Canceled by player.
  15628. }
  15629. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15630. clif_menuskill_clear(sd);
  15631. return; // Prevent hacking.
  15632. }
  15633. switch( type ) {
  15634. case 0: // Change Material
  15635. skill_changematerial(sd,n,item_list);
  15636. break;
  15637. case 1: // Level 1: Pure to Rough
  15638. case 2: // Level 2: Rough to Pure
  15639. skill_elementalanalysis(*sd,n,type,item_list);
  15640. break;
  15641. }
  15642. clif_menuskill_clear(sd);
  15643. return;
  15644. }
  15645. /*==========================================
  15646. * Elemental System
  15647. *==========================================*/
  15648. void clif_elemental_updatestatus(map_session_data *sd, int type) {
  15649. s_elemental_data *ed;
  15650. struct status_data *status;
  15651. int fd;
  15652. if( !clif_session_isValid(sd) || (ed = sd->ed) == nullptr )
  15653. return;
  15654. fd = sd->fd;
  15655. status = &ed->battle_status;
  15656. WFIFOHEAD(fd,8);
  15657. WFIFOW(fd,0) = 0x81e;
  15658. WFIFOW(fd,2) = type;
  15659. switch( type ) {
  15660. case SP_HP:
  15661. WFIFOL(fd,4) = status->hp;
  15662. break;
  15663. case SP_MAXHP:
  15664. WFIFOL(fd,4) = status->max_hp;
  15665. break;
  15666. case SP_SP:
  15667. WFIFOL(fd,4) = status->sp;
  15668. break;
  15669. case SP_MAXSP:
  15670. WFIFOL(fd,4) = status->max_sp;
  15671. break;
  15672. }
  15673. WFIFOSET(fd,8);
  15674. }
  15675. void clif_elemental_info(map_session_data *sd) {
  15676. int fd;
  15677. s_elemental_data *ed;
  15678. struct status_data *status;
  15679. if( !clif_session_isValid(sd) || (ed = sd->ed) == nullptr )
  15680. return;
  15681. fd = sd->fd;
  15682. status = &ed->battle_status;
  15683. WFIFOHEAD(fd,22);
  15684. WFIFOW(fd, 0) = 0x81d;
  15685. WFIFOL(fd, 2) = ed->bl.id;
  15686. WFIFOL(fd, 6) = status->hp;
  15687. WFIFOL(fd,10) = status->max_hp;
  15688. WFIFOL(fd,14) = status->sp;
  15689. WFIFOL(fd,18) = status->max_sp;
  15690. WFIFOSET(fd,22);
  15691. }
  15692. /// Buying Store System
  15693. ///
  15694. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15695. /// 0810 <slots>.B
  15696. void clif_buyingstore_open(map_session_data* sd)
  15697. {
  15698. int fd = sd->fd;
  15699. WFIFOHEAD(fd,packet_len(0x810));
  15700. WFIFOW(fd,0) = 0x810;
  15701. WFIFOB(fd,2) = sd->buyingstore.slots;
  15702. WFIFOSET(fd,packet_len(0x810));
  15703. }
  15704. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15705. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15706. /// result:
  15707. /// 0 = cancel
  15708. /// 1 = open
  15709. static void clif_parse_ReqOpenBuyingStore( int fd, map_session_data* sd ){
  15710. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15711. // TODO: Make this check global for all variable length packets.
  15712. // minimum packet length
  15713. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15714. 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 );
  15715. return;
  15716. }
  15717. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15718. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15719. return;
  15720. }
  15721. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15722. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15723. return;
  15724. }
  15725. char storename[MESSAGE_SIZE];
  15726. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15727. // so that buyingstore_create knows, how many elements it has access to
  15728. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15729. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15730. 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 ) );
  15731. return;
  15732. }
  15733. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), nullptr );
  15734. }
  15735. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15736. /// 0812 <result>.W <total weight>.L
  15737. /// result:
  15738. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15739. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15740. /// 8 = "No sale (purchase) information available." (0x705)
  15741. /// ? = nothing
  15742. void clif_buyingstore_open_failed(map_session_data* sd, unsigned short result, unsigned int weight)
  15743. {
  15744. int fd = sd->fd;
  15745. WFIFOHEAD(fd,packet_len(0x812));
  15746. WFIFOW(fd,0) = 0x812;
  15747. WFIFOW(fd,2) = result;
  15748. WFIFOL(fd,4) = weight;
  15749. WFIFOSET(fd,packet_len(0x812));
  15750. }
  15751. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15752. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15753. void clif_buyingstore_myitemlist( map_session_data* sd ){
  15754. nullpo_retv( sd );
  15755. int fd = sd->fd;
  15756. if( !session_isActive( fd ) ){
  15757. return;
  15758. }
  15759. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15760. WFIFOHEAD( fd, length );
  15761. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15762. p->packetType = 0x813;
  15763. p->packetLength = length;
  15764. p->AID = sd->bl.id;
  15765. p->zenyLimit = sd->buyingstore.zenylimit;
  15766. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15767. p->items[i].price = sd->buyingstore.items[i].price;
  15768. p->items[i].amount = sd->buyingstore.items[i].amount;
  15769. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15770. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15771. }
  15772. WFIFOSET( fd, p->packetLength );
  15773. }
  15774. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15775. /// 0814 <account id>.L <store name>.80B
  15776. void clif_buyingstore_entry( map_session_data& sd, struct block_list* tbl ){
  15777. #if PACKETVER >= 20100420
  15778. enum send_target target;
  15779. if( tbl == nullptr ){
  15780. tbl = &sd.bl;
  15781. target = AREA_WOS;
  15782. }else{
  15783. target = SELF;
  15784. }
  15785. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15786. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15787. p.makerAID = sd.status.account_id;
  15788. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15789. clif_send( &p, sizeof( p ), tbl, target );
  15790. #endif
  15791. }
  15792. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15793. /// 0815
  15794. static void clif_parse_ReqCloseBuyingStore(int fd, map_session_data* sd)
  15795. {
  15796. buyingstore_close(sd);
  15797. }
  15798. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15799. /// 0816 <account id>.L
  15800. void clif_buyingstore_disappear_entry( map_session_data& sd, struct block_list* tbl ){
  15801. #if PACKETVER >= 20100309
  15802. enum send_target target;
  15803. if( tbl == nullptr ){
  15804. tbl = &sd.bl;
  15805. target = AREA_WOS;
  15806. }else{
  15807. target = SELF;
  15808. }
  15809. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15810. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15811. p.makerAID = sd.status.account_id;
  15812. clif_send( &p, sizeof( p ), tbl, target );
  15813. #endif
  15814. }
  15815. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15816. /// 0817 <account id>.L
  15817. static void clif_parse_ReqClickBuyingStore(int fd, map_session_data* sd)
  15818. {
  15819. uint32 account_id;
  15820. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15821. buyingstore_open(sd, account_id);
  15822. }
  15823. /// Sends buying store item list.
  15824. /// 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)
  15825. void clif_buyingstore_itemlist( map_session_data* sd, map_session_data* pl_sd ){
  15826. nullpo_retv( sd );
  15827. nullpo_retv( pl_sd );
  15828. int fd = sd->fd;
  15829. if( !session_isActive( fd ) ){
  15830. return;
  15831. }
  15832. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15833. WFIFOHEAD( fd, length );
  15834. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15835. p->packetType = 0x818;
  15836. p->packetLength = length;
  15837. p->AID = pl_sd->bl.id;
  15838. p->storeId = pl_sd->buyer_id;
  15839. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15840. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15841. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15842. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15843. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15844. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15845. }
  15846. WFIFOSET( fd, p->packetLength );
  15847. }
  15848. /// Request to sell items to a buying store.
  15849. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15850. static void clif_parse_ReqTradeBuyingStore( int fd, map_session_data* sd ){
  15851. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15852. // minimum packet length
  15853. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15854. 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 );
  15855. return;
  15856. }
  15857. // so that buyingstore_trade knows, how many elements it has access to
  15858. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15859. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15860. 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 ) );
  15861. return;
  15862. }
  15863. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15864. }
  15865. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15866. /// 081a <result>.W
  15867. /// result:
  15868. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15869. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15870. /// ? = nothing
  15871. void clif_buyingstore_trade_failed_buyer(map_session_data* sd, short result)
  15872. {
  15873. int fd = sd->fd;
  15874. WFIFOHEAD(fd,packet_len(0x81a));
  15875. WFIFOW(fd,0) = 0x81a;
  15876. WFIFOW(fd,2) = result;
  15877. WFIFOSET(fd,packet_len(0x81a));
  15878. }
  15879. /// Updates the zeny limit and an item in the buying store item list.
  15880. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15881. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15882. void clif_buyingstore_update_item( map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15883. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15884. p.packetType = buyingStoreUpdateItemType;
  15885. p.itemId = client_nameid( nameid );
  15886. p.amount = amount;
  15887. p.zenyLimit = sd->buyingstore.zenylimit;
  15888. #if PACKETVER >= 20141016
  15889. p.zeny = zeny;
  15890. p.charId = char_id; // GID
  15891. p.updateTime = (int)time(nullptr);
  15892. #endif
  15893. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15894. }
  15895. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15896. /// 081c <index>.W <amount>.W <price>.L
  15897. /// message:
  15898. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15899. ///
  15900. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15901. void clif_buyingstore_delete_item(map_session_data* sd, short index, unsigned short amount, int price)
  15902. {
  15903. int fd = sd->fd;
  15904. WFIFOHEAD(fd,packet_len(0x81c));
  15905. WFIFOW(fd,0) = 0x81c;
  15906. WFIFOW(fd,2) = client_index( index );
  15907. WFIFOW(fd,4) = amount;
  15908. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15909. WFIFOSET(fd,packet_len(0x81c));
  15910. }
  15911. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15912. /// 0824 <result>.W <name id>.W
  15913. /// result:
  15914. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15915. /// 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)
  15916. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15917. /// ? = nothing
  15918. void clif_buyingstore_trade_failed_seller( map_session_data* sd, short result, t_itemid nameid ){
  15919. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15920. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15921. p.result = result;
  15922. p.itemId = client_nameid( nameid );
  15923. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15924. }
  15925. /// Search Store Info System
  15926. ///
  15927. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15928. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15929. /// type:
  15930. /// 0 = Vending
  15931. /// 1 = Buying Store
  15932. ///
  15933. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15934. /// amount of card slots. If the client does not know about the item it
  15935. /// cannot be searched.
  15936. static void clif_parse_SearchStoreInfo( int fd, map_session_data *sd ){
  15937. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15938. // minimum packet length
  15939. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15940. 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 );
  15941. return;
  15942. }
  15943. // check, if there is enough data for the claimed count of items
  15944. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15945. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15946. 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 ) );
  15947. return;
  15948. }
  15949. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15950. if( count < p->itemsCount + p->cardsCount ){
  15951. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15952. return;
  15953. }
  15954. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15955. }
  15956. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15957. /// 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 }*
  15958. /// is first page:
  15959. /// 0 = appends to existing results
  15960. /// 1 = clears previous results before displaying this result set
  15961. /// is next page:
  15962. /// 0 = no "next" label
  15963. /// 1 = "next" label to retrieve more results
  15964. void clif_search_store_info_ack( map_session_data* sd ){
  15965. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  15966. nullpo_retv( sd );
  15967. int fd = sd->fd;
  15968. if( !session_isActive( fd ) ){
  15969. return;
  15970. }
  15971. uint32 start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15972. uint32 end = umin( static_cast<uint32>( sd->searchstore.items.size() ), start + SEARCHSTORE_RESULTS_PER_PAGE );
  15973. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15974. WFIFOHEAD( fd, len );
  15975. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15976. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15977. p->packetLength = len;
  15978. p->firstPage = !sd->searchstore.pages;
  15979. p->nextPage = searchstore_querynext( sd );
  15980. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15981. for( int i = 0; i < end - start; i++ ) {
  15982. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  15983. p->items[i].storeId = ssitem->store_id;
  15984. p->items[i].AID = ssitem->account_id;
  15985. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15986. p->items[i].itemId = client_nameid( ssitem->nameid );
  15987. p->items[i].itemType = itemtype( ssitem->nameid );
  15988. p->items[i].price = ssitem->price;
  15989. p->items[i].amount = ssitem->amount;
  15990. p->items[i].refine = ssitem->refine;
  15991. // make-up an item for clif_addcards
  15992. struct item it = {};
  15993. for( int j = 0; j < MAX_SLOTS; j++ ){
  15994. it.card[j] = ssitem->card[j];
  15995. }
  15996. it.nameid = ssitem->nameid;
  15997. it.amount = ssitem->amount;
  15998. clif_addcards( &p->items[i].slot, &it );
  15999. #if PACKETVER >= 20150226
  16000. clif_add_random_options( p->items[i].option_data, it );
  16001. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16002. p->items[i].grade = ssitem->enchantgrade;
  16003. #endif
  16004. #endif
  16005. }
  16006. WFIFOSET( fd, len );
  16007. #endif
  16008. }
  16009. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16010. /// 0837 <reason>.B
  16011. /// reason:
  16012. /// 0 = "No matching stores were found." (0x70b)
  16013. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16014. /// 2 = "You cannot search anymore." (0x706)
  16015. /// 3 = "You cannot search yet." (0x708)
  16016. /// 4 = "No sale (purchase) information available." (0x705)
  16017. void clif_search_store_info_failed(map_session_data* sd, unsigned char reason)
  16018. {
  16019. int fd = sd->fd;
  16020. WFIFOHEAD(fd,packet_len(0x837));
  16021. WFIFOW(fd,0) = 0x837;
  16022. WFIFOB(fd,2) = reason;
  16023. WFIFOSET(fd,packet_len(0x837));
  16024. }
  16025. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16026. /// 0838
  16027. static void clif_parse_SearchStoreInfoNextPage(int fd, map_session_data* sd)
  16028. {
  16029. searchstore_next(sd);
  16030. }
  16031. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16032. /// 083a <type>.W <remaining uses>.B
  16033. /// type:
  16034. /// 0 = Search Stores
  16035. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16036. void clif_open_search_store_info(map_session_data* sd)
  16037. {
  16038. int fd = sd->fd;
  16039. WFIFOHEAD(fd,packet_len(0x83a));
  16040. WFIFOW(fd,0) = 0x83a;
  16041. WFIFOW(fd,2) = sd->searchstore.effect;
  16042. #if PACKETVER > 20100701
  16043. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16044. #endif
  16045. WFIFOSET(fd,packet_len(0x83a));
  16046. }
  16047. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16048. /// 083b
  16049. static void clif_parse_CloseSearchStoreInfo(int fd, map_session_data* sd)
  16050. {
  16051. searchstore_close(sd);
  16052. }
  16053. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16054. /// 083c <account id>.L <store id>.L <nameid>.W
  16055. static void clif_parse_SearchStoreInfoListItemClick( int fd, map_session_data* sd ){
  16056. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16057. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16058. }
  16059. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16060. /// 083d <xPos>.W <yPos>.W
  16061. void clif_search_store_info_click_ack(map_session_data* sd, short x, short y)
  16062. {
  16063. int fd = sd->fd;
  16064. WFIFOHEAD(fd,packet_len(0x83d));
  16065. WFIFOW(fd,0) = 0x83d;
  16066. WFIFOW(fd,2) = x;
  16067. WFIFOW(fd,4) = y;
  16068. WFIFOSET(fd,packet_len(0x83d));
  16069. }
  16070. /// Parse function for packet debugging.
  16071. void clif_parse_debug(int fd,map_session_data *sd)
  16072. {
  16073. int16 packet_len;
  16074. // clif_parse ensures, that there is at least 2 bytes of data
  16075. uint16 cmd = RFIFOW(fd,0);
  16076. if( sd ) {
  16077. packet_len = packet_db[cmd].len;
  16078. if( packet_len == 0 )
  16079. {// unknown
  16080. packet_len = static_cast<decltype(packet_len)>( RFIFOREST(fd) );
  16081. }
  16082. else if( packet_len == -1 )
  16083. {// variable length
  16084. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16085. }
  16086. ShowDebug("Packet debug of 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  16087. }
  16088. else
  16089. {
  16090. packet_len = static_cast<decltype(packet_len)>( RFIFOREST(fd) );
  16091. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16092. }
  16093. ShowDump(RFIFOP(fd,0), packet_len);
  16094. }
  16095. /*==========================================
  16096. * Server tells client to display a window similar to Magnifier (item) one
  16097. * Server populates the window with avilable elemental converter options according to player's inventory
  16098. *------------------------------------------*/
  16099. void clif_elementalconverter_list( map_session_data& sd ){
  16100. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16101. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16102. p->packetLength = sizeof( *p );
  16103. int count = 0;
  16104. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16105. if( skill_can_produce_mix( &sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16106. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16107. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16108. count++;
  16109. }
  16110. }
  16111. clif_send( p, p->packetLength, &sd.bl, SELF );
  16112. if( count > 0 ){
  16113. sd.menuskill_id = SA_CREATECON;
  16114. sd.menuskill_val = count;
  16115. }
  16116. }
  16117. /**
  16118. * Rune Knight
  16119. **/
  16120. void clif_millenniumshield(struct block_list *bl, short shields) {
  16121. #if PACKETVER >= 20081217
  16122. unsigned char buf[10];
  16123. WBUFW(buf,0) = 0x440;
  16124. WBUFL(buf,2) = bl->id;
  16125. WBUFW(buf,6) = shields;
  16126. WBUFW(buf,8) = 0;
  16127. clif_send(buf,packet_len(0x440),bl,AREA);
  16128. #endif
  16129. }
  16130. /**
  16131. * Mechanic
  16132. **/
  16133. /*==========================================
  16134. * Magic Decoy Material List
  16135. *------------------------------------------*/
  16136. void clif_magicdecoy_list( map_session_data& sd, uint16 skill_lv, short x, short y ){
  16137. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16138. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16139. p->packetLength = sizeof( *p );
  16140. size_t count = 0;
  16141. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16142. if( itemdb_group.item_exists( IG_ELEMENT, sd.inventory.u.items_inventory[i].nameid ) ){
  16143. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16144. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16145. count++;
  16146. }
  16147. }
  16148. if( count > 0 ){
  16149. clif_send( p, p->packetLength, &sd.bl, SELF );
  16150. sd.menuskill_id = NC_MAGICDECOY;
  16151. sd.menuskill_val = skill_lv;
  16152. sd.sc.comet_x = x;
  16153. sd.sc.comet_y = y;
  16154. }else{
  16155. clif_skill_fail( sd, NC_MAGICDECOY );
  16156. }
  16157. }
  16158. /*==========================================
  16159. * Guillotine Cross Poisons List
  16160. *------------------------------------------*/
  16161. void clif_poison_list( map_session_data& sd, uint16 skill_lv ){
  16162. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16163. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16164. p->packetLength = sizeof( *p );
  16165. size_t count = 0;
  16166. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16167. if( itemdb_group.item_exists( IG_POISON, sd.inventory.u.items_inventory[i].nameid ) ){
  16168. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16169. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16170. count++;
  16171. }
  16172. }
  16173. if( count > 0 ){
  16174. clif_send( p, p->packetLength, &sd.bl, SELF );
  16175. sd.menuskill_id = GC_POISONINGWEAPON;
  16176. sd.menuskill_val = skill_lv;
  16177. }else{
  16178. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON );
  16179. }
  16180. }
  16181. /// 0442 <Length>.W <why>.L { <Skill_Id>.W }* (ZC_SKILL_SELECT_REQUEST).
  16182. void clif_autoshadowspell_list( map_session_data& sd ){
  16183. #if PACKETVER >= 20081210
  16184. if( sd.menuskill_id == SC_AUTOSHADOWSPELL )
  16185. return;
  16186. PACKET_ZC_SKILL_SELECT_REQUEST* p = reinterpret_cast<PACKET_ZC_SKILL_SELECT_REQUEST*>( packet_buffer );
  16187. p->packetType = HEADER_ZC_SKILL_SELECT_REQUEST;
  16188. p->packetLength = sizeof( *p );
  16189. p->flag = 1; // enum PACKET_ZC_SKILL_SELECT_REQUEST::enumWHY::WHY_SC_AUTOSHADOWSPELL = 0x1
  16190. size_t count = 0;
  16191. for( size_t i = 0; i < MAX_SKILL; i++ ){
  16192. if( sd.status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd.status.skill[i].id > 0 &&
  16193. skill_get_inf2(sd.status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16194. {
  16195. p->skillIds[count] = sd.status.skill[i].id;
  16196. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->skillIds[0] ) );
  16197. count++;
  16198. }
  16199. }
  16200. if( count > 0 ) {
  16201. clif_send( p, p->packetLength, &sd.bl, SELF );
  16202. sd.menuskill_id = SC_AUTOSHADOWSPELL;
  16203. sd.menuskill_val = static_cast<decltype(sd.menuskill_val)>( count );
  16204. } else {
  16205. status_change_end( &sd.bl, SC_STOP );
  16206. clif_skill_fail( sd, SC_AUTOSHADOWSPELL, USESKILL_FAIL_IMITATION_SKILL_NONE );
  16207. }
  16208. #endif
  16209. }
  16210. /*===========================================
  16211. * Skill list for Four Elemental Analysis
  16212. * and Change Material skills.
  16213. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16214. *------------------------------------------*/
  16215. int clif_skill_itemlistwindow( map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16216. #if PACKETVER >= 20090922
  16217. int fd = sd->fd;
  16218. nullpo_ret(sd);
  16219. sd->menuskill_id = skill_id; // To prevent hacking.
  16220. sd->menuskill_val = skill_lv;
  16221. if( skill_id == GN_CHANGEMATERIAL )
  16222. skill_lv = 0; // Changematerial
  16223. WFIFOHEAD(fd, packet_len(0x7e3));
  16224. WFIFOW(fd,0) = 0x7e3;
  16225. WFIFOL(fd,2) = skill_lv;
  16226. WFIFOL(fd,4) = 0;
  16227. WFIFOSET(fd, packet_len(0x7e3));
  16228. #endif
  16229. return 1;
  16230. }
  16231. /*==========================================
  16232. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16233. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16234. *------------------------------------------*/
  16235. void clif_parse_SkillSelectMenu(int fd, map_session_data *sd) {
  16236. #if PACKETVER >= 20081210
  16237. if( sd == nullptr ){
  16238. return;
  16239. }
  16240. PACKET_CZ_SKILL_SELECT_RESPONSE* p = reinterpret_cast<PACKET_CZ_SKILL_SELECT_RESPONSE*>( RFIFOP( fd, 0 ) );
  16241. if (sd->menuskill_id == SA_AUTOSPELL) {
  16242. sd->state.workinprogress = WIP_DISABLE_NONE;
  16243. skill_autospell(sd, p->selectedSkillId);
  16244. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16245. if (pc_istrading(sd)) {
  16246. clif_skill_fail( *sd, sd->ud.skill_id );
  16247. clif_menuskill_clear(sd);
  16248. return;
  16249. }
  16250. skill_select_menu(*sd, p->selectedSkillId);
  16251. } else
  16252. return;
  16253. clif_menuskill_clear(sd);
  16254. #endif
  16255. }
  16256. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16257. /// 08cf <id>.L <type>.W <num>.W
  16258. void clif_spiritcharm(map_session_data *sd) {
  16259. unsigned char buf[10];
  16260. nullpo_retv(sd);
  16261. WBUFW(buf,0) = 0x08cf;
  16262. WBUFL(buf,2) = sd->bl.id;
  16263. WBUFW(buf,6) = sd->spiritcharm_type;
  16264. WBUFW(buf,8) = sd->spiritcharm;
  16265. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16266. }
  16267. /// Move Item from or to Personal Tab
  16268. /// 0907 <index>.W <type>.B (CZ_INVENTORY_TAB)
  16269. /// type:
  16270. /// 0 = move item to personal tab
  16271. /// 1 = move item to normal tab
  16272. void clif_parse_MoveItem( int fd, map_session_data* sd ){
  16273. // TODO: Check for correct packet version
  16274. #if PACKETVER >= 20120410
  16275. /* can't move while dead. */
  16276. if(pc_isdead(sd)) {
  16277. return;
  16278. }
  16279. PACKET_CZ_INVENTORY_TAB* p = (PACKET_CZ_INVENTORY_TAB*)RFIFOP( fd, 0 );
  16280. uint16 index = server_index( p->index );
  16281. if( index >= MAX_INVENTORY ){
  16282. return;
  16283. }
  16284. if ( sd->inventory.u.items_inventory[index].favorite != 0 && p->favorite == true )
  16285. sd->inventory.u.items_inventory[index].favorite = 0;
  16286. else if( p->favorite == false )
  16287. sd->inventory.u.items_inventory[index].favorite = 1;
  16288. else
  16289. return;/* nothing to do. */
  16290. clif_favorite_item( *sd, index );
  16291. #endif
  16292. }
  16293. /// Items that are in favorite tab of inventory.
  16294. /// 0908 <index>.W <favorite>.B (ZC_INVENTORY_TAB)
  16295. static void clif_favorite_item( map_session_data& sd, uint16 index ){
  16296. // TODO: Check for correct packet version
  16297. #if PACKETVER >= 20111122
  16298. PACKET_ZC_INVENTORY_TAB p = {};
  16299. p.packetType = HEADER_ZC_INVENTORY_TAB;
  16300. p.index = client_index( index );
  16301. p.favorite = ( sd.inventory.u.items_inventory[index].favorite == 1 ) ? false : true;
  16302. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16303. #endif
  16304. }
  16305. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16306. void clif_snap( struct block_list *bl, short x, short y ) {
  16307. unsigned char buf[10];
  16308. WBUFW(buf,0) = 0x8d2;
  16309. WBUFL(buf,2) = bl->id;
  16310. WBUFW(buf,6) = x;
  16311. WBUFW(buf,8) = y;
  16312. if( disguised(bl) )
  16313. {
  16314. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16315. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16316. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16317. } else
  16318. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16319. }
  16320. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16321. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16322. #if PACKETVER >= 20120404
  16323. WFIFOHEAD(fd,packet_len(0x977));
  16324. WFIFOW(fd,0) = 0x977;
  16325. WFIFOL(fd,2) = md->bl.id;
  16326. WFIFOL(fd,6) = md->status.hp;
  16327. WFIFOL(fd,10) = md->status.max_hp;
  16328. WFIFOSET(fd,packet_len(0x977));
  16329. #endif
  16330. }
  16331. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16332. void __attribute__ ((unused)) clif_parse_dull(int fd, map_session_data *sd) {
  16333. return;
  16334. }
  16335. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16336. /// 0979 <world name>.24B <char name>.24B
  16337. void clif_ackworldinfo(map_session_data* sd) {
  16338. int fd;
  16339. nullpo_retv(sd);
  16340. fd = sd->fd;
  16341. WFIFOHEAD(fd,packet_len(0x979));
  16342. WFIFOW(fd,0)=0x979;
  16343. //AID -> world name ?
  16344. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16345. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16346. WFIFOSET(fd,packet_len(0x979));
  16347. }
  16348. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16349. /// 0978 <AID>.L
  16350. void clif_parse_reqworldinfo(int fd,map_session_data *sd) {
  16351. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16352. if(sd)
  16353. clif_ackworldinfo(sd);
  16354. }
  16355. static void clif_loadConfirm( map_session_data *sd ){
  16356. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16357. nullpo_retv( sd );
  16358. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16359. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16360. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16361. clif_instance_info( *sd );
  16362. #endif
  16363. }
  16364. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16365. /// 0447
  16366. void clif_parse_blocking_playcancel( int fd, map_session_data *sd ){
  16367. clif_loadConfirm( sd );
  16368. }
  16369. /// req world info (CZ_CLIENT_VERSION)
  16370. /// 044A <version>.L
  16371. void clif_parse_client_version(int fd, map_session_data *sd) {
  16372. //if(sd)
  16373. ;
  16374. }
  16375. /// Ranking list
  16376. /// ranking pointlist { <name>.24B <point>.L }*10
  16377. void clif_sub_ranklist(unsigned char *buf,int idx,map_session_data* sd, enum e_rank rankingtype){
  16378. struct fame_list* list;
  16379. int i, size = MAX_FAME_LIST;
  16380. switch(rankingtype) {
  16381. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16382. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16383. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16384. // PK currently unsupported
  16385. case RANK_KILLER: list = nullptr; size = 0; break;
  16386. default:
  16387. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16388. return;
  16389. }
  16390. //Packet size limits this list to 10 elements. [Skotlex]
  16391. for (i = 0; i < min(10,size); i++) {
  16392. if (list[i].id > 0) {
  16393. const char* name;
  16394. if (strcmp(list[i].name, "-") == 0 &&
  16395. (name = map_charid2nick(list[i].id)) != nullptr)
  16396. {
  16397. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16398. } else {
  16399. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16400. }
  16401. } else {
  16402. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16403. }
  16404. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16405. }
  16406. for(;i < 10; i++) { //In case the MAX is less than 10.
  16407. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16408. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16409. }
  16410. }
  16411. /// Request for the blacksmith ranklist.
  16412. /// /blacksmith command sends this packet to the server.
  16413. /// 0217 (CZ_BLACKSMITH_RANK)
  16414. void clif_parse_Blacksmith( int fd, map_session_data *sd ){
  16415. clif_ranklist(sd,RANK_BLACKSMITH);
  16416. }
  16417. /// Request for the alchemist ranklist.
  16418. /// /alchemist command sends this packet to the server.
  16419. /// 0218 (CZ_ALCHEMIST_RANK)
  16420. void clif_parse_Alchemist( int fd, map_session_data *sd ){
  16421. clif_ranklist(sd,RANK_ALCHEMIST);
  16422. }
  16423. /// Request for the taekwon ranklist.
  16424. /// /taekwon command sends this packet to the server.
  16425. /// 0225 (CZ_TAEKWON_RANK)
  16426. void clif_parse_Taekwon( int fd, map_session_data *sd ){
  16427. clif_ranklist(sd,RANK_TAEKWON);
  16428. }
  16429. /// Request for the killer ranklist.
  16430. /// /pk command sends this packet to the server.
  16431. /// 0237 (CZ_KILLER_RANK)
  16432. void clif_parse_RankingPk( int fd, map_session_data *sd ){
  16433. clif_ranklist(sd,RANK_KILLER);
  16434. }
  16435. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16436. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16437. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16438. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16439. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16440. void clif_ranklist(map_session_data *sd, int16 rankingType) {
  16441. enum e_rank rank;
  16442. #if PACKETVER < 20130710
  16443. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16444. short cmd;
  16445. switch( rankingType ){
  16446. case RANK_BLACKSMITH: cmd = 0x219; break;
  16447. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16448. case RANK_TAEKWON: cmd = 0x226; break;
  16449. case RANK_KILLER: cmd = 0x238; break;
  16450. default:
  16451. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16452. return;
  16453. }
  16454. // Can be safely casted here, since we validated it before
  16455. rank = (enum e_rank)rankingType;
  16456. WBUFW(buf,0) = cmd;
  16457. clif_sub_ranklist(buf,2,sd,rank);
  16458. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16459. #else
  16460. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16461. int mypoint = 0;
  16462. switch( rankingType ){
  16463. case RANK_BLACKSMITH:
  16464. case RANK_ALCHEMIST:
  16465. case RANK_TAEKWON:
  16466. case RANK_KILLER:
  16467. break;
  16468. default:
  16469. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16470. return;
  16471. }
  16472. // Can be safely casted here, since we validated it before
  16473. rank = (enum e_rank)rankingType;
  16474. WBUFW(buf,0) = 0x97d;
  16475. WBUFW(buf,2) = rank;
  16476. clif_sub_ranklist(buf,4,sd,rank);
  16477. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16478. case MAPID_BLACKSMITH:
  16479. case MAPID_ALCHEMIST:
  16480. case MAPID_TAEKWON:
  16481. mypoint = sd->status.fame;
  16482. }
  16483. WBUFL(buf,284) = mypoint; //mypoint
  16484. clif_send(buf, 288, &sd->bl, SELF);
  16485. #endif
  16486. }
  16487. /*
  16488. * 097c <type> (CZ_REQ_RANKING)
  16489. * type
  16490. * 0: /blacksmith
  16491. * 1: /alchemist
  16492. * 2: /taekwon
  16493. * 3: /pk
  16494. * */
  16495. void clif_parse_ranklist(int fd,map_session_data *sd) {
  16496. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16497. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16498. clif_ranklist(sd,rankingtype);
  16499. }
  16500. /// Updates the fame rank points for the given ranking.
  16501. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16502. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16503. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16504. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16505. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16506. int fd = sd.fd;
  16507. #if PACKETVER < 20130710
  16508. short cmd;
  16509. switch(rankingtype){
  16510. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16511. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16512. case RANK_TAEKWON: cmd = 0x224; break;
  16513. default:
  16514. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16515. return;
  16516. }
  16517. WFIFOHEAD(fd,packet_len(cmd));
  16518. WFIFOW(fd,0) = cmd;
  16519. WFIFOL(fd,2) = point;
  16520. WFIFOL(fd,6) = sd.status.fame;
  16521. WFIFOSET(fd, packet_len(cmd));
  16522. #else
  16523. WFIFOHEAD(fd,packet_len(0x97e));
  16524. WFIFOW(fd,0) = 0x97e;
  16525. WFIFOW(fd,2) = rankingtype;
  16526. WFIFOL(fd,4) = point;
  16527. WFIFOL(fd,8) = sd.status.fame;
  16528. WFIFOSET(fd,packet_len(0x97e));
  16529. #endif
  16530. }
  16531. /**
  16532. * Transmit personal information to player. (rates)
  16533. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16534. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16535. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16536. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16537. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16538. * FIXME!
  16539. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16540. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16541. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16542. */
  16543. #ifdef VIP_ENABLE
  16544. void clif_display_pinfo( map_session_data& sd ){
  16545. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16546. // 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]
  16547. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16548. /**
  16549. * EXP
  16550. */
  16551. //0:PCRoom
  16552. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16553. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16554. details_bexp[PINFO_BASIC] = 0;
  16555. else {
  16556. if (details_bexp[PINFO_BASIC] < 100) {
  16557. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16558. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16559. } else
  16560. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16561. }
  16562. //1:Premium
  16563. if( pc_isvip( &sd ) ){
  16564. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16565. if (details_bexp[PINFO_PREMIUM] < 0)
  16566. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16567. } else
  16568. details_bexp[PINFO_PREMIUM] = 0;
  16569. //2:Server
  16570. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16571. if (details_bexp[PINFO_SERVER] == 100)
  16572. details_bexp[PINFO_SERVER] = 0;
  16573. else {
  16574. if (details_bexp[PINFO_SERVER] < 100) {
  16575. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16576. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16577. } else
  16578. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16579. }
  16580. //3:TPLUS
  16581. details_bexp[PINFO_CAFE] = 0;
  16582. /**
  16583. * Drop rate
  16584. */
  16585. //0:PCRoom
  16586. details_drop[PINFO_BASIC] = 0;
  16587. //1:Premium
  16588. if( pc_isvip( &sd ) ){
  16589. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16590. if (details_drop[PINFO_PREMIUM] < 0)
  16591. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16592. } else
  16593. details_drop[PINFO_PREMIUM] = 0;
  16594. //2:Server
  16595. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16596. if (details_drop[PINFO_SERVER] == 100)
  16597. details_drop[PINFO_SERVER] = 0;
  16598. else {
  16599. if (details_drop[PINFO_SERVER] < 100) {
  16600. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16601. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16602. } else
  16603. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16604. }
  16605. //3:TPLUS
  16606. details_drop[PINFO_CAFE] = 0;
  16607. /**
  16608. * Penalty rate
  16609. */
  16610. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16611. //0:PCRoom
  16612. details_penalty[PINFO_BASIC] = 0;
  16613. //1:Premium
  16614. if( pc_isvip( &sd ) ){
  16615. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16616. if (details_penalty[PINFO_PREMIUM] == 100)
  16617. details_penalty[PINFO_PREMIUM] = 0;
  16618. else {
  16619. if (details_penalty[PINFO_PREMIUM] < 100) {
  16620. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16621. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16622. } else
  16623. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16624. }
  16625. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16626. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16627. } else
  16628. details_penalty[PINFO_PREMIUM] = 0;
  16629. //2:Server
  16630. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16631. if (details_penalty[PINFO_SERVER] == 100)
  16632. details_penalty[PINFO_SERVER] = 0;
  16633. else {
  16634. if (details_penalty[PINFO_SERVER] < 100) {
  16635. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16636. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16637. } else
  16638. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16639. }
  16640. //3:TPLUS
  16641. details_penalty[PINFO_CAFE] = 0;
  16642. PACKET_ZC_PERSONAL_INFOMATION* p = reinterpret_cast<PACKET_ZC_PERSONAL_INFOMATION*>( packet_buffer );
  16643. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16644. p->length = sizeof( *p );
  16645. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16646. p->total_exp = 100 * 1000;
  16647. p->total_death = 100 * 1000;
  16648. p->total_drop = 100 * 1000;
  16649. #else
  16650. p->total_exp = 100;
  16651. p->total_death = 100;
  16652. p->total_drop = 100;
  16653. #endif
  16654. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16655. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16656. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16657. p->details[i].exp = details_bexp[i] * 1000;
  16658. p->details[i].death = details_penalty[i] * 1000;
  16659. p->details[i].drop = details_drop[i] * 1000;
  16660. #else
  16661. p->details[i].exp = details_bexp[i];
  16662. p->details[i].death = details_penalty[i];
  16663. p->details[i].drop = details_drop[i];
  16664. #endif
  16665. p->total_exp += p->details[i].exp;
  16666. p->total_death += p->details[i].death;
  16667. p->total_drop += p->details[i].drop;
  16668. p->length += static_cast<decltype(p->length)>( sizeof( p->details[0] ) );
  16669. }
  16670. clif_send( p, p->length, &sd.bl, SELF );
  16671. #endif
  16672. }
  16673. #endif
  16674. void clif_parse_GMFullStrip(int fd, map_session_data *sd) {
  16675. char cmd[30];
  16676. int t_aid = RFIFOL(fd,2);
  16677. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16678. is_atcommand(fd, sd, cmd, 1);
  16679. }
  16680. /**
  16681. * Marks Crimson Marker target on mini-map to the caster
  16682. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16683. * @param fd
  16684. * @param bl Crimson Marker target
  16685. **/
  16686. void clif_crimson_marker( map_session_data& sd, struct block_list& bl, bool remove ){
  16687. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16688. struct PACKET_ZC_C_MARKERINFO p = {};
  16689. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16690. p.AID = bl.id;
  16691. if( remove ){
  16692. p.xPos = -1;
  16693. p.yPos = -1;
  16694. }else{
  16695. p.xPos = bl.x;
  16696. p.yPos = bl.y;
  16697. }
  16698. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16699. #endif
  16700. }
  16701. /**
  16702. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16703. **/
  16704. void clif_notify_bindOnEquip( map_session_data& sd, int16 index ){
  16705. #if PACKETVER >= 20070227
  16706. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16707. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16708. p.index = client_index( index );
  16709. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16710. #endif
  16711. }
  16712. /**
  16713. * [Ind/Hercules]
  16714. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16715. **/
  16716. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16717. char buf[256];
  16718. size_t len;
  16719. nullpo_retv(bl);
  16720. if(!message)
  16721. return;
  16722. len = strlen(message)+1;
  16723. if( len > sizeof(buf)-8 ) {
  16724. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16725. len = sizeof(buf)-8;
  16726. }
  16727. WBUFW(buf,0) = 0x8b3;
  16728. WBUFW(buf,2) = (uint16)(len+8);
  16729. WBUFL(buf,4) = bl->id;
  16730. safestrncpy(WBUFCP(buf,8), message, len);
  16731. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16732. }
  16733. /**
  16734. * [Ind/Hercules]
  16735. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16736. **/
  16737. void clif_party_leaderchanged(map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16738. unsigned char buf[10];
  16739. nullpo_retv(sd);
  16740. WBUFW(buf,0) = 0x7fc;
  16741. WBUFL(buf,2) = prev_leader_aid;
  16742. WBUFL(buf,6) = new_leader_aid;
  16743. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16744. }
  16745. /**
  16746. * Sends a clan message to a player
  16747. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16748. **/
  16749. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16750. #if PACKETVER >= 20131223
  16751. map_session_data *sd;
  16752. uint8 buf[256];
  16753. if( len == 0 ){
  16754. return;
  16755. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16756. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16757. len = sizeof(buf)-5-NAME_LENGTH;
  16758. }
  16759. WBUFW(buf, 0) = 0x98e;
  16760. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16761. // 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
  16762. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16763. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16764. if((sd = clan_getavailablesd(clan)) != nullptr)
  16765. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16766. #endif
  16767. }
  16768. /**
  16769. * Parses a clan message from a player.
  16770. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16771. **/
  16772. void clif_parse_clan_chat( int fd, map_session_data* sd ){
  16773. #if PACKETVER >= 20131223
  16774. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16775. // validate packet and retrieve name and message
  16776. if( !clif_process_message(sd, false, name, message, output ) )
  16777. return;
  16778. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16779. #endif
  16780. }
  16781. /**
  16782. * Sends the basic clan informations to the client.
  16783. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16784. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16785. **/
  16786. void clif_clan_basicinfo( map_session_data *sd ){
  16787. #if PACKETVER >= 20131223
  16788. int fd, offset, length, i, flag;
  16789. struct clan* clan;
  16790. char mapname[MAP_NAME_LENGTH_EXT];
  16791. nullpo_retv( sd );
  16792. nullpo_retv( clan = sd->clan );
  16793. // Check if the player has a valid session and is not autotrading
  16794. if( !clif_session_isValid( sd ) ){
  16795. return;
  16796. }
  16797. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16798. fd = sd->fd;
  16799. WFIFOHEAD(fd,length);
  16800. memset( WFIFOP(fd, 0), 0, length );
  16801. WFIFOW( fd, 0 ) = 0x98a;
  16802. WFIFOL( fd, 4 ) = clan->id;
  16803. offset = 8;
  16804. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16805. offset += NAME_LENGTH;
  16806. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16807. offset += NAME_LENGTH;
  16808. mapindex_getmapname_ext( clan->map, mapname );
  16809. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16810. offset += MAP_NAME_LENGTH_EXT;
  16811. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16812. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16813. for( flag = 0; flag < 2; flag++ ){
  16814. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16815. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16816. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16817. offset += NAME_LENGTH;
  16818. }
  16819. }
  16820. }
  16821. WFIFOW( fd, 2 ) = offset;
  16822. WFIFOSET(fd,offset);
  16823. #endif
  16824. }
  16825. /**
  16826. * Updates the online and maximum player count of a clan.
  16827. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16828. **/
  16829. void clif_clan_onlinecount( struct clan* clan ){
  16830. #if PACKETVER >= 20131223
  16831. uint8 buf[6];
  16832. map_session_data *sd;
  16833. WBUFW(buf,0) = 0x988;
  16834. WBUFW(buf,2) = clan->connect_member;
  16835. WBUFW(buf,4) = clan->max_member;
  16836. if((sd = clan_getavailablesd(clan)) != nullptr)
  16837. clif_send(buf, 6, &sd->bl, CLAN);
  16838. #endif
  16839. }
  16840. /**
  16841. * Notifies the client that the player has left his clan.
  16842. * 0989 (ZC_ACK_CLAN_LEAVE)
  16843. **/
  16844. void clif_clan_leave( map_session_data* sd ){
  16845. #if PACKETVER >= 20131223
  16846. int fd;
  16847. nullpo_retv( sd );
  16848. if( !clif_session_isValid( sd ) ){
  16849. return;
  16850. }
  16851. fd = sd->fd;
  16852. WFIFOHEAD(fd,2);
  16853. WFIFOW(fd,0) = 0x989;
  16854. WFIFOSET(fd,2);
  16855. #endif
  16856. }
  16857. /**
  16858. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16859. * 0A2F <result>.B <title_id>.L
  16860. */
  16861. void clif_change_title_ack(map_session_data *sd, unsigned char result, unsigned long title_id)
  16862. {
  16863. #if PACKETVER >= 20150513
  16864. int fd;
  16865. nullpo_retv(sd);
  16866. if (!clif_session_isValid(sd))
  16867. return;
  16868. fd = sd->fd;
  16869. WFIFOHEAD(fd, packet_len(0xa2f));
  16870. WFIFOW(fd, 0) = 0xa2f;
  16871. WFIFOB(fd, 2) = result;
  16872. WFIFOL(fd, 3) = title_id;
  16873. WFIFOSET(fd, packet_len(0xa2f));
  16874. #endif
  16875. }
  16876. /**
  16877. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16878. * 0A2E <title_id>.L
  16879. */
  16880. void clif_parse_change_title(int fd, map_session_data *sd)
  16881. {
  16882. int title_id;
  16883. nullpo_retv(sd);
  16884. title_id = RFIFOL(fd, 2);
  16885. if( title_id == sd->status.title_id ){
  16886. // It is exactly the same as the old one
  16887. return;
  16888. }else if( title_id <= 0 ){
  16889. sd->status.title_id = 0;
  16890. }else{
  16891. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16892. clif_change_title_ack(sd, 1, title_id);
  16893. return;
  16894. }
  16895. sd->status.title_id = title_id;
  16896. }
  16897. clif_name_area(&sd->bl);
  16898. clif_change_title_ack(sd, 0, title_id);
  16899. }
  16900. #ifdef DUMP_UNKNOWN_PACKET
  16901. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16902. {
  16903. const char* packet_txt = "save/packet.txt";
  16904. FILE* fp;
  16905. time_t time_server;
  16906. struct tm *datetime;
  16907. char datestr[512];
  16908. time(&time_server); // get time in seconds since 1/1/1970
  16909. datetime = localtime(&time_server); // convert seconds in structure
  16910. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16911. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16912. if( ( fp = fopen( packet_txt , "a" ) ) != nullptr ) {
  16913. if( sd ) {
  16914. 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);
  16915. } else {
  16916. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16917. }
  16918. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16919. fprintf(fp, "\n");
  16920. fclose(fp);
  16921. } else {
  16922. ShowError("Failed to write '%s'.\n", packet_txt);
  16923. // Dump on console instead
  16924. if( sd ) {
  16925. 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);
  16926. } else {
  16927. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16928. }
  16929. ShowDump(RFIFOP(fd,0), packet_len);
  16930. }
  16931. }
  16932. #endif
  16933. /// Roulette System
  16934. /// Author: Yommy
  16935. void roulette_generate_bonus( map_session_data& sd ){
  16936. if( battle_config.feature_roulette_bonus_reward && sd.roulette.bonusItemID == 0 ){
  16937. int next_stage = 0;
  16938. if( sd.roulette_point.bronze > 0 ){
  16939. next_stage = 0;
  16940. }else if( sd.roulette_point.silver > 9 ){
  16941. next_stage = 2;
  16942. }else if( sd.roulette_point.gold > 9 ){
  16943. next_stage = 4;
  16944. }
  16945. // Get bonus item stage only from current stage or higher
  16946. int reward_stage = rnd_value( next_stage, MAX_ROULETTE_LEVEL - 1 );
  16947. sd.roulette.bonusItemID = rd.nameid[reward_stage][rnd()%rd.items[reward_stage]];
  16948. }else{
  16949. sd.roulette.bonusItemID = 0;
  16950. }
  16951. }
  16952. /// Opens the roulette window
  16953. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16954. void clif_roulette_open( map_session_data* sd ){
  16955. nullpo_retv( sd );
  16956. roulette_generate_bonus( *sd );
  16957. struct packet_roulette_open_ack p;
  16958. p.PacketType = 0xa1a;
  16959. p.Result = 0; // result
  16960. p.Serial = 0; // serial
  16961. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16962. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16963. p.AdditionItemID = sd->roulette.bonusItemID;
  16964. p.GoldPoint = sd->roulette_point.gold;
  16965. p.SilverPoint = sd->roulette_point.silver;
  16966. p.BronzePoint = sd->roulette_point.bronze;
  16967. sd->state.roulette_open = true;
  16968. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16969. }
  16970. /// Request to open the roulette window
  16971. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16972. void clif_parse_roulette_open( int fd, map_session_data* sd ){
  16973. nullpo_retv(sd);
  16974. if (!battle_config.feature_roulette) {
  16975. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16976. return;
  16977. }
  16978. clif_roulette_open(sd);
  16979. }
  16980. /// Sends the info about the available roulette rewards to the client
  16981. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16982. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16983. void clif_roulette_info( map_session_data* sd ){
  16984. nullpo_retv(sd);
  16985. struct packet_roulette_info_ack p;
  16986. p.PacketType = rouletteinfoackType;
  16987. p.PacketLength = sizeof(p);
  16988. p.RouletteSerial = 1;
  16989. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16990. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16991. p.ItemInfo[count].Row = i;
  16992. p.ItemInfo[count].Position = j;
  16993. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  16994. p.ItemInfo[count].Count = rd.qty[i][j];
  16995. #if PACKETVER >= 20180511
  16996. p.ItemInfo[count].unused = 0;
  16997. #endif
  16998. count++;
  16999. }
  17000. }
  17001. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17002. }
  17003. /// Request the roulette reward data
  17004. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17005. void clif_parse_roulette_info( int fd, map_session_data* sd ){
  17006. nullpo_retv(sd);
  17007. if (!battle_config.feature_roulette) {
  17008. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17009. return;
  17010. }
  17011. clif_roulette_info(sd);
  17012. }
  17013. /// Notification of the client that the roulette window was closed
  17014. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17015. void clif_parse_roulette_close( int fd, map_session_data* sd ){
  17016. nullpo_retv(sd);
  17017. if (!battle_config.feature_roulette) {
  17018. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17019. return;
  17020. }
  17021. sd->state.roulette_open = false;
  17022. }
  17023. /// Response to a item reward request
  17024. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17025. static void clif_roulette_recvitem_ack(map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17026. #if PACKETVER >= 20141016
  17027. nullpo_retv(sd);
  17028. struct packet_roulette_itemrecv_ack p;
  17029. p.PacketType = roulettercvitemackType;
  17030. p.Result = type;
  17031. p.AdditionItemID = sd->roulette.bonusItemID;
  17032. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17033. #endif
  17034. }
  17035. /**
  17036. * Claim roulette reward
  17037. * @param sd Player
  17038. * @return 0:Success
  17039. **/
  17040. static uint8 clif_roulette_getitem(map_session_data *sd) {
  17041. struct item it;
  17042. uint8 res = 1;
  17043. unsigned short factor = 1;
  17044. nullpo_retr(1, sd);
  17045. if (sd->roulette.prizeIdx < 0)
  17046. return RECV_ITEM_FAILED;
  17047. memset(&it, 0, sizeof(it));
  17048. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17049. it.identify = 1;
  17050. if( sd->roulette.bonusItemID != 0 ){
  17051. if( sd->roulette.bonusItemID == it.nameid && battle_config.feature_roulette_bonus_reward && !( rd.flag[sd->roulette.prizeStage][sd->roulette.prizeIdx]&1 ) ){
  17052. factor = 2;
  17053. // Reset the Bonus Item to trigger new calculation
  17054. sd->roulette.bonusItemID = 0;
  17055. }else{
  17056. for( int i = 0; i < MAX_ROULETTE_LEVEL && sd->roulette.bonusItemID != 0; i++ ){
  17057. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i && sd->roulette.bonusItemID != 0; j++ ){
  17058. if( rd.nameid[i][j] == sd->roulette.bonusItemID ){
  17059. // 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
  17060. if( sd->roulette.prizeStage >= i ){
  17061. // Reset the Bonus Item to trigger new calculation and to cancel the loops
  17062. sd->roulette.bonusItemID = 0;
  17063. }
  17064. }
  17065. }
  17066. }
  17067. }
  17068. }
  17069. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx] * factor, LOG_TYPE_ROULETTE)) == 0) {
  17070. ; // onSuccess
  17071. }
  17072. if( sd->roulette.bonusItemID == 0 ){
  17073. roulette_generate_bonus( *sd );
  17074. }
  17075. sd->roulette.claimPrize = false;
  17076. sd->roulette.prizeStage = 0;
  17077. sd->roulette.prizeIdx = -1;
  17078. sd->roulette.stage = 0;
  17079. return res;
  17080. }
  17081. /// Update Roulette window with current stats
  17082. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17083. void clif_roulette_generate( map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17084. nullpo_retv( sd );
  17085. struct packet_roulette_generate_ack p;
  17086. p.PacketType = roulettgenerateackType;
  17087. p.Result = result;
  17088. p.Step = stage;
  17089. p.Idx = prizeIdx;
  17090. p.AdditionItemID = battle_config.feature_roulette_bonus_reward ? bonusItemID : 0;
  17091. p.RemainGold = sd->roulette_point.gold;
  17092. p.RemainSilver = sd->roulette_point.silver;
  17093. p.RemainBronze = sd->roulette_point.bronze;
  17094. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17095. }
  17096. /// Request to start the roulette
  17097. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17098. void clif_parse_roulette_generate( int fd, map_session_data* sd ){
  17099. enum GENERATE_ROULETTE_ACK result;
  17100. nullpo_retv(sd);
  17101. if (!battle_config.feature_roulette) {
  17102. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17103. return;
  17104. }
  17105. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17106. return;
  17107. }
  17108. // Player has not claimed his prize yet
  17109. if( sd->roulette.claimPrize ){
  17110. clif_roulette_getitem( sd );
  17111. }
  17112. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17113. // Make sure everything is reset
  17114. sd->roulette.stage = 0;
  17115. sd->roulette.claimPrize = false;
  17116. sd->roulette.prizeStage = 0;
  17117. sd->roulette.prizeIdx = -1;
  17118. }
  17119. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17120. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17121. }else{
  17122. if (!sd->roulette.stage) {
  17123. if (sd->roulette_point.bronze > 0) {
  17124. sd->roulette_point.bronze -= 1;
  17125. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17126. } else if (sd->roulette_point.silver > 9) {
  17127. sd->roulette_point.silver -= 10;
  17128. sd->roulette.stage = 2;
  17129. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17130. } else if (sd->roulette_point.gold > 9) {
  17131. sd->roulette_point.gold -= 10;
  17132. sd->roulette.stage = 4;
  17133. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17134. }
  17135. }
  17136. sd->roulette.prizeStage = sd->roulette.stage;
  17137. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17138. sd->roulette.claimPrize = true;
  17139. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17140. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17141. result = GENERATE_ROULETTE_LOSING;
  17142. sd->roulette.stage = 0;
  17143. }else{
  17144. result = GENERATE_ROULETTE_SUCCESS;
  17145. sd->roulette.stage++;
  17146. }
  17147. }
  17148. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx), sd->roulette.bonusItemID);
  17149. }
  17150. /// Request to claim a prize
  17151. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17152. void clif_parse_roulette_item( int fd, map_session_data* sd ){
  17153. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17154. nullpo_retv(sd);
  17155. if (!battle_config.feature_roulette) {
  17156. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17157. return;
  17158. }
  17159. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17160. return;
  17161. }
  17162. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17163. switch (clif_roulette_getitem(sd)) {
  17164. case ADDITEM_SUCCESS:
  17165. type = RECV_ITEM_SUCCESS;
  17166. break;
  17167. case ADDITEM_INVALID:
  17168. case ADDITEM_OVERITEM:
  17169. case ADDITEM_OVERAMOUNT:
  17170. type = RECV_ITEM_OVERCOUNT;
  17171. break;
  17172. case ADDITEM_OVERWEIGHT:
  17173. type = RECV_ITEM_OVERWEIGHT;
  17174. break;
  17175. case ADDITEM_STACKLIMIT:
  17176. default:
  17177. type = RECV_ITEM_FAILED;
  17178. break;
  17179. }
  17180. }
  17181. clif_roulette_recvitem_ack(sd,type);
  17182. }
  17183. /// MERGE ITEM
  17184. /**
  17185. * Acknowledge the client about item merger result
  17186. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17187. * @param fd
  17188. * @param sd
  17189. **/
  17190. void clif_merge_item_ack( map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17191. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17192. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17193. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17194. if( type == MERGE_ITEM_SUCCESS ){
  17195. p.index = client_index( index );
  17196. }else{
  17197. p.index = index;
  17198. }
  17199. p.amount = count;
  17200. p.reason = type;
  17201. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17202. #endif
  17203. }
  17204. /**
  17205. * Check if item has the pair to be merged
  17206. * @param sd
  17207. * @param it Item
  17208. * @return True if has pair, False if not
  17209. **/
  17210. static bool clif_merge_item_has_pair(map_session_data *sd, struct item *it) {
  17211. struct item *it_;
  17212. unsigned short i;
  17213. nullpo_retr(false, sd);
  17214. 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);
  17215. if (i < MAX_INVENTORY)
  17216. return true;
  17217. return false;
  17218. }
  17219. /**
  17220. * Check if item can be merged
  17221. * @param id Item Data
  17222. * @param it Item
  17223. * @return True if can be merged, False if not
  17224. **/
  17225. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17226. if (!id || !it)
  17227. return false;
  17228. if (id->type == IT_CASH)
  17229. return false;
  17230. if (!itemdb_isstackable2(id))
  17231. return false;
  17232. if (itemdb_isspecial(it->card[0]))
  17233. return false;
  17234. if (!it->unique_id)
  17235. return false;
  17236. return true;
  17237. }
  17238. /**
  17239. * Open available item to be merged.
  17240. * Only show 1 item in 1 process.
  17241. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17242. * @param sd
  17243. **/
  17244. void clif_merge_item_open( map_session_data& sd ){
  17245. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17246. PACKET_ZC_MERGE_ITEM_OPEN* p = reinterpret_cast<PACKET_ZC_MERGE_ITEM_OPEN*>( packet_buffer );
  17247. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17248. p->packetLen = sizeof( *p );
  17249. int n = 0;
  17250. // Get entries
  17251. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17252. struct item* it = &sd.inventory.u.items_inventory[i];
  17253. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17254. continue;
  17255. }
  17256. if( clif_merge_item_has_pair( &sd, it ) ){
  17257. p->items[n++].index = client_index( i );
  17258. p->packetLen += static_cast<decltype(p->packetLen)>( sizeof( p->items[0] ) );
  17259. }
  17260. }
  17261. // No item need to be merged
  17262. if( n < 2 ){
  17263. clif_msg( &sd, MSI_NOT_EXIST_MERGE_ITEM );
  17264. return;
  17265. }
  17266. clif_send( p, p->packetLen, &sd.bl, SELF );
  17267. #endif
  17268. }
  17269. /**
  17270. * Process item merge request.
  17271. * 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17272. * @param fd
  17273. * @param sd
  17274. **/
  17275. void clif_parse_merge_item_req( int fd, map_session_data* sd ){
  17276. struct PACKET_CZ_REQ_MERGE_ITEM* p = (struct PACKET_CZ_REQ_MERGE_ITEM*)RFIFOP( fd, 0 );
  17277. int count = ( p->packetLength - sizeof( *p ) ) / sizeof( p->indices[0] );
  17278. // No item need to be merged
  17279. if( count < 2 ){
  17280. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17281. return;
  17282. }
  17283. uint16 idx_main = server_index( p->indices[0] );
  17284. if( idx_main >= MAX_INVENTORY ){
  17285. return;
  17286. }
  17287. if( !clif_merge_item_check( sd->inventory_data[idx_main], &sd->inventory.u.items_inventory[idx_main] ) ){
  17288. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17289. return;
  17290. }
  17291. // Ensure each index only comes once
  17292. std::unordered_set<uint16> indices;
  17293. for( int i = 1; i < count; i++ ){
  17294. uint16 idx = server_index( p->indices[i] );
  17295. if( idx >= MAX_INVENTORY ){
  17296. return;
  17297. }
  17298. if( sd->inventory_data[idx] == nullptr ){
  17299. return;
  17300. }
  17301. // Check if it is the same item
  17302. if( sd->inventory_data[idx]->nameid != sd->inventory_data[idx_main]->nameid ){
  17303. return;
  17304. }
  17305. if( !clif_merge_item_check( sd->inventory_data[idx], &sd->inventory.u.items_inventory[idx] ) ){
  17306. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17307. return;
  17308. }
  17309. indices.insert( idx );
  17310. }
  17311. if( indices.empty() ){
  17312. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17313. return;
  17314. }
  17315. uint32 total_amount = sd->inventory.u.items_inventory[idx_main].amount;
  17316. for( uint16 idx : indices ){
  17317. total_amount += sd->inventory.u.items_inventory[idx].amount;
  17318. }
  17319. uint16 stack = sd->inventory_data[idx_main]->stack.amount;
  17320. if( stack == 0 ){
  17321. stack = MAX_AMOUNT;
  17322. }
  17323. if( total_amount >= stack ){
  17324. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17325. return;
  17326. }
  17327. // Merrrrge!!!!
  17328. for( uint16 idx : indices ){
  17329. uint16 amount = sd->inventory.u.items_inventory[idx].amount;
  17330. log_pick_pc( sd, LOG_TYPE_MERGE_ITEM, -amount, &sd->inventory.u.items_inventory[idx] );
  17331. memset( &sd->inventory.u.items_inventory[idx], 0, sizeof( sd->inventory.u.items_inventory[0] ) );
  17332. sd->inventory_data[idx] = nullptr;
  17333. clif_delitem( *sd, idx, amount, 0 );
  17334. }
  17335. sd->inventory.u.items_inventory[idx_main].amount = total_amount;
  17336. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, idx_main, total_amount );
  17337. }
  17338. /**
  17339. * Cancel item merge
  17340. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17341. * @param fd
  17342. * @param sd
  17343. **/
  17344. void clif_parse_merge_item_cancel(int fd, map_session_data* sd) {
  17345. return; // Nothing todo yet
  17346. }
  17347. static std::string clif_hide_name(const char* original_name)
  17348. {
  17349. std::string censored(original_name);
  17350. size_t hide = zmin(battle_config.broadcast_hide_name, censored.length() - 1);
  17351. censored.replace(censored.length() - hide, hide, hide, '*');
  17352. return censored;
  17353. }
  17354. /**
  17355. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17356. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17357. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17358. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17359. **/
  17360. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17361. char name[NAME_LENGTH];
  17362. if( battle_config.broadcast_hide_name ){
  17363. std::string dispname = clif_hide_name(char_name);
  17364. safestrncpy(name, dispname.c_str(), sizeof(name));
  17365. }else{
  17366. safestrncpy( name, char_name, sizeof( name ) );
  17367. }
  17368. switch( type ){
  17369. case ITEMOBTAIN_TYPE_BOXITEM:
  17370. #if PACKETVER >= 20091201
  17371. {
  17372. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17373. p.PacketType = package_item_announceType;
  17374. p.PacketLength = sizeof( p );
  17375. p.type = type;
  17376. p.ItemID = client_nameid( nameid );
  17377. p.len = NAME_LENGTH;
  17378. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17379. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17380. p.BoxItemID = client_nameid( container );
  17381. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17382. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17383. p.refineLevel = 0; // TODO: implement
  17384. #endif
  17385. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17386. }
  17387. #endif
  17388. break;
  17389. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17390. case ITEMOBTAIN_TYPE_NPC:
  17391. {
  17392. struct packet_item_drop_announce p;
  17393. p.PacketType = item_drop_announceType;
  17394. p.type = type;
  17395. p.ItemID = client_nameid( nameid );
  17396. p.len = NAME_LENGTH;
  17397. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17398. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17399. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17400. p.monsterNameLen = NAME_LENGTH;
  17401. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17402. }else{
  17403. p.monsterNameLen = 0;
  17404. p.monsterName[0] = '\0';
  17405. }
  17406. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17407. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17408. #else
  17409. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17410. #endif
  17411. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17412. }
  17413. break;
  17414. }
  17415. }
  17416. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17417. /// 0A02 <view>.W
  17418. /// Value <flag> has the following effects:
  17419. /// 1: Open a Dress Room window.
  17420. void clif_dressing_room(map_session_data *sd, int flag) {
  17421. #if PACKETVER >= 20150513
  17422. int fd = sd->fd;
  17423. nullpo_retv(sd);
  17424. WFIFOHEAD(fd, packet_len(0xa02));
  17425. WFIFOW(fd,0) = 0xa02;
  17426. WFIFOW(fd,2) = flag;
  17427. WFIFOSET(fd, packet_len(0xa02));
  17428. #endif
  17429. }
  17430. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17431. /// 0A35 <result>.W
  17432. void clif_parse_Oneclick_Itemidentify(int fd, map_session_data *sd) {
  17433. #if PACKETVER >= 20150513
  17434. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17435. // Ignore the request
  17436. // - Invalid item index
  17437. // - Invalid item ID or item doesn't exist
  17438. // - Item is already identified
  17439. if (idx < 0 || idx >= MAX_INVENTORY ||
  17440. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == nullptr ||
  17441. sd->inventory.u.items_inventory[idx].identify)
  17442. return;
  17443. // Ignore the request - No magnifiers in inventory
  17444. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17445. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17446. return;
  17447. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17448. return;
  17449. skill_identify(sd, idx);
  17450. #endif
  17451. }
  17452. /// Starts navigation to the given target on client side
  17453. void clif_navigateTo(map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17454. #if PACKETVER >= 20111010
  17455. int fd = sd->fd;
  17456. WFIFOHEAD(fd,27);
  17457. WFIFOW(fd,0) = 0x08e2;
  17458. // How detailed will our navigation be?
  17459. if( mob_id > 0 ){
  17460. x = 0;
  17461. y = 0;
  17462. WFIFOB(fd,2) = 3; // monster with destination field
  17463. }else if( x > 0 && y > 0 ){
  17464. WFIFOB(fd,2) = 0; // with coordinates
  17465. }else{
  17466. x = 0;
  17467. y = 0;
  17468. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17469. }
  17470. // Which services can be used for transportation?
  17471. WFIFOB(fd,3) = flag;
  17472. // If this flag is set, the navigation window will not be opened up
  17473. WFIFOB(fd,4) = hideWindow;
  17474. // Target map
  17475. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17476. // Target x
  17477. WFIFOW(fd,21) = x;
  17478. // Target y
  17479. WFIFOW(fd,23) = y;
  17480. // Target monster ID
  17481. WFIFOW(fd,25) = mob_id;
  17482. WFIFOSET(fd,27);
  17483. #endif
  17484. }
  17485. /// Send hat effects to the client.
  17486. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W } (ZC_EQUIPMENT_EFFECT)
  17487. void clif_hat_effects( map_session_data& sd, block_list& bl, enum send_target target ){
  17488. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17489. map_session_data *tsd;
  17490. block_list* tbl;
  17491. if( target == SELF ){
  17492. tsd = BL_CAST(BL_PC,&bl);
  17493. tbl = &sd.bl;
  17494. }else{
  17495. tsd = &sd;
  17496. tbl = &bl;
  17497. }
  17498. if( tsd == nullptr ){
  17499. return;
  17500. }
  17501. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->getMapFlag(MF_NOCOSTUME) ){
  17502. return;
  17503. }
  17504. PACKET_ZC_EQUIPMENT_EFFECT* p = reinterpret_cast<PACKET_ZC_EQUIPMENT_EFFECT*>( packet_buffer );
  17505. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17506. p->packetLength = sizeof( *p );
  17507. p->aid = tsd->bl.id;
  17508. p->status = 1;
  17509. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17510. p->effects[i] = tsd->hatEffects[i];
  17511. p->packetLength += static_cast<decltype(p->packetLength)>( p->effects[0] );
  17512. }
  17513. clif_send( p, p->packetLength, tbl, target );
  17514. #endif
  17515. }
  17516. /// Send a single hat effect to the client.
  17517. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W } (ZC_EQUIPMENT_EFFECT)
  17518. void clif_hat_effect_single( map_session_data& sd, uint16 effectId, bool enable ){
  17519. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17520. PACKET_ZC_EQUIPMENT_EFFECT* p = reinterpret_cast<PACKET_ZC_EQUIPMENT_EFFECT*>( packet_buffer );
  17521. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17522. p->packetLength = sizeof( *p );
  17523. p->aid = sd.bl.id;
  17524. p->status = enable;
  17525. p->effects[0] = effectId;
  17526. p->packetLength += static_cast<decltype(p->packetLength)>( p->effects[0] );
  17527. clif_send( p, p->packetLength, &sd.bl, AREA );
  17528. #endif
  17529. }
  17530. /// Notify the client that a sale has started
  17531. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17532. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17533. #if PACKETVER_SUPPORTS_SALES
  17534. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17535. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17536. p.itemId = client_nameid( sale_item->nameid );
  17537. p.remainingTime = (uint32)(sale_item->end - time(nullptr)); // time in S
  17538. clif_send( &p, sizeof( p ), bl, target );
  17539. #endif
  17540. }
  17541. /// Notify the client that a sale has ended
  17542. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17543. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17544. #if PACKETVER_SUPPORTS_SALES
  17545. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17546. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17547. p.itemId = client_nameid( sale_item->nameid );
  17548. clif_send( &p, sizeof( p ), bl, target );
  17549. #endif
  17550. }
  17551. /// Update the remaining amount of a sale item.
  17552. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17553. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17554. #if PACKETVER_SUPPORTS_SALES
  17555. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17556. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17557. p.itemId = client_nameid( sale_item->nameid );
  17558. p.amount = sale_item->amount;
  17559. clif_send( &p, sizeof( p ), bl, target );
  17560. #endif
  17561. }
  17562. /// The client requested a refresh of the current remaining count of a sale item
  17563. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17564. void clif_parse_sale_refresh( int fd, map_session_data* sd ){
  17565. #if PACKETVER_SUPPORTS_SALES
  17566. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17567. struct sale_item_data* sale;
  17568. if( p->AID != sd->status.account_id ){
  17569. return;
  17570. }
  17571. sale = sale_find_item( p->itemId, true );
  17572. if( sale == nullptr ){
  17573. return;
  17574. }
  17575. clif_sale_amount(sale, &sd->bl, SELF);
  17576. #endif
  17577. }
  17578. /// Opens the sale administration window on the client
  17579. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17580. void clif_sale_open( map_session_data* sd ){
  17581. #if PACKETVER_SUPPORTS_SALES
  17582. nullpo_retv(sd);
  17583. if( sd->state.sale_open ){
  17584. return;
  17585. }
  17586. sd->state.sale_open = true;
  17587. int fd = sd->fd;
  17588. WFIFOHEAD(fd, 2);
  17589. WFIFOW(fd, 0) = 0x9b5;
  17590. WFIFOSET(fd, 2);
  17591. #endif
  17592. }
  17593. /// Client request to open the sale administration window.
  17594. /// This is sent by /limitedsale
  17595. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17596. void clif_parse_sale_open( int fd, map_session_data* sd ){
  17597. #if PACKETVER_SUPPORTS_SALES
  17598. nullpo_retv(sd);
  17599. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17600. return;
  17601. }
  17602. char command[CHAT_SIZE_MAX];
  17603. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17604. is_atcommand(fd, sd, command, 1);
  17605. #endif
  17606. }
  17607. /// Closes the sale administration window on the client.
  17608. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17609. void clif_sale_close(map_session_data* sd) {
  17610. #if PACKETVER_SUPPORTS_SALES
  17611. nullpo_retv(sd);
  17612. if( !sd->state.sale_open ){
  17613. return;
  17614. }
  17615. sd->state.sale_open = false;
  17616. int fd = sd->fd;
  17617. WFIFOHEAD(fd, 2);
  17618. WFIFOW(fd, 0) = 0x9bd;
  17619. WFIFOSET(fd, 2);
  17620. #endif
  17621. }
  17622. /// Client request to close the sale administration window.
  17623. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17624. void clif_parse_sale_close(int fd, map_session_data* sd) {
  17625. #if PACKETVER_SUPPORTS_SALES
  17626. nullpo_retv(sd);
  17627. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17628. return;
  17629. }
  17630. clif_sale_close(sd);
  17631. #endif
  17632. }
  17633. /// Reply to a item search request for item sale administration.
  17634. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17635. void clif_sale_search_reply( map_session_data* sd, std::shared_ptr<s_cash_item> item ){
  17636. #if PACKETVER_SUPPORTS_SALES
  17637. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17638. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17639. if( item != nullptr ){
  17640. p.result = 0;
  17641. p.itemId = client_nameid( item->nameid );
  17642. p.price = item->price;
  17643. }else{
  17644. p.result = 1;
  17645. p.itemId = 0;
  17646. p.price = 0;
  17647. }
  17648. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17649. #endif
  17650. }
  17651. /// Search request for an item sale administration.
  17652. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17653. void clif_parse_sale_search( int fd, map_session_data* sd ){
  17654. #if PACKETVER_SUPPORTS_SALES
  17655. char item_name[ITEM_NAME_LENGTH];
  17656. nullpo_retv(sd);
  17657. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17658. return;
  17659. }
  17660. if( !sd->state.sale_open ){
  17661. return;
  17662. }
  17663. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17664. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17665. // not found
  17666. if( id == nullptr ){
  17667. clif_sale_search_reply( sd, nullptr );
  17668. return;
  17669. }
  17670. clif_sale_search_reply( sd, cash_shop_db.findItemInTab( CASHSHOP_TAB_SALE, id->nameid ) );
  17671. #endif
  17672. }
  17673. /// Reply if an item was successfully put on sale or not.
  17674. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17675. void clif_sale_add_reply( map_session_data* sd, enum e_sale_add_result result ){
  17676. #if PACKETVER_SUPPORTS_SALES
  17677. int fd = sd->fd;
  17678. WFIFOHEAD(fd, 4);
  17679. WFIFOW(fd, 0) = 0x9af;
  17680. WFIFOW(fd, 2) = (uint16)result;
  17681. WFIFOSET(fd, 4);
  17682. #endif
  17683. }
  17684. /// A client request to put an item on sale.
  17685. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17686. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17687. void clif_parse_sale_add( int fd, map_session_data* sd ){
  17688. #if PACKETVER_SUPPORTS_SALES
  17689. nullpo_retv( sd );
  17690. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17691. if( p->AID != sd->status.account_id ){
  17692. return;
  17693. }
  17694. if( !sd->state.sale_open ){
  17695. return;
  17696. }
  17697. time_t endTime = p->startTime + p->hours * 60 * 60;
  17698. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17699. #endif
  17700. }
  17701. /// Reply to an item removal from sale.
  17702. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17703. void clif_sale_remove_reply( map_session_data* sd, bool failed ){
  17704. #if PACKETVER_SUPPORTS_SALES
  17705. int fd = sd->fd;
  17706. WFIFOHEAD(fd, 4);
  17707. WFIFOW(fd, 0) = 0x9b1;
  17708. WFIFOW(fd, 2) = failed;
  17709. WFIFOSET(fd, 4);
  17710. #endif
  17711. }
  17712. /// Request to remove an item from sale.
  17713. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17714. void clif_parse_sale_remove( int fd, map_session_data* sd ){
  17715. #if PACKETVER_SUPPORTS_SALES
  17716. nullpo_retv( sd );
  17717. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17718. if( p->AID != sd->status.account_id ){
  17719. return;
  17720. }
  17721. if( !sd->state.sale_open ){
  17722. return;
  17723. }
  17724. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17725. #endif
  17726. }
  17727. /// Achievement System
  17728. /// Author: Luxuri, Aleos
  17729. /**
  17730. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17731. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17732. */
  17733. void clif_achievement_list_all(map_session_data *sd)
  17734. {
  17735. nullpo_retv(sd);
  17736. if (!battle_config.feature_achievement) {
  17737. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17738. return;
  17739. }
  17740. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17741. if (count == 0)
  17742. return;
  17743. int len = (50 * count) + 22;
  17744. int fd = sd->fd;
  17745. int *info = achievement_level(sd, true);
  17746. WFIFOHEAD(fd,len);
  17747. WFIFOW(fd, 0) = 0xa23;
  17748. WFIFOW(fd, 2) = len;
  17749. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17750. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17751. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17752. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17753. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17754. for (int i = 0; i < count; i++) {
  17755. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17756. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17757. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17758. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17759. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17760. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17761. }
  17762. WFIFOSET(fd, len);
  17763. }
  17764. /**
  17765. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17766. * 0a24 <ACHPoint>.L
  17767. */
  17768. void clif_achievement_update(map_session_data *sd, struct achievement *ach, int count)
  17769. {
  17770. nullpo_retv(sd);
  17771. if (!battle_config.feature_achievement) {
  17772. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17773. return;
  17774. }
  17775. int fd = sd->fd;
  17776. int *info = achievement_level(sd, true);
  17777. WFIFOHEAD(fd, packet_len(0xa24));
  17778. WFIFOW(fd, 0) = 0xa24;
  17779. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17780. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17781. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17782. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17783. if (ach) {
  17784. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17785. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17786. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17787. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17788. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17789. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17790. } else
  17791. memset(WFIFOP(fd, 16), 0, 40);
  17792. WFIFOSET(fd, packet_len(0xa24));
  17793. }
  17794. /**
  17795. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17796. * 0a25 <achievementID>.L
  17797. */
  17798. void clif_parse_AchievementCheckReward(int fd, map_session_data *sd)
  17799. {
  17800. nullpo_retv(sd);
  17801. if( sd->achievement_data.save )
  17802. intif_achievement_save(sd);
  17803. achievement_check_reward(sd, RFIFOL(fd,2));
  17804. }
  17805. /**
  17806. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17807. * 0a26 <result>.W <achievementID>.L
  17808. */
  17809. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17810. {
  17811. WFIFOHEAD(fd, packet_len(0xa26));
  17812. WFIFOW(fd, 0) = 0xa26;
  17813. WFIFOB(fd, 2) = result;
  17814. WFIFOL(fd, 3) = achievement_id;
  17815. WFIFOSET(fd, packet_len(0xa26));
  17816. }
  17817. /// Process the pet evolution request
  17818. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17819. void clif_parse_pet_evolution( int fd, map_session_data *sd ){
  17820. #if PACKETVER >= 20141008
  17821. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17822. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17823. if (!pet) {
  17824. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17825. return;
  17826. }
  17827. pet_evolution(sd, pet->class_);
  17828. #endif
  17829. }
  17830. /// Sends the result of the evolution to the client.
  17831. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17832. void clif_pet_evolution_result( map_session_data* sd, e_pet_evolution_result result ){
  17833. #if PACKETVER >= 20141008
  17834. int fd = sd->fd;
  17835. WFIFOHEAD(fd, packet_len(0x9fc));
  17836. WFIFOW(fd, 0) = 0x9fc;
  17837. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17838. WFIFOSET(fd, packet_len(0x9fc));
  17839. #endif
  17840. }
  17841. /*
  17842. * This packet is sent by /changedress or /nocosplay
  17843. *
  17844. * 0ae8
  17845. */
  17846. void clif_parse_changedress( int fd, map_session_data* sd ){
  17847. #if PACKETVER >= 20180103
  17848. char command[CHAT_SIZE_MAX];
  17849. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17850. is_atcommand( fd, sd, command, 1 );
  17851. #endif
  17852. }
  17853. /// Opens an UI window of the given type and initializes it with the given data
  17854. /// 0AE2 <type>.B <data>.L
  17855. void clif_ui_open( map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  17856. #if PACKETVER >= 20151202
  17857. // If the UI requires state tracking
  17858. switch( ui_type ){
  17859. case OUT_UI_STYLIST:
  17860. sd.state.stylist_open = true;
  17861. break;
  17862. case OUT_UI_ENCHANTGRADE:
  17863. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  17864. sd.state.enchantgrade_open = true;
  17865. break;
  17866. #else
  17867. return;
  17868. #endif
  17869. }
  17870. struct PACKET_ZC_UI_OPEN p = {};
  17871. p.PacketType = HEADER_ZC_UI_OPEN;
  17872. p.UIType = ui_type;
  17873. #if PACKETVER >= 20171122
  17874. p.data = data;
  17875. #endif
  17876. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17877. #endif
  17878. }
  17879. /// Request to open an UI window of the given type
  17880. /// 0A68 <type>.B
  17881. void clif_parse_open_ui( int fd, map_session_data* sd ){
  17882. switch( RFIFOB(fd,2) ){
  17883. case IN_UI_ATTENDANCE:
  17884. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17885. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17886. }else if( pc_attendance_enabled() ){
  17887. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17888. }else{
  17889. clif_msg_color( sd, MSI_CHECK_ATTENDANCE_NOT_EVENT, color_table[COLOR_RED] );
  17890. }
  17891. break;
  17892. #if PACKETVER >= 20160316
  17893. case IN_UI_MACRO_REGISTER:
  17894. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  17895. break;
  17896. case IN_UI_MACRO_DETECTOR:
  17897. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  17898. break;
  17899. #endif
  17900. }
  17901. }
  17902. /// Response for attedance request
  17903. /// 0AF0 <unknown>.L <data>.L
  17904. void clif_attendence_response( map_session_data *sd, int32 data ){
  17905. nullpo_retv(sd);
  17906. int fd = sd->fd;
  17907. WFIFOHEAD(fd,packet_len(0xAF0));
  17908. WFIFOW(fd,0) = 0xAF0;
  17909. WFIFOL(fd,2) = 0;
  17910. WFIFOL(fd,6) = data;
  17911. WFIFOSET(fd,packet_len(0xAF0));
  17912. }
  17913. /// Request from the client to retrieve today's attendance reward
  17914. /// 0AEF
  17915. void clif_parse_attendance_request( int fd, map_session_data* sd ){
  17916. pc_attendance_claim_reward(sd);
  17917. }
  17918. /// Send out the percentage of weight that causes it to be displayed in red.
  17919. /// 0ADE <percentage>.L
  17920. void clif_weight_limit( map_session_data* sd ){
  17921. #if PACKETVER >= 20171025
  17922. nullpo_retv(sd);
  17923. int fd = sd->fd;
  17924. WFIFOHEAD(fd, packet_len(0xADE));
  17925. WFIFOW(fd, 0) = 0xADE;
  17926. #ifdef RENEWAL
  17927. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17928. #else
  17929. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17930. #endif
  17931. WFIFOSET(fd, packet_len(0xADE));
  17932. #endif
  17933. }
  17934. enum e_private_airship_response : uint32{
  17935. PRIVATEAIRSHIP_OK,
  17936. PRIVATEAIRSHIP_RETRY,
  17937. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17938. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17939. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17940. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17941. };
  17942. /// Send out the response to a private airship request
  17943. /// 0A4A <response>.L
  17944. void clif_private_airship_response( map_session_data* sd, enum e_private_airship_response response ){
  17945. #if PACKETVER >= 20180321
  17946. nullpo_retv( sd );
  17947. int fd = sd->fd;
  17948. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17949. WFIFOW( fd, 0 ) = 0xA4A;
  17950. WFIFOL( fd, 2 ) = response;
  17951. WFIFOSET( fd, packet_len( 0xA4A ) );
  17952. #endif
  17953. }
  17954. /// Parses a request for a private airship
  17955. /// 0A49 <mapname>.16B <itemid>.W
  17956. void clif_parse_private_airship_request( int fd, map_session_data* sd ){
  17957. #if PACKETVER >= 20180321
  17958. // Check if the feature is enabled
  17959. if( !battle_config.feature_privateairship ){
  17960. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17961. return;
  17962. }
  17963. // Check if the player is allowed to warp from the source map
  17964. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17965. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17966. return;
  17967. }
  17968. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17969. char mapname[MAP_NAME_LENGTH_EXT];
  17970. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17971. int16 mapindex = mapindex_name2id( mapname );
  17972. // Check if we know the mapname
  17973. if( mapindex < 0 ){
  17974. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17975. return;
  17976. }
  17977. int16 mapid = map_mapindex2mapid( mapindex );
  17978. // Check if the map is available on this server
  17979. if( mapid < 0 ){
  17980. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17981. return;
  17982. }
  17983. // Check if the player tried to warp to the map he is on
  17984. if( sd->bl.m == mapid ){
  17985. // This is blocked by the client, but just to be sure
  17986. return;
  17987. }
  17988. // This can only be a hack, so we prevent it
  17989. if( map_getmapdata( mapid )->instance_id ){
  17990. // Ignore requests to warp directly into a running instance
  17991. return;
  17992. }
  17993. // Check if the player is allowed to warp to the target map
  17994. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17995. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17996. return;
  17997. }
  17998. t_itemid item_id = p->ItemID;
  17999. // Check if the item sent by the client is known to us
  18000. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18001. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18002. return;
  18003. }
  18004. int idx = pc_search_inventory( sd, item_id );
  18005. // Check if the player has the item at all
  18006. if( idx < 0 ){
  18007. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18008. return;
  18009. }
  18010. // Delete the chosen item
  18011. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18012. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18013. return;
  18014. }
  18015. // Warp the player to a random spot on the destination map
  18016. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18017. #endif
  18018. }
  18019. /// Sends out the usage history of the guild storage
  18020. /// 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
  18021. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18022. void clif_guild_storage_log( map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18023. #if PACKETVER >= 20140205
  18024. nullpo_retv( sd );
  18025. int fd = sd->fd;
  18026. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18027. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18028. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18029. }else{
  18030. log.clear();
  18031. }
  18032. WFIFOHEAD( fd, size );
  18033. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18034. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18035. p->PacketLength = size;
  18036. p->result = result;
  18037. p->amount = (uint16)log.size();
  18038. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18039. for( int i = 0; i < log.size(); i++ ){
  18040. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18041. struct guild_log_entry& entry = log[i];
  18042. item->id = entry.id;
  18043. item->itemId = client_nameid( entry.item.nameid );
  18044. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18045. item->action = entry.amount > 0; // action = true(put), false(get)
  18046. item->refine = entry.item.refine;
  18047. item->uniqueId = entry.item.unique_id;
  18048. item->IsIdentified = entry.item.identify;
  18049. item->itemType = itemtype( entry.item.nameid );
  18050. clif_addcards( &item->slot, &entry.item );
  18051. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18052. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18053. item->attribute = entry.item.attribute;
  18054. }
  18055. }
  18056. WFIFOSET( fd, p->PacketLength );
  18057. #endif
  18058. }
  18059. /// Activates the client camera info or updates the client camera with the given values.
  18060. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18061. void clif_camerainfo( map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18062. #if PACKETVER >= 20160525
  18063. int fd = sd->fd;
  18064. WFIFOHEAD(fd, packet_len(0xa78));
  18065. WFIFOW(fd, 0) = 0xa78;
  18066. WFIFOB(fd, 2) = show;
  18067. WFIFOF(fd, 3) = range;
  18068. WFIFOF(fd, 7) = rotation;
  18069. WFIFOF(fd, 11) = latitude;
  18070. WFIFOSET(fd, packet_len(0xa78));
  18071. #endif
  18072. }
  18073. /// Activates or deactives the client camera info or updates the camera settings.
  18074. /// This packet is triggered by /viewpointvalue or /setcamera
  18075. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18076. void clif_parse_camerainfo( int fd, map_session_data* sd ){
  18077. char command[CHAT_SIZE_MAX];
  18078. // /viewpointvalue
  18079. if( RFIFOB( fd, 2 ) == 1 ){
  18080. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18081. // /setcamera
  18082. }else{
  18083. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18084. }
  18085. is_atcommand( fd, sd, command, 1 );
  18086. }
  18087. /// Send the full list of items in the equip switch window
  18088. /// 0a9b <length>.W { <index>.W <position>.L }*
  18089. void clif_equipswitch_list( map_session_data* sd ){
  18090. #if PACKETVER >= 20170208
  18091. int fd = sd->fd;
  18092. int offset, i, position;
  18093. WFIFOW(fd, 0) = 0xa9b;
  18094. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18095. short index = sd->equip_switch_index[i];
  18096. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18097. WFIFOW(fd, offset) = index + 2;
  18098. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18099. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18100. offset += 6;
  18101. }
  18102. }
  18103. WFIFOW(fd, 2) = offset;
  18104. WFIFOSET(fd, offset);
  18105. #endif
  18106. }
  18107. /// Acknowledgement for removing an equip to the equip switch window
  18108. /// 0a9a <index>.W <position.>.L <failure>.W
  18109. void clif_equipswitch_remove( map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18110. #if PACKETVER >= 20170208
  18111. int fd = sd->fd;
  18112. WFIFOHEAD(fd, packet_len(0xa9a));
  18113. WFIFOW(fd, 0) = 0xa9a;
  18114. WFIFOW(fd, 2) = index + 2;
  18115. WFIFOL(fd, 4) = pos;
  18116. WFIFOW(fd, 8) = failed;
  18117. WFIFOSET(fd, packet_len(0xa9a));
  18118. #endif
  18119. }
  18120. /// Request to remove an equip from the equip switch window
  18121. /// 0a99 <index>.W <position>.L <= 20170502
  18122. /// 0a99 <index>.W
  18123. void clif_parse_equipswitch_remove( int fd, map_session_data* sd ){
  18124. #if PACKETVER >= 20170208
  18125. uint16 index = RFIFOW(fd, 2) - 2;
  18126. bool removed = false;
  18127. if( !battle_config.feature_equipswitch ){
  18128. return;
  18129. }
  18130. // Check if the index is valid
  18131. if( index >= MAX_INVENTORY ){
  18132. return;
  18133. }
  18134. pc_equipswitch_remove( sd, index );
  18135. #endif
  18136. }
  18137. /// Acknowledgement for adding an equip to the equip switch window
  18138. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18139. /// 0a98 <index>.W <position.>.L <flag>.W
  18140. void clif_equipswitch_add( map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18141. #if PACKETVER >= 20170208
  18142. int fd = sd->fd;
  18143. WFIFOHEAD(fd, packet_len(0xa98));
  18144. WFIFOW(fd, 0) = 0xa98;
  18145. WFIFOW(fd, 2) = index + 2;
  18146. WFIFOL(fd, 4) = pos;
  18147. #if PACKETVER <= 20170502
  18148. WFIFOL(fd, 8) = flag;
  18149. #else
  18150. WFIFOW(fd, 8) = flag;
  18151. #endif
  18152. WFIFOSET(fd,packet_len(0xa98));
  18153. #endif
  18154. }
  18155. /// Request to add an equip to the equip switch window
  18156. /// 0a97 <index>.W <position>.L
  18157. void clif_parse_equipswitch_add( int fd, map_session_data* sd ){
  18158. #if PACKETVER >= 20170208
  18159. uint16 index = RFIFOW(fd, 2) - 2;
  18160. uint32 position = RFIFOL(fd, 4);
  18161. if( !battle_config.feature_equipswitch ){
  18162. return;
  18163. }
  18164. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18165. return;
  18166. }
  18167. if( sd->state.trading || sd->npc_shopid ){
  18168. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18169. return;
  18170. }
  18171. if( sd->inventory_data[index]->type == IT_AMMO ){
  18172. position = EQP_AMMO;
  18173. }
  18174. pc_equipitem( sd, index, position, true );
  18175. #endif
  18176. }
  18177. /// Acknowledgement packet for the full equip switch
  18178. /// 0a9d <failed>.W
  18179. void clif_equipswitch_reply( map_session_data* sd, bool failed ){
  18180. #if PACKETVER >= 20170208
  18181. int fd = sd->fd;
  18182. WFIFOHEAD(fd, packet_len(0xa9d));
  18183. WFIFOW(fd, 0) = 0xa9d;
  18184. WFIFOW(fd, 2) = failed;
  18185. WFIFOSET(fd, packet_len(0xa9d));
  18186. #endif
  18187. }
  18188. /// Request to do a full equip switch
  18189. /// 0a9c
  18190. void clif_parse_equipswitch_request( int fd, map_session_data* sd ){
  18191. #if PACKETVER >= 20170208
  18192. int i;
  18193. t_tick tick = gettick();
  18194. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18195. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18196. // Client will not let you send a request
  18197. return;
  18198. }
  18199. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18200. if( !battle_config.feature_equipswitch ){
  18201. return;
  18202. }
  18203. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18204. if( i == EQI_MAX ){
  18205. // client will show: "There is no item to replace." and should not even come here
  18206. clif_equipswitch_reply( sd, false );
  18207. return;
  18208. }
  18209. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18210. return;
  18211. }
  18212. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18213. #endif
  18214. }
  18215. /// Request to do a single equip switch
  18216. /// 0ace <index>.W
  18217. void clif_parse_equipswitch_request_single( int fd, map_session_data* sd ){
  18218. #if PACKETVER >= 20170502
  18219. uint16 index = RFIFOW(fd, 2) - 2;
  18220. if( !battle_config.feature_equipswitch ){
  18221. return;
  18222. }
  18223. // Check if the index is valid
  18224. if( index >= MAX_INVENTORY ){
  18225. return;
  18226. }
  18227. // Check if the item exists
  18228. if (sd->inventory_data[index] == nullptr)
  18229. return;
  18230. // Check if the item was already added to equip switch
  18231. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18232. if( sd->npc_id ){
  18233. #ifdef RENEWAL
  18234. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18235. clif_msg( sd, MSI_BUSY);
  18236. return;
  18237. }
  18238. #endif
  18239. if( !sd->npc_item_flag ){
  18240. return;
  18241. }
  18242. }
  18243. pc_equipswitch( sd, index );
  18244. return;
  18245. }
  18246. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18247. #endif
  18248. }
  18249. void clif_parse_StartUseSkillToId( int fd, map_session_data* sd ){
  18250. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18251. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18252. // Only rolling cutter is supported for now
  18253. if( p->skillId != GC_ROLLINGCUTTER ){
  18254. return;
  18255. }
  18256. // Already running - cant happen on officials, since only one skill is supported
  18257. if( sd->skill_keep_using.skill_id != 0 ){
  18258. return;
  18259. }
  18260. sd->skill_keep_using.tid = INVALID_TIMER;
  18261. sd->skill_keep_using.skill_id = p->skillId;
  18262. sd->skill_keep_using.level = p->skillLv;
  18263. sd->skill_keep_using.target = p->targetId;
  18264. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18265. #endif
  18266. }
  18267. void clif_parse_StopUseSkillToId( int fd, map_session_data* sd ){
  18268. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18269. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18270. // Not running
  18271. if( sd->skill_keep_using.skill_id == 0 ){
  18272. return;
  18273. }
  18274. #if 0
  18275. // Hack
  18276. if( p->skillId != sd->skill_keep_using.skill_id ){
  18277. return;
  18278. }
  18279. #endif
  18280. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18281. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18282. sd->skill_keep_using.tid = INVALID_TIMER;
  18283. }
  18284. sd->skill_keep_using.skill_id = 0;
  18285. sd->skill_keep_using.level = 0;
  18286. sd->skill_keep_using.target = 0;
  18287. #endif
  18288. }
  18289. void clif_ping( map_session_data* sd ){
  18290. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18291. nullpo_retv( sd );
  18292. int fd = sd->fd;
  18293. if( !session_isActive( fd ) ){
  18294. return;
  18295. }
  18296. struct PACKET_ZC_PING_LIVE p = {};
  18297. p.packetType = HEADER_ZC_PING_LIVE;
  18298. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18299. #endif
  18300. }
  18301. int clif_ping_timer_sub( map_session_data *sd, va_list ap ){
  18302. nullpo_ret( sd );
  18303. int fd = sd->fd;
  18304. if( !session_isActive( fd ) ){
  18305. return 0;
  18306. }
  18307. t_tick tick = va_arg( ap, t_tick );
  18308. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18309. clif_ping( sd );
  18310. }
  18311. return 0;
  18312. }
  18313. TIMER_FUNC( clif_ping_timer ){
  18314. map_foreachpc( clif_ping_timer_sub, gettick() );
  18315. return 0;
  18316. }
  18317. /**
  18318. * Opens the refine UI on the designated client.
  18319. * 0aa0
  18320. */
  18321. void clif_refineui_open( map_session_data* sd ){
  18322. #if PACKETVER >= 20161012
  18323. nullpo_retv( sd );
  18324. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18325. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18326. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18327. sd->state.refineui_open = true;
  18328. #endif
  18329. }
  18330. /**
  18331. * Parses cancel/close of the refine UI on client side.
  18332. * 0aa4
  18333. */
  18334. void clif_parse_refineui_close( int fd, map_session_data* sd ){
  18335. #if PACKETVER >= 20161012
  18336. sd->state.refineui_open = false;
  18337. #endif
  18338. }
  18339. /**
  18340. * Adds the selected item into the refine UI and sends the possible materials
  18341. * to the client.
  18342. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18343. */
  18344. void clif_refineui_info( map_session_data* sd, uint16 index ){
  18345. #if PACKETVER >= 20161012
  18346. int fd = sd->fd;
  18347. // Get the item db reference
  18348. struct item_data* id = sd->inventory_data[index];
  18349. // No item data was found
  18350. if( id == nullptr ){
  18351. return;
  18352. }
  18353. // Check the inventory
  18354. struct item* item = &sd->inventory.u.items_inventory[index];
  18355. // No item was found at the given index
  18356. if( item == nullptr ){
  18357. return;
  18358. }
  18359. // Check if the item is identified
  18360. if( !item->identify ){
  18361. return;
  18362. }
  18363. // Check if the item is broken
  18364. if( item->attribute ){
  18365. return;
  18366. }
  18367. PACKET_ZC_REFINING_MATERIAL_LIST* p = reinterpret_cast<PACKET_ZC_REFINING_MATERIAL_LIST*>( packet_buffer );
  18368. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18369. p->packetLength = sizeof( *p );
  18370. p->itemIndex = client_index( index );
  18371. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18372. // No possibilities were found
  18373. if( info == nullptr ){
  18374. p->blacksmithBlessing = 0;
  18375. }else{
  18376. p->blacksmithBlessing = static_cast<decltype(p->blacksmithBlessing)>( info->blessing_amount );
  18377. for( uint16 i = REFINE_COST_NORMAL, count = 0; i < REFINE_COST_MAX; i++ ){
  18378. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18379. if( cost == nullptr ){
  18380. continue;
  18381. }
  18382. PACKET_ZC_REFINING_MATERIAL_LIST_SUB& entry = p->req[count];
  18383. entry.itemId = client_nameid( cost->nameid );
  18384. entry.chance = static_cast<decltype(entry.chance)>( cost->chance / 100 );
  18385. entry.zeny = cost->zeny;
  18386. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  18387. count++;
  18388. }
  18389. }
  18390. clif_send( p, p->packetLength, &sd->bl, SELF );
  18391. #endif
  18392. }
  18393. /**
  18394. * Client request to add an item to the refine UI.
  18395. * 0aa1 <index>.W
  18396. */
  18397. void clif_parse_refineui_add( int fd, map_session_data* sd ){
  18398. #if PACKETVER >= 20161012
  18399. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18400. uint16 index = server_index( p->index );
  18401. // Check if the refine UI is open
  18402. if( !sd->state.refineui_open ){
  18403. return;
  18404. }
  18405. // Check if the index is valid
  18406. if( index >= MAX_INVENTORY ){
  18407. return;
  18408. }
  18409. // Send out the requirements for the refine process
  18410. clif_refineui_info( sd, index );
  18411. #endif
  18412. }
  18413. /**
  18414. * Client requests to try to refine an item.
  18415. * 0aa3 <index>.W <material>.W <catalyst>.B
  18416. */
  18417. void clif_parse_refineui_refine( int fd, map_session_data* sd ){
  18418. #if PACKETVER >= 20161012
  18419. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18420. uint16 index = server_index( p->index );
  18421. t_itemid material = p->itemId;
  18422. int16 j;
  18423. // Check if the refine UI is open
  18424. if( !sd->state.refineui_open ){
  18425. return;
  18426. }
  18427. // Check if the index is valid
  18428. if( index >= MAX_INVENTORY ){
  18429. return;
  18430. }
  18431. // Get the item db reference
  18432. struct item_data* id = sd->inventory_data[index];
  18433. // No item data was found
  18434. if( id == nullptr ){
  18435. return;
  18436. }
  18437. // Check the inventory
  18438. struct item* item = &sd->inventory.u.items_inventory[index];
  18439. // No item was found at the given index
  18440. if( item == nullptr ){
  18441. return;
  18442. }
  18443. // Check if the item is identified
  18444. if( !item->identify ){
  18445. return;
  18446. }
  18447. // Check if the item is broken
  18448. if( item->attribute ){
  18449. return;
  18450. }
  18451. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18452. // No refine possible
  18453. if( info == nullptr ){
  18454. return;
  18455. }
  18456. // No possibilities were found
  18457. if( info->costs.empty() ){
  18458. return;
  18459. }
  18460. // Check if the player has the selected material
  18461. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18462. return;
  18463. }
  18464. int16 blacksmith_index = -1;
  18465. uint16 blacksmith_amount = 0;
  18466. // Check if the player has enough blacksmith blessings
  18467. if( p->blacksmithBlessing != 0 ){
  18468. blacksmith_amount = info->blessing_amount;
  18469. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18470. if( blacksmith_amount == 0 ){
  18471. return;
  18472. }
  18473. // Check if the player has blacksmith blessings
  18474. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18475. return;
  18476. }
  18477. // Check if the player has enough blacksmith blessings
  18478. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18479. return;
  18480. }
  18481. }
  18482. std::shared_ptr<s_refine_cost> cost = nullptr;
  18483. for( const auto& pair : info->costs ){
  18484. if( pair.second->nameid == material ){
  18485. cost = pair.second;
  18486. break;
  18487. }
  18488. }
  18489. // The material was not in the list of possible materials
  18490. if( cost == nullptr ){
  18491. return;
  18492. }
  18493. // Try to pay for the refine
  18494. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME ) ){
  18495. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18496. return;
  18497. }
  18498. // Delete the required material
  18499. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18500. return;
  18501. }
  18502. // Delete the required blacksmith blessings
  18503. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18504. return;
  18505. }
  18506. // Try to refine the item
  18507. if( cost->chance >= ( rnd() % 10000 ) ){
  18508. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18509. // Success
  18510. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18511. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18512. clif_misceffect( sd->bl, NOTIFYEFFECT_REFINE_SUCCESS );
  18513. clif_refine( *sd, index, ITEMREFINING_SUCCESS );
  18514. if (info->broadcast_success) {
  18515. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18516. }
  18517. if( id->type == IT_WEAPON ){
  18518. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18519. }
  18520. clif_refineui_info( sd, index );
  18521. }else{
  18522. // Failure
  18523. if (info->broadcast_failure) {
  18524. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18525. }
  18526. // Blacksmith blessings were used to prevent breaking and downgrading
  18527. if( blacksmith_amount > 0 ){
  18528. clif_refine( *sd, index, ITEMREFINING_FAILURE2 );
  18529. clif_refineui_info( sd, index );
  18530. // Delete the item if it is breakable
  18531. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18532. clif_refine( *sd, index, ITEMREFINING_FAILURE );
  18533. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18534. // Downgrade the item if necessary
  18535. }else if( cost->downgrade_amount > 0 ){
  18536. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18537. clif_refine( *sd, index, ITEMREFINING_DOWNGRADE );
  18538. clif_refineui_info(sd, index);
  18539. // Only show failure, but dont do anything
  18540. }else{
  18541. clif_refine( *sd, index, ITEMREFINING_FAILURE2 );
  18542. clif_refineui_info( sd, index );
  18543. }
  18544. clif_misceffect( sd->bl, NOTIFYEFFECT_REFINE_FAILURE );
  18545. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18546. }
  18547. #endif
  18548. }
  18549. void clif_unequipall_reply( map_session_data* sd, bool failed ){
  18550. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18551. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18552. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18553. p.result = failed;
  18554. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18555. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18556. }
  18557. void clif_parse_unequipall( int fd, map_session_data* sd ){
  18558. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18559. if( pc_cant_act( sd ) ){
  18560. clif_unequipall_reply( sd, true );
  18561. return;
  18562. }
  18563. struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL* p = (struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL*)RFIFOP( fd, 0 );
  18564. #if PACKETVER_MAIN_NUM >= 20230906
  18565. uint32 location = p->location;
  18566. int max = EQI_MAX;
  18567. #else
  18568. uint32 location = 0xFFFFFFFF;
  18569. int max = EQI_COSTUME_HEAD_TOP;
  18570. #endif
  18571. for( int i = 0; i < max; i++ ){
  18572. if( sd->equip_index[i] >= 0 && ( location & equip_bitmask[i] ) != 0 ){
  18573. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18574. }
  18575. }
  18576. clif_unequipall_reply( sd, false );
  18577. #endif
  18578. }
  18579. void clif_stylist_response( map_session_data* sd, bool failed ){
  18580. #if PACKETVER >= 20151104
  18581. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18582. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18583. p.flag = failed;
  18584. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18585. if( !failed ){
  18586. sd->state.stylist_open = false;
  18587. }
  18588. #endif
  18589. }
  18590. bool clif_parse_stylist_buy_sub( map_session_data* sd, _look look, int16 index ){
  18591. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18592. if( list == nullptr ){
  18593. return false;
  18594. }
  18595. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18596. if( entry == nullptr ){
  18597. return false;
  18598. }
  18599. std::shared_ptr<s_stylist_costs> costs;
  18600. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18601. costs = entry->doram;
  18602. }else{
  18603. costs = entry->human;
  18604. }
  18605. if( costs == nullptr ){
  18606. return false;
  18607. }
  18608. if( sd->status.zeny < costs->price ){
  18609. return false;
  18610. }
  18611. int16 inventoryIndex = -1;
  18612. if( costs->requiredItem != 0 ){
  18613. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18614. if( inventoryIndex < 0 ){
  18615. // No other option
  18616. if( costs->requiredItemBox == 0 ){
  18617. return false;
  18618. }
  18619. // Check if the box that contains the item is in the inventory
  18620. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18621. // The box containing the item also does not exist
  18622. if( inventoryIndex < 0 ){
  18623. return false;
  18624. }
  18625. }
  18626. }else if( costs->requiredItemBox != 0 ){
  18627. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18628. if( inventoryIndex < 0 ){
  18629. return false;
  18630. }
  18631. }
  18632. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18633. return false;
  18634. }
  18635. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER ) != 0 ){
  18636. return false;
  18637. }
  18638. switch( look ){
  18639. case LOOK_HAIR:
  18640. case LOOK_HAIR_COLOR:
  18641. case LOOK_CLOTHES_COLOR:
  18642. case LOOK_BODY2:
  18643. pc_changelook( sd, look, entry->value );
  18644. break;
  18645. case LOOK_HEAD_BOTTOM:
  18646. case LOOK_HEAD_MID:
  18647. case LOOK_HEAD_TOP: {
  18648. struct mail_message msg = {};
  18649. msg.dest_id = sd->status.char_id;
  18650. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18651. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18652. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18653. msg.item[0].nameid = entry->value;
  18654. msg.item[0].identify = 1;
  18655. msg.item[0].amount = 1;
  18656. msg.status = MAIL_NEW;
  18657. msg.type = MAIL_INBOX_NORMAL;
  18658. msg.timestamp = time( nullptr );
  18659. intif_Mail_send( 0, &msg );
  18660. } break;
  18661. }
  18662. return true;
  18663. }
  18664. void clif_parse_stylist_buy( int fd, map_session_data* sd ){
  18665. #if PACKETVER >= 20151104
  18666. #if PACKETVER >= 20180516
  18667. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18668. #else
  18669. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18670. #endif
  18671. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18672. clif_stylist_response( sd, true );
  18673. return;
  18674. }
  18675. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18676. clif_stylist_response( sd, true );
  18677. return;
  18678. }
  18679. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18680. clif_stylist_response( sd, true );
  18681. return;
  18682. }
  18683. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18684. clif_stylist_response( sd, true );
  18685. return;
  18686. }
  18687. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18688. clif_stylist_response( sd, true );
  18689. return;
  18690. }
  18691. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18692. clif_stylist_response( sd, true );
  18693. return;
  18694. }
  18695. #if PACKETVER >= 20180516
  18696. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18697. clif_stylist_response( sd, true );
  18698. return;
  18699. }
  18700. #endif
  18701. clif_stylist_response( sd, false );
  18702. #endif
  18703. }
  18704. void clif_parse_stylist_close( int fd, map_session_data* sd ){
  18705. #if PACKETVER >= 20151104
  18706. sd->state.stylist_open = false;
  18707. #endif
  18708. }
  18709. void clif_inventory_expansion_info( map_session_data* sd ){
  18710. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18711. nullpo_retv( sd );
  18712. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18713. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18714. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18715. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18716. #endif
  18717. }
  18718. enum class e_inventory_expansion_response : uint8{
  18719. ASK_CONFIRMATION = 0,
  18720. FAILED,
  18721. BUSY,
  18722. MISSING_ITEM,
  18723. MAXIMUM_REACHED
  18724. };
  18725. void clif_inventory_expansion_response( map_session_data* sd, e_inventory_expansion_response response ){
  18726. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18727. nullpo_retv( sd );
  18728. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18729. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18730. p.result = (uint8)response;
  18731. p.itemId = sd->state.inventory_expansion_confirmation;
  18732. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18733. #endif
  18734. }
  18735. void clif_parse_inventory_expansion_request( int fd, map_session_data* sd ){
  18736. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18737. // Check if player is dead or busy with other stuff
  18738. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18739. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18740. return;
  18741. }
  18742. // Check if the player already reached the maximum
  18743. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18744. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18745. return;
  18746. }
  18747. static std::map<t_itemid, uint16> items = {
  18748. // The order of entries in this list defines which will be used first
  18749. // This order and the usable items are hardcoded into the client
  18750. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18751. { ITEMID_INVENTORY_EX_EVT, 10 },
  18752. { ITEMID_INVENTORY_EX_DIS, 10 },
  18753. { ITEMID_INVENTORY_EX, 10 },
  18754. };
  18755. int16 index = -1;
  18756. bool found_over_limit = false;
  18757. for( const auto& entry : items ){
  18758. // Check if the player has the required item
  18759. index = pc_search_inventory( sd, entry.first );
  18760. // Found an item
  18761. if( index >= 0 ){
  18762. // Check if the player would exceed the maximum
  18763. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18764. found_over_limit = true;
  18765. }else{
  18766. found_over_limit = false;
  18767. sd->state.inventory_expansion_confirmation = entry.first;
  18768. sd->state.inventory_expansion_amount = entry.second;
  18769. break;
  18770. }
  18771. }
  18772. }
  18773. // Check if an item was found
  18774. if( sd->state.inventory_expansion_confirmation == 0 ){
  18775. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18776. return;
  18777. }
  18778. // Check if an item would have been found, but the player would exceed the maximum
  18779. if( found_over_limit ){
  18780. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18781. return;
  18782. }
  18783. // The player met all requirements => ask him for confirmation
  18784. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18785. #endif
  18786. }
  18787. enum class e_inventory_expansion_result : uint8{
  18788. SUCCESS = 0,
  18789. FAILED,
  18790. BUSY,
  18791. MISSING_ITEM,
  18792. MAXIMUM_REACHED
  18793. };
  18794. void clif_inventory_expansion_result( map_session_data* sd, e_inventory_expansion_result result ){
  18795. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18796. nullpo_retv( sd );
  18797. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18798. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18799. p.result = (uint8)result;
  18800. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18801. // Reset the state tracking
  18802. sd->state.inventory_expansion_confirmation = 0;
  18803. sd->state.inventory_expansion_amount = 0;
  18804. #endif
  18805. }
  18806. void clif_parse_inventory_expansion_confirm( int fd, map_session_data* sd ){
  18807. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18808. if( sd->state.inventory_expansion_confirmation == 0 ){
  18809. return;
  18810. }
  18811. // Check if player is dead
  18812. if( pc_isdead( sd ) ){
  18813. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18814. return;
  18815. }
  18816. // Check if the player already reached the maximum
  18817. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18818. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18819. return;
  18820. }
  18821. // Check if the player has the required item
  18822. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18823. // The player did not have the item anymore
  18824. if( index < 0 ){
  18825. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18826. return;
  18827. }
  18828. // Check if the player would exceed the maximum
  18829. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18830. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18831. return;
  18832. }
  18833. // Delete the required item
  18834. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18835. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18836. return;
  18837. }
  18838. // Increase the slots
  18839. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18840. // Save player data (slots) and inventory data (removed item)
  18841. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18842. // Inform the player of success
  18843. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18844. clif_inventory_expansion_info( sd );
  18845. #endif
  18846. }
  18847. void clif_parse_inventory_expansion_reject( int fd, map_session_data* sd ){
  18848. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18849. sd->state.inventory_expansion_confirmation = 0;
  18850. sd->state.inventory_expansion_amount = 0;
  18851. #endif
  18852. }
  18853. void clif_barter_open( map_session_data& sd, struct npc_data& nd ){
  18854. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18855. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18856. return;
  18857. }
  18858. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18859. if( barter == nullptr ){
  18860. return;
  18861. }
  18862. sd.state.barter_open = true;
  18863. PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = reinterpret_cast<PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*>( packet_buffer );
  18864. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18865. p->packetLength = sizeof( *p );
  18866. int16 count = 0;
  18867. for( const auto& itemPair : barter->items ){
  18868. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18869. if( id == nullptr ){
  18870. continue;
  18871. }
  18872. PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub& item = p->list[count];
  18873. item.nameid = client_nameid( id->nameid );
  18874. item.type = itemtype( id->nameid );
  18875. if( itemPair.second->stockLimited ){
  18876. item.amount = itemPair.second->stock;
  18877. }else{
  18878. item.amount = -1;
  18879. }
  18880. item.weight = id->weight;
  18881. item.index = itemPair.second->index;
  18882. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18883. item.viewSprite = id->look;
  18884. item.location = pc_equippoint_sub( &sd, id.get() );
  18885. #endif
  18886. // Use a loop if someone did not start with index 0
  18887. for( const auto& requirementPair : itemPair.second->requirements ){
  18888. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18889. item.currencyNameid = client_nameid( requirement->nameid );
  18890. item.currencyAmount = requirement->amount;
  18891. // It is a normal barter, cancel after first entry
  18892. break;
  18893. }
  18894. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( item ) );
  18895. count++;
  18896. }
  18897. clif_send( p, p->packetLength, &sd.bl, SELF );
  18898. #endif
  18899. }
  18900. void clif_parse_barter_close( int fd, map_session_data* sd ){
  18901. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18902. if( sd->state.barter_open ){
  18903. sd->npc_shopid = 0;
  18904. sd->state.barter_open = false;
  18905. }
  18906. #endif
  18907. }
  18908. void clif_parse_barter_buy( int fd, map_session_data* sd ){
  18909. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18910. // No shop open
  18911. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  18912. return;
  18913. }
  18914. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18915. // Unknown shop
  18916. if( nd == nullptr ){
  18917. return;
  18918. }
  18919. // Not a barter
  18920. if( nd->subtype != NPCTYPE_BARTER ){
  18921. return;
  18922. }
  18923. // It is an extended barter
  18924. if( nd->u.barter.extended ){
  18925. return;
  18926. }
  18927. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  18928. if( barter == nullptr ){
  18929. return;
  18930. }
  18931. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  18932. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  18933. // Empty purchase list
  18934. if( entries == 0 ){
  18935. return;
  18936. }
  18937. std::vector<s_barter_purchase> purchases;
  18938. purchases.reserve( entries );
  18939. // Make sure each shop index and target item id is only used once
  18940. for( int i = 0; i < entries; i++ ){
  18941. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  18942. // Invalid shop index
  18943. if( item == nullptr ){
  18944. return;
  18945. }
  18946. for( int j = i + 1; j < entries; j++ ){
  18947. // Same shop index
  18948. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  18949. return;
  18950. }
  18951. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  18952. // Invalid shop index
  18953. if( item2 == nullptr ){
  18954. return;
  18955. }
  18956. // Same target item id
  18957. if( item->nameid == item2->nameid ){
  18958. return;
  18959. }
  18960. }
  18961. s_barter_purchase purchase = {};
  18962. purchase.item = item;
  18963. purchase.amount = p->list[i].amount;
  18964. purchases.push_back( purchase );
  18965. }
  18966. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  18967. #endif
  18968. }
  18969. void clif_barter_extended_open( map_session_data& sd, struct npc_data& nd ){
  18970. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18971. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  18972. return;
  18973. }
  18974. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18975. if( barter == nullptr ){
  18976. return;
  18977. }
  18978. sd.state.barter_extended_open = true;
  18979. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*>( packet_buffer );
  18980. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  18981. p->packetLength = sizeof( *p );
  18982. p->items_count = 0;
  18983. for( const auto& itemPair : barter->items ){
  18984. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18985. if( id == nullptr ){
  18986. continue;
  18987. }
  18988. // Needs dynamic calculation, because of variable currencies
  18989. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*>( WBUFP( p, p->packetLength ) );
  18990. item->nameid = client_nameid( id->nameid );
  18991. item->type = itemtype( id->nameid );
  18992. if( itemPair.second->stockLimited ){
  18993. item->amount = itemPair.second->stock;
  18994. }else{
  18995. item->amount = -1;
  18996. }
  18997. item->weight = id->weight;
  18998. item->index = itemPair.second->index;
  18999. item->zeny = itemPair.second->price;
  19000. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19001. item->viewSprite = id->look;
  19002. item->location = pc_equippoint_sub( &sd, id.get() );
  19003. #endif
  19004. // Because of a MSVS bug, the currencies have been defined with a fixed array entry, which has to be substracted
  19005. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( *item ) - sizeof( item->currencies ) );
  19006. p->items_count++;
  19007. item->currency_count = 0;
  19008. for( const auto& requirementPair : itemPair.second->requirements ){
  19009. // Needs dynamic calculation, because of variable currencies
  19010. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*>( WBUFP( p, p->packetLength ) );
  19011. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19012. req->nameid = requirement->nameid;
  19013. if( requirement->refine >= 0 ){
  19014. req->refine_level = requirement->refine;
  19015. }else{
  19016. req->refine_level = 0;
  19017. }
  19018. req->amount = requirement->amount;
  19019. req->type = itemtype( requirement->nameid );
  19020. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( *req ) );
  19021. item->currency_count++;
  19022. }
  19023. }
  19024. clif_send( p, p->packetLength, &sd.bl, SELF );
  19025. #endif
  19026. }
  19027. void clif_parse_barter_extended_close( int fd, map_session_data* sd ){
  19028. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19029. if( sd->state.barter_extended_open ){
  19030. sd->npc_shopid = 0;
  19031. sd->state.barter_extended_open = false;
  19032. }
  19033. #endif
  19034. }
  19035. void clif_parse_barter_extended_buy( int fd, map_session_data* sd ){
  19036. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19037. // No shop open
  19038. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19039. return;
  19040. }
  19041. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19042. // Unknown shop
  19043. if( nd == nullptr ){
  19044. return;
  19045. }
  19046. // Not a barter
  19047. if( nd->subtype != NPCTYPE_BARTER ){
  19048. return;
  19049. }
  19050. // Not an extended barter
  19051. if( !nd->u.barter.extended ){
  19052. return;
  19053. }
  19054. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19055. if( barter == nullptr ){
  19056. return;
  19057. }
  19058. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19059. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19060. // Empty purchase list
  19061. if( entries == 0 ){
  19062. return;
  19063. }
  19064. std::vector<s_barter_purchase> purchases;
  19065. purchases.reserve( entries );
  19066. // Make sure each shop index and target item id is only used once
  19067. for( int i = 0; i < entries; i++ ){
  19068. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19069. // Invalid shop index
  19070. if( item == nullptr ){
  19071. return;
  19072. }
  19073. for( int j = i + 1; j < entries; j++ ){
  19074. // Same shop index
  19075. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19076. return;
  19077. }
  19078. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19079. // Invalid shop index
  19080. if( item2 == nullptr ){
  19081. return;
  19082. }
  19083. // Same target item id
  19084. if( item->nameid == item2->nameid ){
  19085. return;
  19086. }
  19087. }
  19088. s_barter_purchase purchase = {};
  19089. purchase.item = item;
  19090. purchase.amount = p->list[i].amount;
  19091. purchases.push_back( purchase );
  19092. }
  19093. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19094. #endif
  19095. }
  19096. void clif_summon_init(struct mob_data& md) {
  19097. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19098. struct block_list* master_bl = battle_get_master(&md.bl);
  19099. if( master_bl == nullptr ){
  19100. return;
  19101. }
  19102. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19103. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19104. p.summonAID = md.bl.id;
  19105. p.CurrentHP = md.status.hp;
  19106. p.MaxHP = md.status.max_hp;
  19107. clif_send( &p, sizeof( p ), master_bl, SELF );
  19108. #endif
  19109. }
  19110. void clif_summon_hp_bar(struct mob_data& md) {
  19111. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19112. struct block_list* master_bl = battle_get_master(&md.bl);
  19113. if( master_bl == nullptr ){
  19114. return;
  19115. }
  19116. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19117. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19118. p.summonAID = md.bl.id;
  19119. p.VarId = SP_HP; // HP parameter
  19120. p.Value = md.status.hp;
  19121. clif_send( &p, sizeof( p ), master_bl, SELF );
  19122. #endif
  19123. }
  19124. void clif_laphine_synthesis_open( map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19125. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19126. nullpo_retv( sd );
  19127. sd->state.laphine_synthesis = synthesis->item_id;
  19128. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19129. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19130. p.itemId = client_nameid( synthesis->item_id );
  19131. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19132. #endif
  19133. }
  19134. void clif_parse_laphine_synthesis_close( int fd, map_session_data* sd ){
  19135. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19136. sd->state.laphine_synthesis = 0;
  19137. #endif
  19138. }
  19139. enum e_laphine_synthesis_result : int16{
  19140. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19141. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19142. LAPHINE_SYNTHESIS_ITEM = 7
  19143. };
  19144. void clif_laphine_synthesis_result( map_session_data* sd, enum e_laphine_synthesis_result result ){
  19145. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19146. nullpo_retv( sd );
  19147. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19148. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19149. p.result = result;
  19150. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19151. #endif
  19152. }
  19153. void clif_parse_laphine_synthesis( int fd, map_session_data* sd ){
  19154. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19155. if( sd->state.laphine_synthesis == 0 ){
  19156. return;
  19157. }
  19158. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19159. if( sd->state.laphine_synthesis != p->itemId ){
  19160. return;
  19161. }
  19162. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19163. if( synthesis == nullptr ){
  19164. return;
  19165. }
  19166. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19167. // Player sent more or less than actually required
  19168. if( count != synthesis->requiredRequirements ){
  19169. return;
  19170. }
  19171. // Check for duplicates
  19172. for( size_t i = 0; i < count; i++ ){
  19173. for( size_t j = i + 1; j < count; j++ ){
  19174. if( p->items[i].index == p->items[j].index ){
  19175. return;
  19176. }
  19177. }
  19178. }
  19179. for( size_t i = 0; i < count; i++ ){
  19180. int16 index = server_index( p->items[i].index );
  19181. if( index >= MAX_INVENTORY ){
  19182. return;
  19183. }
  19184. if( sd->inventory_data[index] == nullptr ){
  19185. return;
  19186. }
  19187. struct item* item = &sd->inventory.u.items_inventory[index];
  19188. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19189. if( requirement == nullptr ){
  19190. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19191. return;
  19192. }
  19193. if( p->items[i].count != requirement->amount ){
  19194. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19195. return;
  19196. }
  19197. if( item->amount < requirement->amount ){
  19198. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19199. return;
  19200. }
  19201. if( item->refine < synthesis->minimumRefine ){
  19202. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19203. return;
  19204. }
  19205. if( item->refine > synthesis->maximumRefine ){
  19206. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19207. return;
  19208. }
  19209. if( item->equip != 0 ){
  19210. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19211. return;
  19212. }
  19213. if( item->equipSwitch != 0 ){
  19214. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19215. return;
  19216. }
  19217. }
  19218. // If triggered from item
  19219. if( sd->itemid == sd->state.laphine_synthesis ){
  19220. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19221. if( index < 0 ){
  19222. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19223. return;
  19224. }
  19225. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19226. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19227. return;
  19228. }
  19229. }
  19230. }
  19231. for( size_t i = 0; i < count; i++ ){
  19232. int16 index = server_index( p->items[i].index );
  19233. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19234. return;
  19235. }
  19236. }
  19237. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19238. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19239. #endif
  19240. }
  19241. void clif_laphine_upgrade_open( map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19242. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19243. nullpo_retv( sd );
  19244. sd->state.laphine_upgrade = upgrade->item_id;
  19245. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19246. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19247. p.itemId = client_nameid( upgrade->item_id );
  19248. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19249. #endif
  19250. }
  19251. void clif_parse_laphine_upgrade_close( int fd, map_session_data* sd ){
  19252. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19253. sd->state.laphine_upgrade = 0;
  19254. #endif
  19255. }
  19256. void clif_laphine_upgrade_result( map_session_data *sd, bool failed ){
  19257. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19258. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19259. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19260. p.result = failed;
  19261. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19262. #endif
  19263. }
  19264. static void clif_item_preview( map_session_data *sd, int16 index ){
  19265. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19266. nullpo_retv( sd );
  19267. struct item* item = &sd->inventory.u.items_inventory[index];
  19268. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19269. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19270. p.index = client_index( index );
  19271. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19272. p.isDamaged = item->attribute != 0;
  19273. #endif
  19274. p.refiningLevel = item->refine;
  19275. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19276. p.grade = item->enchantgrade;
  19277. #endif
  19278. clif_addcards( &p.slot, item );
  19279. clif_add_random_options( p.option_data, *item );
  19280. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19281. #endif
  19282. }
  19283. void clif_parse_laphine_upgrade( int fd, map_session_data* sd ){
  19284. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19285. if( sd->state.laphine_upgrade == 0 ){
  19286. return;
  19287. }
  19288. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19289. if( sd->state.laphine_upgrade != p->itemId ){
  19290. return;
  19291. }
  19292. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19293. if( upgrade == nullptr ){
  19294. return;
  19295. }
  19296. uint16 index = server_index( p->index );
  19297. if( index >= MAX_INVENTORY ){
  19298. return;
  19299. }
  19300. if( sd->inventory_data[index] == nullptr ){
  19301. return;
  19302. }
  19303. struct item* item = &sd->inventory.u.items_inventory[index];
  19304. // Not a valid target item
  19305. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19306. clif_laphine_upgrade_result( sd, true );
  19307. return;
  19308. }
  19309. // If target item is not identified
  19310. if( item->identify == 0 ){
  19311. clif_laphine_upgrade_result( sd, true );
  19312. return;
  19313. }
  19314. // If target item is equipped
  19315. if( item->equip != 0 ){
  19316. clif_laphine_upgrade_result( sd, true );
  19317. return;
  19318. }
  19319. // If target item is in equipswitch
  19320. if( item->equipSwitch != 0 ){
  19321. clif_laphine_upgrade_result( sd, true );
  19322. return;
  19323. }
  19324. // Check minimum refine requirement
  19325. if( item->refine < upgrade->minimumRefine ){
  19326. clif_laphine_upgrade_result( sd, true );
  19327. return;
  19328. }
  19329. // Check maximum refine requirement
  19330. if( item->refine > upgrade->maximumRefine ){
  19331. clif_laphine_upgrade_result( sd, true );
  19332. return;
  19333. }
  19334. // If no cards are allowed
  19335. if( !upgrade->cardsAllowed ){
  19336. for( int i = 0; i < MAX_SLOTS; i++ ){
  19337. if( item->card[i] != 0 ){
  19338. clif_laphine_upgrade_result( sd, true );
  19339. return;
  19340. }
  19341. }
  19342. }
  19343. // If random options are required
  19344. if( upgrade->requiredRandomOptions > 0 ){
  19345. int i;
  19346. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19347. if( item->option[i].id != 0 ){
  19348. break;
  19349. }
  19350. }
  19351. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19352. clif_laphine_upgrade_result( sd, true );
  19353. return;
  19354. }
  19355. }
  19356. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19357. if( index2 < 0 ){
  19358. clif_laphine_upgrade_result( sd, true );
  19359. return;
  19360. }
  19361. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19362. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19363. return;
  19364. }
  19365. }
  19366. // Log removal of item
  19367. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19368. // Visually remove it from the client
  19369. clif_delitem( *sd, index, 1, 0 );
  19370. // Apply the random options
  19371. if( upgrade->randomOptionGroup != nullptr ){
  19372. upgrade->randomOptionGroup->apply( *item );
  19373. }
  19374. // Change the refine rate if needed
  19375. if( upgrade->resultRefine > 0 ){
  19376. // Absolute refine level change
  19377. item->refine = max( item->refine, upgrade->resultRefine );
  19378. }else if( upgrade->resultRefineMaximum > 0 ){
  19379. // If a minimum is specified it can also downgrade
  19380. if( upgrade->resultRefineMinimum ){
  19381. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum ) );
  19382. }else{
  19383. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19384. item->refine = static_cast<uint8>( rnd_value<uint16>( item->refine, upgrade->resultRefineMaximum ) );
  19385. }
  19386. }else if( upgrade->resultRefineMinimum > 0 ){
  19387. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19388. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, MAX_REFINE ) );
  19389. }
  19390. // Log retrieving the item again -> with the new options
  19391. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19392. // Make it visible for the client again
  19393. clif_additem( sd, index, 1, 0 );
  19394. // Open a preview of the item
  19395. clif_item_preview( sd, index );
  19396. // Tell the client we are done
  19397. clif_laphine_upgrade_result( sd, false );
  19398. #endif
  19399. }
  19400. void clif_enchantgrade_add( map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19401. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19402. PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = reinterpret_cast<PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*>( packet_buffer );
  19403. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19404. p->PacketLength = sizeof( *p );
  19405. if( index < UINT16_MAX ){
  19406. p->index = client_index( index );
  19407. p->success_chance = gradeLevel->chances[sd.inventory.u.items_inventory[index].refine] / 100;
  19408. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19409. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19410. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19411. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19412. // Not displayed by client
  19413. p->protect_itemid = 0;
  19414. p->protect_amount = 0;
  19415. int i = 0;
  19416. for( const auto& pair : gradeLevel->options ){
  19417. GRADE_ENCHANT_MATERIAL& mat = p->material_info[i];
  19418. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19419. mat.nameid = client_nameid( option->item );
  19420. mat.amount = option->amount;
  19421. mat.price = option->zeny;
  19422. mat.downgrade = option->downgrade_amount > 0;
  19423. mat.breakable = option->breaking_rate > 0;
  19424. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( mat ) );
  19425. i++;
  19426. }
  19427. }else{
  19428. p->index = -1;
  19429. p->success_chance = 0;
  19430. p->blessing_info.id = 0;
  19431. p->blessing_info.amount = 0;
  19432. p->blessing_info.max_blessing = 0;
  19433. p->blessing_info.bonus = 0;
  19434. p->protect_itemid = 0;
  19435. p->protect_amount = 0;
  19436. }
  19437. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19438. #endif
  19439. }
  19440. void clif_parse_enchantgrade_add( int fd, map_session_data* sd ){
  19441. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19442. nullpo_retv( sd );
  19443. if( !sd->state.enchantgrade_open ){
  19444. return;
  19445. }
  19446. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19447. uint16 index = server_index( p->index );
  19448. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19449. return;
  19450. }
  19451. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19452. // Unsupported item type - no answer, because client should have actually prevented this request
  19453. if( enchantgrade == nullptr ){
  19454. return;
  19455. }
  19456. // Item can't be enhanced
  19457. if( !sd->inventory_data[index]->flag.gradable ){
  19458. return;
  19459. }
  19460. uint16 level = 0;
  19461. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19462. level = sd->inventory_data[index]->weapon_level;
  19463. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19464. level = sd->inventory_data[index]->armor_level;
  19465. }
  19466. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19467. // Cannot upgrade this weapon or armor level
  19468. if( enchantgradelevels == enchantgrade->levels.end() ){
  19469. clif_enchantgrade_add( *sd );
  19470. return;
  19471. }
  19472. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19473. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19474. if( enchantgradelevel == nullptr ){
  19475. return;
  19476. }
  19477. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19478. #endif
  19479. }
  19480. /// <summary>
  19481. /// Sends the result for trying to enchant an item
  19482. /// </summary>
  19483. /// <param name="sd">The player session</param>
  19484. /// <param name="index">The target item</param>
  19485. /// <param name="result">
  19486. /// 0= The grade has been successfully upgraded.
  19487. /// 1= Refinement failed.
  19488. /// 2= The refine level has decreased.
  19489. /// 3= Equipment destroyed.
  19490. /// 4= The equipment is protected.
  19491. /// </param>
  19492. void clif_enchantgrade_result( map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19493. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19494. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19495. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19496. p.index = client_index( index );
  19497. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19498. p.result = result;
  19499. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19500. #endif
  19501. }
  19502. void clif_enchantgrade_announce( map_session_data& sd, struct item& item, bool success ){
  19503. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19504. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19505. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19506. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19507. p.itemId = client_nameid( item.nameid );
  19508. p.grade = item.enchantgrade;
  19509. p.status = success;
  19510. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19511. #endif
  19512. }
  19513. void clif_parse_enchantgrade_start( int fd, map_session_data* sd ){
  19514. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19515. nullpo_retv( sd );
  19516. if( !sd->state.enchantgrade_open ){
  19517. return;
  19518. }
  19519. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19520. uint16 index = server_index( p->index );
  19521. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19522. return;
  19523. }
  19524. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19525. // Unsupported item type - no answer
  19526. if( enchantgrade == nullptr ){
  19527. return;
  19528. }
  19529. uint16 level = 0;
  19530. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19531. level = sd->inventory_data[index]->weapon_level;
  19532. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19533. level = sd->inventory_data[index]->armor_level;
  19534. }
  19535. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19536. // Cannot upgrade this weapon or armor level - no answer
  19537. if( enchantgradelevels == enchantgrade->levels.end() ){
  19538. return;
  19539. }
  19540. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19541. // Cannot increase enchantgrade any further - no answer
  19542. if( enchantgradelevel == nullptr ){
  19543. return;
  19544. }
  19545. uint16 totalChance = enchantgradelevel->chances[sd->inventory.u.items_inventory[index].refine];
  19546. // No chance to increase the enchantgrade
  19547. if( totalChance == 0 ){
  19548. return;
  19549. }
  19550. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19551. // Unknown option id - no answer
  19552. if( option == nullptr ){
  19553. return;
  19554. }
  19555. // Not enough zeny
  19556. if( sd->status.zeny < option->zeny ){
  19557. return;
  19558. }
  19559. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19560. std::unordered_map<uint16, uint16> requiredItems;
  19561. if( p->blessing_flag ){
  19562. // If the catalysator item is the same as the option item build the sum of amounts
  19563. if( enchantgradelevel->catalyst.item == option->item ){
  19564. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19565. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19566. if( index < 0 ){
  19567. return;
  19568. }
  19569. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19570. return;
  19571. }
  19572. requiredItems[index] = amount;
  19573. }else{
  19574. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19575. // Check catalysator item
  19576. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19577. if( index < 0 ){
  19578. return;
  19579. }
  19580. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19581. return;
  19582. }
  19583. requiredItems[index] = amount;
  19584. // Check option item
  19585. index = pc_search_inventory( sd, option->item );
  19586. if( index < 0 ){
  19587. return;
  19588. }
  19589. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19590. return;
  19591. }
  19592. requiredItems[index] = option->amount;
  19593. }
  19594. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19595. }else{
  19596. // Check option item
  19597. int16 index = pc_search_inventory( sd, option->item );
  19598. if( index < 0 ){
  19599. return;
  19600. }
  19601. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19602. return;
  19603. }
  19604. requiredItems[index] = option->amount;
  19605. }
  19606. // All items should be there, start deleting
  19607. for( const auto& pair : requiredItems ){
  19608. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19609. return;
  19610. }
  19611. }
  19612. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE ) > 0 ){
  19613. return;
  19614. }
  19615. if( rnd()%10000 < totalChance ){
  19616. // Log removal of item
  19617. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19618. // Increase enchantgrade
  19619. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19620. // On successful enchantgrade increase the refine is reset
  19621. sd->inventory.u.items_inventory[index].refine = 0;
  19622. // Log retrieving the item again -> with the new refine and enchantgrade
  19623. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19624. // Show success
  19625. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19626. // Check if it has to be announced
  19627. if( enchantgradelevel->announceSuccess ){
  19628. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19629. }
  19630. }else{
  19631. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19632. if( enchantgradelevel->announceFail ){
  19633. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19634. }
  19635. // Delete the item if it is breakable
  19636. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19637. // Delete the item
  19638. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19639. // Show failure
  19640. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19641. // Downgrade the item if necessary
  19642. }else if( option->downgrade_amount > 0 ){
  19643. // Log removal of item
  19644. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19645. // Decrease refine level
  19646. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19647. // Log retrieving the item again -> with the new refine
  19648. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19649. // Show downgrade
  19650. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19651. // Only show failure, but dont do anything
  19652. }else{
  19653. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19654. }
  19655. }
  19656. #endif
  19657. }
  19658. void clif_parse_enchantgrade_close( int fd, map_session_data* sd ){
  19659. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19660. nullpo_retv( sd );
  19661. sd->state.enchantgrade_open = false;
  19662. #endif
  19663. }
  19664. void clif_reputation_type( map_session_data& sd, int64 type, int64 points ){
  19665. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19666. PACKET_ZC_REPUTE_INFO* p = reinterpret_cast<PACKET_ZC_REPUTE_INFO*>( packet_buffer );
  19667. p->packetType = HEADER_ZC_REPUTE_INFO;
  19668. p->packetLength = sizeof( *p );
  19669. p->success = true;
  19670. PACKET_ZC_REPUTE_INFO_sub& entry = p->list[0];
  19671. entry.type = type;
  19672. entry.points = points;
  19673. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  19674. clif_send( p, p->packetLength, &sd.bl, SELF );
  19675. #endif
  19676. }
  19677. void clif_reputation_list( map_session_data& sd ){
  19678. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19679. PACKET_ZC_REPUTE_INFO* p = reinterpret_cast<PACKET_ZC_REPUTE_INFO*>( packet_buffer );
  19680. p->packetType = HEADER_ZC_REPUTE_INFO;
  19681. p->packetLength = sizeof( *p );
  19682. p->success = true;
  19683. size_t index = 0;
  19684. for( const auto& entry : reputation_db ){
  19685. std::shared_ptr<s_reputation> reputation = entry.second;
  19686. PACKET_ZC_REPUTE_INFO_sub& list_entry = p->list[index];
  19687. list_entry.type = reputation->id;
  19688. list_entry.points = pc_readreg2( &sd, reputation->variable.c_str() );
  19689. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( list_entry ) );
  19690. index++;
  19691. }
  19692. clif_send( p, p->packetLength, &sd.bl, SELF );
  19693. #endif
  19694. }
  19695. void clif_item_reform_open( map_session_data& sd, t_itemid item ){
  19696. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19697. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19698. p.PacketType = HEADER_ZC_OPEN_REFORM_UI;
  19699. p.ITID = item;
  19700. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19701. sd.state.item_reform = item;
  19702. #endif
  19703. }
  19704. void clif_parse_item_reform_close( int fd, map_session_data* sd ){
  19705. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19706. sd->state.item_reform = 0;
  19707. #endif
  19708. }
  19709. void clif_item_reform_result( map_session_data& sd, uint16 index, uint8 result ){
  19710. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19711. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19712. p.PacketType = HEADER_ZC_ITEM_REFORM_ACK;
  19713. p.index = client_index( index );
  19714. p.result = result;
  19715. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19716. if( result == 0 ){
  19717. // Client closes the window on success
  19718. sd.state.item_reform = 0;
  19719. }
  19720. #endif
  19721. }
  19722. void clif_parse_item_reform_start( int fd, map_session_data* sd ){
  19723. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19724. // Not opened
  19725. if( sd->state.item_reform == 0 ){
  19726. return;
  19727. }
  19728. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19729. // Item mismatch
  19730. if( p->ITID != sd->state.item_reform ){
  19731. return;
  19732. }
  19733. uint16 index = server_index( p->index );
  19734. if( index >= MAX_INVENTORY ){
  19735. return;
  19736. }
  19737. if( sd->inventory_data[index] == nullptr ){
  19738. return;
  19739. }
  19740. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19741. if( reform == nullptr ){
  19742. return;
  19743. }
  19744. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19745. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19746. if( base == nullptr ){
  19747. return;
  19748. }
  19749. // If target item is not identified
  19750. if( selected_item.identify == 0 ){
  19751. return;
  19752. }
  19753. // If target item is equipped
  19754. if( selected_item.equip != 0 ){
  19755. return;
  19756. }
  19757. // Check minimum refine requirement
  19758. if( selected_item.refine < base->minimumRefine ){
  19759. return;
  19760. }
  19761. // Check maximum refine requirement
  19762. if( selected_item.refine > base->maximumRefine ){
  19763. return;
  19764. }
  19765. // If no cards are allowed
  19766. if( !base->cardsAllowed ){
  19767. for( int i = 0; i < MAX_SLOTS; i++ ){
  19768. if( selected_item.card[i] != 0 ){
  19769. return;
  19770. }
  19771. }
  19772. }
  19773. // If random options are required
  19774. if( base->requiredRandomOptions > 0 ){
  19775. int i;
  19776. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19777. if( selected_item.option[i].id != 0 ){
  19778. break;
  19779. }
  19780. }
  19781. if( ( i + 1 ) < base->requiredRandomOptions ){
  19782. return;
  19783. }
  19784. }
  19785. std::unordered_map<uint16, uint16> materials;
  19786. // Check if all materials exist
  19787. for( const auto& material : base->materials ){
  19788. int16 material_index = pc_search_inventory( sd, material.first );
  19789. if( material_index < 0 ){
  19790. return;
  19791. }
  19792. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19793. return;
  19794. }
  19795. materials[material_index] = material.second;
  19796. }
  19797. // Remove the material
  19798. for( const auto& material : materials ){
  19799. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19800. return;
  19801. }
  19802. }
  19803. // If triggered from item
  19804. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19805. return;
  19806. }
  19807. // Log removal of item
  19808. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19809. // Visually remove it from the client
  19810. clif_delitem( *sd, index, 1, 0 );
  19811. // Apply the random options
  19812. if( base->randomOptionGroup != nullptr ){
  19813. base->randomOptionGroup->apply( selected_item );
  19814. }
  19815. // Change the refine rate if needed
  19816. if( base->refineChange != 0 ){
  19817. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19818. }
  19819. // Remove all cards and socket enchants
  19820. if( base->clearSlots ){
  19821. for( int i = 0; i < MAX_SLOTS; i++ ){
  19822. selected_item.card[i] = 0;
  19823. }
  19824. }
  19825. // Remove the current enchantgrade
  19826. if( base->removeEnchantgrade ){
  19827. selected_item.enchantgrade = 0;
  19828. }
  19829. // Finally change the item id
  19830. selected_item.nameid = base->resultItemId;
  19831. // Link inventory data cache to the new item
  19832. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19833. // Log retrieving the item again -> with the new options
  19834. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19835. // Make it visible for the client again
  19836. clif_additem( sd, index, 1, 0 );
  19837. clif_item_reform_result( *sd, index, 0 );
  19838. #endif
  19839. }
  19840. void clif_enchantwindow_open( map_session_data& sd, uint64 clientLuaIndex ){
  19841. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19842. // Hardcoded clientside check
  19843. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19844. clif_msg_color( &sd, MSI_ENCHANT_FAILED_OVER_WEIGHT, color_table[COLOR_RED] );
  19845. sd.state.item_enchant_index = 0;
  19846. return;
  19847. }
  19848. struct PACKET_ZC_UI_OPEN_V3 p = {};
  19849. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19850. p.type = OUT_UI_ENCHANT;
  19851. p.data = clientLuaIndex;
  19852. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19853. sd.state.item_enchant_index = clientLuaIndex;
  19854. #endif
  19855. }
  19856. void clif_enchantwindow_result( map_session_data& sd, bool success, t_itemid enchant = 0 ){
  19857. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19858. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  19859. p.PacketType = HEADER_ZC_RESPONSE_ENCHANT;
  19860. if( success ){
  19861. p.msgId = MSI_ENCHANT_SUCCESS;
  19862. }else{
  19863. p.msgId = MSI_ENCHANT_FAILED;
  19864. }
  19865. p.ITID = enchant;
  19866. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19867. sd.state.item_enchant_index = 0;
  19868. #endif
  19869. }
  19870. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  19871. if( selected_item.equip != 0 ){
  19872. return false;
  19873. }
  19874. if( selected_item.equipSwitch != 0 ){
  19875. return false;
  19876. }
  19877. if( selected_item.attribute != 0 ){
  19878. return false;
  19879. }
  19880. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  19881. return false;
  19882. }
  19883. if( selected_item.refine < enchant->minimumRefine ){
  19884. return false;
  19885. }
  19886. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  19887. return false;
  19888. }
  19889. if( !enchant->allowRandomOptions ){
  19890. for( const s_item_randomoption& option : selected_item.option ){
  19891. if( option.id != 0 ){
  19892. return false;
  19893. }
  19894. }
  19895. }
  19896. return true;
  19897. }
  19898. void clif_parse_enchantwindow_general( int fd, map_session_data* sd ){
  19899. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19900. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  19901. if( sd->state.item_enchant_index != p->enchant_group ){
  19902. return;
  19903. }
  19904. uint16 index = server_index( p->index );
  19905. if( index >= MAX_INVENTORY ){
  19906. return;
  19907. }
  19908. if( sd->inventory_data[index] == nullptr ){
  19909. return;
  19910. }
  19911. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19912. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  19913. if( enchant == nullptr ){
  19914. return;
  19915. }
  19916. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19917. return;
  19918. }
  19919. uint16 slot = MAX_SLOTS;
  19920. for( uint16 nextSlot : enchant->order ){
  19921. if( selected_item.card[nextSlot] == 0 ){
  19922. slot = nextSlot;
  19923. break;
  19924. }
  19925. }
  19926. if( slot == MAX_SLOTS ){
  19927. return;
  19928. }
  19929. if( slot < sd->inventory_data[index]->slots ){
  19930. return;
  19931. }
  19932. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19933. if( enchant_slot == nullptr ){
  19934. return;
  19935. }
  19936. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  19937. if( enchants_for_enchantgrade == nullptr ){
  19938. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  19939. clif_enchantwindow_result( *sd, false );
  19940. return;
  19941. }
  19942. if( sd->status.zeny < enchant_slot->normal.zeny ){
  19943. return;
  19944. }
  19945. std::unordered_map<uint16, uint16> materials;
  19946. for( const auto& entry : enchant_slot->normal.materials ){
  19947. int16 idx = pc_search_inventory( sd, entry.first );
  19948. if( idx < 0 ){
  19949. return;
  19950. }
  19951. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19952. return;
  19953. }
  19954. materials[idx] = entry.second;
  19955. }
  19956. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  19957. return;
  19958. }
  19959. for( const auto& entry : materials ){
  19960. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  19961. return;
  19962. }
  19963. }
  19964. uint32 chance = enchant_slot->normal.chance;
  19965. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  19966. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  19967. }
  19968. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  19969. clif_enchantwindow_result( *sd, false );
  19970. return;
  19971. }
  19972. // Log removal of item
  19973. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  19974. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  19975. bool enchanted = false;
  19976. for( int i = 0; i < maximum; i++ ){
  19977. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19978. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  19979. selected_item.card[slot] = normal_enchant->item_id;
  19980. enchanted = true;
  19981. break;
  19982. }
  19983. }
  19984. if( !enchanted ){
  19985. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19986. selected_item.card[slot] = normal_enchant->item_id;
  19987. }
  19988. // Log retrieving the item again -> with the new enchant
  19989. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  19990. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  19991. #endif
  19992. }
  19993. void clif_parse_enchantwindow_perfect( int fd, map_session_data* sd ){
  19994. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19995. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  19996. if( sd->state.item_enchant_index != p->enchant_group ){
  19997. return;
  19998. }
  19999. uint16 index = server_index( p->index );
  20000. if( index >= MAX_INVENTORY ){
  20001. return;
  20002. }
  20003. if( sd->inventory_data[index] == nullptr ){
  20004. return;
  20005. }
  20006. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20007. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20008. if( enchant == nullptr ){
  20009. return;
  20010. }
  20011. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20012. return;
  20013. }
  20014. uint16 slot = MAX_SLOTS;
  20015. for( uint16 nextSlot : enchant->order ){
  20016. if( selected_item.card[nextSlot] == 0 ){
  20017. slot = nextSlot;
  20018. break;
  20019. }
  20020. }
  20021. if( slot == MAX_SLOTS ){
  20022. return;
  20023. }
  20024. if( slot < sd->inventory_data[index]->slots ){
  20025. return;
  20026. }
  20027. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20028. if( enchant_slot == nullptr ){
  20029. return;
  20030. }
  20031. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->ITID );
  20032. if( perfect_enchant == nullptr ){
  20033. return;
  20034. }
  20035. if( sd->status.zeny < perfect_enchant->zeny ){
  20036. return;
  20037. }
  20038. std::unordered_map<uint16, uint16> materials;
  20039. for( const auto& entry : perfect_enchant->materials ){
  20040. int16 idx = pc_search_inventory( sd, entry.first );
  20041. if( idx < 0 ){
  20042. return;
  20043. }
  20044. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20045. return;
  20046. }
  20047. materials[idx] = entry.second;
  20048. }
  20049. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20050. return;
  20051. }
  20052. for( const auto& entry : materials ){
  20053. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20054. return;
  20055. }
  20056. }
  20057. // Log removal of item
  20058. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20059. selected_item.card[slot] = perfect_enchant->item_id;
  20060. // Log retrieving the item again -> with the new enchant
  20061. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20062. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20063. #endif
  20064. }
  20065. void clif_parse_enchantwindow_upgrade( int fd, map_session_data* sd ){
  20066. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20067. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20068. if( sd->state.item_enchant_index != p->enchant_group ){
  20069. return;
  20070. }
  20071. uint16 index = server_index( p->index );
  20072. if( index >= MAX_INVENTORY ){
  20073. return;
  20074. }
  20075. if( sd->inventory_data[index] == nullptr ){
  20076. return;
  20077. }
  20078. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20079. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20080. if( enchant == nullptr ){
  20081. return;
  20082. }
  20083. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20084. return;
  20085. }
  20086. uint16 slot = p->slot;
  20087. if( slot >= MAX_SLOTS ){
  20088. return;
  20089. }
  20090. if( slot < sd->inventory_data[index]->slots ){
  20091. return;
  20092. }
  20093. if( selected_item.card[slot] == 0 ){
  20094. return;
  20095. }
  20096. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20097. if( enchant_slot == nullptr ){
  20098. return;
  20099. }
  20100. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20101. if( upgrade == nullptr ){
  20102. return;
  20103. }
  20104. if( sd->status.zeny < upgrade->zeny ){
  20105. return;
  20106. }
  20107. std::unordered_map<uint16, uint16> materials;
  20108. for( const auto& entry : upgrade->materials ){
  20109. int16 idx = pc_search_inventory( sd, entry.first );
  20110. if( idx < 0 ){
  20111. return;
  20112. }
  20113. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20114. return;
  20115. }
  20116. materials[idx] = entry.second;
  20117. }
  20118. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20119. return;
  20120. }
  20121. for( const auto& entry : materials ){
  20122. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20123. return;
  20124. }
  20125. }
  20126. // Log removal of item
  20127. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20128. selected_item.card[slot] = upgrade->upgrade_item_id;
  20129. // Log retrieving the item again -> with the new enchant
  20130. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20131. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20132. #endif
  20133. }
  20134. void clif_parse_enchantwindow_reset( int fd, map_session_data* sd ){
  20135. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20136. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20137. if( sd->state.item_enchant_index != p->enchant_group ){
  20138. return;
  20139. }
  20140. uint16 index = server_index( p->index );
  20141. if( index >= MAX_INVENTORY ){
  20142. return;
  20143. }
  20144. if( sd->inventory_data[index] == nullptr ){
  20145. return;
  20146. }
  20147. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20148. if( selected_item.equip != 0 ){
  20149. return;
  20150. }
  20151. if( selected_item.equipSwitch != 0 ){
  20152. return;
  20153. }
  20154. if( selected_item.attribute != 0 ){
  20155. return;
  20156. }
  20157. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20158. if( enchant == nullptr ){
  20159. return;
  20160. }
  20161. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20162. return;
  20163. }
  20164. if( selected_item.refine < enchant->minimumRefine ){
  20165. return;
  20166. }
  20167. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20168. return;
  20169. }
  20170. bool is_enchanted = false;
  20171. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20172. if( selected_item.card[i] != 0 ){
  20173. is_enchanted = true;
  20174. break;
  20175. }
  20176. }
  20177. if( !is_enchanted ){
  20178. return;
  20179. }
  20180. if( sd->status.zeny < enchant->reset.zeny ){
  20181. return;
  20182. }
  20183. std::unordered_map<uint16, uint16> materials;
  20184. for( const auto& entry : enchant->reset.materials ){
  20185. int16 idx = pc_search_inventory( sd, entry.first );
  20186. if( idx < 0 ){
  20187. return;
  20188. }
  20189. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20190. return;
  20191. }
  20192. materials[idx] = entry.second;
  20193. }
  20194. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20195. return;
  20196. }
  20197. for( const auto& entry : materials ){
  20198. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20199. return;
  20200. }
  20201. }
  20202. uint32 chance = enchant->reset.chance;
  20203. if( chance == 0 ){
  20204. return;
  20205. }
  20206. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20207. clif_enchantwindow_result( *sd, false );
  20208. return;
  20209. }
  20210. // Log removal of item
  20211. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20212. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20213. selected_item.card[i] = 0;
  20214. }
  20215. // Log retrieving the item again -> with the new enchant
  20216. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20217. clif_enchantwindow_result( *sd, true );
  20218. #endif
  20219. }
  20220. void clif_parse_enchantwindow_close( int fd, map_session_data* sd ){
  20221. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20222. sd->state.item_enchant_index = 0;
  20223. #endif
  20224. }
  20225. void clif_parse_itempackage_select( int fd, map_session_data* sd ){
  20226. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20227. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20228. if( p->AID != sd->status.account_id ){
  20229. return;
  20230. }
  20231. uint16 index = server_index( p->index );
  20232. if( index >= MAX_INVENTORY ){
  20233. return;
  20234. }
  20235. if( sd->inventory_data[index] == nullptr ){
  20236. return;
  20237. }
  20238. if( sd->inventory_data[index]->nameid != p->itemID ){
  20239. return;
  20240. }
  20241. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20242. return;
  20243. }
  20244. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20245. if( package == nullptr ){
  20246. return;
  20247. }
  20248. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20249. if( group == nullptr ){
  20250. return;
  20251. }
  20252. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20253. return;
  20254. }
  20255. for( const auto& entry : group->items ){
  20256. struct item item = {};
  20257. item.nameid = entry.second->item_id;
  20258. item.identify = 1;
  20259. item.refine = (char)entry.second->refine;
  20260. if( entry.second->rentalhours ){
  20261. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20262. }
  20263. // Check if it is a pet egg
  20264. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20265. if( pet != nullptr ){
  20266. for( int i = 0; i < entry.second->amount; i++ ){
  20267. pet_create_egg( sd, item.nameid );
  20268. }
  20269. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20270. for( int i = 0; i < entry.second->amount; i++ ){
  20271. // New random options on each iteration
  20272. if( entry.second->randomOptionGroup != nullptr ){
  20273. entry.second->randomOptionGroup->apply( item );
  20274. }
  20275. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20276. }
  20277. }else{
  20278. if( entry.second->randomOptionGroup != nullptr ){
  20279. entry.second->randomOptionGroup->apply( item );
  20280. }
  20281. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20282. }
  20283. }
  20284. #endif
  20285. }
  20286. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20287. {
  20288. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20289. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20290. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20291. p.itemId = itemId;
  20292. p.refine_level = level;
  20293. p.status = (int8)success;
  20294. if (battle_config.broadcast_hide_name) {
  20295. std::string dispname = clif_hide_name(sd.status.name);
  20296. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20297. }
  20298. else {
  20299. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20300. }
  20301. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20302. #endif
  20303. }
  20304. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20305. #if PACKETVER >= 20160316
  20306. nullpo_retv(sd);
  20307. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20308. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20309. return;
  20310. }
  20311. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20312. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20313. #endif
  20314. }
  20315. void clif_captcha_upload_request(map_session_data &sd) {
  20316. #if PACKETVER >= 20160330
  20317. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20318. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20319. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20320. if (sd.captcha_upload.cd != nullptr) {
  20321. p.captchaFlag = 0;
  20322. } else {
  20323. p.captchaFlag = 1;
  20324. }
  20325. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20326. #endif
  20327. }
  20328. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20329. #if PACKETVER >= 20160316
  20330. nullpo_retv(sd);
  20331. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20332. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20333. return;
  20334. }
  20335. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20336. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20337. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20338. return;
  20339. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20340. return;
  20341. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20342. #endif
  20343. }
  20344. void clif_captcha_upload_end(map_session_data &sd) {
  20345. #if PACKETVER >= 20160330
  20346. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20347. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20348. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20349. #endif
  20350. }
  20351. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20352. #if PACKETVER >= 20160323
  20353. nullpo_retv(sd);
  20354. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20355. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20356. return;
  20357. }
  20358. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20359. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20360. #endif
  20361. }
  20362. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20363. #if PACKETVER >= 20160330
  20364. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20365. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20366. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20367. if (cd == nullptr) {
  20368. p.captchaFlag = 1;
  20369. p.imageSize = 0;
  20370. } else {
  20371. p.captchaFlag = 0;
  20372. p.imageSize = cd->image_size;
  20373. }
  20374. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20375. if (cd != nullptr) {
  20376. for (uint16 offset = 0; offset < cd->image_size;) {
  20377. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20378. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA* p2 = reinterpret_cast<PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA*>( packet_buffer );
  20379. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20380. p2->PacketLength = sizeof( *p2 );
  20381. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20382. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20383. p2->PacketLength += static_cast<decltype(p2->PacketLength)>( chunk_size );
  20384. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20385. offset += chunk_size;
  20386. }
  20387. }
  20388. #endif
  20389. }
  20390. void clif_macro_detector_request(map_session_data &sd) {
  20391. #if PACKETVER >= 20160330
  20392. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20393. if (cd == nullptr) {
  20394. return;
  20395. }
  20396. // Send preview initialization request to the client.
  20397. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20398. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20399. p.imageSize = cd->image_size;
  20400. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20401. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20402. for (uint16 offset = 0; offset < cd->image_size;) {
  20403. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20404. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA* p2 = reinterpret_cast<PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA*>( packet_buffer );
  20405. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20406. p2->PacketLength = sizeof( *p2 );
  20407. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20408. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20409. p2->PacketLength += static_cast<decltype(p2->PacketLength)>( chunk_size );
  20410. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20411. offset += chunk_size;
  20412. }
  20413. #endif
  20414. }
  20415. void clif_macro_detector_request_show(map_session_data &sd) {
  20416. #if PACKETVER >= 20160330
  20417. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20418. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20419. p.retryCount = sd.macro_detect.retry;
  20420. p.timeout = battle_config.macro_detection_timeout;
  20421. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20422. #endif
  20423. }
  20424. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20425. #if PACKETVER >= 20160316
  20426. nullpo_retv(sd);
  20427. if (sd->macro_detect.retry != 0) {
  20428. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20429. clif_macro_detector_request_show(*sd);
  20430. }
  20431. #endif
  20432. }
  20433. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20434. #if PACKETVER >= 20160316
  20435. nullpo_retv(sd);
  20436. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20437. pc_macro_detector_process_answer(*sd, p->answer);
  20438. #endif
  20439. }
  20440. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20441. #if PACKETVER >= 20160330
  20442. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20443. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20444. p.status = stype;
  20445. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20446. #endif
  20447. }
  20448. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20449. #if PACKETVER >= 20160330
  20450. nullpo_retv(sd);
  20451. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20452. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20453. return;
  20454. }
  20455. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20456. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20457. #endif
  20458. }
  20459. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20460. #if PACKETVER >= 20160330
  20461. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE* p = reinterpret_cast<PACKET_ZC_ACK_PLAYER_AID_IN_RANGE*>( packet_buffer );
  20462. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20463. p->PacketLength = sizeof( *p );
  20464. for (size_t i = 0; i < aid_list.size(); i++){
  20465. p->AID[i] = aid_list[static_cast<int32>(i)];
  20466. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->AID[0] ) );
  20467. }
  20468. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20469. #endif
  20470. }
  20471. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20472. #if PACKETVER >= 20160316
  20473. nullpo_retv(sd);
  20474. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20475. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20476. return;
  20477. }
  20478. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20479. map_session_data *tsd = map_id2sd(p->AID);
  20480. if (tsd == nullptr) {
  20481. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20482. return;
  20483. }
  20484. if (tsd->macro_detect.retry != 0) {
  20485. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20486. return;
  20487. }
  20488. if (captcha_db.empty()) {
  20489. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20490. return;
  20491. }
  20492. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20493. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20494. #endif
  20495. }
  20496. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20497. #if PACKETVER >= 20160330
  20498. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20499. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20500. p.status = stype;
  20501. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20502. #endif
  20503. }
  20504. void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ){
  20505. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20506. struct PACKET_ZC_DYNAMICNPC_CREATE_RESULT p = {};
  20507. p.PacketType = HEADER_ZC_DYNAMICNPC_CREATE_RESULT;
  20508. p.result = result;
  20509. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20510. #endif
  20511. }
  20512. void clif_partybooking_ask( map_session_data* sd, map_session_data* joining_sd ){
  20513. #if PACKETVER >= 20191204
  20514. struct PACKET_ZC_PARTY_REQ_MASTER_TO_JOIN p = { 0 };
  20515. p.packetType = HEADER_ZC_PARTY_REQ_MASTER_TO_JOIN;
  20516. p.CID = joining_sd->status.char_id;
  20517. p.AID = joining_sd->status.account_id;
  20518. safestrncpy( p.name, joining_sd->status.name, NAME_LENGTH );
  20519. p.x = joining_sd->status.base_level;
  20520. p.y = joining_sd->status.class_;
  20521. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20522. #endif
  20523. }
  20524. void clif_parse_partybooking_join( int fd, map_session_data* sd ){
  20525. #if PACKETVER >= 20191204
  20526. struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20527. // Character is already in a party
  20528. if( sd->status.party_id != 0 ){
  20529. return;
  20530. }
  20531. map_session_data* tsd = map_charid2sd( p->CID );
  20532. // Target player is offline
  20533. if( tsd == nullptr ){
  20534. return;
  20535. }
  20536. if( tsd->status.account_id != p->AID ){
  20537. return;
  20538. }
  20539. struct s_party_booking_requirement requirement;
  20540. if( !party_booking_load( tsd->status.account_id, tsd->status.char_id, &requirement ) ){
  20541. return;
  20542. }
  20543. if( sd->status.base_level < requirement.minimum_level ){
  20544. return;
  20545. }
  20546. if( sd->status.base_level > requirement.maximum_level ){
  20547. return;
  20548. }
  20549. // Already requested to join this party
  20550. if( util::vector_exists( tsd->party_booking_requests, sd->status.char_id ) ){
  20551. return;
  20552. }
  20553. // Store information that the player tried to join the party
  20554. tsd->party_booking_requests.push_back( sd->status.char_id );
  20555. clif_partybooking_ask( tsd, sd );
  20556. #endif
  20557. }
  20558. void clif_partybooking_reply( map_session_data* sd, map_session_data* party_leader_sd, bool accepted ){
  20559. #if PACKETVER >= 20191204
  20560. struct PACKET_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER p = { 0 };
  20561. if( party_leader_sd->status.party_id == 0 ){
  20562. return;
  20563. }
  20564. struct party_data* party = party_search( party_leader_sd->status.party_id );
  20565. if( party == nullptr ){
  20566. return;
  20567. }
  20568. p.packetType = HEADER_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER;
  20569. safestrncpy( p.player_name, party_leader_sd->status.name, NAME_LENGTH );
  20570. safestrncpy( p.party_name, party->party.name, NAME_LENGTH );
  20571. p.AID = party_leader_sd->status.account_id;
  20572. p.refused = !accepted;
  20573. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20574. #endif
  20575. }
  20576. void clif_parse_partybooking_reply( int fd, map_session_data* sd ){
  20577. #if PACKETVER >= 20191204
  20578. struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20579. map_session_data* tsd = map_charid2sd( p->CID );
  20580. // Target player is offline
  20581. if( tsd == nullptr ){
  20582. return;
  20583. }
  20584. if( tsd->status.account_id != p->AID ){
  20585. return;
  20586. }
  20587. // Check if the player even requested to join the party
  20588. if( !util::vector_exists( sd->party_booking_requests, p->CID ) ){
  20589. return;
  20590. }
  20591. util::vector_erase_if_exists( sd->party_booking_requests, p->CID );
  20592. // Only party leaders can reply
  20593. if( !party_isleader( sd ) ){
  20594. return;
  20595. }
  20596. if( p->accept ){
  20597. party_join( tsd, sd->status.party_id );
  20598. }
  20599. clif_partybooking_reply( tsd, sd, p->accept );
  20600. #endif
  20601. }
  20602. void clif_parse_reset_skill( int fd, map_session_data* sd ){
  20603. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220203
  20604. PACKET_CZ_RESET_SKILL* p = (PACKET_CZ_RESET_SKILL*)RFIFOP( fd, 0 );
  20605. #endif
  20606. }
  20607. void clif_set_dialog_align(map_session_data& sd, int npcid, e_say_dialog_align align)
  20608. {
  20609. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20610. PACKET_ZC_DIALOG_TEXT_ALIGN p = {};
  20611. p.PacketType = HEADER_ZC_DIALOG_TEXT_ALIGN;
  20612. p.align = align;
  20613. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20614. #endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20615. }
  20616. void clif_set_npc_window_size(map_session_data& sd, int width, int height)
  20617. {
  20618. #if PACKETVER_MAIN_NUM >= 20220504
  20619. PACKET_ZC_DIALOG_WINDOW_SIZE p = {};
  20620. p.PacketType = HEADER_ZC_DIALOG_WINDOW_SIZE;
  20621. p.width = width;
  20622. p.height = height;
  20623. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20624. #endif // PACKETVER_MAIN_NUM >= 20220504
  20625. }
  20626. void clif_set_npc_window_pos(map_session_data& sd, int x, int y)
  20627. {
  20628. #if PACKETVER_MAIN_NUM >= 20220504
  20629. PACKET_ZC_DIALOG_WINDOW_POS p = {};
  20630. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS;
  20631. p.x = x;
  20632. p.y = y;
  20633. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20634. #endif // PACKETVER_MAIN_NUM >= 20220504
  20635. }
  20636. void clif_set_npc_window_pos_percent(map_session_data& sd, int x, int y)
  20637. {
  20638. #if PACKETVER_MAIN_NUM >= 20220504
  20639. PACKET_ZC_DIALOG_WINDOW_POS2 p = {};
  20640. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS2;
  20641. p.x = x;
  20642. p.y = y;
  20643. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20644. #endif // PACKETVER_MAIN_NUM >= 20220504
  20645. }
  20646. /*==========================================
  20647. * Main client packet processing function
  20648. *------------------------------------------*/
  20649. static int clif_parse(int fd)
  20650. {
  20651. int cmd, packet_len;
  20652. TBL_PC* sd;
  20653. int pnum;
  20654. #ifdef PACKET_OBFUSCATION
  20655. int cmd2;
  20656. #endif
  20657. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20658. // Note: "click masters" can do 80+ clicks in 10 seconds
  20659. 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]
  20660. { // begin main client packet processing loop
  20661. sd = (TBL_PC *)session[fd]->session_data;
  20662. if (session[fd]->flag.eof) {
  20663. if (sd) {
  20664. if (sd->state.autotrade) {
  20665. //Disassociate character from the socket connection.
  20666. session[fd]->session_data = nullptr;
  20667. sd->fd = 0;
  20668. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20669. } else
  20670. if (sd->state.active) {
  20671. // Player logout display [Valaris]
  20672. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20673. clif_quitsave(fd, sd);
  20674. } else {
  20675. //Unusual logout (during log on/off/map-changer procedure)
  20676. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20677. map_quit(sd);
  20678. }
  20679. } else {
  20680. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, nullptr));
  20681. }
  20682. do_close(fd);
  20683. return 0;
  20684. }
  20685. if (RFIFOREST(fd) < 2)
  20686. return 0;
  20687. cmd = RFIFOW(fd, 0);
  20688. #ifdef PACKET_OBFUSCATION
  20689. // Check if it is a player that tries to connect to the map server.
  20690. if( sd ){
  20691. // Decrypt the current packet ID with the last key stored in the session.
  20692. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20693. }else{
  20694. // Store the original value for checking
  20695. cmd2 = cmd;
  20696. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20697. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20698. }
  20699. #endif
  20700. // filter out invalid / unsupported packets
  20701. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20702. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20703. #ifdef DUMP_INVALID_PACKET
  20704. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20705. #endif
  20706. #ifdef PACKET_OBFUSCATION_WARN
  20707. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20708. if( !sd ){
  20709. #ifdef PACKET_OBFUSCATION
  20710. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20711. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20712. }
  20713. #else
  20714. // Try to use the initial keys for the decryption of the packet ID.
  20715. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20716. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20717. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20718. }
  20719. #endif
  20720. }
  20721. #endif
  20722. set_eof(fd);
  20723. return 0;
  20724. }
  20725. // determine real packet length
  20726. packet_len = packet_db[cmd].len;
  20727. if (packet_len == -1) { // variable-length packet
  20728. if (RFIFOREST(fd) < 4)
  20729. return 0;
  20730. packet_len = RFIFOW(fd,2);
  20731. if (packet_len < 4 || packet_len > 32768) {
  20732. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20733. #ifdef DUMP_INVALID_PACKET
  20734. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20735. #endif
  20736. set_eof(fd);
  20737. return 0;
  20738. }
  20739. }
  20740. if ((int)RFIFOREST(fd) < packet_len){
  20741. 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 );
  20742. #ifdef DUMP_INVALID_PACKET
  20743. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20744. #endif
  20745. set_eof( fd );
  20746. return 0; // not enough data received to form the packet
  20747. }
  20748. #ifdef PACKET_OBFUSCATION
  20749. RFIFOW(fd, 0) = cmd;
  20750. if (sd)
  20751. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20752. #endif
  20753. if( packet_db[cmd].func == clif_parse_debug )
  20754. packet_db[cmd].func(fd, sd);
  20755. else if( packet_db[cmd].func != nullptr ) {
  20756. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20757. ; //Only valid packet when there is no session
  20758. else
  20759. if( sd && sd->bl.prev == nullptr && packet_db[cmd].func != clif_parse_LoadEndAck )
  20760. ; //Only valid packet when player is not on a map
  20761. else
  20762. packet_db[cmd].func(fd, sd);
  20763. }
  20764. #ifdef DUMP_UNKNOWN_PACKET
  20765. else DumpUnknown(fd,sd,cmd,packet_len);
  20766. #endif
  20767. RFIFOSKIP(fd, packet_len);
  20768. }; // main loop end
  20769. return 0;
  20770. }
  20771. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, map_session_data *), ... ){
  20772. va_list argp;
  20773. int i;
  20774. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20775. return;
  20776. packet_db[cmd].len = length;
  20777. packet_db[cmd].func = func;
  20778. va_start(argp, func);
  20779. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20780. int offset = va_arg(argp, int);
  20781. if( offset == 0 ){
  20782. break;
  20783. }
  20784. packet_db[cmd].pos[i] = offset;
  20785. }
  20786. if( i == MAX_PACKET_POS ){
  20787. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20788. }
  20789. va_end(argp);
  20790. }
  20791. /*==========================================
  20792. * Reads packets and setups its array reference
  20793. *------------------------------------------*/
  20794. void packetdb_readdb(){
  20795. memset(packet_db,0,sizeof(packet_db));
  20796. #include "clif_packetdb.hpp"
  20797. #include "clif_shuffle.hpp"
  20798. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20799. #ifdef PACKET_OBFUSCATION
  20800. 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]);
  20801. #else
  20802. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20803. #endif
  20804. }
  20805. /*==========================================
  20806. *
  20807. *------------------------------------------*/
  20808. void do_init_clif(void) {
  20809. const int colors[COLOR_MAX] = {
  20810. 0x00FF00, // COLOR_DEFAULT
  20811. 0xFF0000, // COLOR_RED
  20812. 0xFFFFFF, // COLOR_WHITE
  20813. 0xFFFF00, // COLOR_YELLOW
  20814. 0x00FFFF, // COLOR_CYAN
  20815. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20816. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20817. };
  20818. /**
  20819. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20820. **/
  20821. for( int i = 0; i < COLOR_MAX; i++ ){
  20822. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20823. }
  20824. packetdb_readdb();
  20825. set_defaultparse(clif_parse);
  20826. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20827. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20828. exit(EXIT_FAILURE);
  20829. }
  20830. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20831. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20832. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20833. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20834. if( battle_config.ping_timer_interval > 0 ){
  20835. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20836. }
  20837. #endif
  20838. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20839. }
  20840. void do_final_clif(void) {
  20841. ers_destroy(delay_clearunit_ers);
  20842. }