clif.cpp 730 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506
  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 WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  170. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  171. }
  172. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  173. p += pos;
  174. if( x ) {
  175. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  176. }
  177. if( y ) {
  178. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  179. }
  180. if( dir ) {
  181. dir[0] = ( p[2] & 0x0f );
  182. }
  183. }
  184. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  185. p += pos;
  186. if( x0 ) {
  187. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  188. }
  189. if( y0 ) {
  190. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  191. }
  192. if( x1 ) {
  193. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  194. }
  195. if( y1 ) {
  196. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  197. }
  198. if( sx0 ) {
  199. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  200. }
  201. if( sy0 ) {
  202. sy0[0] = ( p[5] & 0x0f ) >> 0;
  203. }
  204. }
  205. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  206. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  207. }
  208. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  209. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  210. }
  211. //To idenfity disguised characters.
  212. static inline bool disguised(struct block_list* bl) {
  213. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  214. }
  215. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  216. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  217. if( len > max )
  218. len = max;
  219. mes[len-1] = '\0';
  220. return len;
  221. }
  222. static char map_ip_str[128];
  223. static uint32 map_ip;
  224. static uint32 bind_ip = INADDR_ANY;
  225. static uint16 map_port = 5121;
  226. static bool clif_ally_only = false;
  227. int map_fd;
  228. static int clif_parse (int fd);
  229. /*==========================================
  230. * Ip setting of map-server
  231. *------------------------------------------*/
  232. int clif_setip(const char* ip) {
  233. char ip_str[16];
  234. map_ip = host2ip(ip);
  235. if (!map_ip) {
  236. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  237. return 0;
  238. }
  239. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  240. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  241. return 1;
  242. }
  243. void clif_setbindip(const char* ip)
  244. {
  245. bind_ip = host2ip(ip);
  246. if (bind_ip) {
  247. char ip_str[16];
  248. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  249. } else {
  250. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  251. }
  252. }
  253. /*==========================================
  254. * Sets map port to 'port'
  255. * is run from map.cpp upon loading map server configuration
  256. *------------------------------------------*/
  257. void clif_setport(uint16 port)
  258. {
  259. map_port = port;
  260. }
  261. /*==========================================
  262. * Returns map server IP
  263. *------------------------------------------*/
  264. uint32 clif_getip(void)
  265. {
  266. return map_ip;
  267. }
  268. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  269. uint32 clif_refresh_ip(void)
  270. {
  271. uint32 new_ip;
  272. new_ip = host2ip(map_ip_str);
  273. if (new_ip && new_ip != map_ip) {
  274. map_ip = new_ip;
  275. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  276. return map_ip;
  277. }
  278. return 0;
  279. }
  280. /*==========================================
  281. * Returns map port which is set by clif_setport()
  282. *------------------------------------------*/
  283. uint16 clif_getport(void)
  284. {
  285. return map_port;
  286. }
  287. #if PACKETVER >= 20071106
  288. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  289. switch (bl->type) {
  290. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  291. case BL_ITEM: return 0x2; //ITEM_TYPE
  292. case BL_SKILL: return 0x3; //SKILL_TYPE
  293. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  294. case BL_MOB:
  295. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  296. return 0x0; //PC_TYPE
  297. }else{
  298. switch( ( (mob_data*)bl )->special_state.ai ){
  299. case AI_ABR:
  300. return 0xd; //NPC_ABR_TYPE
  301. case AI_BIONIC:
  302. return 0xe; //NPC_BIONIC_TYPE
  303. default:
  304. return 0x5; //NPC_MOB_TYPE
  305. }
  306. }
  307. case BL_NPC:
  308. // From 2017-07-26 on NPC type units can also use player sprites.
  309. // There is one exception and this is if they are walking.
  310. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  311. #if PACKETVER >= 20170726
  312. if (pcdb_checkid( status_get_viewdata( bl )->class_ ) && walking)
  313. return 0x0;
  314. else if (mobdb_checkid( status_get_viewdata( bl )->class_ )) // FIXME: categorize NPCs able to walk
  315. return 0xC;
  316. else
  317. return 0x6;
  318. #else
  319. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  320. #endif
  321. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  322. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  323. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  324. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  325. default: return 0x1; //NPC_TYPE
  326. }
  327. }
  328. #endif
  329. static bool clif_session_isValid(map_session_data *sd) {
  330. return ( sd != nullptr && session_isActive(sd->fd) );
  331. }
  332. /*==========================================
  333. * sub process of clif_send
  334. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  335. * In order to send area-wise packets, such as:
  336. * - AREA : everyone nearby your area
  337. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  338. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  339. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  340. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  341. *------------------------------------------*/
  342. static int clif_send_sub(struct block_list *bl, va_list ap)
  343. {
  344. struct block_list *src_bl;
  345. map_session_data *sd;
  346. unsigned char *buf;
  347. int len, type, fd;
  348. nullpo_ret(bl);
  349. nullpo_ret(sd = (map_session_data *)bl);
  350. // Don't send to disconnected clients.
  351. if( !session_isActive( fd = sd->fd ) ){
  352. return 0;
  353. }
  354. buf = va_arg(ap,unsigned char*);
  355. len = va_arg(ap,int);
  356. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  357. type = va_arg(ap,int);
  358. switch(type) {
  359. case AREA_WOS:
  360. if (bl == src_bl)
  361. return 0;
  362. break;
  363. case AREA_WOC:
  364. if (sd->chatID || bl == src_bl)
  365. return 0;
  366. break;
  367. case AREA_WOSC:
  368. {
  369. if(src_bl->type == BL_PC) {
  370. map_session_data *ssd = (map_session_data *)src_bl;
  371. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  372. return 0;
  373. }
  374. else if(src_bl->type == BL_NPC) {
  375. struct npc_data *nd = (struct npc_data *)src_bl;
  376. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  377. return 0;
  378. }
  379. }
  380. break;
  381. }
  382. if( src_bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)src_bl ), *sd ) ){
  383. // Do not send anything
  384. return 0;
  385. }
  386. /* unless visible, hold it here */
  387. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  388. !sd->sc.getSCE(SC_INTRAVISION) && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  389. return 0;
  390. WFIFOHEAD(fd, len);
  391. if (WFIFOP(fd,0) == buf) {
  392. ShowError("WARNING: Invalid use of clif_send function\n");
  393. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  394. ShowError(" Please correct your code.\n");
  395. // don't send to not move the pointer of the packet for next sessions in the loop
  396. //WFIFOSET(fd,0);//## TODO is this ok?
  397. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  398. return 0;
  399. }
  400. memcpy(WFIFOP(fd,0), buf, len);
  401. WFIFOSET(fd,len);
  402. return 0;
  403. }
  404. /*==========================================
  405. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  406. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  407. *------------------------------------------*/
  408. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  409. {
  410. int i;
  411. map_session_data *sd, *tsd;
  412. struct party_data *p = NULL;
  413. std::shared_ptr<s_battleground_data> bg;
  414. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  415. struct s_mapiterator* iter;
  416. if( type != ALL_CLIENT )
  417. nullpo_ret(bl);
  418. sd = BL_CAST(BL_PC, bl);
  419. switch(type) {
  420. case ALL_CLIENT: //All player clients.
  421. iter = mapit_getallusers();
  422. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  423. if( session_isActive( fd = tsd->fd ) ){
  424. WFIFOHEAD( fd, len );
  425. memcpy( WFIFOP( fd, 0 ), buf, len );
  426. WFIFOSET( fd, len );
  427. }
  428. }
  429. mapit_free(iter);
  430. break;
  431. case ALL_SAMEMAP: //All players on the same map
  432. iter = mapit_getallusers();
  433. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  434. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  435. WFIFOHEAD( fd, len );
  436. memcpy( WFIFOP( fd, 0 ), buf, len );
  437. WFIFOSET( fd, len );
  438. }
  439. }
  440. mapit_free(iter);
  441. break;
  442. case AREA:
  443. case AREA_WOSC:
  444. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  445. clif_send (buf, len, bl, SELF);
  446. [[fallthrough]];
  447. case AREA_WOC:
  448. case AREA_WOS:
  449. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  450. BL_PC, buf, len, bl, type);
  451. break;
  452. case AREA_CHAT_WOC:
  453. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  454. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  455. break;
  456. case CHAT:
  457. case CHAT_WOS:
  458. {
  459. struct chat_data *cd;
  460. if (sd) {
  461. cd = (struct chat_data*)map_id2bl(sd->chatID);
  462. } else if (bl->type == BL_CHAT) {
  463. cd = (struct chat_data*)bl;
  464. } else break;
  465. if (cd == NULL)
  466. break;
  467. for(i = 0; i < cd->users; i++) {
  468. if (type == CHAT_WOS && cd->usersd[i] == sd)
  469. continue;
  470. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  471. WFIFOHEAD(fd,len);
  472. memcpy(WFIFOP(fd,0), buf, len);
  473. WFIFOSET(fd,len);
  474. }
  475. }
  476. }
  477. break;
  478. case PARTY_AREA:
  479. case PARTY_AREA_WOS:
  480. x0 = bl->x - AREA_SIZE;
  481. y0 = bl->y - AREA_SIZE;
  482. x1 = bl->x + AREA_SIZE;
  483. y1 = bl->y + AREA_SIZE;
  484. [[fallthrough]];
  485. case PARTY:
  486. case PARTY_WOS:
  487. case PARTY_SAMEMAP:
  488. case PARTY_SAMEMAP_WOS:
  489. if (sd && sd->status.party_id)
  490. p = party_search(sd->status.party_id);
  491. if (p) {
  492. for(i=0;i<MAX_PARTY;i++){
  493. if( (sd = p->data[i].sd) == NULL )
  494. continue;
  495. if( !session_isActive( fd = sd->fd ) )
  496. continue;
  497. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  498. continue;
  499. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  500. continue;
  501. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  502. continue;
  503. WFIFOHEAD(fd, len);
  504. memcpy(WFIFOP(fd, 0), buf, len);
  505. WFIFOSET(fd, len);
  506. }
  507. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  508. break;
  509. iter = mapit_getallusers();
  510. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  511. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  512. WFIFOHEAD( fd, len );
  513. memcpy( WFIFOP( fd, 0 ), buf, len );
  514. WFIFOSET( tsd->fd, len );
  515. }
  516. }
  517. mapit_free(iter);
  518. }
  519. break;
  520. case DUEL:
  521. case DUEL_WOS:
  522. if (!sd || !sd->duel_group) break; //Invalid usage.
  523. iter = mapit_getallusers();
  524. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  525. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  526. continue;
  527. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  528. WFIFOHEAD( fd, len );
  529. memcpy( WFIFOP( fd, 0 ), buf, len );
  530. WFIFOSET( fd, len );
  531. }
  532. }
  533. mapit_free(iter);
  534. break;
  535. case SELF:
  536. if( clif_session_isValid(sd) ){
  537. fd = sd->fd;
  538. WFIFOHEAD(fd,len);
  539. memcpy(WFIFOP(fd,0), buf, len);
  540. WFIFOSET(fd,len);
  541. }
  542. break;
  543. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  544. case GUILD_AREA:
  545. case GUILD_AREA_WOS:
  546. x0 = bl->x - AREA_SIZE;
  547. y0 = bl->y - AREA_SIZE;
  548. x1 = bl->x + AREA_SIZE;
  549. y1 = bl->y + AREA_SIZE;
  550. [[fallthrough]];
  551. case GUILD_SAMEMAP:
  552. case GUILD_SAMEMAP_WOS:
  553. case GUILD:
  554. case GUILD_WOS:
  555. case GUILD_NOBG: {
  556. if (!sd || !sd->status.guild_id || !sd->guild)
  557. break;
  558. const auto &g = sd->guild->guild;
  559. for(i = 0; i < g.max_member; i++) {
  560. if( (sd = g.member[i].sd) != nullptr ){
  561. if( !session_isActive( fd = sd->fd ) )
  562. continue;
  563. if( type == GUILD_NOBG && sd->bg_id )
  564. continue;
  565. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  566. continue;
  567. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  568. continue;
  569. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  570. continue;
  571. WFIFOHEAD(fd,len);
  572. memcpy(WFIFOP(fd,0), buf, len);
  573. WFIFOSET(fd,len);
  574. }
  575. }
  576. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  577. break;
  578. iter = mapit_getallusers();
  579. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  580. if( tsd->guildspy == g.guild_id && session_isActive( fd = tsd->fd ) ){
  581. WFIFOHEAD( fd, len );
  582. memcpy( WFIFOP( fd, 0 ), buf, len );
  583. WFIFOSET( fd, len );
  584. }
  585. }
  586. mapit_free(iter);
  587. break;
  588. }
  589. case BG_AREA:
  590. case BG_AREA_WOS:
  591. x0 = bl->x - AREA_SIZE;
  592. y0 = bl->y - AREA_SIZE;
  593. x1 = bl->x + AREA_SIZE;
  594. y1 = bl->y + AREA_SIZE;
  595. [[fallthrough]];
  596. case BG_SAMEMAP:
  597. case BG_SAMEMAP_WOS:
  598. case BG:
  599. case BG_WOS:
  600. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  601. {
  602. for (const auto &member : bg->members) {
  603. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  604. continue;
  605. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  606. continue;
  607. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  608. continue;
  609. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  610. continue;
  611. WFIFOHEAD(fd,len);
  612. memcpy(WFIFOP(fd,0), buf, len);
  613. WFIFOSET(fd,len);
  614. }
  615. }
  616. break;
  617. case CLAN:
  618. if( sd && sd->clan ){
  619. struct clan* clan = sd->clan;
  620. for( i = 0; i < clan->max_member; i++ ){
  621. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  622. continue;
  623. }
  624. WFIFOHEAD(fd,len);
  625. memcpy(WFIFOP(fd,0), buf, len);
  626. WFIFOSET(fd,len);
  627. }
  628. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  629. break;
  630. iter = mapit_getallusers();
  631. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  632. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  633. WFIFOHEAD(fd, len);
  634. memcpy(WFIFOP(fd, 0), buf, len);
  635. WFIFOSET(fd, len);
  636. }
  637. }
  638. mapit_free(iter);
  639. }
  640. break;
  641. default:
  642. ShowError("clif_send: Unrecognized type %d\n",type);
  643. return -1;
  644. }
  645. return 0;
  646. }
  647. /// Notifies the client, that it's connection attempt was accepted.
  648. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  649. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  650. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  651. void clif_authok(map_session_data *sd)
  652. {
  653. #if PACKETVER < 20080102
  654. const int cmd = 0x73;
  655. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  656. const int cmd = 0x2eb;
  657. #else
  658. const int cmd = 0xa18;
  659. #endif
  660. int fd = sd->fd;
  661. WFIFOHEAD(fd,packet_len(cmd));
  662. WFIFOW(fd, 0) = cmd;
  663. WFIFOL(fd, 2) = client_tick(gettick());
  664. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  665. WFIFOB(fd, 9) = 5; // ignored
  666. WFIFOB(fd,10) = 5; // ignored
  667. #if PACKETVER >= 20080102
  668. WFIFOW(fd,11) = sd->status.font;
  669. #endif
  670. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  671. WFIFOB(fd,13) = sd->status.sex;
  672. #endif
  673. WFIFOSET(fd,packet_len(cmd));
  674. }
  675. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  676. /// 0074 <error code>.B
  677. /// error code:
  678. /// 0 = client type mismatch
  679. /// 1 = ID mismatch
  680. /// 2 = mobile - out of available time
  681. /// 3 = mobile - already logged in
  682. /// 4 = mobile - waiting state
  683. void clif_authrefuse(int fd, uint8 error_code)
  684. {
  685. WFIFOHEAD(fd,packet_len(0x74));
  686. WFIFOW(fd,0) = 0x74;
  687. WFIFOB(fd,2) = error_code;
  688. WFIFOSET(fd,packet_len(0x74));
  689. }
  690. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  691. /// 0081 <error code>.B
  692. /// error code:
  693. /// 0 = BAN_UNFAIR
  694. /// 1 = server closed -> MsgStringTable[4]
  695. /// 2 = ID already logged in -> MsgStringTable[5]
  696. /// 3 = timeout/too much lag -> MsgStringTable[241]
  697. /// 4 = server full -> MsgStringTable[264]
  698. /// 5 = underaged -> MsgStringTable[305]
  699. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  700. /// 9 = too many connections from this ip -> MsgStringTable[529]
  701. /// 10 = out of available time paid for -> MsgStringTable[530]
  702. /// 11 = BAN_PAY_SUSPEND
  703. /// 12 = BAN_PAY_CHANGE
  704. /// 13 = BAN_PAY_WRONGIP
  705. /// 14 = BAN_PAY_PNGAMEROOM
  706. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  707. /// 16 = BAN_JAPAN_REFUSE1
  708. /// 17 = BAN_JAPAN_REFUSE2
  709. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  710. /// 100 = BAN_PC_IP_UNFAIR
  711. /// 101 = BAN_PC_IP_COUNT_ALL
  712. /// 102 = BAN_PC_IP_COUNT
  713. /// 103 = BAN_GRAVITY_MEM_AGREE
  714. /// 104 = BAN_GAME_MEM_AGREE
  715. /// 105 = BAN_HAN_VALID
  716. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  717. /// 107 = BAN_OVER_CHARACTER_LIST
  718. /// 108 = BAN_IP_BLOCK
  719. /// 109 = BAN_INVALID_PWD_CNT
  720. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  721. /// ? = disconnected -> MsgStringTable[3]
  722. void clif_authfail_fd(int fd, int type)
  723. {
  724. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  725. return;
  726. WFIFOHEAD(fd, packet_len(0x81));
  727. WFIFOW(fd,0) = 0x81;
  728. WFIFOB(fd,2) = type;
  729. WFIFOSET(fd,packet_len(0x81));
  730. set_eof(fd);
  731. }
  732. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  733. /// 00b3 <type>.B
  734. /// type:
  735. /// 1 = disconnect, char-select
  736. /// ? = nothing
  737. void clif_charselectok(int id, uint8 ok)
  738. {
  739. map_session_data* sd;
  740. int fd;
  741. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  742. return;
  743. fd = sd->fd;
  744. WFIFOHEAD(fd,packet_len(0xb3));
  745. WFIFOW(fd,0) = 0xb3;
  746. WFIFOB(fd,2) = ok;
  747. WFIFOSET(fd,packet_len(0xb3));
  748. }
  749. /// Makes an item appear on the ground.
  750. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  751. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  752. /// 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)
  753. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  754. nullpo_retv(fitem);
  755. if( fitem->item.nameid == 0 ){
  756. return;
  757. }
  758. struct packet_dropflooritem p;
  759. p.PacketType = dropflooritemType;
  760. p.ITAID = fitem->bl.id;
  761. p.ITID = client_nameid( fitem->item.nameid );
  762. #if PACKETVER >= 20130000 /* not sure date */
  763. p.type = itemtype( fitem->item.nameid );
  764. #endif
  765. p.IsIdentified = fitem->item.identify ? 1 : 0;
  766. p.xPos = fitem->bl.x;
  767. p.yPos = fitem->bl.y;
  768. p.subX = fitem->subx;
  769. p.subY = fitem->suby;
  770. p.count = fitem->item.amount;
  771. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  772. if( canShowEffect ){
  773. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  774. if( dropEffect > 0 ){
  775. p.showdropeffect = 1;
  776. p.dropeffectmode = dropEffect - 1;
  777. }else if (battle_config.rndopt_drop_pillar != 0){
  778. uint8 optionCount = 0;
  779. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  780. if (fitem->item.option[i].id != 0) {
  781. optionCount++;
  782. }
  783. }
  784. if (optionCount > 0) {
  785. p.showdropeffect = 1;
  786. if (optionCount == 1)
  787. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  788. else if (optionCount == 2)
  789. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  790. else
  791. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  792. } else {
  793. p.showdropeffect = 0;
  794. p.dropeffectmode = DROPEFFECT_NONE;
  795. }
  796. } else {
  797. p.showdropeffect = 0;
  798. p.dropeffectmode = DROPEFFECT_NONE;
  799. }
  800. }else{
  801. p.showdropeffect = 0;
  802. p.dropeffectmode = DROPEFFECT_NONE;
  803. }
  804. #endif
  805. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  806. }
  807. /// Makes an item disappear from the ground.
  808. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  809. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  810. {
  811. unsigned char buf[16];
  812. nullpo_retv(fitem);
  813. WBUFW(buf,0) = 0xa1;
  814. WBUFL(buf,2) = fitem->bl.id;
  815. if ( !session_isActive( fd ) ){
  816. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  817. } else {
  818. WFIFOHEAD(fd,packet_len(0xa1));
  819. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  820. WFIFOSET(fd,packet_len(0xa1));
  821. }
  822. }
  823. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  824. /// 0080 <id>.L <type>.B
  825. /// type:
  826. /// 0 = out of sight
  827. /// 1 = died
  828. /// 2 = logged out
  829. /// 3 = teleport
  830. /// 4 = trickdead
  831. void clif_clearunit_single(int id, clr_type type, int fd)
  832. {
  833. WFIFOHEAD(fd, packet_len(0x80));
  834. WFIFOW(fd,0) = 0x80;
  835. WFIFOL(fd,2) = id;
  836. WFIFOB(fd,6) = type;
  837. WFIFOSET(fd, packet_len(0x80));
  838. }
  839. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  840. /// 0080 <id>.L <type>.B
  841. /// type:
  842. /// 0 = out of sight
  843. /// 1 = died
  844. /// 2 = logged out
  845. /// 3 = teleport
  846. /// 4 = trickdead
  847. void clif_clearunit_area(struct block_list* bl, clr_type type)
  848. {
  849. unsigned char buf[8];
  850. nullpo_retv(bl);
  851. WBUFW(buf,0) = 0x80;
  852. WBUFL(buf,2) = bl->id;
  853. WBUFB(buf,6) = type;
  854. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  855. if(disguised(bl)) {
  856. WBUFL(buf,2) = disguised_bl_id( bl->id );
  857. clif_send(buf, packet_len(0x80), bl, SELF);
  858. }
  859. }
  860. /// Used to make monsters with player-sprites disappear after dying
  861. /// like normal monsters, because the client does not remove those
  862. /// automatically.
  863. static TIMER_FUNC(clif_clearunit_delayed_sub){
  864. struct block_list *bl = (struct block_list *)data;
  865. clif_clearunit_area(bl, (clr_type) id);
  866. ers_free(delay_clearunit_ers,bl);
  867. return 0;
  868. }
  869. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  870. {
  871. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  872. tbl->next = nullptr;
  873. tbl->prev = nullptr;
  874. tbl->id = bl->id;
  875. tbl->m = bl->m;
  876. tbl->x = bl->x;
  877. tbl->y = bl->y;
  878. tbl->type = BL_NUL;
  879. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  880. }
  881. void clif_get_weapon_view(map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  882. {
  883. if(sd->sc.option&OPTION_COSTUME)
  884. {
  885. *rhand = *lhand = 0;
  886. return;
  887. }
  888. #if PACKETVER < 4
  889. *rhand = sd->status.weapon;
  890. *lhand = sd->status.shield;
  891. #else
  892. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  893. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  894. {
  895. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  896. if (id->view_id > 0)
  897. *rhand = id->view_id;
  898. else
  899. *rhand = id->nameid;
  900. } else
  901. *rhand = 0;
  902. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  903. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  904. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  905. {
  906. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  907. if (id->view_id > 0)
  908. *lhand = id->view_id;
  909. else
  910. *lhand = id->nameid;
  911. } else
  912. *lhand = 0;
  913. #endif
  914. }
  915. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  916. static int clif_setlevel_sub(int lv) {
  917. if( lv < battle_config.max_lv ) {
  918. ;
  919. } else if( lv < battle_config.aura_lv ) {
  920. lv = battle_config.max_lv - 1;
  921. } else {
  922. lv = battle_config.max_lv;
  923. }
  924. return lv;
  925. }
  926. static int clif_setlevel(struct block_list* bl) {
  927. int lv = status_get_lv(bl);
  928. if( battle_config.client_limit_unit_lv&bl->type )
  929. return clif_setlevel_sub(lv);
  930. switch( bl->type ) {
  931. case BL_NPC:
  932. case BL_PET:
  933. // npcs and pets do not have level
  934. return 0;
  935. }
  936. return lv;
  937. }
  938. /*==========================================
  939. * Prepares 'unit standing/spawning' packet
  940. *------------------------------------------*/
  941. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  942. nullpo_retv( bl );
  943. map_session_data* sd = BL_CAST( BL_PC, bl );
  944. status_change* sc = status_get_sc( bl );
  945. struct view_data* vd = status_get_viewdata( bl );
  946. int g_id = status_get_guild_id( bl );
  947. #if PACKETVER < 20091103
  948. if( !pcdb_checkid( vd->class_ ) ){
  949. struct packet_idle_unit2 p;
  950. p.PacketType = idle_unit2Type;
  951. #if PACKETVER >= 20071106
  952. p.objecttype = clif_bl_type( bl, walking );
  953. #endif
  954. p.GID = bl->id;
  955. p.speed = status_get_speed( bl );
  956. p.bodyState = ( sc ) ? sc->opt1 : 0;
  957. p.healthState = ( sc ) ? sc->opt2 : 0;
  958. p.effectState = ( sc ) ? sc->option : 0;
  959. p.job = vd->class_;
  960. p.head = vd->hair_style;
  961. p.weapon = vd->weapon;
  962. p.accessory = vd->head_bottom;
  963. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  964. // The hell, why flags work like this?
  965. p.shield = status_get_emblem_id( bl );
  966. p.accessory2 = GetWord( g_id, 1 );
  967. p.accessory3 = GetWord( g_id, 0 );
  968. }else{
  969. p.shield = vd->shield;
  970. p.accessory2 = vd->head_top;
  971. p.accessory3 = vd->head_mid;
  972. }
  973. p.headpalette = vd->hair_color;
  974. p.bodypalette = vd->cloth_color;
  975. p.headDir = ( sd )? sd->head_dir : 0;
  976. p.GUID = g_id;
  977. p.GEmblemVer = status_get_emblem_id( bl );
  978. p.honor = ( sd ) ? sd->status.manner : 0;
  979. p.virtue = ( sc ) ? sc->opt3 : 0;
  980. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  981. p.sex = vd->sex;
  982. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  983. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  984. p.state = vd->dead_sit;
  985. p.clevel = clif_setlevel( bl );
  986. clif_send( &p, sizeof( p ), tbl, target );
  987. return;
  988. }
  989. #endif
  990. struct packet_idle_unit p;
  991. p.PacketType = idle_unitType;
  992. #if PACKETVER >= 20091103
  993. p.PacketLength = sizeof(p);
  994. p.objecttype = clif_bl_type( bl, walking );
  995. #endif
  996. #if PACKETVER >= 20131223
  997. p.AID = bl->id;
  998. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  999. #else
  1000. p.GID = bl->id;
  1001. #endif
  1002. p.speed = status_get_speed(bl);
  1003. p.bodyState = (sc) ? sc->opt1 : 0;
  1004. p.healthState = (sc) ? sc->opt2 : 0;
  1005. // npc option changed?
  1006. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  1007. map_session_data* sd = (map_session_data*)tbl;
  1008. struct npc_data* nd = (struct npc_data*)bl;
  1009. int option = (sc) ? sc->option : 0;
  1010. if( !nd->vd.dead_sit ){
  1011. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  1012. option ^= OPTION_CLOAK;
  1013. }
  1014. }
  1015. p.effectState = option;
  1016. }else{
  1017. p.effectState = (sc) ? sc->option : 0;
  1018. }
  1019. p.job = vd->class_;
  1020. p.head = vd->hair_style;
  1021. p.weapon = vd->weapon;
  1022. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1023. p.shield = vd->shield;
  1024. #endif
  1025. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1026. // The hell, why flags work like this?
  1027. p.accessory = status_get_emblem_id( bl );
  1028. p.accessory2 = GetWord( g_id, 1 );
  1029. p.accessory3 = GetWord( g_id, 0 );
  1030. }else{
  1031. p.accessory = vd->head_bottom;
  1032. p.accessory2 = vd->head_top;
  1033. p.accessory3 = vd->head_mid;
  1034. }
  1035. p.headpalette = vd->hair_color;
  1036. p.bodypalette = vd->cloth_color;
  1037. p.headDir = (sd)? sd->head_dir : 0;
  1038. #if PACKETVER >= 20101124
  1039. p.robe = vd->robe;
  1040. #endif
  1041. p.GUID = g_id;
  1042. p.GEmblemVer = status_get_emblem_id( bl );
  1043. p.honor = (sd) ? sd->status.manner : 0;
  1044. p.virtue = (sc) ? sc->opt3 : 0;
  1045. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1046. p.sex = vd->sex;
  1047. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1048. p.xSize = p.ySize = (sd) ? 5 : 0;
  1049. p.state = vd->dead_sit;
  1050. p.clevel = clif_setlevel( bl );
  1051. #if PACKETVER >= 20080102
  1052. p.font = (sd) ? sd->status.font : 0;
  1053. #endif
  1054. #if PACKETVER >= 20120221
  1055. 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 ) ) ){
  1056. p.maxHP = status_get_max_hp(bl);
  1057. p.HP = status_get_hp(bl);
  1058. }else{
  1059. p.maxHP = -1;
  1060. p.HP = -1;
  1061. }
  1062. if( bl->type == BL_MOB ){
  1063. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1064. }else if( bl->type == BL_PET ){
  1065. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1066. }else{
  1067. p.isBoss = BOSSTYPE_NONE;
  1068. }
  1069. #endif
  1070. #if PACKETVER >= 20150513
  1071. p.body = vd->body_style;
  1072. #endif
  1073. /* Might be earlier, this is when the named item bug began */
  1074. #if PACKETVER >= 20131223
  1075. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1076. #endif
  1077. clif_send( &p, sizeof( p ), tbl, target );
  1078. // if disguised, send to self
  1079. if( disguised( bl ) ){
  1080. #if PACKETVER >= 20091103
  1081. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1082. #if PACKETVER >= 20131223
  1083. p.AID = disguised_bl_id( bl->id );
  1084. #else
  1085. p.GID = disguised_bl_id( bl->id );
  1086. #endif
  1087. #else
  1088. p.GID = disguised_bl_id( bl->id );
  1089. #endif
  1090. clif_send(&p, sizeof(p), bl, SELF);
  1091. }
  1092. }
  1093. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1094. nullpo_retv( bl );
  1095. map_session_data* sd = BL_CAST( BL_PC, bl );
  1096. status_change* sc = status_get_sc( bl );
  1097. struct view_data* vd = status_get_viewdata( bl );
  1098. int g_id = status_get_guild_id( bl );
  1099. #if PACKETVER < 20091103
  1100. if( !pcdb_checkid( vd->class_ ) ){
  1101. struct packet_spawn_unit2 p;
  1102. p.PacketType = spawn_unit2Type;
  1103. #if PACKETVER >= 20071106
  1104. p.objecttype = clif_bl_type( bl, false );
  1105. #endif
  1106. p.GID = bl->id;
  1107. p.speed = status_get_speed( bl );
  1108. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1109. p.healthState = ( sc ) ? sc->opt2 : 0;
  1110. p.effectState = ( sc ) ? sc->option : 0;
  1111. p.head = vd->hair_style;
  1112. p.weapon = vd->weapon;
  1113. p.accessory = vd->head_bottom;
  1114. p.job = vd->class_;
  1115. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1116. // The hell, why flags work like this?
  1117. p.shield = status_get_emblem_id( bl );
  1118. p.accessory2 = GetWord( g_id, 1 );
  1119. p.accessory3 = GetWord( g_id, 0 );
  1120. }else{
  1121. p.shield = vd->shield;
  1122. p.accessory2 = vd->head_top;
  1123. p.accessory3 = vd->head_mid;
  1124. }
  1125. p.headpalette = vd->hair_color;
  1126. p.bodypalette = vd->cloth_color;
  1127. p.headDir = ( sd ) ? sd->head_dir : 0;
  1128. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1129. p.sex = vd->sex;
  1130. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1131. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1132. clif_send( &p, sizeof( p ), bl, target );
  1133. return;
  1134. }
  1135. #endif
  1136. struct packet_spawn_unit p;
  1137. p.PacketType = spawn_unitType;
  1138. #if PACKETVER >= 20091103
  1139. p.PacketLength = sizeof(p);
  1140. p.objecttype = clif_bl_type( bl, false );
  1141. #endif
  1142. #if PACKETVER >= 20131223
  1143. p.AID = bl->id;
  1144. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1145. #else
  1146. p.GID = bl->id;
  1147. #endif
  1148. p.speed = status_get_speed( bl );
  1149. p.bodyState = (sc) ? sc->opt1 : 0;
  1150. p.healthState = (sc) ? sc->opt2 : 0;
  1151. p.effectState = (sc) ? sc->option : 0;
  1152. p.job = vd->class_;
  1153. p.head = vd->hair_style;
  1154. p.weapon = vd->weapon;
  1155. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1156. p.shield = vd->shield;
  1157. #endif
  1158. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1159. // The hell, why flags work like this?
  1160. p.accessory = status_get_emblem_id( bl );
  1161. p.accessory2 = GetWord( g_id, 1 );
  1162. p.accessory3 = GetWord( g_id, 0 );
  1163. }else{
  1164. p.accessory = vd->head_bottom;
  1165. p.accessory2 = vd->head_top;
  1166. p.accessory3 = vd->head_mid;
  1167. }
  1168. p.headpalette = vd->hair_color;
  1169. p.bodypalette = vd->cloth_color;
  1170. p.headDir = (sd)? sd->head_dir : 0;
  1171. #if PACKETVER >= 20101124
  1172. p.robe = vd->robe;
  1173. #endif
  1174. p.GUID = g_id;
  1175. p.GEmblemVer = status_get_emblem_id( bl );
  1176. p.honor = (sd) ? sd->status.manner : 0;
  1177. p.virtue = (sc) ? sc->opt3 : 0;
  1178. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1179. p.sex = vd->sex;
  1180. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1181. p.xSize = p.ySize = (sd) ? 5 : 0;
  1182. p.clevel = clif_setlevel( bl );
  1183. #if PACKETVER >= 20080102
  1184. p.font = (sd) ? sd->status.font : 0;
  1185. #endif
  1186. #if PACKETVER >= 20120221
  1187. 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 ) ) ){
  1188. p.maxHP = status_get_max_hp( bl );
  1189. p.HP = status_get_hp( bl );
  1190. }else{
  1191. p.maxHP = -1;
  1192. p.HP = -1;
  1193. }
  1194. if( bl->type == BL_MOB ){
  1195. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1196. }else if( bl->type == BL_PET ){
  1197. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1198. }else{
  1199. p.isBoss = BOSSTYPE_NONE;
  1200. }
  1201. #endif
  1202. #if PACKETVER >= 20150513
  1203. p.body = vd->body_style;
  1204. #endif
  1205. /* Might be earlier, this is when the named item bug began */
  1206. #if PACKETVER >= 20131223
  1207. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1208. #endif
  1209. if( disguised( bl ) ){
  1210. nullpo_retv( sd );
  1211. if( sd->status.class_ != sd->disguise ){
  1212. clif_send( &p, sizeof( p ), bl, target );
  1213. }
  1214. #if PACKETVER >= 20091103
  1215. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1216. #if PACKETVER >= 20131223
  1217. p.AID = disguised_bl_id( bl->id );
  1218. #else
  1219. p.GID = disguised_bl_id( bl->id );
  1220. #endif
  1221. #else
  1222. p.GID = disguised_bl_id( bl->id );
  1223. #endif
  1224. clif_send( &p, sizeof( p ), bl, SELF );
  1225. }else{
  1226. clif_send( &p, sizeof( p ), bl, target );
  1227. }
  1228. }
  1229. /*==========================================
  1230. * Prepares 'unit walking' packet
  1231. *------------------------------------------*/
  1232. static void clif_set_unit_walking( struct block_list *bl, map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1233. nullpo_retv( bl );
  1234. nullpo_retv( ud );
  1235. map_session_data* sd;
  1236. status_change* sc = status_get_sc( bl );
  1237. struct view_data* vd = status_get_viewdata( bl );
  1238. struct packet_unit_walking p;
  1239. int g_id = status_get_guild_id(bl);
  1240. sd = BL_CAST(BL_PC, bl);
  1241. p.PacketType = unit_walkingType;
  1242. #if PACKETVER >= 20091103
  1243. p.PacketLength = sizeof(p);
  1244. #endif
  1245. #if PACKETVER >= 20071106
  1246. p.objecttype = clif_bl_type( bl, true );
  1247. #endif
  1248. #if PACKETVER >= 20131223
  1249. p.AID = bl->id;
  1250. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1251. #else
  1252. p.GID = bl->id;
  1253. #endif
  1254. p.speed = status_get_speed(bl);
  1255. p.bodyState = (sc) ? sc->opt1 : 0;
  1256. p.healthState = (sc) ? sc->opt2 : 0;
  1257. p.effectState = (sc) ? sc->option : 0;
  1258. p.job = vd->class_;
  1259. p.head = vd->hair_style;
  1260. p.weapon = vd->weapon;
  1261. p.accessory = vd->head_bottom;
  1262. p.moveStartTime = client_tick(gettick());
  1263. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1264. p.shield = vd->shield;
  1265. #endif
  1266. p.accessory2 = vd->head_top;
  1267. p.accessory3 = vd->head_mid;
  1268. p.headpalette = vd->hair_color;
  1269. p.bodypalette = vd->cloth_color;
  1270. p.headDir = (sd) ? sd->head_dir : 0;
  1271. #if PACKETVER >= 20101124
  1272. p.robe = vd->robe;
  1273. #endif
  1274. p.GUID = g_id;
  1275. p.GEmblemVer = status_get_emblem_id(bl);
  1276. p.honor = (sd) ? sd->status.manner : 0;
  1277. p.virtue = (sc) ? sc->opt3 : 0;
  1278. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1279. p.sex = vd->sex;
  1280. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1281. p.xSize = p.ySize = (sd) ? 5 : 0;
  1282. p.clevel = clif_setlevel(bl);
  1283. #if PACKETVER >= 20080102
  1284. p.font = (sd) ? sd->status.font : 0;
  1285. #endif
  1286. #if PACKETVER >= 20120221
  1287. 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 ) ) ){
  1288. p.maxHP = status_get_max_hp(bl);
  1289. p.HP = status_get_hp(bl);
  1290. } else {
  1291. p.maxHP = -1;
  1292. p.HP = -1;
  1293. }
  1294. if( bl->type == BL_MOB ){
  1295. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1296. }else if( bl->type == BL_PET ){
  1297. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1298. }else{
  1299. p.isBoss = BOSSTYPE_NONE;
  1300. }
  1301. #endif
  1302. #if PACKETVER >= 20150513
  1303. p.body = vd->body_style;
  1304. #endif
  1305. /* Might be earlier, this is when the named item bug began */
  1306. #if PACKETVER >= 20131223
  1307. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1308. #endif
  1309. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1310. // if disguised, send the info to self
  1311. if( disguised( bl ) ){
  1312. #if PACKETVER >= 20091103
  1313. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1314. #if PACKETVER >= 20131223
  1315. p.AID = disguised_bl_id( bl->id );
  1316. #else
  1317. p.GID = disguised_bl_id( bl->id );
  1318. #endif
  1319. #else
  1320. p.GID = disguised_bl_id( bl->id );
  1321. #endif
  1322. clif_send(&p,sizeof(p),bl,SELF);
  1323. }
  1324. }
  1325. //Modifies the buffer for disguise characters and sends it to self.
  1326. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1327. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1328. {
  1329. #if PACKETVER >= 20091103
  1330. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1331. WBUFL(buf,5)=-bl->id;
  1332. #elif PACKETVER >= 20071106
  1333. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1334. WBUFL(buf,3)=-bl->id;
  1335. #else
  1336. WBUFL(buf,2)=-bl->id;
  1337. #endif
  1338. clif_send(buf, len, bl, SELF);
  1339. }
  1340. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1341. /// 01b0 <id>.L <type>.B <value>.L
  1342. /// type:
  1343. /// unused
  1344. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, map_session_data *sd)
  1345. {
  1346. nullpo_retv(bl);
  1347. if(!pcdb_checkid(class_))
  1348. {// player classes yield missing sprites
  1349. unsigned char buf[16];
  1350. WBUFW(buf,0)=0x1b0;
  1351. WBUFL(buf,2)=bl->id;
  1352. WBUFB(buf,6)=type;
  1353. WBUFL(buf,7)=class_;
  1354. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1355. }
  1356. }
  1357. void clif_servantball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1358. struct PACKET_ZC_SPIRITS p = {};
  1359. p.PacketType = HEADER_ZC_SPIRITS;
  1360. p.AID = sd.bl.id;
  1361. p.num = sd.servantball;
  1362. if( target == nullptr ){
  1363. target = &sd.bl;
  1364. }
  1365. clif_send( &p, sizeof( p ), target, send_target );
  1366. }
  1367. void clif_abyssball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1368. struct PACKET_ZC_SPIRITS p = {};
  1369. p.PacketType = HEADER_ZC_SPIRITS;
  1370. p.AID = sd.bl.id;
  1371. p.num = sd.abyssball;
  1372. if( target == nullptr ){
  1373. target = &sd.bl;
  1374. }
  1375. clif_send( &p, sizeof( p ), target, send_target );
  1376. }
  1377. /// Notifies the client of an object's Millenium Shields.
  1378. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1379. {
  1380. nullpo_retv(sd);
  1381. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD) == nullptr)
  1382. return;
  1383. WFIFOHEAD(fd, packet_len(0x440));
  1384. WFIFOW(fd, 0) = 0x440;
  1385. WFIFOL(fd, 2) = sd->bl.id;
  1386. WFIFOW(fd, 6) = sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2;
  1387. WFIFOW(fd, 8) = 0;
  1388. WFIFOSET(fd, packet_len(0x440));
  1389. }
  1390. /*==========================================
  1391. * Kagerou/Oboro amulet spirit
  1392. *------------------------------------------*/
  1393. static void clif_spiritcharm_single(int fd, map_session_data *sd)
  1394. {
  1395. WFIFOHEAD(fd, packet_len(0x08cf));
  1396. WFIFOW(fd,0)=0x08cf;
  1397. WFIFOL(fd,2)=sd->bl.id;
  1398. WFIFOW(fd,6)=sd->spiritcharm_type;
  1399. WFIFOW(fd,8)=sd->spiritcharm;
  1400. WFIFOSET(fd, packet_len(0x08cf));
  1401. }
  1402. /*==========================================
  1403. * Enchanting Shadow / Shadow Scar Spirit
  1404. *------------------------------------------*/
  1405. void clif_enchantingshadow_spirit(unit_data &ud) {
  1406. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1407. PACKET_ZC_TARGET_SPIRITS p = {};
  1408. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1409. p.GID = ud.bl->id;
  1410. p.unknown_val = 0;
  1411. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1412. clif_send(&p, sizeof(p), ud.bl, AREA);
  1413. #endif
  1414. }
  1415. /*==========================================
  1416. * Run when player changes map / refreshes
  1417. * Tells its client to display all weather settings being used by this map
  1418. *------------------------------------------*/
  1419. static void clif_weather_check(map_session_data *sd)
  1420. {
  1421. int16 m = sd->bl.m;
  1422. int fd = sd->fd;
  1423. if (map_getmapflag(m, MF_SNOW)
  1424. || map_getmapflag(m, MF_CLOUDS)
  1425. || map_getmapflag(m, MF_FOG)
  1426. || map_getmapflag(m, MF_FIREWORKS)
  1427. || map_getmapflag(m, MF_SAKURA)
  1428. || map_getmapflag(m, MF_LEAVES)
  1429. || map_getmapflag(m, MF_CLOUDS2))
  1430. {
  1431. if (map_getmapflag(m, MF_SNOW))
  1432. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1433. if (map_getmapflag(m, MF_CLOUDS))
  1434. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1435. if (map_getmapflag(m, MF_CLOUDS2))
  1436. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1437. if (map_getmapflag(m, MF_FOG))
  1438. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1439. if (map_getmapflag(m, MF_FIREWORKS)) {
  1440. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1441. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1442. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1443. }
  1444. if (map_getmapflag(m, MF_SAKURA))
  1445. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1446. if (map_getmapflag(m, MF_LEAVES))
  1447. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1448. }
  1449. }
  1450. /**
  1451. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1452. **/
  1453. void clif_weather(int16 m)
  1454. {
  1455. struct s_mapiterator* iter;
  1456. map_session_data *sd=NULL;
  1457. iter = mapit_getallusers();
  1458. for( sd = (map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (map_session_data*)mapit_next(iter) )
  1459. {
  1460. if( sd->bl.m == m )
  1461. clif_weather_check(sd);
  1462. }
  1463. mapit_free(iter);
  1464. }
  1465. /**
  1466. * Hide a NPC from the effects of Maya Purple card.
  1467. * @param bl: Block data
  1468. * @return True if NPC is disabled or false otherwise
  1469. */
  1470. static inline bool clif_npc_mayapurple(block_list *bl) {
  1471. nullpo_retr(false, bl);
  1472. if (bl->type == BL_NPC) {
  1473. npc_data *nd = map_id2nd(bl->id);
  1474. // TODO: Confirm if waitingroom cause any special cases
  1475. if (/* nd->chat_id == 0 && */ nd->is_invisible)
  1476. return true;
  1477. }
  1478. return false;
  1479. }
  1480. /**
  1481. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1482. **/
  1483. int clif_spawn( struct block_list *bl, bool walking ){
  1484. struct view_data *vd;
  1485. vd = status_get_viewdata(bl);
  1486. if( !vd || vd->class_ == JT_INVISIBLE )
  1487. return 0;
  1488. // Hide NPC from Maya Purple card
  1489. if (clif_npc_mayapurple(bl))
  1490. return 0;
  1491. if( bl->type == BL_NPC && !vd->dead_sit ){
  1492. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1493. }else{
  1494. clif_spawn_unit( bl, AREA_WOS );
  1495. }
  1496. if (vd->cloth_color)
  1497. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1498. if (vd->body_style)
  1499. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1500. switch (bl->type)
  1501. {
  1502. case BL_PC:
  1503. {
  1504. TBL_PC *sd = ((TBL_PC*)bl);
  1505. if (sd->spiritball > 0)
  1506. clif_spiritball(&sd->bl);
  1507. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  1508. clif_millenniumshield(&sd->bl, sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2);
  1509. if (sd->soulball > 0)
  1510. clif_soulball(sd);
  1511. if (sd->servantball > 0)
  1512. clif_servantball( *sd );
  1513. if (sd->abyssball > 0)
  1514. clif_abyssball( *sd );
  1515. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1516. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1517. else if(sd->state.size==SZ_MEDIUM)
  1518. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1519. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1520. clif_sendbgemblem_area(sd);
  1521. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1522. clif_spiritcharm(sd);
  1523. if (sd->status.robe)
  1524. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1525. clif_efst_status_change_sub(bl, bl, AREA);
  1526. clif_hat_effects(sd,bl,AREA);
  1527. }
  1528. break;
  1529. case BL_MOB:
  1530. {
  1531. TBL_MOB *md = ((TBL_MOB*)bl);
  1532. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1533. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1534. else if(md->special_state.size==SZ_MEDIUM)
  1535. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1536. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1537. clif_summon_init(*md);
  1538. }
  1539. break;
  1540. case BL_NPC:
  1541. {
  1542. TBL_NPC *nd = ((TBL_NPC*)bl);
  1543. if( nd->size == SZ_BIG )
  1544. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1545. else if( nd->size == SZ_MEDIUM )
  1546. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1547. clif_efst_status_change_sub(bl, bl, AREA);
  1548. clif_progressbar_npc_area(nd);
  1549. }
  1550. break;
  1551. case BL_PET:
  1552. if (vd->head_bottom)
  1553. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1554. break;
  1555. }
  1556. return 0;
  1557. }
  1558. /// Sends information about owned homunculus to the client . [orn]
  1559. /// 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)
  1560. /// 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)
  1561. void clif_hominfo( map_session_data *sd, struct homun_data *hd, int flag ){
  1562. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1563. nullpo_retv( sd );
  1564. nullpo_retv( hd );
  1565. struct status_data *status = &hd->battle_status;
  1566. struct PACKET_ZC_PROPERTY_HOMUN p;
  1567. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1568. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1569. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1570. 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 );
  1571. p.level = hd->homunculus.level;
  1572. p.hunger = hd->homunculus.hunger;
  1573. p.intimacy = hd->homunculus.intimacy / 100;
  1574. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1575. p.itemId = 0; // equip id
  1576. #endif
  1577. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1578. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1579. p.hit = status->hit;
  1580. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1581. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1582. }else{
  1583. p.crit = status->cri / 10;
  1584. }
  1585. #ifdef RENEWAL
  1586. p.def = status->def + status->def2;
  1587. p.mdef = status->mdef + status->mdef2;
  1588. #else
  1589. p.def = status->def + status->vit;
  1590. p.mdef = status->mdef;
  1591. #endif
  1592. p.flee = status->flee;
  1593. p.amotion = (flag) ? 0 : status->amotion;
  1594. #if PACKETVER >= 20141016
  1595. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1596. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1597. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1598. p.hp = status->hp / ( status->max_hp / 100 );
  1599. p.maxHp = 100;
  1600. }else{
  1601. p.hp = status->hp;
  1602. p.maxHp = status->max_hp;
  1603. }
  1604. #else
  1605. if( status->max_hp > INT16_MAX ){
  1606. p.hp = status->hp / ( status->max_hp / 100 );
  1607. p.maxHp = 100;
  1608. }else{
  1609. p.hp = status->hp;
  1610. p.maxHp = status->max_hp;
  1611. }
  1612. #endif
  1613. if( status->max_sp > INT16_MAX ){
  1614. p.sp = status->sp / ( status->max_sp / 100 );
  1615. p.maxSp = 100;
  1616. }else{
  1617. p.sp = status->sp;
  1618. p.maxSp = status->max_sp;
  1619. }
  1620. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1621. p.exp = hd->homunculus.exp;
  1622. p.expNext = hd->exp_next;
  1623. #else
  1624. p.exp = (uint32)hd->homunculus.exp;
  1625. p.expNext = (uint32)hd->exp_next;
  1626. #endif
  1627. switch( hom_class2type( hd->homunculus.class_ ) ){
  1628. case HT_REG:
  1629. case HT_EVO:
  1630. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1631. p.expNext = 0;
  1632. }
  1633. break;
  1634. case HT_S:
  1635. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1636. p.expNext = 0;
  1637. }
  1638. break;
  1639. }
  1640. p.skillPoints = hd->homunculus.skillpts;
  1641. p.range = status_get_range( &hd->bl );
  1642. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1643. #endif
  1644. }
  1645. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1646. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1647. /// type:
  1648. /// unused
  1649. /// state:
  1650. /// 0 = pre-init
  1651. /// 1 = intimacy
  1652. /// 2 = hunger
  1653. /// 3 = accessory?
  1654. /// ? = ignored
  1655. void clif_send_homdata(map_session_data *sd, int state, int param)
  1656. { //[orn]
  1657. int fd = sd->fd;
  1658. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1659. hom_calc_skilltree(sd->hd);
  1660. WFIFOHEAD(fd, packet_len(0x230));
  1661. WFIFOW(fd,0)=0x230;
  1662. WFIFOB(fd,2)=0;
  1663. WFIFOB(fd,3)=state;
  1664. WFIFOL(fd,4)=sd->hd->bl.id;
  1665. WFIFOL(fd,8)=param;
  1666. WFIFOSET(fd,packet_len(0x230));
  1667. }
  1668. int clif_homskillinfoblock(map_session_data *sd)
  1669. { //[orn]
  1670. struct homun_data *hd;
  1671. int fd = sd->fd;
  1672. int i, len=4;
  1673. nullpo_ret(sd);
  1674. hd = sd->hd;
  1675. if ( !hd )
  1676. return 0 ;
  1677. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1678. WFIFOW(fd,0)=0x235;
  1679. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1680. int id = hd->homunculus.hskill[i].id;
  1681. if( id != 0 ){
  1682. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1683. short idx = hom_skill_get_index(id);
  1684. if (idx == -1)
  1685. continue;
  1686. WFIFOW(fd,len ) = id;
  1687. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1688. WFIFOW(fd,len+4) = 0;
  1689. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1690. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1691. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1692. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1693. WFIFOB(fd,len+36) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(id, hd->homunculus.class_)) ? 0 : 1;
  1694. len+=37;
  1695. }
  1696. }
  1697. WFIFOW(fd,2)=len;
  1698. WFIFOSET(fd,len);
  1699. return 0;
  1700. }
  1701. void clif_homskillup(map_session_data *sd, uint16 skill_id)
  1702. { //[orn]
  1703. struct homun_data *hd;
  1704. int fd;
  1705. short idx = -1;
  1706. nullpo_retv(sd);
  1707. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1708. return;
  1709. fd = sd->fd;
  1710. hd = sd->hd;
  1711. WFIFOHEAD(fd, packet_len(0x239));
  1712. WFIFOW(fd,0) = 0x239;
  1713. WFIFOW(fd,2) = skill_id;
  1714. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1715. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1716. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1717. WFIFOB(fd,10) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, skill_id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(hd->homunculus.hskill[idx].id, hd->homunculus.class_)) ? 0 : 1;
  1718. WFIFOSET(fd,packet_len(0x239));
  1719. }
  1720. /// Result of request to feed a homun/merc.
  1721. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1722. /// result:
  1723. /// 0 = failure
  1724. /// 1 = success
  1725. void clif_hom_food( map_session_data *sd, int foodid, int fail ){
  1726. nullpo_retv( sd );
  1727. struct PACKET_ZC_FEED_MER p;
  1728. p.packetType = 0x22f;
  1729. p.result = fail;
  1730. p.itemId = client_nameid( foodid );
  1731. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1732. }
  1733. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1734. /// 0087 <walk start time>.L <walk data>.6B
  1735. void clif_walkok(map_session_data *sd)
  1736. {
  1737. int fd=sd->fd;
  1738. WFIFOHEAD(fd, packet_len(0x87));
  1739. WFIFOW(fd,0)=0x87;
  1740. WFIFOL(fd,2)=client_tick(gettick());
  1741. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1742. WFIFOSET(fd,packet_len(0x87));
  1743. }
  1744. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1745. status_change *sc = NULL;
  1746. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1747. clif_ally_only = true;
  1748. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1749. if(vd->cloth_color)
  1750. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1751. if(vd->body_style)
  1752. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1753. switch(bl->type) {
  1754. case BL_PC:
  1755. {
  1756. TBL_PC *sd = ((TBL_PC*)bl);
  1757. // clif_movepc(sd);
  1758. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1759. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1760. else if(sd->state.size==SZ_MEDIUM)
  1761. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1762. if (sd->status.robe)
  1763. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1764. }
  1765. break;
  1766. case BL_MOB:
  1767. {
  1768. TBL_MOB *md = ((TBL_MOB*)bl);
  1769. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1770. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1771. else if(md->special_state.size==SZ_MEDIUM)
  1772. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1773. }
  1774. break;
  1775. case BL_PET:
  1776. if(vd->head_bottom) // needed to display pet equip properly
  1777. clif_pet_equip_area((TBL_PET*)bl);
  1778. break;
  1779. }
  1780. clif_ally_only = false;
  1781. }
  1782. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1783. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1784. /// Note: unit must not be self
  1785. void clif_move(struct unit_data *ud)
  1786. {
  1787. unsigned char buf[16];
  1788. struct view_data* vd;
  1789. struct block_list* bl = ud->bl;
  1790. status_change *sc = NULL;
  1791. vd = status_get_viewdata(bl);
  1792. if (!vd )
  1793. return;
  1794. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1795. else if( vd->class_ == JT_INVISIBLE ){
  1796. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1797. if(disguised(bl)) {
  1798. WBUFW(buf,0)=0x86;
  1799. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1800. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1801. WBUFL(buf,12)=client_tick(gettick());
  1802. clif_send(buf, packet_len(0x86), bl, SELF);
  1803. }
  1804. return;
  1805. }
  1806. // Hide NPC from Maya Purple card
  1807. if (clif_npc_mayapurple(bl))
  1808. return;
  1809. if (ud->state.speed_changed) {
  1810. // Since we don't know how to update the speed of other objects,
  1811. // use the old walk packet to update the data.
  1812. ud->state.speed_changed = 0;
  1813. clif_move2(bl, vd, ud);
  1814. return;
  1815. }
  1816. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1817. clif_ally_only = true;
  1818. WBUFW(buf,0)=0x86;
  1819. WBUFL(buf,2)=bl->id;
  1820. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1821. WBUFL(buf,12)=client_tick(gettick());
  1822. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1823. if (disguised(bl)) {
  1824. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1825. clif_send(buf, packet_len(0x86), bl, SELF);
  1826. }
  1827. clif_ally_only = false;
  1828. }
  1829. /*==========================================
  1830. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1831. *------------------------------------------*/
  1832. static TIMER_FUNC(clif_delayquit){
  1833. map_session_data *sd = NULL;
  1834. //Remove player from map server
  1835. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1836. map_quit(sd);
  1837. return 0;
  1838. }
  1839. /*==========================================
  1840. *
  1841. *------------------------------------------*/
  1842. void clif_quitsave(int fd,map_session_data *sd) {
  1843. if (!battle_config.prevent_logout ||
  1844. sd->canlog_tick == 0 ||
  1845. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1846. map_quit(sd);
  1847. else if (session_isValid(sd->fd)) {
  1848. //Disassociate session from player (session is deleted after this function was called)
  1849. //And set a timer to make him quit later.
  1850. session[sd->fd]->session_data = NULL;
  1851. sd->fd = 0;
  1852. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1853. }
  1854. }
  1855. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1856. /// 0091 <map name>.16B <x>.W <y>.W
  1857. void clif_changemap(map_session_data *sd, short m, int x, int y)
  1858. {
  1859. nullpo_retv(sd);
  1860. int fd = sd->fd;
  1861. WFIFOHEAD(fd,packet_len(0x91));
  1862. WFIFOW(fd,0) = 0x91;
  1863. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1864. WFIFOW(fd,18) = x;
  1865. WFIFOW(fd,20) = y;
  1866. WFIFOSET(fd,packet_len(0x91));
  1867. }
  1868. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1869. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1870. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1871. void clif_changemapserver(map_session_data* sd, const char* map, int x, int y, uint32 ip, uint16 port)
  1872. {
  1873. int fd;
  1874. #if PACKETVER >= 20170315
  1875. int cmd = 0xac7;
  1876. #else
  1877. int cmd = 0x92;
  1878. #endif
  1879. nullpo_retv(sd);
  1880. fd = sd->fd;
  1881. WFIFOHEAD(fd,packet_len(cmd));
  1882. WFIFOW(fd,0) = cmd;
  1883. mapindex_getmapname_ext( map, WFIFOCP( fd, 2 ) );
  1884. WFIFOW(fd,18) = x;
  1885. WFIFOW(fd,20) = y;
  1886. WFIFOL(fd,22) = htonl(ip);
  1887. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1888. #if PACKETVER >= 20170315
  1889. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1890. #endif
  1891. #ifdef DEBUG
  1892. ShowDebug(
  1893. "Sending the client (%d %d.%d.%d.%d) to map-server with ip %d.%d.%d.%d and port %hu\n",
  1894. sd->status.account_id, CONVIP(session[fd]->client_addr), CONVIP(ip), port);
  1895. #endif
  1896. WFIFOSET(fd,packet_len(cmd));
  1897. }
  1898. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1899. /// This function combines both calls and allows to simplify the calling code
  1900. void clif_blown(struct block_list *bl)
  1901. {
  1902. clif_slide(bl, bl->x, bl->y);
  1903. clif_fixpos(bl);
  1904. }
  1905. /// Visually moves(slides) a character to x,y. If the target cell
  1906. /// isn't walkable, the char doesn't move at all. If the char is
  1907. /// sitting it will stand up (ZC_STOPMOVE).
  1908. /// 0088 <id>.L <x>.W <y>.W
  1909. void clif_fixpos(struct block_list *bl)
  1910. {
  1911. unsigned char buf[10];
  1912. nullpo_retv(bl);
  1913. WBUFW(buf,0) = 0x88;
  1914. WBUFL(buf,2) = bl->id;
  1915. WBUFW(buf,6) = bl->x;
  1916. WBUFW(buf,8) = bl->y;
  1917. clif_send(buf, packet_len(0x88), bl, AREA);
  1918. if( disguised(bl) ) {
  1919. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1920. clif_send(buf, packet_len(0x88), bl, SELF);
  1921. }
  1922. }
  1923. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1924. /// 00c4 <shop id>.L
  1925. void clif_npcbuysell(map_session_data* sd, int id)
  1926. {
  1927. int fd;
  1928. nullpo_retv(sd);
  1929. fd=sd->fd;
  1930. WFIFOHEAD(fd, packet_len(0xc4));
  1931. WFIFOW(fd,0)=0xc4;
  1932. WFIFOL(fd,2)=id;
  1933. WFIFOSET(fd,packet_len(0xc4));
  1934. }
  1935. /// Presents list of items, that can be bought in an NPC shop.
  1936. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1937. void clif_buylist( map_session_data *sd, struct npc_data *nd ){
  1938. nullpo_retv( sd );
  1939. nullpo_retv( nd );
  1940. int fd = sd->fd;
  1941. if( !session_isActive( fd ) ){
  1942. return;
  1943. }
  1944. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1945. WFIFOHEAD( fd, len );
  1946. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1947. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1948. int count = 0;
  1949. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1950. int val = nd->u.shop.shop_item[i].value;
  1951. p->items[count].price = val;
  1952. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1953. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1954. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1955. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1956. std::shared_ptr<item_data> id = item_db.find(nd->u.shop.shop_item[i].nameid);
  1957. p->items[count].viewSprite = id->look;
  1958. p->items[count].location = pc_equippoint_sub( sd, id.get() );
  1959. #endif
  1960. count++;
  1961. }
  1962. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1963. WFIFOSET( fd, p->packetLength );
  1964. }
  1965. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1966. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1967. void clif_selllist(map_session_data *sd)
  1968. {
  1969. int fd,i,c=0,val;
  1970. struct npc_data *nd;
  1971. nullpo_retv(sd);
  1972. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1973. return;
  1974. fd=sd->fd;
  1975. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1976. WFIFOW(fd,0)=0xc7;
  1977. for( i = 0; i < MAX_INVENTORY; i++ )
  1978. {
  1979. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1980. {
  1981. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1982. continue;
  1983. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1984. val = 0;
  1985. else {
  1986. val = sd->inventory_data[i]->value_sell;
  1987. if( val < 0 )
  1988. continue;
  1989. }
  1990. WFIFOW(fd,4+c*10)=i+2;
  1991. WFIFOL(fd,6+c*10)=val;
  1992. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1993. c++;
  1994. }
  1995. }
  1996. WFIFOW(fd,2)=c*10+4;
  1997. WFIFOSET(fd,WFIFOW(fd,2));
  1998. }
  1999. /// Closes shop (CZ_NPC_TRADE_QUIT).
  2000. /// 09d4
  2001. void clif_parse_NPCShopClosed(int fd, map_session_data *sd) {
  2002. // TODO: State tracking?
  2003. sd->npc_shopid = 0;
  2004. }
  2005. /**
  2006. * Presents list of items, that can be sold to a Market shop.
  2007. * @author: Ind and Yommy
  2008. **/
  2009. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  2010. void clif_npc_market_open(map_session_data *sd, struct npc_data *nd) {
  2011. #if PACKETVER >= 20131223
  2012. nullpo_retv( sd );
  2013. nullpo_retv( nd );
  2014. if( sd->state.trading ){
  2015. return;
  2016. }
  2017. int fd = sd->fd;
  2018. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  2019. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  2020. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  2021. int count = 0;
  2022. for( int i = 0; i < nd->u.shop.count; i++ ){
  2023. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  2024. if( !item->nameid ){
  2025. continue;
  2026. }
  2027. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  2028. if( !id ){
  2029. continue;
  2030. }
  2031. p->list[count].nameid = client_nameid( item->nameid );
  2032. p->list[count].type = itemtype( item->nameid );
  2033. p->list[count].price = item->value;
  2034. p->list[count].qty = item->qty;
  2035. p->list[count].weight = id->weight;
  2036. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2037. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2038. #endif
  2039. count++;
  2040. }
  2041. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2042. WFIFOSET( fd, p->packetLength );
  2043. sd->state.trading = 1;
  2044. #endif
  2045. }
  2046. /// Closes the Market shop window.
  2047. void clif_parse_NPCMarketClosed(int fd, map_session_data *sd) {
  2048. nullpo_retv(sd);
  2049. sd->npc_shopid = 0;
  2050. sd->state.trading = 0;
  2051. }
  2052. /// Purchase item from Market shop.
  2053. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2054. void clif_npc_market_purchase_ack( map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2055. #if PACKETVER >= 20131223
  2056. nullpo_retv( sd );
  2057. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2058. nullpo_retv( nd );
  2059. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2060. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2061. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2062. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2063. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2064. #else
  2065. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2066. #endif
  2067. if( res == e_purchase_result::PURCHASE_SUCCEED ){
  2068. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2069. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2070. // Not found
  2071. if( j == nd->u.shop.count ){
  2072. continue;
  2073. }
  2074. p->list[count].ITID = client_nameid( list[i].nameid );
  2075. p->list[count].qty = list[i].qty;
  2076. p->list[count].price = nd->u.shop.shop_item[j].value;
  2077. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2078. count++;
  2079. }
  2080. }
  2081. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2082. #endif
  2083. }
  2084. /// Purchase item from Market shop.
  2085. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2086. void clif_parse_NPCMarketPurchase(int fd, map_session_data *sd) {
  2087. #if PACKETVER >= 20131223
  2088. nullpo_retv( sd );
  2089. if( !sd->npc_shopid ){
  2090. return;
  2091. }
  2092. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2093. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2094. std::vector<s_npc_buy_list> items;
  2095. items.reserve( count );
  2096. for( int i = 0; i < count; i++ ){
  2097. s_npc_buy_list item = {};
  2098. item.nameid = p->list[i].ITID;
  2099. item.qty = p->list[i].qty;
  2100. items.push_back( item );
  2101. }
  2102. e_purchase_result res = npc_buylist( sd, items );
  2103. clif_npc_market_purchase_ack( sd, res, items );
  2104. #endif
  2105. }
  2106. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2107. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2108. /// Client behavior (dialog window):
  2109. /// - disable mouse targeting
  2110. /// - open the dialog window
  2111. /// - set npcid of dialog window (0 by default)
  2112. /// - if set to clear on next mes, clear contents
  2113. /// - append this text
  2114. void clif_scriptmes( map_session_data& sd, uint32 npcid, const char *mes ){
  2115. struct PACKET_ZC_SAY_DIALOG* p = (struct PACKET_ZC_SAY_DIALOG*)packet_buffer;
  2116. int16 length = (int16)( strlen( mes ) + 1 );
  2117. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2118. p->PacketLength = sizeof( *p ) + length;
  2119. p->NpcID = npcid;
  2120. safestrncpy( p->message, mes, length );
  2121. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2122. }
  2123. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2124. /// 00b5 <npc id>.L
  2125. /// Client behavior (dialog window):
  2126. /// - disable mouse targeting
  2127. /// - open the dialog window
  2128. /// - add 'next' button
  2129. /// When 'next' is pressed:
  2130. /// - 00B9 <npcid of dialog window>.L
  2131. /// - set to clear on next mes
  2132. /// - remove 'next' button
  2133. void clif_scriptnext( map_session_data& sd, uint32 npcid ){
  2134. struct PACKET_ZC_WAIT_DIALOG p = {};
  2135. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2136. p.NpcID = npcid;
  2137. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2138. }
  2139. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2140. /// 00b6 <npc id>.L
  2141. /// Client behavior:
  2142. /// - if dialog window is open:
  2143. /// - remove 'next' button
  2144. /// - add 'close' button
  2145. /// - else:
  2146. /// - enable mouse targeting
  2147. /// - close the dialog window
  2148. /// - close the menu window
  2149. /// When 'close' is pressed:
  2150. /// - enable mouse targeting
  2151. /// - close the dialog window
  2152. /// - close the menu window
  2153. /// - 0146 <npcid of dialog window>.L
  2154. void clif_scriptclose(map_session_data *sd, int npcid)
  2155. {
  2156. int fd;
  2157. nullpo_retv(sd);
  2158. fd=sd->fd;
  2159. WFIFOHEAD(fd, packet_len(0xb6));
  2160. WFIFOW(fd,0)=0xb6;
  2161. WFIFOL(fd,2)=npcid;
  2162. WFIFOSET(fd,packet_len(0xb6));
  2163. }
  2164. /**
  2165. * Close script when player is idle
  2166. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2167. * @author [Ind/Hercules]
  2168. * @param sd : player pointer
  2169. * @param npcid : npc gid to close
  2170. */
  2171. void clif_scriptclear( map_session_data& sd, int npcid ){
  2172. struct PACKET_ZC_CLEAR_DIALOG p = {};
  2173. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2174. p.GID = npcid;
  2175. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2176. }
  2177. /*==========================================
  2178. *
  2179. *------------------------------------------*/
  2180. void clif_sendfakenpc(map_session_data *sd, int npcid) {
  2181. unsigned char *buf;
  2182. int fd = sd->fd;
  2183. sd->state.using_fake_npc = 1;
  2184. WFIFOHEAD(fd, packet_len(0x78));
  2185. buf = WFIFOP(fd,0);
  2186. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2187. WBUFW(buf,0)=0x78;
  2188. #if PACKETVER >= 20071106
  2189. WBUFB(buf,2) = 0; // object type
  2190. buf = WFIFOP(fd,1);
  2191. #endif
  2192. WBUFL(buf,2)=npcid;
  2193. WBUFW(buf,14)=111;
  2194. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2195. WBUFB(buf,49)=5;
  2196. WBUFB(buf,50)=5;
  2197. WFIFOSET(fd, packet_len(0x78));
  2198. }
  2199. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2200. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2201. /// Client behavior:
  2202. /// - disable mouse targeting
  2203. /// - close the menu window
  2204. /// - open the menu window
  2205. /// - add options to the menu (separated in the text by ":")
  2206. /// - set npcid of menu window
  2207. /// - if dialog window is open:
  2208. /// - remove 'next' button
  2209. /// When 'ok' is pressed:
  2210. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2211. /// - close the menu window
  2212. /// When 'cancel' is pressed:
  2213. /// - 00B8 <npcid of menu window>.L <-1>.B
  2214. /// - enable mouse targeting
  2215. /// - close a bunch of windows...
  2216. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2217. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2218. /// TODO investigate behavior of other windows [FlavioJS]
  2219. void clif_scriptmenu(map_session_data* sd, int npcid, const char* mes)
  2220. {
  2221. int fd = sd->fd;
  2222. int slen = strlen(mes) + 9;
  2223. struct block_list *bl = NULL;
  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. WFIFOHEAD(fd, slen);
  2229. WFIFOW(fd,0)=0xb7;
  2230. WFIFOW(fd,2)=slen;
  2231. WFIFOL(fd,4)=npcid;
  2232. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2233. WFIFOSET(fd,WFIFOW(fd,2));
  2234. }
  2235. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2236. /// 0142 <npc id>.L
  2237. /// Client behavior (inputnum window):
  2238. /// - if npcid exists in the client:
  2239. /// - open the inputnum window
  2240. /// - set npcid of inputnum window
  2241. /// When 'ok' is pressed:
  2242. /// - if inputnum window has text:
  2243. /// - if npcid exists in the client:
  2244. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2245. /// - close inputnum window
  2246. void clif_scriptinput(map_session_data *sd, int npcid)
  2247. {
  2248. int fd;
  2249. struct block_list *bl = NULL;
  2250. nullpo_retv(sd);
  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. fd=sd->fd;
  2256. WFIFOHEAD(fd, packet_len(0x142));
  2257. WFIFOW(fd,0)=0x142;
  2258. WFIFOL(fd,2)=npcid;
  2259. WFIFOSET(fd,packet_len(0x142));
  2260. }
  2261. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2262. /// 01d4 <npc id>.L
  2263. /// Client behavior (inputstr window):
  2264. /// - if npcid is 0 or npcid exists in the client:
  2265. /// - open the inputstr window
  2266. /// - set npcid of inputstr window
  2267. /// When 'ok' is pressed:
  2268. /// - if inputstr window has text and isn't an insult(manner.txt):
  2269. /// - if npcid is 0 or npcid exists in the client:
  2270. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2271. /// - close inputstr window
  2272. void clif_scriptinputstr(map_session_data *sd, int npcid)
  2273. {
  2274. int fd;
  2275. struct block_list *bl = NULL;
  2276. nullpo_retv(sd);
  2277. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2278. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2279. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2280. clif_sendfakenpc(sd, npcid);
  2281. fd=sd->fd;
  2282. WFIFOHEAD(fd, packet_len(0x1d4));
  2283. WFIFOW(fd,0)=0x1d4;
  2284. WFIFOL(fd,2)=npcid;
  2285. WFIFOSET(fd,packet_len(0x1d4));
  2286. }
  2287. /// Marks a position on client's minimap (ZC_COMPASS).
  2288. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2289. /// npc id:
  2290. /// is ignored in the client
  2291. /// type:
  2292. /// 0 = display mark for 15 seconds
  2293. /// 1 = display mark until dead or teleported
  2294. /// 2 = remove mark
  2295. /// color:
  2296. /// 0x00RRGGBB
  2297. void clif_viewpoint(map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2298. {
  2299. int fd;
  2300. nullpo_retv(sd);
  2301. fd=sd->fd;
  2302. WFIFOHEAD(fd, packet_len(0x144));
  2303. WFIFOW(fd,0)=0x144;
  2304. WFIFOL(fd,2)=npc_id;
  2305. WFIFOL(fd,6)=type;
  2306. WFIFOL(fd,10)=x;
  2307. WFIFOL(fd,14)=y;
  2308. WFIFOB(fd,18)=id;
  2309. WFIFOL(fd,19)=color;
  2310. WFIFOSET(fd,packet_len(0x144));
  2311. }
  2312. /// Displays an illustration image.
  2313. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2314. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2315. /// type:
  2316. /// 0 = bottom left corner
  2317. /// 1 = bottom middle
  2318. /// 2 = bottom right corner
  2319. /// 3 = middle of screen, inside a movable window
  2320. /// 4 = middle of screen, movable with a close button, chrome-less
  2321. /// 255 = clear all displayed cutins
  2322. void clif_cutin(map_session_data* sd, const char* image, int type)
  2323. {
  2324. int fd;
  2325. nullpo_retv(sd);
  2326. fd=sd->fd;
  2327. WFIFOHEAD(fd, packet_len(0x1b3));
  2328. WFIFOW(fd,0)=0x1b3;
  2329. strncpy(WFIFOCP(fd,2),image,64);
  2330. WFIFOB(fd,66)=type;
  2331. WFIFOSET(fd,packet_len(0x1b3));
  2332. }
  2333. /*==========================================
  2334. * Fills in card data from the given item and into the buffer. [Skotlex]
  2335. *------------------------------------------*/
  2336. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2337. nullpo_retv( buf );
  2338. // Blank data
  2339. if( item == nullptr ){
  2340. buf->card[0] = 0;
  2341. buf->card[1] = 0;
  2342. buf->card[2] = 0;
  2343. buf->card[3] = 0;
  2344. return;
  2345. }
  2346. // Pet eggs
  2347. if( item->card[0] == CARD0_PET ){
  2348. buf->card[0] = 0;
  2349. buf->card[1] = 0;
  2350. // Pet intimacy
  2351. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2352. buf->card[2] = item->card[3] >> 1;
  2353. // Pet renamed flag
  2354. buf->card[3] = item->card[3] & 1;
  2355. return;
  2356. }
  2357. // Forged/created items
  2358. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2359. buf->card[0] = item->card[0];
  2360. buf->card[1] = item->card[1];
  2361. buf->card[2] = item->card[2];
  2362. buf->card[3] = item->card[3];
  2363. return;
  2364. }
  2365. int i = 0, j;
  2366. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2367. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2368. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2369. }
  2370. // Normal items.
  2371. for( int k = 0; k < 4; k++, i++ ){
  2372. if( item->card[i] > 0 ){
  2373. buf->card[k] = client_nameid( item->card[i] );
  2374. }else{
  2375. buf->card[k] = 0;
  2376. }
  2377. }
  2378. }
  2379. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2380. /// A maximum of 5 random options can be supported.
  2381. static void clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item& it ){
  2382. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2383. if( it.option[i].id ){
  2384. buf[i].index = it.option[i].id; // OptIndex
  2385. buf[i].value = it.option[i].value; // Value
  2386. buf[i].param = it.option[i].param; // Param1
  2387. }else{
  2388. buf[i].index = 0;
  2389. buf[i].value = 0;
  2390. buf[i].param = 0;
  2391. }
  2392. }
  2393. #if MAX_ITEM_RDM_OPT < 5
  2394. for( ; i < 5; i++ ){
  2395. buf[i].index = 0; // OptIndex
  2396. buf[i].value = 0; // Value
  2397. buf[i].param = 0; // Param1
  2398. }
  2399. #endif
  2400. }
  2401. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2402. /// 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)
  2403. /// 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)
  2404. /// 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)
  2405. /// 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)
  2406. /// 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)
  2407. /// 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)
  2408. void clif_additem( map_session_data *sd, int n, int amount, unsigned char fail ){
  2409. nullpo_retv( sd );
  2410. int fd = sd->fd;
  2411. if( !session_isActive( fd ) ){
  2412. return;
  2413. }
  2414. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2415. if( fail ){
  2416. p = {};
  2417. }else{
  2418. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2419. return;
  2420. }
  2421. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2422. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2423. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2424. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2425. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2426. p.location = pc_equippoint(sd,n);
  2427. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2428. #if PACKETVER >= 20061218
  2429. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2430. #if PACKETVER >= 20071002
  2431. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2432. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2433. */
  2434. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2435. #if PACKETVER >= 20150226
  2436. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[n] );
  2437. #if PACKETVER >= 20160921
  2438. p.favorite = ( sd->inventory.u.items_inventory[n].favorite != 0 ) ? 1 : 0;
  2439. p.look = sd->inventory_data[n]->look;
  2440. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2441. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2442. #endif
  2443. #endif
  2444. #endif
  2445. #endif
  2446. #endif
  2447. }
  2448. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2449. p.Index = client_index( n );
  2450. p.count = amount;
  2451. p.result = fail;
  2452. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2453. }
  2454. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2455. /// 00af <index>.W <amount>.W
  2456. void clif_dropitem(map_session_data *sd,int n,int amount)
  2457. {
  2458. int fd;
  2459. nullpo_retv(sd);
  2460. fd=sd->fd;
  2461. WFIFOHEAD(fd, packet_len(0xaf));
  2462. WFIFOW(fd,0)=0xaf;
  2463. WFIFOW(fd,2)=n+2;
  2464. WFIFOW(fd,4)=amount;
  2465. WFIFOSET(fd,packet_len(0xaf));
  2466. }
  2467. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2468. /// 07fa <delete type>.W <index>.W <amount>.W
  2469. /// delete type:
  2470. /// 0 = Normal
  2471. /// 1 = Item used for a skill
  2472. /// 2 = Refine failed
  2473. /// 3 = Material changed
  2474. /// 4 = Moved to storage
  2475. /// 5 = Moved to cart
  2476. /// 6 = Item sold
  2477. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2478. void clif_delitem(map_session_data *sd,int n,int amount, short reason)
  2479. {
  2480. #if PACKETVER < 20091117
  2481. clif_dropitem(sd,n,amount);
  2482. #else
  2483. int fd;
  2484. nullpo_retv(sd);
  2485. fd=sd->fd;
  2486. WFIFOHEAD(fd, packet_len(0x7fa));
  2487. WFIFOW(fd,0)=0x7fa;
  2488. WFIFOW(fd,2)=reason;
  2489. WFIFOW(fd,4)=n+2;
  2490. WFIFOW(fd,6)=amount;
  2491. WFIFOSET(fd,packet_len(0x7fa));
  2492. #endif
  2493. }
  2494. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2495. nullpo_retv( p );
  2496. nullpo_retv( it );
  2497. nullpo_retv( id );
  2498. p->index = idx;
  2499. p->ITID = client_nameid( it->nameid );
  2500. p->type = itemtype( it->nameid );
  2501. #if PACKETVER < 20120925
  2502. p->IsIdentified = it->identify ? 1 : 0;
  2503. #endif
  2504. p->location = eqp_pos;
  2505. p->WearState = it->equip;
  2506. #if PACKETVER < 20120925
  2507. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2508. #endif
  2509. p->RefiningLevel = it->refine;
  2510. clif_addcards( &p->slot, it );
  2511. #if PACKETVER >= 20071002
  2512. p->HireExpireDate = it->expire_time;
  2513. #endif
  2514. #if PACKETVER >= 20080102
  2515. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2516. #endif
  2517. #if PACKETVER >= 20100629
  2518. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2519. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2520. #endif
  2521. #if PACKETVER >= 20120925
  2522. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2523. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2524. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2525. p->Flag.SpareBits = 0;
  2526. #endif
  2527. #if PACKETVER >= 20150226
  2528. clif_add_random_options( p->option_data, *it );
  2529. // Client ingores the value anyway and recalculates it
  2530. p->option_count = 0;
  2531. #endif
  2532. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2533. p->grade = it->enchantgrade;
  2534. #endif
  2535. }
  2536. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2537. nullpo_retv(p);
  2538. nullpo_retv(i);
  2539. nullpo_retv(id);
  2540. p->index = idx;
  2541. p->ITID = client_nameid( i->nameid );
  2542. p->type = itemtype( i->nameid );
  2543. #if PACKETVER < 20120925
  2544. p->IsIdentified = i->identify ? 1 : 0;
  2545. #endif
  2546. p->count = i->amount;
  2547. p->WearState = id->equip;
  2548. #if PACKETVER >= 5
  2549. clif_addcards( &p->slot, i );
  2550. #endif
  2551. #if PACKETVER >= 20080102
  2552. p->HireExpireDate = i->expire_time;
  2553. #endif
  2554. #if PACKETVER >= 20120925
  2555. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2556. p->Flag.PlaceETCTab = ( i->favorite != 0 ) ? 1 : 0;
  2557. p->Flag.SpareBits = 0;
  2558. #endif
  2559. }
  2560. static void clif_inventoryStart( map_session_data *sd, e_inventory_type type, const char *name ){
  2561. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2562. nullpo_retv(sd);
  2563. nullpo_retv(name);
  2564. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2565. memset(buf, 0, sizeof(buf));
  2566. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2567. p->packetType = HEADER_ZC_INVENTORY_START;
  2568. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2569. p->invType = type;
  2570. #endif
  2571. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2572. int strLen = (int)safestrnlen(name, 24) + 1;
  2573. if (strLen > 24)
  2574. strLen = 24;
  2575. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2576. p->packetLength = len;
  2577. safestrncpy(p->name, name, strLen);
  2578. #else
  2579. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2580. safestrncpy(p->name, name, NAME_LENGTH);
  2581. #endif
  2582. clif_send( p, len, &sd->bl, SELF );
  2583. #endif
  2584. }
  2585. static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
  2586. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2587. nullpo_retv(sd);
  2588. struct PACKET_ZC_INVENTORY_END p;
  2589. p.packetType = HEADER_ZC_INVENTORY_END;
  2590. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2591. p.invType = type;
  2592. #endif
  2593. p.flag = 0;
  2594. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2595. #endif
  2596. }
  2597. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2598. void clif_inventorylist( map_session_data *sd ){
  2599. nullpo_retv( sd );
  2600. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2601. e_inventory_type type = INVTYPE_INVENTORY;
  2602. clif_inventoryStart( sd, type, "" );
  2603. #endif
  2604. static struct packet_itemlist_normal itemlist_normal;
  2605. static struct packet_itemlist_equip itemlist_equip;
  2606. int equip = 0;
  2607. int normal = 0;
  2608. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2609. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2610. continue;
  2611. }
  2612. // Non-stackable (Equippable)
  2613. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2614. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2615. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2616. itemlist_equip.PacketType = inventorylistequipType;
  2617. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2618. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2619. itemlist_equip.invType = type;
  2620. #endif
  2621. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2622. equip = 0;
  2623. }
  2624. // Stackable (Normal)
  2625. }else{
  2626. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2627. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2628. itemlist_normal.PacketType = inventorylistnormalType;
  2629. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2630. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2631. itemlist_normal.invType = type;
  2632. #endif
  2633. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2634. normal = 0;
  2635. }
  2636. }
  2637. }
  2638. if( normal ){
  2639. itemlist_normal.PacketType = inventorylistnormalType;
  2640. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2641. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2642. itemlist_normal.invType = type;
  2643. #endif
  2644. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2645. }
  2646. if( sd->equip_index[EQI_AMMO] >= 0 )
  2647. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2648. if( equip ) {
  2649. itemlist_equip.PacketType = inventorylistequipType;
  2650. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2651. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2652. itemlist_equip.invType = type;
  2653. #endif
  2654. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2655. }
  2656. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2657. clif_inventoryEnd( sd, type );
  2658. #endif
  2659. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2660. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2661. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2662. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2663. continue;
  2664. if ( sd->inventory.u.items_inventory[i].favorite != 0 )
  2665. clif_favorite_item( *sd, i );
  2666. }
  2667. #endif
  2668. }
  2669. //Required when items break/get-repaired. Only sends equippable item list.
  2670. void clif_equiplist( map_session_data *sd ){
  2671. // TODO: implement again => only send equip part
  2672. clif_inventorylist( sd );
  2673. }
  2674. void clif_storagelist(map_session_data* sd, struct item* items, int items_length, const char *storename){
  2675. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2676. e_inventory_type type = INVTYPE_STORAGE;
  2677. clif_inventoryStart( sd, type, storename );
  2678. #endif
  2679. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2680. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2681. int equip = 0;
  2682. int normal = 0;
  2683. for( int i = 0; i < items_length; i++ ){
  2684. if( items[i].nameid == 0 ){
  2685. continue;
  2686. }
  2687. struct item_data* id = itemdb_search( items[i].nameid );
  2688. // Non-stackable (Equippable)
  2689. if( !itemdb_isstackable2( id ) ){
  2690. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2691. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2692. storage_itemlist_equip.PacketType = storageListEquipType;
  2693. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2694. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2695. storage_itemlist_equip.invType = type;
  2696. #elif PACKETVER >= 20120925
  2697. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2698. #endif
  2699. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2700. equip = 0;
  2701. }
  2702. // Stackable (Normal)
  2703. }else{
  2704. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2705. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2706. storage_itemlist_normal.PacketType = storageListNormalType;
  2707. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2708. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2709. storage_itemlist_normal.invType = type;
  2710. #elif PACKETVER >= 20120925
  2711. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2712. #endif
  2713. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2714. normal = 0;
  2715. }
  2716. }
  2717. }
  2718. if( normal ){
  2719. storage_itemlist_normal.PacketType = storageListNormalType;
  2720. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2721. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2722. storage_itemlist_normal.invType = type;
  2723. #elif PACKETVER >= 20120925
  2724. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2725. #endif
  2726. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2727. }
  2728. if( equip ) {
  2729. storage_itemlist_equip.PacketType = storageListEquipType;
  2730. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2731. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2732. storage_itemlist_equip.invType = type;
  2733. #elif PACKETVER >= 20120925
  2734. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2735. #endif
  2736. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2737. }
  2738. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2739. clif_inventoryEnd( sd, type );
  2740. #endif
  2741. }
  2742. void clif_cartlist( map_session_data *sd ){
  2743. nullpo_retv( sd );
  2744. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2745. e_inventory_type type = INVTYPE_CART;
  2746. clif_inventoryStart( sd, type, "" );
  2747. #endif
  2748. static struct packet_itemlist_normal itemlist_normal;
  2749. static struct packet_itemlist_equip itemlist_equip;
  2750. int normal = 0;
  2751. int equip = 0;
  2752. for( int i = 0; i < MAX_CART; i++ ){
  2753. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2754. continue;
  2755. }
  2756. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2757. // Non-stackable (Equippable)
  2758. if( !itemdb_isstackable2(id) ){
  2759. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2760. // Stackable (Normal)
  2761. }else{
  2762. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2763. }
  2764. }
  2765. if( normal ){
  2766. itemlist_normal.PacketType = cartlistnormalType;
  2767. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2768. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2769. itemlist_normal.invType = type;
  2770. #endif
  2771. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2772. }
  2773. if( equip ){
  2774. itemlist_equip.PacketType = cartlistequipType;
  2775. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2776. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2777. itemlist_equip.invType = type;
  2778. #endif
  2779. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2780. }
  2781. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2782. clif_inventoryEnd( sd, type );
  2783. #endif
  2784. }
  2785. /// Removes cart (ZC_CARTOFF).
  2786. /// 012b
  2787. /// Client behaviour:
  2788. /// Closes the cart storage and removes all it's items from memory.
  2789. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2790. void clif_clearcart(int fd)
  2791. {
  2792. WFIFOHEAD(fd, packet_len(0x12b));
  2793. WFIFOW(fd,0) = 0x12b;
  2794. WFIFOSET(fd, packet_len(0x12b));
  2795. }
  2796. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2797. /// 01eb <account id>.L <x>.W <y>.W
  2798. void clif_guild_xy(map_session_data *sd)
  2799. {
  2800. unsigned char buf[10];
  2801. nullpo_retv(sd);
  2802. WBUFW(buf,0)=0x1eb;
  2803. WBUFL(buf,2)=sd->status.account_id;
  2804. WBUFW(buf,6)=sd->bl.x;
  2805. WBUFW(buf,8)=sd->bl.y;
  2806. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2807. }
  2808. /*==========================================
  2809. * Sends x/y dot to a single fd. [Skotlex]
  2810. *------------------------------------------*/
  2811. void clif_guild_xy_single(int fd, map_session_data *sd)
  2812. {
  2813. if( sd->bg_id )
  2814. return;
  2815. WFIFOHEAD(fd,packet_len(0x1eb));
  2816. WFIFOW(fd,0)=0x1eb;
  2817. WFIFOL(fd,2)=sd->status.account_id;
  2818. WFIFOW(fd,6)=sd->bl.x;
  2819. WFIFOW(fd,8)=sd->bl.y;
  2820. WFIFOSET(fd,packet_len(0x1eb));
  2821. }
  2822. // Guild XY locators [Valaris]
  2823. void clif_guild_xy_remove(map_session_data *sd)
  2824. {
  2825. unsigned char buf[10];
  2826. nullpo_retv(sd);
  2827. WBUFW(buf,0)=0x1eb;
  2828. WBUFL(buf,2)=sd->status.account_id;
  2829. WBUFW(buf,6)=-1;
  2830. WBUFW(buf,8)=-1;
  2831. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2832. }
  2833. /*==========================================
  2834. * Load castle list for guild UI. [Asheraf] / [Balfear]
  2835. *------------------------------------------*/
  2836. void clif_guild_castle_list(map_session_data& sd){
  2837. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2838. auto &g = sd.guild;
  2839. if (g == nullptr)
  2840. return;
  2841. int castle_count = guild_checkcastles(g->guild);
  2842. if (castle_count > 0) {
  2843. struct PACKET_ZC_GUILD_AGIT_INFO* p = (struct PACKET_ZC_GUILD_AGIT_INFO*)packet_buffer;
  2844. p->packetType = HEADER_ZC_GUILD_AGIT_INFO;
  2845. p->packetLength = static_cast<int16>( sizeof( struct PACKET_ZC_GUILD_AGIT_INFO ) );
  2846. int i = 0;
  2847. for (const auto& gc : castle_db) {
  2848. if (gc.second->guild_id == g->guild.guild_id && gc.second->client_id) {
  2849. p->castle_list[i] = static_cast<int8>( gc.second->client_id );
  2850. p->packetLength += static_cast<int16>( sizeof( p->castle_list[0] ) );
  2851. ++i;
  2852. }
  2853. }
  2854. clif_send(p, p->packetLength, &sd.bl, SELF);
  2855. }
  2856. #endif
  2857. }
  2858. /*==========================================
  2859. * Send castle info Economy/Defence. [Asheraf] / [Balfear]
  2860. *------------------------------------------*/
  2861. void clif_guild_castleinfo(map_session_data& sd, std::shared_ptr<guild_castle> castle ){
  2862. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2863. if( castle->client_id == 0 ){
  2864. return;
  2865. }
  2866. struct PACKET_ZC_REQ_ACK_AGIT_INVESTMENT p = {};
  2867. p.packetType = HEADER_ZC_REQ_ACK_AGIT_INVESTMENT;
  2868. p.castle_id = static_cast<int8>( castle->client_id );
  2869. p.economy = castle->economy;
  2870. p.defense = castle->defense;
  2871. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2872. #endif
  2873. }
  2874. /*==========================================
  2875. * Show teleport request result. [Asheraf] / [Balfear]
  2876. *------------------------------------------*/
  2877. void clif_guild_castle_teleport_res(map_session_data& sd, enum e_siege_teleport_result result){
  2878. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2879. struct PACKET_ZC_REQ_ACK_MOVE_GUILD_AGIT p = {};
  2880. p.packetType = HEADER_ZC_REQ_ACK_MOVE_GUILD_AGIT;
  2881. p.result = static_cast<int16>( result );
  2882. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2883. #endif
  2884. }
  2885. /*==========================================
  2886. * Request castle info. [Asheraf] / [Balfear]
  2887. *------------------------------------------*/
  2888. void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){
  2889. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2890. const struct PACKET_CZ_REQ_AGIT_INVESTMENT* p = (struct PACKET_CZ_REQ_AGIT_INVESTMENT*)RFIFOP(fd, 0);
  2891. auto &g = sd->guild;
  2892. if (g == nullptr)
  2893. return;
  2894. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2895. if (gc == nullptr)
  2896. return;
  2897. if (gc->guild_id != g->guild.guild_id)
  2898. return;
  2899. clif_guild_castleinfo(*sd, gc);
  2900. #endif
  2901. }
  2902. /*==========================================
  2903. * Teleport to castle. [Asheraf] / [Balfear]
  2904. *------------------------------------------*/
  2905. void clif_parse_guild_castle_teleport_request(int fd, map_session_data* sd){
  2906. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2907. const struct PACKET_CZ_REQ_MOVE_GUILD_AGIT* p = (struct PACKET_CZ_REQ_MOVE_GUILD_AGIT*)RFIFOP(fd, 0);
  2908. auto &g = sd->guild;
  2909. if (g == nullptr)
  2910. return;
  2911. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2912. if (gc == nullptr)
  2913. return;
  2914. if (!gc->warp_enabled)
  2915. return;
  2916. if (gc->guild_id != g->guild.guild_id)
  2917. return;
  2918. if (map_getmapflag(sd->bl.m, MF_GVG_CASTLE)
  2919. || map_getmapflag(sd->bl.m, MF_NOTELEPORT)
  2920. || map_getmapflag(sd->bl.m, MF_NOWARP))
  2921. return;
  2922. uint32 zeny = gc->zeny;
  2923. switch( gc->type ){
  2924. case WOE_FIRST_EDITION:
  2925. if( agit_flag ){
  2926. zeny = gc->zeny_siege;
  2927. }
  2928. break;
  2929. case WOE_SECOND_EDITION:
  2930. if( agit2_flag ){
  2931. zeny = gc->zeny_siege;
  2932. }
  2933. break;
  2934. case WOE_THIRD_EDITION:
  2935. if( agit3_flag ){
  2936. zeny = gc->zeny_siege;
  2937. }
  2938. break;
  2939. }
  2940. if (zeny && pc_payzeny(sd, zeny, LOG_TYPE_OTHER)) {
  2941. clif_guild_castle_teleport_res(*sd, SIEGE_TP_NOT_ENOUGH_ZENY);
  2942. return;
  2943. }
  2944. pc_setpos(sd, gc->mapindex, gc->warp_x, gc->warp_y, CLR_OUTSIGHT);
  2945. #endif
  2946. }
  2947. /*==========================================
  2948. *
  2949. *------------------------------------------*/
  2950. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2951. map_session_data* sd = va_arg( ap, map_session_data* );
  2952. map_session_data* tsd = BL_CAST( BL_PC, bl );
  2953. nullpo_ret(sd);
  2954. nullpo_ret(tsd);
  2955. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2956. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2957. }
  2958. return 0;
  2959. }
  2960. /*==========================================
  2961. * Server tells all players that are allowed to view HP bars
  2962. * and are nearby 'sd' that 'sd' hp bar was updated.
  2963. *------------------------------------------*/
  2964. static int clif_hpmeter(map_session_data *sd)
  2965. {
  2966. nullpo_ret(sd);
  2967. map_foreachinallarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2968. return 0;
  2969. }
  2970. /**
  2971. * Send HP bar update to others.
  2972. * @param sd: Player invoking update
  2973. */
  2974. void clif_update_hp(map_session_data &sd) {
  2975. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2976. clif_hpmeter(&sd);
  2977. if (!battle_config.party_hp_mode && sd.status.party_id)
  2978. clif_party_hp( sd );
  2979. if (sd.bg_id)
  2980. clif_bg_hp(&sd);
  2981. }
  2982. /// Notifies client of a character parameter change.
  2983. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2984. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2985. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2986. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2987. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2988. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2989. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2990. /// TODO: Extract individual packets.
  2991. /// FIXME: Packet lengths from packet_len(cmd)
  2992. void clif_updatestatus(map_session_data *sd,int type)
  2993. {
  2994. int fd,len=8;
  2995. nullpo_retv(sd);
  2996. fd=sd->fd;
  2997. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2998. return;
  2999. WFIFOHEAD(fd, 14);
  3000. WFIFOW(fd,0)=0xb0;
  3001. WFIFOW(fd,2)=type;
  3002. switch(type){
  3003. // 00b0
  3004. case SP_WEIGHT:
  3005. pc_updateweightstatus(sd);
  3006. WFIFOHEAD(fd,14);
  3007. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  3008. WFIFOW(fd,2)=type;
  3009. WFIFOL(fd,4)=sd->weight;
  3010. break;
  3011. case SP_MAXWEIGHT:
  3012. WFIFOL(fd,4)=sd->max_weight;
  3013. break;
  3014. case SP_SPEED:
  3015. WFIFOL(fd,4)=sd->battle_status.speed;
  3016. break;
  3017. case SP_BASELEVEL:
  3018. WFIFOL(fd,4)=sd->status.base_level;
  3019. break;
  3020. case SP_JOBLEVEL:
  3021. WFIFOL(fd,4)=sd->status.job_level;
  3022. break;
  3023. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  3024. WFIFOL(fd,4)=sd->status.karma;
  3025. break;
  3026. case SP_MANNER:
  3027. WFIFOL(fd,4)=sd->status.manner;
  3028. break;
  3029. case SP_STATUSPOINT:
  3030. WFIFOL(fd,4)=sd->status.status_point;
  3031. break;
  3032. case SP_SKILLPOINT:
  3033. WFIFOL(fd,4)=sd->status.skill_point;
  3034. break;
  3035. case SP_HIT:
  3036. WFIFOL(fd,4)=sd->battle_status.hit;
  3037. break;
  3038. case SP_FLEE1:
  3039. WFIFOL(fd,4)=sd->battle_status.flee;
  3040. break;
  3041. case SP_FLEE2:
  3042. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  3043. break;
  3044. case SP_MAXHP:
  3045. WFIFOL(fd,4)=sd->battle_status.max_hp;
  3046. break;
  3047. case SP_MAXSP:
  3048. WFIFOL(fd,4)=sd->battle_status.max_sp;
  3049. break;
  3050. case SP_HP:
  3051. // On officials the HP never go below 1, even if you die [Lemongrass]
  3052. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  3053. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  3054. break;
  3055. case SP_SP:
  3056. WFIFOL(fd,4)=sd->battle_status.sp;
  3057. break;
  3058. case SP_ASPD:
  3059. WFIFOL(fd,4)=sd->battle_status.amotion;
  3060. break;
  3061. case SP_ATK1:
  3062. WFIFOL(fd,4)=pc_leftside_atk(sd);
  3063. break;
  3064. case SP_DEF1:
  3065. WFIFOL(fd,4)=pc_leftside_def(sd);
  3066. break;
  3067. case SP_MDEF1:
  3068. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  3069. break;
  3070. case SP_ATK2:
  3071. WFIFOL(fd,4)=pc_rightside_atk(sd);
  3072. break;
  3073. case SP_DEF2:
  3074. WFIFOL(fd,4)=pc_rightside_def(sd);
  3075. break;
  3076. case SP_MDEF2: {
  3077. //negative check (in case you have something like Berserk active)
  3078. int mdef2 = pc_rightside_mdef(sd);
  3079. WFIFOL(fd,4)=
  3080. #ifndef RENEWAL
  3081. ( mdef2 < 0 ) ? 0 :
  3082. #endif
  3083. mdef2;
  3084. }
  3085. break;
  3086. case SP_CRITICAL:
  3087. WFIFOL(fd,4)=sd->battle_status.cri/10;
  3088. break;
  3089. case SP_MATK1:
  3090. WFIFOL(fd,4)=pc_rightside_matk(sd);
  3091. break;
  3092. case SP_MATK2:
  3093. WFIFOL(fd,4)=pc_leftside_matk(sd);
  3094. break;
  3095. case SP_ZENY:
  3096. WFIFOW(fd,0)=0xb1;
  3097. WFIFOL(fd,4)=sd->status.zeny;
  3098. break;
  3099. #if PACKETVER >= 20170830
  3100. case SP_BASEEXP:
  3101. WFIFOW(fd,0)=0xacb;
  3102. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  3103. len = packet_len(0xacb);
  3104. break;
  3105. case SP_JOBEXP:
  3106. WFIFOW(fd,0)=0xacb;
  3107. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  3108. len = packet_len(0xacb);
  3109. break;
  3110. case SP_NEXTBASEEXP:
  3111. WFIFOW(fd,0)=0xacb;
  3112. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  3113. len = packet_len(0xacb);
  3114. break;
  3115. case SP_NEXTJOBEXP:
  3116. WFIFOW(fd,0)=0xacb;
  3117. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3118. len = packet_len(0xacb);
  3119. break;
  3120. #else
  3121. case SP_BASEEXP:
  3122. WFIFOW(fd,0)=0xb1;
  3123. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3124. break;
  3125. case SP_JOBEXP:
  3126. WFIFOW(fd,0)=0xb1;
  3127. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3128. break;
  3129. case SP_NEXTBASEEXP:
  3130. WFIFOW(fd,0)=0xb1;
  3131. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3132. break;
  3133. case SP_NEXTJOBEXP:
  3134. WFIFOW(fd,0)=0xb1;
  3135. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3136. break;
  3137. #endif
  3138. /**
  3139. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3140. **/
  3141. case SP_USTR:
  3142. case SP_UAGI:
  3143. case SP_UVIT:
  3144. case SP_UINT:
  3145. case SP_UDEX:
  3146. case SP_ULUK:
  3147. WFIFOW(fd,0)=0xbe;
  3148. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3149. len=5;
  3150. break;
  3151. /**
  3152. * Tells the client how far it is allowed to attack (weapon range)
  3153. **/
  3154. case SP_ATTACKRANGE:
  3155. WFIFOW(fd,0)=0x13a;
  3156. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3157. len=4;
  3158. break;
  3159. case SP_STR:
  3160. WFIFOW(fd,0)=0x141;
  3161. WFIFOL(fd,2)=type;
  3162. WFIFOL(fd,6)=sd->status.str;
  3163. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3164. len=14;
  3165. break;
  3166. case SP_AGI:
  3167. WFIFOW(fd,0)=0x141;
  3168. WFIFOL(fd,2)=type;
  3169. WFIFOL(fd,6)=sd->status.agi;
  3170. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3171. len=14;
  3172. break;
  3173. case SP_VIT:
  3174. WFIFOW(fd,0)=0x141;
  3175. WFIFOL(fd,2)=type;
  3176. WFIFOL(fd,6)=sd->status.vit;
  3177. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3178. len=14;
  3179. break;
  3180. case SP_INT:
  3181. WFIFOW(fd,0)=0x141;
  3182. WFIFOL(fd,2)=type;
  3183. WFIFOL(fd,6)=sd->status.int_;
  3184. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3185. len=14;
  3186. break;
  3187. case SP_DEX:
  3188. WFIFOW(fd,0)=0x141;
  3189. WFIFOL(fd,2)=type;
  3190. WFIFOL(fd,6)=sd->status.dex;
  3191. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3192. len=14;
  3193. break;
  3194. case SP_LUK:
  3195. WFIFOW(fd,0)=0x141;
  3196. WFIFOL(fd,2)=type;
  3197. WFIFOL(fd,6)=sd->status.luk;
  3198. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3199. len=14;
  3200. break;
  3201. case SP_CARTINFO:
  3202. WFIFOW(fd,0)=0x121;
  3203. WFIFOW(fd,2)=sd->cart_num;
  3204. WFIFOW(fd,4)=MAX_CART;
  3205. WFIFOL(fd,6)=sd->cart_weight;
  3206. WFIFOL(fd,10)=sd->cart_weight_max;
  3207. len=14;
  3208. break;
  3209. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3210. case SP_AP:
  3211. WFIFOL(fd, 4) = sd->battle_status.ap;
  3212. break;
  3213. case SP_TRAITPOINT:
  3214. WFIFOL(fd, 4) = sd->status.trait_point;
  3215. break;
  3216. case SP_MAXAP:
  3217. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3218. break;
  3219. case SP_POW:
  3220. WFIFOW(fd, 0) = 0x141;
  3221. WFIFOL(fd, 2) = type;
  3222. WFIFOL(fd, 6) = sd->status.pow;
  3223. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3224. len = 14;
  3225. break;
  3226. case SP_STA:
  3227. WFIFOW(fd, 0) = 0x141;
  3228. WFIFOL(fd, 2) = type;
  3229. WFIFOL(fd, 6) = sd->status.sta;
  3230. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3231. len = 14;
  3232. break;
  3233. case SP_WIS:
  3234. WFIFOW(fd, 0) = 0x141;
  3235. WFIFOL(fd, 2) = type;
  3236. WFIFOL(fd, 6) = sd->status.wis;
  3237. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3238. len = 14;
  3239. break;
  3240. case SP_SPL:
  3241. WFIFOW(fd, 0) = 0x141;
  3242. WFIFOL(fd, 2) = type;
  3243. WFIFOL(fd, 6) = sd->status.spl;
  3244. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3245. len = 14;
  3246. break;
  3247. case SP_CON:
  3248. WFIFOW(fd, 0) = 0x141;
  3249. WFIFOL(fd, 2) = type;
  3250. WFIFOL(fd, 6) = sd->status.con;
  3251. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3252. len = 14;
  3253. break;
  3254. case SP_CRT:
  3255. WFIFOW(fd, 0) = 0x141;
  3256. WFIFOL(fd, 2) = type;
  3257. WFIFOL(fd, 6) = sd->status.crt;
  3258. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3259. len = 14;
  3260. break;
  3261. case SP_UPOW:
  3262. case SP_USTA:
  3263. case SP_UWIS:
  3264. case SP_USPL:
  3265. case SP_UCON:
  3266. case SP_UCRT:
  3267. WFIFOW(fd, 0) = 0xbe;
  3268. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3269. len = 5;
  3270. break;
  3271. case SP_PATK:
  3272. WFIFOL(fd, 4) = sd->battle_status.patk;
  3273. break;
  3274. case SP_SMATK:
  3275. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3276. break;
  3277. case SP_RES:
  3278. WFIFOL(fd, 4) = sd->battle_status.res;
  3279. break;
  3280. case SP_MRES:
  3281. WFIFOL(fd, 4) = sd->battle_status.mres;
  3282. break;
  3283. case SP_HPLUS:
  3284. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3285. break;
  3286. case SP_CRATE:
  3287. WFIFOL(fd, 4) = sd->battle_status.crate;
  3288. break;
  3289. #else
  3290. case SP_AP:
  3291. case SP_TRAITPOINT:
  3292. case SP_MAXAP:
  3293. case SP_POW:
  3294. case SP_STA:
  3295. case SP_WIS:
  3296. case SP_SPL:
  3297. case SP_CON:
  3298. case SP_CRT:
  3299. case SP_UPOW:
  3300. case SP_USTA:
  3301. case SP_UWIS:
  3302. case SP_USPL:
  3303. case SP_UCON:
  3304. case SP_UCRT:
  3305. case SP_PATK:
  3306. case SP_SMATK:
  3307. case SP_RES:
  3308. case SP_MRES:
  3309. case SP_HPLUS:
  3310. case SP_CRATE:
  3311. // 4th job status are not supported by older clients
  3312. return;
  3313. #endif
  3314. default:
  3315. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3316. return;
  3317. }
  3318. WFIFOSET(fd,len);
  3319. // Additional update packets that should be sent right after
  3320. switch( type ){
  3321. case SP_BASELEVEL:
  3322. if( sd->status.party_id ){
  3323. struct party_data* p;
  3324. int i;
  3325. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3326. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3327. if( i < MAX_PARTY ){
  3328. p->party.member[i].lv = sd->status.base_level;
  3329. clif_party_job_and_level( *sd );
  3330. }
  3331. }
  3332. }
  3333. break;
  3334. case SP_HP:
  3335. clif_update_hp(*sd);
  3336. break;
  3337. }
  3338. }
  3339. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3340. /// 01ab <account id>.L <var id>.W <value>.L
  3341. void clif_changestatus(map_session_data* sd,int type,int val)
  3342. {
  3343. unsigned char buf[12];
  3344. nullpo_retv(sd);
  3345. WBUFW(buf,0)=0x1ab;
  3346. WBUFL(buf,2)=sd->bl.id;
  3347. WBUFW(buf,6)=type;
  3348. switch(type)
  3349. {
  3350. case SP_MANNER:
  3351. WBUFL(buf,8)=val;
  3352. break;
  3353. default:
  3354. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3355. return;
  3356. }
  3357. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3358. }
  3359. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3360. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3361. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3362. struct PACKET_ZC_SPRITE_CHANGE p;
  3363. p.packetType = sendLookType;
  3364. p.AID = id;
  3365. p.type = type;
  3366. p.val = val;
  3367. #if PACKETVER >= 4
  3368. p.val2 = val2;
  3369. #endif
  3370. clif_send( &p, sizeof( p ), bl, target );
  3371. }
  3372. /// Updates sprite/style properties of an object.
  3373. void clif_changelook(struct block_list *bl, int type, int val) {
  3374. map_session_data* sd;
  3375. status_change* sc;
  3376. struct view_data* vd;
  3377. enum send_target target = AREA;
  3378. int val2 = 0;
  3379. nullpo_retv(bl);
  3380. sd = BL_CAST(BL_PC, bl);
  3381. sc = status_get_sc(bl);
  3382. vd = status_get_viewdata(bl);
  3383. if( vd ) //temp hack to let Warp Portal change appearance
  3384. switch(type) {
  3385. case LOOK_WEAPON:
  3386. if (sd) {
  3387. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3388. val = vd->weapon;
  3389. }
  3390. else
  3391. vd->weapon = val;
  3392. break;
  3393. case LOOK_SHIELD:
  3394. if (sd) {
  3395. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3396. val = vd->shield;
  3397. }
  3398. else
  3399. vd->shield = val;
  3400. break;
  3401. case LOOK_BASE:
  3402. if (!sd)
  3403. break;
  3404. if ( val == JT_INVISIBLE )
  3405. return;
  3406. if (sd->sc.option&OPTION_COSTUME)
  3407. vd->weapon = vd->shield = 0;
  3408. if (!vd->cloth_color)
  3409. break;
  3410. if (sd) {
  3411. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3412. vd->cloth_color = 0;
  3413. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3414. vd->cloth_color = 0;
  3415. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3416. vd->cloth_color = 0;
  3417. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3418. vd->cloth_color = 0;
  3419. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3420. vd->cloth_color = 0;
  3421. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3422. vd->body_style = 0;
  3423. }
  3424. break;
  3425. case LOOK_HAIR:
  3426. vd->hair_style = val;
  3427. break;
  3428. case LOOK_HEAD_BOTTOM:
  3429. vd->head_bottom = val;
  3430. break;
  3431. case LOOK_HEAD_TOP:
  3432. vd->head_top = val;
  3433. break;
  3434. case LOOK_HEAD_MID:
  3435. vd->head_mid = val;
  3436. break;
  3437. case LOOK_HAIR_COLOR:
  3438. vd->hair_color = val;
  3439. break;
  3440. case LOOK_CLOTHES_COLOR:
  3441. if (val && sd) {
  3442. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3443. val = 0;
  3444. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3445. val = 0;
  3446. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3447. val = 0;
  3448. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3449. val = 0;
  3450. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3451. val = 0;
  3452. }
  3453. vd->cloth_color = val;
  3454. break;
  3455. case LOOK_SHOES:
  3456. #if PACKETVER > 3
  3457. if (sd) {
  3458. int n;
  3459. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3460. if(sd->inventory_data[n]->view_id > 0)
  3461. val = sd->inventory_data[n]->view_id;
  3462. else
  3463. val = sd->inventory.u.items_inventory[n].nameid;
  3464. } else
  3465. val = 0;
  3466. }
  3467. #endif
  3468. //Shoes? No packet uses this....
  3469. break;
  3470. case LOOK_BODY:
  3471. // unknown purpose
  3472. break;
  3473. case LOOK_ROBE:
  3474. #if PACKETVER < 20110111
  3475. return;
  3476. #else
  3477. vd->robe = val;
  3478. #endif
  3479. break;
  3480. case LOOK_BODY2:
  3481. #if PACKETVER < 20150513
  3482. return;
  3483. #else
  3484. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3485. val = 0;
  3486. vd->body_style = val;
  3487. #endif
  3488. break;
  3489. }
  3490. // prevent leaking the presence of GM-hidden objects
  3491. if( sc && sc->option&OPTION_INVISIBLE )
  3492. target = SELF;
  3493. #if PACKETVER < 4
  3494. if (target != SELF && bl->type == BL_NPC && (((TBL_NPC*)bl)->is_invisible))
  3495. target = SELF;
  3496. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3497. #else
  3498. if (bl->type != BL_NPC) {
  3499. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3500. type = LOOK_WEAPON;
  3501. val = (vd ? vd->weapon : 0);
  3502. val2 = (vd ? vd->shield : 0);
  3503. }
  3504. if (disguised(bl)) {
  3505. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3506. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3507. } else
  3508. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3509. } else
  3510. unit_refresh(bl);
  3511. #endif
  3512. }
  3513. //Sends a change-base-look packet required for traps as they are triggered.
  3514. void clif_changetraplook(struct block_list *bl,int val) {
  3515. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3516. }
  3517. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3518. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3519. clif_sprite_change(bl, id, type, val, 0, target);
  3520. }
  3521. /// Character status (ZC_STATUS).
  3522. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3523. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3524. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3525. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3526. void clif_initialstatus(map_session_data *sd) {
  3527. int fd, mdef2;
  3528. unsigned char *buf;
  3529. nullpo_retv(sd);
  3530. fd=sd->fd;
  3531. WFIFOHEAD(fd, packet_len(0xbd));
  3532. buf = WFIFOP(fd,0);
  3533. WBUFW(buf,0) = 0xbd;
  3534. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3535. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3536. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3537. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3538. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3539. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3540. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3541. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3542. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3543. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3544. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3545. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3546. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3547. WBUFW(buf,16) = pc_leftside_atk(sd);
  3548. WBUFW(buf,18) = pc_rightside_atk(sd);
  3549. WBUFW(buf,20) = pc_rightside_matk(sd);
  3550. WBUFW(buf,22) = pc_leftside_matk(sd);
  3551. WBUFW(buf,24) = pc_leftside_def(sd);
  3552. WBUFW(buf,26) = pc_rightside_def(sd);
  3553. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3554. mdef2 = pc_rightside_mdef(sd);
  3555. WBUFW(buf,30) =
  3556. #ifndef RENEWAL
  3557. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3558. #endif
  3559. mdef2;
  3560. WBUFW(buf,32) = sd->battle_status.hit;
  3561. WBUFW(buf,34) = sd->battle_status.flee;
  3562. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3563. WBUFW(buf,38) = sd->battle_status.cri/10;
  3564. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3565. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3566. WFIFOSET(fd, packet_len(0xbd));
  3567. clif_updatestatus(sd, SP_STR);
  3568. clif_updatestatus(sd, SP_AGI);
  3569. clif_updatestatus(sd, SP_VIT);
  3570. clif_updatestatus(sd, SP_INT);
  3571. clif_updatestatus(sd, SP_DEX);
  3572. clif_updatestatus(sd, SP_LUK);
  3573. clif_updatestatus(sd, SP_ATTACKRANGE);
  3574. clif_updatestatus(sd, SP_ASPD);
  3575. #ifdef RENEWAL
  3576. clif_updatestatus(sd, SP_POW);
  3577. clif_updatestatus(sd, SP_STA);
  3578. clif_updatestatus(sd, SP_WIS);
  3579. clif_updatestatus(sd, SP_SPL);
  3580. clif_updatestatus(sd, SP_CON);
  3581. clif_updatestatus(sd, SP_CRT);
  3582. clif_updatestatus(sd, SP_PATK);
  3583. clif_updatestatus(sd, SP_SMATK);
  3584. clif_updatestatus(sd, SP_RES);
  3585. clif_updatestatus(sd, SP_MRES);
  3586. clif_updatestatus(sd, SP_HPLUS);
  3587. clif_updatestatus(sd, SP_CRATE);
  3588. clif_updatestatus(sd, SP_TRAITPOINT);
  3589. clif_updatestatus(sd, SP_AP);
  3590. clif_updatestatus(sd, SP_MAXAP);
  3591. clif_updatestatus(sd, SP_UPOW);
  3592. clif_updatestatus(sd, SP_USTA);
  3593. clif_updatestatus(sd, SP_UWIS);
  3594. clif_updatestatus(sd, SP_USPL);
  3595. clif_updatestatus(sd, SP_UCON);
  3596. clif_updatestatus(sd, SP_UCRT);
  3597. #endif
  3598. }
  3599. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3600. /// 013c <index>.W
  3601. void clif_arrowequip(map_session_data *sd,int val) {
  3602. int fd;
  3603. nullpo_retv(sd);
  3604. #if PACKETVER >= 20121128
  3605. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3606. #endif
  3607. fd=sd->fd;
  3608. WFIFOHEAD(fd, packet_len(0x013c));
  3609. WFIFOW(fd,0) = 0x013c;
  3610. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3611. WFIFOSET(fd, packet_len(0x013c));
  3612. }
  3613. /// Ammunition action message (ZC_ACTION_FAILURE).
  3614. /// 013b <type>.W
  3615. /// type:
  3616. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3617. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3618. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3619. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3620. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3621. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3622. void clif_arrow_fail(map_session_data *sd,int type) {
  3623. int fd;
  3624. nullpo_retv(sd);
  3625. fd=sd->fd;
  3626. WFIFOHEAD(fd, packet_len(0x013b));
  3627. WFIFOW(fd,0) = 0x013b;
  3628. WFIFOW(fd,2) = type;
  3629. WFIFOSET(fd, packet_len(0x013b));
  3630. }
  3631. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3632. /// 01ad <packet len>.W { <name id>.W }*
  3633. void clif_arrow_create_list( map_session_data *sd ){
  3634. nullpo_retv( sd );
  3635. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3636. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3637. int count = 0;
  3638. for (const auto &it : skill_arrow_db) {
  3639. t_itemid nameid = it.second->nameid;
  3640. if( !item_db.exists( nameid ) ){
  3641. continue;
  3642. }
  3643. int index = pc_search_inventory( sd, nameid );
  3644. if( index < 0 ){
  3645. continue;
  3646. }
  3647. if( sd->inventory.u.items_inventory[index].equip ){
  3648. continue;
  3649. }
  3650. if( !sd->inventory.u.items_inventory[index].identify ){
  3651. continue;
  3652. }
  3653. p->items[count].itemId = client_nameid( nameid );
  3654. count++;
  3655. }
  3656. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3657. clif_send( p, p->packetLength, &sd->bl, SELF );
  3658. if( count > 0 ){
  3659. sd->menuskill_id = AC_MAKINGARROW;
  3660. sd->menuskill_val = count;
  3661. }
  3662. }
  3663. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3664. /// 00bc <status id>.W <result>.B <value>.B
  3665. /// status id:
  3666. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3667. /// result:
  3668. /// 0 = failure
  3669. /// 1 = success
  3670. void clif_statusupack(map_session_data *sd,int type,int ok,int val) {
  3671. int fd;
  3672. nullpo_retv(sd);
  3673. fd=sd->fd;
  3674. WFIFOHEAD(fd, packet_len(0xbc));
  3675. WFIFOW(fd,0) = 0xbc;
  3676. WFIFOW(fd,2) = type;
  3677. WFIFOB(fd,4) = ok;
  3678. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3679. WFIFOSET(fd, packet_len(0xbc));
  3680. }
  3681. /// Notifies the client about the result of a request to equip an item.
  3682. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3683. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3684. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3685. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3686. /// @ok: //inversed forv2 v5
  3687. /// 0 = failure
  3688. /// 1 = success
  3689. /// 2 = failure due to low level
  3690. void clif_equipitemack( map_session_data& sd, uint8 flag, int index, int pos ){
  3691. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3692. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3693. p.index = client_index( index );
  3694. p.wearLocation = pos;
  3695. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3696. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3697. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3698. }else{
  3699. p.wItemSpriteNumber = 0;
  3700. }
  3701. #endif
  3702. p.result = flag;
  3703. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3704. }
  3705. /// Notifies the client about the result of a request to take off an item.
  3706. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3707. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3708. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3709. /// @ok : //inversed for v2 v5
  3710. /// 0 = failure
  3711. /// 1 = success
  3712. void clif_unequipitemack(map_session_data *sd,int n,int pos,int ok)
  3713. {
  3714. int fd, header, offs = 0;
  3715. #if PACKETVER >= 20130000
  3716. header = 0x99a;
  3717. ok = ok ? 0 : 1;
  3718. #elif PACKETVER >= 20110824
  3719. header = 0x8d1;
  3720. ok = ok ? 0 : 1;
  3721. #else
  3722. header = 0xac;
  3723. #endif
  3724. nullpo_retv(sd);
  3725. fd=sd->fd;
  3726. WFIFOHEAD(fd, packet_len(header));
  3727. WFIFOW(fd,offs+0) = header;
  3728. WFIFOW(fd,offs+2) = n+2;
  3729. #if PACKETVER >= 20130000
  3730. WFIFOL(fd,offs+4) = pos;
  3731. offs += 2;
  3732. #else
  3733. WFIFOW(fd,offs+4) = pos;
  3734. #endif
  3735. WFIFOB(fd,offs+6) = ok;
  3736. WFIFOSET(fd, packet_len(header));
  3737. }
  3738. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3739. /// 019b <id>.L <effect id>.L
  3740. /// effect id:
  3741. /// 0 = base level up
  3742. /// 1 = job level up
  3743. /// 2 = refine failure
  3744. /// 3 = refine success
  3745. /// 4 = game over
  3746. /// 5 = pharmacy success
  3747. /// 6 = pharmacy failure
  3748. /// 7 = base level up (super novice)
  3749. /// 8 = job level up (super novice)
  3750. /// 9 = base level up (taekwon)
  3751. void clif_misceffect(struct block_list* bl,int type)
  3752. {
  3753. unsigned char buf[32];
  3754. nullpo_retv(bl);
  3755. WBUFW(buf,0) = 0x19b;
  3756. WBUFL(buf,2) = bl->id;
  3757. WBUFL(buf,6) = type;
  3758. clif_send(buf,packet_len(0x19b),bl,AREA);
  3759. }
  3760. /// Notifies clients in the area of a state change.
  3761. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3762. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3763. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3764. nullpo_retv( bl );
  3765. status_change* sc = status_get_sc( bl );
  3766. //How can an option change if there's no sc?
  3767. if( sc == nullptr ){
  3768. return;
  3769. }
  3770. map_session_data* sd = BL_CAST( BL_PC, bl );
  3771. struct PACKET_ZC_STATE_CHANGE p;
  3772. p.packetType = HEADER_ZC_STATE_CHANGE;
  3773. p.AID = bl->id;
  3774. p.bodyState = sc->opt1;
  3775. p.healthState = sc->opt2;
  3776. p.effectState = sc->option;
  3777. p.isPKModeON = sd ? sd->status.karma : false;
  3778. if( target == nullptr ){
  3779. if( disguised( bl ) ){
  3780. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3781. p.AID = disguised_bl_id( p.AID );
  3782. clif_send( &p, sizeof( p ), bl, SELF );
  3783. p.AID = disguised_bl_id( p.AID );
  3784. p.effectState = OPTION_INVISIBLE;
  3785. clif_send( &p, sizeof( p ), bl, SELF );
  3786. }else{
  3787. clif_send( &p, sizeof( p ), bl, AREA );
  3788. }
  3789. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3790. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3791. if( sc->getSCE(SC_PROVOKE) ){
  3792. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3793. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3794. }
  3795. }else{
  3796. if( disguised( bl ) ){
  3797. p.AID = disguised_bl_id( p.AID );
  3798. clif_send( &p, sizeof( p ), target, SELF );
  3799. p.AID = disguised_bl_id( p.AID );
  3800. p.effectState = OPTION_INVISIBLE;
  3801. clif_send( &p, sizeof( p ), target, SELF );
  3802. }else{
  3803. clif_send( &p, sizeof( p ), target, SELF );
  3804. }
  3805. }
  3806. }
  3807. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3808. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3809. void clif_changeoption2(struct block_list* bl)
  3810. {
  3811. unsigned char buf[20];
  3812. status_change *sc;
  3813. sc = status_get_sc(bl);
  3814. if (!sc) return; //How can an option change if there's no sc?
  3815. WBUFW(buf,0) = 0x28a;
  3816. WBUFL(buf,2) = bl->id;
  3817. WBUFL(buf,6) = sc->option;
  3818. WBUFL(buf,10) = clif_setlevel(bl);
  3819. WBUFL(buf,14) = sc->opt3;
  3820. if(disguised(bl)) {
  3821. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3822. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3823. clif_send(buf,packet_len(0x28a),bl,SELF);
  3824. WBUFL(buf,2) = bl->id;
  3825. WBUFL(buf,6) = OPTION_INVISIBLE;
  3826. clif_send(buf,packet_len(0x28a),bl,SELF);
  3827. } else
  3828. clif_send(buf,packet_len(0x28a),bl,AREA);
  3829. }
  3830. /// Notifies the client about the result of an item use request.
  3831. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3832. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3833. void clif_useitemack( map_session_data *sd, int index, int amount, bool ok ){
  3834. nullpo_retv( sd );
  3835. int fd = sd->fd;
  3836. if( !session_isActive( fd ) ){
  3837. return;
  3838. }
  3839. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3840. return;
  3841. }
  3842. struct PACKET_ZC_USE_ITEM_ACK p;
  3843. p.packetType = useItemAckType;
  3844. p.index = index + 2;
  3845. #if PACKETVER > 3
  3846. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3847. p.AID = sd->bl.id;
  3848. #endif
  3849. p.amount = amount;
  3850. p.result = ok;
  3851. if( !ok ){
  3852. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3853. }else{
  3854. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3855. }
  3856. }
  3857. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3858. /// 00d6 <flag>.B
  3859. /// flag:
  3860. /// 0 = Room has been successfully created (opens chat room)
  3861. /// 1 = Room limit exceeded
  3862. /// 2 = Same room already exists
  3863. void clif_createchat(map_session_data* sd, int flag)
  3864. {
  3865. int fd;
  3866. nullpo_retv(sd);
  3867. fd = sd->fd;
  3868. WFIFOHEAD(fd,packet_len(0xd6));
  3869. WFIFOW(fd,0) = 0xd6;
  3870. WFIFOB(fd,2) = flag;
  3871. WFIFOSET(fd,packet_len(0xd6));
  3872. }
  3873. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3874. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3875. /// type:
  3876. /// 0 = private (password protected)
  3877. /// 1 = public
  3878. /// 2 = arena (npc waiting room)
  3879. /// 3 = PK zone (non-clickable)
  3880. void clif_dispchat(struct chat_data* cd, int fd)
  3881. {
  3882. unsigned char buf[128];
  3883. uint8 type;
  3884. if( cd == NULL || cd->owner == NULL )
  3885. return;
  3886. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3887. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3888. : 1;
  3889. WBUFW(buf, 0) = 0xd7;
  3890. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3891. WBUFL(buf, 4) = cd->owner->id;
  3892. WBUFL(buf, 8) = cd->bl.id;
  3893. WBUFW(buf,12) = cd->limit;
  3894. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3895. WBUFB(buf,16) = type;
  3896. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3897. if( session_isActive(fd) ) {
  3898. WFIFOHEAD(fd,WBUFW(buf,2));
  3899. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3900. WFIFOSET(fd,WBUFW(buf,2));
  3901. } else {
  3902. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3903. }
  3904. }
  3905. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3906. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3907. /// type:
  3908. /// 0 = private (password protected)
  3909. /// 1 = public
  3910. /// 2 = arena (npc waiting room)
  3911. /// 3 = PK zone (non-clickable)
  3912. void clif_changechatstatus(struct chat_data* cd)
  3913. {
  3914. unsigned char buf[128];
  3915. uint8 type;
  3916. if( cd == NULL || cd->usersd[0] == NULL )
  3917. return;
  3918. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3919. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3920. : 1;
  3921. WBUFW(buf, 0) = 0xdf;
  3922. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3923. WBUFL(buf, 4) = cd->owner->id;
  3924. WBUFL(buf, 8) = cd->bl.id;
  3925. WBUFW(buf,12) = cd->limit;
  3926. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3927. WBUFB(buf,16) = type;
  3928. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3929. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3930. }
  3931. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3932. /// 00d8 <chat id>.L
  3933. void clif_clearchat(struct chat_data *cd,int fd)
  3934. {
  3935. unsigned char buf[32];
  3936. nullpo_retv(cd);
  3937. WBUFW(buf,0) = 0xd8;
  3938. WBUFL(buf,2) = cd->bl.id;
  3939. if( session_isActive(fd) ) {
  3940. WFIFOHEAD(fd,packet_len(0xd8));
  3941. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3942. WFIFOSET(fd,packet_len(0xd8));
  3943. } else {
  3944. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3945. }
  3946. }
  3947. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3948. /// 00da <result>.B
  3949. /// result:
  3950. /// 0 = room full
  3951. /// 1 = wrong password
  3952. /// 2 = kicked
  3953. /// 3 = success (no message)
  3954. /// 4 = no enough zeny
  3955. /// 5 = too low level
  3956. /// 6 = too high level
  3957. /// 7 = unsuitable job class
  3958. void clif_joinchatfail(map_session_data *sd,int flag)
  3959. {
  3960. int fd;
  3961. nullpo_retv(sd);
  3962. fd = sd->fd;
  3963. WFIFOHEAD(fd,packet_len(0xda));
  3964. WFIFOW(fd,0) = 0xda;
  3965. WFIFOB(fd,2) = flag;
  3966. WFIFOSET(fd,packet_len(0xda));
  3967. }
  3968. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3969. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3970. /// role:
  3971. /// 0 = owner (menu)
  3972. /// 1 = normal
  3973. void clif_joinchatok(map_session_data *sd,struct chat_data* cd)
  3974. {
  3975. int fd;
  3976. int i,t;
  3977. nullpo_retv(sd);
  3978. nullpo_retv(cd);
  3979. fd = sd->fd;
  3980. if (!session_isActive(fd))
  3981. return;
  3982. t = (int)(cd->owner->type == BL_NPC);
  3983. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3984. WFIFOW(fd, 0) = 0xdb;
  3985. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3986. WFIFOL(fd, 4) = cd->bl.id;
  3987. if(cd->owner->type == BL_NPC){
  3988. WFIFOL(fd, 30) = 1;
  3989. WFIFOL(fd, 8) = 0;
  3990. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3991. for (i = 0; i < cd->users; i++) {
  3992. WFIFOL(fd, 8+(i+1)*28) = 1;
  3993. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3994. }
  3995. }else{
  3996. for (i = 0; i < cd->users; i++) {
  3997. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3998. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3999. }
  4000. }
  4001. WFIFOSET(fd, WFIFOW(fd, 2));
  4002. }
  4003. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  4004. /// 00dc <users>.W <name>.24B
  4005. void clif_addchat(struct chat_data* cd,map_session_data *sd)
  4006. {
  4007. unsigned char buf[29];
  4008. nullpo_retv(sd);
  4009. nullpo_retv(cd);
  4010. WBUFW(buf, 0) = 0xdc;
  4011. WBUFW(buf, 2) = cd->users;
  4012. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  4013. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  4014. }
  4015. /// Announce the new owner (ZC_ROLE_CHANGE).
  4016. /// 00e1 <role>.L <nick>.24B
  4017. /// role:
  4018. /// 0 = owner (menu)
  4019. /// 1 = normal
  4020. void clif_changechatowner(struct chat_data* cd, map_session_data* sd)
  4021. {
  4022. unsigned char buf[64];
  4023. nullpo_retv(sd);
  4024. nullpo_retv(cd);
  4025. WBUFW(buf, 0) = 0xe1;
  4026. WBUFL(buf, 2) = 1;
  4027. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  4028. WBUFW(buf,30) = 0xe1;
  4029. WBUFL(buf,32) = 0;
  4030. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  4031. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  4032. }
  4033. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  4034. /// 00dd <users>.W <nick>.24B <flag>.B
  4035. /// flag:
  4036. /// 0 = left
  4037. /// 1 = kicked
  4038. void clif_leavechat(struct chat_data* cd, map_session_data* sd, bool flag)
  4039. {
  4040. unsigned char buf[32];
  4041. nullpo_retv(sd);
  4042. nullpo_retv(cd);
  4043. WBUFW(buf, 0) = 0xdd;
  4044. WBUFW(buf, 2) = cd->users-1;
  4045. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  4046. WBUFB(buf,28) = flag;
  4047. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  4048. }
  4049. /// Opens a trade request window from char 'name'.
  4050. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  4051. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  4052. void clif_traderequest(map_session_data* sd, const char* name)
  4053. {
  4054. int fd = sd->fd;
  4055. #if PACKETVER < 6
  4056. WFIFOHEAD(fd,packet_len(0xe5));
  4057. WFIFOW(fd,0) = 0xe5;
  4058. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  4059. WFIFOSET(fd,packet_len(0xe5));
  4060. #else
  4061. map_session_data* tsd = map_id2sd(sd->trade_partner);
  4062. if( !tsd ) return;
  4063. WFIFOHEAD(fd,packet_len(0x1f4));
  4064. WFIFOW(fd,0) = 0x1f4;
  4065. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  4066. WFIFOL(fd,26) = tsd->status.char_id;
  4067. WFIFOW(fd,30) = tsd->status.base_level;
  4068. WFIFOSET(fd,packet_len(0x1f4));
  4069. #endif
  4070. }
  4071. /// Reply to a trade-request.
  4072. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  4073. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  4074. /// result:
  4075. /// 0 = Char is too far
  4076. /// 1 = Character does not exist
  4077. /// 2 = Trade failed
  4078. /// 3 = Accept
  4079. /// 4 = Cancel
  4080. /// 5 = Busy
  4081. void clif_tradestart(map_session_data* sd, uint8 type)
  4082. {
  4083. int fd = sd->fd;
  4084. map_session_data* tsd = map_id2sd(sd->trade_partner);
  4085. if( PACKETVER < 6 || !tsd ) {
  4086. WFIFOHEAD(fd,packet_len(0xe7));
  4087. WFIFOW(fd,0) = 0xe7;
  4088. WFIFOB(fd,2) = type;
  4089. WFIFOSET(fd,packet_len(0xe7));
  4090. } else {
  4091. WFIFOHEAD(fd,packet_len(0x1f5));
  4092. WFIFOW(fd,0) = 0x1f5;
  4093. WFIFOB(fd,2) = type;
  4094. WFIFOL(fd,3) = tsd->status.char_id;
  4095. WFIFOW(fd,7) = tsd->status.base_level;
  4096. WFIFOSET(fd,packet_len(0x1f5));
  4097. }
  4098. }
  4099. /// Notifies the client about an item from other player in current trade.
  4100. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4101. /// 080f <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM2)
  4102. /// 0a09 <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_EXCHANGE_ITEM3)
  4103. void clif_tradeadditem( map_session_data* sd, map_session_data* tsd, int index, int amount ){
  4104. nullpo_retv( sd );
  4105. nullpo_retv( tsd );
  4106. int fd = tsd->fd;
  4107. if( !session_isActive( fd ) ){
  4108. return;
  4109. }
  4110. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4111. if( index ){
  4112. index = server_index( index );
  4113. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4114. return;
  4115. }
  4116. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4117. #if PACKETVER >= 20100223
  4118. p.itemType = sd->inventory_data[index]->type;
  4119. #endif
  4120. p.identified = sd->inventory.u.items_inventory[index].identify;
  4121. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4122. p.refine = sd->inventory.u.items_inventory[index].refine;
  4123. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4124. #if PACKETVER >= 20150226
  4125. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[index] );
  4126. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4127. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4128. p.look = sd->inventory_data[index]->look;
  4129. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4130. #endif
  4131. #endif
  4132. }else{
  4133. p = {};
  4134. }
  4135. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4136. p.amount = amount;
  4137. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4138. }
  4139. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4140. /// 00ea <index>.W <result>.B
  4141. /// result:
  4142. /// 0 = success
  4143. /// 1 = overweight
  4144. /// 2 = trade canceled
  4145. void clif_tradeitemok(map_session_data& sd, int index, e_exitem_add_result result)
  4146. {
  4147. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4148. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4149. p.index = client_index(index);
  4150. p.result = static_cast<uint8>(result);
  4151. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4152. }
  4153. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4154. /// 00ec <who>.B
  4155. /// who:
  4156. /// 0 = self
  4157. /// 1 = other player
  4158. void clif_tradedeal_lock(map_session_data* sd, int fail)
  4159. {
  4160. int fd;
  4161. nullpo_retv(sd);
  4162. fd = sd->fd;
  4163. WFIFOHEAD(fd,packet_len(0xec));
  4164. WFIFOW(fd,0) = 0xec;
  4165. WFIFOB(fd,2) = fail;
  4166. WFIFOSET(fd,packet_len(0xec));
  4167. }
  4168. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4169. /// 00ee
  4170. void clif_tradecancelled(map_session_data* sd)
  4171. {
  4172. int fd;
  4173. nullpo_retv(sd);
  4174. fd = sd->fd;
  4175. WFIFOHEAD(fd,packet_len(0xee));
  4176. WFIFOW(fd,0) = 0xee;
  4177. WFIFOSET(fd,packet_len(0xee));
  4178. }
  4179. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4180. /// 00f0 <result>.B
  4181. /// result:
  4182. /// 0 = success
  4183. /// 1 = failure
  4184. void clif_tradecompleted(map_session_data* sd, int fail)
  4185. {
  4186. int fd;
  4187. nullpo_retv(sd);
  4188. fd = sd->fd;
  4189. WFIFOHEAD(fd,packet_len(0xf0));
  4190. WFIFOW(fd,0) = 0xf0;
  4191. WFIFOB(fd,2) = fail;
  4192. WFIFOSET(fd,packet_len(0xf0));
  4193. }
  4194. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4195. /// 00f1
  4196. /// NOTE: Unknown purpose. Items are not removed until the window is
  4197. /// refreshed (ex. by putting another item in there).
  4198. void clif_tradeundo(map_session_data* sd)
  4199. {
  4200. int fd = sd->fd;
  4201. WFIFOHEAD(fd,packet_len(0xf1));
  4202. WFIFOW(fd,0) = 0xf1;
  4203. WFIFOSET(fd,packet_len(0xf1));
  4204. }
  4205. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4206. /// 00f2 <current count>.W <max count>.W
  4207. void clif_updatestorageamount(map_session_data* sd, int amount, int max_amount)
  4208. {
  4209. int fd;
  4210. nullpo_retv(sd);
  4211. fd=sd->fd;
  4212. WFIFOHEAD(fd,packet_len(0xf2));
  4213. WFIFOW(fd,0) = 0xf2;
  4214. WFIFOW(fd,2) = amount;
  4215. WFIFOW(fd,4) = max_amount;
  4216. WFIFOSET(fd,packet_len(0xf2));
  4217. }
  4218. /// Notifies the client of an item being added to the storage.
  4219. /// 00f4 <index>.W <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE)
  4220. /// 01c4 <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE2)
  4221. /// 0a0a <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_ITEM_TO_STORE3)
  4222. void clif_storageitemadded( map_session_data* sd, struct item* i, int index, int amount ){
  4223. nullpo_retv( sd );
  4224. nullpo_retv( i );
  4225. int fd = sd->fd;
  4226. if( !session_isActive( fd ) ){
  4227. return;
  4228. }
  4229. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4230. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4231. p.index = client_storage_index( index ); // index
  4232. p.amount = amount; // amount
  4233. p.itemId = client_nameid( i->nameid ); // id
  4234. #if PACKETVER >= 5
  4235. p.itemType = itemtype( i->nameid ); //type
  4236. #endif
  4237. p.identified = i->identify; //identify flag
  4238. p.damaged = i->attribute; // attribute
  4239. p.refine = i->refine; //refine
  4240. clif_addcards( &p.slot, i );
  4241. #if PACKETVER_MAIN_NUM >= 20140813 || PACKETVER_RE_NUM >= 20140402 || defined(PACKETVER_ZERO)
  4242. clif_add_random_options( p.option_data, *i );
  4243. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20221024
  4244. p.grade = i->enchantgrade;
  4245. #endif
  4246. #endif
  4247. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4248. }
  4249. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4250. /// 00f6 <index>.W <amount>.L
  4251. void clif_storageitemremoved(map_session_data* sd, int index, int amount)
  4252. {
  4253. int fd;
  4254. nullpo_retv(sd);
  4255. fd=sd->fd;
  4256. WFIFOHEAD(fd,packet_len(0xf6));
  4257. WFIFOW(fd,0)=0xf6; // Storage item removed
  4258. WFIFOW(fd,2)=client_storage_index(index);
  4259. WFIFOL(fd,4)=amount;
  4260. WFIFOSET(fd,packet_len(0xf6));
  4261. }
  4262. /// Closes storage (ZC_CLOSE_STORE).
  4263. /// 00f8
  4264. void clif_storageclose(map_session_data* sd)
  4265. {
  4266. int fd;
  4267. nullpo_retv(sd);
  4268. fd=sd->fd;
  4269. WFIFOHEAD(fd,packet_len(0xf8));
  4270. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4271. WFIFOSET(fd,packet_len(0xf8));
  4272. }
  4273. /// Notifies clients in an area of a player's souls.
  4274. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4275. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4276. /// 0b73 <id>.L <amount>.W
  4277. void clif_soulball( map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4278. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4279. struct PACKET_ZC_SOULENERGY p = {};
  4280. p.PacketType = HEADER_ZC_SOULENERGY;
  4281. #else
  4282. struct PACKET_ZC_SPIRITS p = {};
  4283. p.PacketType = HEADER_ZC_SPIRITS;
  4284. #endif
  4285. p.AID = sd->bl.id;
  4286. p.num = sd->soulball;
  4287. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4288. }
  4289. /*==========================================
  4290. * Server tells 'sd' player client the abouts of 'dstsd' player
  4291. *------------------------------------------*/
  4292. static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
  4293. {
  4294. struct block_list *d_bl;
  4295. int i;
  4296. if( dstsd->chatID ) {
  4297. struct chat_data *cd = NULL;
  4298. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4299. clif_dispchat(cd,sd->fd);
  4300. } else if( dstsd->state.vending )
  4301. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4302. else if( dstsd->state.buyingstore )
  4303. clif_buyingstore_entry( *dstsd, &sd->bl );
  4304. if(dstsd->spiritball > 0)
  4305. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4306. if (dstsd->sc.getSCE(SC_MILLENNIUMSHIELD))
  4307. clif_millenniumshield_single(sd->fd, dstsd);
  4308. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4309. clif_spiritcharm_single(sd->fd, dstsd);
  4310. if (dstsd->soulball > 0)
  4311. clif_soulball( dstsd, &sd->bl, SELF );
  4312. if (dstsd->servantball > 0)
  4313. clif_servantball( *dstsd, &sd->bl, SELF );
  4314. if (dstsd->abyssball > 0)
  4315. clif_abyssball( *dstsd, &sd->bl, SELF );
  4316. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4317. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4318. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4319. )
  4320. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4321. // display link (sd - dstsd) to sd
  4322. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4323. if( i < MAX_DEVOTION )
  4324. clif_devotion(&sd->bl, sd);
  4325. // display links (dstsd - devotees) to sd
  4326. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4327. if( i < MAX_DEVOTION )
  4328. clif_devotion(&dstsd->bl, sd);
  4329. // display link (dstsd - crusader) to sd
  4330. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != NULL )
  4331. clif_devotion(d_bl, sd);
  4332. }
  4333. void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
  4334. struct unit_data *ud;
  4335. struct view_data *vd;
  4336. bool option = false;
  4337. unsigned int option_val = 0;
  4338. vd = status_get_viewdata(bl);
  4339. if (!vd || vd->class_ == JT_INVISIBLE)
  4340. return;
  4341. // Hide NPC from Maya Purple card
  4342. if (clif_npc_mayapurple(bl))
  4343. return;
  4344. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4345. // Do not send anything
  4346. return;
  4347. }
  4348. ud = unit_bl2ud(bl);
  4349. if( ud && ud->walktimer != INVALID_TIMER ){
  4350. clif_set_unit_walking( bl, sd, ud, SELF );
  4351. }else{
  4352. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4353. }
  4354. if (vd->cloth_color)
  4355. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4356. if (vd->body_style)
  4357. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4358. switch (bl->type)
  4359. {
  4360. case BL_PC:
  4361. {
  4362. TBL_PC* tsd = (TBL_PC*)bl;
  4363. clif_getareachar_pc(sd, tsd);
  4364. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4365. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4366. else if(tsd->state.size==SZ_MEDIUM)
  4367. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4368. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4369. clif_sendbgemblem_single(sd->fd,tsd);
  4370. if ( tsd->status.robe )
  4371. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4372. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4373. clif_hat_effects(sd,bl,SELF);
  4374. }
  4375. break;
  4376. case BL_MER: // Devotion Effects
  4377. if( ((TBL_MER*)bl)->devotion_flag )
  4378. clif_devotion(bl, sd);
  4379. break;
  4380. case BL_NPC:
  4381. {
  4382. TBL_NPC* nd = (TBL_NPC*)bl;
  4383. if( nd->chat_id )
  4384. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4385. if( nd->size == SZ_BIG )
  4386. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4387. else if( nd->size == SZ_MEDIUM )
  4388. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4389. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4390. clif_progressbar_npc(nd, sd);
  4391. }
  4392. break;
  4393. case BL_MOB:
  4394. {
  4395. TBL_MOB* md = (TBL_MOB*)bl;
  4396. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4397. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4398. else if(md->special_state.size==SZ_MEDIUM)
  4399. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4400. #if PACKETVER >= 20120404
  4401. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4402. int i;
  4403. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4404. if( md->dmglog[i].id == sd->status.char_id )
  4405. clif_monster_hp_bar(md, sd->fd);
  4406. }
  4407. #endif
  4408. }
  4409. break;
  4410. case BL_PET:
  4411. if (vd->head_bottom)
  4412. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4413. break;
  4414. }
  4415. }
  4416. //Modifies the type of damage according to status changes [Skotlex]
  4417. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4418. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4419. {
  4420. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4421. }
  4422. /*==========================================
  4423. * Estimates walk delay based on the damage criteria. [Skotlex]
  4424. *------------------------------------------*/
  4425. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4426. {
  4427. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4428. return 0;
  4429. if (bl->type == BL_PC) {
  4430. if (battle_config.pc_walk_delay_rate != 100)
  4431. delay = delay*battle_config.pc_walk_delay_rate/100;
  4432. } else
  4433. if (battle_config.walk_delay_rate != 100)
  4434. delay = delay*battle_config.walk_delay_rate/100;
  4435. if (div_ > 1) //Multi-hit skills mean higher delays.
  4436. delay += battle_config.multihit_delay*(div_-1);
  4437. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4438. }
  4439. /*========================================== [Playtester]
  4440. * Returns hallucination damage the client displays
  4441. *------------------------------------------*/
  4442. static int clif_hallucination_damage()
  4443. {
  4444. int digit = rnd() % 5 + 1;
  4445. switch (digit)
  4446. {
  4447. case 1:
  4448. return (rnd() % 10);
  4449. case 2:
  4450. return (rnd() % 100);
  4451. case 3:
  4452. return (rnd() % 1000);
  4453. case 4:
  4454. return (rnd() % 10000);
  4455. }
  4456. return (rnd() % 32767);
  4457. }
  4458. /// Sends a 'damage' packet (src performs action on dst)
  4459. /// 008a <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.W <div>.W <type>.B <damage2>.W (ZC_NOTIFY_ACT)
  4460. /// 02e1 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT2)
  4461. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT3)
  4462. /// type:
  4463. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4464. /// 1 = pick up item
  4465. /// 2 = sit down
  4466. /// 3 = stand up
  4467. /// 4 = damage (endure)
  4468. /// 5 = (splash?)
  4469. /// 6 = (skill?)
  4470. /// 7 = (repeat damage?)
  4471. /// 8 = multi-hit damage
  4472. /// 9 = multi-hit damage (endure)
  4473. /// 10 = critical hit
  4474. /// 11 = lucky dodge
  4475. /// 12 = (touch skill?)
  4476. /// 13 = multi-hit critical
  4477. int clif_damage(struct block_list* src, struct block_list* dst, t_tick tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2, bool spdamage)
  4478. {
  4479. unsigned char buf[34];
  4480. status_change *sc;
  4481. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4482. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4483. #if PACKETVER < 20071113
  4484. const int cmd = 0x8a;
  4485. int offset = 0;
  4486. #elif PACKETVER < 20131223
  4487. const int cmd = 0x2e1;
  4488. int offset = 2;
  4489. #else
  4490. const int cmd = 0x8c8;
  4491. int offset = 3;
  4492. #endif
  4493. nullpo_ret(src);
  4494. nullpo_ret(dst);
  4495. if (type != DMG_MULTI_HIT_CRITICAL)
  4496. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4497. sc = status_get_sc(dst);
  4498. if(sc && sc->count) {
  4499. if(sc->getSCE(SC_HALLUCINATION)) {
  4500. damage = clif_hallucination_damage();
  4501. if(damage2) damage2 = clif_hallucination_damage();
  4502. }
  4503. }
  4504. WBUFW(buf,0) = cmd;
  4505. WBUFL(buf,2) = src->id;
  4506. WBUFL(buf,6) = dst->id;
  4507. WBUFL(buf,10) = client_tick(tick);
  4508. WBUFL(buf,14) = sdelay;
  4509. WBUFL(buf,18) = ddelay;
  4510. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4511. #if PACKETVER < 20071113
  4512. WBUFW(buf,22) = damage ? div : 0;
  4513. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4514. #else
  4515. WBUFL(buf, 22) = damage ? div : 0;
  4516. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4517. #endif
  4518. } else {
  4519. #if PACKETVER < 20071113
  4520. WBUFW(buf,22) = min(damage, INT16_MAX);
  4521. WBUFW(buf,27+offset) = damage2;
  4522. #else
  4523. WBUFL(buf,22) = damage;
  4524. WBUFL(buf,27+offset) = damage2;
  4525. #endif
  4526. }
  4527. #if PACKETVER >= 20131223
  4528. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4529. #endif
  4530. WBUFW(buf,24+offset) = div;
  4531. WBUFB(buf,26+offset) = type;
  4532. if(disguised(dst)) {
  4533. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4534. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4535. clif_send(buf, packet_len(cmd), dst, SELF);
  4536. } else
  4537. clif_send(buf, packet_len(cmd), dst, AREA);
  4538. if(disguised(src)) {
  4539. WBUFL(buf,2) = disguised_bl_id( src->id );
  4540. if (disguised(dst))
  4541. WBUFL(buf,6) = dst->id;
  4542. #if PACKETVER < 20071113
  4543. if(damage > 0) WBUFW(buf,22) = -1;
  4544. if(damage2 > 0) WBUFW(buf,27) = -1;
  4545. #else
  4546. if(damage > 0) WBUFL(buf,22) = -1;
  4547. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4548. #endif
  4549. clif_send(buf,packet_len(cmd),src,SELF);
  4550. }
  4551. if(src == dst) {
  4552. unit_setdir(src, unit_getdir(src));
  4553. }
  4554. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4555. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4556. //Return adjusted can't walk delay for further processing.
  4557. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4558. }
  4559. /*==========================================
  4560. * src picks up dst
  4561. *------------------------------------------*/
  4562. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4563. {
  4564. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4565. unsigned char buf[32];
  4566. nullpo_retv(src);
  4567. nullpo_retv(dst);
  4568. WBUFW(buf, 0) = 0x8a;
  4569. WBUFL(buf, 2) = src->id;
  4570. WBUFL(buf, 6) = dst->id;
  4571. WBUFB(buf,26) = 1;
  4572. clif_send(buf, packet_len(0x8a), src, AREA);
  4573. }
  4574. /*==========================================
  4575. * inform clients in area that `bl` is sitting
  4576. *------------------------------------------*/
  4577. void clif_sitting(struct block_list* bl)
  4578. {
  4579. unsigned char buf[32];
  4580. nullpo_retv(bl);
  4581. WBUFW(buf, 0) = 0x8a;
  4582. WBUFL(buf, 2) = bl->id;
  4583. WBUFB(buf,26) = 2;
  4584. clif_send(buf, packet_len(0x8a), bl, AREA);
  4585. if(disguised(bl)) {
  4586. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4587. clif_send(buf, packet_len(0x8a), bl, SELF);
  4588. }
  4589. }
  4590. /*==========================================
  4591. * inform clients in area that `bl` is standing
  4592. *------------------------------------------*/
  4593. void clif_standing(struct block_list* bl)
  4594. {
  4595. unsigned char buf[32];
  4596. nullpo_retv(bl);
  4597. WBUFW(buf, 0) = 0x8a;
  4598. WBUFL(buf, 2) = bl->id;
  4599. WBUFB(buf,26) = 3;
  4600. clif_send(buf, packet_len(0x8a), bl, AREA);
  4601. if(disguised(bl)) {
  4602. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4603. clif_send(buf, packet_len(0x8a), bl, SELF);
  4604. }
  4605. }
  4606. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4607. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4608. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4609. {
  4610. unsigned char buf[32];
  4611. WBUFW(buf,0) = 0x192;
  4612. WBUFW(buf,2) = x;
  4613. WBUFW(buf,4) = y;
  4614. WBUFW(buf,6) = type;
  4615. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4616. if( session_isActive(fd) )
  4617. {
  4618. WFIFOHEAD(fd,packet_len(0x192));
  4619. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4620. WFIFOSET(fd,packet_len(0x192));
  4621. }
  4622. else
  4623. {
  4624. struct block_list dummy_bl;
  4625. dummy_bl.type = BL_NUL;
  4626. dummy_bl.x = x;
  4627. dummy_bl.y = y;
  4628. dummy_bl.m = m;
  4629. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4630. }
  4631. }
  4632. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4633. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4634. void clif_getareachar_item( map_session_data* sd,struct flooritem_data* fitem ){
  4635. nullpo_retv( sd );
  4636. nullpo_retv( fitem );
  4637. struct PACKET_ZC_ITEM_ENTRY p;
  4638. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4639. p.AID = fitem->bl.id;
  4640. p.itemId = client_nameid( fitem->item.nameid );
  4641. p.identify = fitem->item.identify;
  4642. p.x = fitem->bl.x;
  4643. p.y = fitem->bl.y;
  4644. p.amount = fitem->item.amount;
  4645. p.subX = fitem->subx;
  4646. p.subY = fitem->suby;
  4647. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4648. }
  4649. /// Notifes client about Graffiti
  4650. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4651. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4652. unsigned char buf[128];
  4653. nullpo_retv(bl);
  4654. nullpo_retv(unit);
  4655. WBUFW(buf, 0) = 0x1c9;
  4656. WBUFL(buf, 2) = unit->bl.id;
  4657. WBUFL(buf, 6) = unit->group->src_id;
  4658. WBUFW(buf,10) = unit->bl.x;
  4659. WBUFW(buf,12) = unit->bl.y;
  4660. WBUFB(buf,14) = unit->group->unit_id;
  4661. WBUFB(buf,15) = 1;
  4662. WBUFB(buf,16) = 1;
  4663. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4664. clif_send(buf,packet_len(0x1c9),bl,target);
  4665. }
  4666. /// Notifies the client of a skill unit.
  4667. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4668. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4669. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4670. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4671. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4672. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4673. unsigned char buf[128];
  4674. nullpo_retv(bl);
  4675. nullpo_retv(unit);
  4676. if (bl->type == BL_PC)
  4677. fd = ((TBL_PC*)bl)->fd;
  4678. if (unit->group->state.guildaura)
  4679. return;
  4680. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4681. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4682. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4683. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4684. else
  4685. unit_id = unit->group->unit_id;
  4686. if (!visible)
  4687. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4688. #if PACKETVER >= 3
  4689. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4690. clif_graffiti(bl, unit, target);
  4691. return;
  4692. }
  4693. #endif
  4694. #if PACKETVER <= 20120702
  4695. header = 0x011f;
  4696. //#if PACKETVER < 20110718
  4697. // header = 0x011f;
  4698. //#elif PACKETVER < 20121212
  4699. // header = 0x08c7;
  4700. #elif PACKETVER < 20130731
  4701. header = 0x099f;
  4702. #else
  4703. header = 0x09ca;
  4704. #endif
  4705. len = packet_len(header);
  4706. WBUFW(buf,pos) = header;
  4707. if (header != 0x011f) {
  4708. WBUFW(buf, pos+2) = len;
  4709. pos += 2;
  4710. }
  4711. WBUFL(buf,pos+2) = unit->bl.id;
  4712. WBUFL(buf,pos+6) = unit->group->src_id;
  4713. WBUFW(buf,pos+10) = unit->bl.x;
  4714. WBUFW(buf,pos+12) = unit->bl.y;
  4715. switch (header) {
  4716. case 0x011f:
  4717. WBUFB(buf,pos+14) = unit_id;
  4718. WBUFB(buf,pos+15) = visible;
  4719. break;
  4720. case 0x08c7:
  4721. WBUFB(buf,pos+14) = unit_id;
  4722. WBUFW(buf,pos+15) = unit->range;
  4723. WBUFB(buf,pos+17) = visible;
  4724. break;
  4725. case 0x099f:
  4726. WBUFL(buf,pos+14) = unit_id;
  4727. WBUFW(buf,pos+18) = unit->range;
  4728. WBUFB(buf,pos+20) = visible;
  4729. break;
  4730. case 0x09ca:
  4731. WBUFL(buf,pos+14) = unit_id;
  4732. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4733. WBUFB(buf,pos+19) = visible;
  4734. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4735. break;
  4736. }
  4737. clif_send(buf, len, bl, target);
  4738. if (unit->group->skill_id == WZ_ICEWALL)
  4739. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4740. }
  4741. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4742. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4743. unsigned char buf[128];
  4744. nullpo_retv(bl);
  4745. WBUFW(buf, 0) = 0x09ca;
  4746. WBUFW(buf, 2) = packet_len(0x09ca);
  4747. WBUFL(buf, 4) = 1000;
  4748. WBUFL(buf, 8) = 2000;
  4749. WBUFW(buf, 12) = x;
  4750. WBUFW(buf, 14) = y;
  4751. WBUFL(buf, 16) = unit_id;
  4752. WBUFB(buf, 20) = (unsigned char)range;
  4753. WBUFB(buf, 21) = 1;
  4754. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4755. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4756. }
  4757. /*==========================================
  4758. * Server tells client to remove unit of id 'unit->bl.id'
  4759. *------------------------------------------*/
  4760. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4761. {
  4762. nullpo_retv(unit);
  4763. WFIFOHEAD(fd,packet_len(0x120));
  4764. WFIFOW(fd, 0)=0x120;
  4765. WFIFOL(fd, 2)=unit->bl.id;
  4766. WFIFOSET(fd,packet_len(0x120));
  4767. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4768. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4769. }
  4770. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4771. /// 0120 <id>.L
  4772. void clif_skill_delunit(struct skill_unit *unit)
  4773. {
  4774. unsigned char buf[16];
  4775. nullpo_retv(unit);
  4776. WBUFW(buf, 0)=0x120;
  4777. WBUFL(buf, 2)=unit->bl.id;
  4778. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4779. }
  4780. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4781. /// 01ac <id>.L
  4782. /// Only affects units with class [139,153] client-side.
  4783. void clif_skillunit_update(struct block_list* bl)
  4784. {
  4785. unsigned char buf[6];
  4786. nullpo_retv(bl);
  4787. WBUFW(buf,0) = 0x1ac;
  4788. WBUFL(buf,2) = bl->id;
  4789. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4790. }
  4791. /*==========================================
  4792. *
  4793. *------------------------------------------*/
  4794. static int clif_getareachar(struct block_list* bl,va_list ap)
  4795. {
  4796. map_session_data *sd;
  4797. nullpo_ret(bl);
  4798. sd=va_arg(ap,map_session_data*);
  4799. if (!clif_session_isValid(sd))
  4800. return 0;
  4801. switch(bl->type){
  4802. case BL_ITEM:
  4803. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4804. break;
  4805. case BL_SKILL:
  4806. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4807. break;
  4808. default:
  4809. if(&sd->bl == bl)
  4810. break;
  4811. clif_getareachar_unit(sd,bl);
  4812. break;
  4813. }
  4814. return 0;
  4815. }
  4816. /*==========================================
  4817. * tbl has gone out of view-size of bl
  4818. *------------------------------------------*/
  4819. int clif_outsight(struct block_list *bl,va_list ap)
  4820. {
  4821. struct block_list *tbl;
  4822. struct view_data *vd;
  4823. TBL_PC *sd, *tsd;
  4824. tbl=va_arg(ap,struct block_list*);
  4825. if(bl == tbl) return 0;
  4826. sd = BL_CAST(BL_PC, bl);
  4827. tsd = BL_CAST(BL_PC, tbl);
  4828. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4829. nullpo_ret(bl);
  4830. switch(bl->type){
  4831. case BL_PC:
  4832. if(sd->vd.class_ != JT_INVISIBLE)
  4833. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4834. if(sd->chatID){
  4835. struct chat_data *cd;
  4836. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4837. if(cd->usersd[0]==sd)
  4838. clif_dispchat(cd,tsd->fd);
  4839. }
  4840. if(sd->state.vending)
  4841. clif_closevendingboard(bl,tsd->fd);
  4842. if(sd->state.buyingstore)
  4843. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4844. break;
  4845. case BL_ITEM:
  4846. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4847. break;
  4848. case BL_SKILL:
  4849. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4850. break;
  4851. case BL_NPC:
  4852. if(!(((TBL_NPC*)bl)->is_invisible))
  4853. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4854. break;
  4855. default:
  4856. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4857. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4858. break;
  4859. }
  4860. }
  4861. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4862. nullpo_ret(tbl);
  4863. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4864. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4865. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4866. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->is_invisible)))
  4867. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4868. }
  4869. return 0;
  4870. }
  4871. /*==========================================
  4872. * tbl has come into view of bl
  4873. *------------------------------------------*/
  4874. int clif_insight(struct block_list *bl,va_list ap)
  4875. {
  4876. struct block_list *tbl;
  4877. TBL_PC *sd, *tsd;
  4878. tbl=va_arg(ap,struct block_list*);
  4879. if (bl == tbl) return 0;
  4880. sd = BL_CAST(BL_PC, bl);
  4881. tsd = BL_CAST(BL_PC, tbl);
  4882. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4883. switch(bl->type){
  4884. case BL_ITEM:
  4885. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4886. break;
  4887. case BL_SKILL:
  4888. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4889. break;
  4890. default:
  4891. clif_getareachar_unit(tsd,bl);
  4892. break;
  4893. }
  4894. }
  4895. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4896. clif_getareachar_unit(sd,tbl);
  4897. }
  4898. return 0;
  4899. }
  4900. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4901. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4902. void clif_skillinfoblock(map_session_data *sd)
  4903. {
  4904. int fd;
  4905. int i,len,id;
  4906. nullpo_retv(sd);
  4907. fd = sd->fd;
  4908. if (!session_isActive(fd))
  4909. return;
  4910. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4911. WFIFOW(fd,0) = 0x10f;
  4912. bool haveCallPartnerSkill = false;
  4913. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4914. {
  4915. if( (id = sd->status.skill[i].id) != 0 )
  4916. {
  4917. // workaround for bugreport:5348
  4918. if (len + 37 > 8192)
  4919. break;
  4920. // skip WE_CALLPARTNER and send it in special way
  4921. if (id == WE_CALLPARTNER) {
  4922. haveCallPartnerSkill = true;
  4923. continue;
  4924. }
  4925. WFIFOW(fd,len) = id;
  4926. WFIFOL(fd,len+2) = skill_get_inf(id);
  4927. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4928. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4929. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4930. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4931. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4932. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4933. else
  4934. WFIFOB(fd,len+36) = 0;
  4935. len += 37;
  4936. }
  4937. }
  4938. WFIFOW(fd,2)=len;
  4939. WFIFOSET(fd,len);
  4940. // adoption fix
  4941. if (haveCallPartnerSkill) {
  4942. clif_addskill(sd, WE_CALLPARTNER);
  4943. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4944. }
  4945. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4946. for ( ; i < MAX_SKILL; i++)
  4947. {
  4948. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4949. {
  4950. clif_addskill(sd, id);
  4951. clif_skillinfo(sd, id, 0);
  4952. }
  4953. }
  4954. }
  4955. /**
  4956. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4957. **/
  4958. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4959. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4960. void clif_addskill(map_session_data *sd, int skill_id)
  4961. {
  4962. nullpo_retv(sd);
  4963. int fd = sd->fd;
  4964. uint16 idx = skill_get_index(skill_id);
  4965. if (!session_isActive(fd) || !idx)
  4966. return;
  4967. if( sd->status.skill[idx].id <= 0 )
  4968. return;
  4969. WFIFOHEAD(fd, packet_len(0x111));
  4970. WFIFOW(fd,0) = 0x111;
  4971. WFIFOW(fd,2) = skill_id;
  4972. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4973. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4974. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4975. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4976. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4977. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4978. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4979. else
  4980. WFIFOB(fd,38) = 0;
  4981. WFIFOSET(fd,packet_len(0x111));
  4982. }
  4983. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4984. /// 0441 <skill id>.W
  4985. void clif_deleteskill(map_session_data *sd, int skill_id, bool skip_infoblock)
  4986. {
  4987. #if PACKETVER >= 20081217
  4988. nullpo_retv(sd);
  4989. int fd = sd->fd;
  4990. uint16 idx = skill_get_index(skill_id);
  4991. if (!session_isActive(fd) || !idx)
  4992. return;
  4993. WFIFOHEAD(fd,packet_len(0x441));
  4994. WFIFOW(fd,0) = 0x441;
  4995. WFIFOW(fd,2) = skill_id;
  4996. WFIFOSET(fd,packet_len(0x441));
  4997. #endif
  4998. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4999. if (!skip_infoblock)
  5000. #endif
  5001. clif_skillinfoblock(sd);
  5002. }
  5003. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  5004. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  5005. void clif_skillup(map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  5006. nullpo_retv(sd);
  5007. int fd = sd->fd;
  5008. uint16 idx = skill_get_index(skill_id);
  5009. if (!session_isActive(fd) || !idx)
  5010. return;
  5011. WFIFOHEAD(fd, packet_len(0x10e));
  5012. WFIFOW(fd, 0) = 0x10e;
  5013. WFIFOW(fd, 2) = skill_id;
  5014. WFIFOW(fd, 4) = lv;
  5015. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  5016. WFIFOW(fd, 8) = range;
  5017. WFIFOB(fd, 10) = upgradable;
  5018. WFIFOSET(fd, packet_len(0x10e));
  5019. }
  5020. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  5021. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  5022. void clif_skillinfo(map_session_data *sd,int skill_id, int inf)
  5023. {
  5024. nullpo_retv(sd);
  5025. const int fd = sd->fd;
  5026. uint16 idx = skill_get_index(skill_id);
  5027. if (!session_isActive(fd) || !idx)
  5028. return;
  5029. WFIFOHEAD(fd,packet_len(0x7e1));
  5030. WFIFOW(fd,0) = 0x7e1;
  5031. WFIFOW(fd,2) = skill_id;
  5032. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  5033. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  5034. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  5035. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  5036. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  5037. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  5038. else
  5039. WFIFOB(fd,14) = 0;
  5040. WFIFOSET(fd,packet_len(0x7e1));
  5041. }
  5042. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  5043. #if PACKETVER >= 20151223
  5044. if( !battle_config.show_skill_scale ){
  5045. return;
  5046. }
  5047. struct PACKET_ZC_SKILL_SCALE p;
  5048. p.PacketType = skillscale;
  5049. p.AID = src_id;
  5050. p.skill_id = skill_id;
  5051. p.skill_lv = skill_lv;
  5052. p.x = x;
  5053. p.y = y;
  5054. p.casttime = casttime;
  5055. if( disguised( bl ) ){
  5056. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  5057. p.AID = disguised_bl_id( bl->id );
  5058. clif_send( &p, sizeof( p ), bl, SELF );
  5059. }else{
  5060. clif_send( &p, sizeof( p ), bl, AREA );
  5061. }
  5062. #endif
  5063. }
  5064. /// Notifies clients in area, that an object is about to use a skill.
  5065. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  5066. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  5067. /// property:
  5068. /// 0 = Yellow cast aura
  5069. /// 1 = Water elemental cast aura
  5070. /// 2 = Earth elemental cast aura
  5071. /// 3 = Fire elemental cast aura
  5072. /// 4 = Wind elemental cast aura
  5073. /// 5 = Poison elemental cast aura
  5074. /// 6 = Holy elemental cast aura
  5075. /// ? = like 0
  5076. /// is disposable:
  5077. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  5078. /// 1 = no text
  5079. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, uint16 skill_lv, int property, int casttime)
  5080. {
  5081. #if PACKETVER < 20091124
  5082. const int cmd = 0x13e;
  5083. #else
  5084. const int cmd = 0x7fb;
  5085. #endif
  5086. unsigned char buf[32];
  5087. WBUFW(buf,0) = cmd;
  5088. WBUFL(buf,2) = src_id;
  5089. WBUFL(buf,6) = dst_id;
  5090. WBUFW(buf,10) = dst_x;
  5091. WBUFW(buf,12) = dst_y;
  5092. WBUFW(buf,14) = skill_id;
  5093. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5094. WBUFL(buf,20) = casttime;
  5095. #if PACKETVER >= 20091124
  5096. WBUFB(buf,24) = 0; // isDisposable
  5097. #endif
  5098. if (disguised(bl)) {
  5099. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5100. WBUFL(buf,2) = disguised_bl_id( src_id );
  5101. clif_send(buf,packet_len(cmd), bl, SELF);
  5102. } else
  5103. clif_send(buf,packet_len(cmd), bl, AREA);
  5104. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5105. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5106. }
  5107. }
  5108. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5109. /// 01b9 <id>.L
  5110. void clif_skillcastcancel(struct block_list* bl)
  5111. {
  5112. unsigned char buf[16];
  5113. nullpo_retv(bl);
  5114. WBUFW(buf,0) = 0x1b9;
  5115. WBUFL(buf,2) = bl->id;
  5116. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5117. }
  5118. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5119. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5120. /// num (only used when skill id = NV_BASIC and cause = 0):
  5121. /// 0 = "skill failed" MsgStringTable[159]
  5122. /// 1 = "no emotions" MsgStringTable[160]
  5123. /// 2 = "no sit" MsgStringTable[161]
  5124. /// 3 = "no chat" MsgStringTable[162]
  5125. /// 4 = "no party" MsgStringTable[163]
  5126. /// 5 = "no shout" MsgStringTable[164]
  5127. /// 6 = "no PKing" MsgStringTable[165]
  5128. /// 7 = "no alligning" MsgStringTable[383]
  5129. /// ? = ignored
  5130. /// cause:
  5131. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5132. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5133. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5134. /// "skill failed" MsgStringTable[204] (otherwise)
  5135. /// ... = @see enum useskill_fail_cause
  5136. /// ? = ignored
  5137. ///
  5138. /// if(result!=0) doesn't display any of the previous messages
  5139. /// Note: when this packet is received an unknown flag is always set to 0,
  5140. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5141. void clif_skill_fail( map_session_data& sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5142. if(battle_config.display_skill_fail&1)
  5143. return; //Disable all skill failed messages
  5144. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd.state.showdelay)
  5145. return; //Disable delay failed messages
  5146. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5147. return;
  5148. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5149. return;
  5150. struct PACKET_ZC_ACK_TOUSESKILL p;
  5151. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5152. p.skillId = skill_id;
  5153. p.btype = btype;
  5154. p.itemId = itemId;
  5155. p.flag = 0; // 0 - failed
  5156. p.cause = cause;
  5157. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  5158. }
  5159. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5160. /// 043d <skill ID>.W <tick>.L
  5161. void clif_skill_cooldown(map_session_data *sd, uint16 skill_id, t_tick tick)
  5162. {
  5163. #if PACKETVER>=20081112
  5164. int fd;
  5165. nullpo_retv(sd);
  5166. fd=sd->fd;
  5167. WFIFOHEAD(fd,packet_len(0x43d));
  5168. WFIFOW(fd,0) = 0x43d;
  5169. WFIFOW(fd,2) = skill_id;
  5170. WFIFOL(fd,4) = client_tick(tick);
  5171. WFIFOSET(fd,packet_len(0x43d));
  5172. #endif
  5173. }
  5174. /// Skill attack effect and damage.
  5175. /// 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)
  5176. /// 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)
  5177. 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)
  5178. {
  5179. unsigned char buf[64];
  5180. status_change *sc;
  5181. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5182. nullpo_ret(src);
  5183. nullpo_ret(dst);
  5184. type = clif_calc_delay(type,div,damage,ddelay);
  5185. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5186. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5187. damage = clif_hallucination_damage();
  5188. }
  5189. #if PACKETVER < 3
  5190. WBUFW(buf,0)=0x114;
  5191. WBUFW(buf,2)=skill_id;
  5192. WBUFL(buf,4)=src->id;
  5193. WBUFL(buf,8)=dst->id;
  5194. WBUFL(buf,12)=client_tick(tick);
  5195. WBUFL(buf,16)=sdelay;
  5196. WBUFL(buf,20)=ddelay;
  5197. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5198. WBUFW(buf,24)=damage?div:0;
  5199. } else {
  5200. WBUFW(buf,24)=damage;
  5201. }
  5202. WBUFW(buf,26)=skill_lv;
  5203. WBUFW(buf,28)=div;
  5204. WBUFB(buf,30)=type;
  5205. if (disguised(dst)) {
  5206. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5207. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5208. clif_send(buf,packet_len(0x114),dst,SELF);
  5209. } else
  5210. clif_send(buf,packet_len(0x114),dst,AREA);
  5211. if(disguised(src)) {
  5212. WBUFL(buf,4)=disguised_bl_id(src->id);
  5213. if (disguised(dst))
  5214. WBUFL(buf,8)=dst->id;
  5215. if(damage > 0)
  5216. WBUFW(buf,24)=-1;
  5217. clif_send(buf,packet_len(0x114),src,SELF);
  5218. }
  5219. #else
  5220. WBUFW(buf,0)=0x1de;
  5221. WBUFW(buf,2)=skill_id;
  5222. WBUFL(buf,4)=src->id;
  5223. WBUFL(buf,8)=dst->id;
  5224. WBUFL(buf,12)=client_tick(tick);
  5225. WBUFL(buf,16)=sdelay;
  5226. WBUFL(buf,20)=ddelay;
  5227. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5228. WBUFL(buf,24)=damage?div:0;
  5229. } else {
  5230. WBUFL(buf,24)=damage;
  5231. }
  5232. WBUFW(buf,28)=skill_lv;
  5233. WBUFW(buf,30)=div;
  5234. // For some reason, late 2013 and newer clients have
  5235. // a issue that causes players and monsters to endure
  5236. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5237. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5238. #if PACKETVER < 20131223
  5239. WBUFB(buf,32)=type;
  5240. #else
  5241. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5242. #endif
  5243. if (disguised(dst)) {
  5244. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5245. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5246. clif_send(buf,packet_len(0x1de),dst,SELF);
  5247. } else
  5248. clif_send(buf,packet_len(0x1de),dst,AREA);
  5249. if(disguised(src)) {
  5250. WBUFL(buf,4)=disguised_bl_id(src->id);
  5251. if (disguised(dst))
  5252. WBUFL(buf,8)=dst->id;
  5253. if(damage > 0)
  5254. WBUFL(buf,24)=-1;
  5255. clif_send(buf,packet_len(0x1de),src,SELF);
  5256. }
  5257. #endif
  5258. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5259. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5260. }
  5261. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5262. /// 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
  5263. /*
  5264. 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)
  5265. {
  5266. unsigned char buf[64];
  5267. status_change *sc;
  5268. nullpo_ret(src);
  5269. nullpo_ret(dst);
  5270. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5271. type = clif_calc_delay(type,div,damage,ddelay);
  5272. sc = status_get_sc(dst);
  5273. if(sc && sc->count) {
  5274. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5275. damage = clif_hallucination_damage();
  5276. }
  5277. WBUFW(buf,0)=0x115;
  5278. WBUFW(buf,2)=skill_id;
  5279. WBUFL(buf,4)=src->id;
  5280. WBUFL(buf,8)=dst->id;
  5281. WBUFL(buf,12)=client_tick(tick);
  5282. WBUFL(buf,16)=sdelay;
  5283. WBUFL(buf,20)=ddelay;
  5284. WBUFW(buf,24)=dst->x;
  5285. WBUFW(buf,26)=dst->y;
  5286. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5287. WBUFW(buf,28)=damage?div:0;
  5288. } else {
  5289. WBUFW(buf,28)=damage;
  5290. }
  5291. WBUFW(buf,30)=skill_lv;
  5292. WBUFW(buf,32)=div;
  5293. WBUFB(buf,34)=type;
  5294. clif_send(buf,packet_len(0x115),src,AREA);
  5295. if(disguised(src)) {
  5296. WBUFL(buf,4)=disguised_bl_id(src->id);
  5297. if(damage > 0)
  5298. WBUFW(buf,28)=-1;
  5299. clif_send(buf,packet_len(0x115),src,SELF);
  5300. }
  5301. if (disguised(dst)) {
  5302. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5303. if (disguised(src))
  5304. WBUFL(buf,4)=src->id;
  5305. else if(damage > 0)
  5306. WBUFW(buf,28)=-1;
  5307. clif_send(buf,packet_len(0x115),dst,SELF);
  5308. }
  5309. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5310. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5311. }
  5312. */
  5313. /// Non-damaging skill effect
  5314. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5315. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5316. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5317. {
  5318. unsigned char buf[17];
  5319. #if PACKETVER < 20130731
  5320. const int cmd = 0x11a;
  5321. #else
  5322. const int cmd = 0x9cb;
  5323. #endif
  5324. int offset = 0;
  5325. bool success = ( tick != 0 );
  5326. nullpo_ret(dst);
  5327. WBUFW(buf,0) = cmd;
  5328. WBUFW(buf,2) = skill_id;
  5329. #if PACKETVER < 20130731
  5330. WBUFW(buf,4) = min(heal, INT16_MAX);
  5331. #else
  5332. WBUFL(buf,4) = min(heal, INT32_MAX);
  5333. offset += 2;
  5334. #endif
  5335. WBUFL(buf,6+offset) = dst->id;
  5336. WBUFL(buf,10+offset) = src ? src->id : 0;
  5337. WBUFB(buf,14+offset) = success;
  5338. if (disguised(dst)) {
  5339. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5340. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5341. clif_send(buf, packet_len(cmd), dst, SELF);
  5342. } else
  5343. clif_send(buf, packet_len(cmd), dst, AREA);
  5344. if(src && disguised(src)) {
  5345. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5346. if (disguised(dst))
  5347. WBUFL(buf,6+offset) = dst->id;
  5348. clif_send(buf, packet_len(cmd), src, SELF);
  5349. }
  5350. return success;
  5351. }
  5352. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5353. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5354. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5355. {
  5356. unsigned char buf[32];
  5357. nullpo_retv(src);
  5358. WBUFW(buf,0)=0x117;
  5359. WBUFW(buf,2)=skill_id;
  5360. WBUFL(buf,4)=src->id;
  5361. WBUFW(buf,8)=val;
  5362. WBUFW(buf,10)=x;
  5363. WBUFW(buf,12)=y;
  5364. WBUFL(buf,14)=client_tick(tick);
  5365. if(disguised(src)) {
  5366. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5367. WBUFL(buf,4)=disguised_bl_id(src->id);
  5368. clif_send(buf,packet_len(0x117),src,SELF);
  5369. } else
  5370. clif_send(buf,packet_len(0x117),src,AREA);
  5371. }
  5372. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5373. /// 011c <skill id>.W { <map name>.16B }*4
  5374. 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 ){
  5375. int fd;
  5376. nullpo_retv(sd);
  5377. fd = sd->fd;
  5378. WFIFOHEAD(fd,packet_len(0x11c));
  5379. WFIFOW(fd,0) = 0x11c;
  5380. WFIFOW(fd,2) = skill_id;
  5381. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5382. if( strcmp( "", map1 ) != 0 ){
  5383. mapindex_getmapname_ext( map1, WFIFOCP( fd, 4 ) );
  5384. }
  5385. if( strcmp( "", map2 ) != 0 ){
  5386. mapindex_getmapname_ext( map2, WFIFOCP( fd, 20 ) );
  5387. }
  5388. if( strcmp( "", map3 ) != 0 ){
  5389. mapindex_getmapname_ext( map3, WFIFOCP( fd, 36 ) );
  5390. }
  5391. if( strcmp( "", map4 ) != 0 ){
  5392. mapindex_getmapname_ext( map4, WFIFOCP( fd, 52 ) );
  5393. }
  5394. WFIFOSET(fd,packet_len(0x11c));
  5395. sd->menuskill_id = skill_id;
  5396. if (skill_id == AL_WARP) {
  5397. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5398. sd->state.workinprogress = WIP_DISABLE_ALL;
  5399. } else
  5400. sd->menuskill_val = skill_lv;
  5401. }
  5402. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5403. /// 011e <type>.B
  5404. /// type:
  5405. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5406. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5407. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5408. ///
  5409. /// @param sd Who receives the message
  5410. /// @param type What message
  5411. void clif_skill_memomessage(map_session_data* sd, int type)
  5412. {
  5413. int fd;
  5414. nullpo_retv(sd);
  5415. fd=sd->fd;
  5416. WFIFOHEAD(fd,packet_len(0x11e));
  5417. WFIFOW(fd,0)=0x11e;
  5418. WFIFOB(fd,2)=type;
  5419. WFIFOSET(fd,packet_len(0x11e));
  5420. }
  5421. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5422. /// 0189 <type>.W
  5423. /// type:
  5424. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5425. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5426. ///
  5427. /// @param sd Who receives the message
  5428. /// @param type What message
  5429. void clif_skill_teleportmessage(map_session_data *sd, int type)
  5430. {
  5431. int fd;
  5432. nullpo_retv(sd);
  5433. fd=sd->fd;
  5434. WFIFOHEAD(fd,packet_len(0x189));
  5435. WFIFOW(fd,0)=0x189;
  5436. WFIFOW(fd,2)=type;
  5437. WFIFOSET(fd,packet_len(0x189));
  5438. }
  5439. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5440. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5441. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5442. void clif_skill_estimation(map_session_data *sd,struct block_list *dst)
  5443. {
  5444. struct status_data *status;
  5445. unsigned char buf[64];
  5446. int i, fix;
  5447. nullpo_retv(sd);
  5448. nullpo_retv(dst);
  5449. if( dst->type != BL_MOB )
  5450. return;
  5451. status = status_get_status_data(dst);
  5452. WBUFW(buf, 0)=0x18c;
  5453. WBUFW(buf, 2)=status_get_class(dst);
  5454. WBUFW(buf, 4)=status_get_lv(dst);
  5455. WBUFW(buf, 6)=status->size;
  5456. WBUFL(buf, 8)=status->hp;
  5457. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5458. +(battle_config.estimation_type&2?status->def2:0);
  5459. WBUFW(buf,14)=status->race;
  5460. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5461. +(battle_config.estimation_type&2?status->mdef2:0);
  5462. WBUFW(buf,18)= status->def_ele;
  5463. for(i=0;i<9;i++)
  5464. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5465. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5466. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5467. }
  5468. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5469. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5470. /// material id:
  5471. /// unused by the client
  5472. void clif_skill_produce_mix_list( map_session_data *sd, int skill_id, int trigger ){
  5473. nullpo_retv(sd);
  5474. int fd = sd->fd;
  5475. if( !session_isActive( fd ) ){
  5476. return;
  5477. }
  5478. if (sd->menuskill_id == skill_id)
  5479. return; //Avoid resending the menu twice or more times...
  5480. if (skill_id == GC_CREATENEWPOISON)
  5481. skill_id = GC_RESEARCHNEWPOISON;
  5482. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5483. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5484. p->packetType = 0x18d;
  5485. int count = 0;
  5486. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5487. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5488. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5489. )
  5490. {
  5491. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5492. p->items[count].material[0] = 0;
  5493. p->items[count].material[1] = 0;
  5494. p->items[count].material[2] = 0;
  5495. count++;
  5496. }
  5497. }
  5498. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5499. WFIFOSET( fd, p->packetLength );
  5500. if( count > 0 ){
  5501. sd->menuskill_id = skill_id;
  5502. sd->menuskill_val = trigger;
  5503. return;
  5504. }
  5505. }
  5506. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5507. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5508. /// mk type:
  5509. /// 1 = cooking
  5510. /// 2 = arrow
  5511. /// 3 = elemental
  5512. /// 4 = GN_MIX_COOKING
  5513. /// 5 = GN_MAKEBOMB
  5514. /// 6 = GN_S_PHARMACY
  5515. /// 7 = MT_M_MACHINE - Unconfirmed
  5516. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5517. void clif_cooking_list( map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5518. nullpo_retv( sd );
  5519. // Avoid resending the menu twice or more times...
  5520. if( sd->menuskill_id == skill_id ){
  5521. return;
  5522. }
  5523. int fd = sd->fd;
  5524. if( !session_isActive( fd ) ){
  5525. return;
  5526. }
  5527. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5528. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5529. p->packetType = 0x25a;
  5530. p->makeItem = list_type; // list type
  5531. int count = 0;
  5532. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5533. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5534. continue;
  5535. }
  5536. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5537. count++;
  5538. }
  5539. if( count > 0 || skill_id == AM_PHARMACY ){
  5540. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5541. WFIFOSET( fd, p->packetLength );
  5542. sd->menuskill_id = skill_id;
  5543. sd->menuskill_val = trigger;
  5544. sd->menuskill_val2 = qty; // amount.
  5545. }else{
  5546. clif_menuskill_clear(sd);
  5547. #if PACKETVER >= 20090922
  5548. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5549. #else
  5550. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5551. WFIFOSET( fd, p->packetLength );
  5552. #endif
  5553. }
  5554. }
  5555. /// Notifies clients of a status change.
  5556. /// 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)]
  5557. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5558. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5559. /// @param bl Sends packet to clients around this object
  5560. /// @param id ID of object that has this effect
  5561. /// @param type Status icon see enum efst_type
  5562. /// @param flag 1:Active, 0:Deactive
  5563. /// @param tick Duration in ms
  5564. /// @param val1
  5565. /// @param val2
  5566. /// @param val3
  5567. 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)
  5568. {
  5569. unsigned char buf[32];
  5570. if (type == EFST_BLANK) //It shows nothing on the client...
  5571. return;
  5572. if (type == EFST_POSTDELAY && tick == 0)
  5573. return;
  5574. nullpo_retv(bl);
  5575. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5576. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5577. tick = 200;
  5578. #if PACKETVER >= 20120618
  5579. if (flag && battle_config.display_status_timers)
  5580. WBUFW(buf,0) = 0x983;
  5581. else
  5582. #elif PACKETVER >= 20090121
  5583. if (flag && battle_config.display_status_timers)
  5584. WBUFW(buf,0) = 0x43f;
  5585. else
  5586. #endif
  5587. WBUFW(buf,0) = 0x196;
  5588. WBUFW(buf,2) = type;
  5589. WBUFL(buf,4) = id;
  5590. WBUFB(buf,8) = flag;
  5591. #if PACKETVER >= 20120618
  5592. if (flag && battle_config.display_status_timers) {
  5593. if (tick <= 0)
  5594. tick = 9999; // this is indeed what official servers do
  5595. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5596. WBUFL(buf,13) = client_tick(tick);
  5597. WBUFL(buf,17) = val1;
  5598. WBUFL(buf,21) = val2;
  5599. WBUFL(buf,25) = val3;
  5600. }
  5601. #elif PACKETVER >= 20090121
  5602. if (flag && battle_config.display_status_timers) {
  5603. if (tick <= 0)
  5604. tick = 9999; // this is indeed what official servers do
  5605. WBUFL(buf,9) = client_tick(tick);
  5606. WBUFL(buf,13) = val1;
  5607. WBUFL(buf,17) = val2;
  5608. WBUFL(buf,21) = val3;
  5609. }
  5610. #endif
  5611. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5612. }
  5613. /* Sends status effect to clients around the bl
  5614. * @param bl Object that has the effect
  5615. * @param type Status icon see enum efst_type
  5616. * @param flag 1:Active, 0:Deactive
  5617. * @param tick Duration in ms
  5618. * @param val1
  5619. * @param val2
  5620. * @param val3
  5621. */
  5622. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5623. map_session_data *sd = NULL;
  5624. if (type == EFST_BLANK) //It shows nothing on the client...
  5625. return;
  5626. if (type == EFST_POSTDELAY && tick == 0)
  5627. return;
  5628. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5629. return;
  5630. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5631. // Older clients display normal riding icon.
  5632. if (type == EFST_MADOGEAR)
  5633. type = EFST_RIDING;
  5634. #endif
  5635. nullpo_retv(bl);
  5636. sd = BL_CAST(BL_PC, bl);
  5637. // Check if current bl type is in the returned bitmask and only send status changes that actually matter to the client
  5638. if (!(status_efst_get_bl_type(static_cast<efst_type>(type)) & bl->type))
  5639. return;
  5640. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5641. }
  5642. /**
  5643. * Send any active EFST to those around.
  5644. * @param tbl: Unit to send the packet to
  5645. * @param bl: Objects walking into view
  5646. * @param target: Client send type
  5647. */
  5648. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5649. unsigned char i;
  5650. struct sc_display_entry **sc_display;
  5651. unsigned char sc_display_count;
  5652. bool spheres_sent;
  5653. nullpo_retv(bl);
  5654. switch( bl->type ){
  5655. case BL_PC: {
  5656. map_session_data* sd = (map_session_data*)bl;
  5657. sc_display = sd->sc_display;
  5658. sc_display_count = sd->sc_display_count;
  5659. spheres_sent = !sd->state.connect_new;
  5660. }
  5661. break;
  5662. case BL_NPC: {
  5663. struct npc_data* nd = (struct npc_data*)bl;
  5664. sc_display = nd->sc_display;
  5665. sc_display_count = nd->sc_display_count;
  5666. spheres_sent = true;
  5667. }
  5668. break;
  5669. default:
  5670. return;
  5671. }
  5672. for (i = 0; i < sc_display_count; i++) {
  5673. enum sc_type type = sc_display[i]->type;
  5674. status_change *sc = status_get_sc(bl);
  5675. const struct TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : NULL);
  5676. t_tick tick = 0;
  5677. if (td)
  5678. tick = DIFF_TICK(td->tick, gettick());
  5679. // Status changes that need special handling
  5680. switch( type ){
  5681. case SC_SPHERE_1:
  5682. case SC_SPHERE_2:
  5683. case SC_SPHERE_3:
  5684. case SC_SPHERE_4:
  5685. case SC_SPHERE_5:
  5686. if( spheres_sent ){
  5687. target = AREA_WOS;
  5688. }
  5689. break;
  5690. case SC_HELLS_PLANT:
  5691. if( sc && sc->getSCE(type) ){
  5692. tick = sc->getSCE(type)->val4;
  5693. }
  5694. break;
  5695. }
  5696. #if PACKETVER > 20120418
  5697. 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);
  5698. #else
  5699. 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);
  5700. #endif
  5701. }
  5702. }
  5703. /// Notifies the client when a player enters the screen with an active EFST.
  5704. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5705. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5706. 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) {
  5707. #if PACKETVER >= 20111108
  5708. unsigned char buf[32];
  5709. #if PACKETVER >= 20120618
  5710. const int cmd = 0x984;
  5711. #elif PACKETVER >= 20111108
  5712. const int cmd = 0x8ff;
  5713. #endif
  5714. int offset = 0;
  5715. if (type == EFST_BLANK)
  5716. return;
  5717. nullpo_retv(bl);
  5718. if (tick <= 0)
  5719. tick = 9999;
  5720. WBUFW(buf,offset + 0) = cmd;
  5721. WBUFL(buf,offset + 2) = tid;
  5722. WBUFW(buf,offset + 6) = type;
  5723. #if PACKETVER >= 20111108
  5724. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5725. #if PACKETVER >= 20120618
  5726. WBUFL(buf,offset + 12) = client_tick(tick);
  5727. offset += 4;
  5728. #endif
  5729. WBUFL(buf,offset + 12) = val1;
  5730. WBUFL(buf,offset + 16) = val2;
  5731. WBUFL(buf,offset + 20) = val3;
  5732. #endif
  5733. clif_send(buf,packet_len(cmd),bl,target);
  5734. #endif
  5735. }
  5736. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5737. /// 008e <packet len>.W <message>.?B
  5738. void clif_displaymessage(const int fd, const char* mes)
  5739. {
  5740. nullpo_retv(mes);
  5741. if( session_isActive( fd ) ){
  5742. char *message, *line;
  5743. message = aStrdup(mes);
  5744. line = strtok(message, "\n");
  5745. while(line != NULL) {
  5746. #if PACKETVER == 20141022
  5747. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5748. /** so we redirect to ZC_NPC_CHAT **/
  5749. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5750. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5751. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5752. if (len > 0) {
  5753. WFIFOHEAD(fd, 13 + len);
  5754. WFIFOW(fd, 0) = 0x2C1;
  5755. WFIFOW(fd, 2) = 13 + len;
  5756. WFIFOL(fd, 4) = 0;
  5757. WFIFOL(fd, 8) = color;
  5758. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5759. WFIFOSET(fd, WFIFOW(fd, 2));
  5760. }
  5761. #else
  5762. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5763. int len = strnlen(line, CHAT_SIZE_MAX);
  5764. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5765. WFIFOHEAD(fd, 5 + len);
  5766. WFIFOW(fd,0) = 0x8e;
  5767. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5768. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5769. WFIFOSET(fd, 5 + len);
  5770. }
  5771. #endif
  5772. line = strtok(NULL, "\n");
  5773. }
  5774. aFree(message);
  5775. }
  5776. }
  5777. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5778. /// 009a <packet len>.W <message>.?B
  5779. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5780. {
  5781. nullpo_retv(mes);
  5782. if (len < 2)
  5783. return;
  5784. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5785. p->packetType = HEADER_ZC_BROADCAST;
  5786. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5787. if( ( type&BC_BLUE ) != 0 ){
  5788. const char* color = "blue";
  5789. int16 length = (int16)strlen( color );
  5790. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5791. strcpy( p->message, color );
  5792. strncpy( &p->message[length], mes, len );
  5793. p->PacketLength += length;
  5794. }else if( ( type&BC_WOE ) != 0 ){
  5795. const char* color = "ssss";
  5796. int16 length = (int16)strlen( color );
  5797. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5798. strcpy( p->message, color );
  5799. strncpy( &p->message[length], mes, len );
  5800. p->PacketLength += length;
  5801. }else{
  5802. strncpy( p->message, mes, len );
  5803. }
  5804. clif_send( p, p->PacketLength, bl, target );
  5805. }
  5806. /*==========================================
  5807. * Displays a message on a 'bl' to all it's nearby clients
  5808. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5809. *------------------------------------------*/
  5810. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5811. nullpo_retv(bl);
  5812. nullpo_retv(message);
  5813. int16 len = (int16)( strlen( message ) + 1 );
  5814. if( len > CHAT_SIZE_MAX ) {
  5815. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5816. len = CHAT_SIZE_MAX;
  5817. }
  5818. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5819. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5820. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5821. p->GID = bl->id;
  5822. safestrncpy( p->Message, message, len );
  5823. clif_send( p, p->PacketLength, bl, target );
  5824. }
  5825. /// Send broadcast message with font formatting.
  5826. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5827. void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  5828. {
  5829. nullpo_retv(mes);
  5830. if (len < 2)
  5831. return;
  5832. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5833. p->packetType = HEADER_ZC_BROADCAST2;
  5834. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5835. p->fontColor = fontColor;
  5836. p->fontType = fontType;
  5837. p->fontSize = fontSize;
  5838. p->fontAlign = fontAlign;
  5839. p->fontY = fontY;
  5840. strncpy( p->message, mes, len );
  5841. clif_send( p, p->PacketLength, bl, target );
  5842. }
  5843. /*
  5844. * Display *msg to all *users in channel
  5845. */
  5846. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5847. DBIterator *iter;
  5848. map_session_data *user;
  5849. unsigned short msg_len = 0, len = 0;
  5850. unsigned char buf[CHAT_SIZE_MAX];
  5851. if (!channel || !msg)
  5852. return;
  5853. msg_len = (unsigned short)(strlen(msg) + 1);
  5854. if( msg_len > sizeof(buf)-12 ) {
  5855. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5856. msg_len = sizeof(buf)-12;
  5857. }
  5858. WBUFW(buf,0) = 0x2C1;
  5859. WBUFW(buf,2) = (len = msg_len + 12);
  5860. WBUFL(buf,4) = 0;
  5861. WBUFL(buf,8) = color;
  5862. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5863. iter = db_iterator(channel->users);
  5864. for( user = (map_session_data *)dbi_first(iter); dbi_exists(iter); user = (map_session_data *)dbi_next(iter) ) {
  5865. clif_send(buf, len, &user->bl, SELF);
  5866. }
  5867. dbi_destroy(iter);
  5868. }
  5869. /// Displays heal effect.
  5870. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5871. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5872. /// var id:
  5873. /// 5 = HP (SP_HP)
  5874. /// 7 = SP (SP_SP)
  5875. /// ? = ignored
  5876. void clif_heal(int fd,int type,int val) {
  5877. #if PACKETVER < 20141022
  5878. const int cmd = 0x13d;
  5879. #else
  5880. const int cmd = 0xa27;
  5881. #endif
  5882. WFIFOHEAD(fd, packet_len(cmd));
  5883. WFIFOW(fd,0) = cmd;
  5884. WFIFOW(fd,2) = type;
  5885. #if PACKETVER < 20141022
  5886. WFIFOW(fd,4) = min(val, INT16_MAX);
  5887. #else
  5888. WFIFOL(fd,4) = min(val, INT32_MAX);
  5889. #endif
  5890. WFIFOSET(fd, packet_len(cmd));
  5891. }
  5892. /// Displays resurrection effect (ZC_RESURRECTION).
  5893. /// 0148 <id>.L <type>.W
  5894. /// type:
  5895. /// ignored
  5896. void clif_resurrection(struct block_list *bl,int type)
  5897. {
  5898. unsigned char buf[16];
  5899. nullpo_retv(bl);
  5900. WBUFW(buf,0)=0x148;
  5901. WBUFL(buf,2)=bl->id;
  5902. WBUFW(buf,6)=0;
  5903. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5904. if (disguised(bl))
  5905. clif_spawn(bl);
  5906. }
  5907. /// Sets the map property
  5908. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5909. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5910. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5911. {
  5912. #if PACKETVER >= 20121010
  5913. short cmd = 0x99b;
  5914. unsigned char buf[8];
  5915. #else
  5916. short cmd = 0x199;
  5917. unsigned char buf[4];
  5918. #endif
  5919. WBUFW(buf,0)=cmd;
  5920. WBUFW(buf,2)=property;
  5921. #if PACKETVER >= 20121010
  5922. struct map_data *mapdata = map_getmapdata(bl->m);
  5923. map_session_data *sd = BL_CAST(BL_PC, bl);
  5924. WBUFL(buf,4) = ((mapdata->getMapFlag(MF_PVP) || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5925. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5926. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5927. ((mapdata->getMapFlag(MF_FORCEMINEFFECT) || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5928. ((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
  5929. ((mapdata->getMapFlag(MF_PVP))<<5)| // COUNT_PK - Show the PvP counter
  5930. ((mapdata->getMapFlag(MF_PARTYLOCK))<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5931. ((mapdata->getMapFlag(MF_BATTLEGROUND))<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5932. ((mapdata->getMapFlag(MF_NOCOSTUME))<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5933. ((!mapdata->getMapFlag(MF_NOUSECART))<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5934. ((!mapdata->getMapFlag(MF_NOSUNMOONSTARMIRACLE))<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5935. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5936. #endif
  5937. clif_send(buf,packet_len(cmd),bl,t);
  5938. }
  5939. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5940. /// 01d6 <type>.W
  5941. void clif_map_type(map_session_data* sd, enum map_type type)
  5942. {
  5943. int fd;
  5944. nullpo_retv(sd);
  5945. fd=sd->fd;
  5946. WFIFOHEAD(fd,packet_len(0x1D6));
  5947. WFIFOW(fd,0)=0x1D6;
  5948. WFIFOW(fd,2)=type;
  5949. WFIFOSET(fd,packet_len(0x1D6));
  5950. }
  5951. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5952. /// 019a <id>.L <ranking>.L <total>.L
  5953. void clif_pvpset(map_session_data *sd,int pvprank,int pvpnum,int type)
  5954. {
  5955. if(type == 2) {
  5956. int fd = sd->fd;
  5957. WFIFOHEAD(fd,packet_len(0x19a));
  5958. WFIFOW(fd,0) = 0x19a;
  5959. WFIFOL(fd,2) = sd->bl.id;
  5960. WFIFOL(fd,6) = pvprank;
  5961. WFIFOL(fd,10) = pvpnum;
  5962. WFIFOSET(fd,packet_len(0x19a));
  5963. } else {
  5964. unsigned char buf[32];
  5965. WBUFW(buf,0) = 0x19a;
  5966. WBUFL(buf,2) = sd->bl.id;
  5967. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5968. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5969. else
  5970. WBUFL(buf,6) = pvprank;
  5971. WBUFL(buf,10) = pvpnum;
  5972. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5973. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5974. else if(!type)
  5975. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5976. else
  5977. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5978. }
  5979. }
  5980. /*==========================================
  5981. *
  5982. *------------------------------------------*/
  5983. void clif_map_property_mapall(int map_idx, enum map_property property)
  5984. {
  5985. struct block_list bl;
  5986. bl.id = 0;
  5987. bl.type = BL_NUL;
  5988. bl.m = map_idx;
  5989. clif_map_property( &bl, property, ALL_SAMEMAP );
  5990. }
  5991. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5992. /// 0188 <result>.W <index>.W <refine>.W
  5993. /// result:
  5994. /// 0 = success
  5995. /// 1 = failure
  5996. /// 2 = downgrade
  5997. void clif_refine(int fd, int fail, int index, int val)
  5998. {
  5999. WFIFOHEAD(fd,packet_len(0x188));
  6000. WFIFOW(fd,0)=0x188;
  6001. WFIFOW(fd,2)=fail;
  6002. WFIFOW(fd,4)=index+2;
  6003. WFIFOW(fd,6)=val;
  6004. WFIFOSET(fd,packet_len(0x188));
  6005. }
  6006. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  6007. /// 0223 <result>.L <nameid>.W
  6008. /// result:
  6009. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  6010. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  6011. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  6012. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  6013. void clif_upgrademessage( map_session_data* sd, int result, t_itemid item_id ){
  6014. struct PACKET_ZC_ACK_WEAPONREFINE p;
  6015. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  6016. p.result = result;
  6017. p.itemId = client_nameid( item_id );
  6018. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6019. }
  6020. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  6021. /// 0097 <packet len>.W <nick>.24B <message>.?B
  6022. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  6023. void clif_wis_message(map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  6024. int fd;
  6025. nullpo_retv(sd);
  6026. fd = sd->fd;
  6027. #if PACKETVER < 20091104
  6028. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  6029. WFIFOW(fd,0) = 0x97;
  6030. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  6031. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  6032. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  6033. WFIFOSET(fd,WFIFOW(fd,2));
  6034. #else
  6035. map_session_data *ssd = map_nick2sd(nick,false);
  6036. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  6037. WFIFOW(fd,0) = 0x97;
  6038. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  6039. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  6040. // If it is not a message from the server or a player from another map-server
  6041. if( ssd ){
  6042. gmlvl = pc_get_group_level(ssd);
  6043. }
  6044. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  6045. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  6046. WFIFOSET(fd,WFIFOW(fd,2));
  6047. #endif
  6048. }
  6049. /// Inform the player about the result of his whisper action
  6050. /// 0098 <result>.B (ZC_ACK_WHISPER).
  6051. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  6052. /// result:
  6053. /// 0 = success to send wisper
  6054. /// 1 = target character is not loged in
  6055. /// 2 = ignored by target
  6056. /// 3 = everyone ignored by target
  6057. void clif_wis_end(int fd, int result)
  6058. {
  6059. map_session_data *sd = (session_isActive(fd) ? (map_session_data *)session[fd]->session_data : NULL);
  6060. #if PACKETVER < 20131223
  6061. const int cmd = 0x98;
  6062. #else
  6063. const int cmd = 0x9df;
  6064. #endif
  6065. if (!sd)
  6066. return;
  6067. WFIFOHEAD(fd,packet_len(cmd));
  6068. WFIFOW(fd,0) = cmd;
  6069. WFIFOB(fd,2) = (char)result;
  6070. #if PACKETVER >= 20131223
  6071. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  6072. #endif
  6073. WFIFOSET(fd,packet_len(cmd));
  6074. }
  6075. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  6076. /// 0194 <char id>.L <name>.24B
  6077. /// 0af7 <flag>.W <char id>.L <name>.24B
  6078. void clif_solved_charname(int fd, int charid, const char* name)
  6079. {
  6080. #if PACKETVER >= 20180221
  6081. WFIFOHEAD(fd,packet_len(0xaf7));
  6082. WFIFOW(fd,0) = 0xaf7;
  6083. WFIFOW(fd,2) = name[0] ? 3 : 2;
  6084. WFIFOL(fd,4) = charid;
  6085. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  6086. WFIFOSET(fd,packet_len(0x0af7));
  6087. #else
  6088. WFIFOHEAD(fd,packet_len(0x194));
  6089. WFIFOW(fd,0)=0x194;
  6090. WFIFOL(fd,2)=charid;
  6091. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  6092. WFIFOSET(fd,packet_len(0x194));
  6093. #endif
  6094. }
  6095. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  6096. /// 017b <packet len>.W { <name id>.W }*
  6097. void clif_use_card(map_session_data *sd,int idx)
  6098. {
  6099. int i,c,ep;
  6100. int fd=sd->fd;
  6101. nullpo_retv(sd);
  6102. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6103. return;
  6104. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6105. return; //Avoid parsing invalid item indexes (no card/no item)
  6106. ep=sd->inventory_data[idx]->equip;
  6107. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6108. WFIFOW(fd,0)=0x17b;
  6109. for(i=c=0;i<MAX_INVENTORY;i++){
  6110. int j;
  6111. if(sd->inventory_data[i] == NULL)
  6112. continue;
  6113. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6114. continue;
  6115. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6116. continue;
  6117. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6118. continue;
  6119. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6120. continue;
  6121. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6122. continue;
  6123. 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.
  6124. continue;
  6125. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6126. if( j == sd->inventory_data[i]->slots ) // No room
  6127. continue;
  6128. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6129. continue;
  6130. WFIFOW(fd,4+c*2)=i+2;
  6131. c++;
  6132. }
  6133. if( !c ) return; // no item is available for card insertion
  6134. WFIFOW(fd,2)=4+c*2;
  6135. WFIFOSET(fd,WFIFOW(fd,2));
  6136. }
  6137. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6138. /// 017d <equip index>.W <card index>.W <result>.B
  6139. /// result:
  6140. /// 0 = success
  6141. /// 1 = failure
  6142. void clif_insert_card(map_session_data *sd,int idx_equip,int idx_card,int flag)
  6143. {
  6144. int fd;
  6145. nullpo_retv(sd);
  6146. fd=sd->fd;
  6147. WFIFOHEAD(fd,packet_len(0x17d));
  6148. WFIFOW(fd,0)=0x17d;
  6149. WFIFOW(fd,2)=idx_equip+2;
  6150. WFIFOW(fd,4)=idx_card+2;
  6151. WFIFOB(fd,6)=flag;
  6152. WFIFOSET(fd,packet_len(0x17d));
  6153. }
  6154. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6155. /// 0177 <packet len>.W { <index>.W }*
  6156. void clif_item_identify_list(map_session_data *sd)
  6157. {
  6158. int i,c;
  6159. int fd;
  6160. nullpo_retv(sd);
  6161. fd=sd->fd;
  6162. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6163. WFIFOW(fd,0)=0x177;
  6164. for(i=c=0;i<MAX_INVENTORY;i++){
  6165. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6166. WFIFOW(fd,c*2+4)=client_index(i);
  6167. c++;
  6168. }
  6169. }
  6170. if(c > 0) {
  6171. WFIFOW(fd,2)=c*2+4;
  6172. WFIFOSET(fd,WFIFOW(fd,2));
  6173. sd->menuskill_id = MC_IDENTIFY;
  6174. sd->menuskill_val = c;
  6175. sd->state.workinprogress = WIP_DISABLE_ALL;
  6176. }
  6177. }
  6178. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6179. /// 0179 <index>.W <result>.B
  6180. void clif_item_identified(map_session_data *sd,int idx,int flag)
  6181. {
  6182. int fd;
  6183. nullpo_retv(sd);
  6184. fd=sd->fd;
  6185. WFIFOHEAD(fd,packet_len(0x179));
  6186. WFIFOW(fd, 0)=0x179;
  6187. WFIFOW(fd, 2)=idx+2;
  6188. WFIFOB(fd, 4)=flag;
  6189. WFIFOSET(fd,packet_len(0x179));
  6190. }
  6191. /// Presents a list of items that can be repaired.
  6192. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6193. void clif_item_repair_list( map_session_data& sd, map_session_data& dstsd, uint16 lv ){
  6194. PACKET_ZC_REPAIRITEMLIST* p = (PACKET_ZC_REPAIRITEMLIST*)packet_buffer;
  6195. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6196. p->packetLength = sizeof( *p );
  6197. size_t c = 0;
  6198. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  6199. 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)){
  6200. p->items[c].index = static_cast<decltype( p->items[0].index )>( i );
  6201. p->items[c].itemId = client_nameid( dstsd.inventory.u.items_inventory[i].nameid );
  6202. p->items[c].refine = dstsd.inventory.u.items_inventory[i].refine;
  6203. clif_addcards( &p->items[c].slot, &dstsd.inventory.u.items_inventory[i] );
  6204. p->packetLength += sizeof( p->items[0] );
  6205. c++;
  6206. }
  6207. }
  6208. if( c > 0 ){
  6209. clif_send( p, p->packetLength, &sd.bl, SELF );
  6210. sd.menuskill_id = BS_REPAIRWEAPON;
  6211. sd.menuskill_val = dstsd.bl.id;
  6212. sd.menuskill_val2 = lv;
  6213. }else{
  6214. clif_skill_fail( sd, sd.ud.skill_id );
  6215. }
  6216. }
  6217. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6218. /// 01fe <index>.W <result>.B
  6219. /// index:
  6220. /// ignored (inventory index)
  6221. /// result:
  6222. /// 0 = Item repair success.
  6223. /// 1 = Item repair failure.
  6224. void clif_item_repaireffect(map_session_data *sd,int idx,int flag)
  6225. {
  6226. int fd;
  6227. nullpo_retv(sd);
  6228. fd = sd->fd;
  6229. WFIFOHEAD(fd,packet_len(0x1fe));
  6230. WFIFOW(fd, 0)=0x1fe;
  6231. WFIFOW(fd, 2)=idx+2;
  6232. WFIFOB(fd, 4)=flag;
  6233. WFIFOSET(fd,packet_len(0x1fe));
  6234. }
  6235. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6236. /// 02bb <equip location>.W <account id>.L
  6237. void clif_item_damaged(map_session_data* sd, unsigned short position)
  6238. {
  6239. int fd = sd->fd;
  6240. WFIFOHEAD(fd,packet_len(0x2bb));
  6241. WFIFOW(fd,0) = 0x2bb;
  6242. WFIFOW(fd,2) = position;
  6243. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6244. WFIFOSET(fd,packet_len(0x2bb));
  6245. }
  6246. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6247. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6248. void clif_item_refine_list( map_session_data *sd ){
  6249. nullpo_retv( sd );
  6250. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6251. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6252. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6253. int refine_item[MAX_WEAPON_LEVEL];
  6254. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6255. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6256. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6257. #ifdef RENEWAL
  6258. refine_item[4] = -1;
  6259. #endif
  6260. int count = 0;
  6261. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6262. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6263. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6264. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6265. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6266. p->items[count].index = client_index( i );
  6267. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6268. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6269. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6270. count++;
  6271. }
  6272. }
  6273. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6274. clif_send( p, p->packetLength, &sd->bl, SELF );
  6275. if( count > 0 ){
  6276. sd->menuskill_id = WS_WEAPONREFINE;
  6277. sd->menuskill_val = skill_lv;
  6278. }
  6279. }
  6280. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6281. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6282. void clif_item_skill( map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6283. nullpo_retv( sd );
  6284. struct PACKET_ZC_AUTORUN_SKILL p;
  6285. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6286. p.skill_id = skill_id;
  6287. p.skill_type = skill_get_inf( skill_id );
  6288. p.skill_lv = skill_lv;
  6289. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6290. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6291. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6292. p.up_flag = false;
  6293. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6294. }
  6295. /// Adds an item to character's cart.
  6296. /// 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)
  6297. /// 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)
  6298. /// 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)
  6299. void clif_cart_additem( map_session_data *sd, int n, int amount ){
  6300. nullpo_retv( sd );
  6301. int fd = sd->fd;
  6302. if( !session_isActive( fd ) ){
  6303. return;
  6304. }
  6305. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6306. return;
  6307. }
  6308. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6309. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6310. p.index = client_index( n );
  6311. p.amount = amount;
  6312. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6313. #if PACKETVER >= 5
  6314. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6315. #endif
  6316. p.identified = sd->cart.u.items_cart[n].identify;
  6317. p.damaged = sd->cart.u.items_cart[n].attribute;
  6318. p.refine = sd->cart.u.items_cart[n].refine;
  6319. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6320. #if PACKETVER >= 20150226
  6321. clif_add_random_options( p.option_data, sd->cart.u.items_cart[n] );
  6322. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6323. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6324. #endif
  6325. #endif
  6326. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6327. }
  6328. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6329. /* Acknowledge an item have been added to cart
  6330. * 012c <result>B
  6331. * result :
  6332. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6333. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6334. */
  6335. void clif_cart_additem_ack(map_session_data *sd, uint8 flag)
  6336. {
  6337. int fd;
  6338. unsigned char *buf;
  6339. nullpo_retv(sd);
  6340. fd = sd->fd;
  6341. buf = WFIFOP(fd,0);
  6342. WBUFW(buf,0) = 0x12c;
  6343. WBUFB(buf,2) = flag;
  6344. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6345. }
  6346. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6347. void clif_bank_open( map_session_data& sd ){
  6348. #if PACKETVER >= 20130717
  6349. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6350. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6351. p.unknown = 0;
  6352. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6353. #endif
  6354. }
  6355. /*
  6356. * Request to Open the banking system
  6357. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6358. */
  6359. void clif_parse_BankOpen(int fd, map_session_data* sd) {
  6360. //TODO check if preventing trade or stuff like that
  6361. //also mark something in case char ain't available for saving, should we check now ?
  6362. nullpo_retv(sd);
  6363. if( !battle_config.feature_banking ) {
  6364. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6365. return;
  6366. }
  6367. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6368. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6369. return;
  6370. }
  6371. else {
  6372. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6373. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6374. if(sd->status.account_id == aid){
  6375. sd->state.banking = 1;
  6376. //request save ?
  6377. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6378. //on succes open bank ?
  6379. clif_bank_open( *sd );
  6380. }
  6381. }
  6382. }
  6383. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6384. void clif_bank_close( map_session_data& sd ){
  6385. #if PACKETVER >= 20130717
  6386. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6387. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6388. p.unknown = 0;
  6389. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6390. #endif
  6391. }
  6392. /*
  6393. * Request to close the banking system
  6394. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6395. */
  6396. void clif_parse_BankClose(int fd, map_session_data* sd) {
  6397. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6398. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6399. nullpo_retv(sd);
  6400. if( !battle_config.feature_banking ) {
  6401. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6402. //still allow to go trough to not stuck player if we have disable it while they was in
  6403. }
  6404. if(sd->status.account_id == aid){
  6405. sd->state.banking = 0;
  6406. clif_bank_close( *sd );
  6407. }
  6408. }
  6409. /*
  6410. * Display how much we got in bank (I suppose)
  6411. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6412. */
  6413. void clif_Bank_Check( map_session_data& sd ){
  6414. #if PACKETVER >= 20130717
  6415. struct PACKET_ZC_BANKING_CHECK p = {};
  6416. p.packetType = HEADER_ZC_BANKING_CHECK;
  6417. p.money = sd.bank_vault;
  6418. p.reason = 0;
  6419. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6420. #endif
  6421. }
  6422. /*
  6423. * Requesting the data in bank
  6424. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6425. */
  6426. void clif_parse_BankCheck(int fd, map_session_data* sd) {
  6427. nullpo_retv(sd);
  6428. if( !battle_config.feature_banking ) {
  6429. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6430. return;
  6431. }
  6432. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6433. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6434. return;
  6435. }
  6436. else {
  6437. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6438. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6439. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6440. clif_Bank_Check( *sd );
  6441. }
  6442. }
  6443. /*
  6444. * Acknowledge of deposit some money in bank
  6445. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6446. */
  6447. void clif_bank_deposit( map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6448. #if PACKETVER >= 20130717
  6449. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6450. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6451. p.money = sd.bank_vault;
  6452. p.zeny = sd.status.zeny;
  6453. p.reason = reason;
  6454. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6455. #endif
  6456. }
  6457. /*
  6458. * Request saving some money in bank
  6459. * @author : original [Yommy/Hercules]
  6460. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6461. */
  6462. void clif_parse_BankDeposit(int fd, map_session_data* sd) {
  6463. nullpo_retv(sd);
  6464. if( !battle_config.feature_banking ) {
  6465. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6466. return;
  6467. }
  6468. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6469. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6470. return;
  6471. }
  6472. else {
  6473. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6474. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6475. int money = RFIFOL(fd,info->pos[1]);
  6476. if(sd->status.account_id == aid){
  6477. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6478. clif_bank_deposit( *sd, reason );
  6479. }
  6480. }
  6481. }
  6482. /*
  6483. * Acknowledge of withdrawing some money from bank
  6484. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6485. */
  6486. void clif_bank_withdraw( map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6487. #if PACKETVER >= 20130717
  6488. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6489. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6490. p.reason = reason;
  6491. p.money = sd.bank_vault;
  6492. p.zeny = sd.status.zeny;
  6493. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6494. #endif
  6495. }
  6496. /*
  6497. * Request Withdrawing some money from bank
  6498. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6499. */
  6500. void clif_parse_BankWithdraw(int fd, map_session_data* sd) {
  6501. nullpo_retv(sd);
  6502. if( !battle_config.feature_banking ) {
  6503. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6504. return;
  6505. }
  6506. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6507. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6508. return;
  6509. }
  6510. else {
  6511. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6512. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6513. int money = RFIFOL(fd,info->pos[1]);
  6514. if(sd->status.account_id == aid){
  6515. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6516. clif_bank_withdraw( *sd, reason );
  6517. }
  6518. }
  6519. }
  6520. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6521. /// 0125 <index>.W <amount>.L
  6522. void clif_cart_delitem(map_session_data *sd,int n,int amount)
  6523. {
  6524. int fd;
  6525. nullpo_retv(sd);
  6526. fd=sd->fd;
  6527. WFIFOHEAD(fd,packet_len(0x125));
  6528. WFIFOW(fd,0)=0x125;
  6529. WFIFOW(fd,2)=n+2;
  6530. WFIFOL(fd,4)=amount;
  6531. WFIFOSET(fd,packet_len(0x125));
  6532. }
  6533. /// Opens the shop creation menu (ZC_OPENSTORE).
  6534. /// 012d <num>.W
  6535. /// num:
  6536. /// number of allowed item slots
  6537. void clif_openvendingreq(map_session_data* sd, int num)
  6538. {
  6539. int fd;
  6540. nullpo_retv(sd);
  6541. fd = sd->fd;
  6542. WFIFOHEAD(fd,packet_len(0x12d));
  6543. WFIFOW(fd,0) = 0x12d;
  6544. WFIFOW(fd,2) = num;
  6545. WFIFOSET(fd,packet_len(0x12d));
  6546. }
  6547. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6548. /// 0131 <owner id>.L <message>.80B
  6549. void clif_showvendingboard( map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6550. if( tbl == nullptr ){
  6551. tbl = &sd.bl;
  6552. target = AREA_WOS;
  6553. }
  6554. struct PACKET_ZC_STORE_ENTRY p = {};
  6555. p.packetType = HEADER_ZC_STORE_ENTRY;
  6556. p.makerAID = sd.status.account_id;
  6557. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6558. clif_send( &p, sizeof( p ), tbl, target );
  6559. }
  6560. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6561. /// 0132 <owner id>.L
  6562. void clif_closevendingboard(struct block_list* bl, int fd)
  6563. {
  6564. unsigned char buf[16];
  6565. nullpo_retv(bl);
  6566. WBUFW(buf,0) = 0x132;
  6567. WBUFL(buf,2) = bl->id;
  6568. if( session_isActive(fd) ) {
  6569. WFIFOHEAD(fd,packet_len(0x132));
  6570. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6571. WFIFOSET(fd,packet_len(0x132));
  6572. } else {
  6573. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6574. }
  6575. }
  6576. /// Sends a list of items in a shop.
  6577. /// 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)
  6578. /// 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)
  6579. void clif_vendinglist( map_session_data* sd, map_session_data* vsd ){
  6580. nullpo_retv( sd );
  6581. nullpo_retv( vsd );
  6582. nullpo_retv( vsd->vending );
  6583. int fd = sd->fd;
  6584. if( !session_isActive( fd ) ){
  6585. return;
  6586. }
  6587. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6588. WFIFOHEAD( fd, len );
  6589. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6590. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6591. p->packetLength = len;
  6592. p->AID = vsd->status.account_id;
  6593. #if PACKETVER >= 20100105
  6594. p->venderId = vsd->vender_id;
  6595. #endif
  6596. for( int i = 0; i < vsd->vend_num; i++ ){
  6597. int index = vsd->vending[i].index;
  6598. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6599. p->items[i].price = vsd->vending[i].value;
  6600. p->items[i].amount = vsd->vending[i].amount;
  6601. p->items[i].index = client_index( index );
  6602. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6603. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6604. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6605. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6606. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6607. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6608. #if PACKETVER >= 20150226
  6609. clif_add_random_options( p->items[i].option_data, vsd->cart.u.items_cart[index] );
  6610. #if PACKETVER >= 20160921
  6611. p->items[i].location = pc_equippoint_sub( sd, data );
  6612. p->items[i].viewSprite = data->look;
  6613. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6614. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6615. #endif
  6616. #endif
  6617. #endif
  6618. }
  6619. WFIFOSET( fd, len );
  6620. }
  6621. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6622. /// 0135 <index>.W <amount>.W <result>.B
  6623. /// result:
  6624. /// 0 = success
  6625. /// 1 = not enough zeny
  6626. /// 2 = overweight
  6627. /// 4 = out of stock
  6628. /// 5 = "cannot use an npc shop while in a trade"
  6629. /// 6 = Because the store information was incorrect the item was not purchased.
  6630. /// 7 = No sales information.
  6631. void clif_buyvending(map_session_data* sd, int index, int amount, int fail)
  6632. {
  6633. int fd;
  6634. nullpo_retv(sd);
  6635. fd = sd->fd;
  6636. WFIFOHEAD(fd,packet_len(0x135));
  6637. WFIFOW(fd,0) = 0x135;
  6638. WFIFOW(fd,2) = index+2;
  6639. WFIFOW(fd,4) = amount;
  6640. WFIFOB(fd,6) = fail;
  6641. WFIFOSET(fd,packet_len(0x135));
  6642. }
  6643. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6644. /// 0a28 <Result>.B
  6645. /// result:
  6646. /// 0 = Successed
  6647. /// 1 = Failed
  6648. void clif_openvending_ack(map_session_data* sd, int result)
  6649. {
  6650. int fd;
  6651. nullpo_retv(sd);
  6652. fd = sd->fd;
  6653. WFIFOHEAD(fd, 3);
  6654. WFIFOW(fd,0) = 0xa28;
  6655. WFIFOB(fd,2) = result;
  6656. WFIFOSET(fd, 3);
  6657. }
  6658. /// Shop creation success.
  6659. /// 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)
  6660. void clif_openvending( map_session_data* sd, int id, struct s_vending* vending ){
  6661. nullpo_retv( sd );
  6662. nullpo_retv( vending );
  6663. int fd = sd->fd;
  6664. if( !session_isActive( fd ) ){
  6665. return;
  6666. }
  6667. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6668. WFIFOHEAD( fd, len );
  6669. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6670. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6671. p->packetLength = len;
  6672. p->AID = id;
  6673. for( int i = 0; i < sd->vend_num; i++ ) {
  6674. int index = vending[i].index;
  6675. p->items[i].price = vending[i].value;
  6676. p->items[i].index = client_index( index );
  6677. p->items[i].amount = vending[i].amount;
  6678. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6679. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6680. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6681. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6682. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6683. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6684. #if PACKETVER >= 20150226
  6685. clif_add_random_options( p->items[i].option_data, sd->cart.u.items_cart[index] );
  6686. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6687. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6688. #endif
  6689. #endif
  6690. }
  6691. WFIFOSET( fd, len );
  6692. #if PACKETVER >= 20141022
  6693. /// 0 = Successed
  6694. /// 1 = Failed
  6695. clif_openvending_ack( sd, 0 );
  6696. #endif
  6697. }
  6698. /// Inform merchant that someone has bought an item.
  6699. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6700. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6701. void clif_vendingreport(map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6702. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6703. const int cmd = 0x137;
  6704. #else
  6705. const int cmd = 0x9e5;
  6706. #endif
  6707. int fd = sd->fd;
  6708. nullpo_retv(sd);
  6709. WFIFOHEAD(fd,packet_len(cmd));
  6710. WFIFOW(fd,0) = cmd;
  6711. WFIFOW(fd,2) = index+2;
  6712. WFIFOW(fd,4) = amount;
  6713. #if PACKETVER >= 20141016
  6714. WFIFOL(fd,6) = char_id; // GID
  6715. WFIFOL(fd,10) = (int)time(NULL); // Date
  6716. WFIFOL(fd,14) = zeny; // zeny
  6717. #endif
  6718. WFIFOSET(fd,packet_len(cmd));
  6719. }
  6720. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6721. /// 00fa <result>.B
  6722. /// result:
  6723. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6724. /// 1 = MsgStringTable[78]="party name already exists"
  6725. /// 2 = MsgStringTable[79]="already in a party"
  6726. /// 3 = cannot organize parties on this map
  6727. /// ? = nothing
  6728. void clif_party_created( map_session_data& sd, int result ){
  6729. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6730. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6731. p.result = result;
  6732. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6733. }
  6734. /// Adds new member to a party.
  6735. /// 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)
  6736. /// 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)
  6737. /// 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)
  6738. /// role:
  6739. /// 0 = leader
  6740. /// 1 = normal
  6741. /// state:
  6742. /// 0 = connected
  6743. /// 1 = disconnected
  6744. void clif_party_member_info( struct party_data& party, map_session_data& sd ){
  6745. int id = party_getmemberid( &party, &sd );
  6746. if( id < 0 ){
  6747. return;
  6748. }
  6749. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6750. p.packetType = partymemberinfo;
  6751. p.AID = sd.status.account_id;
  6752. #if PACKETVER >= 20171207
  6753. p.GID = sd.status.char_id;
  6754. #endif
  6755. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6756. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6757. p.class_ = sd.status.class_;
  6758. p.baseLevel = sd.status.base_level;
  6759. #endif
  6760. p.x = sd.bl.x;
  6761. p.y = sd.bl.y;
  6762. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6763. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6764. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6765. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6766. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6767. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6768. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6769. }
  6770. /// Sends party information (ZC_GROUP_LIST).
  6771. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6772. /// role:
  6773. /// 0 = leader
  6774. /// 1 = normal
  6775. /// state:
  6776. /// 0 = connected
  6777. /// 1 = disconnected
  6778. /// 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
  6779. void clif_party_info( struct party_data& party, map_session_data* sd ){
  6780. send_target target;
  6781. if( sd == nullptr ){
  6782. sd = party_getavailablesd( &party );
  6783. if( sd == nullptr ){
  6784. // Nobody is online to notify
  6785. return;
  6786. }
  6787. // Send to whole party
  6788. target = PARTY;
  6789. }else{
  6790. // Send only to self
  6791. target = SELF;
  6792. }
  6793. struct PACKET_ZC_GROUP_LIST* p = (struct PACKET_ZC_GROUP_LIST*)packet_buffer;
  6794. p->packetType = partyinfo;
  6795. p->packetLen = sizeof( *p );
  6796. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6797. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6798. struct party_member& m = party.party.member[i];
  6799. if( m.account_id == 0 ){
  6800. continue;
  6801. }
  6802. struct PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6803. member.AID = m.account_id;
  6804. #if PACKETVER >= 20171207
  6805. member.GID = m.char_id;
  6806. #endif
  6807. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6808. mapindex_getmapname_ext( m.map, member.mapName );
  6809. member.leader = ( m.leader ) ? 0 : 1;
  6810. member.offline = ( m.online ) ? 0 : 1;
  6811. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6812. member.class_ = m.class_;
  6813. member.baseLevel = m.lv;
  6814. #endif
  6815. c++;
  6816. p->packetLen += sizeof( member );
  6817. }
  6818. clif_send( p, p->packetLen, &sd->bl, target );
  6819. }
  6820. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6821. /// 02c9 <flag>.B
  6822. /// flag:
  6823. /// 0 = allow party invites
  6824. /// 1 = auto-deny party invites
  6825. void clif_partyinvitationstate( map_session_data& sd ){
  6826. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6827. struct PACKET_ZC_PARTY_CONFIG p = {};
  6828. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6829. p.denyPartyInvites = sd.status.disable_partyinvite;
  6830. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6831. #endif
  6832. }
  6833. /// Party invitation request.
  6834. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6835. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6836. void clif_party_invite( map_session_data& sd, map_session_data& tsd ){
  6837. struct party_data* party = party_search( sd.status.party_id );
  6838. if( party == nullptr ){
  6839. return;
  6840. }
  6841. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6842. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6843. p.GRID = party->party.party_id;
  6844. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6845. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6846. }
  6847. /// Party invite result.
  6848. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6849. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6850. /// result=0 : char is already in a party -> MsgStringTable[80]
  6851. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6852. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6853. /// result=3 : party is full -> MsgStringTable[83]
  6854. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6855. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6856. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6857. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6858. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6859. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6860. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6861. void clif_party_invite_reply( map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6862. #if PACKETVER < 20070904
  6863. if( reply == PARTY_REPLY_OFFLINE ){
  6864. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6865. return;
  6866. }
  6867. #endif
  6868. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6869. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6870. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6871. p.result = reply;
  6872. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6873. }
  6874. /// Updates party settings.
  6875. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6876. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6877. /// exp option:
  6878. /// 0 = exp sharing disabled
  6879. /// 1 = exp sharing enabled
  6880. /// 2 = cannot change exp sharing
  6881. ///
  6882. /// flag:
  6883. /// 0 = send to party
  6884. /// 1 = send to sd
  6885. void clif_party_option(struct party_data *p,map_session_data *sd,int flag)
  6886. {
  6887. unsigned char buf[16];
  6888. #if PACKETVER < 20090603
  6889. const int cmd = 0x101;
  6890. #else
  6891. const int cmd = 0x7d8;
  6892. #endif
  6893. nullpo_retv(p);
  6894. if(!sd && flag==0){
  6895. int i;
  6896. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6897. if (i < MAX_PARTY)
  6898. sd = p->data[i].sd;
  6899. }
  6900. if(!sd) return;
  6901. WBUFW(buf,0)=cmd;
  6902. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6903. #if PACKETVER >= 20090603
  6904. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6905. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6906. #endif
  6907. if(flag==0)
  6908. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6909. else
  6910. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6911. }
  6912. /**
  6913. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6914. * @param sd Send the notification for this player
  6915. * @param account_id Account ID of kicked member
  6916. * @param name Name of kicked member
  6917. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6918. * @param target Send target
  6919. **/
  6920. void clif_party_withdraw( map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6921. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6922. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6923. p.AID = account_id;
  6924. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6925. p.result = result;
  6926. clif_send( &p, sizeof( p ), &sd.bl, target );
  6927. }
  6928. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6929. /// 0109 <packet len>.W <account id>.L <message>.?B
  6930. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, int len ){
  6931. map_session_data* sd = party_getavailablesd( &party );
  6932. if( sd == nullptr ){
  6933. return;
  6934. }
  6935. if (len > CHAT_SIZE_MAX) {
  6936. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6937. len = CHAT_SIZE_MAX;
  6938. }
  6939. struct PACKET_ZC_NOTIFY_CHAT_PARTY* p = (struct PACKET_ZC_NOTIFY_CHAT_PARTY*)packet_buffer;
  6940. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6941. p->PacketLength = sizeof( *p ) + len;
  6942. p->AID = account_id;
  6943. safestrncpy( p->chatMsg, mes, len );
  6944. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6945. }
  6946. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6947. /// 0107 <account id>.L <x>.W <y>.W
  6948. void clif_party_xy( map_session_data& sd ){
  6949. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6950. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6951. p.AID = sd.status.account_id;
  6952. p.xPos = sd.bl.x;
  6953. p.yPos = sd.bl.y;
  6954. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6955. }
  6956. /*==========================================
  6957. * Sends x/y dot to a single fd. [Skotlex]
  6958. *------------------------------------------*/
  6959. void clif_party_xy_single( map_session_data& sd, map_session_data& tsd ){
  6960. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6961. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6962. p.AID = sd.status.account_id;
  6963. p.xPos = sd.bl.x;
  6964. p.yPos = sd.bl.y;
  6965. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6966. }
  6967. /// Updates HP bar of a party member.
  6968. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6969. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6970. void clif_party_hp( map_session_data& sd ){
  6971. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6972. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6973. p.AID = sd.status.account_id;
  6974. #if PACKETVER < 20100119
  6975. // To correctly display the %hp bar. [Skotlex]
  6976. if( sd.battle_status.max_hp > INT16_MAX ){
  6977. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6978. p.maxhp = 100;
  6979. }else{
  6980. p.hp = sd.battle_status.hp;
  6981. p.maxhp = sd.battle_status.max_hp;
  6982. }
  6983. #else
  6984. p.hp = sd.battle_status.hp;
  6985. p.maxhp = sd.battle_status.max_hp;
  6986. #endif
  6987. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6988. }
  6989. /// Notifies the party members of a character's death or revival.
  6990. /// 0AB2 <GID>.L <dead>.B
  6991. void clif_party_dead( map_session_data& sd ){
  6992. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6993. struct PACKET_ZC_GROUP_ISALIVE p = {};
  6994. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6995. p.AID = sd.status.account_id;
  6996. p.isDead = pc_isdead( &sd );
  6997. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6998. #endif
  6999. }
  7000. /// Updates the job and level of a party member
  7001. /// 0abd <account id>.L <job>.W <level>.W
  7002. void clif_party_job_and_level( map_session_data& sd ){
  7003. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  7004. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  7005. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  7006. p.AID = sd.status.account_id;
  7007. p.job = sd.status.class_;
  7008. p.level = sd.status.base_level;
  7009. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  7010. #endif
  7011. }
  7012. /*==========================================
  7013. * Sends HP bar to a single fd. [Skotlex]
  7014. *------------------------------------------*/
  7015. void clif_hpmeter_single( map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  7016. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  7017. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  7018. p.AID = id;
  7019. #if PACKETVER < 20100119
  7020. // To correctly display the %hp bar. [Skotlex]
  7021. if( maxhp > INT16_MAX ){
  7022. p.hp = hp / ( maxhp / 100 );
  7023. p.maxhp = 100;
  7024. }else{
  7025. p.hp = hp;
  7026. p.maxhp = maxhp;
  7027. }
  7028. #else
  7029. p.hp = hp;
  7030. p.maxhp = maxhp;
  7031. #endif
  7032. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7033. }
  7034. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  7035. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  7036. void clif_movetoattack(map_session_data *sd,struct block_list *bl)
  7037. {
  7038. int fd;
  7039. nullpo_retv(sd);
  7040. nullpo_retv(bl);
  7041. fd=sd->fd;
  7042. WFIFOHEAD(fd,packet_len(0x139));
  7043. WFIFOW(fd, 0)=0x139;
  7044. WFIFOL(fd, 2)=bl->id;
  7045. WFIFOW(fd, 6)=bl->x;
  7046. WFIFOW(fd, 8)=bl->y;
  7047. WFIFOW(fd,10)=sd->bl.x;
  7048. WFIFOW(fd,12)=sd->bl.y;
  7049. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  7050. WFIFOSET(fd,packet_len(0x139));
  7051. }
  7052. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  7053. /// 018f <result>.W <name id>.W
  7054. /// result:
  7055. /// 0 = success
  7056. /// 1 = failure
  7057. /// 2 = success (alchemist)
  7058. /// 3 = failure (alchemist)
  7059. void clif_produceeffect(map_session_data* sd,int flag, t_itemid nameid){
  7060. nullpo_retv( sd );
  7061. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  7062. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  7063. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  7064. p.result = flag;
  7065. p.itemId = client_nameid( nameid );
  7066. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7067. }
  7068. /// Initiates the pet taming process (ZC_START_CAPTURE).
  7069. /// 019e
  7070. void clif_catch_process(map_session_data *sd)
  7071. {
  7072. int fd;
  7073. nullpo_retv(sd);
  7074. fd=sd->fd;
  7075. WFIFOHEAD(fd,packet_len(0x19e));
  7076. WFIFOW(fd,0)=0x19e;
  7077. WFIFOSET(fd,packet_len(0x19e));
  7078. }
  7079. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  7080. /// 01a0 <result>.B
  7081. /// 0 = failure
  7082. /// 1 = success
  7083. void clif_pet_roulette(map_session_data *sd,int data)
  7084. {
  7085. int fd;
  7086. nullpo_retv(sd);
  7087. fd=sd->fd;
  7088. WFIFOHEAD(fd,packet_len(0x1a0));
  7089. WFIFOW(fd,0)=0x1a0;
  7090. WFIFOB(fd,2)=data;
  7091. WFIFOSET(fd,packet_len(0x1a0));
  7092. }
  7093. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7094. /// 01a6 <packet len>.W { <index>.W }*
  7095. void clif_sendegg(map_session_data *sd)
  7096. {
  7097. int i,n=0,fd;
  7098. nullpo_retv(sd);
  7099. fd=sd->fd;
  7100. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7101. clif_displaymessage(fd, msg_txt(sd,666));
  7102. return;
  7103. }
  7104. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7105. WFIFOW(fd,0)=0x1a6;
  7106. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7107. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7108. sd->inventory_data[i]->type != IT_PETEGG ||
  7109. sd->inventory.u.items_inventory[i].amount <= 0)
  7110. continue;
  7111. WFIFOW(fd,n*2+4)=client_index(i);
  7112. n++;
  7113. }
  7114. WFIFOW(fd,2)=4+n*2;
  7115. WFIFOSET(fd,WFIFOW(fd,2));
  7116. sd->menuskill_id = SA_TAMINGMONSTER;
  7117. sd->menuskill_val = -1;
  7118. }
  7119. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7120. /// 01a4 <type>.B <id>.L <data>.L
  7121. /// type:
  7122. /// 0 = pre-init (data = 0)
  7123. /// 1 = intimacy (data = 0~4)
  7124. /// 2 = hunger (data = 0~4)
  7125. /// 3 = accessory
  7126. /// 4 = performance (data = 1~3: normal, 4: special)
  7127. /// 5 = hairstyle
  7128. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7129. ///
  7130. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7131. void clif_send_petdata(map_session_data* sd, struct pet_data* pd, int type, int param)
  7132. {
  7133. uint8 buf[16];
  7134. nullpo_retv(pd);
  7135. WBUFW(buf,0) = 0x1a4;
  7136. WBUFB(buf,2) = type;
  7137. WBUFL(buf,3) = pd->bl.id;
  7138. WBUFL(buf,7) = param;
  7139. if (sd)
  7140. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7141. else
  7142. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7143. }
  7144. /// Pet's base data (ZC_PROPERTY_PET).
  7145. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7146. void clif_send_petstatus(map_session_data *sd)
  7147. {
  7148. int fd;
  7149. struct s_pet *pet;
  7150. nullpo_retv(sd);
  7151. nullpo_retv(sd->pd);
  7152. fd=sd->fd;
  7153. pet = &sd->pd->pet;
  7154. WFIFOHEAD(fd,packet_len(0x1a2));
  7155. WFIFOW(fd,0)=0x1a2;
  7156. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7157. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7158. WFIFOW(fd,27)=pet->level;
  7159. WFIFOW(fd,29)=pet->hungry;
  7160. WFIFOW(fd,31)=pet->intimate;
  7161. WFIFOW(fd,33)=pet->equip;
  7162. #if PACKETVER >= 20081126
  7163. WFIFOW(fd,35)=pet->class_;
  7164. #endif
  7165. WFIFOSET(fd,packet_len(0x1a2));
  7166. }
  7167. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7168. /// 01aa <id>.L <data>.L
  7169. /// data:
  7170. /// @see CZ_PET_ACT.
  7171. void clif_pet_emotion(struct pet_data *pd,int param)
  7172. {
  7173. unsigned char buf[16];
  7174. nullpo_retv(pd);
  7175. memset(buf,0,packet_len(0x1aa));
  7176. WBUFW(buf,0)=0x1aa;
  7177. WBUFL(buf,2)=pd->bl.id;
  7178. WBUFL(buf,6)=param;
  7179. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7180. }
  7181. /// Result of request to feed a pet (ZC_FEED_PET).
  7182. /// 01a3 <result>.B <name id>.W
  7183. /// result:
  7184. /// 0 = failure
  7185. /// 1 = success
  7186. void clif_pet_food( map_session_data *sd, int foodid,int fail ){
  7187. nullpo_retv( sd );
  7188. struct PACKET_ZC_FEED_PET p;
  7189. p.packetType = 0x1a3;
  7190. p.result = fail;
  7191. p.itemId = client_nameid( foodid );
  7192. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7193. }
  7194. /// Send pet auto feed info.
  7195. void clif_pet_autofeed_status(map_session_data* sd, bool force) {
  7196. #if PACKETVER >= 20141008
  7197. nullpo_retv(sd);
  7198. if (force || battle_config.pet_autofeed_always) {
  7199. // Always send ON or OFF
  7200. if (sd->pd && battle_config.feature_pet_autofeed) {
  7201. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7202. }
  7203. else {
  7204. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7205. }
  7206. }
  7207. else {
  7208. // Only send when enabled
  7209. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7210. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7211. }
  7212. }
  7213. #endif
  7214. }
  7215. /// Presents a list of skills that can be auto-spelled.
  7216. /// 01cd { <skill id>.L }*7 (ZC_AUTOSPELLLIST)
  7217. void clif_autospell( map_session_data& sd, uint16 skill_lv ){
  7218. struct s_autospell_requirement{
  7219. uint16 skill_id;
  7220. uint16 required_autospell_skill_lv;
  7221. };
  7222. #ifndef RENEWAL
  7223. const std::vector<s_autospell_requirement> autospell_skills = {
  7224. { MG_FIREBOLT, 0 },
  7225. { MG_COLDBOLT, 0 },
  7226. { MG_LIGHTNINGBOLT, 0 },
  7227. { MG_SOULSTRIKE, 3 },
  7228. { MG_FIREBALL, 3 },
  7229. { WZ_EARTHSPIKE, 6 },
  7230. { MG_FROSTDIVER, 6 },
  7231. { MG_THUNDERSTORM, 9 },
  7232. { WZ_HEAVENDRIVE, 9 }
  7233. };
  7234. #else
  7235. const std::vector<s_autospell_requirement> autospell_skills = {
  7236. { MG_NAPALMBEAT, 0 },
  7237. { MG_COLDBOLT, 1 },
  7238. { MG_FIREBOLT, 1 },
  7239. { MG_LIGHTNINGBOLT, 1 },
  7240. { MG_SOULSTRIKE, 4 },
  7241. { MG_FIREBALL, 7 },
  7242. { MG_FROSTDIVER, 9 },
  7243. };
  7244. #endif
  7245. #if PACKETVER_MAIN_NUM >= 20181128 || PACKETVER_RE_NUM >= 20181031
  7246. PACKET_ZC_AUTOSPELLLIST* p = (PACKET_ZC_AUTOSPELLLIST*)packet_buffer;
  7247. p->packetType = HEADER_ZC_AUTOSPELLLIST;
  7248. p->packetLength = sizeof( *p );
  7249. size_t count = 0;
  7250. for( const s_autospell_requirement& requirement : autospell_skills ){
  7251. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7252. p->skills[count++] = requirement.skill_id;
  7253. p->packetLength += sizeof( p->skills[0] );
  7254. }
  7255. }
  7256. clif_send( p, p->packetLength, &sd.bl, SELF );
  7257. #elif PACKETVER_MAIN_NUM >= 20090406 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_SAK_NUM >= 20080618
  7258. PACKET_ZC_AUTOSPELLLIST p = {};
  7259. p.packetType = HEADER_ZC_AUTOSPELLLIST;
  7260. size_t count = 0;
  7261. for( const s_autospell_requirement& requirement : autospell_skills ){
  7262. if( count == ARRAYLENGTH( p.skills ) ){
  7263. break;
  7264. }
  7265. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7266. p.skills[count++] = requirement.skill_id;
  7267. }else{
  7268. p.skills[count++] = 0;
  7269. }
  7270. }
  7271. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7272. #endif
  7273. sd.menuskill_id = SA_AUTOSPELL;
  7274. sd.menuskill_val = skill_lv;
  7275. }
  7276. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7277. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7278. void clif_devotion(struct block_list *src, map_session_data *tsd)
  7279. {
  7280. unsigned char buf[56];
  7281. nullpo_retv(src);
  7282. memset(buf,0,packet_len(0x1cf));
  7283. WBUFW(buf,0) = 0x1cf;
  7284. WBUFL(buf,2) = src->id;
  7285. if( src->type == BL_MER )
  7286. {
  7287. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7288. if( md && md->master && md->devotion_flag )
  7289. WBUFL(buf,6) = md->master->bl.id;
  7290. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7291. }
  7292. else
  7293. {
  7294. int i;
  7295. map_session_data *sd = BL_CAST(BL_PC,src);
  7296. if( sd == NULL )
  7297. return;
  7298. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7299. WBUFL(buf,6+4*i) = sd->devotion[i];
  7300. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7301. }
  7302. if( tsd )
  7303. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7304. else
  7305. clif_send(buf, packet_len(0x1cf), src, AREA);
  7306. }
  7307. /// Notifies the client of an object's spirits.
  7308. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7309. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7310. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7311. nullpo_retv( bl );
  7312. struct PACKET_ZC_SPIRITS p = {};
  7313. p.PacketType = HEADER_ZC_SPIRITS;
  7314. p.AID = bl->id;
  7315. switch( bl->type ){
  7316. case BL_PC:
  7317. p.num = ( (map_session_data*)bl )->spiritball;
  7318. break;
  7319. case BL_HOM:
  7320. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7321. break;
  7322. }
  7323. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7324. }
  7325. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7326. /// 01d2 <account id>.L <delay>.L
  7327. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7328. {
  7329. unsigned char buf[32];
  7330. nullpo_retv(bl);
  7331. WBUFW(buf,0)=0x1d2;
  7332. WBUFL(buf,2)=bl->id;
  7333. WBUFL(buf,6)=client_tick(wait);
  7334. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7335. }
  7336. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7337. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7338. /// flag:
  7339. /// 0 = inactive
  7340. /// 1 = active
  7341. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7342. {
  7343. unsigned char buf[32];
  7344. nullpo_retv(src);
  7345. WBUFW(buf,0)=0x1d1;
  7346. WBUFL(buf,2)=src->id;
  7347. WBUFL(buf,6)=dst_id;
  7348. WBUFL(buf,10)=active;
  7349. clif_send(buf,packet_len(0x1d1),src,AREA);
  7350. }
  7351. /// MVP effect (ZC_MVP).
  7352. /// 010c <account id>.L
  7353. void clif_mvp_effect(map_session_data *sd)
  7354. {
  7355. unsigned char buf[16];
  7356. nullpo_retv(sd);
  7357. WBUFW(buf,0)=0x10c;
  7358. WBUFL(buf,2)=sd->bl.id;
  7359. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7360. }
  7361. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7362. /// 010a <name id>.W
  7363. void clif_mvp_item( map_session_data *sd, t_itemid nameid ){
  7364. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7365. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7366. p.itemId = client_nameid( nameid );
  7367. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7368. }
  7369. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7370. /// 010b <exp>.L
  7371. void clif_mvp_exp(map_session_data *sd, t_exp exp) {
  7372. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7373. if (battle_config.mvp_exp_reward_message) {
  7374. char e_msg[CHAT_SIZE_MAX];
  7375. sprintf(e_msg, msg_txt(sd, 717), exp);
  7376. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7377. }
  7378. #else
  7379. int fd;
  7380. nullpo_retv(sd);
  7381. fd = sd->fd;
  7382. WFIFOHEAD(fd, packet_len(0x10b));
  7383. WFIFOW(fd,0) = 0x10b;
  7384. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7385. WFIFOSET(fd, packet_len(0x10b));
  7386. #endif
  7387. }
  7388. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7389. /// 010d
  7390. ///
  7391. /// "You are the MVP, but cannot obtain the reward because
  7392. /// you are overweight."
  7393. void clif_mvp_noitem(map_session_data* sd)
  7394. {
  7395. int fd = sd->fd;
  7396. WFIFOHEAD(fd,packet_len(0x10d));
  7397. WFIFOW(fd,0) = 0x10d;
  7398. WFIFOSET(fd,packet_len(0x10d));
  7399. }
  7400. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7401. /// 0167 <result>.B
  7402. /// result:
  7403. /// 0 = "Guild has been created."
  7404. /// 1 = "You are already in a Guild."
  7405. /// 2 = "That Guild Name already exists."
  7406. /// 3 = "You need the neccessary item to create a Guild."
  7407. void clif_guild_created(map_session_data *sd,int flag)
  7408. {
  7409. int fd;
  7410. nullpo_retv(sd);
  7411. fd=sd->fd;
  7412. WFIFOHEAD(fd,packet_len(0x167));
  7413. WFIFOW(fd,0)=0x167;
  7414. WFIFOB(fd,2)=flag;
  7415. WFIFOSET(fd,packet_len(0x167));
  7416. }
  7417. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7418. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7419. /// mode:
  7420. /// &0x01 = allow invite
  7421. /// &0x10 = allow expel
  7422. void clif_guild_belonginfo( map_session_data& sd ){
  7423. if( sd.guild == nullptr ){
  7424. return;
  7425. }
  7426. const auto &guild = sd.guild->guild;
  7427. int position = guild_getposition(sd);
  7428. if( position < 0 ){
  7429. return;
  7430. }
  7431. struct PACKET_ZC_UPDATE_GDID p = {};
  7432. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7433. p.guildId = guild.guild_id;
  7434. p.emblemVersion = guild.emblem_id;
  7435. p.mode = guild.position[position].mode;
  7436. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7437. p.interSid = 0; // InterSID (unknown purpose)
  7438. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7439. #if PACKETVER_MAIN_NUM >= 20220216
  7440. p.masterGID = guild.member[0].char_id;
  7441. #endif
  7442. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7443. }
  7444. /// Guild member login notice.
  7445. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7446. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7447. /// status:
  7448. /// 0 = offline
  7449. /// 1 = online
  7450. void clif_guild_memberlogin_notice(const struct mmo_guild &g,int idx,int flag)
  7451. {
  7452. unsigned char buf[64];
  7453. map_session_data* sd;
  7454. WBUFW(buf, 0)=0x1f2;
  7455. WBUFL(buf, 2)=g.member[idx].account_id;
  7456. WBUFL(buf, 6)=g.member[idx].char_id;
  7457. WBUFL(buf,10)=flag;
  7458. if( ( sd = g.member[idx].sd ) != NULL )
  7459. {
  7460. WBUFW(buf,14) = sd->status.sex;
  7461. WBUFW(buf,16) = sd->status.hair;
  7462. WBUFW(buf,18) = sd->status.hair_color;
  7463. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7464. }
  7465. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7466. {
  7467. WBUFW(buf,14) = 0;
  7468. WBUFW(buf,16) = 0;
  7469. WBUFW(buf,18) = 0;
  7470. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7471. }
  7472. }
  7473. // Function `clif_guild_memberlogin_notice` sends info about
  7474. // logins and logouts of a guild member to the rest members.
  7475. // But at the 1st time (after a player login or map changing)
  7476. // the client won't show the message.
  7477. // So I suggest use this function for sending "first-time-info"
  7478. // to some player on entering the game or changing location.
  7479. // At next time the client would always show the message.
  7480. // The function sends all the statuses in the single packet
  7481. // to economize traffic. [LuzZza]
  7482. void clif_guild_send_onlineinfo(map_session_data *sd)
  7483. {
  7484. unsigned char buf[14*128];
  7485. int i, count=0, p_len;
  7486. nullpo_retv(sd);
  7487. p_len = packet_len(0x16d);
  7488. auto &g = sd->guild;
  7489. if (!g)
  7490. return;
  7491. for(i=0; i<g->guild.max_member; i++) {
  7492. if(g->guild.member[i].account_id > 0 &&
  7493. g->guild.member[i].account_id != sd->status.account_id) {
  7494. WBUFW(buf,count*p_len) = 0x16d;
  7495. WBUFL(buf,count*p_len+2) = g->guild.member[i].account_id;
  7496. WBUFL(buf,count*p_len+6) = g->guild.member[i].char_id;
  7497. WBUFL(buf,count*p_len+10) = g->guild.member[i].online;
  7498. count++;
  7499. }
  7500. }
  7501. clif_send(buf, p_len*count, &sd->bl, SELF);
  7502. }
  7503. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7504. /// 014e <menu flag>.L
  7505. /// menu flag:
  7506. /// 0x00 = Basic Info (always on)
  7507. /// &0x01 = Member manager
  7508. /// &0x02 = Positions
  7509. /// &0x04 = Skills
  7510. /// &0x10 = Expulsion list
  7511. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7512. /// &0x80 = Notice
  7513. void clif_guild_masterormember(map_session_data *sd)
  7514. {
  7515. int fd;
  7516. nullpo_retv(sd);
  7517. fd=sd->fd;
  7518. WFIFOHEAD(fd,packet_len(0x14e));
  7519. WFIFOW(fd,0) = 0x14e;
  7520. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7521. WFIFOSET(fd,packet_len(0x14e));
  7522. }
  7523. /// Guild basic information (Territories [Valaris])
  7524. /// 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)
  7525. /// 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)
  7526. /// 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)
  7527. void clif_guild_basicinfo( map_session_data& sd ){
  7528. if( sd.guild == nullptr ){
  7529. return;
  7530. }
  7531. const auto &guild = sd.guild->guild;
  7532. struct PACKET_ZC_GUILD_INFO p = {};
  7533. p.PacketType = HEADER_ZC_GUILD_INFO;
  7534. p.GDID = guild.guild_id;
  7535. p.level = guild.guild_lv;
  7536. p.userNum = guild.connect_member;
  7537. p.maxUserNum = guild.max_member;
  7538. p.userAverageLevel = guild.average_lv;
  7539. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7540. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7541. p.point = 0; // Tax Points
  7542. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7543. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7544. p.emblemVersion = guild.emblem_id;
  7545. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7546. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( guild ) ), sizeof( p.manageLand ) );
  7547. p.zeny = 0;
  7548. #if PACKETVER >= 20200902
  7549. p.masterGID = guild.member[0].char_id; // leader
  7550. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7551. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7552. p.masterGID = guild.member[0].char_id; // leader
  7553. #else
  7554. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7555. #endif
  7556. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7557. }
  7558. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7559. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7560. void clif_guild_allianceinfo(map_session_data *sd)
  7561. {
  7562. int fd,i,c;
  7563. nullpo_retv(sd);
  7564. auto &g = sd->guild;
  7565. if (!g)
  7566. return;
  7567. fd = sd->fd;
  7568. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7569. WFIFOW(fd, 0)=0x14c;
  7570. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7571. struct guild_alliance *a=&g->guild.alliance[i];
  7572. if(a->guild_id>0){
  7573. WFIFOL(fd,c*32+4)=a->opposition;
  7574. WFIFOL(fd,c*32+8)=a->guild_id;
  7575. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7576. c++;
  7577. }
  7578. }
  7579. WFIFOW(fd, 2)=c*32+4;
  7580. WFIFOSET(fd,WFIFOW(fd,2));
  7581. }
  7582. /// Guild member manager information
  7583. /// 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)
  7584. /// state:
  7585. /// 0 = offline
  7586. /// 1 = online
  7587. /// memo:
  7588. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7589. /// 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)
  7590. void clif_guild_memberlist( map_session_data& sd ){
  7591. if( sd.guild == nullptr ){
  7592. return;
  7593. }
  7594. const auto &guild = sd.guild->guild;
  7595. struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer;
  7596. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7597. p->packetLength = sizeof( *p );
  7598. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7599. const auto &member = guild.member[i];
  7600. if( member.account_id == 0 ){
  7601. continue;
  7602. }
  7603. struct GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7604. member_info.AID = member.account_id;
  7605. member_info.GID = member.char_id;
  7606. member_info.head = member.hair;
  7607. member_info.headPalette = member.hair_color;
  7608. member_info.sex = member.gender;
  7609. member_info.job = member.class_;
  7610. member_info.level = member.lv;
  7611. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7612. member_info.currentState = member.online;
  7613. member_info.positionID = member.position;
  7614. #if PACKETVER >= 20200902
  7615. member_info.lastLoginTime = member.last_login;
  7616. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7617. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7618. member_info.lastLoginTime = member.last_login;
  7619. #else
  7620. 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.
  7621. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7622. #endif
  7623. c++;
  7624. p->packetLength += sizeof( member_info );
  7625. }
  7626. clif_send( p, p->packetLength, &sd.bl, SELF );
  7627. }
  7628. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7629. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7630. void clif_guild_positionnamelist(map_session_data *sd)
  7631. {
  7632. int i,fd;
  7633. nullpo_retv(sd);
  7634. auto &g = sd->guild;
  7635. if (!g)
  7636. return;
  7637. fd = sd->fd;
  7638. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7639. WFIFOW(fd, 0)=0x166;
  7640. for(i=0;i<MAX_GUILDPOSITION;i++){
  7641. WFIFOL(fd,i*28+4)=i;
  7642. safestrncpy(WFIFOCP(fd,i*28+8),g->guild.position[i].name,NAME_LENGTH);
  7643. }
  7644. WFIFOW(fd,2)=i*28+4;
  7645. WFIFOSET(fd,WFIFOW(fd,2));
  7646. }
  7647. /// Guild position information (ZC_POSITION_INFO).
  7648. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7649. /// mode:
  7650. /// &0x01 = allow invite
  7651. /// &0x10 = allow expel
  7652. /// ranking:
  7653. /// TODO
  7654. void clif_guild_positioninfolist(map_session_data *sd)
  7655. {
  7656. int i,fd;
  7657. nullpo_retv(sd);
  7658. auto &g = sd->guild;
  7659. if (!g)
  7660. return;
  7661. fd = sd->fd;
  7662. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7663. WFIFOW(fd, 0)=0x160;
  7664. for(i=0;i<MAX_GUILDPOSITION;i++){
  7665. struct guild_position *p=&g->guild.position[i];
  7666. WFIFOL(fd,i*16+ 4)=i;
  7667. WFIFOL(fd,i*16+ 8)=p->mode;
  7668. WFIFOL(fd,i*16+12)=i;
  7669. WFIFOL(fd,i*16+16)=p->exp_mode;
  7670. }
  7671. WFIFOW(fd, 2)=i*16+4;
  7672. WFIFOSET(fd,WFIFOW(fd,2));
  7673. }
  7674. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7675. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7676. /// mode:
  7677. /// &0x01 = allow invite
  7678. /// &0x10 = allow expel
  7679. /// ranking:
  7680. /// TODO
  7681. void clif_guild_positionchanged(const struct mmo_guild &g,int idx)
  7682. {
  7683. // FIXME: This packet is intended to update the clients after a
  7684. // commit of position info changes, not sending one packet per
  7685. // position.
  7686. map_session_data *sd;
  7687. unsigned char buf[128];
  7688. WBUFW(buf, 0)=0x174;
  7689. WBUFW(buf, 2)=44; // packet len
  7690. // GUILD_REG_POSITION_INFO{
  7691. WBUFL(buf, 4)=idx;
  7692. WBUFL(buf, 8)=g.position[idx].mode;
  7693. WBUFL(buf,12)=idx;
  7694. WBUFL(buf,16)=g.position[idx].exp_mode;
  7695. safestrncpy(WBUFCP(buf,20),g.position[idx].name,NAME_LENGTH);
  7696. // }*
  7697. if( (sd=guild_getavailablesd(g))!=NULL )
  7698. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7699. }
  7700. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7701. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7702. void clif_guild_memberpositionchanged(const struct mmo_guild &g, int idx)
  7703. {
  7704. // FIXME: This packet is intended to update the clients after a
  7705. // commit of member position assignment changes, not sending one
  7706. // packet per position.
  7707. map_session_data *sd;
  7708. unsigned char buf[64];
  7709. WBUFW(buf, 0)=0x156;
  7710. WBUFW(buf, 2)=16; // packet len
  7711. // MEMBER_POSITION_INFO{
  7712. WBUFL(buf, 4)=g.member[idx].account_id;
  7713. WBUFL(buf, 8)=g.member[idx].char_id;
  7714. WBUFL(buf,12)=g.member[idx].position;
  7715. // }*
  7716. if( (sd=guild_getavailablesd(g))!=NULL )
  7717. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7718. }
  7719. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7720. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7721. void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g)
  7722. {
  7723. int fd = sd.fd;
  7724. if( g.emblem_len <= 0 )
  7725. return;
  7726. WFIFOHEAD(fd,g.emblem_len+12);
  7727. WFIFOW(fd,0)=0x152;
  7728. WFIFOW(fd,2)=g.emblem_len+12;
  7729. WFIFOL(fd,4)=g.guild_id;
  7730. WFIFOL(fd,8)=g.emblem_id;
  7731. memcpy(WFIFOP(fd,12),g.emblem_data,g.emblem_len);
  7732. WFIFOSET(fd,WFIFOW(fd,2));
  7733. }
  7734. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7735. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7736. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7737. void clif_guild_emblem_area(struct block_list* bl)
  7738. {
  7739. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7740. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7741. PACKET_ZC_CHANGE_GUILD p{};
  7742. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7743. p.guild_id = status_get_guild_id(bl);
  7744. p.emblem_id = status_get_emblem_id(bl);
  7745. p.AID = bl->id;
  7746. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7747. }
  7748. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7749. /// 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 }*
  7750. void clif_guild_skillinfo(map_session_data* sd)
  7751. {
  7752. int fd;
  7753. int i,c;
  7754. nullpo_retv(sd);
  7755. auto &g = sd->guild;
  7756. if (!g)
  7757. return;
  7758. fd = sd->fd;
  7759. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7760. WFIFOW(fd,0) = 0x0162;
  7761. WFIFOW(fd,4) = g->guild.skill_point;
  7762. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7763. {
  7764. if(g->guild.skill[i].id > 0 && guild_check_skill_require(g->guild, g->guild.skill[i].id))
  7765. {
  7766. int id = g->guild.skill[i].id;
  7767. int p = 6 + c*37;
  7768. WFIFOW(fd,p+0) = id;
  7769. WFIFOL(fd,p+2) = skill_get_inf(id);
  7770. WFIFOW(fd,p+6) = g->guild.skill[i].lv;
  7771. WFIFOW(fd,p+8) = skill_get_sp(id, g->guild.skill[i].lv);
  7772. WFIFOW(fd,p+10) = skill_get_range(id, g->guild.skill[i].lv);
  7773. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7774. WFIFOB(fd,p+36)= (g->guild.skill[i].lv < guild_skill_get_max(id) && sd == g->guild.member[0].sd) ? 1 : 0;
  7775. c++;
  7776. }
  7777. }
  7778. WFIFOW(fd,2) = 6 + c*37;
  7779. WFIFOSET(fd,WFIFOW(fd,2));
  7780. }
  7781. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7782. /// 016f <subject>.60B <notice>.120B
  7783. void clif_guild_notice(map_session_data* sd)
  7784. {
  7785. nullpo_retv(sd);
  7786. auto &g = sd->guild;
  7787. int fd = sd->fd;
  7788. if ( !session_isActive(fd) )
  7789. return;
  7790. if(g->guild.mes1[0] == '\0' && g->guild.mes2[0] == '\0')
  7791. return;
  7792. WFIFOHEAD(fd,packet_len(0x16f));
  7793. WFIFOW(fd,0) = 0x16f;
  7794. memcpy(WFIFOP(fd,2), g->guild.mes1, MAX_GUILDMES1);
  7795. memcpy(WFIFOP(fd,62), g->guild.mes2, MAX_GUILDMES2);
  7796. WFIFOSET(fd,packet_len(0x16f));
  7797. }
  7798. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7799. /// 016a <guild id>.L <guild name>.24B
  7800. void clif_guild_invite(const map_session_data &sd, const struct mmo_guild &g)
  7801. {
  7802. int fd = sd.fd;
  7803. WFIFOHEAD(fd,packet_len(0x16a));
  7804. WFIFOW(fd,0)=0x16a;
  7805. WFIFOL(fd,2)=g.guild_id;
  7806. safestrncpy(WFIFOCP(fd,6),g.name,NAME_LENGTH);
  7807. WFIFOSET(fd,packet_len(0x16a));
  7808. }
  7809. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7810. /// 0169 <answer>.B
  7811. /// answer:
  7812. /// 0 = Already in guild.
  7813. /// 1 = Offer rejected.
  7814. /// 2 = Offer accepted.
  7815. /// 3 = Guild full.
  7816. void clif_guild_inviteack(map_session_data *sd,int flag)
  7817. {
  7818. int fd;
  7819. nullpo_retv(sd);
  7820. fd=sd->fd;
  7821. WFIFOHEAD(fd,packet_len(0x169));
  7822. WFIFOW(fd,0)=0x169;
  7823. WFIFOB(fd,2)=flag;
  7824. WFIFOSET(fd,packet_len(0x169));
  7825. }
  7826. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7827. /// 015a <char name>.24B <reason>.40B
  7828. void clif_guild_leave(map_session_data *sd,const char *name,const char *mes)
  7829. {
  7830. unsigned char buf[128];
  7831. nullpo_retv(sd);
  7832. WBUFW(buf, 0)=0x15a;
  7833. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7834. memcpy(WBUFP(buf,26),mes,40);
  7835. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7836. }
  7837. /// Notifies clients of a guild of an expelled member.
  7838. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7839. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7840. void clif_guild_expulsion(map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7841. {
  7842. unsigned char buf[128];
  7843. #if PACKETVER < 20100803
  7844. const unsigned short cmd = 0x15c;
  7845. #else
  7846. const unsigned short cmd = 0x839;
  7847. #endif
  7848. nullpo_retv(sd);
  7849. WBUFW(buf,0) = cmd;
  7850. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7851. safestrncpy(WBUFCP(buf,26), mes, 40);
  7852. #if PACKETVER < 20100803
  7853. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7854. #endif
  7855. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7856. }
  7857. /// Guild expulsion list (ZC_BAN_LIST).
  7858. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7859. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7860. void clif_guild_expulsionlist(map_session_data* sd)
  7861. {
  7862. #if PACKETVER < 20100803
  7863. const int offset = NAME_LENGTH*2+40;
  7864. #else
  7865. const int offset = NAME_LENGTH+40;
  7866. #endif
  7867. int fd, i, c = 0;
  7868. nullpo_retv(sd);
  7869. auto &g = sd->guild;
  7870. if (!g)
  7871. return;
  7872. fd = sd->fd;
  7873. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7874. WFIFOW(fd,0) = 0x163;
  7875. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7876. {
  7877. struct guild_expulsion* e = &g->guild.expulsion[i];
  7878. if( e->account_id > 0 )
  7879. {
  7880. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7881. #if PACKETVER < 20100803
  7882. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7883. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7884. #else
  7885. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7886. #endif
  7887. c++;
  7888. }
  7889. }
  7890. WFIFOW(fd,2) = 4 + c*offset;
  7891. WFIFOSET(fd,WFIFOW(fd,2));
  7892. }
  7893. /// Guild chat message (ZC_GUILD_CHAT).
  7894. /// 017f <packet len>.W <message>.?B
  7895. void clif_guild_message(const struct mmo_guild &g,uint32 account_id,const char *mes,int len)
  7896. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7897. map_session_data *sd;
  7898. uint8 buf[256];
  7899. if( len == 0 )
  7900. {
  7901. return;
  7902. }
  7903. else if( len > sizeof(buf)-5 )
  7904. {
  7905. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g.guild_id);
  7906. len = sizeof(buf)-5;
  7907. }
  7908. WBUFW(buf, 0) = 0x17f;
  7909. WBUFW(buf, 2) = len + 5;
  7910. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7911. if ((sd = guild_getavailablesd(g)) != NULL)
  7912. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7913. }
  7914. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7915. /// 0171 <inviter account id>.L <guild name>.24B
  7916. void clif_guild_reqalliance(map_session_data *sd,uint32 account_id,const char *name)
  7917. {
  7918. int fd;
  7919. nullpo_retv(sd);
  7920. fd=sd->fd;
  7921. WFIFOHEAD(fd,packet_len(0x171));
  7922. WFIFOW(fd,0)=0x171;
  7923. WFIFOL(fd,2)=account_id;
  7924. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7925. WFIFOSET(fd,packet_len(0x171));
  7926. }
  7927. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7928. /// 0173 <answer>.B
  7929. /// answer:
  7930. /// 0 = Already allied.
  7931. /// 1 = You rejected the offer.
  7932. /// 2 = You accepted the offer.
  7933. /// 3 = They have too any alliances.
  7934. /// 4 = You have too many alliances.
  7935. /// 5 = Alliances are disabled.
  7936. void clif_guild_allianceack(map_session_data *sd,int flag)
  7937. {
  7938. int fd;
  7939. nullpo_retv(sd);
  7940. fd=sd->fd;
  7941. WFIFOHEAD(fd,packet_len(0x173));
  7942. WFIFOW(fd,0)=0x173;
  7943. WFIFOL(fd,2)=flag;
  7944. WFIFOSET(fd,packet_len(0x173));
  7945. }
  7946. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7947. /// 0184 <other guild id>.L <relation>.L
  7948. /// relation:
  7949. /// 0 = Ally
  7950. /// 1 = Enemy
  7951. void clif_guild_delalliance(map_session_data *sd,int guild_id,int flag)
  7952. {
  7953. nullpo_retv(sd);
  7954. int fd = sd->fd;
  7955. if ( !session_isActive(fd) )
  7956. return;
  7957. WFIFOHEAD(fd,packet_len(0x184));
  7958. WFIFOW(fd,0)=0x184;
  7959. WFIFOL(fd,2)=guild_id;
  7960. WFIFOL(fd,6)=flag;
  7961. WFIFOSET(fd,packet_len(0x184));
  7962. }
  7963. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7964. /// 0181 <result>.B
  7965. /// result:
  7966. /// 0 = Antagonist has been set.
  7967. /// 1 = Guild has too many Antagonists.
  7968. /// 2 = Already set as an Antagonist.
  7969. /// 3 = Antagonists are disabled.
  7970. void clif_guild_oppositionack(map_session_data *sd,int flag)
  7971. {
  7972. int fd;
  7973. nullpo_retv(sd);
  7974. fd=sd->fd;
  7975. WFIFOHEAD(fd,packet_len(0x181));
  7976. WFIFOW(fd,0)=0x181;
  7977. WFIFOB(fd,2)=flag;
  7978. WFIFOSET(fd,packet_len(0x181));
  7979. }
  7980. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7981. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7982. /*
  7983. void clif_guild_allianceadded(struct guild *g,int idx)
  7984. {
  7985. unsigned char buf[64];
  7986. WBUFW(buf,0)=0x185;
  7987. WBUFL(buf,2)=g->alliance[idx].opposition;
  7988. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7989. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7990. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7991. }
  7992. */
  7993. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7994. /// 015e <reason>.L
  7995. /// 0 = success
  7996. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7997. /// 2 = there are still members in the guild
  7998. void clif_guild_broken(map_session_data *sd,int flag)
  7999. {
  8000. int fd;
  8001. nullpo_retv(sd);
  8002. fd=sd->fd;
  8003. WFIFOHEAD(fd,packet_len(0x15e));
  8004. WFIFOW(fd,0)=0x15e;
  8005. WFIFOL(fd,2)=flag;
  8006. WFIFOSET(fd,packet_len(0x15e));
  8007. }
  8008. /// Displays emotion on an object (ZC_EMOTION).
  8009. /// 00c0 <id>.L <type>.B
  8010. /// type:
  8011. /// enum emotion_type
  8012. void clif_emotion(struct block_list *bl,int type)
  8013. {
  8014. unsigned char buf[8];
  8015. nullpo_retv(bl);
  8016. WBUFW(buf,0)=0xc0;
  8017. WBUFL(buf,2)=bl->id;
  8018. WBUFB(buf,6)=type;
  8019. clif_send(buf,packet_len(0xc0),bl,AREA);
  8020. }
  8021. /// Displays the contents of a talkiebox trap.
  8022. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  8023. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  8024. nullpo_retv( bl );
  8025. nullpo_retv( talkie );
  8026. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  8027. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  8028. p.aid = bl->id;
  8029. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  8030. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  8031. }
  8032. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  8033. /// 01ea <id>.L
  8034. void clif_wedding_effect(struct block_list *bl)
  8035. {
  8036. unsigned char buf[6];
  8037. nullpo_retv(bl);
  8038. WBUFW(buf,0) = 0x1ea;
  8039. WBUFL(buf,2) = bl->id;
  8040. clif_send(buf, packet_len(0x1ea), bl, AREA);
  8041. }
  8042. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  8043. /// 01e6 <partner name>.24B
  8044. void clif_callpartner(map_session_data& sd)
  8045. {
  8046. PACKET_ZC_COUPLENAME p = { 0 };
  8047. p.packetType = HEADER_ZC_COUPLENAME;
  8048. if( sd.status.partner_id ) {
  8049. map_session_data *p_sd = pc_get_partner(&sd);
  8050. if (p_sd != nullptr && !p_sd->state.autotrade)
  8051. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  8052. else
  8053. p.name[0] = 0;
  8054. } else {// Send zero-length name if no partner, to initialize the client buffer.
  8055. p.name[0] = 0;
  8056. }
  8057. clif_send(&p, sizeof(p), &sd.bl, AREA);
  8058. }
  8059. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  8060. /// 01e4
  8061. /// This packet while still implemented by the client is no longer being officially used.
  8062. /*
  8063. void clif_marriage_process(map_session_data *sd)
  8064. {
  8065. int fd;
  8066. nullpo_retv(sd);
  8067. fd=sd->fd;
  8068. WFIFOHEAD(fd,packet_len(0x1e4));
  8069. WFIFOW(fd,0)=0x1e4;
  8070. WFIFOSET(fd,packet_len(0x1e4));
  8071. }
  8072. */
  8073. /// Notice of divorce (ZC_DIVORCE).
  8074. /// 0205 <partner name>.24B
  8075. void clif_divorced(map_session_data* sd, const char* name)
  8076. {
  8077. int fd;
  8078. nullpo_retv(sd);
  8079. fd=sd->fd;
  8080. WFIFOHEAD(fd,packet_len(0x205));
  8081. WFIFOW(fd,0)=0x205;
  8082. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8083. WFIFOSET(fd, packet_len(0x205));
  8084. }
  8085. /// Marriage proposal (ZC_REQ_COUPLE).
  8086. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8087. /// This packet while still implemented by the client is no longer being officially used.
  8088. /*
  8089. void clif_marriage_proposal(int fd, map_session_data *sd, map_session_data* ssd)
  8090. {
  8091. nullpo_retv(sd);
  8092. WFIFOHEAD(fd,packet_len(0x1e2));
  8093. WFIFOW(fd,0) = 0x1e2;
  8094. WFIFOL(fd,2) = ssd->status.account_id;
  8095. WFIFOL(fd,6) = ssd->status.char_id;
  8096. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8097. WFIFOSET(fd, packet_len(0x1e2));
  8098. }
  8099. */
  8100. /*==========================================
  8101. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8102. *------------------------------------------*/
  8103. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8104. {
  8105. unsigned char buf[256];
  8106. if( len == 0 ) {
  8107. return;
  8108. } else if( len > sizeof(buf)-5 ) {
  8109. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8110. len = sizeof(buf)-5;
  8111. }
  8112. WBUFW(buf, 0) = 0x17f;
  8113. WBUFW(buf, 2) = len + 5;
  8114. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8115. clif_send(buf, WBUFW(buf,2), src, target);
  8116. }
  8117. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8118. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8119. /// 00cd <result>.B
  8120. /// result:
  8121. /// 0 = failure
  8122. /// 1 = success
  8123. void clif_GM_kickack(map_session_data *sd, int id)
  8124. {
  8125. int fd;
  8126. nullpo_retv(sd);
  8127. fd = sd->fd;
  8128. WFIFOHEAD(fd,packet_len(0xcd));
  8129. WFIFOW(fd,0) = 0xcd;
  8130. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8131. WFIFOSET(fd, packet_len(0xcd));
  8132. }
  8133. void clif_GM_kick(map_session_data *sd, map_session_data *tsd)
  8134. {
  8135. nullpo_retv(tsd);
  8136. if (sd == NULL)
  8137. tsd->state.keepshop = true;
  8138. if (session_isActive(tsd->fd))
  8139. clif_authfail_fd(tsd->fd, 15);
  8140. else
  8141. map_quit(tsd);
  8142. if (sd)
  8143. clif_GM_kickack(sd, tsd->status.account_id);
  8144. }
  8145. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8146. /// 014a <result>.L
  8147. /// result:
  8148. /// 0 = "A manner point has been successfully aligned."
  8149. /// 1 = MP_FAILURE_EXHAUST
  8150. /// 2 = MP_FAILURE_ALREADY_GIVING
  8151. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8152. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8153. /// 5 = "You got a good point from %s."
  8154. void clif_manner_message(map_session_data* sd, uint32 type)
  8155. {
  8156. int fd;
  8157. nullpo_retv(sd);
  8158. fd = sd->fd;
  8159. WFIFOHEAD(fd,packet_len(0x14a));
  8160. WFIFOW(fd,0) = 0x14a;
  8161. WFIFOL(fd,2) = type;
  8162. WFIFOSET(fd, packet_len(0x14a));
  8163. }
  8164. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8165. /// 014b <type>.B <GM name>.24B
  8166. /// type:
  8167. /// 0 = positive (unmute)
  8168. /// 1 = negative (mute)
  8169. void clif_GM_silence(map_session_data* sd, map_session_data* tsd, uint8 type)
  8170. {
  8171. int fd;
  8172. nullpo_retv(sd);
  8173. nullpo_retv(tsd);
  8174. fd = tsd->fd;
  8175. WFIFOHEAD(fd,packet_len(0x14b));
  8176. WFIFOW(fd,0) = 0x14b;
  8177. WFIFOB(fd,2) = type;
  8178. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8179. WFIFOSET(fd, packet_len(0x14b));
  8180. }
  8181. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8182. /// 00d1 <type>.B <result>.B
  8183. /// type:
  8184. /// 0 = /ex (deny)
  8185. /// 1 = /in (allow)
  8186. /// result:
  8187. /// 0 = success
  8188. /// 1 = failure
  8189. /// 2 = too many blocks
  8190. void clif_wisexin(map_session_data *sd,int type,int flag)
  8191. {
  8192. int fd;
  8193. nullpo_retv(sd);
  8194. fd=sd->fd;
  8195. WFIFOHEAD(fd,packet_len(0xd1));
  8196. WFIFOW(fd,0)=0xd1;
  8197. WFIFOB(fd,2)=type;
  8198. WFIFOB(fd,3)=flag;
  8199. WFIFOSET(fd,packet_len(0xd1));
  8200. }
  8201. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8202. /// 00d2 <type>.B <result>.B
  8203. /// type:
  8204. /// 0 = /exall (deny)
  8205. /// 1 = /inall (allow)
  8206. /// result:
  8207. /// 0 = success
  8208. /// 1 = failure
  8209. void clif_wisall(map_session_data *sd,int type,int flag)
  8210. {
  8211. int fd;
  8212. nullpo_retv(sd);
  8213. fd=sd->fd;
  8214. WFIFOHEAD(fd,packet_len(0xd2));
  8215. WFIFOW(fd,0)=0xd2;
  8216. WFIFOB(fd,2)=type;
  8217. WFIFOB(fd,3)=flag;
  8218. WFIFOSET(fd,packet_len(0xd2));
  8219. }
  8220. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8221. /// 07fe <bgm>.24B
  8222. void clif_playBGM( map_session_data& sd, const char* name ){
  8223. #if PACKETVER_MAIN_NUM >= 20220504
  8224. struct PACKET_ZC_PLAY_NPC_BGM* p = (struct PACKET_ZC_PLAY_NPC_BGM*)packet_buffer;
  8225. int16 length = (int16)( strlen( name ) + 1 );
  8226. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8227. p->PacketLength = sizeof( *p ) + length;
  8228. p->playType = 0; // TODO: implement, send loop for the time being
  8229. safestrncpy( p->bgm, name, length );
  8230. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8231. #elif PACKETVER >= 20091201
  8232. struct PACKET_ZC_PLAY_NPC_BGM p = {};
  8233. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8234. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8235. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8236. #endif
  8237. }
  8238. /// Plays/stops a wave sound (ZC_SOUND).
  8239. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8240. /// file name:
  8241. /// relative to data\wav
  8242. /// act:
  8243. /// 0 = play (once)
  8244. /// 1 = play (repeat, does not work)
  8245. /// 2 = stops all sound instances of file name (does not work)
  8246. /// term:
  8247. /// unknown purpose, only relevant to act = 1
  8248. /// npc id:
  8249. /// The accustic direction of the sound is determined by the
  8250. /// relative position of the NPC to the player (3D sound).
  8251. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8252. struct PACKET_ZC_SOUND p = {};
  8253. p.PacketType = HEADER_ZC_SOUND;
  8254. safestrncpy( p.name, name, sizeof( p.name ) );
  8255. p.act = type;
  8256. p.term = 0; // TODO: implement
  8257. p.AID = bl.id;
  8258. clif_send( &p, sizeof( p ), &bl, target );
  8259. }
  8260. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8261. /// 01f3 <id>.L <effect id>.L
  8262. /// effect id:
  8263. /// @see doc/effect_list.txt
  8264. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8265. {
  8266. unsigned char buf[24];
  8267. nullpo_retv(bl);
  8268. memset(buf, 0, packet_len(0x1f3));
  8269. WBUFW(buf,0) = 0x1f3;
  8270. WBUFL(buf,2) = bl->id;
  8271. WBUFL(buf,6) = type;
  8272. clif_send(buf, packet_len(0x1f3), bl, target);
  8273. if (disguised(bl)) {
  8274. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8275. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8276. }
  8277. }
  8278. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8279. {
  8280. WFIFOHEAD(fd,10);
  8281. WFIFOW(fd,0) = 0x1f3;
  8282. WFIFOL(fd,2) = bl->id;
  8283. WFIFOL(fd,6) = type;
  8284. WFIFOSET(fd,10);
  8285. }
  8286. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8287. /// 0284 <id>.L <effect id>.L <num data>.L
  8288. /// effect id:
  8289. /// @see doc/effect_list.txt
  8290. /// num data:
  8291. /// effect-dependent value
  8292. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8293. {
  8294. uint8 buf[14];
  8295. WBUFW(buf,0) = 0x284;
  8296. WBUFL(buf,2) = bl->id;
  8297. WBUFL(buf,6) = effect_id;
  8298. WBUFL(buf,10) = num;
  8299. clif_send(buf, packet_len(0x284), bl, target);
  8300. if( disguised(bl) )
  8301. {
  8302. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8303. clif_send(buf, packet_len(0x284), bl, SELF);
  8304. }
  8305. }
  8306. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8307. {
  8308. #if PACKETVER >= 20181002
  8309. nullpo_retv( bl_src );
  8310. nullpo_retv( bl_target );
  8311. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8312. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8313. p.aid = bl_src->id;
  8314. p.effectId = effect;
  8315. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8316. if( disguised(bl_src) )
  8317. {
  8318. p.aid = disguised_bl_id( bl_src->id );
  8319. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8320. }
  8321. #endif
  8322. }
  8323. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8324. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8325. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, map_session_data *sd) {
  8326. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8327. uint8 buf[CHAT_SIZE_MAX];
  8328. nullpo_retv(bl);
  8329. if (msg_len > sizeof(buf) - 12) {
  8330. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8331. msg_len = sizeof(buf) - 12;
  8332. }
  8333. if (rgb2bgr)
  8334. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8335. WBUFW(buf,0) = 0x2C1;
  8336. WBUFW(buf,2) = msg_len + 12;
  8337. WBUFL(buf,4) = bl->id;
  8338. WBUFL(buf,8) = color;
  8339. memcpy(WBUFCP(buf,12), msg, msg_len);
  8340. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8341. }
  8342. /**
  8343. * Notifies the client that the storage window is still open
  8344. *
  8345. * Should only be used in cases where the client closed the
  8346. * storage window without server's consent
  8347. */
  8348. void clif_refresh_storagewindow(map_session_data *sd) {
  8349. // Notify the client that the storage is open
  8350. if( sd->state.storage_flag == 1 ) {
  8351. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8352. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8353. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8354. }
  8355. // Notify the client that the gstorage is open otherwise it will
  8356. // remain locked forever and nobody will be able to access it
  8357. if( sd->state.storage_flag == 2 ) {
  8358. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8359. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8360. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8361. else {
  8362. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8363. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8364. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8365. }
  8366. }
  8367. // Notify the client that the premium storage is open
  8368. if (sd->state.storage_flag == 3) {
  8369. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8370. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8371. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8372. }
  8373. }
  8374. // refresh the client's screen, getting rid of any effects
  8375. void clif_refresh(map_session_data *sd)
  8376. {
  8377. nullpo_retv(sd);
  8378. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8379. clif_inventorylist(sd);
  8380. clif_equipswitch_list(sd);
  8381. if(pc_iscarton(sd)) {
  8382. clif_cartlist(sd);
  8383. clif_updatestatus(sd,SP_CARTINFO);
  8384. }
  8385. clif_updatestatus(sd,SP_WEIGHT);
  8386. clif_updatestatus(sd,SP_MAXWEIGHT);
  8387. clif_updatestatus(sd,SP_STR);
  8388. clif_updatestatus(sd,SP_AGI);
  8389. clif_updatestatus(sd,SP_VIT);
  8390. clif_updatestatus(sd,SP_INT);
  8391. clif_updatestatus(sd,SP_DEX);
  8392. clif_updatestatus(sd,SP_LUK);
  8393. #ifdef RENEWAL
  8394. clif_updatestatus(sd,SP_POW);
  8395. clif_updatestatus(sd,SP_STA);
  8396. clif_updatestatus(sd,SP_WIS);
  8397. clif_updatestatus(sd,SP_SPL);
  8398. clif_updatestatus(sd,SP_CON);
  8399. clif_updatestatus(sd,SP_CRT);
  8400. #endif
  8401. if (sd->spiritball)
  8402. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8403. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  8404. clif_millenniumshield_single(sd->fd, sd);
  8405. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8406. clif_spiritcharm_single(sd->fd, sd);
  8407. if (sd->soulball)
  8408. clif_soulball( sd, &sd->bl, SELF );
  8409. if (sd->servantball)
  8410. clif_servantball( *sd, &sd->bl, SELF );
  8411. if (sd->abyssball)
  8412. clif_abyssball( *sd, &sd->bl, SELF );
  8413. if (sd->vd.cloth_color)
  8414. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8415. if (sd->vd.body_style)
  8416. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8417. if(hom_is_active(sd->hd))
  8418. clif_send_homdata(sd,SP_ACK,0);
  8419. if( sd->md ) {
  8420. clif_mercenary_info(sd);
  8421. clif_mercenary_skillblock(sd);
  8422. }
  8423. if( sd->ed )
  8424. clif_elemental_info(sd);
  8425. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8426. clif_weather_check(sd);
  8427. if( sd->chatID )
  8428. chat_leavechat(sd,0);
  8429. if( sd->state.vending )
  8430. clif_openvending(sd, sd->bl.id, sd->vending);
  8431. if( pc_issit(sd) )
  8432. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8433. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8434. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8435. else
  8436. clif_changed_dir(&sd->bl, SELF);
  8437. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8438. //Issue #2143
  8439. //Cancel Trading State
  8440. if (sd->state.trading)
  8441. trade_tradecancel(sd);
  8442. //Cancel Buying/Selling State
  8443. if (sd->state.buyingstore)
  8444. buyingstore_close(sd);
  8445. mail_clear(sd);
  8446. clif_loadConfirm( sd );
  8447. if( disguised(&sd->bl) ) {/* refresh-da */
  8448. short disguise = sd->disguise;
  8449. pc_disguise(sd, 0);
  8450. pc_disguise(sd, disguise);
  8451. }
  8452. clif_refresh_storagewindow(sd);
  8453. }
  8454. /// Updates the object's (bl) name on client.
  8455. /// Used to update when a char leaves a party/guild. [Skotlex]
  8456. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8457. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8458. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8459. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8460. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8461. nullpo_retv( src );
  8462. nullpo_retv( bl );
  8463. switch( bl->type ){
  8464. case BL_PC: {
  8465. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8466. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8467. packet.gid = bl->id;
  8468. map_session_data *sd = (map_session_data *)bl;
  8469. //Requesting your own "shadow" name. [Skotlex]
  8470. if( src == bl && target == SELF && sd->disguise ){
  8471. packet.gid = -bl->id;
  8472. }
  8473. if( sd->fakename[0] ) {
  8474. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8475. clif_send( &packet, sizeof(packet), src, target );
  8476. return;
  8477. }
  8478. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8479. party_data *p = nullptr;
  8480. if( sd->status.party_id ){
  8481. p = party_search( sd->status.party_id );
  8482. }
  8483. // do not display party unless the player is also in a guild
  8484. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8485. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8486. }
  8487. if( sd->guild ){
  8488. int position;
  8489. // Will get the position of the guild the player is in
  8490. position = guild_getposition(*sd);
  8491. safestrncpy( packet.guild_name, sd->guild->guild.name, NAME_LENGTH );
  8492. safestrncpy( packet.position_name, sd->guild->guild.position[position].name, NAME_LENGTH );
  8493. }else if( sd->clan ){
  8494. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8495. }
  8496. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8497. packet.title_id = sd->status.title_id; // Title ID
  8498. #endif
  8499. clif_send(&packet, sizeof(packet), src, target);
  8500. }
  8501. break;
  8502. //[blackhole89]
  8503. case BL_HOM:
  8504. case BL_MER:
  8505. case BL_PET:
  8506. case BL_NPC:
  8507. case BL_ELEM: {
  8508. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8509. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8510. packet.gid = bl->id;
  8511. switch (bl->type) {
  8512. case BL_HOM:
  8513. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8514. break;
  8515. case BL_MER:
  8516. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8517. break;
  8518. case BL_PET:
  8519. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8520. break;
  8521. case BL_NPC:
  8522. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8523. break;
  8524. case BL_ELEM:
  8525. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8526. break;
  8527. }
  8528. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8529. unit_data *ud = unit_bl2ud(bl);
  8530. if (ud != nullptr) {
  8531. memcpy(packet.title, ud->title, NAME_LENGTH);
  8532. packet.groupId = ud->group_id;
  8533. }
  8534. #endif
  8535. clif_send(&packet, sizeof(packet), src, target);
  8536. }
  8537. break;
  8538. case BL_MOB: {
  8539. mob_data *md = (mob_data *)bl;
  8540. if( md->guardian_data && md->guardian_data->guild_id ){
  8541. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8542. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8543. packet.gid = bl->id;
  8544. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8545. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8546. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8547. clif_send(&packet, sizeof(packet), src, target);
  8548. }else if( battle_config.show_mob_info ){
  8549. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8550. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8551. packet.gid = bl->id;
  8552. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8553. char mobhp[50], *str_p = mobhp;
  8554. if( battle_config.show_mob_info&4 ){
  8555. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8556. }
  8557. if( battle_config.show_mob_info&1 ){
  8558. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8559. }
  8560. if( battle_config.show_mob_info&2 ){
  8561. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8562. }
  8563. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8564. if( str_p != mobhp ){
  8565. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8566. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8567. }
  8568. clif_send(&packet, sizeof(packet), src, target);
  8569. } else {
  8570. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8571. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8572. packet.gid = bl->id;
  8573. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8574. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8575. unit_data *ud = unit_bl2ud(bl);
  8576. if (ud != nullptr) {
  8577. memcpy(packet.title, ud->title, NAME_LENGTH);
  8578. packet.groupId = ud->group_id;
  8579. }
  8580. #endif
  8581. clif_send(&packet, sizeof(packet), src, target);
  8582. }
  8583. }
  8584. break;
  8585. case BL_CHAT:
  8586. case BL_SKILL:
  8587. // Newer clients request this, but do not need an answer
  8588. return;
  8589. default:
  8590. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8591. return;
  8592. }
  8593. }
  8594. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8595. /// 01ff <id>.L <x>.W <y>.W
  8596. ///
  8597. /// Visually moves(instant) a character to x,y. The char moves even
  8598. /// when the target cell isn't walkable. If the char is sitting it
  8599. /// stays that way.
  8600. void clif_slide(struct block_list *bl, int x, int y)
  8601. {
  8602. unsigned char buf[10];
  8603. nullpo_retv(bl);
  8604. WBUFW(buf, 0) = 0x01ff;
  8605. WBUFL(buf, 2) = bl->id;
  8606. WBUFW(buf, 6) = x;
  8607. WBUFW(buf, 8) = y;
  8608. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8609. if( disguised(bl) )
  8610. {
  8611. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8612. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8613. }
  8614. }
  8615. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8616. /// 008d <packet len>.W <id>.L <message>.?B
  8617. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8618. {
  8619. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8620. int len_mes = strlen(mes)+1; //Account for \0
  8621. if (len_mes > sizeof(buf)-8) {
  8622. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8623. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8624. }
  8625. // send message to others
  8626. if (flag == AREA) {
  8627. WBUFW(buf,0) = 0x8d;
  8628. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8629. WBUFL(buf,4) = bl->id;
  8630. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8631. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8632. }
  8633. // send back message to the speaker
  8634. if( bl->type == BL_PC ) {
  8635. WBUFW(buf,0) = 0x8e;
  8636. WBUFW(buf, 2) = len_mes + 4;
  8637. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8638. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8639. }
  8640. }
  8641. /*==========================
  8642. * Minimap fix [Kevin]
  8643. * Remove dot from minimap
  8644. *--------------------------*/
  8645. void clif_party_xy_remove(map_session_data* sd)
  8646. {
  8647. nullpo_retv(sd);
  8648. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8649. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8650. p.AID = sd->status.account_id;
  8651. p.xPos = -1;
  8652. p.yPos = -1;
  8653. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8654. }
  8655. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8656. /// 0215 <msg id>.L
  8657. /// msg id:
  8658. /// 0x15 = End all negative status (PA_GOSPEL)
  8659. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8660. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8661. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8662. /// 0x19 = All stats +20 (PA_GOSPEL)
  8663. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8664. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8665. /// 0x1e = DEF +25% (PA_GOSPEL)
  8666. /// 0x1f = ATK +100% (PA_GOSPEL)
  8667. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8668. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8669. /// ? = nothing
  8670. void clif_gospel_info(map_session_data *sd, int type)
  8671. {
  8672. int fd=sd->fd;
  8673. WFIFOHEAD(fd,packet_len(0x215));
  8674. WFIFOW(fd,0)=0x215;
  8675. WFIFOL(fd,2)=type;
  8676. WFIFOSET(fd, packet_len(0x215));
  8677. }
  8678. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8679. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8680. /// result:
  8681. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8682. /// star:
  8683. /// 0 = Place of the Sun
  8684. /// 1 = Place of the Moon
  8685. /// 2 = Place of the Stars
  8686. /// 1 = Star Gladiator %s's %s: <mapname>
  8687. /// star:
  8688. /// 0 = Place of the Sun
  8689. /// 1 = Place of the Moon
  8690. /// 2 = Place of the Stars
  8691. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8692. /// star:
  8693. /// 0 = Target of the Sun
  8694. /// 1 = Target of the Moon
  8695. /// 2 = Target of the Stars
  8696. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8697. /// star:
  8698. /// 0 = Monster of the Sun
  8699. /// 1 = Monster of the Moon
  8700. /// 2 = Monster of the Stars
  8701. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8702. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8703. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8704. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8705. /// 40 = Target HP : <monster_id used as HP>
  8706. void clif_starskill(map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8707. {
  8708. int fd = sd->fd;
  8709. WFIFOHEAD(fd,packet_len(0x20e));
  8710. WFIFOW(fd,0) = 0x20e;
  8711. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8712. WFIFOL(fd,26) = monster_id;
  8713. WFIFOB(fd,30) = star;
  8714. WFIFOB(fd,31) = result;
  8715. WFIFOSET(fd,packet_len(0x20e));
  8716. }
  8717. /*==========================================
  8718. * Info about Star Glaldiator save map [Komurka]
  8719. * type: 1: Information, 0: Map registered
  8720. *------------------------------------------*/
  8721. void clif_feel_info(map_session_data* sd, unsigned char feel_level, unsigned char type)
  8722. {
  8723. char mapname[MAP_NAME_LENGTH_EXT];
  8724. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8725. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8726. }
  8727. /*==========================================
  8728. * Info about Star Glaldiator hate mob [Komurka]
  8729. * type: 1: Register mob, 0: Information.
  8730. *------------------------------------------*/
  8731. void clif_hate_info(map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8732. {
  8733. if( pcdb_checkid(class_) ) {
  8734. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8735. } else if( mobdb_checkid(class_) ) {
  8736. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8737. } else {
  8738. 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);
  8739. }
  8740. }
  8741. /*==========================================
  8742. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8743. *------------------------------------------*/
  8744. void clif_mission_info(map_session_data *sd, int mob_id, unsigned char progress)
  8745. {
  8746. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8747. }
  8748. /*==========================================
  8749. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8750. *------------------------------------------*/
  8751. void clif_feel_hate_reset(map_session_data *sd)
  8752. {
  8753. clif_starskill(sd, "", 0, 0, 30);
  8754. }
  8755. /// Send out reply to configuration change
  8756. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8757. /// type: see enum e_config_type
  8758. /// value:
  8759. /// false = disabled
  8760. /// true = enabled
  8761. void clif_configuration( map_session_data* sd, enum e_config_type type, bool enabled ){
  8762. int fd;
  8763. nullpo_retv(sd);
  8764. fd = sd->fd;
  8765. WFIFOHEAD(fd, packet_len(0x2d9));
  8766. WFIFOW(fd, 0) = 0x2d9;
  8767. WFIFOL(fd, 2) = type;
  8768. WFIFOL(fd, 6) = enabled;
  8769. WFIFOSET(fd, packet_len(0x2d9));
  8770. }
  8771. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8772. /// 02da <open equip window>.B
  8773. /// open equip window:
  8774. /// 0 = disabled
  8775. /// 1 = enabled
  8776. void clif_equipcheckbox(map_session_data* sd)
  8777. {
  8778. int fd;
  8779. nullpo_retv(sd);
  8780. fd = sd->fd;
  8781. WFIFOHEAD(fd, packet_len(0x2da));
  8782. WFIFOW(fd, 0) = 0x2da;
  8783. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8784. WFIFOSET(fd, packet_len(0x2da));
  8785. }
  8786. /// Sends info about a player's equipped items.
  8787. /// 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)
  8788. /// 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)
  8789. /// 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)
  8790. /// 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)
  8791. /// 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)
  8792. /// 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)
  8793. void clif_viewequip_ack( map_session_data* sd, map_session_data* tsd ){
  8794. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8795. nullpo_retv( sd );
  8796. nullpo_retv( tsd );
  8797. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8798. int equip = 0;
  8799. for( int i = 0; i < EQI_MAX; i++ ){
  8800. int k = tsd->equip_index[i];
  8801. if( k >= 0 ){
  8802. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8803. continue;
  8804. }
  8805. if( !tsd->inventory.u.items_inventory[k].equip ){
  8806. continue;
  8807. }
  8808. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8809. continue;
  8810. }
  8811. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8812. }
  8813. }
  8814. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8815. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8816. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8817. p->job = tsd->status.class_;
  8818. p->head = tsd->vd.hair_style;
  8819. p->accessory = tsd->vd.head_bottom;
  8820. p->accessory2 = tsd->vd.head_mid;
  8821. p->accessory3 = tsd->vd.head_top;
  8822. #if PACKETVER >= 20110111
  8823. p->robe = tsd->vd.robe;
  8824. #endif
  8825. p->headpalette = tsd->vd.hair_color;
  8826. p->bodypalette = tsd->vd.cloth_color;
  8827. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8828. p->body2 = tsd->vd.body_style;
  8829. #endif
  8830. p->sex = tsd->vd.sex;
  8831. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8832. #endif
  8833. }
  8834. /// Display msgstringtable.txt string (ZC_MSG).
  8835. /// 0291 <message>.W
  8836. void clif_msg(map_session_data* sd, unsigned short id)
  8837. {
  8838. int fd;
  8839. nullpo_retv(sd);
  8840. fd = sd->fd;
  8841. WFIFOHEAD(fd, packet_len(0x291));
  8842. WFIFOW(fd, 0) = 0x291;
  8843. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8844. WFIFOSET(fd, packet_len(0x291));
  8845. }
  8846. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8847. /// 0x7e2 <message>.W <value>.L
  8848. void clif_msg_value(map_session_data* sd, unsigned short id, int value)
  8849. {
  8850. int fd = sd->fd;
  8851. WFIFOHEAD(fd, packet_len(0x7e2));
  8852. WFIFOW(fd,0) = 0x7e2;
  8853. WFIFOW(fd,2) = id;
  8854. WFIFOL(fd,4) = value;
  8855. WFIFOSET(fd, packet_len(0x7e2));
  8856. }
  8857. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8858. /// 07e6 <skill id>.W <msg id>.L
  8859. ///
  8860. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8861. /// "[SkillName] Message"
  8862. void clif_msg_skill(map_session_data* sd, uint16 skill_id, int msg_id)
  8863. {
  8864. int fd = sd->fd;
  8865. WFIFOHEAD(fd, packet_len(0x7e6));
  8866. WFIFOW(fd,0) = 0x7e6;
  8867. WFIFOW(fd,2) = skill_id;
  8868. WFIFOL(fd,4) = msg_id;
  8869. WFIFOSET(fd, packet_len(0x7e6));
  8870. }
  8871. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8872. /// 09cd <msg id>.W <color>.L
  8873. void clif_msg_color( map_session_data *sd, uint16 msg_id, uint32 color ){
  8874. nullpo_retv(sd);
  8875. int fd = sd->fd;
  8876. WFIFOHEAD(fd, packet_len(0x9cd));
  8877. WFIFOW(fd, 0) = 0x9cd;
  8878. WFIFOW(fd, 2) = msg_id;
  8879. WFIFOL(fd, 4) = color;
  8880. WFIFOSET(fd, packet_len(0x9cd));
  8881. }
  8882. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8883. /// Returns true if the packet was parsed successfully.
  8884. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8885. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8886. static bool clif_process_message(map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8887. const char* seperator = " : ";
  8888. int fd;
  8889. struct s_packet_db* info;
  8890. uint16 packetLength, inputLength;
  8891. const char *input, *name, *message;
  8892. size_t nameLength, messageLength;
  8893. fd = sd->fd;
  8894. info = &packet_db[RFIFOW(fd,0)];
  8895. packetLength = RFIFOW(fd,info->pos[0]);
  8896. input = RFIFOCP(fd,info->pos[1]);
  8897. // basic structure check for the 4-byte header
  8898. if( packetLength < 4 ){
  8899. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8900. return false;
  8901. }else{
  8902. inputLength = packetLength - 4;
  8903. }
  8904. // process <name> part of the packet
  8905. if( whisperFormat ) {
  8906. // name has fixed width
  8907. if( inputLength < NAME_LENGTH + 1 ) {
  8908. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8909. return false;
  8910. }
  8911. name = input;
  8912. // validate name
  8913. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8914. // only restriction is that the name must be zero-terminated
  8915. if( name[nameLength] != '\0' ) {
  8916. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8917. return false;
  8918. }
  8919. message = input + NAME_LENGTH;
  8920. messageLength = inputLength - NAME_LENGTH;
  8921. }else{
  8922. // name and message are separated by ' : '
  8923. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8924. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8925. // check if there's enough data provided
  8926. if( inputLength < nameLength + seperatorLength + 1 ){
  8927. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8928. return false;
  8929. }
  8930. name = input;
  8931. // validate name
  8932. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8933. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8934. {
  8935. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8936. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8937. set_eof(sd->fd); // Just kick them out to correct it.
  8938. return false;
  8939. }
  8940. message = input + nameLength + seperatorLength;
  8941. messageLength = inputLength - nameLength - seperatorLength;
  8942. }
  8943. #if PACKETVER < 20151001
  8944. // the declared length must match real length
  8945. if( messageLength != strnlen(message, messageLength)+1 ) {
  8946. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8947. return false;
  8948. }
  8949. // verify <message> part of the packet
  8950. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8951. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8952. return false;
  8953. }
  8954. #else
  8955. // No zero termination anymore
  8956. messageLength += 1;
  8957. #endif
  8958. // messages mustn't be too long
  8959. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8960. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8961. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8962. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8963. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8964. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8965. return false;
  8966. }
  8967. // If it is not a whisper message, set the name to the fakename of the player
  8968. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8969. strcpy( out_name, sd->fakename );
  8970. }else{
  8971. safestrncpy( out_name, name, nameLength + 1 );
  8972. }
  8973. safestrncpy( out_message, message, messageLength );
  8974. if( whisperFormat ){
  8975. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8976. out_full_message[nameLength] = '\0';
  8977. }else{
  8978. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8979. }
  8980. if( is_atcommand( fd, sd, out_message, 1 ) )
  8981. return false;
  8982. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8983. return false; //no "chatting" while muted.
  8984. if( battle_config.min_chat_delay ) { //[Skotlex]
  8985. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8986. return false;
  8987. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8988. }
  8989. if (battle_config.idletime_option&IDLE_CHAT)
  8990. sd->idletime = last_tick;
  8991. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8992. sd->idletime_hom = last_tick;
  8993. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8994. sd->idletime_mer = last_tick;
  8995. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8996. return true;
  8997. }
  8998. /**
  8999. * Displays a message if the player enters a PK Zone (during pk_mode)
  9000. * @param sd: Player data
  9001. */
  9002. inline void clif_pk_mode_message(map_session_data * sd)
  9003. {
  9004. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  9005. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  9006. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  9007. char output[CHAT_SIZE_MAX];
  9008. // 1504: You've entered a PK Zone (safe until level %d).
  9009. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  9010. battle_config.pk_min_level);
  9011. clif_showscript(&sd->bl, output, SELF);
  9012. } else {
  9013. // 1503: You've entered a PK Zone.
  9014. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  9015. }
  9016. }
  9017. return;
  9018. }
  9019. // ---------------------
  9020. // clif_parse_wanttoconnect
  9021. // ---------------------
  9022. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  9023. // error codes:
  9024. // 0 - Success
  9025. // 1 - Unknown packet_ver
  9026. // 2 - Invalid account_id
  9027. // 3 - Invalid char_id
  9028. // 4 - Invalid login_id1 (reserved)
  9029. // 5 - Invalid client_tick (reserved)
  9030. // 6 - Invalid sex
  9031. // Only the first 'invalid' error that appears is used.
  9032. static int clif_parse_WantToConnection_sub(int fd)
  9033. {
  9034. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  9035. unsigned short cmd;
  9036. //By default, start searching on the default one.
  9037. cmd = RFIFOW(fd, 0);
  9038. packet_len = RFIFOREST(fd);
  9039. // FIXME: If the packet is not received at once, this will FAIL.
  9040. // Figure out, when it happens, that only part of the packet is
  9041. // received, or fix the function to be able to deal with that
  9042. // case.
  9043. if( packet_len != packet_db[cmd].len )
  9044. return 1; /* wrong length */
  9045. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  9046. return 2; /* invalid account_id */
  9047. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  9048. return 3; /* invalid char_id */
  9049. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  9050. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  9051. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  9052. return 6; /* invalid sex */
  9053. else
  9054. return 0;
  9055. }
  9056. /// Request to connect to map-server.
  9057. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  9058. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  9059. /// There are various variants of this packet, some of them have padding between fields.
  9060. void clif_parse_WantToConnection(int fd, map_session_data* sd)
  9061. {
  9062. struct block_list* bl;
  9063. struct auth_node* node;
  9064. int cmd, account_id, char_id, login_id1, sex, err;
  9065. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  9066. if (sd) {
  9067. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9068. return;
  9069. }
  9070. cmd = RFIFOW(fd, 0);
  9071. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9072. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9073. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9074. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9075. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9076. err = clif_parse_WantToConnection_sub(fd);
  9077. if( err ){ // connection rejected
  9078. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9079. err == 1 ? "." :
  9080. err == 2 ? ", possibly for having an invalid account_id." :
  9081. err == 3 ? ", possibly for having an invalid char_id." :
  9082. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9083. err == 4 ? ", possibly for having an invalid login_id1." :
  9084. err == 5 ? ", possibly for having an invalid client_tick." :
  9085. */
  9086. err == 6 ? ", possibly for having an invalid sex." :
  9087. ". ERROR invalid error code"));
  9088. WFIFOHEAD(fd,packet_len(0x6a));
  9089. WFIFOW(fd,0) = 0x6a;
  9090. WFIFOB(fd,2) = err;
  9091. WFIFOSET(fd,packet_len(0x6a));
  9092. #ifdef DUMP_INVALID_PACKET
  9093. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9094. #endif
  9095. RFIFOSKIP(fd, RFIFOREST(fd));
  9096. set_eof(fd);
  9097. return;
  9098. }
  9099. if( !global_core->is_running() ){ // not allowed
  9100. clif_authfail_fd(fd,1);// server closed
  9101. return;
  9102. }
  9103. //Check for double login.
  9104. bl = map_id2bl(account_id);
  9105. if(bl && bl->type != BL_PC) {
  9106. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9107. WFIFOHEAD(fd,packet_len(0x6a));
  9108. WFIFOW(fd,0) = 0x6a;
  9109. WFIFOB(fd,2) = 3; // Rejected by server
  9110. WFIFOSET(fd,packet_len(0x6a));
  9111. set_eof(fd);
  9112. return;
  9113. }
  9114. if (bl ||
  9115. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9116. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9117. {
  9118. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9119. return;
  9120. }
  9121. CREATE(sd, TBL_PC, 1);
  9122. new(sd) map_session_data();
  9123. sd->fd = fd;
  9124. #ifdef PACKET_OBFUSCATION
  9125. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9126. #endif
  9127. session[fd]->session_data = sd;
  9128. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9129. #if PACKETVER < 20070521
  9130. WFIFOHEAD(fd,4);
  9131. WFIFOL(fd,0) = sd->bl.id;
  9132. WFIFOSET(fd,4);
  9133. #else
  9134. WFIFOHEAD(fd,packet_len(0x283));
  9135. WFIFOW(fd,0) = 0x283;
  9136. WFIFOL(fd,2) = sd->bl.id;
  9137. WFIFOSET(fd,packet_len(0x283));
  9138. #endif
  9139. chrif_authreq(sd,false);
  9140. }
  9141. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9142. /// 007d
  9143. void clif_parse_LoadEndAck(int fd,map_session_data *sd)
  9144. {
  9145. bool guild_notice = false;
  9146. if(sd->bl.prev != NULL)
  9147. return;
  9148. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9149. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9150. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9151. sd->state.connect_new = 0;
  9152. return;
  9153. }
  9154. if (sd->state.rewarp) { //Rewarp player.
  9155. sd->state.rewarp = 0;
  9156. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9157. return;
  9158. }
  9159. sd->state.warping = 0;
  9160. // look
  9161. #if PACKETVER < 4
  9162. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9163. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9164. #else
  9165. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9166. #endif
  9167. pc_set_costume_view(sd);
  9168. if(sd->vd.cloth_color)
  9169. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9170. if(sd->vd.body_style)
  9171. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9172. // item
  9173. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9174. pc_checkitem(sd);
  9175. clif_equipswitch_list(sd);
  9176. // cart
  9177. if(pc_iscarton(sd)) {
  9178. clif_cartlist(sd);
  9179. clif_updatestatus(sd,SP_CARTINFO);
  9180. }
  9181. // weight
  9182. clif_updatestatus(sd,SP_WEIGHT);
  9183. clif_updatestatus(sd,SP_MAXWEIGHT);
  9184. // guild
  9185. // (needs to go before clif_spawn() to show guild emblems correctly)
  9186. if(sd->status.guild_id)
  9187. guild_send_memberinfoshort(sd,1);
  9188. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9189. if(battle_config.pc_invincible_time > 0) {
  9190. if(mapdata_flag_gvg(mapdata))
  9191. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9192. else
  9193. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9194. }
  9195. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9196. map_spawnmobs(sd->bl.m);
  9197. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9198. mapdata->users_pvp++;
  9199. }
  9200. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9201. // reset the callshop flag if the player changes map
  9202. sd->state.callshop = 0;
  9203. if(map_addblock(&sd->bl))
  9204. return;
  9205. clif_spawn(&sd->bl);
  9206. // Party
  9207. // (needs to go after clif_spawn() to show hp bars correctly)
  9208. if(sd->status.party_id) {
  9209. party_send_movemap(sd);
  9210. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9211. }
  9212. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9213. if(!pc_isinvisible(sd) && mapdata->getMapFlag(MF_PVP)) {
  9214. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9215. if (!mapdata->getMapFlag(MF_PVP_NOCALCRANK))
  9216. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9217. sd->pvp_rank = 0;
  9218. sd->pvp_lastusers = 0;
  9219. sd->pvp_point = 5;
  9220. sd->pvp_won = 0;
  9221. sd->pvp_lost = 0;
  9222. }
  9223. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9224. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9225. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9226. else if (mapdata->getMapFlag(MF_GVG_DUNGEON))
  9227. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9228. else if( mapdata_flag_gvg(mapdata) )
  9229. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9230. else
  9231. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9232. // info about nearby objects
  9233. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9234. 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);
  9235. // pet
  9236. if( sd->pd ) {
  9237. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9238. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9239. pet_return_egg( sd, sd->pd );
  9240. } else {
  9241. if(map_addblock(&sd->pd->bl))
  9242. return;
  9243. clif_spawn(&sd->pd->bl);
  9244. clif_send_petdata(sd,sd->pd,0,0);
  9245. clif_send_petstatus(sd);
  9246. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9247. }
  9248. }
  9249. //homunculus [blackhole89]
  9250. if( hom_is_active(sd->hd) ) {
  9251. if(map_addblock(&sd->hd->bl))
  9252. return;
  9253. clif_spawn(&sd->hd->bl);
  9254. clif_send_homdata(sd,SP_ACK,0);
  9255. clif_hominfo(sd,sd->hd,1);
  9256. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9257. clif_homskillinfoblock(sd);
  9258. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9259. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9260. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9261. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9262. }
  9263. if( sd->md ) {
  9264. if(map_addblock(&sd->md->bl))
  9265. return;
  9266. clif_spawn(&sd->md->bl);
  9267. clif_mercenary_info(sd);
  9268. clif_mercenary_skillblock(sd);
  9269. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9270. }
  9271. if( sd->ed ) {
  9272. if (map_addblock(&sd->ed->bl))
  9273. return;
  9274. clif_spawn(&sd->ed->bl);
  9275. clif_elemental_info(sd);
  9276. clif_elemental_updatestatus(sd,SP_HP);
  9277. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9278. clif_elemental_updatestatus(sd,SP_SP);
  9279. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9280. }
  9281. if(sd->state.connect_new) {
  9282. int lv;
  9283. guild_notice = true;
  9284. clif_skillinfoblock(sd);
  9285. clif_hotkeys_send(sd,0);
  9286. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9287. clif_hotkeys_send(sd,1);
  9288. #endif
  9289. clif_updatestatus(sd,SP_BASEEXP);
  9290. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9291. clif_updatestatus(sd,SP_JOBEXP);
  9292. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9293. clif_updatestatus(sd,SP_SKILLPOINT);
  9294. clif_initialstatus(sd);
  9295. if (sd->sc.option&OPTION_FALCON)
  9296. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9297. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9298. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9299. else if (sd->sc.option&OPTION_WUGRIDER)
  9300. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9301. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9302. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9303. if(sd->status.manner < 0)
  9304. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9305. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9306. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9307. if(sd->bl.m == sd->feel_map[0].m
  9308. || sd->bl.m == sd->feel_map[1].m
  9309. || sd->bl.m == sd->feel_map[2].m)
  9310. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9311. }
  9312. if(sd->pd && sd->pd->pet.intimate > 900)
  9313. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9314. if(hom_is_active(sd->hd))
  9315. hom_init_timers(sd->hd);
  9316. if (night_flag && mapdata->getMapFlag(MF_NIGHTENABLED)) {
  9317. sd->state.night = 1;
  9318. clif_status_load(&sd->bl, EFST_SKE, 1);
  9319. }
  9320. // Notify everyone that this char logged in [Skotlex].
  9321. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9322. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9323. //Login Event
  9324. npc_script_event(sd, NPCE_LOGIN);
  9325. }
  9326. // Set facing direction before check below to update client
  9327. if (battle_config.spawn_direction)
  9328. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9329. } else {
  9330. //For some reason the client "loses" these on warp/map-change.
  9331. clif_updatestatus(sd,SP_STR);
  9332. clif_updatestatus(sd,SP_AGI);
  9333. clif_updatestatus(sd,SP_VIT);
  9334. clif_updatestatus(sd,SP_INT);
  9335. clif_updatestatus(sd,SP_DEX);
  9336. clif_updatestatus(sd,SP_LUK);
  9337. #ifdef RENEWAL
  9338. clif_updatestatus(sd,SP_POW);
  9339. clif_updatestatus(sd,SP_STA);
  9340. clif_updatestatus(sd,SP_WIS);
  9341. clif_updatestatus(sd,SP_SPL);
  9342. clif_updatestatus(sd,SP_CON);
  9343. clif_updatestatus(sd,SP_CRT);
  9344. #endif
  9345. // abort currently running script
  9346. sd->state.using_fake_npc = 0;
  9347. sd->state.menu_or_input = 0;
  9348. sd->npc_menu = 0;
  9349. if(sd->npc_id)
  9350. npc_event_dequeue(sd);
  9351. }
  9352. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9353. clif_partyinvitationstate( *sd );
  9354. #if PACKETVER >= 20070918
  9355. clif_equipcheckbox(sd);
  9356. #endif
  9357. clif_pet_autofeed_status(sd,false);
  9358. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9359. #if PACKETVER >= 20170920
  9360. if( battle_config.homunculus_autofeed_always ){
  9361. // Always send ON or OFF
  9362. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9363. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9364. }else{
  9365. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9366. }
  9367. }else{
  9368. // Only send when enabled
  9369. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9370. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9371. }
  9372. }
  9373. #endif
  9374. clif_reputation_list( *sd );
  9375. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9376. clif_guild_notice(sd); // Displays after VIP
  9377. guild_notice = false; // Do not display it twice
  9378. }
  9379. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9380. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9381. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->getMapFlag(MF_BATTLEGROUND))) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->getMapFlag(MF_BATTLEGROUND))))
  9382. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9383. }
  9384. if( night_flag && mapdata->getMapFlag(MF_NIGHTENABLED) )
  9385. { //Display night.
  9386. if( !sd->state.night )
  9387. {
  9388. sd->state.night = 1;
  9389. clif_status_load(&sd->bl, EFST_SKE, 1);
  9390. }
  9391. }
  9392. else if( sd->state.night )
  9393. { //Clear night display.
  9394. sd->state.night = 0;
  9395. clif_status_load(&sd->bl, EFST_SKE, 0);
  9396. }
  9397. if( mapdata->getMapFlag(MF_BATTLEGROUND) )
  9398. {
  9399. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9400. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9401. clif_bg_updatescore_single(sd);
  9402. }
  9403. if( mapdata->getMapFlag(MF_ALLOWKS) && !mapdata_flag_ks(mapdata) )
  9404. {
  9405. char output[128];
  9406. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9407. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9408. }
  9409. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9410. mapdata->hpmeter_visible++;
  9411. sd->state.hpmeter_visible = 1;
  9412. }
  9413. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9414. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9415. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9416. #ifdef VIP_ENABLE
  9417. if (!sd->state.connect_new &&
  9418. !sd->vip.disableshowrate &&
  9419. sd->state.pmap != sd->bl.m &&
  9420. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->getMapFlag(MF_BEXP)
  9421. )
  9422. {
  9423. clif_display_pinfo( *sd );
  9424. }
  9425. #endif
  9426. // Instances do not need their own channels
  9427. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->getMapFlag(MF_NOMAPCHANNELAUTOJOIN) )
  9428. channel_mjoin(sd); //join new map
  9429. clif_pk_mode_message(sd);
  9430. }
  9431. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9432. clif_guild_notice(sd); // Displays at end
  9433. }
  9434. mail_clear(sd);
  9435. /* Guild Aura Init */
  9436. if( sd->guild && sd->state.gmaster_flag ) {
  9437. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP));
  9438. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS));
  9439. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD));
  9440. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES));
  9441. }
  9442. if( sd->state.vending ) { /* show we have a vending */
  9443. clif_openvending(sd,sd->bl.id,sd->vending);
  9444. clif_showvendingboard( *sd );
  9445. }
  9446. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9447. if(!sd->state.autotrade && mapdata->getMapFlag(MF_LOADEVENT)) // Lance
  9448. npc_script_event(sd, NPCE_LOADMAP);
  9449. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9450. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9451. if (sd->sc.opt2) //Client loses these on warp.
  9452. clif_changeoption(&sd->bl);
  9453. 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)) {
  9454. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9455. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9456. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9457. }
  9458. clif_weather_check(sd);
  9459. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9460. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9461. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9462. else
  9463. sd->areanpc.clear();
  9464. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9465. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9466. pc_setdead(sd);
  9467. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9468. if(pc_isdead(sd))
  9469. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9470. else {
  9471. skill_usave_trigger(sd);
  9472. if (battle_config.spawn_direction)
  9473. clif_changed_dir(&sd->bl, SELF);
  9474. }
  9475. // Trigger skill effects if you appear standing on them
  9476. if(!battle_config.pc_invincible_time)
  9477. skill_unit_move(&sd->bl,gettick(),1);
  9478. pc_show_questinfo_reinit(sd);
  9479. pc_show_questinfo(sd);
  9480. #if PACKETVER >= 20150513
  9481. if( sd->mail.inbox.unread ){
  9482. clif_Mail_new(sd, 0, NULL, NULL);
  9483. }
  9484. #endif
  9485. sd->state.connect_new = 0;
  9486. sd->state.changemap = false;
  9487. }
  9488. /// Server's tick (ZC_NOTIFY_TIME).
  9489. /// 007f <time>.L
  9490. void clif_notify_time(map_session_data* sd, t_tick time)
  9491. {
  9492. int fd = sd->fd;
  9493. WFIFOHEAD(fd,packet_len(0x7f));
  9494. WFIFOW(fd,0) = 0x7f;
  9495. WFIFOL(fd,2) = client_tick(time);
  9496. WFIFOSET(fd,packet_len(0x7f));
  9497. }
  9498. /// Request for server's tick.
  9499. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9500. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9501. /// There are various variants of this packet, some of them have padding between fields.
  9502. void clif_parse_TickSend(int fd, map_session_data *sd)
  9503. {
  9504. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9505. clif_notify_time(sd, gettick());
  9506. }
  9507. /// Sends hotkey bar.
  9508. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9509. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9510. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9511. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9512. void clif_hotkeys_send( map_session_data *sd, int tab ){
  9513. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9514. nullpo_retv( sd );
  9515. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9516. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9517. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9518. if( tab == 0 ){
  9519. p.rotate = sd->status.hotkey_rowshift;
  9520. }else{
  9521. p.rotate = sd->status.hotkey_rowshift2;
  9522. }
  9523. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9524. p.tab = tab;
  9525. #endif
  9526. #endif
  9527. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9528. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9529. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9530. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9531. }
  9532. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9533. #endif
  9534. }
  9535. /// Request to update a position on the hotkey row bar
  9536. void clif_parse_HotkeyRowShift( int fd, map_session_data *sd ){
  9537. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9538. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9539. if( p->tab == 0 ){
  9540. sd->status.hotkey_rowshift = p->rowshift;
  9541. }else{
  9542. sd->status.hotkey_rowshift2 = p->rowshift;
  9543. }
  9544. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9545. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9546. sd->status.hotkey_rowshift = p->rowshift;
  9547. #endif
  9548. }
  9549. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9550. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9551. void clif_parse_Hotkey(int fd, map_session_data *sd) {
  9552. #ifdef HOTKEY_SAVING
  9553. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9554. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9555. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9556. if( idx >= MAX_HOTKEYS_DB ){
  9557. return;
  9558. }
  9559. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9560. sd->status.hotkeys[idx].id = p->hotkey.id;
  9561. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9562. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9563. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9564. const unsigned short idx = p->index;
  9565. if( idx >= MAX_HOTKEYS_DB ){
  9566. return;
  9567. }
  9568. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9569. sd->status.hotkeys[idx].id = p->hotkey.id;
  9570. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9571. #endif
  9572. #endif
  9573. }
  9574. /// Displays cast-like progress bar (ZC_PROGRESS).
  9575. /// 02f0 <color>.L <time>.L
  9576. void clif_progressbar(map_session_data * sd, unsigned long color, unsigned int second)
  9577. {
  9578. int fd = sd->fd;
  9579. WFIFOHEAD(fd,packet_len(0x2f0));
  9580. WFIFOW(fd,0) = 0x2f0;
  9581. WFIFOL(fd,2) = color;
  9582. WFIFOL(fd,6) = second;
  9583. WFIFOSET(fd,packet_len(0x2f0));
  9584. }
  9585. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9586. /// 02f2
  9587. void clif_progressbar_abort(map_session_data * sd)
  9588. {
  9589. int fd = sd->fd;
  9590. WFIFOHEAD(fd,packet_len(0x2f2));
  9591. WFIFOW(fd,0) = 0x2f2;
  9592. WFIFOSET(fd,packet_len(0x2f2));
  9593. }
  9594. /// Notification from the client, that the progress bar has reached 100%.
  9595. /// 02f1 (CZ_PROGRESS)
  9596. void clif_parse_progressbar(int fd, map_session_data * sd){
  9597. // No progressbar active, ignore it
  9598. if( !sd->progressbar.npc_id ){
  9599. return;
  9600. }
  9601. int npc_id = sd->progressbar.npc_id;
  9602. bool closing = false;
  9603. // Check if the progress was canceled
  9604. if( gettick() < sd->progressbar.timeout && sd->st ){
  9605. closing = true;
  9606. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9607. // If a message window was open, offer a close button to the user
  9608. if( sd->st->mes_active ){
  9609. clif_scriptclose( sd, npc_id );
  9610. }
  9611. }
  9612. sd->progressbar.npc_id = 0;
  9613. sd->progressbar.timeout = 0;
  9614. sd->state.workinprogress = WIP_DISABLE_NONE;
  9615. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9616. sd->idletime = last_tick;
  9617. }
  9618. npc_scriptcont(sd, npc_id, closing);
  9619. }
  9620. /// Displays cast-like progress bar on a NPC
  9621. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9622. void clif_progressbar_npc( struct npc_data *nd, map_session_data* sd ){
  9623. #if PACKETVER >= 20130821
  9624. unsigned char buf[14];
  9625. if( nd->progressbar.timeout > 0 ){
  9626. WBUFW(buf,0) = 0x9d1;
  9627. WBUFL(buf,2) = nd->bl.id;
  9628. WBUFL(buf,6) = nd->progressbar.color;
  9629. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9630. if( sd ){
  9631. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9632. }else{
  9633. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9634. }
  9635. }
  9636. #endif
  9637. }
  9638. /// Request to walk to a certain position on the current map.
  9639. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9640. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9641. /// There are various variants of this packet, some of them have padding between fields.
  9642. void clif_parse_WalkToXY(int fd, map_session_data *sd)
  9643. {
  9644. short x, y;
  9645. if (pc_isdead(sd)) {
  9646. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9647. return;
  9648. }
  9649. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9650. ; //You CAN walk on this OPT1 value.
  9651. else if (sd->progressbar.npc_id) {
  9652. clif_progressbar_abort(sd);
  9653. return; // First walk attempt cancels the progress bar
  9654. } else if (pc_cant_act(sd))
  9655. return;
  9656. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9657. return;
  9658. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9659. //A move command one cell west is only valid if the target cell is free
  9660. if(battle_config.official_cell_stack_limit > 0
  9661. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9662. return;
  9663. // Cloaking wall check is actually updated when you click to process next movement
  9664. // not when you move each cell. This is official behaviour.
  9665. if (sd->sc.getSCE(SC_CLOAKING))
  9666. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9667. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9668. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9669. pc_delinvincibletimer(sd);
  9670. //Set last idle time... [Skotlex]
  9671. if (battle_config.idletime_option&IDLE_WALK)
  9672. sd->idletime = last_tick;
  9673. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9674. sd->idletime_hom = last_tick;
  9675. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9676. sd->idletime_mer = last_tick;
  9677. unit_walktoxy(&sd->bl, x, y, 4);
  9678. }
  9679. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9680. /// 018b <result>.W
  9681. /// result:
  9682. /// 0 = disconnect (quit)
  9683. /// 1 = cannot disconnect (wait 10 seconds)
  9684. /// ? = ignored
  9685. void clif_disconnect_ack(map_session_data* sd, short result)
  9686. {
  9687. int fd = sd->fd;
  9688. WFIFOHEAD(fd,packet_len(0x18b));
  9689. WFIFOW(fd,0) = 0x18b;
  9690. WFIFOW(fd,2) = result;
  9691. WFIFOSET(fd,packet_len(0x18b));
  9692. }
  9693. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9694. /// 018a <type>.W
  9695. /// type:
  9696. /// 0 = quit
  9697. void clif_parse_QuitGame(int fd, map_session_data *sd)
  9698. {
  9699. /* Rovert's prevent logout option fixed [Valaris] */
  9700. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9701. 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) &&
  9702. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9703. {
  9704. pc_damage_log_clear(sd,0);
  9705. clif_disconnect_ack(sd, 0);
  9706. flush_fifo( fd );
  9707. if( battle_config.drop_connection_on_quit ){
  9708. set_eof( fd );
  9709. }
  9710. } else {
  9711. clif_disconnect_ack(sd, 1);
  9712. }
  9713. }
  9714. /// Requesting unit's name.
  9715. /// 0094 <id>.L (CZ_REQNAME)
  9716. /// 0368 <id>.L (CZ_REQNAME2)
  9717. /// There are various variants of this packet, some of them have padding between fields.
  9718. void clif_parse_GetCharNameRequest(int fd, map_session_data *sd)
  9719. {
  9720. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9721. struct block_list* bl;
  9722. //status_change *sc;
  9723. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9724. id = sd->bl.id;
  9725. bl = map_id2bl(id);
  9726. if( bl == NULL )
  9727. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9728. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9729. return; // Block namerequests past view range
  9730. // 'see people in GM hide' cheat detection
  9731. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9732. sc = status_get_sc(bl);
  9733. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9734. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9735. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9736. ) {
  9737. char gm_msg[256];
  9738. 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);
  9739. ShowWarning(gm_msg);
  9740. // information is sent to all online GMs
  9741. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9742. return;
  9743. }
  9744. */
  9745. clif_name(&sd->bl,bl,SELF);
  9746. }
  9747. /// Validates and processes global messages
  9748. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9749. /// There are various variants of this packet.
  9750. void clif_parse_GlobalMessage(int fd, map_session_data* sd)
  9751. {
  9752. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9753. size_t length;
  9754. // validate packet and retrieve name and message
  9755. if( !clif_process_message(sd, false, name, message, output ) )
  9756. return;
  9757. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9758. channel_send(sd->gcbind,sd,message);
  9759. return;
  9760. }
  9761. // send message to others (using the send buffer for temp. storage)
  9762. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9763. length = strlen(output) + 1;
  9764. // send back message to the speaker
  9765. WFIFOHEAD(fd,4+length);
  9766. WFIFOW(fd,0) = 0x8e;
  9767. WFIFOW(fd,2) = (uint16)(4+length);
  9768. safestrncpy(WFIFOCP(fd,4), output, length );
  9769. WFIFOSET(fd, WFIFOW(fd,2));
  9770. #ifdef PCRE_SUPPORT
  9771. // trigger listening npcs
  9772. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9773. #endif
  9774. // Chat logging type 'O' / Global Chat
  9775. log_chat(LOG_CHAT_GLOBAL, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  9776. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9777. }
  9778. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9779. /// Request to warp to a map on given coordinates.
  9780. /// 0140 <map name>.16B <x>.W <y>.W
  9781. void clif_parse_MapMove(int fd, map_session_data *sd)
  9782. {
  9783. char command[MAP_NAME_LENGTH_EXT+25];
  9784. char* map_name;
  9785. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9786. map_name = RFIFOCP(fd,info->pos[0]);
  9787. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9788. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9789. RFIFOW(fd,info->pos[1]), //x
  9790. RFIFOW(fd,info->pos[2])); //y
  9791. is_atcommand(fd, sd, command, 1);
  9792. }
  9793. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9794. /// 009c <id>.L <head dir>.W <dir>.B
  9795. /// head dir:
  9796. /// 0 = straight
  9797. /// 1 = turned CW
  9798. /// 2 = turned CCW
  9799. /// dir:
  9800. /// 0 = north
  9801. /// 1 = northwest
  9802. /// 2 = west
  9803. /// 3 = southwest
  9804. /// 4 = south
  9805. /// 5 = southeast
  9806. /// 6 = east
  9807. /// 7 = northeast
  9808. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9809. {
  9810. unsigned char buf[64];
  9811. WBUFW(buf,0) = 0x9c;
  9812. WBUFL(buf,2) = bl->id;
  9813. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9814. WBUFB(buf,8) = unit_getdir(bl);
  9815. clif_send(buf, packet_len(0x9c), bl, target);
  9816. if (disguised(bl)) {
  9817. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9818. WBUFW(buf,6) = 0;
  9819. clif_send(buf, packet_len(0x9c), bl, SELF);
  9820. }
  9821. }
  9822. /// Request to change own body and head direction.
  9823. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9824. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9825. /// There are various variants of this packet, some of them have padding between fields.
  9826. void clif_parse_ChangeDir(int fd, map_session_data *sd)
  9827. {
  9828. unsigned char headdir, dir;
  9829. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9830. headdir = RFIFOB(fd,info->pos[0]);
  9831. dir = RFIFOB(fd,info->pos[1]);
  9832. pc_setdir(sd, dir, headdir);
  9833. clif_changed_dir(&sd->bl, AREA_WOS);
  9834. }
  9835. /// Request to show an emotion (CZ_REQ_EMOTION).
  9836. /// 00bf <type>.B
  9837. /// type:
  9838. /// @see enum emotion_type
  9839. void clif_parse_Emotion(int fd, map_session_data *sd){
  9840. if( sd == nullptr ){
  9841. return;
  9842. }
  9843. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9844. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9845. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9846. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9847. return;
  9848. }
  9849. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9850. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9851. sd->emotionlasttime = time(NULL);
  9852. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9853. return;
  9854. }
  9855. sd->emotionlasttime = time(NULL);
  9856. if (battle_config.idletime_option&IDLE_EMOTION)
  9857. sd->idletime = last_tick;
  9858. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9859. sd->idletime_hom = last_tick;
  9860. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9861. sd->idletime_mer = last_tick;
  9862. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9863. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9864. return;
  9865. }
  9866. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9867. emoticon = rnd()%6+ET_DICE1;
  9868. }
  9869. clif_emotion(&sd->bl, emoticon);
  9870. } else
  9871. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9872. }
  9873. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9874. /// 00c2 <count>.L
  9875. void clif_user_count(map_session_data* sd, int count)
  9876. {
  9877. int fd = sd->fd;
  9878. WFIFOHEAD(fd,packet_len(0xc2));
  9879. WFIFOW(fd,0) = 0xc2;
  9880. WFIFOL(fd,2) = count;
  9881. WFIFOSET(fd,packet_len(0xc2));
  9882. }
  9883. /// /w /who (CZ_REQ_USER_COUNT).
  9884. /// Request to display amount of currently connected players.
  9885. /// 00c1
  9886. void clif_parse_HowManyConnections(int fd, map_session_data *sd)
  9887. {
  9888. clif_user_count(sd, map_getusers());
  9889. }
  9890. void clif_parse_ActionRequest_sub( map_session_data& sd, int action_type, int target_id, t_tick tick ){
  9891. if (pc_isdead(&sd)) {
  9892. clif_clearunit_area(&sd.bl, CLR_DEAD);
  9893. return;
  9894. }
  9895. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9896. if (action_type != 0x00 && action_type != 0x07) {
  9897. if (sd.sc.cant.interact)
  9898. return;
  9899. pc_stop_walking(&sd, 1);
  9900. }
  9901. pc_stop_attack(&sd);
  9902. if(target_id<0 && -target_id == sd.bl.id) // for disguises [Valaris]
  9903. target_id = sd.bl.id;
  9904. switch(action_type)
  9905. {
  9906. case 0x00: // once attack
  9907. case 0x07: // continuous attack
  9908. if( pc_cant_act(&sd) )
  9909. return;
  9910. if (!battle_config.sdelay_attack_enable && pc_checkskill(&sd, SA_FREECAST) <= 0) {
  9911. if (DIFF_TICK(tick, sd.ud.canact_tick) < 0) {
  9912. clif_skill_fail( sd, 1, USESKILL_FAIL_SKILLINTERVAL );
  9913. return;
  9914. }
  9915. }
  9916. pc_delinvincibletimer(&sd);
  9917. if (battle_config.idletime_option&IDLE_ATTACK)
  9918. sd.idletime = last_tick;
  9919. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9920. sd.idletime_hom = last_tick;
  9921. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9922. sd.idletime_mer = last_tick;
  9923. unit_attack(&sd.bl, target_id, action_type != 0);
  9924. break;
  9925. case 0x02: // sitdown
  9926. if (battle_config.basic_skill_check && pc_checkskill(&sd, NV_BASIC) < 3 && pc_checkskill(&sd, SU_BASIC_SKILL) < 1) {
  9927. clif_skill_fail( sd, 1, USESKILL_FAIL_LEVEL, 2 );
  9928. break;
  9929. }
  9930. if(pc_issit(&sd)) {
  9931. //Bugged client? Just refresh them.
  9932. clif_sitting(&sd.bl);
  9933. return;
  9934. }
  9935. if (sd.ud.skilltimer != INVALID_TIMER || (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING))
  9936. break;
  9937. if (sd.sc.count && (
  9938. sd.sc.getSCE(SC_DANCING) ||
  9939. (sd.sc.getSCE(SC_GRAVITATION) && sd.sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9940. )) //No sitting during these states either.
  9941. break;
  9942. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9943. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9944. break;
  9945. }
  9946. if (battle_config.idletime_option&IDLE_SIT)
  9947. sd.idletime = last_tick;
  9948. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9949. sd.idletime_hom = last_tick;
  9950. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9951. sd.idletime_mer = last_tick;
  9952. pc_setsit(&sd);
  9953. skill_sit(&sd, true);
  9954. clif_sitting(&sd.bl);
  9955. break;
  9956. case 0x03: // standup
  9957. if (!pc_issit(&sd)) {
  9958. //Bugged client? Just refresh them.
  9959. clif_standing(&sd.bl);
  9960. return;
  9961. }
  9962. if (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING)
  9963. break;
  9964. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9965. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9966. break;
  9967. }
  9968. if (pc_setstand(&sd, false)) {
  9969. if (battle_config.idletime_option&IDLE_SIT)
  9970. sd.idletime = last_tick;
  9971. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9972. sd.idletime_hom = last_tick;
  9973. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9974. sd.idletime_mer = last_tick;
  9975. skill_sit(&sd, false);
  9976. clif_standing(&sd.bl);
  9977. }
  9978. break;
  9979. }
  9980. }
  9981. /// Request for an action.
  9982. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9983. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9984. /// action:
  9985. /// 0 = attack
  9986. /// 1 = pick up item
  9987. /// 2 = sit down
  9988. /// 3 = stand up
  9989. /// 7 = continous attack
  9990. /// 12 = (touch skill?)
  9991. /// There are various variants of this packet, some of them have padding between fields.
  9992. void clif_parse_ActionRequest(int fd, map_session_data *sd)
  9993. {
  9994. if( sd == nullptr ){
  9995. return;
  9996. }
  9997. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9998. clif_parse_ActionRequest_sub( *sd,
  9999. RFIFOB(fd,info->pos[1]),
  10000. RFIFOL(fd,info->pos[0]),
  10001. gettick()
  10002. );
  10003. }
  10004. /// Response to the death/system menu (CZ_RESTART).
  10005. /// 00b2 <type>.B
  10006. /// type:
  10007. /// 0 = restart (respawn)
  10008. /// 1 = char-select (disconnect)
  10009. void clif_parse_Restart(int fd, map_session_data *sd)
  10010. {
  10011. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  10012. case 0x00:
  10013. pc_respawn(sd,CLR_OUTSIGHT);
  10014. break;
  10015. case 0x01:
  10016. /* Rovert's Prevent logout option - Fixed [Valaris] */
  10017. 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) &&
  10018. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  10019. { //Send to char-server for character selection.
  10020. pc_damage_log_clear(sd,0);
  10021. chrif_charselectreq(sd, session[fd]->client_addr);
  10022. } else {
  10023. clif_disconnect_ack(sd, 1);
  10024. }
  10025. break;
  10026. }
  10027. }
  10028. /// Validates and processes whispered messages (CZ_WHISPER).
  10029. /// 0096 <packet len>.W <nick>.24B <message>.?B
  10030. void clif_parse_WisMessage(int fd, map_session_data* sd)
  10031. {
  10032. map_session_data* dstsd;
  10033. int i;
  10034. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10035. // validate packet and retrieve name and message
  10036. if( !clif_process_message( sd, true, target, message, output ) )
  10037. return;
  10038. // Chat logging type 'W' / Whisper
  10039. 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);
  10040. //-------------------------------------------------------//
  10041. // Lordalfa - Paperboy - To whisper NPC commands //
  10042. //-------------------------------------------------------//
  10043. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  10044. {
  10045. char* str = target+4; //Skip the NPC: string part.
  10046. struct npc_data* npc;
  10047. if ((npc = npc_name2id(str))) {
  10048. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  10049. char *split;
  10050. char event[EVENT_NAME_LENGTH];
  10051. str = message;
  10052. // skip codepage indicator, if detected
  10053. if( str[0] == '|' && strlen(str) >= 4 )
  10054. str += 3;
  10055. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  10056. split = strchr(str,'#');
  10057. if( split == NULL ) { // use the remaining string
  10058. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10059. for( ++i; i < NUM_WHISPER_VAR; ++i )
  10060. split_data[i][0] = '\0';
  10061. break;
  10062. }
  10063. *split = '\0';
  10064. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10065. str = split+1;
  10066. }
  10067. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  10068. char variablename[CHAT_SIZE_MAX];
  10069. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  10070. set_var_str( sd, variablename, split_data[i] );
  10071. }
  10072. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  10073. npc_event(sd,event,0); // Calls the NPC label
  10074. return;
  10075. }
  10076. } else if( target[0] == '#' ) {
  10077. struct Channel *channel = NULL;
  10078. char* chname = target;
  10079. channel = channel_name2channel(chname,sd,3);
  10080. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  10081. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  10082. channel_send(channel,sd,message);
  10083. }
  10084. else if( channel->pass[0] == '\0') { //no pass needed
  10085. if (channel_join(channel,sd)==0)
  10086. channel_send(channel,sd,message); //join success
  10087. }
  10088. else {
  10089. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  10090. }
  10091. return;
  10092. }
  10093. }
  10094. // searching destination character
  10095. dstsd = map_nick2sd(target,false);
  10096. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  10097. // player is not on this map-server
  10098. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  10099. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  10100. // and if we ask for 'Test', we must not contact 'test' player
  10101. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  10102. intif_wis_message(sd, target, message, strlen(message) + 1);
  10103. return;
  10104. }
  10105. // if player ignores everyone
  10106. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10107. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  10108. clif_wis_end(fd, 1); // 1: target character is not logged in
  10109. else
  10110. clif_wis_end(fd, 3); // 3: everyone ignored by target
  10111. return;
  10112. }
  10113. // if player is autotrading
  10114. if (dstsd->state.autotrade == 1){
  10115. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  10116. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  10117. return;
  10118. }
  10119. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10120. // if player ignores the source character
  10121. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  10122. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  10123. clif_wis_end(fd, 2); // 2: ignored by target
  10124. return;
  10125. }
  10126. }
  10127. // notify sender of success
  10128. clif_wis_end(fd, 0); // 0: success to send wisper
  10129. // Normal message
  10130. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10131. }
  10132. /// /b /nb (CZ_BROADCAST).
  10133. /// Request to broadcast a message on whole server.
  10134. /// 0099 <packet len>.W <text>.?B 00
  10135. void clif_parse_Broadcast(int fd, map_session_data* sd) {
  10136. char command[CHAT_SIZE_MAX+11];
  10137. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10138. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10139. char* msg = RFIFOCP(fd,info->pos[1]);
  10140. // as the length varies depending on the command used, just block unreasonably long strings
  10141. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10142. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10143. is_atcommand(fd, sd, command, 1);
  10144. }
  10145. /// Request to pick up an item.
  10146. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10147. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10148. /// There are various variants of this packet, some of them have padding between fields.
  10149. void clif_parse_TakeItem(int fd, map_session_data *sd)
  10150. {
  10151. struct flooritem_data *fitem;
  10152. int map_object_id;
  10153. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10154. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10155. do {
  10156. if (pc_isdead(sd)) {
  10157. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10158. break;
  10159. }
  10160. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10161. break;
  10162. if (pc_cant_act(sd))
  10163. break;
  10164. if (!pc_takeitem(sd, fitem))
  10165. break;
  10166. return;
  10167. } while (0);
  10168. // Client REQUIRES a fail packet or you can no longer pick items.
  10169. clif_additem(sd,0,0,6);
  10170. }
  10171. /// Request to drop an item.
  10172. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10173. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10174. /// There are various variants of this packet, some of them have padding between fields.
  10175. void clif_parse_DropItem(int fd, map_session_data *sd){
  10176. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10177. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10178. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10179. for(;;) {
  10180. if (pc_isdead(sd))
  10181. break;
  10182. if (pc_cant_act2(sd) || sd->npc_id)
  10183. break;
  10184. if (sd->sc.cant.drop)
  10185. break;
  10186. if (!pc_dropitem(sd, item_index, item_amount))
  10187. break;
  10188. if (battle_config.idletime_option&IDLE_DROPITEM)
  10189. sd->idletime = last_tick;
  10190. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10191. sd->idletime_hom = last_tick;
  10192. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10193. sd->idletime_mer = last_tick;
  10194. return;
  10195. }
  10196. //Because the client does not like being ignored.
  10197. clif_dropitem(sd, item_index,0);
  10198. }
  10199. /// Request to use an item.
  10200. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10201. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10202. /// There are various variants of this packet, some of them have padding between fields.
  10203. void clif_parse_UseItem(int fd, map_session_data *sd)
  10204. {
  10205. int n;
  10206. if (pc_isdead(sd)) {
  10207. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10208. return;
  10209. }
  10210. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10211. clif_msg(sd, WORK_IN_PROGRESS);
  10212. return;
  10213. }
  10214. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10215. if (battle_config.idletime_option&IDLE_USEITEM)
  10216. sd->idletime = last_tick;
  10217. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10218. sd->idletime_hom = last_tick;
  10219. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10220. sd->idletime_mer = last_tick;
  10221. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10222. if(n <0 || n >= MAX_INVENTORY)
  10223. return;
  10224. if (!pc_useitem(sd,n))
  10225. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10226. }
  10227. /// Request to equip an item
  10228. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10229. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10230. void clif_parse_EquipItem(int fd,map_session_data *sd)
  10231. {
  10232. int index;
  10233. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10234. if(pc_isdead(sd)) {
  10235. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10236. return;
  10237. }
  10238. index = RFIFOW(fd,info->pos[0])-2;
  10239. if (index < 0 || index >= MAX_INVENTORY)
  10240. return; //Out of bounds check.
  10241. if(sd->npc_id && !sd->npc_item_flag) {
  10242. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10243. return;
  10244. } else if (sd->state.storage_flag || sd->sc.opt1)
  10245. ; //You can equip/unequip stuff while storage is open/under status changes
  10246. else if (pc_cant_act2(sd))
  10247. return;
  10248. if(!sd->inventory.u.items_inventory[index].identify) {
  10249. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10250. return;
  10251. }
  10252. if(!sd->inventory_data[index])
  10253. return;
  10254. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10255. pet_equipitem(sd,index);
  10256. return;
  10257. }
  10258. if (battle_config.idletime_option&IDLE_USEITEM)
  10259. sd->idletime = last_tick;
  10260. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10261. sd->idletime_hom = last_tick;
  10262. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10263. sd->idletime_mer = last_tick;
  10264. //Client doesn't send the position for ammo.
  10265. if(sd->inventory_data[index]->type == IT_AMMO)
  10266. pc_equipitem(sd,index,EQP_AMMO);
  10267. else {
  10268. int req_pos;
  10269. #if PACKETVER >= 20120925
  10270. req_pos = RFIFOL(fd,info->pos[1]);
  10271. #else
  10272. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10273. #endif
  10274. pc_equipitem(sd,index,req_pos);
  10275. }
  10276. }
  10277. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10278. /// 00ab <index>.W
  10279. void clif_parse_UnequipItem(int fd,map_session_data *sd)
  10280. {
  10281. int index;
  10282. if(pc_isdead(sd)) {
  10283. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10284. return;
  10285. }
  10286. if (sd->npc_id && !sd->npc_item_flag) {
  10287. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10288. return;
  10289. } else if (sd->state.storage_flag || sd->sc.opt1)
  10290. ; //You can equip/unequip stuff while storage is open/under status changes
  10291. else if (pc_cant_act2(sd))
  10292. return;
  10293. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10294. if (battle_config.idletime_option&IDLE_USEITEM)
  10295. sd->idletime = last_tick;
  10296. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10297. sd->idletime_hom = last_tick;
  10298. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10299. sd->idletime_mer = last_tick;
  10300. pc_unequipitem(sd,index,1);
  10301. }
  10302. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10303. /// 0090 <id>.L <type>.B
  10304. /// type:
  10305. /// 1 = click
  10306. void clif_parse_NpcClicked(int fd,map_session_data *sd)
  10307. {
  10308. if( sd == nullptr ){
  10309. return;
  10310. }
  10311. struct block_list *bl;
  10312. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10313. if(pc_isdead(sd)) {
  10314. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10315. return;
  10316. }
  10317. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10318. #ifdef RENEWAL
  10319. clif_msg( sd, WORK_IN_PROGRESS );
  10320. #endif
  10321. return;
  10322. }
  10323. if( sd->state.mail_writing )
  10324. return;
  10325. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10326. //type = RFIFOB(fd,info->pos[1]);
  10327. if (!bl) return;
  10328. switch (bl->type) {
  10329. case BL_MOB:
  10330. case BL_PC:
  10331. clif_parse_ActionRequest_sub( *sd, 0x07, bl->id, gettick() );
  10332. break;
  10333. case BL_NPC:
  10334. #ifdef RENEWAL
  10335. 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
  10336. clif_msg(sd, WORK_IN_PROGRESS);
  10337. break;
  10338. }
  10339. #endif
  10340. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10341. struct npc_data* nd = (struct npc_data*)bl;
  10342. // Progressbar is running
  10343. if( nd->progressbar.timeout > 0 ){
  10344. return;
  10345. }
  10346. npc_click(sd,nd);
  10347. }
  10348. break;
  10349. }
  10350. }
  10351. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10352. /// 00c5 <id>.L <type>.B
  10353. /// type:
  10354. /// 0 = buy
  10355. /// 1 = sell
  10356. void clif_parse_NpcBuySellSelected(int fd,map_session_data *sd)
  10357. {
  10358. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10359. if (sd->state.trading)
  10360. return;
  10361. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10362. }
  10363. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10364. /// 00ca <result>.B
  10365. /// result:
  10366. /// 0 = "The deal has successfully completed."
  10367. /// 1 = "You do not have enough zeny."
  10368. /// 2 = "You are over your Weight Limit."
  10369. /// 3 = "Out of the maximum capacity, you have too many items."
  10370. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10371. /// 10 = "Props open-air store sales will be traded in RODEX"
  10372. /// 11 = "The exchange failed."
  10373. /// 12 = "The exchange was well done."
  10374. /// 13 = "The item is already sold and out of stock."
  10375. /// 14 = "There is not enough goods to exchange."
  10376. void clif_npc_buy_result( map_session_data* sd, e_purchase_result result ){
  10377. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10378. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10379. p.result = (uint8)result;
  10380. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10381. }
  10382. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10383. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10384. void clif_parse_NpcBuyListSend( int fd, map_session_data* sd ){
  10385. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10386. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10387. e_purchase_result result;
  10388. if( sd->state.trading || !sd->npc_shopid )
  10389. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10390. else{
  10391. std::vector<s_npc_buy_list> items = {};
  10392. items.reserve( n );
  10393. for( uint16 i = 0; i < n; i++ ){
  10394. s_npc_buy_list item = {};
  10395. item.nameid = p->items[i].itemId;
  10396. item.qty = p->items[i].amount;
  10397. items.push_back( item );
  10398. }
  10399. result = npc_buylist( sd, items );
  10400. }
  10401. sd->npc_shopid = 0; //Clear shop data.
  10402. clif_npc_buy_result(sd, result);
  10403. }
  10404. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10405. /// 00cb <result>.B
  10406. /// result:
  10407. /// 0 = "The deal has successfully completed."
  10408. /// 1 = "The deal has failed."
  10409. void clif_npc_sell_result(map_session_data* sd, unsigned char result)
  10410. {
  10411. int fd = sd->fd;
  10412. WFIFOHEAD(fd,packet_len(0xcb));
  10413. WFIFOW(fd,0) = 0xcb;
  10414. WFIFOB(fd,2) = result;
  10415. WFIFOSET(fd,packet_len(0xcb));
  10416. }
  10417. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10418. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10419. void clif_parse_NpcSellListSend(int fd,map_session_data *sd)
  10420. {
  10421. int fail=0,n;
  10422. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10423. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10424. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10425. if (sd->state.trading || !sd->npc_shopid)
  10426. fail = 1;
  10427. else
  10428. fail = npc_selllist(sd, n, p->sellList);
  10429. sd->npc_shopid = 0; //Clear shop data.
  10430. clif_npc_sell_result(sd, fail);
  10431. }
  10432. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10433. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10434. /// type:
  10435. /// 0 = private
  10436. /// 1 = public
  10437. void clif_parse_CreateChatRoom(int fd, map_session_data* sd)
  10438. {
  10439. if( sd == nullptr ){
  10440. return;
  10441. }
  10442. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10443. int len = RFIFOW(fd,info->pos[0])-15;
  10444. int limit = RFIFOW(fd,info->pos[1]);
  10445. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10446. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10447. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10448. char s_password[CHATROOM_PASS_SIZE];
  10449. char s_title[CHATROOM_TITLE_SIZE];
  10450. if (sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM)
  10451. return;
  10452. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10453. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 3 );
  10454. return;
  10455. }
  10456. if( npc_isnear(&sd->bl) ) {
  10457. // uncomment to send msg_txt.
  10458. //char output[150];
  10459. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10460. //clif_displaymessage(sd->fd, output);
  10461. clif_skill_fail( *sd, 1, USESKILL_FAIL_THERE_ARE_NPC_AROUND );
  10462. return;
  10463. }
  10464. if( len <= 0 )
  10465. return; // invalid input
  10466. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10467. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10468. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10469. }
  10470. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10471. /// 00d9 <chat ID>.L <passwd>.8B
  10472. void clif_parse_ChatAddMember(int fd, map_session_data* sd){
  10473. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10474. int chatid = RFIFOL(fd,info->pos[0]);
  10475. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10476. chat_joinchat(sd,chatid,password);
  10477. }
  10478. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10479. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10480. /// type:
  10481. /// 0 = private
  10482. /// 1 = public
  10483. void clif_parse_ChatRoomStatusChange(int fd, map_session_data* sd){
  10484. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10485. int len = RFIFOW(fd,info->pos[0])-15;
  10486. int limit = RFIFOW(fd,info->pos[1]);
  10487. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10488. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10489. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10490. char s_password[CHATROOM_PASS_SIZE];
  10491. char s_title[CHATROOM_TITLE_SIZE];
  10492. if( len <= 0 )
  10493. return; // invalid input
  10494. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10495. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10496. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10497. }
  10498. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10499. /// 00e0 <role>.L <nick>.24B
  10500. /// role:
  10501. /// 0 = owner
  10502. /// 1 = normal
  10503. void clif_parse_ChangeChatOwner(int fd, map_session_data* sd)
  10504. {
  10505. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10506. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10507. }
  10508. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10509. /// 00e2 <name>.24B
  10510. void clif_parse_KickFromChat(int fd,map_session_data *sd)
  10511. {
  10512. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10513. }
  10514. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10515. /// 00e3
  10516. void clif_parse_ChatLeave(int fd, map_session_data* sd)
  10517. {
  10518. chat_leavechat(sd,0);
  10519. }
  10520. //Handles notifying asker and rejecter of what has just ocurred.
  10521. //Type is used to determine the correct msg_txt to use:
  10522. //0:
  10523. static void clif_noask_sub(map_session_data *sd, map_session_data *tsd, int type)
  10524. {
  10525. const char* msg;
  10526. char output[256];
  10527. // Your request has been rejected by autoreject option.
  10528. msg = msg_txt(sd,392);
  10529. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10530. //Notice that a request was rejected.
  10531. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10532. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10533. }
  10534. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10535. /// 00e4 <account id>.L
  10536. void clif_parse_TradeRequest(int fd,map_session_data *sd)
  10537. {
  10538. map_session_data *t_sd;
  10539. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10540. if(!sd->chatID && pc_cant_act(sd))
  10541. return; //You can trade while in a chatroom.
  10542. if(t_sd){
  10543. // @noask [LuzZza]
  10544. if(t_sd->state.noask) {
  10545. clif_noask_sub(sd, t_sd, 0);
  10546. return;
  10547. }
  10548. if (t_sd->state.mail_writing) {
  10549. int old = sd->trade_partner;
  10550. // Fake trading
  10551. sd->trade_partner = t_sd->status.account_id;
  10552. clif_tradestart(sd, 5);
  10553. // Restore old state
  10554. sd->trade_partner = old;
  10555. return;
  10556. }
  10557. }
  10558. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10559. clif_skill_fail( *sd, 1 );
  10560. return;
  10561. }
  10562. trade_traderequest(sd,t_sd);
  10563. }
  10564. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10565. /// 00e6 <result>.B
  10566. /// result:
  10567. /// 3 = accepted
  10568. /// 4 = rejected
  10569. void clif_parse_TradeAck(int fd,map_session_data *sd)
  10570. {
  10571. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10572. }
  10573. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10574. /// 00e8 <index>.W <amount>.L
  10575. void clif_parse_TradeAddItem(int fd,map_session_data *sd)
  10576. {
  10577. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10578. short index = RFIFOW(fd,info->pos[0]);
  10579. int amount = RFIFOL(fd,info->pos[1]);
  10580. if( index == 0 )
  10581. trade_tradeaddzeny(sd, amount);
  10582. else
  10583. trade_tradeadditem(sd, server_index(index), (short)amount);
  10584. }
  10585. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10586. /// 00eb
  10587. void clif_parse_TradeOk(int fd,map_session_data *sd)
  10588. {
  10589. trade_tradeok(sd);
  10590. }
  10591. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10592. /// 00ed
  10593. void clif_parse_TradeCancel(int fd,map_session_data *sd)
  10594. {
  10595. trade_tradecancel(sd);
  10596. }
  10597. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10598. /// 00ef
  10599. void clif_parse_TradeCommit(int fd,map_session_data *sd)
  10600. {
  10601. trade_tradecommit(sd);
  10602. }
  10603. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10604. /// 0118
  10605. void clif_parse_StopAttack(int fd,map_session_data *sd)
  10606. {
  10607. pc_stop_attack(sd);
  10608. if (sd) sd->ud.state.attack_continue = 0;
  10609. }
  10610. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10611. /// 0126 <index>.W <amount>.L
  10612. void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
  10613. if (pc_istrading(sd) || !pc_iscarton(sd) || pc_cant_act2(sd))
  10614. return;
  10615. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10616. return;
  10617. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10618. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10619. }
  10620. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10621. /// 0127 <index>.W <amount>.L
  10622. void clif_parse_GetItemFromCart(int fd,map_session_data *sd)
  10623. {
  10624. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10625. if (!pc_iscarton(sd) || pc_cant_act2(sd))
  10626. return;
  10627. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10628. return;
  10629. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10630. }
  10631. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10632. /// 012a
  10633. void clif_parse_RemoveOption(int fd,map_session_data *sd)
  10634. {
  10635. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10636. #ifdef NEW_CARTS
  10637. && sd->sc.getSCE(SC_PUSH_CART) )
  10638. pc_setcart(sd,0);
  10639. #else
  10640. )
  10641. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10642. #endif
  10643. else // priority to remove this option before we can clear cart
  10644. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10645. }
  10646. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10647. /// 097f <Length>.W <identity>.L <type>.B
  10648. void clif_SelectCart(map_session_data *sd) {
  10649. #if PACKETVER >= 20150826
  10650. int i = 0, carts = 3;
  10651. int fd = sd->fd;
  10652. WFIFOHEAD(fd,8 + carts);
  10653. WFIFOW(fd,0) = 0x97f;
  10654. WFIFOW(fd,2) = 8 + carts;
  10655. WFIFOL(fd,4) = sd->status.account_id;
  10656. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10657. for( i = 0; i < carts; i++ ) {
  10658. WFIFOB(fd,8 + i) = 10 + i;
  10659. }
  10660. WFIFOSET(fd,8 + carts);
  10661. #endif
  10662. }
  10663. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10664. /// 0980 <identity>.L <type>.B
  10665. void clif_parse_SelectCart(int fd,map_session_data *sd) {
  10666. #if PACKETVER >= 20150826
  10667. int type;
  10668. // Check identity
  10669. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10670. return;
  10671. type = (int)RFIFOB(fd,6);
  10672. // Check type
  10673. if( type < 10 || type > 12 )
  10674. return;
  10675. pc_setcart(sd, type);
  10676. #endif
  10677. }
  10678. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10679. /// 01af <num>.W
  10680. void clif_parse_ChangeCart(int fd,map_session_data *sd)
  10681. {// TODO: State tracking?
  10682. int type;
  10683. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10684. return;
  10685. #ifdef RENEWAL
  10686. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10687. clif_msg(sd, WORK_IN_PROGRESS);
  10688. return;
  10689. }
  10690. #endif
  10691. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10692. if(
  10693. #ifdef NEW_CARTS
  10694. #if PACKETVER >= 20191106
  10695. (type == 13 && sd->status.base_level > 100) ||
  10696. #endif
  10697. (type == 9 && sd->status.base_level > 130) ||
  10698. (type == 8 && sd->status.base_level > 120) ||
  10699. (type == 7 && sd->status.base_level > 110) ||
  10700. (type == 6 && sd->status.base_level > 100) ||
  10701. #endif
  10702. (type == 5 && sd->status.base_level > 90) ||
  10703. (type == 4 && sd->status.base_level > 80) ||
  10704. (type == 3 && sd->status.base_level > 65) ||
  10705. (type == 2 && sd->status.base_level > 40) ||
  10706. (type == 1))
  10707. pc_setcart(sd, type);
  10708. }
  10709. /// Request to increase status (CZ_STATUS_CHANGE).
  10710. /// 00bb <status id>.W <amount>.B
  10711. /// status id:
  10712. /// SP_STR ~ SP_LUK
  10713. /// amount:
  10714. /// Old clients always send 1 for this, even when using /str+ and the like.
  10715. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10716. void clif_parse_StatusUp(int fd,map_session_data *sd)
  10717. {
  10718. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10719. if( increase_amount < 0 ) {
  10720. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10721. fd, increase_amount);
  10722. }
  10723. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10724. }
  10725. /// Request to increase trait status.
  10726. /// 0b24 <status id>.W <amount>.W
  10727. /// status id:
  10728. /// SP_POW ~ SP_CON
  10729. /// amount:
  10730. /// The amount to increase the trait status
  10731. void clif_parse_traitstatus_up( int fd, map_session_data *sd ){
  10732. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10733. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10734. if( p->amount < 0 ){
  10735. 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 );
  10736. return;
  10737. }
  10738. pc_traitstatusup( sd, p->type, p->amount );
  10739. #endif
  10740. }
  10741. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10742. /// 0112 <skill id>.W
  10743. void clif_parse_SkillUp(int fd,map_session_data *sd)
  10744. {
  10745. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10746. }
  10747. 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)
  10748. {
  10749. int lv;
  10750. if( !hd )
  10751. return;
  10752. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10753. clif_emotion(&hd->bl, ET_THINK);
  10754. return;
  10755. }
  10756. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10757. target_id = hd->bl.id;
  10758. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10759. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10760. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10761. clif_emotion(&hd->bl, ET_THINK);
  10762. if (hd->master)
  10763. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10764. return;
  10765. }
  10766. lv = hom_checkskill(hd, skill_id);
  10767. if( skill_lv > lv )
  10768. skill_lv = lv;
  10769. if( skill_lv )
  10770. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10771. }
  10772. 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)
  10773. {
  10774. int lv;
  10775. if( !hd )
  10776. return;
  10777. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10778. clif_emotion(&hd->bl, ET_THINK);
  10779. return;
  10780. }
  10781. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10782. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10783. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10784. clif_emotion(&hd->bl, ET_THINK);
  10785. if (hd->master)
  10786. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10787. return;
  10788. }
  10789. #ifdef RENEWAL
  10790. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10791. #else
  10792. if (hd->sc.getSCE(SC_BASILICA))
  10793. #endif
  10794. return;
  10795. lv = hom_checkskill(hd, skill_id);
  10796. if( skill_lv > lv )
  10797. skill_lv = lv;
  10798. if( skill_lv )
  10799. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10800. }
  10801. 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)
  10802. {
  10803. int lv;
  10804. if( !md )
  10805. return;
  10806. if( skill_isNotOk_mercenary(skill_id, *md) )
  10807. return;
  10808. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10809. target_id = md->bl.id;
  10810. if( md->ud.skilltimer != INVALID_TIMER )
  10811. {
  10812. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10813. }
  10814. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10815. return;
  10816. lv = mercenary_checkskill(md, skill_id);
  10817. if( skill_lv > lv )
  10818. skill_lv = lv;
  10819. if( skill_lv )
  10820. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10821. }
  10822. 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)
  10823. {
  10824. int lv;
  10825. if( !md )
  10826. return;
  10827. if( skill_isNotOk_mercenary(skill_id, *md) )
  10828. return;
  10829. if( md->ud.skilltimer != INVALID_TIMER )
  10830. return;
  10831. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10832. {
  10833. if (md->master)
  10834. clif_skill_fail( *md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10835. return;
  10836. }
  10837. #ifdef RENEWAL
  10838. if (md->sc.getSCE(SC_BASILICA_CELL))
  10839. #else
  10840. if (md->sc.getSCE(SC_BASILICA))
  10841. #endif
  10842. return;
  10843. lv = mercenary_checkskill(md, skill_id);
  10844. if( skill_lv > lv )
  10845. skill_lv = lv;
  10846. if( skill_lv )
  10847. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10848. }
  10849. void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10850. if( sd == nullptr ){
  10851. return;
  10852. }
  10853. t_tick tick = gettick();
  10854. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10855. int inf = skill_get_inf(skill_id);
  10856. if (inf&INF_GROUND_SKILL || !inf)
  10857. return; //Using a ground/passive skill on a target? WRONG.
  10858. if (sd->state.block_action & PCBLOCK_SKILL) {
  10859. clif_msg(sd, WORK_IN_PROGRESS);
  10860. return;
  10861. }
  10862. if( SKILL_CHK_HOMUN(skill_id) ) {
  10863. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10864. return;
  10865. }
  10866. if( SKILL_CHK_MERC(skill_id) ) {
  10867. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10868. return;
  10869. }
  10870. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10871. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10872. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10873. sd->idletime = last_tick;
  10874. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10875. sd->idletime_hom = last_tick;
  10876. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10877. sd->idletime_mer = last_tick;
  10878. if( sd->npc_id ){
  10879. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10880. #ifdef RENEWAL
  10881. clif_msg( sd, WORK_IN_PROGRESS );
  10882. #endif
  10883. return;
  10884. }
  10885. }
  10886. if ((pc_cant_act2(sd) || sd->chatID) &&
  10887. skill_id != RK_REFRESH &&
  10888. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10889. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10890. return;
  10891. if( pc_issit(sd) )
  10892. return;
  10893. if( skill_isNotOk(skill_id, *sd) )
  10894. return;
  10895. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10896. target_id = sd->bl.id; // never trust the client
  10897. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10898. target_id = sd->bl.id;
  10899. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10900. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10901. return;
  10902. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10903. if( sd->skillitem != skill_id ) {
  10904. clif_skill_fail( *sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10905. return;
  10906. }
  10907. }
  10908. if( sd->sc.option&OPTION_COSTUME )
  10909. return;
  10910. #ifndef RENEWAL
  10911. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10912. return; // On basilica only caster can use Basilica again to stop it.
  10913. #endif
  10914. if( sd->menuskill_id ) {
  10915. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10916. clif_menuskill_clear(sd); //Cancel pet capture.
  10917. }else if( sd->menuskill_id == SG_FEEL ){
  10918. clif_menuskill_clear( sd ); // Cancel selection
  10919. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10920. return; //Can't use skills while a menu is open.
  10921. }
  10922. if( sd->skillitem == skill_id ) {
  10923. if( skill_lv != sd->skillitemlv )
  10924. skill_lv = sd->skillitemlv;
  10925. if( !(inf&INF_SELF_SKILL) )
  10926. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10927. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10928. return;
  10929. }
  10930. sd->skillitem = sd->skillitemlv = 0;
  10931. if( SKILL_CHK_GUILD(skill_id) ) {
  10932. if (sd->guild && sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING)
  10933. skill_lv = guild_checkskill(sd->guild->guild, skill_id);
  10934. else
  10935. skill_lv = 0;
  10936. } else {
  10937. if( skill_id != ALL_EQSWITCH ){
  10938. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10939. }
  10940. }
  10941. pc_delinvincibletimer(sd);
  10942. if( skill_lv )
  10943. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10944. }
  10945. /// Request to use a targeted skill.
  10946. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10947. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10948. /// There are various variants of this packet, some of them have padding between fields.
  10949. void clif_parse_UseSkillToId( int fd, map_session_data *sd ){
  10950. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10951. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10952. }
  10953. /*==========================================
  10954. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10955. *------------------------------------------*/
  10956. static void clif_parse_UseSkillToPosSub( int fd, map_session_data& sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo ){
  10957. t_tick tick = gettick();
  10958. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10959. return; //Using a target skill on the ground? WRONG.
  10960. if (sd.state.block_action & PCBLOCK_SKILL) {
  10961. clif_msg(&sd, WORK_IN_PROGRESS);
  10962. return;
  10963. }
  10964. if( SKILL_CHK_HOMUN(skill_id) ) {
  10965. clif_parse_UseSkillToPos_homun(sd.hd, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10966. return;
  10967. }
  10968. if( SKILL_CHK_MERC(skill_id) ) {
  10969. clif_parse_UseSkillToPos_mercenary(sd.md, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10970. return;
  10971. }
  10972. if( pc_hasprogress( &sd, WIP_DISABLE_SKILLITEM ) ){
  10973. #ifdef RENEWAL
  10974. clif_msg( &sd, WORK_IN_PROGRESS );
  10975. #endif
  10976. return;
  10977. }
  10978. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10979. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10980. sd.idletime = last_tick;
  10981. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10982. sd.idletime_hom = last_tick;
  10983. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10984. sd.idletime_mer = last_tick;
  10985. if( skill_isNotOk(skill_id, sd) )
  10986. return;
  10987. if( skillmoreinfo != -1 ) {
  10988. if( pc_issit(&sd) ) {
  10989. clif_skill_fail( sd, skill_id );
  10990. return;
  10991. }
  10992. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10993. safestrncpy(sd.message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10994. }
  10995. if( sd.ud.skilltimer != INVALID_TIMER )
  10996. return;
  10997. if( DIFF_TICK(tick, sd.ud.canact_tick) < 0 ) {
  10998. if( sd.skillitem != skill_id ) {
  10999. clif_skill_fail( sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  11000. return;
  11001. }
  11002. }
  11003. if( sd.sc.option&OPTION_COSTUME )
  11004. return;
  11005. #ifndef RENEWAL
  11006. if( sd.sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd.sc.getSCE(SC_BASILICA)->val4 != sd.bl.id) )
  11007. return; // On basilica only caster can use Basilica again to stop it.
  11008. #endif
  11009. if( sd.menuskill_id ) {
  11010. if( sd.menuskill_id == SA_TAMINGMONSTER ) {
  11011. clif_menuskill_clear(&sd); //Cancel pet capture.
  11012. }else if( sd.menuskill_id == SG_FEEL ){
  11013. clif_menuskill_clear( &sd ); // Cancel selection
  11014. } else if( sd.menuskill_id != SA_AUTOSPELL )
  11015. return; //Can't use skills while a menu is open.
  11016. }
  11017. pc_delinvincibletimer(&sd);
  11018. if( sd.skillitem == skill_id ) {
  11019. if( skill_lv != sd.skillitemlv )
  11020. skill_lv = sd.skillitemlv;
  11021. unit_skilluse_pos(&sd.bl, x, y, skill_id, skill_lv);
  11022. } else {
  11023. int lv;
  11024. sd.skillitem = sd.skillitemlv = 0;
  11025. if( (lv = pc_checkskill(&sd, skill_id)) > 0 ) {
  11026. if( skill_lv > lv )
  11027. skill_lv = lv;
  11028. unit_skilluse_pos(&sd.bl, x, y, skill_id,skill_lv);
  11029. }
  11030. }
  11031. }
  11032. /// Request to use a ground skill.
  11033. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  11034. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  11035. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  11036. /// There are various variants of this packet, some of them have padding between fields.
  11037. void clif_parse_UseSkillToPos(int fd, map_session_data *sd)
  11038. {
  11039. if( sd == nullptr ){
  11040. return;
  11041. }
  11042. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11043. if (pc_cant_act(sd))
  11044. return;
  11045. if (pc_issit(sd))
  11046. return;
  11047. clif_parse_UseSkillToPosSub(fd, *sd,
  11048. RFIFOW(fd,info->pos[0]), //skill lv
  11049. RFIFOW(fd,info->pos[1]), //skill num
  11050. RFIFOW(fd,info->pos[2]), //pos x
  11051. RFIFOW(fd,info->pos[3]), //pos y
  11052. // TODO: find out what this is intended to do
  11053. //RFIFOB(fd, info->pos[4])
  11054. -1 //Skill more info.
  11055. );
  11056. }
  11057. /// Request to use a ground skill with text.
  11058. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  11059. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  11060. /// There are various variants of this packet, some of them have padding between fields.
  11061. void clif_parse_UseSkillToPosMoreInfo(int fd, map_session_data *sd)
  11062. {
  11063. if( sd == nullptr ){
  11064. return;
  11065. }
  11066. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11067. if (pc_cant_act(sd))
  11068. return;
  11069. if (pc_issit(sd))
  11070. return;
  11071. clif_parse_UseSkillToPosSub(fd, *sd,
  11072. RFIFOW(fd,info->pos[0]), //Skill lv
  11073. RFIFOW(fd,info->pos[1]), //Skill num
  11074. RFIFOW(fd,info->pos[2]), //pos x
  11075. RFIFOW(fd,info->pos[3]), //pos y
  11076. info->pos[4] //skill more info
  11077. );
  11078. }
  11079. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  11080. /// 011b <skill id>.W <map name>.16B
  11081. void clif_parse_UseSkillMap(int fd, map_session_data* sd)
  11082. {
  11083. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11084. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11085. char map_name[MAP_NAME_LENGTH];
  11086. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11087. sd->state.workinprogress = WIP_DISABLE_NONE;
  11088. if(skill_id != sd->menuskill_id)
  11089. return;
  11090. //It is possible to use teleport with the storage window open bugreport:8027
  11091. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11092. clif_menuskill_clear(sd);
  11093. return;
  11094. }
  11095. pc_delinvincibletimer(sd);
  11096. skill_castend_map(sd,skill_id,map_name);
  11097. }
  11098. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11099. /// 011d
  11100. void clif_parse_RequestMemo(int fd,map_session_data *sd)
  11101. {
  11102. if (!pc_isdead(sd))
  11103. pc_memo(sd,-1);
  11104. }
  11105. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11106. /// 018e <name id>.W { <material id>.W }*3
  11107. void clif_parse_ProduceMix(int fd,map_session_data *sd){
  11108. if( sd == nullptr ){
  11109. return;
  11110. }
  11111. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11112. switch( sd->menuskill_id ) {
  11113. case -1:
  11114. case AM_PHARMACY:
  11115. case RK_RUNEMASTERY:
  11116. case GC_RESEARCHNEWPOISON:
  11117. break;
  11118. default:
  11119. return;
  11120. }
  11121. if (pc_istrading(sd)) {
  11122. //Make it fail to avoid shop exploits where you sell something different than you see.
  11123. clif_skill_fail( *sd, sd->ud.skill_id );
  11124. clif_menuskill_clear(sd);
  11125. return;
  11126. }
  11127. int produce_idx;
  11128. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11129. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11130. clif_menuskill_clear(sd);
  11131. }
  11132. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11133. /// 025b <mk type>.W <name id>.W
  11134. /// mk type:
  11135. /// 1 = cooking
  11136. /// 2 = arrow
  11137. /// 3 = elemental
  11138. /// 4 = GN_MIX_COOKING
  11139. /// 5 = GN_MAKEBOMB
  11140. /// 6 = GN_S_PHARMACY
  11141. /// 7 = MT_M_MACHINE - Unconfirmed
  11142. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11143. void clif_parse_Cooking(int fd,map_session_data *sd) {
  11144. if( sd == nullptr ){
  11145. return;
  11146. }
  11147. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11148. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11149. short food_idx = -1;
  11150. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11151. return;
  11152. if (pc_istrading(sd)) {
  11153. //Make it fail to avoid shop exploits where you sell something different than you see.
  11154. clif_skill_fail( *sd, sd->ud.skill_id );
  11155. clif_menuskill_clear(sd);
  11156. return;
  11157. }
  11158. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11159. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11160. clif_menuskill_clear(sd);
  11161. }
  11162. /// Answer to repair weapon item selection dialog
  11163. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11164. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11165. void clif_parse_RepairItem( int fd, map_session_data *sd ){
  11166. if( sd == nullptr ){
  11167. return;
  11168. }
  11169. // Hercules has wrong date -> use correct one here
  11170. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11171. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11172. #else
  11173. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11174. #endif
  11175. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11176. return;
  11177. if (pc_istrading(sd)) {
  11178. //Make it fail to avoid shop exploits where you sell something different than you see.
  11179. clif_skill_fail( *sd, sd->ud.skill_id );
  11180. clif_menuskill_clear(sd);
  11181. return;
  11182. }
  11183. skill_repairweapon( *sd, p->item.index );
  11184. clif_menuskill_clear(sd);
  11185. }
  11186. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11187. /// 0222 <index>.L
  11188. void clif_parse_WeaponRefine( int fd, map_session_data *sd ){
  11189. if( sd == nullptr ){
  11190. return;
  11191. }
  11192. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11193. return;
  11194. if (pc_istrading(sd)) {
  11195. //Make it fail to avoid shop exploits where you sell something different than you see.
  11196. clif_skill_fail( *sd, sd->ud.skill_id );
  11197. clif_menuskill_clear(sd);
  11198. return;
  11199. }
  11200. skill_weaponrefine( *sd, server_index( RFIFOL( fd, 2 ) ) );
  11201. clif_menuskill_clear(sd);
  11202. }
  11203. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11204. /// 00b8 <npc id>.L <choice>.B
  11205. /// choice:
  11206. /// 1~254 = menu item
  11207. /// 255 = cancel
  11208. /// NOTE: If there were more than 254 items in the list, choice
  11209. /// overflows to choice%256.
  11210. void clif_parse_NpcSelectMenu(int fd,map_session_data *sd){
  11211. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11212. int npc_id = RFIFOL(fd,info->pos[0]);
  11213. uint8 select = RFIFOB(fd,info->pos[1]);
  11214. #ifdef SECURE_NPCTIMEOUT
  11215. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11216. return;
  11217. #endif
  11218. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11219. TBL_NPC* nd = map_id2nd(npc_id);
  11220. 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);
  11221. clif_GM_kick(NULL,sd);
  11222. return;
  11223. }
  11224. sd->npc_menu = select;
  11225. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11226. sd->idletime = last_tick;
  11227. }
  11228. npc_scriptcont(sd,npc_id, false);
  11229. }
  11230. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11231. /// 00b9 <npc id>.L
  11232. void clif_parse_NpcNextClicked(int fd,map_session_data *sd)
  11233. {
  11234. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11235. sd->idletime = last_tick;
  11236. }
  11237. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11238. }
  11239. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11240. /// 0143 <npc id>.L <value>.L
  11241. void clif_parse_NpcAmountInput(int fd,map_session_data *sd){
  11242. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11243. int npcid = RFIFOL(fd,info->pos[0]);
  11244. int amount = (int)RFIFOL(fd,info->pos[1]);
  11245. sd->npc_amount = amount;
  11246. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11247. sd->idletime = last_tick;
  11248. }
  11249. npc_scriptcont(sd, npcid, false);
  11250. }
  11251. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11252. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11253. void clif_parse_NpcStringInput(int fd, map_session_data* sd){
  11254. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11255. int message_len = RFIFOW(fd,info->pos[0])-8;
  11256. int npcid = RFIFOL(fd,info->pos[1]);
  11257. const char* message = RFIFOCP(fd,info->pos[2]);
  11258. if( message_len <= 0 )
  11259. return; // invalid input
  11260. #if PACKETVER >= 20151001
  11261. message_len++;
  11262. #endif
  11263. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11264. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11265. sd->idletime = last_tick;
  11266. }
  11267. npc_scriptcont(sd, npcid, false);
  11268. }
  11269. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11270. /// 0146 <npc id>.L
  11271. void clif_parse_NpcCloseClicked(int fd,map_session_data *sd)
  11272. {
  11273. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11274. return;
  11275. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11276. sd->idletime = last_tick;
  11277. }
  11278. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11279. }
  11280. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11281. /// 0178 <index>.W
  11282. /// index:
  11283. /// -1 = cancel
  11284. void clif_parse_ItemIdentify(int fd,map_session_data *sd) {
  11285. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11286. if (sd->menuskill_id != MC_IDENTIFY)
  11287. return;
  11288. // Ignore the request
  11289. // - Invalid item index
  11290. // - Invalid item ID or item doesn't exist
  11291. // - Item is already identified
  11292. if (idx < 0 || idx >= MAX_INVENTORY ||
  11293. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11294. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11295. sd->state.workinprogress = WIP_DISABLE_NONE;
  11296. clif_menuskill_clear(sd);
  11297. return;
  11298. }
  11299. skill_identify(sd, idx);
  11300. clif_menuskill_clear(sd);
  11301. }
  11302. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11303. /// 01ae <name id>.W
  11304. void clif_parse_SelectArrow(int fd,map_session_data *sd) {
  11305. if( sd == nullptr ){
  11306. return;
  11307. }
  11308. if (pc_istrading(sd)) {
  11309. //Make it fail to avoid shop exploits where you sell something different than you see.
  11310. clif_skill_fail( *sd, sd->ud.skill_id );
  11311. clif_menuskill_clear(sd);
  11312. return;
  11313. }
  11314. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11315. switch (sd->menuskill_id) {
  11316. case AC_MAKINGARROW:
  11317. skill_arrow_create(sd,p->itemId);
  11318. break;
  11319. case SA_CREATECON:
  11320. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11321. break;
  11322. case GC_POISONINGWEAPON:
  11323. skill_poisoningweapon(*sd,p->itemId);
  11324. break;
  11325. case NC_MAGICDECOY:
  11326. skill_magicdecoy(*sd,p->itemId);
  11327. break;
  11328. }
  11329. clif_menuskill_clear(sd);
  11330. }
  11331. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11332. /// 01ce <skill id>.L
  11333. void clif_parse_AutoSpell(int fd,map_session_data *sd)
  11334. {
  11335. if (sd->menuskill_id != SA_AUTOSPELL)
  11336. return;
  11337. sd->state.workinprogress = WIP_DISABLE_NONE;
  11338. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11339. clif_menuskill_clear(sd);
  11340. }
  11341. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11342. /// 017a <card index>.W
  11343. void clif_parse_UseCard(int fd,map_session_data *sd)
  11344. {
  11345. if (sd->state.trading != 0)
  11346. return;
  11347. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11348. }
  11349. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11350. /// 017c <card index>.W <equip index>.W
  11351. void clif_parse_InsertCard(int fd,map_session_data *sd)
  11352. {
  11353. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11354. if (sd->state.trading != 0)
  11355. return;
  11356. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11357. }
  11358. /// Request of character's name by char ID.
  11359. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11360. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11361. /// There are various variants of this packet, some of them have padding between fields.
  11362. void clif_parse_SolveCharName(int fd, map_session_data *sd)
  11363. {
  11364. int charid;
  11365. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11366. map_reqnickdb(sd, charid);
  11367. }
  11368. /// /resetskill /resetstate (CZ_RESET).
  11369. /// Request to reset stats or skills.
  11370. /// 0197 <type>.W
  11371. /// type:
  11372. /// 0 = state
  11373. /// 1 = skill
  11374. void clif_parse_ResetChar(int fd, map_session_data *sd) {
  11375. char cmd[15];
  11376. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11377. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11378. else
  11379. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11380. is_atcommand(fd, sd, cmd, 1);
  11381. }
  11382. /// /lb /nlb (CZ_LOCALBROADCAST).
  11383. /// Request to broadcast a message on current map.
  11384. /// 019c <packet len>.W <text>.?B
  11385. void clif_parse_LocalBroadcast(int fd, map_session_data* sd)
  11386. {
  11387. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11388. char command[CHAT_SIZE_MAX+16];
  11389. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11390. char* msg = RFIFOCP(fd,info->pos[1]);
  11391. // as the length varies depending on the command used, just block unreasonably long strings
  11392. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11393. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11394. is_atcommand(fd, sd, command, 1);
  11395. }
  11396. /// Request to move an item from inventory to storage.
  11397. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11398. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11399. /// There are various variants of this packet, some of them have padding between fields.
  11400. void clif_parse_MoveToKafra(int fd, map_session_data *sd)
  11401. {
  11402. int item_index, item_amount;
  11403. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11404. if (pc_istrading(sd))
  11405. return;
  11406. item_index = RFIFOW(fd,info->pos[0])-2;
  11407. item_amount = RFIFOL(fd,info->pos[1]);
  11408. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11409. return;
  11410. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11411. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11412. return;
  11413. }
  11414. if (sd->state.storage_flag == 1)
  11415. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11416. else
  11417. if (sd->state.storage_flag == 2)
  11418. storage_guild_storageadd(sd, item_index, item_amount);
  11419. else if (sd->state.storage_flag == 3)
  11420. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11421. }
  11422. /// Request to move an item from storage to inventory.
  11423. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11424. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11425. /// There are various variants of this packet, some of them have padding between fields.
  11426. void clif_parse_MoveFromKafra(int fd,map_session_data *sd)
  11427. {
  11428. int item_index, item_amount;
  11429. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11430. item_index = RFIFOW(fd,info->pos[0])-1;
  11431. item_amount = RFIFOL(fd,info->pos[1]);
  11432. if (sd->state.storage_flag == 1)
  11433. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11434. else if(sd->state.storage_flag == 2)
  11435. storage_guild_storageget(sd, item_index, item_amount);
  11436. else if(sd->state.storage_flag == 3)
  11437. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11438. }
  11439. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11440. /// 0129 <index>.W <amount>.L
  11441. void clif_parse_MoveToKafraFromCart(int fd, map_session_data *sd){
  11442. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11443. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11444. int amount = RFIFOL(fd,info->pos[1]);
  11445. if( sd->state.vending )
  11446. return;
  11447. if (!pc_iscarton(sd))
  11448. return;
  11449. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11450. return;
  11451. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11452. return;
  11453. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11454. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11455. return;
  11456. }
  11457. if (sd->state.storage_flag == 1)
  11458. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11459. else if (sd->state.storage_flag == 2)
  11460. storage_guild_storageaddfromcart(sd, idx, amount);
  11461. else if (sd->state.storage_flag == 3)
  11462. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11463. }
  11464. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11465. /// 0128 <index>.W <amount>.L
  11466. void clif_parse_MoveFromKafraToCart(int fd, map_session_data *sd){
  11467. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11468. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11469. int amount = RFIFOL(fd,info->pos[1]);
  11470. if( sd->state.vending )
  11471. return;
  11472. if (!pc_iscarton(sd))
  11473. return;
  11474. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11475. return;
  11476. if (sd->state.storage_flag == 1)
  11477. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11478. else
  11479. if (sd->state.storage_flag == 2)
  11480. storage_guild_storagegettocart(sd, idx, amount);
  11481. else if (sd->state.storage_flag == 3)
  11482. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11483. }
  11484. /// Request to close storage (CZ_CLOSE_STORE).
  11485. /// 00f7
  11486. void clif_parse_CloseKafra(int fd, map_session_data *sd)
  11487. {
  11488. if( sd->state.storage_flag == 1 )
  11489. storage_storageclose(sd);
  11490. else
  11491. if( sd->state.storage_flag == 2 )
  11492. storage_guild_storageclose(sd);
  11493. else if( sd->state.storage_flag == 3 )
  11494. storage_premiumStorage_close(sd);
  11495. }
  11496. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11497. /// 023a <info>.W
  11498. /// info:
  11499. /// 0 = password has not been set yet
  11500. /// 1 = storage is password-protected
  11501. /// 8 = too many wrong passwords
  11502. /// ? = ignored
  11503. /// NOTE: This packet is only available on certain non-kRO clients.
  11504. void clif_storagepassword(map_session_data* sd, short info)
  11505. {
  11506. int fd = sd->fd;
  11507. WFIFOHEAD(fd,packet_len(0x23a));
  11508. WFIFOW(fd,0) = 0x23a;
  11509. WFIFOW(fd,2) = info;
  11510. WFIFOSET(fd,packet_len(0x23a));
  11511. }
  11512. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11513. /// 023b <type>.W <password>.16B <new password>.16B
  11514. /// type:
  11515. /// 2 = change password
  11516. /// 3 = check password
  11517. /// NOTE: This packet is only available on certain non-kRO clients.
  11518. void clif_parse_StoragePassword(int fd, map_session_data *sd){ //@TODO
  11519. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11520. // int type = RFIFOW(fd,info->pos[0]);
  11521. // char* password = RFIFOP(fd,info->pos[1]);
  11522. // char* new_password = RFIFOP(fd,info->pos[2]);
  11523. // storage_changepass(sd,password,new_password);
  11524. }
  11525. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11526. /// 023c <result>.W <error count>.W
  11527. /// result:
  11528. /// 4 = password change success
  11529. /// 5 = password change failure
  11530. /// 6 = password check success
  11531. /// 7 = password check failure
  11532. /// 8 = too many wrong passwords
  11533. /// ? = ignored
  11534. /// NOTE: This packet is only available on certain non-kRO clients.
  11535. void clif_storagepassword_result(map_session_data* sd, short result, short error_count)
  11536. {
  11537. int fd = sd->fd;
  11538. WFIFOHEAD(fd,packet_len(0x23c));
  11539. WFIFOW(fd,0) = 0x23c;
  11540. WFIFOW(fd,2) = result;
  11541. WFIFOW(fd,4) = error_count;
  11542. WFIFOSET(fd,packet_len(0x23c));
  11543. }
  11544. /// Party creation request
  11545. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11546. void clif_parse_CreateParty(int fd, map_session_data *sd){
  11547. if( sd == nullptr ){
  11548. return;
  11549. }
  11550. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11551. name[NAME_LENGTH-1] = '\0';
  11552. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11553. clif_displaymessage(fd, msg_txt(sd,227));
  11554. return;
  11555. }
  11556. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11557. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11558. return;
  11559. }
  11560. party_create(sd,name,0,0);
  11561. }
  11562. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11563. void clif_parse_CreateParty2(int fd, map_session_data *sd){
  11564. if( sd == nullptr ){
  11565. return;
  11566. }
  11567. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11568. char* name = RFIFOCP(fd,info->pos[0]);
  11569. int item1 = RFIFOB(fd,info->pos[1]);
  11570. int item2 = RFIFOB(fd,info->pos[2]);
  11571. name[NAME_LENGTH-1] = '\0';
  11572. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11573. clif_displaymessage(fd, msg_txt(sd,227));
  11574. return;
  11575. }
  11576. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11577. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11578. return;
  11579. }
  11580. party_create(sd,name,item1,item2);
  11581. }
  11582. /// Party invitation request
  11583. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11584. void clif_parse_PartyInvite(int fd, map_session_data *sd)
  11585. {
  11586. map_session_data *t_sd;
  11587. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11588. clif_displaymessage(fd, msg_txt(sd,227));
  11589. return;
  11590. }
  11591. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11592. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11593. clif_noask_sub(sd, t_sd, 1);
  11594. return;
  11595. }
  11596. party_invite(sd, t_sd);
  11597. }
  11598. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11599. void clif_parse_PartyInvite2(int fd, map_session_data *sd){
  11600. map_session_data *t_sd;
  11601. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11602. name[NAME_LENGTH-1] = '\0';
  11603. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11604. clif_displaymessage(fd, msg_txt(sd,227));
  11605. return;
  11606. }
  11607. t_sd = map_nick2sd(name,false);
  11608. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11609. clif_noask_sub(sd, t_sd, 1);
  11610. return;
  11611. }
  11612. party_invite(sd, t_sd);
  11613. }
  11614. /// Party invitation reply
  11615. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11616. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11617. /// flag:
  11618. /// 0 = reject
  11619. /// 1 = accept
  11620. void clif_parse_ReplyPartyInvite(int fd,map_session_data *sd)
  11621. {
  11622. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11623. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11624. RFIFOL(fd,info->pos[1]));
  11625. }
  11626. //(CZ_PARTY_JOIN_REQ_ACK)
  11627. void clif_parse_ReplyPartyInvite2(int fd,map_session_data *sd)
  11628. {
  11629. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11630. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11631. RFIFOB(fd,info->pos[1]));
  11632. }
  11633. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11634. /// 0100
  11635. void clif_parse_LeaveParty(int fd, map_session_data *sd)
  11636. {
  11637. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11638. clif_displaymessage(fd, msg_txt(sd,227));
  11639. return;
  11640. }
  11641. party_leave(sd);
  11642. }
  11643. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11644. /// 0103 <account id>.L <char name>.24B
  11645. void clif_parse_RemovePartyMember(int fd, map_session_data *sd)
  11646. {
  11647. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11648. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11649. clif_displaymessage(fd, msg_txt(sd,227));
  11650. return;
  11651. }
  11652. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11653. RFIFOCP(fd,info->pos[1]));
  11654. }
  11655. /// Request to change party options.
  11656. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11657. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11658. void clif_parse_PartyChangeOption(int fd, map_session_data *sd)
  11659. {
  11660. struct party_data *p;
  11661. int i,expflag;
  11662. int cmd = RFIFOW(fd,0);
  11663. struct s_packet_db* info = &packet_db[cmd];
  11664. if( !sd->status.party_id )
  11665. return;
  11666. p = party_search(sd->status.party_id);
  11667. if( p == NULL )
  11668. return;
  11669. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11670. if( i == MAX_PARTY )
  11671. return; //Shouldn't happen
  11672. if( !p->party.member[i].leader )
  11673. return;
  11674. expflag = RFIFOL(fd,info->pos[0]);
  11675. if(cmd == 0x0102){ //Client can't change the item-field
  11676. party_changeoption(sd, expflag, p->party.item);
  11677. }
  11678. else {
  11679. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11680. party_changeoption(sd, expflag, itemflag);
  11681. }
  11682. }
  11683. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11684. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11685. void clif_parse_PartyMessage(int fd, map_session_data* sd){
  11686. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11687. // validate packet and retrieve name and message
  11688. if( !clif_process_message( sd, false, name, message, output ) )
  11689. return;
  11690. party_send_message(sd, output, strlen(output) + 1 );
  11691. }
  11692. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11693. /// 07da <account id>.L
  11694. void clif_parse_PartyChangeLeader(int fd, map_session_data* sd){
  11695. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11696. }
  11697. /// Party Booking in KRO [Spiria]
  11698. ///
  11699. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11700. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11701. void clif_parse_PartyBookingRegisterReq(int fd, map_session_data* sd){
  11702. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11703. short level = RFIFOW(fd,info->pos[0]);
  11704. short mapid = RFIFOW(fd,info->pos[1]);
  11705. int idxpbj = info->pos[2];
  11706. short job[MAX_PARTY_BOOKING_JOBS];
  11707. int i;
  11708. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11709. job[i] = RFIFOB(fd,idxpbj+i*2);
  11710. party_booking_register(sd, level, mapid, job);
  11711. }
  11712. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11713. /// 0803 <result>.W
  11714. /// result:
  11715. /// 0 = success
  11716. /// 1 = failure
  11717. /// 2 = already registered
  11718. void clif_PartyBookingRegisterAck(map_session_data *sd, int flag)
  11719. {
  11720. int fd = sd->fd;
  11721. WFIFOHEAD(fd,packet_len(0x803));
  11722. WFIFOW(fd,0) = 0x803;
  11723. WFIFOW(fd,2) = flag;
  11724. WFIFOSET(fd,packet_len(0x803));
  11725. }
  11726. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11727. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11728. void clif_parse_PartyBookingSearchReq(int fd, map_session_data* sd){
  11729. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11730. short level = RFIFOW(fd,info->pos[0]);
  11731. short mapid = RFIFOW(fd,info->pos[1]);
  11732. short job = RFIFOW(fd,info->pos[2]);
  11733. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11734. short resultcount = RFIFOW(fd,info->pos[4]);
  11735. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11736. }
  11737. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11738. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11739. /// more results:
  11740. /// 0 = no
  11741. /// 1 = yes
  11742. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11743. {
  11744. int i, j;
  11745. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11746. struct party_booking_ad_info *pb_ad;
  11747. WFIFOHEAD(fd,size*count + 5);
  11748. WFIFOW(fd,0) = 0x805;
  11749. WFIFOW(fd,2) = size*count + 5;
  11750. WFIFOB(fd,4) = more_result;
  11751. for(i=0; i<count; i++)
  11752. {
  11753. pb_ad = results[i];
  11754. WFIFOL(fd,i*size+5) = pb_ad->index;
  11755. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11756. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11757. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11758. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11759. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11760. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11761. }
  11762. WFIFOSET(fd,WFIFOW(fd,2));
  11763. }
  11764. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11765. /// 0806
  11766. void clif_parse_PartyBookingDeleteReq(int fd, map_session_data* sd)
  11767. {
  11768. if(party_booking_delete(sd))
  11769. clif_PartyBookingDeleteAck(sd, 0);
  11770. }
  11771. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11772. /// 0807 <result>.W
  11773. /// result:
  11774. /// 0 = success
  11775. /// 1 = success (auto-removed expired ad)
  11776. /// 2 = failure
  11777. /// 3 = nothing registered
  11778. void clif_PartyBookingDeleteAck(map_session_data* sd, int flag)
  11779. {
  11780. int fd = sd->fd;
  11781. WFIFOHEAD(fd,packet_len(0x807));
  11782. WFIFOW(fd,0) = 0x807;
  11783. WFIFOW(fd,2) = flag;
  11784. WFIFOSET(fd,packet_len(0x807));
  11785. }
  11786. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11787. /// 0808 { <job>.W }*6
  11788. void clif_parse_PartyBookingUpdateReq(int fd, map_session_data* sd)
  11789. {
  11790. short job[MAX_PARTY_BOOKING_JOBS];
  11791. int i;
  11792. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11793. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11794. job[i] = RFIFOW(fd,idxpbu+i*2);
  11795. party_booking_update(sd, job);
  11796. }
  11797. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11798. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11799. void clif_PartyBookingInsertNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11800. {
  11801. int i;
  11802. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11803. if(pb_ad == NULL) return;
  11804. WBUFW(buf,0) = 0x809;
  11805. WBUFL(buf,2) = pb_ad->index;
  11806. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11807. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11808. WBUFW(buf,34) = pb_ad->p_detail.level;
  11809. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11810. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11811. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11812. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11813. }
  11814. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11815. /// 080a <index>.L { <job>.W }*6
  11816. void clif_PartyBookingUpdateNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11817. {
  11818. int i;
  11819. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11820. if(pb_ad == NULL) return;
  11821. WBUFW(buf,0) = 0x80a;
  11822. WBUFL(buf,2) = pb_ad->index;
  11823. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11824. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11825. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11826. }
  11827. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11828. /// 080b <index>.L
  11829. void clif_PartyBookingDeleteNotify(map_session_data* sd, int index)
  11830. {
  11831. uint8 buf[6];
  11832. WBUFW(buf,0) = 0x80b;
  11833. WBUFL(buf,2) = index;
  11834. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11835. }
  11836. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11837. /// 012e
  11838. void clif_parse_CloseVending(int fd, map_session_data* sd)
  11839. {
  11840. vending_closevending(sd);
  11841. }
  11842. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11843. /// 0130 <account id>.L
  11844. void clif_parse_VendingListReq(int fd, map_session_data* sd)
  11845. {
  11846. if( sd->npc_id ) {// using an NPC
  11847. return;
  11848. }
  11849. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11850. }
  11851. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11852. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11853. void clif_parse_PurchaseReq(int fd, map_session_data* sd){
  11854. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11855. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11856. // whether it fails or not, the buy window is closed
  11857. sd->vended_id = 0;
  11858. }
  11859. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11860. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11861. void clif_parse_PurchaseReq2(int fd, map_session_data* sd){
  11862. #if PACKETVER >= 20100105
  11863. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11864. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11865. // whether it fails or not, the buy window is closed
  11866. sd->vended_id = 0;
  11867. #endif
  11868. }
  11869. /// Confirm or cancel the shop preparation window.
  11870. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11871. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11872. /// result:
  11873. /// 0 = canceled
  11874. /// 1 = open
  11875. void clif_parse_OpenVending(int fd, map_session_data* sd){
  11876. if( sd == nullptr ){
  11877. return;
  11878. }
  11879. int cmd = RFIFOW(fd,0);
  11880. struct s_packet_db* info = &packet_db[cmd];
  11881. short len = (short)RFIFOW(fd,info->pos[0]);
  11882. const char* message = RFIFOCP(fd,info->pos[1]);
  11883. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11884. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11885. len -= 84;
  11886. }
  11887. else { //(CZ_REQ_OPENSTORE2)
  11888. bool flag;
  11889. len -= 85;
  11890. flag = RFIFOB(fd,info->pos[2]) != 0;
  11891. if (!flag) {
  11892. sd->state.prevend = 0;
  11893. sd->state.workinprogress = WIP_DISABLE_NONE;
  11894. }
  11895. }
  11896. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11897. return;
  11898. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11899. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11900. return;
  11901. }
  11902. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11903. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11904. return;
  11905. }
  11906. if( message[0] == '\0' ) // invalid input
  11907. return;
  11908. vending_openvending(*sd, message, data, len/8, NULL);
  11909. }
  11910. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11911. /// 0165 <char id>.L <guild name>.24B
  11912. void clif_parse_CreateGuild(int fd,map_session_data *sd){
  11913. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11914. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11915. name[NAME_LENGTH-1] = '\0';
  11916. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11917. clif_displaymessage(fd, msg_txt(sd,228));
  11918. return;
  11919. }
  11920. if(sd->clan){
  11921. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11922. return;
  11923. }
  11924. guild_create(sd, name);
  11925. }
  11926. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11927. /// 014d
  11928. void clif_parse_GuildCheckMaster(int fd, map_session_data *sd)
  11929. {
  11930. clif_guild_masterormember(sd);
  11931. }
  11932. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11933. /// 014f <type>.L
  11934. /// type:
  11935. /// 0 = basic info
  11936. /// 1 = member manager
  11937. /// 2 = positions
  11938. /// 3 = skills
  11939. /// 4 = expulsion list
  11940. /// 5 = unknown (GM_ALLGUILDLIST)
  11941. /// 6 = notice
  11942. void clif_parse_GuildRequestInfo(int fd, map_session_data *sd)
  11943. {
  11944. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11945. if( !sd->status.guild_id && !sd->bg_id )
  11946. return;
  11947. switch( type )
  11948. {
  11949. case 0: // Basic Information Guild, hostile alliance information
  11950. clif_guild_basicinfo( *sd );
  11951. clif_guild_allianceinfo(sd);
  11952. clif_guild_castle_list(*sd);
  11953. break;
  11954. case 1: // Members list, list job title
  11955. clif_guild_positionnamelist(sd);
  11956. clif_guild_memberlist( *sd );
  11957. break;
  11958. case 2: // List job title, title information list
  11959. clif_guild_positionnamelist(sd);
  11960. clif_guild_positioninfolist(sd);
  11961. break;
  11962. case 3: // Skill list
  11963. clif_guild_skillinfo(sd);
  11964. break;
  11965. case 4: // Expulsion list
  11966. clif_guild_expulsionlist(sd);
  11967. break;
  11968. default:
  11969. ShowError("clif: guild request info: unknown type %d\n", type);
  11970. break;
  11971. }
  11972. }
  11973. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11974. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11975. void clif_parse_GuildChangePositionInfo(int fd, map_session_data *sd)
  11976. {
  11977. int i;
  11978. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11979. int len = RFIFOW(fd,info->pos[0]);
  11980. int idxgpos = info->pos[1];
  11981. if(!sd->state.gmaster_flag)
  11982. return;
  11983. for(i = idxgpos; i < len; i += 40 ){
  11984. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11985. }
  11986. }
  11987. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11988. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11989. void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){
  11990. if(!sd->state.gmaster_flag)
  11991. return;
  11992. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11993. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11994. for( int16 i = 0; i < entries; i++ ){
  11995. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11996. // Guild leadership change
  11997. if( entry.position == 0 ){
  11998. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11999. clif_msg( sd, GUILD_MASTER_WOE );
  12000. return;
  12001. }
  12002. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->guild.last_leader_change ) < battle_config.guild_leaderchange_delay ){
  12003. clif_msg( sd, GUILD_MASTER_DELAY );
  12004. return;
  12005. }
  12006. guild_gm_change( sd->status.guild_id, entry.CID );
  12007. // No further entries will be processed - the requesting player lost his guild master status
  12008. return;
  12009. }else if( entry.position > 0 ){
  12010. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  12011. }
  12012. }
  12013. }
  12014. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  12015. /// 0151 <guild id>.L
  12016. void clif_parse_GuildRequestEmblem(int fd,map_session_data *sd)
  12017. {
  12018. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12019. auto g = guild_search(guild_id);
  12020. if (g)
  12021. clif_guild_emblem(*sd, g->guild);
  12022. }
  12023. /// Validates data of a guild emblem (compressed bitmap)
  12024. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  12025. EMBVALIDATE_SUCCESS = 0,
  12026. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  12027. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  12028. };
  12029. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  12030. {
  12031. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  12032. unsigned long buf_len = sizeof(buf);
  12033. int offset = 0;
  12034. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  12035. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  12036. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  12037. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  12038. ))
  12039. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  12040. if(inter_config.emblem_transparency_limit != 100) {
  12041. int i, transcount = 1, tmp[3];
  12042. for(i = offset; i < buf_len-1; i++) {
  12043. int j = i%3;
  12044. tmp[j] = RBUFL(buf,i);
  12045. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  12046. transcount++;
  12047. }
  12048. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  12049. return EMBVALIDATE_ERR_TRANSPARENCY;
  12050. }
  12051. return EMBVALIDATE_SUCCESS;
  12052. }
  12053. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  12054. /// 0153 <packet len>.W <emblem data>.?B
  12055. void clif_parse_GuildChangeEmblem(int fd,map_session_data *sd){
  12056. if( sd == nullptr ){
  12057. return;
  12058. }
  12059. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12060. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  12061. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  12062. int emb_val=0;
  12063. if( !emblem_len || !sd->state.gmaster_flag )
  12064. return;
  12065. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  12066. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  12067. return;
  12068. }
  12069. emb_val = clif_validate_emblem(emblem, emblem_len);
  12070. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  12071. 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);
  12072. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  12073. return;
  12074. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  12075. char output[128];
  12076. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  12077. 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"
  12078. return;
  12079. }
  12080. guild_change_emblem( *sd, emblem_len, (const char*)emblem );
  12081. }
  12082. /// Request to update the guild emblem id (version, according to Gravity)
  12083. /// 0b46 <guild id>.L <version>.L
  12084. void clif_parse_GuildChangeEmblem2(int fd, map_session_data* sd) {
  12085. if( sd == nullptr ){
  12086. return;
  12087. }
  12088. #if PACKETVER >= 20190724
  12089. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  12090. auto &g = sd->guild;
  12091. if (!g || g->guild.guild_id != p->guild_id)
  12092. return;
  12093. if (!sd->state.gmaster_flag)
  12094. return;
  12095. if (!inter_config.emblem_woe_change && is_agit_start()) {
  12096. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  12097. return;
  12098. }
  12099. guild_change_emblem_version( *sd, p->version );
  12100. #endif
  12101. }
  12102. /// Guild notice update request (CZ_GUILD_NOTICE).
  12103. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  12104. void clif_parse_GuildChangeNotice(int fd, map_session_data* sd){
  12105. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12106. int guild_id = RFIFOL(fd,info->pos[0]);
  12107. char* msg1 = RFIFOCP(fd,info->pos[1]);
  12108. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12109. if(!sd->state.gmaster_flag)
  12110. return;
  12111. // compensate for some client defects when using multilanguage mode
  12112. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12113. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12114. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12115. guild_change_notice(sd, guild_id, msg1, msg2);
  12116. }
  12117. // Helper function for guild invite functions
  12118. int clif_sub_guild_invite(int fd, map_session_data *sd, map_session_data *t_sd)
  12119. {
  12120. if (t_sd == NULL) // not online or does not exist
  12121. return 1;
  12122. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12123. clif_displaymessage(fd, msg_txt(sd,228));
  12124. return 1;
  12125. }
  12126. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12127. clif_noask_sub(sd, t_sd, 2);
  12128. return 1;
  12129. }
  12130. // Players in a clan can not join a guild
  12131. if(t_sd && t_sd->clan){
  12132. return 1;
  12133. }
  12134. guild_invite(sd, t_sd);
  12135. return 0;
  12136. }
  12137. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12138. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12139. void clif_parse_GuildInvite(int fd,map_session_data *sd){
  12140. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12141. map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12142. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12143. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12144. if (clif_sub_guild_invite(fd, sd, t_sd))
  12145. return;
  12146. }
  12147. /// Guild invite request (/guildinvite)
  12148. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12149. void
  12150. clif_parse_GuildInvite2(int fd, map_session_data *sd) {
  12151. map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12152. if (clif_sub_guild_invite(fd, sd, t_sd))
  12153. return;
  12154. }
  12155. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12156. /// 016b <guild id>.L <answer>.L
  12157. /// answer:
  12158. /// 0 = refuse
  12159. /// 1 = accept
  12160. void clif_parse_GuildReplyInvite(int fd,map_session_data *sd){
  12161. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12162. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12163. RFIFOL(fd,info->pos[1]));
  12164. }
  12165. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12166. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12167. void clif_parse_GuildLeave(int fd,map_session_data *sd){
  12168. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12169. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12170. clif_displaymessage(fd, msg_txt(sd,228));
  12171. return;
  12172. }
  12173. if( sd->bg_id ) {
  12174. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12175. return;
  12176. }
  12177. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12178. RFIFOL(fd,info->pos[1]),
  12179. RFIFOL(fd,info->pos[2]),
  12180. RFIFOCP(fd,info->pos[3]));
  12181. }
  12182. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12183. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12184. void clif_parse_GuildExpulsion(int fd,map_session_data *sd){
  12185. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12186. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12187. { // Guild locked.
  12188. clif_displaymessage(fd, msg_txt(sd,228));
  12189. return;
  12190. }
  12191. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12192. RFIFOL(fd,info->pos[1]),
  12193. RFIFOL(fd,info->pos[2]),
  12194. RFIFOCP(fd,info->pos[3]));
  12195. }
  12196. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12197. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12198. void clif_parse_GuildMessage(int fd, map_session_data* sd){
  12199. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12200. // validate packet and retrieve name and message
  12201. if( !clif_process_message( sd, false, name, message, output ) )
  12202. return;
  12203. if( sd->bg_id )
  12204. bg_send_message(sd, output, strlen(output) );
  12205. else
  12206. guild_send_message(sd, output, strlen(output) );
  12207. }
  12208. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12209. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12210. void clif_parse_GuildRequestAlliance(int fd, map_session_data *sd)
  12211. {
  12212. map_session_data *t_sd;
  12213. if(!sd->state.gmaster_flag)
  12214. return;
  12215. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12216. clif_displaymessage(fd, msg_txt(sd,228));
  12217. return;
  12218. }
  12219. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12220. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12221. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12222. // @noask [LuzZza]
  12223. if(t_sd && t_sd->state.noask) {
  12224. clif_noask_sub(sd, t_sd, 3);
  12225. return;
  12226. }
  12227. guild_reqalliance(sd,t_sd);
  12228. }
  12229. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12230. /// 0172 <inviter account id>.L <answer>.L
  12231. /// answer:
  12232. /// 0 = refuse
  12233. /// 1 = accept
  12234. void clif_parse_GuildReplyAlliance(int fd, map_session_data *sd){
  12235. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12236. guild_reply_reqalliance(sd,
  12237. RFIFOL(fd,info->pos[0]),
  12238. RFIFOL(fd,info->pos[1]));
  12239. }
  12240. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12241. /// 0183 <opponent guild id>.L <relation>.L
  12242. /// relation:
  12243. /// 0 = Ally
  12244. /// 1 = Enemy
  12245. void clif_parse_GuildDelAlliance(int fd, map_session_data *sd){
  12246. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12247. if(!sd->state.gmaster_flag)
  12248. return;
  12249. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12250. clif_displaymessage(fd, msg_txt(sd,228));
  12251. return;
  12252. }
  12253. guild_delalliance(sd,
  12254. RFIFOL(fd,info->pos[0]),
  12255. RFIFOL(fd,info->pos[1]));
  12256. }
  12257. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12258. /// 0180 <account id>.L
  12259. void clif_parse_GuildOpposition(int fd, map_session_data *sd)
  12260. {
  12261. map_session_data *t_sd;
  12262. if(!sd->state.gmaster_flag)
  12263. return;
  12264. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12265. clif_displaymessage(fd, msg_txt(sd,228));
  12266. return;
  12267. }
  12268. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12269. // @noask [LuzZza]
  12270. if(t_sd && t_sd->state.noask) {
  12271. clif_noask_sub(sd, t_sd, 4);
  12272. return;
  12273. }
  12274. guild_opposition(sd,t_sd);
  12275. }
  12276. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12277. /// 015d <key>.40B
  12278. /// key:
  12279. /// now guild name; might have been (intended) email, since the
  12280. /// field name and size is same as the one in CH_DELETE_CHAR.
  12281. void clif_parse_GuildBreak(int fd, map_session_data *sd)
  12282. {
  12283. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12284. clif_displaymessage(fd, msg_txt(sd,228));
  12285. return;
  12286. }
  12287. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12288. }
  12289. /// Pet
  12290. ///
  12291. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12292. /// 01a1 <type>.B
  12293. /// type:
  12294. /// 0 = pet information
  12295. /// 1 = feed
  12296. /// 2 = performance
  12297. /// 3 = return to egg
  12298. /// 4 = unequip accessory
  12299. void clif_parse_PetMenu(int fd, map_session_data *sd){
  12300. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12301. }
  12302. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12303. /// 019f <id>.L
  12304. void clif_parse_CatchPet(int fd, map_session_data *sd){
  12305. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12306. }
  12307. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12308. /// 01a7 <index>.W
  12309. void clif_parse_SelectEgg(int fd, map_session_data *sd){
  12310. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12311. return;
  12312. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12313. clif_menuskill_clear(sd);
  12314. }
  12315. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12316. /// 01a9 <data>.L
  12317. /// data:
  12318. /// is either emotion (@see enum emotion_type) or a compound value
  12319. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12320. /// entry (given in parentheses) in data\pettalktable.xml
  12321. /// act id:
  12322. /// 0 = feeding
  12323. /// 1 = hunting
  12324. /// 2 = danger
  12325. /// 3 = dead
  12326. /// 4 = normal (stand)
  12327. /// 5 = special performance (perfor_s)
  12328. /// 6 = level up (levelup)
  12329. /// 7 = performance 1 (perfor_1)
  12330. /// 8 = performance 2 (perfor_2)
  12331. /// 9 = performance 3 (perfor_3)
  12332. /// 10 = log-in greeting (connect)
  12333. /// hungry value:
  12334. /// 0 = very hungry (hungry)
  12335. /// 1 = hungry (bit_hungry)
  12336. /// 2 = satisfied (noting)
  12337. /// 3 = stuffed (full)
  12338. /// 4 = full (so_full)
  12339. void clif_parse_SendEmotion(int fd, map_session_data *sd)
  12340. {
  12341. if(sd->pd)
  12342. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12343. }
  12344. /// Request to change pet's name (CZ_RENAME_PET).
  12345. /// 01a5 <name>.24B
  12346. void clif_parse_ChangePetName(int fd, map_session_data *sd)
  12347. {
  12348. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12349. }
  12350. /// /kill (CZ_DISCONNECT_CHARACTER).
  12351. /// Request to disconnect a character.
  12352. /// 00cc <account id>.L
  12353. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12354. void clif_parse_GMKick(int fd, map_session_data *sd)
  12355. {
  12356. struct block_list *target;
  12357. int tid;
  12358. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12359. target = map_id2bl(tid);
  12360. if (!target) {
  12361. clif_GM_kickack(sd, 0);
  12362. return;
  12363. }
  12364. switch (target->type) {
  12365. case BL_PC:
  12366. {
  12367. char command[NAME_LENGTH+6];
  12368. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12369. is_atcommand(fd, sd, command, 1);
  12370. }
  12371. break;
  12372. /**
  12373. * This one does not invoke any atcommand, so we need to check for permissions.
  12374. */
  12375. case BL_MOB:
  12376. {
  12377. char command[100];
  12378. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12379. clif_GM_kickack(sd, 0);
  12380. return;
  12381. }
  12382. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12383. log_atcommand(sd, command);
  12384. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12385. }
  12386. break;
  12387. case BL_NPC:
  12388. {
  12389. struct npc_data* nd = (struct npc_data *)target;
  12390. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12391. npc_unload_duplicates(nd);
  12392. npc_unload(nd,true);
  12393. npc_read_event_script();
  12394. }
  12395. }
  12396. break;
  12397. default:
  12398. clif_GM_kickack(sd, 0);
  12399. }
  12400. }
  12401. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12402. /// Request to disconnect all characters.
  12403. /// 00ce
  12404. void clif_parse_GMKickAll(int fd, map_session_data* sd) {
  12405. char cmd[15];
  12406. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12407. is_atcommand(fd, sd, cmd, 1);
  12408. }
  12409. /// /remove (CZ_REMOVE_AID).
  12410. /// Request to warp to a character with given login ID.
  12411. /// 01ba <account name>.24B
  12412. /// /shift (CZ_SHIFT).
  12413. /// Request to warp to a character with given name.
  12414. /// 01bb <char name>.24B
  12415. void clif_parse_GMShift(int fd, map_session_data *sd)
  12416. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12417. char *player_name;
  12418. char command[NAME_LENGTH+8];
  12419. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12420. player_name[NAME_LENGTH-1] = '\0';
  12421. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12422. is_atcommand(fd, sd, command, 1);
  12423. }
  12424. /// /remove (CZ_REMOVE_AID_SSO).
  12425. /// Request to warp to a character with given account ID.
  12426. /// 0843 <account id>.L
  12427. void clif_parse_GMRemove2(int fd, map_session_data* sd)
  12428. {
  12429. uint32 account_id;
  12430. map_session_data* pl_sd;
  12431. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12432. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12433. char command[NAME_LENGTH+8];
  12434. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12435. is_atcommand(fd, sd, command, 1);
  12436. }
  12437. }
  12438. /// /recall (CZ_RECALL).
  12439. /// Request to summon a player with given login ID to own position.
  12440. /// 01bc <account name>.24B
  12441. /// /summon (CZ_RECALL_GID).
  12442. /// Request to summon a player with given name to own position.
  12443. /// 01bd <char name>.24B
  12444. void clif_parse_GMRecall(int fd, map_session_data *sd)
  12445. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12446. char *player_name;
  12447. char command [NAME_LENGTH+8];
  12448. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12449. player_name[NAME_LENGTH-1] = '\0';
  12450. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12451. is_atcommand(fd, sd, command, 1);
  12452. }
  12453. /// /recall (CZ_RECALL_SSO).
  12454. /// Request to summon a player with given account ID to own position.
  12455. /// 0842 <account id>.L
  12456. void clif_parse_GMRecall2(int fd, map_session_data* sd)
  12457. {
  12458. uint32 account_id;
  12459. map_session_data* pl_sd;
  12460. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12461. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12462. char command[NAME_LENGTH+8];
  12463. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12464. is_atcommand(fd, sd, command, 1);
  12465. }
  12466. }
  12467. /// /item /monster (CZ_ITEM_CREATE).
  12468. /// Request to execute GM commands.
  12469. /// Usage:
  12470. /// /item n - summon n monster or acquire n item/s
  12471. /// /item money - grants 2147483647 zenies
  12472. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12473. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12474. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12475. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12476. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12477. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12478. /// 013f <item/mob name>.24B
  12479. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12480. void clif_parse_GM_Item_Monster(int fd, map_session_data *sd)
  12481. {
  12482. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12483. int mob_id = 0;
  12484. StringBuf command;
  12485. char *str;
  12486. //#if PACKETVER >= 20131218
  12487. // char str[100];
  12488. //#else
  12489. // char str[24];
  12490. //#endif
  12491. str = RFIFOCP(fd,info->pos[0]);
  12492. if (!str || str[0] == '\0')
  12493. return;
  12494. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12495. return;
  12496. trim(str);
  12497. // Zeny
  12498. if( strcmpi(str, "money") == 0 ) {
  12499. StringBuf_Init(&command);
  12500. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12501. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12502. StringBuf_Destroy(&command);
  12503. return;
  12504. }
  12505. std::shared_ptr<item_data> id = item_db.searchname( str );
  12506. // Item
  12507. if( id ){
  12508. StringBuf_Init(&command);
  12509. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12510. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12511. }else{
  12512. if (id->flag.guid)
  12513. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12514. else
  12515. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12516. }
  12517. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12518. StringBuf_Destroy(&command);
  12519. return;
  12520. }
  12521. // Monster
  12522. if ((mob_id = mobdb_searchname(str)) == 0)
  12523. mob_id = mobdb_checkid(atoi(str));
  12524. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12525. if( mob != nullptr ) {
  12526. StringBuf_Init(&command);
  12527. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12528. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12529. StringBuf_Destroy(&command);
  12530. return;
  12531. }
  12532. }
  12533. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12534. /// 019d <effect state>.L
  12535. /// effect state:
  12536. /// TODO: Any OPTION_* ?
  12537. void clif_parse_GMHide(int fd, map_session_data *sd) {
  12538. char cmd[6];
  12539. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12540. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12541. is_atcommand(fd, sd, cmd, 1);
  12542. }
  12543. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12544. /// 0149 <account id>.L <type>.B <value>.W
  12545. /// type:
  12546. /// 0 = positive points
  12547. /// 1 = negative points
  12548. /// 2 = self mute (+10 minutes)
  12549. void clif_parse_GMReqNoChat(int fd,map_session_data *sd)
  12550. {
  12551. int id, type, value;
  12552. map_session_data *dstsd;
  12553. char command[NAME_LENGTH+15];
  12554. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12555. id = RFIFOL(fd,info->pos[0]);
  12556. type = RFIFOB(fd,info->pos[1]);
  12557. value = RFIFOW(fd,info->pos[2]);
  12558. if( type == 0 )
  12559. value = -value;
  12560. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12561. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12562. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12563. return;
  12564. dstsd = map_id2sd(id);
  12565. if( dstsd == NULL )
  12566. return;
  12567. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12568. is_atcommand(fd, sd, command, 1);
  12569. }
  12570. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12571. /// GM adjustment of a player's manner value by -60.
  12572. /// 0212 <char name>.24B
  12573. void clif_parse_GMRc(int fd, map_session_data* sd)
  12574. {
  12575. char command[NAME_LENGTH+15];
  12576. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12577. name[NAME_LENGTH-1] = '\0';
  12578. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12579. is_atcommand(fd, sd, command, 1);
  12580. }
  12581. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12582. /// 01e0 <account id>.L <account name>.24B
  12583. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12584. {
  12585. WFIFOHEAD(fd,packet_len(0x1e0));
  12586. WFIFOW(fd,0) = 0x1e0;
  12587. WFIFOL(fd,2) = account_id;
  12588. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12589. WFIFOSET(fd,packet_len(0x1e0));
  12590. }
  12591. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12592. /// 01df <account id>.L
  12593. //! TODO: Figure out how does this actually work
  12594. void clif_parse_GMReqAccountName(int fd, map_session_data *sd)
  12595. {
  12596. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12597. /*
  12598. char query[30];
  12599. safesnprintf(query,sizeof(query),"%d", account_id);
  12600. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12601. */
  12602. clif_account_name(fd, account_id, "");
  12603. }
  12604. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12605. /// GM single cell type change request.
  12606. /// 0198 <x>.W <y>.W <type>.W
  12607. /// type:
  12608. /// 0 = not walkable
  12609. /// 1 = walkable
  12610. void clif_parse_GMChangeMapType(int fd, map_session_data *sd)
  12611. {
  12612. int x,y,type;
  12613. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12614. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12615. return;
  12616. x = RFIFOW(fd,info->pos[0]);
  12617. y = RFIFOW(fd,info->pos[1]);
  12618. type = RFIFOW(fd,info->pos[2]);
  12619. map_setgatcell(sd->bl.m,x,y,type);
  12620. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12621. //FIXME: once players leave the map, the client 'forgets' this information.
  12622. }
  12623. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12624. /// Request to allow/deny whispers from a nick.
  12625. /// 00cf <nick>.24B <type>.B
  12626. /// type:
  12627. /// 0 = (/ex nick) deny speech from nick
  12628. /// 1 = (/in nick) allow speech from nick
  12629. void clif_parse_PMIgnore(int fd, map_session_data* sd)
  12630. {
  12631. char* nick;
  12632. uint8 type;
  12633. int i;
  12634. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12635. nick = RFIFOCP(fd,info->pos[0]);
  12636. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12637. type = RFIFOB(fd,info->pos[1]);
  12638. if( type == 0 ) { // Add name to ignore list (block)
  12639. if (strcmp(wisp_server_name, nick) == 0) {
  12640. clif_wisexin(sd, type, 1); // fail
  12641. return;
  12642. }
  12643. // try to find a free spot, while checking for duplicates at the same time
  12644. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12645. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12646. clif_wisexin(sd, type, 2); // too many blocks
  12647. return;
  12648. }
  12649. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12650. clif_wisexin(sd, type, 0); // Aegis reports success.
  12651. return;
  12652. }
  12653. //Insert in position i
  12654. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12655. } else { // Remove name from ignore list (unblock)
  12656. // find entry
  12657. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12658. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12659. clif_wisexin(sd, type, 1); // fail
  12660. return;
  12661. }
  12662. // move everything one place down to overwrite removed entry
  12663. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12664. // wipe last entry
  12665. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12666. }
  12667. clif_wisexin(sd, type, 0); // success
  12668. }
  12669. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12670. /// Request to allow/deny all whispers.
  12671. /// 00d0 <type>.B
  12672. /// type:
  12673. /// 0 = (/exall) deny all speech
  12674. /// 1 = (/inall) allow all speech
  12675. void clif_parse_PMIgnoreAll(int fd, map_session_data *sd)
  12676. {
  12677. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12678. if( type == 0 ) {// Deny all
  12679. if( sd->state.ignoreAll ) {
  12680. flag = 1; // fail
  12681. } else {
  12682. sd->state.ignoreAll = 1;
  12683. flag = 0; // success
  12684. }
  12685. } else {//Unblock everyone
  12686. if( sd->state.ignoreAll ) {
  12687. sd->state.ignoreAll = 0;
  12688. flag = 0; // success
  12689. } else {
  12690. if (sd->ignore[0].name[0] != '\0')
  12691. { //Wipe the ignore list.
  12692. memset(sd->ignore, 0, sizeof(sd->ignore));
  12693. flag = 0; // success
  12694. } else {
  12695. flag = 1; // fail
  12696. }
  12697. }
  12698. }
  12699. clif_wisall(sd, type, flag);
  12700. }
  12701. /// Whisper ignore list (ZC_WHISPER_LIST).
  12702. /// 00d4 <packet len>.W { <char name>.24B }*
  12703. void clif_PMIgnoreList(map_session_data* sd)
  12704. {
  12705. int i, fd = sd->fd;
  12706. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12707. WFIFOW(fd,0) = 0xd4;
  12708. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12709. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12710. }
  12711. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12712. WFIFOSET(fd,WFIFOW(fd,2));
  12713. }
  12714. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12715. /// 00d3
  12716. void clif_parse_PMIgnoreList(int fd,map_session_data *sd)
  12717. {
  12718. clif_PMIgnoreList(sd);
  12719. }
  12720. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12721. /// 01e7
  12722. void clif_parse_NoviceDoriDori(int fd, map_session_data *sd)
  12723. {
  12724. if (sd->state.doridori) return;
  12725. switch (sd->class_&MAPID_UPPERMASK) {
  12726. case MAPID_SOUL_LINKER:
  12727. case MAPID_STAR_GLADIATOR:
  12728. case MAPID_TAEKWON:
  12729. if (!sd->state.rest)
  12730. break;
  12731. [[fallthrough]];
  12732. case MAPID_SUPER_NOVICE:
  12733. case MAPID_SUPER_BABY:
  12734. case MAPID_SUPER_NOVICE_E:
  12735. case MAPID_SUPER_BABY_E:
  12736. sd->state.doridori=1;
  12737. break;
  12738. }
  12739. }
  12740. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12741. /// 01ed
  12742. /// Note: This packet is caused by 7 lines of any text, followed by
  12743. /// the prayer and an another line of any text. The prayer is
  12744. /// defined by lines 790~793 in data\msgstringtable.txt
  12745. /// "Dear angel, can you hear my voice?"
  12746. /// "I am" (space separated player name) "Super Novice~"
  12747. /// "Help me out~ Please~ T_T"
  12748. void clif_parse_NoviceExplosionSpirits(int fd, map_session_data *sd)
  12749. {
  12750. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12751. t_exp next = pc_nextbaseexp(sd);
  12752. if( next ) {
  12753. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12754. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12755. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12756. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12757. }
  12758. }
  12759. }
  12760. }
  12761. /// Friends List
  12762. ///
  12763. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12764. /// 0206 <account id>.L <char id>.L <state>.B
  12765. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12766. /// state:
  12767. /// 0 = online
  12768. /// 1 = offline
  12769. void clif_friendslist_toggle(map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12770. {
  12771. int i, fd = sd->fd;
  12772. //Seek friend.
  12773. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12774. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12775. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12776. return; //Not found
  12777. WFIFOHEAD(fd,packet_len(0x206));
  12778. WFIFOW(fd, 0) = 0x206;
  12779. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12780. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12781. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12782. #if PACKETVER >= 20180221
  12783. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12784. #endif
  12785. WFIFOSET(fd, packet_len(0x206));
  12786. }
  12787. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12788. int clif_friendslist_toggle_sub(map_session_data *sd,va_list ap)
  12789. {
  12790. uint32 account_id, char_id, online;
  12791. account_id = va_arg(ap, int);
  12792. char_id = va_arg(ap, int);
  12793. online = va_arg(ap, int);
  12794. clif_friendslist_toggle(sd, account_id, char_id, online);
  12795. return 0;
  12796. }
  12797. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12798. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12799. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12800. void clif_friendslist_send( map_session_data& sd ){
  12801. struct PACKET_ZC_FRIENDS_LIST* p = (struct PACKET_ZC_FRIENDS_LIST*)packet_buffer;
  12802. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12803. p->PacketLength = sizeof( *p );
  12804. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12805. struct PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12806. f.AID = sd.status.friends[i].account_id;
  12807. f.CID = sd.status.friends[i].char_id;
  12808. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12809. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12810. #endif
  12811. c++;
  12812. p->PacketLength += sizeof( f );
  12813. }
  12814. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12815. // Sending the online players
  12816. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12817. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12818. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12819. }
  12820. }
  12821. }
  12822. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12823. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12824. /// result:
  12825. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12826. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12827. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12828. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12829. void clif_friendslist_reqack(map_session_data *sd, map_session_data *f_sd, int type)
  12830. {
  12831. int fd;
  12832. nullpo_retv(sd);
  12833. fd = sd->fd;
  12834. WFIFOHEAD(fd,packet_len(0x209));
  12835. WFIFOW(fd,0) = 0x209;
  12836. WFIFOW(fd,2) = type;
  12837. if (f_sd) {
  12838. WFIFOL(fd,4) = f_sd->status.account_id;
  12839. WFIFOL(fd,8) = f_sd->status.char_id;
  12840. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12841. }
  12842. WFIFOSET(fd, packet_len(0x209));
  12843. }
  12844. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12845. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12846. void clif_friendlist_req(map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12847. {
  12848. int fd = sd->fd;
  12849. WFIFOHEAD(fd,packet_len(0x207));
  12850. WFIFOW(fd,0) = 0x207;
  12851. WFIFOL(fd,2) = account_id;
  12852. WFIFOL(fd,6) = char_id;
  12853. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12854. WFIFOSET(fd,packet_len(0x207));
  12855. }
  12856. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12857. /// 0202 <name>.24B
  12858. void clif_parse_FriendsListAdd(int fd, map_session_data *sd)
  12859. {
  12860. map_session_data *f_sd;
  12861. int i;
  12862. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12863. // Friend doesn't exist (no player with this name)
  12864. if (f_sd == NULL) {
  12865. clif_displaymessage(fd, msg_txt(sd,3));
  12866. return;
  12867. }
  12868. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12869. return;
  12870. }
  12871. // ensure that the request player's friend list is not full
  12872. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12873. if( i == MAX_FRIENDS ){
  12874. clif_friendslist_reqack(sd, f_sd, 2);
  12875. return;
  12876. }
  12877. // @noask [LuzZza]
  12878. if(f_sd->state.noask) {
  12879. clif_noask_sub(sd, f_sd, 5);
  12880. return;
  12881. }
  12882. // Friend already exists
  12883. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12884. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12885. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12886. return;
  12887. }
  12888. }
  12889. f_sd->friend_req = sd->status.char_id;
  12890. sd->friend_req = f_sd->status.char_id;
  12891. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12892. }
  12893. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12894. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12895. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12896. /// reply:
  12897. /// 0 = rejected
  12898. /// 1 = accepted
  12899. void clif_parse_FriendsListReply(int fd, map_session_data *sd)
  12900. {
  12901. map_session_data *f_sd;
  12902. uint32 account_id;
  12903. char reply;
  12904. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12905. account_id = RFIFOL(fd,info->pos[0]);
  12906. //char_id = RFIFOL(fd,info->pos[1]);
  12907. #if PACKETVER < 6
  12908. reply = RFIFOB(fd,info->pos[2]);
  12909. #else
  12910. reply = RFIFOL(fd,info->pos[2]);
  12911. #endif
  12912. if( sd->bl.id == account_id ) {// adding oneself as friend
  12913. return;
  12914. }
  12915. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12916. if (f_sd == NULL)
  12917. return;
  12918. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12919. clif_friendslist_reqack(f_sd, sd, 1);
  12920. else {
  12921. int i;
  12922. // Find an empty slot
  12923. for (i = 0; i < MAX_FRIENDS; i++)
  12924. if (f_sd->status.friends[i].char_id == 0)
  12925. break;
  12926. if (i == MAX_FRIENDS) {
  12927. clif_friendslist_reqack(f_sd, sd, 2);
  12928. return;
  12929. }
  12930. f_sd->status.friends[i].account_id = sd->status.account_id;
  12931. f_sd->status.friends[i].char_id = sd->status.char_id;
  12932. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12933. clif_friendslist_reqack(f_sd, sd, 0);
  12934. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12935. if (battle_config.friend_auto_add) {
  12936. // Also add f_sd to sd's friendlist.
  12937. for (i = 0; i < MAX_FRIENDS; i++) {
  12938. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12939. return; //No need to add anything.
  12940. if (sd->status.friends[i].char_id == 0)
  12941. break;
  12942. }
  12943. if (i == MAX_FRIENDS) {
  12944. clif_friendslist_reqack(sd, f_sd, 2);
  12945. return;
  12946. }
  12947. sd->status.friends[i].account_id = f_sd->status.account_id;
  12948. sd->status.friends[i].char_id = f_sd->status.char_id;
  12949. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12950. clif_friendslist_reqack(sd, f_sd, 0);
  12951. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12952. }
  12953. }
  12954. }
  12955. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12956. /// 0203 <account id>.L <char id>.L
  12957. void clif_parse_FriendsListRemove(int fd, map_session_data *sd)
  12958. {
  12959. map_session_data *f_sd = NULL;
  12960. uint32 account_id, char_id;
  12961. int i, j;
  12962. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12963. account_id = RFIFOL(fd,info->pos[0]);
  12964. char_id = RFIFOL(fd,info->pos[1]);
  12965. // Search friend
  12966. for (i = 0; i < MAX_FRIENDS &&
  12967. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12968. if (i == MAX_FRIENDS) {
  12969. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12970. return;
  12971. }
  12972. //remove from friend's list first
  12973. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12974. for (i = 0; i < MAX_FRIENDS &&
  12975. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12976. if (i != MAX_FRIENDS) {
  12977. // move all chars up
  12978. for(j = i + 1; j < MAX_FRIENDS; j++)
  12979. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12980. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12981. //should the guy be notified of some message? we should add it here if so
  12982. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12983. WFIFOW(f_sd->fd,0) = 0x20a;
  12984. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12985. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12986. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12987. }
  12988. } else { //friend not online -- ask char server to delete from his friendlist
  12989. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12990. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12991. return;
  12992. }
  12993. }
  12994. // We can now delete from original requester
  12995. for (i = 0; i < MAX_FRIENDS &&
  12996. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12997. // move all chars up
  12998. for(j = i + 1; j < MAX_FRIENDS; j++)
  12999. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  13000. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  13001. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  13002. WFIFOHEAD(fd,packet_len(0x20a));
  13003. WFIFOW(fd,0) = 0x20a;
  13004. WFIFOL(fd,2) = account_id;
  13005. WFIFOL(fd,6) = char_id;
  13006. WFIFOSET(fd, packet_len(0x20a));
  13007. }
  13008. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  13009. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  13010. void clif_PVPInfo(map_session_data* sd)
  13011. {
  13012. int fd = sd->fd;
  13013. WFIFOHEAD(fd,packet_len(0x210));
  13014. WFIFOW(fd,0) = 0x210;
  13015. WFIFOL(fd,2) = sd->status.char_id;
  13016. WFIFOL(fd,6) = sd->status.account_id;
  13017. WFIFOL(fd,10) = sd->pvp_won; // times won
  13018. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  13019. WFIFOL(fd,18) = sd->pvp_point;
  13020. WFIFOSET(fd, packet_len(0x210));
  13021. }
  13022. /// /pvpinfo (CZ_REQ_PVPPOINT).
  13023. /// 020f <char id>.L <account id>.L
  13024. void clif_parse_PVPInfo(int fd,map_session_data *sd)
  13025. {
  13026. // TODO: Is there a way to use this on an another player (char/acc id)?
  13027. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13028. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13029. clif_PVPInfo(sd);
  13030. }
  13031. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  13032. /// 0254 <which>.B
  13033. /// which: (unused atm for security purpose)
  13034. /// 0 = sun
  13035. /// 1 = moon
  13036. /// 2 = star
  13037. void clif_parse_FeelSaveOk(int fd,map_session_data *sd)
  13038. {
  13039. int i;
  13040. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13041. if (sd->menuskill_id != SG_FEEL)
  13042. return;
  13043. i = sd->menuskill_val-1;
  13044. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  13045. sd->feel_map[i].index = map_id2index(sd->bl.m);
  13046. sd->feel_map[i].m = sd->bl.m;
  13047. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  13048. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  13049. // clif_misceffect2(&sd->bl, 0x1b0);
  13050. // clif_misceffect2(&sd->bl, 0x21f);
  13051. clif_feel_info(sd, i, 0);
  13052. clif_menuskill_clear(sd);
  13053. }
  13054. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  13055. /// 0253 <which>.B
  13056. /// which:
  13057. /// 0 = sun
  13058. /// 1 = moon
  13059. /// 2 = star
  13060. void clif_feel_req(int fd, map_session_data *sd, uint16 skill_lv)
  13061. {
  13062. WFIFOHEAD(fd,packet_len(0x253));
  13063. WFIFOW(fd,0)=0x253;
  13064. WFIFOB(fd,2)=TOB(skill_lv-1);
  13065. WFIFOSET(fd, packet_len(0x253));
  13066. sd->menuskill_id = SG_FEEL;
  13067. sd->menuskill_val = skill_lv;
  13068. }
  13069. /// Request to change homunculus' name (CZ_RENAME_MER).
  13070. /// 0231 <name>.24B
  13071. void clif_parse_ChangeHomunculusName(int fd, map_session_data *sd){
  13072. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13073. }
  13074. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  13075. /// 0234 <id>.L
  13076. void clif_parse_HomMoveToMaster(int fd, map_session_data *sd){
  13077. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  13078. struct block_list *bl = NULL;
  13079. struct unit_data *ud = NULL;
  13080. if( sd->md && sd->md->bl.id == id )
  13081. bl = &sd->md->bl;
  13082. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13083. bl = &sd->hd->bl; // Moving Homunculus
  13084. else
  13085. return;
  13086. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  13087. ud = unit_bl2ud(bl);
  13088. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  13089. }
  13090. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  13091. /// 0232 <id>.L <position data>.3B
  13092. void clif_parse_HomMoveTo(int fd, map_session_data *sd){
  13093. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13094. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  13095. struct block_list *bl = NULL;
  13096. short x, y;
  13097. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  13098. if( sd->md && sd->md->bl.id == id )
  13099. bl = &sd->md->bl; // Moving Mercenary
  13100. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13101. bl = &sd->hd->bl; // Moving Homunculus
  13102. else
  13103. return;
  13104. unit_walktoxy(bl, x, y, 4);
  13105. }
  13106. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  13107. /// 0233 <id>.L <target id>.L <action>.B
  13108. /// action:
  13109. /// always 0
  13110. void clif_parse_HomAttack(int fd,map_session_data *sd)
  13111. {
  13112. struct block_list *bl = NULL;
  13113. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13114. int id = RFIFOL(fd,info->pos[0]);
  13115. int target_id = RFIFOL(fd,info->pos[1]);
  13116. int action_type = RFIFOB(fd,info->pos[2]);
  13117. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13118. bl = &sd->hd->bl;
  13119. else if( sd->md && sd->md->bl.id == id )
  13120. bl = &sd->md->bl;
  13121. else return;
  13122. unit_stop_attack(bl);
  13123. unit_attack(bl, target_id, action_type != 0);
  13124. }
  13125. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13126. /// 022d <type>.W <command>.B
  13127. /// type:
  13128. /// always 0
  13129. /// command:
  13130. /// 0 = homunculus information
  13131. /// 1 = feed
  13132. /// 2 = delete
  13133. void clif_parse_HomMenu(int fd, map_session_data *sd)
  13134. { //[orn]
  13135. int cmd = RFIFOW(fd,0);
  13136. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13137. if(!hom_is_active(sd->hd))
  13138. return;
  13139. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13140. }
  13141. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13142. /// 0292
  13143. void clif_parse_AutoRevive(int fd, map_session_data *sd)
  13144. {
  13145. pc_revive_item(sd);
  13146. }
  13147. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13148. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13149. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13150. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13151. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13152. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13153. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13154. void clif_check(int fd, map_session_data* pl_sd)
  13155. {
  13156. WFIFOHEAD(fd,packet_len(0x214));
  13157. WFIFOW(fd, 0) = 0x214;
  13158. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13159. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13160. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13161. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13162. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13163. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13164. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13165. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13166. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13167. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13168. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13169. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13170. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13171. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13172. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13173. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13174. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13175. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13176. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13177. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13178. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13179. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13180. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13181. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13182. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13183. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13184. WFIFOSET(fd,packet_len(0x214));
  13185. }
  13186. /// /check (CZ_REQ_STATUS_GM).
  13187. /// Request character's status values.
  13188. /// 0213 <char name>.24B
  13189. void clif_parse_Check(int fd, map_session_data *sd)
  13190. {
  13191. char charname[NAME_LENGTH];
  13192. map_session_data* pl_sd;
  13193. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13194. return;
  13195. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13196. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13197. {
  13198. return;
  13199. }
  13200. clif_check(fd, pl_sd);
  13201. }
  13202. /// MAIL SYSTEM
  13203. /// By Zephyrus
  13204. ///
  13205. /// Notification about the result of adding an item to mail
  13206. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13207. /// result:
  13208. /// 0 = success
  13209. /// 1 = failure
  13210. /// 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)
  13211. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13212. /// result:
  13213. /// 0 = success
  13214. /// 1 = over weight
  13215. /// 2 = fatal error
  13216. void clif_Mail_setattachment( map_session_data* sd, int index, int amount, uint8 flag ){
  13217. int fd = sd->fd;
  13218. #if PACKETVER < 20150513
  13219. WFIFOHEAD(fd,packet_len(0x255));
  13220. WFIFOW(fd,0) = 0x255;
  13221. WFIFOW(fd,2) = index;
  13222. WFIFOB(fd,4) = flag;
  13223. WFIFOSET(fd,packet_len(0x255));
  13224. #else
  13225. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13226. if( flag ){
  13227. memset( &p, 0, sizeof( p ) );
  13228. }else{
  13229. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13230. p.index = index;
  13231. p.count = amount;
  13232. p.itemId = client_nameid( item->nameid );
  13233. p.type = itemtype( item->nameid );
  13234. p.IsIdentified = item->identify ? 1 : 0;
  13235. p.IsDamaged = item->attribute ? 1 : 0;
  13236. p.refiningLevel = item->refine;
  13237. clif_addcards( &p.slot, item );
  13238. clif_add_random_options( p.optionData, *item );
  13239. p.weight = 0;
  13240. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13241. if( sd->mail.item[i].nameid == 0 ){
  13242. continue;
  13243. }
  13244. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13245. }
  13246. p.favorite = ( item->favorite != 0 ) ? 1 : 0;
  13247. p.location = pc_equippoint( sd, server_index( index ) );
  13248. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13249. p.grade = item->enchantgrade;
  13250. #endif
  13251. }
  13252. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13253. p.result = flag;
  13254. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13255. #endif
  13256. }
  13257. /// Notification about the result of retrieving a mail attachment
  13258. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13259. /// result:
  13260. /// 0 = success
  13261. /// 1 = failure
  13262. /// 2 = too many items
  13263. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13264. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13265. void clif_mail_getattachment(map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13266. #if PACKETVER < 20150513
  13267. int fd = sd->fd;
  13268. WFIFOHEAD(fd,packet_len(0x245));
  13269. WFIFOW(fd,0) = 0x245;
  13270. WFIFOB(fd,2) = result;
  13271. WFIFOSET(fd,packet_len(0x245));
  13272. #else
  13273. switch( type ){
  13274. case MAIL_ATT_ITEM:
  13275. case MAIL_ATT_ZENY:
  13276. break;
  13277. default:
  13278. return;
  13279. }
  13280. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13281. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13282. p.MailID = msg->id;
  13283. p.opentype = msg->type;
  13284. p.result = result;
  13285. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13286. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13287. #endif
  13288. }
  13289. /// Notification about the result of sending a mail
  13290. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13291. /// result:
  13292. /// 0 = success
  13293. /// 1 = recipinent does not exist
  13294. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13295. void clif_Mail_send(map_session_data* sd, enum mail_send_result result){
  13296. #if PACKETVER < 20150513
  13297. int fd = sd->fd;
  13298. WFIFOHEAD(fd,packet_len(0x249));
  13299. WFIFOW(fd,0) = 0x249;
  13300. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13301. WFIFOSET(fd,packet_len(0x249));
  13302. #else
  13303. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13304. p.PacketType = rodexwriteresult;
  13305. p.result = result;
  13306. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13307. #endif
  13308. }
  13309. /// Notification about the result of deleting a mail.
  13310. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13311. /// result:
  13312. /// 0 = success
  13313. /// 1 = failure
  13314. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13315. void clif_mail_delete( map_session_data* sd, struct mail_message *msg, bool success ){
  13316. #if PACKETVER < 20150513
  13317. int fd = sd->fd;
  13318. WFIFOHEAD(fd, packet_len(0x257));
  13319. WFIFOW(fd,0) = 0x257;
  13320. WFIFOL(fd,2) = msg->id;
  13321. WFIFOW(fd,6) = !success;
  13322. WFIFOSET(fd, packet_len(0x257));
  13323. #else
  13324. // This is only a success notification
  13325. if( success ){
  13326. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13327. p.PacketType = rodexdelete;
  13328. p.opentype = msg->type;
  13329. p.MailID = msg->id;
  13330. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13331. }
  13332. #endif
  13333. }
  13334. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13335. /// 0274 <mail id>.L <result>.W
  13336. /// result:
  13337. /// 0 = success
  13338. /// 1 = failure
  13339. void clif_Mail_return(int fd, int mail_id, short fail)
  13340. {
  13341. WFIFOHEAD(fd,packet_len(0x274));
  13342. WFIFOW(fd,0) = 0x274;
  13343. WFIFOL(fd,2) = mail_id;
  13344. WFIFOW(fd,6) = fail;
  13345. WFIFOSET(fd,packet_len(0x274));
  13346. }
  13347. /// Notification about new mail.
  13348. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13349. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13350. void clif_Mail_new(map_session_data* sd, int mail_id, const char *sender, const char *title){
  13351. #if PACKETVER < 20150513
  13352. int fd = sd->fd;
  13353. WFIFOHEAD(fd,packet_len(0x24a));
  13354. WFIFOW(fd,0) = 0x24a;
  13355. WFIFOL(fd,2) = mail_id;
  13356. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13357. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13358. WFIFOSET(fd,packet_len(0x24a));
  13359. #else
  13360. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13361. p.PacketType = rodexicon;
  13362. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13363. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13364. #endif
  13365. }
  13366. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13367. /// 0260 <type>.L
  13368. /// type:
  13369. /// 0 = open
  13370. /// 1 = close
  13371. void clif_Mail_window(int fd, int flag)
  13372. {
  13373. WFIFOHEAD(fd,packet_len(0x260));
  13374. WFIFOW(fd,0) = 0x260;
  13375. WFIFOL(fd,2) = flag;
  13376. WFIFOSET(fd,packet_len(0x260));
  13377. }
  13378. /// Lists mails stored in inbox.
  13379. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13380. /// read:
  13381. /// 0 = unread
  13382. /// 1 = read
  13383. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13384. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13385. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13386. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13387. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13388. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13389. void clif_Mail_refreshinbox(map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13390. #if PACKETVER < 20150513
  13391. int fd = sd->fd;
  13392. struct mail_data *md = &sd->mail.inbox;
  13393. struct mail_message *msg;
  13394. int len, i, j;
  13395. len = 8 + (73 * md->amount);
  13396. WFIFOHEAD(fd,len);
  13397. WFIFOW(fd,0) = 0x240;
  13398. WFIFOW(fd,2) = len;
  13399. WFIFOL(fd,4) = md->amount;
  13400. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13401. {
  13402. msg = &md->msg[i];
  13403. if (msg->id < 1)
  13404. continue;
  13405. WFIFOL(fd,8+73*j) = msg->id;
  13406. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13407. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13408. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13409. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13410. j++;
  13411. }
  13412. WFIFOSET(fd,len);
  13413. if( md->full ) {// TODO: is this official?
  13414. char output[100];
  13415. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13416. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13417. }
  13418. #else
  13419. int fd = sd->fd;
  13420. struct mail_data *md = &sd->mail.inbox;
  13421. struct mail_message *msg;
  13422. int i, j, k, offset, titleLength;
  13423. uint8 mailType, amount, remaining;
  13424. uint32 now = (uint32)time(NULL);
  13425. #if PACKETVER >= 20170419
  13426. int cmd = 0xac2;
  13427. #elif PACKETVER >= 20160601
  13428. int cmd = 0xa7d;
  13429. #else
  13430. int cmd = 0x9f0;
  13431. #endif
  13432. if( battle_config.mail_daily_count ){
  13433. mail_refresh_remaining_amount(sd);
  13434. }
  13435. #if PACKETVER >= 20170419
  13436. // Always send all
  13437. i = md->amount;
  13438. #else
  13439. // If a starting mail id was sent
  13440. if( mailID != 0 ){
  13441. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13442. // Unknown mail
  13443. if( i == md->amount ){
  13444. // Ignore the request for now
  13445. return; // TODO: Should we just show the first page instead?
  13446. }
  13447. // It was actually the oldest/first mail, there is no further page
  13448. if( i == 0 ){
  13449. return;
  13450. }
  13451. // We actually want the next/older mail
  13452. i -= 1;
  13453. }else{
  13454. i = md->amount;
  13455. }
  13456. #endif
  13457. // Count the remaining mails from the starting mail or the beginning
  13458. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13459. for( j = i, remaining = 0; j >= 0; j-- ){
  13460. msg = &md->msg[j];
  13461. if (msg->id < 1)
  13462. continue;
  13463. #if PACKETVER < 20170419
  13464. if (msg->type != type)
  13465. continue;
  13466. #endif
  13467. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13468. continue;
  13469. remaining++;
  13470. }
  13471. #if PACKETVER >= 20170419
  13472. // Always send all
  13473. amount = remaining;
  13474. #else
  13475. if( remaining > MAIL_PAGE_SIZE ){
  13476. amount = MAIL_PAGE_SIZE;
  13477. }else{
  13478. amount = remaining;
  13479. }
  13480. #endif
  13481. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13482. WFIFOW(fd, 0) = cmd;
  13483. #if PACKETVER >= 20170419
  13484. WFIFOB(fd, 4) = 1; // Unknown
  13485. offset = 5;
  13486. #else
  13487. WFIFOB(fd, 4) = type;
  13488. WFIFOB(fd, 5) = amount;
  13489. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13490. offset = 7;
  13491. #endif
  13492. for( amount = 0; i >= 0; i-- ){
  13493. msg = &md->msg[i];
  13494. if (msg->id < 1)
  13495. continue;
  13496. #if PACKETVER < 20170419
  13497. if (msg->type != type)
  13498. continue;
  13499. #endif
  13500. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13501. continue;
  13502. #if PACKETVER >= 20170419
  13503. WFIFOB(fd, offset) = msg->type;
  13504. offset += 1;
  13505. #endif
  13506. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13507. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13508. mailType = MAIL_TYPE_TEXT; // Normal letter
  13509. if( msg->zeny > 0 ){
  13510. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13511. }
  13512. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13513. if( msg->item[k].nameid > 0 ){
  13514. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13515. break;
  13516. }
  13517. }
  13518. #if PACKETVER >= 20170419
  13519. // If it came from an npc?
  13520. if( !msg->send_id ){
  13521. mailType |= MAIL_TYPE_NPC;
  13522. }
  13523. #endif
  13524. WFIFOB(fd, offset + 9) = mailType;
  13525. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13526. #if PACKETVER < 20170419
  13527. // How much time has passed since you received the mail
  13528. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13529. offset += 4;
  13530. #endif
  13531. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13532. if( msg->scheduled_deletion > 0 ){
  13533. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13534. }else{
  13535. // Fake the scheduled deletion to one year in the future
  13536. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13537. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13538. }
  13539. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13540. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13541. offset += 40 + titleLength;
  13542. }
  13543. WFIFOW(fd, 2) = (int16)offset;
  13544. WFIFOSET(fd, offset);
  13545. #endif
  13546. }
  13547. /// Mail inbox list request.
  13548. /// 023f (CZ_MAIL_GET_LIST)
  13549. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13550. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13551. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13552. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13553. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13554. void clif_parse_Mail_refreshinbox(int fd, map_session_data *sd){
  13555. if( mail_invalid_operation( sd ) ){
  13556. return;
  13557. }
  13558. #if PACKETVER < 20150513
  13559. struct mail_data* md = &sd->mail.inbox;
  13560. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13561. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13562. else
  13563. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13564. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13565. mail_removezeny(sd, false);
  13566. #else
  13567. int cmd = RFIFOW(fd, 0);
  13568. #if PACKETVER < 20170419
  13569. uint8 openType = RFIFOB(fd, 2);
  13570. uint64 mailId = RFIFOQ(fd, 3);
  13571. #else
  13572. uint8 openType;
  13573. uint64 mailId = RFIFOQ(fd, 2);
  13574. int i;
  13575. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13576. if( i == MAIL_MAX_INBOX ){
  13577. openType = MAIL_INBOX_NORMAL;
  13578. mailId = 0;
  13579. }else{
  13580. openType = sd->mail.inbox.msg[i].type;
  13581. mailId = 0;
  13582. }
  13583. #endif
  13584. switch( openType ){
  13585. case MAIL_INBOX_NORMAL:
  13586. case MAIL_INBOX_ACCOUNT:
  13587. case MAIL_INBOX_RETURNED:
  13588. break;
  13589. default:
  13590. // Unknown type: ignore request
  13591. return;
  13592. }
  13593. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13594. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13595. return;
  13596. }
  13597. // If it is not a next page request
  13598. if( cmd != 0x9ee ){
  13599. mailId = 0;
  13600. }
  13601. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13602. #endif
  13603. }
  13604. /// Opens a mail
  13605. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13606. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13607. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13608. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13609. /// { }*n
  13610. // TODO: Packet description => for repeated block
  13611. void clif_Mail_read( map_session_data *sd, int mail_id ){
  13612. int i, fd = sd->fd;
  13613. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13614. if( i == MAIL_MAX_INBOX ) {
  13615. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13616. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13617. return;
  13618. } else {
  13619. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13620. struct item *item;
  13621. int msg_len = strlen(msg->body);
  13622. if( msg_len == 0 ) {
  13623. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13624. msg_len = strlen(msg->body);
  13625. }
  13626. #if PACKETVER < 20150513
  13627. item = &msg->item[0];
  13628. int len = 101 + msg_len;
  13629. WFIFOHEAD(fd,len);
  13630. WFIFOW(fd,0) = 0x242;
  13631. WFIFOW(fd,2) = len;
  13632. WFIFOL(fd,4) = msg->id;
  13633. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13634. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13635. WFIFOL(fd,72) = 0;
  13636. WFIFOL(fd,76) = msg->zeny;
  13637. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13638. if( item->nameid && data != nullptr ) {
  13639. WFIFOL(fd,80) = item->amount;
  13640. WFIFOW(fd,84) = client_nameid( item->nameid );
  13641. WFIFOW(fd,86) = itemtype( item->nameid );
  13642. WFIFOB(fd,88) = item->identify;
  13643. WFIFOB(fd,89) = item->attribute;
  13644. WFIFOB(fd,90) = item->refine;
  13645. WFIFOW(fd,91) = item->card[0];
  13646. WFIFOW(fd,93) = item->card[1];
  13647. WFIFOW(fd,95) = item->card[2];
  13648. WFIFOW(fd,97) = item->card[3];
  13649. } else // no item, set all to zero
  13650. memset(WFIFOP(fd,80), 0x00, 19);
  13651. WFIFOB(fd,99) = (unsigned char)msg_len;
  13652. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13653. WFIFOSET(fd,len);
  13654. #else
  13655. msg_len += 1; // Zero Termination
  13656. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13657. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13658. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13659. p->opentype = msg->type;
  13660. p->MailID = msg->id;
  13661. p->TextcontentsLength = msg_len;
  13662. p->zeny = msg->zeny;
  13663. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13664. p->PacketLength += p->TextcontentsLength;
  13665. p->ItemCnt = 0;
  13666. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13667. item = &msg->item[j];
  13668. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13669. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13670. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13671. mailitem->ITID = client_nameid( item->nameid );
  13672. mailitem->count = item->amount;
  13673. mailitem->type = itemtype( item->nameid );
  13674. mailitem->IsIdentified = item->identify ? 1 : 0;
  13675. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13676. mailitem->refiningLevel = item->refine;
  13677. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13678. mailitem->viewSprite = data->look;
  13679. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13680. clif_addcards( &mailitem->slot, item );
  13681. clif_add_random_options( mailitem->option_data, *item );
  13682. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13683. mailitem->grade = item->enchantgrade;
  13684. #endif
  13685. p->PacketLength += sizeof( *mailitem );
  13686. p->ItemCnt++;
  13687. }
  13688. }
  13689. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13690. #endif
  13691. if (msg->status == MAIL_UNREAD) {
  13692. msg->status = MAIL_READ;
  13693. intif_Mail_read(mail_id);
  13694. clif_parse_Mail_refreshinbox(fd, sd);
  13695. sd->mail.inbox.unread--;
  13696. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13697. }
  13698. }
  13699. }
  13700. /// Request to open a mail.
  13701. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13702. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13703. void clif_parse_Mail_read(int fd, map_session_data *sd){
  13704. #if PACKETVER < 20150513
  13705. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13706. #else
  13707. //uint8 openType = RFIFOB(fd, 2);
  13708. int mail_id = (int)RFIFOQ(fd, 3);
  13709. #endif
  13710. if( mail_id <= 0 )
  13711. return;
  13712. if( mail_invalid_operation(sd) )
  13713. return;
  13714. clif_Mail_read(sd, mail_id);
  13715. }
  13716. /// Allow a player to begin writing a mail
  13717. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13718. void clif_send_Mail_beginwrite_ack( map_session_data *sd, char* name, bool success ){
  13719. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13720. p.PacketType = rodexopenwrite;
  13721. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13722. p.result = success;
  13723. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13724. }
  13725. /// Request to start writing a mail
  13726. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13727. void clif_parse_Mail_beginwrite( int fd, map_session_data *sd ){
  13728. char name[NAME_LENGTH];
  13729. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13730. if( mail_invalid_operation( sd ) ){
  13731. return;
  13732. }
  13733. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13734. clif_send_Mail_beginwrite_ack(sd, name, false);
  13735. return;
  13736. }
  13737. mail_clear(sd);
  13738. sd->state.mail_writing = true;
  13739. clif_send_Mail_beginwrite_ack(sd, name,true);
  13740. }
  13741. /// Notification that the client cancelled writing a mail
  13742. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13743. void clif_parse_Mail_cancelwrite( int fd, map_session_data *sd ){
  13744. sd->state.mail_writing = false;
  13745. }
  13746. /// Give the client information about the recipient, if available
  13747. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13748. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13749. void clif_Mail_Receiver_Ack( map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13750. #if PACKETVER >= 20141119
  13751. PACKET_ZC_CHECKNAME p = { 0 };
  13752. p.PacketType = HEADER_ZC_CHECKNAME;
  13753. p.CharId = char_id;
  13754. p.Class = class_;
  13755. p.BaseLevel = level;
  13756. #if PACKETVER >= 20160302
  13757. strncpy(p.Name, name, NAME_LENGTH);
  13758. #endif
  13759. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13760. #endif
  13761. }
  13762. /// Request information about the recipient
  13763. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13764. void clif_parse_Mail_Receiver_Check(int fd, map_session_data *sd) {
  13765. #if PACKETVER >= 20140423
  13766. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13767. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13768. #else
  13769. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13770. #endif
  13771. static char name[NAME_LENGTH];
  13772. if( mail_invalid_operation( sd ) ){
  13773. return;
  13774. }
  13775. safestrncpy(name, p->Name, NAME_LENGTH);
  13776. intif_mail_checkreceiver(sd, name);
  13777. #endif
  13778. }
  13779. /// Request to receive mail's attachment.
  13780. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13781. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13782. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13783. void clif_parse_Mail_getattach( int fd, map_session_data *sd ){
  13784. int i;
  13785. struct mail_message* msg;
  13786. #if PACKETVER < 20150513
  13787. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13788. int attachment = MAIL_ATT_ALL;
  13789. #else
  13790. uint16 packet_id = RFIFOW(fd, 0);
  13791. int mail_id = (int)RFIFOQ(fd, 2);
  13792. //int openType = RFIFOB(fd, 10);
  13793. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13794. #endif
  13795. if( !chrif_isconnected() )
  13796. return;
  13797. if( mail_id <= 0 )
  13798. return;
  13799. if( mail_invalid_operation(sd) )
  13800. return;
  13801. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13802. if( i == MAIL_MAX_INBOX )
  13803. return;
  13804. msg = &sd->mail.inbox.msg[i];
  13805. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13806. attachment &= ~MAIL_ATT_ZENY;
  13807. }
  13808. if( attachment&MAIL_ATT_ITEM ){
  13809. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13810. // No items were found
  13811. if( i == MAIL_MAX_ITEM ){
  13812. attachment &= ~MAIL_ATT_ITEM;
  13813. }
  13814. }
  13815. // Either no attachment requested at all or there are no zeny or items in the mail
  13816. if( attachment == MAIL_ATT_NONE ){
  13817. return;
  13818. }
  13819. if( attachment&MAIL_ATT_ZENY ){
  13820. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13821. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13822. return;
  13823. }else{
  13824. // Store the pending zeny (required for the "retrieve all" feature)
  13825. sd->mail.pending_zeny += msg->zeny;
  13826. // To make sure another request fails
  13827. msg->zeny = 0;
  13828. }
  13829. }
  13830. if( attachment&MAIL_ATT_ITEM ){
  13831. int slots = 0, totalweight = 0;
  13832. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13833. struct item* item = &msg->item[i];
  13834. if( item->nameid > 0 && item->amount > 0 ){
  13835. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13836. if(data == nullptr)
  13837. continue;
  13838. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13839. case CHKADDITEM_NEW:
  13840. slots += data->inventorySlotNeeded( item->amount );
  13841. break;
  13842. case CHKADDITEM_OVERAMOUNT:
  13843. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13844. return;
  13845. }
  13846. totalweight += data->weight * item->amount;
  13847. }
  13848. }
  13849. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13850. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13851. return;
  13852. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13853. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13854. return;
  13855. }
  13856. // To make sure another request fails
  13857. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13858. // Store the pending weight (required for the "retrieve all" feature)
  13859. sd->mail.pending_weight += totalweight;
  13860. // Store the pending slots (required for the "retrieve all" feature)
  13861. sd->mail.pending_slots += slots;
  13862. }
  13863. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13864. }
  13865. /// Request to delete a mail.
  13866. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13867. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13868. void clif_parse_Mail_delete(int fd, map_session_data *sd){
  13869. #if PACKETVER < 20150513
  13870. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13871. #else
  13872. //int openType = RFIFOB(fd, 2);
  13873. int mail_id = (int)RFIFOQ(fd, 3);
  13874. #endif
  13875. int i, j;
  13876. if( !chrif_isconnected() )
  13877. return;
  13878. if( mail_id <= 0 )
  13879. return;
  13880. if( mail_invalid_operation(sd) )
  13881. return;
  13882. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13883. if (i < MAIL_MAX_INBOX) {
  13884. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13885. // can't delete mail without removing zeny first
  13886. if( msg->zeny > 0 ){
  13887. clif_mail_delete(sd, msg, false);
  13888. return;
  13889. }
  13890. // can't delete mail without removing attachment(s) first
  13891. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13892. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13893. clif_mail_delete(sd, msg, false);
  13894. return;
  13895. }
  13896. }
  13897. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13898. sd->mail.inbox.unread--;
  13899. clif_Mail_new(sd,0,NULL,NULL);
  13900. }
  13901. }
  13902. }
  13903. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13904. /// 0273 <mail id>.L <receive name>.24B
  13905. void clif_parse_Mail_return(int fd, map_session_data *sd){
  13906. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13907. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13908. //ShowDump( p, sizeof( p ) );
  13909. int mail_id = p->msgId;
  13910. // not supported for now
  13911. return;
  13912. #else
  13913. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13914. #endif
  13915. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13916. int i;
  13917. if( mail_id <= 0 )
  13918. return;
  13919. if( mail_invalid_operation(sd) )
  13920. return;
  13921. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13922. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13923. intif_Mail_return(sd->status.char_id, mail_id);
  13924. else
  13925. clif_Mail_return(sd->fd, mail_id, 1);
  13926. }
  13927. /// Request to add an item or Zeny to mail.
  13928. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13929. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13930. void clif_parse_Mail_setattach(int fd, map_session_data *sd){
  13931. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13932. uint16 idx = RFIFOW(fd,info->pos[0]);
  13933. #if PACKETVER < 20150513
  13934. int amount = RFIFOL(fd,info->pos[1]);
  13935. #else
  13936. int amount = RFIFOW(fd,info->pos[1]);
  13937. #endif
  13938. unsigned char flag;
  13939. if( !chrif_isconnected() )
  13940. return;
  13941. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13942. return;
  13943. if (sd->inventory_data[server_index(idx)] == nullptr)
  13944. return;
  13945. if( mail_invalid_operation( sd ) ){
  13946. return;
  13947. }
  13948. flag = mail_setitem(sd, idx, amount);
  13949. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13950. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13951. }else{
  13952. clif_Mail_setattachment(sd,idx,amount,flag);
  13953. }
  13954. }
  13955. /// Remove an item from a mail
  13956. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13957. void clif_mail_removeitem( map_session_data* sd, bool success, int index, int amount ){
  13958. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13959. p.PacketType = rodexremoveitem;
  13960. p.result = success;
  13961. p.index = index;
  13962. p.cnt = amount;
  13963. int total = 0;
  13964. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13965. if( sd->mail.item[i].nameid == 0 ){
  13966. break;
  13967. }
  13968. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13969. }
  13970. p.weight = total;
  13971. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13972. }
  13973. /// Request to reset mail item and/or Zeny
  13974. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13975. /// type:
  13976. /// 0 = reset all
  13977. /// 1 = remove item
  13978. /// 2 = remove zeny
  13979. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13980. void clif_parse_Mail_winopen(int fd, map_session_data *sd)
  13981. {
  13982. #if PACKETVER < 20150513
  13983. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13984. if (type == 0 || type == 1)
  13985. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13986. if (type == 0 || type == 2)
  13987. mail_removezeny(sd, false);
  13988. #else
  13989. uint16 index = RFIFOW(fd, 2);
  13990. uint16 count = RFIFOW(fd, 4);
  13991. mail_removeitem(sd,0,index,count);
  13992. #endif
  13993. }
  13994. /// Request to send mail
  13995. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13996. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13997. /// 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)
  13998. void clif_parse_Mail_send(int fd, map_session_data *sd){
  13999. #if PACKETVER < 20150513
  14000. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14001. if( !chrif_isconnected() )
  14002. return;
  14003. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  14004. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  14005. return;
  14006. }
  14007. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  14008. #else
  14009. uint16 length = RFIFOW(fd, 2);
  14010. if( length < 0x3e ){
  14011. ShowWarning("Too short...\n");
  14012. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  14013. return;
  14014. }
  14015. if( mail_invalid_operation( sd ) ){
  14016. return;
  14017. }
  14018. // Forged request without a begin writing packet?
  14019. if( !sd->state.mail_writing ){
  14020. return; // Ignore it
  14021. }
  14022. char receiver[NAME_LENGTH];
  14023. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  14024. // char sender[NAME_LENGTH];
  14025. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  14026. uint64 zeny = RFIFOQ(fd, 52);
  14027. uint16 titleLength = RFIFOW(fd, 60);
  14028. uint16 textLength = RFIFOW(fd, 62);
  14029. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  14030. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  14031. char title[MAIL_TITLE_LENGTH];
  14032. char text[MAIL_BODY_LENGTH];
  14033. #if PACKETVER <= 20160330
  14034. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  14035. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  14036. #else
  14037. // 64 = <char id>.L
  14038. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  14039. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  14040. #endif
  14041. if( zeny > 0 ){
  14042. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  14043. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  14044. return;
  14045. }
  14046. }
  14047. mail_send(sd, receiver, title, text, realTextLength);
  14048. #endif
  14049. }
  14050. /// AUCTION SYSTEM
  14051. /// By Zephyrus
  14052. ///
  14053. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  14054. /// 025f <type>.L
  14055. /// type:
  14056. /// 0 = open
  14057. /// 1 = close
  14058. void clif_Auction_openwindow(map_session_data *sd)
  14059. {
  14060. int fd = sd->fd;
  14061. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  14062. return;
  14063. if( !battle_config.feature_auction )
  14064. return;
  14065. WFIFOHEAD(fd,packet_len(0x25f));
  14066. WFIFOW(fd,0) = 0x25f;
  14067. WFIFOL(fd,2) = 0;
  14068. WFIFOSET(fd,packet_len(0x25f));
  14069. }
  14070. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  14071. /// 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 }*
  14072. void clif_Auction_results(map_session_data *sd, short count, short pages, uint8 *buf)
  14073. {
  14074. int i, fd = sd->fd, len = sizeof(struct auction_data);
  14075. struct auction_data auction;
  14076. WFIFOHEAD(fd,12 + (count * 83));
  14077. WFIFOW(fd,0) = 0x252;
  14078. WFIFOW(fd,2) = 12 + (count * 83);
  14079. WFIFOL(fd,4) = pages;
  14080. WFIFOL(fd,8) = count;
  14081. for( i = 0; i < count; i++ ) {
  14082. int k = 12 + (i * 83);
  14083. memcpy(&auction, RBUFP(buf,i * len), len);
  14084. WFIFOL(fd,k) = auction.auction_id;
  14085. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  14086. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  14087. WFIFOL(fd,30+k) = auction.type;
  14088. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  14089. WFIFOB(fd,36+k) = auction.item.identify;
  14090. WFIFOB(fd,37+k) = auction.item.attribute;
  14091. WFIFOB(fd,38+k) = auction.item.refine;
  14092. WFIFOW(fd,39+k) = auction.item.card[0];
  14093. WFIFOW(fd,41+k) = auction.item.card[1];
  14094. WFIFOW(fd,43+k) = auction.item.card[2];
  14095. WFIFOW(fd,45+k) = auction.item.card[3];
  14096. WFIFOL(fd,47+k) = auction.price;
  14097. WFIFOL(fd,51+k) = auction.buynow;
  14098. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  14099. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  14100. }
  14101. WFIFOSET(fd,WFIFOW(fd,2));
  14102. }
  14103. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  14104. /// 0256 <index>.W <result>.B
  14105. /// result:
  14106. /// 0 = success
  14107. /// 1 = failure
  14108. static void clif_Auction_setitem(int fd, int index, bool fail)
  14109. {
  14110. WFIFOHEAD(fd,packet_len(0x256));
  14111. WFIFOW(fd,0) = 0x256;
  14112. WFIFOW(fd,2) = index;
  14113. WFIFOB(fd,4) = fail;
  14114. WFIFOSET(fd,packet_len(0x256));
  14115. }
  14116. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  14117. /// 024b <type>.W
  14118. /// type:
  14119. /// 0 = create (any other action in auction window)
  14120. /// 1 = cancel (cancel pressed on register tab)
  14121. /// ? = junk, uninitialized value (ex. when switching between list filters)
  14122. void clif_parse_Auction_cancelreg(int fd, map_session_data *sd){
  14123. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14124. if( sd->auction.amount > 0 )
  14125. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  14126. sd->auction.amount = 0;
  14127. }
  14128. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  14129. /// 024c <index>.W <count>.L
  14130. void clif_parse_Auction_setitem(int fd, map_session_data *sd){
  14131. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14132. int idx = RFIFOW(fd,info->pos[0]) - 2;
  14133. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  14134. if( !battle_config.feature_auction )
  14135. return;
  14136. if( sd->auction.amount > 0 )
  14137. sd->auction.amount = 0;
  14138. if( idx < 0 || idx >= MAX_INVENTORY ) {
  14139. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  14140. return;
  14141. }
  14142. 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.
  14143. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  14144. return;
  14145. }
  14146. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  14147. 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) )
  14148. { // Consumable or pets are not allowed
  14149. clif_Auction_setitem(sd->fd, idx, true);
  14150. return;
  14151. }
  14152. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  14153. !sd->inventory.u.items_inventory[idx].identify ||
  14154. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  14155. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  14156. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  14157. clif_Auction_setitem(sd->fd, idx, true);
  14158. return;
  14159. }
  14160. sd->auction.index = idx;
  14161. sd->auction.amount = amount;
  14162. clif_Auction_setitem(fd, idx + 2, false);
  14163. }
  14164. /// Result from an auction action (ZC_AUCTION_RESULT).
  14165. /// 0250 <result>.B
  14166. /// result:
  14167. /// 0 = You have failed to bid into the auction
  14168. /// 1 = You have successfully bid in the auction
  14169. /// 2 = The auction has been canceled
  14170. /// 3 = An auction with at least one bidder cannot be canceled
  14171. /// 4 = You cannot register more than 5 items in an auction at a time
  14172. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14173. /// 6 = You have won the auction
  14174. /// 7 = You have failed to win the auction
  14175. /// 8 = You do not have enough Zeny
  14176. /// 9 = You cannot place more than 5 bids at a time
  14177. void clif_Auction_message(int fd, unsigned char flag)
  14178. {
  14179. WFIFOHEAD(fd,packet_len(0x250));
  14180. WFIFOW(fd,0) = 0x250;
  14181. WFIFOB(fd,2) = flag;
  14182. WFIFOSET(fd,packet_len(0x250));
  14183. }
  14184. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14185. /// 025e <result>.W
  14186. /// result:
  14187. /// 0 = You have ended the auction
  14188. /// 1 = You cannot end the auction
  14189. /// 2 = Auction ID is incorrect
  14190. void clif_Auction_close(int fd, unsigned char flag)
  14191. {
  14192. WFIFOHEAD(fd,packet_len(0x25e));
  14193. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14194. WFIFOW(fd,2) = flag;
  14195. WFIFOSET(fd,packet_len(0x25e));
  14196. }
  14197. /// Request to add an auction (CZ_AUCTION_ADD).
  14198. /// 024d <now money>.L <max money>.L <delete hour>.W
  14199. void clif_parse_Auction_register(int fd, map_session_data *sd)
  14200. {
  14201. struct auction_data auction;
  14202. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14203. if( !battle_config.feature_auction )
  14204. return;
  14205. auction.price = RFIFOL(fd,info->pos[0]);
  14206. auction.buynow = RFIFOL(fd,info->pos[1]);
  14207. auction.hours = RFIFOW(fd,info->pos[2]);
  14208. // Invalid Situations...
  14209. if( sd->auction.amount < 1 ) {
  14210. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14211. return;
  14212. }
  14213. if( auction.price >= auction.buynow ) {
  14214. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14215. return;
  14216. }
  14217. if( auction.hours < 1 || auction.hours > 48 ) {
  14218. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14219. return;
  14220. }
  14221. // Auction checks...
  14222. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14223. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14224. clif_Auction_message(fd, 2); // The auction has been canceled
  14225. return;
  14226. }
  14227. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14228. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14229. return;
  14230. }
  14231. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14232. auction.buynow = battle_config.auction_maximumprice;
  14233. if( auction.price >= auction.buynow )
  14234. auction.price = auction.buynow - 1;
  14235. }
  14236. auction.auction_id = 0;
  14237. auction.seller_id = sd->status.char_id;
  14238. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14239. auction.buyer_id = 0;
  14240. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14241. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14242. {
  14243. clif_Auction_message(fd, 2); // The auction has been canceled
  14244. return;
  14245. }
  14246. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14247. if( id == nullptr )
  14248. { // Just in case
  14249. clif_Auction_message(fd, 2); // The auction has been canceled
  14250. return;
  14251. }
  14252. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14253. auction.type = id->type;
  14254. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14255. auction.item.amount = 1;
  14256. auction.timestamp = 0;
  14257. if( !intif_Auction_register(&auction) )
  14258. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14259. else
  14260. {
  14261. int zeny = auction.hours*battle_config.auction_feeperhour;
  14262. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14263. sd->auction.amount = 0;
  14264. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION);
  14265. }
  14266. }
  14267. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14268. /// 024e <auction id>.L
  14269. void clif_parse_Auction_cancel(int fd, map_session_data *sd){
  14270. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14271. intif_Auction_cancel(sd->status.char_id, auction_id);
  14272. }
  14273. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14274. /// 025d <auction id>.L
  14275. void clif_parse_Auction_close(int fd, map_session_data *sd){
  14276. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14277. intif_Auction_close(sd->status.char_id, auction_id);
  14278. }
  14279. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14280. /// 024f <auction id>.L <money>.L
  14281. void clif_parse_Auction_bid(int fd, map_session_data *sd){
  14282. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14283. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14284. int bid = RFIFOL(fd,info->pos[1]);
  14285. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14286. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14287. return;
  14288. }
  14289. if( bid <= 0 )
  14290. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14291. else if( bid > sd->status.zeny )
  14292. clif_Auction_message(fd, 8); // You do not have enough zeny
  14293. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14294. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14295. else {
  14296. pc_payzeny(sd, bid, LOG_TYPE_AUCTION);
  14297. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14298. }
  14299. }
  14300. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14301. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14302. /// search type:
  14303. /// 0 = armor
  14304. /// 1 = weapon
  14305. /// 2 = card
  14306. /// 3 = misc
  14307. /// 4 = name search
  14308. /// 5 = auction id search
  14309. void clif_parse_Auction_search(int fd, map_session_data* sd){
  14310. char search_text[NAME_LENGTH];
  14311. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14312. short type = RFIFOW(fd,info->pos[0]);
  14313. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14314. int page = RFIFOW(fd,info->pos[3]);
  14315. if( !battle_config.feature_auction )
  14316. return;
  14317. clif_parse_Auction_cancelreg(fd, sd);
  14318. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14319. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14320. }
  14321. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14322. /// 025c <type>.W
  14323. /// type:
  14324. /// 0 = sell (own auctions)
  14325. /// 1 = buy (own bids)
  14326. void clif_parse_Auction_buysell(int fd, map_session_data* sd)
  14327. {
  14328. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14329. if( !battle_config.feature_auction )
  14330. return;
  14331. clif_parse_Auction_cancelreg(fd, sd);
  14332. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14333. }
  14334. /// CASH/POINT SHOP
  14335. ///
  14336. void clif_cashshop_open( map_session_data* sd, int tab ){
  14337. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14338. nullpo_retv( sd );
  14339. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14340. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14341. p.cashPoints = sd->cashPoints;
  14342. p.kafraPoints = sd->kafraPoints;
  14343. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14344. p.tab = tab;
  14345. #endif
  14346. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14347. #endif
  14348. }
  14349. void clif_parse_cashshop_open_request( int fd, map_session_data* sd ){
  14350. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14351. nullpo_retv( sd );
  14352. int tab = 0;
  14353. #if PACKETVER >= 20191224
  14354. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14355. tab = p->tab;
  14356. #endif
  14357. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14358. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14359. return;
  14360. }
  14361. sd->state.cashshop_open = true;
  14362. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14363. clif_cashshop_open( sd, tab );
  14364. #endif
  14365. }
  14366. void clif_parse_cashshop_close( int fd, map_session_data* sd ){
  14367. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14368. sd->state.cashshop_open = false;
  14369. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14370. // No need to do anything here
  14371. #endif
  14372. }
  14373. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14374. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14375. void clif_parse_CashShopReqTab(int fd, map_session_data *sd) {
  14376. #if PACKETVER_MAIN_NUM >= 20100824 || PACKETVER_RE_NUM >= 20100824 || defined(PACKETVER_ZERO)
  14377. struct PACKET_CZ_REQ_SE_CASH_TAB_CODE* p_in = (struct PACKET_CZ_REQ_SE_CASH_TAB_CODE*)RFIFOP( fd, 0 );
  14378. // TODO: most likely wrong answer packet. Most likely HEADER_ZC_ACK_SE_CASH_ITEM_LIST (0x847) would be correct [Lemongrass]
  14379. // [4144] packet exists only in 2011 and was dropped after
  14380. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14381. std::shared_ptr<s_cash_item_tab> tab = cash_shop_db.find( static_cast<e_cash_shop_tab>( p_in->tab ) );
  14382. if( tab == nullptr ){
  14383. return;
  14384. }
  14385. // Skip empty tabs, the client only expects filled ones
  14386. if( tab->items.empty() ){
  14387. return;
  14388. }
  14389. #if !(PACKETVER_SUPPORTS_SALES)
  14390. if( tab->tab == CASHSHOP_TAB_SALE ){
  14391. return;
  14392. }
  14393. #endif
  14394. struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2* p = (struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2*)packet_buffer;
  14395. p->packetType = HEADER_ZC_ACK_SE_CASH_ITEM_LIST2;
  14396. p->packetLength = sizeof( struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2 );
  14397. p->tab = tab->tab;
  14398. p->count = 0;
  14399. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14400. p->items[p->count].itemId = client_nameid( item->nameid );
  14401. p->items[p->count].price = item->price;
  14402. p->packetLength += sizeof( struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2_sub );
  14403. p->count++;
  14404. }
  14405. clif_send( p, p->packetLength, &sd->bl, SELF );
  14406. #endif
  14407. #endif
  14408. }
  14409. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14410. void clif_cashshop_list( map_session_data* sd ){
  14411. nullpo_retv( sd );
  14412. for( const auto& pair : cash_shop_db ){
  14413. std::shared_ptr<s_cash_item_tab> tab = pair.second;
  14414. // Skip empty tabs, the client only expects filled ones
  14415. if( tab->items.empty() ){
  14416. continue;
  14417. }
  14418. #if !(PACKETVER_SUPPORTS_SALES)
  14419. if( tab->tab == CASHSHOP_TAB_SALE ){
  14420. continue;
  14421. }
  14422. #endif
  14423. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)packet_buffer;
  14424. p->packetType = HEADER_ZC_ACK_SCHEDULER_CASHITEM;
  14425. p->packetLength = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM );
  14426. p->count = 0;
  14427. p->tabNum = tab->tab;
  14428. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14429. p->items[p->count].itemId = client_nameid( item->nameid );
  14430. p->items[p->count].price = item->price;
  14431. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14432. struct item_data* id = itemdb_search( item->nameid );
  14433. if( id == nullptr ){
  14434. p->items[p->count].location = 0;
  14435. p->items[p->count].viewSprite = 0;
  14436. }else{
  14437. p->items[p->count].location = pc_equippoint_sub( sd, id );
  14438. p->items[p->count].viewSprite = id->look;
  14439. }
  14440. #endif
  14441. p->count++;
  14442. p->packetLength += sizeof( p->items[0] );
  14443. if( ( static_cast<size_t>( p->packetLength ) + sizeof( p->items[0] ) ) >= INT16_MAX ){
  14444. // Send current data
  14445. clif_send( p, p->packetLength, &sd->bl, SELF );
  14446. // Start a new packet
  14447. p->count = 0;
  14448. p->packetLength = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM );
  14449. }
  14450. }
  14451. clif_send( p, p->packetLength, &sd->bl, SELF );
  14452. }
  14453. }
  14454. void clif_parse_cashshop_list_request( int fd, map_session_data* sd ){
  14455. if( !sd->status.cashshop_sent ) {
  14456. clif_cashshop_list( sd );
  14457. #if PACKETVER_SUPPORTS_SALES
  14458. sale_notify_login(sd);
  14459. #endif
  14460. sd->status.cashshop_sent = true;
  14461. }
  14462. }
  14463. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14464. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14465. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14466. void clif_cashshop_show( map_session_data *sd, struct npc_data *nd ){
  14467. nullpo_retv( sd );
  14468. nullpo_retv( nd );
  14469. int fd = sd->fd;
  14470. if( !session_isActive( fd ) ){
  14471. return;
  14472. }
  14473. sd->npc_shopid = nd->bl.id;
  14474. int cost[2] = { 0, 0 };
  14475. npc_shop_currency_type( sd, nd, cost, true );
  14476. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST*)packet_buffer;
  14477. p->packetType = HEADER_ZC_PC_CASH_POINT_ITEMLIST;
  14478. p->packetLength = sizeof( *p );
  14479. p->cashPoints = cost[0];
  14480. #if PACKETVER >= 20070711
  14481. p->kafraPoints = cost[1];
  14482. #endif
  14483. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14484. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14485. p->items[i].price = nd->u.shop.shop_item[i].value;
  14486. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14487. p->items[i].itemType = itemtype( id->nameid );
  14488. p->items[i].itemId = client_nameid( id->nameid );
  14489. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14490. p->items[i].location = pc_equippoint_sub( sd, id );
  14491. p->items[i].viewSprite = id->look;
  14492. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14493. #endif
  14494. p->packetLength += sizeof( p->items[0] );
  14495. }
  14496. clif_send( p, p->packetLength, &sd->bl, SELF );
  14497. }
  14498. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14499. /// 0289 <cash point>.L <error>.W
  14500. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14501. /// error:
  14502. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14503. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14504. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14505. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14506. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14507. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14508. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14509. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14510. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14511. void clif_cashshop_ack(map_session_data* sd, int error)
  14512. {
  14513. int fd, cost[2] = { 0, 0 };
  14514. struct npc_data *nd;
  14515. nullpo_retv(sd);
  14516. fd = sd->fd;
  14517. nd = map_id2nd(sd->npc_shopid);
  14518. npc_shop_currency_type(sd, nd, cost, false);
  14519. WFIFOHEAD(fd, packet_len(0x289));
  14520. WFIFOW(fd,0) = 0x289;
  14521. WFIFOL(fd,2) = cost[0];
  14522. #if PACKETVER < 20070711
  14523. WFIFOW(fd,6) = TOW(error);
  14524. #else
  14525. WFIFOL(fd,6) = cost[1];
  14526. WFIFOW(fd,10) = TOW(error);
  14527. #endif
  14528. WFIFOSET(fd, packet_len(0x289));
  14529. }
  14530. void clif_cashshop_result( map_session_data *sd, t_itemid item_id, uint16 result ){
  14531. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14532. nullpo_retv( sd );
  14533. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet = {};
  14534. packet.packetType = HEADER_ZC_SE_PC_BUY_CASHITEM_RESULT;
  14535. if( item_id != 0 ){
  14536. packet.itemId = client_nameid( item_id );
  14537. }else{
  14538. packet.itemId = 0;
  14539. }
  14540. packet.result = result;
  14541. packet.cashPoints = sd->cashPoints;
  14542. packet.kafraPoints = sd->kafraPoints;
  14543. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  14544. #endif
  14545. }
  14546. /// Request to buy item(s) from cash shop.
  14547. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14548. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14549. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14550. void clif_parse_npccashshop_buy( int fd, map_session_data *sd ){
  14551. nullpo_retv( sd );
  14552. if( sd->state.trading || !sd->npc_shopid ){
  14553. clif_cashshop_ack( sd, 1 );
  14554. return;
  14555. }
  14556. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14557. #if PACKETVER < 20070711
  14558. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14559. #elif PACKETVER < 20101116
  14560. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14561. #else
  14562. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14563. 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 ){
  14564. 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 );
  14565. return;
  14566. }
  14567. std::vector<s_npc_buy_list> item_list = {};
  14568. item_list.reserve( p->count );
  14569. for( int i = 0; i < p->count; i++ ){
  14570. s_npc_buy_list item = {};
  14571. item.nameid = p->items[i].itemId;
  14572. item.qty = p->items[i].amount;
  14573. item_list.push_back( item );
  14574. }
  14575. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14576. #endif
  14577. }
  14578. /// Request to buy item(s) from cash shop.
  14579. /// 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)
  14580. void clif_parse_cashshop_buy( int fd, map_session_data *sd ){
  14581. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14582. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14583. 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 ){
  14584. 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 );
  14585. return;
  14586. }
  14587. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14588. }
  14589. /// Adoption System
  14590. ///
  14591. /// Adoption message (ZC_BABYMSG).
  14592. /// 0216 <msg>.L
  14593. /// msg:
  14594. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14595. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14596. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14597. void clif_Adopt_reply(map_session_data *sd, int type)
  14598. {
  14599. int fd = sd->fd;
  14600. WFIFOHEAD(fd,6);
  14601. WFIFOW(fd,0) = 0x216;
  14602. WFIFOL(fd,2) = type;
  14603. WFIFOSET(fd,6);
  14604. }
  14605. /// Adoption confirmation (ZC_REQ_BABY).
  14606. /// 01f6 <account id>.L <char id>.L <name>.B
  14607. void clif_Adopt_request(map_session_data *sd, map_session_data *src, int p_id)
  14608. {
  14609. int fd = sd->fd;
  14610. WFIFOHEAD(fd,34);
  14611. WFIFOW(fd,0) = 0x1f6;
  14612. WFIFOL(fd,2) = src->status.account_id;
  14613. WFIFOL(fd,6) = p_id;
  14614. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14615. WFIFOSET(fd,34);
  14616. }
  14617. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14618. /// 01f9 <account id>.L
  14619. void clif_parse_Adopt_request(int fd, map_session_data *sd)
  14620. {
  14621. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14622. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14623. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14624. {
  14625. tsd->adopt_invite = sd->status.account_id;
  14626. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14627. }
  14628. }
  14629. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14630. /// 01f7 <account id>.L <char id>.L <answer>.L
  14631. /// answer:
  14632. /// 0 = rejected
  14633. /// 1 = accepted
  14634. void clif_parse_Adopt_reply(int fd, map_session_data *sd){
  14635. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14636. int p1_id = RFIFOL(fd,info->pos[0]);
  14637. int p2_id = RFIFOL(fd,info->pos[1]);
  14638. int result = RFIFOL(fd,info->pos[2]);
  14639. map_session_data* p1_sd = map_id2sd(p1_id);
  14640. map_session_data* p2_sd = map_id2sd(p2_id);
  14641. int pid = sd->adopt_invite;
  14642. sd->adopt_invite = 0;
  14643. if( p1_sd == NULL || p2_sd == NULL )
  14644. return; // Both players need to be online
  14645. if( pid != p1_sd->status.account_id )
  14646. return; // Incorrect values
  14647. if( result == 0 )
  14648. return; // Rejected
  14649. pc_adoption(p1_sd, p2_sd, sd);
  14650. }
  14651. /// Convex Mirror
  14652. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B (ZC_BOSS_INFO)
  14653. /// infoType:
  14654. /// BOSS_INFO_NOT = No boss on this map.
  14655. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14656. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14657. /// BOSS_INFO_DEAD = Boss is dead.
  14658. void clif_bossmapinfo( map_session_data& sd, mob_data* md, e_bossmap_info flag ){
  14659. PACKET_ZC_BOSS_INFO p = {};
  14660. p.packetType = HEADER_ZC_BOSS_INFO;
  14661. p.type = flag;
  14662. switch (flag) {
  14663. case BOSS_INFO_NOT:
  14664. // No data required
  14665. break;
  14666. case BOSS_INFO_ALIVE_WITHMSG:
  14667. [[fallthrough]];
  14668. case BOSS_INFO_ALIVE:
  14669. p.x = md->bl.x;
  14670. p.y = md->bl.y;
  14671. break;
  14672. case BOSS_INFO_DEAD: {
  14673. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14674. unsigned int seconds;
  14675. int hours, minutes;
  14676. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14677. hours = seconds / (60 * 60);
  14678. seconds = seconds - (60 * 60 * hours);
  14679. minutes = seconds / 60;
  14680. p.minHours = hours;
  14681. p.minMinutes = minutes;
  14682. break;
  14683. }
  14684. }
  14685. if( md != nullptr ){
  14686. safestrncpy( p.name, md->db->jname.c_str(), sizeof( p.name ) );
  14687. }
  14688. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  14689. }
  14690. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14691. /// 02d6 <account id>.L
  14692. void clif_parse_ViewPlayerEquip(int fd, map_session_data* sd)
  14693. {
  14694. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14695. map_session_data* tsd = map_id2sd(aid);
  14696. if (!tsd)
  14697. return;
  14698. if (sd->bl.m != tsd->bl.m)
  14699. return;
  14700. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14701. clif_viewequip_ack(sd, tsd);
  14702. else
  14703. clif_msg(sd, VIEW_EQUIP_FAIL);
  14704. }
  14705. /// Request to a configuration.
  14706. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14707. /// type: see enum e_config_type
  14708. /// flag:
  14709. /// false = disabled
  14710. /// true = enabled
  14711. void clif_parse_configuration( int fd, map_session_data* sd ){
  14712. int cmd = RFIFOW(fd,0);
  14713. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14714. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14715. switch( type ){
  14716. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14717. sd->status.show_equip = flag;
  14718. break;
  14719. case CONFIG_CALL:
  14720. sd->status.disable_call = flag;
  14721. break;
  14722. case CONFIG_PET_AUTOFEED:
  14723. // Player can not click this if he does not have a pet
  14724. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14725. return;
  14726. }
  14727. sd->pd->pet.autofeed = flag;
  14728. break;
  14729. case CONFIG_HOMUNCULUS_AUTOFEED:
  14730. // Player can not click this if he does not have a homunculus or it is vaporized
  14731. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14732. return;
  14733. }
  14734. sd->hd->homunculus.autofeed = flag;
  14735. break;
  14736. default:
  14737. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14738. return;
  14739. }
  14740. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14741. }
  14742. /// Request to change party invitation tick.
  14743. /// value:
  14744. /// 0 = disabled (triggered by /accept)
  14745. /// 1 = enabled (triggered by /refuse)
  14746. void clif_parse_PartyTick( int fd, map_session_data* sd ){
  14747. PACKET_CZ_PARTY_CONFIG* p = (PACKET_CZ_PARTY_CONFIG*)RFIFOP( fd, 0 );
  14748. sd->status.disable_partyinvite = p->refuseInvite;
  14749. clif_partyinvitationstate( *sd );
  14750. }
  14751. /// Questlog System [Kevin] [Inkfish]
  14752. ///
  14753. /**
  14754. * Safe check to init packet len & quest num for player.
  14755. * @param def_len
  14756. * @param info_len Length of each quest info.
  14757. * @param avail_quests Avail quests that player has.
  14758. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14759. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14760. **/
  14761. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14762. (*limit_out) = (0xFFFF - def_len) / info_len;
  14763. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14764. (*len_out) = ((*limit_out) * info_len) + def_len;
  14765. }
  14766. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14767. std::string race_name;
  14768. switch( objective->race ){
  14769. case RC_FORMLESS: race_name = "Formless"; break;
  14770. case RC_UNDEAD: race_name = "Undead"; break;
  14771. case RC_BRUTE: race_name = "Brute"; break;
  14772. case RC_PLANT: race_name = "Plant"; break;
  14773. case RC_INSECT: race_name = "Insect"; break;
  14774. case RC_FISH: race_name = "Fish"; break;
  14775. case RC_DEMON: race_name = "Demon"; break;
  14776. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14777. case RC_ANGEL: race_name = "Angel"; break;
  14778. case RC_DRAGON: race_name = "Dragon"; break;
  14779. default:
  14780. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14781. [[fallthrough]];
  14782. case RC_ALL: race_name = ""; break;
  14783. }
  14784. std::string size_name;
  14785. switch( objective->size ){
  14786. case SZ_SMALL: size_name = "Small"; break;
  14787. case SZ_MEDIUM: size_name = "Medium"; break;
  14788. case SZ_BIG: size_name = "Large"; break;
  14789. default:
  14790. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14791. [[fallthrough]];
  14792. case SZ_ALL: size_name = ""; break;
  14793. }
  14794. std::string ele_name;
  14795. switch( objective->element ){
  14796. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14797. case ELE_WATER: ele_name = "Water Element"; break;
  14798. case ELE_EARTH: ele_name = "Earth Element"; break;
  14799. case ELE_FIRE: ele_name = "Fire Element"; break;
  14800. case ELE_WIND: ele_name = "Wind Element"; break;
  14801. case ELE_POISON: ele_name = "Poison Element"; break;
  14802. case ELE_HOLY: ele_name = "Holy Element"; break;
  14803. case ELE_DARK: ele_name = "Shadow Element"; break;
  14804. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14805. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14806. default:
  14807. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14808. [[fallthrough]];
  14809. case ELE_ALL: ele_name = ""; break;
  14810. }
  14811. std::string str;
  14812. if( !objective->map_name.empty() ){
  14813. str += objective->map_name;
  14814. }
  14815. if( !race_name.empty() ){
  14816. if( !str.empty() ){
  14817. str += ", ";
  14818. }
  14819. str += race_name;
  14820. }
  14821. if( !size_name.empty() ){
  14822. if( !str.empty() ){
  14823. str += ", ";
  14824. }
  14825. str += size_name;
  14826. }
  14827. if( !ele_name.empty() ){
  14828. if( !str.empty() ){
  14829. str += ", ";
  14830. }
  14831. str += ele_name;
  14832. }
  14833. return str;
  14834. }
  14835. /// Sends list of all quest states
  14836. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14837. /// 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)
  14838. /// 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)
  14839. void clif_quest_send_list(map_session_data *sd)
  14840. {
  14841. nullpo_retv(sd);
  14842. int fd = sd->fd;
  14843. int i;
  14844. int offset = 8;
  14845. int limit = 0;
  14846. #if PACKETVER >= 20141022
  14847. #if PACKETVER >= 20150513
  14848. int size = 22 + NAME_LENGTH;
  14849. #else
  14850. int size = 10 + NAME_LENGTH;
  14851. #endif
  14852. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14853. WFIFOHEAD(fd,i);
  14854. #if PACKETVER >= 20150513
  14855. WFIFOW(fd, 0) = 0x9f8;
  14856. #else
  14857. WFIFOW(fd, 0) = 0x97a;
  14858. #endif
  14859. WFIFOL(fd, 4) = limit;
  14860. for (i = 0; i < limit; i++) {
  14861. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14862. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14863. offset += 4;
  14864. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14865. offset++;
  14866. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14867. offset += 4;
  14868. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14869. offset += 4;
  14870. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14871. offset += 2;
  14872. if (!qi->objectives.empty()) {
  14873. std::shared_ptr<s_mob_db> mob;
  14874. for (int j = 0; j < qi->objectives.size(); j++) {
  14875. mob = mob_db.find(qi->objectives[j]->mob_id);
  14876. e_race race = qi->objectives[j]->race;
  14877. e_size size = qi->objectives[j]->size;
  14878. e_element element = qi->objectives[j]->element;
  14879. #if PACKETVER >= 20150513
  14880. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14881. offset += 4;
  14882. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14883. offset += 4;
  14884. #endif
  14885. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14886. offset += 4;
  14887. #if PACKETVER >= 20150513
  14888. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14889. offset += 2;
  14890. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14891. offset += 2;
  14892. #endif
  14893. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14894. offset += 2;
  14895. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14896. offset += 2;
  14897. if (mob && qi->objectives[j]->mob_id > 0)
  14898. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14899. else
  14900. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14901. offset += NAME_LENGTH;
  14902. }
  14903. }
  14904. }
  14905. WFIFOW(fd, 2) = offset;
  14906. WFIFOSET(fd, offset);
  14907. #else
  14908. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14909. WFIFOHEAD(fd,i);
  14910. WFIFOW(fd, 0) = 0x2b1;
  14911. WFIFOL(fd, 4) = limit;
  14912. for (i = 0; i < limit; i++) {
  14913. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14914. offset += 4;
  14915. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14916. offset += 1;
  14917. }
  14918. WFIFOW(fd, 2) = offset;
  14919. WFIFOSET(fd, offset);
  14920. #endif
  14921. }
  14922. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14923. /// 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
  14924. void clif_quest_send_mission(map_session_data *sd)
  14925. {
  14926. nullpo_retv(sd);
  14927. int fd = sd->fd;
  14928. int limit = 0;
  14929. int len = sd->avail_quests*104+8;
  14930. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14931. WFIFOHEAD(fd, len);
  14932. WFIFOW(fd, 0) = 0x2b2;
  14933. WFIFOW(fd, 2) = len;
  14934. WFIFOL(fd, 4) = limit;
  14935. for (int i = 0; i < limit; i++) {
  14936. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14937. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14938. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14939. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14940. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14941. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14942. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14943. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14944. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14945. if (mob && qi->objectives[j]->mob_id > 0)
  14946. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14947. else
  14948. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14949. }
  14950. }
  14951. WFIFOSET(fd, len);
  14952. }
  14953. /// Notification about a new quest
  14954. /// 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)
  14955. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14956. /// 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)
  14957. void clif_quest_add(map_session_data *sd, struct quest *qd)
  14958. {
  14959. nullpo_retv(sd);
  14960. nullpo_retv(qd);
  14961. int fd = sd->fd;
  14962. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14963. if (!qi)
  14964. return;
  14965. #if PACKETVER >= 20150513
  14966. int cmd = 0x9f9;
  14967. #else
  14968. int cmd = 0x2b3;
  14969. #endif
  14970. WFIFOHEAD(fd, packet_len(cmd));
  14971. WFIFOW(fd, 0) = cmd;
  14972. WFIFOL(fd, 2) = qd->quest_id;
  14973. WFIFOB(fd, 6) = qd->state;
  14974. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14975. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14976. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14977. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14978. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14979. e_race race = qi->objectives[i]->race;
  14980. e_size size = qi->objectives[i]->size;
  14981. e_element element = qi->objectives[i]->element;
  14982. #if PACKETVER >= 20150513
  14983. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14984. offset += 4;
  14985. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14986. offset += 4;
  14987. #endif
  14988. 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
  14989. offset += 4;
  14990. #if PACKETVER >= 20150513
  14991. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14992. offset += 2;
  14993. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14994. offset += 2;
  14995. #endif
  14996. WFIFOW(fd, offset) = qd->count[i];
  14997. offset += 2;
  14998. if (mob && qi->objectives[i]->mob_id > 0)
  14999. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  15000. else
  15001. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  15002. offset += NAME_LENGTH;
  15003. }
  15004. WFIFOSET(fd, packet_len(cmd));
  15005. #if PACKETVER >= 20150513
  15006. int len = 4 + qi->objectives.size() * 12;
  15007. WFIFOHEAD(fd, len);
  15008. WFIFOW(fd, 0) = 0x8fe;
  15009. WFIFOW(fd, 2) = len;
  15010. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  15011. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15012. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  15013. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  15014. WFIFOW(fd, offset + 10) = qd->count[i];
  15015. }
  15016. WFIFOSET(fd, len);
  15017. #endif
  15018. }
  15019. /// Notification about a quest being removed (ZC_DEL_QUEST).
  15020. /// 02b4 <quest id>.L
  15021. void clif_quest_delete(map_session_data *sd, int quest_id)
  15022. {
  15023. int fd = sd->fd;
  15024. WFIFOHEAD(fd, packet_len(0x2b4));
  15025. WFIFOW(fd, 0) = 0x2b4;
  15026. WFIFOL(fd, 2) = quest_id;
  15027. WFIFOSET(fd, packet_len(0x2b4));
  15028. }
  15029. /// Notification of an update to the hunting mission counter
  15030. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  15031. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  15032. void clif_quest_update_objective(map_session_data *sd, struct quest *qd)
  15033. {
  15034. int fd = sd->fd;
  15035. int offset = 6;
  15036. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  15037. int len = qi->objectives.size() * 12 + 6;
  15038. #if PACKETVER >= 20150513
  15039. int cmd = 0x9fa;
  15040. #else
  15041. int cmd = 0x2b5;
  15042. #endif
  15043. WFIFOHEAD(fd, len);
  15044. WFIFOW(fd, 0) = cmd;
  15045. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  15046. for (int i = 0; i < qi->objectives.size(); i++) {
  15047. WFIFOL(fd, offset) = qd->quest_id;
  15048. offset += 4;
  15049. #if PACKETVER >= 20150513
  15050. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15051. offset += 4;
  15052. #else
  15053. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  15054. offset += 4;
  15055. #endif
  15056. WFIFOW(fd, offset) = qi->objectives[i]->count;
  15057. offset += 2;
  15058. WFIFOW(fd, offset) = qd->count[i];
  15059. offset += 2;
  15060. }
  15061. WFIFOW(fd, 2) = offset;
  15062. WFIFOSET(fd, offset);
  15063. }
  15064. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  15065. /// 02b6 <quest id>.L <active>.B
  15066. void clif_parse_questStateAck(int fd, map_session_data *sd)
  15067. {
  15068. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15069. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  15070. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  15071. }
  15072. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  15073. /// 02b7 <quest id>.L <active>.B
  15074. void clif_quest_update_status(map_session_data *sd, int quest_id, bool active)
  15075. {
  15076. int fd = sd->fd;
  15077. WFIFOHEAD(fd, packet_len(0x2b7));
  15078. WFIFOW(fd, 0) = 0x2b7;
  15079. WFIFOL(fd, 2) = quest_id;
  15080. WFIFOB(fd, 6) = active;
  15081. WFIFOSET(fd, packet_len(0x2b7));
  15082. }
  15083. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  15084. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  15085. /// effect:
  15086. /// 0 = none
  15087. /// 1 = exclamation mark icon
  15088. /// 2 = question mark icon
  15089. /// color:
  15090. /// 0 = yellow
  15091. /// 1 = orange
  15092. /// 2 = green
  15093. /// 3 = purple
  15094. void clif_quest_show_event(map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  15095. {
  15096. #if PACKETVER >= 20090218
  15097. nullpo_retv(sd);
  15098. nullpo_retv(bl);
  15099. int fd = sd->fd;
  15100. WFIFOHEAD(fd, packet_len(0x446));
  15101. WFIFOW(fd, 0) = 0x446;
  15102. WFIFOL(fd, 2) = bl->id;
  15103. WFIFOW(fd, 6) = bl->x;
  15104. WFIFOW(fd, 8) = bl->y;
  15105. WFIFOW(fd, 10) = effect;
  15106. WFIFOW(fd, 12) = color;
  15107. WFIFOSET(fd, packet_len(0x446));
  15108. #endif
  15109. }
  15110. /// Mercenary System
  15111. ///
  15112. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  15113. /// 02a2 <var id>.W <value>.L
  15114. void clif_mercenary_updatestatus(map_session_data *sd, int type)
  15115. {
  15116. s_mercenary_data *md;
  15117. struct status_data *status;
  15118. int fd;
  15119. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15120. return;
  15121. fd = sd->fd;
  15122. status = &md->battle_status;
  15123. WFIFOHEAD(fd,packet_len(0x2a2));
  15124. WFIFOW(fd,0) = 0x2a2;
  15125. WFIFOW(fd,2) = type;
  15126. switch( type ) {
  15127. case SP_ATK1:
  15128. {
  15129. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15130. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  15131. }
  15132. break;
  15133. case SP_MATK1:
  15134. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  15135. break;
  15136. case SP_HIT:
  15137. WFIFOL(fd,4) = status->hit;
  15138. break;
  15139. case SP_CRITICAL:
  15140. WFIFOL(fd,4) = status->cri/10;
  15141. break;
  15142. case SP_DEF1:
  15143. WFIFOL(fd,4) = status->def;
  15144. break;
  15145. case SP_MDEF1:
  15146. WFIFOL(fd,4) = status->mdef;
  15147. break;
  15148. case SP_MERCFLEE:
  15149. WFIFOL(fd,4) = status->flee;
  15150. break;
  15151. case SP_ASPD:
  15152. WFIFOL(fd,4) = status->amotion;
  15153. break;
  15154. case SP_HP:
  15155. WFIFOL(fd,4) = status->hp;
  15156. break;
  15157. case SP_MAXHP:
  15158. WFIFOL(fd,4) = status->max_hp;
  15159. break;
  15160. case SP_SP:
  15161. WFIFOL(fd,4) = status->sp;
  15162. break;
  15163. case SP_MAXSP:
  15164. WFIFOL(fd,4) = status->max_sp;
  15165. break;
  15166. case SP_MERCKILLS:
  15167. WFIFOL(fd,4) = md->mercenary.kill_count;
  15168. break;
  15169. case SP_MERCFAITH:
  15170. WFIFOL(fd,4) = mercenary_get_faith(md);
  15171. break;
  15172. }
  15173. WFIFOSET(fd,packet_len(0x2a2));
  15174. }
  15175. /// Mercenary base status data (ZC_MER_INIT).
  15176. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  15177. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  15178. /// <calls>.L <kills>.L <atk range>.W
  15179. void clif_mercenary_info(map_session_data *sd)
  15180. {
  15181. int fd;
  15182. s_mercenary_data *md;
  15183. struct status_data *status;
  15184. int atk;
  15185. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15186. return;
  15187. fd = sd->fd;
  15188. status = &md->battle_status;
  15189. WFIFOHEAD(fd,packet_len(0x29b));
  15190. WFIFOW(fd,0) = 0x29b;
  15191. WFIFOL(fd,2) = md->bl.id;
  15192. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15193. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15194. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15195. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15196. WFIFOW(fd,10) = status->hit;
  15197. WFIFOW(fd,12) = status->cri/10;
  15198. WFIFOW(fd,14) = status->def;
  15199. WFIFOW(fd,16) = status->mdef;
  15200. WFIFOW(fd,18) = status->flee;
  15201. WFIFOW(fd,20) = status->amotion;
  15202. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15203. WFIFOW(fd,46) = md->db->lv;
  15204. WFIFOL(fd,48) = status->hp;
  15205. WFIFOL(fd,52) = status->max_hp;
  15206. WFIFOL(fd,56) = status->sp;
  15207. WFIFOL(fd,60) = status->max_sp;
  15208. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15209. WFIFOW(fd,68) = mercenary_get_faith(md);
  15210. WFIFOL(fd,70) = mercenary_get_calls(md);
  15211. WFIFOL(fd,74) = md->mercenary.kill_count;
  15212. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15213. WFIFOSET(fd,packet_len(0x29b));
  15214. }
  15215. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15216. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15217. void clif_mercenary_skillblock(map_session_data *sd)
  15218. {
  15219. s_mercenary_data *md;
  15220. int fd, len = 4;
  15221. if( sd == NULL || (md = sd->md) == NULL )
  15222. return;
  15223. fd = sd->fd;
  15224. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15225. WFIFOW(fd,0) = 0x29d;
  15226. for (const auto &it : md->db->skill) {
  15227. uint16 id = it.first;
  15228. if (!SKILL_CHK_MERC(id))
  15229. continue;
  15230. uint16 lv = it.second;
  15231. WFIFOW(fd,len) = id;
  15232. WFIFOL(fd,len+2) = skill_get_inf(id);
  15233. WFIFOW(fd,len+6) = lv;
  15234. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15235. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15236. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15237. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15238. len += 37;
  15239. }
  15240. WFIFOW(fd,2) = len;
  15241. WFIFOSET(fd,len);
  15242. }
  15243. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15244. /// 029f <command>.B
  15245. /// 1 = mercenary information
  15246. /// 2 = delete
  15247. void clif_parse_mercenary_action(int fd, map_session_data* sd)
  15248. {
  15249. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15250. if( sd->md == NULL )
  15251. return;
  15252. if( option == 2 ) mercenary_delete(sd->md, 2);
  15253. }
  15254. /// Mercenary Message
  15255. /// message:
  15256. /// 0 = Mercenary soldier's duty hour is over.
  15257. /// 1 = Your mercenary soldier has been killed.
  15258. /// 2 = Your mercenary soldier has been fired.
  15259. /// 3 = Your mercenary soldier has ran away.
  15260. void clif_mercenary_message(map_session_data* sd, int message){
  15261. clif_msg(sd, MERC_MSG_BASE + message);
  15262. }
  15263. /// Notification about the remaining time of a rental item.
  15264. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15265. void clif_rental_time( map_session_data* sd, t_itemid nameid, int seconds ){
  15266. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15267. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15268. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15269. p.itemId = client_nameid( nameid );
  15270. p.seconds = seconds;
  15271. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15272. }
  15273. /// Deletes a rental item from client's inventory.
  15274. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15275. void clif_rental_expired( map_session_data* sd, int index, t_itemid nameid ){
  15276. // '<ItemName>' item has been deleted from the Inventory
  15277. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15278. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15279. p.index = client_index( index );
  15280. p.itemId = client_nameid( nameid );
  15281. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15282. }
  15283. /// Book Reading (ZC_READ_BOOK).
  15284. /// 0294 <book id>.L <page>.L
  15285. void clif_readbook(int fd, int book_id, int page)
  15286. {
  15287. WFIFOHEAD(fd,packet_len(0x294));
  15288. WFIFOW(fd,0) = 0x294;
  15289. WFIFOL(fd,2) = book_id;
  15290. WFIFOL(fd,6) = page;
  15291. WFIFOSET(fd,packet_len(0x294));
  15292. }
  15293. /// Battlegrounds
  15294. ///
  15295. /// Updates HP bar of a camp member.
  15296. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15297. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15298. void clif_bg_hp(map_session_data *sd) {
  15299. #if PACKETVER < 20140613
  15300. unsigned char buf[34];
  15301. const int cmd = 0x2e0;
  15302. #else
  15303. unsigned char buf[14];
  15304. const int cmd = 0xa0e;
  15305. #endif
  15306. nullpo_retv(sd);
  15307. WBUFW(buf,0) = cmd;
  15308. WBUFL(buf,2) = sd->status.account_id;
  15309. #if PACKETVER < 20140613
  15310. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15311. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15312. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15313. WBUFW(buf,32) = 100;
  15314. } else {
  15315. WBUFW(buf,30) = sd->battle_status.hp;
  15316. WBUFW(buf,32) = sd->battle_status.max_hp;
  15317. }
  15318. #else
  15319. if( sd->battle_status.max_hp > INT32_MAX ) {
  15320. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15321. WBUFL(buf,10) = 100;
  15322. } else {
  15323. WBUFL(buf,6) = sd->battle_status.hp;
  15324. WBUFL(buf,10) = sd->battle_status.max_hp;
  15325. }
  15326. #endif
  15327. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15328. }
  15329. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15330. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15331. void clif_bg_xy(map_session_data *sd)
  15332. {
  15333. unsigned char buf[36];
  15334. nullpo_retv(sd);
  15335. WBUFW(buf,0)=0x2df;
  15336. WBUFL(buf,2)=sd->status.account_id;
  15337. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15338. WBUFW(buf,30)=sd->status.class_;
  15339. WBUFW(buf,32)=sd->bl.x;
  15340. WBUFW(buf,34)=sd->bl.y;
  15341. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15342. }
  15343. void clif_bg_xy_remove(map_session_data *sd)
  15344. {
  15345. unsigned char buf[36];
  15346. nullpo_retv(sd);
  15347. WBUFW(buf,0)=0x2df;
  15348. WBUFL(buf,2)=sd->status.account_id;
  15349. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15350. WBUFW(buf,30)=0;
  15351. WBUFW(buf,32)=-1;
  15352. WBUFW(buf,34)=-1;
  15353. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15354. }
  15355. /// Notifies clients of a battleground message.
  15356. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15357. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15358. map_session_data *sd = bg_getavailablesd( bg );
  15359. if( sd == nullptr ){
  15360. return;
  15361. }
  15362. // limit length
  15363. len = min( len + 1, CHAT_SIZE_MAX );
  15364. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15365. WBUFW(buf,0) = 0x2dc;
  15366. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15367. WBUFL(buf,4) = src_id;
  15368. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15369. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15370. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15371. }
  15372. /// Validates and processes battlechat messages.
  15373. /// All messages that are sent after enabling battleground chat with /battlechat.
  15374. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15375. void clif_parse_BattleChat(int fd, map_session_data* sd){
  15376. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15377. if( !clif_process_message( sd, false, name, message, output ) )
  15378. return;
  15379. bg_send_message(sd, output, strlen(output) );
  15380. }
  15381. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15382. /// 02de <camp A points>.W <camp B points>.W
  15383. void clif_bg_updatescore(int16 m)
  15384. {
  15385. struct block_list bl;
  15386. unsigned char buf[6];
  15387. struct map_data *mapdata = map_getmapdata(m);
  15388. bl.id = 0;
  15389. bl.type = BL_NUL;
  15390. bl.m = m;
  15391. WBUFW(buf,0) = 0x2de;
  15392. WBUFW(buf,2) = mapdata->bgscore_lion;
  15393. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15394. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15395. }
  15396. void clif_bg_updatescore_single(map_session_data *sd)
  15397. {
  15398. int fd;
  15399. nullpo_retv(sd);
  15400. fd = sd->fd;
  15401. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15402. WFIFOHEAD(fd,packet_len(0x2de));
  15403. WFIFOW(fd,0) = 0x2de;
  15404. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15405. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15406. WFIFOSET(fd,packet_len(0x2de));
  15407. }
  15408. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15409. /// 02dd <account id>.L <name>.24B <camp>.W
  15410. void clif_sendbgemblem_area(map_session_data *sd)
  15411. {
  15412. unsigned char buf[33];
  15413. nullpo_retv(sd);
  15414. WBUFW(buf, 0) = 0x2dd;
  15415. WBUFL(buf,2) = sd->bl.id;
  15416. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15417. WBUFW(buf,30) = sd->bg_id;
  15418. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15419. }
  15420. void clif_sendbgemblem_single(int fd, map_session_data *sd)
  15421. {
  15422. nullpo_retv(sd);
  15423. WFIFOHEAD(fd,32);
  15424. WFIFOW(fd,0) = 0x2dd;
  15425. WFIFOL(fd,2) = sd->bl.id;
  15426. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15427. WFIFOW(fd,30) = sd->bg_id;
  15428. WFIFOSET(fd,packet_len(0x2dd));
  15429. }
  15430. /// Battlegrounds queue incoming apply request from client.
  15431. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15432. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15433. void clif_parse_bg_queue_apply_request(int fd, map_session_data *sd)
  15434. {
  15435. if (!battle_config.feature_bgqueue)
  15436. return;
  15437. nullpo_retv(sd);
  15438. short type = RFIFOW(fd,2);
  15439. char name[NAME_LENGTH];
  15440. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15441. if (sd->bg_queue_id > 0) {
  15442. //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);
  15443. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15444. return;
  15445. } else if (type == 1) // Solo
  15446. bg_queue_join_solo(name, sd);
  15447. else if (type == 2) // Party
  15448. bg_queue_join_party(name, sd);
  15449. else if (type == 4) // Guild
  15450. bg_queue_join_guild(name, sd);
  15451. else {
  15452. 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);
  15453. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15454. return;
  15455. }
  15456. }
  15457. /// Outgoing battlegrounds queue apply result.
  15458. /// Result types: @see e_bg_queue_apply_ack
  15459. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15460. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, map_session_data *sd)
  15461. {
  15462. nullpo_retv(sd);
  15463. int fd = sd->fd;
  15464. WFIFOHEAD(fd, packet_len(0x8d8));
  15465. WFIFOW(fd,0) = 0x8d8;
  15466. WFIFOB(fd,2) = result;
  15467. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15468. WFIFOSET(fd, packet_len(0x8d8));
  15469. }
  15470. /// Outgoing battlegrounds queue apply notification.
  15471. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15472. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15473. void clif_bg_queue_apply_notify(const char *name, map_session_data *sd)
  15474. {
  15475. nullpo_retv(sd);
  15476. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15477. if (queue == nullptr) {
  15478. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15479. return;
  15480. }
  15481. int fd = sd->fd;
  15482. WFIFOHEAD(fd, packet_len(0x8d9));
  15483. WFIFOW(fd,0) = 0x8d9;
  15484. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15485. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15486. WFIFOSET(fd, packet_len(0x8d9));
  15487. }
  15488. /// Battlegrounds queue outgoing cancel result.
  15489. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15490. void clif_bg_queue_cancel_result(bool success, const char *name, map_session_data *sd)
  15491. {
  15492. nullpo_retv(sd);
  15493. int fd = sd->fd;
  15494. WFIFOHEAD(fd, packet_len(0x8d8));
  15495. WFIFOW(fd,0) = 0x8db;
  15496. WFIFOB(fd,2) = success;
  15497. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15498. WFIFOSET(fd, packet_len(0x8d8));
  15499. }
  15500. /// Battlegrounds queue incoming cancel request from client.
  15501. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15502. void clif_parse_bg_queue_cancel_request(int fd, map_session_data *sd)
  15503. {
  15504. if (!battle_config.feature_bgqueue)
  15505. return;
  15506. nullpo_retv(sd);
  15507. bool success;
  15508. if (sd->bg_queue_id > 0) {
  15509. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15510. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15511. 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.
  15512. else
  15513. success = bg_queue_leave(sd);
  15514. } else {
  15515. 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);
  15516. success = false;
  15517. }
  15518. char name[NAME_LENGTH];
  15519. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15520. clif_bg_queue_cancel_result(success, name, sd);
  15521. }
  15522. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15523. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15524. void clif_bg_queue_lobby_notify(const char *name, map_session_data *sd)
  15525. {
  15526. nullpo_retv(sd);
  15527. int fd = sd->fd;
  15528. WFIFOHEAD(fd, packet_len(0x8df));
  15529. WFIFOW(fd,0) = 0x8df;
  15530. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15531. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15532. WFIFOSET(fd, packet_len(0x8df));
  15533. }
  15534. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15535. /// Result types: 1(Accept), 2(Decline).
  15536. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15537. void clif_parse_bg_queue_lobby_reply(int fd, map_session_data *sd)
  15538. {
  15539. nullpo_retv(sd);
  15540. if(sd->bg_queue_id > 0) {
  15541. uint8 result = RFIFOB(fd, 2);
  15542. if(result == 1) { // Accept
  15543. bg_queue_on_accept_invite(sd);
  15544. } else if(result == 2) { // Decline
  15545. bg_queue_leave(sd);
  15546. clif_bg_queue_entry_init(sd);
  15547. }
  15548. }
  15549. }
  15550. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15551. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15552. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, map_session_data *sd)
  15553. {
  15554. nullpo_retv(sd);
  15555. int fd = sd->fd;
  15556. WFIFOHEAD(fd, packet_len(0x8e1));
  15557. WFIFOW(fd,0) = 0x8e1;
  15558. WFIFOB(fd,2) = result;
  15559. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15560. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15561. WFIFOSET(fd, packet_len(0x8e1));
  15562. }
  15563. /// Battlegrounds queue incoming queue number request from client.
  15564. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15565. void clif_parse_bg_queue_request_queue_number(int fd, map_session_data *sd)
  15566. {
  15567. nullpo_retv(sd);
  15568. char name[NAME_LENGTH];
  15569. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15570. clif_bg_queue_apply_notify(name, sd);
  15571. }
  15572. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15573. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15574. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15575. void clif_bg_queue_entry_init(map_session_data *sd)
  15576. {
  15577. nullpo_retv(sd);
  15578. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15579. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15580. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15581. }
  15582. /// Custom Fonts (ZC_NOTIFY_FONT).
  15583. /// 02ef <account_id>.L <font id>.W
  15584. void clif_font(map_session_data *sd)
  15585. {
  15586. #if PACKETVER >= 20080102
  15587. unsigned char buf[8];
  15588. nullpo_retv(sd);
  15589. WBUFW(buf,0) = 0x2ef;
  15590. WBUFL(buf,2) = sd->bl.id;
  15591. WBUFW(buf,6) = sd->status.font;
  15592. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15593. #endif
  15594. }
  15595. /// Required to start the instancing information window on Client
  15596. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15597. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15598. void clif_instance_create(int instance_id, int num)
  15599. {
  15600. #if PACKETVER >= 20071128
  15601. map_session_data *sd = NULL;
  15602. enum send_target target = PARTY;
  15603. unsigned char buf[65];
  15604. instance_getsd(instance_id, sd, &target);
  15605. if (!sd)
  15606. return;
  15607. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15608. if (!db)
  15609. return;
  15610. WBUFW(buf,0) = 0x2cb;
  15611. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15612. WBUFW(buf,63) = num;
  15613. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15614. #endif
  15615. return;
  15616. }
  15617. /// To announce Instancing queue creation if no maps available
  15618. /// S 0x2cc <Standby Position>.W
  15619. void clif_instance_changewait(int instance_id, int num)
  15620. {
  15621. #if PACKETVER >= 20071128
  15622. map_session_data *sd = NULL;
  15623. enum send_target target = PARTY;
  15624. unsigned char buf[4];
  15625. instance_getsd(instance_id, sd, &target);
  15626. if (!sd)
  15627. return;
  15628. WBUFW(buf,0) = 0x2cc;
  15629. WBUFW(buf,2) = num;
  15630. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15631. #endif
  15632. return;
  15633. }
  15634. /// Notify the current status to members
  15635. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15636. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15637. {
  15638. #if PACKETVER >= 20071128
  15639. map_session_data *sd = NULL;
  15640. enum send_target target = PARTY;
  15641. unsigned char buf[71];
  15642. instance_getsd(instance_id, sd, &target);
  15643. if (!sd)
  15644. return;
  15645. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15646. if (!db)
  15647. return;
  15648. WBUFW(buf,0) = 0x2cd;
  15649. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15650. WBUFL(buf,63) = limit1;
  15651. WBUFL(buf,67) = limit2;
  15652. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15653. #endif
  15654. return;
  15655. }
  15656. /// Notify a status change to members
  15657. /// S 0x2ce <Message ID>.L
  15658. /// 0 = Notification (EnterLimitDate update?)
  15659. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15660. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15661. /// 3 = The Memorial Dungeon has been removed.
  15662. /// 4 = Create failure (removes the instance window)
  15663. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15664. {
  15665. #if PACKETVER >= 20071128
  15666. map_session_data *sd = NULL;
  15667. enum send_target target = PARTY;
  15668. unsigned char buf[10];
  15669. instance_getsd(instance_id, sd, &target);
  15670. if (!sd)
  15671. return;
  15672. WBUFW(buf,0) = 0x2ce;
  15673. WBUFL(buf,2) = type;
  15674. WBUFL(buf,6) = limit;
  15675. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15676. #endif
  15677. return;
  15678. }
  15679. /// Destroy an instance from the status window
  15680. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15681. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15682. {
  15683. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15684. return;
  15685. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15686. switch (p->command) {
  15687. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15688. instance_destroy_command(sd);
  15689. break;
  15690. }
  15691. }
  15692. void clif_instance_info( map_session_data& sd ){
  15693. if( sd.instance_id > 0 ){
  15694. instance_reqinfo( &sd, sd.instance_id );
  15695. }
  15696. if( sd.status.party_id > 0 ){
  15697. struct party_data* p = party_search( sd.status.party_id );
  15698. if( p != nullptr && p->instance_id > 0 ){
  15699. instance_reqinfo( &sd, p->instance_id );
  15700. }
  15701. }
  15702. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15703. instance_reqinfo( &sd, sd.guild->instance_id );
  15704. }
  15705. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15706. instance_reqinfo( &sd, sd.clan->instance_id );
  15707. }
  15708. }
  15709. /// Notifies clients about item picked up by a party member.
  15710. /// 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)
  15711. void clif_party_show_picker( map_session_data* sd, struct item* item_data ){
  15712. #if PACKETVER >= 20071002
  15713. nullpo_retv( sd );
  15714. nullpo_retv( item_data );
  15715. struct item_data* id = itemdb_search( item_data->nameid );
  15716. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15717. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15718. p.AID = sd->status.account_id;
  15719. p.itemId = client_nameid( item_data->nameid );
  15720. p.identified = item_data->identify;
  15721. p.damaged = item_data->attribute;
  15722. p.refine = item_data->refine;
  15723. clif_addcards( &p.slot, item_data );
  15724. p.location = id->equip; // equip location
  15725. p.itemType = itemtype( id->nameid ); // item type
  15726. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15727. p.grade = item_data->enchantgrade;
  15728. #endif
  15729. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15730. #endif
  15731. }
  15732. /** Display gained exp.
  15733. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15734. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15735. * amount: INT32_MIN ~ INT32_MAX
  15736. * var id:
  15737. * SP_BASEEXP, SP_JOBEXP
  15738. * exp type:
  15739. * 0 = normal exp gained/lost
  15740. * 1 = quest exp gained/lost
  15741. * @param sd Player
  15742. * @param exp EXP value gained/loss
  15743. * @param type SP_BASEEXP, SP_JOBEXP
  15744. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15745. * @param lost True:if losing EXP
  15746. */
  15747. void clif_displayexp(map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15748. {
  15749. int fd;
  15750. int offset;
  15751. #if PACKETVER >= 20170830
  15752. int cmd = 0xacc;
  15753. #else
  15754. int cmd = 0x7f6;
  15755. #endif
  15756. nullpo_retv(sd);
  15757. fd = sd->fd;
  15758. WFIFOHEAD(fd, packet_len(cmd));
  15759. WFIFOW(fd,0) = cmd;
  15760. WFIFOL(fd,2) = sd->bl.id;
  15761. #if PACKETVER >= 20170830
  15762. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15763. offset = 4;
  15764. #else
  15765. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15766. offset = 0;
  15767. #endif
  15768. WFIFOW(fd,10+offset) = type;
  15769. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15770. WFIFOSET(fd,packet_len(cmd));
  15771. }
  15772. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15773. /// type:
  15774. /// 0 = Displays 'value' for 5 seconds.
  15775. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15776. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15777. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15778. /// value:
  15779. /// 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).
  15780. void clif_showdigit(map_session_data* sd, unsigned char type, int value)
  15781. {
  15782. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15783. WFIFOW(sd->fd,0) = 0x1b1;
  15784. WFIFOB(sd->fd,2) = type;
  15785. WFIFOL(sd->fd,3) = value;
  15786. WFIFOSET(sd->fd, packet_len(0x1b1));
  15787. }
  15788. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15789. /// 021d <state>.L
  15790. /// state:
  15791. /// 0 = Full effects
  15792. /// 1 = Reduced effects
  15793. ///
  15794. /// NOTE: The state is used on Aegis for sending skill unit packet
  15795. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15796. /// whenever possible. Due to the way the decision check is
  15797. /// constructed, this state tracking was rendered useless,
  15798. /// as the only skill unit, that is sent with 0x1c9 is
  15799. /// Graffiti.
  15800. void clif_parse_LessEffect(int fd, map_session_data* sd){
  15801. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15802. sd->state.lesseffect = ( isLess != 0 );
  15803. }
  15804. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15805. void clif_parse_ItemListWindowSelected(int fd, map_session_data* sd) {
  15806. if( sd == nullptr ){
  15807. return;
  15808. }
  15809. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15810. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15811. int type = RFIFOL(fd,info->pos[1]);
  15812. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15813. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15814. if( sd->state.trading || sd->npc_shopid )
  15815. return;
  15816. if( flag == 0 || n == 0) {
  15817. clif_menuskill_clear(sd);
  15818. return; // Canceled by player.
  15819. }
  15820. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15821. clif_menuskill_clear(sd);
  15822. return; // Prevent hacking.
  15823. }
  15824. switch( type ) {
  15825. case 0: // Change Material
  15826. skill_changematerial(sd,n,item_list);
  15827. break;
  15828. case 1: // Level 1: Pure to Rough
  15829. case 2: // Level 2: Rough to Pure
  15830. skill_elementalanalysis(*sd,n,type,item_list);
  15831. break;
  15832. }
  15833. clif_menuskill_clear(sd);
  15834. return;
  15835. }
  15836. /*==========================================
  15837. * Elemental System
  15838. *==========================================*/
  15839. void clif_elemental_updatestatus(map_session_data *sd, int type) {
  15840. s_elemental_data *ed;
  15841. struct status_data *status;
  15842. int fd;
  15843. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15844. return;
  15845. fd = sd->fd;
  15846. status = &ed->battle_status;
  15847. WFIFOHEAD(fd,8);
  15848. WFIFOW(fd,0) = 0x81e;
  15849. WFIFOW(fd,2) = type;
  15850. switch( type ) {
  15851. case SP_HP:
  15852. WFIFOL(fd,4) = status->hp;
  15853. break;
  15854. case SP_MAXHP:
  15855. WFIFOL(fd,4) = status->max_hp;
  15856. break;
  15857. case SP_SP:
  15858. WFIFOL(fd,4) = status->sp;
  15859. break;
  15860. case SP_MAXSP:
  15861. WFIFOL(fd,4) = status->max_sp;
  15862. break;
  15863. }
  15864. WFIFOSET(fd,8);
  15865. }
  15866. void clif_elemental_info(map_session_data *sd) {
  15867. int fd;
  15868. s_elemental_data *ed;
  15869. struct status_data *status;
  15870. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15871. return;
  15872. fd = sd->fd;
  15873. status = &ed->battle_status;
  15874. WFIFOHEAD(fd,22);
  15875. WFIFOW(fd, 0) = 0x81d;
  15876. WFIFOL(fd, 2) = ed->bl.id;
  15877. WFIFOL(fd, 6) = status->hp;
  15878. WFIFOL(fd,10) = status->max_hp;
  15879. WFIFOL(fd,14) = status->sp;
  15880. WFIFOL(fd,18) = status->max_sp;
  15881. WFIFOSET(fd,22);
  15882. }
  15883. /// Buying Store System
  15884. ///
  15885. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15886. /// 0810 <slots>.B
  15887. void clif_buyingstore_open(map_session_data* sd)
  15888. {
  15889. int fd = sd->fd;
  15890. WFIFOHEAD(fd,packet_len(0x810));
  15891. WFIFOW(fd,0) = 0x810;
  15892. WFIFOB(fd,2) = sd->buyingstore.slots;
  15893. WFIFOSET(fd,packet_len(0x810));
  15894. }
  15895. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15896. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15897. /// result:
  15898. /// 0 = cancel
  15899. /// 1 = open
  15900. static void clif_parse_ReqOpenBuyingStore( int fd, map_session_data* sd ){
  15901. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15902. // TODO: Make this check global for all variable length packets.
  15903. // minimum packet length
  15904. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15905. 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 );
  15906. return;
  15907. }
  15908. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15909. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15910. return;
  15911. }
  15912. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15913. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15914. return;
  15915. }
  15916. char storename[MESSAGE_SIZE];
  15917. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15918. // so that buyingstore_create knows, how many elements it has access to
  15919. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15920. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15921. 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 ) );
  15922. return;
  15923. }
  15924. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15925. }
  15926. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15927. /// 0812 <result>.W <total weight>.L
  15928. /// result:
  15929. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15930. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15931. /// 8 = "No sale (purchase) information available." (0x705)
  15932. /// ? = nothing
  15933. void clif_buyingstore_open_failed(map_session_data* sd, unsigned short result, unsigned int weight)
  15934. {
  15935. int fd = sd->fd;
  15936. WFIFOHEAD(fd,packet_len(0x812));
  15937. WFIFOW(fd,0) = 0x812;
  15938. WFIFOW(fd,2) = result;
  15939. WFIFOL(fd,4) = weight;
  15940. WFIFOSET(fd,packet_len(0x812));
  15941. }
  15942. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15943. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15944. void clif_buyingstore_myitemlist( map_session_data* sd ){
  15945. nullpo_retv( sd );
  15946. int fd = sd->fd;
  15947. if( !session_isActive( fd ) ){
  15948. return;
  15949. }
  15950. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15951. WFIFOHEAD( fd, length );
  15952. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15953. p->packetType = 0x813;
  15954. p->packetLength = length;
  15955. p->AID = sd->bl.id;
  15956. p->zenyLimit = sd->buyingstore.zenylimit;
  15957. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15958. p->items[i].price = sd->buyingstore.items[i].price;
  15959. p->items[i].amount = sd->buyingstore.items[i].amount;
  15960. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15961. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15962. }
  15963. WFIFOSET( fd, p->packetLength );
  15964. }
  15965. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15966. /// 0814 <account id>.L <store name>.80B
  15967. void clif_buyingstore_entry( map_session_data& sd, struct block_list* tbl ){
  15968. #if PACKETVER >= 20100420
  15969. enum send_target target;
  15970. if( tbl == nullptr ){
  15971. tbl = &sd.bl;
  15972. target = AREA_WOS;
  15973. }else{
  15974. target = SELF;
  15975. }
  15976. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15977. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15978. p.makerAID = sd.status.account_id;
  15979. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15980. clif_send( &p, sizeof( p ), tbl, target );
  15981. #endif
  15982. }
  15983. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15984. /// 0815
  15985. static void clif_parse_ReqCloseBuyingStore(int fd, map_session_data* sd)
  15986. {
  15987. buyingstore_close(sd);
  15988. }
  15989. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15990. /// 0816 <account id>.L
  15991. void clif_buyingstore_disappear_entry( map_session_data& sd, struct block_list* tbl ){
  15992. #if PACKETVER >= 20100309
  15993. enum send_target target;
  15994. if( tbl == nullptr ){
  15995. tbl = &sd.bl;
  15996. target = AREA_WOS;
  15997. }else{
  15998. target = SELF;
  15999. }
  16000. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  16001. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  16002. p.makerAID = sd.status.account_id;
  16003. clif_send( &p, sizeof( p ), tbl, target );
  16004. #endif
  16005. }
  16006. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  16007. /// 0817 <account id>.L
  16008. static void clif_parse_ReqClickBuyingStore(int fd, map_session_data* sd)
  16009. {
  16010. uint32 account_id;
  16011. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  16012. buyingstore_open(sd, account_id);
  16013. }
  16014. /// Sends buying store item list.
  16015. /// 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)
  16016. void clif_buyingstore_itemlist( map_session_data* sd, map_session_data* pl_sd ){
  16017. nullpo_retv( sd );
  16018. nullpo_retv( pl_sd );
  16019. int fd = sd->fd;
  16020. if( !session_isActive( fd ) ){
  16021. return;
  16022. }
  16023. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  16024. WFIFOHEAD( fd, length );
  16025. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  16026. p->packetType = 0x818;
  16027. p->packetLength = length;
  16028. p->AID = pl_sd->bl.id;
  16029. p->storeId = pl_sd->buyer_id;
  16030. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  16031. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  16032. p->items[i].price = pl_sd->buyingstore.items[i].price;
  16033. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  16034. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  16035. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  16036. }
  16037. WFIFOSET( fd, p->packetLength );
  16038. }
  16039. /// Request to sell items to a buying store.
  16040. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  16041. static void clif_parse_ReqTradeBuyingStore( int fd, map_session_data* sd ){
  16042. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  16043. // minimum packet length
  16044. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  16045. 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 );
  16046. return;
  16047. }
  16048. // so that buyingstore_trade knows, how many elements it has access to
  16049. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  16050. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  16051. 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 ) );
  16052. return;
  16053. }
  16054. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  16055. }
  16056. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  16057. /// 081a <result>.W
  16058. /// result:
  16059. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  16060. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  16061. /// ? = nothing
  16062. void clif_buyingstore_trade_failed_buyer(map_session_data* sd, short result)
  16063. {
  16064. int fd = sd->fd;
  16065. WFIFOHEAD(fd,packet_len(0x81a));
  16066. WFIFOW(fd,0) = 0x81a;
  16067. WFIFOW(fd,2) = result;
  16068. WFIFOSET(fd,packet_len(0x81a));
  16069. }
  16070. /// Updates the zeny limit and an item in the buying store item list.
  16071. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  16072. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  16073. void clif_buyingstore_update_item( map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  16074. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  16075. p.packetType = buyingStoreUpdateItemType;
  16076. p.itemId = client_nameid( nameid );
  16077. p.amount = amount;
  16078. p.zenyLimit = sd->buyingstore.zenylimit;
  16079. #if PACKETVER >= 20141016
  16080. p.zeny = zeny;
  16081. p.charId = char_id; // GID
  16082. p.updateTime = (int)time(NULL);
  16083. #endif
  16084. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16085. }
  16086. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  16087. /// 081c <index>.W <amount>.W <price>.L
  16088. /// message:
  16089. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  16090. ///
  16091. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  16092. void clif_buyingstore_delete_item(map_session_data* sd, short index, unsigned short amount, int price)
  16093. {
  16094. int fd = sd->fd;
  16095. WFIFOHEAD(fd,packet_len(0x81c));
  16096. WFIFOW(fd,0) = 0x81c;
  16097. WFIFOW(fd,2) = client_index( index );
  16098. WFIFOW(fd,4) = amount;
  16099. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  16100. WFIFOSET(fd,packet_len(0x81c));
  16101. }
  16102. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  16103. /// 0824 <result>.W <name id>.W
  16104. /// result:
  16105. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  16106. /// 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)
  16107. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  16108. /// ? = nothing
  16109. void clif_buyingstore_trade_failed_seller( map_session_data* sd, short result, t_itemid nameid ){
  16110. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  16111. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  16112. p.result = result;
  16113. p.itemId = client_nameid( nameid );
  16114. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16115. }
  16116. /// Search Store Info System
  16117. ///
  16118. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  16119. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  16120. /// type:
  16121. /// 0 = Vending
  16122. /// 1 = Buying Store
  16123. ///
  16124. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16125. /// amount of card slots. If the client does not know about the item it
  16126. /// cannot be searched.
  16127. static void clif_parse_SearchStoreInfo( int fd, map_session_data *sd ){
  16128. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16129. // minimum packet length
  16130. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16131. 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 );
  16132. return;
  16133. }
  16134. // check, if there is enough data for the claimed count of items
  16135. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16136. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16137. 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 ) );
  16138. return;
  16139. }
  16140. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16141. if( count < p->itemsCount + p->cardsCount ){
  16142. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16143. return;
  16144. }
  16145. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16146. }
  16147. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16148. /// 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 }*
  16149. /// is first page:
  16150. /// 0 = appends to existing results
  16151. /// 1 = clears previous results before displaying this result set
  16152. /// is next page:
  16153. /// 0 = no "next" label
  16154. /// 1 = "next" label to retrieve more results
  16155. void clif_search_store_info_ack( map_session_data* sd ){
  16156. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  16157. nullpo_retv( sd );
  16158. int fd = sd->fd;
  16159. if( !session_isActive( fd ) ){
  16160. return;
  16161. }
  16162. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16163. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16164. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16165. WFIFOHEAD( fd, len );
  16166. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16167. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16168. p->packetLength = len;
  16169. p->firstPage = !sd->searchstore.pages;
  16170. p->nextPage = searchstore_querynext( sd );
  16171. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16172. for( int i = 0; i < end - start; i++ ) {
  16173. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16174. p->items[i].storeId = ssitem->store_id;
  16175. p->items[i].AID = ssitem->account_id;
  16176. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16177. p->items[i].itemId = client_nameid( ssitem->nameid );
  16178. p->items[i].itemType = itemtype( ssitem->nameid );
  16179. p->items[i].price = ssitem->price;
  16180. p->items[i].amount = ssitem->amount;
  16181. p->items[i].refine = ssitem->refine;
  16182. // make-up an item for clif_addcards
  16183. struct item it = {};
  16184. for( int j = 0; j < MAX_SLOTS; j++ ){
  16185. it.card[j] = ssitem->card[j];
  16186. }
  16187. it.nameid = ssitem->nameid;
  16188. it.amount = ssitem->amount;
  16189. clif_addcards( &p->items[i].slot, &it );
  16190. #if PACKETVER >= 20150226
  16191. clif_add_random_options( p->items[i].option_data, it );
  16192. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16193. p->items[i].grade = ssitem->enchantgrade;
  16194. #endif
  16195. #endif
  16196. }
  16197. WFIFOSET( fd, len );
  16198. #endif
  16199. }
  16200. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16201. /// 0837 <reason>.B
  16202. /// reason:
  16203. /// 0 = "No matching stores were found." (0x70b)
  16204. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16205. /// 2 = "You cannot search anymore." (0x706)
  16206. /// 3 = "You cannot search yet." (0x708)
  16207. /// 4 = "No sale (purchase) information available." (0x705)
  16208. void clif_search_store_info_failed(map_session_data* sd, unsigned char reason)
  16209. {
  16210. int fd = sd->fd;
  16211. WFIFOHEAD(fd,packet_len(0x837));
  16212. WFIFOW(fd,0) = 0x837;
  16213. WFIFOB(fd,2) = reason;
  16214. WFIFOSET(fd,packet_len(0x837));
  16215. }
  16216. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16217. /// 0838
  16218. static void clif_parse_SearchStoreInfoNextPage(int fd, map_session_data* sd)
  16219. {
  16220. searchstore_next(sd);
  16221. }
  16222. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16223. /// 083a <type>.W <remaining uses>.B
  16224. /// type:
  16225. /// 0 = Search Stores
  16226. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16227. void clif_open_search_store_info(map_session_data* sd)
  16228. {
  16229. int fd = sd->fd;
  16230. WFIFOHEAD(fd,packet_len(0x83a));
  16231. WFIFOW(fd,0) = 0x83a;
  16232. WFIFOW(fd,2) = sd->searchstore.effect;
  16233. #if PACKETVER > 20100701
  16234. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16235. #endif
  16236. WFIFOSET(fd,packet_len(0x83a));
  16237. }
  16238. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16239. /// 083b
  16240. static void clif_parse_CloseSearchStoreInfo(int fd, map_session_data* sd)
  16241. {
  16242. searchstore_close(sd);
  16243. }
  16244. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16245. /// 083c <account id>.L <store id>.L <nameid>.W
  16246. static void clif_parse_SearchStoreInfoListItemClick( int fd, map_session_data* sd ){
  16247. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16248. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16249. }
  16250. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16251. /// 083d <xPos>.W <yPos>.W
  16252. void clif_search_store_info_click_ack(map_session_data* sd, short x, short y)
  16253. {
  16254. int fd = sd->fd;
  16255. WFIFOHEAD(fd,packet_len(0x83d));
  16256. WFIFOW(fd,0) = 0x83d;
  16257. WFIFOW(fd,2) = x;
  16258. WFIFOW(fd,4) = y;
  16259. WFIFOSET(fd,packet_len(0x83d));
  16260. }
  16261. /// Parse function for packet debugging.
  16262. void clif_parse_debug(int fd,map_session_data *sd)
  16263. {
  16264. int cmd, packet_len;
  16265. // clif_parse ensures, that there is at least 2 bytes of data
  16266. cmd = RFIFOW(fd,0);
  16267. if( sd ) {
  16268. packet_len = packet_db[cmd].len;
  16269. if( packet_len == 0 )
  16270. {// unknown
  16271. packet_len = RFIFOREST(fd);
  16272. }
  16273. else if( packet_len == -1 )
  16274. {// variable length
  16275. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16276. }
  16277. 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);
  16278. }
  16279. else
  16280. {
  16281. packet_len = RFIFOREST(fd);
  16282. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16283. }
  16284. ShowDump(RFIFOP(fd,0), packet_len);
  16285. }
  16286. /*==========================================
  16287. * Server tells client to display a window similar to Magnifier (item) one
  16288. * Server populates the window with avilable elemental converter options according to player's inventory
  16289. *------------------------------------------*/
  16290. void clif_elementalconverter_list( map_session_data *sd ){
  16291. nullpo_retv( sd );
  16292. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16293. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16294. int count = 0;
  16295. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16296. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16297. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16298. count++;
  16299. }
  16300. }
  16301. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16302. clif_send( p, p->packetLength, &sd->bl, SELF );
  16303. if( count > 0 ){
  16304. sd->menuskill_id = SA_CREATECON;
  16305. sd->menuskill_val = count;
  16306. }
  16307. }
  16308. /**
  16309. * Rune Knight
  16310. **/
  16311. void clif_millenniumshield(struct block_list *bl, short shields) {
  16312. #if PACKETVER >= 20081217
  16313. unsigned char buf[10];
  16314. WBUFW(buf,0) = 0x440;
  16315. WBUFL(buf,2) = bl->id;
  16316. WBUFW(buf,6) = shields;
  16317. WBUFW(buf,8) = 0;
  16318. clif_send(buf,packet_len(0x440),bl,AREA);
  16319. #endif
  16320. }
  16321. /**
  16322. * Mechanic
  16323. **/
  16324. /*==========================================
  16325. * Magic Decoy Material List
  16326. *------------------------------------------*/
  16327. void clif_magicdecoy_list( map_session_data& sd, uint16 skill_lv, short x, short y ){
  16328. PACKET_ZC_MAKINGARROW_LIST* p = (PACKET_ZC_MAKINGARROW_LIST*)packet_buffer;
  16329. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16330. p->packetLength = sizeof( *p );
  16331. size_t count = 0;
  16332. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16333. if( itemdb_group.item_exists( IG_ELEMENT, sd.inventory.u.items_inventory[i].nameid ) ){
  16334. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16335. p->packetLength += sizeof( p->items[0] );
  16336. count++;
  16337. }
  16338. }
  16339. if( count > 0 ){
  16340. clif_send( p, p->packetLength, &sd.bl, SELF );
  16341. sd.menuskill_id = NC_MAGICDECOY;
  16342. sd.menuskill_val = skill_lv;
  16343. sd.sc.comet_x = x;
  16344. sd.sc.comet_y = y;
  16345. }else{
  16346. clif_skill_fail( sd, NC_MAGICDECOY );
  16347. }
  16348. }
  16349. /*==========================================
  16350. * Guillotine Cross Poisons List
  16351. *------------------------------------------*/
  16352. void clif_poison_list( map_session_data& sd, uint16 skill_lv ){
  16353. PACKET_ZC_MAKINGARROW_LIST* p = (PACKET_ZC_MAKINGARROW_LIST*)packet_buffer;
  16354. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16355. p->packetLength = sizeof( *p );
  16356. size_t count = 0;
  16357. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16358. if( itemdb_group.item_exists( IG_POISON, sd.inventory.u.items_inventory[i].nameid ) ){
  16359. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16360. p->packetLength += sizeof( p->items[0] );
  16361. count++;
  16362. }
  16363. }
  16364. if( count > 0 ){
  16365. clif_send( p, p->packetLength, &sd.bl, SELF );
  16366. sd.menuskill_id = GC_POISONINGWEAPON;
  16367. sd.menuskill_val = skill_lv;
  16368. }else{
  16369. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON );
  16370. }
  16371. }
  16372. /// 0442 <Length>.W <why>.L { <Skill_Id>.W }* (ZC_SKILL_SELECT_REQUEST).
  16373. void clif_autoshadowspell_list( map_session_data& sd ){
  16374. #if PACKETVER >= 20081210
  16375. if( sd.menuskill_id == SC_AUTOSHADOWSPELL )
  16376. return;
  16377. PACKET_ZC_SKILL_SELECT_REQUEST* p = (PACKET_ZC_SKILL_SELECT_REQUEST*)packet_buffer;
  16378. p->packetType = HEADER_ZC_SKILL_SELECT_REQUEST;
  16379. p->packetLength = sizeof( *p );
  16380. p->why = 1; // enum PACKET_ZC_SKILL_SELECT_REQUEST::enumWHY::WHY_SC_AUTOSHADOWSPELL = 0x1
  16381. size_t count = 0;
  16382. for( size_t i = 0; i < MAX_SKILL; i++ ){
  16383. if( sd.status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd.status.skill[i].id > 0 &&
  16384. skill_get_inf2(sd.status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16385. {
  16386. p->skills[count].skill_id = sd.status.skill[i].id;
  16387. p->packetLength += sizeof( p->skills[0] );
  16388. count++;
  16389. }
  16390. }
  16391. if( count > 0 ) {
  16392. clif_send( p, p->packetLength, &sd.bl, SELF );
  16393. sd.menuskill_id = SC_AUTOSHADOWSPELL;
  16394. sd.menuskill_val = count;
  16395. } else {
  16396. status_change_end( &sd.bl, SC_STOP );
  16397. clif_skill_fail( sd, SC_AUTOSHADOWSPELL, USESKILL_FAIL_IMITATION_SKILL_NONE );
  16398. }
  16399. #endif
  16400. }
  16401. /*===========================================
  16402. * Skill list for Four Elemental Analysis
  16403. * and Change Material skills.
  16404. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16405. *------------------------------------------*/
  16406. int clif_skill_itemlistwindow( map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16407. #if PACKETVER >= 20090922
  16408. int fd = sd->fd;
  16409. nullpo_ret(sd);
  16410. sd->menuskill_id = skill_id; // To prevent hacking.
  16411. sd->menuskill_val = skill_lv;
  16412. if( skill_id == GN_CHANGEMATERIAL )
  16413. skill_lv = 0; // Changematerial
  16414. WFIFOHEAD(fd, packet_len(0x7e3));
  16415. WFIFOW(fd,0) = 0x7e3;
  16416. WFIFOL(fd,2) = skill_lv;
  16417. WFIFOL(fd,4) = 0;
  16418. WFIFOSET(fd, packet_len(0x7e3));
  16419. #endif
  16420. return 1;
  16421. }
  16422. /*==========================================
  16423. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16424. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16425. * RFIFOL(fd,2) - type (currently not used)
  16426. *------------------------------------------*/
  16427. void clif_parse_SkillSelectMenu(int fd, map_session_data *sd) {
  16428. if( sd == nullptr ){
  16429. return;
  16430. }
  16431. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16432. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16433. if (sd->menuskill_id == SA_AUTOSPELL) {
  16434. sd->state.workinprogress = WIP_DISABLE_NONE;
  16435. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16436. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16437. if (pc_istrading(sd)) {
  16438. clif_skill_fail( *sd, sd->ud.skill_id );
  16439. clif_menuskill_clear(sd);
  16440. return;
  16441. }
  16442. skill_select_menu(*sd, RFIFOW(fd, info->pos[1]));
  16443. } else
  16444. return;
  16445. clif_menuskill_clear(sd);
  16446. }
  16447. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16448. /// 08cf <id>.L <type>.W <num>.W
  16449. void clif_spiritcharm(map_session_data *sd) {
  16450. unsigned char buf[10];
  16451. nullpo_retv(sd);
  16452. WBUFW(buf,0) = 0x08cf;
  16453. WBUFL(buf,2) = sd->bl.id;
  16454. WBUFW(buf,6) = sd->spiritcharm_type;
  16455. WBUFW(buf,8) = sd->spiritcharm;
  16456. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16457. }
  16458. /// Move Item from or to Personal Tab
  16459. /// 0907 <index>.W <type>.B (CZ_INVENTORY_TAB)
  16460. /// type:
  16461. /// 0 = move item to personal tab
  16462. /// 1 = move item to normal tab
  16463. void clif_parse_MoveItem( int fd, map_session_data* sd ){
  16464. // TODO: Check for correct packet version
  16465. #if PACKETVER >= 20120410
  16466. /* can't move while dead. */
  16467. if(pc_isdead(sd)) {
  16468. return;
  16469. }
  16470. PACKET_CZ_INVENTORY_TAB* p = (PACKET_CZ_INVENTORY_TAB*)RFIFOP( fd, 0 );
  16471. uint16 index = server_index( p->index );
  16472. if( index >= MAX_INVENTORY ){
  16473. return;
  16474. }
  16475. if ( sd->inventory.u.items_inventory[index].favorite != 0 && p->favorite == true )
  16476. sd->inventory.u.items_inventory[index].favorite = 0;
  16477. else if( p->favorite == false )
  16478. sd->inventory.u.items_inventory[index].favorite = 1;
  16479. else
  16480. return;/* nothing to do. */
  16481. clif_favorite_item( *sd, index );
  16482. #endif
  16483. }
  16484. /// Items that are in favorite tab of inventory.
  16485. /// 0908 <index>.W <favorite>.B (ZC_INVENTORY_TAB)
  16486. static void clif_favorite_item( map_session_data& sd, uint16 index ){
  16487. // TODO: Check for correct packet version
  16488. #if PACKETVER >= 20111122
  16489. PACKET_ZC_INVENTORY_TAB p = {};
  16490. p.packetType = HEADER_ZC_INVENTORY_TAB;
  16491. p.index = client_index( index );
  16492. p.favorite = ( sd.inventory.u.items_inventory[index].favorite == 1 ) ? false : true;
  16493. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16494. #endif
  16495. }
  16496. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16497. void clif_snap( struct block_list *bl, short x, short y ) {
  16498. unsigned char buf[10];
  16499. WBUFW(buf,0) = 0x8d2;
  16500. WBUFL(buf,2) = bl->id;
  16501. WBUFW(buf,6) = x;
  16502. WBUFW(buf,8) = y;
  16503. if( disguised(bl) )
  16504. {
  16505. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16506. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16507. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16508. } else
  16509. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16510. }
  16511. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16512. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16513. #if PACKETVER >= 20120404
  16514. WFIFOHEAD(fd,packet_len(0x977));
  16515. WFIFOW(fd,0) = 0x977;
  16516. WFIFOL(fd,2) = md->bl.id;
  16517. WFIFOL(fd,6) = md->status.hp;
  16518. WFIFOL(fd,10) = md->status.max_hp;
  16519. WFIFOSET(fd,packet_len(0x977));
  16520. #endif
  16521. }
  16522. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16523. void __attribute__ ((unused)) clif_parse_dull(int fd, map_session_data *sd) {
  16524. return;
  16525. }
  16526. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16527. /// 0979 <world name>.24B <char name>.24B
  16528. void clif_ackworldinfo(map_session_data* sd) {
  16529. int fd;
  16530. nullpo_retv(sd);
  16531. fd = sd->fd;
  16532. WFIFOHEAD(fd,packet_len(0x979));
  16533. WFIFOW(fd,0)=0x979;
  16534. //AID -> world name ?
  16535. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16536. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16537. WFIFOSET(fd,packet_len(0x979));
  16538. }
  16539. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16540. /// 0978 <AID>.L
  16541. void clif_parse_reqworldinfo(int fd,map_session_data *sd) {
  16542. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16543. if(sd)
  16544. clif_ackworldinfo(sd);
  16545. }
  16546. static void clif_loadConfirm( map_session_data *sd ){
  16547. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16548. nullpo_retv( sd );
  16549. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16550. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16551. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16552. clif_instance_info( *sd );
  16553. #endif
  16554. }
  16555. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16556. /// 0447
  16557. void clif_parse_blocking_playcancel( int fd, map_session_data *sd ){
  16558. clif_loadConfirm( sd );
  16559. }
  16560. /// req world info (CZ_CLIENT_VERSION)
  16561. /// 044A <version>.L
  16562. void clif_parse_client_version(int fd, map_session_data *sd) {
  16563. //if(sd)
  16564. ;
  16565. }
  16566. /// Ranking list
  16567. /// ranking pointlist { <name>.24B <point>.L }*10
  16568. void clif_sub_ranklist(unsigned char *buf,int idx,map_session_data* sd, enum e_rank rankingtype){
  16569. struct fame_list* list;
  16570. int i, size = MAX_FAME_LIST;
  16571. switch(rankingtype) {
  16572. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16573. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16574. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16575. // PK currently unsupported
  16576. case RANK_KILLER: list = NULL; size = 0; break;
  16577. default:
  16578. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16579. return;
  16580. }
  16581. //Packet size limits this list to 10 elements. [Skotlex]
  16582. for (i = 0; i < min(10,size); i++) {
  16583. if (list[i].id > 0) {
  16584. const char* name;
  16585. if (strcmp(list[i].name, "-") == 0 &&
  16586. (name = map_charid2nick(list[i].id)) != NULL)
  16587. {
  16588. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16589. } else {
  16590. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16591. }
  16592. } else {
  16593. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16594. }
  16595. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16596. }
  16597. for(;i < 10; i++) { //In case the MAX is less than 10.
  16598. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16599. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16600. }
  16601. }
  16602. /// Request for the blacksmith ranklist.
  16603. /// /blacksmith command sends this packet to the server.
  16604. /// 0217 (CZ_BLACKSMITH_RANK)
  16605. void clif_parse_Blacksmith( int fd, map_session_data *sd ){
  16606. clif_ranklist(sd,RANK_BLACKSMITH);
  16607. }
  16608. /// Request for the alchemist ranklist.
  16609. /// /alchemist command sends this packet to the server.
  16610. /// 0218 (CZ_ALCHEMIST_RANK)
  16611. void clif_parse_Alchemist( int fd, map_session_data *sd ){
  16612. clif_ranklist(sd,RANK_ALCHEMIST);
  16613. }
  16614. /// Request for the taekwon ranklist.
  16615. /// /taekwon command sends this packet to the server.
  16616. /// 0225 (CZ_TAEKWON_RANK)
  16617. void clif_parse_Taekwon( int fd, map_session_data *sd ){
  16618. clif_ranklist(sd,RANK_TAEKWON);
  16619. }
  16620. /// Request for the killer ranklist.
  16621. /// /pk command sends this packet to the server.
  16622. /// 0237 (CZ_KILLER_RANK)
  16623. void clif_parse_RankingPk( int fd, map_session_data *sd ){
  16624. clif_ranklist(sd,RANK_KILLER);
  16625. }
  16626. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16627. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16628. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16629. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16630. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16631. void clif_ranklist(map_session_data *sd, int16 rankingType) {
  16632. enum e_rank rank;
  16633. #if PACKETVER < 20130710
  16634. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16635. short cmd;
  16636. switch( rankingType ){
  16637. case RANK_BLACKSMITH: cmd = 0x219; break;
  16638. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16639. case RANK_TAEKWON: cmd = 0x226; break;
  16640. case RANK_KILLER: cmd = 0x238; break;
  16641. default:
  16642. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16643. return;
  16644. }
  16645. // Can be safely casted here, since we validated it before
  16646. rank = (enum e_rank)rankingType;
  16647. WBUFW(buf,0) = cmd;
  16648. clif_sub_ranklist(buf,2,sd,rank);
  16649. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16650. #else
  16651. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16652. int mypoint = 0;
  16653. switch( rankingType ){
  16654. case RANK_BLACKSMITH:
  16655. case RANK_ALCHEMIST:
  16656. case RANK_TAEKWON:
  16657. case RANK_KILLER:
  16658. break;
  16659. default:
  16660. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16661. return;
  16662. }
  16663. // Can be safely casted here, since we validated it before
  16664. rank = (enum e_rank)rankingType;
  16665. WBUFW(buf,0) = 0x97d;
  16666. WBUFW(buf,2) = rank;
  16667. clif_sub_ranklist(buf,4,sd,rank);
  16668. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16669. case MAPID_BLACKSMITH:
  16670. case MAPID_ALCHEMIST:
  16671. case MAPID_TAEKWON:
  16672. mypoint = sd->status.fame;
  16673. }
  16674. WBUFL(buf,284) = mypoint; //mypoint
  16675. clif_send(buf, 288, &sd->bl, SELF);
  16676. #endif
  16677. }
  16678. /*
  16679. * 097c <type> (CZ_REQ_RANKING)
  16680. * type
  16681. * 0: /blacksmith
  16682. * 1: /alchemist
  16683. * 2: /taekwon
  16684. * 3: /pk
  16685. * */
  16686. void clif_parse_ranklist(int fd,map_session_data *sd) {
  16687. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16688. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16689. clif_ranklist(sd,rankingtype);
  16690. }
  16691. /// Updates the fame rank points for the given ranking.
  16692. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16693. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16694. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16695. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16696. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16697. int fd = sd.fd;
  16698. #if PACKETVER < 20130710
  16699. short cmd;
  16700. switch(rankingtype){
  16701. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16702. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16703. case RANK_TAEKWON: cmd = 0x224; break;
  16704. default:
  16705. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16706. return;
  16707. }
  16708. WFIFOHEAD(fd,packet_len(cmd));
  16709. WFIFOW(fd,0) = cmd;
  16710. WFIFOL(fd,2) = point;
  16711. WFIFOL(fd,6) = sd.status.fame;
  16712. WFIFOSET(fd, packet_len(cmd));
  16713. #else
  16714. WFIFOHEAD(fd,packet_len(0x97e));
  16715. WFIFOW(fd,0) = 0x97e;
  16716. WFIFOW(fd,2) = rankingtype;
  16717. WFIFOL(fd,4) = point;
  16718. WFIFOL(fd,8) = sd.status.fame;
  16719. WFIFOSET(fd,packet_len(0x97e));
  16720. #endif
  16721. }
  16722. /**
  16723. * Transmit personal information to player. (rates)
  16724. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16725. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16726. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16727. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16728. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16729. * FIXME!
  16730. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16731. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16732. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16733. */
  16734. #ifdef VIP_ENABLE
  16735. void clif_display_pinfo( map_session_data& sd ){
  16736. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16737. // 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]
  16738. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16739. /**
  16740. * EXP
  16741. */
  16742. //0:PCRoom
  16743. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16744. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16745. details_bexp[PINFO_BASIC] = 0;
  16746. else {
  16747. if (details_bexp[PINFO_BASIC] < 100) {
  16748. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16749. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16750. } else
  16751. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16752. }
  16753. //1:Premium
  16754. if( pc_isvip( &sd ) ){
  16755. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16756. if (details_bexp[PINFO_PREMIUM] < 0)
  16757. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16758. } else
  16759. details_bexp[PINFO_PREMIUM] = 0;
  16760. //2:Server
  16761. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16762. if (details_bexp[PINFO_SERVER] == 100)
  16763. details_bexp[PINFO_SERVER] = 0;
  16764. else {
  16765. if (details_bexp[PINFO_SERVER] < 100) {
  16766. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16767. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16768. } else
  16769. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16770. }
  16771. //3:TPLUS
  16772. details_bexp[PINFO_CAFE] = 0;
  16773. /**
  16774. * Drop rate
  16775. */
  16776. //0:PCRoom
  16777. details_drop[PINFO_BASIC] = 0;
  16778. //1:Premium
  16779. if( pc_isvip( &sd ) ){
  16780. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16781. if (details_drop[PINFO_PREMIUM] < 0)
  16782. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16783. } else
  16784. details_drop[PINFO_PREMIUM] = 0;
  16785. //2:Server
  16786. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16787. if (details_drop[PINFO_SERVER] == 100)
  16788. details_drop[PINFO_SERVER] = 0;
  16789. else {
  16790. if (details_drop[PINFO_SERVER] < 100) {
  16791. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16792. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16793. } else
  16794. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16795. }
  16796. //3:TPLUS
  16797. details_drop[PINFO_CAFE] = 0;
  16798. /**
  16799. * Penalty rate
  16800. */
  16801. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16802. //0:PCRoom
  16803. details_penalty[PINFO_BASIC] = 0;
  16804. //1:Premium
  16805. if( pc_isvip( &sd ) ){
  16806. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16807. if (details_penalty[PINFO_PREMIUM] == 100)
  16808. details_penalty[PINFO_PREMIUM] = 0;
  16809. else {
  16810. if (details_penalty[PINFO_PREMIUM] < 100) {
  16811. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16812. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16813. } else
  16814. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16815. }
  16816. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16817. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16818. } else
  16819. details_penalty[PINFO_PREMIUM] = 0;
  16820. //2:Server
  16821. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16822. if (details_penalty[PINFO_SERVER] == 100)
  16823. details_penalty[PINFO_SERVER] = 0;
  16824. else {
  16825. if (details_penalty[PINFO_SERVER] < 100) {
  16826. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16827. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16828. } else
  16829. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16830. }
  16831. //3:TPLUS
  16832. details_penalty[PINFO_CAFE] = 0;
  16833. struct PACKET_ZC_PERSONAL_INFOMATION* p = (struct PACKET_ZC_PERSONAL_INFOMATION*)packet_buffer;
  16834. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16835. p->length = sizeof( *p ) + PINFO_MAX * sizeof( p->details[0] );
  16836. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16837. p->total_exp = 100 * 1000;
  16838. p->total_death = 100 * 1000;
  16839. p->total_drop = 100 * 1000;
  16840. #else
  16841. p->total_exp = 100;
  16842. p->total_death = 100;
  16843. p->total_drop = 100;
  16844. #endif
  16845. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16846. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16847. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16848. p->details[i].exp = details_bexp[i] * 1000;
  16849. p->details[i].death = details_penalty[i] * 1000;
  16850. p->details[i].drop = details_drop[i] * 1000;
  16851. #else
  16852. p->details[i].exp = details_bexp[i];
  16853. p->details[i].death = details_penalty[i];
  16854. p->details[i].drop = details_drop[i];
  16855. #endif
  16856. p->total_exp += p->details[i].exp;
  16857. p->total_death += p->details[i].death;
  16858. p->total_drop += p->details[i].drop;
  16859. }
  16860. clif_send( p, p->length, &sd.bl, SELF );
  16861. #endif
  16862. }
  16863. #endif
  16864. void clif_parse_GMFullStrip(int fd, map_session_data *sd) {
  16865. char cmd[30];
  16866. int t_aid = RFIFOL(fd,2);
  16867. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16868. is_atcommand(fd, sd, cmd, 1);
  16869. }
  16870. /**
  16871. * Marks Crimson Marker target on mini-map to the caster
  16872. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16873. * @param fd
  16874. * @param bl Crimson Marker target
  16875. **/
  16876. void clif_crimson_marker( map_session_data& sd, struct block_list& bl, bool remove ){
  16877. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16878. struct PACKET_ZC_C_MARKERINFO p = {};
  16879. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16880. p.AID = bl.id;
  16881. if( remove ){
  16882. p.xPos = -1;
  16883. p.yPos = -1;
  16884. }else{
  16885. p.xPos = bl.x;
  16886. p.yPos = bl.y;
  16887. }
  16888. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16889. #endif
  16890. }
  16891. /**
  16892. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16893. **/
  16894. void clif_notify_bindOnEquip( map_session_data& sd, int16 index ){
  16895. #if PACKETVER >= 20070227
  16896. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16897. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16898. p.index = client_index( index );
  16899. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16900. #endif
  16901. }
  16902. /**
  16903. * [Ind/Hercules]
  16904. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16905. **/
  16906. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16907. char buf[256];
  16908. size_t len;
  16909. nullpo_retv(bl);
  16910. if(!message)
  16911. return;
  16912. len = strlen(message)+1;
  16913. if( len > sizeof(buf)-8 ) {
  16914. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16915. len = sizeof(buf)-8;
  16916. }
  16917. WBUFW(buf,0) = 0x8b3;
  16918. WBUFW(buf,2) = (uint16)(len+8);
  16919. WBUFL(buf,4) = bl->id;
  16920. safestrncpy(WBUFCP(buf,8), message, len);
  16921. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16922. }
  16923. /**
  16924. * [Ind/Hercules]
  16925. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16926. **/
  16927. void clif_party_leaderchanged(map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16928. unsigned char buf[10];
  16929. nullpo_retv(sd);
  16930. WBUFW(buf,0) = 0x7fc;
  16931. WBUFL(buf,2) = prev_leader_aid;
  16932. WBUFL(buf,6) = new_leader_aid;
  16933. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16934. }
  16935. /**
  16936. * Sends a clan message to a player
  16937. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16938. **/
  16939. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16940. #if PACKETVER >= 20131223
  16941. map_session_data *sd;
  16942. uint8 buf[256];
  16943. if( len == 0 ){
  16944. return;
  16945. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16946. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16947. len = sizeof(buf)-5-NAME_LENGTH;
  16948. }
  16949. WBUFW(buf, 0) = 0x98e;
  16950. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16951. // 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
  16952. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16953. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16954. if((sd = clan_getavailablesd(clan)) != NULL)
  16955. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16956. #endif
  16957. }
  16958. /**
  16959. * Parses a clan message from a player.
  16960. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16961. **/
  16962. void clif_parse_clan_chat( int fd, map_session_data* sd ){
  16963. #if PACKETVER >= 20131223
  16964. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16965. // validate packet and retrieve name and message
  16966. if( !clif_process_message(sd, false, name, message, output ) )
  16967. return;
  16968. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16969. #endif
  16970. }
  16971. /**
  16972. * Sends the basic clan informations to the client.
  16973. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16974. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16975. **/
  16976. void clif_clan_basicinfo( map_session_data *sd ){
  16977. #if PACKETVER >= 20131223
  16978. int fd, offset, length, i, flag;
  16979. struct clan* clan;
  16980. char mapname[MAP_NAME_LENGTH_EXT];
  16981. nullpo_retv( sd );
  16982. nullpo_retv( clan = sd->clan );
  16983. // Check if the player has a valid session and is not autotrading
  16984. if( !clif_session_isValid( sd ) ){
  16985. return;
  16986. }
  16987. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16988. fd = sd->fd;
  16989. WFIFOHEAD(fd,length);
  16990. memset( WFIFOP(fd, 0), 0, length );
  16991. WFIFOW( fd, 0 ) = 0x98a;
  16992. WFIFOL( fd, 4 ) = clan->id;
  16993. offset = 8;
  16994. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16995. offset += NAME_LENGTH;
  16996. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16997. offset += NAME_LENGTH;
  16998. mapindex_getmapname_ext( clan->map, mapname );
  16999. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  17000. offset += MAP_NAME_LENGTH_EXT;
  17001. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  17002. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  17003. for( flag = 0; flag < 2; flag++ ){
  17004. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  17005. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  17006. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  17007. offset += NAME_LENGTH;
  17008. }
  17009. }
  17010. }
  17011. WFIFOW( fd, 2 ) = offset;
  17012. WFIFOSET(fd,offset);
  17013. #endif
  17014. }
  17015. /**
  17016. * Updates the online and maximum player count of a clan.
  17017. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  17018. **/
  17019. void clif_clan_onlinecount( struct clan* clan ){
  17020. #if PACKETVER >= 20131223
  17021. uint8 buf[6];
  17022. map_session_data *sd;
  17023. WBUFW(buf,0) = 0x988;
  17024. WBUFW(buf,2) = clan->connect_member;
  17025. WBUFW(buf,4) = clan->max_member;
  17026. if((sd = clan_getavailablesd(clan)) != NULL)
  17027. clif_send(buf, 6, &sd->bl, CLAN);
  17028. #endif
  17029. }
  17030. /**
  17031. * Notifies the client that the player has left his clan.
  17032. * 0989 (ZC_ACK_CLAN_LEAVE)
  17033. **/
  17034. void clif_clan_leave( map_session_data* sd ){
  17035. #if PACKETVER >= 20131223
  17036. int fd;
  17037. nullpo_retv( sd );
  17038. if( !clif_session_isValid( sd ) ){
  17039. return;
  17040. }
  17041. fd = sd->fd;
  17042. WFIFOHEAD(fd,2);
  17043. WFIFOW(fd,0) = 0x989;
  17044. WFIFOSET(fd,2);
  17045. #endif
  17046. }
  17047. /**
  17048. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  17049. * 0A2F <result>.B <title_id>.L
  17050. */
  17051. void clif_change_title_ack(map_session_data *sd, unsigned char result, unsigned long title_id)
  17052. {
  17053. #if PACKETVER >= 20150513
  17054. int fd;
  17055. nullpo_retv(sd);
  17056. if (!clif_session_isValid(sd))
  17057. return;
  17058. fd = sd->fd;
  17059. WFIFOHEAD(fd, packet_len(0xa2f));
  17060. WFIFOW(fd, 0) = 0xa2f;
  17061. WFIFOB(fd, 2) = result;
  17062. WFIFOL(fd, 3) = title_id;
  17063. WFIFOSET(fd, packet_len(0xa2f));
  17064. #endif
  17065. }
  17066. /**
  17067. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  17068. * 0A2E <title_id>.L
  17069. */
  17070. void clif_parse_change_title(int fd, map_session_data *sd)
  17071. {
  17072. int title_id;
  17073. nullpo_retv(sd);
  17074. title_id = RFIFOL(fd, 2);
  17075. if( title_id == sd->status.title_id ){
  17076. // It is exactly the same as the old one
  17077. return;
  17078. }else if( title_id <= 0 ){
  17079. sd->status.title_id = 0;
  17080. }else{
  17081. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17082. clif_change_title_ack(sd, 1, title_id);
  17083. return;
  17084. }
  17085. sd->status.title_id = title_id;
  17086. }
  17087. clif_name_area(&sd->bl);
  17088. clif_change_title_ack(sd, 0, title_id);
  17089. }
  17090. #ifdef DUMP_UNKNOWN_PACKET
  17091. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17092. {
  17093. const char* packet_txt = "save/packet.txt";
  17094. FILE* fp;
  17095. time_t time_server;
  17096. struct tm *datetime;
  17097. char datestr[512];
  17098. time(&time_server); // get time in seconds since 1/1/1970
  17099. datetime = localtime(&time_server); // convert seconds in structure
  17100. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17101. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17102. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17103. if( sd ) {
  17104. 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);
  17105. } else {
  17106. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17107. }
  17108. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17109. fprintf(fp, "\n");
  17110. fclose(fp);
  17111. } else {
  17112. ShowError("Failed to write '%s'.\n", packet_txt);
  17113. // Dump on console instead
  17114. if( sd ) {
  17115. 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);
  17116. } else {
  17117. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17118. }
  17119. ShowDump(RFIFOP(fd,0), packet_len);
  17120. }
  17121. }
  17122. #endif
  17123. /// Roulette System
  17124. /// Author: Yommy
  17125. void roulette_generate_bonus( map_session_data& sd ){
  17126. if( battle_config.feature_roulette_bonus_reward && sd.roulette.bonusItemID == 0 ){
  17127. int next_stage = 0;
  17128. if( sd.roulette_point.bronze > 0 ){
  17129. next_stage = 0;
  17130. }else if( sd.roulette_point.silver > 9 ){
  17131. next_stage = 2;
  17132. }else if( sd.roulette_point.gold > 9 ){
  17133. next_stage = 4;
  17134. }
  17135. // Get bonus item stage only from current stage or higher
  17136. int reward_stage = rnd_value( next_stage, MAX_ROULETTE_LEVEL - 1 );
  17137. sd.roulette.bonusItemID = rd.nameid[reward_stage][rnd()%rd.items[reward_stage]];
  17138. }else{
  17139. sd.roulette.bonusItemID = 0;
  17140. }
  17141. }
  17142. /// Opens the roulette window
  17143. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17144. void clif_roulette_open( map_session_data* sd ){
  17145. nullpo_retv( sd );
  17146. roulette_generate_bonus( *sd );
  17147. struct packet_roulette_open_ack p;
  17148. p.PacketType = 0xa1a;
  17149. p.Result = 0; // result
  17150. p.Serial = 0; // serial
  17151. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17152. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17153. p.AdditionItemID = sd->roulette.bonusItemID;
  17154. p.GoldPoint = sd->roulette_point.gold;
  17155. p.SilverPoint = sd->roulette_point.silver;
  17156. p.BronzePoint = sd->roulette_point.bronze;
  17157. sd->state.roulette_open = true;
  17158. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17159. }
  17160. /// Request to open the roulette window
  17161. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17162. void clif_parse_roulette_open( int fd, map_session_data* sd ){
  17163. nullpo_retv(sd);
  17164. if (!battle_config.feature_roulette) {
  17165. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17166. return;
  17167. }
  17168. clif_roulette_open(sd);
  17169. }
  17170. /// Sends the info about the available roulette rewards to the client
  17171. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17172. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17173. void clif_roulette_info( map_session_data* sd ){
  17174. nullpo_retv(sd);
  17175. struct packet_roulette_info_ack p;
  17176. p.PacketType = rouletteinfoackType;
  17177. p.PacketLength = sizeof(p);
  17178. p.RouletteSerial = 1;
  17179. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17180. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17181. p.ItemInfo[count].Row = i;
  17182. p.ItemInfo[count].Position = j;
  17183. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17184. p.ItemInfo[count].Count = rd.qty[i][j];
  17185. #if PACKETVER >= 20180511
  17186. p.ItemInfo[count].unused = 0;
  17187. #endif
  17188. count++;
  17189. }
  17190. }
  17191. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17192. }
  17193. /// Request the roulette reward data
  17194. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17195. void clif_parse_roulette_info( int fd, map_session_data* sd ){
  17196. nullpo_retv(sd);
  17197. if (!battle_config.feature_roulette) {
  17198. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17199. return;
  17200. }
  17201. clif_roulette_info(sd);
  17202. }
  17203. /// Notification of the client that the roulette window was closed
  17204. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17205. void clif_parse_roulette_close( int fd, map_session_data* sd ){
  17206. nullpo_retv(sd);
  17207. if (!battle_config.feature_roulette) {
  17208. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17209. return;
  17210. }
  17211. sd->state.roulette_open = false;
  17212. }
  17213. /// Response to a item reward request
  17214. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17215. static void clif_roulette_recvitem_ack(map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17216. #if PACKETVER >= 20141016
  17217. nullpo_retv(sd);
  17218. struct packet_roulette_itemrecv_ack p;
  17219. p.PacketType = roulettercvitemackType;
  17220. p.Result = type;
  17221. p.AdditionItemID = sd->roulette.bonusItemID;
  17222. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17223. #endif
  17224. }
  17225. /**
  17226. * Claim roulette reward
  17227. * @param sd Player
  17228. * @return 0:Success
  17229. **/
  17230. static uint8 clif_roulette_getitem(map_session_data *sd) {
  17231. struct item it;
  17232. uint8 res = 1;
  17233. unsigned short factor = 1;
  17234. nullpo_retr(1, sd);
  17235. if (sd->roulette.prizeIdx < 0)
  17236. return RECV_ITEM_FAILED;
  17237. memset(&it, 0, sizeof(it));
  17238. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17239. it.identify = 1;
  17240. if( sd->roulette.bonusItemID != 0 ){
  17241. if( sd->roulette.bonusItemID == it.nameid && battle_config.feature_roulette_bonus_reward && !( rd.flag[sd->roulette.prizeStage][sd->roulette.prizeIdx]&1 ) ){
  17242. factor = 2;
  17243. // Reset the Bonus Item to trigger new calculation
  17244. sd->roulette.bonusItemID = 0;
  17245. }else{
  17246. for( int i = 0; i < MAX_ROULETTE_LEVEL && sd->roulette.bonusItemID != 0; i++ ){
  17247. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i && sd->roulette.bonusItemID != 0; j++ ){
  17248. if( rd.nameid[i][j] == sd->roulette.bonusItemID ){
  17249. // 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
  17250. if( sd->roulette.prizeStage >= i ){
  17251. // Reset the Bonus Item to trigger new calculation and to cancel the loops
  17252. sd->roulette.bonusItemID = 0;
  17253. }
  17254. }
  17255. }
  17256. }
  17257. }
  17258. }
  17259. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx] * factor, LOG_TYPE_ROULETTE)) == 0) {
  17260. ; // onSuccess
  17261. }
  17262. if( sd->roulette.bonusItemID == 0 ){
  17263. roulette_generate_bonus( *sd );
  17264. }
  17265. sd->roulette.claimPrize = false;
  17266. sd->roulette.prizeStage = 0;
  17267. sd->roulette.prizeIdx = -1;
  17268. sd->roulette.stage = 0;
  17269. return res;
  17270. }
  17271. /// Update Roulette window with current stats
  17272. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17273. void clif_roulette_generate( map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17274. nullpo_retv( sd );
  17275. struct packet_roulette_generate_ack p;
  17276. p.PacketType = roulettgenerateackType;
  17277. p.Result = result;
  17278. p.Step = stage;
  17279. p.Idx = prizeIdx;
  17280. p.AdditionItemID = battle_config.feature_roulette_bonus_reward ? bonusItemID : 0;
  17281. p.RemainGold = sd->roulette_point.gold;
  17282. p.RemainSilver = sd->roulette_point.silver;
  17283. p.RemainBronze = sd->roulette_point.bronze;
  17284. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17285. }
  17286. /// Request to start the roulette
  17287. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17288. void clif_parse_roulette_generate( int fd, map_session_data* sd ){
  17289. enum GENERATE_ROULETTE_ACK result;
  17290. nullpo_retv(sd);
  17291. if (!battle_config.feature_roulette) {
  17292. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17293. return;
  17294. }
  17295. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17296. return;
  17297. }
  17298. // Player has not claimed his prize yet
  17299. if( sd->roulette.claimPrize ){
  17300. clif_roulette_getitem( sd );
  17301. }
  17302. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17303. // Make sure everything is reset
  17304. sd->roulette.stage = 0;
  17305. sd->roulette.claimPrize = false;
  17306. sd->roulette.prizeStage = 0;
  17307. sd->roulette.prizeIdx = -1;
  17308. }
  17309. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17310. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17311. }else{
  17312. if (!sd->roulette.stage) {
  17313. if (sd->roulette_point.bronze > 0) {
  17314. sd->roulette_point.bronze -= 1;
  17315. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17316. } else if (sd->roulette_point.silver > 9) {
  17317. sd->roulette_point.silver -= 10;
  17318. sd->roulette.stage = 2;
  17319. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17320. } else if (sd->roulette_point.gold > 9) {
  17321. sd->roulette_point.gold -= 10;
  17322. sd->roulette.stage = 4;
  17323. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17324. }
  17325. }
  17326. sd->roulette.prizeStage = sd->roulette.stage;
  17327. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17328. sd->roulette.claimPrize = true;
  17329. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17330. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17331. result = GENERATE_ROULETTE_LOSING;
  17332. sd->roulette.stage = 0;
  17333. }else{
  17334. result = GENERATE_ROULETTE_SUCCESS;
  17335. sd->roulette.stage++;
  17336. }
  17337. }
  17338. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx), sd->roulette.bonusItemID);
  17339. }
  17340. /// Request to claim a prize
  17341. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17342. void clif_parse_roulette_item( int fd, map_session_data* sd ){
  17343. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17344. nullpo_retv(sd);
  17345. if (!battle_config.feature_roulette) {
  17346. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17347. return;
  17348. }
  17349. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17350. return;
  17351. }
  17352. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17353. switch (clif_roulette_getitem(sd)) {
  17354. case ADDITEM_SUCCESS:
  17355. type = RECV_ITEM_SUCCESS;
  17356. break;
  17357. case ADDITEM_INVALID:
  17358. case ADDITEM_OVERITEM:
  17359. case ADDITEM_OVERAMOUNT:
  17360. type = RECV_ITEM_OVERCOUNT;
  17361. break;
  17362. case ADDITEM_OVERWEIGHT:
  17363. type = RECV_ITEM_OVERWEIGHT;
  17364. break;
  17365. case ADDITEM_STACKLIMIT:
  17366. default:
  17367. type = RECV_ITEM_FAILED;
  17368. break;
  17369. }
  17370. }
  17371. clif_roulette_recvitem_ack(sd,type);
  17372. }
  17373. /// MERGE ITEM
  17374. /**
  17375. * Acknowledge the client about item merger result
  17376. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17377. * @param fd
  17378. * @param sd
  17379. **/
  17380. void clif_merge_item_ack( map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17381. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17382. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17383. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17384. if( type == MERGE_ITEM_SUCCESS ){
  17385. p.index = client_index( index );
  17386. }else{
  17387. p.index = index;
  17388. }
  17389. p.amount = count;
  17390. p.reason = type;
  17391. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17392. #endif
  17393. }
  17394. /**
  17395. * Check if item has the pair to be merged
  17396. * @param sd
  17397. * @param it Item
  17398. * @return True if has pair, False if not
  17399. **/
  17400. static bool clif_merge_item_has_pair(map_session_data *sd, struct item *it) {
  17401. struct item *it_;
  17402. unsigned short i;
  17403. nullpo_retr(false, sd);
  17404. 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);
  17405. if (i < MAX_INVENTORY)
  17406. return true;
  17407. return false;
  17408. }
  17409. /**
  17410. * Check if item can be merged
  17411. * @param id Item Data
  17412. * @param it Item
  17413. * @return True if can be merged, False if not
  17414. **/
  17415. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17416. if (!id || !it)
  17417. return false;
  17418. if (id->type == IT_CASH)
  17419. return false;
  17420. if (!itemdb_isstackable2(id))
  17421. return false;
  17422. if (itemdb_isspecial(it->card[0]))
  17423. return false;
  17424. if (!it->unique_id)
  17425. return false;
  17426. return true;
  17427. }
  17428. /**
  17429. * Open available item to be merged.
  17430. * Only show 1 item in 1 process.
  17431. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17432. * @param sd
  17433. **/
  17434. void clif_merge_item_open( map_session_data& sd ){
  17435. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17436. struct PACKET_ZC_MERGE_ITEM_OPEN* p = (struct PACKET_ZC_MERGE_ITEM_OPEN*)packet_buffer;
  17437. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17438. p->packetLen = sizeof( *p );
  17439. int n = 0;
  17440. // Get entries
  17441. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17442. struct item* it = &sd.inventory.u.items_inventory[i];
  17443. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17444. continue;
  17445. }
  17446. if( clif_merge_item_has_pair( &sd, it ) ){
  17447. p->items[n++].index = client_index( i );
  17448. p->packetLen += sizeof( p->items[0] );
  17449. }
  17450. }
  17451. // No item need to be merged
  17452. if( n < 2 ){
  17453. clif_msg( &sd, MERGE_ITEM_NOT_AVAILABLE );
  17454. return;
  17455. }
  17456. clif_send( p, p->packetLen, &sd.bl, SELF );
  17457. #endif
  17458. }
  17459. /**
  17460. * Process item merge request.
  17461. * 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17462. * @param fd
  17463. * @param sd
  17464. **/
  17465. void clif_parse_merge_item_req( int fd, map_session_data* sd ){
  17466. struct PACKET_CZ_REQ_MERGE_ITEM* p = (struct PACKET_CZ_REQ_MERGE_ITEM*)RFIFOP( fd, 0 );
  17467. int count = ( p->packetLength - sizeof( *p ) ) / sizeof( p->indices[0] );
  17468. // No item need to be merged
  17469. if( count < 2 ){
  17470. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17471. return;
  17472. }
  17473. uint16 idx_main = server_index( p->indices[0] );
  17474. if( idx_main >= MAX_INVENTORY ){
  17475. return;
  17476. }
  17477. if( !clif_merge_item_check( sd->inventory_data[idx_main], &sd->inventory.u.items_inventory[idx_main] ) ){
  17478. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17479. return;
  17480. }
  17481. // Ensure each index only comes once
  17482. std::unordered_set<uint16> indices;
  17483. for( int i = 1; i < count; i++ ){
  17484. uint16 idx = server_index( p->indices[i] );
  17485. if( idx >= MAX_INVENTORY ){
  17486. return;
  17487. }
  17488. if( sd->inventory_data[idx] == nullptr ){
  17489. return;
  17490. }
  17491. // Check if it is the same item
  17492. if( sd->inventory_data[idx]->nameid != sd->inventory_data[idx_main]->nameid ){
  17493. return;
  17494. }
  17495. if( !clif_merge_item_check( sd->inventory_data[idx], &sd->inventory.u.items_inventory[idx] ) ){
  17496. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17497. return;
  17498. }
  17499. indices.insert( idx );
  17500. }
  17501. if( indices.empty() ){
  17502. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17503. return;
  17504. }
  17505. uint32 total_amount = sd->inventory.u.items_inventory[idx_main].amount;
  17506. for( uint16 idx : indices ){
  17507. total_amount += sd->inventory.u.items_inventory[idx].amount;
  17508. }
  17509. uint16 stack = sd->inventory_data[idx_main]->stack.amount;
  17510. if( stack == 0 ){
  17511. stack = MAX_AMOUNT;
  17512. }
  17513. if( total_amount >= stack ){
  17514. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17515. return;
  17516. }
  17517. // Merrrrge!!!!
  17518. for( uint16 idx : indices ){
  17519. uint16 amount = sd->inventory.u.items_inventory[idx].amount;
  17520. log_pick_pc( sd, LOG_TYPE_MERGE_ITEM, -amount, &sd->inventory.u.items_inventory[idx] );
  17521. memset( &sd->inventory.u.items_inventory[idx], 0, sizeof( sd->inventory.u.items_inventory[0] ) );
  17522. sd->inventory_data[idx] = nullptr;
  17523. clif_delitem( sd, idx, amount, 0 );
  17524. }
  17525. sd->inventory.u.items_inventory[idx_main].amount = total_amount;
  17526. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, idx_main, total_amount );
  17527. }
  17528. /**
  17529. * Cancel item merge
  17530. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17531. * @param fd
  17532. * @param sd
  17533. **/
  17534. void clif_parse_merge_item_cancel(int fd, map_session_data* sd) {
  17535. return; // Nothing todo yet
  17536. }
  17537. static std::string clif_hide_name(const char* original_name)
  17538. {
  17539. std::string censored(original_name);
  17540. int hide = min(battle_config.broadcast_hide_name, censored.length() - 1);
  17541. censored.replace(censored.length() - hide, hide, hide, '*');
  17542. return censored;
  17543. }
  17544. /**
  17545. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17546. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17547. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17548. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17549. **/
  17550. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17551. char name[NAME_LENGTH];
  17552. if( battle_config.broadcast_hide_name ){
  17553. std::string dispname = clif_hide_name(char_name);
  17554. safestrncpy(name, dispname.c_str(), sizeof(name));
  17555. }else{
  17556. safestrncpy( name, char_name, sizeof( name ) );
  17557. }
  17558. switch( type ){
  17559. case ITEMOBTAIN_TYPE_BOXITEM:
  17560. #if PACKETVER >= 20091201
  17561. {
  17562. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17563. p.PacketType = package_item_announceType;
  17564. p.PacketLength = sizeof( p );
  17565. p.type = type;
  17566. p.ItemID = client_nameid( nameid );
  17567. p.len = NAME_LENGTH;
  17568. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17569. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17570. p.BoxItemID = client_nameid( container );
  17571. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17572. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17573. p.refineLevel = 0; // TODO: implement
  17574. #endif
  17575. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17576. }
  17577. #endif
  17578. break;
  17579. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17580. case ITEMOBTAIN_TYPE_NPC:
  17581. {
  17582. struct packet_item_drop_announce p;
  17583. p.PacketType = item_drop_announceType;
  17584. p.type = type;
  17585. p.ItemID = client_nameid( nameid );
  17586. p.len = NAME_LENGTH;
  17587. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17588. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17589. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17590. p.monsterNameLen = NAME_LENGTH;
  17591. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17592. }else{
  17593. p.monsterNameLen = 0;
  17594. p.monsterName[0] = '\0';
  17595. }
  17596. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17597. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17598. #else
  17599. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17600. #endif
  17601. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17602. }
  17603. break;
  17604. }
  17605. }
  17606. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17607. /// 0A02 <view>.W
  17608. /// Value <flag> has the following effects:
  17609. /// 1: Open a Dress Room window.
  17610. void clif_dressing_room(map_session_data *sd, int flag) {
  17611. #if PACKETVER >= 20150513
  17612. int fd = sd->fd;
  17613. nullpo_retv(sd);
  17614. WFIFOHEAD(fd, packet_len(0xa02));
  17615. WFIFOW(fd,0) = 0xa02;
  17616. WFIFOW(fd,2) = flag;
  17617. WFIFOSET(fd, packet_len(0xa02));
  17618. #endif
  17619. }
  17620. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17621. /// 0A35 <result>.W
  17622. void clif_parse_Oneclick_Itemidentify(int fd, map_session_data *sd) {
  17623. #if PACKETVER >= 20150513
  17624. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17625. // Ignore the request
  17626. // - Invalid item index
  17627. // - Invalid item ID or item doesn't exist
  17628. // - Item is already identified
  17629. if (idx < 0 || idx >= MAX_INVENTORY ||
  17630. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17631. sd->inventory.u.items_inventory[idx].identify)
  17632. return;
  17633. // Ignore the request - No magnifiers in inventory
  17634. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17635. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17636. return;
  17637. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17638. return;
  17639. skill_identify(sd, idx);
  17640. #endif
  17641. }
  17642. /// Starts navigation to the given target on client side
  17643. void clif_navigateTo(map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17644. #if PACKETVER >= 20111010
  17645. int fd = sd->fd;
  17646. WFIFOHEAD(fd,27);
  17647. WFIFOW(fd,0) = 0x08e2;
  17648. // How detailed will our navigation be?
  17649. if( mob_id > 0 ){
  17650. x = 0;
  17651. y = 0;
  17652. WFIFOB(fd,2) = 3; // monster with destination field
  17653. }else if( x > 0 && y > 0 ){
  17654. WFIFOB(fd,2) = 0; // with coordinates
  17655. }else{
  17656. x = 0;
  17657. y = 0;
  17658. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17659. }
  17660. // Which services can be used for transportation?
  17661. WFIFOB(fd,3) = flag;
  17662. // If this flag is set, the navigation window will not be opened up
  17663. WFIFOB(fd,4) = hideWindow;
  17664. // Target map
  17665. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17666. // Target x
  17667. WFIFOW(fd,21) = x;
  17668. // Target y
  17669. WFIFOW(fd,23) = y;
  17670. // Target monster ID
  17671. WFIFOW(fd,25) = mob_id;
  17672. WFIFOSET(fd,27);
  17673. #endif
  17674. }
  17675. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17676. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17677. void clif_hat_effects( map_session_data* sd, struct block_list* bl, enum send_target target ){
  17678. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17679. map_session_data *tsd;
  17680. struct block_list* tbl;
  17681. if( target == SELF ){
  17682. tsd = BL_CAST(BL_PC,bl);
  17683. tbl = &sd->bl;
  17684. }else{
  17685. tsd = sd;
  17686. tbl = bl;
  17687. }
  17688. nullpo_retv( tsd );
  17689. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->getMapFlag(MF_NOCOSTUME) ){
  17690. return;
  17691. }
  17692. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17693. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17694. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17695. p->aid = tsd->bl.id;
  17696. p->status = 1;
  17697. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17698. p->effects[i] = tsd->hatEffects[i];
  17699. }
  17700. clif_send( p, p->packetLength, tbl, target );
  17701. #endif
  17702. }
  17703. void clif_hat_effect_single( map_session_data* sd, uint16 effectId, bool enable ){
  17704. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17705. nullpo_retv( sd );
  17706. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17707. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17708. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17709. p->aid = sd->bl.id;
  17710. p->status = enable;
  17711. p->effects[0] = effectId;
  17712. clif_send( p, p->packetLength, &sd->bl, AREA );
  17713. #endif
  17714. }
  17715. /// Notify the client that a sale has started
  17716. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17717. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17718. #if PACKETVER_SUPPORTS_SALES
  17719. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17720. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17721. p.itemId = client_nameid( sale_item->nameid );
  17722. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17723. clif_send( &p, sizeof( p ), bl, target );
  17724. #endif
  17725. }
  17726. /// Notify the client that a sale has ended
  17727. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17728. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17729. #if PACKETVER_SUPPORTS_SALES
  17730. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17731. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17732. p.itemId = client_nameid( sale_item->nameid );
  17733. clif_send( &p, sizeof( p ), bl, target );
  17734. #endif
  17735. }
  17736. /// Update the remaining amount of a sale item.
  17737. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17738. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17739. #if PACKETVER_SUPPORTS_SALES
  17740. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17741. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17742. p.itemId = client_nameid( sale_item->nameid );
  17743. p.amount = sale_item->amount;
  17744. clif_send( &p, sizeof( p ), bl, target );
  17745. #endif
  17746. }
  17747. /// The client requested a refresh of the current remaining count of a sale item
  17748. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17749. void clif_parse_sale_refresh( int fd, map_session_data* sd ){
  17750. #if PACKETVER_SUPPORTS_SALES
  17751. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17752. struct sale_item_data* sale;
  17753. if( p->AID != sd->status.account_id ){
  17754. return;
  17755. }
  17756. sale = sale_find_item( p->itemId, true );
  17757. if( sale == NULL ){
  17758. return;
  17759. }
  17760. clif_sale_amount(sale, &sd->bl, SELF);
  17761. #endif
  17762. }
  17763. /// Opens the sale administration window on the client
  17764. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17765. void clif_sale_open( map_session_data* sd ){
  17766. #if PACKETVER_SUPPORTS_SALES
  17767. nullpo_retv(sd);
  17768. if( sd->state.sale_open ){
  17769. return;
  17770. }
  17771. sd->state.sale_open = true;
  17772. int fd = sd->fd;
  17773. WFIFOHEAD(fd, 2);
  17774. WFIFOW(fd, 0) = 0x9b5;
  17775. WFIFOSET(fd, 2);
  17776. #endif
  17777. }
  17778. /// Client request to open the sale administration window.
  17779. /// This is sent by /limitedsale
  17780. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17781. void clif_parse_sale_open( int fd, map_session_data* sd ){
  17782. #if PACKETVER_SUPPORTS_SALES
  17783. nullpo_retv(sd);
  17784. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17785. return;
  17786. }
  17787. char command[CHAT_SIZE_MAX];
  17788. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17789. is_atcommand(fd, sd, command, 1);
  17790. #endif
  17791. }
  17792. /// Closes the sale administration window on the client.
  17793. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17794. void clif_sale_close(map_session_data* sd) {
  17795. #if PACKETVER_SUPPORTS_SALES
  17796. nullpo_retv(sd);
  17797. if( !sd->state.sale_open ){
  17798. return;
  17799. }
  17800. sd->state.sale_open = false;
  17801. int fd = sd->fd;
  17802. WFIFOHEAD(fd, 2);
  17803. WFIFOW(fd, 0) = 0x9bd;
  17804. WFIFOSET(fd, 2);
  17805. #endif
  17806. }
  17807. /// Client request to close the sale administration window.
  17808. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17809. void clif_parse_sale_close(int fd, map_session_data* sd) {
  17810. #if PACKETVER_SUPPORTS_SALES
  17811. nullpo_retv(sd);
  17812. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17813. return;
  17814. }
  17815. clif_sale_close(sd);
  17816. #endif
  17817. }
  17818. /// Reply to a item search request for item sale administration.
  17819. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17820. void clif_sale_search_reply( map_session_data* sd, std::shared_ptr<s_cash_item> item ){
  17821. #if PACKETVER_SUPPORTS_SALES
  17822. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17823. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17824. if( item != NULL ){
  17825. p.result = 0;
  17826. p.itemId = client_nameid( item->nameid );
  17827. p.price = item->price;
  17828. }else{
  17829. p.result = 1;
  17830. p.itemId = 0;
  17831. p.price = 0;
  17832. }
  17833. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17834. #endif
  17835. }
  17836. /// Search request for an item sale administration.
  17837. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17838. void clif_parse_sale_search( int fd, map_session_data* sd ){
  17839. #if PACKETVER_SUPPORTS_SALES
  17840. char item_name[ITEM_NAME_LENGTH];
  17841. nullpo_retv(sd);
  17842. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17843. return;
  17844. }
  17845. if( !sd->state.sale_open ){
  17846. return;
  17847. }
  17848. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17849. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17850. // not found
  17851. if( id == nullptr ){
  17852. clif_sale_search_reply( sd, nullptr );
  17853. return;
  17854. }
  17855. clif_sale_search_reply( sd, cash_shop_db.findItemInTab( CASHSHOP_TAB_SALE, id->nameid ) );
  17856. #endif
  17857. }
  17858. /// Reply if an item was successfully put on sale or not.
  17859. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17860. void clif_sale_add_reply( map_session_data* sd, enum e_sale_add_result result ){
  17861. #if PACKETVER_SUPPORTS_SALES
  17862. int fd = sd->fd;
  17863. WFIFOHEAD(fd, 4);
  17864. WFIFOW(fd, 0) = 0x9af;
  17865. WFIFOW(fd, 2) = (uint16)result;
  17866. WFIFOSET(fd, 4);
  17867. #endif
  17868. }
  17869. /// A client request to put an item on sale.
  17870. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17871. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17872. void clif_parse_sale_add( int fd, map_session_data* sd ){
  17873. #if PACKETVER_SUPPORTS_SALES
  17874. nullpo_retv( sd );
  17875. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17876. if( p->AID != sd->status.account_id ){
  17877. return;
  17878. }
  17879. if( !sd->state.sale_open ){
  17880. return;
  17881. }
  17882. time_t endTime = p->startTime + p->hours * 60 * 60;
  17883. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17884. #endif
  17885. }
  17886. /// Reply to an item removal from sale.
  17887. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17888. void clif_sale_remove_reply( map_session_data* sd, bool failed ){
  17889. #if PACKETVER_SUPPORTS_SALES
  17890. int fd = sd->fd;
  17891. WFIFOHEAD(fd, 4);
  17892. WFIFOW(fd, 0) = 0x9b1;
  17893. WFIFOW(fd, 2) = failed;
  17894. WFIFOSET(fd, 4);
  17895. #endif
  17896. }
  17897. /// Request to remove an item from sale.
  17898. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17899. void clif_parse_sale_remove( int fd, map_session_data* sd ){
  17900. #if PACKETVER_SUPPORTS_SALES
  17901. nullpo_retv( sd );
  17902. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17903. if( p->AID != sd->status.account_id ){
  17904. return;
  17905. }
  17906. if( !sd->state.sale_open ){
  17907. return;
  17908. }
  17909. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17910. #endif
  17911. }
  17912. /// Achievement System
  17913. /// Author: Luxuri, Aleos
  17914. /**
  17915. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17916. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17917. */
  17918. void clif_achievement_list_all(map_session_data *sd)
  17919. {
  17920. nullpo_retv(sd);
  17921. if (!battle_config.feature_achievement) {
  17922. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17923. return;
  17924. }
  17925. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17926. if (count == 0)
  17927. return;
  17928. int len = (50 * count) + 22;
  17929. int fd = sd->fd;
  17930. int *info = achievement_level(sd, true);
  17931. WFIFOHEAD(fd,len);
  17932. WFIFOW(fd, 0) = 0xa23;
  17933. WFIFOW(fd, 2) = len;
  17934. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17935. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17936. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17937. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17938. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17939. for (int i = 0; i < count; i++) {
  17940. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17941. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17942. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17943. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17944. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17945. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17946. }
  17947. WFIFOSET(fd, len);
  17948. }
  17949. /**
  17950. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17951. * 0a24 <ACHPoint>.L
  17952. */
  17953. void clif_achievement_update(map_session_data *sd, struct achievement *ach, int count)
  17954. {
  17955. nullpo_retv(sd);
  17956. if (!battle_config.feature_achievement) {
  17957. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17958. return;
  17959. }
  17960. int fd = sd->fd;
  17961. int *info = achievement_level(sd, true);
  17962. WFIFOHEAD(fd, packet_len(0xa24));
  17963. WFIFOW(fd, 0) = 0xa24;
  17964. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17965. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17966. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17967. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17968. if (ach) {
  17969. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17970. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17971. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17972. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17973. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17974. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17975. } else
  17976. memset(WFIFOP(fd, 16), 0, 40);
  17977. WFIFOSET(fd, packet_len(0xa24));
  17978. }
  17979. /**
  17980. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17981. * 0a25 <achievementID>.L
  17982. */
  17983. void clif_parse_AchievementCheckReward(int fd, map_session_data *sd)
  17984. {
  17985. nullpo_retv(sd);
  17986. if( sd->achievement_data.save )
  17987. intif_achievement_save(sd);
  17988. achievement_check_reward(sd, RFIFOL(fd,2));
  17989. }
  17990. /**
  17991. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17992. * 0a26 <result>.W <achievementID>.L
  17993. */
  17994. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17995. {
  17996. WFIFOHEAD(fd, packet_len(0xa26));
  17997. WFIFOW(fd, 0) = 0xa26;
  17998. WFIFOB(fd, 2) = result;
  17999. WFIFOL(fd, 3) = achievement_id;
  18000. WFIFOSET(fd, packet_len(0xa26));
  18001. }
  18002. /// Process the pet evolution request
  18003. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  18004. void clif_parse_pet_evolution( int fd, map_session_data *sd ){
  18005. #if PACKETVER >= 20141008
  18006. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  18007. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  18008. if (!pet) {
  18009. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  18010. return;
  18011. }
  18012. pet_evolution(sd, pet->class_);
  18013. #endif
  18014. }
  18015. /// Sends the result of the evolution to the client.
  18016. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  18017. void clif_pet_evolution_result( map_session_data* sd, e_pet_evolution_result result ){
  18018. #if PACKETVER >= 20141008
  18019. int fd = sd->fd;
  18020. WFIFOHEAD(fd, packet_len(0x9fc));
  18021. WFIFOW(fd, 0) = 0x9fc;
  18022. WFIFOL(fd, 2) = static_cast<uint32>(result);
  18023. WFIFOSET(fd, packet_len(0x9fc));
  18024. #endif
  18025. }
  18026. /*
  18027. * This packet is sent by /changedress or /nocosplay
  18028. *
  18029. * 0ae8
  18030. */
  18031. void clif_parse_changedress( int fd, map_session_data* sd ){
  18032. #if PACKETVER >= 20180103
  18033. char command[CHAT_SIZE_MAX];
  18034. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  18035. is_atcommand( fd, sd, command, 1 );
  18036. #endif
  18037. }
  18038. /// Opens an UI window of the given type and initializes it with the given data
  18039. /// 0AE2 <type>.B <data>.L
  18040. void clif_ui_open( map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  18041. #if PACKETVER >= 20151202
  18042. // If the UI requires state tracking
  18043. switch( ui_type ){
  18044. case OUT_UI_STYLIST:
  18045. sd.state.stylist_open = true;
  18046. break;
  18047. case OUT_UI_ENCHANTGRADE:
  18048. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  18049. sd.state.enchantgrade_open = true;
  18050. break;
  18051. #else
  18052. return;
  18053. #endif
  18054. }
  18055. struct PACKET_ZC_UI_OPEN p = {};
  18056. p.PacketType = HEADER_ZC_UI_OPEN;
  18057. p.UIType = ui_type;
  18058. #if PACKETVER >= 20171122
  18059. p.data = data;
  18060. #endif
  18061. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  18062. #endif
  18063. }
  18064. /// Request to open an UI window of the given type
  18065. /// 0A68 <type>.B
  18066. void clif_parse_open_ui( int fd, map_session_data* sd ){
  18067. switch( RFIFOB(fd,2) ){
  18068. case IN_UI_ATTENDANCE:
  18069. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  18070. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  18071. }else if( pc_attendance_enabled() ){
  18072. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  18073. }else{
  18074. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  18075. }
  18076. break;
  18077. #if PACKETVER >= 20160316
  18078. case IN_UI_MACRO_REGISTER:
  18079. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  18080. break;
  18081. case IN_UI_MACRO_DETECTOR:
  18082. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  18083. break;
  18084. #endif
  18085. }
  18086. }
  18087. /// Response for attedance request
  18088. /// 0AF0 <unknown>.L <data>.L
  18089. void clif_attendence_response( map_session_data *sd, int32 data ){
  18090. nullpo_retv(sd);
  18091. int fd = sd->fd;
  18092. WFIFOHEAD(fd,packet_len(0xAF0));
  18093. WFIFOW(fd,0) = 0xAF0;
  18094. WFIFOL(fd,2) = 0;
  18095. WFIFOL(fd,6) = data;
  18096. WFIFOSET(fd,packet_len(0xAF0));
  18097. }
  18098. /// Request from the client to retrieve today's attendance reward
  18099. /// 0AEF
  18100. void clif_parse_attendance_request( int fd, map_session_data* sd ){
  18101. pc_attendance_claim_reward(sd);
  18102. }
  18103. /// Send out the percentage of weight that causes it to be displayed in red.
  18104. /// 0ADE <percentage>.L
  18105. void clif_weight_limit( map_session_data* sd ){
  18106. #if PACKETVER >= 20171025
  18107. nullpo_retv(sd);
  18108. int fd = sd->fd;
  18109. WFIFOHEAD(fd, packet_len(0xADE));
  18110. WFIFOW(fd, 0) = 0xADE;
  18111. #ifdef RENEWAL
  18112. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18113. #else
  18114. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18115. #endif
  18116. WFIFOSET(fd, packet_len(0xADE));
  18117. #endif
  18118. }
  18119. enum e_private_airship_response : uint32{
  18120. PRIVATEAIRSHIP_OK,
  18121. PRIVATEAIRSHIP_RETRY,
  18122. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18123. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18124. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18125. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18126. };
  18127. /// Send out the response to a private airship request
  18128. /// 0A4A <response>.L
  18129. void clif_private_airship_response( map_session_data* sd, enum e_private_airship_response response ){
  18130. #if PACKETVER >= 20180321
  18131. nullpo_retv( sd );
  18132. int fd = sd->fd;
  18133. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18134. WFIFOW( fd, 0 ) = 0xA4A;
  18135. WFIFOL( fd, 2 ) = response;
  18136. WFIFOSET( fd, packet_len( 0xA4A ) );
  18137. #endif
  18138. }
  18139. /// Parses a request for a private airship
  18140. /// 0A49 <mapname>.16B <itemid>.W
  18141. void clif_parse_private_airship_request( int fd, map_session_data* sd ){
  18142. #if PACKETVER >= 20180321
  18143. // Check if the feature is enabled
  18144. if( !battle_config.feature_privateairship ){
  18145. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18146. return;
  18147. }
  18148. // Check if the player is allowed to warp from the source map
  18149. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18150. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18151. return;
  18152. }
  18153. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18154. char mapname[MAP_NAME_LENGTH_EXT];
  18155. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18156. int16 mapindex = mapindex_name2id( mapname );
  18157. // Check if we know the mapname
  18158. if( mapindex < 0 ){
  18159. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18160. return;
  18161. }
  18162. int16 mapid = map_mapindex2mapid( mapindex );
  18163. // Check if the map is available on this server
  18164. if( mapid < 0 ){
  18165. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18166. return;
  18167. }
  18168. // Check if the player tried to warp to the map he is on
  18169. if( sd->bl.m == mapid ){
  18170. // This is blocked by the client, but just to be sure
  18171. return;
  18172. }
  18173. // This can only be a hack, so we prevent it
  18174. if( map_getmapdata( mapid )->instance_id ){
  18175. // Ignore requests to warp directly into a running instance
  18176. return;
  18177. }
  18178. // Check if the player is allowed to warp to the target map
  18179. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18180. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18181. return;
  18182. }
  18183. t_itemid item_id = p->ItemID;
  18184. // Check if the item sent by the client is known to us
  18185. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18186. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18187. return;
  18188. }
  18189. int idx = pc_search_inventory( sd, item_id );
  18190. // Check if the player has the item at all
  18191. if( idx < 0 ){
  18192. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18193. return;
  18194. }
  18195. // Delete the chosen item
  18196. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18197. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18198. return;
  18199. }
  18200. // Warp the player to a random spot on the destination map
  18201. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18202. #endif
  18203. }
  18204. /// Sends out the usage history of the guild storage
  18205. /// 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
  18206. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18207. void clif_guild_storage_log( map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18208. #if PACKETVER >= 20140205
  18209. nullpo_retv( sd );
  18210. int fd = sd->fd;
  18211. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18212. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18213. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18214. }else{
  18215. log.clear();
  18216. }
  18217. WFIFOHEAD( fd, size );
  18218. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18219. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18220. p->PacketLength = size;
  18221. p->result = result;
  18222. p->amount = (uint16)log.size();
  18223. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18224. for( int i = 0; i < log.size(); i++ ){
  18225. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18226. struct guild_log_entry& entry = log[i];
  18227. item->id = entry.id;
  18228. item->itemId = client_nameid( entry.item.nameid );
  18229. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18230. item->action = entry.amount > 0; // action = true(put), false(get)
  18231. item->refine = entry.item.refine;
  18232. item->uniqueId = entry.item.unique_id;
  18233. item->IsIdentified = entry.item.identify;
  18234. item->itemType = itemtype( entry.item.nameid );
  18235. clif_addcards( &item->slot, &entry.item );
  18236. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18237. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18238. item->attribute = entry.item.attribute;
  18239. }
  18240. }
  18241. WFIFOSET( fd, p->PacketLength );
  18242. #endif
  18243. }
  18244. /// Activates the client camera info or updates the client camera with the given values.
  18245. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18246. void clif_camerainfo( map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18247. #if PACKETVER >= 20160525
  18248. int fd = sd->fd;
  18249. WFIFOHEAD(fd, packet_len(0xa78));
  18250. WFIFOW(fd, 0) = 0xa78;
  18251. WFIFOB(fd, 2) = show;
  18252. WFIFOF(fd, 3) = range;
  18253. WFIFOF(fd, 7) = rotation;
  18254. WFIFOF(fd, 11) = latitude;
  18255. WFIFOSET(fd, packet_len(0xa78));
  18256. #endif
  18257. }
  18258. /// Activates or deactives the client camera info or updates the camera settings.
  18259. /// This packet is triggered by /viewpointvalue or /setcamera
  18260. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18261. void clif_parse_camerainfo( int fd, map_session_data* sd ){
  18262. char command[CHAT_SIZE_MAX];
  18263. // /viewpointvalue
  18264. if( RFIFOB( fd, 2 ) == 1 ){
  18265. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18266. // /setcamera
  18267. }else{
  18268. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18269. }
  18270. is_atcommand( fd, sd, command, 1 );
  18271. }
  18272. /// Send the full list of items in the equip switch window
  18273. /// 0a9b <length>.W { <index>.W <position>.L }*
  18274. void clif_equipswitch_list( map_session_data* sd ){
  18275. #if PACKETVER >= 20170208
  18276. int fd = sd->fd;
  18277. int offset, i, position;
  18278. WFIFOW(fd, 0) = 0xa9b;
  18279. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18280. short index = sd->equip_switch_index[i];
  18281. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18282. WFIFOW(fd, offset) = index + 2;
  18283. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18284. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18285. offset += 6;
  18286. }
  18287. }
  18288. WFIFOW(fd, 2) = offset;
  18289. WFIFOSET(fd, offset);
  18290. #endif
  18291. }
  18292. /// Acknowledgement for removing an equip to the equip switch window
  18293. /// 0a9a <index>.W <position.>.L <failure>.W
  18294. void clif_equipswitch_remove( map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18295. #if PACKETVER >= 20170208
  18296. int fd = sd->fd;
  18297. WFIFOHEAD(fd, packet_len(0xa9a));
  18298. WFIFOW(fd, 0) = 0xa9a;
  18299. WFIFOW(fd, 2) = index + 2;
  18300. WFIFOL(fd, 4) = pos;
  18301. WFIFOW(fd, 8) = failed;
  18302. WFIFOSET(fd, packet_len(0xa9a));
  18303. #endif
  18304. }
  18305. /// Request to remove an equip from the equip switch window
  18306. /// 0a99 <index>.W <position>.L <= 20170502
  18307. /// 0a99 <index>.W
  18308. void clif_parse_equipswitch_remove( int fd, map_session_data* sd ){
  18309. #if PACKETVER >= 20170208
  18310. uint16 index = RFIFOW(fd, 2) - 2;
  18311. bool removed = false;
  18312. if( !battle_config.feature_equipswitch ){
  18313. return;
  18314. }
  18315. // Check if the index is valid
  18316. if( index >= MAX_INVENTORY ){
  18317. return;
  18318. }
  18319. pc_equipswitch_remove( sd, index );
  18320. #endif
  18321. }
  18322. /// Acknowledgement for adding an equip to the equip switch window
  18323. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18324. /// 0a98 <index>.W <position.>.L <flag>.W
  18325. void clif_equipswitch_add( map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18326. #if PACKETVER >= 20170208
  18327. int fd = sd->fd;
  18328. WFIFOHEAD(fd, packet_len(0xa98));
  18329. WFIFOW(fd, 0) = 0xa98;
  18330. WFIFOW(fd, 2) = index + 2;
  18331. WFIFOL(fd, 4) = pos;
  18332. #if PACKETVER <= 20170502
  18333. WFIFOL(fd, 8) = flag;
  18334. #else
  18335. WFIFOW(fd, 8) = flag;
  18336. #endif
  18337. WFIFOSET(fd,packet_len(0xa98));
  18338. #endif
  18339. }
  18340. /// Request to add an equip to the equip switch window
  18341. /// 0a97 <index>.W <position>.L
  18342. void clif_parse_equipswitch_add( int fd, map_session_data* sd ){
  18343. #if PACKETVER >= 20170208
  18344. uint16 index = RFIFOW(fd, 2) - 2;
  18345. uint32 position = RFIFOL(fd, 4);
  18346. if( !battle_config.feature_equipswitch ){
  18347. return;
  18348. }
  18349. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18350. return;
  18351. }
  18352. if( sd->state.trading || sd->npc_shopid ){
  18353. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18354. return;
  18355. }
  18356. if( sd->inventory_data[index]->type == IT_AMMO ){
  18357. position = EQP_AMMO;
  18358. }
  18359. pc_equipitem( sd, index, position, true );
  18360. #endif
  18361. }
  18362. /// Acknowledgement packet for the full equip switch
  18363. /// 0a9d <failed>.W
  18364. void clif_equipswitch_reply( map_session_data* sd, bool failed ){
  18365. #if PACKETVER >= 20170208
  18366. int fd = sd->fd;
  18367. WFIFOHEAD(fd, packet_len(0xa9d));
  18368. WFIFOW(fd, 0) = 0xa9d;
  18369. WFIFOW(fd, 2) = failed;
  18370. WFIFOSET(fd, packet_len(0xa9d));
  18371. #endif
  18372. }
  18373. /// Request to do a full equip switch
  18374. /// 0a9c
  18375. void clif_parse_equipswitch_request( int fd, map_session_data* sd ){
  18376. #if PACKETVER >= 20170208
  18377. int i;
  18378. t_tick tick = gettick();
  18379. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18380. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18381. // Client will not let you send a request
  18382. return;
  18383. }
  18384. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18385. if( !battle_config.feature_equipswitch ){
  18386. return;
  18387. }
  18388. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18389. if( i == EQI_MAX ){
  18390. // client will show: "There is no item to replace." and should not even come here
  18391. clif_equipswitch_reply( sd, false );
  18392. return;
  18393. }
  18394. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18395. return;
  18396. }
  18397. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18398. #endif
  18399. }
  18400. /// Request to do a single equip switch
  18401. /// 0ace <index>.W
  18402. void clif_parse_equipswitch_request_single( int fd, map_session_data* sd ){
  18403. #if PACKETVER >= 20170502
  18404. uint16 index = RFIFOW(fd, 2) - 2;
  18405. if( !battle_config.feature_equipswitch ){
  18406. return;
  18407. }
  18408. // Check if the index is valid
  18409. if( index >= MAX_INVENTORY ){
  18410. return;
  18411. }
  18412. // Check if the item exists
  18413. if (sd->inventory_data[index] == nullptr)
  18414. return;
  18415. // Check if the item was already added to equip switch
  18416. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18417. if( sd->npc_id ){
  18418. #ifdef RENEWAL
  18419. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18420. clif_msg( sd, WORK_IN_PROGRESS );
  18421. return;
  18422. }
  18423. #endif
  18424. if( !sd->npc_item_flag ){
  18425. return;
  18426. }
  18427. }
  18428. pc_equipswitch( sd, index );
  18429. return;
  18430. }
  18431. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18432. #endif
  18433. }
  18434. void clif_parse_StartUseSkillToId( int fd, map_session_data* sd ){
  18435. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18436. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18437. // Only rolling cutter is supported for now
  18438. if( p->skillId != GC_ROLLINGCUTTER ){
  18439. return;
  18440. }
  18441. // Already running - cant happen on officials, since only one skill is supported
  18442. if( sd->skill_keep_using.skill_id != 0 ){
  18443. return;
  18444. }
  18445. sd->skill_keep_using.tid = INVALID_TIMER;
  18446. sd->skill_keep_using.skill_id = p->skillId;
  18447. sd->skill_keep_using.level = p->skillLv;
  18448. sd->skill_keep_using.target = p->targetId;
  18449. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18450. #endif
  18451. }
  18452. void clif_parse_StopUseSkillToId( int fd, map_session_data* sd ){
  18453. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18454. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18455. // Not running
  18456. if( sd->skill_keep_using.skill_id == 0 ){
  18457. return;
  18458. }
  18459. #if 0
  18460. // Hack
  18461. if( p->skillId != sd->skill_keep_using.skill_id ){
  18462. return;
  18463. }
  18464. #endif
  18465. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18466. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18467. sd->skill_keep_using.tid = INVALID_TIMER;
  18468. }
  18469. sd->skill_keep_using.skill_id = 0;
  18470. sd->skill_keep_using.level = 0;
  18471. sd->skill_keep_using.target = 0;
  18472. #endif
  18473. }
  18474. void clif_ping( map_session_data* sd ){
  18475. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18476. nullpo_retv( sd );
  18477. int fd = sd->fd;
  18478. if( !session_isActive( fd ) ){
  18479. return;
  18480. }
  18481. struct PACKET_ZC_PING_LIVE p = {};
  18482. p.packetType = HEADER_ZC_PING_LIVE;
  18483. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18484. #endif
  18485. }
  18486. int clif_ping_timer_sub( map_session_data *sd, va_list ap ){
  18487. nullpo_ret( sd );
  18488. int fd = sd->fd;
  18489. if( !session_isActive( fd ) ){
  18490. return 0;
  18491. }
  18492. t_tick tick = va_arg( ap, t_tick );
  18493. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18494. clif_ping( sd );
  18495. }
  18496. return 0;
  18497. }
  18498. TIMER_FUNC( clif_ping_timer ){
  18499. map_foreachpc( clif_ping_timer_sub, gettick() );
  18500. return 0;
  18501. }
  18502. /**
  18503. * Opens the refine UI on the designated client.
  18504. * 0aa0
  18505. */
  18506. void clif_refineui_open( map_session_data* sd ){
  18507. #if PACKETVER >= 20161012
  18508. nullpo_retv( sd );
  18509. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18510. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18511. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18512. sd->state.refineui_open = true;
  18513. #endif
  18514. }
  18515. /**
  18516. * Parses cancel/close of the refine UI on client side.
  18517. * 0aa4
  18518. */
  18519. void clif_parse_refineui_close( int fd, map_session_data* sd ){
  18520. #if PACKETVER >= 20161012
  18521. sd->state.refineui_open = false;
  18522. #endif
  18523. }
  18524. /**
  18525. * Adds the selected item into the refine UI and sends the possible materials
  18526. * to the client.
  18527. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18528. */
  18529. void clif_refineui_info( map_session_data* sd, uint16 index ){
  18530. #if PACKETVER >= 20161012
  18531. int fd = sd->fd;
  18532. // Get the item db reference
  18533. struct item_data* id = sd->inventory_data[index];
  18534. // No item data was found
  18535. if( id == NULL ){
  18536. return;
  18537. }
  18538. // Check the inventory
  18539. struct item* item = &sd->inventory.u.items_inventory[index];
  18540. // No item was found at the given index
  18541. if( item == NULL ){
  18542. return;
  18543. }
  18544. // Check if the item is identified
  18545. if( !item->identify ){
  18546. return;
  18547. }
  18548. // Check if the item is broken
  18549. if( item->attribute ){
  18550. return;
  18551. }
  18552. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18553. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18554. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18555. p->itemIndex = client_index( index );
  18556. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18557. // No possibilities were found
  18558. if( info == nullptr ){
  18559. p->blacksmithBlessing = 0;
  18560. }else{
  18561. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18562. uint16 count = 0;
  18563. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18564. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18565. if( cost != nullptr ){
  18566. p->req[count].itemId = client_nameid( cost->nameid );
  18567. p->req[count].chance = (uint8)( cost->chance / 100 );
  18568. p->req[count].zeny = cost->zeny;
  18569. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18570. count++;
  18571. }
  18572. }
  18573. }
  18574. clif_send( p, p->packetLength, &sd->bl, SELF );
  18575. #endif
  18576. }
  18577. /**
  18578. * Client request to add an item to the refine UI.
  18579. * 0aa1 <index>.W
  18580. */
  18581. void clif_parse_refineui_add( int fd, map_session_data* sd ){
  18582. #if PACKETVER >= 20161012
  18583. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18584. uint16 index = server_index( p->index );
  18585. // Check if the refine UI is open
  18586. if( !sd->state.refineui_open ){
  18587. return;
  18588. }
  18589. // Check if the index is valid
  18590. if( index >= MAX_INVENTORY ){
  18591. return;
  18592. }
  18593. // Send out the requirements for the refine process
  18594. clif_refineui_info( sd, index );
  18595. #endif
  18596. }
  18597. /**
  18598. * Client requests to try to refine an item.
  18599. * 0aa3 <index>.W <material>.W <catalyst>.B
  18600. */
  18601. void clif_parse_refineui_refine( int fd, map_session_data* sd ){
  18602. #if PACKETVER >= 20161012
  18603. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18604. uint16 index = server_index( p->index );
  18605. t_itemid material = p->itemId;
  18606. int16 j;
  18607. // Check if the refine UI is open
  18608. if( !sd->state.refineui_open ){
  18609. return;
  18610. }
  18611. // Check if the index is valid
  18612. if( index >= MAX_INVENTORY ){
  18613. return;
  18614. }
  18615. // Get the item db reference
  18616. struct item_data* id = sd->inventory_data[index];
  18617. // No item data was found
  18618. if( id == NULL ){
  18619. return;
  18620. }
  18621. // Check the inventory
  18622. struct item* item = &sd->inventory.u.items_inventory[index];
  18623. // No item was found at the given index
  18624. if( item == NULL ){
  18625. return;
  18626. }
  18627. // Check if the item is identified
  18628. if( !item->identify ){
  18629. return;
  18630. }
  18631. // Check if the item is broken
  18632. if( item->attribute ){
  18633. return;
  18634. }
  18635. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18636. // No refine possible
  18637. if( info == nullptr ){
  18638. return;
  18639. }
  18640. // No possibilities were found
  18641. if( info->costs.empty() ){
  18642. return;
  18643. }
  18644. // Check if the player has the selected material
  18645. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18646. return;
  18647. }
  18648. int16 blacksmith_index = -1;
  18649. uint16 blacksmith_amount = 0;
  18650. // Check if the player has enough blacksmith blessings
  18651. if( p->blacksmithBlessing != 0 ){
  18652. blacksmith_amount = info->blessing_amount;
  18653. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18654. if( blacksmith_amount == 0 ){
  18655. return;
  18656. }
  18657. // Check if the player has blacksmith blessings
  18658. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18659. return;
  18660. }
  18661. // Check if the player has enough blacksmith blessings
  18662. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18663. return;
  18664. }
  18665. }
  18666. std::shared_ptr<s_refine_cost> cost = nullptr;
  18667. for( const auto& pair : info->costs ){
  18668. if( pair.second->nameid == material ){
  18669. cost = pair.second;
  18670. break;
  18671. }
  18672. }
  18673. // The material was not in the list of possible materials
  18674. if( cost == nullptr ){
  18675. return;
  18676. }
  18677. // Try to pay for the refine
  18678. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME ) ){
  18679. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18680. return;
  18681. }
  18682. // Delete the required material
  18683. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18684. return;
  18685. }
  18686. // Delete the required blacksmith blessings
  18687. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18688. return;
  18689. }
  18690. // Try to refine the item
  18691. if( cost->chance >= ( rnd() % 10000 ) ){
  18692. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18693. // Success
  18694. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18695. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18696. clif_misceffect( &sd->bl, 3 );
  18697. clif_refine( fd, 0, index, item->refine );
  18698. if (info->broadcast_success) {
  18699. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18700. }
  18701. if( id->type == IT_WEAPON ){
  18702. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18703. }
  18704. clif_refineui_info( sd, index );
  18705. }else{
  18706. // Failure
  18707. if (info->broadcast_failure) {
  18708. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18709. }
  18710. // Blacksmith blessings were used to prevent breaking and downgrading
  18711. if( blacksmith_amount > 0 ){
  18712. clif_refine( fd, 3, index, item->refine );
  18713. clif_refineui_info( sd, index );
  18714. // Delete the item if it is breakable
  18715. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18716. clif_refine( fd, 1, index, item->refine );
  18717. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18718. // Downgrade the item if necessary
  18719. }else if( cost->downgrade_amount > 0 ){
  18720. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18721. clif_refine( fd, 2, index, item->refine );
  18722. clif_refineui_info(sd, index);
  18723. // Only show failure, but dont do anything
  18724. }else{
  18725. clif_refine( fd, 3, index, item->refine );
  18726. clif_refineui_info( sd, index );
  18727. }
  18728. clif_misceffect( &sd->bl, 2 );
  18729. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18730. }
  18731. #endif
  18732. }
  18733. void clif_unequipall_reply( map_session_data* sd, bool failed ){
  18734. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18735. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18736. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18737. p.result = failed;
  18738. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18739. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18740. }
  18741. void clif_parse_unequipall( int fd, map_session_data* sd ){
  18742. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18743. if( pc_cant_act( sd ) ){
  18744. clif_unequipall_reply( sd, true );
  18745. return;
  18746. }
  18747. struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL* p = (struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL*)RFIFOP( fd, 0 );
  18748. #if PACKETVER_MAIN_NUM >= 20230906
  18749. uint32 location = p->location;
  18750. int max = EQI_MAX;
  18751. #else
  18752. uint32 location = 0xFFFFFFFF;
  18753. int max = EQI_COSTUME_HEAD_TOP;
  18754. #endif
  18755. for( int i = 0; i < max; i++ ){
  18756. if( sd->equip_index[i] >= 0 && ( location & equip_bitmask[i] ) != 0 ){
  18757. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18758. }
  18759. }
  18760. clif_unequipall_reply( sd, false );
  18761. #endif
  18762. }
  18763. void clif_stylist_response( map_session_data* sd, bool failed ){
  18764. #if PACKETVER >= 20151104
  18765. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18766. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18767. p.flag = failed;
  18768. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18769. if( !failed ){
  18770. sd->state.stylist_open = false;
  18771. }
  18772. #endif
  18773. }
  18774. bool clif_parse_stylist_buy_sub( map_session_data* sd, _look look, int16 index ){
  18775. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18776. if( list == nullptr ){
  18777. return false;
  18778. }
  18779. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18780. if( entry == nullptr ){
  18781. return false;
  18782. }
  18783. std::shared_ptr<s_stylist_costs> costs;
  18784. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18785. costs = entry->doram;
  18786. }else{
  18787. costs = entry->human;
  18788. }
  18789. if( costs == nullptr ){
  18790. return false;
  18791. }
  18792. if( sd->status.zeny < costs->price ){
  18793. return false;
  18794. }
  18795. int16 inventoryIndex = -1;
  18796. if( costs->requiredItem != 0 ){
  18797. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18798. if( inventoryIndex < 0 ){
  18799. // No other option
  18800. if( costs->requiredItemBox == 0 ){
  18801. return false;
  18802. }
  18803. // Check if the box that contains the item is in the inventory
  18804. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18805. // The box containing the item also does not exist
  18806. if( inventoryIndex < 0 ){
  18807. return false;
  18808. }
  18809. }
  18810. }else if( costs->requiredItemBox != 0 ){
  18811. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18812. if( inventoryIndex < 0 ){
  18813. return false;
  18814. }
  18815. }
  18816. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18817. return false;
  18818. }
  18819. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER ) != 0 ){
  18820. return false;
  18821. }
  18822. switch( look ){
  18823. case LOOK_HAIR:
  18824. case LOOK_HAIR_COLOR:
  18825. case LOOK_CLOTHES_COLOR:
  18826. case LOOK_BODY2:
  18827. pc_changelook( sd, look, entry->value );
  18828. break;
  18829. case LOOK_HEAD_BOTTOM:
  18830. case LOOK_HEAD_MID:
  18831. case LOOK_HEAD_TOP: {
  18832. struct mail_message msg = {};
  18833. msg.dest_id = sd->status.char_id;
  18834. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18835. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18836. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18837. msg.item[0].nameid = entry->value;
  18838. msg.item[0].identify = 1;
  18839. msg.item[0].amount = 1;
  18840. msg.status = MAIL_NEW;
  18841. msg.type = MAIL_INBOX_NORMAL;
  18842. msg.timestamp = time( nullptr );
  18843. intif_Mail_send( 0, &msg );
  18844. } break;
  18845. }
  18846. return true;
  18847. }
  18848. void clif_parse_stylist_buy( int fd, map_session_data* sd ){
  18849. #if PACKETVER >= 20151104
  18850. #if PACKETVER >= 20180516
  18851. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18852. #else
  18853. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18854. #endif
  18855. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18856. clif_stylist_response( sd, true );
  18857. return;
  18858. }
  18859. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18860. clif_stylist_response( sd, true );
  18861. return;
  18862. }
  18863. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18864. clif_stylist_response( sd, true );
  18865. return;
  18866. }
  18867. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18868. clif_stylist_response( sd, true );
  18869. return;
  18870. }
  18871. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18872. clif_stylist_response( sd, true );
  18873. return;
  18874. }
  18875. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18876. clif_stylist_response( sd, true );
  18877. return;
  18878. }
  18879. #if PACKETVER >= 20180516
  18880. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18881. clif_stylist_response( sd, true );
  18882. return;
  18883. }
  18884. #endif
  18885. clif_stylist_response( sd, false );
  18886. #endif
  18887. }
  18888. void clif_parse_stylist_close( int fd, map_session_data* sd ){
  18889. #if PACKETVER >= 20151104
  18890. sd->state.stylist_open = false;
  18891. #endif
  18892. }
  18893. void clif_inventory_expansion_info( map_session_data* sd ){
  18894. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18895. nullpo_retv( sd );
  18896. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18897. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18898. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18899. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18900. #endif
  18901. }
  18902. enum class e_inventory_expansion_response : uint8{
  18903. ASK_CONFIRMATION = 0,
  18904. FAILED,
  18905. BUSY,
  18906. MISSING_ITEM,
  18907. MAXIMUM_REACHED
  18908. };
  18909. void clif_inventory_expansion_response( map_session_data* sd, e_inventory_expansion_response response ){
  18910. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18911. nullpo_retv( sd );
  18912. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18913. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18914. p.result = (uint8)response;
  18915. p.itemId = sd->state.inventory_expansion_confirmation;
  18916. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18917. #endif
  18918. }
  18919. void clif_parse_inventory_expansion_request( int fd, map_session_data* sd ){
  18920. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18921. // Check if player is dead or busy with other stuff
  18922. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18923. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18924. return;
  18925. }
  18926. // Check if the player already reached the maximum
  18927. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18928. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18929. return;
  18930. }
  18931. static std::map<t_itemid, uint16> items = {
  18932. // The order of entries in this list defines which will be used first
  18933. // This order and the usable items are hardcoded into the client
  18934. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18935. { ITEMID_INVENTORY_EX_EVT, 10 },
  18936. { ITEMID_INVENTORY_EX_DIS, 10 },
  18937. { ITEMID_INVENTORY_EX, 10 },
  18938. };
  18939. int16 index = -1;
  18940. bool found_over_limit = false;
  18941. for( const auto& entry : items ){
  18942. // Check if the player has the required item
  18943. index = pc_search_inventory( sd, entry.first );
  18944. // Found an item
  18945. if( index >= 0 ){
  18946. // Check if the player would exceed the maximum
  18947. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18948. found_over_limit = true;
  18949. }else{
  18950. found_over_limit = false;
  18951. sd->state.inventory_expansion_confirmation = entry.first;
  18952. sd->state.inventory_expansion_amount = entry.second;
  18953. break;
  18954. }
  18955. }
  18956. }
  18957. // Check if an item was found
  18958. if( sd->state.inventory_expansion_confirmation == 0 ){
  18959. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18960. return;
  18961. }
  18962. // Check if an item would have been found, but the player would exceed the maximum
  18963. if( found_over_limit ){
  18964. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18965. return;
  18966. }
  18967. // The player met all requirements => ask him for confirmation
  18968. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18969. #endif
  18970. }
  18971. enum class e_inventory_expansion_result : uint8{
  18972. SUCCESS = 0,
  18973. FAILED,
  18974. BUSY,
  18975. MISSING_ITEM,
  18976. MAXIMUM_REACHED
  18977. };
  18978. void clif_inventory_expansion_result( map_session_data* sd, e_inventory_expansion_result result ){
  18979. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18980. nullpo_retv( sd );
  18981. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18982. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18983. p.result = (uint8)result;
  18984. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18985. // Reset the state tracking
  18986. sd->state.inventory_expansion_confirmation = 0;
  18987. sd->state.inventory_expansion_amount = 0;
  18988. #endif
  18989. }
  18990. void clif_parse_inventory_expansion_confirm( int fd, map_session_data* sd ){
  18991. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18992. if( sd->state.inventory_expansion_confirmation == 0 ){
  18993. return;
  18994. }
  18995. // Check if player is dead
  18996. if( pc_isdead( sd ) ){
  18997. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18998. return;
  18999. }
  19000. // Check if the player already reached the maximum
  19001. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  19002. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  19003. return;
  19004. }
  19005. // Check if the player has the required item
  19006. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  19007. // The player did not have the item anymore
  19008. if( index < 0 ){
  19009. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  19010. return;
  19011. }
  19012. // Check if the player would exceed the maximum
  19013. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  19014. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  19015. return;
  19016. }
  19017. // Delete the required item
  19018. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  19019. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  19020. return;
  19021. }
  19022. // Increase the slots
  19023. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  19024. // Save player data (slots) and inventory data (removed item)
  19025. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  19026. // Inform the player of success
  19027. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  19028. clif_inventory_expansion_info( sd );
  19029. #endif
  19030. }
  19031. void clif_parse_inventory_expansion_reject( int fd, map_session_data* sd ){
  19032. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  19033. sd->state.inventory_expansion_confirmation = 0;
  19034. sd->state.inventory_expansion_amount = 0;
  19035. #endif
  19036. }
  19037. void clif_barter_open( map_session_data& sd, struct npc_data& nd ){
  19038. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19039. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  19040. return;
  19041. }
  19042. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19043. if( barter == nullptr ){
  19044. return;
  19045. }
  19046. sd.state.barter_open = true;
  19047. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19048. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  19049. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  19050. int16 count = 0;
  19051. for( const auto& itemPair : barter->items ){
  19052. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  19053. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19054. item->nameid = client_nameid( id->nameid );
  19055. item->type = itemtype( id->nameid );
  19056. if( itemPair.second->stockLimited ){
  19057. item->amount = itemPair.second->stock;
  19058. }else{
  19059. item->amount = -1;
  19060. }
  19061. item->weight = id->weight;
  19062. item->index = itemPair.second->index;
  19063. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19064. item->viewSprite = id->look;
  19065. item->location = pc_equippoint_sub( &sd, id.get() );
  19066. #endif
  19067. // Use a loop if someone did not start with index 0
  19068. for( const auto& requirementPair : itemPair.second->requirements ){
  19069. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19070. item->currencyNameid = client_nameid( requirement->nameid );
  19071. item->currencyAmount = requirement->amount;
  19072. // It is a normal barter, cancel after first entry
  19073. break;
  19074. }
  19075. p->packetLength += (int16)( sizeof( *item ) );
  19076. count++;
  19077. }
  19078. clif_send( p, p->packetLength, &sd.bl, SELF );
  19079. #endif
  19080. }
  19081. void clif_parse_barter_close( int fd, map_session_data* sd ){
  19082. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19083. if( sd->state.barter_open ){
  19084. sd->npc_shopid = 0;
  19085. sd->state.barter_open = false;
  19086. }
  19087. #endif
  19088. }
  19089. void clif_parse_barter_buy( int fd, map_session_data* sd ){
  19090. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19091. // No shop open
  19092. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  19093. return;
  19094. }
  19095. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19096. // Unknown shop
  19097. if( nd == nullptr ){
  19098. return;
  19099. }
  19100. // Not a barter
  19101. if( nd->subtype != NPCTYPE_BARTER ){
  19102. return;
  19103. }
  19104. // It is an extended barter
  19105. if( nd->u.barter.extended ){
  19106. return;
  19107. }
  19108. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19109. if( barter == nullptr ){
  19110. return;
  19111. }
  19112. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19113. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  19114. // Empty purchase list
  19115. if( entries == 0 ){
  19116. return;
  19117. }
  19118. std::vector<s_barter_purchase> purchases;
  19119. purchases.reserve( entries );
  19120. // Make sure each shop index and target item id is only used once
  19121. for( int i = 0; i < entries; i++ ){
  19122. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19123. // Invalid shop index
  19124. if( item == nullptr ){
  19125. return;
  19126. }
  19127. for( int j = i + 1; j < entries; j++ ){
  19128. // Same shop index
  19129. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19130. return;
  19131. }
  19132. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19133. // Invalid shop index
  19134. if( item2 == nullptr ){
  19135. return;
  19136. }
  19137. // Same target item id
  19138. if( item->nameid == item2->nameid ){
  19139. return;
  19140. }
  19141. }
  19142. s_barter_purchase purchase = {};
  19143. purchase.item = item;
  19144. purchase.amount = p->list[i].amount;
  19145. purchases.push_back( purchase );
  19146. }
  19147. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19148. #endif
  19149. }
  19150. void clif_barter_extended_open( map_session_data& sd, struct npc_data& nd ){
  19151. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19152. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19153. return;
  19154. }
  19155. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19156. if( barter == nullptr ){
  19157. return;
  19158. }
  19159. sd.state.barter_extended_open = true;
  19160. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19161. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19162. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  19163. p->items_count = 0;
  19164. for( const auto& itemPair : barter->items ){
  19165. // Needs dynamic calculation, because of variable currencies
  19166. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  19167. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19168. item->nameid = client_nameid( id->nameid );
  19169. item->type = itemtype( id->nameid );
  19170. if( itemPair.second->stockLimited ){
  19171. item->amount = itemPair.second->stock;
  19172. }else{
  19173. item->amount = -1;
  19174. }
  19175. item->weight = id->weight;
  19176. item->index = itemPair.second->index;
  19177. item->zeny = itemPair.second->price;
  19178. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19179. item->viewSprite = id->look;
  19180. item->location = pc_equippoint_sub( &sd, id.get() );
  19181. #endif
  19182. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19183. p->items_count++;
  19184. item->currency_count = 0;
  19185. for( const auto& requirementPair : itemPair.second->requirements ){
  19186. // Needs dynamic calculation, because of variable currencies
  19187. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19188. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19189. req->nameid = requirement->nameid;
  19190. if( requirement->refine >= 0 ){
  19191. req->refine_level = requirement->refine;
  19192. }else{
  19193. req->refine_level = 0;
  19194. }
  19195. req->amount = requirement->amount;
  19196. req->type = itemtype( requirement->nameid );
  19197. p->packetLength += (int16)( sizeof( *req ) );
  19198. item->currency_count++;
  19199. }
  19200. }
  19201. clif_send( p, p->packetLength, &sd.bl, SELF );
  19202. #endif
  19203. }
  19204. void clif_parse_barter_extended_close( int fd, map_session_data* sd ){
  19205. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19206. if( sd->state.barter_extended_open ){
  19207. sd->npc_shopid = 0;
  19208. sd->state.barter_extended_open = false;
  19209. }
  19210. #endif
  19211. }
  19212. void clif_parse_barter_extended_buy( int fd, map_session_data* sd ){
  19213. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19214. // No shop open
  19215. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19216. return;
  19217. }
  19218. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19219. // Unknown shop
  19220. if( nd == nullptr ){
  19221. return;
  19222. }
  19223. // Not a barter
  19224. if( nd->subtype != NPCTYPE_BARTER ){
  19225. return;
  19226. }
  19227. // Not an extended barter
  19228. if( !nd->u.barter.extended ){
  19229. return;
  19230. }
  19231. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19232. if( barter == nullptr ){
  19233. return;
  19234. }
  19235. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19236. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19237. // Empty purchase list
  19238. if( entries == 0 ){
  19239. return;
  19240. }
  19241. std::vector<s_barter_purchase> purchases;
  19242. purchases.reserve( entries );
  19243. // Make sure each shop index and target item id is only used once
  19244. for( int i = 0; i < entries; i++ ){
  19245. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19246. // Invalid shop index
  19247. if( item == nullptr ){
  19248. return;
  19249. }
  19250. for( int j = i + 1; j < entries; j++ ){
  19251. // Same shop index
  19252. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19253. return;
  19254. }
  19255. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19256. // Invalid shop index
  19257. if( item2 == nullptr ){
  19258. return;
  19259. }
  19260. // Same target item id
  19261. if( item->nameid == item2->nameid ){
  19262. return;
  19263. }
  19264. }
  19265. s_barter_purchase purchase = {};
  19266. purchase.item = item;
  19267. purchase.amount = p->list[i].amount;
  19268. purchases.push_back( purchase );
  19269. }
  19270. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19271. #endif
  19272. }
  19273. void clif_summon_init(struct mob_data& md) {
  19274. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19275. struct block_list* master_bl = battle_get_master(&md.bl);
  19276. if( master_bl == nullptr ){
  19277. return;
  19278. }
  19279. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19280. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19281. p.summonAID = md.bl.id;
  19282. p.CurrentHP = md.status.hp;
  19283. p.MaxHP = md.status.max_hp;
  19284. clif_send( &p, sizeof( p ), master_bl, SELF );
  19285. #endif
  19286. }
  19287. void clif_summon_hp_bar(struct mob_data& md) {
  19288. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19289. struct block_list* master_bl = battle_get_master(&md.bl);
  19290. if( master_bl == nullptr ){
  19291. return;
  19292. }
  19293. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19294. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19295. p.summonAID = md.bl.id;
  19296. p.VarId = SP_HP; // HP parameter
  19297. p.Value = md.status.hp;
  19298. clif_send( &p, sizeof( p ), master_bl, SELF );
  19299. #endif
  19300. }
  19301. void clif_laphine_synthesis_open( map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19302. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19303. nullpo_retv( sd );
  19304. sd->state.laphine_synthesis = synthesis->item_id;
  19305. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19306. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19307. p.itemId = client_nameid( synthesis->item_id );
  19308. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19309. #endif
  19310. }
  19311. void clif_parse_laphine_synthesis_close( int fd, map_session_data* sd ){
  19312. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19313. sd->state.laphine_synthesis = 0;
  19314. #endif
  19315. }
  19316. enum e_laphine_synthesis_result : int16{
  19317. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19318. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19319. LAPHINE_SYNTHESIS_ITEM = 7
  19320. };
  19321. void clif_laphine_synthesis_result( map_session_data* sd, enum e_laphine_synthesis_result result ){
  19322. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19323. nullpo_retv( sd );
  19324. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19325. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19326. p.result = result;
  19327. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19328. #endif
  19329. }
  19330. void clif_parse_laphine_synthesis( int fd, map_session_data* sd ){
  19331. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19332. if( sd->state.laphine_synthesis == 0 ){
  19333. return;
  19334. }
  19335. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19336. if( sd->state.laphine_synthesis != p->itemId ){
  19337. return;
  19338. }
  19339. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19340. if( synthesis == nullptr ){
  19341. return;
  19342. }
  19343. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19344. // Player sent more or less than actually required
  19345. if( count != synthesis->requiredRequirements ){
  19346. return;
  19347. }
  19348. // Check for duplicates
  19349. for( size_t i = 0; i < count; i++ ){
  19350. for( size_t j = i + 1; j < count; j++ ){
  19351. if( p->items[i].index == p->items[j].index ){
  19352. return;
  19353. }
  19354. }
  19355. }
  19356. for( size_t i = 0; i < count; i++ ){
  19357. int16 index = server_index( p->items[i].index );
  19358. if( index >= MAX_INVENTORY ){
  19359. return;
  19360. }
  19361. if( sd->inventory_data[index] == nullptr ){
  19362. return;
  19363. }
  19364. struct item* item = &sd->inventory.u.items_inventory[index];
  19365. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19366. if( requirement == nullptr ){
  19367. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19368. return;
  19369. }
  19370. if( p->items[i].count != requirement->amount ){
  19371. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19372. return;
  19373. }
  19374. if( item->amount < requirement->amount ){
  19375. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19376. return;
  19377. }
  19378. if( item->refine < synthesis->minimumRefine ){
  19379. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19380. return;
  19381. }
  19382. if( item->refine > synthesis->maximumRefine ){
  19383. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19384. return;
  19385. }
  19386. if( item->equip != 0 ){
  19387. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19388. return;
  19389. }
  19390. if( item->equipSwitch != 0 ){
  19391. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19392. return;
  19393. }
  19394. }
  19395. // If triggered from item
  19396. if( sd->itemid == sd->state.laphine_synthesis ){
  19397. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19398. if( index < 0 ){
  19399. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19400. return;
  19401. }
  19402. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19403. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19404. return;
  19405. }
  19406. }
  19407. }
  19408. for( size_t i = 0; i < count; i++ ){
  19409. int16 index = server_index( p->items[i].index );
  19410. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19411. return;
  19412. }
  19413. }
  19414. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19415. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19416. #endif
  19417. }
  19418. void clif_laphine_upgrade_open( map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19419. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19420. nullpo_retv( sd );
  19421. sd->state.laphine_upgrade = upgrade->item_id;
  19422. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19423. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19424. p.itemId = client_nameid( upgrade->item_id );
  19425. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19426. #endif
  19427. }
  19428. void clif_parse_laphine_upgrade_close( int fd, map_session_data* sd ){
  19429. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19430. sd->state.laphine_upgrade = 0;
  19431. #endif
  19432. }
  19433. void clif_laphine_upgrade_result( map_session_data *sd, bool failed ){
  19434. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19435. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19436. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19437. p.result = failed;
  19438. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19439. #endif
  19440. }
  19441. static void clif_item_preview( map_session_data *sd, int16 index ){
  19442. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19443. nullpo_retv( sd );
  19444. struct item* item = &sd->inventory.u.items_inventory[index];
  19445. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19446. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19447. p.index = client_index( index );
  19448. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19449. p.isDamaged = item->attribute != 0;
  19450. #endif
  19451. p.refiningLevel = item->refine;
  19452. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19453. p.grade = item->enchantgrade;
  19454. #endif
  19455. clif_addcards( &p.slot, item );
  19456. clif_add_random_options( p.option_data, *item );
  19457. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19458. #endif
  19459. }
  19460. void clif_parse_laphine_upgrade( int fd, map_session_data* sd ){
  19461. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19462. if( sd->state.laphine_upgrade == 0 ){
  19463. return;
  19464. }
  19465. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19466. if( sd->state.laphine_upgrade != p->itemId ){
  19467. return;
  19468. }
  19469. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19470. if( upgrade == nullptr ){
  19471. return;
  19472. }
  19473. uint16 index = server_index( p->index );
  19474. if( index >= MAX_INVENTORY ){
  19475. return;
  19476. }
  19477. if( sd->inventory_data[index] == nullptr ){
  19478. return;
  19479. }
  19480. struct item* item = &sd->inventory.u.items_inventory[index];
  19481. // Not a valid target item
  19482. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19483. clif_laphine_upgrade_result( sd, true );
  19484. return;
  19485. }
  19486. // If target item is not identified
  19487. if( item->identify == 0 ){
  19488. clif_laphine_upgrade_result( sd, true );
  19489. return;
  19490. }
  19491. // If target item is equipped
  19492. if( item->equip != 0 ){
  19493. clif_laphine_upgrade_result( sd, true );
  19494. return;
  19495. }
  19496. // If target item is in equipswitch
  19497. if( item->equipSwitch != 0 ){
  19498. clif_laphine_upgrade_result( sd, true );
  19499. return;
  19500. }
  19501. // Check minimum refine requirement
  19502. if( item->refine < upgrade->minimumRefine ){
  19503. clif_laphine_upgrade_result( sd, true );
  19504. return;
  19505. }
  19506. // Check maximum refine requirement
  19507. if( item->refine > upgrade->maximumRefine ){
  19508. clif_laphine_upgrade_result( sd, true );
  19509. return;
  19510. }
  19511. // If no cards are allowed
  19512. if( !upgrade->cardsAllowed ){
  19513. for( int i = 0; i < MAX_SLOTS; i++ ){
  19514. if( item->card[i] != 0 ){
  19515. clif_laphine_upgrade_result( sd, true );
  19516. return;
  19517. }
  19518. }
  19519. }
  19520. // If random options are required
  19521. if( upgrade->requiredRandomOptions > 0 ){
  19522. int i;
  19523. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19524. if( item->option[i].id != 0 ){
  19525. break;
  19526. }
  19527. }
  19528. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19529. clif_laphine_upgrade_result( sd, true );
  19530. return;
  19531. }
  19532. }
  19533. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19534. if( index2 < 0 ){
  19535. clif_laphine_upgrade_result( sd, true );
  19536. return;
  19537. }
  19538. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19539. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19540. return;
  19541. }
  19542. }
  19543. // Log removal of item
  19544. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19545. // Visually remove it from the client
  19546. clif_delitem( sd, index, 1, 0 );
  19547. // Apply the random options
  19548. if( upgrade->randomOptionGroup != nullptr ){
  19549. upgrade->randomOptionGroup->apply( *item );
  19550. }
  19551. // Change the refine rate if needed
  19552. if( upgrade->resultRefine > 0 ){
  19553. // Absolute refine level change
  19554. item->refine = max( item->refine, upgrade->resultRefine );
  19555. }else if( upgrade->resultRefineMaximum > 0 ){
  19556. // If a minimum is specified it can also downgrade
  19557. if( upgrade->resultRefineMinimum ){
  19558. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum ) );
  19559. }else{
  19560. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19561. item->refine = static_cast<uint8>( rnd_value<uint16>( item->refine, upgrade->resultRefineMaximum ) );
  19562. }
  19563. }else if( upgrade->resultRefineMinimum > 0 ){
  19564. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19565. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, MAX_REFINE ) );
  19566. }
  19567. // Log retrieving the item again -> with the new options
  19568. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19569. // Make it visible for the client again
  19570. clif_additem( sd, index, 1, 0 );
  19571. // Open a preview of the item
  19572. clif_item_preview( sd, index );
  19573. // Tell the client we are done
  19574. clif_laphine_upgrade_result( sd, false );
  19575. #endif
  19576. }
  19577. void clif_enchantgrade_add( map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19578. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19579. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19580. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19581. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19582. if( index < UINT16_MAX ){
  19583. p->index = client_index( index );
  19584. p->success_chance = gradeLevel->chances[sd.inventory.u.items_inventory[index].refine] / 100;
  19585. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19586. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19587. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19588. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19589. // Not displayed by client
  19590. p->protect_itemid = 0;
  19591. p->protect_amount = 0;
  19592. int i = 0;
  19593. for( const auto& pair : gradeLevel->options ){
  19594. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19595. p->material_info[i].nameid = client_nameid( option->item );
  19596. p->material_info[i].amount = option->amount;
  19597. p->material_info[i].price = option->zeny;
  19598. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19599. p->material_info[i].breakable = option->breaking_rate > 0;
  19600. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19601. i++;
  19602. }
  19603. }else{
  19604. p->index = -1;
  19605. p->success_chance = 0;
  19606. p->blessing_info.id = 0;
  19607. p->blessing_info.amount = 0;
  19608. p->blessing_info.max_blessing = 0;
  19609. p->blessing_info.bonus = 0;
  19610. p->protect_itemid = 0;
  19611. p->protect_amount = 0;
  19612. }
  19613. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19614. #endif
  19615. }
  19616. void clif_parse_enchantgrade_add( int fd, map_session_data* sd ){
  19617. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19618. nullpo_retv( sd );
  19619. if( !sd->state.enchantgrade_open ){
  19620. return;
  19621. }
  19622. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19623. uint16 index = server_index( p->index );
  19624. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19625. return;
  19626. }
  19627. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19628. // Unsupported item type - no answer, because client should have actually prevented this request
  19629. if( enchantgrade == nullptr ){
  19630. return;
  19631. }
  19632. // Item can't be enhanced
  19633. if( !sd->inventory_data[index]->flag.gradable ){
  19634. return;
  19635. }
  19636. uint16 level = 0;
  19637. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19638. level = sd->inventory_data[index]->weapon_level;
  19639. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19640. level = sd->inventory_data[index]->armor_level;
  19641. }
  19642. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19643. // Cannot upgrade this weapon or armor level
  19644. if( enchantgradelevels == enchantgrade->levels.end() ){
  19645. clif_enchantgrade_add( *sd );
  19646. return;
  19647. }
  19648. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19649. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19650. if( enchantgradelevel == nullptr ){
  19651. return;
  19652. }
  19653. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19654. #endif
  19655. }
  19656. /// <summary>
  19657. /// Sends the result for trying to enchant an item
  19658. /// </summary>
  19659. /// <param name="sd">The player session</param>
  19660. /// <param name="index">The target item</param>
  19661. /// <param name="result">
  19662. /// 0= The grade has been successfully upgraded.
  19663. /// 1= Refinement failed.
  19664. /// 2= The refine level has decreased.
  19665. /// 3= Equipment destroyed.
  19666. /// 4= The equipment is protected.
  19667. /// </param>
  19668. void clif_enchantgrade_result( map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19669. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19670. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19671. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19672. p.index = client_index( index );
  19673. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19674. p.result = result;
  19675. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19676. #endif
  19677. }
  19678. void clif_enchantgrade_announce( map_session_data& sd, struct item& item, bool success ){
  19679. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19680. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19681. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19682. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19683. p.itemId = client_nameid( item.nameid );
  19684. p.grade = item.enchantgrade;
  19685. p.status = success;
  19686. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19687. #endif
  19688. }
  19689. void clif_parse_enchantgrade_start( int fd, map_session_data* sd ){
  19690. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19691. nullpo_retv( sd );
  19692. if( !sd->state.enchantgrade_open ){
  19693. return;
  19694. }
  19695. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19696. uint16 index = server_index( p->index );
  19697. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19698. return;
  19699. }
  19700. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19701. // Unsupported item type - no answer
  19702. if( enchantgrade == nullptr ){
  19703. return;
  19704. }
  19705. uint16 level = 0;
  19706. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19707. level = sd->inventory_data[index]->weapon_level;
  19708. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19709. level = sd->inventory_data[index]->armor_level;
  19710. }
  19711. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19712. // Cannot upgrade this weapon or armor level - no answer
  19713. if( enchantgradelevels == enchantgrade->levels.end() ){
  19714. return;
  19715. }
  19716. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19717. // Cannot increase enchantgrade any further - no answer
  19718. if( enchantgradelevel == nullptr ){
  19719. return;
  19720. }
  19721. uint16 totalChance = enchantgradelevel->chances[sd->inventory.u.items_inventory[index].refine];
  19722. // No chance to increase the enchantgrade
  19723. if( totalChance == 0 ){
  19724. return;
  19725. }
  19726. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19727. // Unknown option id - no answer
  19728. if( option == nullptr ){
  19729. return;
  19730. }
  19731. // Not enough zeny
  19732. if( sd->status.zeny < option->zeny ){
  19733. return;
  19734. }
  19735. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19736. std::unordered_map<uint16, uint16> requiredItems;
  19737. if( p->blessing_flag ){
  19738. // If the catalysator item is the same as the option item build the sum of amounts
  19739. if( enchantgradelevel->catalyst.item == option->item ){
  19740. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19741. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19742. if( index < 0 ){
  19743. return;
  19744. }
  19745. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19746. return;
  19747. }
  19748. requiredItems[index] = amount;
  19749. }else{
  19750. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19751. // Check catalysator item
  19752. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19753. if( index < 0 ){
  19754. return;
  19755. }
  19756. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19757. return;
  19758. }
  19759. requiredItems[index] = amount;
  19760. // Check option item
  19761. index = pc_search_inventory( sd, option->item );
  19762. if( index < 0 ){
  19763. return;
  19764. }
  19765. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19766. return;
  19767. }
  19768. requiredItems[index] = option->amount;
  19769. }
  19770. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19771. }else{
  19772. // Check option item
  19773. int16 index = pc_search_inventory( sd, option->item );
  19774. if( index < 0 ){
  19775. return;
  19776. }
  19777. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19778. return;
  19779. }
  19780. requiredItems[index] = option->amount;
  19781. }
  19782. // All items should be there, start deleting
  19783. for( const auto& pair : requiredItems ){
  19784. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19785. return;
  19786. }
  19787. }
  19788. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE ) > 0 ){
  19789. return;
  19790. }
  19791. if( rnd()%10000 < totalChance ){
  19792. // Log removal of item
  19793. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19794. // Increase enchantgrade
  19795. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19796. // On successful enchantgrade increase the refine is reset
  19797. sd->inventory.u.items_inventory[index].refine = 0;
  19798. // Log retrieving the item again -> with the new refine and enchantgrade
  19799. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19800. // Show success
  19801. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19802. // Check if it has to be announced
  19803. if( enchantgradelevel->announceSuccess ){
  19804. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19805. }
  19806. }else{
  19807. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19808. if( enchantgradelevel->announceFail ){
  19809. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19810. }
  19811. // Delete the item if it is breakable
  19812. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19813. // Delete the item
  19814. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19815. // Show failure
  19816. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19817. // Downgrade the item if necessary
  19818. }else if( option->downgrade_amount > 0 ){
  19819. // Log removal of item
  19820. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19821. // Decrease refine level
  19822. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19823. // Log retrieving the item again -> with the new refine
  19824. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19825. // Show downgrade
  19826. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19827. // Only show failure, but dont do anything
  19828. }else{
  19829. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19830. }
  19831. }
  19832. #endif
  19833. }
  19834. void clif_parse_enchantgrade_close( int fd, map_session_data* sd ){
  19835. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19836. nullpo_retv( sd );
  19837. sd->state.enchantgrade_open = false;
  19838. #endif
  19839. }
  19840. void clif_reputation_type( map_session_data& sd, int64 type, int64 points ){
  19841. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19842. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19843. p->packetType = HEADER_ZC_REPUTE_INFO;
  19844. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19845. p->success = true;
  19846. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19847. entry->type = type;
  19848. entry->points = points;
  19849. clif_send( p, p->packetLength, &sd.bl, SELF );
  19850. #endif
  19851. }
  19852. void clif_reputation_list( map_session_data& sd ){
  19853. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19854. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19855. p->packetType = HEADER_ZC_REPUTE_INFO;
  19856. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19857. p->success = true;
  19858. size_t index = 0;
  19859. for( const auto& entry : reputation_db ){
  19860. std::shared_ptr<s_reputation> reputation = entry.second;
  19861. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19862. list_entry->type = reputation->id;
  19863. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19864. p->packetLength += sizeof( *list_entry );
  19865. index++;
  19866. }
  19867. clif_send( p, p->packetLength, &sd.bl, SELF );
  19868. #endif
  19869. }
  19870. void clif_item_reform_open( map_session_data& sd, t_itemid item ){
  19871. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19872. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19873. p.PacketType = HEADER_ZC_OPEN_REFORM_UI;
  19874. p.ITID = item;
  19875. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19876. sd.state.item_reform = item;
  19877. #endif
  19878. }
  19879. void clif_parse_item_reform_close( int fd, map_session_data* sd ){
  19880. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19881. sd->state.item_reform = 0;
  19882. #endif
  19883. }
  19884. void clif_item_reform_result( map_session_data& sd, uint16 index, uint8 result ){
  19885. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19886. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19887. p.PacketType = HEADER_ZC_ITEM_REFORM_ACK;
  19888. p.index = client_index( index );
  19889. p.result = result;
  19890. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19891. if( result == 0 ){
  19892. // Client closes the window on success
  19893. sd.state.item_reform = 0;
  19894. }
  19895. #endif
  19896. }
  19897. void clif_parse_item_reform_start( int fd, map_session_data* sd ){
  19898. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19899. // Not opened
  19900. if( sd->state.item_reform == 0 ){
  19901. return;
  19902. }
  19903. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19904. // Item mismatch
  19905. if( p->ITID != sd->state.item_reform ){
  19906. return;
  19907. }
  19908. uint16 index = server_index( p->index );
  19909. if( index >= MAX_INVENTORY ){
  19910. return;
  19911. }
  19912. if( sd->inventory_data[index] == nullptr ){
  19913. return;
  19914. }
  19915. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19916. if( reform == nullptr ){
  19917. return;
  19918. }
  19919. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19920. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19921. if( base == nullptr ){
  19922. return;
  19923. }
  19924. // If target item is not identified
  19925. if( selected_item.identify == 0 ){
  19926. return;
  19927. }
  19928. // If target item is equipped
  19929. if( selected_item.equip != 0 ){
  19930. return;
  19931. }
  19932. // Check minimum refine requirement
  19933. if( selected_item.refine < base->minimumRefine ){
  19934. return;
  19935. }
  19936. // Check maximum refine requirement
  19937. if( selected_item.refine > base->maximumRefine ){
  19938. return;
  19939. }
  19940. // If no cards are allowed
  19941. if( !base->cardsAllowed ){
  19942. for( int i = 0; i < MAX_SLOTS; i++ ){
  19943. if( selected_item.card[i] != 0 ){
  19944. return;
  19945. }
  19946. }
  19947. }
  19948. // If random options are required
  19949. if( base->requiredRandomOptions > 0 ){
  19950. int i;
  19951. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19952. if( selected_item.option[i].id != 0 ){
  19953. break;
  19954. }
  19955. }
  19956. if( ( i + 1 ) < base->requiredRandomOptions ){
  19957. return;
  19958. }
  19959. }
  19960. std::unordered_map<uint16, uint16> materials;
  19961. // Check if all materials exist
  19962. for( const auto& material : base->materials ){
  19963. int16 material_index = pc_search_inventory( sd, material.first );
  19964. if( material_index < 0 ){
  19965. return;
  19966. }
  19967. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19968. return;
  19969. }
  19970. materials[material_index] = material.second;
  19971. }
  19972. // Remove the material
  19973. for( const auto& material : materials ){
  19974. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19975. return;
  19976. }
  19977. }
  19978. // If triggered from item
  19979. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19980. return;
  19981. }
  19982. // Log removal of item
  19983. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19984. // Visually remove it from the client
  19985. clif_delitem( sd, index, 1, 0 );
  19986. // Apply the random options
  19987. if( base->randomOptionGroup != nullptr ){
  19988. base->randomOptionGroup->apply( selected_item );
  19989. }
  19990. // Change the refine rate if needed
  19991. if( base->refineChange != 0 ){
  19992. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19993. }
  19994. // Remove all cards and socket enchants
  19995. if( base->clearSlots ){
  19996. for( int i = 0; i < MAX_SLOTS; i++ ){
  19997. selected_item.card[i] = 0;
  19998. }
  19999. }
  20000. // Remove the current enchantgrade
  20001. if( base->removeEnchantgrade ){
  20002. selected_item.enchantgrade = 0;
  20003. }
  20004. // Finally change the item id
  20005. selected_item.nameid = base->resultItemId;
  20006. // Link inventory data cache to the new item
  20007. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  20008. // Log retrieving the item again -> with the new options
  20009. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  20010. // Make it visible for the client again
  20011. clif_additem( sd, index, 1, 0 );
  20012. clif_item_reform_result( *sd, index, 0 );
  20013. #endif
  20014. }
  20015. void clif_enchantwindow_open( map_session_data& sd, uint64 clientLuaIndex ){
  20016. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20017. // Hardcoded clientside check
  20018. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  20019. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  20020. sd.state.item_enchant_index = 0;
  20021. return;
  20022. }
  20023. struct PACKET_ZC_UI_OPEN_V3 p = {};
  20024. p.packetType = HEADER_ZC_UI_OPEN_V3;
  20025. p.type = OUT_UI_ENCHANT;
  20026. p.data = clientLuaIndex;
  20027. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20028. sd.state.item_enchant_index = clientLuaIndex;
  20029. #endif
  20030. }
  20031. void clif_enchantwindow_result( map_session_data& sd, bool success, t_itemid enchant = 0 ){
  20032. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20033. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  20034. p.PacketType = HEADER_ZC_RESPONSE_ENCHANT;
  20035. if( success ){
  20036. p.msgId = C_ENCHANT_SUCCESS;
  20037. }else{
  20038. p.msgId = C_ENCHANT_FAILURE;
  20039. }
  20040. p.ITID = enchant;
  20041. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20042. sd.state.item_enchant_index = 0;
  20043. #endif
  20044. }
  20045. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  20046. if( selected_item.equip != 0 ){
  20047. return false;
  20048. }
  20049. if( selected_item.equipSwitch != 0 ){
  20050. return false;
  20051. }
  20052. if( selected_item.attribute != 0 ){
  20053. return false;
  20054. }
  20055. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20056. return false;
  20057. }
  20058. if( selected_item.refine < enchant->minimumRefine ){
  20059. return false;
  20060. }
  20061. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20062. return false;
  20063. }
  20064. if( !enchant->allowRandomOptions ){
  20065. for( const s_item_randomoption& option : selected_item.option ){
  20066. if( option.id != 0 ){
  20067. return false;
  20068. }
  20069. }
  20070. }
  20071. return true;
  20072. }
  20073. void clif_parse_enchantwindow_general( int fd, map_session_data* sd ){
  20074. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20075. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  20076. if( sd->state.item_enchant_index != p->enchant_group ){
  20077. return;
  20078. }
  20079. uint16 index = server_index( p->index );
  20080. if( index >= MAX_INVENTORY ){
  20081. return;
  20082. }
  20083. if( sd->inventory_data[index] == nullptr ){
  20084. return;
  20085. }
  20086. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20087. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20088. if( enchant == nullptr ){
  20089. return;
  20090. }
  20091. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20092. return;
  20093. }
  20094. uint16 slot = MAX_SLOTS;
  20095. for( uint16 nextSlot : enchant->order ){
  20096. if( selected_item.card[nextSlot] == 0 ){
  20097. slot = nextSlot;
  20098. break;
  20099. }
  20100. }
  20101. if( slot == MAX_SLOTS ){
  20102. return;
  20103. }
  20104. if( slot < sd->inventory_data[index]->slots ){
  20105. return;
  20106. }
  20107. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20108. if( enchant_slot == nullptr ){
  20109. return;
  20110. }
  20111. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  20112. if( enchants_for_enchantgrade == nullptr ){
  20113. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  20114. clif_enchantwindow_result( *sd, false );
  20115. return;
  20116. }
  20117. if( sd->status.zeny < enchant_slot->normal.zeny ){
  20118. return;
  20119. }
  20120. std::unordered_map<uint16, uint16> materials;
  20121. for( const auto& entry : enchant_slot->normal.materials ){
  20122. int16 idx = pc_search_inventory( sd, entry.first );
  20123. if( idx < 0 ){
  20124. return;
  20125. }
  20126. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20127. return;
  20128. }
  20129. materials[idx] = entry.second;
  20130. }
  20131. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20132. return;
  20133. }
  20134. for( const auto& entry : materials ){
  20135. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20136. return;
  20137. }
  20138. }
  20139. uint32 chance = enchant_slot->normal.chance;
  20140. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  20141. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  20142. }
  20143. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20144. clif_enchantwindow_result( *sd, false );
  20145. return;
  20146. }
  20147. // Log removal of item
  20148. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20149. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  20150. bool enchanted = false;
  20151. for( int i = 0; i < maximum; i++ ){
  20152. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20153. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  20154. selected_item.card[slot] = normal_enchant->item_id;
  20155. enchanted = true;
  20156. break;
  20157. }
  20158. }
  20159. if( !enchanted ){
  20160. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20161. selected_item.card[slot] = normal_enchant->item_id;
  20162. }
  20163. // Log retrieving the item again -> with the new enchant
  20164. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20165. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20166. #endif
  20167. }
  20168. void clif_parse_enchantwindow_perfect( int fd, map_session_data* sd ){
  20169. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20170. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  20171. if( sd->state.item_enchant_index != p->enchant_group ){
  20172. return;
  20173. }
  20174. uint16 index = server_index( p->index );
  20175. if( index >= MAX_INVENTORY ){
  20176. return;
  20177. }
  20178. if( sd->inventory_data[index] == nullptr ){
  20179. return;
  20180. }
  20181. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20182. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20183. if( enchant == nullptr ){
  20184. return;
  20185. }
  20186. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20187. return;
  20188. }
  20189. uint16 slot = MAX_SLOTS;
  20190. for( uint16 nextSlot : enchant->order ){
  20191. if( selected_item.card[nextSlot] == 0 ){
  20192. slot = nextSlot;
  20193. break;
  20194. }
  20195. }
  20196. if( slot == MAX_SLOTS ){
  20197. return;
  20198. }
  20199. if( slot < sd->inventory_data[index]->slots ){
  20200. return;
  20201. }
  20202. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20203. if( enchant_slot == nullptr ){
  20204. return;
  20205. }
  20206. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->ITID );
  20207. if( perfect_enchant == nullptr ){
  20208. return;
  20209. }
  20210. if( sd->status.zeny < perfect_enchant->zeny ){
  20211. return;
  20212. }
  20213. std::unordered_map<uint16, uint16> materials;
  20214. for( const auto& entry : perfect_enchant->materials ){
  20215. int16 idx = pc_search_inventory( sd, entry.first );
  20216. if( idx < 0 ){
  20217. return;
  20218. }
  20219. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20220. return;
  20221. }
  20222. materials[idx] = entry.second;
  20223. }
  20224. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20225. return;
  20226. }
  20227. for( const auto& entry : materials ){
  20228. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20229. return;
  20230. }
  20231. }
  20232. // Log removal of item
  20233. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20234. selected_item.card[slot] = perfect_enchant->item_id;
  20235. // Log retrieving the item again -> with the new enchant
  20236. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20237. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20238. #endif
  20239. }
  20240. void clif_parse_enchantwindow_upgrade( int fd, map_session_data* sd ){
  20241. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20242. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20243. if( sd->state.item_enchant_index != p->enchant_group ){
  20244. return;
  20245. }
  20246. uint16 index = server_index( p->index );
  20247. if( index >= MAX_INVENTORY ){
  20248. return;
  20249. }
  20250. if( sd->inventory_data[index] == nullptr ){
  20251. return;
  20252. }
  20253. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20254. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20255. if( enchant == nullptr ){
  20256. return;
  20257. }
  20258. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20259. return;
  20260. }
  20261. uint16 slot = p->slot;
  20262. if( slot >= MAX_SLOTS ){
  20263. return;
  20264. }
  20265. if( slot < sd->inventory_data[index]->slots ){
  20266. return;
  20267. }
  20268. if( selected_item.card[slot] == 0 ){
  20269. return;
  20270. }
  20271. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20272. if( enchant_slot == nullptr ){
  20273. return;
  20274. }
  20275. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20276. if( upgrade == nullptr ){
  20277. return;
  20278. }
  20279. if( sd->status.zeny < upgrade->zeny ){
  20280. return;
  20281. }
  20282. std::unordered_map<uint16, uint16> materials;
  20283. for( const auto& entry : upgrade->materials ){
  20284. int16 idx = pc_search_inventory( sd, entry.first );
  20285. if( idx < 0 ){
  20286. return;
  20287. }
  20288. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20289. return;
  20290. }
  20291. materials[idx] = entry.second;
  20292. }
  20293. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20294. return;
  20295. }
  20296. for( const auto& entry : materials ){
  20297. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20298. return;
  20299. }
  20300. }
  20301. // Log removal of item
  20302. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20303. selected_item.card[slot] = upgrade->upgrade_item_id;
  20304. // Log retrieving the item again -> with the new enchant
  20305. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20306. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20307. #endif
  20308. }
  20309. void clif_parse_enchantwindow_reset( int fd, map_session_data* sd ){
  20310. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20311. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20312. if( sd->state.item_enchant_index != p->enchant_group ){
  20313. return;
  20314. }
  20315. uint16 index = server_index( p->index );
  20316. if( index >= MAX_INVENTORY ){
  20317. return;
  20318. }
  20319. if( sd->inventory_data[index] == nullptr ){
  20320. return;
  20321. }
  20322. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20323. if( selected_item.equip != 0 ){
  20324. return;
  20325. }
  20326. if( selected_item.equipSwitch != 0 ){
  20327. return;
  20328. }
  20329. if( selected_item.attribute != 0 ){
  20330. return;
  20331. }
  20332. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20333. if( enchant == nullptr ){
  20334. return;
  20335. }
  20336. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20337. return;
  20338. }
  20339. if( selected_item.refine < enchant->minimumRefine ){
  20340. return;
  20341. }
  20342. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20343. return;
  20344. }
  20345. bool is_enchanted = false;
  20346. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20347. if( selected_item.card[i] != 0 ){
  20348. is_enchanted = true;
  20349. break;
  20350. }
  20351. }
  20352. if( !is_enchanted ){
  20353. return;
  20354. }
  20355. if( sd->status.zeny < enchant->reset.zeny ){
  20356. return;
  20357. }
  20358. std::unordered_map<uint16, uint16> materials;
  20359. for( const auto& entry : enchant->reset.materials ){
  20360. int16 idx = pc_search_inventory( sd, entry.first );
  20361. if( idx < 0 ){
  20362. return;
  20363. }
  20364. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20365. return;
  20366. }
  20367. materials[idx] = entry.second;
  20368. }
  20369. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20370. return;
  20371. }
  20372. for( const auto& entry : materials ){
  20373. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20374. return;
  20375. }
  20376. }
  20377. uint32 chance = enchant->reset.chance;
  20378. if( chance == 0 ){
  20379. return;
  20380. }
  20381. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20382. clif_enchantwindow_result( *sd, false );
  20383. return;
  20384. }
  20385. // Log removal of item
  20386. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20387. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20388. selected_item.card[i] = 0;
  20389. }
  20390. // Log retrieving the item again -> with the new enchant
  20391. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20392. clif_enchantwindow_result( *sd, true );
  20393. #endif
  20394. }
  20395. void clif_parse_enchantwindow_close( int fd, map_session_data* sd ){
  20396. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20397. sd->state.item_enchant_index = 0;
  20398. #endif
  20399. }
  20400. void clif_parse_itempackage_select( int fd, map_session_data* sd ){
  20401. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20402. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20403. if( p->AID != sd->status.account_id ){
  20404. return;
  20405. }
  20406. uint16 index = server_index( p->index );
  20407. if( index >= MAX_INVENTORY ){
  20408. return;
  20409. }
  20410. if( sd->inventory_data[index] == nullptr ){
  20411. return;
  20412. }
  20413. if( sd->inventory_data[index]->nameid != p->itemID ){
  20414. return;
  20415. }
  20416. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20417. return;
  20418. }
  20419. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20420. if( package == nullptr ){
  20421. return;
  20422. }
  20423. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20424. if( group == nullptr ){
  20425. return;
  20426. }
  20427. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20428. return;
  20429. }
  20430. for( const auto& entry : group->items ){
  20431. struct item item = {};
  20432. item.nameid = entry.second->item_id;
  20433. item.identify = 1;
  20434. item.refine = (char)entry.second->refine;
  20435. if( entry.second->rentalhours ){
  20436. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20437. }
  20438. // Check if it is a pet egg
  20439. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20440. if( pet != nullptr ){
  20441. for( int i = 0; i < entry.second->amount; i++ ){
  20442. pet_create_egg( sd, item.nameid );
  20443. }
  20444. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20445. for( int i = 0; i < entry.second->amount; i++ ){
  20446. // New random options on each iteration
  20447. if( entry.second->randomOptionGroup != nullptr ){
  20448. entry.second->randomOptionGroup->apply( item );
  20449. }
  20450. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20451. }
  20452. }else{
  20453. if( entry.second->randomOptionGroup != nullptr ){
  20454. entry.second->randomOptionGroup->apply( item );
  20455. }
  20456. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20457. }
  20458. }
  20459. #endif
  20460. }
  20461. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20462. {
  20463. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20464. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20465. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20466. p.itemId = itemId;
  20467. p.refine_level = level;
  20468. p.status = (int8)success;
  20469. if (battle_config.broadcast_hide_name) {
  20470. std::string dispname = clif_hide_name(sd.status.name);
  20471. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20472. }
  20473. else {
  20474. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20475. }
  20476. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20477. #endif
  20478. }
  20479. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20480. #if PACKETVER >= 20160316
  20481. nullpo_retv(sd);
  20482. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20483. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20484. return;
  20485. }
  20486. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20487. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20488. #endif
  20489. }
  20490. void clif_captcha_upload_request(map_session_data &sd) {
  20491. #if PACKETVER >= 20160330
  20492. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20493. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20494. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20495. if (sd.captcha_upload.cd != nullptr) {
  20496. p.captchaFlag = 0;
  20497. } else {
  20498. p.captchaFlag = 1;
  20499. }
  20500. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20501. #endif
  20502. }
  20503. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20504. #if PACKETVER >= 20160316
  20505. nullpo_retv(sd);
  20506. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20507. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20508. return;
  20509. }
  20510. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20511. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20512. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20513. return;
  20514. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20515. return;
  20516. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20517. #endif
  20518. }
  20519. void clif_captcha_upload_end(map_session_data &sd) {
  20520. #if PACKETVER >= 20160330
  20521. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20522. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20523. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20524. #endif
  20525. }
  20526. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20527. #if PACKETVER >= 20160323
  20528. nullpo_retv(sd);
  20529. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20530. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20531. return;
  20532. }
  20533. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20534. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20535. #endif
  20536. }
  20537. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20538. #if PACKETVER >= 20160330
  20539. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20540. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20541. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20542. if (cd == nullptr) {
  20543. p.captchaFlag = 1;
  20544. p.imageSize = 0;
  20545. } else {
  20546. p.captchaFlag = 0;
  20547. p.imageSize = cd->image_size;
  20548. }
  20549. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20550. if (cd != nullptr) {
  20551. for (uint16 offset = 0; offset < cd->image_size;) {
  20552. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20553. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20554. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20555. p2->PacketLength = (int16)(sizeof(PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20556. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20557. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20558. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20559. offset += chunk_size;
  20560. }
  20561. }
  20562. #endif
  20563. }
  20564. void clif_macro_detector_request(map_session_data &sd) {
  20565. #if PACKETVER >= 20160330
  20566. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20567. if (cd == nullptr) {
  20568. return;
  20569. }
  20570. // Send preview initialization request to the client.
  20571. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20572. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20573. p.imageSize = cd->image_size;
  20574. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20575. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20576. for (uint16 offset = 0; offset < cd->image_size;) {
  20577. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20578. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20579. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20580. p2->PacketLength = (int16)(sizeof(PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20581. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20582. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20583. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20584. offset += chunk_size;
  20585. }
  20586. #endif
  20587. }
  20588. void clif_macro_detector_request_show(map_session_data &sd) {
  20589. #if PACKETVER >= 20160330
  20590. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20591. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20592. p.retryCount = sd.macro_detect.retry;
  20593. p.timeout = battle_config.macro_detection_timeout;
  20594. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20595. #endif
  20596. }
  20597. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20598. #if PACKETVER >= 20160316
  20599. nullpo_retv(sd);
  20600. if (sd->macro_detect.retry != 0) {
  20601. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20602. clif_macro_detector_request_show(*sd);
  20603. }
  20604. #endif
  20605. }
  20606. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20607. #if PACKETVER >= 20160316
  20608. nullpo_retv(sd);
  20609. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20610. pc_macro_detector_process_answer(*sd, p->answer);
  20611. #endif
  20612. }
  20613. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20614. #if PACKETVER >= 20160330
  20615. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20616. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20617. p.status = stype;
  20618. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20619. #endif
  20620. }
  20621. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20622. #if PACKETVER >= 20160330
  20623. nullpo_retv(sd);
  20624. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20625. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20626. return;
  20627. }
  20628. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20629. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20630. #endif
  20631. }
  20632. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20633. #if PACKETVER >= 20160330
  20634. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *p = (PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *)packet_buffer;
  20635. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20636. p->PacketLength = static_cast<int16>(sizeof(PACKET_ZC_ACK_PLAYER_AID_IN_RANGE) + sizeof(uint32) * aid_list.size());
  20637. for (size_t i = 0; i < aid_list.size(); i++)
  20638. p->AID[i] = aid_list[static_cast<int32>(i)];
  20639. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20640. #endif
  20641. }
  20642. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20643. #if PACKETVER >= 20160316
  20644. nullpo_retv(sd);
  20645. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20646. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20647. return;
  20648. }
  20649. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20650. map_session_data *tsd = map_id2sd(p->AID);
  20651. if (tsd == nullptr) {
  20652. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20653. return;
  20654. }
  20655. if (tsd->macro_detect.retry != 0) {
  20656. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20657. return;
  20658. }
  20659. if (captcha_db.empty()) {
  20660. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20661. return;
  20662. }
  20663. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20664. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20665. #endif
  20666. }
  20667. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20668. #if PACKETVER >= 20160330
  20669. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20670. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20671. p.status = stype;
  20672. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20673. #endif
  20674. }
  20675. void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ){
  20676. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20677. struct PACKET_ZC_DYNAMICNPC_CREATE_RESULT p = {};
  20678. p.PacketType = HEADER_ZC_DYNAMICNPC_CREATE_RESULT;
  20679. p.result = result;
  20680. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20681. #endif
  20682. }
  20683. void clif_partybooking_ask( map_session_data* sd, map_session_data* joining_sd ){
  20684. #if PACKETVER >= 20191204
  20685. struct PACKET_ZC_PARTY_REQ_MASTER_TO_JOIN p = { 0 };
  20686. p.packetType = HEADER_ZC_PARTY_REQ_MASTER_TO_JOIN;
  20687. p.CID = joining_sd->status.char_id;
  20688. p.AID = joining_sd->status.account_id;
  20689. safestrncpy( p.name, joining_sd->status.name, NAME_LENGTH );
  20690. p.x = joining_sd->status.base_level;
  20691. p.y = joining_sd->status.class_;
  20692. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20693. #endif
  20694. }
  20695. void clif_parse_partybooking_join( int fd, map_session_data* sd ){
  20696. #if PACKETVER >= 20191204
  20697. struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20698. // Character is already in a party
  20699. if( sd->status.party_id != 0 ){
  20700. return;
  20701. }
  20702. map_session_data* tsd = map_charid2sd( p->CID );
  20703. // Target player is offline
  20704. if( tsd == nullptr ){
  20705. return;
  20706. }
  20707. if( tsd->status.account_id != p->AID ){
  20708. return;
  20709. }
  20710. struct s_party_booking_requirement requirement;
  20711. if( !party_booking_load( tsd->status.account_id, tsd->status.char_id, &requirement ) ){
  20712. return;
  20713. }
  20714. if( sd->status.base_level < requirement.minimum_level ){
  20715. return;
  20716. }
  20717. if( sd->status.base_level > requirement.maximum_level ){
  20718. return;
  20719. }
  20720. // Already requested to join this party
  20721. if( util::vector_exists( tsd->party_booking_requests, sd->status.char_id ) ){
  20722. return;
  20723. }
  20724. // Store information that the player tried to join the party
  20725. tsd->party_booking_requests.push_back( sd->status.char_id );
  20726. clif_partybooking_ask( tsd, sd );
  20727. #endif
  20728. }
  20729. void clif_partybooking_reply( map_session_data* sd, map_session_data* party_leader_sd, bool accepted ){
  20730. #if PACKETVER >= 20191204
  20731. struct PACKET_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER p = { 0 };
  20732. if( party_leader_sd->status.party_id == 0 ){
  20733. return;
  20734. }
  20735. struct party_data* party = party_search( party_leader_sd->status.party_id );
  20736. if( party == nullptr ){
  20737. return;
  20738. }
  20739. p.packetType = HEADER_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER;
  20740. safestrncpy( p.player_name, party_leader_sd->status.name, NAME_LENGTH );
  20741. safestrncpy( p.party_name, party->party.name, NAME_LENGTH );
  20742. p.AID = party_leader_sd->status.account_id;
  20743. p.refused = !accepted;
  20744. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20745. #endif
  20746. }
  20747. void clif_parse_partybooking_reply( int fd, map_session_data* sd ){
  20748. #if PACKETVER >= 20191204
  20749. struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20750. map_session_data* tsd = map_charid2sd( p->CID );
  20751. // Target player is offline
  20752. if( tsd == nullptr ){
  20753. return;
  20754. }
  20755. if( tsd->status.account_id != p->AID ){
  20756. return;
  20757. }
  20758. // Check if the player even requested to join the party
  20759. if( !util::vector_exists( sd->party_booking_requests, p->CID ) ){
  20760. return;
  20761. }
  20762. util::vector_erase_if_exists( sd->party_booking_requests, p->CID );
  20763. // Only party leaders can reply
  20764. if( !party_isleader( sd ) ){
  20765. return;
  20766. }
  20767. if( p->accept ){
  20768. party_join( tsd, sd->status.party_id );
  20769. }
  20770. clif_partybooking_reply( tsd, sd, p->accept );
  20771. #endif
  20772. }
  20773. void clif_parse_reset_skill( int fd, map_session_data* sd ){
  20774. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220203
  20775. PACKET_CZ_RESET_SKILL* p = (PACKET_CZ_RESET_SKILL*)RFIFOP( fd, 0 );
  20776. #endif
  20777. }
  20778. void clif_set_dialog_align(map_session_data& sd, int npcid, e_say_dialog_align align)
  20779. {
  20780. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20781. PACKET_ZC_DIALOG_TEXT_ALIGN p = {};
  20782. p.PacketType = HEADER_ZC_DIALOG_TEXT_ALIGN;
  20783. p.align = align;
  20784. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20785. #endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20786. }
  20787. void clif_set_npc_window_size(map_session_data& sd, int width, int height)
  20788. {
  20789. #if PACKETVER_MAIN_NUM >= 20220504
  20790. PACKET_ZC_DIALOG_WINDOW_SIZE p = {};
  20791. p.PacketType = HEADER_ZC_DIALOG_WINDOW_SIZE;
  20792. p.width = width;
  20793. p.height = height;
  20794. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20795. #endif // PACKETVER_MAIN_NUM >= 20220504
  20796. }
  20797. void clif_set_npc_window_pos(map_session_data& sd, int x, int y)
  20798. {
  20799. #if PACKETVER_MAIN_NUM >= 20220504
  20800. PACKET_ZC_DIALOG_WINDOW_POS p = {};
  20801. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS;
  20802. p.x = x;
  20803. p.y = y;
  20804. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20805. #endif // PACKETVER_MAIN_NUM >= 20220504
  20806. }
  20807. void clif_set_npc_window_pos_percent(map_session_data& sd, int x, int y)
  20808. {
  20809. #if PACKETVER_MAIN_NUM >= 20220504
  20810. PACKET_ZC_DIALOG_WINDOW_POS2 p = {};
  20811. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS2;
  20812. p.x = x;
  20813. p.y = y;
  20814. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20815. #endif // PACKETVER_MAIN_NUM >= 20220504
  20816. }
  20817. /*==========================================
  20818. * Main client packet processing function
  20819. *------------------------------------------*/
  20820. static int clif_parse(int fd)
  20821. {
  20822. int cmd, packet_len;
  20823. TBL_PC* sd;
  20824. int pnum;
  20825. #ifdef PACKET_OBFUSCATION
  20826. int cmd2;
  20827. #endif
  20828. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20829. // Note: "click masters" can do 80+ clicks in 10 seconds
  20830. 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]
  20831. { // begin main client packet processing loop
  20832. sd = (TBL_PC *)session[fd]->session_data;
  20833. if (session[fd]->flag.eof) {
  20834. if (sd) {
  20835. if (sd->state.autotrade) {
  20836. //Disassociate character from the socket connection.
  20837. session[fd]->session_data = NULL;
  20838. sd->fd = 0;
  20839. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20840. } else
  20841. if (sd->state.active) {
  20842. // Player logout display [Valaris]
  20843. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20844. clif_quitsave(fd, sd);
  20845. } else {
  20846. //Unusual logout (during log on/off/map-changer procedure)
  20847. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20848. map_quit(sd);
  20849. }
  20850. } else {
  20851. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20852. }
  20853. do_close(fd);
  20854. return 0;
  20855. }
  20856. if (RFIFOREST(fd) < 2)
  20857. return 0;
  20858. cmd = RFIFOW(fd, 0);
  20859. #ifdef PACKET_OBFUSCATION
  20860. // Check if it is a player that tries to connect to the map server.
  20861. if( sd ){
  20862. // Decrypt the current packet ID with the last key stored in the session.
  20863. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20864. }else{
  20865. // Store the original value for checking
  20866. cmd2 = cmd;
  20867. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20868. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20869. }
  20870. #endif
  20871. // filter out invalid / unsupported packets
  20872. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20873. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20874. #ifdef DUMP_INVALID_PACKET
  20875. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20876. #endif
  20877. #ifdef PACKET_OBFUSCATION_WARN
  20878. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20879. if( !sd ){
  20880. #ifdef PACKET_OBFUSCATION
  20881. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20882. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20883. }
  20884. #else
  20885. // Try to use the initial keys for the decryption of the packet ID.
  20886. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20887. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20888. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20889. }
  20890. #endif
  20891. }
  20892. #endif
  20893. set_eof(fd);
  20894. return 0;
  20895. }
  20896. // determine real packet length
  20897. packet_len = packet_db[cmd].len;
  20898. if (packet_len == -1) { // variable-length packet
  20899. if (RFIFOREST(fd) < 4)
  20900. return 0;
  20901. packet_len = RFIFOW(fd,2);
  20902. if (packet_len < 4 || packet_len > 32768) {
  20903. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20904. #ifdef DUMP_INVALID_PACKET
  20905. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20906. #endif
  20907. set_eof(fd);
  20908. return 0;
  20909. }
  20910. }
  20911. if ((int)RFIFOREST(fd) < packet_len){
  20912. 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 );
  20913. #ifdef DUMP_INVALID_PACKET
  20914. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20915. #endif
  20916. set_eof( fd );
  20917. return 0; // not enough data received to form the packet
  20918. }
  20919. #ifdef PACKET_OBFUSCATION
  20920. RFIFOW(fd, 0) = cmd;
  20921. if (sd)
  20922. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20923. #endif
  20924. if( packet_db[cmd].func == clif_parse_debug )
  20925. packet_db[cmd].func(fd, sd);
  20926. else if( packet_db[cmd].func != NULL ) {
  20927. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20928. ; //Only valid packet when there is no session
  20929. else
  20930. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20931. ; //Only valid packet when player is not on a map
  20932. else
  20933. packet_db[cmd].func(fd, sd);
  20934. }
  20935. #ifdef DUMP_UNKNOWN_PACKET
  20936. else DumpUnknown(fd,sd,cmd,packet_len);
  20937. #endif
  20938. RFIFOSKIP(fd, packet_len);
  20939. }; // main loop end
  20940. return 0;
  20941. }
  20942. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, map_session_data *), ... ){
  20943. va_list argp;
  20944. int i;
  20945. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20946. return;
  20947. packet_db[cmd].len = length;
  20948. packet_db[cmd].func = func;
  20949. va_start(argp, func);
  20950. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20951. int offset = va_arg(argp, int);
  20952. if( offset == 0 ){
  20953. break;
  20954. }
  20955. packet_db[cmd].pos[i] = offset;
  20956. }
  20957. if( i == MAX_PACKET_POS ){
  20958. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20959. }
  20960. va_end(argp);
  20961. }
  20962. /*==========================================
  20963. * Reads packets and setups its array reference
  20964. *------------------------------------------*/
  20965. void packetdb_readdb(){
  20966. memset(packet_db,0,sizeof(packet_db));
  20967. #include "clif_packetdb.hpp"
  20968. #include "clif_shuffle.hpp"
  20969. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20970. #ifdef PACKET_OBFUSCATION
  20971. 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]);
  20972. #else
  20973. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20974. #endif
  20975. }
  20976. /*==========================================
  20977. *
  20978. *------------------------------------------*/
  20979. void do_init_clif(void) {
  20980. const int colors[COLOR_MAX] = {
  20981. 0x00FF00, // COLOR_DEFAULT
  20982. 0xFF0000, // COLOR_RED
  20983. 0xFFFFFF, // COLOR_WHITE
  20984. 0xFFFF00, // COLOR_YELLOW
  20985. 0x00FFFF, // COLOR_CYAN
  20986. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20987. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20988. };
  20989. /**
  20990. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20991. **/
  20992. for( int i = 0; i < COLOR_MAX; i++ ){
  20993. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20994. }
  20995. packetdb_readdb();
  20996. set_defaultparse(clif_parse);
  20997. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20998. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20999. exit(EXIT_FAILURE);
  21000. }
  21001. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  21002. add_timer_func_list(clif_delayquit, "clif_delayquit");
  21003. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  21004. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  21005. if( battle_config.ping_timer_interval > 0 ){
  21006. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  21007. }
  21008. #endif
  21009. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  21010. }
  21011. void do_final_clif(void) {
  21012. ers_destroy(delay_clearunit_ers);
  21013. }