clif.cpp 728 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // Copyright (c) Hercules Dev Team - Licensed under GNU GPL
  3. // For more information, see LICENCE in the main folder
  4. #include "clif.hpp"
  5. #include <unordered_set>
  6. #include <cstdarg>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <ctime>
  11. #include <common/cbasetypes.hpp>
  12. #include <common/conf.hpp>
  13. #include <common/ers.hpp>
  14. #include <common/grfio.hpp>
  15. #include <common/malloc.hpp>
  16. #include <common/nullpo.hpp>
  17. #include <common/random.hpp>
  18. #include <common/showmsg.hpp>
  19. #include <common/socket.hpp>
  20. #include <common/strlib.hpp>
  21. #include <common/timer.hpp>
  22. #include <common/utilities.hpp>
  23. #include <common/utils.hpp>
  24. #include "achievement.hpp"
  25. #include "atcommand.hpp"
  26. #include "battle.hpp"
  27. #include "battleground.hpp"
  28. #include "cashshop.hpp"
  29. #include "channel.hpp"
  30. #include "chat.hpp"
  31. #include "chrif.hpp"
  32. #include "clan.hpp"
  33. #include "clif.hpp"
  34. #include "elemental.hpp"
  35. #include "guild.hpp"
  36. #include "homunculus.hpp"
  37. #include "instance.hpp"
  38. #include "intif.hpp"
  39. #include "itemdb.hpp"
  40. #include "log.hpp"
  41. #include "mail.hpp"
  42. #include "map.hpp"
  43. #include "mercenary.hpp"
  44. #include "mob.hpp"
  45. #include "npc.hpp"
  46. #include "party.hpp"
  47. #include "pc.hpp"
  48. #include "pc_groups.hpp"
  49. #include "pet.hpp"
  50. #include "quest.hpp"
  51. #include "script.hpp"
  52. #include "skill.hpp"
  53. #include "status.hpp"
  54. #include "storage.hpp"
  55. #include "trade.hpp"
  56. #include "unit.hpp"
  57. #include "vending.hpp"
  58. using namespace rathena;
  59. static inline uint32 client_tick( t_tick tick ){
  60. return (uint32)tick;
  61. }
  62. #if PACKETVER >= 20170830
  63. static inline int64 client_exp(t_exp exp) {
  64. return (int64)u64min(exp, MAX_EXP);
  65. }
  66. #else
  67. static inline int32 client_exp(t_exp exp) {
  68. return (int32)u64min(exp, MAX_EXP);
  69. }
  70. #endif
  71. /* for clif_clearunit_delayed */
  72. static struct eri *delay_clearunit_ers;
  73. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  74. unsigned long color_table[COLOR_MAX];
  75. #include "clif_obfuscation.hpp"
  76. static bool clif_session_isValid(map_session_data *sd);
  77. static void clif_loadConfirm( map_session_data *sd );
  78. #if PACKETVER >= 20150513
  79. enum mail_type {
  80. MAIL_TYPE_TEXT = 0x0,
  81. MAIL_TYPE_ZENY = 0x2,
  82. MAIL_TYPE_ITEM = 0x4,
  83. MAIL_TYPE_NPC = 0x8
  84. };
  85. #endif
  86. enum e_inventory_type{
  87. INVTYPE_INVENTORY = 0,
  88. INVTYPE_CART = 1,
  89. INVTYPE_STORAGE = 2,
  90. INVTYPE_GUILD_STORAGE = 3,
  91. };
  92. /** Converts item type to display it on client if necessary.
  93. * @param nameid: Item ID
  94. * @return item type. For IT_PETEGG will be displayed as IT_ARMOR. If Shadow Weapon of IT_SHADOWGEAR as IT_WEAPON and else as IT_ARMOR
  95. */
  96. static inline int itemtype(t_itemid nameid) {
  97. struct item_data* id = itemdb_search(nameid); //Use itemdb_search, so non-existance item will use dummy data and won't crash the server. bugreport:8468
  98. int type = id->type;
  99. if( type == IT_SHADOWGEAR ) {
  100. if( id->equip&EQP_SHADOW_WEAPON )
  101. return IT_WEAPON;
  102. else
  103. return IT_ARMOR;
  104. }
  105. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  106. }
  107. // TODO: doc
  108. static inline uint16 client_index( uint16 server_index ){
  109. return server_index + 2;
  110. }
  111. static inline uint16 server_index( uint16 client_index ){
  112. return client_index - 2;
  113. }
  114. static inline uint16 client_storage_index( uint16 server_index ){
  115. return server_index + 1;
  116. }
  117. static inline uint16 server_storage_index( uint16 client_index ){
  118. return client_index - 1;
  119. }
  120. static inline uint32 disguised_bl_id( uint32 bl_id ){
  121. // Casting to prevent a compiler warning
  122. return -((int32)bl_id);
  123. }
  124. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  125. static inline uint32 client_nameid( t_itemid server_nameid ){
  126. t_itemid view = itemdb_viewid( server_nameid );
  127. if( view > 0 ){
  128. return view;
  129. }else{
  130. return server_nameid;
  131. }
  132. }
  133. #else
  134. static inline uint16 client_nameid( t_itemid server_nameid ){
  135. t_itemid view = itemdb_viewid( server_nameid );
  136. if( view > 0 ){
  137. if( view > UINT16_MAX ){
  138. return (uint16)UNKNOWN_ITEM_ID;
  139. }
  140. return (uint16)view;
  141. }else{
  142. if( server_nameid > UINT16_MAX ){
  143. return (uint16)UNKNOWN_ITEM_ID;
  144. }
  145. return (uint16)server_nameid;
  146. }
  147. }
  148. #endif
  149. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  150. p += pos;
  151. p[0] = (uint8)(x>>2);
  152. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  153. p[2] = (uint8)((y<<4) | (dir&0xf));
  154. }
  155. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  156. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  157. p += pos;
  158. p[0] = (uint8)(x0>>2);
  159. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  160. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  161. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  162. p[4] = (uint8)y1;
  163. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  164. }
  165. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  166. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  167. }
  168. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  169. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  170. }
  171. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  172. p += pos;
  173. if( x ) {
  174. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  175. }
  176. if( y ) {
  177. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  178. }
  179. if( dir ) {
  180. dir[0] = ( p[2] & 0x0f );
  181. }
  182. }
  183. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  184. p += pos;
  185. if( x0 ) {
  186. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  187. }
  188. if( y0 ) {
  189. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  190. }
  191. if( x1 ) {
  192. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  193. }
  194. if( y1 ) {
  195. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  196. }
  197. if( sx0 ) {
  198. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  199. }
  200. if( sy0 ) {
  201. sy0[0] = ( p[5] & 0x0f ) >> 0;
  202. }
  203. }
  204. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  205. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  206. }
  207. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  208. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  209. }
  210. //To idenfity disguised characters.
  211. static inline bool disguised(struct block_list* bl) {
  212. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  213. }
  214. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  215. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  216. if( len > max )
  217. len = max;
  218. mes[len-1] = '\0';
  219. return len;
  220. }
  221. static char map_ip_str[128];
  222. static uint32 map_ip;
  223. static uint32 bind_ip = INADDR_ANY;
  224. static uint16 map_port = 5121;
  225. static bool clif_ally_only = false;
  226. int map_fd;
  227. static int clif_parse (int fd);
  228. /*==========================================
  229. * Ip setting of map-server
  230. *------------------------------------------*/
  231. int clif_setip(const char* ip) {
  232. char ip_str[16];
  233. map_ip = host2ip(ip);
  234. if (!map_ip) {
  235. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  236. return 0;
  237. }
  238. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  239. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  240. return 1;
  241. }
  242. void clif_setbindip(const char* ip)
  243. {
  244. bind_ip = host2ip(ip);
  245. if (bind_ip) {
  246. char ip_str[16];
  247. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  248. } else {
  249. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  250. }
  251. }
  252. /*==========================================
  253. * Sets map port to 'port'
  254. * is run from map.cpp upon loading map server configuration
  255. *------------------------------------------*/
  256. void clif_setport(uint16 port)
  257. {
  258. map_port = port;
  259. }
  260. /*==========================================
  261. * Returns map server IP
  262. *------------------------------------------*/
  263. uint32 clif_getip(void)
  264. {
  265. return map_ip;
  266. }
  267. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  268. uint32 clif_refresh_ip(void)
  269. {
  270. uint32 new_ip;
  271. new_ip = host2ip(map_ip_str);
  272. if (new_ip && new_ip != map_ip) {
  273. map_ip = new_ip;
  274. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  275. return map_ip;
  276. }
  277. return 0;
  278. }
  279. /*==========================================
  280. * Returns map port which is set by clif_setport()
  281. *------------------------------------------*/
  282. uint16 clif_getport(void)
  283. {
  284. return map_port;
  285. }
  286. #if PACKETVER >= 20071106
  287. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  288. switch (bl->type) {
  289. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  290. case BL_ITEM: return 0x2; //ITEM_TYPE
  291. case BL_SKILL: return 0x3; //SKILL_TYPE
  292. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  293. case BL_MOB:
  294. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  295. return 0x0; //PC_TYPE
  296. }else{
  297. switch( ( (mob_data*)bl )->special_state.ai ){
  298. case AI_ABR:
  299. return 0xd; //NPC_ABR_TYPE
  300. case AI_BIONIC:
  301. return 0xe; //NPC_BIONIC_TYPE
  302. default:
  303. return 0x5; //NPC_MOB_TYPE
  304. }
  305. }
  306. case BL_NPC:
  307. // From 2017-07-26 on NPC type units can also use player sprites.
  308. // There is one exception and this is if they are walking.
  309. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  310. #if PACKETVER >= 20170726
  311. if (pcdb_checkid( status_get_viewdata( bl )->class_ ) && walking)
  312. return 0x0;
  313. else if (mobdb_checkid( status_get_viewdata( bl )->class_ )) // FIXME: categorize NPCs able to walk
  314. return 0xC;
  315. else
  316. return 0x6;
  317. #else
  318. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  319. #endif
  320. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  321. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  322. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  323. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  324. default: return 0x1; //NPC_TYPE
  325. }
  326. }
  327. #endif
  328. static bool clif_session_isValid(map_session_data *sd) {
  329. return ( sd != nullptr && session_isActive(sd->fd) );
  330. }
  331. /*==========================================
  332. * sub process of clif_send
  333. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  334. * In order to send area-wise packets, such as:
  335. * - AREA : everyone nearby your area
  336. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  337. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  338. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  339. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  340. *------------------------------------------*/
  341. static int clif_send_sub(struct block_list *bl, va_list ap)
  342. {
  343. struct block_list *src_bl;
  344. map_session_data *sd;
  345. unsigned char *buf;
  346. int len, type, fd;
  347. nullpo_ret(bl);
  348. nullpo_ret(sd = (map_session_data *)bl);
  349. // Don't send to disconnected clients.
  350. if( !session_isActive( fd = sd->fd ) ){
  351. return 0;
  352. }
  353. buf = va_arg(ap,unsigned char*);
  354. len = va_arg(ap,int);
  355. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  356. type = va_arg(ap,int);
  357. switch(type) {
  358. case AREA_WOS:
  359. if (bl == src_bl)
  360. return 0;
  361. break;
  362. case AREA_WOC:
  363. if (sd->chatID || bl == src_bl)
  364. return 0;
  365. break;
  366. case AREA_WOSC:
  367. {
  368. if(src_bl->type == BL_PC) {
  369. map_session_data *ssd = (map_session_data *)src_bl;
  370. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  371. return 0;
  372. }
  373. else if(src_bl->type == BL_NPC) {
  374. struct npc_data *nd = (struct npc_data *)src_bl;
  375. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  376. return 0;
  377. }
  378. }
  379. break;
  380. }
  381. if( src_bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)src_bl ), *sd ) ){
  382. // Do not send anything
  383. return 0;
  384. }
  385. /* unless visible, hold it here */
  386. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  387. !sd->sc.getSCE(SC_INTRAVISION) && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  388. return 0;
  389. WFIFOHEAD(fd, len);
  390. if (WFIFOP(fd,0) == buf) {
  391. ShowError("WARNING: Invalid use of clif_send function\n");
  392. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  393. ShowError(" Please correct your code.\n");
  394. // don't send to not move the pointer of the packet for next sessions in the loop
  395. //WFIFOSET(fd,0);//## TODO is this ok?
  396. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  397. return 0;
  398. }
  399. memcpy(WFIFOP(fd,0), buf, len);
  400. WFIFOSET(fd,len);
  401. return 0;
  402. }
  403. /*==========================================
  404. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  405. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  406. *------------------------------------------*/
  407. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  408. {
  409. int i;
  410. map_session_data *sd, *tsd;
  411. struct party_data *p = NULL;
  412. std::shared_ptr<s_battleground_data> bg;
  413. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  414. struct s_mapiterator* iter;
  415. if( type != ALL_CLIENT )
  416. nullpo_ret(bl);
  417. sd = BL_CAST(BL_PC, bl);
  418. switch(type) {
  419. case ALL_CLIENT: //All player clients.
  420. iter = mapit_getallusers();
  421. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  422. if( session_isActive( fd = tsd->fd ) ){
  423. WFIFOHEAD( fd, len );
  424. memcpy( WFIFOP( fd, 0 ), buf, len );
  425. WFIFOSET( fd, len );
  426. }
  427. }
  428. mapit_free(iter);
  429. break;
  430. case ALL_SAMEMAP: //All players on the same map
  431. iter = mapit_getallusers();
  432. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  433. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  434. WFIFOHEAD( fd, len );
  435. memcpy( WFIFOP( fd, 0 ), buf, len );
  436. WFIFOSET( fd, len );
  437. }
  438. }
  439. mapit_free(iter);
  440. break;
  441. case AREA:
  442. case AREA_WOSC:
  443. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  444. clif_send (buf, len, bl, SELF);
  445. [[fallthrough]];
  446. case AREA_WOC:
  447. case AREA_WOS:
  448. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  449. BL_PC, buf, len, bl, type);
  450. break;
  451. case AREA_CHAT_WOC:
  452. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  453. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  454. break;
  455. case CHAT:
  456. case CHAT_WOS:
  457. {
  458. struct chat_data *cd;
  459. if (sd) {
  460. cd = (struct chat_data*)map_id2bl(sd->chatID);
  461. } else if (bl->type == BL_CHAT) {
  462. cd = (struct chat_data*)bl;
  463. } else break;
  464. if (cd == NULL)
  465. break;
  466. for(i = 0; i < cd->users; i++) {
  467. if (type == CHAT_WOS && cd->usersd[i] == sd)
  468. continue;
  469. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  470. WFIFOHEAD(fd,len);
  471. memcpy(WFIFOP(fd,0), buf, len);
  472. WFIFOSET(fd,len);
  473. }
  474. }
  475. }
  476. break;
  477. case PARTY_AREA:
  478. case PARTY_AREA_WOS:
  479. x0 = bl->x - AREA_SIZE;
  480. y0 = bl->y - AREA_SIZE;
  481. x1 = bl->x + AREA_SIZE;
  482. y1 = bl->y + AREA_SIZE;
  483. [[fallthrough]];
  484. case PARTY:
  485. case PARTY_WOS:
  486. case PARTY_SAMEMAP:
  487. case PARTY_SAMEMAP_WOS:
  488. if (sd && sd->status.party_id)
  489. p = party_search(sd->status.party_id);
  490. if (p) {
  491. for(i=0;i<MAX_PARTY;i++){
  492. if( (sd = p->data[i].sd) == NULL )
  493. continue;
  494. if( !session_isActive( fd = sd->fd ) )
  495. continue;
  496. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  497. continue;
  498. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  499. continue;
  500. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  501. continue;
  502. WFIFOHEAD(fd, len);
  503. memcpy(WFIFOP(fd, 0), buf, len);
  504. WFIFOSET(fd, len);
  505. }
  506. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  507. break;
  508. iter = mapit_getallusers();
  509. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  510. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  511. WFIFOHEAD( fd, len );
  512. memcpy( WFIFOP( fd, 0 ), buf, len );
  513. WFIFOSET( tsd->fd, len );
  514. }
  515. }
  516. mapit_free(iter);
  517. }
  518. break;
  519. case DUEL:
  520. case DUEL_WOS:
  521. if (!sd || !sd->duel_group) break; //Invalid usage.
  522. iter = mapit_getallusers();
  523. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  524. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  525. continue;
  526. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  527. WFIFOHEAD( fd, len );
  528. memcpy( WFIFOP( fd, 0 ), buf, len );
  529. WFIFOSET( fd, len );
  530. }
  531. }
  532. mapit_free(iter);
  533. break;
  534. case SELF:
  535. if( clif_session_isValid(sd) ){
  536. fd = sd->fd;
  537. WFIFOHEAD(fd,len);
  538. memcpy(WFIFOP(fd,0), buf, len);
  539. WFIFOSET(fd,len);
  540. }
  541. break;
  542. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  543. case GUILD_AREA:
  544. case GUILD_AREA_WOS:
  545. x0 = bl->x - AREA_SIZE;
  546. y0 = bl->y - AREA_SIZE;
  547. x1 = bl->x + AREA_SIZE;
  548. y1 = bl->y + AREA_SIZE;
  549. [[fallthrough]];
  550. case GUILD_SAMEMAP:
  551. case GUILD_SAMEMAP_WOS:
  552. case GUILD:
  553. case GUILD_WOS:
  554. case GUILD_NOBG: {
  555. if (!sd || !sd->status.guild_id || !sd->guild)
  556. break;
  557. const auto &g = sd->guild->guild;
  558. for(i = 0; i < g.max_member; i++) {
  559. if( (sd = g.member[i].sd) != nullptr ){
  560. if( !session_isActive( fd = sd->fd ) )
  561. continue;
  562. if( type == GUILD_NOBG && sd->bg_id )
  563. continue;
  564. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  565. continue;
  566. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  567. continue;
  568. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  569. continue;
  570. WFIFOHEAD(fd,len);
  571. memcpy(WFIFOP(fd,0), buf, len);
  572. WFIFOSET(fd,len);
  573. }
  574. }
  575. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  576. break;
  577. iter = mapit_getallusers();
  578. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  579. if( tsd->guildspy == g.guild_id && session_isActive( fd = tsd->fd ) ){
  580. WFIFOHEAD( fd, len );
  581. memcpy( WFIFOP( fd, 0 ), buf, len );
  582. WFIFOSET( fd, len );
  583. }
  584. }
  585. mapit_free(iter);
  586. break;
  587. }
  588. case BG_AREA:
  589. case BG_AREA_WOS:
  590. x0 = bl->x - AREA_SIZE;
  591. y0 = bl->y - AREA_SIZE;
  592. x1 = bl->x + AREA_SIZE;
  593. y1 = bl->y + AREA_SIZE;
  594. [[fallthrough]];
  595. case BG_SAMEMAP:
  596. case BG_SAMEMAP_WOS:
  597. case BG:
  598. case BG_WOS:
  599. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  600. {
  601. for (const auto &member : bg->members) {
  602. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  603. continue;
  604. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  605. continue;
  606. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  607. continue;
  608. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  609. continue;
  610. WFIFOHEAD(fd,len);
  611. memcpy(WFIFOP(fd,0), buf, len);
  612. WFIFOSET(fd,len);
  613. }
  614. }
  615. break;
  616. case CLAN:
  617. if( sd && sd->clan ){
  618. struct clan* clan = sd->clan;
  619. for( i = 0; i < clan->max_member; i++ ){
  620. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  621. continue;
  622. }
  623. WFIFOHEAD(fd,len);
  624. memcpy(WFIFOP(fd,0), buf, len);
  625. WFIFOSET(fd,len);
  626. }
  627. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  628. break;
  629. iter = mapit_getallusers();
  630. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  631. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  632. WFIFOHEAD(fd, len);
  633. memcpy(WFIFOP(fd, 0), buf, len);
  634. WFIFOSET(fd, len);
  635. }
  636. }
  637. mapit_free(iter);
  638. }
  639. break;
  640. default:
  641. ShowError("clif_send: Unrecognized type %d\n",type);
  642. return -1;
  643. }
  644. return 0;
  645. }
  646. /// Notifies the client, that it's connection attempt was accepted.
  647. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  648. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  649. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  650. void clif_authok(map_session_data *sd)
  651. {
  652. #if PACKETVER < 20080102
  653. const int cmd = 0x73;
  654. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  655. const int cmd = 0x2eb;
  656. #else
  657. const int cmd = 0xa18;
  658. #endif
  659. int fd = sd->fd;
  660. WFIFOHEAD(fd,packet_len(cmd));
  661. WFIFOW(fd, 0) = cmd;
  662. WFIFOL(fd, 2) = client_tick(gettick());
  663. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  664. WFIFOB(fd, 9) = 5; // ignored
  665. WFIFOB(fd,10) = 5; // ignored
  666. #if PACKETVER >= 20080102
  667. WFIFOW(fd,11) = sd->status.font;
  668. #endif
  669. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  670. WFIFOB(fd,13) = sd->status.sex;
  671. #endif
  672. WFIFOSET(fd,packet_len(cmd));
  673. }
  674. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  675. /// 0074 <error code>.B
  676. /// error code:
  677. /// 0 = client type mismatch
  678. /// 1 = ID mismatch
  679. /// 2 = mobile - out of available time
  680. /// 3 = mobile - already logged in
  681. /// 4 = mobile - waiting state
  682. void clif_authrefuse(int fd, uint8 error_code)
  683. {
  684. WFIFOHEAD(fd,packet_len(0x74));
  685. WFIFOW(fd,0) = 0x74;
  686. WFIFOB(fd,2) = error_code;
  687. WFIFOSET(fd,packet_len(0x74));
  688. }
  689. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  690. /// 0081 <error code>.B
  691. /// error code:
  692. /// 0 = BAN_UNFAIR
  693. /// 1 = server closed -> MsgStringTable[4]
  694. /// 2 = ID already logged in -> MsgStringTable[5]
  695. /// 3 = timeout/too much lag -> MsgStringTable[241]
  696. /// 4 = server full -> MsgStringTable[264]
  697. /// 5 = underaged -> MsgStringTable[305]
  698. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  699. /// 9 = too many connections from this ip -> MsgStringTable[529]
  700. /// 10 = out of available time paid for -> MsgStringTable[530]
  701. /// 11 = BAN_PAY_SUSPEND
  702. /// 12 = BAN_PAY_CHANGE
  703. /// 13 = BAN_PAY_WRONGIP
  704. /// 14 = BAN_PAY_PNGAMEROOM
  705. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  706. /// 16 = BAN_JAPAN_REFUSE1
  707. /// 17 = BAN_JAPAN_REFUSE2
  708. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  709. /// 100 = BAN_PC_IP_UNFAIR
  710. /// 101 = BAN_PC_IP_COUNT_ALL
  711. /// 102 = BAN_PC_IP_COUNT
  712. /// 103 = BAN_GRAVITY_MEM_AGREE
  713. /// 104 = BAN_GAME_MEM_AGREE
  714. /// 105 = BAN_HAN_VALID
  715. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  716. /// 107 = BAN_OVER_CHARACTER_LIST
  717. /// 108 = BAN_IP_BLOCK
  718. /// 109 = BAN_INVALID_PWD_CNT
  719. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  720. /// ? = disconnected -> MsgStringTable[3]
  721. void clif_authfail_fd(int fd, int type)
  722. {
  723. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  724. return;
  725. WFIFOHEAD(fd, packet_len(0x81));
  726. WFIFOW(fd,0) = 0x81;
  727. WFIFOB(fd,2) = type;
  728. WFIFOSET(fd,packet_len(0x81));
  729. set_eof(fd);
  730. }
  731. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  732. /// 00b3 <type>.B
  733. /// type:
  734. /// 1 = disconnect, char-select
  735. /// ? = nothing
  736. void clif_charselectok(int id, uint8 ok)
  737. {
  738. map_session_data* sd;
  739. int fd;
  740. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  741. return;
  742. fd = sd->fd;
  743. WFIFOHEAD(fd,packet_len(0xb3));
  744. WFIFOW(fd,0) = 0xb3;
  745. WFIFOB(fd,2) = ok;
  746. WFIFOSET(fd,packet_len(0xb3));
  747. }
  748. /// Makes an item appear on the ground.
  749. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  750. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  751. /// 0ADD <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W <show drop effect>.B <drop effect mode>.W (ZC_ITEM_FALL_ENTRY5)
  752. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  753. nullpo_retv(fitem);
  754. if( fitem->item.nameid == 0 ){
  755. return;
  756. }
  757. struct packet_dropflooritem p;
  758. p.PacketType = dropflooritemType;
  759. p.ITAID = fitem->bl.id;
  760. p.ITID = client_nameid( fitem->item.nameid );
  761. #if PACKETVER >= 20130000 /* not sure date */
  762. p.type = itemtype( fitem->item.nameid );
  763. #endif
  764. p.IsIdentified = fitem->item.identify ? 1 : 0;
  765. p.xPos = fitem->bl.x;
  766. p.yPos = fitem->bl.y;
  767. p.subX = fitem->subx;
  768. p.subY = fitem->suby;
  769. p.count = fitem->item.amount;
  770. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  771. if( canShowEffect ){
  772. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  773. if( dropEffect > 0 ){
  774. p.showdropeffect = 1;
  775. p.dropeffectmode = dropEffect - 1;
  776. }else if (battle_config.rndopt_drop_pillar != 0){
  777. uint8 optionCount = 0;
  778. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  779. if (fitem->item.option[i].id != 0) {
  780. optionCount++;
  781. }
  782. }
  783. if (optionCount > 0) {
  784. p.showdropeffect = 1;
  785. if (optionCount == 1)
  786. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  787. else if (optionCount == 2)
  788. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  789. else
  790. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  791. } else {
  792. p.showdropeffect = 0;
  793. p.dropeffectmode = DROPEFFECT_NONE;
  794. }
  795. } else {
  796. p.showdropeffect = 0;
  797. p.dropeffectmode = DROPEFFECT_NONE;
  798. }
  799. }else{
  800. p.showdropeffect = 0;
  801. p.dropeffectmode = DROPEFFECT_NONE;
  802. }
  803. #endif
  804. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  805. }
  806. /// Makes an item disappear from the ground.
  807. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  808. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  809. {
  810. unsigned char buf[16];
  811. nullpo_retv(fitem);
  812. WBUFW(buf,0) = 0xa1;
  813. WBUFL(buf,2) = fitem->bl.id;
  814. if ( !session_isActive( fd ) ){
  815. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  816. } else {
  817. WFIFOHEAD(fd,packet_len(0xa1));
  818. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  819. WFIFOSET(fd,packet_len(0xa1));
  820. }
  821. }
  822. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  823. /// 0080 <id>.L <type>.B
  824. /// type:
  825. /// 0 = out of sight
  826. /// 1 = died
  827. /// 2 = logged out
  828. /// 3 = teleport
  829. /// 4 = trickdead
  830. void clif_clearunit_single(int id, clr_type type, int fd)
  831. {
  832. WFIFOHEAD(fd, packet_len(0x80));
  833. WFIFOW(fd,0) = 0x80;
  834. WFIFOL(fd,2) = id;
  835. WFIFOB(fd,6) = type;
  836. WFIFOSET(fd, packet_len(0x80));
  837. }
  838. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  839. /// 0080 <id>.L <type>.B
  840. /// type:
  841. /// 0 = out of sight
  842. /// 1 = died
  843. /// 2 = logged out
  844. /// 3 = teleport
  845. /// 4 = trickdead
  846. void clif_clearunit_area(struct block_list* bl, clr_type type)
  847. {
  848. unsigned char buf[8];
  849. nullpo_retv(bl);
  850. WBUFW(buf,0) = 0x80;
  851. WBUFL(buf,2) = bl->id;
  852. WBUFB(buf,6) = type;
  853. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  854. if(disguised(bl)) {
  855. WBUFL(buf,2) = disguised_bl_id( bl->id );
  856. clif_send(buf, packet_len(0x80), bl, SELF);
  857. }
  858. }
  859. /// Used to make monsters with player-sprites disappear after dying
  860. /// like normal monsters, because the client does not remove those
  861. /// automatically.
  862. static TIMER_FUNC(clif_clearunit_delayed_sub){
  863. struct block_list *bl = (struct block_list *)data;
  864. clif_clearunit_area(bl, (clr_type) id);
  865. ers_free(delay_clearunit_ers,bl);
  866. return 0;
  867. }
  868. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  869. {
  870. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  871. tbl->next = nullptr;
  872. tbl->prev = nullptr;
  873. tbl->id = bl->id;
  874. tbl->m = bl->m;
  875. tbl->x = bl->x;
  876. tbl->y = bl->y;
  877. tbl->type = BL_NUL;
  878. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  879. }
  880. void clif_get_weapon_view(map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  881. {
  882. if(sd->sc.option&OPTION_COSTUME)
  883. {
  884. *rhand = *lhand = 0;
  885. return;
  886. }
  887. #if PACKETVER < 4
  888. *rhand = sd->status.weapon;
  889. *lhand = sd->status.shield;
  890. #else
  891. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  892. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  893. {
  894. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  895. if (id->view_id > 0)
  896. *rhand = id->view_id;
  897. else
  898. *rhand = id->nameid;
  899. } else
  900. *rhand = 0;
  901. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  902. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  903. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  904. {
  905. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  906. if (id->view_id > 0)
  907. *lhand = id->view_id;
  908. else
  909. *lhand = id->nameid;
  910. } else
  911. *lhand = 0;
  912. #endif
  913. }
  914. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  915. static int clif_setlevel_sub(int lv) {
  916. if( lv < battle_config.max_lv ) {
  917. ;
  918. } else if( lv < battle_config.aura_lv ) {
  919. lv = battle_config.max_lv - 1;
  920. } else {
  921. lv = battle_config.max_lv;
  922. }
  923. return lv;
  924. }
  925. static int clif_setlevel(struct block_list* bl) {
  926. int lv = status_get_lv(bl);
  927. if( battle_config.client_limit_unit_lv&bl->type )
  928. return clif_setlevel_sub(lv);
  929. switch( bl->type ) {
  930. case BL_NPC:
  931. case BL_PET:
  932. // npcs and pets do not have level
  933. return 0;
  934. }
  935. return lv;
  936. }
  937. /*==========================================
  938. * Prepares 'unit standing/spawning' packet
  939. *------------------------------------------*/
  940. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  941. nullpo_retv( bl );
  942. map_session_data* sd = BL_CAST( BL_PC, bl );
  943. status_change* sc = status_get_sc( bl );
  944. struct view_data* vd = status_get_viewdata( bl );
  945. int g_id = status_get_guild_id( bl );
  946. #if PACKETVER < 20091103
  947. if( !pcdb_checkid( vd->class_ ) ){
  948. struct packet_idle_unit2 p;
  949. p.PacketType = idle_unit2Type;
  950. #if PACKETVER >= 20071106
  951. p.objecttype = clif_bl_type( bl, walking );
  952. #endif
  953. p.GID = bl->id;
  954. p.speed = status_get_speed( bl );
  955. p.bodyState = ( sc ) ? sc->opt1 : 0;
  956. p.healthState = ( sc ) ? sc->opt2 : 0;
  957. p.effectState = ( sc ) ? sc->option : 0;
  958. p.job = vd->class_;
  959. p.head = vd->hair_style;
  960. p.weapon = vd->weapon;
  961. p.accessory = vd->head_bottom;
  962. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  963. // The hell, why flags work like this?
  964. p.shield = status_get_emblem_id( bl );
  965. p.accessory2 = GetWord( g_id, 1 );
  966. p.accessory3 = GetWord( g_id, 0 );
  967. }else{
  968. p.shield = vd->shield;
  969. p.accessory2 = vd->head_top;
  970. p.accessory3 = vd->head_mid;
  971. }
  972. p.headpalette = vd->hair_color;
  973. p.bodypalette = vd->cloth_color;
  974. p.headDir = ( sd )? sd->head_dir : 0;
  975. p.GUID = g_id;
  976. p.GEmblemVer = status_get_emblem_id( bl );
  977. p.honor = ( sd ) ? sd->status.manner : 0;
  978. p.virtue = ( sc ) ? sc->opt3 : 0;
  979. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  980. p.sex = vd->sex;
  981. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  982. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  983. p.state = vd->dead_sit;
  984. p.clevel = clif_setlevel( bl );
  985. clif_send( &p, sizeof( p ), tbl, target );
  986. return;
  987. }
  988. #endif
  989. struct packet_idle_unit p;
  990. p.PacketType = idle_unitType;
  991. #if PACKETVER >= 20091103
  992. p.PacketLength = sizeof(p);
  993. p.objecttype = clif_bl_type( bl, walking );
  994. #endif
  995. #if PACKETVER >= 20131223
  996. p.AID = bl->id;
  997. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  998. #else
  999. p.GID = bl->id;
  1000. #endif
  1001. p.speed = status_get_speed(bl);
  1002. p.bodyState = (sc) ? sc->opt1 : 0;
  1003. p.healthState = (sc) ? sc->opt2 : 0;
  1004. // npc option changed?
  1005. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  1006. map_session_data* sd = (map_session_data*)tbl;
  1007. struct npc_data* nd = (struct npc_data*)bl;
  1008. int option = (sc) ? sc->option : 0;
  1009. if( !nd->vd.dead_sit ){
  1010. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  1011. option ^= OPTION_CLOAK;
  1012. }
  1013. }
  1014. p.effectState = option;
  1015. }else{
  1016. p.effectState = (sc) ? sc->option : 0;
  1017. }
  1018. p.job = vd->class_;
  1019. p.head = vd->hair_style;
  1020. p.weapon = vd->weapon;
  1021. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1022. p.shield = vd->shield;
  1023. #endif
  1024. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1025. // The hell, why flags work like this?
  1026. p.accessory = status_get_emblem_id( bl );
  1027. p.accessory2 = GetWord( g_id, 1 );
  1028. p.accessory3 = GetWord( g_id, 0 );
  1029. }else{
  1030. p.accessory = vd->head_bottom;
  1031. p.accessory2 = vd->head_top;
  1032. p.accessory3 = vd->head_mid;
  1033. }
  1034. p.headpalette = vd->hair_color;
  1035. p.bodypalette = vd->cloth_color;
  1036. p.headDir = (sd)? sd->head_dir : 0;
  1037. #if PACKETVER >= 20101124
  1038. p.robe = vd->robe;
  1039. #endif
  1040. p.GUID = g_id;
  1041. p.GEmblemVer = status_get_emblem_id( bl );
  1042. p.honor = (sd) ? sd->status.manner : 0;
  1043. p.virtue = (sc) ? sc->opt3 : 0;
  1044. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1045. p.sex = vd->sex;
  1046. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1047. p.xSize = p.ySize = (sd) ? 5 : 0;
  1048. p.state = vd->dead_sit;
  1049. p.clevel = clif_setlevel( bl );
  1050. #if PACKETVER >= 20080102
  1051. p.font = (sd) ? sd->status.font : 0;
  1052. #endif
  1053. #if PACKETVER >= 20120221
  1054. if( battle_config.monster_hp_bars_info && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && bl->type == BL_MOB && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1055. p.maxHP = status_get_max_hp(bl);
  1056. p.HP = status_get_hp(bl);
  1057. }else{
  1058. p.maxHP = -1;
  1059. p.HP = -1;
  1060. }
  1061. if( bl->type == BL_MOB ){
  1062. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1063. }else if( bl->type == BL_PET ){
  1064. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1065. }else{
  1066. p.isBoss = BOSSTYPE_NONE;
  1067. }
  1068. #endif
  1069. #if PACKETVER >= 20150513
  1070. p.body = vd->body_style;
  1071. #endif
  1072. /* Might be earlier, this is when the named item bug began */
  1073. #if PACKETVER >= 20131223
  1074. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1075. #endif
  1076. clif_send( &p, sizeof( p ), tbl, target );
  1077. // if disguised, send to self
  1078. if( disguised( bl ) ){
  1079. #if PACKETVER >= 20091103
  1080. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1081. #if PACKETVER >= 20131223
  1082. p.AID = disguised_bl_id( bl->id );
  1083. #else
  1084. p.GID = disguised_bl_id( bl->id );
  1085. #endif
  1086. #else
  1087. p.GID = disguised_bl_id( bl->id );
  1088. #endif
  1089. clif_send(&p, sizeof(p), bl, SELF);
  1090. }
  1091. }
  1092. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1093. nullpo_retv( bl );
  1094. map_session_data* sd = BL_CAST( BL_PC, bl );
  1095. status_change* sc = status_get_sc( bl );
  1096. struct view_data* vd = status_get_viewdata( bl );
  1097. int g_id = status_get_guild_id( bl );
  1098. #if PACKETVER < 20091103
  1099. if( !pcdb_checkid( vd->class_ ) ){
  1100. struct packet_spawn_unit2 p;
  1101. p.PacketType = spawn_unit2Type;
  1102. #if PACKETVER >= 20071106
  1103. p.objecttype = clif_bl_type( bl, false );
  1104. #endif
  1105. p.GID = bl->id;
  1106. p.speed = status_get_speed( bl );
  1107. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1108. p.healthState = ( sc ) ? sc->opt2 : 0;
  1109. p.effectState = ( sc ) ? sc->option : 0;
  1110. p.head = vd->hair_style;
  1111. p.weapon = vd->weapon;
  1112. p.accessory = vd->head_bottom;
  1113. p.job = vd->class_;
  1114. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1115. // The hell, why flags work like this?
  1116. p.shield = status_get_emblem_id( bl );
  1117. p.accessory2 = GetWord( g_id, 1 );
  1118. p.accessory3 = GetWord( g_id, 0 );
  1119. }else{
  1120. p.shield = vd->shield;
  1121. p.accessory2 = vd->head_top;
  1122. p.accessory3 = vd->head_mid;
  1123. }
  1124. p.headpalette = vd->hair_color;
  1125. p.bodypalette = vd->cloth_color;
  1126. p.headDir = ( sd ) ? sd->head_dir : 0;
  1127. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1128. p.sex = vd->sex;
  1129. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1130. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1131. clif_send( &p, sizeof( p ), bl, target );
  1132. return;
  1133. }
  1134. #endif
  1135. struct packet_spawn_unit p;
  1136. p.PacketType = spawn_unitType;
  1137. #if PACKETVER >= 20091103
  1138. p.PacketLength = sizeof(p);
  1139. p.objecttype = clif_bl_type( bl, false );
  1140. #endif
  1141. #if PACKETVER >= 20131223
  1142. p.AID = bl->id;
  1143. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1144. #else
  1145. p.GID = bl->id;
  1146. #endif
  1147. p.speed = status_get_speed( bl );
  1148. p.bodyState = (sc) ? sc->opt1 : 0;
  1149. p.healthState = (sc) ? sc->opt2 : 0;
  1150. p.effectState = (sc) ? sc->option : 0;
  1151. p.job = vd->class_;
  1152. p.head = vd->hair_style;
  1153. p.weapon = vd->weapon;
  1154. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1155. p.shield = vd->shield;
  1156. #endif
  1157. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1158. // The hell, why flags work like this?
  1159. p.accessory = status_get_emblem_id( bl );
  1160. p.accessory2 = GetWord( g_id, 1 );
  1161. p.accessory3 = GetWord( g_id, 0 );
  1162. }else{
  1163. p.accessory = vd->head_bottom;
  1164. p.accessory2 = vd->head_top;
  1165. p.accessory3 = vd->head_mid;
  1166. }
  1167. p.headpalette = vd->hair_color;
  1168. p.bodypalette = vd->cloth_color;
  1169. p.headDir = (sd)? sd->head_dir : 0;
  1170. #if PACKETVER >= 20101124
  1171. p.robe = vd->robe;
  1172. #endif
  1173. p.GUID = g_id;
  1174. p.GEmblemVer = status_get_emblem_id( bl );
  1175. p.honor = (sd) ? sd->status.manner : 0;
  1176. p.virtue = (sc) ? sc->opt3 : 0;
  1177. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1178. p.sex = vd->sex;
  1179. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1180. p.xSize = p.ySize = (sd) ? 5 : 0;
  1181. p.clevel = clif_setlevel( bl );
  1182. #if PACKETVER >= 20080102
  1183. p.font = (sd) ? sd->status.font : 0;
  1184. #endif
  1185. #if PACKETVER >= 20120221
  1186. if( battle_config.monster_hp_bars_info && bl->type == BL_MOB && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1187. p.maxHP = status_get_max_hp( bl );
  1188. p.HP = status_get_hp( bl );
  1189. }else{
  1190. p.maxHP = -1;
  1191. p.HP = -1;
  1192. }
  1193. if( bl->type == BL_MOB ){
  1194. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1195. }else if( bl->type == BL_PET ){
  1196. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1197. }else{
  1198. p.isBoss = BOSSTYPE_NONE;
  1199. }
  1200. #endif
  1201. #if PACKETVER >= 20150513
  1202. p.body = vd->body_style;
  1203. #endif
  1204. /* Might be earlier, this is when the named item bug began */
  1205. #if PACKETVER >= 20131223
  1206. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1207. #endif
  1208. if( disguised( bl ) ){
  1209. nullpo_retv( sd );
  1210. if( sd->status.class_ != sd->disguise ){
  1211. clif_send( &p, sizeof( p ), bl, target );
  1212. }
  1213. #if PACKETVER >= 20091103
  1214. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1215. #if PACKETVER >= 20131223
  1216. p.AID = disguised_bl_id( bl->id );
  1217. #else
  1218. p.GID = disguised_bl_id( bl->id );
  1219. #endif
  1220. #else
  1221. p.GID = disguised_bl_id( bl->id );
  1222. #endif
  1223. clif_send( &p, sizeof( p ), bl, SELF );
  1224. }else{
  1225. clif_send( &p, sizeof( p ), bl, target );
  1226. }
  1227. }
  1228. /*==========================================
  1229. * Prepares 'unit walking' packet
  1230. *------------------------------------------*/
  1231. static void clif_set_unit_walking( struct block_list *bl, map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1232. nullpo_retv( bl );
  1233. nullpo_retv( ud );
  1234. map_session_data* sd;
  1235. status_change* sc = status_get_sc( bl );
  1236. struct view_data* vd = status_get_viewdata( bl );
  1237. struct packet_unit_walking p;
  1238. int g_id = status_get_guild_id(bl);
  1239. sd = BL_CAST(BL_PC, bl);
  1240. p.PacketType = unit_walkingType;
  1241. #if PACKETVER >= 20091103
  1242. p.PacketLength = sizeof(p);
  1243. #endif
  1244. #if PACKETVER >= 20071106
  1245. p.objecttype = clif_bl_type( bl, true );
  1246. #endif
  1247. #if PACKETVER >= 20131223
  1248. p.AID = bl->id;
  1249. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1250. #else
  1251. p.GID = bl->id;
  1252. #endif
  1253. p.speed = status_get_speed(bl);
  1254. p.bodyState = (sc) ? sc->opt1 : 0;
  1255. p.healthState = (sc) ? sc->opt2 : 0;
  1256. p.effectState = (sc) ? sc->option : 0;
  1257. p.job = vd->class_;
  1258. p.head = vd->hair_style;
  1259. p.weapon = vd->weapon;
  1260. p.accessory = vd->head_bottom;
  1261. p.moveStartTime = client_tick(gettick());
  1262. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1263. p.shield = vd->shield;
  1264. #endif
  1265. p.accessory2 = vd->head_top;
  1266. p.accessory3 = vd->head_mid;
  1267. p.headpalette = vd->hair_color;
  1268. p.bodypalette = vd->cloth_color;
  1269. p.headDir = (sd) ? sd->head_dir : 0;
  1270. #if PACKETVER >= 20101124
  1271. p.robe = vd->robe;
  1272. #endif
  1273. p.GUID = g_id;
  1274. p.GEmblemVer = status_get_emblem_id(bl);
  1275. p.honor = (sd) ? sd->status.manner : 0;
  1276. p.virtue = (sc) ? sc->opt3 : 0;
  1277. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1278. p.sex = vd->sex;
  1279. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1280. p.xSize = p.ySize = (sd) ? 5 : 0;
  1281. p.clevel = clif_setlevel(bl);
  1282. #if PACKETVER >= 20080102
  1283. p.font = (sd) ? sd->status.font : 0;
  1284. #endif
  1285. #if PACKETVER >= 20120221
  1286. if( battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR) && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp( bl ) ) ){
  1287. p.maxHP = status_get_max_hp(bl);
  1288. p.HP = status_get_hp(bl);
  1289. } else {
  1290. p.maxHP = -1;
  1291. p.HP = -1;
  1292. }
  1293. if( bl->type == BL_MOB ){
  1294. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1295. }else if( bl->type == BL_PET ){
  1296. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1297. }else{
  1298. p.isBoss = BOSSTYPE_NONE;
  1299. }
  1300. #endif
  1301. #if PACKETVER >= 20150513
  1302. p.body = vd->body_style;
  1303. #endif
  1304. /* Might be earlier, this is when the named item bug began */
  1305. #if PACKETVER >= 20131223
  1306. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1307. #endif
  1308. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1309. // if disguised, send the info to self
  1310. if( disguised( bl ) ){
  1311. #if PACKETVER >= 20091103
  1312. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1313. #if PACKETVER >= 20131223
  1314. p.AID = disguised_bl_id( bl->id );
  1315. #else
  1316. p.GID = disguised_bl_id( bl->id );
  1317. #endif
  1318. #else
  1319. p.GID = disguised_bl_id( bl->id );
  1320. #endif
  1321. clif_send(&p,sizeof(p),bl,SELF);
  1322. }
  1323. }
  1324. //Modifies the buffer for disguise characters and sends it to self.
  1325. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1326. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1327. {
  1328. #if PACKETVER >= 20091103
  1329. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1330. WBUFL(buf,5)=-bl->id;
  1331. #elif PACKETVER >= 20071106
  1332. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1333. WBUFL(buf,3)=-bl->id;
  1334. #else
  1335. WBUFL(buf,2)=-bl->id;
  1336. #endif
  1337. clif_send(buf, len, bl, SELF);
  1338. }
  1339. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1340. /// 01b0 <id>.L <type>.B <value>.L
  1341. /// type:
  1342. /// unused
  1343. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, map_session_data *sd)
  1344. {
  1345. nullpo_retv(bl);
  1346. if(!pcdb_checkid(class_))
  1347. {// player classes yield missing sprites
  1348. unsigned char buf[16];
  1349. WBUFW(buf,0)=0x1b0;
  1350. WBUFL(buf,2)=bl->id;
  1351. WBUFB(buf,6)=type;
  1352. WBUFL(buf,7)=class_;
  1353. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1354. }
  1355. }
  1356. void clif_servantball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1357. struct PACKET_ZC_SPIRITS p = {};
  1358. p.PacketType = HEADER_ZC_SPIRITS;
  1359. p.AID = sd.bl.id;
  1360. p.num = sd.servantball;
  1361. if( target == nullptr ){
  1362. target = &sd.bl;
  1363. }
  1364. clif_send( &p, sizeof( p ), target, send_target );
  1365. }
  1366. void clif_abyssball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1367. struct PACKET_ZC_SPIRITS p = {};
  1368. p.PacketType = HEADER_ZC_SPIRITS;
  1369. p.AID = sd.bl.id;
  1370. p.num = sd.abyssball;
  1371. if( target == nullptr ){
  1372. target = &sd.bl;
  1373. }
  1374. clif_send( &p, sizeof( p ), target, send_target );
  1375. }
  1376. /// Notifies the client of an object's Millenium Shields.
  1377. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1378. {
  1379. nullpo_retv(sd);
  1380. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD) == nullptr)
  1381. return;
  1382. WFIFOHEAD(fd, packet_len(0x440));
  1383. WFIFOW(fd, 0) = 0x440;
  1384. WFIFOL(fd, 2) = sd->bl.id;
  1385. WFIFOW(fd, 6) = sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2;
  1386. WFIFOW(fd, 8) = 0;
  1387. WFIFOSET(fd, packet_len(0x440));
  1388. }
  1389. /*==========================================
  1390. * Kagerou/Oboro amulet spirit
  1391. *------------------------------------------*/
  1392. static void clif_spiritcharm_single(int fd, map_session_data *sd)
  1393. {
  1394. WFIFOHEAD(fd, packet_len(0x08cf));
  1395. WFIFOW(fd,0)=0x08cf;
  1396. WFIFOL(fd,2)=sd->bl.id;
  1397. WFIFOW(fd,6)=sd->spiritcharm_type;
  1398. WFIFOW(fd,8)=sd->spiritcharm;
  1399. WFIFOSET(fd, packet_len(0x08cf));
  1400. }
  1401. /*==========================================
  1402. * Enchanting Shadow / Shadow Scar Spirit
  1403. *------------------------------------------*/
  1404. void clif_enchantingshadow_spirit(unit_data &ud) {
  1405. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1406. PACKET_ZC_TARGET_SPIRITS p = {};
  1407. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1408. p.GID = ud.bl->id;
  1409. p.unknown_val = 0;
  1410. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1411. clif_send(&p, sizeof(p), ud.bl, AREA);
  1412. #endif
  1413. }
  1414. /*==========================================
  1415. * Run when player changes map / refreshes
  1416. * Tells its client to display all weather settings being used by this map
  1417. *------------------------------------------*/
  1418. static void clif_weather_check(map_session_data *sd)
  1419. {
  1420. int16 m = sd->bl.m;
  1421. int fd = sd->fd;
  1422. if (map_getmapflag(m, MF_SNOW)
  1423. || map_getmapflag(m, MF_CLOUDS)
  1424. || map_getmapflag(m, MF_FOG)
  1425. || map_getmapflag(m, MF_FIREWORKS)
  1426. || map_getmapflag(m, MF_SAKURA)
  1427. || map_getmapflag(m, MF_LEAVES)
  1428. || map_getmapflag(m, MF_CLOUDS2))
  1429. {
  1430. if (map_getmapflag(m, MF_SNOW))
  1431. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1432. if (map_getmapflag(m, MF_CLOUDS))
  1433. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1434. if (map_getmapflag(m, MF_CLOUDS2))
  1435. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1436. if (map_getmapflag(m, MF_FOG))
  1437. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1438. if (map_getmapflag(m, MF_FIREWORKS)) {
  1439. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1440. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1441. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1442. }
  1443. if (map_getmapflag(m, MF_SAKURA))
  1444. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1445. if (map_getmapflag(m, MF_LEAVES))
  1446. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1447. }
  1448. }
  1449. /**
  1450. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1451. **/
  1452. void clif_weather(int16 m)
  1453. {
  1454. struct s_mapiterator* iter;
  1455. map_session_data *sd=NULL;
  1456. iter = mapit_getallusers();
  1457. for( sd = (map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (map_session_data*)mapit_next(iter) )
  1458. {
  1459. if( sd->bl.m == m )
  1460. clif_weather_check(sd);
  1461. }
  1462. mapit_free(iter);
  1463. }
  1464. /**
  1465. * Hide a NPC from the effects of Maya Purple card.
  1466. * @param bl: Block data
  1467. * @return True if NPC is disabled or false otherwise
  1468. */
  1469. static inline bool clif_npc_mayapurple(block_list *bl) {
  1470. nullpo_retr(false, bl);
  1471. if (bl->type == BL_NPC) {
  1472. npc_data *nd = map_id2nd(bl->id);
  1473. // TODO: Confirm if waitingroom cause any special cases
  1474. if (/* nd->chat_id == 0 && */ nd->is_invisible)
  1475. return true;
  1476. }
  1477. return false;
  1478. }
  1479. /**
  1480. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1481. **/
  1482. int clif_spawn( struct block_list *bl, bool walking ){
  1483. struct view_data *vd;
  1484. vd = status_get_viewdata(bl);
  1485. if( !vd || vd->class_ == JT_INVISIBLE )
  1486. return 0;
  1487. // Hide NPC from Maya Purple card
  1488. if (clif_npc_mayapurple(bl))
  1489. return 0;
  1490. if( bl->type == BL_NPC && !vd->dead_sit ){
  1491. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1492. }else{
  1493. clif_spawn_unit( bl, AREA_WOS );
  1494. }
  1495. if (vd->cloth_color)
  1496. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1497. if (vd->body_style)
  1498. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1499. switch (bl->type)
  1500. {
  1501. case BL_PC:
  1502. {
  1503. TBL_PC *sd = ((TBL_PC*)bl);
  1504. if (sd->spiritball > 0)
  1505. clif_spiritball(&sd->bl);
  1506. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  1507. clif_millenniumshield(&sd->bl, sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2);
  1508. if (sd->soulball > 0)
  1509. clif_soulball(sd);
  1510. if (sd->servantball > 0)
  1511. clif_servantball( *sd );
  1512. if (sd->abyssball > 0)
  1513. clif_abyssball( *sd );
  1514. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1515. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1516. else if(sd->state.size==SZ_MEDIUM)
  1517. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1518. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1519. clif_sendbgemblem_area(sd);
  1520. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1521. clif_spiritcharm(sd);
  1522. if (sd->status.robe)
  1523. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1524. clif_efst_status_change_sub(bl, bl, AREA);
  1525. clif_hat_effects(sd,bl,AREA);
  1526. }
  1527. break;
  1528. case BL_MOB:
  1529. {
  1530. TBL_MOB *md = ((TBL_MOB*)bl);
  1531. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1532. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1533. else if(md->special_state.size==SZ_MEDIUM)
  1534. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1535. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1536. clif_summon_init(*md);
  1537. }
  1538. break;
  1539. case BL_NPC:
  1540. {
  1541. TBL_NPC *nd = ((TBL_NPC*)bl);
  1542. if( nd->size == SZ_BIG )
  1543. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1544. else if( nd->size == SZ_MEDIUM )
  1545. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1546. clif_efst_status_change_sub(bl, bl, AREA);
  1547. clif_progressbar_npc_area(nd);
  1548. }
  1549. break;
  1550. case BL_PET:
  1551. if (vd->head_bottom)
  1552. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1553. break;
  1554. }
  1555. return 0;
  1556. }
  1557. /// Sends information about owned homunculus to the client . [orn]
  1558. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN)
  1559. /// 09f7 <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.L <max hp>.L <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN_2)
  1560. void clif_hominfo( map_session_data *sd, struct homun_data *hd, int flag ){
  1561. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1562. nullpo_retv( sd );
  1563. nullpo_retv( hd );
  1564. struct status_data *status = &hd->battle_status;
  1565. struct PACKET_ZC_PROPERTY_HOMUN p;
  1566. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1567. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1568. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1569. p.flags = ( !battle_config.hom_rename && hd->homunculus.rename_flag ? 0x1 : 0x0 ) | ( hd->homunculus.vaporize == HOM_ST_REST ? 0x2 : 0 ) | ( hd->homunculus.hp > 0 ? 0x4 : 0 );
  1570. p.level = hd->homunculus.level;
  1571. p.hunger = hd->homunculus.hunger;
  1572. p.intimacy = hd->homunculus.intimacy / 100;
  1573. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1574. p.itemId = 0; // equip id
  1575. #endif
  1576. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1577. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1578. p.hit = status->hit;
  1579. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1580. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1581. }else{
  1582. p.crit = status->cri / 10;
  1583. }
  1584. #ifdef RENEWAL
  1585. p.def = status->def + status->def2;
  1586. p.mdef = status->mdef + status->mdef2;
  1587. #else
  1588. p.def = status->def + status->vit;
  1589. p.mdef = status->mdef;
  1590. #endif
  1591. p.flee = status->flee;
  1592. p.amotion = (flag) ? 0 : status->amotion;
  1593. #if PACKETVER >= 20141016
  1594. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1595. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1596. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1597. p.hp = status->hp / ( status->max_hp / 100 );
  1598. p.maxHp = 100;
  1599. }else{
  1600. p.hp = status->hp;
  1601. p.maxHp = status->max_hp;
  1602. }
  1603. #else
  1604. if( status->max_hp > INT16_MAX ){
  1605. p.hp = status->hp / ( status->max_hp / 100 );
  1606. p.maxHp = 100;
  1607. }else{
  1608. p.hp = status->hp;
  1609. p.maxHp = status->max_hp;
  1610. }
  1611. #endif
  1612. if( status->max_sp > INT16_MAX ){
  1613. p.sp = status->sp / ( status->max_sp / 100 );
  1614. p.maxSp = 100;
  1615. }else{
  1616. p.sp = status->sp;
  1617. p.maxSp = status->max_sp;
  1618. }
  1619. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1620. p.exp = hd->homunculus.exp;
  1621. p.expNext = hd->exp_next;
  1622. #else
  1623. p.exp = (uint32)hd->homunculus.exp;
  1624. p.expNext = (uint32)hd->exp_next;
  1625. #endif
  1626. switch( hom_class2type( hd->homunculus.class_ ) ){
  1627. case HT_REG:
  1628. case HT_EVO:
  1629. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1630. p.expNext = 0;
  1631. }
  1632. break;
  1633. case HT_S:
  1634. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1635. p.expNext = 0;
  1636. }
  1637. break;
  1638. }
  1639. p.skillPoints = hd->homunculus.skillpts;
  1640. p.range = status_get_range( &hd->bl );
  1641. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1642. #endif
  1643. }
  1644. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1645. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1646. /// type:
  1647. /// unused
  1648. /// state:
  1649. /// 0 = pre-init
  1650. /// 1 = intimacy
  1651. /// 2 = hunger
  1652. /// 3 = accessory?
  1653. /// ? = ignored
  1654. void clif_send_homdata(map_session_data *sd, int state, int param)
  1655. { //[orn]
  1656. int fd = sd->fd;
  1657. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1658. hom_calc_skilltree(sd->hd);
  1659. WFIFOHEAD(fd, packet_len(0x230));
  1660. WFIFOW(fd,0)=0x230;
  1661. WFIFOB(fd,2)=0;
  1662. WFIFOB(fd,3)=state;
  1663. WFIFOL(fd,4)=sd->hd->bl.id;
  1664. WFIFOL(fd,8)=param;
  1665. WFIFOSET(fd,packet_len(0x230));
  1666. }
  1667. int clif_homskillinfoblock(map_session_data *sd)
  1668. { //[orn]
  1669. struct homun_data *hd;
  1670. int fd = sd->fd;
  1671. int i, len=4;
  1672. nullpo_ret(sd);
  1673. hd = sd->hd;
  1674. if ( !hd )
  1675. return 0 ;
  1676. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1677. WFIFOW(fd,0)=0x235;
  1678. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1679. int id = hd->homunculus.hskill[i].id;
  1680. if( id != 0 ){
  1681. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1682. short idx = hom_skill_get_index(id);
  1683. if (idx == -1)
  1684. continue;
  1685. WFIFOW(fd,len ) = id;
  1686. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1687. WFIFOW(fd,len+4) = 0;
  1688. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1689. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1690. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1691. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1692. WFIFOB(fd,len+36) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(id, hd->homunculus.class_)) ? 0 : 1;
  1693. len+=37;
  1694. }
  1695. }
  1696. WFIFOW(fd,2)=len;
  1697. WFIFOSET(fd,len);
  1698. return 0;
  1699. }
  1700. void clif_homskillup(map_session_data *sd, uint16 skill_id)
  1701. { //[orn]
  1702. struct homun_data *hd;
  1703. int fd;
  1704. short idx = -1;
  1705. nullpo_retv(sd);
  1706. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1707. return;
  1708. fd = sd->fd;
  1709. hd = sd->hd;
  1710. WFIFOHEAD(fd, packet_len(0x239));
  1711. WFIFOW(fd,0) = 0x239;
  1712. WFIFOW(fd,2) = skill_id;
  1713. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1714. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1715. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1716. WFIFOB(fd,10) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, skill_id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(hd->homunculus.hskill[idx].id, hd->homunculus.class_)) ? 0 : 1;
  1717. WFIFOSET(fd,packet_len(0x239));
  1718. }
  1719. /// Result of request to feed a homun/merc.
  1720. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1721. /// result:
  1722. /// 0 = failure
  1723. /// 1 = success
  1724. void clif_hom_food( map_session_data *sd, int foodid, int fail ){
  1725. nullpo_retv( sd );
  1726. struct PACKET_ZC_FEED_MER p;
  1727. p.packetType = 0x22f;
  1728. p.result = fail;
  1729. p.itemId = client_nameid( foodid );
  1730. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1731. }
  1732. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1733. /// 0087 <walk start time>.L <walk data>.6B
  1734. void clif_walkok(map_session_data *sd)
  1735. {
  1736. int fd=sd->fd;
  1737. WFIFOHEAD(fd, packet_len(0x87));
  1738. WFIFOW(fd,0)=0x87;
  1739. WFIFOL(fd,2)=client_tick(gettick());
  1740. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1741. WFIFOSET(fd,packet_len(0x87));
  1742. }
  1743. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1744. status_change *sc = NULL;
  1745. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1746. clif_ally_only = true;
  1747. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1748. if(vd->cloth_color)
  1749. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1750. if(vd->body_style)
  1751. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1752. switch(bl->type) {
  1753. case BL_PC:
  1754. {
  1755. TBL_PC *sd = ((TBL_PC*)bl);
  1756. // clif_movepc(sd);
  1757. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1758. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1759. else if(sd->state.size==SZ_MEDIUM)
  1760. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1761. if (sd->status.robe)
  1762. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1763. }
  1764. break;
  1765. case BL_MOB:
  1766. {
  1767. TBL_MOB *md = ((TBL_MOB*)bl);
  1768. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1769. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1770. else if(md->special_state.size==SZ_MEDIUM)
  1771. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1772. }
  1773. break;
  1774. case BL_PET:
  1775. if(vd->head_bottom) // needed to display pet equip properly
  1776. clif_pet_equip_area((TBL_PET*)bl);
  1777. break;
  1778. }
  1779. clif_ally_only = false;
  1780. }
  1781. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1782. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1783. /// Note: unit must not be self
  1784. void clif_move(struct unit_data *ud)
  1785. {
  1786. unsigned char buf[16];
  1787. struct view_data* vd;
  1788. struct block_list* bl = ud->bl;
  1789. status_change *sc = NULL;
  1790. vd = status_get_viewdata(bl);
  1791. if (!vd )
  1792. return;
  1793. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1794. else if( vd->class_ == JT_INVISIBLE ){
  1795. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1796. if(disguised(bl)) {
  1797. WBUFW(buf,0)=0x86;
  1798. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1799. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1800. WBUFL(buf,12)=client_tick(gettick());
  1801. clif_send(buf, packet_len(0x86), bl, SELF);
  1802. }
  1803. return;
  1804. }
  1805. // Hide NPC from Maya Purple card
  1806. if (clif_npc_mayapurple(bl))
  1807. return;
  1808. if (ud->state.speed_changed) {
  1809. // Since we don't know how to update the speed of other objects,
  1810. // use the old walk packet to update the data.
  1811. ud->state.speed_changed = 0;
  1812. clif_move2(bl, vd, ud);
  1813. return;
  1814. }
  1815. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1816. clif_ally_only = true;
  1817. WBUFW(buf,0)=0x86;
  1818. WBUFL(buf,2)=bl->id;
  1819. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1820. WBUFL(buf,12)=client_tick(gettick());
  1821. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1822. if (disguised(bl)) {
  1823. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1824. clif_send(buf, packet_len(0x86), bl, SELF);
  1825. }
  1826. clif_ally_only = false;
  1827. }
  1828. /*==========================================
  1829. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1830. *------------------------------------------*/
  1831. static TIMER_FUNC(clif_delayquit){
  1832. map_session_data *sd = NULL;
  1833. //Remove player from map server
  1834. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1835. map_quit(sd);
  1836. return 0;
  1837. }
  1838. /*==========================================
  1839. *
  1840. *------------------------------------------*/
  1841. void clif_quitsave(int fd,map_session_data *sd) {
  1842. if (!battle_config.prevent_logout ||
  1843. sd->canlog_tick == 0 ||
  1844. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1845. map_quit(sd);
  1846. else if (session_isValid(sd->fd)) {
  1847. //Disassociate session from player (session is deleted after this function was called)
  1848. //And set a timer to make him quit later.
  1849. session[sd->fd]->session_data = NULL;
  1850. sd->fd = 0;
  1851. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1852. }
  1853. }
  1854. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1855. /// 0091 <map name>.16B <x>.W <y>.W
  1856. void clif_changemap(map_session_data *sd, short m, int x, int y)
  1857. {
  1858. nullpo_retv(sd);
  1859. int fd = sd->fd;
  1860. WFIFOHEAD(fd,packet_len(0x91));
  1861. WFIFOW(fd,0) = 0x91;
  1862. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1863. WFIFOW(fd,18) = x;
  1864. WFIFOW(fd,20) = y;
  1865. WFIFOSET(fd,packet_len(0x91));
  1866. }
  1867. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1868. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1869. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1870. void clif_changemapserver(map_session_data* sd, const char* map, int x, int y, uint32 ip, uint16 port)
  1871. {
  1872. int fd;
  1873. #if PACKETVER >= 20170315
  1874. int cmd = 0xac7;
  1875. #else
  1876. int cmd = 0x92;
  1877. #endif
  1878. nullpo_retv(sd);
  1879. fd = sd->fd;
  1880. WFIFOHEAD(fd,packet_len(cmd));
  1881. WFIFOW(fd,0) = cmd;
  1882. mapindex_getmapname_ext( map, WFIFOCP( fd, 2 ) );
  1883. WFIFOW(fd,18) = x;
  1884. WFIFOW(fd,20) = y;
  1885. WFIFOL(fd,22) = htonl(ip);
  1886. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1887. #if PACKETVER >= 20170315
  1888. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1889. #endif
  1890. #ifdef DEBUG
  1891. ShowDebug(
  1892. "Sending the client (%d %d.%d.%d.%d) to map-server with ip %d.%d.%d.%d and port %hu\n",
  1893. sd->status.account_id, CONVIP(session[fd]->client_addr), CONVIP(ip), port);
  1894. #endif
  1895. WFIFOSET(fd,packet_len(cmd));
  1896. }
  1897. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1898. /// This function combines both calls and allows to simplify the calling code
  1899. void clif_blown(struct block_list *bl)
  1900. {
  1901. clif_slide(bl, bl->x, bl->y);
  1902. clif_fixpos(bl);
  1903. }
  1904. /// Visually moves(slides) a character to x,y. If the target cell
  1905. /// isn't walkable, the char doesn't move at all. If the char is
  1906. /// sitting it will stand up (ZC_STOPMOVE).
  1907. /// 0088 <id>.L <x>.W <y>.W
  1908. void clif_fixpos(struct block_list *bl)
  1909. {
  1910. unsigned char buf[10];
  1911. nullpo_retv(bl);
  1912. WBUFW(buf,0) = 0x88;
  1913. WBUFL(buf,2) = bl->id;
  1914. WBUFW(buf,6) = bl->x;
  1915. WBUFW(buf,8) = bl->y;
  1916. clif_send(buf, packet_len(0x88), bl, AREA);
  1917. if( disguised(bl) ) {
  1918. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1919. clif_send(buf, packet_len(0x88), bl, SELF);
  1920. }
  1921. }
  1922. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1923. /// 00c4 <shop id>.L
  1924. void clif_npcbuysell(map_session_data* sd, int id)
  1925. {
  1926. int fd;
  1927. nullpo_retv(sd);
  1928. fd=sd->fd;
  1929. WFIFOHEAD(fd, packet_len(0xc4));
  1930. WFIFOW(fd,0)=0xc4;
  1931. WFIFOL(fd,2)=id;
  1932. WFIFOSET(fd,packet_len(0xc4));
  1933. }
  1934. /// Presents list of items, that can be bought in an NPC shop.
  1935. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1936. void clif_buylist( map_session_data *sd, struct npc_data *nd ){
  1937. nullpo_retv( sd );
  1938. nullpo_retv( nd );
  1939. int fd = sd->fd;
  1940. if( !session_isActive( fd ) ){
  1941. return;
  1942. }
  1943. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1944. WFIFOHEAD( fd, len );
  1945. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1946. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1947. int count = 0;
  1948. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1949. int val = nd->u.shop.shop_item[i].value;
  1950. p->items[count].price = val;
  1951. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1952. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1953. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1954. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1955. std::shared_ptr<item_data> id = item_db.find(nd->u.shop.shop_item[i].nameid);
  1956. p->items[count].viewSprite = id->look;
  1957. p->items[count].location = pc_equippoint_sub( sd, id.get() );
  1958. #endif
  1959. count++;
  1960. }
  1961. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1962. WFIFOSET( fd, p->packetLength );
  1963. }
  1964. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1965. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1966. void clif_selllist(map_session_data *sd)
  1967. {
  1968. int fd,i,c=0,val;
  1969. struct npc_data *nd;
  1970. nullpo_retv(sd);
  1971. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1972. return;
  1973. fd=sd->fd;
  1974. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1975. WFIFOW(fd,0)=0xc7;
  1976. for( i = 0; i < MAX_INVENTORY; i++ )
  1977. {
  1978. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1979. {
  1980. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1981. continue;
  1982. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1983. val = 0;
  1984. else {
  1985. val = sd->inventory_data[i]->value_sell;
  1986. if( val < 0 )
  1987. continue;
  1988. }
  1989. WFIFOW(fd,4+c*10)=i+2;
  1990. WFIFOL(fd,6+c*10)=val;
  1991. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1992. c++;
  1993. }
  1994. }
  1995. WFIFOW(fd,2)=c*10+4;
  1996. WFIFOSET(fd,WFIFOW(fd,2));
  1997. }
  1998. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1999. /// 09d4
  2000. void clif_parse_NPCShopClosed(int fd, map_session_data *sd) {
  2001. // TODO: State tracking?
  2002. sd->npc_shopid = 0;
  2003. }
  2004. /**
  2005. * Presents list of items, that can be sold to a Market shop.
  2006. * @author: Ind and Yommy
  2007. **/
  2008. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  2009. void clif_npc_market_open(map_session_data *sd, struct npc_data *nd) {
  2010. #if PACKETVER >= 20131223
  2011. nullpo_retv( sd );
  2012. nullpo_retv( nd );
  2013. if( sd->state.trading ){
  2014. return;
  2015. }
  2016. int fd = sd->fd;
  2017. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  2018. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  2019. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  2020. int count = 0;
  2021. for( int i = 0; i < nd->u.shop.count; i++ ){
  2022. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  2023. if( !item->nameid ){
  2024. continue;
  2025. }
  2026. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  2027. if( !id ){
  2028. continue;
  2029. }
  2030. p->list[count].nameid = client_nameid( item->nameid );
  2031. p->list[count].type = itemtype( item->nameid );
  2032. p->list[count].price = item->value;
  2033. p->list[count].qty = item->qty;
  2034. p->list[count].weight = id->weight;
  2035. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2036. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2037. #endif
  2038. count++;
  2039. }
  2040. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2041. WFIFOSET( fd, p->packetLength );
  2042. sd->state.trading = 1;
  2043. #endif
  2044. }
  2045. /// Closes the Market shop window.
  2046. void clif_parse_NPCMarketClosed(int fd, map_session_data *sd) {
  2047. nullpo_retv(sd);
  2048. sd->npc_shopid = 0;
  2049. sd->state.trading = 0;
  2050. }
  2051. /// Purchase item from Market shop.
  2052. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2053. void clif_npc_market_purchase_ack( map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2054. #if PACKETVER >= 20131223
  2055. nullpo_retv( sd );
  2056. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2057. nullpo_retv( nd );
  2058. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2059. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2060. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2061. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2062. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2063. #else
  2064. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2065. #endif
  2066. if( res == e_purchase_result::PURCHASE_SUCCEED ){
  2067. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2068. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2069. // Not found
  2070. if( j == nd->u.shop.count ){
  2071. continue;
  2072. }
  2073. p->list[count].ITID = client_nameid( list[i].nameid );
  2074. p->list[count].qty = list[i].qty;
  2075. p->list[count].price = nd->u.shop.shop_item[j].value;
  2076. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2077. count++;
  2078. }
  2079. }
  2080. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2081. #endif
  2082. }
  2083. /// Purchase item from Market shop.
  2084. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2085. void clif_parse_NPCMarketPurchase(int fd, map_session_data *sd) {
  2086. #if PACKETVER >= 20131223
  2087. nullpo_retv( sd );
  2088. if( !sd->npc_shopid ){
  2089. return;
  2090. }
  2091. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2092. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2093. std::vector<s_npc_buy_list> items;
  2094. items.reserve( count );
  2095. for( int i = 0; i < count; i++ ){
  2096. s_npc_buy_list item = {};
  2097. item.nameid = p->list[i].ITID;
  2098. item.qty = p->list[i].qty;
  2099. items.push_back( item );
  2100. }
  2101. e_purchase_result res = npc_buylist( sd, items );
  2102. clif_npc_market_purchase_ack( sd, res, items );
  2103. #endif
  2104. }
  2105. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2106. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2107. /// Client behavior (dialog window):
  2108. /// - disable mouse targeting
  2109. /// - open the dialog window
  2110. /// - set npcid of dialog window (0 by default)
  2111. /// - if set to clear on next mes, clear contents
  2112. /// - append this text
  2113. void clif_scriptmes( map_session_data& sd, uint32 npcid, const char *mes ){
  2114. struct PACKET_ZC_SAY_DIALOG* p = (struct PACKET_ZC_SAY_DIALOG*)packet_buffer;
  2115. int16 length = (int16)( strlen( mes ) + 1 );
  2116. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2117. p->PacketLength = sizeof( *p ) + length;
  2118. p->NpcID = npcid;
  2119. safestrncpy( p->message, mes, length );
  2120. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2121. }
  2122. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2123. /// 00b5 <npc id>.L
  2124. /// Client behavior (dialog window):
  2125. /// - disable mouse targeting
  2126. /// - open the dialog window
  2127. /// - add 'next' button
  2128. /// When 'next' is pressed:
  2129. /// - 00B9 <npcid of dialog window>.L
  2130. /// - set to clear on next mes
  2131. /// - remove 'next' button
  2132. void clif_scriptnext( map_session_data& sd, uint32 npcid ){
  2133. struct PACKET_ZC_WAIT_DIALOG p = {};
  2134. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2135. p.NpcID = npcid;
  2136. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2137. }
  2138. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2139. /// 00b6 <npc id>.L
  2140. /// Client behavior:
  2141. /// - if dialog window is open:
  2142. /// - remove 'next' button
  2143. /// - add 'close' button
  2144. /// - else:
  2145. /// - enable mouse targeting
  2146. /// - close the dialog window
  2147. /// - close the menu window
  2148. /// When 'close' is pressed:
  2149. /// - enable mouse targeting
  2150. /// - close the dialog window
  2151. /// - close the menu window
  2152. /// - 0146 <npcid of dialog window>.L
  2153. void clif_scriptclose(map_session_data *sd, int npcid)
  2154. {
  2155. int fd;
  2156. nullpo_retv(sd);
  2157. fd=sd->fd;
  2158. WFIFOHEAD(fd, packet_len(0xb6));
  2159. WFIFOW(fd,0)=0xb6;
  2160. WFIFOL(fd,2)=npcid;
  2161. WFIFOSET(fd,packet_len(0xb6));
  2162. }
  2163. /**
  2164. * Close script when player is idle
  2165. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2166. * @author [Ind/Hercules]
  2167. * @param sd : player pointer
  2168. * @param npcid : npc gid to close
  2169. */
  2170. void clif_scriptclear( map_session_data& sd, int npcid ){
  2171. struct PACKET_ZC_CLEAR_DIALOG p = {};
  2172. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2173. p.GID = npcid;
  2174. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2175. }
  2176. /*==========================================
  2177. *
  2178. *------------------------------------------*/
  2179. void clif_sendfakenpc(map_session_data *sd, int npcid) {
  2180. unsigned char *buf;
  2181. int fd = sd->fd;
  2182. sd->state.using_fake_npc = 1;
  2183. WFIFOHEAD(fd, packet_len(0x78));
  2184. buf = WFIFOP(fd,0);
  2185. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2186. WBUFW(buf,0)=0x78;
  2187. #if PACKETVER >= 20071106
  2188. WBUFB(buf,2) = 0; // object type
  2189. buf = WFIFOP(fd,1);
  2190. #endif
  2191. WBUFL(buf,2)=npcid;
  2192. WBUFW(buf,14)=111;
  2193. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2194. WBUFB(buf,49)=5;
  2195. WBUFB(buf,50)=5;
  2196. WFIFOSET(fd, packet_len(0x78));
  2197. }
  2198. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2199. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2200. /// Client behavior:
  2201. /// - disable mouse targeting
  2202. /// - close the menu window
  2203. /// - open the menu window
  2204. /// - add options to the menu (separated in the text by ":")
  2205. /// - set npcid of menu window
  2206. /// - if dialog window is open:
  2207. /// - remove 'next' button
  2208. /// When 'ok' is pressed:
  2209. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2210. /// - close the menu window
  2211. /// When 'cancel' is pressed:
  2212. /// - 00B8 <npcid of menu window>.L <-1>.B
  2213. /// - enable mouse targeting
  2214. /// - close a bunch of windows...
  2215. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2216. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2217. /// TODO investigate behavior of other windows [FlavioJS]
  2218. void clif_scriptmenu(map_session_data* sd, int npcid, const char* mes)
  2219. {
  2220. int fd = sd->fd;
  2221. int slen = strlen(mes) + 9;
  2222. struct block_list *bl = NULL;
  2223. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2224. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2225. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2226. clif_sendfakenpc(sd, npcid);
  2227. WFIFOHEAD(fd, slen);
  2228. WFIFOW(fd,0)=0xb7;
  2229. WFIFOW(fd,2)=slen;
  2230. WFIFOL(fd,4)=npcid;
  2231. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2232. WFIFOSET(fd,WFIFOW(fd,2));
  2233. }
  2234. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2235. /// 0142 <npc id>.L
  2236. /// Client behavior (inputnum window):
  2237. /// - if npcid exists in the client:
  2238. /// - open the inputnum window
  2239. /// - set npcid of inputnum window
  2240. /// When 'ok' is pressed:
  2241. /// - if inputnum window has text:
  2242. /// - if npcid exists in the client:
  2243. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2244. /// - close inputnum window
  2245. void clif_scriptinput(map_session_data *sd, int npcid)
  2246. {
  2247. int fd;
  2248. struct block_list *bl = NULL;
  2249. nullpo_retv(sd);
  2250. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2251. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2252. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2253. clif_sendfakenpc(sd, npcid);
  2254. fd=sd->fd;
  2255. WFIFOHEAD(fd, packet_len(0x142));
  2256. WFIFOW(fd,0)=0x142;
  2257. WFIFOL(fd,2)=npcid;
  2258. WFIFOSET(fd,packet_len(0x142));
  2259. }
  2260. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2261. /// 01d4 <npc id>.L
  2262. /// Client behavior (inputstr window):
  2263. /// - if npcid is 0 or npcid exists in the client:
  2264. /// - open the inputstr window
  2265. /// - set npcid of inputstr window
  2266. /// When 'ok' is pressed:
  2267. /// - if inputstr window has text and isn't an insult(manner.txt):
  2268. /// - if npcid is 0 or npcid exists in the client:
  2269. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2270. /// - close inputstr window
  2271. void clif_scriptinputstr(map_session_data *sd, int npcid)
  2272. {
  2273. int fd;
  2274. struct block_list *bl = NULL;
  2275. nullpo_retv(sd);
  2276. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2277. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2278. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2279. clif_sendfakenpc(sd, npcid);
  2280. fd=sd->fd;
  2281. WFIFOHEAD(fd, packet_len(0x1d4));
  2282. WFIFOW(fd,0)=0x1d4;
  2283. WFIFOL(fd,2)=npcid;
  2284. WFIFOSET(fd,packet_len(0x1d4));
  2285. }
  2286. /// Marks a position on client's minimap (ZC_COMPASS).
  2287. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2288. /// npc id:
  2289. /// is ignored in the client
  2290. /// type:
  2291. /// 0 = display mark for 15 seconds
  2292. /// 1 = display mark until dead or teleported
  2293. /// 2 = remove mark
  2294. /// color:
  2295. /// 0x00RRGGBB
  2296. void clif_viewpoint(map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2297. {
  2298. int fd;
  2299. nullpo_retv(sd);
  2300. fd=sd->fd;
  2301. WFIFOHEAD(fd, packet_len(0x144));
  2302. WFIFOW(fd,0)=0x144;
  2303. WFIFOL(fd,2)=npc_id;
  2304. WFIFOL(fd,6)=type;
  2305. WFIFOL(fd,10)=x;
  2306. WFIFOL(fd,14)=y;
  2307. WFIFOB(fd,18)=id;
  2308. WFIFOL(fd,19)=color;
  2309. WFIFOSET(fd,packet_len(0x144));
  2310. }
  2311. /// Displays an illustration image.
  2312. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2313. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2314. /// type:
  2315. /// 0 = bottom left corner
  2316. /// 1 = bottom middle
  2317. /// 2 = bottom right corner
  2318. /// 3 = middle of screen, inside a movable window
  2319. /// 4 = middle of screen, movable with a close button, chrome-less
  2320. /// 255 = clear all displayed cutins
  2321. void clif_cutin(map_session_data* sd, const char* image, int type)
  2322. {
  2323. int fd;
  2324. nullpo_retv(sd);
  2325. fd=sd->fd;
  2326. WFIFOHEAD(fd, packet_len(0x1b3));
  2327. WFIFOW(fd,0)=0x1b3;
  2328. strncpy(WFIFOCP(fd,2),image,64);
  2329. WFIFOB(fd,66)=type;
  2330. WFIFOSET(fd,packet_len(0x1b3));
  2331. }
  2332. /*==========================================
  2333. * Fills in card data from the given item and into the buffer. [Skotlex]
  2334. *------------------------------------------*/
  2335. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2336. nullpo_retv( buf );
  2337. // Blank data
  2338. if( item == nullptr ){
  2339. buf->card[0] = 0;
  2340. buf->card[1] = 0;
  2341. buf->card[2] = 0;
  2342. buf->card[3] = 0;
  2343. return;
  2344. }
  2345. // Pet eggs
  2346. if( item->card[0] == CARD0_PET ){
  2347. buf->card[0] = 0;
  2348. buf->card[1] = 0;
  2349. // Pet intimacy
  2350. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2351. buf->card[2] = item->card[3] >> 1;
  2352. // Pet renamed flag
  2353. buf->card[3] = item->card[3] & 1;
  2354. return;
  2355. }
  2356. // Forged/created items
  2357. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2358. buf->card[0] = item->card[0];
  2359. buf->card[1] = item->card[1];
  2360. buf->card[2] = item->card[2];
  2361. buf->card[3] = item->card[3];
  2362. return;
  2363. }
  2364. int i = 0, j;
  2365. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2366. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2367. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2368. }
  2369. // Normal items.
  2370. for( int k = 0; k < 4; k++, i++ ){
  2371. if( item->card[i] > 0 ){
  2372. buf->card[k] = client_nameid( item->card[i] );
  2373. }else{
  2374. buf->card[k] = 0;
  2375. }
  2376. }
  2377. }
  2378. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2379. /// A maximum of 5 random options can be supported.
  2380. static void clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item& it ){
  2381. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2382. if( it.option[i].id ){
  2383. buf[i].index = it.option[i].id; // OptIndex
  2384. buf[i].value = it.option[i].value; // Value
  2385. buf[i].param = it.option[i].param; // Param1
  2386. }else{
  2387. buf[i].index = 0;
  2388. buf[i].value = 0;
  2389. buf[i].param = 0;
  2390. }
  2391. }
  2392. #if MAX_ITEM_RDM_OPT < 5
  2393. for( ; i < 5; i++ ){
  2394. buf[i].index = 0; // OptIndex
  2395. buf[i].value = 0; // Value
  2396. buf[i].param = 0; // Param1
  2397. }
  2398. #endif
  2399. }
  2400. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2401. /// 00a0 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B (ZC_ITEM_PICKUP_ACK)
  2402. /// 029a <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L (ZC_ITEM_PICKUP_ACK2)
  2403. /// 02d4 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK3)
  2404. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  2405. /// 0a0c <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ITEM_PICKUP_ACK_V6)
  2406. /// 0a37 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W { <option id>.W <option value>.W <option param>.B }*5 <favorite>.B <view id>.W (ZC_ITEM_PICKUP_ACK_V7)
  2407. void clif_additem( map_session_data *sd, int n, int amount, unsigned char fail ){
  2408. nullpo_retv( sd );
  2409. int fd = sd->fd;
  2410. if( !session_isActive( fd ) ){
  2411. return;
  2412. }
  2413. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2414. if( fail ){
  2415. p = {};
  2416. }else{
  2417. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2418. return;
  2419. }
  2420. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2421. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2422. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2423. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2424. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2425. p.location = pc_equippoint(sd,n);
  2426. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2427. #if PACKETVER >= 20061218
  2428. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2429. #if PACKETVER >= 20071002
  2430. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2431. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2432. */
  2433. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2434. #if PACKETVER >= 20150226
  2435. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[n] );
  2436. #if PACKETVER >= 20160921
  2437. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2438. p.look = sd->inventory_data[n]->look;
  2439. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2440. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2441. #endif
  2442. #endif
  2443. #endif
  2444. #endif
  2445. #endif
  2446. }
  2447. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2448. p.Index = client_index( n );
  2449. p.count = amount;
  2450. p.result = fail;
  2451. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2452. }
  2453. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2454. /// 00af <index>.W <amount>.W
  2455. void clif_dropitem(map_session_data *sd,int n,int amount)
  2456. {
  2457. int fd;
  2458. nullpo_retv(sd);
  2459. fd=sd->fd;
  2460. WFIFOHEAD(fd, packet_len(0xaf));
  2461. WFIFOW(fd,0)=0xaf;
  2462. WFIFOW(fd,2)=n+2;
  2463. WFIFOW(fd,4)=amount;
  2464. WFIFOSET(fd,packet_len(0xaf));
  2465. }
  2466. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2467. /// 07fa <delete type>.W <index>.W <amount>.W
  2468. /// delete type:
  2469. /// 0 = Normal
  2470. /// 1 = Item used for a skill
  2471. /// 2 = Refine failed
  2472. /// 3 = Material changed
  2473. /// 4 = Moved to storage
  2474. /// 5 = Moved to cart
  2475. /// 6 = Item sold
  2476. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2477. void clif_delitem(map_session_data *sd,int n,int amount, short reason)
  2478. {
  2479. #if PACKETVER < 20091117
  2480. clif_dropitem(sd,n,amount);
  2481. #else
  2482. int fd;
  2483. nullpo_retv(sd);
  2484. fd=sd->fd;
  2485. WFIFOHEAD(fd, packet_len(0x7fa));
  2486. WFIFOW(fd,0)=0x7fa;
  2487. WFIFOW(fd,2)=reason;
  2488. WFIFOW(fd,4)=n+2;
  2489. WFIFOW(fd,6)=amount;
  2490. WFIFOSET(fd,packet_len(0x7fa));
  2491. #endif
  2492. }
  2493. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2494. nullpo_retv( p );
  2495. nullpo_retv( it );
  2496. nullpo_retv( id );
  2497. p->index = idx;
  2498. p->ITID = client_nameid( it->nameid );
  2499. p->type = itemtype( it->nameid );
  2500. #if PACKETVER < 20120925
  2501. p->IsIdentified = it->identify ? 1 : 0;
  2502. #endif
  2503. p->location = eqp_pos;
  2504. p->WearState = it->equip;
  2505. #if PACKETVER < 20120925
  2506. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2507. #endif
  2508. p->RefiningLevel = it->refine;
  2509. clif_addcards( &p->slot, it );
  2510. #if PACKETVER >= 20071002
  2511. p->HireExpireDate = it->expire_time;
  2512. #endif
  2513. #if PACKETVER >= 20080102
  2514. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2515. #endif
  2516. #if PACKETVER >= 20100629
  2517. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2518. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2519. #endif
  2520. #if PACKETVER >= 20120925
  2521. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2522. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2523. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2524. p->Flag.SpareBits = 0;
  2525. #endif
  2526. #if PACKETVER >= 20150226
  2527. clif_add_random_options( p->option_data, *it );
  2528. // Client ingores the value anyway and recalculates it
  2529. p->option_count = 0;
  2530. #endif
  2531. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2532. p->grade = it->enchantgrade;
  2533. #endif
  2534. }
  2535. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2536. nullpo_retv(p);
  2537. nullpo_retv(i);
  2538. nullpo_retv(id);
  2539. p->index = idx;
  2540. p->ITID = client_nameid( i->nameid );
  2541. p->type = itemtype( i->nameid );
  2542. #if PACKETVER < 20120925
  2543. p->IsIdentified = i->identify ? 1 : 0;
  2544. #endif
  2545. p->count = i->amount;
  2546. p->WearState = id->equip;
  2547. #if PACKETVER >= 5
  2548. clif_addcards( &p->slot, i );
  2549. #endif
  2550. #if PACKETVER >= 20080102
  2551. p->HireExpireDate = i->expire_time;
  2552. #endif
  2553. #if PACKETVER >= 20120925
  2554. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2555. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2556. p->Flag.SpareBits = 0;
  2557. #endif
  2558. }
  2559. static void clif_inventoryStart( map_session_data *sd, e_inventory_type type, const char *name ){
  2560. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2561. nullpo_retv(sd);
  2562. nullpo_retv(name);
  2563. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2564. memset(buf, 0, sizeof(buf));
  2565. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2566. p->packetType = HEADER_ZC_INVENTORY_START;
  2567. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2568. p->invType = type;
  2569. #endif
  2570. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2571. int strLen = (int)safestrnlen(name, 24) + 1;
  2572. if (strLen > 24)
  2573. strLen = 24;
  2574. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2575. p->packetLength = len;
  2576. safestrncpy(p->name, name, strLen);
  2577. #else
  2578. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2579. safestrncpy(p->name, name, NAME_LENGTH);
  2580. #endif
  2581. clif_send( p, len, &sd->bl, SELF );
  2582. #endif
  2583. }
  2584. static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
  2585. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2586. nullpo_retv(sd);
  2587. struct PACKET_ZC_INVENTORY_END p;
  2588. p.packetType = HEADER_ZC_INVENTORY_END;
  2589. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2590. p.invType = type;
  2591. #endif
  2592. p.flag = 0;
  2593. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2594. #endif
  2595. }
  2596. void clif_favorite_item(map_session_data* sd, unsigned short index);
  2597. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2598. void clif_inventorylist( map_session_data *sd ){
  2599. nullpo_retv( sd );
  2600. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2601. e_inventory_type type = INVTYPE_INVENTORY;
  2602. clif_inventoryStart( sd, type, "" );
  2603. #endif
  2604. static struct packet_itemlist_normal itemlist_normal;
  2605. static struct packet_itemlist_equip itemlist_equip;
  2606. int equip = 0;
  2607. int normal = 0;
  2608. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2609. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2610. continue;
  2611. }
  2612. // Non-stackable (Equippable)
  2613. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2614. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2615. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2616. itemlist_equip.PacketType = inventorylistequipType;
  2617. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2618. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2619. itemlist_equip.invType = type;
  2620. #endif
  2621. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2622. equip = 0;
  2623. }
  2624. // Stackable (Normal)
  2625. }else{
  2626. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2627. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2628. itemlist_normal.PacketType = inventorylistnormalType;
  2629. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2630. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2631. itemlist_normal.invType = type;
  2632. #endif
  2633. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2634. normal = 0;
  2635. }
  2636. }
  2637. }
  2638. if( normal ){
  2639. itemlist_normal.PacketType = inventorylistnormalType;
  2640. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2641. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2642. itemlist_normal.invType = type;
  2643. #endif
  2644. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2645. }
  2646. if( sd->equip_index[EQI_AMMO] >= 0 )
  2647. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2648. if( equip ) {
  2649. itemlist_equip.PacketType = inventorylistequipType;
  2650. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2651. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2652. itemlist_equip.invType = type;
  2653. #endif
  2654. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2655. }
  2656. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2657. clif_inventoryEnd( sd, type );
  2658. #endif
  2659. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2660. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2661. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2662. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2663. continue;
  2664. if ( sd->inventory.u.items_inventory[i].favorite )
  2665. clif_favorite_item(sd, i);
  2666. }
  2667. #endif
  2668. }
  2669. //Required when items break/get-repaired. Only sends equippable item list.
  2670. void clif_equiplist( map_session_data *sd ){
  2671. // TODO: implement again => only send equip part
  2672. clif_inventorylist( sd );
  2673. }
  2674. void clif_storagelist(map_session_data* sd, struct item* items, int items_length, const char *storename){
  2675. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2676. e_inventory_type type = INVTYPE_STORAGE;
  2677. clif_inventoryStart( sd, type, storename );
  2678. #endif
  2679. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2680. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2681. int equip = 0;
  2682. int normal = 0;
  2683. for( int i = 0; i < items_length; i++ ){
  2684. if( items[i].nameid == 0 ){
  2685. continue;
  2686. }
  2687. struct item_data* id = itemdb_search( items[i].nameid );
  2688. // Non-stackable (Equippable)
  2689. if( !itemdb_isstackable2( id ) ){
  2690. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2691. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2692. storage_itemlist_equip.PacketType = storageListEquipType;
  2693. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2694. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2695. storage_itemlist_equip.invType = type;
  2696. #elif PACKETVER >= 20120925
  2697. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2698. #endif
  2699. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2700. equip = 0;
  2701. }
  2702. // Stackable (Normal)
  2703. }else{
  2704. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2705. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2706. storage_itemlist_normal.PacketType = storageListNormalType;
  2707. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2708. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2709. storage_itemlist_normal.invType = type;
  2710. #elif PACKETVER >= 20120925
  2711. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2712. #endif
  2713. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2714. normal = 0;
  2715. }
  2716. }
  2717. }
  2718. if( normal ){
  2719. storage_itemlist_normal.PacketType = storageListNormalType;
  2720. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2721. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2722. storage_itemlist_normal.invType = type;
  2723. #elif PACKETVER >= 20120925
  2724. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2725. #endif
  2726. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2727. }
  2728. if( equip ) {
  2729. storage_itemlist_equip.PacketType = storageListEquipType;
  2730. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2731. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2732. storage_itemlist_equip.invType = type;
  2733. #elif PACKETVER >= 20120925
  2734. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2735. #endif
  2736. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2737. }
  2738. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2739. clif_inventoryEnd( sd, type );
  2740. #endif
  2741. }
  2742. void clif_cartlist( map_session_data *sd ){
  2743. nullpo_retv( sd );
  2744. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2745. e_inventory_type type = INVTYPE_CART;
  2746. clif_inventoryStart( sd, type, "" );
  2747. #endif
  2748. static struct packet_itemlist_normal itemlist_normal;
  2749. static struct packet_itemlist_equip itemlist_equip;
  2750. int normal = 0;
  2751. int equip = 0;
  2752. for( int i = 0; i < MAX_CART; i++ ){
  2753. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2754. continue;
  2755. }
  2756. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2757. // Non-stackable (Equippable)
  2758. if( !itemdb_isstackable2(id) ){
  2759. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2760. // Stackable (Normal)
  2761. }else{
  2762. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2763. }
  2764. }
  2765. if( normal ){
  2766. itemlist_normal.PacketType = cartlistnormalType;
  2767. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2768. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2769. itemlist_normal.invType = type;
  2770. #endif
  2771. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2772. }
  2773. if( equip ){
  2774. itemlist_equip.PacketType = cartlistequipType;
  2775. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2776. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2777. itemlist_equip.invType = type;
  2778. #endif
  2779. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2780. }
  2781. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2782. clif_inventoryEnd( sd, type );
  2783. #endif
  2784. }
  2785. /// Removes cart (ZC_CARTOFF).
  2786. /// 012b
  2787. /// Client behaviour:
  2788. /// Closes the cart storage and removes all it's items from memory.
  2789. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2790. void clif_clearcart(int fd)
  2791. {
  2792. WFIFOHEAD(fd, packet_len(0x12b));
  2793. WFIFOW(fd,0) = 0x12b;
  2794. WFIFOSET(fd, packet_len(0x12b));
  2795. }
  2796. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2797. /// 01eb <account id>.L <x>.W <y>.W
  2798. void clif_guild_xy(map_session_data *sd)
  2799. {
  2800. unsigned char buf[10];
  2801. nullpo_retv(sd);
  2802. WBUFW(buf,0)=0x1eb;
  2803. WBUFL(buf,2)=sd->status.account_id;
  2804. WBUFW(buf,6)=sd->bl.x;
  2805. WBUFW(buf,8)=sd->bl.y;
  2806. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2807. }
  2808. /*==========================================
  2809. * Sends x/y dot to a single fd. [Skotlex]
  2810. *------------------------------------------*/
  2811. void clif_guild_xy_single(int fd, map_session_data *sd)
  2812. {
  2813. if( sd->bg_id )
  2814. return;
  2815. WFIFOHEAD(fd,packet_len(0x1eb));
  2816. WFIFOW(fd,0)=0x1eb;
  2817. WFIFOL(fd,2)=sd->status.account_id;
  2818. WFIFOW(fd,6)=sd->bl.x;
  2819. WFIFOW(fd,8)=sd->bl.y;
  2820. WFIFOSET(fd,packet_len(0x1eb));
  2821. }
  2822. // Guild XY locators [Valaris]
  2823. void clif_guild_xy_remove(map_session_data *sd)
  2824. {
  2825. unsigned char buf[10];
  2826. nullpo_retv(sd);
  2827. WBUFW(buf,0)=0x1eb;
  2828. WBUFL(buf,2)=sd->status.account_id;
  2829. WBUFW(buf,6)=-1;
  2830. WBUFW(buf,8)=-1;
  2831. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2832. }
  2833. /*==========================================
  2834. * Load castle list for guild UI. [Asheraf] / [Balfear]
  2835. *------------------------------------------*/
  2836. void clif_guild_castle_list(map_session_data& sd){
  2837. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2838. auto &g = sd.guild;
  2839. if (g == nullptr)
  2840. return;
  2841. int castle_count = guild_checkcastles(g->guild);
  2842. if (castle_count > 0) {
  2843. struct PACKET_ZC_GUILD_AGIT_INFO* p = (struct PACKET_ZC_GUILD_AGIT_INFO*)packet_buffer;
  2844. p->packetType = HEADER_ZC_GUILD_AGIT_INFO;
  2845. p->packetLength = static_cast<int16>( sizeof( struct PACKET_ZC_GUILD_AGIT_INFO ) );
  2846. int i = 0;
  2847. for (const auto& gc : castle_db) {
  2848. if (gc.second->guild_id == g->guild.guild_id && gc.second->client_id) {
  2849. p->castle_list[i] = static_cast<int8>( gc.second->client_id );
  2850. p->packetLength += static_cast<int16>( sizeof( p->castle_list[0] ) );
  2851. ++i;
  2852. }
  2853. }
  2854. clif_send(p, p->packetLength, &sd.bl, SELF);
  2855. }
  2856. #endif
  2857. }
  2858. /*==========================================
  2859. * Send castle info Economy/Defence. [Asheraf] / [Balfear]
  2860. *------------------------------------------*/
  2861. void clif_guild_castleinfo(map_session_data& sd, std::shared_ptr<guild_castle> castle ){
  2862. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2863. if( castle->client_id == 0 ){
  2864. return;
  2865. }
  2866. struct PACKET_ZC_REQ_ACK_AGIT_INVESTMENT p = {};
  2867. p.packetType = HEADER_ZC_REQ_ACK_AGIT_INVESTMENT;
  2868. p.castle_id = static_cast<int8>( castle->client_id );
  2869. p.economy = castle->economy;
  2870. p.defense = castle->defense;
  2871. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2872. #endif
  2873. }
  2874. /*==========================================
  2875. * Show teleport request result. [Asheraf] / [Balfear]
  2876. *------------------------------------------*/
  2877. void clif_guild_castle_teleport_res(map_session_data& sd, enum e_siege_teleport_result result){
  2878. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2879. struct PACKET_ZC_REQ_ACK_MOVE_GUILD_AGIT p = {};
  2880. p.packetType = HEADER_ZC_REQ_ACK_MOVE_GUILD_AGIT;
  2881. p.result = static_cast<int16>( result );
  2882. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2883. #endif
  2884. }
  2885. /*==========================================
  2886. * Request castle info. [Asheraf] / [Balfear]
  2887. *------------------------------------------*/
  2888. void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){
  2889. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2890. const struct PACKET_CZ_REQ_AGIT_INVESTMENT* p = (struct PACKET_CZ_REQ_AGIT_INVESTMENT*)RFIFOP(fd, 0);
  2891. auto &g = sd->guild;
  2892. if (g == nullptr)
  2893. return;
  2894. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2895. if (gc == nullptr)
  2896. return;
  2897. if (gc->guild_id != g->guild.guild_id)
  2898. return;
  2899. clif_guild_castleinfo(*sd, gc);
  2900. #endif
  2901. }
  2902. /*==========================================
  2903. * Teleport to castle. [Asheraf] / [Balfear]
  2904. *------------------------------------------*/
  2905. void clif_parse_guild_castle_teleport_request(int fd, map_session_data* sd){
  2906. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2907. const struct PACKET_CZ_REQ_MOVE_GUILD_AGIT* p = (struct PACKET_CZ_REQ_MOVE_GUILD_AGIT*)RFIFOP(fd, 0);
  2908. auto &g = sd->guild;
  2909. if (g == nullptr)
  2910. return;
  2911. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2912. if (gc == nullptr)
  2913. return;
  2914. if (!gc->warp_enabled)
  2915. return;
  2916. if (gc->guild_id != g->guild.guild_id)
  2917. return;
  2918. if (map_getmapflag(sd->bl.m, MF_GVG_CASTLE)
  2919. || map_getmapflag(sd->bl.m, MF_NOTELEPORT)
  2920. || map_getmapflag(sd->bl.m, MF_NOWARP))
  2921. return;
  2922. uint32 zeny = gc->zeny;
  2923. switch( gc->type ){
  2924. case WOE_FIRST_EDITION:
  2925. if( agit_flag ){
  2926. zeny = gc->zeny_siege;
  2927. }
  2928. break;
  2929. case WOE_SECOND_EDITION:
  2930. if( agit2_flag ){
  2931. zeny = gc->zeny_siege;
  2932. }
  2933. break;
  2934. case WOE_THIRD_EDITION:
  2935. if( agit3_flag ){
  2936. zeny = gc->zeny_siege;
  2937. }
  2938. break;
  2939. }
  2940. if (zeny && pc_payzeny(sd, zeny, LOG_TYPE_OTHER)) {
  2941. clif_guild_castle_teleport_res(*sd, SIEGE_TP_NOT_ENOUGH_ZENY);
  2942. return;
  2943. }
  2944. pc_setpos(sd, gc->mapindex, gc->warp_x, gc->warp_y, CLR_OUTSIGHT);
  2945. #endif
  2946. }
  2947. /*==========================================
  2948. *
  2949. *------------------------------------------*/
  2950. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2951. map_session_data* sd = va_arg( ap, map_session_data* );
  2952. map_session_data* tsd = BL_CAST( BL_PC, bl );
  2953. nullpo_ret(sd);
  2954. nullpo_ret(tsd);
  2955. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2956. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2957. }
  2958. return 0;
  2959. }
  2960. /*==========================================
  2961. * Server tells all players that are allowed to view HP bars
  2962. * and are nearby 'sd' that 'sd' hp bar was updated.
  2963. *------------------------------------------*/
  2964. static int clif_hpmeter(map_session_data *sd)
  2965. {
  2966. nullpo_ret(sd);
  2967. map_foreachinallarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2968. return 0;
  2969. }
  2970. /**
  2971. * Send HP bar update to others.
  2972. * @param sd: Player invoking update
  2973. */
  2974. void clif_update_hp(map_session_data &sd) {
  2975. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2976. clif_hpmeter(&sd);
  2977. if (!battle_config.party_hp_mode && sd.status.party_id)
  2978. clif_party_hp( sd );
  2979. if (sd.bg_id)
  2980. clif_bg_hp(&sd);
  2981. }
  2982. /// Notifies client of a character parameter change.
  2983. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2984. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2985. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2986. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2987. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2988. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2989. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2990. /// TODO: Extract individual packets.
  2991. /// FIXME: Packet lengths from packet_len(cmd)
  2992. void clif_updatestatus(map_session_data *sd,int type)
  2993. {
  2994. int fd,len=8;
  2995. nullpo_retv(sd);
  2996. fd=sd->fd;
  2997. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2998. return;
  2999. WFIFOHEAD(fd, 14);
  3000. WFIFOW(fd,0)=0xb0;
  3001. WFIFOW(fd,2)=type;
  3002. switch(type){
  3003. // 00b0
  3004. case SP_WEIGHT:
  3005. pc_updateweightstatus(sd);
  3006. WFIFOHEAD(fd,14);
  3007. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  3008. WFIFOW(fd,2)=type;
  3009. WFIFOL(fd,4)=sd->weight;
  3010. break;
  3011. case SP_MAXWEIGHT:
  3012. WFIFOL(fd,4)=sd->max_weight;
  3013. break;
  3014. case SP_SPEED:
  3015. WFIFOL(fd,4)=sd->battle_status.speed;
  3016. break;
  3017. case SP_BASELEVEL:
  3018. WFIFOL(fd,4)=sd->status.base_level;
  3019. break;
  3020. case SP_JOBLEVEL:
  3021. WFIFOL(fd,4)=sd->status.job_level;
  3022. break;
  3023. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  3024. WFIFOL(fd,4)=sd->status.karma;
  3025. break;
  3026. case SP_MANNER:
  3027. WFIFOL(fd,4)=sd->status.manner;
  3028. break;
  3029. case SP_STATUSPOINT:
  3030. WFIFOL(fd,4)=sd->status.status_point;
  3031. break;
  3032. case SP_SKILLPOINT:
  3033. WFIFOL(fd,4)=sd->status.skill_point;
  3034. break;
  3035. case SP_HIT:
  3036. WFIFOL(fd,4)=sd->battle_status.hit;
  3037. break;
  3038. case SP_FLEE1:
  3039. WFIFOL(fd,4)=sd->battle_status.flee;
  3040. break;
  3041. case SP_FLEE2:
  3042. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  3043. break;
  3044. case SP_MAXHP:
  3045. WFIFOL(fd,4)=sd->battle_status.max_hp;
  3046. break;
  3047. case SP_MAXSP:
  3048. WFIFOL(fd,4)=sd->battle_status.max_sp;
  3049. break;
  3050. case SP_HP:
  3051. // On officials the HP never go below 1, even if you die [Lemongrass]
  3052. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  3053. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  3054. break;
  3055. case SP_SP:
  3056. WFIFOL(fd,4)=sd->battle_status.sp;
  3057. break;
  3058. case SP_ASPD:
  3059. WFIFOL(fd,4)=sd->battle_status.amotion;
  3060. break;
  3061. case SP_ATK1:
  3062. WFIFOL(fd,4)=pc_leftside_atk(sd);
  3063. break;
  3064. case SP_DEF1:
  3065. WFIFOL(fd,4)=pc_leftside_def(sd);
  3066. break;
  3067. case SP_MDEF1:
  3068. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  3069. break;
  3070. case SP_ATK2:
  3071. WFIFOL(fd,4)=pc_rightside_atk(sd);
  3072. break;
  3073. case SP_DEF2:
  3074. WFIFOL(fd,4)=pc_rightside_def(sd);
  3075. break;
  3076. case SP_MDEF2: {
  3077. //negative check (in case you have something like Berserk active)
  3078. int mdef2 = pc_rightside_mdef(sd);
  3079. WFIFOL(fd,4)=
  3080. #ifndef RENEWAL
  3081. ( mdef2 < 0 ) ? 0 :
  3082. #endif
  3083. mdef2;
  3084. }
  3085. break;
  3086. case SP_CRITICAL:
  3087. WFIFOL(fd,4)=sd->battle_status.cri/10;
  3088. break;
  3089. case SP_MATK1:
  3090. WFIFOL(fd,4)=pc_rightside_matk(sd);
  3091. break;
  3092. case SP_MATK2:
  3093. WFIFOL(fd,4)=pc_leftside_matk(sd);
  3094. break;
  3095. case SP_ZENY:
  3096. WFIFOW(fd,0)=0xb1;
  3097. WFIFOL(fd,4)=sd->status.zeny;
  3098. break;
  3099. #if PACKETVER >= 20170830
  3100. case SP_BASEEXP:
  3101. WFIFOW(fd,0)=0xacb;
  3102. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  3103. len = packet_len(0xacb);
  3104. break;
  3105. case SP_JOBEXP:
  3106. WFIFOW(fd,0)=0xacb;
  3107. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  3108. len = packet_len(0xacb);
  3109. break;
  3110. case SP_NEXTBASEEXP:
  3111. WFIFOW(fd,0)=0xacb;
  3112. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  3113. len = packet_len(0xacb);
  3114. break;
  3115. case SP_NEXTJOBEXP:
  3116. WFIFOW(fd,0)=0xacb;
  3117. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3118. len = packet_len(0xacb);
  3119. break;
  3120. #else
  3121. case SP_BASEEXP:
  3122. WFIFOW(fd,0)=0xb1;
  3123. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3124. break;
  3125. case SP_JOBEXP:
  3126. WFIFOW(fd,0)=0xb1;
  3127. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3128. break;
  3129. case SP_NEXTBASEEXP:
  3130. WFIFOW(fd,0)=0xb1;
  3131. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3132. break;
  3133. case SP_NEXTJOBEXP:
  3134. WFIFOW(fd,0)=0xb1;
  3135. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3136. break;
  3137. #endif
  3138. /**
  3139. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3140. **/
  3141. case SP_USTR:
  3142. case SP_UAGI:
  3143. case SP_UVIT:
  3144. case SP_UINT:
  3145. case SP_UDEX:
  3146. case SP_ULUK:
  3147. WFIFOW(fd,0)=0xbe;
  3148. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3149. len=5;
  3150. break;
  3151. /**
  3152. * Tells the client how far it is allowed to attack (weapon range)
  3153. **/
  3154. case SP_ATTACKRANGE:
  3155. WFIFOW(fd,0)=0x13a;
  3156. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3157. len=4;
  3158. break;
  3159. case SP_STR:
  3160. WFIFOW(fd,0)=0x141;
  3161. WFIFOL(fd,2)=type;
  3162. WFIFOL(fd,6)=sd->status.str;
  3163. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3164. len=14;
  3165. break;
  3166. case SP_AGI:
  3167. WFIFOW(fd,0)=0x141;
  3168. WFIFOL(fd,2)=type;
  3169. WFIFOL(fd,6)=sd->status.agi;
  3170. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3171. len=14;
  3172. break;
  3173. case SP_VIT:
  3174. WFIFOW(fd,0)=0x141;
  3175. WFIFOL(fd,2)=type;
  3176. WFIFOL(fd,6)=sd->status.vit;
  3177. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3178. len=14;
  3179. break;
  3180. case SP_INT:
  3181. WFIFOW(fd,0)=0x141;
  3182. WFIFOL(fd,2)=type;
  3183. WFIFOL(fd,6)=sd->status.int_;
  3184. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3185. len=14;
  3186. break;
  3187. case SP_DEX:
  3188. WFIFOW(fd,0)=0x141;
  3189. WFIFOL(fd,2)=type;
  3190. WFIFOL(fd,6)=sd->status.dex;
  3191. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3192. len=14;
  3193. break;
  3194. case SP_LUK:
  3195. WFIFOW(fd,0)=0x141;
  3196. WFIFOL(fd,2)=type;
  3197. WFIFOL(fd,6)=sd->status.luk;
  3198. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3199. len=14;
  3200. break;
  3201. case SP_CARTINFO:
  3202. WFIFOW(fd,0)=0x121;
  3203. WFIFOW(fd,2)=sd->cart_num;
  3204. WFIFOW(fd,4)=MAX_CART;
  3205. WFIFOL(fd,6)=sd->cart_weight;
  3206. WFIFOL(fd,10)=sd->cart_weight_max;
  3207. len=14;
  3208. break;
  3209. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3210. case SP_AP:
  3211. WFIFOL(fd, 4) = sd->battle_status.ap;
  3212. break;
  3213. case SP_TRAITPOINT:
  3214. WFIFOL(fd, 4) = sd->status.trait_point;
  3215. break;
  3216. case SP_MAXAP:
  3217. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3218. break;
  3219. case SP_POW:
  3220. WFIFOW(fd, 0) = 0x141;
  3221. WFIFOL(fd, 2) = type;
  3222. WFIFOL(fd, 6) = sd->status.pow;
  3223. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3224. len = 14;
  3225. break;
  3226. case SP_STA:
  3227. WFIFOW(fd, 0) = 0x141;
  3228. WFIFOL(fd, 2) = type;
  3229. WFIFOL(fd, 6) = sd->status.sta;
  3230. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3231. len = 14;
  3232. break;
  3233. case SP_WIS:
  3234. WFIFOW(fd, 0) = 0x141;
  3235. WFIFOL(fd, 2) = type;
  3236. WFIFOL(fd, 6) = sd->status.wis;
  3237. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3238. len = 14;
  3239. break;
  3240. case SP_SPL:
  3241. WFIFOW(fd, 0) = 0x141;
  3242. WFIFOL(fd, 2) = type;
  3243. WFIFOL(fd, 6) = sd->status.spl;
  3244. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3245. len = 14;
  3246. break;
  3247. case SP_CON:
  3248. WFIFOW(fd, 0) = 0x141;
  3249. WFIFOL(fd, 2) = type;
  3250. WFIFOL(fd, 6) = sd->status.con;
  3251. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3252. len = 14;
  3253. break;
  3254. case SP_CRT:
  3255. WFIFOW(fd, 0) = 0x141;
  3256. WFIFOL(fd, 2) = type;
  3257. WFIFOL(fd, 6) = sd->status.crt;
  3258. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3259. len = 14;
  3260. break;
  3261. case SP_UPOW:
  3262. case SP_USTA:
  3263. case SP_UWIS:
  3264. case SP_USPL:
  3265. case SP_UCON:
  3266. case SP_UCRT:
  3267. WFIFOW(fd, 0) = 0xbe;
  3268. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3269. len = 5;
  3270. break;
  3271. case SP_PATK:
  3272. WFIFOL(fd, 4) = sd->battle_status.patk;
  3273. break;
  3274. case SP_SMATK:
  3275. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3276. break;
  3277. case SP_RES:
  3278. WFIFOL(fd, 4) = sd->battle_status.res;
  3279. break;
  3280. case SP_MRES:
  3281. WFIFOL(fd, 4) = sd->battle_status.mres;
  3282. break;
  3283. case SP_HPLUS:
  3284. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3285. break;
  3286. case SP_CRATE:
  3287. WFIFOL(fd, 4) = sd->battle_status.crate;
  3288. break;
  3289. #else
  3290. case SP_AP:
  3291. case SP_TRAITPOINT:
  3292. case SP_MAXAP:
  3293. case SP_POW:
  3294. case SP_STA:
  3295. case SP_WIS:
  3296. case SP_SPL:
  3297. case SP_CON:
  3298. case SP_CRT:
  3299. case SP_UPOW:
  3300. case SP_USTA:
  3301. case SP_UWIS:
  3302. case SP_USPL:
  3303. case SP_UCON:
  3304. case SP_UCRT:
  3305. case SP_PATK:
  3306. case SP_SMATK:
  3307. case SP_RES:
  3308. case SP_MRES:
  3309. case SP_HPLUS:
  3310. case SP_CRATE:
  3311. // 4th job status are not supported by older clients
  3312. return;
  3313. #endif
  3314. default:
  3315. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3316. return;
  3317. }
  3318. WFIFOSET(fd,len);
  3319. // Additional update packets that should be sent right after
  3320. switch( type ){
  3321. case SP_BASELEVEL:
  3322. if( sd->status.party_id ){
  3323. struct party_data* p;
  3324. int i;
  3325. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3326. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3327. if( i < MAX_PARTY ){
  3328. p->party.member[i].lv = sd->status.base_level;
  3329. clif_party_job_and_level( *sd );
  3330. }
  3331. }
  3332. }
  3333. break;
  3334. case SP_HP:
  3335. clif_update_hp(*sd);
  3336. break;
  3337. }
  3338. }
  3339. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3340. /// 01ab <account id>.L <var id>.W <value>.L
  3341. void clif_changestatus(map_session_data* sd,int type,int val)
  3342. {
  3343. unsigned char buf[12];
  3344. nullpo_retv(sd);
  3345. WBUFW(buf,0)=0x1ab;
  3346. WBUFL(buf,2)=sd->bl.id;
  3347. WBUFW(buf,6)=type;
  3348. switch(type)
  3349. {
  3350. case SP_MANNER:
  3351. WBUFL(buf,8)=val;
  3352. break;
  3353. default:
  3354. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3355. return;
  3356. }
  3357. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3358. }
  3359. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3360. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3361. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3362. struct PACKET_ZC_SPRITE_CHANGE p;
  3363. p.packetType = sendLookType;
  3364. p.AID = id;
  3365. p.type = type;
  3366. p.val = val;
  3367. #if PACKETVER >= 4
  3368. p.val2 = val2;
  3369. #endif
  3370. clif_send( &p, sizeof( p ), bl, target );
  3371. }
  3372. /// Updates sprite/style properties of an object.
  3373. void clif_changelook(struct block_list *bl, int type, int val) {
  3374. map_session_data* sd;
  3375. status_change* sc;
  3376. struct view_data* vd;
  3377. enum send_target target = AREA;
  3378. int val2 = 0;
  3379. nullpo_retv(bl);
  3380. sd = BL_CAST(BL_PC, bl);
  3381. sc = status_get_sc(bl);
  3382. vd = status_get_viewdata(bl);
  3383. if( vd ) //temp hack to let Warp Portal change appearance
  3384. switch(type) {
  3385. case LOOK_WEAPON:
  3386. if (sd) {
  3387. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3388. val = vd->weapon;
  3389. }
  3390. else
  3391. vd->weapon = val;
  3392. break;
  3393. case LOOK_SHIELD:
  3394. if (sd) {
  3395. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3396. val = vd->shield;
  3397. }
  3398. else
  3399. vd->shield = val;
  3400. break;
  3401. case LOOK_BASE:
  3402. if (!sd)
  3403. break;
  3404. if ( val == JT_INVISIBLE )
  3405. return;
  3406. if (sd->sc.option&OPTION_COSTUME)
  3407. vd->weapon = vd->shield = 0;
  3408. if (!vd->cloth_color)
  3409. break;
  3410. if (sd) {
  3411. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3412. vd->cloth_color = 0;
  3413. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3414. vd->cloth_color = 0;
  3415. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3416. vd->cloth_color = 0;
  3417. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3418. vd->cloth_color = 0;
  3419. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3420. vd->cloth_color = 0;
  3421. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3422. vd->body_style = 0;
  3423. }
  3424. break;
  3425. case LOOK_HAIR:
  3426. vd->hair_style = val;
  3427. break;
  3428. case LOOK_HEAD_BOTTOM:
  3429. vd->head_bottom = val;
  3430. break;
  3431. case LOOK_HEAD_TOP:
  3432. vd->head_top = val;
  3433. break;
  3434. case LOOK_HEAD_MID:
  3435. vd->head_mid = val;
  3436. break;
  3437. case LOOK_HAIR_COLOR:
  3438. vd->hair_color = val;
  3439. break;
  3440. case LOOK_CLOTHES_COLOR:
  3441. if (val && sd) {
  3442. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3443. val = 0;
  3444. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3445. val = 0;
  3446. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3447. val = 0;
  3448. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3449. val = 0;
  3450. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3451. val = 0;
  3452. }
  3453. vd->cloth_color = val;
  3454. break;
  3455. case LOOK_SHOES:
  3456. #if PACKETVER > 3
  3457. if (sd) {
  3458. int n;
  3459. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3460. if(sd->inventory_data[n]->view_id > 0)
  3461. val = sd->inventory_data[n]->view_id;
  3462. else
  3463. val = sd->inventory.u.items_inventory[n].nameid;
  3464. } else
  3465. val = 0;
  3466. }
  3467. #endif
  3468. //Shoes? No packet uses this....
  3469. break;
  3470. case LOOK_BODY:
  3471. // unknown purpose
  3472. break;
  3473. case LOOK_ROBE:
  3474. #if PACKETVER < 20110111
  3475. return;
  3476. #else
  3477. vd->robe = val;
  3478. #endif
  3479. break;
  3480. case LOOK_BODY2:
  3481. #if PACKETVER < 20150513
  3482. return;
  3483. #else
  3484. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3485. val = 0;
  3486. vd->body_style = val;
  3487. #endif
  3488. break;
  3489. }
  3490. // prevent leaking the presence of GM-hidden objects
  3491. if( sc && sc->option&OPTION_INVISIBLE )
  3492. target = SELF;
  3493. #if PACKETVER < 4
  3494. if (target != SELF && bl->type == BL_NPC && (((TBL_NPC*)bl)->is_invisible))
  3495. target = SELF;
  3496. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3497. #else
  3498. if (bl->type != BL_NPC) {
  3499. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3500. type = LOOK_WEAPON;
  3501. val = (vd ? vd->weapon : 0);
  3502. val2 = (vd ? vd->shield : 0);
  3503. }
  3504. if (disguised(bl)) {
  3505. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3506. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3507. } else
  3508. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3509. } else
  3510. unit_refresh(bl);
  3511. #endif
  3512. }
  3513. //Sends a change-base-look packet required for traps as they are triggered.
  3514. void clif_changetraplook(struct block_list *bl,int val) {
  3515. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3516. }
  3517. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3518. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3519. clif_sprite_change(bl, id, type, val, 0, target);
  3520. }
  3521. /// Character status (ZC_STATUS).
  3522. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3523. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3524. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3525. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3526. void clif_initialstatus(map_session_data *sd) {
  3527. int fd, mdef2;
  3528. unsigned char *buf;
  3529. nullpo_retv(sd);
  3530. fd=sd->fd;
  3531. WFIFOHEAD(fd, packet_len(0xbd));
  3532. buf = WFIFOP(fd,0);
  3533. WBUFW(buf,0) = 0xbd;
  3534. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3535. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3536. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3537. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3538. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3539. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3540. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3541. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3542. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3543. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3544. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3545. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3546. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3547. WBUFW(buf,16) = pc_leftside_atk(sd);
  3548. WBUFW(buf,18) = pc_rightside_atk(sd);
  3549. WBUFW(buf,20) = pc_rightside_matk(sd);
  3550. WBUFW(buf,22) = pc_leftside_matk(sd);
  3551. WBUFW(buf,24) = pc_leftside_def(sd);
  3552. WBUFW(buf,26) = pc_rightside_def(sd);
  3553. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3554. mdef2 = pc_rightside_mdef(sd);
  3555. WBUFW(buf,30) =
  3556. #ifndef RENEWAL
  3557. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3558. #endif
  3559. mdef2;
  3560. WBUFW(buf,32) = sd->battle_status.hit;
  3561. WBUFW(buf,34) = sd->battle_status.flee;
  3562. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3563. WBUFW(buf,38) = sd->battle_status.cri/10;
  3564. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3565. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3566. WFIFOSET(fd, packet_len(0xbd));
  3567. clif_updatestatus(sd, SP_STR);
  3568. clif_updatestatus(sd, SP_AGI);
  3569. clif_updatestatus(sd, SP_VIT);
  3570. clif_updatestatus(sd, SP_INT);
  3571. clif_updatestatus(sd, SP_DEX);
  3572. clif_updatestatus(sd, SP_LUK);
  3573. clif_updatestatus(sd, SP_ATTACKRANGE);
  3574. clif_updatestatus(sd, SP_ASPD);
  3575. #ifdef RENEWAL
  3576. clif_updatestatus(sd, SP_POW);
  3577. clif_updatestatus(sd, SP_STA);
  3578. clif_updatestatus(sd, SP_WIS);
  3579. clif_updatestatus(sd, SP_SPL);
  3580. clif_updatestatus(sd, SP_CON);
  3581. clif_updatestatus(sd, SP_CRT);
  3582. clif_updatestatus(sd, SP_PATK);
  3583. clif_updatestatus(sd, SP_SMATK);
  3584. clif_updatestatus(sd, SP_RES);
  3585. clif_updatestatus(sd, SP_MRES);
  3586. clif_updatestatus(sd, SP_HPLUS);
  3587. clif_updatestatus(sd, SP_CRATE);
  3588. clif_updatestatus(sd, SP_TRAITPOINT);
  3589. clif_updatestatus(sd, SP_AP);
  3590. clif_updatestatus(sd, SP_MAXAP);
  3591. clif_updatestatus(sd, SP_UPOW);
  3592. clif_updatestatus(sd, SP_USTA);
  3593. clif_updatestatus(sd, SP_UWIS);
  3594. clif_updatestatus(sd, SP_USPL);
  3595. clif_updatestatus(sd, SP_UCON);
  3596. clif_updatestatus(sd, SP_UCRT);
  3597. #endif
  3598. }
  3599. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3600. /// 013c <index>.W
  3601. void clif_arrowequip(map_session_data *sd,int val) {
  3602. int fd;
  3603. nullpo_retv(sd);
  3604. #if PACKETVER >= 20121128
  3605. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3606. #endif
  3607. fd=sd->fd;
  3608. WFIFOHEAD(fd, packet_len(0x013c));
  3609. WFIFOW(fd,0) = 0x013c;
  3610. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3611. WFIFOSET(fd, packet_len(0x013c));
  3612. }
  3613. /// Ammunition action message (ZC_ACTION_FAILURE).
  3614. /// 013b <type>.W
  3615. /// type:
  3616. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3617. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3618. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3619. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3620. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3621. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3622. void clif_arrow_fail(map_session_data *sd,int type) {
  3623. int fd;
  3624. nullpo_retv(sd);
  3625. fd=sd->fd;
  3626. WFIFOHEAD(fd, packet_len(0x013b));
  3627. WFIFOW(fd,0) = 0x013b;
  3628. WFIFOW(fd,2) = type;
  3629. WFIFOSET(fd, packet_len(0x013b));
  3630. }
  3631. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3632. /// 01ad <packet len>.W { <name id>.W }*
  3633. void clif_arrow_create_list( map_session_data *sd ){
  3634. nullpo_retv( sd );
  3635. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3636. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3637. int count = 0;
  3638. for (const auto &it : skill_arrow_db) {
  3639. t_itemid nameid = it.second->nameid;
  3640. if( !item_db.exists( nameid ) ){
  3641. continue;
  3642. }
  3643. int index = pc_search_inventory( sd, nameid );
  3644. if( index < 0 ){
  3645. continue;
  3646. }
  3647. if( sd->inventory.u.items_inventory[index].equip ){
  3648. continue;
  3649. }
  3650. if( !sd->inventory.u.items_inventory[index].identify ){
  3651. continue;
  3652. }
  3653. p->items[count].itemId = client_nameid( nameid );
  3654. count++;
  3655. }
  3656. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3657. clif_send( p, p->packetLength, &sd->bl, SELF );
  3658. if( count > 0 ){
  3659. sd->menuskill_id = AC_MAKINGARROW;
  3660. sd->menuskill_val = count;
  3661. }
  3662. }
  3663. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3664. /// 00bc <status id>.W <result>.B <value>.B
  3665. /// status id:
  3666. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3667. /// result:
  3668. /// 0 = failure
  3669. /// 1 = success
  3670. void clif_statusupack(map_session_data *sd,int type,int ok,int val) {
  3671. int fd;
  3672. nullpo_retv(sd);
  3673. fd=sd->fd;
  3674. WFIFOHEAD(fd, packet_len(0xbc));
  3675. WFIFOW(fd,0) = 0xbc;
  3676. WFIFOW(fd,2) = type;
  3677. WFIFOB(fd,4) = ok;
  3678. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3679. WFIFOSET(fd, packet_len(0xbc));
  3680. }
  3681. /// Notifies the client about the result of a request to equip an item.
  3682. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3683. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3684. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3685. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3686. /// @ok: //inversed forv2 v5
  3687. /// 0 = failure
  3688. /// 1 = success
  3689. /// 2 = failure due to low level
  3690. void clif_equipitemack( map_session_data& sd, uint8 flag, int index, int pos ){
  3691. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3692. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3693. p.index = client_index( index );
  3694. p.wearLocation = pos;
  3695. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3696. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3697. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3698. }else{
  3699. p.wItemSpriteNumber = 0;
  3700. }
  3701. #endif
  3702. p.result = flag;
  3703. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3704. }
  3705. /// Notifies the client about the result of a request to take off an item.
  3706. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3707. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3708. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3709. /// @ok : //inversed for v2 v5
  3710. /// 0 = failure
  3711. /// 1 = success
  3712. void clif_unequipitemack(map_session_data *sd,int n,int pos,int ok)
  3713. {
  3714. int fd, header, offs = 0;
  3715. #if PACKETVER >= 20130000
  3716. header = 0x99a;
  3717. ok = ok ? 0 : 1;
  3718. #elif PACKETVER >= 20110824
  3719. header = 0x8d1;
  3720. ok = ok ? 0 : 1;
  3721. #else
  3722. header = 0xac;
  3723. #endif
  3724. nullpo_retv(sd);
  3725. fd=sd->fd;
  3726. WFIFOHEAD(fd, packet_len(header));
  3727. WFIFOW(fd,offs+0) = header;
  3728. WFIFOW(fd,offs+2) = n+2;
  3729. #if PACKETVER >= 20130000
  3730. WFIFOL(fd,offs+4) = pos;
  3731. offs += 2;
  3732. #else
  3733. WFIFOW(fd,offs+4) = pos;
  3734. #endif
  3735. WFIFOB(fd,offs+6) = ok;
  3736. WFIFOSET(fd, packet_len(header));
  3737. }
  3738. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3739. /// 019b <id>.L <effect id>.L
  3740. /// effect id:
  3741. /// 0 = base level up
  3742. /// 1 = job level up
  3743. /// 2 = refine failure
  3744. /// 3 = refine success
  3745. /// 4 = game over
  3746. /// 5 = pharmacy success
  3747. /// 6 = pharmacy failure
  3748. /// 7 = base level up (super novice)
  3749. /// 8 = job level up (super novice)
  3750. /// 9 = base level up (taekwon)
  3751. void clif_misceffect(struct block_list* bl,int type)
  3752. {
  3753. unsigned char buf[32];
  3754. nullpo_retv(bl);
  3755. WBUFW(buf,0) = 0x19b;
  3756. WBUFL(buf,2) = bl->id;
  3757. WBUFL(buf,6) = type;
  3758. clif_send(buf,packet_len(0x19b),bl,AREA);
  3759. }
  3760. /// Notifies clients in the area of a state change.
  3761. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3762. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3763. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3764. nullpo_retv( bl );
  3765. status_change* sc = status_get_sc( bl );
  3766. //How can an option change if there's no sc?
  3767. if( sc == nullptr ){
  3768. return;
  3769. }
  3770. map_session_data* sd = BL_CAST( BL_PC, bl );
  3771. struct PACKET_ZC_STATE_CHANGE p;
  3772. p.packetType = HEADER_ZC_STATE_CHANGE;
  3773. p.AID = bl->id;
  3774. p.bodyState = sc->opt1;
  3775. p.healthState = sc->opt2;
  3776. p.effectState = sc->option;
  3777. p.isPKModeON = sd ? sd->status.karma : false;
  3778. if( target == nullptr ){
  3779. if( disguised( bl ) ){
  3780. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3781. p.AID = disguised_bl_id( p.AID );
  3782. clif_send( &p, sizeof( p ), bl, SELF );
  3783. p.AID = disguised_bl_id( p.AID );
  3784. p.effectState = OPTION_INVISIBLE;
  3785. clif_send( &p, sizeof( p ), bl, SELF );
  3786. }else{
  3787. clif_send( &p, sizeof( p ), bl, AREA );
  3788. }
  3789. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3790. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3791. if( sc->getSCE(SC_PROVOKE) ){
  3792. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3793. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3794. }
  3795. }else{
  3796. if( disguised( bl ) ){
  3797. p.AID = disguised_bl_id( p.AID );
  3798. clif_send( &p, sizeof( p ), target, SELF );
  3799. p.AID = disguised_bl_id( p.AID );
  3800. p.effectState = OPTION_INVISIBLE;
  3801. clif_send( &p, sizeof( p ), target, SELF );
  3802. }else{
  3803. clif_send( &p, sizeof( p ), target, SELF );
  3804. }
  3805. }
  3806. }
  3807. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3808. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3809. void clif_changeoption2(struct block_list* bl)
  3810. {
  3811. unsigned char buf[20];
  3812. status_change *sc;
  3813. sc = status_get_sc(bl);
  3814. if (!sc) return; //How can an option change if there's no sc?
  3815. WBUFW(buf,0) = 0x28a;
  3816. WBUFL(buf,2) = bl->id;
  3817. WBUFL(buf,6) = sc->option;
  3818. WBUFL(buf,10) = clif_setlevel(bl);
  3819. WBUFL(buf,14) = sc->opt3;
  3820. if(disguised(bl)) {
  3821. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3822. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3823. clif_send(buf,packet_len(0x28a),bl,SELF);
  3824. WBUFL(buf,2) = bl->id;
  3825. WBUFL(buf,6) = OPTION_INVISIBLE;
  3826. clif_send(buf,packet_len(0x28a),bl,SELF);
  3827. } else
  3828. clif_send(buf,packet_len(0x28a),bl,AREA);
  3829. }
  3830. /// Notifies the client about the result of an item use request.
  3831. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3832. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3833. void clif_useitemack( map_session_data *sd, int index, int amount, bool ok ){
  3834. nullpo_retv( sd );
  3835. int fd = sd->fd;
  3836. if( !session_isActive( fd ) ){
  3837. return;
  3838. }
  3839. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3840. return;
  3841. }
  3842. struct PACKET_ZC_USE_ITEM_ACK p;
  3843. p.packetType = useItemAckType;
  3844. p.index = index + 2;
  3845. #if PACKETVER > 3
  3846. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3847. p.AID = sd->bl.id;
  3848. #endif
  3849. p.amount = amount;
  3850. p.result = ok;
  3851. if( !ok ){
  3852. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3853. }else{
  3854. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3855. }
  3856. }
  3857. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3858. /// 00d6 <flag>.B
  3859. /// flag:
  3860. /// 0 = Room has been successfully created (opens chat room)
  3861. /// 1 = Room limit exceeded
  3862. /// 2 = Same room already exists
  3863. void clif_createchat(map_session_data* sd, int flag)
  3864. {
  3865. int fd;
  3866. nullpo_retv(sd);
  3867. fd = sd->fd;
  3868. WFIFOHEAD(fd,packet_len(0xd6));
  3869. WFIFOW(fd,0) = 0xd6;
  3870. WFIFOB(fd,2) = flag;
  3871. WFIFOSET(fd,packet_len(0xd6));
  3872. }
  3873. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3874. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3875. /// type:
  3876. /// 0 = private (password protected)
  3877. /// 1 = public
  3878. /// 2 = arena (npc waiting room)
  3879. /// 3 = PK zone (non-clickable)
  3880. void clif_dispchat(struct chat_data* cd, int fd)
  3881. {
  3882. unsigned char buf[128];
  3883. uint8 type;
  3884. if( cd == NULL || cd->owner == NULL )
  3885. return;
  3886. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3887. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3888. : 1;
  3889. WBUFW(buf, 0) = 0xd7;
  3890. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3891. WBUFL(buf, 4) = cd->owner->id;
  3892. WBUFL(buf, 8) = cd->bl.id;
  3893. WBUFW(buf,12) = cd->limit;
  3894. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3895. WBUFB(buf,16) = type;
  3896. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3897. if( session_isActive(fd) ) {
  3898. WFIFOHEAD(fd,WBUFW(buf,2));
  3899. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3900. WFIFOSET(fd,WBUFW(buf,2));
  3901. } else {
  3902. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3903. }
  3904. }
  3905. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3906. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3907. /// type:
  3908. /// 0 = private (password protected)
  3909. /// 1 = public
  3910. /// 2 = arena (npc waiting room)
  3911. /// 3 = PK zone (non-clickable)
  3912. void clif_changechatstatus(struct chat_data* cd)
  3913. {
  3914. unsigned char buf[128];
  3915. uint8 type;
  3916. if( cd == NULL || cd->usersd[0] == NULL )
  3917. return;
  3918. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3919. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3920. : 1;
  3921. WBUFW(buf, 0) = 0xdf;
  3922. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3923. WBUFL(buf, 4) = cd->owner->id;
  3924. WBUFL(buf, 8) = cd->bl.id;
  3925. WBUFW(buf,12) = cd->limit;
  3926. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3927. WBUFB(buf,16) = type;
  3928. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3929. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3930. }
  3931. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3932. /// 00d8 <chat id>.L
  3933. void clif_clearchat(struct chat_data *cd,int fd)
  3934. {
  3935. unsigned char buf[32];
  3936. nullpo_retv(cd);
  3937. WBUFW(buf,0) = 0xd8;
  3938. WBUFL(buf,2) = cd->bl.id;
  3939. if( session_isActive(fd) ) {
  3940. WFIFOHEAD(fd,packet_len(0xd8));
  3941. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3942. WFIFOSET(fd,packet_len(0xd8));
  3943. } else {
  3944. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3945. }
  3946. }
  3947. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3948. /// 00da <result>.B
  3949. /// result:
  3950. /// 0 = room full
  3951. /// 1 = wrong password
  3952. /// 2 = kicked
  3953. /// 3 = success (no message)
  3954. /// 4 = no enough zeny
  3955. /// 5 = too low level
  3956. /// 6 = too high level
  3957. /// 7 = unsuitable job class
  3958. void clif_joinchatfail(map_session_data *sd,int flag)
  3959. {
  3960. int fd;
  3961. nullpo_retv(sd);
  3962. fd = sd->fd;
  3963. WFIFOHEAD(fd,packet_len(0xda));
  3964. WFIFOW(fd,0) = 0xda;
  3965. WFIFOB(fd,2) = flag;
  3966. WFIFOSET(fd,packet_len(0xda));
  3967. }
  3968. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3969. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3970. /// role:
  3971. /// 0 = owner (menu)
  3972. /// 1 = normal
  3973. void clif_joinchatok(map_session_data *sd,struct chat_data* cd)
  3974. {
  3975. int fd;
  3976. int i,t;
  3977. nullpo_retv(sd);
  3978. nullpo_retv(cd);
  3979. fd = sd->fd;
  3980. if (!session_isActive(fd))
  3981. return;
  3982. t = (int)(cd->owner->type == BL_NPC);
  3983. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3984. WFIFOW(fd, 0) = 0xdb;
  3985. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3986. WFIFOL(fd, 4) = cd->bl.id;
  3987. if(cd->owner->type == BL_NPC){
  3988. WFIFOL(fd, 30) = 1;
  3989. WFIFOL(fd, 8) = 0;
  3990. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3991. for (i = 0; i < cd->users; i++) {
  3992. WFIFOL(fd, 8+(i+1)*28) = 1;
  3993. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3994. }
  3995. }else{
  3996. for (i = 0; i < cd->users; i++) {
  3997. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3998. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3999. }
  4000. }
  4001. WFIFOSET(fd, WFIFOW(fd, 2));
  4002. }
  4003. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  4004. /// 00dc <users>.W <name>.24B
  4005. void clif_addchat(struct chat_data* cd,map_session_data *sd)
  4006. {
  4007. unsigned char buf[29];
  4008. nullpo_retv(sd);
  4009. nullpo_retv(cd);
  4010. WBUFW(buf, 0) = 0xdc;
  4011. WBUFW(buf, 2) = cd->users;
  4012. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  4013. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  4014. }
  4015. /// Announce the new owner (ZC_ROLE_CHANGE).
  4016. /// 00e1 <role>.L <nick>.24B
  4017. /// role:
  4018. /// 0 = owner (menu)
  4019. /// 1 = normal
  4020. void clif_changechatowner(struct chat_data* cd, map_session_data* sd)
  4021. {
  4022. unsigned char buf[64];
  4023. nullpo_retv(sd);
  4024. nullpo_retv(cd);
  4025. WBUFW(buf, 0) = 0xe1;
  4026. WBUFL(buf, 2) = 1;
  4027. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  4028. WBUFW(buf,30) = 0xe1;
  4029. WBUFL(buf,32) = 0;
  4030. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  4031. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  4032. }
  4033. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  4034. /// 00dd <users>.W <nick>.24B <flag>.B
  4035. /// flag:
  4036. /// 0 = left
  4037. /// 1 = kicked
  4038. void clif_leavechat(struct chat_data* cd, map_session_data* sd, bool flag)
  4039. {
  4040. unsigned char buf[32];
  4041. nullpo_retv(sd);
  4042. nullpo_retv(cd);
  4043. WBUFW(buf, 0) = 0xdd;
  4044. WBUFW(buf, 2) = cd->users-1;
  4045. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  4046. WBUFB(buf,28) = flag;
  4047. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  4048. }
  4049. /// Opens a trade request window from char 'name'.
  4050. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  4051. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  4052. void clif_traderequest(map_session_data* sd, const char* name)
  4053. {
  4054. int fd = sd->fd;
  4055. #if PACKETVER < 6
  4056. WFIFOHEAD(fd,packet_len(0xe5));
  4057. WFIFOW(fd,0) = 0xe5;
  4058. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  4059. WFIFOSET(fd,packet_len(0xe5));
  4060. #else
  4061. map_session_data* tsd = map_id2sd(sd->trade_partner);
  4062. if( !tsd ) return;
  4063. WFIFOHEAD(fd,packet_len(0x1f4));
  4064. WFIFOW(fd,0) = 0x1f4;
  4065. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  4066. WFIFOL(fd,26) = tsd->status.char_id;
  4067. WFIFOW(fd,30) = tsd->status.base_level;
  4068. WFIFOSET(fd,packet_len(0x1f4));
  4069. #endif
  4070. }
  4071. /// Reply to a trade-request.
  4072. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  4073. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  4074. /// result:
  4075. /// 0 = Char is too far
  4076. /// 1 = Character does not exist
  4077. /// 2 = Trade failed
  4078. /// 3 = Accept
  4079. /// 4 = Cancel
  4080. /// 5 = Busy
  4081. void clif_tradestart(map_session_data* sd, uint8 type)
  4082. {
  4083. int fd = sd->fd;
  4084. map_session_data* tsd = map_id2sd(sd->trade_partner);
  4085. if( PACKETVER < 6 || !tsd ) {
  4086. WFIFOHEAD(fd,packet_len(0xe7));
  4087. WFIFOW(fd,0) = 0xe7;
  4088. WFIFOB(fd,2) = type;
  4089. WFIFOSET(fd,packet_len(0xe7));
  4090. } else {
  4091. WFIFOHEAD(fd,packet_len(0x1f5));
  4092. WFIFOW(fd,0) = 0x1f5;
  4093. WFIFOB(fd,2) = type;
  4094. WFIFOL(fd,3) = tsd->status.char_id;
  4095. WFIFOW(fd,7) = tsd->status.base_level;
  4096. WFIFOSET(fd,packet_len(0x1f5));
  4097. }
  4098. }
  4099. /// Notifies the client about an item from other player in current trade.
  4100. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4101. /// 080f <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM2)
  4102. /// 0a09 <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_EXCHANGE_ITEM3)
  4103. void clif_tradeadditem( map_session_data* sd, map_session_data* tsd, int index, int amount ){
  4104. nullpo_retv( sd );
  4105. nullpo_retv( tsd );
  4106. int fd = tsd->fd;
  4107. if( !session_isActive( fd ) ){
  4108. return;
  4109. }
  4110. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4111. if( index ){
  4112. index = server_index( index );
  4113. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4114. return;
  4115. }
  4116. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4117. #if PACKETVER >= 20100223
  4118. p.itemType = sd->inventory_data[index]->type;
  4119. #endif
  4120. p.identified = sd->inventory.u.items_inventory[index].identify;
  4121. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4122. p.refine = sd->inventory.u.items_inventory[index].refine;
  4123. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4124. #if PACKETVER >= 20150226
  4125. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[index] );
  4126. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4127. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4128. p.look = sd->inventory_data[index]->look;
  4129. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4130. #endif
  4131. #endif
  4132. }else{
  4133. p = {};
  4134. }
  4135. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4136. p.amount = amount;
  4137. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4138. }
  4139. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4140. /// 00ea <index>.W <result>.B
  4141. /// result:
  4142. /// 0 = success
  4143. /// 1 = overweight
  4144. /// 2 = trade canceled
  4145. void clif_tradeitemok(map_session_data& sd, int index, e_exitem_add_result result)
  4146. {
  4147. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4148. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4149. p.index = client_index(index);
  4150. p.result = static_cast<uint8>(result);
  4151. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4152. }
  4153. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4154. /// 00ec <who>.B
  4155. /// who:
  4156. /// 0 = self
  4157. /// 1 = other player
  4158. void clif_tradedeal_lock(map_session_data* sd, int fail)
  4159. {
  4160. int fd;
  4161. nullpo_retv(sd);
  4162. fd = sd->fd;
  4163. WFIFOHEAD(fd,packet_len(0xec));
  4164. WFIFOW(fd,0) = 0xec;
  4165. WFIFOB(fd,2) = fail;
  4166. WFIFOSET(fd,packet_len(0xec));
  4167. }
  4168. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4169. /// 00ee
  4170. void clif_tradecancelled(map_session_data* sd)
  4171. {
  4172. int fd;
  4173. nullpo_retv(sd);
  4174. fd = sd->fd;
  4175. WFIFOHEAD(fd,packet_len(0xee));
  4176. WFIFOW(fd,0) = 0xee;
  4177. WFIFOSET(fd,packet_len(0xee));
  4178. }
  4179. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4180. /// 00f0 <result>.B
  4181. /// result:
  4182. /// 0 = success
  4183. /// 1 = failure
  4184. void clif_tradecompleted(map_session_data* sd, int fail)
  4185. {
  4186. int fd;
  4187. nullpo_retv(sd);
  4188. fd = sd->fd;
  4189. WFIFOHEAD(fd,packet_len(0xf0));
  4190. WFIFOW(fd,0) = 0xf0;
  4191. WFIFOB(fd,2) = fail;
  4192. WFIFOSET(fd,packet_len(0xf0));
  4193. }
  4194. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4195. /// 00f1
  4196. /// NOTE: Unknown purpose. Items are not removed until the window is
  4197. /// refreshed (ex. by putting another item in there).
  4198. void clif_tradeundo(map_session_data* sd)
  4199. {
  4200. int fd = sd->fd;
  4201. WFIFOHEAD(fd,packet_len(0xf1));
  4202. WFIFOW(fd,0) = 0xf1;
  4203. WFIFOSET(fd,packet_len(0xf1));
  4204. }
  4205. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4206. /// 00f2 <current count>.W <max count>.W
  4207. void clif_updatestorageamount(map_session_data* sd, int amount, int max_amount)
  4208. {
  4209. int fd;
  4210. nullpo_retv(sd);
  4211. fd=sd->fd;
  4212. WFIFOHEAD(fd,packet_len(0xf2));
  4213. WFIFOW(fd,0) = 0xf2;
  4214. WFIFOW(fd,2) = amount;
  4215. WFIFOW(fd,4) = max_amount;
  4216. WFIFOSET(fd,packet_len(0xf2));
  4217. }
  4218. /// Notifies the client of an item being added to the storage.
  4219. /// 00f4 <index>.W <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE)
  4220. /// 01c4 <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE2)
  4221. /// 0a0a <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_ITEM_TO_STORE3)
  4222. void clif_storageitemadded( map_session_data* sd, struct item* i, int index, int amount ){
  4223. nullpo_retv( sd );
  4224. nullpo_retv( i );
  4225. int fd = sd->fd;
  4226. if( !session_isActive( fd ) ){
  4227. return;
  4228. }
  4229. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4230. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4231. p.index = client_storage_index( index ); // index
  4232. p.amount = amount; // amount
  4233. p.itemId = client_nameid( i->nameid ); // id
  4234. #if PACKETVER >= 5
  4235. p.itemType = itemtype( i->nameid ); //type
  4236. #endif
  4237. p.identified = i->identify; //identify flag
  4238. p.damaged = i->attribute; // attribute
  4239. p.refine = i->refine; //refine
  4240. clif_addcards( &p.slot, i );
  4241. #if PACKETVER_MAIN_NUM >= 20140813 || PACKETVER_RE_NUM >= 20140402 || defined(PACKETVER_ZERO)
  4242. clif_add_random_options( p.option_data, *i );
  4243. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20221024
  4244. p.grade = i->enchantgrade;
  4245. #endif
  4246. #endif
  4247. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4248. }
  4249. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4250. /// 00f6 <index>.W <amount>.L
  4251. void clif_storageitemremoved(map_session_data* sd, int index, int amount)
  4252. {
  4253. int fd;
  4254. nullpo_retv(sd);
  4255. fd=sd->fd;
  4256. WFIFOHEAD(fd,packet_len(0xf6));
  4257. WFIFOW(fd,0)=0xf6; // Storage item removed
  4258. WFIFOW(fd,2)=client_storage_index(index);
  4259. WFIFOL(fd,4)=amount;
  4260. WFIFOSET(fd,packet_len(0xf6));
  4261. }
  4262. /// Closes storage (ZC_CLOSE_STORE).
  4263. /// 00f8
  4264. void clif_storageclose(map_session_data* sd)
  4265. {
  4266. int fd;
  4267. nullpo_retv(sd);
  4268. fd=sd->fd;
  4269. WFIFOHEAD(fd,packet_len(0xf8));
  4270. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4271. WFIFOSET(fd,packet_len(0xf8));
  4272. }
  4273. /// Notifies clients in an area of a player's souls.
  4274. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4275. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4276. /// 0b73 <id>.L <amount>.W
  4277. void clif_soulball( map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4278. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4279. struct PACKET_ZC_SOULENERGY p = {};
  4280. p.PacketType = HEADER_ZC_SOULENERGY;
  4281. #else
  4282. struct PACKET_ZC_SPIRITS p = {};
  4283. p.PacketType = HEADER_ZC_SPIRITS;
  4284. #endif
  4285. p.AID = sd->bl.id;
  4286. p.num = sd->soulball;
  4287. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4288. }
  4289. /*==========================================
  4290. * Server tells 'sd' player client the abouts of 'dstsd' player
  4291. *------------------------------------------*/
  4292. static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
  4293. {
  4294. struct block_list *d_bl;
  4295. int i;
  4296. if( dstsd->chatID ) {
  4297. struct chat_data *cd = NULL;
  4298. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4299. clif_dispchat(cd,sd->fd);
  4300. } else if( dstsd->state.vending )
  4301. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4302. else if( dstsd->state.buyingstore )
  4303. clif_buyingstore_entry( *dstsd, &sd->bl );
  4304. if(dstsd->spiritball > 0)
  4305. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4306. if (dstsd->sc.getSCE(SC_MILLENNIUMSHIELD))
  4307. clif_millenniumshield_single(sd->fd, dstsd);
  4308. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4309. clif_spiritcharm_single(sd->fd, dstsd);
  4310. if (dstsd->soulball > 0)
  4311. clif_soulball( dstsd, &sd->bl, SELF );
  4312. if (dstsd->servantball > 0)
  4313. clif_servantball( *dstsd, &sd->bl, SELF );
  4314. if (dstsd->abyssball > 0)
  4315. clif_abyssball( *dstsd, &sd->bl, SELF );
  4316. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4317. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4318. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4319. )
  4320. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4321. // display link (sd - dstsd) to sd
  4322. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4323. if( i < MAX_DEVOTION )
  4324. clif_devotion(&sd->bl, sd);
  4325. // display links (dstsd - devotees) to sd
  4326. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4327. if( i < MAX_DEVOTION )
  4328. clif_devotion(&dstsd->bl, sd);
  4329. // display link (dstsd - crusader) to sd
  4330. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != NULL )
  4331. clif_devotion(d_bl, sd);
  4332. }
  4333. void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
  4334. struct unit_data *ud;
  4335. struct view_data *vd;
  4336. bool option = false;
  4337. unsigned int option_val = 0;
  4338. vd = status_get_viewdata(bl);
  4339. if (!vd || vd->class_ == JT_INVISIBLE)
  4340. return;
  4341. // Hide NPC from Maya Purple card
  4342. if (clif_npc_mayapurple(bl))
  4343. return;
  4344. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4345. // Do not send anything
  4346. return;
  4347. }
  4348. ud = unit_bl2ud(bl);
  4349. if( ud && ud->walktimer != INVALID_TIMER ){
  4350. clif_set_unit_walking( bl, sd, ud, SELF );
  4351. }else{
  4352. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4353. }
  4354. if (vd->cloth_color)
  4355. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4356. if (vd->body_style)
  4357. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4358. switch (bl->type)
  4359. {
  4360. case BL_PC:
  4361. {
  4362. TBL_PC* tsd = (TBL_PC*)bl;
  4363. clif_getareachar_pc(sd, tsd);
  4364. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4365. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4366. else if(tsd->state.size==SZ_MEDIUM)
  4367. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4368. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4369. clif_sendbgemblem_single(sd->fd,tsd);
  4370. if ( tsd->status.robe )
  4371. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4372. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4373. clif_hat_effects(sd,bl,SELF);
  4374. }
  4375. break;
  4376. case BL_MER: // Devotion Effects
  4377. if( ((TBL_MER*)bl)->devotion_flag )
  4378. clif_devotion(bl, sd);
  4379. break;
  4380. case BL_NPC:
  4381. {
  4382. TBL_NPC* nd = (TBL_NPC*)bl;
  4383. if( nd->chat_id )
  4384. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4385. if( nd->size == SZ_BIG )
  4386. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4387. else if( nd->size == SZ_MEDIUM )
  4388. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4389. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4390. clif_progressbar_npc(nd, sd);
  4391. }
  4392. break;
  4393. case BL_MOB:
  4394. {
  4395. TBL_MOB* md = (TBL_MOB*)bl;
  4396. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4397. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4398. else if(md->special_state.size==SZ_MEDIUM)
  4399. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4400. #if PACKETVER >= 20120404
  4401. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4402. int i;
  4403. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4404. if( md->dmglog[i].id == sd->status.char_id )
  4405. clif_monster_hp_bar(md, sd->fd);
  4406. }
  4407. #endif
  4408. }
  4409. break;
  4410. case BL_PET:
  4411. if (vd->head_bottom)
  4412. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4413. break;
  4414. }
  4415. }
  4416. //Modifies the type of damage according to status changes [Skotlex]
  4417. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4418. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4419. {
  4420. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4421. }
  4422. /*==========================================
  4423. * Estimates walk delay based on the damage criteria. [Skotlex]
  4424. *------------------------------------------*/
  4425. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4426. {
  4427. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4428. return 0;
  4429. if (bl->type == BL_PC) {
  4430. if (battle_config.pc_walk_delay_rate != 100)
  4431. delay = delay*battle_config.pc_walk_delay_rate/100;
  4432. } else
  4433. if (battle_config.walk_delay_rate != 100)
  4434. delay = delay*battle_config.walk_delay_rate/100;
  4435. if (div_ > 1) //Multi-hit skills mean higher delays.
  4436. delay += battle_config.multihit_delay*(div_-1);
  4437. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4438. }
  4439. /*========================================== [Playtester]
  4440. * Returns hallucination damage the client displays
  4441. *------------------------------------------*/
  4442. static int clif_hallucination_damage()
  4443. {
  4444. int digit = rnd() % 5 + 1;
  4445. switch (digit)
  4446. {
  4447. case 1:
  4448. return (rnd() % 10);
  4449. case 2:
  4450. return (rnd() % 100);
  4451. case 3:
  4452. return (rnd() % 1000);
  4453. case 4:
  4454. return (rnd() % 10000);
  4455. }
  4456. return (rnd() % 32767);
  4457. }
  4458. /// Sends a 'damage' packet (src performs action on dst)
  4459. /// 008a <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.W <div>.W <type>.B <damage2>.W (ZC_NOTIFY_ACT)
  4460. /// 02e1 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT2)
  4461. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT3)
  4462. /// type:
  4463. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4464. /// 1 = pick up item
  4465. /// 2 = sit down
  4466. /// 3 = stand up
  4467. /// 4 = damage (endure)
  4468. /// 5 = (splash?)
  4469. /// 6 = (skill?)
  4470. /// 7 = (repeat damage?)
  4471. /// 8 = multi-hit damage
  4472. /// 9 = multi-hit damage (endure)
  4473. /// 10 = critical hit
  4474. /// 11 = lucky dodge
  4475. /// 12 = (touch skill?)
  4476. /// 13 = multi-hit critical
  4477. int clif_damage(struct block_list* src, struct block_list* dst, t_tick tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2, bool spdamage)
  4478. {
  4479. unsigned char buf[34];
  4480. status_change *sc;
  4481. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4482. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4483. #if PACKETVER < 20071113
  4484. const int cmd = 0x8a;
  4485. int offset = 0;
  4486. #elif PACKETVER < 20131223
  4487. const int cmd = 0x2e1;
  4488. int offset = 2;
  4489. #else
  4490. const int cmd = 0x8c8;
  4491. int offset = 3;
  4492. #endif
  4493. nullpo_ret(src);
  4494. nullpo_ret(dst);
  4495. if (type != DMG_MULTI_HIT_CRITICAL)
  4496. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4497. sc = status_get_sc(dst);
  4498. if(sc && sc->count) {
  4499. if(sc->getSCE(SC_HALLUCINATION)) {
  4500. damage = clif_hallucination_damage();
  4501. if(damage2) damage2 = clif_hallucination_damage();
  4502. }
  4503. }
  4504. WBUFW(buf,0) = cmd;
  4505. WBUFL(buf,2) = src->id;
  4506. WBUFL(buf,6) = dst->id;
  4507. WBUFL(buf,10) = client_tick(tick);
  4508. WBUFL(buf,14) = sdelay;
  4509. WBUFL(buf,18) = ddelay;
  4510. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4511. #if PACKETVER < 20071113
  4512. WBUFW(buf,22) = damage ? div : 0;
  4513. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4514. #else
  4515. WBUFL(buf, 22) = damage ? div : 0;
  4516. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4517. #endif
  4518. } else {
  4519. #if PACKETVER < 20071113
  4520. WBUFW(buf,22) = min(damage, INT16_MAX);
  4521. WBUFW(buf,27+offset) = damage2;
  4522. #else
  4523. WBUFL(buf,22) = damage;
  4524. WBUFL(buf,27+offset) = damage2;
  4525. #endif
  4526. }
  4527. #if PACKETVER >= 20131223
  4528. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4529. #endif
  4530. WBUFW(buf,24+offset) = div;
  4531. WBUFB(buf,26+offset) = type;
  4532. if(disguised(dst)) {
  4533. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4534. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4535. clif_send(buf, packet_len(cmd), dst, SELF);
  4536. } else
  4537. clif_send(buf, packet_len(cmd), dst, AREA);
  4538. if(disguised(src)) {
  4539. WBUFL(buf,2) = disguised_bl_id( src->id );
  4540. if (disguised(dst))
  4541. WBUFL(buf,6) = dst->id;
  4542. #if PACKETVER < 20071113
  4543. if(damage > 0) WBUFW(buf,22) = -1;
  4544. if(damage2 > 0) WBUFW(buf,27) = -1;
  4545. #else
  4546. if(damage > 0) WBUFL(buf,22) = -1;
  4547. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4548. #endif
  4549. clif_send(buf,packet_len(cmd),src,SELF);
  4550. }
  4551. if(src == dst) {
  4552. unit_setdir(src, unit_getdir(src));
  4553. }
  4554. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4555. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4556. //Return adjusted can't walk delay for further processing.
  4557. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4558. }
  4559. /*==========================================
  4560. * src picks up dst
  4561. *------------------------------------------*/
  4562. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4563. {
  4564. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4565. unsigned char buf[32];
  4566. nullpo_retv(src);
  4567. nullpo_retv(dst);
  4568. WBUFW(buf, 0) = 0x8a;
  4569. WBUFL(buf, 2) = src->id;
  4570. WBUFL(buf, 6) = dst->id;
  4571. WBUFB(buf,26) = 1;
  4572. clif_send(buf, packet_len(0x8a), src, AREA);
  4573. }
  4574. /*==========================================
  4575. * inform clients in area that `bl` is sitting
  4576. *------------------------------------------*/
  4577. void clif_sitting(struct block_list* bl)
  4578. {
  4579. unsigned char buf[32];
  4580. nullpo_retv(bl);
  4581. WBUFW(buf, 0) = 0x8a;
  4582. WBUFL(buf, 2) = bl->id;
  4583. WBUFB(buf,26) = 2;
  4584. clif_send(buf, packet_len(0x8a), bl, AREA);
  4585. if(disguised(bl)) {
  4586. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4587. clif_send(buf, packet_len(0x8a), bl, SELF);
  4588. }
  4589. }
  4590. /*==========================================
  4591. * inform clients in area that `bl` is standing
  4592. *------------------------------------------*/
  4593. void clif_standing(struct block_list* bl)
  4594. {
  4595. unsigned char buf[32];
  4596. nullpo_retv(bl);
  4597. WBUFW(buf, 0) = 0x8a;
  4598. WBUFL(buf, 2) = bl->id;
  4599. WBUFB(buf,26) = 3;
  4600. clif_send(buf, packet_len(0x8a), bl, AREA);
  4601. if(disguised(bl)) {
  4602. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4603. clif_send(buf, packet_len(0x8a), bl, SELF);
  4604. }
  4605. }
  4606. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4607. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4608. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4609. {
  4610. unsigned char buf[32];
  4611. WBUFW(buf,0) = 0x192;
  4612. WBUFW(buf,2) = x;
  4613. WBUFW(buf,4) = y;
  4614. WBUFW(buf,6) = type;
  4615. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4616. if( session_isActive(fd) )
  4617. {
  4618. WFIFOHEAD(fd,packet_len(0x192));
  4619. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4620. WFIFOSET(fd,packet_len(0x192));
  4621. }
  4622. else
  4623. {
  4624. struct block_list dummy_bl;
  4625. dummy_bl.type = BL_NUL;
  4626. dummy_bl.x = x;
  4627. dummy_bl.y = y;
  4628. dummy_bl.m = m;
  4629. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4630. }
  4631. }
  4632. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4633. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4634. void clif_getareachar_item( map_session_data* sd,struct flooritem_data* fitem ){
  4635. nullpo_retv( sd );
  4636. nullpo_retv( fitem );
  4637. struct PACKET_ZC_ITEM_ENTRY p;
  4638. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4639. p.AID = fitem->bl.id;
  4640. p.itemId = client_nameid( fitem->item.nameid );
  4641. p.identify = fitem->item.identify;
  4642. p.x = fitem->bl.x;
  4643. p.y = fitem->bl.y;
  4644. p.amount = fitem->item.amount;
  4645. p.subX = fitem->subx;
  4646. p.subY = fitem->suby;
  4647. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4648. }
  4649. /// Notifes client about Graffiti
  4650. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4651. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4652. unsigned char buf[128];
  4653. nullpo_retv(bl);
  4654. nullpo_retv(unit);
  4655. WBUFW(buf, 0) = 0x1c9;
  4656. WBUFL(buf, 2) = unit->bl.id;
  4657. WBUFL(buf, 6) = unit->group->src_id;
  4658. WBUFW(buf,10) = unit->bl.x;
  4659. WBUFW(buf,12) = unit->bl.y;
  4660. WBUFB(buf,14) = unit->group->unit_id;
  4661. WBUFB(buf,15) = 1;
  4662. WBUFB(buf,16) = 1;
  4663. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4664. clif_send(buf,packet_len(0x1c9),bl,target);
  4665. }
  4666. /// Notifies the client of a skill unit.
  4667. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4668. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4669. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4670. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4671. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4672. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4673. unsigned char buf[128];
  4674. nullpo_retv(bl);
  4675. nullpo_retv(unit);
  4676. if (bl->type == BL_PC)
  4677. fd = ((TBL_PC*)bl)->fd;
  4678. if (unit->group->state.guildaura)
  4679. return;
  4680. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4681. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4682. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4683. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4684. else
  4685. unit_id = unit->group->unit_id;
  4686. if (!visible)
  4687. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4688. #if PACKETVER >= 3
  4689. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4690. clif_graffiti(bl, unit, target);
  4691. return;
  4692. }
  4693. #endif
  4694. #if PACKETVER <= 20120702
  4695. header = 0x011f;
  4696. //#if PACKETVER < 20110718
  4697. // header = 0x011f;
  4698. //#elif PACKETVER < 20121212
  4699. // header = 0x08c7;
  4700. #elif PACKETVER < 20130731
  4701. header = 0x099f;
  4702. #else
  4703. header = 0x09ca;
  4704. #endif
  4705. len = packet_len(header);
  4706. WBUFW(buf,pos) = header;
  4707. if (header != 0x011f) {
  4708. WBUFW(buf, pos+2) = len;
  4709. pos += 2;
  4710. }
  4711. WBUFL(buf,pos+2) = unit->bl.id;
  4712. WBUFL(buf,pos+6) = unit->group->src_id;
  4713. WBUFW(buf,pos+10) = unit->bl.x;
  4714. WBUFW(buf,pos+12) = unit->bl.y;
  4715. switch (header) {
  4716. case 0x011f:
  4717. WBUFB(buf,pos+14) = unit_id;
  4718. WBUFB(buf,pos+15) = visible;
  4719. break;
  4720. case 0x08c7:
  4721. WBUFB(buf,pos+14) = unit_id;
  4722. WBUFW(buf,pos+15) = unit->range;
  4723. WBUFB(buf,pos+17) = visible;
  4724. break;
  4725. case 0x099f:
  4726. WBUFL(buf,pos+14) = unit_id;
  4727. WBUFW(buf,pos+18) = unit->range;
  4728. WBUFB(buf,pos+20) = visible;
  4729. break;
  4730. case 0x09ca:
  4731. WBUFL(buf,pos+14) = unit_id;
  4732. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4733. WBUFB(buf,pos+19) = visible;
  4734. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4735. break;
  4736. }
  4737. clif_send(buf, len, bl, target);
  4738. if (unit->group->skill_id == WZ_ICEWALL)
  4739. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4740. }
  4741. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4742. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4743. unsigned char buf[128];
  4744. nullpo_retv(bl);
  4745. WBUFW(buf, 0) = 0x09ca;
  4746. WBUFW(buf, 2) = packet_len(0x09ca);
  4747. WBUFL(buf, 4) = 1000;
  4748. WBUFL(buf, 8) = 2000;
  4749. WBUFW(buf, 12) = x;
  4750. WBUFW(buf, 14) = y;
  4751. WBUFL(buf, 16) = unit_id;
  4752. WBUFB(buf, 20) = (unsigned char)range;
  4753. WBUFB(buf, 21) = 1;
  4754. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4755. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4756. }
  4757. /*==========================================
  4758. * Server tells client to remove unit of id 'unit->bl.id'
  4759. *------------------------------------------*/
  4760. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4761. {
  4762. nullpo_retv(unit);
  4763. WFIFOHEAD(fd,packet_len(0x120));
  4764. WFIFOW(fd, 0)=0x120;
  4765. WFIFOL(fd, 2)=unit->bl.id;
  4766. WFIFOSET(fd,packet_len(0x120));
  4767. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4768. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4769. }
  4770. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4771. /// 0120 <id>.L
  4772. void clif_skill_delunit(struct skill_unit *unit)
  4773. {
  4774. unsigned char buf[16];
  4775. nullpo_retv(unit);
  4776. WBUFW(buf, 0)=0x120;
  4777. WBUFL(buf, 2)=unit->bl.id;
  4778. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4779. }
  4780. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4781. /// 01ac <id>.L
  4782. /// Only affects units with class [139,153] client-side.
  4783. void clif_skillunit_update(struct block_list* bl)
  4784. {
  4785. unsigned char buf[6];
  4786. nullpo_retv(bl);
  4787. WBUFW(buf,0) = 0x1ac;
  4788. WBUFL(buf,2) = bl->id;
  4789. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4790. }
  4791. /*==========================================
  4792. *
  4793. *------------------------------------------*/
  4794. static int clif_getareachar(struct block_list* bl,va_list ap)
  4795. {
  4796. map_session_data *sd;
  4797. nullpo_ret(bl);
  4798. sd=va_arg(ap,map_session_data*);
  4799. if (!clif_session_isValid(sd))
  4800. return 0;
  4801. switch(bl->type){
  4802. case BL_ITEM:
  4803. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4804. break;
  4805. case BL_SKILL:
  4806. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4807. break;
  4808. default:
  4809. if(&sd->bl == bl)
  4810. break;
  4811. clif_getareachar_unit(sd,bl);
  4812. break;
  4813. }
  4814. return 0;
  4815. }
  4816. /*==========================================
  4817. * tbl has gone out of view-size of bl
  4818. *------------------------------------------*/
  4819. int clif_outsight(struct block_list *bl,va_list ap)
  4820. {
  4821. struct block_list *tbl;
  4822. struct view_data *vd;
  4823. TBL_PC *sd, *tsd;
  4824. tbl=va_arg(ap,struct block_list*);
  4825. if(bl == tbl) return 0;
  4826. sd = BL_CAST(BL_PC, bl);
  4827. tsd = BL_CAST(BL_PC, tbl);
  4828. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4829. nullpo_ret(bl);
  4830. switch(bl->type){
  4831. case BL_PC:
  4832. if(sd->vd.class_ != JT_INVISIBLE)
  4833. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4834. if(sd->chatID){
  4835. struct chat_data *cd;
  4836. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4837. if(cd->usersd[0]==sd)
  4838. clif_dispchat(cd,tsd->fd);
  4839. }
  4840. if(sd->state.vending)
  4841. clif_closevendingboard(bl,tsd->fd);
  4842. if(sd->state.buyingstore)
  4843. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4844. break;
  4845. case BL_ITEM:
  4846. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4847. break;
  4848. case BL_SKILL:
  4849. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4850. break;
  4851. case BL_NPC:
  4852. if(!(((TBL_NPC*)bl)->is_invisible))
  4853. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4854. break;
  4855. default:
  4856. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4857. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4858. break;
  4859. }
  4860. }
  4861. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4862. nullpo_ret(tbl);
  4863. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4864. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4865. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4866. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->is_invisible)))
  4867. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4868. }
  4869. return 0;
  4870. }
  4871. /*==========================================
  4872. * tbl has come into view of bl
  4873. *------------------------------------------*/
  4874. int clif_insight(struct block_list *bl,va_list ap)
  4875. {
  4876. struct block_list *tbl;
  4877. TBL_PC *sd, *tsd;
  4878. tbl=va_arg(ap,struct block_list*);
  4879. if (bl == tbl) return 0;
  4880. sd = BL_CAST(BL_PC, bl);
  4881. tsd = BL_CAST(BL_PC, tbl);
  4882. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4883. switch(bl->type){
  4884. case BL_ITEM:
  4885. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4886. break;
  4887. case BL_SKILL:
  4888. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4889. break;
  4890. default:
  4891. clif_getareachar_unit(tsd,bl);
  4892. break;
  4893. }
  4894. }
  4895. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4896. clif_getareachar_unit(sd,tbl);
  4897. }
  4898. return 0;
  4899. }
  4900. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4901. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4902. void clif_skillinfoblock(map_session_data *sd)
  4903. {
  4904. int fd;
  4905. int i,len,id;
  4906. nullpo_retv(sd);
  4907. fd = sd->fd;
  4908. if (!session_isActive(fd))
  4909. return;
  4910. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4911. WFIFOW(fd,0) = 0x10f;
  4912. bool haveCallPartnerSkill = false;
  4913. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4914. {
  4915. if( (id = sd->status.skill[i].id) != 0 )
  4916. {
  4917. // workaround for bugreport:5348
  4918. if (len + 37 > 8192)
  4919. break;
  4920. // skip WE_CALLPARTNER and send it in special way
  4921. if (id == WE_CALLPARTNER) {
  4922. haveCallPartnerSkill = true;
  4923. continue;
  4924. }
  4925. WFIFOW(fd,len) = id;
  4926. WFIFOL(fd,len+2) = skill_get_inf(id);
  4927. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4928. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4929. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4930. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4931. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4932. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4933. else
  4934. WFIFOB(fd,len+36) = 0;
  4935. len += 37;
  4936. }
  4937. }
  4938. WFIFOW(fd,2)=len;
  4939. WFIFOSET(fd,len);
  4940. // adoption fix
  4941. if (haveCallPartnerSkill) {
  4942. clif_addskill(sd, WE_CALLPARTNER);
  4943. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4944. }
  4945. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4946. for ( ; i < MAX_SKILL; i++)
  4947. {
  4948. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4949. {
  4950. clif_addskill(sd, id);
  4951. clif_skillinfo(sd, id, 0);
  4952. }
  4953. }
  4954. }
  4955. /**
  4956. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4957. **/
  4958. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4959. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4960. void clif_addskill(map_session_data *sd, int skill_id)
  4961. {
  4962. nullpo_retv(sd);
  4963. int fd = sd->fd;
  4964. uint16 idx = skill_get_index(skill_id);
  4965. if (!session_isActive(fd) || !idx)
  4966. return;
  4967. if( sd->status.skill[idx].id <= 0 )
  4968. return;
  4969. WFIFOHEAD(fd, packet_len(0x111));
  4970. WFIFOW(fd,0) = 0x111;
  4971. WFIFOW(fd,2) = skill_id;
  4972. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4973. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4974. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4975. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4976. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4977. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4978. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4979. else
  4980. WFIFOB(fd,38) = 0;
  4981. WFIFOSET(fd,packet_len(0x111));
  4982. }
  4983. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4984. /// 0441 <skill id>.W
  4985. void clif_deleteskill(map_session_data *sd, int skill_id, bool skip_infoblock)
  4986. {
  4987. #if PACKETVER >= 20081217
  4988. nullpo_retv(sd);
  4989. int fd = sd->fd;
  4990. uint16 idx = skill_get_index(skill_id);
  4991. if (!session_isActive(fd) || !idx)
  4992. return;
  4993. WFIFOHEAD(fd,packet_len(0x441));
  4994. WFIFOW(fd,0) = 0x441;
  4995. WFIFOW(fd,2) = skill_id;
  4996. WFIFOSET(fd,packet_len(0x441));
  4997. #endif
  4998. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4999. if (!skip_infoblock)
  5000. #endif
  5001. clif_skillinfoblock(sd);
  5002. }
  5003. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  5004. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  5005. void clif_skillup(map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  5006. nullpo_retv(sd);
  5007. int fd = sd->fd;
  5008. uint16 idx = skill_get_index(skill_id);
  5009. if (!session_isActive(fd) || !idx)
  5010. return;
  5011. WFIFOHEAD(fd, packet_len(0x10e));
  5012. WFIFOW(fd, 0) = 0x10e;
  5013. WFIFOW(fd, 2) = skill_id;
  5014. WFIFOW(fd, 4) = lv;
  5015. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  5016. WFIFOW(fd, 8) = range;
  5017. WFIFOB(fd, 10) = upgradable;
  5018. WFIFOSET(fd, packet_len(0x10e));
  5019. }
  5020. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  5021. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  5022. void clif_skillinfo(map_session_data *sd,int skill_id, int inf)
  5023. {
  5024. nullpo_retv(sd);
  5025. const int fd = sd->fd;
  5026. uint16 idx = skill_get_index(skill_id);
  5027. if (!session_isActive(fd) || !idx)
  5028. return;
  5029. WFIFOHEAD(fd,packet_len(0x7e1));
  5030. WFIFOW(fd,0) = 0x7e1;
  5031. WFIFOW(fd,2) = skill_id;
  5032. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  5033. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  5034. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  5035. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  5036. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  5037. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  5038. else
  5039. WFIFOB(fd,14) = 0;
  5040. WFIFOSET(fd,packet_len(0x7e1));
  5041. }
  5042. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  5043. #if PACKETVER >= 20151223
  5044. if( !battle_config.show_skill_scale ){
  5045. return;
  5046. }
  5047. struct PACKET_ZC_SKILL_SCALE p;
  5048. p.PacketType = skillscale;
  5049. p.AID = src_id;
  5050. p.skill_id = skill_id;
  5051. p.skill_lv = skill_lv;
  5052. p.x = x;
  5053. p.y = y;
  5054. p.casttime = casttime;
  5055. if( disguised( bl ) ){
  5056. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  5057. p.AID = disguised_bl_id( bl->id );
  5058. clif_send( &p, sizeof( p ), bl, SELF );
  5059. }else{
  5060. clif_send( &p, sizeof( p ), bl, AREA );
  5061. }
  5062. #endif
  5063. }
  5064. /// Notifies clients in area, that an object is about to use a skill.
  5065. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  5066. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  5067. /// property:
  5068. /// 0 = Yellow cast aura
  5069. /// 1 = Water elemental cast aura
  5070. /// 2 = Earth elemental cast aura
  5071. /// 3 = Fire elemental cast aura
  5072. /// 4 = Wind elemental cast aura
  5073. /// 5 = Poison elemental cast aura
  5074. /// 6 = Holy elemental cast aura
  5075. /// ? = like 0
  5076. /// is disposable:
  5077. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  5078. /// 1 = no text
  5079. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, uint16 skill_lv, int property, int casttime)
  5080. {
  5081. #if PACKETVER < 20091124
  5082. const int cmd = 0x13e;
  5083. #else
  5084. const int cmd = 0x7fb;
  5085. #endif
  5086. unsigned char buf[32];
  5087. WBUFW(buf,0) = cmd;
  5088. WBUFL(buf,2) = src_id;
  5089. WBUFL(buf,6) = dst_id;
  5090. WBUFW(buf,10) = dst_x;
  5091. WBUFW(buf,12) = dst_y;
  5092. WBUFW(buf,14) = skill_id;
  5093. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5094. WBUFL(buf,20) = casttime;
  5095. #if PACKETVER >= 20091124
  5096. WBUFB(buf,24) = 0; // isDisposable
  5097. #endif
  5098. if (disguised(bl)) {
  5099. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5100. WBUFL(buf,2) = disguised_bl_id( src_id );
  5101. clif_send(buf,packet_len(cmd), bl, SELF);
  5102. } else
  5103. clif_send(buf,packet_len(cmd), bl, AREA);
  5104. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5105. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5106. }
  5107. }
  5108. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5109. /// 01b9 <id>.L
  5110. void clif_skillcastcancel(struct block_list* bl)
  5111. {
  5112. unsigned char buf[16];
  5113. nullpo_retv(bl);
  5114. WBUFW(buf,0) = 0x1b9;
  5115. WBUFL(buf,2) = bl->id;
  5116. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5117. }
  5118. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5119. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5120. /// num (only used when skill id = NV_BASIC and cause = 0):
  5121. /// 0 = "skill failed" MsgStringTable[159]
  5122. /// 1 = "no emotions" MsgStringTable[160]
  5123. /// 2 = "no sit" MsgStringTable[161]
  5124. /// 3 = "no chat" MsgStringTable[162]
  5125. /// 4 = "no party" MsgStringTable[163]
  5126. /// 5 = "no shout" MsgStringTable[164]
  5127. /// 6 = "no PKing" MsgStringTable[165]
  5128. /// 7 = "no alligning" MsgStringTable[383]
  5129. /// ? = ignored
  5130. /// cause:
  5131. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5132. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5133. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5134. /// "skill failed" MsgStringTable[204] (otherwise)
  5135. /// ... = @see enum useskill_fail_cause
  5136. /// ? = ignored
  5137. ///
  5138. /// if(result!=0) doesn't display any of the previous messages
  5139. /// Note: when this packet is received an unknown flag is always set to 0,
  5140. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5141. void clif_skill_fail( map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5142. nullpo_retv( sd );
  5143. int fd = sd->fd;
  5144. if( !session_isActive( fd ) ){
  5145. return;
  5146. }
  5147. if(battle_config.display_skill_fail&1)
  5148. return; //Disable all skill failed messages
  5149. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5150. return; //Disable delay failed messages
  5151. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5152. return;
  5153. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5154. return;
  5155. struct PACKET_ZC_ACK_TOUSESKILL p;
  5156. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5157. p.skillId = skill_id;
  5158. p.btype = btype;
  5159. p.itemId = itemId;
  5160. p.flag = 0; // 0 - failed
  5161. p.cause = cause;
  5162. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5163. }
  5164. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5165. /// 043d <skill ID>.W <tick>.L
  5166. void clif_skill_cooldown(map_session_data *sd, uint16 skill_id, t_tick tick)
  5167. {
  5168. #if PACKETVER>=20081112
  5169. int fd;
  5170. nullpo_retv(sd);
  5171. fd=sd->fd;
  5172. WFIFOHEAD(fd,packet_len(0x43d));
  5173. WFIFOW(fd,0) = 0x43d;
  5174. WFIFOW(fd,2) = skill_id;
  5175. WFIFOL(fd,4) = client_tick(tick);
  5176. WFIFOSET(fd,packet_len(0x43d));
  5177. #endif
  5178. }
  5179. /// Skill attack effect and damage.
  5180. /// 0114 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.W <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL)
  5181. /// 01de <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.L <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL2)
  5182. int clif_skill_damage(struct block_list *src,struct block_list *dst,t_tick tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  5183. {
  5184. unsigned char buf[64];
  5185. status_change *sc;
  5186. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5187. nullpo_ret(src);
  5188. nullpo_ret(dst);
  5189. type = clif_calc_delay(type,div,damage,ddelay);
  5190. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5191. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5192. damage = clif_hallucination_damage();
  5193. }
  5194. #if PACKETVER < 3
  5195. WBUFW(buf,0)=0x114;
  5196. WBUFW(buf,2)=skill_id;
  5197. WBUFL(buf,4)=src->id;
  5198. WBUFL(buf,8)=dst->id;
  5199. WBUFL(buf,12)=client_tick(tick);
  5200. WBUFL(buf,16)=sdelay;
  5201. WBUFL(buf,20)=ddelay;
  5202. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5203. WBUFW(buf,24)=damage?div:0;
  5204. } else {
  5205. WBUFW(buf,24)=damage;
  5206. }
  5207. WBUFW(buf,26)=skill_lv;
  5208. WBUFW(buf,28)=div;
  5209. WBUFB(buf,30)=type;
  5210. if (disguised(dst)) {
  5211. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5212. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5213. clif_send(buf,packet_len(0x114),dst,SELF);
  5214. } else
  5215. clif_send(buf,packet_len(0x114),dst,AREA);
  5216. if(disguised(src)) {
  5217. WBUFL(buf,4)=disguised_bl_id(src->id);
  5218. if (disguised(dst))
  5219. WBUFL(buf,8)=dst->id;
  5220. if(damage > 0)
  5221. WBUFW(buf,24)=-1;
  5222. clif_send(buf,packet_len(0x114),src,SELF);
  5223. }
  5224. #else
  5225. WBUFW(buf,0)=0x1de;
  5226. WBUFW(buf,2)=skill_id;
  5227. WBUFL(buf,4)=src->id;
  5228. WBUFL(buf,8)=dst->id;
  5229. WBUFL(buf,12)=client_tick(tick);
  5230. WBUFL(buf,16)=sdelay;
  5231. WBUFL(buf,20)=ddelay;
  5232. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5233. WBUFL(buf,24)=damage?div:0;
  5234. } else {
  5235. WBUFL(buf,24)=damage;
  5236. }
  5237. WBUFW(buf,28)=skill_lv;
  5238. WBUFW(buf,30)=div;
  5239. // For some reason, late 2013 and newer clients have
  5240. // a issue that causes players and monsters to endure
  5241. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5242. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5243. #if PACKETVER < 20131223
  5244. WBUFB(buf,32)=type;
  5245. #else
  5246. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5247. #endif
  5248. if (disguised(dst)) {
  5249. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5250. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5251. clif_send(buf,packet_len(0x1de),dst,SELF);
  5252. } else
  5253. clif_send(buf,packet_len(0x1de),dst,AREA);
  5254. if(disguised(src)) {
  5255. WBUFL(buf,4)=disguised_bl_id(src->id);
  5256. if (disguised(dst))
  5257. WBUFL(buf,8)=dst->id;
  5258. if(damage > 0)
  5259. WBUFL(buf,24)=-1;
  5260. clif_send(buf,packet_len(0x1de),src,SELF);
  5261. }
  5262. #endif
  5263. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5264. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5265. }
  5266. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5267. /// 0115 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <x>.W <y>.W <damage>.W <level>.W <div>.W <type>.B
  5268. /*
  5269. int clif_skill_damage2(struct block_list *src,struct block_list *dst,t_tick tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  5270. {
  5271. unsigned char buf[64];
  5272. status_change *sc;
  5273. nullpo_ret(src);
  5274. nullpo_ret(dst);
  5275. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5276. type = clif_calc_delay(type,div,damage,ddelay);
  5277. sc = status_get_sc(dst);
  5278. if(sc && sc->count) {
  5279. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5280. damage = clif_hallucination_damage();
  5281. }
  5282. WBUFW(buf,0)=0x115;
  5283. WBUFW(buf,2)=skill_id;
  5284. WBUFL(buf,4)=src->id;
  5285. WBUFL(buf,8)=dst->id;
  5286. WBUFL(buf,12)=client_tick(tick);
  5287. WBUFL(buf,16)=sdelay;
  5288. WBUFL(buf,20)=ddelay;
  5289. WBUFW(buf,24)=dst->x;
  5290. WBUFW(buf,26)=dst->y;
  5291. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5292. WBUFW(buf,28)=damage?div:0;
  5293. } else {
  5294. WBUFW(buf,28)=damage;
  5295. }
  5296. WBUFW(buf,30)=skill_lv;
  5297. WBUFW(buf,32)=div;
  5298. WBUFB(buf,34)=type;
  5299. clif_send(buf,packet_len(0x115),src,AREA);
  5300. if(disguised(src)) {
  5301. WBUFL(buf,4)=disguised_bl_id(src->id);
  5302. if(damage > 0)
  5303. WBUFW(buf,28)=-1;
  5304. clif_send(buf,packet_len(0x115),src,SELF);
  5305. }
  5306. if (disguised(dst)) {
  5307. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5308. if (disguised(src))
  5309. WBUFL(buf,4)=src->id;
  5310. else if(damage > 0)
  5311. WBUFW(buf,28)=-1;
  5312. clif_send(buf,packet_len(0x115),dst,SELF);
  5313. }
  5314. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5315. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5316. }
  5317. */
  5318. /// Non-damaging skill effect
  5319. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5320. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5321. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5322. {
  5323. unsigned char buf[17];
  5324. #if PACKETVER < 20130731
  5325. const int cmd = 0x11a;
  5326. #else
  5327. const int cmd = 0x9cb;
  5328. #endif
  5329. int offset = 0;
  5330. bool success = ( tick != 0 );
  5331. nullpo_ret(dst);
  5332. WBUFW(buf,0) = cmd;
  5333. WBUFW(buf,2) = skill_id;
  5334. #if PACKETVER < 20130731
  5335. WBUFW(buf,4) = min(heal, INT16_MAX);
  5336. #else
  5337. WBUFL(buf,4) = min(heal, INT32_MAX);
  5338. offset += 2;
  5339. #endif
  5340. WBUFL(buf,6+offset) = dst->id;
  5341. WBUFL(buf,10+offset) = src ? src->id : 0;
  5342. WBUFB(buf,14+offset) = success;
  5343. if (disguised(dst)) {
  5344. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5345. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5346. clif_send(buf, packet_len(cmd), dst, SELF);
  5347. } else
  5348. clif_send(buf, packet_len(cmd), dst, AREA);
  5349. if(src && disguised(src)) {
  5350. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5351. if (disguised(dst))
  5352. WBUFL(buf,6+offset) = dst->id;
  5353. clif_send(buf, packet_len(cmd), src, SELF);
  5354. }
  5355. return success;
  5356. }
  5357. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5358. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5359. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5360. {
  5361. unsigned char buf[32];
  5362. nullpo_retv(src);
  5363. WBUFW(buf,0)=0x117;
  5364. WBUFW(buf,2)=skill_id;
  5365. WBUFL(buf,4)=src->id;
  5366. WBUFW(buf,8)=val;
  5367. WBUFW(buf,10)=x;
  5368. WBUFW(buf,12)=y;
  5369. WBUFL(buf,14)=client_tick(tick);
  5370. if(disguised(src)) {
  5371. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5372. WBUFL(buf,4)=disguised_bl_id(src->id);
  5373. clif_send(buf,packet_len(0x117),src,SELF);
  5374. } else
  5375. clif_send(buf,packet_len(0x117),src,AREA);
  5376. }
  5377. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5378. /// 011c <skill id>.W { <map name>.16B }*4
  5379. void clif_skill_warppoint( map_session_data* sd, uint16 skill_id, uint16 skill_lv, const char* map1, const char* map2, const char* map3, const char* map4 ){
  5380. int fd;
  5381. nullpo_retv(sd);
  5382. fd = sd->fd;
  5383. WFIFOHEAD(fd,packet_len(0x11c));
  5384. WFIFOW(fd,0) = 0x11c;
  5385. WFIFOW(fd,2) = skill_id;
  5386. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5387. if( strcmp( "", map1 ) != 0 ){
  5388. mapindex_getmapname_ext( map1, WFIFOCP( fd, 4 ) );
  5389. }
  5390. if( strcmp( "", map2 ) != 0 ){
  5391. mapindex_getmapname_ext( map2, WFIFOCP( fd, 20 ) );
  5392. }
  5393. if( strcmp( "", map3 ) != 0 ){
  5394. mapindex_getmapname_ext( map3, WFIFOCP( fd, 36 ) );
  5395. }
  5396. if( strcmp( "", map4 ) != 0 ){
  5397. mapindex_getmapname_ext( map4, WFIFOCP( fd, 52 ) );
  5398. }
  5399. WFIFOSET(fd,packet_len(0x11c));
  5400. sd->menuskill_id = skill_id;
  5401. if (skill_id == AL_WARP) {
  5402. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5403. sd->state.workinprogress = WIP_DISABLE_ALL;
  5404. } else
  5405. sd->menuskill_val = skill_lv;
  5406. }
  5407. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5408. /// 011e <type>.B
  5409. /// type:
  5410. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5411. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5412. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5413. ///
  5414. /// @param sd Who receives the message
  5415. /// @param type What message
  5416. void clif_skill_memomessage(map_session_data* sd, int type)
  5417. {
  5418. int fd;
  5419. nullpo_retv(sd);
  5420. fd=sd->fd;
  5421. WFIFOHEAD(fd,packet_len(0x11e));
  5422. WFIFOW(fd,0)=0x11e;
  5423. WFIFOB(fd,2)=type;
  5424. WFIFOSET(fd,packet_len(0x11e));
  5425. }
  5426. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5427. /// 0189 <type>.W
  5428. /// type:
  5429. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5430. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5431. ///
  5432. /// @param sd Who receives the message
  5433. /// @param type What message
  5434. void clif_skill_teleportmessage(map_session_data *sd, int type)
  5435. {
  5436. int fd;
  5437. nullpo_retv(sd);
  5438. fd=sd->fd;
  5439. WFIFOHEAD(fd,packet_len(0x189));
  5440. WFIFOW(fd,0)=0x189;
  5441. WFIFOW(fd,2)=type;
  5442. WFIFOSET(fd,packet_len(0x189));
  5443. }
  5444. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5445. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5446. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5447. void clif_skill_estimation(map_session_data *sd,struct block_list *dst)
  5448. {
  5449. struct status_data *status;
  5450. unsigned char buf[64];
  5451. int i, fix;
  5452. nullpo_retv(sd);
  5453. nullpo_retv(dst);
  5454. if( dst->type != BL_MOB )
  5455. return;
  5456. status = status_get_status_data(dst);
  5457. WBUFW(buf, 0)=0x18c;
  5458. WBUFW(buf, 2)=status_get_class(dst);
  5459. WBUFW(buf, 4)=status_get_lv(dst);
  5460. WBUFW(buf, 6)=status->size;
  5461. WBUFL(buf, 8)=status->hp;
  5462. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5463. +(battle_config.estimation_type&2?status->def2:0);
  5464. WBUFW(buf,14)=status->race;
  5465. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5466. +(battle_config.estimation_type&2?status->mdef2:0);
  5467. WBUFW(buf,18)= status->def_ele;
  5468. for(i=0;i<9;i++)
  5469. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5470. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5471. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5472. }
  5473. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5474. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5475. /// material id:
  5476. /// unused by the client
  5477. void clif_skill_produce_mix_list( map_session_data *sd, int skill_id, int trigger ){
  5478. nullpo_retv(sd);
  5479. int fd = sd->fd;
  5480. if( !session_isActive( fd ) ){
  5481. return;
  5482. }
  5483. if (sd->menuskill_id == skill_id)
  5484. return; //Avoid resending the menu twice or more times...
  5485. if (skill_id == GC_CREATENEWPOISON)
  5486. skill_id = GC_RESEARCHNEWPOISON;
  5487. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5488. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5489. p->packetType = 0x18d;
  5490. int count = 0;
  5491. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5492. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5493. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5494. )
  5495. {
  5496. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5497. p->items[count].material[0] = 0;
  5498. p->items[count].material[1] = 0;
  5499. p->items[count].material[2] = 0;
  5500. count++;
  5501. }
  5502. }
  5503. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5504. WFIFOSET( fd, p->packetLength );
  5505. if( count > 0 ){
  5506. sd->menuskill_id = skill_id;
  5507. sd->menuskill_val = trigger;
  5508. return;
  5509. }
  5510. }
  5511. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5512. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5513. /// mk type:
  5514. /// 1 = cooking
  5515. /// 2 = arrow
  5516. /// 3 = elemental
  5517. /// 4 = GN_MIX_COOKING
  5518. /// 5 = GN_MAKEBOMB
  5519. /// 6 = GN_S_PHARMACY
  5520. /// 7 = MT_M_MACHINE - Unconfirmed
  5521. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5522. void clif_cooking_list( map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5523. nullpo_retv( sd );
  5524. // Avoid resending the menu twice or more times...
  5525. if( sd->menuskill_id == skill_id ){
  5526. return;
  5527. }
  5528. int fd = sd->fd;
  5529. if( !session_isActive( fd ) ){
  5530. return;
  5531. }
  5532. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5533. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5534. p->packetType = 0x25a;
  5535. p->makeItem = list_type; // list type
  5536. int count = 0;
  5537. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5538. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5539. continue;
  5540. }
  5541. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5542. count++;
  5543. }
  5544. if( count > 0 || skill_id == AM_PHARMACY ){
  5545. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5546. WFIFOSET( fd, p->packetLength );
  5547. sd->menuskill_id = skill_id;
  5548. sd->menuskill_val = trigger;
  5549. sd->menuskill_val2 = qty; // amount.
  5550. }else{
  5551. clif_menuskill_clear(sd);
  5552. #if PACKETVER >= 20090922
  5553. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5554. #else
  5555. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5556. WFIFOSET( fd, p->packetLength );
  5557. #endif
  5558. }
  5559. }
  5560. /// Notifies clients of a status change.
  5561. /// 0196 <index>.W <id>.L <state>.B (ZC_MSG_STATE_CHANGE) [used for ending status changes and starting them on non-pc units (when needed)]
  5562. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5563. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5564. /// @param bl Sends packet to clients around this object
  5565. /// @param id ID of object that has this effect
  5566. /// @param type Status icon see enum efst_type
  5567. /// @param flag 1:Active, 0:Deactive
  5568. /// @param tick Duration in ms
  5569. /// @param val1
  5570. /// @param val2
  5571. /// @param val3
  5572. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, t_tick tick, int val1, int val2, int val3, enum send_target target_type)
  5573. {
  5574. unsigned char buf[32];
  5575. if (type == EFST_BLANK) //It shows nothing on the client...
  5576. return;
  5577. if (type == EFST_POSTDELAY && tick == 0)
  5578. return;
  5579. nullpo_retv(bl);
  5580. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5581. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5582. tick = 200;
  5583. #if PACKETVER >= 20120618
  5584. if (flag && battle_config.display_status_timers)
  5585. WBUFW(buf,0) = 0x983;
  5586. else
  5587. #elif PACKETVER >= 20090121
  5588. if (flag && battle_config.display_status_timers)
  5589. WBUFW(buf,0) = 0x43f;
  5590. else
  5591. #endif
  5592. WBUFW(buf,0) = 0x196;
  5593. WBUFW(buf,2) = type;
  5594. WBUFL(buf,4) = id;
  5595. WBUFB(buf,8) = flag;
  5596. #if PACKETVER >= 20120618
  5597. if (flag && battle_config.display_status_timers) {
  5598. if (tick <= 0)
  5599. tick = 9999; // this is indeed what official servers do
  5600. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5601. WBUFL(buf,13) = client_tick(tick);
  5602. WBUFL(buf,17) = val1;
  5603. WBUFL(buf,21) = val2;
  5604. WBUFL(buf,25) = val3;
  5605. }
  5606. #elif PACKETVER >= 20090121
  5607. if (flag && battle_config.display_status_timers) {
  5608. if (tick <= 0)
  5609. tick = 9999; // this is indeed what official servers do
  5610. WBUFL(buf,9) = client_tick(tick);
  5611. WBUFL(buf,13) = val1;
  5612. WBUFL(buf,17) = val2;
  5613. WBUFL(buf,21) = val3;
  5614. }
  5615. #endif
  5616. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5617. }
  5618. /* Sends status effect to clients around the bl
  5619. * @param bl Object that has the effect
  5620. * @param type Status icon see enum efst_type
  5621. * @param flag 1:Active, 0:Deactive
  5622. * @param tick Duration in ms
  5623. * @param val1
  5624. * @param val2
  5625. * @param val3
  5626. */
  5627. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5628. map_session_data *sd = NULL;
  5629. if (type == EFST_BLANK) //It shows nothing on the client...
  5630. return;
  5631. if (type == EFST_POSTDELAY && tick == 0)
  5632. return;
  5633. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5634. return;
  5635. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5636. // Older clients display normal riding icon.
  5637. if (type == EFST_MADOGEAR)
  5638. type = EFST_RIDING;
  5639. #endif
  5640. nullpo_retv(bl);
  5641. sd = BL_CAST(BL_PC, bl);
  5642. if (!(status_efst_get_bl_type((efst_type)type)&bl->type)) // only send status changes that actually matter to the client
  5643. return;
  5644. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5645. }
  5646. /**
  5647. * Send any active EFST to those around.
  5648. * @param tbl: Unit to send the packet to
  5649. * @param bl: Objects walking into view
  5650. * @param target: Client send type
  5651. */
  5652. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5653. unsigned char i;
  5654. struct sc_display_entry **sc_display;
  5655. unsigned char sc_display_count;
  5656. bool spheres_sent;
  5657. nullpo_retv(bl);
  5658. switch( bl->type ){
  5659. case BL_PC: {
  5660. map_session_data* sd = (map_session_data*)bl;
  5661. sc_display = sd->sc_display;
  5662. sc_display_count = sd->sc_display_count;
  5663. spheres_sent = !sd->state.connect_new;
  5664. }
  5665. break;
  5666. case BL_NPC: {
  5667. struct npc_data* nd = (struct npc_data*)bl;
  5668. sc_display = nd->sc_display;
  5669. sc_display_count = nd->sc_display_count;
  5670. spheres_sent = true;
  5671. }
  5672. break;
  5673. default:
  5674. return;
  5675. }
  5676. for (i = 0; i < sc_display_count; i++) {
  5677. enum sc_type type = sc_display[i]->type;
  5678. status_change *sc = status_get_sc(bl);
  5679. const struct TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : NULL);
  5680. t_tick tick = 0;
  5681. if (td)
  5682. tick = DIFF_TICK(td->tick, gettick());
  5683. // Status changes that need special handling
  5684. switch( type ){
  5685. case SC_SPHERE_1:
  5686. case SC_SPHERE_2:
  5687. case SC_SPHERE_3:
  5688. case SC_SPHERE_4:
  5689. case SC_SPHERE_5:
  5690. if( spheres_sent ){
  5691. target = AREA_WOS;
  5692. }
  5693. break;
  5694. case SC_HELLS_PLANT:
  5695. if( sc && sc->getSCE(type) ){
  5696. tick = sc->getSCE(type)->val4;
  5697. }
  5698. break;
  5699. }
  5700. #if PACKETVER > 20120418
  5701. 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);
  5702. #else
  5703. 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);
  5704. #endif
  5705. }
  5706. }
  5707. /// Notifies the client when a player enters the screen with an active EFST.
  5708. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5709. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5710. 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) {
  5711. #if PACKETVER >= 20111108
  5712. unsigned char buf[32];
  5713. #if PACKETVER >= 20120618
  5714. const int cmd = 0x984;
  5715. #elif PACKETVER >= 20111108
  5716. const int cmd = 0x8ff;
  5717. #endif
  5718. int offset = 0;
  5719. if (type == EFST_BLANK)
  5720. return;
  5721. nullpo_retv(bl);
  5722. if (tick <= 0)
  5723. tick = 9999;
  5724. WBUFW(buf,offset + 0) = cmd;
  5725. WBUFL(buf,offset + 2) = tid;
  5726. WBUFW(buf,offset + 6) = type;
  5727. #if PACKETVER >= 20111108
  5728. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5729. #if PACKETVER >= 20120618
  5730. WBUFL(buf,offset + 12) = client_tick(tick);
  5731. offset += 4;
  5732. #endif
  5733. WBUFL(buf,offset + 12) = val1;
  5734. WBUFL(buf,offset + 16) = val2;
  5735. WBUFL(buf,offset + 20) = val3;
  5736. #endif
  5737. clif_send(buf,packet_len(cmd),bl,target);
  5738. #endif
  5739. }
  5740. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5741. /// 008e <packet len>.W <message>.?B
  5742. void clif_displaymessage(const int fd, const char* mes)
  5743. {
  5744. nullpo_retv(mes);
  5745. if( session_isActive( fd ) ){
  5746. char *message, *line;
  5747. message = aStrdup(mes);
  5748. line = strtok(message, "\n");
  5749. while(line != NULL) {
  5750. #if PACKETVER == 20141022
  5751. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5752. /** so we redirect to ZC_NPC_CHAT **/
  5753. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5754. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5755. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5756. if (len > 0) {
  5757. WFIFOHEAD(fd, 13 + len);
  5758. WFIFOW(fd, 0) = 0x2C1;
  5759. WFIFOW(fd, 2) = 13 + len;
  5760. WFIFOL(fd, 4) = 0;
  5761. WFIFOL(fd, 8) = color;
  5762. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5763. WFIFOSET(fd, WFIFOW(fd, 2));
  5764. }
  5765. #else
  5766. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5767. int len = strnlen(line, CHAT_SIZE_MAX);
  5768. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5769. WFIFOHEAD(fd, 5 + len);
  5770. WFIFOW(fd,0) = 0x8e;
  5771. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5772. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5773. WFIFOSET(fd, 5 + len);
  5774. }
  5775. #endif
  5776. line = strtok(NULL, "\n");
  5777. }
  5778. aFree(message);
  5779. }
  5780. }
  5781. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5782. /// 009a <packet len>.W <message>.?B
  5783. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5784. {
  5785. nullpo_retv(mes);
  5786. if (len < 2)
  5787. return;
  5788. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5789. p->packetType = HEADER_ZC_BROADCAST;
  5790. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5791. if( ( type&BC_BLUE ) != 0 ){
  5792. const char* color = "blue";
  5793. int16 length = (int16)strlen( color );
  5794. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5795. strcpy( p->message, color );
  5796. strncpy( &p->message[length], mes, len );
  5797. p->PacketLength += length;
  5798. }else if( ( type&BC_WOE ) != 0 ){
  5799. const char* color = "ssss";
  5800. int16 length = (int16)strlen( color );
  5801. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5802. strcpy( p->message, color );
  5803. strncpy( &p->message[length], mes, len );
  5804. p->PacketLength += length;
  5805. }else{
  5806. strncpy( p->message, mes, len );
  5807. }
  5808. clif_send( p, p->PacketLength, bl, target );
  5809. }
  5810. /*==========================================
  5811. * Displays a message on a 'bl' to all it's nearby clients
  5812. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5813. *------------------------------------------*/
  5814. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5815. nullpo_retv(bl);
  5816. nullpo_retv(message);
  5817. int16 len = (int16)( strlen( message ) + 1 );
  5818. if( len > CHAT_SIZE_MAX ) {
  5819. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5820. len = CHAT_SIZE_MAX;
  5821. }
  5822. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5823. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5824. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5825. p->GID = bl->id;
  5826. safestrncpy( p->Message, message, len );
  5827. clif_send( p, p->PacketLength, bl, target );
  5828. }
  5829. /// Send broadcast message with font formatting.
  5830. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5831. 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)
  5832. {
  5833. nullpo_retv(mes);
  5834. if (len < 2)
  5835. return;
  5836. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5837. p->packetType = HEADER_ZC_BROADCAST2;
  5838. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5839. p->fontColor = fontColor;
  5840. p->fontType = fontType;
  5841. p->fontSize = fontSize;
  5842. p->fontAlign = fontAlign;
  5843. p->fontY = fontY;
  5844. strncpy( p->message, mes, len );
  5845. clif_send( p, p->PacketLength, bl, target );
  5846. }
  5847. /*
  5848. * Display *msg to all *users in channel
  5849. */
  5850. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5851. DBIterator *iter;
  5852. map_session_data *user;
  5853. unsigned short msg_len = 0, len = 0;
  5854. unsigned char buf[CHAT_SIZE_MAX];
  5855. if (!channel || !msg)
  5856. return;
  5857. msg_len = (unsigned short)(strlen(msg) + 1);
  5858. if( msg_len > sizeof(buf)-12 ) {
  5859. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5860. msg_len = sizeof(buf)-12;
  5861. }
  5862. WBUFW(buf,0) = 0x2C1;
  5863. WBUFW(buf,2) = (len = msg_len + 12);
  5864. WBUFL(buf,4) = 0;
  5865. WBUFL(buf,8) = color;
  5866. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5867. iter = db_iterator(channel->users);
  5868. for( user = (map_session_data *)dbi_first(iter); dbi_exists(iter); user = (map_session_data *)dbi_next(iter) ) {
  5869. clif_send(buf, len, &user->bl, SELF);
  5870. }
  5871. dbi_destroy(iter);
  5872. }
  5873. /// Displays heal effect.
  5874. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5875. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5876. /// var id:
  5877. /// 5 = HP (SP_HP)
  5878. /// 7 = SP (SP_SP)
  5879. /// ? = ignored
  5880. void clif_heal(int fd,int type,int val) {
  5881. #if PACKETVER < 20141022
  5882. const int cmd = 0x13d;
  5883. #else
  5884. const int cmd = 0xa27;
  5885. #endif
  5886. WFIFOHEAD(fd, packet_len(cmd));
  5887. WFIFOW(fd,0) = cmd;
  5888. WFIFOW(fd,2) = type;
  5889. #if PACKETVER < 20141022
  5890. WFIFOW(fd,4) = min(val, INT16_MAX);
  5891. #else
  5892. WFIFOL(fd,4) = min(val, INT32_MAX);
  5893. #endif
  5894. WFIFOSET(fd, packet_len(cmd));
  5895. }
  5896. /// Displays resurrection effect (ZC_RESURRECTION).
  5897. /// 0148 <id>.L <type>.W
  5898. /// type:
  5899. /// ignored
  5900. void clif_resurrection(struct block_list *bl,int type)
  5901. {
  5902. unsigned char buf[16];
  5903. nullpo_retv(bl);
  5904. WBUFW(buf,0)=0x148;
  5905. WBUFL(buf,2)=bl->id;
  5906. WBUFW(buf,6)=0;
  5907. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5908. if (disguised(bl))
  5909. clif_spawn(bl);
  5910. }
  5911. /// Sets the map property
  5912. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5913. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5914. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5915. {
  5916. #if PACKETVER >= 20121010
  5917. short cmd = 0x99b;
  5918. unsigned char buf[8];
  5919. #else
  5920. short cmd = 0x199;
  5921. unsigned char buf[4];
  5922. #endif
  5923. WBUFW(buf,0)=cmd;
  5924. WBUFW(buf,2)=property;
  5925. #if PACKETVER >= 20121010
  5926. struct map_data *mapdata = map_getmapdata(bl->m);
  5927. map_session_data *sd = BL_CAST(BL_PC, bl);
  5928. WBUFL(buf,4) = ((mapdata->getMapFlag(MF_PVP) || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5929. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5930. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5931. ((mapdata->getMapFlag(MF_FORCEMINEFFECT) || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5932. ((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
  5933. ((mapdata->getMapFlag(MF_PVP))<<5)| // COUNT_PK - Show the PvP counter
  5934. ((mapdata->getMapFlag(MF_PARTYLOCK))<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5935. ((mapdata->getMapFlag(MF_BATTLEGROUND))<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5936. ((mapdata->getMapFlag(MF_NOCOSTUME))<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5937. ((!mapdata->getMapFlag(MF_NOUSECART))<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5938. ((!mapdata->getMapFlag(MF_NOSUNMOONSTARMIRACLE))<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5939. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5940. #endif
  5941. clif_send(buf,packet_len(cmd),bl,t);
  5942. }
  5943. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5944. /// 01d6 <type>.W
  5945. void clif_map_type(map_session_data* sd, enum map_type type)
  5946. {
  5947. int fd;
  5948. nullpo_retv(sd);
  5949. fd=sd->fd;
  5950. WFIFOHEAD(fd,packet_len(0x1D6));
  5951. WFIFOW(fd,0)=0x1D6;
  5952. WFIFOW(fd,2)=type;
  5953. WFIFOSET(fd,packet_len(0x1D6));
  5954. }
  5955. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5956. /// 019a <id>.L <ranking>.L <total>.L
  5957. void clif_pvpset(map_session_data *sd,int pvprank,int pvpnum,int type)
  5958. {
  5959. if(type == 2) {
  5960. int fd = sd->fd;
  5961. WFIFOHEAD(fd,packet_len(0x19a));
  5962. WFIFOW(fd,0) = 0x19a;
  5963. WFIFOL(fd,2) = sd->bl.id;
  5964. WFIFOL(fd,6) = pvprank;
  5965. WFIFOL(fd,10) = pvpnum;
  5966. WFIFOSET(fd,packet_len(0x19a));
  5967. } else {
  5968. unsigned char buf[32];
  5969. WBUFW(buf,0) = 0x19a;
  5970. WBUFL(buf,2) = sd->bl.id;
  5971. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5972. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5973. else
  5974. WBUFL(buf,6) = pvprank;
  5975. WBUFL(buf,10) = pvpnum;
  5976. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5977. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5978. else if(!type)
  5979. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5980. else
  5981. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5982. }
  5983. }
  5984. /*==========================================
  5985. *
  5986. *------------------------------------------*/
  5987. void clif_map_property_mapall(int map_idx, enum map_property property)
  5988. {
  5989. struct block_list bl;
  5990. bl.id = 0;
  5991. bl.type = BL_NUL;
  5992. bl.m = map_idx;
  5993. clif_map_property( &bl, property, ALL_SAMEMAP );
  5994. }
  5995. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5996. /// 0188 <result>.W <index>.W <refine>.W
  5997. /// result:
  5998. /// 0 = success
  5999. /// 1 = failure
  6000. /// 2 = downgrade
  6001. void clif_refine(int fd, int fail, int index, int val)
  6002. {
  6003. WFIFOHEAD(fd,packet_len(0x188));
  6004. WFIFOW(fd,0)=0x188;
  6005. WFIFOW(fd,2)=fail;
  6006. WFIFOW(fd,4)=index+2;
  6007. WFIFOW(fd,6)=val;
  6008. WFIFOSET(fd,packet_len(0x188));
  6009. }
  6010. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  6011. /// 0223 <result>.L <nameid>.W
  6012. /// result:
  6013. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  6014. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  6015. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  6016. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  6017. void clif_upgrademessage( map_session_data* sd, int result, t_itemid item_id ){
  6018. struct PACKET_ZC_ACK_WEAPONREFINE p;
  6019. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  6020. p.result = result;
  6021. p.itemId = client_nameid( item_id );
  6022. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6023. }
  6024. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  6025. /// 0097 <packet len>.W <nick>.24B <message>.?B
  6026. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  6027. void clif_wis_message(map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  6028. int fd;
  6029. nullpo_retv(sd);
  6030. fd = sd->fd;
  6031. #if PACKETVER < 20091104
  6032. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  6033. WFIFOW(fd,0) = 0x97;
  6034. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  6035. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  6036. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  6037. WFIFOSET(fd,WFIFOW(fd,2));
  6038. #else
  6039. map_session_data *ssd = map_nick2sd(nick,false);
  6040. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  6041. WFIFOW(fd,0) = 0x97;
  6042. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  6043. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  6044. // If it is not a message from the server or a player from another map-server
  6045. if( ssd ){
  6046. gmlvl = pc_get_group_level(ssd);
  6047. }
  6048. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  6049. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  6050. WFIFOSET(fd,WFIFOW(fd,2));
  6051. #endif
  6052. }
  6053. /// Inform the player about the result of his whisper action
  6054. /// 0098 <result>.B (ZC_ACK_WHISPER).
  6055. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  6056. /// result:
  6057. /// 0 = success to send wisper
  6058. /// 1 = target character is not loged in
  6059. /// 2 = ignored by target
  6060. /// 3 = everyone ignored by target
  6061. void clif_wis_end(int fd, int result)
  6062. {
  6063. map_session_data *sd = (session_isActive(fd) ? (map_session_data *)session[fd]->session_data : NULL);
  6064. #if PACKETVER < 20131223
  6065. const int cmd = 0x98;
  6066. #else
  6067. const int cmd = 0x9df;
  6068. #endif
  6069. if (!sd)
  6070. return;
  6071. WFIFOHEAD(fd,packet_len(cmd));
  6072. WFIFOW(fd,0) = cmd;
  6073. WFIFOB(fd,2) = (char)result;
  6074. #if PACKETVER >= 20131223
  6075. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  6076. #endif
  6077. WFIFOSET(fd,packet_len(cmd));
  6078. }
  6079. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  6080. /// 0194 <char id>.L <name>.24B
  6081. /// 0af7 <flag>.W <char id>.L <name>.24B
  6082. void clif_solved_charname(int fd, int charid, const char* name)
  6083. {
  6084. #if PACKETVER >= 20180221
  6085. WFIFOHEAD(fd,packet_len(0xaf7));
  6086. WFIFOW(fd,0) = 0xaf7;
  6087. WFIFOW(fd,2) = name[0] ? 3 : 2;
  6088. WFIFOL(fd,4) = charid;
  6089. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  6090. WFIFOSET(fd,packet_len(0x0af7));
  6091. #else
  6092. WFIFOHEAD(fd,packet_len(0x194));
  6093. WFIFOW(fd,0)=0x194;
  6094. WFIFOL(fd,2)=charid;
  6095. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  6096. WFIFOSET(fd,packet_len(0x194));
  6097. #endif
  6098. }
  6099. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  6100. /// 017b <packet len>.W { <name id>.W }*
  6101. void clif_use_card(map_session_data *sd,int idx)
  6102. {
  6103. int i,c,ep;
  6104. int fd=sd->fd;
  6105. nullpo_retv(sd);
  6106. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6107. return;
  6108. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6109. return; //Avoid parsing invalid item indexes (no card/no item)
  6110. ep=sd->inventory_data[idx]->equip;
  6111. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6112. WFIFOW(fd,0)=0x17b;
  6113. for(i=c=0;i<MAX_INVENTORY;i++){
  6114. int j;
  6115. if(sd->inventory_data[i] == NULL)
  6116. continue;
  6117. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6118. continue;
  6119. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6120. continue;
  6121. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6122. continue;
  6123. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6124. continue;
  6125. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6126. continue;
  6127. 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.
  6128. continue;
  6129. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6130. if( j == sd->inventory_data[i]->slots ) // No room
  6131. continue;
  6132. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6133. continue;
  6134. WFIFOW(fd,4+c*2)=i+2;
  6135. c++;
  6136. }
  6137. if( !c ) return; // no item is available for card insertion
  6138. WFIFOW(fd,2)=4+c*2;
  6139. WFIFOSET(fd,WFIFOW(fd,2));
  6140. }
  6141. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6142. /// 017d <equip index>.W <card index>.W <result>.B
  6143. /// result:
  6144. /// 0 = success
  6145. /// 1 = failure
  6146. void clif_insert_card(map_session_data *sd,int idx_equip,int idx_card,int flag)
  6147. {
  6148. int fd;
  6149. nullpo_retv(sd);
  6150. fd=sd->fd;
  6151. WFIFOHEAD(fd,packet_len(0x17d));
  6152. WFIFOW(fd,0)=0x17d;
  6153. WFIFOW(fd,2)=idx_equip+2;
  6154. WFIFOW(fd,4)=idx_card+2;
  6155. WFIFOB(fd,6)=flag;
  6156. WFIFOSET(fd,packet_len(0x17d));
  6157. }
  6158. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6159. /// 0177 <packet len>.W { <index>.W }*
  6160. void clif_item_identify_list(map_session_data *sd)
  6161. {
  6162. int i,c;
  6163. int fd;
  6164. nullpo_retv(sd);
  6165. fd=sd->fd;
  6166. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6167. WFIFOW(fd,0)=0x177;
  6168. for(i=c=0;i<MAX_INVENTORY;i++){
  6169. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6170. WFIFOW(fd,c*2+4)=client_index(i);
  6171. c++;
  6172. }
  6173. }
  6174. if(c > 0) {
  6175. WFIFOW(fd,2)=c*2+4;
  6176. WFIFOSET(fd,WFIFOW(fd,2));
  6177. sd->menuskill_id = MC_IDENTIFY;
  6178. sd->menuskill_val = c;
  6179. sd->state.workinprogress = WIP_DISABLE_ALL;
  6180. }
  6181. }
  6182. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6183. /// 0179 <index>.W <result>.B
  6184. void clif_item_identified(map_session_data *sd,int idx,int flag)
  6185. {
  6186. int fd;
  6187. nullpo_retv(sd);
  6188. fd=sd->fd;
  6189. WFIFOHEAD(fd,packet_len(0x179));
  6190. WFIFOW(fd, 0)=0x179;
  6191. WFIFOW(fd, 2)=idx+2;
  6192. WFIFOB(fd, 4)=flag;
  6193. WFIFOSET(fd,packet_len(0x179));
  6194. }
  6195. /// Presents a list of items that can be repaired.
  6196. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6197. void clif_item_repair_list( map_session_data *sd,map_session_data *dstsd, int lv ){
  6198. nullpo_retv( sd );
  6199. nullpo_retv( dstsd );
  6200. int fd = sd->fd;
  6201. if( !session_isActive( fd ) ){
  6202. return;
  6203. }
  6204. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6205. // Preallocate the maximum size
  6206. WFIFOHEAD( fd, len );
  6207. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6208. int c = 0;
  6209. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6210. 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)){
  6211. p->items[c].index = i;
  6212. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6213. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6214. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6215. c++;
  6216. }
  6217. }
  6218. if( c > 0 ){
  6219. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6220. // Recalculate real length
  6221. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6222. p->packetLength = len;
  6223. WFIFOSET( fd, len );
  6224. sd->menuskill_id = BS_REPAIRWEAPON;
  6225. sd->menuskill_val = dstsd->bl.id;
  6226. sd->menuskill_val2 = lv;
  6227. }else{
  6228. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6229. }
  6230. }
  6231. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6232. /// 01fe <index>.W <result>.B
  6233. /// index:
  6234. /// ignored (inventory index)
  6235. /// result:
  6236. /// 0 = Item repair success.
  6237. /// 1 = Item repair failure.
  6238. void clif_item_repaireffect(map_session_data *sd,int idx,int flag)
  6239. {
  6240. int fd;
  6241. nullpo_retv(sd);
  6242. fd = sd->fd;
  6243. WFIFOHEAD(fd,packet_len(0x1fe));
  6244. WFIFOW(fd, 0)=0x1fe;
  6245. WFIFOW(fd, 2)=idx+2;
  6246. WFIFOB(fd, 4)=flag;
  6247. WFIFOSET(fd,packet_len(0x1fe));
  6248. }
  6249. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6250. /// 02bb <equip location>.W <account id>.L
  6251. void clif_item_damaged(map_session_data* sd, unsigned short position)
  6252. {
  6253. int fd = sd->fd;
  6254. WFIFOHEAD(fd,packet_len(0x2bb));
  6255. WFIFOW(fd,0) = 0x2bb;
  6256. WFIFOW(fd,2) = position;
  6257. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6258. WFIFOSET(fd,packet_len(0x2bb));
  6259. }
  6260. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6261. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6262. void clif_item_refine_list( map_session_data *sd ){
  6263. nullpo_retv( sd );
  6264. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6265. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6266. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6267. int refine_item[MAX_WEAPON_LEVEL];
  6268. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6269. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6270. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6271. #ifdef RENEWAL
  6272. refine_item[4] = -1;
  6273. #endif
  6274. int count = 0;
  6275. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6276. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6277. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6278. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6279. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6280. p->items[count].index = client_index( i );
  6281. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6282. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6283. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6284. count++;
  6285. }
  6286. }
  6287. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6288. clif_send( p, p->packetLength, &sd->bl, SELF );
  6289. if( count > 0 ){
  6290. sd->menuskill_id = WS_WEAPONREFINE;
  6291. sd->menuskill_val = skill_lv;
  6292. }
  6293. }
  6294. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6295. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6296. void clif_item_skill( map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6297. nullpo_retv( sd );
  6298. struct PACKET_ZC_AUTORUN_SKILL p;
  6299. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6300. p.skill_id = skill_id;
  6301. p.skill_type = skill_get_inf( skill_id );
  6302. p.skill_lv = skill_lv;
  6303. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6304. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6305. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6306. p.up_flag = false;
  6307. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6308. }
  6309. /// Adds an item to character's cart.
  6310. /// 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)
  6311. /// 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)
  6312. /// 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)
  6313. void clif_cart_additem( map_session_data *sd, int n, int amount ){
  6314. nullpo_retv( sd );
  6315. int fd = sd->fd;
  6316. if( !session_isActive( fd ) ){
  6317. return;
  6318. }
  6319. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6320. return;
  6321. }
  6322. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6323. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6324. p.index = client_index( n );
  6325. p.amount = amount;
  6326. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6327. #if PACKETVER >= 5
  6328. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6329. #endif
  6330. p.identified = sd->cart.u.items_cart[n].identify;
  6331. p.damaged = sd->cart.u.items_cart[n].attribute;
  6332. p.refine = sd->cart.u.items_cart[n].refine;
  6333. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6334. #if PACKETVER >= 20150226
  6335. clif_add_random_options( p.option_data, sd->cart.u.items_cart[n] );
  6336. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6337. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6338. #endif
  6339. #endif
  6340. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6341. }
  6342. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6343. /* Acknowledge an item have been added to cart
  6344. * 012c <result>B
  6345. * result :
  6346. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6347. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6348. */
  6349. void clif_cart_additem_ack(map_session_data *sd, uint8 flag)
  6350. {
  6351. int fd;
  6352. unsigned char *buf;
  6353. nullpo_retv(sd);
  6354. fd = sd->fd;
  6355. buf = WFIFOP(fd,0);
  6356. WBUFW(buf,0) = 0x12c;
  6357. WBUFB(buf,2) = flag;
  6358. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6359. }
  6360. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6361. void clif_bank_open( map_session_data& sd ){
  6362. #if PACKETVER >= 20130717
  6363. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6364. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6365. p.unknown = 0;
  6366. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6367. #endif
  6368. }
  6369. /*
  6370. * Request to Open the banking system
  6371. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6372. */
  6373. void clif_parse_BankOpen(int fd, map_session_data* sd) {
  6374. //TODO check if preventing trade or stuff like that
  6375. //also mark something in case char ain't available for saving, should we check now ?
  6376. nullpo_retv(sd);
  6377. if( !battle_config.feature_banking ) {
  6378. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6379. return;
  6380. }
  6381. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6382. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6383. return;
  6384. }
  6385. else {
  6386. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6387. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6388. if(sd->status.account_id == aid){
  6389. sd->state.banking = 1;
  6390. //request save ?
  6391. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6392. //on succes open bank ?
  6393. clif_bank_open( *sd );
  6394. }
  6395. }
  6396. }
  6397. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6398. void clif_bank_close( map_session_data& sd ){
  6399. #if PACKETVER >= 20130717
  6400. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6401. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6402. p.unknown = 0;
  6403. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6404. #endif
  6405. }
  6406. /*
  6407. * Request to close the banking system
  6408. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6409. */
  6410. void clif_parse_BankClose(int fd, map_session_data* sd) {
  6411. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6412. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6413. nullpo_retv(sd);
  6414. if( !battle_config.feature_banking ) {
  6415. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6416. //still allow to go trough to not stuck player if we have disable it while they was in
  6417. }
  6418. if(sd->status.account_id == aid){
  6419. sd->state.banking = 0;
  6420. clif_bank_close( *sd );
  6421. }
  6422. }
  6423. /*
  6424. * Display how much we got in bank (I suppose)
  6425. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6426. */
  6427. void clif_Bank_Check( map_session_data& sd ){
  6428. #if PACKETVER >= 20130717
  6429. struct PACKET_ZC_BANKING_CHECK p = {};
  6430. p.packetType = HEADER_ZC_BANKING_CHECK;
  6431. p.money = sd.bank_vault;
  6432. p.reason = 0;
  6433. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6434. #endif
  6435. }
  6436. /*
  6437. * Requesting the data in bank
  6438. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6439. */
  6440. void clif_parse_BankCheck(int fd, map_session_data* sd) {
  6441. nullpo_retv(sd);
  6442. if( !battle_config.feature_banking ) {
  6443. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6444. return;
  6445. }
  6446. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6447. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6448. return;
  6449. }
  6450. else {
  6451. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6452. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6453. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6454. clif_Bank_Check( *sd );
  6455. }
  6456. }
  6457. /*
  6458. * Acknowledge of deposit some money in bank
  6459. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6460. */
  6461. void clif_bank_deposit( map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6462. #if PACKETVER >= 20130717
  6463. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6464. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6465. p.money = sd.bank_vault;
  6466. p.zeny = sd.status.zeny;
  6467. p.reason = reason;
  6468. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6469. #endif
  6470. }
  6471. /*
  6472. * Request saving some money in bank
  6473. * @author : original [Yommy/Hercules]
  6474. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6475. */
  6476. void clif_parse_BankDeposit(int fd, map_session_data* sd) {
  6477. nullpo_retv(sd);
  6478. if( !battle_config.feature_banking ) {
  6479. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6480. return;
  6481. }
  6482. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6483. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6484. return;
  6485. }
  6486. else {
  6487. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6488. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6489. int money = RFIFOL(fd,info->pos[1]);
  6490. if(sd->status.account_id == aid){
  6491. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6492. clif_bank_deposit( *sd, reason );
  6493. }
  6494. }
  6495. }
  6496. /*
  6497. * Acknowledge of withdrawing some money from bank
  6498. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6499. */
  6500. void clif_bank_withdraw( map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6501. #if PACKETVER >= 20130717
  6502. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6503. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6504. p.reason = reason;
  6505. p.money = sd.bank_vault;
  6506. p.zeny = sd.status.zeny;
  6507. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6508. #endif
  6509. }
  6510. /*
  6511. * Request Withdrawing some money from bank
  6512. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6513. */
  6514. void clif_parse_BankWithdraw(int fd, map_session_data* sd) {
  6515. nullpo_retv(sd);
  6516. if( !battle_config.feature_banking ) {
  6517. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6518. return;
  6519. }
  6520. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6521. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6522. return;
  6523. }
  6524. else {
  6525. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6526. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6527. int money = RFIFOL(fd,info->pos[1]);
  6528. if(sd->status.account_id == aid){
  6529. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6530. clif_bank_withdraw( *sd, reason );
  6531. }
  6532. }
  6533. }
  6534. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6535. /// 0125 <index>.W <amount>.L
  6536. void clif_cart_delitem(map_session_data *sd,int n,int amount)
  6537. {
  6538. int fd;
  6539. nullpo_retv(sd);
  6540. fd=sd->fd;
  6541. WFIFOHEAD(fd,packet_len(0x125));
  6542. WFIFOW(fd,0)=0x125;
  6543. WFIFOW(fd,2)=n+2;
  6544. WFIFOL(fd,4)=amount;
  6545. WFIFOSET(fd,packet_len(0x125));
  6546. }
  6547. /// Opens the shop creation menu (ZC_OPENSTORE).
  6548. /// 012d <num>.W
  6549. /// num:
  6550. /// number of allowed item slots
  6551. void clif_openvendingreq(map_session_data* sd, int num)
  6552. {
  6553. int fd;
  6554. nullpo_retv(sd);
  6555. fd = sd->fd;
  6556. WFIFOHEAD(fd,packet_len(0x12d));
  6557. WFIFOW(fd,0) = 0x12d;
  6558. WFIFOW(fd,2) = num;
  6559. WFIFOSET(fd,packet_len(0x12d));
  6560. }
  6561. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6562. /// 0131 <owner id>.L <message>.80B
  6563. void clif_showvendingboard( map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6564. if( tbl == nullptr ){
  6565. tbl = &sd.bl;
  6566. target = AREA_WOS;
  6567. }
  6568. struct PACKET_ZC_STORE_ENTRY p = {};
  6569. p.packetType = HEADER_ZC_STORE_ENTRY;
  6570. p.makerAID = sd.status.account_id;
  6571. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6572. clif_send( &p, sizeof( p ), tbl, target );
  6573. }
  6574. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6575. /// 0132 <owner id>.L
  6576. void clif_closevendingboard(struct block_list* bl, int fd)
  6577. {
  6578. unsigned char buf[16];
  6579. nullpo_retv(bl);
  6580. WBUFW(buf,0) = 0x132;
  6581. WBUFL(buf,2) = bl->id;
  6582. if( session_isActive(fd) ) {
  6583. WFIFOHEAD(fd,packet_len(0x132));
  6584. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6585. WFIFOSET(fd,packet_len(0x132));
  6586. } else {
  6587. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6588. }
  6589. }
  6590. /// Sends a list of items in a shop.
  6591. /// 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)
  6592. /// 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)
  6593. void clif_vendinglist( map_session_data* sd, map_session_data* vsd ){
  6594. nullpo_retv( sd );
  6595. nullpo_retv( vsd );
  6596. nullpo_retv( vsd->vending );
  6597. int fd = sd->fd;
  6598. if( !session_isActive( fd ) ){
  6599. return;
  6600. }
  6601. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6602. WFIFOHEAD( fd, len );
  6603. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6604. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6605. p->packetLength = len;
  6606. p->AID = vsd->status.account_id;
  6607. #if PACKETVER >= 20100105
  6608. p->venderId = vsd->vender_id;
  6609. #endif
  6610. for( int i = 0; i < vsd->vend_num; i++ ){
  6611. int index = vsd->vending[i].index;
  6612. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6613. p->items[i].price = vsd->vending[i].value;
  6614. p->items[i].amount = vsd->vending[i].amount;
  6615. p->items[i].index = client_index( index );
  6616. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6617. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6618. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6619. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6620. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6621. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6622. #if PACKETVER >= 20150226
  6623. clif_add_random_options( p->items[i].option_data, vsd->cart.u.items_cart[index] );
  6624. #if PACKETVER >= 20160921
  6625. p->items[i].location = pc_equippoint_sub( sd, data );
  6626. p->items[i].viewSprite = data->look;
  6627. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6628. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6629. #endif
  6630. #endif
  6631. #endif
  6632. }
  6633. WFIFOSET( fd, len );
  6634. }
  6635. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6636. /// 0135 <index>.W <amount>.W <result>.B
  6637. /// result:
  6638. /// 0 = success
  6639. /// 1 = not enough zeny
  6640. /// 2 = overweight
  6641. /// 4 = out of stock
  6642. /// 5 = "cannot use an npc shop while in a trade"
  6643. /// 6 = Because the store information was incorrect the item was not purchased.
  6644. /// 7 = No sales information.
  6645. void clif_buyvending(map_session_data* sd, int index, int amount, int fail)
  6646. {
  6647. int fd;
  6648. nullpo_retv(sd);
  6649. fd = sd->fd;
  6650. WFIFOHEAD(fd,packet_len(0x135));
  6651. WFIFOW(fd,0) = 0x135;
  6652. WFIFOW(fd,2) = index+2;
  6653. WFIFOW(fd,4) = amount;
  6654. WFIFOB(fd,6) = fail;
  6655. WFIFOSET(fd,packet_len(0x135));
  6656. }
  6657. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6658. /// 0a28 <Result>.B
  6659. /// result:
  6660. /// 0 = Successed
  6661. /// 1 = Failed
  6662. void clif_openvending_ack(map_session_data* sd, int result)
  6663. {
  6664. int fd;
  6665. nullpo_retv(sd);
  6666. fd = sd->fd;
  6667. WFIFOHEAD(fd, 3);
  6668. WFIFOW(fd,0) = 0xa28;
  6669. WFIFOB(fd,2) = result;
  6670. WFIFOSET(fd, 3);
  6671. }
  6672. /// Shop creation success.
  6673. /// 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)
  6674. void clif_openvending( map_session_data* sd, int id, struct s_vending* vending ){
  6675. nullpo_retv( sd );
  6676. nullpo_retv( vending );
  6677. int fd = sd->fd;
  6678. if( !session_isActive( fd ) ){
  6679. return;
  6680. }
  6681. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6682. WFIFOHEAD( fd, len );
  6683. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6684. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6685. p->packetLength = len;
  6686. p->AID = id;
  6687. for( int i = 0; i < sd->vend_num; i++ ) {
  6688. int index = vending[i].index;
  6689. p->items[i].price = vending[i].value;
  6690. p->items[i].index = client_index( index );
  6691. p->items[i].amount = vending[i].amount;
  6692. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6693. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6694. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6695. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6696. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6697. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6698. #if PACKETVER >= 20150226
  6699. clif_add_random_options( p->items[i].option_data, sd->cart.u.items_cart[index] );
  6700. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6701. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6702. #endif
  6703. #endif
  6704. }
  6705. WFIFOSET( fd, len );
  6706. #if PACKETVER >= 20141022
  6707. /// 0 = Successed
  6708. /// 1 = Failed
  6709. clif_openvending_ack( sd, 0 );
  6710. #endif
  6711. }
  6712. /// Inform merchant that someone has bought an item.
  6713. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6714. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6715. void clif_vendingreport(map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6716. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6717. const int cmd = 0x137;
  6718. #else
  6719. const int cmd = 0x9e5;
  6720. #endif
  6721. int fd = sd->fd;
  6722. nullpo_retv(sd);
  6723. WFIFOHEAD(fd,packet_len(cmd));
  6724. WFIFOW(fd,0) = cmd;
  6725. WFIFOW(fd,2) = index+2;
  6726. WFIFOW(fd,4) = amount;
  6727. #if PACKETVER >= 20141016
  6728. WFIFOL(fd,6) = char_id; // GID
  6729. WFIFOL(fd,10) = (int)time(NULL); // Date
  6730. WFIFOL(fd,14) = zeny; // zeny
  6731. #endif
  6732. WFIFOSET(fd,packet_len(cmd));
  6733. }
  6734. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6735. /// 00fa <result>.B
  6736. /// result:
  6737. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6738. /// 1 = MsgStringTable[78]="party name already exists"
  6739. /// 2 = MsgStringTable[79]="already in a party"
  6740. /// 3 = cannot organize parties on this map
  6741. /// ? = nothing
  6742. void clif_party_created( map_session_data& sd, int result ){
  6743. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6744. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6745. p.result = result;
  6746. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6747. }
  6748. /// Adds new member to a party.
  6749. /// 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)
  6750. /// 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)
  6751. /// 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)
  6752. /// role:
  6753. /// 0 = leader
  6754. /// 1 = normal
  6755. /// state:
  6756. /// 0 = connected
  6757. /// 1 = disconnected
  6758. void clif_party_member_info( struct party_data& party, map_session_data& sd ){
  6759. int id = party_getmemberid( &party, &sd );
  6760. if( id < 0 ){
  6761. return;
  6762. }
  6763. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6764. p.packetType = partymemberinfo;
  6765. p.AID = sd.status.account_id;
  6766. #if PACKETVER >= 20171207
  6767. p.GID = sd.status.char_id;
  6768. #endif
  6769. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6770. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6771. p.class_ = sd.status.class_;
  6772. p.baseLevel = sd.status.base_level;
  6773. #endif
  6774. p.x = sd.bl.x;
  6775. p.y = sd.bl.y;
  6776. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6777. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6778. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6779. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6780. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6781. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6782. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6783. }
  6784. /// Sends party information (ZC_GROUP_LIST).
  6785. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6786. /// role:
  6787. /// 0 = leader
  6788. /// 1 = normal
  6789. /// state:
  6790. /// 0 = connected
  6791. /// 1 = disconnected
  6792. /// 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
  6793. void clif_party_info( struct party_data& party, map_session_data* sd ){
  6794. send_target target;
  6795. if( sd == nullptr ){
  6796. sd = party_getavailablesd( &party );
  6797. if( sd == nullptr ){
  6798. // Nobody is online to notify
  6799. return;
  6800. }
  6801. // Send to whole party
  6802. target = PARTY;
  6803. }else{
  6804. // Send only to self
  6805. target = SELF;
  6806. }
  6807. struct PACKET_ZC_GROUP_LIST* p = (struct PACKET_ZC_GROUP_LIST*)packet_buffer;
  6808. p->packetType = partyinfo;
  6809. p->packetLen = sizeof( *p );
  6810. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6811. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6812. struct party_member& m = party.party.member[i];
  6813. if( m.account_id == 0 ){
  6814. continue;
  6815. }
  6816. struct PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6817. member.AID = m.account_id;
  6818. #if PACKETVER >= 20171207
  6819. member.GID = m.char_id;
  6820. #endif
  6821. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6822. mapindex_getmapname_ext( m.map, member.mapName );
  6823. member.leader = ( m.leader ) ? 0 : 1;
  6824. member.offline = ( m.online ) ? 0 : 1;
  6825. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6826. member.class_ = m.class_;
  6827. member.baseLevel = m.lv;
  6828. #endif
  6829. c++;
  6830. p->packetLen += sizeof( member );
  6831. }
  6832. clif_send( p, p->packetLen, &sd->bl, target );
  6833. }
  6834. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6835. /// 02c9 <flag>.B
  6836. /// flag:
  6837. /// 0 = allow party invites
  6838. /// 1 = auto-deny party invites
  6839. void clif_partyinvitationstate( map_session_data& sd ){
  6840. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6841. struct PACKET_ZC_PARTY_CONFIG p = {};
  6842. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6843. p.denyPartyInvites = 0; // TODO: not implemented
  6844. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6845. #endif
  6846. }
  6847. /// Party invitation request.
  6848. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6849. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6850. void clif_party_invite( map_session_data& sd, map_session_data& tsd ){
  6851. struct party_data* party = party_search( sd.status.party_id );
  6852. if( party == nullptr ){
  6853. return;
  6854. }
  6855. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6856. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6857. p.GRID = party->party.party_id;
  6858. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6859. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6860. }
  6861. /// Party invite result.
  6862. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6863. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6864. /// result=0 : char is already in a party -> MsgStringTable[80]
  6865. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6866. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6867. /// result=3 : party is full -> MsgStringTable[83]
  6868. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6869. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6870. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6871. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6872. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6873. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6874. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6875. void clif_party_invite_reply( map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6876. #if PACKETVER < 20070904
  6877. if( reply == PARTY_REPLY_OFFLINE ){
  6878. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6879. return;
  6880. }
  6881. #endif
  6882. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6883. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6884. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6885. p.result = reply;
  6886. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6887. }
  6888. /// Updates party settings.
  6889. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6890. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6891. /// exp option:
  6892. /// 0 = exp sharing disabled
  6893. /// 1 = exp sharing enabled
  6894. /// 2 = cannot change exp sharing
  6895. ///
  6896. /// flag:
  6897. /// 0 = send to party
  6898. /// 1 = send to sd
  6899. void clif_party_option(struct party_data *p,map_session_data *sd,int flag)
  6900. {
  6901. unsigned char buf[16];
  6902. #if PACKETVER < 20090603
  6903. const int cmd = 0x101;
  6904. #else
  6905. const int cmd = 0x7d8;
  6906. #endif
  6907. nullpo_retv(p);
  6908. if(!sd && flag==0){
  6909. int i;
  6910. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6911. if (i < MAX_PARTY)
  6912. sd = p->data[i].sd;
  6913. }
  6914. if(!sd) return;
  6915. WBUFW(buf,0)=cmd;
  6916. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6917. #if PACKETVER >= 20090603
  6918. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6919. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6920. #endif
  6921. if(flag==0)
  6922. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6923. else
  6924. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6925. }
  6926. /**
  6927. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6928. * @param sd Send the notification for this player
  6929. * @param account_id Account ID of kicked member
  6930. * @param name Name of kicked member
  6931. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6932. * @param target Send target
  6933. **/
  6934. void clif_party_withdraw( map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6935. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6936. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6937. p.AID = account_id;
  6938. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6939. p.result = result;
  6940. clif_send( &p, sizeof( p ), &sd.bl, target );
  6941. }
  6942. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6943. /// 0109 <packet len>.W <account id>.L <message>.?B
  6944. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, int len ){
  6945. map_session_data* sd = party_getavailablesd( &party );
  6946. if( sd == nullptr ){
  6947. return;
  6948. }
  6949. if (len > CHAT_SIZE_MAX) {
  6950. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6951. len = CHAT_SIZE_MAX;
  6952. }
  6953. struct PACKET_ZC_NOTIFY_CHAT_PARTY* p = (struct PACKET_ZC_NOTIFY_CHAT_PARTY*)packet_buffer;
  6954. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6955. p->PacketLength = sizeof( *p ) + len;
  6956. p->AID = account_id;
  6957. safestrncpy( p->chatMsg, mes, len );
  6958. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6959. }
  6960. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6961. /// 0107 <account id>.L <x>.W <y>.W
  6962. void clif_party_xy( map_session_data& sd ){
  6963. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6964. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6965. p.AID = sd.status.account_id;
  6966. p.xPos = sd.bl.x;
  6967. p.yPos = sd.bl.y;
  6968. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6969. }
  6970. /*==========================================
  6971. * Sends x/y dot to a single fd. [Skotlex]
  6972. *------------------------------------------*/
  6973. void clif_party_xy_single( map_session_data& sd, map_session_data& tsd ){
  6974. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6975. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6976. p.AID = sd.status.account_id;
  6977. p.xPos = sd.bl.x;
  6978. p.yPos = sd.bl.y;
  6979. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6980. }
  6981. /// Updates HP bar of a party member.
  6982. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6983. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6984. void clif_party_hp( map_session_data& sd ){
  6985. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6986. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6987. p.AID = sd.status.account_id;
  6988. #if PACKETVER < 20100119
  6989. // To correctly display the %hp bar. [Skotlex]
  6990. if( sd.battle_status.max_hp > INT16_MAX ){
  6991. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6992. p.maxhp = 100;
  6993. }else{
  6994. p.hp = sd.battle_status.hp;
  6995. p.maxhp = sd.battle_status.max_hp;
  6996. }
  6997. #else
  6998. p.hp = sd.battle_status.hp;
  6999. p.maxhp = sd.battle_status.max_hp;
  7000. #endif
  7001. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  7002. }
  7003. /// Notifies the party members of a character's death or revival.
  7004. /// 0AB2 <GID>.L <dead>.B
  7005. void clif_party_dead( map_session_data& sd ){
  7006. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  7007. struct PACKET_ZC_GROUP_ISALIVE p = {};
  7008. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  7009. p.AID = sd.status.account_id;
  7010. p.isDead = pc_isdead( &sd );
  7011. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  7012. #endif
  7013. }
  7014. /// Updates the job and level of a party member
  7015. /// 0abd <account id>.L <job>.W <level>.W
  7016. void clif_party_job_and_level( map_session_data& sd ){
  7017. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  7018. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  7019. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  7020. p.AID = sd.status.account_id;
  7021. p.job = sd.status.class_;
  7022. p.level = sd.status.base_level;
  7023. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  7024. #endif
  7025. }
  7026. /*==========================================
  7027. * Sends HP bar to a single fd. [Skotlex]
  7028. *------------------------------------------*/
  7029. void clif_hpmeter_single( map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  7030. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  7031. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  7032. p.AID = id;
  7033. #if PACKETVER < 20100119
  7034. // To correctly display the %hp bar. [Skotlex]
  7035. if( maxhp > INT16_MAX ){
  7036. p.hp = hp / ( maxhp / 100 );
  7037. p.maxhp = 100;
  7038. }else{
  7039. p.hp = hp;
  7040. p.maxhp = maxhp;
  7041. }
  7042. #else
  7043. p.hp = hp;
  7044. p.maxhp = maxhp;
  7045. #endif
  7046. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7047. }
  7048. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  7049. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  7050. void clif_movetoattack(map_session_data *sd,struct block_list *bl)
  7051. {
  7052. int fd;
  7053. nullpo_retv(sd);
  7054. nullpo_retv(bl);
  7055. fd=sd->fd;
  7056. WFIFOHEAD(fd,packet_len(0x139));
  7057. WFIFOW(fd, 0)=0x139;
  7058. WFIFOL(fd, 2)=bl->id;
  7059. WFIFOW(fd, 6)=bl->x;
  7060. WFIFOW(fd, 8)=bl->y;
  7061. WFIFOW(fd,10)=sd->bl.x;
  7062. WFIFOW(fd,12)=sd->bl.y;
  7063. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  7064. WFIFOSET(fd,packet_len(0x139));
  7065. }
  7066. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  7067. /// 018f <result>.W <name id>.W
  7068. /// result:
  7069. /// 0 = success
  7070. /// 1 = failure
  7071. /// 2 = success (alchemist)
  7072. /// 3 = failure (alchemist)
  7073. void clif_produceeffect(map_session_data* sd,int flag, t_itemid nameid){
  7074. nullpo_retv( sd );
  7075. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  7076. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  7077. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  7078. p.result = flag;
  7079. p.itemId = client_nameid( nameid );
  7080. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7081. }
  7082. /// Initiates the pet taming process (ZC_START_CAPTURE).
  7083. /// 019e
  7084. void clif_catch_process(map_session_data *sd)
  7085. {
  7086. int fd;
  7087. nullpo_retv(sd);
  7088. fd=sd->fd;
  7089. WFIFOHEAD(fd,packet_len(0x19e));
  7090. WFIFOW(fd,0)=0x19e;
  7091. WFIFOSET(fd,packet_len(0x19e));
  7092. }
  7093. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  7094. /// 01a0 <result>.B
  7095. /// 0 = failure
  7096. /// 1 = success
  7097. void clif_pet_roulette(map_session_data *sd,int data)
  7098. {
  7099. int fd;
  7100. nullpo_retv(sd);
  7101. fd=sd->fd;
  7102. WFIFOHEAD(fd,packet_len(0x1a0));
  7103. WFIFOW(fd,0)=0x1a0;
  7104. WFIFOB(fd,2)=data;
  7105. WFIFOSET(fd,packet_len(0x1a0));
  7106. }
  7107. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7108. /// 01a6 <packet len>.W { <index>.W }*
  7109. void clif_sendegg(map_session_data *sd)
  7110. {
  7111. int i,n=0,fd;
  7112. nullpo_retv(sd);
  7113. fd=sd->fd;
  7114. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7115. clif_displaymessage(fd, msg_txt(sd,666));
  7116. return;
  7117. }
  7118. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7119. WFIFOW(fd,0)=0x1a6;
  7120. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7121. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7122. sd->inventory_data[i]->type != IT_PETEGG ||
  7123. sd->inventory.u.items_inventory[i].amount <= 0)
  7124. continue;
  7125. WFIFOW(fd,n*2+4)=client_index(i);
  7126. n++;
  7127. }
  7128. WFIFOW(fd,2)=4+n*2;
  7129. WFIFOSET(fd,WFIFOW(fd,2));
  7130. sd->menuskill_id = SA_TAMINGMONSTER;
  7131. sd->menuskill_val = -1;
  7132. }
  7133. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7134. /// 01a4 <type>.B <id>.L <data>.L
  7135. /// type:
  7136. /// 0 = pre-init (data = 0)
  7137. /// 1 = intimacy (data = 0~4)
  7138. /// 2 = hunger (data = 0~4)
  7139. /// 3 = accessory
  7140. /// 4 = performance (data = 1~3: normal, 4: special)
  7141. /// 5 = hairstyle
  7142. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7143. ///
  7144. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7145. void clif_send_petdata(map_session_data* sd, struct pet_data* pd, int type, int param)
  7146. {
  7147. uint8 buf[16];
  7148. nullpo_retv(pd);
  7149. WBUFW(buf,0) = 0x1a4;
  7150. WBUFB(buf,2) = type;
  7151. WBUFL(buf,3) = pd->bl.id;
  7152. WBUFL(buf,7) = param;
  7153. if (sd)
  7154. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7155. else
  7156. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7157. }
  7158. /// Pet's base data (ZC_PROPERTY_PET).
  7159. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7160. void clif_send_petstatus(map_session_data *sd)
  7161. {
  7162. int fd;
  7163. struct s_pet *pet;
  7164. nullpo_retv(sd);
  7165. nullpo_retv(sd->pd);
  7166. fd=sd->fd;
  7167. pet = &sd->pd->pet;
  7168. WFIFOHEAD(fd,packet_len(0x1a2));
  7169. WFIFOW(fd,0)=0x1a2;
  7170. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7171. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7172. WFIFOW(fd,27)=pet->level;
  7173. WFIFOW(fd,29)=pet->hungry;
  7174. WFIFOW(fd,31)=pet->intimate;
  7175. WFIFOW(fd,33)=pet->equip;
  7176. #if PACKETVER >= 20081126
  7177. WFIFOW(fd,35)=pet->class_;
  7178. #endif
  7179. WFIFOSET(fd,packet_len(0x1a2));
  7180. }
  7181. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7182. /// 01aa <id>.L <data>.L
  7183. /// data:
  7184. /// @see CZ_PET_ACT.
  7185. void clif_pet_emotion(struct pet_data *pd,int param)
  7186. {
  7187. unsigned char buf[16];
  7188. nullpo_retv(pd);
  7189. memset(buf,0,packet_len(0x1aa));
  7190. WBUFW(buf,0)=0x1aa;
  7191. WBUFL(buf,2)=pd->bl.id;
  7192. WBUFL(buf,6)=param;
  7193. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7194. }
  7195. /// Result of request to feed a pet (ZC_FEED_PET).
  7196. /// 01a3 <result>.B <name id>.W
  7197. /// result:
  7198. /// 0 = failure
  7199. /// 1 = success
  7200. void clif_pet_food( map_session_data *sd, int foodid,int fail ){
  7201. nullpo_retv( sd );
  7202. struct PACKET_ZC_FEED_PET p;
  7203. p.packetType = 0x1a3;
  7204. p.result = fail;
  7205. p.itemId = client_nameid( foodid );
  7206. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7207. }
  7208. /// Send pet auto feed info.
  7209. void clif_pet_autofeed_status(map_session_data* sd, bool force) {
  7210. #if PACKETVER >= 20141008
  7211. nullpo_retv(sd);
  7212. if (force || battle_config.pet_autofeed_always) {
  7213. // Always send ON or OFF
  7214. if (sd->pd && battle_config.feature_pet_autofeed) {
  7215. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7216. }
  7217. else {
  7218. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7219. }
  7220. }
  7221. else {
  7222. // Only send when enabled
  7223. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7224. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7225. }
  7226. }
  7227. #endif
  7228. }
  7229. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7230. /// 01cd { <skill id>.L }*7
  7231. void clif_autospell(map_session_data *sd,uint16 skill_lv)
  7232. {
  7233. nullpo_retv(sd);
  7234. int fd = sd->fd;
  7235. #ifdef RENEWAL
  7236. uint16 autospell_skill[][2] = {
  7237. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7238. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7239. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7240. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7241. };
  7242. int count = 0;
  7243. WFIFOHEAD(fd, 2 * 6 + 4);
  7244. WFIFOW(fd, 0) = 0x442;
  7245. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7246. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7247. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7248. count++;
  7249. }
  7250. }
  7251. WFIFOW(fd, 2) = 8 + count * 2;
  7252. WFIFOL(fd, 4) = count;
  7253. WFIFOSET(fd, WFIFOW(fd, 2));
  7254. #else
  7255. WFIFOHEAD(fd,packet_len(0x1cd));
  7256. WFIFOW(fd, 0)=0x1cd;
  7257. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7258. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7259. else
  7260. WFIFOL(fd,2)= 0x00000000;
  7261. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7262. WFIFOL(fd,6)= MG_COLDBOLT;
  7263. else
  7264. WFIFOL(fd,6)= 0x00000000;
  7265. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7266. WFIFOL(fd,10)= MG_FIREBOLT;
  7267. else
  7268. WFIFOL(fd,10)= 0x00000000;
  7269. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7270. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7271. else
  7272. WFIFOL(fd,14)= 0x00000000;
  7273. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7274. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7275. else
  7276. WFIFOL(fd,18)= 0x00000000;
  7277. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7278. WFIFOL(fd,22)= MG_FIREBALL;
  7279. else
  7280. WFIFOL(fd,22)= 0x00000000;
  7281. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7282. WFIFOL(fd,26)= MG_FROSTDIVER;
  7283. else
  7284. WFIFOL(fd,26)= 0x00000000;
  7285. WFIFOSET(fd,packet_len(0x1cd));
  7286. #endif
  7287. sd->menuskill_id = SA_AUTOSPELL;
  7288. sd->menuskill_val = skill_lv;
  7289. }
  7290. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7291. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7292. void clif_devotion(struct block_list *src, map_session_data *tsd)
  7293. {
  7294. unsigned char buf[56];
  7295. nullpo_retv(src);
  7296. memset(buf,0,packet_len(0x1cf));
  7297. WBUFW(buf,0) = 0x1cf;
  7298. WBUFL(buf,2) = src->id;
  7299. if( src->type == BL_MER )
  7300. {
  7301. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7302. if( md && md->master && md->devotion_flag )
  7303. WBUFL(buf,6) = md->master->bl.id;
  7304. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7305. }
  7306. else
  7307. {
  7308. int i;
  7309. map_session_data *sd = BL_CAST(BL_PC,src);
  7310. if( sd == NULL )
  7311. return;
  7312. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7313. WBUFL(buf,6+4*i) = sd->devotion[i];
  7314. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7315. }
  7316. if( tsd )
  7317. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7318. else
  7319. clif_send(buf, packet_len(0x1cf), src, AREA);
  7320. }
  7321. /// Notifies the client of an object's spirits.
  7322. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7323. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7324. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7325. nullpo_retv( bl );
  7326. struct PACKET_ZC_SPIRITS p = {};
  7327. p.PacketType = HEADER_ZC_SPIRITS;
  7328. p.AID = bl->id;
  7329. switch( bl->type ){
  7330. case BL_PC:
  7331. p.num = ( (map_session_data*)bl )->spiritball;
  7332. break;
  7333. case BL_HOM:
  7334. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7335. break;
  7336. }
  7337. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7338. }
  7339. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7340. /// 01d2 <account id>.L <delay>.L
  7341. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7342. {
  7343. unsigned char buf[32];
  7344. nullpo_retv(bl);
  7345. WBUFW(buf,0)=0x1d2;
  7346. WBUFL(buf,2)=bl->id;
  7347. WBUFL(buf,6)=client_tick(wait);
  7348. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7349. }
  7350. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7351. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7352. /// flag:
  7353. /// 0 = inactive
  7354. /// 1 = active
  7355. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7356. {
  7357. unsigned char buf[32];
  7358. nullpo_retv(src);
  7359. WBUFW(buf,0)=0x1d1;
  7360. WBUFL(buf,2)=src->id;
  7361. WBUFL(buf,6)=dst_id;
  7362. WBUFL(buf,10)=active;
  7363. clif_send(buf,packet_len(0x1d1),src,AREA);
  7364. }
  7365. /// MVP effect (ZC_MVP).
  7366. /// 010c <account id>.L
  7367. void clif_mvp_effect(map_session_data *sd)
  7368. {
  7369. unsigned char buf[16];
  7370. nullpo_retv(sd);
  7371. WBUFW(buf,0)=0x10c;
  7372. WBUFL(buf,2)=sd->bl.id;
  7373. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7374. }
  7375. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7376. /// 010a <name id>.W
  7377. void clif_mvp_item( map_session_data *sd, t_itemid nameid ){
  7378. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7379. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7380. p.itemId = client_nameid( nameid );
  7381. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7382. }
  7383. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7384. /// 010b <exp>.L
  7385. void clif_mvp_exp(map_session_data *sd, t_exp exp) {
  7386. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7387. if (battle_config.mvp_exp_reward_message) {
  7388. char e_msg[CHAT_SIZE_MAX];
  7389. sprintf(e_msg, msg_txt(sd, 717), exp);
  7390. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7391. }
  7392. #else
  7393. int fd;
  7394. nullpo_retv(sd);
  7395. fd = sd->fd;
  7396. WFIFOHEAD(fd, packet_len(0x10b));
  7397. WFIFOW(fd,0) = 0x10b;
  7398. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7399. WFIFOSET(fd, packet_len(0x10b));
  7400. #endif
  7401. }
  7402. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7403. /// 010d
  7404. ///
  7405. /// "You are the MVP, but cannot obtain the reward because
  7406. /// you are overweight."
  7407. void clif_mvp_noitem(map_session_data* sd)
  7408. {
  7409. int fd = sd->fd;
  7410. WFIFOHEAD(fd,packet_len(0x10d));
  7411. WFIFOW(fd,0) = 0x10d;
  7412. WFIFOSET(fd,packet_len(0x10d));
  7413. }
  7414. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7415. /// 0167 <result>.B
  7416. /// result:
  7417. /// 0 = "Guild has been created."
  7418. /// 1 = "You are already in a Guild."
  7419. /// 2 = "That Guild Name already exists."
  7420. /// 3 = "You need the neccessary item to create a Guild."
  7421. void clif_guild_created(map_session_data *sd,int flag)
  7422. {
  7423. int fd;
  7424. nullpo_retv(sd);
  7425. fd=sd->fd;
  7426. WFIFOHEAD(fd,packet_len(0x167));
  7427. WFIFOW(fd,0)=0x167;
  7428. WFIFOB(fd,2)=flag;
  7429. WFIFOSET(fd,packet_len(0x167));
  7430. }
  7431. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7432. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7433. /// mode:
  7434. /// &0x01 = allow invite
  7435. /// &0x10 = allow expel
  7436. void clif_guild_belonginfo( map_session_data& sd ){
  7437. if( sd.guild == nullptr ){
  7438. return;
  7439. }
  7440. const auto &guild = sd.guild->guild;
  7441. int position = guild_getposition(sd);
  7442. if( position < 0 ){
  7443. return;
  7444. }
  7445. struct PACKET_ZC_UPDATE_GDID p = {};
  7446. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7447. p.guildId = guild.guild_id;
  7448. p.emblemVersion = guild.emblem_id;
  7449. p.mode = guild.position[position].mode;
  7450. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7451. p.interSid = 0; // InterSID (unknown purpose)
  7452. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7453. #if PACKETVER_MAIN_NUM >= 20220216
  7454. p.masterGID = guild.member[0].char_id;
  7455. #endif
  7456. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7457. }
  7458. /// Guild member login notice.
  7459. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7460. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7461. /// status:
  7462. /// 0 = offline
  7463. /// 1 = online
  7464. void clif_guild_memberlogin_notice(const struct mmo_guild &g,int idx,int flag)
  7465. {
  7466. unsigned char buf[64];
  7467. map_session_data* sd;
  7468. WBUFW(buf, 0)=0x1f2;
  7469. WBUFL(buf, 2)=g.member[idx].account_id;
  7470. WBUFL(buf, 6)=g.member[idx].char_id;
  7471. WBUFL(buf,10)=flag;
  7472. if( ( sd = g.member[idx].sd ) != NULL )
  7473. {
  7474. WBUFW(buf,14) = sd->status.sex;
  7475. WBUFW(buf,16) = sd->status.hair;
  7476. WBUFW(buf,18) = sd->status.hair_color;
  7477. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7478. }
  7479. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7480. {
  7481. WBUFW(buf,14) = 0;
  7482. WBUFW(buf,16) = 0;
  7483. WBUFW(buf,18) = 0;
  7484. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7485. }
  7486. }
  7487. // Function `clif_guild_memberlogin_notice` sends info about
  7488. // logins and logouts of a guild member to the rest members.
  7489. // But at the 1st time (after a player login or map changing)
  7490. // the client won't show the message.
  7491. // So I suggest use this function for sending "first-time-info"
  7492. // to some player on entering the game or changing location.
  7493. // At next time the client would always show the message.
  7494. // The function sends all the statuses in the single packet
  7495. // to economize traffic. [LuzZza]
  7496. void clif_guild_send_onlineinfo(map_session_data *sd)
  7497. {
  7498. unsigned char buf[14*128];
  7499. int i, count=0, p_len;
  7500. nullpo_retv(sd);
  7501. p_len = packet_len(0x16d);
  7502. auto &g = sd->guild;
  7503. if (!g)
  7504. return;
  7505. for(i=0; i<g->guild.max_member; i++) {
  7506. if(g->guild.member[i].account_id > 0 &&
  7507. g->guild.member[i].account_id != sd->status.account_id) {
  7508. WBUFW(buf,count*p_len) = 0x16d;
  7509. WBUFL(buf,count*p_len+2) = g->guild.member[i].account_id;
  7510. WBUFL(buf,count*p_len+6) = g->guild.member[i].char_id;
  7511. WBUFL(buf,count*p_len+10) = g->guild.member[i].online;
  7512. count++;
  7513. }
  7514. }
  7515. clif_send(buf, p_len*count, &sd->bl, SELF);
  7516. }
  7517. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7518. /// 014e <menu flag>.L
  7519. /// menu flag:
  7520. /// 0x00 = Basic Info (always on)
  7521. /// &0x01 = Member manager
  7522. /// &0x02 = Positions
  7523. /// &0x04 = Skills
  7524. /// &0x10 = Expulsion list
  7525. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7526. /// &0x80 = Notice
  7527. void clif_guild_masterormember(map_session_data *sd)
  7528. {
  7529. int fd;
  7530. nullpo_retv(sd);
  7531. fd=sd->fd;
  7532. WFIFOHEAD(fd,packet_len(0x14e));
  7533. WFIFOW(fd,0) = 0x14e;
  7534. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7535. WFIFOSET(fd,packet_len(0x14e));
  7536. }
  7537. /// Guild basic information (Territories [Valaris])
  7538. /// 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)
  7539. /// 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)
  7540. /// 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)
  7541. void clif_guild_basicinfo( map_session_data& sd ){
  7542. if( sd.guild == nullptr ){
  7543. return;
  7544. }
  7545. const auto &guild = sd.guild->guild;
  7546. struct PACKET_ZC_GUILD_INFO p = {};
  7547. p.PacketType = HEADER_ZC_GUILD_INFO;
  7548. p.GDID = guild.guild_id;
  7549. p.level = guild.guild_lv;
  7550. p.userNum = guild.connect_member;
  7551. p.maxUserNum = guild.max_member;
  7552. p.userAverageLevel = guild.average_lv;
  7553. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7554. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7555. p.point = 0; // Tax Points
  7556. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7557. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7558. p.emblemVersion = guild.emblem_id;
  7559. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7560. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( guild ) ), sizeof( p.manageLand ) );
  7561. p.zeny = 0;
  7562. #if PACKETVER >= 20200902
  7563. p.masterGID = guild.member[0].char_id; // leader
  7564. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7565. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7566. p.masterGID = guild.member[0].char_id; // leader
  7567. #else
  7568. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7569. #endif
  7570. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7571. }
  7572. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7573. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7574. void clif_guild_allianceinfo(map_session_data *sd)
  7575. {
  7576. int fd,i,c;
  7577. nullpo_retv(sd);
  7578. auto &g = sd->guild;
  7579. if (!g)
  7580. return;
  7581. fd = sd->fd;
  7582. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7583. WFIFOW(fd, 0)=0x14c;
  7584. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7585. struct guild_alliance *a=&g->guild.alliance[i];
  7586. if(a->guild_id>0){
  7587. WFIFOL(fd,c*32+4)=a->opposition;
  7588. WFIFOL(fd,c*32+8)=a->guild_id;
  7589. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7590. c++;
  7591. }
  7592. }
  7593. WFIFOW(fd, 2)=c*32+4;
  7594. WFIFOSET(fd,WFIFOW(fd,2));
  7595. }
  7596. /// Guild member manager information
  7597. /// 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)
  7598. /// state:
  7599. /// 0 = offline
  7600. /// 1 = online
  7601. /// memo:
  7602. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7603. /// 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)
  7604. void clif_guild_memberlist( map_session_data& sd ){
  7605. if( sd.guild == nullptr ){
  7606. return;
  7607. }
  7608. const auto &guild = sd.guild->guild;
  7609. struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer;
  7610. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7611. p->packetLength = sizeof( *p );
  7612. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7613. const auto &member = guild.member[i];
  7614. if( member.account_id == 0 ){
  7615. continue;
  7616. }
  7617. struct GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7618. member_info.AID = member.account_id;
  7619. member_info.GID = member.char_id;
  7620. member_info.head = member.hair;
  7621. member_info.headPalette = member.hair_color;
  7622. member_info.sex = member.gender;
  7623. member_info.job = member.class_;
  7624. member_info.level = member.lv;
  7625. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7626. member_info.currentState = member.online;
  7627. member_info.positionID = member.position;
  7628. #if PACKETVER >= 20200902
  7629. member_info.lastLoginTime = member.last_login;
  7630. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7631. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7632. member_info.lastLoginTime = member.last_login;
  7633. #else
  7634. 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.
  7635. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7636. #endif
  7637. c++;
  7638. p->packetLength += sizeof( member_info );
  7639. }
  7640. clif_send( p, p->packetLength, &sd.bl, SELF );
  7641. }
  7642. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7643. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7644. void clif_guild_positionnamelist(map_session_data *sd)
  7645. {
  7646. int i,fd;
  7647. nullpo_retv(sd);
  7648. auto &g = sd->guild;
  7649. if (!g)
  7650. return;
  7651. fd = sd->fd;
  7652. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7653. WFIFOW(fd, 0)=0x166;
  7654. for(i=0;i<MAX_GUILDPOSITION;i++){
  7655. WFIFOL(fd,i*28+4)=i;
  7656. safestrncpy(WFIFOCP(fd,i*28+8),g->guild.position[i].name,NAME_LENGTH);
  7657. }
  7658. WFIFOW(fd,2)=i*28+4;
  7659. WFIFOSET(fd,WFIFOW(fd,2));
  7660. }
  7661. /// Guild position information (ZC_POSITION_INFO).
  7662. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7663. /// mode:
  7664. /// &0x01 = allow invite
  7665. /// &0x10 = allow expel
  7666. /// ranking:
  7667. /// TODO
  7668. void clif_guild_positioninfolist(map_session_data *sd)
  7669. {
  7670. int i,fd;
  7671. nullpo_retv(sd);
  7672. auto &g = sd->guild;
  7673. if (!g)
  7674. return;
  7675. fd = sd->fd;
  7676. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7677. WFIFOW(fd, 0)=0x160;
  7678. for(i=0;i<MAX_GUILDPOSITION;i++){
  7679. struct guild_position *p=&g->guild.position[i];
  7680. WFIFOL(fd,i*16+ 4)=i;
  7681. WFIFOL(fd,i*16+ 8)=p->mode;
  7682. WFIFOL(fd,i*16+12)=i;
  7683. WFIFOL(fd,i*16+16)=p->exp_mode;
  7684. }
  7685. WFIFOW(fd, 2)=i*16+4;
  7686. WFIFOSET(fd,WFIFOW(fd,2));
  7687. }
  7688. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7689. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7690. /// mode:
  7691. /// &0x01 = allow invite
  7692. /// &0x10 = allow expel
  7693. /// ranking:
  7694. /// TODO
  7695. void clif_guild_positionchanged(const struct mmo_guild &g,int idx)
  7696. {
  7697. // FIXME: This packet is intended to update the clients after a
  7698. // commit of position info changes, not sending one packet per
  7699. // position.
  7700. map_session_data *sd;
  7701. unsigned char buf[128];
  7702. WBUFW(buf, 0)=0x174;
  7703. WBUFW(buf, 2)=44; // packet len
  7704. // GUILD_REG_POSITION_INFO{
  7705. WBUFL(buf, 4)=idx;
  7706. WBUFL(buf, 8)=g.position[idx].mode;
  7707. WBUFL(buf,12)=idx;
  7708. WBUFL(buf,16)=g.position[idx].exp_mode;
  7709. safestrncpy(WBUFCP(buf,20),g.position[idx].name,NAME_LENGTH);
  7710. // }*
  7711. if( (sd=guild_getavailablesd(g))!=NULL )
  7712. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7713. }
  7714. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7715. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7716. void clif_guild_memberpositionchanged(const struct mmo_guild &g, int idx)
  7717. {
  7718. // FIXME: This packet is intended to update the clients after a
  7719. // commit of member position assignment changes, not sending one
  7720. // packet per position.
  7721. map_session_data *sd;
  7722. unsigned char buf[64];
  7723. WBUFW(buf, 0)=0x156;
  7724. WBUFW(buf, 2)=16; // packet len
  7725. // MEMBER_POSITION_INFO{
  7726. WBUFL(buf, 4)=g.member[idx].account_id;
  7727. WBUFL(buf, 8)=g.member[idx].char_id;
  7728. WBUFL(buf,12)=g.member[idx].position;
  7729. // }*
  7730. if( (sd=guild_getavailablesd(g))!=NULL )
  7731. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7732. }
  7733. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7734. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7735. void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g)
  7736. {
  7737. int fd = sd.fd;
  7738. if( g.emblem_len <= 0 )
  7739. return;
  7740. WFIFOHEAD(fd,g.emblem_len+12);
  7741. WFIFOW(fd,0)=0x152;
  7742. WFIFOW(fd,2)=g.emblem_len+12;
  7743. WFIFOL(fd,4)=g.guild_id;
  7744. WFIFOL(fd,8)=g.emblem_id;
  7745. memcpy(WFIFOP(fd,12),g.emblem_data,g.emblem_len);
  7746. WFIFOSET(fd,WFIFOW(fd,2));
  7747. }
  7748. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7749. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7750. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7751. void clif_guild_emblem_area(struct block_list* bl)
  7752. {
  7753. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7754. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7755. PACKET_ZC_CHANGE_GUILD p{};
  7756. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7757. p.guild_id = status_get_guild_id(bl);
  7758. p.emblem_id = status_get_emblem_id(bl);
  7759. p.AID = bl->id;
  7760. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7761. }
  7762. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7763. /// 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 }*
  7764. void clif_guild_skillinfo(map_session_data* sd)
  7765. {
  7766. int fd;
  7767. int i,c;
  7768. nullpo_retv(sd);
  7769. auto &g = sd->guild;
  7770. if (!g)
  7771. return;
  7772. fd = sd->fd;
  7773. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7774. WFIFOW(fd,0) = 0x0162;
  7775. WFIFOW(fd,4) = g->guild.skill_point;
  7776. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7777. {
  7778. if(g->guild.skill[i].id > 0 && guild_check_skill_require(g->guild, g->guild.skill[i].id))
  7779. {
  7780. int id = g->guild.skill[i].id;
  7781. int p = 6 + c*37;
  7782. WFIFOW(fd,p+0) = id;
  7783. WFIFOL(fd,p+2) = skill_get_inf(id);
  7784. WFIFOW(fd,p+6) = g->guild.skill[i].lv;
  7785. WFIFOW(fd,p+8) = skill_get_sp(id, g->guild.skill[i].lv);
  7786. WFIFOW(fd,p+10) = skill_get_range(id, g->guild.skill[i].lv);
  7787. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7788. WFIFOB(fd,p+36)= (g->guild.skill[i].lv < guild_skill_get_max(id) && sd == g->guild.member[0].sd) ? 1 : 0;
  7789. c++;
  7790. }
  7791. }
  7792. WFIFOW(fd,2) = 6 + c*37;
  7793. WFIFOSET(fd,WFIFOW(fd,2));
  7794. }
  7795. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7796. /// 016f <subject>.60B <notice>.120B
  7797. void clif_guild_notice(map_session_data* sd)
  7798. {
  7799. nullpo_retv(sd);
  7800. auto &g = sd->guild;
  7801. int fd = sd->fd;
  7802. if ( !session_isActive(fd) )
  7803. return;
  7804. if(g->guild.mes1[0] == '\0' && g->guild.mes2[0] == '\0')
  7805. return;
  7806. WFIFOHEAD(fd,packet_len(0x16f));
  7807. WFIFOW(fd,0) = 0x16f;
  7808. memcpy(WFIFOP(fd,2), g->guild.mes1, MAX_GUILDMES1);
  7809. memcpy(WFIFOP(fd,62), g->guild.mes2, MAX_GUILDMES2);
  7810. WFIFOSET(fd,packet_len(0x16f));
  7811. }
  7812. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7813. /// 016a <guild id>.L <guild name>.24B
  7814. void clif_guild_invite(const map_session_data &sd, const struct mmo_guild &g)
  7815. {
  7816. int fd = sd.fd;
  7817. WFIFOHEAD(fd,packet_len(0x16a));
  7818. WFIFOW(fd,0)=0x16a;
  7819. WFIFOL(fd,2)=g.guild_id;
  7820. safestrncpy(WFIFOCP(fd,6),g.name,NAME_LENGTH);
  7821. WFIFOSET(fd,packet_len(0x16a));
  7822. }
  7823. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7824. /// 0169 <answer>.B
  7825. /// answer:
  7826. /// 0 = Already in guild.
  7827. /// 1 = Offer rejected.
  7828. /// 2 = Offer accepted.
  7829. /// 3 = Guild full.
  7830. void clif_guild_inviteack(map_session_data *sd,int flag)
  7831. {
  7832. int fd;
  7833. nullpo_retv(sd);
  7834. fd=sd->fd;
  7835. WFIFOHEAD(fd,packet_len(0x169));
  7836. WFIFOW(fd,0)=0x169;
  7837. WFIFOB(fd,2)=flag;
  7838. WFIFOSET(fd,packet_len(0x169));
  7839. }
  7840. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7841. /// 015a <char name>.24B <reason>.40B
  7842. void clif_guild_leave(map_session_data *sd,const char *name,const char *mes)
  7843. {
  7844. unsigned char buf[128];
  7845. nullpo_retv(sd);
  7846. WBUFW(buf, 0)=0x15a;
  7847. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7848. memcpy(WBUFP(buf,26),mes,40);
  7849. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7850. }
  7851. /// Notifies clients of a guild of an expelled member.
  7852. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7853. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7854. void clif_guild_expulsion(map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7855. {
  7856. unsigned char buf[128];
  7857. #if PACKETVER < 20100803
  7858. const unsigned short cmd = 0x15c;
  7859. #else
  7860. const unsigned short cmd = 0x839;
  7861. #endif
  7862. nullpo_retv(sd);
  7863. WBUFW(buf,0) = cmd;
  7864. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7865. safestrncpy(WBUFCP(buf,26), mes, 40);
  7866. #if PACKETVER < 20100803
  7867. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7868. #endif
  7869. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7870. }
  7871. /// Guild expulsion list (ZC_BAN_LIST).
  7872. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7873. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7874. void clif_guild_expulsionlist(map_session_data* sd)
  7875. {
  7876. #if PACKETVER < 20100803
  7877. const int offset = NAME_LENGTH*2+40;
  7878. #else
  7879. const int offset = NAME_LENGTH+40;
  7880. #endif
  7881. int fd, i, c = 0;
  7882. nullpo_retv(sd);
  7883. auto &g = sd->guild;
  7884. if (!g)
  7885. return;
  7886. fd = sd->fd;
  7887. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7888. WFIFOW(fd,0) = 0x163;
  7889. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7890. {
  7891. struct guild_expulsion* e = &g->guild.expulsion[i];
  7892. if( e->account_id > 0 )
  7893. {
  7894. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7895. #if PACKETVER < 20100803
  7896. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7897. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7898. #else
  7899. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7900. #endif
  7901. c++;
  7902. }
  7903. }
  7904. WFIFOW(fd,2) = 4 + c*offset;
  7905. WFIFOSET(fd,WFIFOW(fd,2));
  7906. }
  7907. /// Guild chat message (ZC_GUILD_CHAT).
  7908. /// 017f <packet len>.W <message>.?B
  7909. void clif_guild_message(const struct mmo_guild &g,uint32 account_id,const char *mes,int len)
  7910. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7911. map_session_data *sd;
  7912. uint8 buf[256];
  7913. if( len == 0 )
  7914. {
  7915. return;
  7916. }
  7917. else if( len > sizeof(buf)-5 )
  7918. {
  7919. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g.guild_id);
  7920. len = sizeof(buf)-5;
  7921. }
  7922. WBUFW(buf, 0) = 0x17f;
  7923. WBUFW(buf, 2) = len + 5;
  7924. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7925. if ((sd = guild_getavailablesd(g)) != NULL)
  7926. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7927. }
  7928. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7929. /// 0171 <inviter account id>.L <guild name>.24B
  7930. void clif_guild_reqalliance(map_session_data *sd,uint32 account_id,const char *name)
  7931. {
  7932. int fd;
  7933. nullpo_retv(sd);
  7934. fd=sd->fd;
  7935. WFIFOHEAD(fd,packet_len(0x171));
  7936. WFIFOW(fd,0)=0x171;
  7937. WFIFOL(fd,2)=account_id;
  7938. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7939. WFIFOSET(fd,packet_len(0x171));
  7940. }
  7941. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7942. /// 0173 <answer>.B
  7943. /// answer:
  7944. /// 0 = Already allied.
  7945. /// 1 = You rejected the offer.
  7946. /// 2 = You accepted the offer.
  7947. /// 3 = They have too any alliances.
  7948. /// 4 = You have too many alliances.
  7949. /// 5 = Alliances are disabled.
  7950. void clif_guild_allianceack(map_session_data *sd,int flag)
  7951. {
  7952. int fd;
  7953. nullpo_retv(sd);
  7954. fd=sd->fd;
  7955. WFIFOHEAD(fd,packet_len(0x173));
  7956. WFIFOW(fd,0)=0x173;
  7957. WFIFOL(fd,2)=flag;
  7958. WFIFOSET(fd,packet_len(0x173));
  7959. }
  7960. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7961. /// 0184 <other guild id>.L <relation>.L
  7962. /// relation:
  7963. /// 0 = Ally
  7964. /// 1 = Enemy
  7965. void clif_guild_delalliance(map_session_data *sd,int guild_id,int flag)
  7966. {
  7967. nullpo_retv(sd);
  7968. int fd = sd->fd;
  7969. if ( !session_isActive(fd) )
  7970. return;
  7971. WFIFOHEAD(fd,packet_len(0x184));
  7972. WFIFOW(fd,0)=0x184;
  7973. WFIFOL(fd,2)=guild_id;
  7974. WFIFOL(fd,6)=flag;
  7975. WFIFOSET(fd,packet_len(0x184));
  7976. }
  7977. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7978. /// 0181 <result>.B
  7979. /// result:
  7980. /// 0 = Antagonist has been set.
  7981. /// 1 = Guild has too many Antagonists.
  7982. /// 2 = Already set as an Antagonist.
  7983. /// 3 = Antagonists are disabled.
  7984. void clif_guild_oppositionack(map_session_data *sd,int flag)
  7985. {
  7986. int fd;
  7987. nullpo_retv(sd);
  7988. fd=sd->fd;
  7989. WFIFOHEAD(fd,packet_len(0x181));
  7990. WFIFOW(fd,0)=0x181;
  7991. WFIFOB(fd,2)=flag;
  7992. WFIFOSET(fd,packet_len(0x181));
  7993. }
  7994. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7995. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7996. /*
  7997. void clif_guild_allianceadded(struct guild *g,int idx)
  7998. {
  7999. unsigned char buf[64];
  8000. WBUFW(buf,0)=0x185;
  8001. WBUFL(buf,2)=g->alliance[idx].opposition;
  8002. WBUFL(buf,6)=g->alliance[idx].guild_id;
  8003. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  8004. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  8005. }
  8006. */
  8007. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  8008. /// 015e <reason>.L
  8009. /// 0 = success
  8010. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  8011. /// 2 = there are still members in the guild
  8012. void clif_guild_broken(map_session_data *sd,int flag)
  8013. {
  8014. int fd;
  8015. nullpo_retv(sd);
  8016. fd=sd->fd;
  8017. WFIFOHEAD(fd,packet_len(0x15e));
  8018. WFIFOW(fd,0)=0x15e;
  8019. WFIFOL(fd,2)=flag;
  8020. WFIFOSET(fd,packet_len(0x15e));
  8021. }
  8022. /// Displays emotion on an object (ZC_EMOTION).
  8023. /// 00c0 <id>.L <type>.B
  8024. /// type:
  8025. /// enum emotion_type
  8026. void clif_emotion(struct block_list *bl,int type)
  8027. {
  8028. unsigned char buf[8];
  8029. nullpo_retv(bl);
  8030. WBUFW(buf,0)=0xc0;
  8031. WBUFL(buf,2)=bl->id;
  8032. WBUFB(buf,6)=type;
  8033. clif_send(buf,packet_len(0xc0),bl,AREA);
  8034. }
  8035. /// Displays the contents of a talkiebox trap.
  8036. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  8037. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  8038. nullpo_retv( bl );
  8039. nullpo_retv( talkie );
  8040. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  8041. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  8042. p.aid = bl->id;
  8043. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  8044. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  8045. }
  8046. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  8047. /// 01ea <id>.L
  8048. void clif_wedding_effect(struct block_list *bl)
  8049. {
  8050. unsigned char buf[6];
  8051. nullpo_retv(bl);
  8052. WBUFW(buf,0) = 0x1ea;
  8053. WBUFL(buf,2) = bl->id;
  8054. clif_send(buf, packet_len(0x1ea), bl, AREA);
  8055. }
  8056. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  8057. /// 01e6 <partner name>.24B
  8058. void clif_callpartner(map_session_data& sd)
  8059. {
  8060. PACKET_ZC_COUPLENAME p = { 0 };
  8061. p.packetType = HEADER_ZC_COUPLENAME;
  8062. if( sd.status.partner_id ) {
  8063. map_session_data *p_sd = pc_get_partner(&sd);
  8064. if (p_sd != nullptr && !p_sd->state.autotrade)
  8065. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  8066. else
  8067. p.name[0] = 0;
  8068. } else {// Send zero-length name if no partner, to initialize the client buffer.
  8069. p.name[0] = 0;
  8070. }
  8071. clif_send(&p, sizeof(p), &sd.bl, AREA);
  8072. }
  8073. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  8074. /// 01e4
  8075. /// This packet while still implemented by the client is no longer being officially used.
  8076. /*
  8077. void clif_marriage_process(map_session_data *sd)
  8078. {
  8079. int fd;
  8080. nullpo_retv(sd);
  8081. fd=sd->fd;
  8082. WFIFOHEAD(fd,packet_len(0x1e4));
  8083. WFIFOW(fd,0)=0x1e4;
  8084. WFIFOSET(fd,packet_len(0x1e4));
  8085. }
  8086. */
  8087. /// Notice of divorce (ZC_DIVORCE).
  8088. /// 0205 <partner name>.24B
  8089. void clif_divorced(map_session_data* sd, const char* name)
  8090. {
  8091. int fd;
  8092. nullpo_retv(sd);
  8093. fd=sd->fd;
  8094. WFIFOHEAD(fd,packet_len(0x205));
  8095. WFIFOW(fd,0)=0x205;
  8096. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8097. WFIFOSET(fd, packet_len(0x205));
  8098. }
  8099. /// Marriage proposal (ZC_REQ_COUPLE).
  8100. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8101. /// This packet while still implemented by the client is no longer being officially used.
  8102. /*
  8103. void clif_marriage_proposal(int fd, map_session_data *sd, map_session_data* ssd)
  8104. {
  8105. nullpo_retv(sd);
  8106. WFIFOHEAD(fd,packet_len(0x1e2));
  8107. WFIFOW(fd,0) = 0x1e2;
  8108. WFIFOL(fd,2) = ssd->status.account_id;
  8109. WFIFOL(fd,6) = ssd->status.char_id;
  8110. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8111. WFIFOSET(fd, packet_len(0x1e2));
  8112. }
  8113. */
  8114. /*==========================================
  8115. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8116. *------------------------------------------*/
  8117. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8118. {
  8119. unsigned char buf[256];
  8120. if( len == 0 ) {
  8121. return;
  8122. } else if( len > sizeof(buf)-5 ) {
  8123. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8124. len = sizeof(buf)-5;
  8125. }
  8126. WBUFW(buf, 0) = 0x17f;
  8127. WBUFW(buf, 2) = len + 5;
  8128. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8129. clif_send(buf, WBUFW(buf,2), src, target);
  8130. }
  8131. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8132. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8133. /// 00cd <result>.B
  8134. /// result:
  8135. /// 0 = failure
  8136. /// 1 = success
  8137. void clif_GM_kickack(map_session_data *sd, int id)
  8138. {
  8139. int fd;
  8140. nullpo_retv(sd);
  8141. fd = sd->fd;
  8142. WFIFOHEAD(fd,packet_len(0xcd));
  8143. WFIFOW(fd,0) = 0xcd;
  8144. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8145. WFIFOSET(fd, packet_len(0xcd));
  8146. }
  8147. void clif_GM_kick(map_session_data *sd, map_session_data *tsd)
  8148. {
  8149. nullpo_retv(tsd);
  8150. if (sd == NULL)
  8151. tsd->state.keepshop = true;
  8152. if (session_isActive(tsd->fd))
  8153. clif_authfail_fd(tsd->fd, 15);
  8154. else
  8155. map_quit(tsd);
  8156. if (sd)
  8157. clif_GM_kickack(sd, tsd->status.account_id);
  8158. }
  8159. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8160. /// 014a <result>.L
  8161. /// result:
  8162. /// 0 = "A manner point has been successfully aligned."
  8163. /// 1 = MP_FAILURE_EXHAUST
  8164. /// 2 = MP_FAILURE_ALREADY_GIVING
  8165. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8166. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8167. /// 5 = "You got a good point from %s."
  8168. void clif_manner_message(map_session_data* sd, uint32 type)
  8169. {
  8170. int fd;
  8171. nullpo_retv(sd);
  8172. fd = sd->fd;
  8173. WFIFOHEAD(fd,packet_len(0x14a));
  8174. WFIFOW(fd,0) = 0x14a;
  8175. WFIFOL(fd,2) = type;
  8176. WFIFOSET(fd, packet_len(0x14a));
  8177. }
  8178. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8179. /// 014b <type>.B <GM name>.24B
  8180. /// type:
  8181. /// 0 = positive (unmute)
  8182. /// 1 = negative (mute)
  8183. void clif_GM_silence(map_session_data* sd, map_session_data* tsd, uint8 type)
  8184. {
  8185. int fd;
  8186. nullpo_retv(sd);
  8187. nullpo_retv(tsd);
  8188. fd = tsd->fd;
  8189. WFIFOHEAD(fd,packet_len(0x14b));
  8190. WFIFOW(fd,0) = 0x14b;
  8191. WFIFOB(fd,2) = type;
  8192. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8193. WFIFOSET(fd, packet_len(0x14b));
  8194. }
  8195. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8196. /// 00d1 <type>.B <result>.B
  8197. /// type:
  8198. /// 0 = /ex (deny)
  8199. /// 1 = /in (allow)
  8200. /// result:
  8201. /// 0 = success
  8202. /// 1 = failure
  8203. /// 2 = too many blocks
  8204. void clif_wisexin(map_session_data *sd,int type,int flag)
  8205. {
  8206. int fd;
  8207. nullpo_retv(sd);
  8208. fd=sd->fd;
  8209. WFIFOHEAD(fd,packet_len(0xd1));
  8210. WFIFOW(fd,0)=0xd1;
  8211. WFIFOB(fd,2)=type;
  8212. WFIFOB(fd,3)=flag;
  8213. WFIFOSET(fd,packet_len(0xd1));
  8214. }
  8215. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8216. /// 00d2 <type>.B <result>.B
  8217. /// type:
  8218. /// 0 = /exall (deny)
  8219. /// 1 = /inall (allow)
  8220. /// result:
  8221. /// 0 = success
  8222. /// 1 = failure
  8223. void clif_wisall(map_session_data *sd,int type,int flag)
  8224. {
  8225. int fd;
  8226. nullpo_retv(sd);
  8227. fd=sd->fd;
  8228. WFIFOHEAD(fd,packet_len(0xd2));
  8229. WFIFOW(fd,0)=0xd2;
  8230. WFIFOB(fd,2)=type;
  8231. WFIFOB(fd,3)=flag;
  8232. WFIFOSET(fd,packet_len(0xd2));
  8233. }
  8234. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8235. /// 07fe <bgm>.24B
  8236. void clif_playBGM( map_session_data& sd, const char* name ){
  8237. #if PACKETVER_MAIN_NUM >= 20220504
  8238. struct PACKET_ZC_PLAY_NPC_BGM* p = (struct PACKET_ZC_PLAY_NPC_BGM*)packet_buffer;
  8239. int16 length = (int16)( strlen( name ) + 1 );
  8240. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8241. p->PacketLength = sizeof( *p ) + length;
  8242. p->playType = 0; // TODO: implement, send loop for the time being
  8243. safestrncpy( p->bgm, name, length );
  8244. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8245. #elif PACKETVER >= 20091201
  8246. struct PACKET_ZC_PLAY_NPC_BGM p = {};
  8247. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8248. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8249. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8250. #endif
  8251. }
  8252. /// Plays/stops a wave sound (ZC_SOUND).
  8253. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8254. /// file name:
  8255. /// relative to data\wav
  8256. /// act:
  8257. /// 0 = play (once)
  8258. /// 1 = play (repeat, does not work)
  8259. /// 2 = stops all sound instances of file name (does not work)
  8260. /// term:
  8261. /// unknown purpose, only relevant to act = 1
  8262. /// npc id:
  8263. /// The accustic direction of the sound is determined by the
  8264. /// relative position of the NPC to the player (3D sound).
  8265. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8266. struct PACKET_ZC_SOUND p = {};
  8267. p.PacketType = HEADER_ZC_SOUND;
  8268. safestrncpy( p.name, name, sizeof( p.name ) );
  8269. p.act = type;
  8270. p.term = 0; // TODO: implement
  8271. p.AID = bl.id;
  8272. clif_send( &p, sizeof( p ), &bl, target );
  8273. }
  8274. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8275. /// 01f3 <id>.L <effect id>.L
  8276. /// effect id:
  8277. /// @see doc/effect_list.txt
  8278. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8279. {
  8280. unsigned char buf[24];
  8281. nullpo_retv(bl);
  8282. memset(buf, 0, packet_len(0x1f3));
  8283. WBUFW(buf,0) = 0x1f3;
  8284. WBUFL(buf,2) = bl->id;
  8285. WBUFL(buf,6) = type;
  8286. clif_send(buf, packet_len(0x1f3), bl, target);
  8287. if (disguised(bl)) {
  8288. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8289. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8290. }
  8291. }
  8292. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8293. {
  8294. WFIFOHEAD(fd,10);
  8295. WFIFOW(fd,0) = 0x1f3;
  8296. WFIFOL(fd,2) = bl->id;
  8297. WFIFOL(fd,6) = type;
  8298. WFIFOSET(fd,10);
  8299. }
  8300. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8301. /// 0284 <id>.L <effect id>.L <num data>.L
  8302. /// effect id:
  8303. /// @see doc/effect_list.txt
  8304. /// num data:
  8305. /// effect-dependent value
  8306. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8307. {
  8308. uint8 buf[14];
  8309. WBUFW(buf,0) = 0x284;
  8310. WBUFL(buf,2) = bl->id;
  8311. WBUFL(buf,6) = effect_id;
  8312. WBUFL(buf,10) = num;
  8313. clif_send(buf, packet_len(0x284), bl, target);
  8314. if( disguised(bl) )
  8315. {
  8316. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8317. clif_send(buf, packet_len(0x284), bl, SELF);
  8318. }
  8319. }
  8320. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8321. {
  8322. #if PACKETVER >= 20181002
  8323. nullpo_retv( bl_src );
  8324. nullpo_retv( bl_target );
  8325. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8326. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8327. p.aid = bl_src->id;
  8328. p.effectId = effect;
  8329. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8330. if( disguised(bl_src) )
  8331. {
  8332. p.aid = disguised_bl_id( bl_src->id );
  8333. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8334. }
  8335. #endif
  8336. }
  8337. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8338. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8339. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, map_session_data *sd) {
  8340. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8341. uint8 buf[CHAT_SIZE_MAX];
  8342. nullpo_retv(bl);
  8343. if (msg_len > sizeof(buf) - 12) {
  8344. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8345. msg_len = sizeof(buf) - 12;
  8346. }
  8347. if (rgb2bgr)
  8348. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8349. WBUFW(buf,0) = 0x2C1;
  8350. WBUFW(buf,2) = msg_len + 12;
  8351. WBUFL(buf,4) = bl->id;
  8352. WBUFL(buf,8) = color;
  8353. memcpy(WBUFCP(buf,12), msg, msg_len);
  8354. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8355. }
  8356. /**
  8357. * Notifies the client that the storage window is still open
  8358. *
  8359. * Should only be used in cases where the client closed the
  8360. * storage window without server's consent
  8361. */
  8362. void clif_refresh_storagewindow(map_session_data *sd) {
  8363. // Notify the client that the storage is open
  8364. if( sd->state.storage_flag == 1 ) {
  8365. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8366. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8367. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8368. }
  8369. // Notify the client that the gstorage is open otherwise it will
  8370. // remain locked forever and nobody will be able to access it
  8371. if( sd->state.storage_flag == 2 ) {
  8372. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8373. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8374. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8375. else {
  8376. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8377. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8378. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8379. }
  8380. }
  8381. // Notify the client that the premium storage is open
  8382. if (sd->state.storage_flag == 3) {
  8383. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8384. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8385. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8386. }
  8387. }
  8388. // refresh the client's screen, getting rid of any effects
  8389. void clif_refresh(map_session_data *sd)
  8390. {
  8391. nullpo_retv(sd);
  8392. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8393. clif_inventorylist(sd);
  8394. clif_equipswitch_list(sd);
  8395. if(pc_iscarton(sd)) {
  8396. clif_cartlist(sd);
  8397. clif_updatestatus(sd,SP_CARTINFO);
  8398. }
  8399. clif_updatestatus(sd,SP_WEIGHT);
  8400. clif_updatestatus(sd,SP_MAXWEIGHT);
  8401. clif_updatestatus(sd,SP_STR);
  8402. clif_updatestatus(sd,SP_AGI);
  8403. clif_updatestatus(sd,SP_VIT);
  8404. clif_updatestatus(sd,SP_INT);
  8405. clif_updatestatus(sd,SP_DEX);
  8406. clif_updatestatus(sd,SP_LUK);
  8407. #ifdef RENEWAL
  8408. clif_updatestatus(sd,SP_POW);
  8409. clif_updatestatus(sd,SP_STA);
  8410. clif_updatestatus(sd,SP_WIS);
  8411. clif_updatestatus(sd,SP_SPL);
  8412. clif_updatestatus(sd,SP_CON);
  8413. clif_updatestatus(sd,SP_CRT);
  8414. #endif
  8415. if (sd->spiritball)
  8416. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8417. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  8418. clif_millenniumshield_single(sd->fd, sd);
  8419. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8420. clif_spiritcharm_single(sd->fd, sd);
  8421. if (sd->soulball)
  8422. clif_soulball( sd, &sd->bl, SELF );
  8423. if (sd->servantball)
  8424. clif_servantball( *sd, &sd->bl, SELF );
  8425. if (sd->abyssball)
  8426. clif_abyssball( *sd, &sd->bl, SELF );
  8427. if (sd->vd.cloth_color)
  8428. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8429. if (sd->vd.body_style)
  8430. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8431. if(hom_is_active(sd->hd))
  8432. clif_send_homdata(sd,SP_ACK,0);
  8433. if( sd->md ) {
  8434. clif_mercenary_info(sd);
  8435. clif_mercenary_skillblock(sd);
  8436. }
  8437. if( sd->ed )
  8438. clif_elemental_info(sd);
  8439. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8440. clif_weather_check(sd);
  8441. if( sd->chatID )
  8442. chat_leavechat(sd,0);
  8443. if( sd->state.vending )
  8444. clif_openvending(sd, sd->bl.id, sd->vending);
  8445. if( pc_issit(sd) )
  8446. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8447. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8448. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8449. else
  8450. clif_changed_dir(&sd->bl, SELF);
  8451. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8452. //Issue #2143
  8453. //Cancel Trading State
  8454. if (sd->state.trading)
  8455. trade_tradecancel(sd);
  8456. //Cancel Buying/Selling State
  8457. if (sd->state.buyingstore)
  8458. buyingstore_close(sd);
  8459. mail_clear(sd);
  8460. clif_loadConfirm( sd );
  8461. if( disguised(&sd->bl) ) {/* refresh-da */
  8462. short disguise = sd->disguise;
  8463. pc_disguise(sd, 0);
  8464. pc_disguise(sd, disguise);
  8465. }
  8466. clif_refresh_storagewindow(sd);
  8467. }
  8468. /// Updates the object's (bl) name on client.
  8469. /// Used to update when a char leaves a party/guild. [Skotlex]
  8470. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8471. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8472. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8473. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8474. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8475. nullpo_retv( src );
  8476. nullpo_retv( bl );
  8477. switch( bl->type ){
  8478. case BL_PC: {
  8479. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8480. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8481. packet.gid = bl->id;
  8482. map_session_data *sd = (map_session_data *)bl;
  8483. //Requesting your own "shadow" name. [Skotlex]
  8484. if( src == bl && target == SELF && sd->disguise ){
  8485. packet.gid = -bl->id;
  8486. }
  8487. if( sd->fakename[0] ) {
  8488. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8489. clif_send( &packet, sizeof(packet), src, target );
  8490. return;
  8491. }
  8492. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8493. party_data *p = nullptr;
  8494. if( sd->status.party_id ){
  8495. p = party_search( sd->status.party_id );
  8496. }
  8497. // do not display party unless the player is also in a guild
  8498. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8499. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8500. }
  8501. if( sd->guild ){
  8502. int position;
  8503. // Will get the position of the guild the player is in
  8504. position = guild_getposition(*sd);
  8505. safestrncpy( packet.guild_name, sd->guild->guild.name, NAME_LENGTH );
  8506. safestrncpy( packet.position_name, sd->guild->guild.position[position].name, NAME_LENGTH );
  8507. }else if( sd->clan ){
  8508. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8509. }
  8510. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8511. packet.title_id = sd->status.title_id; // Title ID
  8512. #endif
  8513. clif_send(&packet, sizeof(packet), src, target);
  8514. }
  8515. break;
  8516. //[blackhole89]
  8517. case BL_HOM:
  8518. case BL_MER:
  8519. case BL_PET:
  8520. case BL_NPC:
  8521. case BL_ELEM: {
  8522. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8523. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8524. packet.gid = bl->id;
  8525. switch (bl->type) {
  8526. case BL_HOM:
  8527. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8528. break;
  8529. case BL_MER:
  8530. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8531. break;
  8532. case BL_PET:
  8533. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8534. break;
  8535. case BL_NPC:
  8536. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8537. break;
  8538. case BL_ELEM:
  8539. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8540. break;
  8541. }
  8542. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8543. unit_data *ud = unit_bl2ud(bl);
  8544. if (ud != nullptr) {
  8545. memcpy(packet.title, ud->title, NAME_LENGTH);
  8546. packet.groupId = ud->group_id;
  8547. }
  8548. #endif
  8549. clif_send(&packet, sizeof(packet), src, target);
  8550. }
  8551. break;
  8552. case BL_MOB: {
  8553. mob_data *md = (mob_data *)bl;
  8554. if( md->guardian_data && md->guardian_data->guild_id ){
  8555. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8556. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8557. packet.gid = bl->id;
  8558. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8559. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8560. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8561. clif_send(&packet, sizeof(packet), src, target);
  8562. }else if( battle_config.show_mob_info ){
  8563. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8564. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8565. packet.gid = bl->id;
  8566. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8567. char mobhp[50], *str_p = mobhp;
  8568. if( battle_config.show_mob_info&4 ){
  8569. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8570. }
  8571. if( battle_config.show_mob_info&1 ){
  8572. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8573. }
  8574. if( battle_config.show_mob_info&2 ){
  8575. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8576. }
  8577. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8578. if( str_p != mobhp ){
  8579. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8580. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8581. }
  8582. clif_send(&packet, sizeof(packet), src, target);
  8583. } else {
  8584. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8585. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8586. packet.gid = bl->id;
  8587. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8588. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8589. unit_data *ud = unit_bl2ud(bl);
  8590. if (ud != nullptr) {
  8591. memcpy(packet.title, ud->title, NAME_LENGTH);
  8592. packet.groupId = ud->group_id;
  8593. }
  8594. #endif
  8595. clif_send(&packet, sizeof(packet), src, target);
  8596. }
  8597. }
  8598. break;
  8599. case BL_CHAT:
  8600. case BL_SKILL:
  8601. // Newer clients request this, but do not need an answer
  8602. return;
  8603. default:
  8604. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8605. return;
  8606. }
  8607. }
  8608. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8609. /// 01ff <id>.L <x>.W <y>.W
  8610. ///
  8611. /// Visually moves(instant) a character to x,y. The char moves even
  8612. /// when the target cell isn't walkable. If the char is sitting it
  8613. /// stays that way.
  8614. void clif_slide(struct block_list *bl, int x, int y)
  8615. {
  8616. unsigned char buf[10];
  8617. nullpo_retv(bl);
  8618. WBUFW(buf, 0) = 0x01ff;
  8619. WBUFL(buf, 2) = bl->id;
  8620. WBUFW(buf, 6) = x;
  8621. WBUFW(buf, 8) = y;
  8622. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8623. if( disguised(bl) )
  8624. {
  8625. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8626. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8627. }
  8628. }
  8629. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8630. /// 008d <packet len>.W <id>.L <message>.?B
  8631. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8632. {
  8633. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8634. int len_mes = strlen(mes)+1; //Account for \0
  8635. if (len_mes > sizeof(buf)-8) {
  8636. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8637. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8638. }
  8639. // send message to others
  8640. if (flag == AREA) {
  8641. WBUFW(buf,0) = 0x8d;
  8642. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8643. WBUFL(buf,4) = bl->id;
  8644. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8645. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8646. }
  8647. // send back message to the speaker
  8648. if( bl->type == BL_PC ) {
  8649. WBUFW(buf,0) = 0x8e;
  8650. WBUFW(buf, 2) = len_mes + 4;
  8651. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8652. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8653. }
  8654. }
  8655. /*==========================
  8656. * Minimap fix [Kevin]
  8657. * Remove dot from minimap
  8658. *--------------------------*/
  8659. void clif_party_xy_remove(map_session_data* sd)
  8660. {
  8661. nullpo_retv(sd);
  8662. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8663. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8664. p.AID = sd->status.account_id;
  8665. p.xPos = -1;
  8666. p.yPos = -1;
  8667. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8668. }
  8669. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8670. /// 0215 <msg id>.L
  8671. /// msg id:
  8672. /// 0x15 = End all negative status (PA_GOSPEL)
  8673. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8674. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8675. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8676. /// 0x19 = All stats +20 (PA_GOSPEL)
  8677. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8678. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8679. /// 0x1e = DEF +25% (PA_GOSPEL)
  8680. /// 0x1f = ATK +100% (PA_GOSPEL)
  8681. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8682. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8683. /// ? = nothing
  8684. void clif_gospel_info(map_session_data *sd, int type)
  8685. {
  8686. int fd=sd->fd;
  8687. WFIFOHEAD(fd,packet_len(0x215));
  8688. WFIFOW(fd,0)=0x215;
  8689. WFIFOL(fd,2)=type;
  8690. WFIFOSET(fd, packet_len(0x215));
  8691. }
  8692. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8693. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8694. /// result:
  8695. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8696. /// star:
  8697. /// 0 = Place of the Sun
  8698. /// 1 = Place of the Moon
  8699. /// 2 = Place of the Stars
  8700. /// 1 = Star Gladiator %s's %s: <mapname>
  8701. /// star:
  8702. /// 0 = Place of the Sun
  8703. /// 1 = Place of the Moon
  8704. /// 2 = Place of the Stars
  8705. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8706. /// star:
  8707. /// 0 = Target of the Sun
  8708. /// 1 = Target of the Moon
  8709. /// 2 = Target of the Stars
  8710. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8711. /// star:
  8712. /// 0 = Monster of the Sun
  8713. /// 1 = Monster of the Moon
  8714. /// 2 = Monster of the Stars
  8715. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8716. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8717. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8718. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8719. /// 40 = Target HP : <monster_id used as HP>
  8720. void clif_starskill(map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8721. {
  8722. int fd = sd->fd;
  8723. WFIFOHEAD(fd,packet_len(0x20e));
  8724. WFIFOW(fd,0) = 0x20e;
  8725. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8726. WFIFOL(fd,26) = monster_id;
  8727. WFIFOB(fd,30) = star;
  8728. WFIFOB(fd,31) = result;
  8729. WFIFOSET(fd,packet_len(0x20e));
  8730. }
  8731. /*==========================================
  8732. * Info about Star Glaldiator save map [Komurka]
  8733. * type: 1: Information, 0: Map registered
  8734. *------------------------------------------*/
  8735. void clif_feel_info(map_session_data* sd, unsigned char feel_level, unsigned char type)
  8736. {
  8737. char mapname[MAP_NAME_LENGTH_EXT];
  8738. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8739. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8740. }
  8741. /*==========================================
  8742. * Info about Star Glaldiator hate mob [Komurka]
  8743. * type: 1: Register mob, 0: Information.
  8744. *------------------------------------------*/
  8745. void clif_hate_info(map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8746. {
  8747. if( pcdb_checkid(class_) ) {
  8748. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8749. } else if( mobdb_checkid(class_) ) {
  8750. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8751. } else {
  8752. 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);
  8753. }
  8754. }
  8755. /*==========================================
  8756. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8757. *------------------------------------------*/
  8758. void clif_mission_info(map_session_data *sd, int mob_id, unsigned char progress)
  8759. {
  8760. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8761. }
  8762. /*==========================================
  8763. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8764. *------------------------------------------*/
  8765. void clif_feel_hate_reset(map_session_data *sd)
  8766. {
  8767. clif_starskill(sd, "", 0, 0, 30);
  8768. }
  8769. /// Send out reply to configuration change
  8770. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8771. /// type: see enum e_config_type
  8772. /// value:
  8773. /// false = disabled
  8774. /// true = enabled
  8775. void clif_configuration( map_session_data* sd, enum e_config_type type, bool enabled ){
  8776. int fd;
  8777. nullpo_retv(sd);
  8778. fd = sd->fd;
  8779. WFIFOHEAD(fd, packet_len(0x2d9));
  8780. WFIFOW(fd, 0) = 0x2d9;
  8781. WFIFOL(fd, 2) = type;
  8782. WFIFOL(fd, 6) = enabled;
  8783. WFIFOSET(fd, packet_len(0x2d9));
  8784. }
  8785. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8786. /// 02da <open equip window>.B
  8787. /// open equip window:
  8788. /// 0 = disabled
  8789. /// 1 = enabled
  8790. void clif_equipcheckbox(map_session_data* sd)
  8791. {
  8792. int fd;
  8793. nullpo_retv(sd);
  8794. fd = sd->fd;
  8795. WFIFOHEAD(fd, packet_len(0x2da));
  8796. WFIFOW(fd, 0) = 0x2da;
  8797. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8798. WFIFOSET(fd, packet_len(0x2da));
  8799. }
  8800. /// Sends info about a player's equipped items.
  8801. /// 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)
  8802. /// 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)
  8803. /// 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)
  8804. /// 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)
  8805. /// 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)
  8806. /// 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)
  8807. void clif_viewequip_ack( map_session_data* sd, map_session_data* tsd ){
  8808. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8809. nullpo_retv( sd );
  8810. nullpo_retv( tsd );
  8811. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8812. int equip = 0;
  8813. for( int i = 0; i < EQI_MAX; i++ ){
  8814. int k = tsd->equip_index[i];
  8815. if( k >= 0 ){
  8816. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8817. continue;
  8818. }
  8819. if( !tsd->inventory.u.items_inventory[k].equip ){
  8820. continue;
  8821. }
  8822. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8823. continue;
  8824. }
  8825. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8826. }
  8827. }
  8828. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8829. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8830. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8831. p->job = tsd->status.class_;
  8832. p->head = tsd->vd.hair_style;
  8833. p->accessory = tsd->vd.head_bottom;
  8834. p->accessory2 = tsd->vd.head_mid;
  8835. p->accessory3 = tsd->vd.head_top;
  8836. #if PACKETVER >= 20110111
  8837. p->robe = tsd->vd.robe;
  8838. #endif
  8839. p->headpalette = tsd->vd.hair_color;
  8840. p->bodypalette = tsd->vd.cloth_color;
  8841. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8842. p->body2 = tsd->vd.body_style;
  8843. #endif
  8844. p->sex = tsd->vd.sex;
  8845. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8846. #endif
  8847. }
  8848. /// Display msgstringtable.txt string (ZC_MSG).
  8849. /// 0291 <message>.W
  8850. void clif_msg(map_session_data* sd, unsigned short id)
  8851. {
  8852. int fd;
  8853. nullpo_retv(sd);
  8854. fd = sd->fd;
  8855. WFIFOHEAD(fd, packet_len(0x291));
  8856. WFIFOW(fd, 0) = 0x291;
  8857. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8858. WFIFOSET(fd, packet_len(0x291));
  8859. }
  8860. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8861. /// 0x7e2 <message>.W <value>.L
  8862. void clif_msg_value(map_session_data* sd, unsigned short id, int value)
  8863. {
  8864. int fd = sd->fd;
  8865. WFIFOHEAD(fd, packet_len(0x7e2));
  8866. WFIFOW(fd,0) = 0x7e2;
  8867. WFIFOW(fd,2) = id;
  8868. WFIFOL(fd,4) = value;
  8869. WFIFOSET(fd, packet_len(0x7e2));
  8870. }
  8871. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8872. /// 07e6 <skill id>.W <msg id>.L
  8873. ///
  8874. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8875. /// "[SkillName] Message"
  8876. void clif_msg_skill(map_session_data* sd, uint16 skill_id, int msg_id)
  8877. {
  8878. int fd = sd->fd;
  8879. WFIFOHEAD(fd, packet_len(0x7e6));
  8880. WFIFOW(fd,0) = 0x7e6;
  8881. WFIFOW(fd,2) = skill_id;
  8882. WFIFOL(fd,4) = msg_id;
  8883. WFIFOSET(fd, packet_len(0x7e6));
  8884. }
  8885. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8886. /// 09cd <msg id>.W <color>.L
  8887. void clif_msg_color( map_session_data *sd, uint16 msg_id, uint32 color ){
  8888. nullpo_retv(sd);
  8889. int fd = sd->fd;
  8890. WFIFOHEAD(fd, packet_len(0x9cd));
  8891. WFIFOW(fd, 0) = 0x9cd;
  8892. WFIFOW(fd, 2) = msg_id;
  8893. WFIFOL(fd, 4) = color;
  8894. WFIFOSET(fd, packet_len(0x9cd));
  8895. }
  8896. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8897. /// Returns true if the packet was parsed successfully.
  8898. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8899. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8900. static bool clif_process_message(map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8901. const char* seperator = " : ";
  8902. int fd;
  8903. struct s_packet_db* info;
  8904. uint16 packetLength, inputLength;
  8905. const char *input, *name, *message;
  8906. size_t nameLength, messageLength;
  8907. fd = sd->fd;
  8908. info = &packet_db[RFIFOW(fd,0)];
  8909. packetLength = RFIFOW(fd,info->pos[0]);
  8910. input = RFIFOCP(fd,info->pos[1]);
  8911. // basic structure check for the 4-byte header
  8912. if( packetLength < 4 ){
  8913. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8914. return false;
  8915. }else{
  8916. inputLength = packetLength - 4;
  8917. }
  8918. // process <name> part of the packet
  8919. if( whisperFormat ) {
  8920. // name has fixed width
  8921. if( inputLength < NAME_LENGTH + 1 ) {
  8922. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8923. return false;
  8924. }
  8925. name = input;
  8926. // validate name
  8927. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8928. // only restriction is that the name must be zero-terminated
  8929. if( name[nameLength] != '\0' ) {
  8930. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8931. return false;
  8932. }
  8933. message = input + NAME_LENGTH;
  8934. messageLength = inputLength - NAME_LENGTH;
  8935. }else{
  8936. // name and message are separated by ' : '
  8937. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8938. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8939. // check if there's enough data provided
  8940. if( inputLength < nameLength + seperatorLength + 1 ){
  8941. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8942. return false;
  8943. }
  8944. name = input;
  8945. // validate name
  8946. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8947. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8948. {
  8949. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8950. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8951. set_eof(sd->fd); // Just kick them out to correct it.
  8952. return false;
  8953. }
  8954. message = input + nameLength + seperatorLength;
  8955. messageLength = inputLength - nameLength - seperatorLength;
  8956. }
  8957. #if PACKETVER < 20151001
  8958. // the declared length must match real length
  8959. if( messageLength != strnlen(message, messageLength)+1 ) {
  8960. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8961. return false;
  8962. }
  8963. // verify <message> part of the packet
  8964. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8965. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8966. return false;
  8967. }
  8968. #else
  8969. // No zero termination anymore
  8970. messageLength += 1;
  8971. #endif
  8972. // messages mustn't be too long
  8973. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8974. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8975. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8976. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8977. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8978. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8979. return false;
  8980. }
  8981. // If it is not a whisper message, set the name to the fakename of the player
  8982. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8983. strcpy( out_name, sd->fakename );
  8984. }else{
  8985. safestrncpy( out_name, name, nameLength + 1 );
  8986. }
  8987. safestrncpy( out_message, message, messageLength );
  8988. if( whisperFormat ){
  8989. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8990. out_full_message[nameLength] = '\0';
  8991. }else{
  8992. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8993. }
  8994. if( is_atcommand( fd, sd, out_message, 1 ) )
  8995. return false;
  8996. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8997. return false; //no "chatting" while muted.
  8998. if( battle_config.min_chat_delay ) { //[Skotlex]
  8999. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9000. return false;
  9001. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9002. }
  9003. if (battle_config.idletime_option&IDLE_CHAT)
  9004. sd->idletime = last_tick;
  9005. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  9006. sd->idletime_hom = last_tick;
  9007. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  9008. sd->idletime_mer = last_tick;
  9009. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  9010. return true;
  9011. }
  9012. /**
  9013. * Displays a message if the player enters a PK Zone (during pk_mode)
  9014. * @param sd: Player data
  9015. */
  9016. inline void clif_pk_mode_message(map_session_data * sd)
  9017. {
  9018. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  9019. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  9020. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  9021. char output[CHAT_SIZE_MAX];
  9022. // 1504: You've entered a PK Zone (safe until level %d).
  9023. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  9024. battle_config.pk_min_level);
  9025. clif_showscript(&sd->bl, output, SELF);
  9026. } else {
  9027. // 1503: You've entered a PK Zone.
  9028. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  9029. }
  9030. }
  9031. return;
  9032. }
  9033. // ---------------------
  9034. // clif_parse_wanttoconnect
  9035. // ---------------------
  9036. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  9037. // error codes:
  9038. // 0 - Success
  9039. // 1 - Unknown packet_ver
  9040. // 2 - Invalid account_id
  9041. // 3 - Invalid char_id
  9042. // 4 - Invalid login_id1 (reserved)
  9043. // 5 - Invalid client_tick (reserved)
  9044. // 6 - Invalid sex
  9045. // Only the first 'invalid' error that appears is used.
  9046. static int clif_parse_WantToConnection_sub(int fd)
  9047. {
  9048. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  9049. unsigned short cmd;
  9050. //By default, start searching on the default one.
  9051. cmd = RFIFOW(fd, 0);
  9052. packet_len = RFIFOREST(fd);
  9053. // FIXME: If the packet is not received at once, this will FAIL.
  9054. // Figure out, when it happens, that only part of the packet is
  9055. // received, or fix the function to be able to deal with that
  9056. // case.
  9057. if( packet_len != packet_db[cmd].len )
  9058. return 1; /* wrong length */
  9059. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  9060. return 2; /* invalid account_id */
  9061. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  9062. return 3; /* invalid char_id */
  9063. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  9064. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  9065. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  9066. return 6; /* invalid sex */
  9067. else
  9068. return 0;
  9069. }
  9070. /// Request to connect to map-server.
  9071. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  9072. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  9073. /// There are various variants of this packet, some of them have padding between fields.
  9074. void clif_parse_WantToConnection(int fd, map_session_data* sd)
  9075. {
  9076. struct block_list* bl;
  9077. struct auth_node* node;
  9078. int cmd, account_id, char_id, login_id1, sex, err;
  9079. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  9080. if (sd) {
  9081. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9082. return;
  9083. }
  9084. cmd = RFIFOW(fd, 0);
  9085. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9086. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9087. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9088. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9089. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9090. err = clif_parse_WantToConnection_sub(fd);
  9091. if( err ){ // connection rejected
  9092. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9093. err == 1 ? "." :
  9094. err == 2 ? ", possibly for having an invalid account_id." :
  9095. err == 3 ? ", possibly for having an invalid char_id." :
  9096. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9097. err == 4 ? ", possibly for having an invalid login_id1." :
  9098. err == 5 ? ", possibly for having an invalid client_tick." :
  9099. */
  9100. err == 6 ? ", possibly for having an invalid sex." :
  9101. ". ERROR invalid error code"));
  9102. WFIFOHEAD(fd,packet_len(0x6a));
  9103. WFIFOW(fd,0) = 0x6a;
  9104. WFIFOB(fd,2) = err;
  9105. WFIFOSET(fd,packet_len(0x6a));
  9106. #ifdef DUMP_INVALID_PACKET
  9107. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9108. #endif
  9109. RFIFOSKIP(fd, RFIFOREST(fd));
  9110. set_eof(fd);
  9111. return;
  9112. }
  9113. if( !global_core->is_running() ){ // not allowed
  9114. clif_authfail_fd(fd,1);// server closed
  9115. return;
  9116. }
  9117. //Check for double login.
  9118. bl = map_id2bl(account_id);
  9119. if(bl && bl->type != BL_PC) {
  9120. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9121. WFIFOHEAD(fd,packet_len(0x6a));
  9122. WFIFOW(fd,0) = 0x6a;
  9123. WFIFOB(fd,2) = 3; // Rejected by server
  9124. WFIFOSET(fd,packet_len(0x6a));
  9125. set_eof(fd);
  9126. return;
  9127. }
  9128. if (bl ||
  9129. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9130. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9131. {
  9132. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9133. return;
  9134. }
  9135. CREATE(sd, TBL_PC, 1);
  9136. new(sd) map_session_data();
  9137. sd->fd = fd;
  9138. #ifdef PACKET_OBFUSCATION
  9139. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9140. #endif
  9141. session[fd]->session_data = sd;
  9142. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9143. #if PACKETVER < 20070521
  9144. WFIFOHEAD(fd,4);
  9145. WFIFOL(fd,0) = sd->bl.id;
  9146. WFIFOSET(fd,4);
  9147. #else
  9148. WFIFOHEAD(fd,packet_len(0x283));
  9149. WFIFOW(fd,0) = 0x283;
  9150. WFIFOL(fd,2) = sd->bl.id;
  9151. WFIFOSET(fd,packet_len(0x283));
  9152. #endif
  9153. chrif_authreq(sd,false);
  9154. }
  9155. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9156. /// 007d
  9157. void clif_parse_LoadEndAck(int fd,map_session_data *sd)
  9158. {
  9159. bool guild_notice = false;
  9160. if(sd->bl.prev != NULL)
  9161. return;
  9162. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9163. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9164. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9165. sd->state.connect_new = 0;
  9166. return;
  9167. }
  9168. if (sd->state.rewarp) { //Rewarp player.
  9169. sd->state.rewarp = 0;
  9170. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9171. return;
  9172. }
  9173. sd->state.warping = 0;
  9174. // look
  9175. #if PACKETVER < 4
  9176. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9177. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9178. #else
  9179. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9180. #endif
  9181. pc_set_costume_view(sd);
  9182. if(sd->vd.cloth_color)
  9183. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9184. if(sd->vd.body_style)
  9185. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9186. // item
  9187. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9188. pc_checkitem(sd);
  9189. clif_equipswitch_list(sd);
  9190. // cart
  9191. if(pc_iscarton(sd)) {
  9192. clif_cartlist(sd);
  9193. clif_updatestatus(sd,SP_CARTINFO);
  9194. }
  9195. // weight
  9196. clif_updatestatus(sd,SP_WEIGHT);
  9197. clif_updatestatus(sd,SP_MAXWEIGHT);
  9198. // guild
  9199. // (needs to go before clif_spawn() to show guild emblems correctly)
  9200. if(sd->status.guild_id)
  9201. guild_send_memberinfoshort(sd,1);
  9202. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9203. if(battle_config.pc_invincible_time > 0) {
  9204. if(mapdata_flag_gvg(mapdata))
  9205. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9206. else
  9207. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9208. }
  9209. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9210. map_spawnmobs(sd->bl.m);
  9211. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9212. mapdata->users_pvp++;
  9213. }
  9214. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9215. // reset the callshop flag if the player changes map
  9216. sd->state.callshop = 0;
  9217. if(map_addblock(&sd->bl))
  9218. return;
  9219. clif_spawn(&sd->bl);
  9220. // Party
  9221. // (needs to go after clif_spawn() to show hp bars correctly)
  9222. if(sd->status.party_id) {
  9223. party_send_movemap(sd);
  9224. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9225. }
  9226. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9227. if(!pc_isinvisible(sd) && mapdata->getMapFlag(MF_PVP)) {
  9228. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9229. if (!mapdata->getMapFlag(MF_PVP_NOCALCRANK))
  9230. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9231. sd->pvp_rank = 0;
  9232. sd->pvp_lastusers = 0;
  9233. sd->pvp_point = 5;
  9234. sd->pvp_won = 0;
  9235. sd->pvp_lost = 0;
  9236. }
  9237. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9238. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9239. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9240. else if (mapdata->getMapFlag(MF_GVG_DUNGEON))
  9241. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9242. else if( mapdata_flag_gvg(mapdata) )
  9243. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9244. else
  9245. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9246. // info about nearby objects
  9247. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9248. 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);
  9249. // pet
  9250. if( sd->pd ) {
  9251. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9252. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9253. pet_return_egg( sd, sd->pd );
  9254. } else {
  9255. if(map_addblock(&sd->pd->bl))
  9256. return;
  9257. clif_spawn(&sd->pd->bl);
  9258. clif_send_petdata(sd,sd->pd,0,0);
  9259. clif_send_petstatus(sd);
  9260. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9261. }
  9262. }
  9263. //homunculus [blackhole89]
  9264. if( hom_is_active(sd->hd) ) {
  9265. if(map_addblock(&sd->hd->bl))
  9266. return;
  9267. clif_spawn(&sd->hd->bl);
  9268. clif_send_homdata(sd,SP_ACK,0);
  9269. clif_hominfo(sd,sd->hd,1);
  9270. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9271. clif_homskillinfoblock(sd);
  9272. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9273. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9274. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9275. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9276. }
  9277. if( sd->md ) {
  9278. if(map_addblock(&sd->md->bl))
  9279. return;
  9280. clif_spawn(&sd->md->bl);
  9281. clif_mercenary_info(sd);
  9282. clif_mercenary_skillblock(sd);
  9283. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9284. }
  9285. if( sd->ed ) {
  9286. if (map_addblock(&sd->ed->bl))
  9287. return;
  9288. clif_spawn(&sd->ed->bl);
  9289. clif_elemental_info(sd);
  9290. clif_elemental_updatestatus(sd,SP_HP);
  9291. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9292. clif_elemental_updatestatus(sd,SP_SP);
  9293. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9294. }
  9295. if(sd->state.connect_new) {
  9296. int lv;
  9297. guild_notice = true;
  9298. clif_skillinfoblock(sd);
  9299. clif_hotkeys_send(sd,0);
  9300. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9301. clif_hotkeys_send(sd,1);
  9302. #endif
  9303. clif_updatestatus(sd,SP_BASEEXP);
  9304. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9305. clif_updatestatus(sd,SP_JOBEXP);
  9306. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9307. clif_updatestatus(sd,SP_SKILLPOINT);
  9308. clif_initialstatus(sd);
  9309. if (sd->sc.option&OPTION_FALCON)
  9310. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9311. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9312. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9313. else if (sd->sc.option&OPTION_WUGRIDER)
  9314. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9315. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9316. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9317. if(sd->status.manner < 0)
  9318. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9319. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9320. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9321. if(sd->bl.m == sd->feel_map[0].m
  9322. || sd->bl.m == sd->feel_map[1].m
  9323. || sd->bl.m == sd->feel_map[2].m)
  9324. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9325. }
  9326. if(sd->pd && sd->pd->pet.intimate > 900)
  9327. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9328. if(hom_is_active(sd->hd))
  9329. hom_init_timers(sd->hd);
  9330. if (night_flag && mapdata->getMapFlag(MF_NIGHTENABLED)) {
  9331. sd->state.night = 1;
  9332. clif_status_load(&sd->bl, EFST_SKE, 1);
  9333. }
  9334. // Notify everyone that this char logged in [Skotlex].
  9335. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9336. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9337. //Login Event
  9338. npc_script_event(sd, NPCE_LOGIN);
  9339. }
  9340. // Set facing direction before check below to update client
  9341. if (battle_config.spawn_direction)
  9342. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9343. } else {
  9344. //For some reason the client "loses" these on warp/map-change.
  9345. clif_updatestatus(sd,SP_STR);
  9346. clif_updatestatus(sd,SP_AGI);
  9347. clif_updatestatus(sd,SP_VIT);
  9348. clif_updatestatus(sd,SP_INT);
  9349. clif_updatestatus(sd,SP_DEX);
  9350. clif_updatestatus(sd,SP_LUK);
  9351. #ifdef RENEWAL
  9352. clif_updatestatus(sd,SP_POW);
  9353. clif_updatestatus(sd,SP_STA);
  9354. clif_updatestatus(sd,SP_WIS);
  9355. clif_updatestatus(sd,SP_SPL);
  9356. clif_updatestatus(sd,SP_CON);
  9357. clif_updatestatus(sd,SP_CRT);
  9358. #endif
  9359. // abort currently running script
  9360. sd->state.using_fake_npc = 0;
  9361. sd->state.menu_or_input = 0;
  9362. sd->npc_menu = 0;
  9363. if(sd->npc_id)
  9364. npc_event_dequeue(sd);
  9365. }
  9366. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9367. clif_partyinvitationstate( *sd );
  9368. #if PACKETVER >= 20070918
  9369. clif_equipcheckbox(sd);
  9370. #endif
  9371. clif_pet_autofeed_status(sd,false);
  9372. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9373. #if PACKETVER >= 20170920
  9374. if( battle_config.homunculus_autofeed_always ){
  9375. // Always send ON or OFF
  9376. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9377. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9378. }else{
  9379. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9380. }
  9381. }else{
  9382. // Only send when enabled
  9383. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9384. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9385. }
  9386. }
  9387. #endif
  9388. clif_reputation_list( *sd );
  9389. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9390. clif_guild_notice(sd); // Displays after VIP
  9391. guild_notice = false; // Do not display it twice
  9392. }
  9393. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9394. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9395. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->getMapFlag(MF_BATTLEGROUND))) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->getMapFlag(MF_BATTLEGROUND))))
  9396. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9397. }
  9398. if( night_flag && mapdata->getMapFlag(MF_NIGHTENABLED) )
  9399. { //Display night.
  9400. if( !sd->state.night )
  9401. {
  9402. sd->state.night = 1;
  9403. clif_status_load(&sd->bl, EFST_SKE, 1);
  9404. }
  9405. }
  9406. else if( sd->state.night )
  9407. { //Clear night display.
  9408. sd->state.night = 0;
  9409. clif_status_load(&sd->bl, EFST_SKE, 0);
  9410. }
  9411. if( mapdata->getMapFlag(MF_BATTLEGROUND) )
  9412. {
  9413. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9414. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9415. clif_bg_updatescore_single(sd);
  9416. }
  9417. if( mapdata->getMapFlag(MF_ALLOWKS) && !mapdata_flag_ks(mapdata) )
  9418. {
  9419. char output[128];
  9420. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9421. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9422. }
  9423. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9424. mapdata->hpmeter_visible++;
  9425. sd->state.hpmeter_visible = 1;
  9426. }
  9427. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9428. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9429. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9430. #ifdef VIP_ENABLE
  9431. if (!sd->state.connect_new &&
  9432. !sd->vip.disableshowrate &&
  9433. sd->state.pmap != sd->bl.m &&
  9434. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->getMapFlag(MF_BEXP)
  9435. )
  9436. {
  9437. clif_display_pinfo( *sd );
  9438. }
  9439. #endif
  9440. // Instances do not need their own channels
  9441. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->getMapFlag(MF_NOMAPCHANNELAUTOJOIN) )
  9442. channel_mjoin(sd); //join new map
  9443. clif_pk_mode_message(sd);
  9444. }
  9445. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9446. clif_guild_notice(sd); // Displays at end
  9447. }
  9448. mail_clear(sd);
  9449. /* Guild Aura Init */
  9450. if( sd->guild && sd->state.gmaster_flag ) {
  9451. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP));
  9452. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS));
  9453. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD));
  9454. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES));
  9455. }
  9456. if( sd->state.vending ) { /* show we have a vending */
  9457. clif_openvending(sd,sd->bl.id,sd->vending);
  9458. clif_showvendingboard( *sd );
  9459. }
  9460. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9461. if(!sd->state.autotrade && mapdata->getMapFlag(MF_LOADEVENT)) // Lance
  9462. npc_script_event(sd, NPCE_LOADMAP);
  9463. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9464. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9465. if (sd->sc.opt2) //Client loses these on warp.
  9466. clif_changeoption(&sd->bl);
  9467. 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)) {
  9468. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9469. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9470. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9471. }
  9472. clif_weather_check(sd);
  9473. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9474. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9475. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9476. else
  9477. sd->areanpc.clear();
  9478. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9479. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9480. pc_setdead(sd);
  9481. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9482. if(pc_isdead(sd))
  9483. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9484. else {
  9485. skill_usave_trigger(sd);
  9486. if (battle_config.spawn_direction)
  9487. clif_changed_dir(&sd->bl, SELF);
  9488. }
  9489. // Trigger skill effects if you appear standing on them
  9490. if(!battle_config.pc_invincible_time)
  9491. skill_unit_move(&sd->bl,gettick(),1);
  9492. pc_show_questinfo_reinit(sd);
  9493. pc_show_questinfo(sd);
  9494. #if PACKETVER >= 20150513
  9495. if( sd->mail.inbox.unread ){
  9496. clif_Mail_new(sd, 0, NULL, NULL);
  9497. }
  9498. #endif
  9499. sd->state.connect_new = 0;
  9500. sd->state.changemap = false;
  9501. }
  9502. /// Server's tick (ZC_NOTIFY_TIME).
  9503. /// 007f <time>.L
  9504. void clif_notify_time(map_session_data* sd, t_tick time)
  9505. {
  9506. int fd = sd->fd;
  9507. WFIFOHEAD(fd,packet_len(0x7f));
  9508. WFIFOW(fd,0) = 0x7f;
  9509. WFIFOL(fd,2) = client_tick(time);
  9510. WFIFOSET(fd,packet_len(0x7f));
  9511. }
  9512. /// Request for server's tick.
  9513. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9514. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9515. /// There are various variants of this packet, some of them have padding between fields.
  9516. void clif_parse_TickSend(int fd, map_session_data *sd)
  9517. {
  9518. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9519. clif_notify_time(sd, gettick());
  9520. }
  9521. /// Sends hotkey bar.
  9522. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9523. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9524. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9525. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9526. void clif_hotkeys_send( map_session_data *sd, int tab ){
  9527. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9528. nullpo_retv( sd );
  9529. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9530. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9531. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9532. if( tab == 0 ){
  9533. p.rotate = sd->status.hotkey_rowshift;
  9534. }else{
  9535. p.rotate = sd->status.hotkey_rowshift2;
  9536. }
  9537. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9538. p.tab = tab;
  9539. #endif
  9540. #endif
  9541. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9542. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9543. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9544. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9545. }
  9546. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9547. #endif
  9548. }
  9549. /// Request to update a position on the hotkey row bar
  9550. void clif_parse_HotkeyRowShift( int fd, map_session_data *sd ){
  9551. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9552. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9553. if( p->tab == 0 ){
  9554. sd->status.hotkey_rowshift = p->rowshift;
  9555. }else{
  9556. sd->status.hotkey_rowshift2 = p->rowshift;
  9557. }
  9558. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9559. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9560. sd->status.hotkey_rowshift = p->rowshift;
  9561. #endif
  9562. }
  9563. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9564. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9565. void clif_parse_Hotkey(int fd, map_session_data *sd) {
  9566. #ifdef HOTKEY_SAVING
  9567. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9568. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9569. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9570. if( idx >= MAX_HOTKEYS_DB ){
  9571. return;
  9572. }
  9573. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9574. sd->status.hotkeys[idx].id = p->hotkey.id;
  9575. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9576. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9577. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9578. const unsigned short idx = p->index;
  9579. if( idx >= MAX_HOTKEYS_DB ){
  9580. return;
  9581. }
  9582. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9583. sd->status.hotkeys[idx].id = p->hotkey.id;
  9584. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9585. #endif
  9586. #endif
  9587. }
  9588. /// Displays cast-like progress bar (ZC_PROGRESS).
  9589. /// 02f0 <color>.L <time>.L
  9590. void clif_progressbar(map_session_data * sd, unsigned long color, unsigned int second)
  9591. {
  9592. int fd = sd->fd;
  9593. WFIFOHEAD(fd,packet_len(0x2f0));
  9594. WFIFOW(fd,0) = 0x2f0;
  9595. WFIFOL(fd,2) = color;
  9596. WFIFOL(fd,6) = second;
  9597. WFIFOSET(fd,packet_len(0x2f0));
  9598. }
  9599. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9600. /// 02f2
  9601. void clif_progressbar_abort(map_session_data * sd)
  9602. {
  9603. int fd = sd->fd;
  9604. WFIFOHEAD(fd,packet_len(0x2f2));
  9605. WFIFOW(fd,0) = 0x2f2;
  9606. WFIFOSET(fd,packet_len(0x2f2));
  9607. }
  9608. /// Notification from the client, that the progress bar has reached 100%.
  9609. /// 02f1 (CZ_PROGRESS)
  9610. void clif_parse_progressbar(int fd, map_session_data * sd){
  9611. // No progressbar active, ignore it
  9612. if( !sd->progressbar.npc_id ){
  9613. return;
  9614. }
  9615. int npc_id = sd->progressbar.npc_id;
  9616. bool closing = false;
  9617. // Check if the progress was canceled
  9618. if( gettick() < sd->progressbar.timeout && sd->st ){
  9619. closing = true;
  9620. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9621. // If a message window was open, offer a close button to the user
  9622. if( sd->st->mes_active ){
  9623. clif_scriptclose( sd, npc_id );
  9624. }
  9625. }
  9626. sd->progressbar.npc_id = 0;
  9627. sd->progressbar.timeout = 0;
  9628. sd->state.workinprogress = WIP_DISABLE_NONE;
  9629. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9630. sd->idletime = last_tick;
  9631. }
  9632. npc_scriptcont(sd, npc_id, closing);
  9633. }
  9634. /// Displays cast-like progress bar on a NPC
  9635. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9636. void clif_progressbar_npc( struct npc_data *nd, map_session_data* sd ){
  9637. #if PACKETVER >= 20130821
  9638. unsigned char buf[14];
  9639. if( nd->progressbar.timeout > 0 ){
  9640. WBUFW(buf,0) = 0x9d1;
  9641. WBUFL(buf,2) = nd->bl.id;
  9642. WBUFL(buf,6) = nd->progressbar.color;
  9643. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9644. if( sd ){
  9645. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9646. }else{
  9647. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9648. }
  9649. }
  9650. #endif
  9651. }
  9652. /// Request to walk to a certain position on the current map.
  9653. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9654. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9655. /// There are various variants of this packet, some of them have padding between fields.
  9656. void clif_parse_WalkToXY(int fd, map_session_data *sd)
  9657. {
  9658. short x, y;
  9659. if (pc_isdead(sd)) {
  9660. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9661. return;
  9662. }
  9663. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9664. ; //You CAN walk on this OPT1 value.
  9665. else if (sd->progressbar.npc_id) {
  9666. clif_progressbar_abort(sd);
  9667. return; // First walk attempt cancels the progress bar
  9668. } else if (pc_cant_act(sd))
  9669. return;
  9670. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9671. return;
  9672. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9673. //A move command one cell west is only valid if the target cell is free
  9674. if(battle_config.official_cell_stack_limit > 0
  9675. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9676. return;
  9677. // Cloaking wall check is actually updated when you click to process next movement
  9678. // not when you move each cell. This is official behaviour.
  9679. if (sd->sc.getSCE(SC_CLOAKING))
  9680. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9681. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9682. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9683. pc_delinvincibletimer(sd);
  9684. //Set last idle time... [Skotlex]
  9685. if (battle_config.idletime_option&IDLE_WALK)
  9686. sd->idletime = last_tick;
  9687. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9688. sd->idletime_hom = last_tick;
  9689. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9690. sd->idletime_mer = last_tick;
  9691. unit_walktoxy(&sd->bl, x, y, 4);
  9692. }
  9693. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9694. /// 018b <result>.W
  9695. /// result:
  9696. /// 0 = disconnect (quit)
  9697. /// 1 = cannot disconnect (wait 10 seconds)
  9698. /// ? = ignored
  9699. void clif_disconnect_ack(map_session_data* sd, short result)
  9700. {
  9701. int fd = sd->fd;
  9702. WFIFOHEAD(fd,packet_len(0x18b));
  9703. WFIFOW(fd,0) = 0x18b;
  9704. WFIFOW(fd,2) = result;
  9705. WFIFOSET(fd,packet_len(0x18b));
  9706. }
  9707. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9708. /// 018a <type>.W
  9709. /// type:
  9710. /// 0 = quit
  9711. void clif_parse_QuitGame(int fd, map_session_data *sd)
  9712. {
  9713. /* Rovert's prevent logout option fixed [Valaris] */
  9714. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9715. 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) &&
  9716. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9717. {
  9718. pc_damage_log_clear(sd,0);
  9719. clif_disconnect_ack(sd, 0);
  9720. flush_fifo( fd );
  9721. if( battle_config.drop_connection_on_quit ){
  9722. set_eof( fd );
  9723. }
  9724. } else {
  9725. clif_disconnect_ack(sd, 1);
  9726. }
  9727. }
  9728. /// Requesting unit's name.
  9729. /// 0094 <id>.L (CZ_REQNAME)
  9730. /// 0368 <id>.L (CZ_REQNAME2)
  9731. /// There are various variants of this packet, some of them have padding between fields.
  9732. void clif_parse_GetCharNameRequest(int fd, map_session_data *sd)
  9733. {
  9734. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9735. struct block_list* bl;
  9736. //status_change *sc;
  9737. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9738. id = sd->bl.id;
  9739. bl = map_id2bl(id);
  9740. if( bl == NULL )
  9741. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9742. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9743. return; // Block namerequests past view range
  9744. // 'see people in GM hide' cheat detection
  9745. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9746. sc = status_get_sc(bl);
  9747. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9748. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9749. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9750. ) {
  9751. char gm_msg[256];
  9752. 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);
  9753. ShowWarning(gm_msg);
  9754. // information is sent to all online GMs
  9755. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9756. return;
  9757. }
  9758. */
  9759. clif_name(&sd->bl,bl,SELF);
  9760. }
  9761. /// Validates and processes global messages
  9762. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9763. /// There are various variants of this packet.
  9764. void clif_parse_GlobalMessage(int fd, map_session_data* sd)
  9765. {
  9766. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9767. size_t length;
  9768. // validate packet and retrieve name and message
  9769. if( !clif_process_message(sd, false, name, message, output ) )
  9770. return;
  9771. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9772. channel_send(sd->gcbind,sd,message);
  9773. return;
  9774. }
  9775. // send message to others (using the send buffer for temp. storage)
  9776. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9777. length = strlen(output) + 1;
  9778. // send back message to the speaker
  9779. WFIFOHEAD(fd,4+length);
  9780. WFIFOW(fd,0) = 0x8e;
  9781. WFIFOW(fd,2) = (uint16)(4+length);
  9782. safestrncpy(WFIFOCP(fd,4), output, length );
  9783. WFIFOSET(fd, WFIFOW(fd,2));
  9784. #ifdef PCRE_SUPPORT
  9785. // trigger listening npcs
  9786. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9787. #endif
  9788. // Chat logging type 'O' / Global Chat
  9789. 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);
  9790. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9791. }
  9792. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9793. /// Request to warp to a map on given coordinates.
  9794. /// 0140 <map name>.16B <x>.W <y>.W
  9795. void clif_parse_MapMove(int fd, map_session_data *sd)
  9796. {
  9797. char command[MAP_NAME_LENGTH_EXT+25];
  9798. char* map_name;
  9799. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9800. map_name = RFIFOCP(fd,info->pos[0]);
  9801. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9802. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9803. RFIFOW(fd,info->pos[1]), //x
  9804. RFIFOW(fd,info->pos[2])); //y
  9805. is_atcommand(fd, sd, command, 1);
  9806. }
  9807. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9808. /// 009c <id>.L <head dir>.W <dir>.B
  9809. /// head dir:
  9810. /// 0 = straight
  9811. /// 1 = turned CW
  9812. /// 2 = turned CCW
  9813. /// dir:
  9814. /// 0 = north
  9815. /// 1 = northwest
  9816. /// 2 = west
  9817. /// 3 = southwest
  9818. /// 4 = south
  9819. /// 5 = southeast
  9820. /// 6 = east
  9821. /// 7 = northeast
  9822. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9823. {
  9824. unsigned char buf[64];
  9825. WBUFW(buf,0) = 0x9c;
  9826. WBUFL(buf,2) = bl->id;
  9827. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9828. WBUFB(buf,8) = unit_getdir(bl);
  9829. clif_send(buf, packet_len(0x9c), bl, target);
  9830. if (disguised(bl)) {
  9831. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9832. WBUFW(buf,6) = 0;
  9833. clif_send(buf, packet_len(0x9c), bl, SELF);
  9834. }
  9835. }
  9836. /// Request to change own body and head direction.
  9837. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9838. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9839. /// There are various variants of this packet, some of them have padding between fields.
  9840. void clif_parse_ChangeDir(int fd, map_session_data *sd)
  9841. {
  9842. unsigned char headdir, dir;
  9843. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9844. headdir = RFIFOB(fd,info->pos[0]);
  9845. dir = RFIFOB(fd,info->pos[1]);
  9846. pc_setdir(sd, dir, headdir);
  9847. clif_changed_dir(&sd->bl, AREA_WOS);
  9848. }
  9849. /// Request to show an emotion (CZ_REQ_EMOTION).
  9850. /// 00bf <type>.B
  9851. /// type:
  9852. /// @see enum emotion_type
  9853. void clif_parse_Emotion(int fd, map_session_data *sd)
  9854. {
  9855. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9856. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9857. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9858. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9859. return;
  9860. }
  9861. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9862. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9863. sd->emotionlasttime = time(NULL);
  9864. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9865. return;
  9866. }
  9867. sd->emotionlasttime = time(NULL);
  9868. if (battle_config.idletime_option&IDLE_EMOTION)
  9869. sd->idletime = last_tick;
  9870. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9871. sd->idletime_hom = last_tick;
  9872. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9873. sd->idletime_mer = last_tick;
  9874. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9875. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9876. return;
  9877. }
  9878. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9879. emoticon = rnd()%6+ET_DICE1;
  9880. }
  9881. clif_emotion(&sd->bl, emoticon);
  9882. } else
  9883. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9884. }
  9885. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9886. /// 00c2 <count>.L
  9887. void clif_user_count(map_session_data* sd, int count)
  9888. {
  9889. int fd = sd->fd;
  9890. WFIFOHEAD(fd,packet_len(0xc2));
  9891. WFIFOW(fd,0) = 0xc2;
  9892. WFIFOL(fd,2) = count;
  9893. WFIFOSET(fd,packet_len(0xc2));
  9894. }
  9895. /// /w /who (CZ_REQ_USER_COUNT).
  9896. /// Request to display amount of currently connected players.
  9897. /// 00c1
  9898. void clif_parse_HowManyConnections(int fd, map_session_data *sd)
  9899. {
  9900. clif_user_count(sd, map_getusers());
  9901. }
  9902. void clif_parse_ActionRequest_sub(map_session_data *sd, int action_type, int target_id, t_tick tick)
  9903. {
  9904. if (pc_isdead(sd)) {
  9905. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9906. return;
  9907. }
  9908. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9909. if (action_type != 0x00 && action_type != 0x07) {
  9910. if (sd->sc.cant.interact)
  9911. return;
  9912. pc_stop_walking(sd, 1);
  9913. }
  9914. pc_stop_attack(sd);
  9915. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9916. target_id = sd->bl.id;
  9917. switch(action_type)
  9918. {
  9919. case 0x00: // once attack
  9920. case 0x07: // continuous attack
  9921. if( pc_cant_act(sd) )
  9922. return;
  9923. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9924. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9925. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9926. return;
  9927. }
  9928. }
  9929. pc_delinvincibletimer(sd);
  9930. if (battle_config.idletime_option&IDLE_ATTACK)
  9931. sd->idletime = last_tick;
  9932. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9933. sd->idletime_hom = last_tick;
  9934. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9935. sd->idletime_mer = last_tick;
  9936. unit_attack(&sd->bl, target_id, action_type != 0);
  9937. break;
  9938. case 0x02: // sitdown
  9939. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9940. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9941. break;
  9942. }
  9943. if(pc_issit(sd)) {
  9944. //Bugged client? Just refresh them.
  9945. clif_sitting(&sd->bl);
  9946. return;
  9947. }
  9948. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9949. break;
  9950. if (sd->sc.count && (
  9951. sd->sc.getSCE(SC_DANCING) ||
  9952. (sd->sc.getSCE(SC_GRAVITATION) && sd->sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9953. )) //No sitting during these states either.
  9954. break;
  9955. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9956. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9957. break;
  9958. }
  9959. if (battle_config.idletime_option&IDLE_SIT)
  9960. sd->idletime = last_tick;
  9961. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9962. sd->idletime_hom = last_tick;
  9963. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9964. sd->idletime_mer = last_tick;
  9965. pc_setsit(sd);
  9966. skill_sit(sd, true);
  9967. clif_sitting(&sd->bl);
  9968. break;
  9969. case 0x03: // standup
  9970. if (!pc_issit(sd)) {
  9971. //Bugged client? Just refresh them.
  9972. clif_standing(&sd->bl);
  9973. return;
  9974. }
  9975. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9976. break;
  9977. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9978. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9979. break;
  9980. }
  9981. if (pc_setstand(sd, false)) {
  9982. if (battle_config.idletime_option&IDLE_SIT)
  9983. sd->idletime = last_tick;
  9984. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9985. sd->idletime_hom = last_tick;
  9986. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9987. sd->idletime_mer = last_tick;
  9988. skill_sit(sd, false);
  9989. clif_standing(&sd->bl);
  9990. }
  9991. break;
  9992. }
  9993. }
  9994. /// Request for an action.
  9995. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9996. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9997. /// action:
  9998. /// 0 = attack
  9999. /// 1 = pick up item
  10000. /// 2 = sit down
  10001. /// 3 = stand up
  10002. /// 7 = continous attack
  10003. /// 12 = (touch skill?)
  10004. /// There are various variants of this packet, some of them have padding between fields.
  10005. void clif_parse_ActionRequest(int fd, map_session_data *sd)
  10006. {
  10007. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10008. clif_parse_ActionRequest_sub(sd,
  10009. RFIFOB(fd,info->pos[1]),
  10010. RFIFOL(fd,info->pos[0]),
  10011. gettick()
  10012. );
  10013. }
  10014. /// Response to the death/system menu (CZ_RESTART).
  10015. /// 00b2 <type>.B
  10016. /// type:
  10017. /// 0 = restart (respawn)
  10018. /// 1 = char-select (disconnect)
  10019. void clif_parse_Restart(int fd, map_session_data *sd)
  10020. {
  10021. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  10022. case 0x00:
  10023. pc_respawn(sd,CLR_OUTSIGHT);
  10024. break;
  10025. case 0x01:
  10026. /* Rovert's Prevent logout option - Fixed [Valaris] */
  10027. 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) &&
  10028. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  10029. { //Send to char-server for character selection.
  10030. pc_damage_log_clear(sd,0);
  10031. chrif_charselectreq(sd, session[fd]->client_addr);
  10032. } else {
  10033. clif_disconnect_ack(sd, 1);
  10034. }
  10035. break;
  10036. }
  10037. }
  10038. /// Validates and processes whispered messages (CZ_WHISPER).
  10039. /// 0096 <packet len>.W <nick>.24B <message>.?B
  10040. void clif_parse_WisMessage(int fd, map_session_data* sd)
  10041. {
  10042. map_session_data* dstsd;
  10043. int i;
  10044. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10045. // validate packet and retrieve name and message
  10046. if( !clif_process_message( sd, true, target, message, output ) )
  10047. return;
  10048. // Chat logging type 'W' / Whisper
  10049. 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);
  10050. //-------------------------------------------------------//
  10051. // Lordalfa - Paperboy - To whisper NPC commands //
  10052. //-------------------------------------------------------//
  10053. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  10054. {
  10055. char* str = target+4; //Skip the NPC: string part.
  10056. struct npc_data* npc;
  10057. if ((npc = npc_name2id(str))) {
  10058. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  10059. char *split;
  10060. char event[EVENT_NAME_LENGTH];
  10061. str = message;
  10062. // skip codepage indicator, if detected
  10063. if( str[0] == '|' && strlen(str) >= 4 )
  10064. str += 3;
  10065. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  10066. split = strchr(str,'#');
  10067. if( split == NULL ) { // use the remaining string
  10068. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10069. for( ++i; i < NUM_WHISPER_VAR; ++i )
  10070. split_data[i][0] = '\0';
  10071. break;
  10072. }
  10073. *split = '\0';
  10074. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10075. str = split+1;
  10076. }
  10077. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  10078. char variablename[CHAT_SIZE_MAX];
  10079. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  10080. set_var_str( sd, variablename, split_data[i] );
  10081. }
  10082. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  10083. npc_event(sd,event,0); // Calls the NPC label
  10084. return;
  10085. }
  10086. } else if( target[0] == '#' ) {
  10087. struct Channel *channel = NULL;
  10088. char* chname = target;
  10089. channel = channel_name2channel(chname,sd,3);
  10090. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  10091. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  10092. channel_send(channel,sd,message);
  10093. }
  10094. else if( channel->pass[0] == '\0') { //no pass needed
  10095. if (channel_join(channel,sd)==0)
  10096. channel_send(channel,sd,message); //join success
  10097. }
  10098. else {
  10099. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  10100. }
  10101. return;
  10102. }
  10103. }
  10104. // searching destination character
  10105. dstsd = map_nick2sd(target,false);
  10106. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  10107. // player is not on this map-server
  10108. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  10109. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  10110. // and if we ask for 'Test', we must not contact 'test' player
  10111. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  10112. intif_wis_message(sd, target, message, strlen(message) + 1);
  10113. return;
  10114. }
  10115. // if player ignores everyone
  10116. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10117. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  10118. clif_wis_end(fd, 1); // 1: target character is not logged in
  10119. else
  10120. clif_wis_end(fd, 3); // 3: everyone ignored by target
  10121. return;
  10122. }
  10123. // if player is autotrading
  10124. if (dstsd->state.autotrade == 1){
  10125. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  10126. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  10127. return;
  10128. }
  10129. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10130. // if player ignores the source character
  10131. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  10132. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  10133. clif_wis_end(fd, 2); // 2: ignored by target
  10134. return;
  10135. }
  10136. }
  10137. // notify sender of success
  10138. clif_wis_end(fd, 0); // 0: success to send wisper
  10139. // Normal message
  10140. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10141. }
  10142. /// /b /nb (CZ_BROADCAST).
  10143. /// Request to broadcast a message on whole server.
  10144. /// 0099 <packet len>.W <text>.?B 00
  10145. void clif_parse_Broadcast(int fd, map_session_data* sd) {
  10146. char command[CHAT_SIZE_MAX+11];
  10147. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10148. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10149. char* msg = RFIFOCP(fd,info->pos[1]);
  10150. // as the length varies depending on the command used, just block unreasonably long strings
  10151. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10152. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10153. is_atcommand(fd, sd, command, 1);
  10154. }
  10155. /// Request to pick up an item.
  10156. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10157. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10158. /// There are various variants of this packet, some of them have padding between fields.
  10159. void clif_parse_TakeItem(int fd, map_session_data *sd)
  10160. {
  10161. struct flooritem_data *fitem;
  10162. int map_object_id;
  10163. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10164. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10165. do {
  10166. if (pc_isdead(sd)) {
  10167. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10168. break;
  10169. }
  10170. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10171. break;
  10172. if (pc_cant_act(sd))
  10173. break;
  10174. if (!pc_takeitem(sd, fitem))
  10175. break;
  10176. return;
  10177. } while (0);
  10178. // Client REQUIRES a fail packet or you can no longer pick items.
  10179. clif_additem(sd,0,0,6);
  10180. }
  10181. /// Request to drop an item.
  10182. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10183. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10184. /// There are various variants of this packet, some of them have padding between fields.
  10185. void clif_parse_DropItem(int fd, map_session_data *sd){
  10186. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10187. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10188. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10189. for(;;) {
  10190. if (pc_isdead(sd))
  10191. break;
  10192. if (pc_cant_act2(sd) || sd->npc_id)
  10193. break;
  10194. if (sd->sc.cant.drop)
  10195. break;
  10196. if (!pc_dropitem(sd, item_index, item_amount))
  10197. break;
  10198. if (battle_config.idletime_option&IDLE_DROPITEM)
  10199. sd->idletime = last_tick;
  10200. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10201. sd->idletime_hom = last_tick;
  10202. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10203. sd->idletime_mer = last_tick;
  10204. return;
  10205. }
  10206. //Because the client does not like being ignored.
  10207. clif_dropitem(sd, item_index,0);
  10208. }
  10209. /// Request to use an item.
  10210. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10211. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10212. /// There are various variants of this packet, some of them have padding between fields.
  10213. void clif_parse_UseItem(int fd, map_session_data *sd)
  10214. {
  10215. int n;
  10216. if (pc_isdead(sd)) {
  10217. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10218. return;
  10219. }
  10220. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10221. clif_msg(sd, WORK_IN_PROGRESS);
  10222. return;
  10223. }
  10224. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10225. if (battle_config.idletime_option&IDLE_USEITEM)
  10226. sd->idletime = last_tick;
  10227. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10228. sd->idletime_hom = last_tick;
  10229. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10230. sd->idletime_mer = last_tick;
  10231. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10232. if(n <0 || n >= MAX_INVENTORY)
  10233. return;
  10234. if (!pc_useitem(sd,n))
  10235. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10236. }
  10237. /// Request to equip an item
  10238. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10239. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10240. void clif_parse_EquipItem(int fd,map_session_data *sd)
  10241. {
  10242. int index;
  10243. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10244. if(pc_isdead(sd)) {
  10245. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10246. return;
  10247. }
  10248. index = RFIFOW(fd,info->pos[0])-2;
  10249. if (index < 0 || index >= MAX_INVENTORY)
  10250. return; //Out of bounds check.
  10251. if(sd->npc_id && !sd->npc_item_flag) {
  10252. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10253. return;
  10254. } else if (sd->state.storage_flag || sd->sc.opt1)
  10255. ; //You can equip/unequip stuff while storage is open/under status changes
  10256. else if (pc_cant_act2(sd))
  10257. return;
  10258. if(!sd->inventory.u.items_inventory[index].identify) {
  10259. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10260. return;
  10261. }
  10262. if(!sd->inventory_data[index])
  10263. return;
  10264. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10265. pet_equipitem(sd,index);
  10266. return;
  10267. }
  10268. if (battle_config.idletime_option&IDLE_USEITEM)
  10269. sd->idletime = last_tick;
  10270. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10271. sd->idletime_hom = last_tick;
  10272. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10273. sd->idletime_mer = last_tick;
  10274. //Client doesn't send the position for ammo.
  10275. if(sd->inventory_data[index]->type == IT_AMMO)
  10276. pc_equipitem(sd,index,EQP_AMMO);
  10277. else {
  10278. int req_pos;
  10279. #if PACKETVER >= 20120925
  10280. req_pos = RFIFOL(fd,info->pos[1]);
  10281. #else
  10282. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10283. #endif
  10284. pc_equipitem(sd,index,req_pos);
  10285. }
  10286. }
  10287. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10288. /// 00ab <index>.W
  10289. void clif_parse_UnequipItem(int fd,map_session_data *sd)
  10290. {
  10291. int index;
  10292. if(pc_isdead(sd)) {
  10293. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10294. return;
  10295. }
  10296. if (sd->npc_id && !sd->npc_item_flag) {
  10297. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10298. return;
  10299. } else if (sd->state.storage_flag || sd->sc.opt1)
  10300. ; //You can equip/unequip stuff while storage is open/under status changes
  10301. else if (pc_cant_act2(sd))
  10302. return;
  10303. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10304. if (battle_config.idletime_option&IDLE_USEITEM)
  10305. sd->idletime = last_tick;
  10306. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10307. sd->idletime_hom = last_tick;
  10308. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10309. sd->idletime_mer = last_tick;
  10310. pc_unequipitem(sd,index,1);
  10311. }
  10312. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10313. /// 0090 <id>.L <type>.B
  10314. /// type:
  10315. /// 1 = click
  10316. void clif_parse_NpcClicked(int fd,map_session_data *sd)
  10317. {
  10318. struct block_list *bl;
  10319. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10320. if(pc_isdead(sd)) {
  10321. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10322. return;
  10323. }
  10324. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10325. #ifdef RENEWAL
  10326. clif_msg( sd, WORK_IN_PROGRESS );
  10327. #endif
  10328. return;
  10329. }
  10330. if( sd->state.mail_writing )
  10331. return;
  10332. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10333. //type = RFIFOB(fd,info->pos[1]);
  10334. if (!bl) return;
  10335. switch (bl->type) {
  10336. case BL_MOB:
  10337. case BL_PC:
  10338. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10339. break;
  10340. case BL_NPC:
  10341. #ifdef RENEWAL
  10342. 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
  10343. clif_msg(sd, WORK_IN_PROGRESS);
  10344. break;
  10345. }
  10346. #endif
  10347. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10348. struct npc_data* nd = (struct npc_data*)bl;
  10349. // Progressbar is running
  10350. if( nd->progressbar.timeout > 0 ){
  10351. return;
  10352. }
  10353. npc_click(sd,nd);
  10354. }
  10355. break;
  10356. }
  10357. }
  10358. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10359. /// 00c5 <id>.L <type>.B
  10360. /// type:
  10361. /// 0 = buy
  10362. /// 1 = sell
  10363. void clif_parse_NpcBuySellSelected(int fd,map_session_data *sd)
  10364. {
  10365. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10366. if (sd->state.trading)
  10367. return;
  10368. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10369. }
  10370. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10371. /// 00ca <result>.B
  10372. /// result:
  10373. /// 0 = "The deal has successfully completed."
  10374. /// 1 = "You do not have enough zeny."
  10375. /// 2 = "You are over your Weight Limit."
  10376. /// 3 = "Out of the maximum capacity, you have too many items."
  10377. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10378. /// 10 = "Props open-air store sales will be traded in RODEX"
  10379. /// 11 = "The exchange failed."
  10380. /// 12 = "The exchange was well done."
  10381. /// 13 = "The item is already sold and out of stock."
  10382. /// 14 = "There is not enough goods to exchange."
  10383. void clif_npc_buy_result( map_session_data* sd, e_purchase_result result ){
  10384. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10385. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10386. p.result = (uint8)result;
  10387. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10388. }
  10389. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10390. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10391. void clif_parse_NpcBuyListSend( int fd, map_session_data* sd ){
  10392. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10393. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10394. e_purchase_result result;
  10395. if( sd->state.trading || !sd->npc_shopid )
  10396. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10397. else{
  10398. std::vector<s_npc_buy_list> items = {};
  10399. items.reserve( n );
  10400. for( uint16 i = 0; i < n; i++ ){
  10401. s_npc_buy_list item = {};
  10402. item.nameid = p->items[i].itemId;
  10403. item.qty = p->items[i].amount;
  10404. items.push_back( item );
  10405. }
  10406. result = npc_buylist( sd, items );
  10407. }
  10408. sd->npc_shopid = 0; //Clear shop data.
  10409. clif_npc_buy_result(sd, result);
  10410. }
  10411. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10412. /// 00cb <result>.B
  10413. /// result:
  10414. /// 0 = "The deal has successfully completed."
  10415. /// 1 = "The deal has failed."
  10416. void clif_npc_sell_result(map_session_data* sd, unsigned char result)
  10417. {
  10418. int fd = sd->fd;
  10419. WFIFOHEAD(fd,packet_len(0xcb));
  10420. WFIFOW(fd,0) = 0xcb;
  10421. WFIFOB(fd,2) = result;
  10422. WFIFOSET(fd,packet_len(0xcb));
  10423. }
  10424. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10425. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10426. void clif_parse_NpcSellListSend(int fd,map_session_data *sd)
  10427. {
  10428. int fail=0,n;
  10429. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10430. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10431. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10432. if (sd->state.trading || !sd->npc_shopid)
  10433. fail = 1;
  10434. else
  10435. fail = npc_selllist(sd, n, p->sellList);
  10436. sd->npc_shopid = 0; //Clear shop data.
  10437. clif_npc_sell_result(sd, fail);
  10438. }
  10439. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10440. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10441. /// type:
  10442. /// 0 = private
  10443. /// 1 = public
  10444. void clif_parse_CreateChatRoom(int fd, map_session_data* sd)
  10445. {
  10446. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10447. int len = RFIFOW(fd,info->pos[0])-15;
  10448. int limit = RFIFOW(fd,info->pos[1]);
  10449. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10450. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10451. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10452. char s_password[CHATROOM_PASS_SIZE];
  10453. char s_title[CHATROOM_TITLE_SIZE];
  10454. if (sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM)
  10455. return;
  10456. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10457. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10458. return;
  10459. }
  10460. if( npc_isnear(&sd->bl) ) {
  10461. // uncomment to send msg_txt.
  10462. //char output[150];
  10463. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10464. //clif_displaymessage(sd->fd, output);
  10465. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10466. return;
  10467. }
  10468. if( len <= 0 )
  10469. return; // invalid input
  10470. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10471. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10472. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10473. }
  10474. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10475. /// 00d9 <chat ID>.L <passwd>.8B
  10476. void clif_parse_ChatAddMember(int fd, map_session_data* sd){
  10477. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10478. int chatid = RFIFOL(fd,info->pos[0]);
  10479. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10480. chat_joinchat(sd,chatid,password);
  10481. }
  10482. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10483. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10484. /// type:
  10485. /// 0 = private
  10486. /// 1 = public
  10487. void clif_parse_ChatRoomStatusChange(int fd, map_session_data* sd){
  10488. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10489. int len = RFIFOW(fd,info->pos[0])-15;
  10490. int limit = RFIFOW(fd,info->pos[1]);
  10491. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10492. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10493. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10494. char s_password[CHATROOM_PASS_SIZE];
  10495. char s_title[CHATROOM_TITLE_SIZE];
  10496. if( len <= 0 )
  10497. return; // invalid input
  10498. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10499. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10500. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10501. }
  10502. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10503. /// 00e0 <role>.L <nick>.24B
  10504. /// role:
  10505. /// 0 = owner
  10506. /// 1 = normal
  10507. void clif_parse_ChangeChatOwner(int fd, map_session_data* sd)
  10508. {
  10509. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10510. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10511. }
  10512. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10513. /// 00e2 <name>.24B
  10514. void clif_parse_KickFromChat(int fd,map_session_data *sd)
  10515. {
  10516. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10517. }
  10518. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10519. /// 00e3
  10520. void clif_parse_ChatLeave(int fd, map_session_data* sd)
  10521. {
  10522. chat_leavechat(sd,0);
  10523. }
  10524. //Handles notifying asker and rejecter of what has just ocurred.
  10525. //Type is used to determine the correct msg_txt to use:
  10526. //0:
  10527. static void clif_noask_sub(map_session_data *sd, map_session_data *tsd, int type)
  10528. {
  10529. const char* msg;
  10530. char output[256];
  10531. // Your request has been rejected by autoreject option.
  10532. msg = msg_txt(sd,392);
  10533. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10534. //Notice that a request was rejected.
  10535. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10536. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10537. }
  10538. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10539. /// 00e4 <account id>.L
  10540. void clif_parse_TradeRequest(int fd,map_session_data *sd)
  10541. {
  10542. map_session_data *t_sd;
  10543. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10544. if(!sd->chatID && pc_cant_act(sd))
  10545. return; //You can trade while in a chatroom.
  10546. if(t_sd){
  10547. // @noask [LuzZza]
  10548. if(t_sd->state.noask) {
  10549. clif_noask_sub(sd, t_sd, 0);
  10550. return;
  10551. }
  10552. if (t_sd->state.mail_writing) {
  10553. int old = sd->trade_partner;
  10554. // Fake trading
  10555. sd->trade_partner = t_sd->status.account_id;
  10556. clif_tradestart(sd, 5);
  10557. // Restore old state
  10558. sd->trade_partner = old;
  10559. return;
  10560. }
  10561. }
  10562. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10563. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10564. return;
  10565. }
  10566. trade_traderequest(sd,t_sd);
  10567. }
  10568. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10569. /// 00e6 <result>.B
  10570. /// result:
  10571. /// 3 = accepted
  10572. /// 4 = rejected
  10573. void clif_parse_TradeAck(int fd,map_session_data *sd)
  10574. {
  10575. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10576. }
  10577. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10578. /// 00e8 <index>.W <amount>.L
  10579. void clif_parse_TradeAddItem(int fd,map_session_data *sd)
  10580. {
  10581. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10582. short index = RFIFOW(fd,info->pos[0]);
  10583. int amount = RFIFOL(fd,info->pos[1]);
  10584. if( index == 0 )
  10585. trade_tradeaddzeny(sd, amount);
  10586. else
  10587. trade_tradeadditem(sd, server_index(index), (short)amount);
  10588. }
  10589. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10590. /// 00eb
  10591. void clif_parse_TradeOk(int fd,map_session_data *sd)
  10592. {
  10593. trade_tradeok(sd);
  10594. }
  10595. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10596. /// 00ed
  10597. void clif_parse_TradeCancel(int fd,map_session_data *sd)
  10598. {
  10599. trade_tradecancel(sd);
  10600. }
  10601. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10602. /// 00ef
  10603. void clif_parse_TradeCommit(int fd,map_session_data *sd)
  10604. {
  10605. trade_tradecommit(sd);
  10606. }
  10607. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10608. /// 0118
  10609. void clif_parse_StopAttack(int fd,map_session_data *sd)
  10610. {
  10611. pc_stop_attack(sd);
  10612. if (sd) sd->ud.state.attack_continue = 0;
  10613. }
  10614. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10615. /// 0126 <index>.W <amount>.L
  10616. void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
  10617. if (pc_istrading(sd) || !pc_iscarton(sd) || pc_cant_act2(sd))
  10618. return;
  10619. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10620. return;
  10621. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10622. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10623. }
  10624. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10625. /// 0127 <index>.W <amount>.L
  10626. void clif_parse_GetItemFromCart(int fd,map_session_data *sd)
  10627. {
  10628. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10629. if (!pc_iscarton(sd) || pc_cant_act2(sd))
  10630. return;
  10631. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10632. return;
  10633. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10634. }
  10635. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10636. /// 012a
  10637. void clif_parse_RemoveOption(int fd,map_session_data *sd)
  10638. {
  10639. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10640. #ifdef NEW_CARTS
  10641. && sd->sc.getSCE(SC_PUSH_CART) )
  10642. pc_setcart(sd,0);
  10643. #else
  10644. )
  10645. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10646. #endif
  10647. else // priority to remove this option before we can clear cart
  10648. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10649. }
  10650. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10651. /// 097f <Length>.W <identity>.L <type>.B
  10652. void clif_SelectCart(map_session_data *sd) {
  10653. #if PACKETVER >= 20150826
  10654. int i = 0, carts = 3;
  10655. int fd = sd->fd;
  10656. WFIFOHEAD(fd,8 + carts);
  10657. WFIFOW(fd,0) = 0x97f;
  10658. WFIFOW(fd,2) = 8 + carts;
  10659. WFIFOL(fd,4) = sd->status.account_id;
  10660. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10661. for( i = 0; i < carts; i++ ) {
  10662. WFIFOB(fd,8 + i) = 10 + i;
  10663. }
  10664. WFIFOSET(fd,8 + carts);
  10665. #endif
  10666. }
  10667. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10668. /// 0980 <identity>.L <type>.B
  10669. void clif_parse_SelectCart(int fd,map_session_data *sd) {
  10670. #if PACKETVER >= 20150826
  10671. int type;
  10672. // Check identity
  10673. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10674. return;
  10675. type = (int)RFIFOB(fd,6);
  10676. // Check type
  10677. if( type < 10 || type > 12 )
  10678. return;
  10679. pc_setcart(sd, type);
  10680. #endif
  10681. }
  10682. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10683. /// 01af <num>.W
  10684. void clif_parse_ChangeCart(int fd,map_session_data *sd)
  10685. {// TODO: State tracking?
  10686. int type;
  10687. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10688. return;
  10689. #ifdef RENEWAL
  10690. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10691. clif_msg(sd, WORK_IN_PROGRESS);
  10692. return;
  10693. }
  10694. #endif
  10695. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10696. if(
  10697. #ifdef NEW_CARTS
  10698. #if PACKETVER >= 20191106
  10699. (type == 13 && sd->status.base_level > 100) ||
  10700. #endif
  10701. (type == 9 && sd->status.base_level > 130) ||
  10702. (type == 8 && sd->status.base_level > 120) ||
  10703. (type == 7 && sd->status.base_level > 110) ||
  10704. (type == 6 && sd->status.base_level > 100) ||
  10705. #endif
  10706. (type == 5 && sd->status.base_level > 90) ||
  10707. (type == 4 && sd->status.base_level > 80) ||
  10708. (type == 3 && sd->status.base_level > 65) ||
  10709. (type == 2 && sd->status.base_level > 40) ||
  10710. (type == 1))
  10711. pc_setcart(sd, type);
  10712. }
  10713. /// Request to increase status (CZ_STATUS_CHANGE).
  10714. /// 00bb <status id>.W <amount>.B
  10715. /// status id:
  10716. /// SP_STR ~ SP_LUK
  10717. /// amount:
  10718. /// Old clients always send 1 for this, even when using /str+ and the like.
  10719. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10720. void clif_parse_StatusUp(int fd,map_session_data *sd)
  10721. {
  10722. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10723. if( increase_amount < 0 ) {
  10724. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10725. fd, increase_amount);
  10726. }
  10727. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10728. }
  10729. /// Request to increase trait status.
  10730. /// 0b24 <status id>.W <amount>.W
  10731. /// status id:
  10732. /// SP_POW ~ SP_CON
  10733. /// amount:
  10734. /// The amount to increase the trait status
  10735. void clif_parse_traitstatus_up( int fd, map_session_data *sd ){
  10736. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10737. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10738. if( p->amount < 0 ){
  10739. 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 );
  10740. return;
  10741. }
  10742. pc_traitstatusup( sd, p->type, p->amount );
  10743. #endif
  10744. }
  10745. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10746. /// 0112 <skill id>.W
  10747. void clif_parse_SkillUp(int fd,map_session_data *sd)
  10748. {
  10749. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10750. }
  10751. 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)
  10752. {
  10753. int lv;
  10754. if( !hd )
  10755. return;
  10756. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10757. clif_emotion(&hd->bl, ET_THINK);
  10758. return;
  10759. }
  10760. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10761. target_id = hd->bl.id;
  10762. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10763. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10764. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10765. clif_emotion(&hd->bl, ET_THINK);
  10766. if (hd->master)
  10767. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10768. return;
  10769. }
  10770. lv = hom_checkskill(hd, skill_id);
  10771. if( skill_lv > lv )
  10772. skill_lv = lv;
  10773. if( skill_lv )
  10774. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10775. }
  10776. 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)
  10777. {
  10778. int lv;
  10779. if( !hd )
  10780. return;
  10781. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10782. clif_emotion(&hd->bl, ET_THINK);
  10783. return;
  10784. }
  10785. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10786. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10787. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10788. clif_emotion(&hd->bl, ET_THINK);
  10789. if (hd->master)
  10790. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10791. return;
  10792. }
  10793. #ifdef RENEWAL
  10794. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10795. #else
  10796. if (hd->sc.getSCE(SC_BASILICA))
  10797. #endif
  10798. return;
  10799. lv = hom_checkskill(hd, skill_id);
  10800. if( skill_lv > lv )
  10801. skill_lv = lv;
  10802. if( skill_lv )
  10803. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10804. }
  10805. 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)
  10806. {
  10807. int lv;
  10808. if( !md )
  10809. return;
  10810. if( skill_isNotOk_mercenary(skill_id, md) )
  10811. return;
  10812. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10813. target_id = md->bl.id;
  10814. if( md->ud.skilltimer != INVALID_TIMER )
  10815. {
  10816. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10817. }
  10818. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10819. return;
  10820. lv = mercenary_checkskill(md, skill_id);
  10821. if( skill_lv > lv )
  10822. skill_lv = lv;
  10823. if( skill_lv )
  10824. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10825. }
  10826. 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)
  10827. {
  10828. int lv;
  10829. if( !md )
  10830. return;
  10831. if( skill_isNotOk_mercenary(skill_id, md) )
  10832. return;
  10833. if( md->ud.skilltimer != INVALID_TIMER )
  10834. return;
  10835. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10836. {
  10837. if (md->master)
  10838. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10839. return;
  10840. }
  10841. #ifdef RENEWAL
  10842. if (md->sc.getSCE(SC_BASILICA_CELL))
  10843. #else
  10844. if (md->sc.getSCE(SC_BASILICA))
  10845. #endif
  10846. return;
  10847. lv = mercenary_checkskill(md, skill_id);
  10848. if( skill_lv > lv )
  10849. skill_lv = lv;
  10850. if( skill_lv )
  10851. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10852. }
  10853. void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10854. t_tick tick = gettick();
  10855. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10856. int inf = skill_get_inf(skill_id);
  10857. if (inf&INF_GROUND_SKILL || !inf)
  10858. return; //Using a ground/passive skill on a target? WRONG.
  10859. if (sd->state.block_action & PCBLOCK_SKILL) {
  10860. clif_msg(sd, WORK_IN_PROGRESS);
  10861. return;
  10862. }
  10863. if( SKILL_CHK_HOMUN(skill_id) ) {
  10864. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10865. return;
  10866. }
  10867. if( SKILL_CHK_MERC(skill_id) ) {
  10868. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10869. return;
  10870. }
  10871. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10872. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10873. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10874. sd->idletime = last_tick;
  10875. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10876. sd->idletime_hom = last_tick;
  10877. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10878. sd->idletime_mer = last_tick;
  10879. if( sd->npc_id ){
  10880. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10881. #ifdef RENEWAL
  10882. clif_msg( sd, WORK_IN_PROGRESS );
  10883. #endif
  10884. return;
  10885. }
  10886. }
  10887. if ((pc_cant_act2(sd) || sd->chatID) &&
  10888. skill_id != RK_REFRESH &&
  10889. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10890. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10891. return;
  10892. if( pc_issit(sd) )
  10893. return;
  10894. if( skill_isNotOk(skill_id, sd) )
  10895. return;
  10896. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10897. target_id = sd->bl.id; // never trust the client
  10898. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10899. target_id = sd->bl.id;
  10900. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10901. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10902. return;
  10903. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10904. if( sd->skillitem != skill_id ) {
  10905. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10906. return;
  10907. }
  10908. }
  10909. if( sd->sc.option&OPTION_COSTUME )
  10910. return;
  10911. #ifndef RENEWAL
  10912. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10913. return; // On basilica only caster can use Basilica again to stop it.
  10914. #endif
  10915. if( sd->menuskill_id ) {
  10916. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10917. clif_menuskill_clear(sd); //Cancel pet capture.
  10918. }else if( sd->menuskill_id == SG_FEEL ){
  10919. clif_menuskill_clear( sd ); // Cancel selection
  10920. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10921. return; //Can't use skills while a menu is open.
  10922. }
  10923. if( sd->skillitem == skill_id ) {
  10924. if( skill_lv != sd->skillitemlv )
  10925. skill_lv = sd->skillitemlv;
  10926. if( !(inf&INF_SELF_SKILL) )
  10927. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10928. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10929. return;
  10930. }
  10931. sd->skillitem = sd->skillitemlv = 0;
  10932. if( SKILL_CHK_GUILD(skill_id) ) {
  10933. if (sd->guild && sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING)
  10934. skill_lv = guild_checkskill(sd->guild->guild, skill_id);
  10935. else
  10936. skill_lv = 0;
  10937. } else {
  10938. if( skill_id != ALL_EQSWITCH ){
  10939. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10940. }
  10941. }
  10942. pc_delinvincibletimer(sd);
  10943. if( skill_lv )
  10944. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10945. }
  10946. /// Request to use a targeted skill.
  10947. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10948. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10949. /// There are various variants of this packet, some of them have padding between fields.
  10950. void clif_parse_UseSkillToId( int fd, map_session_data *sd ){
  10951. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10952. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10953. }
  10954. /*==========================================
  10955. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10956. *------------------------------------------*/
  10957. static void clif_parse_UseSkillToPosSub(int fd, map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10958. {
  10959. t_tick tick = gettick();
  10960. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10961. return; //Using a target skill on the ground? WRONG.
  10962. if (sd->state.block_action & PCBLOCK_SKILL) {
  10963. clif_msg(sd, WORK_IN_PROGRESS);
  10964. return;
  10965. }
  10966. if( SKILL_CHK_HOMUN(skill_id) ) {
  10967. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10968. return;
  10969. }
  10970. if( SKILL_CHK_MERC(skill_id) ) {
  10971. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10972. return;
  10973. }
  10974. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10975. #ifdef RENEWAL
  10976. clif_msg( sd, WORK_IN_PROGRESS );
  10977. #endif
  10978. return;
  10979. }
  10980. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10981. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10982. sd->idletime = last_tick;
  10983. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10984. sd->idletime_hom = last_tick;
  10985. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10986. sd->idletime_mer = last_tick;
  10987. if( skill_isNotOk(skill_id, sd) )
  10988. return;
  10989. if( skillmoreinfo != -1 ) {
  10990. if( pc_issit(sd) ) {
  10991. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10992. return;
  10993. }
  10994. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10995. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10996. }
  10997. if( sd->ud.skilltimer != INVALID_TIMER )
  10998. return;
  10999. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  11000. if( sd->skillitem != skill_id ) {
  11001. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  11002. return;
  11003. }
  11004. }
  11005. if( sd->sc.option&OPTION_COSTUME )
  11006. return;
  11007. #ifndef RENEWAL
  11008. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  11009. return; // On basilica only caster can use Basilica again to stop it.
  11010. #endif
  11011. if( sd->menuskill_id ) {
  11012. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  11013. clif_menuskill_clear(sd); //Cancel pet capture.
  11014. }else if( sd->menuskill_id == SG_FEEL ){
  11015. clif_menuskill_clear( sd ); // Cancel selection
  11016. } else if( sd->menuskill_id != SA_AUTOSPELL )
  11017. return; //Can't use skills while a menu is open.
  11018. }
  11019. pc_delinvincibletimer(sd);
  11020. if( sd->skillitem == skill_id ) {
  11021. if( skill_lv != sd->skillitemlv )
  11022. skill_lv = sd->skillitemlv;
  11023. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  11024. } else {
  11025. int lv;
  11026. sd->skillitem = sd->skillitemlv = 0;
  11027. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  11028. if( skill_lv > lv )
  11029. skill_lv = lv;
  11030. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  11031. }
  11032. }
  11033. }
  11034. /// Request to use a ground skill.
  11035. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  11036. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  11037. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  11038. /// There are various variants of this packet, some of them have padding between fields.
  11039. void clif_parse_UseSkillToPos(int fd, map_session_data *sd)
  11040. {
  11041. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11042. if (pc_cant_act(sd))
  11043. return;
  11044. if (pc_issit(sd))
  11045. return;
  11046. clif_parse_UseSkillToPosSub(fd, sd,
  11047. RFIFOW(fd,info->pos[0]), //skill lv
  11048. RFIFOW(fd,info->pos[1]), //skill num
  11049. RFIFOW(fd,info->pos[2]), //pos x
  11050. RFIFOW(fd,info->pos[3]), //pos y
  11051. // TODO: find out what this is intended to do
  11052. //RFIFOB(fd, info->pos[4])
  11053. -1 //Skill more info.
  11054. );
  11055. }
  11056. /// Request to use a ground skill with text.
  11057. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  11058. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  11059. /// There are various variants of this packet, some of them have padding between fields.
  11060. void clif_parse_UseSkillToPosMoreInfo(int fd, map_session_data *sd)
  11061. {
  11062. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11063. if (pc_cant_act(sd))
  11064. return;
  11065. if (pc_issit(sd))
  11066. return;
  11067. clif_parse_UseSkillToPosSub(fd, sd,
  11068. RFIFOW(fd,info->pos[0]), //Skill lv
  11069. RFIFOW(fd,info->pos[1]), //Skill num
  11070. RFIFOW(fd,info->pos[2]), //pos x
  11071. RFIFOW(fd,info->pos[3]), //pos y
  11072. info->pos[4] //skill more info
  11073. );
  11074. }
  11075. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  11076. /// 011b <skill id>.W <map name>.16B
  11077. void clif_parse_UseSkillMap(int fd, map_session_data* sd)
  11078. {
  11079. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11080. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11081. char map_name[MAP_NAME_LENGTH];
  11082. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11083. sd->state.workinprogress = WIP_DISABLE_NONE;
  11084. if(skill_id != sd->menuskill_id)
  11085. return;
  11086. //It is possible to use teleport with the storage window open bugreport:8027
  11087. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11088. clif_menuskill_clear(sd);
  11089. return;
  11090. }
  11091. pc_delinvincibletimer(sd);
  11092. skill_castend_map(sd,skill_id,map_name);
  11093. }
  11094. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11095. /// 011d
  11096. void clif_parse_RequestMemo(int fd,map_session_data *sd)
  11097. {
  11098. if (!pc_isdead(sd))
  11099. pc_memo(sd,-1);
  11100. }
  11101. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11102. /// 018e <name id>.W { <material id>.W }*3
  11103. void clif_parse_ProduceMix(int fd,map_session_data *sd){
  11104. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11105. switch( sd->menuskill_id ) {
  11106. case -1:
  11107. case AM_PHARMACY:
  11108. case RK_RUNEMASTERY:
  11109. case GC_RESEARCHNEWPOISON:
  11110. break;
  11111. default:
  11112. return;
  11113. }
  11114. if (pc_istrading(sd)) {
  11115. //Make it fail to avoid shop exploits where you sell something different than you see.
  11116. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11117. clif_menuskill_clear(sd);
  11118. return;
  11119. }
  11120. int produce_idx;
  11121. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11122. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11123. clif_menuskill_clear(sd);
  11124. }
  11125. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11126. /// 025b <mk type>.W <name id>.W
  11127. /// mk type:
  11128. /// 1 = cooking
  11129. /// 2 = arrow
  11130. /// 3 = elemental
  11131. /// 4 = GN_MIX_COOKING
  11132. /// 5 = GN_MAKEBOMB
  11133. /// 6 = GN_S_PHARMACY
  11134. /// 7 = MT_M_MACHINE - Unconfirmed
  11135. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11136. void clif_parse_Cooking(int fd,map_session_data *sd) {
  11137. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11138. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11139. short food_idx = -1;
  11140. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11141. return;
  11142. if (pc_istrading(sd)) {
  11143. //Make it fail to avoid shop exploits where you sell something different than you see.
  11144. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11145. clif_menuskill_clear(sd);
  11146. return;
  11147. }
  11148. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11149. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11150. clif_menuskill_clear(sd);
  11151. }
  11152. /// Answer to repair weapon item selection dialog
  11153. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11154. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11155. void clif_parse_RepairItem( int fd, map_session_data *sd ){
  11156. // Hercules has wrong date -> use correct one here
  11157. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11158. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11159. #else
  11160. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11161. #endif
  11162. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11163. return;
  11164. if (pc_istrading(sd)) {
  11165. //Make it fail to avoid shop exploits where you sell something different than you see.
  11166. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11167. clif_menuskill_clear(sd);
  11168. return;
  11169. }
  11170. skill_repairweapon( sd, p->item.index );
  11171. clif_menuskill_clear(sd);
  11172. }
  11173. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11174. /// 0222 <index>.L
  11175. void clif_parse_WeaponRefine( int fd, map_session_data *sd ){
  11176. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11177. return;
  11178. if (pc_istrading(sd)) {
  11179. //Make it fail to avoid shop exploits where you sell something different than you see.
  11180. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11181. clif_menuskill_clear(sd);
  11182. return;
  11183. }
  11184. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11185. clif_menuskill_clear(sd);
  11186. }
  11187. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11188. /// 00b8 <npc id>.L <choice>.B
  11189. /// choice:
  11190. /// 1~254 = menu item
  11191. /// 255 = cancel
  11192. /// NOTE: If there were more than 254 items in the list, choice
  11193. /// overflows to choice%256.
  11194. void clif_parse_NpcSelectMenu(int fd,map_session_data *sd){
  11195. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11196. int npc_id = RFIFOL(fd,info->pos[0]);
  11197. uint8 select = RFIFOB(fd,info->pos[1]);
  11198. #ifdef SECURE_NPCTIMEOUT
  11199. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11200. return;
  11201. #endif
  11202. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11203. TBL_NPC* nd = map_id2nd(npc_id);
  11204. 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);
  11205. clif_GM_kick(NULL,sd);
  11206. return;
  11207. }
  11208. sd->npc_menu = select;
  11209. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11210. sd->idletime = last_tick;
  11211. }
  11212. npc_scriptcont(sd,npc_id, false);
  11213. }
  11214. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11215. /// 00b9 <npc id>.L
  11216. void clif_parse_NpcNextClicked(int fd,map_session_data *sd)
  11217. {
  11218. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11219. sd->idletime = last_tick;
  11220. }
  11221. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11222. }
  11223. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11224. /// 0143 <npc id>.L <value>.L
  11225. void clif_parse_NpcAmountInput(int fd,map_session_data *sd){
  11226. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11227. int npcid = RFIFOL(fd,info->pos[0]);
  11228. int amount = (int)RFIFOL(fd,info->pos[1]);
  11229. sd->npc_amount = amount;
  11230. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11231. sd->idletime = last_tick;
  11232. }
  11233. npc_scriptcont(sd, npcid, false);
  11234. }
  11235. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11236. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11237. void clif_parse_NpcStringInput(int fd, map_session_data* sd){
  11238. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11239. int message_len = RFIFOW(fd,info->pos[0])-8;
  11240. int npcid = RFIFOL(fd,info->pos[1]);
  11241. const char* message = RFIFOCP(fd,info->pos[2]);
  11242. if( message_len <= 0 )
  11243. return; // invalid input
  11244. #if PACKETVER >= 20151001
  11245. message_len++;
  11246. #endif
  11247. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11248. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11249. sd->idletime = last_tick;
  11250. }
  11251. npc_scriptcont(sd, npcid, false);
  11252. }
  11253. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11254. /// 0146 <npc id>.L
  11255. void clif_parse_NpcCloseClicked(int fd,map_session_data *sd)
  11256. {
  11257. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11258. return;
  11259. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11260. sd->idletime = last_tick;
  11261. }
  11262. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11263. }
  11264. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11265. /// 0178 <index>.W
  11266. /// index:
  11267. /// -1 = cancel
  11268. void clif_parse_ItemIdentify(int fd,map_session_data *sd) {
  11269. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11270. if (sd->menuskill_id != MC_IDENTIFY)
  11271. return;
  11272. // Ignore the request
  11273. // - Invalid item index
  11274. // - Invalid item ID or item doesn't exist
  11275. // - Item is already identified
  11276. if (idx < 0 || idx >= MAX_INVENTORY ||
  11277. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11278. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11279. sd->state.workinprogress = WIP_DISABLE_NONE;
  11280. clif_menuskill_clear(sd);
  11281. return;
  11282. }
  11283. skill_identify(sd, idx);
  11284. clif_menuskill_clear(sd);
  11285. }
  11286. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11287. /// 01ae <name id>.W
  11288. void clif_parse_SelectArrow(int fd,map_session_data *sd) {
  11289. if (pc_istrading(sd)) {
  11290. //Make it fail to avoid shop exploits where you sell something different than you see.
  11291. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11292. clif_menuskill_clear(sd);
  11293. return;
  11294. }
  11295. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11296. switch (sd->menuskill_id) {
  11297. case AC_MAKINGARROW:
  11298. skill_arrow_create(sd,p->itemId);
  11299. break;
  11300. case SA_CREATECON:
  11301. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11302. break;
  11303. case GC_POISONINGWEAPON:
  11304. skill_poisoningweapon(sd,p->itemId);
  11305. break;
  11306. case NC_MAGICDECOY:
  11307. skill_magicdecoy(sd,p->itemId);
  11308. break;
  11309. }
  11310. clif_menuskill_clear(sd);
  11311. }
  11312. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11313. /// 01ce <skill id>.L
  11314. void clif_parse_AutoSpell(int fd,map_session_data *sd)
  11315. {
  11316. if (sd->menuskill_id != SA_AUTOSPELL)
  11317. return;
  11318. sd->state.workinprogress = WIP_DISABLE_NONE;
  11319. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11320. clif_menuskill_clear(sd);
  11321. }
  11322. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11323. /// 017a <card index>.W
  11324. void clif_parse_UseCard(int fd,map_session_data *sd)
  11325. {
  11326. if (sd->state.trading != 0)
  11327. return;
  11328. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11329. }
  11330. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11331. /// 017c <card index>.W <equip index>.W
  11332. void clif_parse_InsertCard(int fd,map_session_data *sd)
  11333. {
  11334. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11335. if (sd->state.trading != 0)
  11336. return;
  11337. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11338. }
  11339. /// Request of character's name by char ID.
  11340. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11341. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11342. /// There are various variants of this packet, some of them have padding between fields.
  11343. void clif_parse_SolveCharName(int fd, map_session_data *sd)
  11344. {
  11345. int charid;
  11346. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11347. map_reqnickdb(sd, charid);
  11348. }
  11349. /// /resetskill /resetstate (CZ_RESET).
  11350. /// Request to reset stats or skills.
  11351. /// 0197 <type>.W
  11352. /// type:
  11353. /// 0 = state
  11354. /// 1 = skill
  11355. void clif_parse_ResetChar(int fd, map_session_data *sd) {
  11356. char cmd[15];
  11357. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11358. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11359. else
  11360. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11361. is_atcommand(fd, sd, cmd, 1);
  11362. }
  11363. /// /lb /nlb (CZ_LOCALBROADCAST).
  11364. /// Request to broadcast a message on current map.
  11365. /// 019c <packet len>.W <text>.?B
  11366. void clif_parse_LocalBroadcast(int fd, map_session_data* sd)
  11367. {
  11368. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11369. char command[CHAT_SIZE_MAX+16];
  11370. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11371. char* msg = RFIFOCP(fd,info->pos[1]);
  11372. // as the length varies depending on the command used, just block unreasonably long strings
  11373. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11374. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11375. is_atcommand(fd, sd, command, 1);
  11376. }
  11377. /// Request to move an item from inventory to storage.
  11378. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11379. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11380. /// There are various variants of this packet, some of them have padding between fields.
  11381. void clif_parse_MoveToKafra(int fd, map_session_data *sd)
  11382. {
  11383. int item_index, item_amount;
  11384. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11385. if (pc_istrading(sd))
  11386. return;
  11387. item_index = RFIFOW(fd,info->pos[0])-2;
  11388. item_amount = RFIFOL(fd,info->pos[1]);
  11389. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11390. return;
  11391. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11392. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11393. return;
  11394. }
  11395. if (sd->state.storage_flag == 1)
  11396. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11397. else
  11398. if (sd->state.storage_flag == 2)
  11399. storage_guild_storageadd(sd, item_index, item_amount);
  11400. else if (sd->state.storage_flag == 3)
  11401. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11402. }
  11403. /// Request to move an item from storage to inventory.
  11404. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11405. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11406. /// There are various variants of this packet, some of them have padding between fields.
  11407. void clif_parse_MoveFromKafra(int fd,map_session_data *sd)
  11408. {
  11409. int item_index, item_amount;
  11410. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11411. item_index = RFIFOW(fd,info->pos[0])-1;
  11412. item_amount = RFIFOL(fd,info->pos[1]);
  11413. if (sd->state.storage_flag == 1)
  11414. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11415. else if(sd->state.storage_flag == 2)
  11416. storage_guild_storageget(sd, item_index, item_amount);
  11417. else if(sd->state.storage_flag == 3)
  11418. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11419. }
  11420. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11421. /// 0129 <index>.W <amount>.L
  11422. void clif_parse_MoveToKafraFromCart(int fd, map_session_data *sd){
  11423. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11424. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11425. int amount = RFIFOL(fd,info->pos[1]);
  11426. if( sd->state.vending )
  11427. return;
  11428. if (!pc_iscarton(sd))
  11429. return;
  11430. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11431. return;
  11432. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11433. return;
  11434. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11435. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11436. return;
  11437. }
  11438. if (sd->state.storage_flag == 1)
  11439. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11440. else if (sd->state.storage_flag == 2)
  11441. storage_guild_storageaddfromcart(sd, idx, amount);
  11442. else if (sd->state.storage_flag == 3)
  11443. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11444. }
  11445. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11446. /// 0128 <index>.W <amount>.L
  11447. void clif_parse_MoveFromKafraToCart(int fd, map_session_data *sd){
  11448. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11449. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11450. int amount = RFIFOL(fd,info->pos[1]);
  11451. if( sd->state.vending )
  11452. return;
  11453. if (!pc_iscarton(sd))
  11454. return;
  11455. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11456. return;
  11457. if (sd->state.storage_flag == 1)
  11458. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11459. else
  11460. if (sd->state.storage_flag == 2)
  11461. storage_guild_storagegettocart(sd, idx, amount);
  11462. else if (sd->state.storage_flag == 3)
  11463. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11464. }
  11465. /// Request to close storage (CZ_CLOSE_STORE).
  11466. /// 00f7
  11467. void clif_parse_CloseKafra(int fd, map_session_data *sd)
  11468. {
  11469. if( sd->state.storage_flag == 1 )
  11470. storage_storageclose(sd);
  11471. else
  11472. if( sd->state.storage_flag == 2 )
  11473. storage_guild_storageclose(sd);
  11474. else if( sd->state.storage_flag == 3 )
  11475. storage_premiumStorage_close(sd);
  11476. }
  11477. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11478. /// 023a <info>.W
  11479. /// info:
  11480. /// 0 = password has not been set yet
  11481. /// 1 = storage is password-protected
  11482. /// 8 = too many wrong passwords
  11483. /// ? = ignored
  11484. /// NOTE: This packet is only available on certain non-kRO clients.
  11485. void clif_storagepassword(map_session_data* sd, short info)
  11486. {
  11487. int fd = sd->fd;
  11488. WFIFOHEAD(fd,packet_len(0x23a));
  11489. WFIFOW(fd,0) = 0x23a;
  11490. WFIFOW(fd,2) = info;
  11491. WFIFOSET(fd,packet_len(0x23a));
  11492. }
  11493. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11494. /// 023b <type>.W <password>.16B <new password>.16B
  11495. /// type:
  11496. /// 2 = change password
  11497. /// 3 = check password
  11498. /// NOTE: This packet is only available on certain non-kRO clients.
  11499. void clif_parse_StoragePassword(int fd, map_session_data *sd){ //@TODO
  11500. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11501. // int type = RFIFOW(fd,info->pos[0]);
  11502. // char* password = RFIFOP(fd,info->pos[1]);
  11503. // char* new_password = RFIFOP(fd,info->pos[2]);
  11504. // storage_changepass(sd,password,new_password);
  11505. }
  11506. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11507. /// 023c <result>.W <error count>.W
  11508. /// result:
  11509. /// 4 = password change success
  11510. /// 5 = password change failure
  11511. /// 6 = password check success
  11512. /// 7 = password check failure
  11513. /// 8 = too many wrong passwords
  11514. /// ? = ignored
  11515. /// NOTE: This packet is only available on certain non-kRO clients.
  11516. void clif_storagepassword_result(map_session_data* sd, short result, short error_count)
  11517. {
  11518. int fd = sd->fd;
  11519. WFIFOHEAD(fd,packet_len(0x23c));
  11520. WFIFOW(fd,0) = 0x23c;
  11521. WFIFOW(fd,2) = result;
  11522. WFIFOW(fd,4) = error_count;
  11523. WFIFOSET(fd,packet_len(0x23c));
  11524. }
  11525. /// Party creation request
  11526. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11527. void clif_parse_CreateParty(int fd, map_session_data *sd){
  11528. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11529. name[NAME_LENGTH-1] = '\0';
  11530. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11531. clif_displaymessage(fd, msg_txt(sd,227));
  11532. return;
  11533. }
  11534. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11535. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11536. return;
  11537. }
  11538. party_create(sd,name,0,0);
  11539. }
  11540. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11541. void clif_parse_CreateParty2(int fd, map_session_data *sd){
  11542. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11543. char* name = RFIFOCP(fd,info->pos[0]);
  11544. int item1 = RFIFOB(fd,info->pos[1]);
  11545. int item2 = RFIFOB(fd,info->pos[2]);
  11546. name[NAME_LENGTH-1] = '\0';
  11547. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11548. clif_displaymessage(fd, msg_txt(sd,227));
  11549. return;
  11550. }
  11551. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11552. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11553. return;
  11554. }
  11555. party_create(sd,name,item1,item2);
  11556. }
  11557. /// Party invitation request
  11558. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11559. void clif_parse_PartyInvite(int fd, map_session_data *sd)
  11560. {
  11561. map_session_data *t_sd;
  11562. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11563. clif_displaymessage(fd, msg_txt(sd,227));
  11564. return;
  11565. }
  11566. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11567. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11568. clif_noask_sub(sd, t_sd, 1);
  11569. return;
  11570. }
  11571. party_invite(sd, t_sd);
  11572. }
  11573. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11574. void clif_parse_PartyInvite2(int fd, map_session_data *sd){
  11575. map_session_data *t_sd;
  11576. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11577. name[NAME_LENGTH-1] = '\0';
  11578. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11579. clif_displaymessage(fd, msg_txt(sd,227));
  11580. return;
  11581. }
  11582. t_sd = map_nick2sd(name,false);
  11583. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11584. clif_noask_sub(sd, t_sd, 1);
  11585. return;
  11586. }
  11587. party_invite(sd, t_sd);
  11588. }
  11589. /// Party invitation reply
  11590. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11591. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11592. /// flag:
  11593. /// 0 = reject
  11594. /// 1 = accept
  11595. void clif_parse_ReplyPartyInvite(int fd,map_session_data *sd)
  11596. {
  11597. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11598. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11599. RFIFOL(fd,info->pos[1]));
  11600. }
  11601. //(CZ_PARTY_JOIN_REQ_ACK)
  11602. void clif_parse_ReplyPartyInvite2(int fd,map_session_data *sd)
  11603. {
  11604. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11605. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11606. RFIFOB(fd,info->pos[1]));
  11607. }
  11608. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11609. /// 0100
  11610. void clif_parse_LeaveParty(int fd, map_session_data *sd)
  11611. {
  11612. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11613. clif_displaymessage(fd, msg_txt(sd,227));
  11614. return;
  11615. }
  11616. party_leave(sd);
  11617. }
  11618. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11619. /// 0103 <account id>.L <char name>.24B
  11620. void clif_parse_RemovePartyMember(int fd, map_session_data *sd)
  11621. {
  11622. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11623. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11624. clif_displaymessage(fd, msg_txt(sd,227));
  11625. return;
  11626. }
  11627. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11628. RFIFOCP(fd,info->pos[1]));
  11629. }
  11630. /// Request to change party options.
  11631. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11632. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11633. void clif_parse_PartyChangeOption(int fd, map_session_data *sd)
  11634. {
  11635. struct party_data *p;
  11636. int i,expflag;
  11637. int cmd = RFIFOW(fd,0);
  11638. struct s_packet_db* info = &packet_db[cmd];
  11639. if( !sd->status.party_id )
  11640. return;
  11641. p = party_search(sd->status.party_id);
  11642. if( p == NULL )
  11643. return;
  11644. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11645. if( i == MAX_PARTY )
  11646. return; //Shouldn't happen
  11647. if( !p->party.member[i].leader )
  11648. return;
  11649. expflag = RFIFOL(fd,info->pos[0]);
  11650. if(cmd == 0x0102){ //Client can't change the item-field
  11651. party_changeoption(sd, expflag, p->party.item);
  11652. }
  11653. else {
  11654. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11655. party_changeoption(sd, expflag, itemflag);
  11656. }
  11657. }
  11658. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11659. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11660. void clif_parse_PartyMessage(int fd, map_session_data* sd){
  11661. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11662. // validate packet and retrieve name and message
  11663. if( !clif_process_message( sd, false, name, message, output ) )
  11664. return;
  11665. party_send_message(sd, output, strlen(output) + 1 );
  11666. }
  11667. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11668. /// 07da <account id>.L
  11669. void clif_parse_PartyChangeLeader(int fd, map_session_data* sd){
  11670. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11671. }
  11672. /// Party Booking in KRO [Spiria]
  11673. ///
  11674. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11675. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11676. void clif_parse_PartyBookingRegisterReq(int fd, map_session_data* sd){
  11677. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11678. short level = RFIFOW(fd,info->pos[0]);
  11679. short mapid = RFIFOW(fd,info->pos[1]);
  11680. int idxpbj = info->pos[2];
  11681. short job[MAX_PARTY_BOOKING_JOBS];
  11682. int i;
  11683. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11684. job[i] = RFIFOB(fd,idxpbj+i*2);
  11685. party_booking_register(sd, level, mapid, job);
  11686. }
  11687. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11688. /// 0803 <result>.W
  11689. /// result:
  11690. /// 0 = success
  11691. /// 1 = failure
  11692. /// 2 = already registered
  11693. void clif_PartyBookingRegisterAck(map_session_data *sd, int flag)
  11694. {
  11695. int fd = sd->fd;
  11696. WFIFOHEAD(fd,packet_len(0x803));
  11697. WFIFOW(fd,0) = 0x803;
  11698. WFIFOW(fd,2) = flag;
  11699. WFIFOSET(fd,packet_len(0x803));
  11700. }
  11701. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11702. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11703. void clif_parse_PartyBookingSearchReq(int fd, map_session_data* sd){
  11704. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11705. short level = RFIFOW(fd,info->pos[0]);
  11706. short mapid = RFIFOW(fd,info->pos[1]);
  11707. short job = RFIFOW(fd,info->pos[2]);
  11708. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11709. short resultcount = RFIFOW(fd,info->pos[4]);
  11710. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11711. }
  11712. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11713. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11714. /// more results:
  11715. /// 0 = no
  11716. /// 1 = yes
  11717. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11718. {
  11719. int i, j;
  11720. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11721. struct party_booking_ad_info *pb_ad;
  11722. WFIFOHEAD(fd,size*count + 5);
  11723. WFIFOW(fd,0) = 0x805;
  11724. WFIFOW(fd,2) = size*count + 5;
  11725. WFIFOB(fd,4) = more_result;
  11726. for(i=0; i<count; i++)
  11727. {
  11728. pb_ad = results[i];
  11729. WFIFOL(fd,i*size+5) = pb_ad->index;
  11730. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11731. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11732. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11733. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11734. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11735. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11736. }
  11737. WFIFOSET(fd,WFIFOW(fd,2));
  11738. }
  11739. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11740. /// 0806
  11741. void clif_parse_PartyBookingDeleteReq(int fd, map_session_data* sd)
  11742. {
  11743. if(party_booking_delete(sd))
  11744. clif_PartyBookingDeleteAck(sd, 0);
  11745. }
  11746. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11747. /// 0807 <result>.W
  11748. /// result:
  11749. /// 0 = success
  11750. /// 1 = success (auto-removed expired ad)
  11751. /// 2 = failure
  11752. /// 3 = nothing registered
  11753. void clif_PartyBookingDeleteAck(map_session_data* sd, int flag)
  11754. {
  11755. int fd = sd->fd;
  11756. WFIFOHEAD(fd,packet_len(0x807));
  11757. WFIFOW(fd,0) = 0x807;
  11758. WFIFOW(fd,2) = flag;
  11759. WFIFOSET(fd,packet_len(0x807));
  11760. }
  11761. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11762. /// 0808 { <job>.W }*6
  11763. void clif_parse_PartyBookingUpdateReq(int fd, map_session_data* sd)
  11764. {
  11765. short job[MAX_PARTY_BOOKING_JOBS];
  11766. int i;
  11767. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11768. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11769. job[i] = RFIFOW(fd,idxpbu+i*2);
  11770. party_booking_update(sd, job);
  11771. }
  11772. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11773. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11774. void clif_PartyBookingInsertNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11775. {
  11776. int i;
  11777. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11778. if(pb_ad == NULL) return;
  11779. WBUFW(buf,0) = 0x809;
  11780. WBUFL(buf,2) = pb_ad->index;
  11781. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11782. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11783. WBUFW(buf,34) = pb_ad->p_detail.level;
  11784. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11785. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11786. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11787. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11788. }
  11789. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11790. /// 080a <index>.L { <job>.W }*6
  11791. void clif_PartyBookingUpdateNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11792. {
  11793. int i;
  11794. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11795. if(pb_ad == NULL) return;
  11796. WBUFW(buf,0) = 0x80a;
  11797. WBUFL(buf,2) = pb_ad->index;
  11798. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11799. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11800. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11801. }
  11802. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11803. /// 080b <index>.L
  11804. void clif_PartyBookingDeleteNotify(map_session_data* sd, int index)
  11805. {
  11806. uint8 buf[6];
  11807. WBUFW(buf,0) = 0x80b;
  11808. WBUFL(buf,2) = index;
  11809. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11810. }
  11811. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11812. /// 012e
  11813. void clif_parse_CloseVending(int fd, map_session_data* sd)
  11814. {
  11815. vending_closevending(sd);
  11816. }
  11817. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11818. /// 0130 <account id>.L
  11819. void clif_parse_VendingListReq(int fd, map_session_data* sd)
  11820. {
  11821. if( sd->npc_id ) {// using an NPC
  11822. return;
  11823. }
  11824. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11825. }
  11826. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11827. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11828. void clif_parse_PurchaseReq(int fd, map_session_data* sd){
  11829. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11830. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11831. // whether it fails or not, the buy window is closed
  11832. sd->vended_id = 0;
  11833. }
  11834. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11835. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11836. void clif_parse_PurchaseReq2(int fd, map_session_data* sd){
  11837. #if PACKETVER >= 20100105
  11838. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11839. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11840. // whether it fails or not, the buy window is closed
  11841. sd->vended_id = 0;
  11842. #endif
  11843. }
  11844. /// Confirm or cancel the shop preparation window.
  11845. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11846. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11847. /// result:
  11848. /// 0 = canceled
  11849. /// 1 = open
  11850. void clif_parse_OpenVending(int fd, map_session_data* sd){
  11851. int cmd = RFIFOW(fd,0);
  11852. struct s_packet_db* info = &packet_db[cmd];
  11853. short len = (short)RFIFOW(fd,info->pos[0]);
  11854. const char* message = RFIFOCP(fd,info->pos[1]);
  11855. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11856. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11857. len -= 84;
  11858. }
  11859. else { //(CZ_REQ_OPENSTORE2)
  11860. bool flag;
  11861. len -= 85;
  11862. flag = RFIFOB(fd,info->pos[2]) != 0;
  11863. if (!flag) {
  11864. sd->state.prevend = 0;
  11865. sd->state.workinprogress = WIP_DISABLE_NONE;
  11866. }
  11867. }
  11868. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11869. return;
  11870. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11871. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11872. return;
  11873. }
  11874. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11875. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11876. return;
  11877. }
  11878. if( message[0] == '\0' ) // invalid input
  11879. return;
  11880. vending_openvending(sd, message, data, len/8, NULL);
  11881. }
  11882. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11883. /// 0165 <char id>.L <guild name>.24B
  11884. void clif_parse_CreateGuild(int fd,map_session_data *sd){
  11885. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11886. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11887. name[NAME_LENGTH-1] = '\0';
  11888. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11889. clif_displaymessage(fd, msg_txt(sd,228));
  11890. return;
  11891. }
  11892. if(sd->clan){
  11893. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11894. return;
  11895. }
  11896. guild_create(sd, name);
  11897. }
  11898. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11899. /// 014d
  11900. void clif_parse_GuildCheckMaster(int fd, map_session_data *sd)
  11901. {
  11902. clif_guild_masterormember(sd);
  11903. }
  11904. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11905. /// 014f <type>.L
  11906. /// type:
  11907. /// 0 = basic info
  11908. /// 1 = member manager
  11909. /// 2 = positions
  11910. /// 3 = skills
  11911. /// 4 = expulsion list
  11912. /// 5 = unknown (GM_ALLGUILDLIST)
  11913. /// 6 = notice
  11914. void clif_parse_GuildRequestInfo(int fd, map_session_data *sd)
  11915. {
  11916. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11917. if( !sd->status.guild_id && !sd->bg_id )
  11918. return;
  11919. switch( type )
  11920. {
  11921. case 0: // Basic Information Guild, hostile alliance information
  11922. clif_guild_basicinfo( *sd );
  11923. clif_guild_allianceinfo(sd);
  11924. clif_guild_castle_list(*sd);
  11925. break;
  11926. case 1: // Members list, list job title
  11927. clif_guild_positionnamelist(sd);
  11928. clif_guild_memberlist( *sd );
  11929. break;
  11930. case 2: // List job title, title information list
  11931. clif_guild_positionnamelist(sd);
  11932. clif_guild_positioninfolist(sd);
  11933. break;
  11934. case 3: // Skill list
  11935. clif_guild_skillinfo(sd);
  11936. break;
  11937. case 4: // Expulsion list
  11938. clif_guild_expulsionlist(sd);
  11939. break;
  11940. default:
  11941. ShowError("clif: guild request info: unknown type %d\n", type);
  11942. break;
  11943. }
  11944. }
  11945. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11946. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11947. void clif_parse_GuildChangePositionInfo(int fd, map_session_data *sd)
  11948. {
  11949. int i;
  11950. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11951. int len = RFIFOW(fd,info->pos[0]);
  11952. int idxgpos = info->pos[1];
  11953. if(!sd->state.gmaster_flag)
  11954. return;
  11955. for(i = idxgpos; i < len; i += 40 ){
  11956. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11957. }
  11958. }
  11959. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11960. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11961. void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){
  11962. if(!sd->state.gmaster_flag)
  11963. return;
  11964. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11965. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11966. for( int16 i = 0; i < entries; i++ ){
  11967. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11968. // Guild leadership change
  11969. if( entry.position == 0 ){
  11970. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11971. clif_msg( sd, GUILD_MASTER_WOE );
  11972. return;
  11973. }
  11974. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->guild.last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11975. clif_msg( sd, GUILD_MASTER_DELAY );
  11976. return;
  11977. }
  11978. guild_gm_change( sd->status.guild_id, entry.CID );
  11979. // No further entries will be processed - the requesting player lost his guild master status
  11980. return;
  11981. }else if( entry.position > 0 ){
  11982. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11983. }
  11984. }
  11985. }
  11986. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11987. /// 0151 <guild id>.L
  11988. void clif_parse_GuildRequestEmblem(int fd,map_session_data *sd)
  11989. {
  11990. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11991. auto g = guild_search(guild_id);
  11992. if (g)
  11993. clif_guild_emblem(*sd, g->guild);
  11994. }
  11995. /// Validates data of a guild emblem (compressed bitmap)
  11996. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11997. EMBVALIDATE_SUCCESS = 0,
  11998. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11999. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  12000. };
  12001. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  12002. {
  12003. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  12004. unsigned long buf_len = sizeof(buf);
  12005. int offset = 0;
  12006. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  12007. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  12008. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  12009. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  12010. ))
  12011. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  12012. if(inter_config.emblem_transparency_limit != 100) {
  12013. int i, transcount = 1, tmp[3];
  12014. for(i = offset; i < buf_len-1; i++) {
  12015. int j = i%3;
  12016. tmp[j] = RBUFL(buf,i);
  12017. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  12018. transcount++;
  12019. }
  12020. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  12021. return EMBVALIDATE_ERR_TRANSPARENCY;
  12022. }
  12023. return EMBVALIDATE_SUCCESS;
  12024. }
  12025. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  12026. /// 0153 <packet len>.W <emblem data>.?B
  12027. void clif_parse_GuildChangeEmblem(int fd,map_session_data *sd){
  12028. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12029. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  12030. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  12031. int emb_val=0;
  12032. if( !emblem_len || !sd->state.gmaster_flag )
  12033. return;
  12034. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  12035. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  12036. return;
  12037. }
  12038. emb_val = clif_validate_emblem(emblem, emblem_len);
  12039. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  12040. 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);
  12041. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  12042. return;
  12043. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  12044. char output[128];
  12045. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  12046. 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"
  12047. return;
  12048. }
  12049. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  12050. }
  12051. /// Request to update the guild emblem id (version, according to Gravity)
  12052. /// 0b46 <guild id>.L <version>.L
  12053. void clif_parse_GuildChangeEmblem2(int fd, map_session_data* sd) {
  12054. nullpo_retv(sd);
  12055. #if PACKETVER >= 20190724
  12056. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  12057. auto &g = sd->guild;
  12058. if (!g || g->guild.guild_id != p->guild_id)
  12059. return;
  12060. if (!sd->state.gmaster_flag)
  12061. return;
  12062. if (!inter_config.emblem_woe_change && is_agit_start()) {
  12063. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  12064. return;
  12065. }
  12066. guild_change_emblem_version(sd, p->version);
  12067. #endif
  12068. }
  12069. /// Guild notice update request (CZ_GUILD_NOTICE).
  12070. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  12071. void clif_parse_GuildChangeNotice(int fd, map_session_data* sd){
  12072. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12073. int guild_id = RFIFOL(fd,info->pos[0]);
  12074. char* msg1 = RFIFOCP(fd,info->pos[1]);
  12075. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12076. if(!sd->state.gmaster_flag)
  12077. return;
  12078. // compensate for some client defects when using multilanguage mode
  12079. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12080. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12081. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12082. guild_change_notice(sd, guild_id, msg1, msg2);
  12083. }
  12084. // Helper function for guild invite functions
  12085. int clif_sub_guild_invite(int fd, map_session_data *sd, map_session_data *t_sd)
  12086. {
  12087. if (t_sd == NULL) // not online or does not exist
  12088. return 1;
  12089. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12090. clif_displaymessage(fd, msg_txt(sd,228));
  12091. return 1;
  12092. }
  12093. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12094. clif_noask_sub(sd, t_sd, 2);
  12095. return 1;
  12096. }
  12097. // Players in a clan can not join a guild
  12098. if(t_sd && t_sd->clan){
  12099. return 1;
  12100. }
  12101. guild_invite(sd, t_sd);
  12102. return 0;
  12103. }
  12104. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12105. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12106. void clif_parse_GuildInvite(int fd,map_session_data *sd){
  12107. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12108. map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12109. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12110. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12111. if (clif_sub_guild_invite(fd, sd, t_sd))
  12112. return;
  12113. }
  12114. /// Guild invite request (/guildinvite)
  12115. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12116. void
  12117. clif_parse_GuildInvite2(int fd, map_session_data *sd) {
  12118. map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12119. if (clif_sub_guild_invite(fd, sd, t_sd))
  12120. return;
  12121. }
  12122. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12123. /// 016b <guild id>.L <answer>.L
  12124. /// answer:
  12125. /// 0 = refuse
  12126. /// 1 = accept
  12127. void clif_parse_GuildReplyInvite(int fd,map_session_data *sd){
  12128. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12129. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12130. RFIFOL(fd,info->pos[1]));
  12131. }
  12132. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12133. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12134. void clif_parse_GuildLeave(int fd,map_session_data *sd){
  12135. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12136. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12137. clif_displaymessage(fd, msg_txt(sd,228));
  12138. return;
  12139. }
  12140. if( sd->bg_id ) {
  12141. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12142. return;
  12143. }
  12144. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12145. RFIFOL(fd,info->pos[1]),
  12146. RFIFOL(fd,info->pos[2]),
  12147. RFIFOCP(fd,info->pos[3]));
  12148. }
  12149. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12150. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12151. void clif_parse_GuildExpulsion(int fd,map_session_data *sd){
  12152. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12153. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12154. { // Guild locked.
  12155. clif_displaymessage(fd, msg_txt(sd,228));
  12156. return;
  12157. }
  12158. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12159. RFIFOL(fd,info->pos[1]),
  12160. RFIFOL(fd,info->pos[2]),
  12161. RFIFOCP(fd,info->pos[3]));
  12162. }
  12163. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12164. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12165. void clif_parse_GuildMessage(int fd, map_session_data* sd){
  12166. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12167. // validate packet and retrieve name and message
  12168. if( !clif_process_message( sd, false, name, message, output ) )
  12169. return;
  12170. if( sd->bg_id )
  12171. bg_send_message(sd, output, strlen(output) );
  12172. else
  12173. guild_send_message(sd, output, strlen(output) );
  12174. }
  12175. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12176. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12177. void clif_parse_GuildRequestAlliance(int fd, map_session_data *sd)
  12178. {
  12179. map_session_data *t_sd;
  12180. if(!sd->state.gmaster_flag)
  12181. return;
  12182. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12183. clif_displaymessage(fd, msg_txt(sd,228));
  12184. return;
  12185. }
  12186. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12187. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12188. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12189. // @noask [LuzZza]
  12190. if(t_sd && t_sd->state.noask) {
  12191. clif_noask_sub(sd, t_sd, 3);
  12192. return;
  12193. }
  12194. guild_reqalliance(sd,t_sd);
  12195. }
  12196. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12197. /// 0172 <inviter account id>.L <answer>.L
  12198. /// answer:
  12199. /// 0 = refuse
  12200. /// 1 = accept
  12201. void clif_parse_GuildReplyAlliance(int fd, map_session_data *sd){
  12202. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12203. guild_reply_reqalliance(sd,
  12204. RFIFOL(fd,info->pos[0]),
  12205. RFIFOL(fd,info->pos[1]));
  12206. }
  12207. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12208. /// 0183 <opponent guild id>.L <relation>.L
  12209. /// relation:
  12210. /// 0 = Ally
  12211. /// 1 = Enemy
  12212. void clif_parse_GuildDelAlliance(int fd, map_session_data *sd){
  12213. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12214. if(!sd->state.gmaster_flag)
  12215. return;
  12216. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12217. clif_displaymessage(fd, msg_txt(sd,228));
  12218. return;
  12219. }
  12220. guild_delalliance(sd,
  12221. RFIFOL(fd,info->pos[0]),
  12222. RFIFOL(fd,info->pos[1]));
  12223. }
  12224. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12225. /// 0180 <account id>.L
  12226. void clif_parse_GuildOpposition(int fd, map_session_data *sd)
  12227. {
  12228. map_session_data *t_sd;
  12229. if(!sd->state.gmaster_flag)
  12230. return;
  12231. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12232. clif_displaymessage(fd, msg_txt(sd,228));
  12233. return;
  12234. }
  12235. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12236. // @noask [LuzZza]
  12237. if(t_sd && t_sd->state.noask) {
  12238. clif_noask_sub(sd, t_sd, 4);
  12239. return;
  12240. }
  12241. guild_opposition(sd,t_sd);
  12242. }
  12243. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12244. /// 015d <key>.40B
  12245. /// key:
  12246. /// now guild name; might have been (intended) email, since the
  12247. /// field name and size is same as the one in CH_DELETE_CHAR.
  12248. void clif_parse_GuildBreak(int fd, map_session_data *sd)
  12249. {
  12250. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12251. clif_displaymessage(fd, msg_txt(sd,228));
  12252. return;
  12253. }
  12254. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12255. }
  12256. /// Pet
  12257. ///
  12258. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12259. /// 01a1 <type>.B
  12260. /// type:
  12261. /// 0 = pet information
  12262. /// 1 = feed
  12263. /// 2 = performance
  12264. /// 3 = return to egg
  12265. /// 4 = unequip accessory
  12266. void clif_parse_PetMenu(int fd, map_session_data *sd){
  12267. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12268. }
  12269. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12270. /// 019f <id>.L
  12271. void clif_parse_CatchPet(int fd, map_session_data *sd){
  12272. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12273. }
  12274. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12275. /// 01a7 <index>.W
  12276. void clif_parse_SelectEgg(int fd, map_session_data *sd){
  12277. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12278. return;
  12279. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12280. clif_menuskill_clear(sd);
  12281. }
  12282. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12283. /// 01a9 <data>.L
  12284. /// data:
  12285. /// is either emotion (@see enum emotion_type) or a compound value
  12286. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12287. /// entry (given in parentheses) in data\pettalktable.xml
  12288. /// act id:
  12289. /// 0 = feeding
  12290. /// 1 = hunting
  12291. /// 2 = danger
  12292. /// 3 = dead
  12293. /// 4 = normal (stand)
  12294. /// 5 = special performance (perfor_s)
  12295. /// 6 = level up (levelup)
  12296. /// 7 = performance 1 (perfor_1)
  12297. /// 8 = performance 2 (perfor_2)
  12298. /// 9 = performance 3 (perfor_3)
  12299. /// 10 = log-in greeting (connect)
  12300. /// hungry value:
  12301. /// 0 = very hungry (hungry)
  12302. /// 1 = hungry (bit_hungry)
  12303. /// 2 = satisfied (noting)
  12304. /// 3 = stuffed (full)
  12305. /// 4 = full (so_full)
  12306. void clif_parse_SendEmotion(int fd, map_session_data *sd)
  12307. {
  12308. if(sd->pd)
  12309. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12310. }
  12311. /// Request to change pet's name (CZ_RENAME_PET).
  12312. /// 01a5 <name>.24B
  12313. void clif_parse_ChangePetName(int fd, map_session_data *sd)
  12314. {
  12315. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12316. }
  12317. /// /kill (CZ_DISCONNECT_CHARACTER).
  12318. /// Request to disconnect a character.
  12319. /// 00cc <account id>.L
  12320. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12321. void clif_parse_GMKick(int fd, map_session_data *sd)
  12322. {
  12323. struct block_list *target;
  12324. int tid;
  12325. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12326. target = map_id2bl(tid);
  12327. if (!target) {
  12328. clif_GM_kickack(sd, 0);
  12329. return;
  12330. }
  12331. switch (target->type) {
  12332. case BL_PC:
  12333. {
  12334. char command[NAME_LENGTH+6];
  12335. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12336. is_atcommand(fd, sd, command, 1);
  12337. }
  12338. break;
  12339. /**
  12340. * This one does not invoke any atcommand, so we need to check for permissions.
  12341. */
  12342. case BL_MOB:
  12343. {
  12344. char command[100];
  12345. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12346. clif_GM_kickack(sd, 0);
  12347. return;
  12348. }
  12349. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12350. log_atcommand(sd, command);
  12351. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12352. }
  12353. break;
  12354. case BL_NPC:
  12355. {
  12356. struct npc_data* nd = (struct npc_data *)target;
  12357. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12358. npc_unload_duplicates(nd);
  12359. npc_unload(nd,true);
  12360. npc_read_event_script();
  12361. }
  12362. }
  12363. break;
  12364. default:
  12365. clif_GM_kickack(sd, 0);
  12366. }
  12367. }
  12368. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12369. /// Request to disconnect all characters.
  12370. /// 00ce
  12371. void clif_parse_GMKickAll(int fd, map_session_data* sd) {
  12372. char cmd[15];
  12373. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12374. is_atcommand(fd, sd, cmd, 1);
  12375. }
  12376. /// /remove (CZ_REMOVE_AID).
  12377. /// Request to warp to a character with given login ID.
  12378. /// 01ba <account name>.24B
  12379. /// /shift (CZ_SHIFT).
  12380. /// Request to warp to a character with given name.
  12381. /// 01bb <char name>.24B
  12382. void clif_parse_GMShift(int fd, map_session_data *sd)
  12383. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12384. char *player_name;
  12385. char command[NAME_LENGTH+8];
  12386. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12387. player_name[NAME_LENGTH-1] = '\0';
  12388. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12389. is_atcommand(fd, sd, command, 1);
  12390. }
  12391. /// /remove (CZ_REMOVE_AID_SSO).
  12392. /// Request to warp to a character with given account ID.
  12393. /// 0843 <account id>.L
  12394. void clif_parse_GMRemove2(int fd, map_session_data* sd)
  12395. {
  12396. uint32 account_id;
  12397. map_session_data* pl_sd;
  12398. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12399. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12400. char command[NAME_LENGTH+8];
  12401. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12402. is_atcommand(fd, sd, command, 1);
  12403. }
  12404. }
  12405. /// /recall (CZ_RECALL).
  12406. /// Request to summon a player with given login ID to own position.
  12407. /// 01bc <account name>.24B
  12408. /// /summon (CZ_RECALL_GID).
  12409. /// Request to summon a player with given name to own position.
  12410. /// 01bd <char name>.24B
  12411. void clif_parse_GMRecall(int fd, map_session_data *sd)
  12412. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12413. char *player_name;
  12414. char command [NAME_LENGTH+8];
  12415. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12416. player_name[NAME_LENGTH-1] = '\0';
  12417. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12418. is_atcommand(fd, sd, command, 1);
  12419. }
  12420. /// /recall (CZ_RECALL_SSO).
  12421. /// Request to summon a player with given account ID to own position.
  12422. /// 0842 <account id>.L
  12423. void clif_parse_GMRecall2(int fd, map_session_data* sd)
  12424. {
  12425. uint32 account_id;
  12426. map_session_data* pl_sd;
  12427. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12428. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12429. char command[NAME_LENGTH+8];
  12430. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12431. is_atcommand(fd, sd, command, 1);
  12432. }
  12433. }
  12434. /// /item /monster (CZ_ITEM_CREATE).
  12435. /// Request to execute GM commands.
  12436. /// Usage:
  12437. /// /item n - summon n monster or acquire n item/s
  12438. /// /item money - grants 2147483647 zenies
  12439. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12440. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12441. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12442. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12443. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12444. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12445. /// 013f <item/mob name>.24B
  12446. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12447. void clif_parse_GM_Item_Monster(int fd, map_session_data *sd)
  12448. {
  12449. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12450. int mob_id = 0;
  12451. StringBuf command;
  12452. char *str;
  12453. //#if PACKETVER >= 20131218
  12454. // char str[100];
  12455. //#else
  12456. // char str[24];
  12457. //#endif
  12458. str = RFIFOCP(fd,info->pos[0]);
  12459. if (!str || str[0] == '\0')
  12460. return;
  12461. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12462. return;
  12463. trim(str);
  12464. // Zeny
  12465. if( strcmpi(str, "money") == 0 ) {
  12466. StringBuf_Init(&command);
  12467. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12468. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12469. StringBuf_Destroy(&command);
  12470. return;
  12471. }
  12472. std::shared_ptr<item_data> id = item_db.searchname( str );
  12473. // Item
  12474. if( id ){
  12475. StringBuf_Init(&command);
  12476. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12477. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12478. }else{
  12479. if (id->flag.guid)
  12480. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12481. else
  12482. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12483. }
  12484. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12485. StringBuf_Destroy(&command);
  12486. return;
  12487. }
  12488. // Monster
  12489. if ((mob_id = mobdb_searchname(str)) == 0)
  12490. mob_id = mobdb_checkid(atoi(str));
  12491. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12492. if( mob != nullptr ) {
  12493. StringBuf_Init(&command);
  12494. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12495. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12496. StringBuf_Destroy(&command);
  12497. return;
  12498. }
  12499. }
  12500. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12501. /// 019d <effect state>.L
  12502. /// effect state:
  12503. /// TODO: Any OPTION_* ?
  12504. void clif_parse_GMHide(int fd, map_session_data *sd) {
  12505. char cmd[6];
  12506. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12507. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12508. is_atcommand(fd, sd, cmd, 1);
  12509. }
  12510. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12511. /// 0149 <account id>.L <type>.B <value>.W
  12512. /// type:
  12513. /// 0 = positive points
  12514. /// 1 = negative points
  12515. /// 2 = self mute (+10 minutes)
  12516. void clif_parse_GMReqNoChat(int fd,map_session_data *sd)
  12517. {
  12518. int id, type, value;
  12519. map_session_data *dstsd;
  12520. char command[NAME_LENGTH+15];
  12521. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12522. id = RFIFOL(fd,info->pos[0]);
  12523. type = RFIFOB(fd,info->pos[1]);
  12524. value = RFIFOW(fd,info->pos[2]);
  12525. if( type == 0 )
  12526. value = -value;
  12527. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12528. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12529. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12530. return;
  12531. dstsd = map_id2sd(id);
  12532. if( dstsd == NULL )
  12533. return;
  12534. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12535. is_atcommand(fd, sd, command, 1);
  12536. }
  12537. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12538. /// GM adjustment of a player's manner value by -60.
  12539. /// 0212 <char name>.24B
  12540. void clif_parse_GMRc(int fd, map_session_data* sd)
  12541. {
  12542. char command[NAME_LENGTH+15];
  12543. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12544. name[NAME_LENGTH-1] = '\0';
  12545. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12546. is_atcommand(fd, sd, command, 1);
  12547. }
  12548. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12549. /// 01e0 <account id>.L <account name>.24B
  12550. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12551. {
  12552. WFIFOHEAD(fd,packet_len(0x1e0));
  12553. WFIFOW(fd,0) = 0x1e0;
  12554. WFIFOL(fd,2) = account_id;
  12555. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12556. WFIFOSET(fd,packet_len(0x1e0));
  12557. }
  12558. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12559. /// 01df <account id>.L
  12560. //! TODO: Figure out how does this actually work
  12561. void clif_parse_GMReqAccountName(int fd, map_session_data *sd)
  12562. {
  12563. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12564. /*
  12565. char query[30];
  12566. safesnprintf(query,sizeof(query),"%d", account_id);
  12567. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12568. */
  12569. clif_account_name(fd, account_id, "");
  12570. }
  12571. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12572. /// GM single cell type change request.
  12573. /// 0198 <x>.W <y>.W <type>.W
  12574. /// type:
  12575. /// 0 = not walkable
  12576. /// 1 = walkable
  12577. void clif_parse_GMChangeMapType(int fd, map_session_data *sd)
  12578. {
  12579. int x,y,type;
  12580. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12581. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12582. return;
  12583. x = RFIFOW(fd,info->pos[0]);
  12584. y = RFIFOW(fd,info->pos[1]);
  12585. type = RFIFOW(fd,info->pos[2]);
  12586. map_setgatcell(sd->bl.m,x,y,type);
  12587. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12588. //FIXME: once players leave the map, the client 'forgets' this information.
  12589. }
  12590. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12591. /// Request to allow/deny whispers from a nick.
  12592. /// 00cf <nick>.24B <type>.B
  12593. /// type:
  12594. /// 0 = (/ex nick) deny speech from nick
  12595. /// 1 = (/in nick) allow speech from nick
  12596. void clif_parse_PMIgnore(int fd, map_session_data* sd)
  12597. {
  12598. char* nick;
  12599. uint8 type;
  12600. int i;
  12601. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12602. nick = RFIFOCP(fd,info->pos[0]);
  12603. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12604. type = RFIFOB(fd,info->pos[1]);
  12605. if( type == 0 ) { // Add name to ignore list (block)
  12606. if (strcmp(wisp_server_name, nick) == 0) {
  12607. clif_wisexin(sd, type, 1); // fail
  12608. return;
  12609. }
  12610. // try to find a free spot, while checking for duplicates at the same time
  12611. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12612. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12613. clif_wisexin(sd, type, 2); // too many blocks
  12614. return;
  12615. }
  12616. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12617. clif_wisexin(sd, type, 0); // Aegis reports success.
  12618. return;
  12619. }
  12620. //Insert in position i
  12621. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12622. } else { // Remove name from ignore list (unblock)
  12623. // find entry
  12624. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12625. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12626. clif_wisexin(sd, type, 1); // fail
  12627. return;
  12628. }
  12629. // move everything one place down to overwrite removed entry
  12630. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12631. // wipe last entry
  12632. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12633. }
  12634. clif_wisexin(sd, type, 0); // success
  12635. }
  12636. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12637. /// Request to allow/deny all whispers.
  12638. /// 00d0 <type>.B
  12639. /// type:
  12640. /// 0 = (/exall) deny all speech
  12641. /// 1 = (/inall) allow all speech
  12642. void clif_parse_PMIgnoreAll(int fd, map_session_data *sd)
  12643. {
  12644. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12645. if( type == 0 ) {// Deny all
  12646. if( sd->state.ignoreAll ) {
  12647. flag = 1; // fail
  12648. } else {
  12649. sd->state.ignoreAll = 1;
  12650. flag = 0; // success
  12651. }
  12652. } else {//Unblock everyone
  12653. if( sd->state.ignoreAll ) {
  12654. sd->state.ignoreAll = 0;
  12655. flag = 0; // success
  12656. } else {
  12657. if (sd->ignore[0].name[0] != '\0')
  12658. { //Wipe the ignore list.
  12659. memset(sd->ignore, 0, sizeof(sd->ignore));
  12660. flag = 0; // success
  12661. } else {
  12662. flag = 1; // fail
  12663. }
  12664. }
  12665. }
  12666. clif_wisall(sd, type, flag);
  12667. }
  12668. /// Whisper ignore list (ZC_WHISPER_LIST).
  12669. /// 00d4 <packet len>.W { <char name>.24B }*
  12670. void clif_PMIgnoreList(map_session_data* sd)
  12671. {
  12672. int i, fd = sd->fd;
  12673. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12674. WFIFOW(fd,0) = 0xd4;
  12675. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12676. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12677. }
  12678. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12679. WFIFOSET(fd,WFIFOW(fd,2));
  12680. }
  12681. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12682. /// 00d3
  12683. void clif_parse_PMIgnoreList(int fd,map_session_data *sd)
  12684. {
  12685. clif_PMIgnoreList(sd);
  12686. }
  12687. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12688. /// 01e7
  12689. void clif_parse_NoviceDoriDori(int fd, map_session_data *sd)
  12690. {
  12691. if (sd->state.doridori) return;
  12692. switch (sd->class_&MAPID_UPPERMASK) {
  12693. case MAPID_SOUL_LINKER:
  12694. case MAPID_STAR_GLADIATOR:
  12695. case MAPID_TAEKWON:
  12696. if (!sd->state.rest)
  12697. break;
  12698. [[fallthrough]];
  12699. case MAPID_SUPER_NOVICE:
  12700. case MAPID_SUPER_BABY:
  12701. case MAPID_SUPER_NOVICE_E:
  12702. case MAPID_SUPER_BABY_E:
  12703. sd->state.doridori=1;
  12704. break;
  12705. }
  12706. }
  12707. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12708. /// 01ed
  12709. /// Note: This packet is caused by 7 lines of any text, followed by
  12710. /// the prayer and an another line of any text. The prayer is
  12711. /// defined by lines 790~793 in data\msgstringtable.txt
  12712. /// "Dear angel, can you hear my voice?"
  12713. /// "I am" (space separated player name) "Super Novice~"
  12714. /// "Help me out~ Please~ T_T"
  12715. void clif_parse_NoviceExplosionSpirits(int fd, map_session_data *sd)
  12716. {
  12717. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12718. t_exp next = pc_nextbaseexp(sd);
  12719. if( next ) {
  12720. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12721. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12722. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12723. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12724. }
  12725. }
  12726. }
  12727. }
  12728. /// Friends List
  12729. ///
  12730. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12731. /// 0206 <account id>.L <char id>.L <state>.B
  12732. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12733. /// state:
  12734. /// 0 = online
  12735. /// 1 = offline
  12736. void clif_friendslist_toggle(map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12737. {
  12738. int i, fd = sd->fd;
  12739. //Seek friend.
  12740. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12741. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12742. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12743. return; //Not found
  12744. WFIFOHEAD(fd,packet_len(0x206));
  12745. WFIFOW(fd, 0) = 0x206;
  12746. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12747. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12748. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12749. #if PACKETVER >= 20180221
  12750. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12751. #endif
  12752. WFIFOSET(fd, packet_len(0x206));
  12753. }
  12754. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12755. int clif_friendslist_toggle_sub(map_session_data *sd,va_list ap)
  12756. {
  12757. uint32 account_id, char_id, online;
  12758. account_id = va_arg(ap, int);
  12759. char_id = va_arg(ap, int);
  12760. online = va_arg(ap, int);
  12761. clif_friendslist_toggle(sd, account_id, char_id, online);
  12762. return 0;
  12763. }
  12764. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12765. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12766. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12767. void clif_friendslist_send( map_session_data& sd ){
  12768. struct PACKET_ZC_FRIENDS_LIST* p = (struct PACKET_ZC_FRIENDS_LIST*)packet_buffer;
  12769. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12770. p->PacketLength = sizeof( *p );
  12771. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12772. struct PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12773. f.AID = sd.status.friends[i].account_id;
  12774. f.CID = sd.status.friends[i].char_id;
  12775. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12776. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12777. #endif
  12778. c++;
  12779. p->PacketLength += sizeof( f );
  12780. }
  12781. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12782. // Sending the online players
  12783. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12784. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12785. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12786. }
  12787. }
  12788. }
  12789. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12790. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12791. /// result:
  12792. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12793. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12794. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12795. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12796. void clif_friendslist_reqack(map_session_data *sd, map_session_data *f_sd, int type)
  12797. {
  12798. int fd;
  12799. nullpo_retv(sd);
  12800. fd = sd->fd;
  12801. WFIFOHEAD(fd,packet_len(0x209));
  12802. WFIFOW(fd,0) = 0x209;
  12803. WFIFOW(fd,2) = type;
  12804. if (f_sd) {
  12805. WFIFOL(fd,4) = f_sd->status.account_id;
  12806. WFIFOL(fd,8) = f_sd->status.char_id;
  12807. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12808. }
  12809. WFIFOSET(fd, packet_len(0x209));
  12810. }
  12811. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12812. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12813. void clif_friendlist_req(map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12814. {
  12815. int fd = sd->fd;
  12816. WFIFOHEAD(fd,packet_len(0x207));
  12817. WFIFOW(fd,0) = 0x207;
  12818. WFIFOL(fd,2) = account_id;
  12819. WFIFOL(fd,6) = char_id;
  12820. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12821. WFIFOSET(fd,packet_len(0x207));
  12822. }
  12823. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12824. /// 0202 <name>.24B
  12825. void clif_parse_FriendsListAdd(int fd, map_session_data *sd)
  12826. {
  12827. map_session_data *f_sd;
  12828. int i;
  12829. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12830. // Friend doesn't exist (no player with this name)
  12831. if (f_sd == NULL) {
  12832. clif_displaymessage(fd, msg_txt(sd,3));
  12833. return;
  12834. }
  12835. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12836. return;
  12837. }
  12838. // ensure that the request player's friend list is not full
  12839. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12840. if( i == MAX_FRIENDS ){
  12841. clif_friendslist_reqack(sd, f_sd, 2);
  12842. return;
  12843. }
  12844. // @noask [LuzZza]
  12845. if(f_sd->state.noask) {
  12846. clif_noask_sub(sd, f_sd, 5);
  12847. return;
  12848. }
  12849. // Friend already exists
  12850. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12851. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12852. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12853. return;
  12854. }
  12855. }
  12856. f_sd->friend_req = sd->status.char_id;
  12857. sd->friend_req = f_sd->status.char_id;
  12858. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12859. }
  12860. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12861. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12862. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12863. /// reply:
  12864. /// 0 = rejected
  12865. /// 1 = accepted
  12866. void clif_parse_FriendsListReply(int fd, map_session_data *sd)
  12867. {
  12868. map_session_data *f_sd;
  12869. uint32 account_id;
  12870. char reply;
  12871. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12872. account_id = RFIFOL(fd,info->pos[0]);
  12873. //char_id = RFIFOL(fd,info->pos[1]);
  12874. #if PACKETVER < 6
  12875. reply = RFIFOB(fd,info->pos[2]);
  12876. #else
  12877. reply = RFIFOL(fd,info->pos[2]);
  12878. #endif
  12879. if( sd->bl.id == account_id ) {// adding oneself as friend
  12880. return;
  12881. }
  12882. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12883. if (f_sd == NULL)
  12884. return;
  12885. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12886. clif_friendslist_reqack(f_sd, sd, 1);
  12887. else {
  12888. int i;
  12889. // Find an empty slot
  12890. for (i = 0; i < MAX_FRIENDS; i++)
  12891. if (f_sd->status.friends[i].char_id == 0)
  12892. break;
  12893. if (i == MAX_FRIENDS) {
  12894. clif_friendslist_reqack(f_sd, sd, 2);
  12895. return;
  12896. }
  12897. f_sd->status.friends[i].account_id = sd->status.account_id;
  12898. f_sd->status.friends[i].char_id = sd->status.char_id;
  12899. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12900. clif_friendslist_reqack(f_sd, sd, 0);
  12901. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12902. if (battle_config.friend_auto_add) {
  12903. // Also add f_sd to sd's friendlist.
  12904. for (i = 0; i < MAX_FRIENDS; i++) {
  12905. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12906. return; //No need to add anything.
  12907. if (sd->status.friends[i].char_id == 0)
  12908. break;
  12909. }
  12910. if (i == MAX_FRIENDS) {
  12911. clif_friendslist_reqack(sd, f_sd, 2);
  12912. return;
  12913. }
  12914. sd->status.friends[i].account_id = f_sd->status.account_id;
  12915. sd->status.friends[i].char_id = f_sd->status.char_id;
  12916. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12917. clif_friendslist_reqack(sd, f_sd, 0);
  12918. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12919. }
  12920. }
  12921. }
  12922. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12923. /// 0203 <account id>.L <char id>.L
  12924. void clif_parse_FriendsListRemove(int fd, map_session_data *sd)
  12925. {
  12926. map_session_data *f_sd = NULL;
  12927. uint32 account_id, char_id;
  12928. int i, j;
  12929. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12930. account_id = RFIFOL(fd,info->pos[0]);
  12931. char_id = RFIFOL(fd,info->pos[1]);
  12932. // Search friend
  12933. for (i = 0; i < MAX_FRIENDS &&
  12934. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12935. if (i == MAX_FRIENDS) {
  12936. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12937. return;
  12938. }
  12939. //remove from friend's list first
  12940. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12941. for (i = 0; i < MAX_FRIENDS &&
  12942. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12943. if (i != MAX_FRIENDS) {
  12944. // move all chars up
  12945. for(j = i + 1; j < MAX_FRIENDS; j++)
  12946. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12947. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12948. //should the guy be notified of some message? we should add it here if so
  12949. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12950. WFIFOW(f_sd->fd,0) = 0x20a;
  12951. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12952. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12953. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12954. }
  12955. } else { //friend not online -- ask char server to delete from his friendlist
  12956. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12957. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12958. return;
  12959. }
  12960. }
  12961. // We can now delete from original requester
  12962. for (i = 0; i < MAX_FRIENDS &&
  12963. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12964. // move all chars up
  12965. for(j = i + 1; j < MAX_FRIENDS; j++)
  12966. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12967. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12968. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12969. WFIFOHEAD(fd,packet_len(0x20a));
  12970. WFIFOW(fd,0) = 0x20a;
  12971. WFIFOL(fd,2) = account_id;
  12972. WFIFOL(fd,6) = char_id;
  12973. WFIFOSET(fd, packet_len(0x20a));
  12974. }
  12975. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12976. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12977. void clif_PVPInfo(map_session_data* sd)
  12978. {
  12979. int fd = sd->fd;
  12980. WFIFOHEAD(fd,packet_len(0x210));
  12981. WFIFOW(fd,0) = 0x210;
  12982. WFIFOL(fd,2) = sd->status.char_id;
  12983. WFIFOL(fd,6) = sd->status.account_id;
  12984. WFIFOL(fd,10) = sd->pvp_won; // times won
  12985. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12986. WFIFOL(fd,18) = sd->pvp_point;
  12987. WFIFOSET(fd, packet_len(0x210));
  12988. }
  12989. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12990. /// 020f <char id>.L <account id>.L
  12991. void clif_parse_PVPInfo(int fd,map_session_data *sd)
  12992. {
  12993. // TODO: Is there a way to use this on an another player (char/acc id)?
  12994. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12995. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12996. clif_PVPInfo(sd);
  12997. }
  12998. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12999. /// 0254 <which>.B
  13000. /// which: (unused atm for security purpose)
  13001. /// 0 = sun
  13002. /// 1 = moon
  13003. /// 2 = star
  13004. void clif_parse_FeelSaveOk(int fd,map_session_data *sd)
  13005. {
  13006. int i;
  13007. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13008. if (sd->menuskill_id != SG_FEEL)
  13009. return;
  13010. i = sd->menuskill_val-1;
  13011. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  13012. sd->feel_map[i].index = map_id2index(sd->bl.m);
  13013. sd->feel_map[i].m = sd->bl.m;
  13014. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  13015. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  13016. // clif_misceffect2(&sd->bl, 0x1b0);
  13017. // clif_misceffect2(&sd->bl, 0x21f);
  13018. clif_feel_info(sd, i, 0);
  13019. clif_menuskill_clear(sd);
  13020. }
  13021. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  13022. /// 0253 <which>.B
  13023. /// which:
  13024. /// 0 = sun
  13025. /// 1 = moon
  13026. /// 2 = star
  13027. void clif_feel_req(int fd, map_session_data *sd, uint16 skill_lv)
  13028. {
  13029. WFIFOHEAD(fd,packet_len(0x253));
  13030. WFIFOW(fd,0)=0x253;
  13031. WFIFOB(fd,2)=TOB(skill_lv-1);
  13032. WFIFOSET(fd, packet_len(0x253));
  13033. sd->menuskill_id = SG_FEEL;
  13034. sd->menuskill_val = skill_lv;
  13035. }
  13036. /// Request to change homunculus' name (CZ_RENAME_MER).
  13037. /// 0231 <name>.24B
  13038. void clif_parse_ChangeHomunculusName(int fd, map_session_data *sd){
  13039. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13040. }
  13041. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  13042. /// 0234 <id>.L
  13043. void clif_parse_HomMoveToMaster(int fd, map_session_data *sd){
  13044. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  13045. struct block_list *bl = NULL;
  13046. struct unit_data *ud = NULL;
  13047. if( sd->md && sd->md->bl.id == id )
  13048. bl = &sd->md->bl;
  13049. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13050. bl = &sd->hd->bl; // Moving Homunculus
  13051. else
  13052. return;
  13053. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  13054. ud = unit_bl2ud(bl);
  13055. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  13056. }
  13057. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  13058. /// 0232 <id>.L <position data>.3B
  13059. void clif_parse_HomMoveTo(int fd, map_session_data *sd){
  13060. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13061. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  13062. struct block_list *bl = NULL;
  13063. short x, y;
  13064. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  13065. if( sd->md && sd->md->bl.id == id )
  13066. bl = &sd->md->bl; // Moving Mercenary
  13067. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13068. bl = &sd->hd->bl; // Moving Homunculus
  13069. else
  13070. return;
  13071. unit_walktoxy(bl, x, y, 4);
  13072. }
  13073. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  13074. /// 0233 <id>.L <target id>.L <action>.B
  13075. /// action:
  13076. /// always 0
  13077. void clif_parse_HomAttack(int fd,map_session_data *sd)
  13078. {
  13079. struct block_list *bl = NULL;
  13080. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13081. int id = RFIFOL(fd,info->pos[0]);
  13082. int target_id = RFIFOL(fd,info->pos[1]);
  13083. int action_type = RFIFOB(fd,info->pos[2]);
  13084. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13085. bl = &sd->hd->bl;
  13086. else if( sd->md && sd->md->bl.id == id )
  13087. bl = &sd->md->bl;
  13088. else return;
  13089. unit_stop_attack(bl);
  13090. unit_attack(bl, target_id, action_type != 0);
  13091. }
  13092. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13093. /// 022d <type>.W <command>.B
  13094. /// type:
  13095. /// always 0
  13096. /// command:
  13097. /// 0 = homunculus information
  13098. /// 1 = feed
  13099. /// 2 = delete
  13100. void clif_parse_HomMenu(int fd, map_session_data *sd)
  13101. { //[orn]
  13102. int cmd = RFIFOW(fd,0);
  13103. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13104. if(!hom_is_active(sd->hd))
  13105. return;
  13106. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13107. }
  13108. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13109. /// 0292
  13110. void clif_parse_AutoRevive(int fd, map_session_data *sd)
  13111. {
  13112. pc_revive_item(sd);
  13113. }
  13114. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13115. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13116. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13117. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13118. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13119. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13120. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13121. void clif_check(int fd, map_session_data* pl_sd)
  13122. {
  13123. WFIFOHEAD(fd,packet_len(0x214));
  13124. WFIFOW(fd, 0) = 0x214;
  13125. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13126. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13127. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13128. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13129. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13130. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13131. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13132. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13133. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13134. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13135. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13136. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13137. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13138. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13139. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13140. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13141. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13142. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13143. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13144. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13145. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13146. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13147. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13148. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13149. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13150. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13151. WFIFOSET(fd,packet_len(0x214));
  13152. }
  13153. /// /check (CZ_REQ_STATUS_GM).
  13154. /// Request character's status values.
  13155. /// 0213 <char name>.24B
  13156. void clif_parse_Check(int fd, map_session_data *sd)
  13157. {
  13158. char charname[NAME_LENGTH];
  13159. map_session_data* pl_sd;
  13160. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13161. return;
  13162. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13163. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13164. {
  13165. return;
  13166. }
  13167. clif_check(fd, pl_sd);
  13168. }
  13169. /// MAIL SYSTEM
  13170. /// By Zephyrus
  13171. ///
  13172. /// Notification about the result of adding an item to mail
  13173. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13174. /// result:
  13175. /// 0 = success
  13176. /// 1 = failure
  13177. /// 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)
  13178. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13179. /// result:
  13180. /// 0 = success
  13181. /// 1 = over weight
  13182. /// 2 = fatal error
  13183. void clif_Mail_setattachment( map_session_data* sd, int index, int amount, uint8 flag ){
  13184. int fd = sd->fd;
  13185. #if PACKETVER < 20150513
  13186. WFIFOHEAD(fd,packet_len(0x255));
  13187. WFIFOW(fd,0) = 0x255;
  13188. WFIFOW(fd,2) = index;
  13189. WFIFOB(fd,4) = flag;
  13190. WFIFOSET(fd,packet_len(0x255));
  13191. #else
  13192. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13193. if( flag ){
  13194. memset( &p, 0, sizeof( p ) );
  13195. }else{
  13196. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13197. p.index = index;
  13198. p.count = amount;
  13199. p.itemId = client_nameid( item->nameid );
  13200. p.type = itemtype( item->nameid );
  13201. p.IsIdentified = item->identify ? 1 : 0;
  13202. p.IsDamaged = item->attribute ? 1 : 0;
  13203. p.refiningLevel = item->refine;
  13204. clif_addcards( &p.slot, item );
  13205. clif_add_random_options( p.optionData, *item );
  13206. p.weight = 0;
  13207. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13208. if( sd->mail.item[i].nameid == 0 ){
  13209. continue;
  13210. }
  13211. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13212. }
  13213. p.favorite = item->favorite;
  13214. p.location = pc_equippoint( sd, server_index( index ) );
  13215. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13216. p.grade = item->enchantgrade;
  13217. #endif
  13218. }
  13219. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13220. p.result = flag;
  13221. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13222. #endif
  13223. }
  13224. /// Notification about the result of retrieving a mail attachment
  13225. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13226. /// result:
  13227. /// 0 = success
  13228. /// 1 = failure
  13229. /// 2 = too many items
  13230. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13231. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13232. void clif_mail_getattachment(map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13233. #if PACKETVER < 20150513
  13234. int fd = sd->fd;
  13235. WFIFOHEAD(fd,packet_len(0x245));
  13236. WFIFOW(fd,0) = 0x245;
  13237. WFIFOB(fd,2) = result;
  13238. WFIFOSET(fd,packet_len(0x245));
  13239. #else
  13240. switch( type ){
  13241. case MAIL_ATT_ITEM:
  13242. case MAIL_ATT_ZENY:
  13243. break;
  13244. default:
  13245. return;
  13246. }
  13247. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13248. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13249. p.MailID = msg->id;
  13250. p.opentype = msg->type;
  13251. p.result = result;
  13252. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13253. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13254. #endif
  13255. }
  13256. /// Notification about the result of sending a mail
  13257. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13258. /// result:
  13259. /// 0 = success
  13260. /// 1 = recipinent does not exist
  13261. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13262. void clif_Mail_send(map_session_data* sd, enum mail_send_result result){
  13263. #if PACKETVER < 20150513
  13264. int fd = sd->fd;
  13265. WFIFOHEAD(fd,packet_len(0x249));
  13266. WFIFOW(fd,0) = 0x249;
  13267. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13268. WFIFOSET(fd,packet_len(0x249));
  13269. #else
  13270. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13271. p.PacketType = rodexwriteresult;
  13272. p.result = result;
  13273. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13274. #endif
  13275. }
  13276. /// Notification about the result of deleting a mail.
  13277. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13278. /// result:
  13279. /// 0 = success
  13280. /// 1 = failure
  13281. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13282. void clif_mail_delete( map_session_data* sd, struct mail_message *msg, bool success ){
  13283. #if PACKETVER < 20150513
  13284. int fd = sd->fd;
  13285. WFIFOHEAD(fd, packet_len(0x257));
  13286. WFIFOW(fd,0) = 0x257;
  13287. WFIFOL(fd,2) = msg->id;
  13288. WFIFOW(fd,6) = !success;
  13289. WFIFOSET(fd, packet_len(0x257));
  13290. #else
  13291. // This is only a success notification
  13292. if( success ){
  13293. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13294. p.PacketType = rodexdelete;
  13295. p.opentype = msg->type;
  13296. p.MailID = msg->id;
  13297. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13298. }
  13299. #endif
  13300. }
  13301. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13302. /// 0274 <mail id>.L <result>.W
  13303. /// result:
  13304. /// 0 = success
  13305. /// 1 = failure
  13306. void clif_Mail_return(int fd, int mail_id, short fail)
  13307. {
  13308. WFIFOHEAD(fd,packet_len(0x274));
  13309. WFIFOW(fd,0) = 0x274;
  13310. WFIFOL(fd,2) = mail_id;
  13311. WFIFOW(fd,6) = fail;
  13312. WFIFOSET(fd,packet_len(0x274));
  13313. }
  13314. /// Notification about new mail.
  13315. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13316. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13317. void clif_Mail_new(map_session_data* sd, int mail_id, const char *sender, const char *title){
  13318. #if PACKETVER < 20150513
  13319. int fd = sd->fd;
  13320. WFIFOHEAD(fd,packet_len(0x24a));
  13321. WFIFOW(fd,0) = 0x24a;
  13322. WFIFOL(fd,2) = mail_id;
  13323. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13324. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13325. WFIFOSET(fd,packet_len(0x24a));
  13326. #else
  13327. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13328. p.PacketType = rodexicon;
  13329. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13330. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13331. #endif
  13332. }
  13333. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13334. /// 0260 <type>.L
  13335. /// type:
  13336. /// 0 = open
  13337. /// 1 = close
  13338. void clif_Mail_window(int fd, int flag)
  13339. {
  13340. WFIFOHEAD(fd,packet_len(0x260));
  13341. WFIFOW(fd,0) = 0x260;
  13342. WFIFOL(fd,2) = flag;
  13343. WFIFOSET(fd,packet_len(0x260));
  13344. }
  13345. /// Lists mails stored in inbox.
  13346. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13347. /// read:
  13348. /// 0 = unread
  13349. /// 1 = read
  13350. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13351. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13352. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13353. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13354. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13355. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13356. void clif_Mail_refreshinbox(map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13357. #if PACKETVER < 20150513
  13358. int fd = sd->fd;
  13359. struct mail_data *md = &sd->mail.inbox;
  13360. struct mail_message *msg;
  13361. int len, i, j;
  13362. len = 8 + (73 * md->amount);
  13363. WFIFOHEAD(fd,len);
  13364. WFIFOW(fd,0) = 0x240;
  13365. WFIFOW(fd,2) = len;
  13366. WFIFOL(fd,4) = md->amount;
  13367. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13368. {
  13369. msg = &md->msg[i];
  13370. if (msg->id < 1)
  13371. continue;
  13372. WFIFOL(fd,8+73*j) = msg->id;
  13373. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13374. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13375. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13376. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13377. j++;
  13378. }
  13379. WFIFOSET(fd,len);
  13380. if( md->full ) {// TODO: is this official?
  13381. char output[100];
  13382. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13383. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13384. }
  13385. #else
  13386. int fd = sd->fd;
  13387. struct mail_data *md = &sd->mail.inbox;
  13388. struct mail_message *msg;
  13389. int i, j, k, offset, titleLength;
  13390. uint8 mailType, amount, remaining;
  13391. uint32 now = (uint32)time(NULL);
  13392. #if PACKETVER >= 20170419
  13393. int cmd = 0xac2;
  13394. #elif PACKETVER >= 20160601
  13395. int cmd = 0xa7d;
  13396. #else
  13397. int cmd = 0x9f0;
  13398. #endif
  13399. if( battle_config.mail_daily_count ){
  13400. mail_refresh_remaining_amount(sd);
  13401. }
  13402. #if PACKETVER >= 20170419
  13403. // Always send all
  13404. i = md->amount;
  13405. #else
  13406. // If a starting mail id was sent
  13407. if( mailID != 0 ){
  13408. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13409. // Unknown mail
  13410. if( i == md->amount ){
  13411. // Ignore the request for now
  13412. return; // TODO: Should we just show the first page instead?
  13413. }
  13414. // It was actually the oldest/first mail, there is no further page
  13415. if( i == 0 ){
  13416. return;
  13417. }
  13418. // We actually want the next/older mail
  13419. i -= 1;
  13420. }else{
  13421. i = md->amount;
  13422. }
  13423. #endif
  13424. // Count the remaining mails from the starting mail or the beginning
  13425. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13426. for( j = i, remaining = 0; j >= 0; j-- ){
  13427. msg = &md->msg[j];
  13428. if (msg->id < 1)
  13429. continue;
  13430. #if PACKETVER < 20170419
  13431. if (msg->type != type)
  13432. continue;
  13433. #endif
  13434. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13435. continue;
  13436. remaining++;
  13437. }
  13438. #if PACKETVER >= 20170419
  13439. // Always send all
  13440. amount = remaining;
  13441. #else
  13442. if( remaining > MAIL_PAGE_SIZE ){
  13443. amount = MAIL_PAGE_SIZE;
  13444. }else{
  13445. amount = remaining;
  13446. }
  13447. #endif
  13448. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13449. WFIFOW(fd, 0) = cmd;
  13450. #if PACKETVER >= 20170419
  13451. WFIFOB(fd, 4) = 1; // Unknown
  13452. offset = 5;
  13453. #else
  13454. WFIFOB(fd, 4) = type;
  13455. WFIFOB(fd, 5) = amount;
  13456. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13457. offset = 7;
  13458. #endif
  13459. for( amount = 0; i >= 0; i-- ){
  13460. msg = &md->msg[i];
  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. #if PACKETVER >= 20170419
  13470. WFIFOB(fd, offset) = msg->type;
  13471. offset += 1;
  13472. #endif
  13473. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13474. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13475. mailType = MAIL_TYPE_TEXT; // Normal letter
  13476. if( msg->zeny > 0 ){
  13477. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13478. }
  13479. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13480. if( msg->item[k].nameid > 0 ){
  13481. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13482. break;
  13483. }
  13484. }
  13485. #if PACKETVER >= 20170419
  13486. // If it came from an npc?
  13487. if( !msg->send_id ){
  13488. mailType |= MAIL_TYPE_NPC;
  13489. }
  13490. #endif
  13491. WFIFOB(fd, offset + 9) = mailType;
  13492. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13493. #if PACKETVER < 20170419
  13494. // How much time has passed since you received the mail
  13495. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13496. offset += 4;
  13497. #endif
  13498. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13499. if( msg->scheduled_deletion > 0 ){
  13500. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13501. }else{
  13502. // Fake the scheduled deletion to one year in the future
  13503. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13504. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13505. }
  13506. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13507. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13508. offset += 40 + titleLength;
  13509. }
  13510. WFIFOW(fd, 2) = (int16)offset;
  13511. WFIFOSET(fd, offset);
  13512. #endif
  13513. }
  13514. /// Mail inbox list request.
  13515. /// 023f (CZ_MAIL_GET_LIST)
  13516. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13517. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13518. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13519. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13520. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13521. void clif_parse_Mail_refreshinbox(int fd, map_session_data *sd){
  13522. if( mail_invalid_operation( sd ) ){
  13523. return;
  13524. }
  13525. #if PACKETVER < 20150513
  13526. struct mail_data* md = &sd->mail.inbox;
  13527. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13528. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13529. else
  13530. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13531. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13532. mail_removezeny(sd, false);
  13533. #else
  13534. int cmd = RFIFOW(fd, 0);
  13535. #if PACKETVER < 20170419
  13536. uint8 openType = RFIFOB(fd, 2);
  13537. uint64 mailId = RFIFOQ(fd, 3);
  13538. #else
  13539. uint8 openType;
  13540. uint64 mailId = RFIFOQ(fd, 2);
  13541. int i;
  13542. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13543. if( i == MAIL_MAX_INBOX ){
  13544. openType = MAIL_INBOX_NORMAL;
  13545. mailId = 0;
  13546. }else{
  13547. openType = sd->mail.inbox.msg[i].type;
  13548. mailId = 0;
  13549. }
  13550. #endif
  13551. switch( openType ){
  13552. case MAIL_INBOX_NORMAL:
  13553. case MAIL_INBOX_ACCOUNT:
  13554. case MAIL_INBOX_RETURNED:
  13555. break;
  13556. default:
  13557. // Unknown type: ignore request
  13558. return;
  13559. }
  13560. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13561. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13562. return;
  13563. }
  13564. // If it is not a next page request
  13565. if( cmd != 0x9ee ){
  13566. mailId = 0;
  13567. }
  13568. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13569. #endif
  13570. }
  13571. /// Opens a mail
  13572. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13573. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13574. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13575. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13576. /// { }*n
  13577. // TODO: Packet description => for repeated block
  13578. void clif_Mail_read( map_session_data *sd, int mail_id ){
  13579. int i, fd = sd->fd;
  13580. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13581. if( i == MAIL_MAX_INBOX ) {
  13582. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13583. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13584. return;
  13585. } else {
  13586. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13587. struct item *item;
  13588. int msg_len = strlen(msg->body);
  13589. if( msg_len == 0 ) {
  13590. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13591. msg_len = strlen(msg->body);
  13592. }
  13593. #if PACKETVER < 20150513
  13594. item = &msg->item[0];
  13595. int len = 101 + msg_len;
  13596. WFIFOHEAD(fd,len);
  13597. WFIFOW(fd,0) = 0x242;
  13598. WFIFOW(fd,2) = len;
  13599. WFIFOL(fd,4) = msg->id;
  13600. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13601. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13602. WFIFOL(fd,72) = 0;
  13603. WFIFOL(fd,76) = msg->zeny;
  13604. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13605. if( item->nameid && data != nullptr ) {
  13606. WFIFOL(fd,80) = item->amount;
  13607. WFIFOW(fd,84) = client_nameid( item->nameid );
  13608. WFIFOW(fd,86) = itemtype( item->nameid );
  13609. WFIFOB(fd,88) = item->identify;
  13610. WFIFOB(fd,89) = item->attribute;
  13611. WFIFOB(fd,90) = item->refine;
  13612. WFIFOW(fd,91) = item->card[0];
  13613. WFIFOW(fd,93) = item->card[1];
  13614. WFIFOW(fd,95) = item->card[2];
  13615. WFIFOW(fd,97) = item->card[3];
  13616. } else // no item, set all to zero
  13617. memset(WFIFOP(fd,80), 0x00, 19);
  13618. WFIFOB(fd,99) = (unsigned char)msg_len;
  13619. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13620. WFIFOSET(fd,len);
  13621. #else
  13622. msg_len += 1; // Zero Termination
  13623. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13624. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13625. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13626. p->opentype = msg->type;
  13627. p->MailID = msg->id;
  13628. p->TextcontentsLength = msg_len;
  13629. p->zeny = msg->zeny;
  13630. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13631. p->PacketLength += p->TextcontentsLength;
  13632. p->ItemCnt = 0;
  13633. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13634. item = &msg->item[j];
  13635. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13636. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13637. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13638. mailitem->ITID = client_nameid( item->nameid );
  13639. mailitem->count = item->amount;
  13640. mailitem->type = itemtype( item->nameid );
  13641. mailitem->IsIdentified = item->identify ? 1 : 0;
  13642. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13643. mailitem->refiningLevel = item->refine;
  13644. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13645. mailitem->viewSprite = data->look;
  13646. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13647. clif_addcards( &mailitem->slot, item );
  13648. clif_add_random_options( mailitem->option_data, *item );
  13649. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13650. mailitem->grade = item->enchantgrade;
  13651. #endif
  13652. p->PacketLength += sizeof( *mailitem );
  13653. p->ItemCnt++;
  13654. }
  13655. }
  13656. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13657. #endif
  13658. if (msg->status == MAIL_UNREAD) {
  13659. msg->status = MAIL_READ;
  13660. intif_Mail_read(mail_id);
  13661. clif_parse_Mail_refreshinbox(fd, sd);
  13662. sd->mail.inbox.unread--;
  13663. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13664. }
  13665. }
  13666. }
  13667. /// Request to open a mail.
  13668. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13669. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13670. void clif_parse_Mail_read(int fd, map_session_data *sd){
  13671. #if PACKETVER < 20150513
  13672. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13673. #else
  13674. //uint8 openType = RFIFOB(fd, 2);
  13675. int mail_id = (int)RFIFOQ(fd, 3);
  13676. #endif
  13677. if( mail_id <= 0 )
  13678. return;
  13679. if( mail_invalid_operation(sd) )
  13680. return;
  13681. clif_Mail_read(sd, mail_id);
  13682. }
  13683. /// Allow a player to begin writing a mail
  13684. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13685. void clif_send_Mail_beginwrite_ack( map_session_data *sd, char* name, bool success ){
  13686. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13687. p.PacketType = rodexopenwrite;
  13688. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13689. p.result = success;
  13690. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13691. }
  13692. /// Request to start writing a mail
  13693. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13694. void clif_parse_Mail_beginwrite( int fd, map_session_data *sd ){
  13695. char name[NAME_LENGTH];
  13696. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13697. if( mail_invalid_operation( sd ) ){
  13698. return;
  13699. }
  13700. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13701. clif_send_Mail_beginwrite_ack(sd, name, false);
  13702. return;
  13703. }
  13704. mail_clear(sd);
  13705. sd->state.mail_writing = true;
  13706. clif_send_Mail_beginwrite_ack(sd, name,true);
  13707. }
  13708. /// Notification that the client cancelled writing a mail
  13709. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13710. void clif_parse_Mail_cancelwrite( int fd, map_session_data *sd ){
  13711. sd->state.mail_writing = false;
  13712. }
  13713. /// Give the client information about the recipient, if available
  13714. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13715. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13716. void clif_Mail_Receiver_Ack( map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13717. #if PACKETVER >= 20141119
  13718. PACKET_ZC_CHECKNAME p = { 0 };
  13719. p.PacketType = HEADER_ZC_CHECKNAME;
  13720. p.CharId = char_id;
  13721. p.Class = class_;
  13722. p.BaseLevel = level;
  13723. #if PACKETVER >= 20160302
  13724. strncpy(p.Name, name, NAME_LENGTH);
  13725. #endif
  13726. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13727. #endif
  13728. }
  13729. /// Request information about the recipient
  13730. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13731. void clif_parse_Mail_Receiver_Check(int fd, map_session_data *sd) {
  13732. #if PACKETVER >= 20140423
  13733. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13734. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13735. #else
  13736. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13737. #endif
  13738. static char name[NAME_LENGTH];
  13739. if( mail_invalid_operation( sd ) ){
  13740. return;
  13741. }
  13742. safestrncpy(name, p->Name, NAME_LENGTH);
  13743. intif_mail_checkreceiver(sd, name);
  13744. #endif
  13745. }
  13746. /// Request to receive mail's attachment.
  13747. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13748. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13749. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13750. void clif_parse_Mail_getattach( int fd, map_session_data *sd ){
  13751. int i;
  13752. struct mail_message* msg;
  13753. #if PACKETVER < 20150513
  13754. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13755. int attachment = MAIL_ATT_ALL;
  13756. #else
  13757. uint16 packet_id = RFIFOW(fd, 0);
  13758. int mail_id = (int)RFIFOQ(fd, 2);
  13759. //int openType = RFIFOB(fd, 10);
  13760. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13761. #endif
  13762. if( !chrif_isconnected() )
  13763. return;
  13764. if( mail_id <= 0 )
  13765. return;
  13766. if( mail_invalid_operation(sd) )
  13767. return;
  13768. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13769. if( i == MAIL_MAX_INBOX )
  13770. return;
  13771. msg = &sd->mail.inbox.msg[i];
  13772. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13773. attachment &= ~MAIL_ATT_ZENY;
  13774. }
  13775. if( attachment&MAIL_ATT_ITEM ){
  13776. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13777. // No items were found
  13778. if( i == MAIL_MAX_ITEM ){
  13779. attachment &= ~MAIL_ATT_ITEM;
  13780. }
  13781. }
  13782. // Either no attachment requested at all or there are no zeny or items in the mail
  13783. if( attachment == MAIL_ATT_NONE ){
  13784. return;
  13785. }
  13786. if( attachment&MAIL_ATT_ZENY ){
  13787. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13788. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13789. return;
  13790. }else{
  13791. // Store the pending zeny (required for the "retrieve all" feature)
  13792. sd->mail.pending_zeny += msg->zeny;
  13793. // To make sure another request fails
  13794. msg->zeny = 0;
  13795. }
  13796. }
  13797. if( attachment&MAIL_ATT_ITEM ){
  13798. int slots = 0, totalweight = 0;
  13799. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13800. struct item* item = &msg->item[i];
  13801. if( item->nameid > 0 && item->amount > 0 ){
  13802. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13803. if(data == nullptr)
  13804. continue;
  13805. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13806. case CHKADDITEM_NEW:
  13807. slots += data->inventorySlotNeeded( item->amount );
  13808. break;
  13809. case CHKADDITEM_OVERAMOUNT:
  13810. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13811. return;
  13812. }
  13813. totalweight += data->weight * item->amount;
  13814. }
  13815. }
  13816. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13817. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13818. return;
  13819. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13820. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13821. return;
  13822. }
  13823. // To make sure another request fails
  13824. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13825. // Store the pending weight (required for the "retrieve all" feature)
  13826. sd->mail.pending_weight += totalweight;
  13827. // Store the pending slots (required for the "retrieve all" feature)
  13828. sd->mail.pending_slots += slots;
  13829. }
  13830. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13831. }
  13832. /// Request to delete a mail.
  13833. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13834. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13835. void clif_parse_Mail_delete(int fd, map_session_data *sd){
  13836. #if PACKETVER < 20150513
  13837. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13838. #else
  13839. //int openType = RFIFOB(fd, 2);
  13840. int mail_id = (int)RFIFOQ(fd, 3);
  13841. #endif
  13842. int i, j;
  13843. if( !chrif_isconnected() )
  13844. return;
  13845. if( mail_id <= 0 )
  13846. return;
  13847. if( mail_invalid_operation(sd) )
  13848. return;
  13849. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13850. if (i < MAIL_MAX_INBOX) {
  13851. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13852. // can't delete mail without removing zeny first
  13853. if( msg->zeny > 0 ){
  13854. clif_mail_delete(sd, msg, false);
  13855. return;
  13856. }
  13857. // can't delete mail without removing attachment(s) first
  13858. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13859. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13860. clif_mail_delete(sd, msg, false);
  13861. return;
  13862. }
  13863. }
  13864. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13865. sd->mail.inbox.unread--;
  13866. clif_Mail_new(sd,0,NULL,NULL);
  13867. }
  13868. }
  13869. }
  13870. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13871. /// 0273 <mail id>.L <receive name>.24B
  13872. void clif_parse_Mail_return(int fd, map_session_data *sd){
  13873. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13874. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13875. //ShowDump( p, sizeof( p ) );
  13876. int mail_id = p->msgId;
  13877. // not supported for now
  13878. return;
  13879. #else
  13880. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13881. #endif
  13882. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13883. int i;
  13884. if( mail_id <= 0 )
  13885. return;
  13886. if( mail_invalid_operation(sd) )
  13887. return;
  13888. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13889. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13890. intif_Mail_return(sd->status.char_id, mail_id);
  13891. else
  13892. clif_Mail_return(sd->fd, mail_id, 1);
  13893. }
  13894. /// Request to add an item or Zeny to mail.
  13895. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13896. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13897. void clif_parse_Mail_setattach(int fd, map_session_data *sd){
  13898. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13899. uint16 idx = RFIFOW(fd,info->pos[0]);
  13900. #if PACKETVER < 20150513
  13901. int amount = RFIFOL(fd,info->pos[1]);
  13902. #else
  13903. int amount = RFIFOW(fd,info->pos[1]);
  13904. #endif
  13905. unsigned char flag;
  13906. if( !chrif_isconnected() )
  13907. return;
  13908. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13909. return;
  13910. if (sd->inventory_data[server_index(idx)] == nullptr)
  13911. return;
  13912. if( mail_invalid_operation( sd ) ){
  13913. return;
  13914. }
  13915. flag = mail_setitem(sd, idx, amount);
  13916. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13917. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13918. }else{
  13919. clif_Mail_setattachment(sd,idx,amount,flag);
  13920. }
  13921. }
  13922. /// Remove an item from a mail
  13923. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13924. void clif_mail_removeitem( map_session_data* sd, bool success, int index, int amount ){
  13925. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13926. p.PacketType = rodexremoveitem;
  13927. p.result = success;
  13928. p.index = index;
  13929. p.cnt = amount;
  13930. int total = 0;
  13931. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13932. if( sd->mail.item[i].nameid == 0 ){
  13933. break;
  13934. }
  13935. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13936. }
  13937. p.weight = total;
  13938. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13939. }
  13940. /// Request to reset mail item and/or Zeny
  13941. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13942. /// type:
  13943. /// 0 = reset all
  13944. /// 1 = remove item
  13945. /// 2 = remove zeny
  13946. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13947. void clif_parse_Mail_winopen(int fd, map_session_data *sd)
  13948. {
  13949. #if PACKETVER < 20150513
  13950. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13951. if (type == 0 || type == 1)
  13952. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13953. if (type == 0 || type == 2)
  13954. mail_removezeny(sd, false);
  13955. #else
  13956. uint16 index = RFIFOW(fd, 2);
  13957. uint16 count = RFIFOW(fd, 4);
  13958. mail_removeitem(sd,0,index,count);
  13959. #endif
  13960. }
  13961. /// Request to send mail
  13962. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13963. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13964. /// 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)
  13965. void clif_parse_Mail_send(int fd, map_session_data *sd){
  13966. #if PACKETVER < 20150513
  13967. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13968. if( !chrif_isconnected() )
  13969. return;
  13970. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13971. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13972. return;
  13973. }
  13974. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13975. #else
  13976. uint16 length = RFIFOW(fd, 2);
  13977. if( length < 0x3e ){
  13978. ShowWarning("Too short...\n");
  13979. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13980. return;
  13981. }
  13982. if( mail_invalid_operation( sd ) ){
  13983. return;
  13984. }
  13985. // Forged request without a begin writing packet?
  13986. if( !sd->state.mail_writing ){
  13987. return; // Ignore it
  13988. }
  13989. char receiver[NAME_LENGTH];
  13990. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13991. // char sender[NAME_LENGTH];
  13992. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13993. uint64 zeny = RFIFOQ(fd, 52);
  13994. uint16 titleLength = RFIFOW(fd, 60);
  13995. uint16 textLength = RFIFOW(fd, 62);
  13996. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13997. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13998. char title[MAIL_TITLE_LENGTH];
  13999. char text[MAIL_BODY_LENGTH];
  14000. #if PACKETVER <= 20160330
  14001. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  14002. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  14003. #else
  14004. // 64 = <char id>.L
  14005. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  14006. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  14007. #endif
  14008. if( zeny > 0 ){
  14009. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  14010. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  14011. return;
  14012. }
  14013. }
  14014. mail_send(sd, receiver, title, text, realTextLength);
  14015. #endif
  14016. }
  14017. /// AUCTION SYSTEM
  14018. /// By Zephyrus
  14019. ///
  14020. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  14021. /// 025f <type>.L
  14022. /// type:
  14023. /// 0 = open
  14024. /// 1 = close
  14025. void clif_Auction_openwindow(map_session_data *sd)
  14026. {
  14027. int fd = sd->fd;
  14028. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  14029. return;
  14030. if( !battle_config.feature_auction )
  14031. return;
  14032. WFIFOHEAD(fd,packet_len(0x25f));
  14033. WFIFOW(fd,0) = 0x25f;
  14034. WFIFOL(fd,2) = 0;
  14035. WFIFOSET(fd,packet_len(0x25f));
  14036. }
  14037. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  14038. /// 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 }*
  14039. void clif_Auction_results(map_session_data *sd, short count, short pages, uint8 *buf)
  14040. {
  14041. int i, fd = sd->fd, len = sizeof(struct auction_data);
  14042. struct auction_data auction;
  14043. WFIFOHEAD(fd,12 + (count * 83));
  14044. WFIFOW(fd,0) = 0x252;
  14045. WFIFOW(fd,2) = 12 + (count * 83);
  14046. WFIFOL(fd,4) = pages;
  14047. WFIFOL(fd,8) = count;
  14048. for( i = 0; i < count; i++ ) {
  14049. int k = 12 + (i * 83);
  14050. memcpy(&auction, RBUFP(buf,i * len), len);
  14051. WFIFOL(fd,k) = auction.auction_id;
  14052. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  14053. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  14054. WFIFOL(fd,30+k) = auction.type;
  14055. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  14056. WFIFOB(fd,36+k) = auction.item.identify;
  14057. WFIFOB(fd,37+k) = auction.item.attribute;
  14058. WFIFOB(fd,38+k) = auction.item.refine;
  14059. WFIFOW(fd,39+k) = auction.item.card[0];
  14060. WFIFOW(fd,41+k) = auction.item.card[1];
  14061. WFIFOW(fd,43+k) = auction.item.card[2];
  14062. WFIFOW(fd,45+k) = auction.item.card[3];
  14063. WFIFOL(fd,47+k) = auction.price;
  14064. WFIFOL(fd,51+k) = auction.buynow;
  14065. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  14066. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  14067. }
  14068. WFIFOSET(fd,WFIFOW(fd,2));
  14069. }
  14070. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  14071. /// 0256 <index>.W <result>.B
  14072. /// result:
  14073. /// 0 = success
  14074. /// 1 = failure
  14075. static void clif_Auction_setitem(int fd, int index, bool fail)
  14076. {
  14077. WFIFOHEAD(fd,packet_len(0x256));
  14078. WFIFOW(fd,0) = 0x256;
  14079. WFIFOW(fd,2) = index;
  14080. WFIFOB(fd,4) = fail;
  14081. WFIFOSET(fd,packet_len(0x256));
  14082. }
  14083. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  14084. /// 024b <type>.W
  14085. /// type:
  14086. /// 0 = create (any other action in auction window)
  14087. /// 1 = cancel (cancel pressed on register tab)
  14088. /// ? = junk, uninitialized value (ex. when switching between list filters)
  14089. void clif_parse_Auction_cancelreg(int fd, map_session_data *sd){
  14090. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14091. if( sd->auction.amount > 0 )
  14092. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  14093. sd->auction.amount = 0;
  14094. }
  14095. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  14096. /// 024c <index>.W <count>.L
  14097. void clif_parse_Auction_setitem(int fd, map_session_data *sd){
  14098. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14099. int idx = RFIFOW(fd,info->pos[0]) - 2;
  14100. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  14101. if( !battle_config.feature_auction )
  14102. return;
  14103. if( sd->auction.amount > 0 )
  14104. sd->auction.amount = 0;
  14105. if( idx < 0 || idx >= MAX_INVENTORY ) {
  14106. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  14107. return;
  14108. }
  14109. 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.
  14110. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  14111. return;
  14112. }
  14113. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  14114. 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) )
  14115. { // Consumable or pets are not allowed
  14116. clif_Auction_setitem(sd->fd, idx, true);
  14117. return;
  14118. }
  14119. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  14120. !sd->inventory.u.items_inventory[idx].identify ||
  14121. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  14122. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  14123. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  14124. clif_Auction_setitem(sd->fd, idx, true);
  14125. return;
  14126. }
  14127. sd->auction.index = idx;
  14128. sd->auction.amount = amount;
  14129. clif_Auction_setitem(fd, idx + 2, false);
  14130. }
  14131. /// Result from an auction action (ZC_AUCTION_RESULT).
  14132. /// 0250 <result>.B
  14133. /// result:
  14134. /// 0 = You have failed to bid into the auction
  14135. /// 1 = You have successfully bid in the auction
  14136. /// 2 = The auction has been canceled
  14137. /// 3 = An auction with at least one bidder cannot be canceled
  14138. /// 4 = You cannot register more than 5 items in an auction at a time
  14139. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14140. /// 6 = You have won the auction
  14141. /// 7 = You have failed to win the auction
  14142. /// 8 = You do not have enough Zeny
  14143. /// 9 = You cannot place more than 5 bids at a time
  14144. void clif_Auction_message(int fd, unsigned char flag)
  14145. {
  14146. WFIFOHEAD(fd,packet_len(0x250));
  14147. WFIFOW(fd,0) = 0x250;
  14148. WFIFOB(fd,2) = flag;
  14149. WFIFOSET(fd,packet_len(0x250));
  14150. }
  14151. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14152. /// 025e <result>.W
  14153. /// result:
  14154. /// 0 = You have ended the auction
  14155. /// 1 = You cannot end the auction
  14156. /// 2 = Auction ID is incorrect
  14157. void clif_Auction_close(int fd, unsigned char flag)
  14158. {
  14159. WFIFOHEAD(fd,packet_len(0x25e));
  14160. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14161. WFIFOW(fd,2) = flag;
  14162. WFIFOSET(fd,packet_len(0x25e));
  14163. }
  14164. /// Request to add an auction (CZ_AUCTION_ADD).
  14165. /// 024d <now money>.L <max money>.L <delete hour>.W
  14166. void clif_parse_Auction_register(int fd, map_session_data *sd)
  14167. {
  14168. struct auction_data auction;
  14169. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14170. if( !battle_config.feature_auction )
  14171. return;
  14172. auction.price = RFIFOL(fd,info->pos[0]);
  14173. auction.buynow = RFIFOL(fd,info->pos[1]);
  14174. auction.hours = RFIFOW(fd,info->pos[2]);
  14175. // Invalid Situations...
  14176. if( sd->auction.amount < 1 ) {
  14177. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14178. return;
  14179. }
  14180. if( auction.price >= auction.buynow ) {
  14181. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14182. return;
  14183. }
  14184. if( auction.hours < 1 || auction.hours > 48 ) {
  14185. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14186. return;
  14187. }
  14188. // Auction checks...
  14189. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14190. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14191. clif_Auction_message(fd, 2); // The auction has been canceled
  14192. return;
  14193. }
  14194. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14195. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14196. return;
  14197. }
  14198. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14199. auction.buynow = battle_config.auction_maximumprice;
  14200. if( auction.price >= auction.buynow )
  14201. auction.price = auction.buynow - 1;
  14202. }
  14203. auction.auction_id = 0;
  14204. auction.seller_id = sd->status.char_id;
  14205. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14206. auction.buyer_id = 0;
  14207. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14208. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14209. {
  14210. clif_Auction_message(fd, 2); // The auction has been canceled
  14211. return;
  14212. }
  14213. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14214. if( id == nullptr )
  14215. { // Just in case
  14216. clif_Auction_message(fd, 2); // The auction has been canceled
  14217. return;
  14218. }
  14219. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14220. auction.type = id->type;
  14221. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14222. auction.item.amount = 1;
  14223. auction.timestamp = 0;
  14224. if( !intif_Auction_register(&auction) )
  14225. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14226. else
  14227. {
  14228. int zeny = auction.hours*battle_config.auction_feeperhour;
  14229. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14230. sd->auction.amount = 0;
  14231. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION);
  14232. }
  14233. }
  14234. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14235. /// 024e <auction id>.L
  14236. void clif_parse_Auction_cancel(int fd, map_session_data *sd){
  14237. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14238. intif_Auction_cancel(sd->status.char_id, auction_id);
  14239. }
  14240. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14241. /// 025d <auction id>.L
  14242. void clif_parse_Auction_close(int fd, map_session_data *sd){
  14243. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14244. intif_Auction_close(sd->status.char_id, auction_id);
  14245. }
  14246. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14247. /// 024f <auction id>.L <money>.L
  14248. void clif_parse_Auction_bid(int fd, map_session_data *sd){
  14249. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14250. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14251. int bid = RFIFOL(fd,info->pos[1]);
  14252. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14253. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14254. return;
  14255. }
  14256. if( bid <= 0 )
  14257. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14258. else if( bid > sd->status.zeny )
  14259. clif_Auction_message(fd, 8); // You do not have enough zeny
  14260. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14261. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14262. else {
  14263. pc_payzeny(sd, bid, LOG_TYPE_AUCTION);
  14264. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14265. }
  14266. }
  14267. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14268. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14269. /// search type:
  14270. /// 0 = armor
  14271. /// 1 = weapon
  14272. /// 2 = card
  14273. /// 3 = misc
  14274. /// 4 = name search
  14275. /// 5 = auction id search
  14276. void clif_parse_Auction_search(int fd, map_session_data* sd){
  14277. char search_text[NAME_LENGTH];
  14278. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14279. short type = RFIFOW(fd,info->pos[0]);
  14280. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14281. int page = RFIFOW(fd,info->pos[3]);
  14282. if( !battle_config.feature_auction )
  14283. return;
  14284. clif_parse_Auction_cancelreg(fd, sd);
  14285. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14286. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14287. }
  14288. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14289. /// 025c <type>.W
  14290. /// type:
  14291. /// 0 = sell (own auctions)
  14292. /// 1 = buy (own bids)
  14293. void clif_parse_Auction_buysell(int fd, map_session_data* sd)
  14294. {
  14295. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14296. if( !battle_config.feature_auction )
  14297. return;
  14298. clif_parse_Auction_cancelreg(fd, sd);
  14299. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14300. }
  14301. /// CASH/POINT SHOP
  14302. ///
  14303. void clif_cashshop_open( map_session_data* sd, int tab ){
  14304. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14305. nullpo_retv( sd );
  14306. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14307. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14308. p.cashPoints = sd->cashPoints;
  14309. p.kafraPoints = sd->kafraPoints;
  14310. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14311. p.tab = tab;
  14312. #endif
  14313. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14314. #endif
  14315. }
  14316. void clif_parse_cashshop_open_request( int fd, map_session_data* sd ){
  14317. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14318. nullpo_retv( sd );
  14319. int tab = 0;
  14320. #if PACKETVER >= 20191224
  14321. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14322. tab = p->tab;
  14323. #endif
  14324. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14325. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14326. return;
  14327. }
  14328. sd->state.cashshop_open = true;
  14329. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14330. clif_cashshop_open( sd, tab );
  14331. #endif
  14332. }
  14333. void clif_parse_cashshop_close( int fd, map_session_data* sd ){
  14334. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14335. sd->state.cashshop_open = false;
  14336. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14337. // No need to do anything here
  14338. #endif
  14339. }
  14340. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14341. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14342. void clif_parse_CashShopReqTab(int fd, map_session_data *sd) {
  14343. #if PACKETVER_MAIN_NUM >= 20100824 || PACKETVER_RE_NUM >= 20100824 || defined(PACKETVER_ZERO)
  14344. struct PACKET_CZ_REQ_SE_CASH_TAB_CODE* p_in = (struct PACKET_CZ_REQ_SE_CASH_TAB_CODE*)RFIFOP( fd, 0 );
  14345. // TODO: most likely wrong answer packet. Most likely HEADER_ZC_ACK_SE_CASH_ITEM_LIST (0x847) would be correct [Lemongrass]
  14346. // [4144] packet exists only in 2011 and was dropped after
  14347. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14348. std::shared_ptr<s_cash_item_tab> tab = cash_shop_db.find( static_cast<e_cash_shop_tab>( p_in->tab ) );
  14349. if( tab == nullptr ){
  14350. return;
  14351. }
  14352. // Skip empty tabs, the client only expects filled ones
  14353. if( tab->items.empty() ){
  14354. return;
  14355. }
  14356. #if !(PACKETVER_SUPPORTS_SALES)
  14357. if( tab->tab == CASHSHOP_TAB_SALE ){
  14358. return;
  14359. }
  14360. #endif
  14361. struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2* p = (struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2*)packet_buffer;
  14362. p->packetType = HEADER_ZC_ACK_SE_CASH_ITEM_LIST2;
  14363. p->packetLength = sizeof( struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2 );
  14364. p->tab = tab->tab;
  14365. p->count = 0;
  14366. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14367. p->items[p->count].itemId = client_nameid( item->nameid );
  14368. p->items[p->count].price = item->price;
  14369. p->packetLength += sizeof( struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2_sub );
  14370. p->count++;
  14371. }
  14372. clif_send( p, p->packetLength, &sd->bl, SELF );
  14373. #endif
  14374. #endif
  14375. }
  14376. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14377. void clif_cashshop_list( map_session_data* sd ){
  14378. nullpo_retv( sd );
  14379. for( const auto& pair : cash_shop_db ){
  14380. std::shared_ptr<s_cash_item_tab> tab = pair.second;
  14381. // Skip empty tabs, the client only expects filled ones
  14382. if( tab->items.empty() ){
  14383. continue;
  14384. }
  14385. #if !(PACKETVER_SUPPORTS_SALES)
  14386. if( tab->tab == CASHSHOP_TAB_SALE ){
  14387. continue;
  14388. }
  14389. #endif
  14390. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)packet_buffer;
  14391. p->packetType = HEADER_ZC_ACK_SCHEDULER_CASHITEM;
  14392. p->packetLength = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM );
  14393. p->count = 0;
  14394. p->tabNum = tab->tab;
  14395. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14396. p->items[p->count].itemId = client_nameid( item->nameid );
  14397. p->items[p->count].price = item->price;
  14398. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14399. struct item_data* id = itemdb_search( item->nameid );
  14400. if( id == nullptr ){
  14401. p->items[p->count].location = 0;
  14402. p->items[p->count].viewSprite = 0;
  14403. }else{
  14404. p->items[p->count].location = pc_equippoint_sub( sd, id );
  14405. p->items[p->count].viewSprite = id->look;
  14406. }
  14407. #endif
  14408. p->count++;
  14409. p->packetLength += sizeof( p->items[0] );
  14410. if( ( static_cast<size_t>( p->packetLength ) + sizeof( p->items[0] ) ) >= INT16_MAX ){
  14411. // Send current data
  14412. clif_send( p, p->packetLength, &sd->bl, SELF );
  14413. // Start a new packet
  14414. p->count = 0;
  14415. p->packetLength = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM );
  14416. }
  14417. }
  14418. clif_send( p, p->packetLength, &sd->bl, SELF );
  14419. }
  14420. }
  14421. void clif_parse_cashshop_list_request( int fd, map_session_data* sd ){
  14422. if( !sd->status.cashshop_sent ) {
  14423. clif_cashshop_list( sd );
  14424. #if PACKETVER_SUPPORTS_SALES
  14425. sale_notify_login(sd);
  14426. #endif
  14427. sd->status.cashshop_sent = true;
  14428. }
  14429. }
  14430. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14431. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14432. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14433. void clif_cashshop_show( map_session_data *sd, struct npc_data *nd ){
  14434. nullpo_retv( sd );
  14435. nullpo_retv( nd );
  14436. int fd = sd->fd;
  14437. if( !session_isActive( fd ) ){
  14438. return;
  14439. }
  14440. sd->npc_shopid = nd->bl.id;
  14441. int cost[2] = { 0, 0 };
  14442. npc_shop_currency_type( sd, nd, cost, true );
  14443. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST*)packet_buffer;
  14444. p->packetType = HEADER_ZC_PC_CASH_POINT_ITEMLIST;
  14445. p->packetLength = sizeof( *p );
  14446. p->cashPoints = cost[0];
  14447. #if PACKETVER >= 20070711
  14448. p->kafraPoints = cost[1];
  14449. #endif
  14450. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14451. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14452. p->items[i].price = nd->u.shop.shop_item[i].value;
  14453. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14454. p->items[i].itemType = itemtype( id->nameid );
  14455. p->items[i].itemId = client_nameid( id->nameid );
  14456. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14457. p->items[i].location = pc_equippoint_sub( sd, id );
  14458. p->items[i].viewSprite = id->look;
  14459. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14460. #endif
  14461. p->packetLength += sizeof( p->items[0] );
  14462. }
  14463. clif_send( p, p->packetLength, &sd->bl, SELF );
  14464. }
  14465. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14466. /// 0289 <cash point>.L <error>.W
  14467. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14468. /// error:
  14469. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14470. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14471. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14472. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14473. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14474. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14475. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14476. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14477. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14478. void clif_cashshop_ack(map_session_data* sd, int error)
  14479. {
  14480. int fd, cost[2] = { 0, 0 };
  14481. struct npc_data *nd;
  14482. nullpo_retv(sd);
  14483. fd = sd->fd;
  14484. nd = map_id2nd(sd->npc_shopid);
  14485. npc_shop_currency_type(sd, nd, cost, false);
  14486. WFIFOHEAD(fd, packet_len(0x289));
  14487. WFIFOW(fd,0) = 0x289;
  14488. WFIFOL(fd,2) = cost[0];
  14489. #if PACKETVER < 20070711
  14490. WFIFOW(fd,6) = TOW(error);
  14491. #else
  14492. WFIFOL(fd,6) = cost[1];
  14493. WFIFOW(fd,10) = TOW(error);
  14494. #endif
  14495. WFIFOSET(fd, packet_len(0x289));
  14496. }
  14497. void clif_cashshop_result( map_session_data *sd, t_itemid item_id, uint16 result ){
  14498. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14499. nullpo_retv( sd );
  14500. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet = {};
  14501. packet.packetType = HEADER_ZC_SE_PC_BUY_CASHITEM_RESULT;
  14502. if( item_id != 0 ){
  14503. packet.itemId = client_nameid( item_id );
  14504. }else{
  14505. packet.itemId = 0;
  14506. }
  14507. packet.result = result;
  14508. packet.cashPoints = sd->cashPoints;
  14509. packet.kafraPoints = sd->kafraPoints;
  14510. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  14511. #endif
  14512. }
  14513. /// Request to buy item(s) from cash shop.
  14514. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14515. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14516. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14517. void clif_parse_npccashshop_buy( int fd, map_session_data *sd ){
  14518. nullpo_retv( sd );
  14519. if( sd->state.trading || !sd->npc_shopid ){
  14520. clif_cashshop_ack( sd, 1 );
  14521. return;
  14522. }
  14523. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14524. #if PACKETVER < 20070711
  14525. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14526. #elif PACKETVER < 20101116
  14527. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14528. #else
  14529. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14530. 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 ){
  14531. 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 );
  14532. return;
  14533. }
  14534. std::vector<s_npc_buy_list> item_list = {};
  14535. item_list.reserve( p->count );
  14536. for( int i = 0; i < p->count; i++ ){
  14537. s_npc_buy_list item = {};
  14538. item.nameid = p->items[i].itemId;
  14539. item.qty = p->items[i].amount;
  14540. item_list.push_back( item );
  14541. }
  14542. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14543. #endif
  14544. }
  14545. /// Request to buy item(s) from cash shop.
  14546. /// 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)
  14547. void clif_parse_cashshop_buy( int fd, map_session_data *sd ){
  14548. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14549. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14550. 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 ){
  14551. 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 );
  14552. return;
  14553. }
  14554. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14555. }
  14556. /// Adoption System
  14557. ///
  14558. /// Adoption message (ZC_BABYMSG).
  14559. /// 0216 <msg>.L
  14560. /// msg:
  14561. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14562. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14563. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14564. void clif_Adopt_reply(map_session_data *sd, int type)
  14565. {
  14566. int fd = sd->fd;
  14567. WFIFOHEAD(fd,6);
  14568. WFIFOW(fd,0) = 0x216;
  14569. WFIFOL(fd,2) = type;
  14570. WFIFOSET(fd,6);
  14571. }
  14572. /// Adoption confirmation (ZC_REQ_BABY).
  14573. /// 01f6 <account id>.L <char id>.L <name>.B
  14574. void clif_Adopt_request(map_session_data *sd, map_session_data *src, int p_id)
  14575. {
  14576. int fd = sd->fd;
  14577. WFIFOHEAD(fd,34);
  14578. WFIFOW(fd,0) = 0x1f6;
  14579. WFIFOL(fd,2) = src->status.account_id;
  14580. WFIFOL(fd,6) = p_id;
  14581. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14582. WFIFOSET(fd,34);
  14583. }
  14584. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14585. /// 01f9 <account id>.L
  14586. void clif_parse_Adopt_request(int fd, map_session_data *sd)
  14587. {
  14588. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14589. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14590. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14591. {
  14592. tsd->adopt_invite = sd->status.account_id;
  14593. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14594. }
  14595. }
  14596. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14597. /// 01f7 <account id>.L <char id>.L <answer>.L
  14598. /// answer:
  14599. /// 0 = rejected
  14600. /// 1 = accepted
  14601. void clif_parse_Adopt_reply(int fd, map_session_data *sd){
  14602. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14603. int p1_id = RFIFOL(fd,info->pos[0]);
  14604. int p2_id = RFIFOL(fd,info->pos[1]);
  14605. int result = RFIFOL(fd,info->pos[2]);
  14606. map_session_data* p1_sd = map_id2sd(p1_id);
  14607. map_session_data* p2_sd = map_id2sd(p2_id);
  14608. int pid = sd->adopt_invite;
  14609. sd->adopt_invite = 0;
  14610. if( p1_sd == NULL || p2_sd == NULL )
  14611. return; // Both players need to be online
  14612. if( pid != p1_sd->status.account_id )
  14613. return; // Incorrect values
  14614. if( result == 0 )
  14615. return; // Rejected
  14616. pc_adoption(p1_sd, p2_sd, sd);
  14617. }
  14618. /// Convex Mirror
  14619. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B (ZC_BOSS_INFO)
  14620. /// infoType:
  14621. /// BOSS_INFO_NOT = No boss on this map.
  14622. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14623. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14624. /// BOSS_INFO_DEAD = Boss is dead.
  14625. void clif_bossmapinfo( map_session_data& sd, mob_data* md, e_bossmap_info flag ){
  14626. PACKET_ZC_BOSS_INFO p = {};
  14627. p.packetType = HEADER_ZC_BOSS_INFO;
  14628. p.type = flag;
  14629. switch (flag) {
  14630. case BOSS_INFO_NOT:
  14631. // No data required
  14632. break;
  14633. case BOSS_INFO_ALIVE_WITHMSG:
  14634. [[fallthrough]];
  14635. case BOSS_INFO_ALIVE:
  14636. p.x = md->bl.x;
  14637. p.y = md->bl.y;
  14638. break;
  14639. case BOSS_INFO_DEAD: {
  14640. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14641. unsigned int seconds;
  14642. int hours, minutes;
  14643. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14644. hours = seconds / (60 * 60);
  14645. seconds = seconds - (60 * 60 * hours);
  14646. minutes = seconds / 60;
  14647. p.minHours = hours;
  14648. p.minMinutes = minutes;
  14649. break;
  14650. }
  14651. }
  14652. if( md != nullptr ){
  14653. safestrncpy( p.name, md->db->jname.c_str(), sizeof( p.name ) );
  14654. }
  14655. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  14656. }
  14657. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14658. /// 02d6 <account id>.L
  14659. void clif_parse_ViewPlayerEquip(int fd, map_session_data* sd)
  14660. {
  14661. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14662. map_session_data* tsd = map_id2sd(aid);
  14663. if (!tsd)
  14664. return;
  14665. if (sd->bl.m != tsd->bl.m)
  14666. return;
  14667. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14668. clif_viewequip_ack(sd, tsd);
  14669. else
  14670. clif_msg(sd, VIEW_EQUIP_FAIL);
  14671. }
  14672. /// Request to a configuration.
  14673. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14674. /// type: see enum e_config_type
  14675. /// flag:
  14676. /// false = disabled
  14677. /// true = enabled
  14678. void clif_parse_configuration( int fd, map_session_data* sd ){
  14679. int cmd = RFIFOW(fd,0);
  14680. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14681. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14682. switch( type ){
  14683. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14684. sd->status.show_equip = flag;
  14685. break;
  14686. case CONFIG_CALL:
  14687. sd->status.disable_call = flag;
  14688. break;
  14689. case CONFIG_PET_AUTOFEED:
  14690. // Player can not click this if he does not have a pet
  14691. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14692. return;
  14693. }
  14694. sd->pd->pet.autofeed = flag;
  14695. break;
  14696. case CONFIG_HOMUNCULUS_AUTOFEED:
  14697. // Player can not click this if he does not have a homunculus or it is vaporized
  14698. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14699. return;
  14700. }
  14701. sd->hd->homunculus.autofeed = flag;
  14702. break;
  14703. default:
  14704. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14705. return;
  14706. }
  14707. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14708. }
  14709. /// Request to change party invitation tick.
  14710. /// value:
  14711. /// 0 = disabled
  14712. /// 1 = enabled
  14713. void clif_parse_PartyTick(int fd, map_session_data* sd)
  14714. {
  14715. bool flag = RFIFOB(fd,6) ? true : false;
  14716. sd->status.allow_party = flag;
  14717. clif_partytickack(sd, flag);
  14718. }
  14719. /// Questlog System [Kevin] [Inkfish]
  14720. ///
  14721. /**
  14722. * Safe check to init packet len & quest num for player.
  14723. * @param def_len
  14724. * @param info_len Length of each quest info.
  14725. * @param avail_quests Avail quests that player has.
  14726. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14727. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14728. **/
  14729. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14730. (*limit_out) = (0xFFFF - def_len) / info_len;
  14731. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14732. (*len_out) = ((*limit_out) * info_len) + def_len;
  14733. }
  14734. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14735. std::string race_name;
  14736. switch( objective->race ){
  14737. case RC_FORMLESS: race_name = "Formless"; break;
  14738. case RC_UNDEAD: race_name = "Undead"; break;
  14739. case RC_BRUTE: race_name = "Brute"; break;
  14740. case RC_PLANT: race_name = "Plant"; break;
  14741. case RC_INSECT: race_name = "Insect"; break;
  14742. case RC_FISH: race_name = "Fish"; break;
  14743. case RC_DEMON: race_name = "Demon"; break;
  14744. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14745. case RC_ANGEL: race_name = "Angel"; break;
  14746. case RC_DRAGON: race_name = "Dragon"; break;
  14747. default:
  14748. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14749. [[fallthrough]];
  14750. case RC_ALL: race_name = ""; break;
  14751. }
  14752. std::string size_name;
  14753. switch( objective->size ){
  14754. case SZ_SMALL: size_name = "Small"; break;
  14755. case SZ_MEDIUM: size_name = "Medium"; break;
  14756. case SZ_BIG: size_name = "Large"; break;
  14757. default:
  14758. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14759. [[fallthrough]];
  14760. case SZ_ALL: size_name = ""; break;
  14761. }
  14762. std::string ele_name;
  14763. switch( objective->element ){
  14764. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14765. case ELE_WATER: ele_name = "Water Element"; break;
  14766. case ELE_EARTH: ele_name = "Earth Element"; break;
  14767. case ELE_FIRE: ele_name = "Fire Element"; break;
  14768. case ELE_WIND: ele_name = "Wind Element"; break;
  14769. case ELE_POISON: ele_name = "Poison Element"; break;
  14770. case ELE_HOLY: ele_name = "Holy Element"; break;
  14771. case ELE_DARK: ele_name = "Shadow Element"; break;
  14772. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14773. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14774. default:
  14775. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14776. [[fallthrough]];
  14777. case ELE_ALL: ele_name = ""; break;
  14778. }
  14779. std::string str;
  14780. if( !objective->map_name.empty() ){
  14781. str += objective->map_name;
  14782. }
  14783. if( !race_name.empty() ){
  14784. if( !str.empty() ){
  14785. str += ", ";
  14786. }
  14787. str += race_name;
  14788. }
  14789. if( !size_name.empty() ){
  14790. if( !str.empty() ){
  14791. str += ", ";
  14792. }
  14793. str += size_name;
  14794. }
  14795. if( !ele_name.empty() ){
  14796. if( !str.empty() ){
  14797. str += ", ";
  14798. }
  14799. str += ele_name;
  14800. }
  14801. return str;
  14802. }
  14803. /// Sends list of all quest states
  14804. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14805. /// 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)
  14806. /// 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)
  14807. void clif_quest_send_list(map_session_data *sd)
  14808. {
  14809. nullpo_retv(sd);
  14810. int fd = sd->fd;
  14811. int i;
  14812. int offset = 8;
  14813. int limit = 0;
  14814. #if PACKETVER >= 20141022
  14815. #if PACKETVER >= 20150513
  14816. int size = 22 + NAME_LENGTH;
  14817. #else
  14818. int size = 10 + NAME_LENGTH;
  14819. #endif
  14820. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14821. WFIFOHEAD(fd,i);
  14822. #if PACKETVER >= 20150513
  14823. WFIFOW(fd, 0) = 0x9f8;
  14824. #else
  14825. WFIFOW(fd, 0) = 0x97a;
  14826. #endif
  14827. WFIFOL(fd, 4) = limit;
  14828. for (i = 0; i < limit; i++) {
  14829. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14830. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14831. offset += 4;
  14832. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14833. offset++;
  14834. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14835. offset += 4;
  14836. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14837. offset += 4;
  14838. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14839. offset += 2;
  14840. if (!qi->objectives.empty()) {
  14841. std::shared_ptr<s_mob_db> mob;
  14842. for (int j = 0; j < qi->objectives.size(); j++) {
  14843. mob = mob_db.find(qi->objectives[j]->mob_id);
  14844. e_race race = qi->objectives[j]->race;
  14845. e_size size = qi->objectives[j]->size;
  14846. e_element element = qi->objectives[j]->element;
  14847. #if PACKETVER >= 20150513
  14848. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14849. offset += 4;
  14850. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14851. offset += 4;
  14852. #endif
  14853. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14854. offset += 4;
  14855. #if PACKETVER >= 20150513
  14856. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14857. offset += 2;
  14858. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14859. offset += 2;
  14860. #endif
  14861. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14862. offset += 2;
  14863. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14864. offset += 2;
  14865. if (mob && qi->objectives[j]->mob_id > 0)
  14866. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14867. else
  14868. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14869. offset += NAME_LENGTH;
  14870. }
  14871. }
  14872. }
  14873. WFIFOW(fd, 2) = offset;
  14874. WFIFOSET(fd, offset);
  14875. #else
  14876. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14877. WFIFOHEAD(fd,i);
  14878. WFIFOW(fd, 0) = 0x2b1;
  14879. WFIFOL(fd, 4) = limit;
  14880. for (i = 0; i < limit; i++) {
  14881. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14882. offset += 4;
  14883. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14884. offset += 1;
  14885. }
  14886. WFIFOW(fd, 2) = offset;
  14887. WFIFOSET(fd, offset);
  14888. #endif
  14889. }
  14890. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14891. /// 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
  14892. void clif_quest_send_mission(map_session_data *sd)
  14893. {
  14894. nullpo_retv(sd);
  14895. int fd = sd->fd;
  14896. int limit = 0;
  14897. int len = sd->avail_quests*104+8;
  14898. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14899. WFIFOHEAD(fd, len);
  14900. WFIFOW(fd, 0) = 0x2b2;
  14901. WFIFOW(fd, 2) = len;
  14902. WFIFOL(fd, 4) = limit;
  14903. for (int i = 0; i < limit; i++) {
  14904. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14905. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14906. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14907. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14908. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14909. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14910. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14911. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14912. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14913. if (mob && qi->objectives[j]->mob_id > 0)
  14914. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14915. else
  14916. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14917. }
  14918. }
  14919. WFIFOSET(fd, len);
  14920. }
  14921. /// Notification about a new quest
  14922. /// 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)
  14923. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14924. /// 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)
  14925. void clif_quest_add(map_session_data *sd, struct quest *qd)
  14926. {
  14927. nullpo_retv(sd);
  14928. nullpo_retv(qd);
  14929. int fd = sd->fd;
  14930. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14931. if (!qi)
  14932. return;
  14933. #if PACKETVER >= 20150513
  14934. int cmd = 0x9f9;
  14935. #else
  14936. int cmd = 0x2b3;
  14937. #endif
  14938. WFIFOHEAD(fd, packet_len(cmd));
  14939. WFIFOW(fd, 0) = cmd;
  14940. WFIFOL(fd, 2) = qd->quest_id;
  14941. WFIFOB(fd, 6) = qd->state;
  14942. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14943. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14944. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14945. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14946. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14947. e_race race = qi->objectives[i]->race;
  14948. e_size size = qi->objectives[i]->size;
  14949. e_element element = qi->objectives[i]->element;
  14950. #if PACKETVER >= 20150513
  14951. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14952. offset += 4;
  14953. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14954. offset += 4;
  14955. #endif
  14956. 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
  14957. offset += 4;
  14958. #if PACKETVER >= 20150513
  14959. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14960. offset += 2;
  14961. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14962. offset += 2;
  14963. #endif
  14964. WFIFOW(fd, offset) = qd->count[i];
  14965. offset += 2;
  14966. if (mob && qi->objectives[i]->mob_id > 0)
  14967. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14968. else
  14969. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14970. offset += NAME_LENGTH;
  14971. }
  14972. WFIFOSET(fd, packet_len(cmd));
  14973. #if PACKETVER >= 20150513
  14974. int len = 4 + qi->objectives.size() * 12;
  14975. WFIFOHEAD(fd, len);
  14976. WFIFOW(fd, 0) = 0x8fe;
  14977. WFIFOW(fd, 2) = len;
  14978. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14979. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14980. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14981. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14982. WFIFOW(fd, offset + 10) = qd->count[i];
  14983. }
  14984. WFIFOSET(fd, len);
  14985. #endif
  14986. }
  14987. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14988. /// 02b4 <quest id>.L
  14989. void clif_quest_delete(map_session_data *sd, int quest_id)
  14990. {
  14991. int fd = sd->fd;
  14992. WFIFOHEAD(fd, packet_len(0x2b4));
  14993. WFIFOW(fd, 0) = 0x2b4;
  14994. WFIFOL(fd, 2) = quest_id;
  14995. WFIFOSET(fd, packet_len(0x2b4));
  14996. }
  14997. /// Notification of an update to the hunting mission counter
  14998. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14999. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  15000. void clif_quest_update_objective(map_session_data *sd, struct quest *qd)
  15001. {
  15002. int fd = sd->fd;
  15003. int offset = 6;
  15004. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  15005. int len = qi->objectives.size() * 12 + 6;
  15006. #if PACKETVER >= 20150513
  15007. int cmd = 0x9fa;
  15008. #else
  15009. int cmd = 0x2b5;
  15010. #endif
  15011. WFIFOHEAD(fd, len);
  15012. WFIFOW(fd, 0) = cmd;
  15013. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  15014. for (int i = 0; i < qi->objectives.size(); i++) {
  15015. WFIFOL(fd, offset) = qd->quest_id;
  15016. offset += 4;
  15017. #if PACKETVER >= 20150513
  15018. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15019. offset += 4;
  15020. #else
  15021. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  15022. offset += 4;
  15023. #endif
  15024. WFIFOW(fd, offset) = qi->objectives[i]->count;
  15025. offset += 2;
  15026. WFIFOW(fd, offset) = qd->count[i];
  15027. offset += 2;
  15028. }
  15029. WFIFOW(fd, 2) = offset;
  15030. WFIFOSET(fd, offset);
  15031. }
  15032. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  15033. /// 02b6 <quest id>.L <active>.B
  15034. void clif_parse_questStateAck(int fd, map_session_data *sd)
  15035. {
  15036. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15037. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  15038. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  15039. }
  15040. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  15041. /// 02b7 <quest id>.L <active>.B
  15042. void clif_quest_update_status(map_session_data *sd, int quest_id, bool active)
  15043. {
  15044. int fd = sd->fd;
  15045. WFIFOHEAD(fd, packet_len(0x2b7));
  15046. WFIFOW(fd, 0) = 0x2b7;
  15047. WFIFOL(fd, 2) = quest_id;
  15048. WFIFOB(fd, 6) = active;
  15049. WFIFOSET(fd, packet_len(0x2b7));
  15050. }
  15051. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  15052. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  15053. /// effect:
  15054. /// 0 = none
  15055. /// 1 = exclamation mark icon
  15056. /// 2 = question mark icon
  15057. /// color:
  15058. /// 0 = yellow
  15059. /// 1 = orange
  15060. /// 2 = green
  15061. /// 3 = purple
  15062. void clif_quest_show_event(map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  15063. {
  15064. #if PACKETVER >= 20090218
  15065. nullpo_retv(sd);
  15066. nullpo_retv(bl);
  15067. int fd = sd->fd;
  15068. WFIFOHEAD(fd, packet_len(0x446));
  15069. WFIFOW(fd, 0) = 0x446;
  15070. WFIFOL(fd, 2) = bl->id;
  15071. WFIFOW(fd, 6) = bl->x;
  15072. WFIFOW(fd, 8) = bl->y;
  15073. WFIFOW(fd, 10) = effect;
  15074. WFIFOW(fd, 12) = color;
  15075. WFIFOSET(fd, packet_len(0x446));
  15076. #endif
  15077. }
  15078. /// Mercenary System
  15079. ///
  15080. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  15081. /// 02a2 <var id>.W <value>.L
  15082. void clif_mercenary_updatestatus(map_session_data *sd, int type)
  15083. {
  15084. s_mercenary_data *md;
  15085. struct status_data *status;
  15086. int fd;
  15087. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15088. return;
  15089. fd = sd->fd;
  15090. status = &md->battle_status;
  15091. WFIFOHEAD(fd,packet_len(0x2a2));
  15092. WFIFOW(fd,0) = 0x2a2;
  15093. WFIFOW(fd,2) = type;
  15094. switch( type ) {
  15095. case SP_ATK1:
  15096. {
  15097. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15098. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  15099. }
  15100. break;
  15101. case SP_MATK1:
  15102. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  15103. break;
  15104. case SP_HIT:
  15105. WFIFOL(fd,4) = status->hit;
  15106. break;
  15107. case SP_CRITICAL:
  15108. WFIFOL(fd,4) = status->cri/10;
  15109. break;
  15110. case SP_DEF1:
  15111. WFIFOL(fd,4) = status->def;
  15112. break;
  15113. case SP_MDEF1:
  15114. WFIFOL(fd,4) = status->mdef;
  15115. break;
  15116. case SP_MERCFLEE:
  15117. WFIFOL(fd,4) = status->flee;
  15118. break;
  15119. case SP_ASPD:
  15120. WFIFOL(fd,4) = status->amotion;
  15121. break;
  15122. case SP_HP:
  15123. WFIFOL(fd,4) = status->hp;
  15124. break;
  15125. case SP_MAXHP:
  15126. WFIFOL(fd,4) = status->max_hp;
  15127. break;
  15128. case SP_SP:
  15129. WFIFOL(fd,4) = status->sp;
  15130. break;
  15131. case SP_MAXSP:
  15132. WFIFOL(fd,4) = status->max_sp;
  15133. break;
  15134. case SP_MERCKILLS:
  15135. WFIFOL(fd,4) = md->mercenary.kill_count;
  15136. break;
  15137. case SP_MERCFAITH:
  15138. WFIFOL(fd,4) = mercenary_get_faith(md);
  15139. break;
  15140. }
  15141. WFIFOSET(fd,packet_len(0x2a2));
  15142. }
  15143. /// Mercenary base status data (ZC_MER_INIT).
  15144. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  15145. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  15146. /// <calls>.L <kills>.L <atk range>.W
  15147. void clif_mercenary_info(map_session_data *sd)
  15148. {
  15149. int fd;
  15150. s_mercenary_data *md;
  15151. struct status_data *status;
  15152. int atk;
  15153. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15154. return;
  15155. fd = sd->fd;
  15156. status = &md->battle_status;
  15157. WFIFOHEAD(fd,packet_len(0x29b));
  15158. WFIFOW(fd,0) = 0x29b;
  15159. WFIFOL(fd,2) = md->bl.id;
  15160. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15161. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15162. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15163. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15164. WFIFOW(fd,10) = status->hit;
  15165. WFIFOW(fd,12) = status->cri/10;
  15166. WFIFOW(fd,14) = status->def;
  15167. WFIFOW(fd,16) = status->mdef;
  15168. WFIFOW(fd,18) = status->flee;
  15169. WFIFOW(fd,20) = status->amotion;
  15170. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15171. WFIFOW(fd,46) = md->db->lv;
  15172. WFIFOL(fd,48) = status->hp;
  15173. WFIFOL(fd,52) = status->max_hp;
  15174. WFIFOL(fd,56) = status->sp;
  15175. WFIFOL(fd,60) = status->max_sp;
  15176. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15177. WFIFOW(fd,68) = mercenary_get_faith(md);
  15178. WFIFOL(fd,70) = mercenary_get_calls(md);
  15179. WFIFOL(fd,74) = md->mercenary.kill_count;
  15180. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15181. WFIFOSET(fd,packet_len(0x29b));
  15182. }
  15183. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15184. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15185. void clif_mercenary_skillblock(map_session_data *sd)
  15186. {
  15187. s_mercenary_data *md;
  15188. int fd, len = 4;
  15189. if( sd == NULL || (md = sd->md) == NULL )
  15190. return;
  15191. fd = sd->fd;
  15192. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15193. WFIFOW(fd,0) = 0x29d;
  15194. for (const auto &it : md->db->skill) {
  15195. uint16 id = it.first;
  15196. if (!SKILL_CHK_MERC(id))
  15197. continue;
  15198. uint16 lv = it.second;
  15199. WFIFOW(fd,len) = id;
  15200. WFIFOL(fd,len+2) = skill_get_inf(id);
  15201. WFIFOW(fd,len+6) = lv;
  15202. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15203. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15204. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15205. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15206. len += 37;
  15207. }
  15208. WFIFOW(fd,2) = len;
  15209. WFIFOSET(fd,len);
  15210. }
  15211. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15212. /// 029f <command>.B
  15213. /// 1 = mercenary information
  15214. /// 2 = delete
  15215. void clif_parse_mercenary_action(int fd, map_session_data* sd)
  15216. {
  15217. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15218. if( sd->md == NULL )
  15219. return;
  15220. if( option == 2 ) mercenary_delete(sd->md, 2);
  15221. }
  15222. /// Mercenary Message
  15223. /// message:
  15224. /// 0 = Mercenary soldier's duty hour is over.
  15225. /// 1 = Your mercenary soldier has been killed.
  15226. /// 2 = Your mercenary soldier has been fired.
  15227. /// 3 = Your mercenary soldier has ran away.
  15228. void clif_mercenary_message(map_session_data* sd, int message){
  15229. clif_msg(sd, MERC_MSG_BASE + message);
  15230. }
  15231. /// Notification about the remaining time of a rental item.
  15232. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15233. void clif_rental_time( map_session_data* sd, t_itemid nameid, int seconds ){
  15234. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15235. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15236. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15237. p.itemId = client_nameid( nameid );
  15238. p.seconds = seconds;
  15239. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15240. }
  15241. /// Deletes a rental item from client's inventory.
  15242. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15243. void clif_rental_expired( map_session_data* sd, int index, t_itemid nameid ){
  15244. // '<ItemName>' item has been deleted from the Inventory
  15245. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15246. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15247. p.index = client_index( index );
  15248. p.itemId = client_nameid( nameid );
  15249. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15250. }
  15251. /// Book Reading (ZC_READ_BOOK).
  15252. /// 0294 <book id>.L <page>.L
  15253. void clif_readbook(int fd, int book_id, int page)
  15254. {
  15255. WFIFOHEAD(fd,packet_len(0x294));
  15256. WFIFOW(fd,0) = 0x294;
  15257. WFIFOL(fd,2) = book_id;
  15258. WFIFOL(fd,6) = page;
  15259. WFIFOSET(fd,packet_len(0x294));
  15260. }
  15261. /// Battlegrounds
  15262. ///
  15263. /// Updates HP bar of a camp member.
  15264. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15265. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15266. void clif_bg_hp(map_session_data *sd) {
  15267. #if PACKETVER < 20140613
  15268. unsigned char buf[34];
  15269. const int cmd = 0x2e0;
  15270. #else
  15271. unsigned char buf[14];
  15272. const int cmd = 0xa0e;
  15273. #endif
  15274. nullpo_retv(sd);
  15275. WBUFW(buf,0) = cmd;
  15276. WBUFL(buf,2) = sd->status.account_id;
  15277. #if PACKETVER < 20140613
  15278. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15279. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15280. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15281. WBUFW(buf,32) = 100;
  15282. } else {
  15283. WBUFW(buf,30) = sd->battle_status.hp;
  15284. WBUFW(buf,32) = sd->battle_status.max_hp;
  15285. }
  15286. #else
  15287. if( sd->battle_status.max_hp > INT32_MAX ) {
  15288. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15289. WBUFL(buf,10) = 100;
  15290. } else {
  15291. WBUFL(buf,6) = sd->battle_status.hp;
  15292. WBUFL(buf,10) = sd->battle_status.max_hp;
  15293. }
  15294. #endif
  15295. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15296. }
  15297. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15298. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15299. void clif_bg_xy(map_session_data *sd)
  15300. {
  15301. unsigned char buf[36];
  15302. nullpo_retv(sd);
  15303. WBUFW(buf,0)=0x2df;
  15304. WBUFL(buf,2)=sd->status.account_id;
  15305. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15306. WBUFW(buf,30)=sd->status.class_;
  15307. WBUFW(buf,32)=sd->bl.x;
  15308. WBUFW(buf,34)=sd->bl.y;
  15309. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15310. }
  15311. void clif_bg_xy_remove(map_session_data *sd)
  15312. {
  15313. unsigned char buf[36];
  15314. nullpo_retv(sd);
  15315. WBUFW(buf,0)=0x2df;
  15316. WBUFL(buf,2)=sd->status.account_id;
  15317. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15318. WBUFW(buf,30)=0;
  15319. WBUFW(buf,32)=-1;
  15320. WBUFW(buf,34)=-1;
  15321. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15322. }
  15323. /// Notifies clients of a battleground message.
  15324. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15325. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15326. map_session_data *sd = bg_getavailablesd( bg );
  15327. if( sd == nullptr ){
  15328. return;
  15329. }
  15330. // limit length
  15331. len = min( len + 1, CHAT_SIZE_MAX );
  15332. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15333. WBUFW(buf,0) = 0x2dc;
  15334. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15335. WBUFL(buf,4) = src_id;
  15336. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15337. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15338. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15339. }
  15340. /// Validates and processes battlechat messages.
  15341. /// All messages that are sent after enabling battleground chat with /battlechat.
  15342. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15343. void clif_parse_BattleChat(int fd, map_session_data* sd){
  15344. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15345. if( !clif_process_message( sd, false, name, message, output ) )
  15346. return;
  15347. bg_send_message(sd, output, strlen(output) );
  15348. }
  15349. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15350. /// 02de <camp A points>.W <camp B points>.W
  15351. void clif_bg_updatescore(int16 m)
  15352. {
  15353. struct block_list bl;
  15354. unsigned char buf[6];
  15355. struct map_data *mapdata = map_getmapdata(m);
  15356. bl.id = 0;
  15357. bl.type = BL_NUL;
  15358. bl.m = m;
  15359. WBUFW(buf,0) = 0x2de;
  15360. WBUFW(buf,2) = mapdata->bgscore_lion;
  15361. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15362. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15363. }
  15364. void clif_bg_updatescore_single(map_session_data *sd)
  15365. {
  15366. int fd;
  15367. nullpo_retv(sd);
  15368. fd = sd->fd;
  15369. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15370. WFIFOHEAD(fd,packet_len(0x2de));
  15371. WFIFOW(fd,0) = 0x2de;
  15372. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15373. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15374. WFIFOSET(fd,packet_len(0x2de));
  15375. }
  15376. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15377. /// 02dd <account id>.L <name>.24B <camp>.W
  15378. void clif_sendbgemblem_area(map_session_data *sd)
  15379. {
  15380. unsigned char buf[33];
  15381. nullpo_retv(sd);
  15382. WBUFW(buf, 0) = 0x2dd;
  15383. WBUFL(buf,2) = sd->bl.id;
  15384. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15385. WBUFW(buf,30) = sd->bg_id;
  15386. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15387. }
  15388. void clif_sendbgemblem_single(int fd, map_session_data *sd)
  15389. {
  15390. nullpo_retv(sd);
  15391. WFIFOHEAD(fd,32);
  15392. WFIFOW(fd,0) = 0x2dd;
  15393. WFIFOL(fd,2) = sd->bl.id;
  15394. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15395. WFIFOW(fd,30) = sd->bg_id;
  15396. WFIFOSET(fd,packet_len(0x2dd));
  15397. }
  15398. /// Battlegrounds queue incoming apply request from client.
  15399. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15400. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15401. void clif_parse_bg_queue_apply_request(int fd, map_session_data *sd)
  15402. {
  15403. if (!battle_config.feature_bgqueue)
  15404. return;
  15405. nullpo_retv(sd);
  15406. short type = RFIFOW(fd,2);
  15407. char name[NAME_LENGTH];
  15408. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15409. if (sd->bg_queue_id > 0) {
  15410. //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);
  15411. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15412. return;
  15413. } else if (type == 1) // Solo
  15414. bg_queue_join_solo(name, sd);
  15415. else if (type == 2) // Party
  15416. bg_queue_join_party(name, sd);
  15417. else if (type == 4) // Guild
  15418. bg_queue_join_guild(name, sd);
  15419. else {
  15420. 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);
  15421. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15422. return;
  15423. }
  15424. }
  15425. /// Outgoing battlegrounds queue apply result.
  15426. /// Result types: @see e_bg_queue_apply_ack
  15427. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15428. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, map_session_data *sd)
  15429. {
  15430. nullpo_retv(sd);
  15431. int fd = sd->fd;
  15432. WFIFOHEAD(fd, packet_len(0x8d8));
  15433. WFIFOW(fd,0) = 0x8d8;
  15434. WFIFOB(fd,2) = result;
  15435. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15436. WFIFOSET(fd, packet_len(0x8d8));
  15437. }
  15438. /// Outgoing battlegrounds queue apply notification.
  15439. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15440. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15441. void clif_bg_queue_apply_notify(const char *name, map_session_data *sd)
  15442. {
  15443. nullpo_retv(sd);
  15444. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15445. if (queue == nullptr) {
  15446. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15447. return;
  15448. }
  15449. int fd = sd->fd;
  15450. WFIFOHEAD(fd, packet_len(0x8d9));
  15451. WFIFOW(fd,0) = 0x8d9;
  15452. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15453. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15454. WFIFOSET(fd, packet_len(0x8d9));
  15455. }
  15456. /// Battlegrounds queue outgoing cancel result.
  15457. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15458. void clif_bg_queue_cancel_result(bool success, const char *name, map_session_data *sd)
  15459. {
  15460. nullpo_retv(sd);
  15461. int fd = sd->fd;
  15462. WFIFOHEAD(fd, packet_len(0x8d8));
  15463. WFIFOW(fd,0) = 0x8db;
  15464. WFIFOB(fd,2) = success;
  15465. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15466. WFIFOSET(fd, packet_len(0x8d8));
  15467. }
  15468. /// Battlegrounds queue incoming cancel request from client.
  15469. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15470. void clif_parse_bg_queue_cancel_request(int fd, map_session_data *sd)
  15471. {
  15472. if (!battle_config.feature_bgqueue)
  15473. return;
  15474. nullpo_retv(sd);
  15475. bool success;
  15476. if (sd->bg_queue_id > 0) {
  15477. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15478. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15479. 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.
  15480. else
  15481. success = bg_queue_leave(sd);
  15482. } else {
  15483. 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);
  15484. success = false;
  15485. }
  15486. char name[NAME_LENGTH];
  15487. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15488. clif_bg_queue_cancel_result(success, name, sd);
  15489. }
  15490. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15491. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15492. void clif_bg_queue_lobby_notify(const char *name, map_session_data *sd)
  15493. {
  15494. nullpo_retv(sd);
  15495. int fd = sd->fd;
  15496. WFIFOHEAD(fd, packet_len(0x8df));
  15497. WFIFOW(fd,0) = 0x8df;
  15498. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15499. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15500. WFIFOSET(fd, packet_len(0x8df));
  15501. }
  15502. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15503. /// Result types: 1(Accept), 2(Decline).
  15504. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15505. void clif_parse_bg_queue_lobby_reply(int fd, map_session_data *sd)
  15506. {
  15507. nullpo_retv(sd);
  15508. if(sd->bg_queue_id > 0) {
  15509. uint8 result = RFIFOB(fd, 2);
  15510. if(result == 1) { // Accept
  15511. bg_queue_on_accept_invite(sd);
  15512. } else if(result == 2) { // Decline
  15513. bg_queue_leave(sd);
  15514. clif_bg_queue_entry_init(sd);
  15515. }
  15516. }
  15517. }
  15518. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15519. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15520. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, map_session_data *sd)
  15521. {
  15522. nullpo_retv(sd);
  15523. int fd = sd->fd;
  15524. WFIFOHEAD(fd, packet_len(0x8e1));
  15525. WFIFOW(fd,0) = 0x8e1;
  15526. WFIFOB(fd,2) = result;
  15527. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15528. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15529. WFIFOSET(fd, packet_len(0x8e1));
  15530. }
  15531. /// Battlegrounds queue incoming queue number request from client.
  15532. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15533. void clif_parse_bg_queue_request_queue_number(int fd, map_session_data *sd)
  15534. {
  15535. nullpo_retv(sd);
  15536. char name[NAME_LENGTH];
  15537. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15538. clif_bg_queue_apply_notify(name, sd);
  15539. }
  15540. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15541. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15542. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15543. void clif_bg_queue_entry_init(map_session_data *sd)
  15544. {
  15545. nullpo_retv(sd);
  15546. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15547. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15548. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15549. }
  15550. /// Custom Fonts (ZC_NOTIFY_FONT).
  15551. /// 02ef <account_id>.L <font id>.W
  15552. void clif_font(map_session_data *sd)
  15553. {
  15554. #if PACKETVER >= 20080102
  15555. unsigned char buf[8];
  15556. nullpo_retv(sd);
  15557. WBUFW(buf,0) = 0x2ef;
  15558. WBUFL(buf,2) = sd->bl.id;
  15559. WBUFW(buf,6) = sd->status.font;
  15560. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15561. #endif
  15562. }
  15563. /// Required to start the instancing information window on Client
  15564. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15565. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15566. void clif_instance_create(int instance_id, int num)
  15567. {
  15568. #if PACKETVER >= 20071128
  15569. map_session_data *sd = NULL;
  15570. enum send_target target = PARTY;
  15571. unsigned char buf[65];
  15572. instance_getsd(instance_id, sd, &target);
  15573. if (!sd)
  15574. return;
  15575. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15576. if (!db)
  15577. return;
  15578. WBUFW(buf,0) = 0x2cb;
  15579. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15580. WBUFW(buf,63) = num;
  15581. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15582. #endif
  15583. return;
  15584. }
  15585. /// To announce Instancing queue creation if no maps available
  15586. /// S 0x2cc <Standby Position>.W
  15587. void clif_instance_changewait(int instance_id, int num)
  15588. {
  15589. #if PACKETVER >= 20071128
  15590. map_session_data *sd = NULL;
  15591. enum send_target target = PARTY;
  15592. unsigned char buf[4];
  15593. instance_getsd(instance_id, sd, &target);
  15594. if (!sd)
  15595. return;
  15596. WBUFW(buf,0) = 0x2cc;
  15597. WBUFW(buf,2) = num;
  15598. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15599. #endif
  15600. return;
  15601. }
  15602. /// Notify the current status to members
  15603. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15604. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15605. {
  15606. #if PACKETVER >= 20071128
  15607. map_session_data *sd = NULL;
  15608. enum send_target target = PARTY;
  15609. unsigned char buf[71];
  15610. instance_getsd(instance_id, sd, &target);
  15611. if (!sd)
  15612. return;
  15613. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15614. if (!db)
  15615. return;
  15616. WBUFW(buf,0) = 0x2cd;
  15617. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15618. WBUFL(buf,63) = limit1;
  15619. WBUFL(buf,67) = limit2;
  15620. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15621. #endif
  15622. return;
  15623. }
  15624. /// Notify a status change to members
  15625. /// S 0x2ce <Message ID>.L
  15626. /// 0 = Notification (EnterLimitDate update?)
  15627. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15628. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15629. /// 3 = The Memorial Dungeon has been removed.
  15630. /// 4 = Create failure (removes the instance window)
  15631. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15632. {
  15633. #if PACKETVER >= 20071128
  15634. map_session_data *sd = NULL;
  15635. enum send_target target = PARTY;
  15636. unsigned char buf[10];
  15637. instance_getsd(instance_id, sd, &target);
  15638. if (!sd)
  15639. return;
  15640. WBUFW(buf,0) = 0x2ce;
  15641. WBUFL(buf,2) = type;
  15642. WBUFL(buf,6) = limit;
  15643. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15644. #endif
  15645. return;
  15646. }
  15647. /// Destroy an instance from the status window
  15648. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15649. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15650. {
  15651. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15652. return;
  15653. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15654. switch (p->command) {
  15655. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15656. instance_destroy_command(sd);
  15657. break;
  15658. }
  15659. }
  15660. void clif_instance_info( map_session_data& sd ){
  15661. if( sd.instance_id > 0 ){
  15662. instance_reqinfo( &sd, sd.instance_id );
  15663. }
  15664. if( sd.status.party_id > 0 ){
  15665. struct party_data* p = party_search( sd.status.party_id );
  15666. if( p != nullptr && p->instance_id > 0 ){
  15667. instance_reqinfo( &sd, p->instance_id );
  15668. }
  15669. }
  15670. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15671. instance_reqinfo( &sd, sd.guild->instance_id );
  15672. }
  15673. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15674. instance_reqinfo( &sd, sd.clan->instance_id );
  15675. }
  15676. }
  15677. /// Notifies clients about item picked up by a party member.
  15678. /// 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)
  15679. void clif_party_show_picker( map_session_data* sd, struct item* item_data ){
  15680. #if PACKETVER >= 20071002
  15681. nullpo_retv( sd );
  15682. nullpo_retv( item_data );
  15683. struct item_data* id = itemdb_search( item_data->nameid );
  15684. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15685. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15686. p.AID = sd->status.account_id;
  15687. p.itemId = client_nameid( item_data->nameid );
  15688. p.identified = item_data->identify;
  15689. p.damaged = item_data->attribute;
  15690. p.refine = item_data->refine;
  15691. clif_addcards( &p.slot, item_data );
  15692. p.location = id->equip; // equip location
  15693. p.itemType = itemtype( id->nameid ); // item type
  15694. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15695. p.grade = item_data->enchantgrade;
  15696. #endif
  15697. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15698. #endif
  15699. }
  15700. /** Display gained exp.
  15701. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15702. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15703. * amount: INT32_MIN ~ INT32_MAX
  15704. * var id:
  15705. * SP_BASEEXP, SP_JOBEXP
  15706. * exp type:
  15707. * 0 = normal exp gained/lost
  15708. * 1 = quest exp gained/lost
  15709. * @param sd Player
  15710. * @param exp EXP value gained/loss
  15711. * @param type SP_BASEEXP, SP_JOBEXP
  15712. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15713. * @param lost True:if losing EXP
  15714. */
  15715. void clif_displayexp(map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15716. {
  15717. int fd;
  15718. int offset;
  15719. #if PACKETVER >= 20170830
  15720. int cmd = 0xacc;
  15721. #else
  15722. int cmd = 0x7f6;
  15723. #endif
  15724. nullpo_retv(sd);
  15725. fd = sd->fd;
  15726. WFIFOHEAD(fd, packet_len(cmd));
  15727. WFIFOW(fd,0) = cmd;
  15728. WFIFOL(fd,2) = sd->bl.id;
  15729. #if PACKETVER >= 20170830
  15730. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15731. offset = 4;
  15732. #else
  15733. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15734. offset = 0;
  15735. #endif
  15736. WFIFOW(fd,10+offset) = type;
  15737. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15738. WFIFOSET(fd,packet_len(cmd));
  15739. }
  15740. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15741. /// type:
  15742. /// 0 = Displays 'value' for 5 seconds.
  15743. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15744. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15745. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15746. /// value:
  15747. /// 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).
  15748. void clif_showdigit(map_session_data* sd, unsigned char type, int value)
  15749. {
  15750. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15751. WFIFOW(sd->fd,0) = 0x1b1;
  15752. WFIFOB(sd->fd,2) = type;
  15753. WFIFOL(sd->fd,3) = value;
  15754. WFIFOSET(sd->fd, packet_len(0x1b1));
  15755. }
  15756. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15757. /// 021d <state>.L
  15758. /// state:
  15759. /// 0 = Full effects
  15760. /// 1 = Reduced effects
  15761. ///
  15762. /// NOTE: The state is used on Aegis for sending skill unit packet
  15763. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15764. /// whenever possible. Due to the way the decision check is
  15765. /// constructed, this state tracking was rendered useless,
  15766. /// as the only skill unit, that is sent with 0x1c9 is
  15767. /// Graffiti.
  15768. void clif_parse_LessEffect(int fd, map_session_data* sd){
  15769. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15770. sd->state.lesseffect = ( isLess != 0 );
  15771. }
  15772. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15773. void clif_parse_ItemListWindowSelected(int fd, map_session_data* sd) {
  15774. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15775. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15776. int type = RFIFOL(fd,info->pos[1]);
  15777. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15778. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15779. if( sd->state.trading || sd->npc_shopid )
  15780. return;
  15781. if( flag == 0 || n == 0) {
  15782. clif_menuskill_clear(sd);
  15783. return; // Canceled by player.
  15784. }
  15785. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15786. clif_menuskill_clear(sd);
  15787. return; // Prevent hacking.
  15788. }
  15789. switch( type ) {
  15790. case 0: // Change Material
  15791. skill_changematerial(sd,n,item_list);
  15792. break;
  15793. case 1: // Level 1: Pure to Rough
  15794. case 2: // Level 2: Rough to Pure
  15795. skill_elementalanalysis(sd,n,type,item_list);
  15796. break;
  15797. }
  15798. clif_menuskill_clear(sd);
  15799. return;
  15800. }
  15801. /*==========================================
  15802. * Elemental System
  15803. *==========================================*/
  15804. void clif_elemental_updatestatus(map_session_data *sd, int type) {
  15805. s_elemental_data *ed;
  15806. struct status_data *status;
  15807. int fd;
  15808. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15809. return;
  15810. fd = sd->fd;
  15811. status = &ed->battle_status;
  15812. WFIFOHEAD(fd,8);
  15813. WFIFOW(fd,0) = 0x81e;
  15814. WFIFOW(fd,2) = type;
  15815. switch( type ) {
  15816. case SP_HP:
  15817. WFIFOL(fd,4) = status->hp;
  15818. break;
  15819. case SP_MAXHP:
  15820. WFIFOL(fd,4) = status->max_hp;
  15821. break;
  15822. case SP_SP:
  15823. WFIFOL(fd,4) = status->sp;
  15824. break;
  15825. case SP_MAXSP:
  15826. WFIFOL(fd,4) = status->max_sp;
  15827. break;
  15828. }
  15829. WFIFOSET(fd,8);
  15830. }
  15831. void clif_elemental_info(map_session_data *sd) {
  15832. int fd;
  15833. s_elemental_data *ed;
  15834. struct status_data *status;
  15835. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15836. return;
  15837. fd = sd->fd;
  15838. status = &ed->battle_status;
  15839. WFIFOHEAD(fd,22);
  15840. WFIFOW(fd, 0) = 0x81d;
  15841. WFIFOL(fd, 2) = ed->bl.id;
  15842. WFIFOL(fd, 6) = status->hp;
  15843. WFIFOL(fd,10) = status->max_hp;
  15844. WFIFOL(fd,14) = status->sp;
  15845. WFIFOL(fd,18) = status->max_sp;
  15846. WFIFOSET(fd,22);
  15847. }
  15848. /// Buying Store System
  15849. ///
  15850. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15851. /// 0810 <slots>.B
  15852. void clif_buyingstore_open(map_session_data* sd)
  15853. {
  15854. int fd = sd->fd;
  15855. WFIFOHEAD(fd,packet_len(0x810));
  15856. WFIFOW(fd,0) = 0x810;
  15857. WFIFOB(fd,2) = sd->buyingstore.slots;
  15858. WFIFOSET(fd,packet_len(0x810));
  15859. }
  15860. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15861. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15862. /// result:
  15863. /// 0 = cancel
  15864. /// 1 = open
  15865. static void clif_parse_ReqOpenBuyingStore( int fd, map_session_data* sd ){
  15866. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15867. // TODO: Make this check global for all variable length packets.
  15868. // minimum packet length
  15869. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15870. 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 );
  15871. return;
  15872. }
  15873. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15874. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15875. return;
  15876. }
  15877. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15878. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15879. return;
  15880. }
  15881. char storename[MESSAGE_SIZE];
  15882. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15883. // so that buyingstore_create knows, how many elements it has access to
  15884. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15885. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15886. 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 ) );
  15887. return;
  15888. }
  15889. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15890. }
  15891. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15892. /// 0812 <result>.W <total weight>.L
  15893. /// result:
  15894. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15895. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15896. /// 8 = "No sale (purchase) information available." (0x705)
  15897. /// ? = nothing
  15898. void clif_buyingstore_open_failed(map_session_data* sd, unsigned short result, unsigned int weight)
  15899. {
  15900. int fd = sd->fd;
  15901. WFIFOHEAD(fd,packet_len(0x812));
  15902. WFIFOW(fd,0) = 0x812;
  15903. WFIFOW(fd,2) = result;
  15904. WFIFOL(fd,4) = weight;
  15905. WFIFOSET(fd,packet_len(0x812));
  15906. }
  15907. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15908. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15909. void clif_buyingstore_myitemlist( map_session_data* sd ){
  15910. nullpo_retv( sd );
  15911. int fd = sd->fd;
  15912. if( !session_isActive( fd ) ){
  15913. return;
  15914. }
  15915. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15916. WFIFOHEAD( fd, length );
  15917. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15918. p->packetType = 0x813;
  15919. p->packetLength = length;
  15920. p->AID = sd->bl.id;
  15921. p->zenyLimit = sd->buyingstore.zenylimit;
  15922. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15923. p->items[i].price = sd->buyingstore.items[i].price;
  15924. p->items[i].amount = sd->buyingstore.items[i].amount;
  15925. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15926. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15927. }
  15928. WFIFOSET( fd, p->packetLength );
  15929. }
  15930. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15931. /// 0814 <account id>.L <store name>.80B
  15932. void clif_buyingstore_entry( map_session_data& sd, struct block_list* tbl ){
  15933. #if PACKETVER >= 20100420
  15934. enum send_target target;
  15935. if( tbl == nullptr ){
  15936. tbl = &sd.bl;
  15937. target = AREA_WOS;
  15938. }else{
  15939. target = SELF;
  15940. }
  15941. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15942. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15943. p.makerAID = sd.status.account_id;
  15944. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15945. clif_send( &p, sizeof( p ), tbl, target );
  15946. #endif
  15947. }
  15948. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15949. /// 0815
  15950. static void clif_parse_ReqCloseBuyingStore(int fd, map_session_data* sd)
  15951. {
  15952. buyingstore_close(sd);
  15953. }
  15954. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15955. /// 0816 <account id>.L
  15956. void clif_buyingstore_disappear_entry( map_session_data& sd, struct block_list* tbl ){
  15957. #if PACKETVER >= 20100309
  15958. enum send_target target;
  15959. if( tbl == nullptr ){
  15960. tbl = &sd.bl;
  15961. target = AREA_WOS;
  15962. }else{
  15963. target = SELF;
  15964. }
  15965. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15966. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15967. p.makerAID = sd.status.account_id;
  15968. clif_send( &p, sizeof( p ), tbl, target );
  15969. #endif
  15970. }
  15971. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15972. /// 0817 <account id>.L
  15973. static void clif_parse_ReqClickBuyingStore(int fd, map_session_data* sd)
  15974. {
  15975. uint32 account_id;
  15976. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15977. buyingstore_open(sd, account_id);
  15978. }
  15979. /// Sends buying store item list.
  15980. /// 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)
  15981. void clif_buyingstore_itemlist( map_session_data* sd, map_session_data* pl_sd ){
  15982. nullpo_retv( sd );
  15983. nullpo_retv( pl_sd );
  15984. int fd = sd->fd;
  15985. if( !session_isActive( fd ) ){
  15986. return;
  15987. }
  15988. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15989. WFIFOHEAD( fd, length );
  15990. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15991. p->packetType = 0x818;
  15992. p->packetLength = length;
  15993. p->AID = pl_sd->bl.id;
  15994. p->storeId = pl_sd->buyer_id;
  15995. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15996. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15997. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15998. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15999. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  16000. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  16001. }
  16002. WFIFOSET( fd, p->packetLength );
  16003. }
  16004. /// Request to sell items to a buying store.
  16005. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  16006. static void clif_parse_ReqTradeBuyingStore( int fd, map_session_data* sd ){
  16007. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  16008. // minimum packet length
  16009. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  16010. 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 );
  16011. return;
  16012. }
  16013. // so that buyingstore_trade knows, how many elements it has access to
  16014. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  16015. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  16016. 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 ) );
  16017. return;
  16018. }
  16019. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  16020. }
  16021. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  16022. /// 081a <result>.W
  16023. /// result:
  16024. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  16025. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  16026. /// ? = nothing
  16027. void clif_buyingstore_trade_failed_buyer(map_session_data* sd, short result)
  16028. {
  16029. int fd = sd->fd;
  16030. WFIFOHEAD(fd,packet_len(0x81a));
  16031. WFIFOW(fd,0) = 0x81a;
  16032. WFIFOW(fd,2) = result;
  16033. WFIFOSET(fd,packet_len(0x81a));
  16034. }
  16035. /// Updates the zeny limit and an item in the buying store item list.
  16036. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  16037. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  16038. void clif_buyingstore_update_item( map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  16039. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  16040. p.packetType = buyingStoreUpdateItemType;
  16041. p.itemId = client_nameid( nameid );
  16042. p.amount = amount;
  16043. p.zenyLimit = sd->buyingstore.zenylimit;
  16044. #if PACKETVER >= 20141016
  16045. p.zeny = zeny;
  16046. p.charId = char_id; // GID
  16047. p.updateTime = (int)time(NULL);
  16048. #endif
  16049. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16050. }
  16051. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  16052. /// 081c <index>.W <amount>.W <price>.L
  16053. /// message:
  16054. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  16055. ///
  16056. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  16057. void clif_buyingstore_delete_item(map_session_data* sd, short index, unsigned short amount, int price)
  16058. {
  16059. int fd = sd->fd;
  16060. WFIFOHEAD(fd,packet_len(0x81c));
  16061. WFIFOW(fd,0) = 0x81c;
  16062. WFIFOW(fd,2) = client_index( index );
  16063. WFIFOW(fd,4) = amount;
  16064. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  16065. WFIFOSET(fd,packet_len(0x81c));
  16066. }
  16067. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  16068. /// 0824 <result>.W <name id>.W
  16069. /// result:
  16070. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  16071. /// 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)
  16072. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  16073. /// ? = nothing
  16074. void clif_buyingstore_trade_failed_seller( map_session_data* sd, short result, t_itemid nameid ){
  16075. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  16076. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  16077. p.result = result;
  16078. p.itemId = client_nameid( nameid );
  16079. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16080. }
  16081. /// Search Store Info System
  16082. ///
  16083. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  16084. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  16085. /// type:
  16086. /// 0 = Vending
  16087. /// 1 = Buying Store
  16088. ///
  16089. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16090. /// amount of card slots. If the client does not know about the item it
  16091. /// cannot be searched.
  16092. static void clif_parse_SearchStoreInfo( int fd, map_session_data *sd ){
  16093. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16094. // minimum packet length
  16095. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16096. 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 );
  16097. return;
  16098. }
  16099. // check, if there is enough data for the claimed count of items
  16100. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16101. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16102. 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 ) );
  16103. return;
  16104. }
  16105. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16106. if( count < p->itemsCount + p->cardsCount ){
  16107. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16108. return;
  16109. }
  16110. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16111. }
  16112. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16113. /// 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 }*
  16114. /// is first page:
  16115. /// 0 = appends to existing results
  16116. /// 1 = clears previous results before displaying this result set
  16117. /// is next page:
  16118. /// 0 = no "next" label
  16119. /// 1 = "next" label to retrieve more results
  16120. void clif_search_store_info_ack( map_session_data* sd ){
  16121. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  16122. nullpo_retv( sd );
  16123. int fd = sd->fd;
  16124. if( !session_isActive( fd ) ){
  16125. return;
  16126. }
  16127. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16128. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16129. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16130. WFIFOHEAD( fd, len );
  16131. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16132. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16133. p->packetLength = len;
  16134. p->firstPage = !sd->searchstore.pages;
  16135. p->nextPage = searchstore_querynext( sd );
  16136. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16137. for( int i = 0; i < end - start; i++ ) {
  16138. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16139. p->items[i].storeId = ssitem->store_id;
  16140. p->items[i].AID = ssitem->account_id;
  16141. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16142. p->items[i].itemId = client_nameid( ssitem->nameid );
  16143. p->items[i].itemType = itemtype( ssitem->nameid );
  16144. p->items[i].price = ssitem->price;
  16145. p->items[i].amount = ssitem->amount;
  16146. p->items[i].refine = ssitem->refine;
  16147. // make-up an item for clif_addcards
  16148. struct item it = {};
  16149. for( int j = 0; j < MAX_SLOTS; j++ ){
  16150. it.card[j] = ssitem->card[j];
  16151. }
  16152. it.nameid = ssitem->nameid;
  16153. it.amount = ssitem->amount;
  16154. clif_addcards( &p->items[i].slot, &it );
  16155. #if PACKETVER >= 20150226
  16156. clif_add_random_options( p->items[i].option_data, it );
  16157. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16158. p->items[i].grade = ssitem->enchantgrade;
  16159. #endif
  16160. #endif
  16161. }
  16162. WFIFOSET( fd, len );
  16163. #endif
  16164. }
  16165. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16166. /// 0837 <reason>.B
  16167. /// reason:
  16168. /// 0 = "No matching stores were found." (0x70b)
  16169. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16170. /// 2 = "You cannot search anymore." (0x706)
  16171. /// 3 = "You cannot search yet." (0x708)
  16172. /// 4 = "No sale (purchase) information available." (0x705)
  16173. void clif_search_store_info_failed(map_session_data* sd, unsigned char reason)
  16174. {
  16175. int fd = sd->fd;
  16176. WFIFOHEAD(fd,packet_len(0x837));
  16177. WFIFOW(fd,0) = 0x837;
  16178. WFIFOB(fd,2) = reason;
  16179. WFIFOSET(fd,packet_len(0x837));
  16180. }
  16181. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16182. /// 0838
  16183. static void clif_parse_SearchStoreInfoNextPage(int fd, map_session_data* sd)
  16184. {
  16185. searchstore_next(sd);
  16186. }
  16187. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16188. /// 083a <type>.W <remaining uses>.B
  16189. /// type:
  16190. /// 0 = Search Stores
  16191. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16192. void clif_open_search_store_info(map_session_data* sd)
  16193. {
  16194. int fd = sd->fd;
  16195. WFIFOHEAD(fd,packet_len(0x83a));
  16196. WFIFOW(fd,0) = 0x83a;
  16197. WFIFOW(fd,2) = sd->searchstore.effect;
  16198. #if PACKETVER > 20100701
  16199. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16200. #endif
  16201. WFIFOSET(fd,packet_len(0x83a));
  16202. }
  16203. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16204. /// 083b
  16205. static void clif_parse_CloseSearchStoreInfo(int fd, map_session_data* sd)
  16206. {
  16207. searchstore_close(sd);
  16208. }
  16209. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16210. /// 083c <account id>.L <store id>.L <nameid>.W
  16211. static void clif_parse_SearchStoreInfoListItemClick( int fd, map_session_data* sd ){
  16212. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16213. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16214. }
  16215. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16216. /// 083d <xPos>.W <yPos>.W
  16217. void clif_search_store_info_click_ack(map_session_data* sd, short x, short y)
  16218. {
  16219. int fd = sd->fd;
  16220. WFIFOHEAD(fd,packet_len(0x83d));
  16221. WFIFOW(fd,0) = 0x83d;
  16222. WFIFOW(fd,2) = x;
  16223. WFIFOW(fd,4) = y;
  16224. WFIFOSET(fd,packet_len(0x83d));
  16225. }
  16226. /// Parse function for packet debugging.
  16227. void clif_parse_debug(int fd,map_session_data *sd)
  16228. {
  16229. int cmd, packet_len;
  16230. // clif_parse ensures, that there is at least 2 bytes of data
  16231. cmd = RFIFOW(fd,0);
  16232. if( sd ) {
  16233. packet_len = packet_db[cmd].len;
  16234. if( packet_len == 0 )
  16235. {// unknown
  16236. packet_len = RFIFOREST(fd);
  16237. }
  16238. else if( packet_len == -1 )
  16239. {// variable length
  16240. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16241. }
  16242. 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);
  16243. }
  16244. else
  16245. {
  16246. packet_len = RFIFOREST(fd);
  16247. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16248. }
  16249. ShowDump(RFIFOP(fd,0), packet_len);
  16250. }
  16251. /*==========================================
  16252. * Server tells client to display a window similar to Magnifier (item) one
  16253. * Server populates the window with avilable elemental converter options according to player's inventory
  16254. *------------------------------------------*/
  16255. void clif_elementalconverter_list( map_session_data *sd ){
  16256. nullpo_retv( sd );
  16257. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16258. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16259. int count = 0;
  16260. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16261. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16262. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16263. count++;
  16264. }
  16265. }
  16266. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16267. clif_send( p, p->packetLength, &sd->bl, SELF );
  16268. if( count > 0 ){
  16269. sd->menuskill_id = SA_CREATECON;
  16270. sd->menuskill_val = count;
  16271. }
  16272. }
  16273. /**
  16274. * Rune Knight
  16275. **/
  16276. void clif_millenniumshield(struct block_list *bl, short shields) {
  16277. #if PACKETVER >= 20081217
  16278. unsigned char buf[10];
  16279. WBUFW(buf,0) = 0x440;
  16280. WBUFL(buf,2) = bl->id;
  16281. WBUFW(buf,6) = shields;
  16282. WBUFW(buf,8) = 0;
  16283. clif_send(buf,packet_len(0x440),bl,AREA);
  16284. #endif
  16285. }
  16286. /**
  16287. * Mechanic
  16288. **/
  16289. /*==========================================
  16290. * Magic Decoy Material List
  16291. *------------------------------------------*/
  16292. void clif_magicdecoy_list( map_session_data *sd, uint16 skill_lv, short x, short y ){
  16293. nullpo_retv( sd );
  16294. int fd = sd->fd;
  16295. if( !session_isActive( fd ) ){
  16296. return;
  16297. }
  16298. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16299. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16300. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16301. int count = 0;
  16302. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16303. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16304. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16305. count++;
  16306. }
  16307. }
  16308. if( count > 0 ) {
  16309. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16310. WFIFOSET( fd, p->packetLength );
  16311. sd->menuskill_id = NC_MAGICDECOY;
  16312. sd->menuskill_val = skill_lv;
  16313. sd->sc.comet_x = x;
  16314. sd->sc.comet_y = y;
  16315. }else{
  16316. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16317. }
  16318. }
  16319. /*==========================================
  16320. * Guillotine Cross Poisons List
  16321. *------------------------------------------*/
  16322. void clif_poison_list( map_session_data *sd, uint16 skill_lv ){
  16323. nullpo_retv( sd );
  16324. int fd = sd->fd;
  16325. if( !session_isActive( fd ) ){
  16326. return;
  16327. }
  16328. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16329. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16330. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16331. int count = 0;
  16332. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16333. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16334. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16335. count++;
  16336. }
  16337. }
  16338. if( count > 0 ){
  16339. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16340. WFIFOSET( fd, p->packetLength );
  16341. sd->menuskill_id = GC_POISONINGWEAPON;
  16342. sd->menuskill_val = skill_lv;
  16343. }else{
  16344. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16345. }
  16346. }
  16347. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16348. int clif_autoshadowspell_list(map_session_data *sd) {
  16349. int fd, i, c;
  16350. nullpo_ret(sd);
  16351. fd = sd->fd;
  16352. if( !session_isActive(fd) )
  16353. return 0;
  16354. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16355. return 0;
  16356. WFIFOHEAD(fd, 2 * 6 + 4);
  16357. WFIFOW(fd,0) = 0x442;
  16358. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16359. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16360. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16361. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16362. {
  16363. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16364. c++;
  16365. }
  16366. if( c > 0 ) {
  16367. WFIFOW(fd,2) = 8 + c * 2;
  16368. WFIFOL(fd,4) = c;
  16369. WFIFOSET(fd,WFIFOW(fd,2));
  16370. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16371. sd->menuskill_val = c;
  16372. } else {
  16373. status_change_end(&sd->bl,SC_STOP);
  16374. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16375. }
  16376. return 1;
  16377. }
  16378. /*===========================================
  16379. * Skill list for Four Elemental Analysis
  16380. * and Change Material skills.
  16381. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16382. *------------------------------------------*/
  16383. int clif_skill_itemlistwindow( map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16384. #if PACKETVER >= 20090922
  16385. int fd = sd->fd;
  16386. nullpo_ret(sd);
  16387. sd->menuskill_id = skill_id; // To prevent hacking.
  16388. sd->menuskill_val = skill_lv;
  16389. if( skill_id == GN_CHANGEMATERIAL )
  16390. skill_lv = 0; // Changematerial
  16391. WFIFOHEAD(fd, packet_len(0x7e3));
  16392. WFIFOW(fd,0) = 0x7e3;
  16393. WFIFOL(fd,2) = skill_lv;
  16394. WFIFOL(fd,4) = 0;
  16395. WFIFOSET(fd, packet_len(0x7e3));
  16396. #endif
  16397. return 1;
  16398. }
  16399. /*==========================================
  16400. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16401. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16402. * RFIFOL(fd,2) - type (currently not used)
  16403. *------------------------------------------*/
  16404. void clif_parse_SkillSelectMenu(int fd, map_session_data *sd) {
  16405. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16406. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16407. if (sd->menuskill_id == SA_AUTOSPELL) {
  16408. sd->state.workinprogress = WIP_DISABLE_NONE;
  16409. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16410. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16411. if (pc_istrading(sd)) {
  16412. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16413. clif_menuskill_clear(sd);
  16414. return;
  16415. }
  16416. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16417. } else
  16418. return;
  16419. clif_menuskill_clear(sd);
  16420. }
  16421. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16422. /// 08cf <id>.L <type>.W <num>.W
  16423. void clif_spiritcharm(map_session_data *sd) {
  16424. unsigned char buf[10];
  16425. nullpo_retv(sd);
  16426. WBUFW(buf,0) = 0x08cf;
  16427. WBUFL(buf,2) = sd->bl.id;
  16428. WBUFW(buf,6) = sd->spiritcharm_type;
  16429. WBUFW(buf,8) = sd->spiritcharm;
  16430. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16431. }
  16432. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16433. /// 0907 <index>.W
  16434. ///
  16435. /// R 0908 <index>.w <type>.b
  16436. /// type:
  16437. /// 0 = move item to personal tab
  16438. /// 1 = move item to normal tab
  16439. void clif_parse_MoveItem(int fd, map_session_data *sd) {
  16440. #if PACKETVER >= 20111122
  16441. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16442. int index = RFIFOW(fd,info->pos[0]) - 2;
  16443. int type = RFIFOB(fd, info->pos[1]);
  16444. /* can't move while dead. */
  16445. if(pc_isdead(sd)) {
  16446. return;
  16447. }
  16448. if (index < 0 || index >= MAX_INVENTORY)
  16449. return;
  16450. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16451. sd->inventory.u.items_inventory[index].favorite = 0;
  16452. else if( type == 0 )
  16453. sd->inventory.u.items_inventory[index].favorite = 1;
  16454. else
  16455. return;/* nothing to do. */
  16456. clif_favorite_item(sd, index);
  16457. #endif
  16458. }
  16459. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16460. /// 0900 <index>.W <favorite>.B
  16461. void clif_favorite_item(map_session_data* sd, unsigned short index) {
  16462. int fd = sd->fd;
  16463. WFIFOHEAD(fd,packet_len(0x908));
  16464. WFIFOW(fd,0) = 0x908;
  16465. WFIFOW(fd,2) = index+2;
  16466. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16467. WFIFOSET(fd,packet_len(0x908));
  16468. }
  16469. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16470. void clif_snap( struct block_list *bl, short x, short y ) {
  16471. unsigned char buf[10];
  16472. WBUFW(buf,0) = 0x8d2;
  16473. WBUFL(buf,2) = bl->id;
  16474. WBUFW(buf,6) = x;
  16475. WBUFW(buf,8) = y;
  16476. if( disguised(bl) )
  16477. {
  16478. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16479. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16480. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16481. } else
  16482. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16483. }
  16484. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16485. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16486. #if PACKETVER >= 20120404
  16487. WFIFOHEAD(fd,packet_len(0x977));
  16488. WFIFOW(fd,0) = 0x977;
  16489. WFIFOL(fd,2) = md->bl.id;
  16490. WFIFOL(fd,6) = md->status.hp;
  16491. WFIFOL(fd,10) = md->status.max_hp;
  16492. WFIFOSET(fd,packet_len(0x977));
  16493. #endif
  16494. }
  16495. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16496. void __attribute__ ((unused)) clif_parse_dull(int fd, map_session_data *sd) {
  16497. return;
  16498. }
  16499. void clif_partytickack(map_session_data* sd, bool flag) {
  16500. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16501. WFIFOW(sd->fd,0) = 0x2c9;
  16502. WFIFOB(sd->fd,2) = flag;
  16503. WFIFOSET(sd->fd, packet_len(0x2c9));
  16504. }
  16505. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16506. /// 0979 <world name>.24B <char name>.24B
  16507. void clif_ackworldinfo(map_session_data* sd) {
  16508. int fd;
  16509. nullpo_retv(sd);
  16510. fd = sd->fd;
  16511. WFIFOHEAD(fd,packet_len(0x979));
  16512. WFIFOW(fd,0)=0x979;
  16513. //AID -> world name ?
  16514. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16515. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16516. WFIFOSET(fd,packet_len(0x979));
  16517. }
  16518. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16519. /// 0978 <AID>.L
  16520. void clif_parse_reqworldinfo(int fd,map_session_data *sd) {
  16521. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16522. if(sd)
  16523. clif_ackworldinfo(sd);
  16524. }
  16525. static void clif_loadConfirm( map_session_data *sd ){
  16526. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16527. nullpo_retv( sd );
  16528. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16529. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16530. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16531. clif_instance_info( *sd );
  16532. #endif
  16533. }
  16534. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16535. /// 0447
  16536. void clif_parse_blocking_playcancel( int fd, map_session_data *sd ){
  16537. clif_loadConfirm( sd );
  16538. }
  16539. /// req world info (CZ_CLIENT_VERSION)
  16540. /// 044A <version>.L
  16541. void clif_parse_client_version(int fd, map_session_data *sd) {
  16542. //if(sd)
  16543. ;
  16544. }
  16545. /// Ranking list
  16546. /// ranking pointlist { <name>.24B <point>.L }*10
  16547. void clif_sub_ranklist(unsigned char *buf,int idx,map_session_data* sd, enum e_rank rankingtype){
  16548. struct fame_list* list;
  16549. int i, size = MAX_FAME_LIST;
  16550. switch(rankingtype) {
  16551. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16552. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16553. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16554. // PK currently unsupported
  16555. case RANK_KILLER: list = NULL; size = 0; break;
  16556. default:
  16557. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16558. return;
  16559. }
  16560. //Packet size limits this list to 10 elements. [Skotlex]
  16561. for (i = 0; i < min(10,size); i++) {
  16562. if (list[i].id > 0) {
  16563. const char* name;
  16564. if (strcmp(list[i].name, "-") == 0 &&
  16565. (name = map_charid2nick(list[i].id)) != NULL)
  16566. {
  16567. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16568. } else {
  16569. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16570. }
  16571. } else {
  16572. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16573. }
  16574. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16575. }
  16576. for(;i < 10; i++) { //In case the MAX is less than 10.
  16577. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16578. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16579. }
  16580. }
  16581. /// Request for the blacksmith ranklist.
  16582. /// /blacksmith command sends this packet to the server.
  16583. /// 0217 (CZ_BLACKSMITH_RANK)
  16584. void clif_parse_Blacksmith( int fd, map_session_data *sd ){
  16585. clif_ranklist(sd,RANK_BLACKSMITH);
  16586. }
  16587. /// Request for the alchemist ranklist.
  16588. /// /alchemist command sends this packet to the server.
  16589. /// 0218 (CZ_ALCHEMIST_RANK)
  16590. void clif_parse_Alchemist( int fd, map_session_data *sd ){
  16591. clif_ranklist(sd,RANK_ALCHEMIST);
  16592. }
  16593. /// Request for the taekwon ranklist.
  16594. /// /taekwon command sends this packet to the server.
  16595. /// 0225 (CZ_TAEKWON_RANK)
  16596. void clif_parse_Taekwon( int fd, map_session_data *sd ){
  16597. clif_ranklist(sd,RANK_TAEKWON);
  16598. }
  16599. /// Request for the killer ranklist.
  16600. /// /pk command sends this packet to the server.
  16601. /// 0237 (CZ_KILLER_RANK)
  16602. void clif_parse_RankingPk( int fd, map_session_data *sd ){
  16603. clif_ranklist(sd,RANK_KILLER);
  16604. }
  16605. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16606. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16607. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16608. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16609. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16610. void clif_ranklist(map_session_data *sd, int16 rankingType) {
  16611. enum e_rank rank;
  16612. #if PACKETVER < 20130710
  16613. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16614. short cmd;
  16615. switch( rankingType ){
  16616. case RANK_BLACKSMITH: cmd = 0x219; break;
  16617. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16618. case RANK_TAEKWON: cmd = 0x226; break;
  16619. case RANK_KILLER: cmd = 0x238; break;
  16620. default:
  16621. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16622. return;
  16623. }
  16624. // Can be safely casted here, since we validated it before
  16625. rank = (enum e_rank)rankingType;
  16626. WBUFW(buf,0) = cmd;
  16627. clif_sub_ranklist(buf,2,sd,rank);
  16628. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16629. #else
  16630. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16631. int mypoint = 0;
  16632. switch( rankingType ){
  16633. case RANK_BLACKSMITH:
  16634. case RANK_ALCHEMIST:
  16635. case RANK_TAEKWON:
  16636. case RANK_KILLER:
  16637. break;
  16638. default:
  16639. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16640. return;
  16641. }
  16642. // Can be safely casted here, since we validated it before
  16643. rank = (enum e_rank)rankingType;
  16644. WBUFW(buf,0) = 0x97d;
  16645. WBUFW(buf,2) = rank;
  16646. clif_sub_ranklist(buf,4,sd,rank);
  16647. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16648. case MAPID_BLACKSMITH:
  16649. case MAPID_ALCHEMIST:
  16650. case MAPID_TAEKWON:
  16651. mypoint = sd->status.fame;
  16652. }
  16653. WBUFL(buf,284) = mypoint; //mypoint
  16654. clif_send(buf, 288, &sd->bl, SELF);
  16655. #endif
  16656. }
  16657. /*
  16658. * 097c <type> (CZ_REQ_RANKING)
  16659. * type
  16660. * 0: /blacksmith
  16661. * 1: /alchemist
  16662. * 2: /taekwon
  16663. * 3: /pk
  16664. * */
  16665. void clif_parse_ranklist(int fd,map_session_data *sd) {
  16666. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16667. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16668. clif_ranklist(sd,rankingtype);
  16669. }
  16670. /// Updates the fame rank points for the given ranking.
  16671. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16672. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16673. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16674. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16675. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16676. int fd = sd.fd;
  16677. #if PACKETVER < 20130710
  16678. short cmd;
  16679. switch(rankingtype){
  16680. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16681. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16682. case RANK_TAEKWON: cmd = 0x224; break;
  16683. default:
  16684. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16685. return;
  16686. }
  16687. WFIFOHEAD(fd,packet_len(cmd));
  16688. WFIFOW(fd,0) = cmd;
  16689. WFIFOL(fd,2) = point;
  16690. WFIFOL(fd,6) = sd.status.fame;
  16691. WFIFOSET(fd, packet_len(cmd));
  16692. #else
  16693. WFIFOHEAD(fd,packet_len(0x97e));
  16694. WFIFOW(fd,0) = 0x97e;
  16695. WFIFOW(fd,2) = rankingtype;
  16696. WFIFOL(fd,4) = point;
  16697. WFIFOL(fd,8) = sd.status.fame;
  16698. WFIFOSET(fd,packet_len(0x97e));
  16699. #endif
  16700. }
  16701. /**
  16702. * Transmit personal information to player. (rates)
  16703. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16704. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16705. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16706. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16707. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16708. * FIXME!
  16709. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16710. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16711. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16712. */
  16713. #ifdef VIP_ENABLE
  16714. void clif_display_pinfo( map_session_data& sd ){
  16715. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16716. // 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]
  16717. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16718. /**
  16719. * EXP
  16720. */
  16721. //0:PCRoom
  16722. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16723. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16724. details_bexp[PINFO_BASIC] = 0;
  16725. else {
  16726. if (details_bexp[PINFO_BASIC] < 100) {
  16727. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16728. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16729. } else
  16730. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16731. }
  16732. //1:Premium
  16733. if( pc_isvip( &sd ) ){
  16734. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16735. if (details_bexp[PINFO_PREMIUM] < 0)
  16736. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16737. } else
  16738. details_bexp[PINFO_PREMIUM] = 0;
  16739. //2:Server
  16740. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16741. if (details_bexp[PINFO_SERVER] == 100)
  16742. details_bexp[PINFO_SERVER] = 0;
  16743. else {
  16744. if (details_bexp[PINFO_SERVER] < 100) {
  16745. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16746. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16747. } else
  16748. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16749. }
  16750. //3:TPLUS
  16751. details_bexp[PINFO_CAFE] = 0;
  16752. /**
  16753. * Drop rate
  16754. */
  16755. //0:PCRoom
  16756. details_drop[PINFO_BASIC] = 0;
  16757. //1:Premium
  16758. if( pc_isvip( &sd ) ){
  16759. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16760. if (details_drop[PINFO_PREMIUM] < 0)
  16761. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16762. } else
  16763. details_drop[PINFO_PREMIUM] = 0;
  16764. //2:Server
  16765. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16766. if (details_drop[PINFO_SERVER] == 100)
  16767. details_drop[PINFO_SERVER] = 0;
  16768. else {
  16769. if (details_drop[PINFO_SERVER] < 100) {
  16770. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16771. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16772. } else
  16773. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16774. }
  16775. //3:TPLUS
  16776. details_drop[PINFO_CAFE] = 0;
  16777. /**
  16778. * Penalty rate
  16779. */
  16780. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16781. //0:PCRoom
  16782. details_penalty[PINFO_BASIC] = 0;
  16783. //1:Premium
  16784. if( pc_isvip( &sd ) ){
  16785. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16786. if (details_penalty[PINFO_PREMIUM] == 100)
  16787. details_penalty[PINFO_PREMIUM] = 0;
  16788. else {
  16789. if (details_penalty[PINFO_PREMIUM] < 100) {
  16790. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16791. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16792. } else
  16793. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16794. }
  16795. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16796. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16797. } else
  16798. details_penalty[PINFO_PREMIUM] = 0;
  16799. //2:Server
  16800. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16801. if (details_penalty[PINFO_SERVER] == 100)
  16802. details_penalty[PINFO_SERVER] = 0;
  16803. else {
  16804. if (details_penalty[PINFO_SERVER] < 100) {
  16805. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16806. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16807. } else
  16808. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16809. }
  16810. //3:TPLUS
  16811. details_penalty[PINFO_CAFE] = 0;
  16812. struct PACKET_ZC_PERSONAL_INFOMATION* p = (struct PACKET_ZC_PERSONAL_INFOMATION*)packet_buffer;
  16813. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16814. p->length = sizeof( *p ) + PINFO_MAX * sizeof( p->details[0] );
  16815. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16816. p->total_exp = 100 * 1000;
  16817. p->total_death = 100 * 1000;
  16818. p->total_drop = 100 * 1000;
  16819. #else
  16820. p->total_exp = 100;
  16821. p->total_death = 100;
  16822. p->total_drop = 100;
  16823. #endif
  16824. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16825. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16826. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16827. p->details[i].exp = details_bexp[i] * 1000;
  16828. p->details[i].death = details_penalty[i] * 1000;
  16829. p->details[i].drop = details_drop[i] * 1000;
  16830. #else
  16831. p->details[i].exp = details_bexp[i];
  16832. p->details[i].death = details_penalty[i];
  16833. p->details[i].drop = details_drop[i];
  16834. #endif
  16835. p->total_exp += p->details[i].exp;
  16836. p->total_death += p->details[i].death;
  16837. p->total_drop += p->details[i].drop;
  16838. }
  16839. clif_send( p, p->length, &sd.bl, SELF );
  16840. #endif
  16841. }
  16842. #endif
  16843. void clif_parse_GMFullStrip(int fd, map_session_data *sd) {
  16844. char cmd[30];
  16845. int t_aid = RFIFOL(fd,2);
  16846. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16847. is_atcommand(fd, sd, cmd, 1);
  16848. }
  16849. /**
  16850. * Marks Crimson Marker target on mini-map to the caster
  16851. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16852. * @param fd
  16853. * @param bl Crimson Marker target
  16854. **/
  16855. void clif_crimson_marker( map_session_data& sd, struct block_list& bl, bool remove ){
  16856. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16857. struct PACKET_ZC_C_MARKERINFO p = {};
  16858. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16859. p.AID = bl.id;
  16860. if( remove ){
  16861. p.xPos = -1;
  16862. p.yPos = -1;
  16863. }else{
  16864. p.xPos = bl.x;
  16865. p.yPos = bl.y;
  16866. }
  16867. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16868. #endif
  16869. }
  16870. /**
  16871. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16872. **/
  16873. void clif_notify_bindOnEquip( map_session_data& sd, int16 index ){
  16874. #if PACKETVER >= 20070227
  16875. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16876. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16877. p.index = client_index( index );
  16878. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16879. #endif
  16880. }
  16881. /**
  16882. * [Ind/Hercules]
  16883. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16884. **/
  16885. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16886. char buf[256];
  16887. size_t len;
  16888. nullpo_retv(bl);
  16889. if(!message)
  16890. return;
  16891. len = strlen(message)+1;
  16892. if( len > sizeof(buf)-8 ) {
  16893. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16894. len = sizeof(buf)-8;
  16895. }
  16896. WBUFW(buf,0) = 0x8b3;
  16897. WBUFW(buf,2) = (uint16)(len+8);
  16898. WBUFL(buf,4) = bl->id;
  16899. safestrncpy(WBUFCP(buf,8), message, len);
  16900. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16901. }
  16902. /**
  16903. * [Ind/Hercules]
  16904. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16905. **/
  16906. void clif_party_leaderchanged(map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16907. unsigned char buf[10];
  16908. nullpo_retv(sd);
  16909. WBUFW(buf,0) = 0x7fc;
  16910. WBUFL(buf,2) = prev_leader_aid;
  16911. WBUFL(buf,6) = new_leader_aid;
  16912. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16913. }
  16914. /**
  16915. * Sends a clan message to a player
  16916. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16917. **/
  16918. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16919. #if PACKETVER >= 20131223
  16920. map_session_data *sd;
  16921. uint8 buf[256];
  16922. if( len == 0 ){
  16923. return;
  16924. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16925. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16926. len = sizeof(buf)-5-NAME_LENGTH;
  16927. }
  16928. WBUFW(buf, 0) = 0x98e;
  16929. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16930. // 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
  16931. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16932. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16933. if((sd = clan_getavailablesd(clan)) != NULL)
  16934. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16935. #endif
  16936. }
  16937. /**
  16938. * Parses a clan message from a player.
  16939. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16940. **/
  16941. void clif_parse_clan_chat( int fd, map_session_data* sd ){
  16942. #if PACKETVER >= 20131223
  16943. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16944. // validate packet and retrieve name and message
  16945. if( !clif_process_message(sd, false, name, message, output ) )
  16946. return;
  16947. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16948. #endif
  16949. }
  16950. /**
  16951. * Sends the basic clan informations to the client.
  16952. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16953. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16954. **/
  16955. void clif_clan_basicinfo( map_session_data *sd ){
  16956. #if PACKETVER >= 20131223
  16957. int fd, offset, length, i, flag;
  16958. struct clan* clan;
  16959. char mapname[MAP_NAME_LENGTH_EXT];
  16960. nullpo_retv( sd );
  16961. nullpo_retv( clan = sd->clan );
  16962. // Check if the player has a valid session and is not autotrading
  16963. if( !clif_session_isValid( sd ) ){
  16964. return;
  16965. }
  16966. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16967. fd = sd->fd;
  16968. WFIFOHEAD(fd,length);
  16969. memset( WFIFOP(fd, 0), 0, length );
  16970. WFIFOW( fd, 0 ) = 0x98a;
  16971. WFIFOL( fd, 4 ) = clan->id;
  16972. offset = 8;
  16973. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16974. offset += NAME_LENGTH;
  16975. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16976. offset += NAME_LENGTH;
  16977. mapindex_getmapname_ext( clan->map, mapname );
  16978. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16979. offset += MAP_NAME_LENGTH_EXT;
  16980. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16981. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16982. for( flag = 0; flag < 2; flag++ ){
  16983. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16984. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16985. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16986. offset += NAME_LENGTH;
  16987. }
  16988. }
  16989. }
  16990. WFIFOW( fd, 2 ) = offset;
  16991. WFIFOSET(fd,offset);
  16992. #endif
  16993. }
  16994. /**
  16995. * Updates the online and maximum player count of a clan.
  16996. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16997. **/
  16998. void clif_clan_onlinecount( struct clan* clan ){
  16999. #if PACKETVER >= 20131223
  17000. uint8 buf[6];
  17001. map_session_data *sd;
  17002. WBUFW(buf,0) = 0x988;
  17003. WBUFW(buf,2) = clan->connect_member;
  17004. WBUFW(buf,4) = clan->max_member;
  17005. if((sd = clan_getavailablesd(clan)) != NULL)
  17006. clif_send(buf, 6, &sd->bl, CLAN);
  17007. #endif
  17008. }
  17009. /**
  17010. * Notifies the client that the player has left his clan.
  17011. * 0989 (ZC_ACK_CLAN_LEAVE)
  17012. **/
  17013. void clif_clan_leave( map_session_data* sd ){
  17014. #if PACKETVER >= 20131223
  17015. int fd;
  17016. nullpo_retv( sd );
  17017. if( !clif_session_isValid( sd ) ){
  17018. return;
  17019. }
  17020. fd = sd->fd;
  17021. WFIFOHEAD(fd,2);
  17022. WFIFOW(fd,0) = 0x989;
  17023. WFIFOSET(fd,2);
  17024. #endif
  17025. }
  17026. /**
  17027. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  17028. * 0A2F <result>.B <title_id>.L
  17029. */
  17030. void clif_change_title_ack(map_session_data *sd, unsigned char result, unsigned long title_id)
  17031. {
  17032. #if PACKETVER >= 20150513
  17033. int fd;
  17034. nullpo_retv(sd);
  17035. if (!clif_session_isValid(sd))
  17036. return;
  17037. fd = sd->fd;
  17038. WFIFOHEAD(fd, packet_len(0xa2f));
  17039. WFIFOW(fd, 0) = 0xa2f;
  17040. WFIFOB(fd, 2) = result;
  17041. WFIFOL(fd, 3) = title_id;
  17042. WFIFOSET(fd, packet_len(0xa2f));
  17043. #endif
  17044. }
  17045. /**
  17046. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  17047. * 0A2E <title_id>.L
  17048. */
  17049. void clif_parse_change_title(int fd, map_session_data *sd)
  17050. {
  17051. int title_id;
  17052. nullpo_retv(sd);
  17053. title_id = RFIFOL(fd, 2);
  17054. if( title_id == sd->status.title_id ){
  17055. // It is exactly the same as the old one
  17056. return;
  17057. }else if( title_id <= 0 ){
  17058. sd->status.title_id = 0;
  17059. }else{
  17060. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17061. clif_change_title_ack(sd, 1, title_id);
  17062. return;
  17063. }
  17064. sd->status.title_id = title_id;
  17065. }
  17066. clif_name_area(&sd->bl);
  17067. clif_change_title_ack(sd, 0, title_id);
  17068. }
  17069. #ifdef DUMP_UNKNOWN_PACKET
  17070. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17071. {
  17072. const char* packet_txt = "save/packet.txt";
  17073. FILE* fp;
  17074. time_t time_server;
  17075. struct tm *datetime;
  17076. char datestr[512];
  17077. time(&time_server); // get time in seconds since 1/1/1970
  17078. datetime = localtime(&time_server); // convert seconds in structure
  17079. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17080. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17081. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17082. if( sd ) {
  17083. 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);
  17084. } else {
  17085. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17086. }
  17087. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17088. fprintf(fp, "\n");
  17089. fclose(fp);
  17090. } else {
  17091. ShowError("Failed to write '%s'.\n", packet_txt);
  17092. // Dump on console instead
  17093. if( sd ) {
  17094. 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);
  17095. } else {
  17096. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17097. }
  17098. ShowDump(RFIFOP(fd,0), packet_len);
  17099. }
  17100. }
  17101. #endif
  17102. /// Roulette System
  17103. /// Author: Yommy
  17104. void roulette_generate_bonus( map_session_data& sd ){
  17105. if( battle_config.feature_roulette_bonus_reward && sd.roulette.bonusItemID == 0 ){
  17106. int next_stage = 0;
  17107. if( sd.roulette_point.bronze > 0 ){
  17108. next_stage = 0;
  17109. }else if( sd.roulette_point.silver > 9 ){
  17110. next_stage = 2;
  17111. }else if( sd.roulette_point.gold > 9 ){
  17112. next_stage = 4;
  17113. }
  17114. // Get bonus item stage only from current stage or higher
  17115. int reward_stage = rnd_value( next_stage, MAX_ROULETTE_LEVEL - 1 );
  17116. sd.roulette.bonusItemID = rd.nameid[reward_stage][rnd()%rd.items[reward_stage]];
  17117. }else{
  17118. sd.roulette.bonusItemID = 0;
  17119. }
  17120. }
  17121. /// Opens the roulette window
  17122. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17123. void clif_roulette_open( map_session_data* sd ){
  17124. nullpo_retv( sd );
  17125. roulette_generate_bonus( *sd );
  17126. struct packet_roulette_open_ack p;
  17127. p.PacketType = 0xa1a;
  17128. p.Result = 0; // result
  17129. p.Serial = 0; // serial
  17130. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17131. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17132. p.AdditionItemID = sd->roulette.bonusItemID;
  17133. p.GoldPoint = sd->roulette_point.gold;
  17134. p.SilverPoint = sd->roulette_point.silver;
  17135. p.BronzePoint = sd->roulette_point.bronze;
  17136. sd->state.roulette_open = true;
  17137. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17138. }
  17139. /// Request to open the roulette window
  17140. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17141. void clif_parse_roulette_open( int fd, map_session_data* sd ){
  17142. nullpo_retv(sd);
  17143. if (!battle_config.feature_roulette) {
  17144. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17145. return;
  17146. }
  17147. clif_roulette_open(sd);
  17148. }
  17149. /// Sends the info about the available roulette rewards to the client
  17150. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17151. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17152. void clif_roulette_info( map_session_data* sd ){
  17153. nullpo_retv(sd);
  17154. struct packet_roulette_info_ack p;
  17155. p.PacketType = rouletteinfoackType;
  17156. p.PacketLength = sizeof(p);
  17157. p.RouletteSerial = 1;
  17158. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17159. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17160. p.ItemInfo[count].Row = i;
  17161. p.ItemInfo[count].Position = j;
  17162. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17163. p.ItemInfo[count].Count = rd.qty[i][j];
  17164. #if PACKETVER >= 20180511
  17165. p.ItemInfo[count].unused = 0;
  17166. #endif
  17167. count++;
  17168. }
  17169. }
  17170. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17171. }
  17172. /// Request the roulette reward data
  17173. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17174. void clif_parse_roulette_info( int fd, map_session_data* sd ){
  17175. nullpo_retv(sd);
  17176. if (!battle_config.feature_roulette) {
  17177. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17178. return;
  17179. }
  17180. clif_roulette_info(sd);
  17181. }
  17182. /// Notification of the client that the roulette window was closed
  17183. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17184. void clif_parse_roulette_close( int fd, map_session_data* sd ){
  17185. nullpo_retv(sd);
  17186. if (!battle_config.feature_roulette) {
  17187. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17188. return;
  17189. }
  17190. sd->state.roulette_open = false;
  17191. }
  17192. /// Response to a item reward request
  17193. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17194. static void clif_roulette_recvitem_ack(map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17195. #if PACKETVER >= 20141016
  17196. nullpo_retv(sd);
  17197. struct packet_roulette_itemrecv_ack p;
  17198. p.PacketType = roulettercvitemackType;
  17199. p.Result = type;
  17200. p.AdditionItemID = sd->roulette.bonusItemID;
  17201. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17202. #endif
  17203. }
  17204. /**
  17205. * Claim roulette reward
  17206. * @param sd Player
  17207. * @return 0:Success
  17208. **/
  17209. static uint8 clif_roulette_getitem(map_session_data *sd) {
  17210. struct item it;
  17211. uint8 res = 1;
  17212. unsigned short factor = 1;
  17213. nullpo_retr(1, sd);
  17214. if (sd->roulette.prizeIdx < 0)
  17215. return RECV_ITEM_FAILED;
  17216. memset(&it, 0, sizeof(it));
  17217. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17218. it.identify = 1;
  17219. if( sd->roulette.bonusItemID != 0 ){
  17220. if( sd->roulette.bonusItemID == it.nameid && battle_config.feature_roulette_bonus_reward && !( rd.flag[sd->roulette.prizeStage][sd->roulette.prizeIdx]&1 ) ){
  17221. factor = 2;
  17222. // Reset the Bonus Item to trigger new calculation
  17223. sd->roulette.bonusItemID = 0;
  17224. }else{
  17225. for( int i = 0; i < MAX_ROULETTE_LEVEL && sd->roulette.bonusItemID != 0; i++ ){
  17226. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i && sd->roulette.bonusItemID != 0; j++ ){
  17227. if( rd.nameid[i][j] == sd->roulette.bonusItemID ){
  17228. // 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
  17229. if( sd->roulette.prizeStage >= i ){
  17230. // Reset the Bonus Item to trigger new calculation and to cancel the loops
  17231. sd->roulette.bonusItemID = 0;
  17232. }
  17233. }
  17234. }
  17235. }
  17236. }
  17237. }
  17238. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx] * factor, LOG_TYPE_ROULETTE)) == 0) {
  17239. ; // onSuccess
  17240. }
  17241. if( sd->roulette.bonusItemID == 0 ){
  17242. roulette_generate_bonus( *sd );
  17243. }
  17244. sd->roulette.claimPrize = false;
  17245. sd->roulette.prizeStage = 0;
  17246. sd->roulette.prizeIdx = -1;
  17247. sd->roulette.stage = 0;
  17248. return res;
  17249. }
  17250. /// Update Roulette window with current stats
  17251. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17252. void clif_roulette_generate( map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17253. nullpo_retv( sd );
  17254. struct packet_roulette_generate_ack p;
  17255. p.PacketType = roulettgenerateackType;
  17256. p.Result = result;
  17257. p.Step = stage;
  17258. p.Idx = prizeIdx;
  17259. p.AdditionItemID = battle_config.feature_roulette_bonus_reward ? bonusItemID : 0;
  17260. p.RemainGold = sd->roulette_point.gold;
  17261. p.RemainSilver = sd->roulette_point.silver;
  17262. p.RemainBronze = sd->roulette_point.bronze;
  17263. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17264. }
  17265. /// Request to start the roulette
  17266. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17267. void clif_parse_roulette_generate( int fd, map_session_data* sd ){
  17268. enum GENERATE_ROULETTE_ACK result;
  17269. nullpo_retv(sd);
  17270. if (!battle_config.feature_roulette) {
  17271. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17272. return;
  17273. }
  17274. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17275. return;
  17276. }
  17277. // Player has not claimed his prize yet
  17278. if( sd->roulette.claimPrize ){
  17279. clif_roulette_getitem( sd );
  17280. }
  17281. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17282. // Make sure everything is reset
  17283. sd->roulette.stage = 0;
  17284. sd->roulette.claimPrize = false;
  17285. sd->roulette.prizeStage = 0;
  17286. sd->roulette.prizeIdx = -1;
  17287. }
  17288. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17289. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17290. }else{
  17291. if (!sd->roulette.stage) {
  17292. if (sd->roulette_point.bronze > 0) {
  17293. sd->roulette_point.bronze -= 1;
  17294. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17295. } else if (sd->roulette_point.silver > 9) {
  17296. sd->roulette_point.silver -= 10;
  17297. sd->roulette.stage = 2;
  17298. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17299. } else if (sd->roulette_point.gold > 9) {
  17300. sd->roulette_point.gold -= 10;
  17301. sd->roulette.stage = 4;
  17302. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17303. }
  17304. }
  17305. sd->roulette.prizeStage = sd->roulette.stage;
  17306. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17307. sd->roulette.claimPrize = true;
  17308. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17309. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17310. result = GENERATE_ROULETTE_LOSING;
  17311. sd->roulette.stage = 0;
  17312. }else{
  17313. result = GENERATE_ROULETTE_SUCCESS;
  17314. sd->roulette.stage++;
  17315. }
  17316. }
  17317. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx), sd->roulette.bonusItemID);
  17318. }
  17319. /// Request to claim a prize
  17320. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17321. void clif_parse_roulette_item( int fd, map_session_data* sd ){
  17322. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17323. nullpo_retv(sd);
  17324. if (!battle_config.feature_roulette) {
  17325. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17326. return;
  17327. }
  17328. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17329. return;
  17330. }
  17331. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17332. switch (clif_roulette_getitem(sd)) {
  17333. case ADDITEM_SUCCESS:
  17334. type = RECV_ITEM_SUCCESS;
  17335. break;
  17336. case ADDITEM_INVALID:
  17337. case ADDITEM_OVERITEM:
  17338. case ADDITEM_OVERAMOUNT:
  17339. type = RECV_ITEM_OVERCOUNT;
  17340. break;
  17341. case ADDITEM_OVERWEIGHT:
  17342. type = RECV_ITEM_OVERWEIGHT;
  17343. break;
  17344. case ADDITEM_STACKLIMIT:
  17345. default:
  17346. type = RECV_ITEM_FAILED;
  17347. break;
  17348. }
  17349. }
  17350. clif_roulette_recvitem_ack(sd,type);
  17351. }
  17352. /// MERGE ITEM
  17353. /**
  17354. * Acknowledge the client about item merger result
  17355. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17356. * @param fd
  17357. * @param sd
  17358. **/
  17359. void clif_merge_item_ack( map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17360. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17361. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17362. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17363. if( type == MERGE_ITEM_SUCCESS ){
  17364. p.index = client_index( index );
  17365. }else{
  17366. p.index = index;
  17367. }
  17368. p.amount = count;
  17369. p.reason = type;
  17370. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17371. #endif
  17372. }
  17373. /**
  17374. * Check if item has the pair to be merged
  17375. * @param sd
  17376. * @param it Item
  17377. * @return True if has pair, False if not
  17378. **/
  17379. static bool clif_merge_item_has_pair(map_session_data *sd, struct item *it) {
  17380. struct item *it_;
  17381. unsigned short i;
  17382. nullpo_retr(false, sd);
  17383. 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);
  17384. if (i < MAX_INVENTORY)
  17385. return true;
  17386. return false;
  17387. }
  17388. /**
  17389. * Check if item can be merged
  17390. * @param id Item Data
  17391. * @param it Item
  17392. * @return True if can be merged, False if not
  17393. **/
  17394. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17395. if (!id || !it)
  17396. return false;
  17397. if (id->type == IT_CASH)
  17398. return false;
  17399. if (!itemdb_isstackable2(id))
  17400. return false;
  17401. if (itemdb_isspecial(it->card[0]))
  17402. return false;
  17403. if (!it->unique_id)
  17404. return false;
  17405. return true;
  17406. }
  17407. /**
  17408. * Open available item to be merged.
  17409. * Only show 1 item in 1 process.
  17410. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17411. * @param sd
  17412. **/
  17413. void clif_merge_item_open( map_session_data& sd ){
  17414. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17415. struct PACKET_ZC_MERGE_ITEM_OPEN* p = (struct PACKET_ZC_MERGE_ITEM_OPEN*)packet_buffer;
  17416. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17417. p->packetLen = sizeof( *p );
  17418. int n = 0;
  17419. // Get entries
  17420. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17421. struct item* it = &sd.inventory.u.items_inventory[i];
  17422. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17423. continue;
  17424. }
  17425. if( clif_merge_item_has_pair( &sd, it ) ){
  17426. p->items[n++].index = client_index( i );
  17427. p->packetLen += sizeof( p->items[0] );
  17428. }
  17429. }
  17430. // No item need to be merged
  17431. if( n < 2 ){
  17432. clif_msg( &sd, MERGE_ITEM_NOT_AVAILABLE );
  17433. return;
  17434. }
  17435. clif_send( p, p->packetLen, &sd.bl, SELF );
  17436. #endif
  17437. }
  17438. /**
  17439. * Process item merge request.
  17440. * 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17441. * @param fd
  17442. * @param sd
  17443. **/
  17444. void clif_parse_merge_item_req( int fd, map_session_data* sd ){
  17445. struct PACKET_CZ_REQ_MERGE_ITEM* p = (struct PACKET_CZ_REQ_MERGE_ITEM*)RFIFOP( fd, 0 );
  17446. int count = ( p->packetLength - sizeof( *p ) ) / sizeof( p->indices[0] );
  17447. // No item need to be merged
  17448. if( count < 2 ){
  17449. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17450. return;
  17451. }
  17452. uint16 idx_main = server_index( p->indices[0] );
  17453. if( idx_main >= MAX_INVENTORY ){
  17454. return;
  17455. }
  17456. if( !clif_merge_item_check( sd->inventory_data[idx_main], &sd->inventory.u.items_inventory[idx_main] ) ){
  17457. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17458. return;
  17459. }
  17460. // Ensure each index only comes once
  17461. std::unordered_set<uint16> indices;
  17462. for( int i = 1; i < count; i++ ){
  17463. uint16 idx = server_index( p->indices[i] );
  17464. if( idx >= MAX_INVENTORY ){
  17465. return;
  17466. }
  17467. if( sd->inventory_data[idx] == nullptr ){
  17468. return;
  17469. }
  17470. // Check if it is the same item
  17471. if( sd->inventory_data[idx]->nameid != sd->inventory_data[idx_main]->nameid ){
  17472. return;
  17473. }
  17474. if( !clif_merge_item_check( sd->inventory_data[idx], &sd->inventory.u.items_inventory[idx] ) ){
  17475. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17476. return;
  17477. }
  17478. indices.insert( idx );
  17479. }
  17480. if( indices.empty() ){
  17481. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17482. return;
  17483. }
  17484. uint32 total_amount = sd->inventory.u.items_inventory[idx_main].amount;
  17485. for( uint16 idx : indices ){
  17486. total_amount += sd->inventory.u.items_inventory[idx].amount;
  17487. }
  17488. uint16 stack = sd->inventory_data[idx_main]->stack.amount;
  17489. if( stack == 0 ){
  17490. stack = MAX_AMOUNT;
  17491. }
  17492. if( total_amount >= stack ){
  17493. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17494. return;
  17495. }
  17496. // Merrrrge!!!!
  17497. for( uint16 idx : indices ){
  17498. uint16 amount = sd->inventory.u.items_inventory[idx].amount;
  17499. log_pick_pc( sd, LOG_TYPE_MERGE_ITEM, -amount, &sd->inventory.u.items_inventory[idx] );
  17500. memset( &sd->inventory.u.items_inventory[idx], 0, sizeof( sd->inventory.u.items_inventory[0] ) );
  17501. sd->inventory_data[idx] = nullptr;
  17502. clif_delitem( sd, idx, amount, 0 );
  17503. }
  17504. sd->inventory.u.items_inventory[idx_main].amount = total_amount;
  17505. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, idx_main, total_amount );
  17506. }
  17507. /**
  17508. * Cancel item merge
  17509. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17510. * @param fd
  17511. * @param sd
  17512. **/
  17513. void clif_parse_merge_item_cancel(int fd, map_session_data* sd) {
  17514. return; // Nothing todo yet
  17515. }
  17516. static std::string clif_hide_name(const char* original_name)
  17517. {
  17518. std::string censored(original_name);
  17519. int hide = min(battle_config.broadcast_hide_name, censored.length() - 1);
  17520. censored.replace(censored.length() - hide, hide, hide, '*');
  17521. return censored;
  17522. }
  17523. /**
  17524. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17525. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17526. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17527. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17528. **/
  17529. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17530. char name[NAME_LENGTH];
  17531. if( battle_config.broadcast_hide_name ){
  17532. std::string dispname = clif_hide_name(char_name);
  17533. safestrncpy(name, dispname.c_str(), sizeof(name));
  17534. }else{
  17535. safestrncpy( name, char_name, sizeof( name ) );
  17536. }
  17537. switch( type ){
  17538. case ITEMOBTAIN_TYPE_BOXITEM:
  17539. #if PACKETVER >= 20091201
  17540. {
  17541. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17542. p.PacketType = package_item_announceType;
  17543. p.PacketLength = sizeof( p );
  17544. p.type = type;
  17545. p.ItemID = client_nameid( nameid );
  17546. p.len = NAME_LENGTH;
  17547. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17548. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17549. p.BoxItemID = client_nameid( container );
  17550. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17551. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17552. p.refineLevel = 0; // TODO: implement
  17553. #endif
  17554. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17555. }
  17556. #endif
  17557. break;
  17558. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17559. case ITEMOBTAIN_TYPE_NPC:
  17560. {
  17561. struct packet_item_drop_announce p;
  17562. p.PacketType = item_drop_announceType;
  17563. p.type = type;
  17564. p.ItemID = client_nameid( nameid );
  17565. p.len = NAME_LENGTH;
  17566. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17567. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17568. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17569. p.monsterNameLen = NAME_LENGTH;
  17570. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17571. }else{
  17572. p.monsterNameLen = 0;
  17573. p.monsterName[0] = '\0';
  17574. }
  17575. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17576. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17577. #else
  17578. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17579. #endif
  17580. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17581. }
  17582. break;
  17583. }
  17584. }
  17585. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17586. /// 0A02 <view>.W
  17587. /// Value <flag> has the following effects:
  17588. /// 1: Open a Dress Room window.
  17589. void clif_dressing_room(map_session_data *sd, int flag) {
  17590. #if PACKETVER >= 20150513
  17591. int fd = sd->fd;
  17592. nullpo_retv(sd);
  17593. WFIFOHEAD(fd, packet_len(0xa02));
  17594. WFIFOW(fd,0) = 0xa02;
  17595. WFIFOW(fd,2) = flag;
  17596. WFIFOSET(fd, packet_len(0xa02));
  17597. #endif
  17598. }
  17599. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17600. /// 0A35 <result>.W
  17601. void clif_parse_Oneclick_Itemidentify(int fd, map_session_data *sd) {
  17602. #if PACKETVER >= 20150513
  17603. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17604. // Ignore the request
  17605. // - Invalid item index
  17606. // - Invalid item ID or item doesn't exist
  17607. // - Item is already identified
  17608. if (idx < 0 || idx >= MAX_INVENTORY ||
  17609. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17610. sd->inventory.u.items_inventory[idx].identify)
  17611. return;
  17612. // Ignore the request - No magnifiers in inventory
  17613. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17614. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17615. return;
  17616. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17617. return;
  17618. skill_identify(sd, idx);
  17619. #endif
  17620. }
  17621. /// Starts navigation to the given target on client side
  17622. void clif_navigateTo(map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17623. #if PACKETVER >= 20111010
  17624. int fd = sd->fd;
  17625. WFIFOHEAD(fd,27);
  17626. WFIFOW(fd,0) = 0x08e2;
  17627. // How detailed will our navigation be?
  17628. if( mob_id > 0 ){
  17629. x = 0;
  17630. y = 0;
  17631. WFIFOB(fd,2) = 3; // monster with destination field
  17632. }else if( x > 0 && y > 0 ){
  17633. WFIFOB(fd,2) = 0; // with coordinates
  17634. }else{
  17635. x = 0;
  17636. y = 0;
  17637. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17638. }
  17639. // Which services can be used for transportation?
  17640. WFIFOB(fd,3) = flag;
  17641. // If this flag is set, the navigation window will not be opened up
  17642. WFIFOB(fd,4) = hideWindow;
  17643. // Target map
  17644. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17645. // Target x
  17646. WFIFOW(fd,21) = x;
  17647. // Target y
  17648. WFIFOW(fd,23) = y;
  17649. // Target monster ID
  17650. WFIFOW(fd,25) = mob_id;
  17651. WFIFOSET(fd,27);
  17652. #endif
  17653. }
  17654. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17655. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17656. void clif_hat_effects( map_session_data* sd, struct block_list* bl, enum send_target target ){
  17657. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17658. map_session_data *tsd;
  17659. struct block_list* tbl;
  17660. if( target == SELF ){
  17661. tsd = BL_CAST(BL_PC,bl);
  17662. tbl = &sd->bl;
  17663. }else{
  17664. tsd = sd;
  17665. tbl = bl;
  17666. }
  17667. nullpo_retv( tsd );
  17668. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->getMapFlag(MF_NOCOSTUME) ){
  17669. return;
  17670. }
  17671. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17672. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17673. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17674. p->aid = tsd->bl.id;
  17675. p->status = 1;
  17676. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17677. p->effects[i] = tsd->hatEffects[i];
  17678. }
  17679. clif_send( p, p->packetLength, tbl, target );
  17680. #endif
  17681. }
  17682. void clif_hat_effect_single( map_session_data* sd, uint16 effectId, bool enable ){
  17683. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17684. nullpo_retv( sd );
  17685. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17686. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17687. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17688. p->aid = sd->bl.id;
  17689. p->status = enable;
  17690. p->effects[0] = effectId;
  17691. clif_send( p, p->packetLength, &sd->bl, AREA );
  17692. #endif
  17693. }
  17694. /// Notify the client that a sale has started
  17695. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17696. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17697. #if PACKETVER_SUPPORTS_SALES
  17698. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17699. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17700. p.itemId = client_nameid( sale_item->nameid );
  17701. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17702. clif_send( &p, sizeof( p ), bl, target );
  17703. #endif
  17704. }
  17705. /// Notify the client that a sale has ended
  17706. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17707. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17708. #if PACKETVER_SUPPORTS_SALES
  17709. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17710. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17711. p.itemId = client_nameid( sale_item->nameid );
  17712. clif_send( &p, sizeof( p ), bl, target );
  17713. #endif
  17714. }
  17715. /// Update the remaining amount of a sale item.
  17716. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17717. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17718. #if PACKETVER_SUPPORTS_SALES
  17719. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17720. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17721. p.itemId = client_nameid( sale_item->nameid );
  17722. p.amount = sale_item->amount;
  17723. clif_send( &p, sizeof( p ), bl, target );
  17724. #endif
  17725. }
  17726. /// The client requested a refresh of the current remaining count of a sale item
  17727. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17728. void clif_parse_sale_refresh( int fd, map_session_data* sd ){
  17729. #if PACKETVER_SUPPORTS_SALES
  17730. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17731. struct sale_item_data* sale;
  17732. if( p->AID != sd->status.account_id ){
  17733. return;
  17734. }
  17735. sale = sale_find_item( p->itemId, true );
  17736. if( sale == NULL ){
  17737. return;
  17738. }
  17739. clif_sale_amount(sale, &sd->bl, SELF);
  17740. #endif
  17741. }
  17742. /// Opens the sale administration window on the client
  17743. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17744. void clif_sale_open( map_session_data* sd ){
  17745. #if PACKETVER_SUPPORTS_SALES
  17746. nullpo_retv(sd);
  17747. if( sd->state.sale_open ){
  17748. return;
  17749. }
  17750. sd->state.sale_open = true;
  17751. int fd = sd->fd;
  17752. WFIFOHEAD(fd, 2);
  17753. WFIFOW(fd, 0) = 0x9b5;
  17754. WFIFOSET(fd, 2);
  17755. #endif
  17756. }
  17757. /// Client request to open the sale administration window.
  17758. /// This is sent by /limitedsale
  17759. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17760. void clif_parse_sale_open( int fd, map_session_data* sd ){
  17761. #if PACKETVER_SUPPORTS_SALES
  17762. nullpo_retv(sd);
  17763. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17764. return;
  17765. }
  17766. char command[CHAT_SIZE_MAX];
  17767. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17768. is_atcommand(fd, sd, command, 1);
  17769. #endif
  17770. }
  17771. /// Closes the sale administration window on the client.
  17772. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17773. void clif_sale_close(map_session_data* sd) {
  17774. #if PACKETVER_SUPPORTS_SALES
  17775. nullpo_retv(sd);
  17776. if( !sd->state.sale_open ){
  17777. return;
  17778. }
  17779. sd->state.sale_open = false;
  17780. int fd = sd->fd;
  17781. WFIFOHEAD(fd, 2);
  17782. WFIFOW(fd, 0) = 0x9bd;
  17783. WFIFOSET(fd, 2);
  17784. #endif
  17785. }
  17786. /// Client request to close the sale administration window.
  17787. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17788. void clif_parse_sale_close(int fd, map_session_data* sd) {
  17789. #if PACKETVER_SUPPORTS_SALES
  17790. nullpo_retv(sd);
  17791. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17792. return;
  17793. }
  17794. clif_sale_close(sd);
  17795. #endif
  17796. }
  17797. /// Reply to a item search request for item sale administration.
  17798. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17799. void clif_sale_search_reply( map_session_data* sd, std::shared_ptr<s_cash_item> item ){
  17800. #if PACKETVER_SUPPORTS_SALES
  17801. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17802. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17803. if( item != NULL ){
  17804. p.result = 0;
  17805. p.itemId = client_nameid( item->nameid );
  17806. p.price = item->price;
  17807. }else{
  17808. p.result = 1;
  17809. p.itemId = 0;
  17810. p.price = 0;
  17811. }
  17812. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17813. #endif
  17814. }
  17815. /// Search request for an item sale administration.
  17816. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17817. void clif_parse_sale_search( int fd, map_session_data* sd ){
  17818. #if PACKETVER_SUPPORTS_SALES
  17819. char item_name[ITEM_NAME_LENGTH];
  17820. nullpo_retv(sd);
  17821. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17822. return;
  17823. }
  17824. if( !sd->state.sale_open ){
  17825. return;
  17826. }
  17827. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17828. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17829. // not found
  17830. if( id == nullptr ){
  17831. clif_sale_search_reply( sd, nullptr );
  17832. return;
  17833. }
  17834. clif_sale_search_reply( sd, cash_shop_db.findItemInTab( CASHSHOP_TAB_SALE, id->nameid ) );
  17835. #endif
  17836. }
  17837. /// Reply if an item was successfully put on sale or not.
  17838. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17839. void clif_sale_add_reply( map_session_data* sd, enum e_sale_add_result result ){
  17840. #if PACKETVER_SUPPORTS_SALES
  17841. int fd = sd->fd;
  17842. WFIFOHEAD(fd, 4);
  17843. WFIFOW(fd, 0) = 0x9af;
  17844. WFIFOW(fd, 2) = (uint16)result;
  17845. WFIFOSET(fd, 4);
  17846. #endif
  17847. }
  17848. /// A client request to put an item on sale.
  17849. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17850. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17851. void clif_parse_sale_add( int fd, map_session_data* sd ){
  17852. #if PACKETVER_SUPPORTS_SALES
  17853. nullpo_retv( sd );
  17854. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17855. if( p->AID != sd->status.account_id ){
  17856. return;
  17857. }
  17858. if( !sd->state.sale_open ){
  17859. return;
  17860. }
  17861. time_t endTime = p->startTime + p->hours * 60 * 60;
  17862. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17863. #endif
  17864. }
  17865. /// Reply to an item removal from sale.
  17866. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17867. void clif_sale_remove_reply( map_session_data* sd, bool failed ){
  17868. #if PACKETVER_SUPPORTS_SALES
  17869. int fd = sd->fd;
  17870. WFIFOHEAD(fd, 4);
  17871. WFIFOW(fd, 0) = 0x9b1;
  17872. WFIFOW(fd, 2) = failed;
  17873. WFIFOSET(fd, 4);
  17874. #endif
  17875. }
  17876. /// Request to remove an item from sale.
  17877. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17878. void clif_parse_sale_remove( int fd, map_session_data* sd ){
  17879. #if PACKETVER_SUPPORTS_SALES
  17880. nullpo_retv( sd );
  17881. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17882. if( p->AID != sd->status.account_id ){
  17883. return;
  17884. }
  17885. if( !sd->state.sale_open ){
  17886. return;
  17887. }
  17888. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17889. #endif
  17890. }
  17891. /// Achievement System
  17892. /// Author: Luxuri, Aleos
  17893. /**
  17894. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17895. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17896. */
  17897. void clif_achievement_list_all(map_session_data *sd)
  17898. {
  17899. nullpo_retv(sd);
  17900. if (!battle_config.feature_achievement) {
  17901. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17902. return;
  17903. }
  17904. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17905. if (count == 0)
  17906. return;
  17907. int len = (50 * count) + 22;
  17908. int fd = sd->fd;
  17909. int *info = achievement_level(sd, true);
  17910. WFIFOHEAD(fd,len);
  17911. WFIFOW(fd, 0) = 0xa23;
  17912. WFIFOW(fd, 2) = len;
  17913. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17914. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17915. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17916. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17917. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17918. for (int i = 0; i < count; i++) {
  17919. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17920. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17921. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17922. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17923. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17924. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17925. }
  17926. WFIFOSET(fd, len);
  17927. }
  17928. /**
  17929. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17930. * 0a24 <ACHPoint>.L
  17931. */
  17932. void clif_achievement_update(map_session_data *sd, struct achievement *ach, int count)
  17933. {
  17934. nullpo_retv(sd);
  17935. if (!battle_config.feature_achievement) {
  17936. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17937. return;
  17938. }
  17939. int fd = sd->fd;
  17940. int *info = achievement_level(sd, true);
  17941. WFIFOHEAD(fd, packet_len(0xa24));
  17942. WFIFOW(fd, 0) = 0xa24;
  17943. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17944. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17945. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17946. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17947. if (ach) {
  17948. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17949. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17950. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17951. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17952. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17953. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17954. } else
  17955. memset(WFIFOP(fd, 16), 0, 40);
  17956. WFIFOSET(fd, packet_len(0xa24));
  17957. }
  17958. /**
  17959. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17960. * 0a25 <achievementID>.L
  17961. */
  17962. void clif_parse_AchievementCheckReward(int fd, map_session_data *sd)
  17963. {
  17964. nullpo_retv(sd);
  17965. if( sd->achievement_data.save )
  17966. intif_achievement_save(sd);
  17967. achievement_check_reward(sd, RFIFOL(fd,2));
  17968. }
  17969. /**
  17970. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17971. * 0a26 <result>.W <achievementID>.L
  17972. */
  17973. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17974. {
  17975. WFIFOHEAD(fd, packet_len(0xa26));
  17976. WFIFOW(fd, 0) = 0xa26;
  17977. WFIFOB(fd, 2) = result;
  17978. WFIFOL(fd, 3) = achievement_id;
  17979. WFIFOSET(fd, packet_len(0xa26));
  17980. }
  17981. /// Process the pet evolution request
  17982. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17983. void clif_parse_pet_evolution( int fd, map_session_data *sd ){
  17984. #if PACKETVER >= 20141008
  17985. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17986. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17987. if (!pet) {
  17988. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17989. return;
  17990. }
  17991. pet_evolution(sd, pet->class_);
  17992. #endif
  17993. }
  17994. /// Sends the result of the evolution to the client.
  17995. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17996. void clif_pet_evolution_result( map_session_data* sd, e_pet_evolution_result result ){
  17997. #if PACKETVER >= 20141008
  17998. int fd = sd->fd;
  17999. WFIFOHEAD(fd, packet_len(0x9fc));
  18000. WFIFOW(fd, 0) = 0x9fc;
  18001. WFIFOL(fd, 2) = static_cast<uint32>(result);
  18002. WFIFOSET(fd, packet_len(0x9fc));
  18003. #endif
  18004. }
  18005. /*
  18006. * This packet is sent by /changedress or /nocosplay
  18007. *
  18008. * 0ae8
  18009. */
  18010. void clif_parse_changedress( int fd, map_session_data* sd ){
  18011. #if PACKETVER >= 20180103
  18012. char command[CHAT_SIZE_MAX];
  18013. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  18014. is_atcommand( fd, sd, command, 1 );
  18015. #endif
  18016. }
  18017. /// Opens an UI window of the given type and initializes it with the given data
  18018. /// 0AE2 <type>.B <data>.L
  18019. void clif_ui_open( map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  18020. #if PACKETVER >= 20151202
  18021. // If the UI requires state tracking
  18022. switch( ui_type ){
  18023. case OUT_UI_STYLIST:
  18024. sd.state.stylist_open = true;
  18025. break;
  18026. case OUT_UI_ENCHANTGRADE:
  18027. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  18028. sd.state.enchantgrade_open = true;
  18029. break;
  18030. #else
  18031. return;
  18032. #endif
  18033. }
  18034. struct PACKET_ZC_UI_OPEN p = {};
  18035. p.PacketType = HEADER_ZC_UI_OPEN;
  18036. p.UIType = ui_type;
  18037. #if PACKETVER >= 20171122
  18038. p.data = data;
  18039. #endif
  18040. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  18041. #endif
  18042. }
  18043. /// Request to open an UI window of the given type
  18044. /// 0A68 <type>.B
  18045. void clif_parse_open_ui( int fd, map_session_data* sd ){
  18046. switch( RFIFOB(fd,2) ){
  18047. case IN_UI_ATTENDANCE:
  18048. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  18049. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  18050. }else if( pc_attendance_enabled() ){
  18051. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  18052. }else{
  18053. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  18054. }
  18055. break;
  18056. #if PACKETVER >= 20160316
  18057. case IN_UI_MACRO_REGISTER:
  18058. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  18059. break;
  18060. case IN_UI_MACRO_DETECTOR:
  18061. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  18062. break;
  18063. #endif
  18064. }
  18065. }
  18066. /// Response for attedance request
  18067. /// 0AF0 <unknown>.L <data>.L
  18068. void clif_attendence_response( map_session_data *sd, int32 data ){
  18069. nullpo_retv(sd);
  18070. int fd = sd->fd;
  18071. WFIFOHEAD(fd,packet_len(0xAF0));
  18072. WFIFOW(fd,0) = 0xAF0;
  18073. WFIFOL(fd,2) = 0;
  18074. WFIFOL(fd,6) = data;
  18075. WFIFOSET(fd,packet_len(0xAF0));
  18076. }
  18077. /// Request from the client to retrieve today's attendance reward
  18078. /// 0AEF
  18079. void clif_parse_attendance_request( int fd, map_session_data* sd ){
  18080. pc_attendance_claim_reward(sd);
  18081. }
  18082. /// Send out the percentage of weight that causes it to be displayed in red.
  18083. /// 0ADE <percentage>.L
  18084. void clif_weight_limit( map_session_data* sd ){
  18085. #if PACKETVER >= 20171025
  18086. nullpo_retv(sd);
  18087. int fd = sd->fd;
  18088. WFIFOHEAD(fd, packet_len(0xADE));
  18089. WFIFOW(fd, 0) = 0xADE;
  18090. #ifdef RENEWAL
  18091. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18092. #else
  18093. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18094. #endif
  18095. WFIFOSET(fd, packet_len(0xADE));
  18096. #endif
  18097. }
  18098. enum e_private_airship_response : uint32{
  18099. PRIVATEAIRSHIP_OK,
  18100. PRIVATEAIRSHIP_RETRY,
  18101. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18102. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18103. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18104. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18105. };
  18106. /// Send out the response to a private airship request
  18107. /// 0A4A <response>.L
  18108. void clif_private_airship_response( map_session_data* sd, enum e_private_airship_response response ){
  18109. #if PACKETVER >= 20180321
  18110. nullpo_retv( sd );
  18111. int fd = sd->fd;
  18112. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18113. WFIFOW( fd, 0 ) = 0xA4A;
  18114. WFIFOL( fd, 2 ) = response;
  18115. WFIFOSET( fd, packet_len( 0xA4A ) );
  18116. #endif
  18117. }
  18118. /// Parses a request for a private airship
  18119. /// 0A49 <mapname>.16B <itemid>.W
  18120. void clif_parse_private_airship_request( int fd, map_session_data* sd ){
  18121. #if PACKETVER >= 20180321
  18122. // Check if the feature is enabled
  18123. if( !battle_config.feature_privateairship ){
  18124. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18125. return;
  18126. }
  18127. // Check if the player is allowed to warp from the source map
  18128. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18129. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18130. return;
  18131. }
  18132. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18133. char mapname[MAP_NAME_LENGTH_EXT];
  18134. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18135. int16 mapindex = mapindex_name2id( mapname );
  18136. // Check if we know the mapname
  18137. if( mapindex < 0 ){
  18138. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18139. return;
  18140. }
  18141. int16 mapid = map_mapindex2mapid( mapindex );
  18142. // Check if the map is available on this server
  18143. if( mapid < 0 ){
  18144. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18145. return;
  18146. }
  18147. // Check if the player tried to warp to the map he is on
  18148. if( sd->bl.m == mapid ){
  18149. // This is blocked by the client, but just to be sure
  18150. return;
  18151. }
  18152. // This can only be a hack, so we prevent it
  18153. if( map_getmapdata( mapid )->instance_id ){
  18154. // Ignore requests to warp directly into a running instance
  18155. return;
  18156. }
  18157. // Check if the player is allowed to warp to the target map
  18158. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18159. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18160. return;
  18161. }
  18162. t_itemid item_id = p->ItemID;
  18163. // Check if the item sent by the client is known to us
  18164. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18165. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18166. return;
  18167. }
  18168. int idx = pc_search_inventory( sd, item_id );
  18169. // Check if the player has the item at all
  18170. if( idx < 0 ){
  18171. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18172. return;
  18173. }
  18174. // Delete the chosen item
  18175. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18176. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18177. return;
  18178. }
  18179. // Warp the player to a random spot on the destination map
  18180. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18181. #endif
  18182. }
  18183. /// Sends out the usage history of the guild storage
  18184. /// 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
  18185. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18186. void clif_guild_storage_log( map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18187. #if PACKETVER >= 20140205
  18188. nullpo_retv( sd );
  18189. int fd = sd->fd;
  18190. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18191. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18192. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18193. }else{
  18194. log.clear();
  18195. }
  18196. WFIFOHEAD( fd, size );
  18197. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18198. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18199. p->PacketLength = size;
  18200. p->result = result;
  18201. p->amount = (uint16)log.size();
  18202. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18203. for( int i = 0; i < log.size(); i++ ){
  18204. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18205. struct guild_log_entry& entry = log[i];
  18206. item->id = entry.id;
  18207. item->itemId = client_nameid( entry.item.nameid );
  18208. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18209. item->action = entry.amount > 0; // action = true(put), false(get)
  18210. item->refine = entry.item.refine;
  18211. item->uniqueId = entry.item.unique_id;
  18212. item->IsIdentified = entry.item.identify;
  18213. item->itemType = itemtype( entry.item.nameid );
  18214. clif_addcards( &item->slot, &entry.item );
  18215. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18216. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18217. item->attribute = entry.item.attribute;
  18218. }
  18219. }
  18220. WFIFOSET( fd, p->PacketLength );
  18221. #endif
  18222. }
  18223. /// Activates the client camera info or updates the client camera with the given values.
  18224. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18225. void clif_camerainfo( map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18226. #if PACKETVER >= 20160525
  18227. int fd = sd->fd;
  18228. WFIFOHEAD(fd, packet_len(0xa78));
  18229. WFIFOW(fd, 0) = 0xa78;
  18230. WFIFOB(fd, 2) = show;
  18231. WFIFOF(fd, 3) = range;
  18232. WFIFOF(fd, 7) = rotation;
  18233. WFIFOF(fd, 11) = latitude;
  18234. WFIFOSET(fd, packet_len(0xa78));
  18235. #endif
  18236. }
  18237. /// Activates or deactives the client camera info or updates the camera settings.
  18238. /// This packet is triggered by /viewpointvalue or /setcamera
  18239. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18240. void clif_parse_camerainfo( int fd, map_session_data* sd ){
  18241. char command[CHAT_SIZE_MAX];
  18242. // /viewpointvalue
  18243. if( RFIFOB( fd, 2 ) == 1 ){
  18244. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18245. // /setcamera
  18246. }else{
  18247. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18248. }
  18249. is_atcommand( fd, sd, command, 1 );
  18250. }
  18251. /// Send the full list of items in the equip switch window
  18252. /// 0a9b <length>.W { <index>.W <position>.L }*
  18253. void clif_equipswitch_list( map_session_data* sd ){
  18254. #if PACKETVER >= 20170208
  18255. int fd = sd->fd;
  18256. int offset, i, position;
  18257. WFIFOW(fd, 0) = 0xa9b;
  18258. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18259. short index = sd->equip_switch_index[i];
  18260. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18261. WFIFOW(fd, offset) = index + 2;
  18262. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18263. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18264. offset += 6;
  18265. }
  18266. }
  18267. WFIFOW(fd, 2) = offset;
  18268. WFIFOSET(fd, offset);
  18269. #endif
  18270. }
  18271. /// Acknowledgement for removing an equip to the equip switch window
  18272. /// 0a9a <index>.W <position.>.L <failure>.W
  18273. void clif_equipswitch_remove( map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18274. #if PACKETVER >= 20170208
  18275. int fd = sd->fd;
  18276. WFIFOHEAD(fd, packet_len(0xa9a));
  18277. WFIFOW(fd, 0) = 0xa9a;
  18278. WFIFOW(fd, 2) = index + 2;
  18279. WFIFOL(fd, 4) = pos;
  18280. WFIFOW(fd, 8) = failed;
  18281. WFIFOSET(fd, packet_len(0xa9a));
  18282. #endif
  18283. }
  18284. /// Request to remove an equip from the equip switch window
  18285. /// 0a99 <index>.W <position>.L <= 20170502
  18286. /// 0a99 <index>.W
  18287. void clif_parse_equipswitch_remove( int fd, map_session_data* sd ){
  18288. #if PACKETVER >= 20170208
  18289. uint16 index = RFIFOW(fd, 2) - 2;
  18290. bool removed = false;
  18291. if( !battle_config.feature_equipswitch ){
  18292. return;
  18293. }
  18294. // Check if the index is valid
  18295. if( index >= MAX_INVENTORY ){
  18296. return;
  18297. }
  18298. pc_equipswitch_remove( sd, index );
  18299. #endif
  18300. }
  18301. /// Acknowledgement for adding an equip to the equip switch window
  18302. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18303. /// 0a98 <index>.W <position.>.L <flag>.W
  18304. void clif_equipswitch_add( map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18305. #if PACKETVER >= 20170208
  18306. int fd = sd->fd;
  18307. WFIFOHEAD(fd, packet_len(0xa98));
  18308. WFIFOW(fd, 0) = 0xa98;
  18309. WFIFOW(fd, 2) = index + 2;
  18310. WFIFOL(fd, 4) = pos;
  18311. #if PACKETVER <= 20170502
  18312. WFIFOL(fd, 8) = flag;
  18313. #else
  18314. WFIFOW(fd, 8) = flag;
  18315. #endif
  18316. WFIFOSET(fd,packet_len(0xa98));
  18317. #endif
  18318. }
  18319. /// Request to add an equip to the equip switch window
  18320. /// 0a97 <index>.W <position>.L
  18321. void clif_parse_equipswitch_add( int fd, map_session_data* sd ){
  18322. #if PACKETVER >= 20170208
  18323. uint16 index = RFIFOW(fd, 2) - 2;
  18324. uint32 position = RFIFOL(fd, 4);
  18325. if( !battle_config.feature_equipswitch ){
  18326. return;
  18327. }
  18328. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18329. return;
  18330. }
  18331. if( sd->state.trading || sd->npc_shopid ){
  18332. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18333. return;
  18334. }
  18335. if( sd->inventory_data[index]->type == IT_AMMO ){
  18336. position = EQP_AMMO;
  18337. }
  18338. pc_equipitem( sd, index, position, true );
  18339. #endif
  18340. }
  18341. /// Acknowledgement packet for the full equip switch
  18342. /// 0a9d <failed>.W
  18343. void clif_equipswitch_reply( map_session_data* sd, bool failed ){
  18344. #if PACKETVER >= 20170208
  18345. int fd = sd->fd;
  18346. WFIFOHEAD(fd, packet_len(0xa9d));
  18347. WFIFOW(fd, 0) = 0xa9d;
  18348. WFIFOW(fd, 2) = failed;
  18349. WFIFOSET(fd, packet_len(0xa9d));
  18350. #endif
  18351. }
  18352. /// Request to do a full equip switch
  18353. /// 0a9c
  18354. void clif_parse_equipswitch_request( int fd, map_session_data* sd ){
  18355. #if PACKETVER >= 20170208
  18356. int i;
  18357. t_tick tick = gettick();
  18358. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18359. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18360. // Client will not let you send a request
  18361. return;
  18362. }
  18363. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18364. if( !battle_config.feature_equipswitch ){
  18365. return;
  18366. }
  18367. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18368. if( i == EQI_MAX ){
  18369. // client will show: "There is no item to replace." and should not even come here
  18370. clif_equipswitch_reply( sd, false );
  18371. return;
  18372. }
  18373. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18374. return;
  18375. }
  18376. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18377. #endif
  18378. }
  18379. /// Request to do a single equip switch
  18380. /// 0ace <index>.W
  18381. void clif_parse_equipswitch_request_single( int fd, map_session_data* sd ){
  18382. #if PACKETVER >= 20170502
  18383. uint16 index = RFIFOW(fd, 2) - 2;
  18384. if( !battle_config.feature_equipswitch ){
  18385. return;
  18386. }
  18387. // Check if the index is valid
  18388. if( index >= MAX_INVENTORY ){
  18389. return;
  18390. }
  18391. // Check if the item exists
  18392. if (sd->inventory_data[index] == nullptr)
  18393. return;
  18394. // Check if the item was already added to equip switch
  18395. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18396. if( sd->npc_id ){
  18397. #ifdef RENEWAL
  18398. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18399. clif_msg( sd, WORK_IN_PROGRESS );
  18400. return;
  18401. }
  18402. #endif
  18403. if( !sd->npc_item_flag ){
  18404. return;
  18405. }
  18406. }
  18407. pc_equipswitch( sd, index );
  18408. return;
  18409. }
  18410. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18411. #endif
  18412. }
  18413. void clif_parse_StartUseSkillToId( int fd, map_session_data* sd ){
  18414. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18415. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18416. // Only rolling cutter is supported for now
  18417. if( p->skillId != GC_ROLLINGCUTTER ){
  18418. return;
  18419. }
  18420. // Already running - cant happen on officials, since only one skill is supported
  18421. if( sd->skill_keep_using.skill_id != 0 ){
  18422. return;
  18423. }
  18424. sd->skill_keep_using.tid = INVALID_TIMER;
  18425. sd->skill_keep_using.skill_id = p->skillId;
  18426. sd->skill_keep_using.level = p->skillLv;
  18427. sd->skill_keep_using.target = p->targetId;
  18428. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18429. #endif
  18430. }
  18431. void clif_parse_StopUseSkillToId( int fd, map_session_data* sd ){
  18432. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18433. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18434. // Not running
  18435. if( sd->skill_keep_using.skill_id == 0 ){
  18436. return;
  18437. }
  18438. #if 0
  18439. // Hack
  18440. if( p->skillId != sd->skill_keep_using.skill_id ){
  18441. return;
  18442. }
  18443. #endif
  18444. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18445. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18446. sd->skill_keep_using.tid = INVALID_TIMER;
  18447. }
  18448. sd->skill_keep_using.skill_id = 0;
  18449. sd->skill_keep_using.level = 0;
  18450. sd->skill_keep_using.target = 0;
  18451. #endif
  18452. }
  18453. void clif_ping( map_session_data* sd ){
  18454. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18455. nullpo_retv( sd );
  18456. int fd = sd->fd;
  18457. if( !session_isActive( fd ) ){
  18458. return;
  18459. }
  18460. struct PACKET_ZC_PING_LIVE p = {};
  18461. p.packetType = HEADER_ZC_PING_LIVE;
  18462. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18463. #endif
  18464. }
  18465. int clif_ping_timer_sub( map_session_data *sd, va_list ap ){
  18466. nullpo_ret( sd );
  18467. int fd = sd->fd;
  18468. if( !session_isActive( fd ) ){
  18469. return 0;
  18470. }
  18471. t_tick tick = va_arg( ap, t_tick );
  18472. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18473. clif_ping( sd );
  18474. }
  18475. return 0;
  18476. }
  18477. TIMER_FUNC( clif_ping_timer ){
  18478. map_foreachpc( clif_ping_timer_sub, gettick() );
  18479. return 0;
  18480. }
  18481. /**
  18482. * Opens the refine UI on the designated client.
  18483. * 0aa0
  18484. */
  18485. void clif_refineui_open( map_session_data* sd ){
  18486. #if PACKETVER >= 20161012
  18487. nullpo_retv( sd );
  18488. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18489. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18490. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18491. sd->state.refineui_open = true;
  18492. #endif
  18493. }
  18494. /**
  18495. * Parses cancel/close of the refine UI on client side.
  18496. * 0aa4
  18497. */
  18498. void clif_parse_refineui_close( int fd, map_session_data* sd ){
  18499. #if PACKETVER >= 20161012
  18500. sd->state.refineui_open = false;
  18501. #endif
  18502. }
  18503. /**
  18504. * Adds the selected item into the refine UI and sends the possible materials
  18505. * to the client.
  18506. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18507. */
  18508. void clif_refineui_info( map_session_data* sd, uint16 index ){
  18509. #if PACKETVER >= 20161012
  18510. int fd = sd->fd;
  18511. // Get the item db reference
  18512. struct item_data* id = sd->inventory_data[index];
  18513. // No item data was found
  18514. if( id == NULL ){
  18515. return;
  18516. }
  18517. // Check the inventory
  18518. struct item* item = &sd->inventory.u.items_inventory[index];
  18519. // No item was found at the given index
  18520. if( item == NULL ){
  18521. return;
  18522. }
  18523. // Check if the item is identified
  18524. if( !item->identify ){
  18525. return;
  18526. }
  18527. // Check if the item is broken
  18528. if( item->attribute ){
  18529. return;
  18530. }
  18531. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18532. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18533. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18534. p->itemIndex = client_index( index );
  18535. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18536. // No possibilities were found
  18537. if( info == nullptr ){
  18538. p->blacksmithBlessing = 0;
  18539. }else{
  18540. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18541. uint16 count = 0;
  18542. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18543. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18544. if( cost != nullptr ){
  18545. p->req[count].itemId = client_nameid( cost->nameid );
  18546. p->req[count].chance = (uint8)( cost->chance / 100 );
  18547. p->req[count].zeny = cost->zeny;
  18548. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18549. count++;
  18550. }
  18551. }
  18552. }
  18553. clif_send( p, p->packetLength, &sd->bl, SELF );
  18554. #endif
  18555. }
  18556. /**
  18557. * Client request to add an item to the refine UI.
  18558. * 0aa1 <index>.W
  18559. */
  18560. void clif_parse_refineui_add( int fd, map_session_data* sd ){
  18561. #if PACKETVER >= 20161012
  18562. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18563. uint16 index = server_index( p->index );
  18564. // Check if the refine UI is open
  18565. if( !sd->state.refineui_open ){
  18566. return;
  18567. }
  18568. // Check if the index is valid
  18569. if( index >= MAX_INVENTORY ){
  18570. return;
  18571. }
  18572. // Send out the requirements for the refine process
  18573. clif_refineui_info( sd, index );
  18574. #endif
  18575. }
  18576. /**
  18577. * Client requests to try to refine an item.
  18578. * 0aa3 <index>.W <material>.W <catalyst>.B
  18579. */
  18580. void clif_parse_refineui_refine( int fd, map_session_data* sd ){
  18581. #if PACKETVER >= 20161012
  18582. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18583. uint16 index = server_index( p->index );
  18584. t_itemid material = p->itemId;
  18585. int16 j;
  18586. // Check if the refine UI is open
  18587. if( !sd->state.refineui_open ){
  18588. return;
  18589. }
  18590. // Check if the index is valid
  18591. if( index >= MAX_INVENTORY ){
  18592. return;
  18593. }
  18594. // Get the item db reference
  18595. struct item_data* id = sd->inventory_data[index];
  18596. // No item data was found
  18597. if( id == NULL ){
  18598. return;
  18599. }
  18600. // Check the inventory
  18601. struct item* item = &sd->inventory.u.items_inventory[index];
  18602. // No item was found at the given index
  18603. if( item == NULL ){
  18604. return;
  18605. }
  18606. // Check if the item is identified
  18607. if( !item->identify ){
  18608. return;
  18609. }
  18610. // Check if the item is broken
  18611. if( item->attribute ){
  18612. return;
  18613. }
  18614. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18615. // No refine possible
  18616. if( info == nullptr ){
  18617. return;
  18618. }
  18619. // No possibilities were found
  18620. if( info->costs.empty() ){
  18621. return;
  18622. }
  18623. // Check if the player has the selected material
  18624. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18625. return;
  18626. }
  18627. int16 blacksmith_index = -1;
  18628. uint16 blacksmith_amount = 0;
  18629. // Check if the player has enough blacksmith blessings
  18630. if( p->blacksmithBlessing != 0 ){
  18631. blacksmith_amount = info->blessing_amount;
  18632. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18633. if( blacksmith_amount == 0 ){
  18634. return;
  18635. }
  18636. // Check if the player has blacksmith blessings
  18637. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18638. return;
  18639. }
  18640. // Check if the player has enough blacksmith blessings
  18641. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18642. return;
  18643. }
  18644. }
  18645. std::shared_ptr<s_refine_cost> cost = nullptr;
  18646. for( const auto& pair : info->costs ){
  18647. if( pair.second->nameid == material ){
  18648. cost = pair.second;
  18649. break;
  18650. }
  18651. }
  18652. // The material was not in the list of possible materials
  18653. if( cost == nullptr ){
  18654. return;
  18655. }
  18656. // Try to pay for the refine
  18657. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME ) ){
  18658. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18659. return;
  18660. }
  18661. // Delete the required material
  18662. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18663. return;
  18664. }
  18665. // Delete the required blacksmith blessings
  18666. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18667. return;
  18668. }
  18669. // Try to refine the item
  18670. if( cost->chance >= ( rnd() % 10000 ) ){
  18671. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18672. // Success
  18673. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18674. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18675. clif_misceffect( &sd->bl, 3 );
  18676. clif_refine( fd, 0, index, item->refine );
  18677. if (info->broadcast_success) {
  18678. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18679. }
  18680. if( id->type == IT_WEAPON ){
  18681. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18682. }
  18683. clif_refineui_info( sd, index );
  18684. }else{
  18685. // Failure
  18686. if (info->broadcast_failure) {
  18687. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18688. }
  18689. // Blacksmith blessings were used to prevent breaking and downgrading
  18690. if( blacksmith_amount > 0 ){
  18691. clif_refine( fd, 3, index, item->refine );
  18692. clif_refineui_info( sd, index );
  18693. // Delete the item if it is breakable
  18694. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18695. clif_refine( fd, 1, index, item->refine );
  18696. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18697. // Downgrade the item if necessary
  18698. }else if( cost->downgrade_amount > 0 ){
  18699. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18700. clif_refine( fd, 2, index, item->refine );
  18701. clif_refineui_info(sd, index);
  18702. // Only show failure, but dont do anything
  18703. }else{
  18704. clif_refine( fd, 3, index, item->refine );
  18705. clif_refineui_info( sd, index );
  18706. }
  18707. clif_misceffect( &sd->bl, 2 );
  18708. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18709. }
  18710. #endif
  18711. }
  18712. void clif_unequipall_reply( map_session_data* sd, bool failed ){
  18713. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18714. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18715. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18716. p.result = failed;
  18717. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18718. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18719. }
  18720. void clif_parse_unequipall( int fd, map_session_data* sd ){
  18721. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18722. if( pc_cant_act( sd ) ){
  18723. clif_unequipall_reply( sd, true );
  18724. return;
  18725. }
  18726. struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL* p = (struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL*)RFIFOP( fd, 0 );
  18727. #if PACKETVER_MAIN_NUM >= 20230906
  18728. uint32 location = p->location;
  18729. int max = EQI_MAX;
  18730. #else
  18731. uint32 location = 0xFFFFFFFF;
  18732. int max = EQI_COSTUME_HEAD_TOP;
  18733. #endif
  18734. for( int i = 0; i < max; i++ ){
  18735. if( sd->equip_index[i] >= 0 && ( location & equip_bitmask[i] ) != 0 ){
  18736. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18737. }
  18738. }
  18739. clif_unequipall_reply( sd, false );
  18740. #endif
  18741. }
  18742. void clif_stylist_response( map_session_data* sd, bool failed ){
  18743. #if PACKETVER >= 20151104
  18744. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18745. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18746. p.flag = failed;
  18747. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18748. if( !failed ){
  18749. sd->state.stylist_open = false;
  18750. }
  18751. #endif
  18752. }
  18753. bool clif_parse_stylist_buy_sub( map_session_data* sd, _look look, int16 index ){
  18754. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18755. if( list == nullptr ){
  18756. return false;
  18757. }
  18758. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18759. if( entry == nullptr ){
  18760. return false;
  18761. }
  18762. std::shared_ptr<s_stylist_costs> costs;
  18763. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18764. costs = entry->doram;
  18765. }else{
  18766. costs = entry->human;
  18767. }
  18768. if( costs == nullptr ){
  18769. return false;
  18770. }
  18771. if( sd->status.zeny < costs->price ){
  18772. return false;
  18773. }
  18774. int16 inventoryIndex = -1;
  18775. if( costs->requiredItem != 0 ){
  18776. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18777. if( inventoryIndex < 0 ){
  18778. // No other option
  18779. if( costs->requiredItemBox == 0 ){
  18780. return false;
  18781. }
  18782. // Check if the box that contains the item is in the inventory
  18783. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18784. // The box containing the item also does not exist
  18785. if( inventoryIndex < 0 ){
  18786. return false;
  18787. }
  18788. }
  18789. }else if( costs->requiredItemBox != 0 ){
  18790. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18791. if( inventoryIndex < 0 ){
  18792. return false;
  18793. }
  18794. }
  18795. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18796. return false;
  18797. }
  18798. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER ) != 0 ){
  18799. return false;
  18800. }
  18801. switch( look ){
  18802. case LOOK_HAIR:
  18803. case LOOK_HAIR_COLOR:
  18804. case LOOK_CLOTHES_COLOR:
  18805. case LOOK_BODY2:
  18806. pc_changelook( sd, look, entry->value );
  18807. break;
  18808. case LOOK_HEAD_BOTTOM:
  18809. case LOOK_HEAD_MID:
  18810. case LOOK_HEAD_TOP: {
  18811. struct mail_message msg = {};
  18812. msg.dest_id = sd->status.char_id;
  18813. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18814. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18815. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18816. msg.item[0].nameid = entry->value;
  18817. msg.item[0].identify = 1;
  18818. msg.item[0].amount = 1;
  18819. msg.status = MAIL_NEW;
  18820. msg.type = MAIL_INBOX_NORMAL;
  18821. msg.timestamp = time( nullptr );
  18822. intif_Mail_send( 0, &msg );
  18823. } break;
  18824. }
  18825. return true;
  18826. }
  18827. void clif_parse_stylist_buy( int fd, map_session_data* sd ){
  18828. #if PACKETVER >= 20151104
  18829. #if PACKETVER >= 20180516
  18830. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18831. #else
  18832. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18833. #endif
  18834. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18835. clif_stylist_response( sd, true );
  18836. return;
  18837. }
  18838. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18839. clif_stylist_response( sd, true );
  18840. return;
  18841. }
  18842. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18843. clif_stylist_response( sd, true );
  18844. return;
  18845. }
  18846. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18847. clif_stylist_response( sd, true );
  18848. return;
  18849. }
  18850. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18851. clif_stylist_response( sd, true );
  18852. return;
  18853. }
  18854. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18855. clif_stylist_response( sd, true );
  18856. return;
  18857. }
  18858. #if PACKETVER >= 20180516
  18859. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18860. clif_stylist_response( sd, true );
  18861. return;
  18862. }
  18863. #endif
  18864. clif_stylist_response( sd, false );
  18865. #endif
  18866. }
  18867. void clif_parse_stylist_close( int fd, map_session_data* sd ){
  18868. #if PACKETVER >= 20151104
  18869. sd->state.stylist_open = false;
  18870. #endif
  18871. }
  18872. void clif_inventory_expansion_info( map_session_data* sd ){
  18873. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18874. nullpo_retv( sd );
  18875. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18876. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18877. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18878. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18879. #endif
  18880. }
  18881. enum class e_inventory_expansion_response : uint8{
  18882. ASK_CONFIRMATION = 0,
  18883. FAILED,
  18884. BUSY,
  18885. MISSING_ITEM,
  18886. MAXIMUM_REACHED
  18887. };
  18888. void clif_inventory_expansion_response( map_session_data* sd, e_inventory_expansion_response response ){
  18889. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18890. nullpo_retv( sd );
  18891. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18892. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18893. p.result = (uint8)response;
  18894. p.itemId = sd->state.inventory_expansion_confirmation;
  18895. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18896. #endif
  18897. }
  18898. void clif_parse_inventory_expansion_request( int fd, map_session_data* sd ){
  18899. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18900. // Check if player is dead or busy with other stuff
  18901. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18902. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18903. return;
  18904. }
  18905. // Check if the player already reached the maximum
  18906. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18907. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18908. return;
  18909. }
  18910. static std::map<t_itemid, uint16> items = {
  18911. // The order of entries in this list defines which will be used first
  18912. // This order and the usable items are hardcoded into the client
  18913. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18914. { ITEMID_INVENTORY_EX_EVT, 10 },
  18915. { ITEMID_INVENTORY_EX_DIS, 10 },
  18916. { ITEMID_INVENTORY_EX, 10 },
  18917. };
  18918. int16 index = -1;
  18919. bool found_over_limit = false;
  18920. for( const auto& entry : items ){
  18921. // Check if the player has the required item
  18922. index = pc_search_inventory( sd, entry.first );
  18923. // Found an item
  18924. if( index >= 0 ){
  18925. // Check if the player would exceed the maximum
  18926. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18927. found_over_limit = true;
  18928. }else{
  18929. found_over_limit = false;
  18930. sd->state.inventory_expansion_confirmation = entry.first;
  18931. sd->state.inventory_expansion_amount = entry.second;
  18932. break;
  18933. }
  18934. }
  18935. }
  18936. // Check if an item was found
  18937. if( sd->state.inventory_expansion_confirmation == 0 ){
  18938. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18939. return;
  18940. }
  18941. // Check if an item would have been found, but the player would exceed the maximum
  18942. if( found_over_limit ){
  18943. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18944. return;
  18945. }
  18946. // The player met all requirements => ask him for confirmation
  18947. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18948. #endif
  18949. }
  18950. enum class e_inventory_expansion_result : uint8{
  18951. SUCCESS = 0,
  18952. FAILED,
  18953. BUSY,
  18954. MISSING_ITEM,
  18955. MAXIMUM_REACHED
  18956. };
  18957. void clif_inventory_expansion_result( map_session_data* sd, e_inventory_expansion_result result ){
  18958. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18959. nullpo_retv( sd );
  18960. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18961. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18962. p.result = (uint8)result;
  18963. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18964. // Reset the state tracking
  18965. sd->state.inventory_expansion_confirmation = 0;
  18966. sd->state.inventory_expansion_amount = 0;
  18967. #endif
  18968. }
  18969. void clif_parse_inventory_expansion_confirm( int fd, map_session_data* sd ){
  18970. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18971. if( sd->state.inventory_expansion_confirmation == 0 ){
  18972. return;
  18973. }
  18974. // Check if player is dead
  18975. if( pc_isdead( sd ) ){
  18976. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18977. return;
  18978. }
  18979. // Check if the player already reached the maximum
  18980. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18981. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18982. return;
  18983. }
  18984. // Check if the player has the required item
  18985. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18986. // The player did not have the item anymore
  18987. if( index < 0 ){
  18988. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18989. return;
  18990. }
  18991. // Check if the player would exceed the maximum
  18992. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18993. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18994. return;
  18995. }
  18996. // Delete the required item
  18997. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18998. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18999. return;
  19000. }
  19001. // Increase the slots
  19002. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  19003. // Save player data (slots) and inventory data (removed item)
  19004. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  19005. // Inform the player of success
  19006. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  19007. clif_inventory_expansion_info( sd );
  19008. #endif
  19009. }
  19010. void clif_parse_inventory_expansion_reject( int fd, map_session_data* sd ){
  19011. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  19012. sd->state.inventory_expansion_confirmation = 0;
  19013. sd->state.inventory_expansion_amount = 0;
  19014. #endif
  19015. }
  19016. void clif_barter_open( map_session_data& sd, struct npc_data& nd ){
  19017. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19018. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  19019. return;
  19020. }
  19021. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19022. if( barter == nullptr ){
  19023. return;
  19024. }
  19025. sd.state.barter_open = true;
  19026. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19027. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  19028. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  19029. int16 count = 0;
  19030. for( const auto& itemPair : barter->items ){
  19031. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  19032. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19033. item->nameid = client_nameid( id->nameid );
  19034. item->type = itemtype( id->nameid );
  19035. if( itemPair.second->stockLimited ){
  19036. item->amount = itemPair.second->stock;
  19037. }else{
  19038. item->amount = -1;
  19039. }
  19040. item->weight = id->weight;
  19041. item->index = itemPair.second->index;
  19042. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19043. item->viewSprite = id->look;
  19044. item->location = pc_equippoint_sub( &sd, id.get() );
  19045. #endif
  19046. // Use a loop if someone did not start with index 0
  19047. for( const auto& requirementPair : itemPair.second->requirements ){
  19048. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19049. item->currencyNameid = client_nameid( requirement->nameid );
  19050. item->currencyAmount = requirement->amount;
  19051. // It is a normal barter, cancel after first entry
  19052. break;
  19053. }
  19054. p->packetLength += (int16)( sizeof( *item ) );
  19055. count++;
  19056. }
  19057. clif_send( p, p->packetLength, &sd.bl, SELF );
  19058. #endif
  19059. }
  19060. void clif_parse_barter_close( int fd, map_session_data* sd ){
  19061. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19062. if( sd->state.barter_open ){
  19063. sd->npc_shopid = 0;
  19064. sd->state.barter_open = false;
  19065. }
  19066. #endif
  19067. }
  19068. void clif_parse_barter_buy( int fd, map_session_data* sd ){
  19069. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19070. // No shop open
  19071. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  19072. return;
  19073. }
  19074. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19075. // Unknown shop
  19076. if( nd == nullptr ){
  19077. return;
  19078. }
  19079. // Not a barter
  19080. if( nd->subtype != NPCTYPE_BARTER ){
  19081. return;
  19082. }
  19083. // It is an extended barter
  19084. if( nd->u.barter.extended ){
  19085. return;
  19086. }
  19087. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19088. if( barter == nullptr ){
  19089. return;
  19090. }
  19091. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19092. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  19093. // Empty purchase list
  19094. if( entries == 0 ){
  19095. return;
  19096. }
  19097. std::vector<s_barter_purchase> purchases;
  19098. purchases.reserve( entries );
  19099. // Make sure each shop index and target item id is only used once
  19100. for( int i = 0; i < entries; i++ ){
  19101. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19102. // Invalid shop index
  19103. if( item == nullptr ){
  19104. return;
  19105. }
  19106. for( int j = i + 1; j < entries; j++ ){
  19107. // Same shop index
  19108. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19109. return;
  19110. }
  19111. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19112. // Invalid shop index
  19113. if( item2 == nullptr ){
  19114. return;
  19115. }
  19116. // Same target item id
  19117. if( item->nameid == item2->nameid ){
  19118. return;
  19119. }
  19120. }
  19121. s_barter_purchase purchase = {};
  19122. purchase.item = item;
  19123. purchase.amount = p->list[i].amount;
  19124. purchases.push_back( purchase );
  19125. }
  19126. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19127. #endif
  19128. }
  19129. void clif_barter_extended_open( map_session_data& sd, struct npc_data& nd ){
  19130. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19131. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19132. return;
  19133. }
  19134. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19135. if( barter == nullptr ){
  19136. return;
  19137. }
  19138. sd.state.barter_extended_open = true;
  19139. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19140. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19141. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  19142. p->items_count = 0;
  19143. for( const auto& itemPair : barter->items ){
  19144. // Needs dynamic calculation, because of variable currencies
  19145. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  19146. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19147. item->nameid = client_nameid( id->nameid );
  19148. item->type = itemtype( id->nameid );
  19149. if( itemPair.second->stockLimited ){
  19150. item->amount = itemPair.second->stock;
  19151. }else{
  19152. item->amount = -1;
  19153. }
  19154. item->weight = id->weight;
  19155. item->index = itemPair.second->index;
  19156. item->zeny = itemPair.second->price;
  19157. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19158. item->viewSprite = id->look;
  19159. item->location = pc_equippoint_sub( &sd, id.get() );
  19160. #endif
  19161. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19162. p->items_count++;
  19163. item->currency_count = 0;
  19164. for( const auto& requirementPair : itemPair.second->requirements ){
  19165. // Needs dynamic calculation, because of variable currencies
  19166. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19167. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19168. req->nameid = requirement->nameid;
  19169. if( requirement->refine >= 0 ){
  19170. req->refine_level = requirement->refine;
  19171. }else{
  19172. req->refine_level = 0;
  19173. }
  19174. req->amount = requirement->amount;
  19175. req->type = itemtype( requirement->nameid );
  19176. p->packetLength += (int16)( sizeof( *req ) );
  19177. item->currency_count++;
  19178. }
  19179. }
  19180. clif_send( p, p->packetLength, &sd.bl, SELF );
  19181. #endif
  19182. }
  19183. void clif_parse_barter_extended_close( int fd, map_session_data* sd ){
  19184. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19185. if( sd->state.barter_extended_open ){
  19186. sd->npc_shopid = 0;
  19187. sd->state.barter_extended_open = false;
  19188. }
  19189. #endif
  19190. }
  19191. void clif_parse_barter_extended_buy( int fd, map_session_data* sd ){
  19192. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19193. // No shop open
  19194. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19195. return;
  19196. }
  19197. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19198. // Unknown shop
  19199. if( nd == nullptr ){
  19200. return;
  19201. }
  19202. // Not a barter
  19203. if( nd->subtype != NPCTYPE_BARTER ){
  19204. return;
  19205. }
  19206. // Not an extended barter
  19207. if( !nd->u.barter.extended ){
  19208. return;
  19209. }
  19210. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19211. if( barter == nullptr ){
  19212. return;
  19213. }
  19214. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19215. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19216. // Empty purchase list
  19217. if( entries == 0 ){
  19218. return;
  19219. }
  19220. std::vector<s_barter_purchase> purchases;
  19221. purchases.reserve( entries );
  19222. // Make sure each shop index and target item id is only used once
  19223. for( int i = 0; i < entries; i++ ){
  19224. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19225. // Invalid shop index
  19226. if( item == nullptr ){
  19227. return;
  19228. }
  19229. for( int j = i + 1; j < entries; j++ ){
  19230. // Same shop index
  19231. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19232. return;
  19233. }
  19234. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19235. // Invalid shop index
  19236. if( item2 == nullptr ){
  19237. return;
  19238. }
  19239. // Same target item id
  19240. if( item->nameid == item2->nameid ){
  19241. return;
  19242. }
  19243. }
  19244. s_barter_purchase purchase = {};
  19245. purchase.item = item;
  19246. purchase.amount = p->list[i].amount;
  19247. purchases.push_back( purchase );
  19248. }
  19249. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19250. #endif
  19251. }
  19252. void clif_summon_init(struct mob_data& md) {
  19253. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19254. struct block_list* master_bl = battle_get_master(&md.bl);
  19255. if( master_bl == nullptr ){
  19256. return;
  19257. }
  19258. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19259. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19260. p.summonAID = md.bl.id;
  19261. p.CurrentHP = md.status.hp;
  19262. p.MaxHP = md.status.max_hp;
  19263. clif_send( &p, sizeof( p ), master_bl, SELF );
  19264. #endif
  19265. }
  19266. void clif_summon_hp_bar(struct mob_data& md) {
  19267. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19268. struct block_list* master_bl = battle_get_master(&md.bl);
  19269. if( master_bl == nullptr ){
  19270. return;
  19271. }
  19272. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19273. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19274. p.summonAID = md.bl.id;
  19275. p.VarId = SP_HP; // HP parameter
  19276. p.Value = md.status.hp;
  19277. clif_send( &p, sizeof( p ), master_bl, SELF );
  19278. #endif
  19279. }
  19280. void clif_laphine_synthesis_open( map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19281. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19282. nullpo_retv( sd );
  19283. sd->state.laphine_synthesis = synthesis->item_id;
  19284. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19285. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19286. p.itemId = client_nameid( synthesis->item_id );
  19287. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19288. #endif
  19289. }
  19290. void clif_parse_laphine_synthesis_close( int fd, map_session_data* sd ){
  19291. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19292. sd->state.laphine_synthesis = 0;
  19293. #endif
  19294. }
  19295. enum e_laphine_synthesis_result : int16{
  19296. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19297. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19298. LAPHINE_SYNTHESIS_ITEM = 7
  19299. };
  19300. void clif_laphine_synthesis_result( map_session_data* sd, enum e_laphine_synthesis_result result ){
  19301. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19302. nullpo_retv( sd );
  19303. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19304. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19305. p.result = result;
  19306. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19307. #endif
  19308. }
  19309. void clif_parse_laphine_synthesis( int fd, map_session_data* sd ){
  19310. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19311. if( sd->state.laphine_synthesis == 0 ){
  19312. return;
  19313. }
  19314. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19315. if( sd->state.laphine_synthesis != p->itemId ){
  19316. return;
  19317. }
  19318. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19319. if( synthesis == nullptr ){
  19320. return;
  19321. }
  19322. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19323. // Player sent more or less than actually required
  19324. if( count != synthesis->requiredRequirements ){
  19325. return;
  19326. }
  19327. // Check for duplicates
  19328. for( size_t i = 0; i < count; i++ ){
  19329. for( size_t j = i + 1; j < count; j++ ){
  19330. if( p->items[i].index == p->items[j].index ){
  19331. return;
  19332. }
  19333. }
  19334. }
  19335. for( size_t i = 0; i < count; i++ ){
  19336. int16 index = server_index( p->items[i].index );
  19337. if( index >= MAX_INVENTORY ){
  19338. return;
  19339. }
  19340. if( sd->inventory_data[index] == nullptr ){
  19341. return;
  19342. }
  19343. struct item* item = &sd->inventory.u.items_inventory[index];
  19344. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19345. if( requirement == nullptr ){
  19346. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19347. return;
  19348. }
  19349. if( p->items[i].count != requirement->amount ){
  19350. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19351. return;
  19352. }
  19353. if( item->amount < requirement->amount ){
  19354. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19355. return;
  19356. }
  19357. if( item->refine < synthesis->minimumRefine ){
  19358. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19359. return;
  19360. }
  19361. if( item->refine > synthesis->maximumRefine ){
  19362. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19363. return;
  19364. }
  19365. if( item->equip != 0 ){
  19366. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19367. return;
  19368. }
  19369. if( item->equipSwitch != 0 ){
  19370. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19371. return;
  19372. }
  19373. }
  19374. // If triggered from item
  19375. if( sd->itemid == sd->state.laphine_synthesis ){
  19376. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19377. if( index < 0 ){
  19378. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19379. return;
  19380. }
  19381. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19382. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19383. return;
  19384. }
  19385. }
  19386. }
  19387. for( size_t i = 0; i < count; i++ ){
  19388. int16 index = server_index( p->items[i].index );
  19389. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19390. return;
  19391. }
  19392. }
  19393. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19394. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19395. #endif
  19396. }
  19397. void clif_laphine_upgrade_open( map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19398. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19399. nullpo_retv( sd );
  19400. sd->state.laphine_upgrade = upgrade->item_id;
  19401. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19402. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19403. p.itemId = client_nameid( upgrade->item_id );
  19404. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19405. #endif
  19406. }
  19407. void clif_parse_laphine_upgrade_close( int fd, map_session_data* sd ){
  19408. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19409. sd->state.laphine_upgrade = 0;
  19410. #endif
  19411. }
  19412. void clif_laphine_upgrade_result( map_session_data *sd, bool failed ){
  19413. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19414. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19415. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19416. p.result = failed;
  19417. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19418. #endif
  19419. }
  19420. static void clif_item_preview( map_session_data *sd, int16 index ){
  19421. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19422. nullpo_retv( sd );
  19423. struct item* item = &sd->inventory.u.items_inventory[index];
  19424. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19425. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19426. p.index = client_index( index );
  19427. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19428. p.isDamaged = item->attribute != 0;
  19429. #endif
  19430. p.refiningLevel = item->refine;
  19431. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19432. p.grade = item->enchantgrade;
  19433. #endif
  19434. clif_addcards( &p.slot, item );
  19435. clif_add_random_options( p.option_data, *item );
  19436. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19437. #endif
  19438. }
  19439. void clif_parse_laphine_upgrade( int fd, map_session_data* sd ){
  19440. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19441. if( sd->state.laphine_upgrade == 0 ){
  19442. return;
  19443. }
  19444. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19445. if( sd->state.laphine_upgrade != p->itemId ){
  19446. return;
  19447. }
  19448. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19449. if( upgrade == nullptr ){
  19450. return;
  19451. }
  19452. uint16 index = server_index( p->index );
  19453. if( index >= MAX_INVENTORY ){
  19454. return;
  19455. }
  19456. if( sd->inventory_data[index] == nullptr ){
  19457. return;
  19458. }
  19459. struct item* item = &sd->inventory.u.items_inventory[index];
  19460. // Not a valid target item
  19461. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19462. clif_laphine_upgrade_result( sd, true );
  19463. return;
  19464. }
  19465. // If target item is not identified
  19466. if( item->identify == 0 ){
  19467. clif_laphine_upgrade_result( sd, true );
  19468. return;
  19469. }
  19470. // If target item is equipped
  19471. if( item->equip != 0 ){
  19472. clif_laphine_upgrade_result( sd, true );
  19473. return;
  19474. }
  19475. // If target item is in equipswitch
  19476. if( item->equipSwitch != 0 ){
  19477. clif_laphine_upgrade_result( sd, true );
  19478. return;
  19479. }
  19480. // Check minimum refine requirement
  19481. if( item->refine < upgrade->minimumRefine ){
  19482. clif_laphine_upgrade_result( sd, true );
  19483. return;
  19484. }
  19485. // Check maximum refine requirement
  19486. if( item->refine > upgrade->maximumRefine ){
  19487. clif_laphine_upgrade_result( sd, true );
  19488. return;
  19489. }
  19490. // If no cards are allowed
  19491. if( !upgrade->cardsAllowed ){
  19492. for( int i = 0; i < MAX_SLOTS; i++ ){
  19493. if( item->card[i] != 0 ){
  19494. clif_laphine_upgrade_result( sd, true );
  19495. return;
  19496. }
  19497. }
  19498. }
  19499. // If random options are required
  19500. if( upgrade->requiredRandomOptions > 0 ){
  19501. int i;
  19502. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19503. if( item->option[i].id != 0 ){
  19504. break;
  19505. }
  19506. }
  19507. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19508. clif_laphine_upgrade_result( sd, true );
  19509. return;
  19510. }
  19511. }
  19512. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19513. if( index2 < 0 ){
  19514. clif_laphine_upgrade_result( sd, true );
  19515. return;
  19516. }
  19517. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19518. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19519. return;
  19520. }
  19521. }
  19522. // Log removal of item
  19523. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19524. // Visually remove it from the client
  19525. clif_delitem( sd, index, 1, 0 );
  19526. // Apply the random options
  19527. if( upgrade->randomOptionGroup != nullptr ){
  19528. upgrade->randomOptionGroup->apply( *item );
  19529. }
  19530. // Change the refine rate if needed
  19531. if (!upgrade->resultRefine.empty()) {
  19532. int total_rate = 0;
  19533. // Get the total rate (sum of the rate)
  19534. for (const auto& it : upgrade->resultRefine) {
  19535. if (it.second == 0) // Level removed on import
  19536. continue;
  19537. total_rate += it.second;
  19538. }
  19539. if (total_rate > 0) {
  19540. int chance = rnd_value(1, total_rate);
  19541. int sum_rate = 0;
  19542. for (const auto& it : upgrade->resultRefine) {
  19543. if (it.second == 0)
  19544. continue;
  19545. sum_rate += it.second;
  19546. if (chance <= sum_rate) {
  19547. item->refine = cap_value(it.first, 0, MAX_REFINE);
  19548. break;
  19549. }
  19550. }
  19551. }
  19552. }
  19553. // Log retrieving the item again -> with the new options
  19554. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19555. // Make it visible for the client again
  19556. clif_additem( sd, index, 1, 0 );
  19557. // Open a preview of the item
  19558. clif_item_preview( sd, index );
  19559. // Tell the client we are done
  19560. clif_laphine_upgrade_result( sd, false );
  19561. #endif
  19562. }
  19563. void clif_enchantgrade_add( map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19564. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19565. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19566. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19567. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19568. if( index < UINT16_MAX ){
  19569. p->index = client_index( index );
  19570. p->success_chance = gradeLevel->chances[sd.inventory.u.items_inventory[index].refine] / 100;
  19571. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19572. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19573. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19574. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19575. // Not displayed by client
  19576. p->protect_itemid = 0;
  19577. p->protect_amount = 0;
  19578. int i = 0;
  19579. for( const auto& pair : gradeLevel->options ){
  19580. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19581. p->material_info[i].nameid = client_nameid( option->item );
  19582. p->material_info[i].amount = option->amount;
  19583. p->material_info[i].price = option->zeny;
  19584. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19585. p->material_info[i].breakable = option->breaking_rate > 0;
  19586. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19587. i++;
  19588. }
  19589. }else{
  19590. p->index = -1;
  19591. p->success_chance = 0;
  19592. p->blessing_info.id = 0;
  19593. p->blessing_info.amount = 0;
  19594. p->blessing_info.max_blessing = 0;
  19595. p->blessing_info.bonus = 0;
  19596. p->protect_itemid = 0;
  19597. p->protect_amount = 0;
  19598. }
  19599. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19600. #endif
  19601. }
  19602. void clif_parse_enchantgrade_add( int fd, map_session_data* sd ){
  19603. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19604. nullpo_retv( sd );
  19605. if( !sd->state.enchantgrade_open ){
  19606. return;
  19607. }
  19608. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19609. uint16 index = server_index( p->index );
  19610. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19611. return;
  19612. }
  19613. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19614. // Unsupported item type - no answer, because client should have actually prevented this request
  19615. if( enchantgrade == nullptr ){
  19616. return;
  19617. }
  19618. // Item can't be enhanced
  19619. if( !sd->inventory_data[index]->flag.gradable ){
  19620. return;
  19621. }
  19622. uint16 level = 0;
  19623. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19624. level = sd->inventory_data[index]->weapon_level;
  19625. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19626. level = sd->inventory_data[index]->armor_level;
  19627. }
  19628. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19629. // Cannot upgrade this weapon or armor level
  19630. if( enchantgradelevels == enchantgrade->levels.end() ){
  19631. clif_enchantgrade_add( *sd );
  19632. return;
  19633. }
  19634. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19635. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19636. if( enchantgradelevel == nullptr ){
  19637. return;
  19638. }
  19639. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19640. #endif
  19641. }
  19642. /// <summary>
  19643. /// Sends the result for trying to enchant an item
  19644. /// </summary>
  19645. /// <param name="sd">The player session</param>
  19646. /// <param name="index">The target item</param>
  19647. /// <param name="result">
  19648. /// 0= The grade has been successfully upgraded.
  19649. /// 1= Refinement failed.
  19650. /// 2= The refine level has decreased.
  19651. /// 3= Equipment destroyed.
  19652. /// 4= The equipment is protected.
  19653. /// </param>
  19654. void clif_enchantgrade_result( map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19655. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19656. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19657. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19658. p.index = client_index( index );
  19659. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19660. p.result = result;
  19661. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19662. #endif
  19663. }
  19664. void clif_enchantgrade_announce( map_session_data& sd, struct item& item, bool success ){
  19665. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19666. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19667. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19668. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19669. p.itemId = client_nameid( item.nameid );
  19670. p.grade = item.enchantgrade;
  19671. p.status = success;
  19672. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19673. #endif
  19674. }
  19675. void clif_parse_enchantgrade_start( int fd, map_session_data* sd ){
  19676. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19677. nullpo_retv( sd );
  19678. if( !sd->state.enchantgrade_open ){
  19679. return;
  19680. }
  19681. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19682. uint16 index = server_index( p->index );
  19683. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19684. return;
  19685. }
  19686. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19687. // Unsupported item type - no answer
  19688. if( enchantgrade == nullptr ){
  19689. return;
  19690. }
  19691. uint16 level = 0;
  19692. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19693. level = sd->inventory_data[index]->weapon_level;
  19694. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19695. level = sd->inventory_data[index]->armor_level;
  19696. }
  19697. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19698. // Cannot upgrade this weapon or armor level - no answer
  19699. if( enchantgradelevels == enchantgrade->levels.end() ){
  19700. return;
  19701. }
  19702. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19703. // Cannot increase enchantgrade any further - no answer
  19704. if( enchantgradelevel == nullptr ){
  19705. return;
  19706. }
  19707. uint16 totalChance = enchantgradelevel->chances[sd->inventory.u.items_inventory[index].refine];
  19708. // No chance to increase the enchantgrade
  19709. if( totalChance == 0 ){
  19710. return;
  19711. }
  19712. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19713. // Unknown option id - no answer
  19714. if( option == nullptr ){
  19715. return;
  19716. }
  19717. // Not enough zeny
  19718. if( sd->status.zeny < option->zeny ){
  19719. return;
  19720. }
  19721. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19722. std::unordered_map<uint16, uint16> requiredItems;
  19723. if( p->blessing_flag ){
  19724. // If the catalysator item is the same as the option item build the sum of amounts
  19725. if( enchantgradelevel->catalyst.item == option->item ){
  19726. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19727. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19728. if( index < 0 ){
  19729. return;
  19730. }
  19731. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19732. return;
  19733. }
  19734. requiredItems[index] = amount;
  19735. }else{
  19736. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19737. // Check catalysator item
  19738. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19739. if( index < 0 ){
  19740. return;
  19741. }
  19742. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19743. return;
  19744. }
  19745. requiredItems[index] = amount;
  19746. // Check option item
  19747. index = pc_search_inventory( sd, option->item );
  19748. if( index < 0 ){
  19749. return;
  19750. }
  19751. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19752. return;
  19753. }
  19754. requiredItems[index] = option->amount;
  19755. }
  19756. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19757. }else{
  19758. // Check option item
  19759. int16 index = pc_search_inventory( sd, option->item );
  19760. if( index < 0 ){
  19761. return;
  19762. }
  19763. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19764. return;
  19765. }
  19766. requiredItems[index] = option->amount;
  19767. }
  19768. // All items should be there, start deleting
  19769. for( const auto& pair : requiredItems ){
  19770. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19771. return;
  19772. }
  19773. }
  19774. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE ) > 0 ){
  19775. return;
  19776. }
  19777. if( rnd()%10000 < totalChance ){
  19778. // Log removal of item
  19779. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19780. // Increase enchantgrade
  19781. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19782. // On successful enchantgrade increase the refine is reset
  19783. sd->inventory.u.items_inventory[index].refine = 0;
  19784. // Log retrieving the item again -> with the new refine and enchantgrade
  19785. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19786. // Show success
  19787. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19788. // Check if it has to be announced
  19789. if( enchantgradelevel->announceSuccess ){
  19790. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19791. }
  19792. }else{
  19793. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19794. if( enchantgradelevel->announceFail ){
  19795. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19796. }
  19797. // Delete the item if it is breakable
  19798. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19799. // Delete the item
  19800. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19801. // Show failure
  19802. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19803. // Downgrade the item if necessary
  19804. }else if( option->downgrade_amount > 0 ){
  19805. // Log removal of item
  19806. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19807. // Decrease refine level
  19808. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19809. // Log retrieving the item again -> with the new refine
  19810. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19811. // Show downgrade
  19812. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19813. // Only show failure, but dont do anything
  19814. }else{
  19815. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19816. }
  19817. }
  19818. #endif
  19819. }
  19820. void clif_parse_enchantgrade_close( int fd, map_session_data* sd ){
  19821. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19822. nullpo_retv( sd );
  19823. sd->state.enchantgrade_open = false;
  19824. #endif
  19825. }
  19826. void clif_reputation_type( map_session_data& sd, int64 type, int64 points ){
  19827. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19828. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19829. p->packetType = HEADER_ZC_REPUTE_INFO;
  19830. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19831. p->success = true;
  19832. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19833. entry->type = type;
  19834. entry->points = points;
  19835. clif_send( p, p->packetLength, &sd.bl, SELF );
  19836. #endif
  19837. }
  19838. void clif_reputation_list( map_session_data& sd ){
  19839. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19840. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19841. p->packetType = HEADER_ZC_REPUTE_INFO;
  19842. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19843. p->success = true;
  19844. size_t index = 0;
  19845. for( const auto& entry : reputation_db ){
  19846. std::shared_ptr<s_reputation> reputation = entry.second;
  19847. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19848. list_entry->type = reputation->id;
  19849. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19850. p->packetLength += sizeof( *list_entry );
  19851. index++;
  19852. }
  19853. clif_send( p, p->packetLength, &sd.bl, SELF );
  19854. #endif
  19855. }
  19856. void clif_item_reform_open( map_session_data& sd, t_itemid item ){
  19857. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19858. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19859. p.PacketType = HEADER_ZC_OPEN_REFORM_UI;
  19860. p.ITID = item;
  19861. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19862. sd.state.item_reform = item;
  19863. #endif
  19864. }
  19865. void clif_parse_item_reform_close( int fd, map_session_data* sd ){
  19866. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19867. sd->state.item_reform = 0;
  19868. #endif
  19869. }
  19870. void clif_item_reform_result( map_session_data& sd, uint16 index, uint8 result ){
  19871. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19872. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19873. p.PacketType = HEADER_ZC_ITEM_REFORM_ACK;
  19874. p.index = client_index( index );
  19875. p.result = result;
  19876. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19877. if( result == 0 ){
  19878. // Client closes the window on success
  19879. sd.state.item_reform = 0;
  19880. }
  19881. #endif
  19882. }
  19883. void clif_parse_item_reform_start( int fd, map_session_data* sd ){
  19884. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19885. // Not opened
  19886. if( sd->state.item_reform == 0 ){
  19887. return;
  19888. }
  19889. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19890. // Item mismatch
  19891. if( p->ITID != sd->state.item_reform ){
  19892. return;
  19893. }
  19894. uint16 index = server_index( p->index );
  19895. if( index >= MAX_INVENTORY ){
  19896. return;
  19897. }
  19898. if( sd->inventory_data[index] == nullptr ){
  19899. return;
  19900. }
  19901. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19902. if( reform == nullptr ){
  19903. return;
  19904. }
  19905. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19906. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19907. if( base == nullptr ){
  19908. return;
  19909. }
  19910. // If target item is not identified
  19911. if( selected_item.identify == 0 ){
  19912. return;
  19913. }
  19914. // If target item is equipped
  19915. if( selected_item.equip != 0 ){
  19916. return;
  19917. }
  19918. // Check minimum refine requirement
  19919. if( selected_item.refine < base->minimumRefine ){
  19920. return;
  19921. }
  19922. // Check maximum refine requirement
  19923. if( selected_item.refine > base->maximumRefine ){
  19924. return;
  19925. }
  19926. // If no cards are allowed
  19927. if( !base->cardsAllowed ){
  19928. for( int i = 0; i < MAX_SLOTS; i++ ){
  19929. if( selected_item.card[i] != 0 ){
  19930. return;
  19931. }
  19932. }
  19933. }
  19934. // If random options are required
  19935. if( base->requiredRandomOptions > 0 ){
  19936. int i;
  19937. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19938. if( selected_item.option[i].id != 0 ){
  19939. break;
  19940. }
  19941. }
  19942. if( ( i + 1 ) < base->requiredRandomOptions ){
  19943. return;
  19944. }
  19945. }
  19946. std::unordered_map<uint16, uint16> materials;
  19947. // Check if all materials exist
  19948. for( const auto& material : base->materials ){
  19949. int16 material_index = pc_search_inventory( sd, material.first );
  19950. if( material_index < 0 ){
  19951. return;
  19952. }
  19953. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19954. return;
  19955. }
  19956. materials[material_index] = material.second;
  19957. }
  19958. // Remove the material
  19959. for( const auto& material : materials ){
  19960. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19961. return;
  19962. }
  19963. }
  19964. // If triggered from item
  19965. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19966. return;
  19967. }
  19968. // Log removal of item
  19969. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19970. // Visually remove it from the client
  19971. clif_delitem( sd, index, 1, 0 );
  19972. // Apply the random options
  19973. if( base->randomOptionGroup != nullptr ){
  19974. base->randomOptionGroup->apply( selected_item );
  19975. }
  19976. // Change the refine rate if needed
  19977. if( base->refineChange != 0 ){
  19978. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19979. }
  19980. // Remove all cards and socket enchants
  19981. if( base->clearSlots ){
  19982. for( int i = 0; i < MAX_SLOTS; i++ ){
  19983. selected_item.card[i] = 0;
  19984. }
  19985. }
  19986. // Remove the current enchantgrade
  19987. if( base->removeEnchantgrade ){
  19988. selected_item.enchantgrade = 0;
  19989. }
  19990. // Finally change the item id
  19991. selected_item.nameid = base->resultItemId;
  19992. // Link inventory data cache to the new item
  19993. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19994. // Log retrieving the item again -> with the new options
  19995. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19996. // Make it visible for the client again
  19997. clif_additem( sd, index, 1, 0 );
  19998. clif_item_reform_result( *sd, index, 0 );
  19999. #endif
  20000. }
  20001. void clif_enchantwindow_open( map_session_data& sd, uint64 clientLuaIndex ){
  20002. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20003. // Hardcoded clientside check
  20004. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  20005. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  20006. sd.state.item_enchant_index = 0;
  20007. return;
  20008. }
  20009. struct PACKET_ZC_UI_OPEN_V3 p = {};
  20010. p.packetType = HEADER_ZC_UI_OPEN_V3;
  20011. p.type = OUT_UI_ENCHANT;
  20012. p.data = clientLuaIndex;
  20013. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20014. sd.state.item_enchant_index = clientLuaIndex;
  20015. #endif
  20016. }
  20017. void clif_enchantwindow_result( map_session_data& sd, bool success, t_itemid enchant = 0 ){
  20018. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20019. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  20020. p.PacketType = HEADER_ZC_RESPONSE_ENCHANT;
  20021. if( success ){
  20022. p.msgId = C_ENCHANT_SUCCESS;
  20023. }else{
  20024. p.msgId = C_ENCHANT_FAILURE;
  20025. }
  20026. p.ITID = enchant;
  20027. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20028. sd.state.item_enchant_index = 0;
  20029. #endif
  20030. }
  20031. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  20032. if( selected_item.equip != 0 ){
  20033. return false;
  20034. }
  20035. if( selected_item.equipSwitch != 0 ){
  20036. return false;
  20037. }
  20038. if( selected_item.attribute != 0 ){
  20039. return false;
  20040. }
  20041. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20042. return false;
  20043. }
  20044. if( selected_item.refine < enchant->minimumRefine ){
  20045. return false;
  20046. }
  20047. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20048. return false;
  20049. }
  20050. if( !enchant->allowRandomOptions ){
  20051. for( const s_item_randomoption& option : selected_item.option ){
  20052. if( option.id != 0 ){
  20053. return false;
  20054. }
  20055. }
  20056. }
  20057. return true;
  20058. }
  20059. void clif_parse_enchantwindow_general( int fd, map_session_data* sd ){
  20060. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20061. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  20062. if( sd->state.item_enchant_index != p->enchant_group ){
  20063. return;
  20064. }
  20065. uint16 index = server_index( p->index );
  20066. if( index >= MAX_INVENTORY ){
  20067. return;
  20068. }
  20069. if( sd->inventory_data[index] == nullptr ){
  20070. return;
  20071. }
  20072. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20073. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20074. if( enchant == nullptr ){
  20075. return;
  20076. }
  20077. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20078. return;
  20079. }
  20080. uint16 slot = MAX_SLOTS;
  20081. for( uint16 nextSlot : enchant->order ){
  20082. if( selected_item.card[nextSlot] == 0 ){
  20083. slot = nextSlot;
  20084. break;
  20085. }
  20086. }
  20087. if( slot == MAX_SLOTS ){
  20088. return;
  20089. }
  20090. if( slot < sd->inventory_data[index]->slots ){
  20091. return;
  20092. }
  20093. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20094. if( enchant_slot == nullptr ){
  20095. return;
  20096. }
  20097. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  20098. if( enchants_for_enchantgrade == nullptr ){
  20099. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  20100. clif_enchantwindow_result( *sd, false );
  20101. return;
  20102. }
  20103. if( sd->status.zeny < enchant_slot->normal.zeny ){
  20104. return;
  20105. }
  20106. std::unordered_map<uint16, uint16> materials;
  20107. for( const auto& entry : enchant_slot->normal.materials ){
  20108. int16 idx = pc_search_inventory( sd, entry.first );
  20109. if( idx < 0 ){
  20110. return;
  20111. }
  20112. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20113. return;
  20114. }
  20115. materials[idx] = entry.second;
  20116. }
  20117. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20118. return;
  20119. }
  20120. for( const auto& entry : materials ){
  20121. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20122. return;
  20123. }
  20124. }
  20125. uint32 chance = enchant_slot->normal.chance;
  20126. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  20127. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  20128. }
  20129. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20130. clif_enchantwindow_result( *sd, false );
  20131. return;
  20132. }
  20133. // Log removal of item
  20134. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20135. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  20136. bool enchanted = false;
  20137. for( int i = 0; i < maximum; i++ ){
  20138. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20139. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  20140. selected_item.card[slot] = normal_enchant->item_id;
  20141. enchanted = true;
  20142. break;
  20143. }
  20144. }
  20145. if( !enchanted ){
  20146. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20147. selected_item.card[slot] = normal_enchant->item_id;
  20148. }
  20149. // Log retrieving the item again -> with the new enchant
  20150. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20151. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20152. #endif
  20153. }
  20154. void clif_parse_enchantwindow_perfect( int fd, map_session_data* sd ){
  20155. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20156. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  20157. if( sd->state.item_enchant_index != p->enchant_group ){
  20158. return;
  20159. }
  20160. uint16 index = server_index( p->index );
  20161. if( index >= MAX_INVENTORY ){
  20162. return;
  20163. }
  20164. if( sd->inventory_data[index] == nullptr ){
  20165. return;
  20166. }
  20167. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20168. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20169. if( enchant == nullptr ){
  20170. return;
  20171. }
  20172. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20173. return;
  20174. }
  20175. uint16 slot = MAX_SLOTS;
  20176. for( uint16 nextSlot : enchant->order ){
  20177. if( selected_item.card[nextSlot] == 0 ){
  20178. slot = nextSlot;
  20179. break;
  20180. }
  20181. }
  20182. if( slot == MAX_SLOTS ){
  20183. return;
  20184. }
  20185. if( slot < sd->inventory_data[index]->slots ){
  20186. return;
  20187. }
  20188. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20189. if( enchant_slot == nullptr ){
  20190. return;
  20191. }
  20192. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->ITID );
  20193. if( perfect_enchant == nullptr ){
  20194. return;
  20195. }
  20196. if( sd->status.zeny < perfect_enchant->zeny ){
  20197. return;
  20198. }
  20199. std::unordered_map<uint16, uint16> materials;
  20200. for( const auto& entry : perfect_enchant->materials ){
  20201. int16 idx = pc_search_inventory( sd, entry.first );
  20202. if( idx < 0 ){
  20203. return;
  20204. }
  20205. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20206. return;
  20207. }
  20208. materials[idx] = entry.second;
  20209. }
  20210. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20211. return;
  20212. }
  20213. for( const auto& entry : materials ){
  20214. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20215. return;
  20216. }
  20217. }
  20218. // Log removal of item
  20219. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20220. selected_item.card[slot] = perfect_enchant->item_id;
  20221. // Log retrieving the item again -> with the new enchant
  20222. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20223. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20224. #endif
  20225. }
  20226. void clif_parse_enchantwindow_upgrade( int fd, map_session_data* sd ){
  20227. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20228. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20229. if( sd->state.item_enchant_index != p->enchant_group ){
  20230. return;
  20231. }
  20232. uint16 index = server_index( p->index );
  20233. if( index >= MAX_INVENTORY ){
  20234. return;
  20235. }
  20236. if( sd->inventory_data[index] == nullptr ){
  20237. return;
  20238. }
  20239. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20240. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20241. if( enchant == nullptr ){
  20242. return;
  20243. }
  20244. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20245. return;
  20246. }
  20247. uint16 slot = p->slot;
  20248. if( slot >= MAX_SLOTS ){
  20249. return;
  20250. }
  20251. if( slot < sd->inventory_data[index]->slots ){
  20252. return;
  20253. }
  20254. if( selected_item.card[slot] == 0 ){
  20255. return;
  20256. }
  20257. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20258. if( enchant_slot == nullptr ){
  20259. return;
  20260. }
  20261. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20262. if( upgrade == nullptr ){
  20263. return;
  20264. }
  20265. if( sd->status.zeny < upgrade->zeny ){
  20266. return;
  20267. }
  20268. std::unordered_map<uint16, uint16> materials;
  20269. for( const auto& entry : upgrade->materials ){
  20270. int16 idx = pc_search_inventory( sd, entry.first );
  20271. if( idx < 0 ){
  20272. return;
  20273. }
  20274. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20275. return;
  20276. }
  20277. materials[idx] = entry.second;
  20278. }
  20279. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20280. return;
  20281. }
  20282. for( const auto& entry : materials ){
  20283. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20284. return;
  20285. }
  20286. }
  20287. // Log removal of item
  20288. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20289. selected_item.card[slot] = upgrade->upgrade_item_id;
  20290. // Log retrieving the item again -> with the new enchant
  20291. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20292. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20293. #endif
  20294. }
  20295. void clif_parse_enchantwindow_reset( int fd, map_session_data* sd ){
  20296. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20297. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20298. if( sd->state.item_enchant_index != p->enchant_group ){
  20299. return;
  20300. }
  20301. uint16 index = server_index( p->index );
  20302. if( index >= MAX_INVENTORY ){
  20303. return;
  20304. }
  20305. if( sd->inventory_data[index] == nullptr ){
  20306. return;
  20307. }
  20308. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20309. if( selected_item.equip != 0 ){
  20310. return;
  20311. }
  20312. if( selected_item.equipSwitch != 0 ){
  20313. return;
  20314. }
  20315. if( selected_item.attribute != 0 ){
  20316. return;
  20317. }
  20318. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20319. if( enchant == nullptr ){
  20320. return;
  20321. }
  20322. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20323. return;
  20324. }
  20325. if( selected_item.refine < enchant->minimumRefine ){
  20326. return;
  20327. }
  20328. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20329. return;
  20330. }
  20331. bool is_enchanted = false;
  20332. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20333. if( selected_item.card[i] != 0 ){
  20334. is_enchanted = true;
  20335. break;
  20336. }
  20337. }
  20338. if( !is_enchanted ){
  20339. return;
  20340. }
  20341. if( sd->status.zeny < enchant->reset.zeny ){
  20342. return;
  20343. }
  20344. std::unordered_map<uint16, uint16> materials;
  20345. for( const auto& entry : enchant->reset.materials ){
  20346. int16 idx = pc_search_inventory( sd, entry.first );
  20347. if( idx < 0 ){
  20348. return;
  20349. }
  20350. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20351. return;
  20352. }
  20353. materials[idx] = entry.second;
  20354. }
  20355. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20356. return;
  20357. }
  20358. for( const auto& entry : materials ){
  20359. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20360. return;
  20361. }
  20362. }
  20363. uint32 chance = enchant->reset.chance;
  20364. if( chance == 0 ){
  20365. return;
  20366. }
  20367. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20368. clif_enchantwindow_result( *sd, false );
  20369. return;
  20370. }
  20371. // Log removal of item
  20372. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20373. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20374. selected_item.card[i] = 0;
  20375. }
  20376. // Log retrieving the item again -> with the new enchant
  20377. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20378. clif_enchantwindow_result( *sd, true );
  20379. #endif
  20380. }
  20381. void clif_parse_enchantwindow_close( int fd, map_session_data* sd ){
  20382. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20383. sd->state.item_enchant_index = 0;
  20384. #endif
  20385. }
  20386. void clif_parse_itempackage_select( int fd, map_session_data* sd ){
  20387. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20388. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20389. if( p->AID != sd->status.account_id ){
  20390. return;
  20391. }
  20392. uint16 index = server_index( p->index );
  20393. if( index >= MAX_INVENTORY ){
  20394. return;
  20395. }
  20396. if( sd->inventory_data[index] == nullptr ){
  20397. return;
  20398. }
  20399. if( sd->inventory_data[index]->nameid != p->itemID ){
  20400. return;
  20401. }
  20402. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20403. return;
  20404. }
  20405. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20406. if( package == nullptr ){
  20407. return;
  20408. }
  20409. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20410. if( group == nullptr ){
  20411. return;
  20412. }
  20413. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20414. return;
  20415. }
  20416. for( const auto& entry : group->items ){
  20417. struct item item = {};
  20418. item.nameid = entry.second->item_id;
  20419. item.identify = 1;
  20420. item.refine = (char)entry.second->refine;
  20421. if( entry.second->rentalhours ){
  20422. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20423. }
  20424. // Check if it is a pet egg
  20425. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20426. if( pet != nullptr ){
  20427. for( int i = 0; i < entry.second->amount; i++ ){
  20428. pet_create_egg( sd, item.nameid );
  20429. }
  20430. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20431. for( int i = 0; i < entry.second->amount; i++ ){
  20432. // New random options on each iteration
  20433. if( entry.second->randomOptionGroup != nullptr ){
  20434. entry.second->randomOptionGroup->apply( item );
  20435. }
  20436. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20437. }
  20438. }else{
  20439. if( entry.second->randomOptionGroup != nullptr ){
  20440. entry.second->randomOptionGroup->apply( item );
  20441. }
  20442. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20443. }
  20444. }
  20445. #endif
  20446. }
  20447. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20448. {
  20449. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20450. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20451. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20452. p.itemId = itemId;
  20453. p.refine_level = level;
  20454. p.status = (int8)success;
  20455. if (battle_config.broadcast_hide_name) {
  20456. std::string dispname = clif_hide_name(sd.status.name);
  20457. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20458. }
  20459. else {
  20460. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20461. }
  20462. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20463. #endif
  20464. }
  20465. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20466. #if PACKETVER >= 20160316
  20467. nullpo_retv(sd);
  20468. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20469. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20470. return;
  20471. }
  20472. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20473. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20474. #endif
  20475. }
  20476. void clif_captcha_upload_request(map_session_data &sd) {
  20477. #if PACKETVER >= 20160330
  20478. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20479. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20480. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20481. if (sd.captcha_upload.cd != nullptr) {
  20482. p.captchaFlag = 0;
  20483. } else {
  20484. p.captchaFlag = 1;
  20485. }
  20486. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20487. #endif
  20488. }
  20489. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20490. #if PACKETVER >= 20160316
  20491. nullpo_retv(sd);
  20492. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20493. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20494. return;
  20495. }
  20496. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20497. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20498. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20499. return;
  20500. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20501. return;
  20502. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20503. #endif
  20504. }
  20505. void clif_captcha_upload_end(map_session_data &sd) {
  20506. #if PACKETVER >= 20160330
  20507. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20508. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20509. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20510. #endif
  20511. }
  20512. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20513. #if PACKETVER >= 20160323
  20514. nullpo_retv(sd);
  20515. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20516. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20517. return;
  20518. }
  20519. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20520. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20521. #endif
  20522. }
  20523. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20524. #if PACKETVER >= 20160330
  20525. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20526. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20527. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20528. if (cd == nullptr) {
  20529. p.captchaFlag = 1;
  20530. p.imageSize = 0;
  20531. } else {
  20532. p.captchaFlag = 0;
  20533. p.imageSize = cd->image_size;
  20534. }
  20535. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20536. if (cd != nullptr) {
  20537. for (uint16 offset = 0; offset < cd->image_size;) {
  20538. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20539. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20540. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20541. p2->PacketLength = (int16)(sizeof(PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20542. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20543. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20544. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20545. offset += chunk_size;
  20546. }
  20547. }
  20548. #endif
  20549. }
  20550. void clif_macro_detector_request(map_session_data &sd) {
  20551. #if PACKETVER >= 20160330
  20552. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20553. if (cd == nullptr) {
  20554. return;
  20555. }
  20556. // Send preview initialization request to the client.
  20557. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20558. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20559. p.imageSize = cd->image_size;
  20560. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20561. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20562. for (uint16 offset = 0; offset < cd->image_size;) {
  20563. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20564. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20565. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20566. p2->PacketLength = (int16)(sizeof(PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20567. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20568. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20569. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20570. offset += chunk_size;
  20571. }
  20572. #endif
  20573. }
  20574. void clif_macro_detector_request_show(map_session_data &sd) {
  20575. #if PACKETVER >= 20160330
  20576. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20577. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20578. p.retryCount = sd.macro_detect.retry;
  20579. p.timeout = battle_config.macro_detection_timeout;
  20580. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20581. #endif
  20582. }
  20583. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20584. #if PACKETVER >= 20160316
  20585. nullpo_retv(sd);
  20586. if (sd->macro_detect.retry != 0) {
  20587. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20588. clif_macro_detector_request_show(*sd);
  20589. }
  20590. #endif
  20591. }
  20592. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20593. #if PACKETVER >= 20160316
  20594. nullpo_retv(sd);
  20595. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20596. pc_macro_detector_process_answer(*sd, p->answer);
  20597. #endif
  20598. }
  20599. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20600. #if PACKETVER >= 20160330
  20601. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20602. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20603. p.status = stype;
  20604. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20605. #endif
  20606. }
  20607. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20608. #if PACKETVER >= 20160330
  20609. nullpo_retv(sd);
  20610. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20611. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20612. return;
  20613. }
  20614. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20615. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20616. #endif
  20617. }
  20618. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20619. #if PACKETVER >= 20160330
  20620. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *p = (PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *)packet_buffer;
  20621. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20622. p->PacketLength = static_cast<int16>(sizeof(PACKET_ZC_ACK_PLAYER_AID_IN_RANGE) + sizeof(uint32) * aid_list.size());
  20623. for (size_t i = 0; i < aid_list.size(); i++)
  20624. p->AID[i] = aid_list[static_cast<int32>(i)];
  20625. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20626. #endif
  20627. }
  20628. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20629. #if PACKETVER >= 20160316
  20630. nullpo_retv(sd);
  20631. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20632. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20633. return;
  20634. }
  20635. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20636. map_session_data *tsd = map_id2sd(p->AID);
  20637. if (tsd == nullptr) {
  20638. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20639. return;
  20640. }
  20641. if (tsd->macro_detect.retry != 0) {
  20642. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20643. return;
  20644. }
  20645. if (captcha_db.empty()) {
  20646. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20647. return;
  20648. }
  20649. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20650. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20651. #endif
  20652. }
  20653. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20654. #if PACKETVER >= 20160330
  20655. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20656. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20657. p.status = stype;
  20658. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20659. #endif
  20660. }
  20661. void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ){
  20662. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20663. struct PACKET_ZC_DYNAMICNPC_CREATE_RESULT p = {};
  20664. p.PacketType = HEADER_ZC_DYNAMICNPC_CREATE_RESULT;
  20665. p.result = result;
  20666. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20667. #endif
  20668. }
  20669. void clif_partybooking_ask( map_session_data* sd, map_session_data* joining_sd ){
  20670. #if PACKETVER >= 20191204
  20671. struct PACKET_ZC_PARTY_REQ_MASTER_TO_JOIN p = { 0 };
  20672. p.packetType = HEADER_ZC_PARTY_REQ_MASTER_TO_JOIN;
  20673. p.CID = joining_sd->status.char_id;
  20674. p.AID = joining_sd->status.account_id;
  20675. safestrncpy( p.name, joining_sd->status.name, NAME_LENGTH );
  20676. p.x = joining_sd->status.base_level;
  20677. p.y = joining_sd->status.class_;
  20678. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20679. #endif
  20680. }
  20681. void clif_parse_partybooking_join( int fd, map_session_data* sd ){
  20682. #if PACKETVER >= 20191204
  20683. struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20684. // Character is already in a party
  20685. if( sd->status.party_id != 0 ){
  20686. return;
  20687. }
  20688. map_session_data* tsd = map_charid2sd( p->CID );
  20689. // Target player is offline
  20690. if( tsd == nullptr ){
  20691. return;
  20692. }
  20693. if( tsd->status.account_id != p->AID ){
  20694. return;
  20695. }
  20696. struct s_party_booking_requirement requirement;
  20697. if( !party_booking_load( tsd->status.account_id, tsd->status.char_id, &requirement ) ){
  20698. return;
  20699. }
  20700. if( sd->status.base_level < requirement.minimum_level ){
  20701. return;
  20702. }
  20703. if( sd->status.base_level > requirement.maximum_level ){
  20704. return;
  20705. }
  20706. // Already requested to join this party
  20707. if( util::vector_exists( tsd->party_booking_requests, sd->status.char_id ) ){
  20708. return;
  20709. }
  20710. // Store information that the player tried to join the party
  20711. tsd->party_booking_requests.push_back( sd->status.char_id );
  20712. clif_partybooking_ask( tsd, sd );
  20713. #endif
  20714. }
  20715. void clif_partybooking_reply( map_session_data* sd, map_session_data* party_leader_sd, bool accepted ){
  20716. #if PACKETVER >= 20191204
  20717. struct PACKET_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER p = { 0 };
  20718. if( party_leader_sd->status.party_id == 0 ){
  20719. return;
  20720. }
  20721. struct party_data* party = party_search( party_leader_sd->status.party_id );
  20722. if( party == nullptr ){
  20723. return;
  20724. }
  20725. p.packetType = HEADER_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER;
  20726. safestrncpy( p.player_name, party_leader_sd->status.name, NAME_LENGTH );
  20727. safestrncpy( p.party_name, party->party.name, NAME_LENGTH );
  20728. p.AID = party_leader_sd->status.account_id;
  20729. p.refused = !accepted;
  20730. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20731. #endif
  20732. }
  20733. void clif_parse_partybooking_reply( int fd, map_session_data* sd ){
  20734. #if PACKETVER >= 20191204
  20735. struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20736. map_session_data* tsd = map_charid2sd( p->CID );
  20737. // Target player is offline
  20738. if( tsd == nullptr ){
  20739. return;
  20740. }
  20741. if( tsd->status.account_id != p->AID ){
  20742. return;
  20743. }
  20744. // Check if the player even requested to join the party
  20745. if( !util::vector_exists( sd->party_booking_requests, p->CID ) ){
  20746. return;
  20747. }
  20748. util::vector_erase_if_exists( sd->party_booking_requests, p->CID );
  20749. // Only party leaders can reply
  20750. if( !party_isleader( sd ) ){
  20751. return;
  20752. }
  20753. if( p->accept ){
  20754. party_join( tsd, sd->status.party_id );
  20755. }
  20756. clif_partybooking_reply( tsd, sd, p->accept );
  20757. #endif
  20758. }
  20759. void clif_parse_reset_skill( int fd, map_session_data* sd ){
  20760. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220203
  20761. PACKET_CZ_RESET_SKILL* p = (PACKET_CZ_RESET_SKILL*)RFIFOP( fd, 0 );
  20762. #endif
  20763. }
  20764. /*==========================================
  20765. * Main client packet processing function
  20766. *------------------------------------------*/
  20767. static int clif_parse(int fd)
  20768. {
  20769. int cmd, packet_len;
  20770. TBL_PC* sd;
  20771. int pnum;
  20772. #ifdef PACKET_OBFUSCATION
  20773. int cmd2;
  20774. #endif
  20775. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20776. // Note: "click masters" can do 80+ clicks in 10 seconds
  20777. 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]
  20778. { // begin main client packet processing loop
  20779. sd = (TBL_PC *)session[fd]->session_data;
  20780. if (session[fd]->flag.eof) {
  20781. if (sd) {
  20782. if (sd->state.autotrade) {
  20783. //Disassociate character from the socket connection.
  20784. session[fd]->session_data = NULL;
  20785. sd->fd = 0;
  20786. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20787. } else
  20788. if (sd->state.active) {
  20789. // Player logout display [Valaris]
  20790. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20791. clif_quitsave(fd, sd);
  20792. } else {
  20793. //Unusual logout (during log on/off/map-changer procedure)
  20794. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20795. map_quit(sd);
  20796. }
  20797. } else {
  20798. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20799. }
  20800. do_close(fd);
  20801. return 0;
  20802. }
  20803. if (RFIFOREST(fd) < 2)
  20804. return 0;
  20805. cmd = RFIFOW(fd, 0);
  20806. #ifdef PACKET_OBFUSCATION
  20807. // Check if it is a player that tries to connect to the map server.
  20808. if( sd ){
  20809. // Decrypt the current packet ID with the last key stored in the session.
  20810. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20811. }else{
  20812. // Store the original value for checking
  20813. cmd2 = cmd;
  20814. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20815. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20816. }
  20817. #endif
  20818. // filter out invalid / unsupported packets
  20819. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20820. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20821. #ifdef DUMP_INVALID_PACKET
  20822. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20823. #endif
  20824. #ifdef PACKET_OBFUSCATION_WARN
  20825. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20826. if( !sd ){
  20827. #ifdef PACKET_OBFUSCATION
  20828. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20829. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20830. }
  20831. #else
  20832. // Try to use the initial keys for the decryption of the packet ID.
  20833. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20834. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20835. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20836. }
  20837. #endif
  20838. }
  20839. #endif
  20840. set_eof(fd);
  20841. return 0;
  20842. }
  20843. // determine real packet length
  20844. packet_len = packet_db[cmd].len;
  20845. if (packet_len == -1) { // variable-length packet
  20846. if (RFIFOREST(fd) < 4)
  20847. return 0;
  20848. packet_len = RFIFOW(fd,2);
  20849. if (packet_len < 4 || packet_len > 32768) {
  20850. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20851. #ifdef DUMP_INVALID_PACKET
  20852. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20853. #endif
  20854. set_eof(fd);
  20855. return 0;
  20856. }
  20857. }
  20858. if ((int)RFIFOREST(fd) < packet_len){
  20859. 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 );
  20860. #ifdef DUMP_INVALID_PACKET
  20861. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20862. #endif
  20863. set_eof( fd );
  20864. return 0; // not enough data received to form the packet
  20865. }
  20866. #ifdef PACKET_OBFUSCATION
  20867. RFIFOW(fd, 0) = cmd;
  20868. if (sd)
  20869. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20870. #endif
  20871. if( packet_db[cmd].func == clif_parse_debug )
  20872. packet_db[cmd].func(fd, sd);
  20873. else if( packet_db[cmd].func != NULL ) {
  20874. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20875. ; //Only valid packet when there is no session
  20876. else
  20877. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20878. ; //Only valid packet when player is not on a map
  20879. else
  20880. packet_db[cmd].func(fd, sd);
  20881. }
  20882. #ifdef DUMP_UNKNOWN_PACKET
  20883. else DumpUnknown(fd,sd,cmd,packet_len);
  20884. #endif
  20885. RFIFOSKIP(fd, packet_len);
  20886. }; // main loop end
  20887. return 0;
  20888. }
  20889. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, map_session_data *), ... ){
  20890. va_list argp;
  20891. int i;
  20892. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20893. return;
  20894. packet_db[cmd].len = length;
  20895. packet_db[cmd].func = func;
  20896. va_start(argp, func);
  20897. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20898. int offset = va_arg(argp, int);
  20899. if( offset == 0 ){
  20900. break;
  20901. }
  20902. packet_db[cmd].pos[i] = offset;
  20903. }
  20904. if( i == MAX_PACKET_POS ){
  20905. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20906. }
  20907. va_end(argp);
  20908. }
  20909. /*==========================================
  20910. * Reads packets and setups its array reference
  20911. *------------------------------------------*/
  20912. void packetdb_readdb(){
  20913. memset(packet_db,0,sizeof(packet_db));
  20914. #include "clif_packetdb.hpp"
  20915. #include "clif_shuffle.hpp"
  20916. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20917. #ifdef PACKET_OBFUSCATION
  20918. 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]);
  20919. #else
  20920. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20921. #endif
  20922. }
  20923. /*==========================================
  20924. *
  20925. *------------------------------------------*/
  20926. void do_init_clif(void) {
  20927. const int colors[COLOR_MAX] = {
  20928. 0x00FF00, // COLOR_DEFAULT
  20929. 0xFF0000, // COLOR_RED
  20930. 0xFFFFFF, // COLOR_WHITE
  20931. 0xFFFF00, // COLOR_YELLOW
  20932. 0x00FFFF, // COLOR_CYAN
  20933. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20934. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20935. };
  20936. /**
  20937. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20938. **/
  20939. for( int i = 0; i < COLOR_MAX; i++ ){
  20940. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20941. }
  20942. packetdb_readdb();
  20943. set_defaultparse(clif_parse);
  20944. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20945. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20946. exit(EXIT_FAILURE);
  20947. }
  20948. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20949. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20950. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20951. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20952. if( battle_config.ping_timer_interval > 0 ){
  20953. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20954. }
  20955. #endif
  20956. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20957. }
  20958. void do_final_clif(void) {
  20959. ers_destroy(delay_clearunit_ers);
  20960. }