clif.cpp 722 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // Copyright (c) Hercules Dev Team - Licensed under GNU GPL
  3. // For more information, see LICENCE in the main folder
  4. #include "clif.hpp"
  5. #include <cstdarg>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <ctime>
  10. #include "../common/cbasetypes.hpp"
  11. #include "../common/conf.hpp"
  12. #include "../common/ers.hpp"
  13. #include "../common/grfio.hpp"
  14. #include "../common/malloc.hpp"
  15. #include "../common/nullpo.hpp"
  16. #include "../common/random.hpp"
  17. #include "../common/showmsg.hpp"
  18. #include "../common/socket.hpp"
  19. #include "../common/strlib.hpp"
  20. #include "../common/timer.hpp"
  21. #include "../common/utilities.hpp"
  22. #include "../common/utils.hpp"
  23. #include "achievement.hpp"
  24. #include "atcommand.hpp"
  25. #include "battle.hpp"
  26. #include "battleground.hpp"
  27. #include "cashshop.hpp"
  28. #include "channel.hpp"
  29. #include "chat.hpp"
  30. #include "chrif.hpp"
  31. #include "clan.hpp"
  32. #include "clif.hpp"
  33. #include "elemental.hpp"
  34. #include "guild.hpp"
  35. #include "homunculus.hpp"
  36. #include "instance.hpp"
  37. #include "intif.hpp"
  38. #include "itemdb.hpp"
  39. #include "log.hpp"
  40. #include "mail.hpp"
  41. #include "map.hpp"
  42. #include "mercenary.hpp"
  43. #include "mob.hpp"
  44. #include "npc.hpp"
  45. #include "party.hpp"
  46. #include "pc.hpp"
  47. #include "pc_groups.hpp"
  48. #include "pet.hpp"
  49. #include "quest.hpp"
  50. #include "script.hpp"
  51. #include "skill.hpp"
  52. #include "status.hpp"
  53. #include "storage.hpp"
  54. #include "trade.hpp"
  55. #include "unit.hpp"
  56. #include "vending.hpp"
  57. using namespace rathena;
  58. static inline uint32 client_tick( t_tick tick ){
  59. return (uint32)tick;
  60. }
  61. #if PACKETVER >= 20170830
  62. static inline int64 client_exp(t_exp exp) {
  63. return (int64)u64min(exp, MAX_EXP);
  64. }
  65. #else
  66. static inline int32 client_exp(t_exp exp) {
  67. return (int32)u64min(exp, MAX_EXP);
  68. }
  69. #endif
  70. /* for clif_clearunit_delayed */
  71. static struct eri *delay_clearunit_ers;
  72. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  73. // Reuseable global packet buffer to prevent too many allocations
  74. // Take socket.cpp::socket_max_client_packet into consideration
  75. static int8 packet_buffer[UINT16_MAX];
  76. unsigned long color_table[COLOR_MAX];
  77. #include "clif_obfuscation.hpp"
  78. static bool clif_session_isValid(map_session_data *sd);
  79. static void clif_loadConfirm( map_session_data *sd );
  80. #if PACKETVER >= 20150513
  81. enum mail_type {
  82. MAIL_TYPE_TEXT = 0x0,
  83. MAIL_TYPE_ZENY = 0x2,
  84. MAIL_TYPE_ITEM = 0x4,
  85. MAIL_TYPE_NPC = 0x8
  86. };
  87. #endif
  88. enum e_inventory_type{
  89. INVTYPE_INVENTORY = 0,
  90. INVTYPE_CART = 1,
  91. INVTYPE_STORAGE = 2,
  92. INVTYPE_GUILD_STORAGE = 3,
  93. };
  94. /** Converts item type to display it on client if necessary.
  95. * @param nameid: Item ID
  96. * @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
  97. */
  98. static inline int itemtype(t_itemid nameid) {
  99. 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
  100. int type = id->type;
  101. if( type == IT_SHADOWGEAR ) {
  102. if( id->equip&EQP_SHADOW_WEAPON )
  103. return IT_WEAPON;
  104. else
  105. return IT_ARMOR;
  106. }
  107. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  108. }
  109. // TODO: doc
  110. static inline uint16 client_index( uint16 server_index ){
  111. return server_index + 2;
  112. }
  113. static inline uint16 server_index( uint16 client_index ){
  114. return client_index - 2;
  115. }
  116. static inline uint16 client_storage_index( uint16 server_index ){
  117. return server_index + 1;
  118. }
  119. static inline uint16 server_storage_index( uint16 client_index ){
  120. return client_index - 1;
  121. }
  122. static inline uint32 disguised_bl_id( uint32 bl_id ){
  123. // Casting to prevent a compiler warning
  124. return -((int32)bl_id);
  125. }
  126. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  127. static inline uint32 client_nameid( t_itemid server_nameid ){
  128. t_itemid view = itemdb_viewid( server_nameid );
  129. if( view > 0 ){
  130. return view;
  131. }else{
  132. return server_nameid;
  133. }
  134. }
  135. #else
  136. static inline uint16 client_nameid( t_itemid server_nameid ){
  137. t_itemid view = itemdb_viewid( server_nameid );
  138. if( view > 0 ){
  139. if( view > UINT16_MAX ){
  140. return (uint16)UNKNOWN_ITEM_ID;
  141. }
  142. return (uint16)view;
  143. }else{
  144. if( server_nameid > UINT16_MAX ){
  145. return (uint16)UNKNOWN_ITEM_ID;
  146. }
  147. return (uint16)server_nameid;
  148. }
  149. }
  150. #endif
  151. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  152. p += pos;
  153. p[0] = (uint8)(x>>2);
  154. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  155. p[2] = (uint8)((y<<4) | (dir&0xf));
  156. }
  157. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  158. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  159. p += pos;
  160. p[0] = (uint8)(x0>>2);
  161. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  162. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  163. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  164. p[4] = (uint8)y1;
  165. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  166. }
  167. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  168. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  169. }
  170. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  171. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  172. }
  173. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  174. p += pos;
  175. if( x ) {
  176. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  177. }
  178. if( y ) {
  179. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  180. }
  181. if( dir ) {
  182. dir[0] = ( p[2] & 0x0f );
  183. }
  184. }
  185. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  186. p += pos;
  187. if( x0 ) {
  188. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  189. }
  190. if( y0 ) {
  191. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  192. }
  193. if( x1 ) {
  194. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  195. }
  196. if( y1 ) {
  197. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  198. }
  199. if( sx0 ) {
  200. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  201. }
  202. if( sy0 ) {
  203. sy0[0] = ( p[5] & 0x0f ) >> 0;
  204. }
  205. }
  206. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  207. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  208. }
  209. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  210. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  211. }
  212. //To idenfity disguised characters.
  213. static inline bool disguised(struct block_list* bl) {
  214. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  215. }
  216. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  217. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  218. if( len > max )
  219. len = max;
  220. mes[len-1] = '\0';
  221. return len;
  222. }
  223. static char map_ip_str[128];
  224. static uint32 map_ip;
  225. static uint32 bind_ip = INADDR_ANY;
  226. static uint16 map_port = 5121;
  227. static bool clif_ally_only = false;
  228. int map_fd;
  229. static int clif_parse (int fd);
  230. /*==========================================
  231. * Ip setting of map-server
  232. *------------------------------------------*/
  233. int clif_setip(const char* ip) {
  234. char ip_str[16];
  235. map_ip = host2ip(ip);
  236. if (!map_ip) {
  237. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  238. return 0;
  239. }
  240. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  241. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  242. return 1;
  243. }
  244. void clif_setbindip(const char* ip)
  245. {
  246. bind_ip = host2ip(ip);
  247. if (bind_ip) {
  248. char ip_str[16];
  249. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  250. } else {
  251. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  252. }
  253. }
  254. /*==========================================
  255. * Sets map port to 'port'
  256. * is run from map.cpp upon loading map server configuration
  257. *------------------------------------------*/
  258. void clif_setport(uint16 port)
  259. {
  260. map_port = port;
  261. }
  262. /*==========================================
  263. * Returns map server IP
  264. *------------------------------------------*/
  265. uint32 clif_getip(void)
  266. {
  267. return map_ip;
  268. }
  269. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  270. uint32 clif_refresh_ip(void)
  271. {
  272. uint32 new_ip;
  273. new_ip = host2ip(map_ip_str);
  274. if (new_ip && new_ip != map_ip) {
  275. map_ip = new_ip;
  276. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  277. return map_ip;
  278. }
  279. return 0;
  280. }
  281. /*==========================================
  282. * Returns map port which is set by clif_setport()
  283. *------------------------------------------*/
  284. uint16 clif_getport(void)
  285. {
  286. return map_port;
  287. }
  288. #if PACKETVER >= 20071106
  289. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  290. switch (bl->type) {
  291. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  292. case BL_ITEM: return 0x2; //ITEM_TYPE
  293. case BL_SKILL: return 0x3; //SKILL_TYPE
  294. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  295. case BL_MOB:
  296. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  297. return 0x0; //PC_TYPE
  298. }else{
  299. switch( ( (mob_data*)bl )->special_state.ai ){
  300. case AI_ABR:
  301. return 0xd; //NPC_ABR_TYPE
  302. case AI_BIONIC:
  303. return 0xe; //NPC_BIONIC_TYPE
  304. default:
  305. return 0x5; //NPC_MOB_TYPE
  306. }
  307. }
  308. case BL_NPC:
  309. // From 2017-07-26 on NPC type units can also use player sprites.
  310. // There is one exception and this is if they are walking.
  311. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  312. #if PACKETVER >= 20170726
  313. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0xC; // New walking NPC type
  314. #else
  315. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  316. #endif
  317. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  318. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  319. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  320. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  321. default: return 0x1; //NPC_TYPE
  322. }
  323. }
  324. #endif
  325. static bool clif_session_isValid(map_session_data *sd) {
  326. return ( sd != nullptr && session_isActive(sd->fd) );
  327. }
  328. /*==========================================
  329. * sub process of clif_send
  330. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  331. * In order to send area-wise packets, such as:
  332. * - AREA : everyone nearby your area
  333. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  334. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  335. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  336. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  337. *------------------------------------------*/
  338. static int clif_send_sub(struct block_list *bl, va_list ap)
  339. {
  340. struct block_list *src_bl;
  341. map_session_data *sd;
  342. unsigned char *buf;
  343. int len, type, fd;
  344. nullpo_ret(bl);
  345. nullpo_ret(sd = (map_session_data *)bl);
  346. // Don't send to disconnected clients.
  347. if( !session_isActive( fd = sd->fd ) ){
  348. return 0;
  349. }
  350. buf = va_arg(ap,unsigned char*);
  351. len = va_arg(ap,int);
  352. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  353. type = va_arg(ap,int);
  354. switch(type) {
  355. case AREA_WOS:
  356. if (bl == src_bl)
  357. return 0;
  358. break;
  359. case AREA_WOC:
  360. if (sd->chatID || bl == src_bl)
  361. return 0;
  362. break;
  363. case AREA_WOSC:
  364. {
  365. if(src_bl->type == BL_PC) {
  366. map_session_data *ssd = (map_session_data *)src_bl;
  367. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  368. return 0;
  369. }
  370. else if(src_bl->type == BL_NPC) {
  371. struct npc_data *nd = (struct npc_data *)src_bl;
  372. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  373. return 0;
  374. }
  375. }
  376. break;
  377. }
  378. if( src_bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)src_bl ), *sd ) ){
  379. // Do not send anything
  380. return 0;
  381. }
  382. /* unless visible, hold it here */
  383. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  384. !sd->sc.getSCE(SC_INTRAVISION) && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  385. return 0;
  386. WFIFOHEAD(fd, len);
  387. if (WFIFOP(fd,0) == buf) {
  388. ShowError("WARNING: Invalid use of clif_send function\n");
  389. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  390. ShowError(" Please correct your code.\n");
  391. // don't send to not move the pointer of the packet for next sessions in the loop
  392. //WFIFOSET(fd,0);//## TODO is this ok?
  393. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  394. return 0;
  395. }
  396. memcpy(WFIFOP(fd,0), buf, len);
  397. WFIFOSET(fd,len);
  398. return 0;
  399. }
  400. /*==========================================
  401. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  402. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  403. *------------------------------------------*/
  404. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  405. {
  406. int i;
  407. map_session_data *sd, *tsd;
  408. struct party_data *p = NULL;
  409. struct guild *g = NULL;
  410. std::shared_ptr<s_battleground_data> bg;
  411. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  412. struct s_mapiterator* iter;
  413. if( type != ALL_CLIENT )
  414. nullpo_ret(bl);
  415. sd = BL_CAST(BL_PC, bl);
  416. switch(type) {
  417. case ALL_CLIENT: //All player clients.
  418. iter = mapit_getallusers();
  419. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  420. if( session_isActive( fd = tsd->fd ) ){
  421. WFIFOHEAD( fd, len );
  422. memcpy( WFIFOP( fd, 0 ), buf, len );
  423. WFIFOSET( fd, len );
  424. }
  425. }
  426. mapit_free(iter);
  427. break;
  428. case ALL_SAMEMAP: //All players on the same map
  429. iter = mapit_getallusers();
  430. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  431. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  432. WFIFOHEAD( fd, len );
  433. memcpy( WFIFOP( fd, 0 ), buf, len );
  434. WFIFOSET( fd, len );
  435. }
  436. }
  437. mapit_free(iter);
  438. break;
  439. case AREA:
  440. case AREA_WOSC:
  441. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  442. clif_send (buf, len, bl, SELF);
  443. case AREA_WOC:
  444. case AREA_WOS:
  445. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  446. BL_PC, buf, len, bl, type);
  447. break;
  448. case AREA_CHAT_WOC:
  449. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  450. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  451. break;
  452. case CHAT:
  453. case CHAT_WOS:
  454. {
  455. struct chat_data *cd;
  456. if (sd) {
  457. cd = (struct chat_data*)map_id2bl(sd->chatID);
  458. } else if (bl->type == BL_CHAT) {
  459. cd = (struct chat_data*)bl;
  460. } else break;
  461. if (cd == NULL)
  462. break;
  463. for(i = 0; i < cd->users; i++) {
  464. if (type == CHAT_WOS && cd->usersd[i] == sd)
  465. continue;
  466. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  467. WFIFOHEAD(fd,len);
  468. memcpy(WFIFOP(fd,0), buf, len);
  469. WFIFOSET(fd,len);
  470. }
  471. }
  472. }
  473. break;
  474. case PARTY_AREA:
  475. case PARTY_AREA_WOS:
  476. x0 = bl->x - AREA_SIZE;
  477. y0 = bl->y - AREA_SIZE;
  478. x1 = bl->x + AREA_SIZE;
  479. y1 = bl->y + AREA_SIZE;
  480. case PARTY:
  481. case PARTY_WOS:
  482. case PARTY_SAMEMAP:
  483. case PARTY_SAMEMAP_WOS:
  484. if (sd && sd->status.party_id)
  485. p = party_search(sd->status.party_id);
  486. if (p) {
  487. for(i=0;i<MAX_PARTY;i++){
  488. if( (sd = p->data[i].sd) == NULL )
  489. continue;
  490. if( !session_isActive( fd = sd->fd ) )
  491. continue;
  492. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  493. continue;
  494. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  495. continue;
  496. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  497. continue;
  498. WFIFOHEAD(fd, len);
  499. memcpy(WFIFOP(fd, 0), buf, len);
  500. WFIFOSET(fd, len);
  501. }
  502. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  503. break;
  504. iter = mapit_getallusers();
  505. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  506. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  507. WFIFOHEAD( fd, len );
  508. memcpy( WFIFOP( fd, 0 ), buf, len );
  509. WFIFOSET( tsd->fd, len );
  510. }
  511. }
  512. mapit_free(iter);
  513. }
  514. break;
  515. case DUEL:
  516. case DUEL_WOS:
  517. if (!sd || !sd->duel_group) break; //Invalid usage.
  518. iter = mapit_getallusers();
  519. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  520. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  521. continue;
  522. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  523. WFIFOHEAD( fd, len );
  524. memcpy( WFIFOP( fd, 0 ), buf, len );
  525. WFIFOSET( fd, len );
  526. }
  527. }
  528. mapit_free(iter);
  529. break;
  530. case SELF:
  531. if( clif_session_isValid(sd) ){
  532. fd = sd->fd;
  533. WFIFOHEAD(fd,len);
  534. memcpy(WFIFOP(fd,0), buf, len);
  535. WFIFOSET(fd,len);
  536. }
  537. break;
  538. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  539. case GUILD_AREA:
  540. case GUILD_AREA_WOS:
  541. x0 = bl->x - AREA_SIZE;
  542. y0 = bl->y - AREA_SIZE;
  543. x1 = bl->x + AREA_SIZE;
  544. y1 = bl->y + AREA_SIZE;
  545. case GUILD_SAMEMAP:
  546. case GUILD_SAMEMAP_WOS:
  547. case GUILD:
  548. case GUILD_WOS:
  549. case GUILD_NOBG:
  550. if (sd && sd->status.guild_id)
  551. g = sd->guild;
  552. if (g) {
  553. for(i = 0; i < g->max_member; i++) {
  554. if( (sd = g->member[i].sd) != nullptr ){
  555. if( !session_isActive( fd = sd->fd ) )
  556. continue;
  557. if( type == GUILD_NOBG && sd->bg_id )
  558. continue;
  559. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  560. continue;
  561. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  562. continue;
  563. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  564. continue;
  565. WFIFOHEAD(fd,len);
  566. memcpy(WFIFOP(fd,0), buf, len);
  567. WFIFOSET(fd,len);
  568. }
  569. }
  570. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  571. break;
  572. iter = mapit_getallusers();
  573. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  574. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  575. WFIFOHEAD( fd, len );
  576. memcpy( WFIFOP( fd, 0 ), buf, len );
  577. WFIFOSET( fd, len );
  578. }
  579. }
  580. mapit_free(iter);
  581. }
  582. break;
  583. case BG_AREA:
  584. case BG_AREA_WOS:
  585. x0 = bl->x - AREA_SIZE;
  586. y0 = bl->y - AREA_SIZE;
  587. x1 = bl->x + AREA_SIZE;
  588. y1 = bl->y + AREA_SIZE;
  589. case BG_SAMEMAP:
  590. case BG_SAMEMAP_WOS:
  591. case BG:
  592. case BG_WOS:
  593. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  594. {
  595. for (const auto &member : bg->members) {
  596. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  597. continue;
  598. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  599. continue;
  600. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  601. continue;
  602. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  603. continue;
  604. WFIFOHEAD(fd,len);
  605. memcpy(WFIFOP(fd,0), buf, len);
  606. WFIFOSET(fd,len);
  607. }
  608. }
  609. break;
  610. case CLAN:
  611. if( sd && sd->clan ){
  612. struct clan* clan = sd->clan;
  613. for( i = 0; i < clan->max_member; i++ ){
  614. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  615. continue;
  616. }
  617. WFIFOHEAD(fd,len);
  618. memcpy(WFIFOP(fd,0), buf, len);
  619. WFIFOSET(fd,len);
  620. }
  621. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  622. break;
  623. iter = mapit_getallusers();
  624. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  625. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  626. WFIFOHEAD(fd, len);
  627. memcpy(WFIFOP(fd, 0), buf, len);
  628. WFIFOSET(fd, len);
  629. }
  630. }
  631. mapit_free(iter);
  632. }
  633. break;
  634. default:
  635. ShowError("clif_send: Unrecognized type %d\n",type);
  636. return -1;
  637. }
  638. return 0;
  639. }
  640. /// Notifies the client, that it's connection attempt was accepted.
  641. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  642. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  643. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  644. void clif_authok(map_session_data *sd)
  645. {
  646. #if PACKETVER < 20080102
  647. const int cmd = 0x73;
  648. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  649. const int cmd = 0x2eb;
  650. #else
  651. const int cmd = 0xa18;
  652. #endif
  653. int fd = sd->fd;
  654. WFIFOHEAD(fd,packet_len(cmd));
  655. WFIFOW(fd, 0) = cmd;
  656. WFIFOL(fd, 2) = client_tick(gettick());
  657. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  658. WFIFOB(fd, 9) = 5; // ignored
  659. WFIFOB(fd,10) = 5; // ignored
  660. #if PACKETVER >= 20080102
  661. WFIFOW(fd,11) = sd->status.font;
  662. #endif
  663. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  664. WFIFOB(fd,13) = sd->status.sex;
  665. #endif
  666. WFIFOSET(fd,packet_len(cmd));
  667. }
  668. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  669. /// 0074 <error code>.B
  670. /// error code:
  671. /// 0 = client type mismatch
  672. /// 1 = ID mismatch
  673. /// 2 = mobile - out of available time
  674. /// 3 = mobile - already logged in
  675. /// 4 = mobile - waiting state
  676. void clif_authrefuse(int fd, uint8 error_code)
  677. {
  678. WFIFOHEAD(fd,packet_len(0x74));
  679. WFIFOW(fd,0) = 0x74;
  680. WFIFOB(fd,2) = error_code;
  681. WFIFOSET(fd,packet_len(0x74));
  682. }
  683. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  684. /// 0081 <error code>.B
  685. /// error code:
  686. /// 0 = BAN_UNFAIR
  687. /// 1 = server closed -> MsgStringTable[4]
  688. /// 2 = ID already logged in -> MsgStringTable[5]
  689. /// 3 = timeout/too much lag -> MsgStringTable[241]
  690. /// 4 = server full -> MsgStringTable[264]
  691. /// 5 = underaged -> MsgStringTable[305]
  692. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  693. /// 9 = too many connections from this ip -> MsgStringTable[529]
  694. /// 10 = out of available time paid for -> MsgStringTable[530]
  695. /// 11 = BAN_PAY_SUSPEND
  696. /// 12 = BAN_PAY_CHANGE
  697. /// 13 = BAN_PAY_WRONGIP
  698. /// 14 = BAN_PAY_PNGAMEROOM
  699. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  700. /// 16 = BAN_JAPAN_REFUSE1
  701. /// 17 = BAN_JAPAN_REFUSE2
  702. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  703. /// 100 = BAN_PC_IP_UNFAIR
  704. /// 101 = BAN_PC_IP_COUNT_ALL
  705. /// 102 = BAN_PC_IP_COUNT
  706. /// 103 = BAN_GRAVITY_MEM_AGREE
  707. /// 104 = BAN_GAME_MEM_AGREE
  708. /// 105 = BAN_HAN_VALID
  709. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  710. /// 107 = BAN_OVER_CHARACTER_LIST
  711. /// 108 = BAN_IP_BLOCK
  712. /// 109 = BAN_INVALID_PWD_CNT
  713. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  714. /// ? = disconnected -> MsgStringTable[3]
  715. void clif_authfail_fd(int fd, int type)
  716. {
  717. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  718. return;
  719. WFIFOHEAD(fd, packet_len(0x81));
  720. WFIFOW(fd,0) = 0x81;
  721. WFIFOB(fd,2) = type;
  722. WFIFOSET(fd,packet_len(0x81));
  723. set_eof(fd);
  724. }
  725. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  726. /// 00b3 <type>.B
  727. /// type:
  728. /// 1 = disconnect, char-select
  729. /// ? = nothing
  730. void clif_charselectok(int id, uint8 ok)
  731. {
  732. map_session_data* sd;
  733. int fd;
  734. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  735. return;
  736. fd = sd->fd;
  737. WFIFOHEAD(fd,packet_len(0xb3));
  738. WFIFOW(fd,0) = 0xb3;
  739. WFIFOB(fd,2) = ok;
  740. WFIFOSET(fd,packet_len(0xb3));
  741. }
  742. /// Makes an item appear on the ground.
  743. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  744. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  745. /// 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)
  746. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  747. nullpo_retv(fitem);
  748. if( fitem->item.nameid == 0 ){
  749. return;
  750. }
  751. struct packet_dropflooritem p;
  752. p.PacketType = dropflooritemType;
  753. p.ITAID = fitem->bl.id;
  754. p.ITID = client_nameid( fitem->item.nameid );
  755. #if PACKETVER >= 20130000 /* not sure date */
  756. p.type = itemtype( fitem->item.nameid );
  757. #endif
  758. p.IsIdentified = fitem->item.identify ? 1 : 0;
  759. p.xPos = fitem->bl.x;
  760. p.yPos = fitem->bl.y;
  761. p.subX = fitem->subx;
  762. p.subY = fitem->suby;
  763. p.count = fitem->item.amount;
  764. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  765. if( canShowEffect ){
  766. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  767. if( dropEffect > 0 ){
  768. p.showdropeffect = 1;
  769. p.dropeffectmode = dropEffect - 1;
  770. }else if (battle_config.rndopt_drop_pillar != 0){
  771. uint8 optionCount = 0;
  772. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  773. if (fitem->item.option[i].id != 0) {
  774. optionCount++;
  775. }
  776. }
  777. if (optionCount > 0) {
  778. p.showdropeffect = 1;
  779. if (optionCount == 1)
  780. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  781. else if (optionCount == 2)
  782. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  783. else
  784. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  785. } else {
  786. p.showdropeffect = 0;
  787. p.dropeffectmode = DROPEFFECT_NONE;
  788. }
  789. } else {
  790. p.showdropeffect = 0;
  791. p.dropeffectmode = DROPEFFECT_NONE;
  792. }
  793. }else{
  794. p.showdropeffect = 0;
  795. p.dropeffectmode = DROPEFFECT_NONE;
  796. }
  797. #endif
  798. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  799. }
  800. /// Makes an item disappear from the ground.
  801. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  802. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  803. {
  804. unsigned char buf[16];
  805. nullpo_retv(fitem);
  806. WBUFW(buf,0) = 0xa1;
  807. WBUFL(buf,2) = fitem->bl.id;
  808. if ( !session_isActive( fd ) ){
  809. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  810. } else {
  811. WFIFOHEAD(fd,packet_len(0xa1));
  812. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  813. WFIFOSET(fd,packet_len(0xa1));
  814. }
  815. }
  816. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  817. /// 0080 <id>.L <type>.B
  818. /// type:
  819. /// 0 = out of sight
  820. /// 1 = died
  821. /// 2 = logged out
  822. /// 3 = teleport
  823. /// 4 = trickdead
  824. void clif_clearunit_single(int id, clr_type type, int fd)
  825. {
  826. WFIFOHEAD(fd, packet_len(0x80));
  827. WFIFOW(fd,0) = 0x80;
  828. WFIFOL(fd,2) = id;
  829. WFIFOB(fd,6) = type;
  830. WFIFOSET(fd, packet_len(0x80));
  831. }
  832. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  833. /// 0080 <id>.L <type>.B
  834. /// type:
  835. /// 0 = out of sight
  836. /// 1 = died
  837. /// 2 = logged out
  838. /// 3 = teleport
  839. /// 4 = trickdead
  840. void clif_clearunit_area(struct block_list* bl, clr_type type)
  841. {
  842. unsigned char buf[8];
  843. nullpo_retv(bl);
  844. WBUFW(buf,0) = 0x80;
  845. WBUFL(buf,2) = bl->id;
  846. WBUFB(buf,6) = type;
  847. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  848. if(disguised(bl)) {
  849. WBUFL(buf,2) = disguised_bl_id( bl->id );
  850. clif_send(buf, packet_len(0x80), bl, SELF);
  851. }
  852. }
  853. /// Used to make monsters with player-sprites disappear after dying
  854. /// like normal monsters, because the client does not remove those
  855. /// automatically.
  856. static TIMER_FUNC(clif_clearunit_delayed_sub){
  857. struct block_list *bl = (struct block_list *)data;
  858. clif_clearunit_area(bl, (clr_type) id);
  859. ers_free(delay_clearunit_ers,bl);
  860. return 0;
  861. }
  862. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  863. {
  864. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  865. memcpy (tbl, bl, sizeof (struct block_list));
  866. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  867. }
  868. void clif_get_weapon_view(map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  869. {
  870. if(sd->sc.option&OPTION_COSTUME)
  871. {
  872. *rhand = *lhand = 0;
  873. return;
  874. }
  875. #if PACKETVER < 4
  876. *rhand = sd->status.weapon;
  877. *lhand = sd->status.shield;
  878. #else
  879. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  880. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  881. {
  882. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  883. if (id->view_id > 0)
  884. *rhand = id->view_id;
  885. else
  886. *rhand = id->nameid;
  887. } else
  888. *rhand = 0;
  889. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  890. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  891. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  892. {
  893. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  894. if (id->view_id > 0)
  895. *lhand = id->view_id;
  896. else
  897. *lhand = id->nameid;
  898. } else
  899. *lhand = 0;
  900. #endif
  901. }
  902. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  903. static int clif_setlevel_sub(int lv) {
  904. if( lv < battle_config.max_lv ) {
  905. ;
  906. } else if( lv < battle_config.aura_lv ) {
  907. lv = battle_config.max_lv - 1;
  908. } else {
  909. lv = battle_config.max_lv;
  910. }
  911. return lv;
  912. }
  913. static int clif_setlevel(struct block_list* bl) {
  914. int lv = status_get_lv(bl);
  915. if( battle_config.client_limit_unit_lv&bl->type )
  916. return clif_setlevel_sub(lv);
  917. switch( bl->type ) {
  918. case BL_NPC:
  919. case BL_PET:
  920. // npcs and pets do not have level
  921. return 0;
  922. }
  923. return lv;
  924. }
  925. /*==========================================
  926. * Prepares 'unit standing/spawning' packet
  927. *------------------------------------------*/
  928. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  929. nullpo_retv( bl );
  930. map_session_data* sd = BL_CAST( BL_PC, bl );
  931. status_change* sc = status_get_sc( bl );
  932. struct view_data* vd = status_get_viewdata( bl );
  933. int g_id = status_get_guild_id( bl );
  934. #if PACKETVER < 20091103
  935. if( !pcdb_checkid( vd->class_ ) ){
  936. struct packet_idle_unit2 p;
  937. p.PacketType = idle_unit2Type;
  938. #if PACKETVER >= 20071106
  939. p.objecttype = clif_bl_type( bl, walking );
  940. #endif
  941. p.GID = bl->id;
  942. p.speed = status_get_speed( bl );
  943. p.bodyState = ( sc ) ? sc->opt1 : 0;
  944. p.healthState = ( sc ) ? sc->opt2 : 0;
  945. p.effectState = ( sc ) ? sc->option : 0;
  946. p.job = vd->class_;
  947. p.head = vd->hair_style;
  948. p.weapon = vd->weapon;
  949. p.accessory = vd->head_bottom;
  950. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  951. // The hell, why flags work like this?
  952. p.shield = status_get_emblem_id( bl );
  953. p.accessory2 = GetWord( g_id, 1 );
  954. p.accessory3 = GetWord( g_id, 0 );
  955. }else{
  956. p.shield = vd->shield;
  957. p.accessory2 = vd->head_top;
  958. p.accessory3 = vd->head_mid;
  959. }
  960. p.headpalette = vd->hair_color;
  961. p.bodypalette = vd->cloth_color;
  962. p.headDir = ( sd )? sd->head_dir : 0;
  963. p.GUID = g_id;
  964. p.GEmblemVer = status_get_emblem_id( bl );
  965. p.honor = ( sd ) ? sd->status.manner : 0;
  966. p.virtue = ( sc ) ? sc->opt3 : 0;
  967. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  968. p.sex = vd->sex;
  969. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  970. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  971. p.state = vd->dead_sit;
  972. p.clevel = clif_setlevel( bl );
  973. clif_send( &p, sizeof( p ), tbl, target );
  974. return;
  975. }
  976. #endif
  977. struct packet_idle_unit p;
  978. p.PacketType = idle_unitType;
  979. #if PACKETVER >= 20091103
  980. p.PacketLength = sizeof(p);
  981. p.objecttype = clif_bl_type( bl, walking );
  982. #endif
  983. #if PACKETVER >= 20131223
  984. p.AID = bl->id;
  985. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  986. #else
  987. p.GID = bl->id;
  988. #endif
  989. p.speed = status_get_speed(bl);
  990. p.bodyState = (sc) ? sc->opt1 : 0;
  991. p.healthState = (sc) ? sc->opt2 : 0;
  992. // npc option changed?
  993. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  994. map_session_data* sd = (map_session_data*)tbl;
  995. struct npc_data* nd = (struct npc_data*)bl;
  996. int option = (sc) ? sc->option : 0;
  997. if( !nd->vd.dead_sit ){
  998. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  999. option ^= OPTION_CLOAK;
  1000. }
  1001. }
  1002. p.effectState = option;
  1003. }else{
  1004. p.effectState = (sc) ? sc->option : 0;
  1005. }
  1006. p.job = vd->class_;
  1007. p.head = vd->hair_style;
  1008. p.weapon = vd->weapon;
  1009. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1010. p.shield = vd->shield;
  1011. #endif
  1012. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1013. // The hell, why flags work like this?
  1014. p.accessory = status_get_emblem_id( bl );
  1015. p.accessory2 = GetWord( g_id, 1 );
  1016. p.accessory3 = GetWord( g_id, 0 );
  1017. }else{
  1018. p.accessory = vd->head_bottom;
  1019. p.accessory2 = vd->head_top;
  1020. p.accessory3 = vd->head_mid;
  1021. }
  1022. p.headpalette = vd->hair_color;
  1023. p.bodypalette = vd->cloth_color;
  1024. p.headDir = (sd)? sd->head_dir : 0;
  1025. #if PACKETVER >= 20101124
  1026. p.robe = vd->robe;
  1027. #endif
  1028. p.GUID = g_id;
  1029. p.GEmblemVer = status_get_emblem_id( bl );
  1030. p.honor = (sd) ? sd->status.manner : 0;
  1031. p.virtue = (sc) ? sc->opt3 : 0;
  1032. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1033. p.sex = vd->sex;
  1034. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1035. p.xSize = p.ySize = (sd) ? 5 : 0;
  1036. p.state = vd->dead_sit;
  1037. p.clevel = clif_setlevel( bl );
  1038. #if PACKETVER >= 20080102
  1039. p.font = (sd) ? sd->status.font : 0;
  1040. #endif
  1041. #if PACKETVER >= 20120221
  1042. 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 ) ) ){
  1043. p.maxHP = status_get_max_hp(bl);
  1044. p.HP = status_get_hp(bl);
  1045. }else{
  1046. p.maxHP = -1;
  1047. p.HP = -1;
  1048. }
  1049. if( bl->type == BL_MOB ){
  1050. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1051. }else if( bl->type == BL_PET ){
  1052. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1053. }else{
  1054. p.isBoss = BOSSTYPE_NONE;
  1055. }
  1056. #endif
  1057. #if PACKETVER >= 20150513
  1058. p.body = vd->body_style;
  1059. #endif
  1060. /* Might be earlier, this is when the named item bug began */
  1061. #if PACKETVER >= 20131223
  1062. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1063. #endif
  1064. clif_send( &p, sizeof( p ), tbl, target );
  1065. // if disguised, send to self
  1066. if( disguised( bl ) ){
  1067. #if PACKETVER >= 20091103
  1068. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1069. #if PACKETVER >= 20131223
  1070. p.AID = disguised_bl_id( bl->id );
  1071. #else
  1072. p.GID = disguised_bl_id( bl->id );
  1073. #endif
  1074. #else
  1075. p.GID = disguised_bl_id( bl->id );
  1076. #endif
  1077. clif_send(&p, sizeof(p), bl, SELF);
  1078. }
  1079. }
  1080. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1081. nullpo_retv( bl );
  1082. map_session_data* sd = BL_CAST( BL_PC, bl );
  1083. status_change* sc = status_get_sc( bl );
  1084. struct view_data* vd = status_get_viewdata( bl );
  1085. int g_id = status_get_guild_id( bl );
  1086. #if PACKETVER < 20091103
  1087. if( !pcdb_checkid( vd->class_ ) ){
  1088. struct packet_spawn_unit2 p;
  1089. p.PacketType = spawn_unit2Type;
  1090. #if PACKETVER >= 20071106
  1091. p.objecttype = clif_bl_type( bl, false );
  1092. #endif
  1093. p.GID = bl->id;
  1094. p.speed = status_get_speed( bl );
  1095. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1096. p.healthState = ( sc ) ? sc->opt2 : 0;
  1097. p.effectState = ( sc ) ? sc->option : 0;
  1098. p.head = vd->hair_style;
  1099. p.weapon = vd->weapon;
  1100. p.accessory = vd->head_bottom;
  1101. p.job = vd->class_;
  1102. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1103. // The hell, why flags work like this?
  1104. p.shield = status_get_emblem_id( bl );
  1105. p.accessory2 = GetWord( g_id, 1 );
  1106. p.accessory3 = GetWord( g_id, 0 );
  1107. }else{
  1108. p.shield = vd->shield;
  1109. p.accessory2 = vd->head_top;
  1110. p.accessory3 = vd->head_mid;
  1111. }
  1112. p.headpalette = vd->hair_color;
  1113. p.bodypalette = vd->cloth_color;
  1114. p.headDir = ( sd ) ? sd->head_dir : 0;
  1115. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1116. p.sex = vd->sex;
  1117. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1118. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1119. clif_send( &p, sizeof( p ), bl, target );
  1120. return;
  1121. }
  1122. #endif
  1123. struct packet_spawn_unit p;
  1124. p.PacketType = spawn_unitType;
  1125. #if PACKETVER >= 20091103
  1126. p.PacketLength = sizeof(p);
  1127. p.objecttype = clif_bl_type( bl, false );
  1128. #endif
  1129. #if PACKETVER >= 20131223
  1130. p.AID = bl->id;
  1131. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1132. #else
  1133. p.GID = bl->id;
  1134. #endif
  1135. p.speed = status_get_speed( bl );
  1136. p.bodyState = (sc) ? sc->opt1 : 0;
  1137. p.healthState = (sc) ? sc->opt2 : 0;
  1138. p.effectState = (sc) ? sc->option : 0;
  1139. p.job = vd->class_;
  1140. p.head = vd->hair_style;
  1141. p.weapon = vd->weapon;
  1142. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1143. p.shield = vd->shield;
  1144. #endif
  1145. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1146. // The hell, why flags work like this?
  1147. p.accessory = status_get_emblem_id( bl );
  1148. p.accessory2 = GetWord( g_id, 1 );
  1149. p.accessory3 = GetWord( g_id, 0 );
  1150. }else{
  1151. p.accessory = vd->head_bottom;
  1152. p.accessory2 = vd->head_top;
  1153. p.accessory3 = vd->head_mid;
  1154. }
  1155. p.headpalette = vd->hair_color;
  1156. p.bodypalette = vd->cloth_color;
  1157. p.headDir = (sd)? sd->head_dir : 0;
  1158. #if PACKETVER >= 20101124
  1159. p.robe = vd->robe;
  1160. #endif
  1161. p.GUID = g_id;
  1162. p.GEmblemVer = status_get_emblem_id( bl );
  1163. p.honor = (sd) ? sd->status.manner : 0;
  1164. p.virtue = (sc) ? sc->opt3 : 0;
  1165. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1166. p.sex = vd->sex;
  1167. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1168. p.xSize = p.ySize = (sd) ? 5 : 0;
  1169. p.clevel = clif_setlevel( bl );
  1170. #if PACKETVER >= 20080102
  1171. p.font = (sd) ? sd->status.font : 0;
  1172. #endif
  1173. #if PACKETVER >= 20120221
  1174. 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 ) ) ){
  1175. p.maxHP = status_get_max_hp( bl );
  1176. p.HP = status_get_hp( bl );
  1177. }else{
  1178. p.maxHP = -1;
  1179. p.HP = -1;
  1180. }
  1181. if( bl->type == BL_MOB ){
  1182. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1183. }else if( bl->type == BL_PET ){
  1184. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1185. }else{
  1186. p.isBoss = BOSSTYPE_NONE;
  1187. }
  1188. #endif
  1189. #if PACKETVER >= 20150513
  1190. p.body = vd->body_style;
  1191. #endif
  1192. /* Might be earlier, this is when the named item bug began */
  1193. #if PACKETVER >= 20131223
  1194. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1195. #endif
  1196. if( disguised( bl ) ){
  1197. nullpo_retv( sd );
  1198. if( sd->status.class_ != sd->disguise ){
  1199. clif_send( &p, sizeof( p ), bl, target );
  1200. }
  1201. #if PACKETVER >= 20091103
  1202. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1203. #if PACKETVER >= 20131223
  1204. p.AID = disguised_bl_id( bl->id );
  1205. #else
  1206. p.GID = disguised_bl_id( bl->id );
  1207. #endif
  1208. #else
  1209. p.GID = disguised_bl_id( bl->id );
  1210. #endif
  1211. clif_send( &p, sizeof( p ), bl, SELF );
  1212. }else{
  1213. clif_send( &p, sizeof( p ), bl, target );
  1214. }
  1215. }
  1216. /*==========================================
  1217. * Prepares 'unit walking' packet
  1218. *------------------------------------------*/
  1219. static void clif_set_unit_walking( struct block_list *bl, map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1220. nullpo_retv( bl );
  1221. nullpo_retv( ud );
  1222. map_session_data* sd;
  1223. status_change* sc = status_get_sc( bl );
  1224. struct view_data* vd = status_get_viewdata( bl );
  1225. struct packet_unit_walking p;
  1226. int g_id = status_get_guild_id(bl);
  1227. sd = BL_CAST(BL_PC, bl);
  1228. p.PacketType = unit_walkingType;
  1229. #if PACKETVER >= 20091103
  1230. p.PacketLength = sizeof(p);
  1231. #endif
  1232. #if PACKETVER >= 20071106
  1233. p.objecttype = clif_bl_type( bl, true );
  1234. #endif
  1235. #if PACKETVER >= 20131223
  1236. p.AID = bl->id;
  1237. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1238. #else
  1239. p.GID = bl->id;
  1240. #endif
  1241. p.speed = status_get_speed(bl);
  1242. p.bodyState = (sc) ? sc->opt1 : 0;
  1243. p.healthState = (sc) ? sc->opt2 : 0;
  1244. p.effectState = (sc) ? sc->option : 0;
  1245. p.job = vd->class_;
  1246. p.head = vd->hair_style;
  1247. p.weapon = vd->weapon;
  1248. p.accessory = vd->head_bottom;
  1249. p.moveStartTime = client_tick(gettick());
  1250. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1251. p.shield = vd->shield;
  1252. #endif
  1253. p.accessory2 = vd->head_top;
  1254. p.accessory3 = vd->head_mid;
  1255. p.headpalette = vd->hair_color;
  1256. p.bodypalette = vd->cloth_color;
  1257. p.headDir = (sd) ? sd->head_dir : 0;
  1258. #if PACKETVER >= 20101124
  1259. p.robe = vd->robe;
  1260. #endif
  1261. p.GUID = g_id;
  1262. p.GEmblemVer = status_get_emblem_id(bl);
  1263. p.honor = (sd) ? sd->status.manner : 0;
  1264. p.virtue = (sc) ? sc->opt3 : 0;
  1265. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1266. p.sex = vd->sex;
  1267. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1268. p.xSize = p.ySize = (sd) ? 5 : 0;
  1269. p.clevel = clif_setlevel(bl);
  1270. #if PACKETVER >= 20080102
  1271. p.font = (sd) ? sd->status.font : 0;
  1272. #endif
  1273. #if PACKETVER >= 20120221
  1274. 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 ) ) ){
  1275. p.maxHP = status_get_max_hp(bl);
  1276. p.HP = status_get_hp(bl);
  1277. } else {
  1278. p.maxHP = -1;
  1279. p.HP = -1;
  1280. }
  1281. if( bl->type == BL_MOB ){
  1282. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1283. }else if( bl->type == BL_PET ){
  1284. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1285. }else{
  1286. p.isBoss = BOSSTYPE_NONE;
  1287. }
  1288. #endif
  1289. #if PACKETVER >= 20150513
  1290. p.body = vd->body_style;
  1291. #endif
  1292. /* Might be earlier, this is when the named item bug began */
  1293. #if PACKETVER >= 20131223
  1294. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1295. #endif
  1296. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1297. // if disguised, send the info to self
  1298. if( disguised( bl ) ){
  1299. #if PACKETVER >= 20091103
  1300. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1301. #if PACKETVER >= 20131223
  1302. p.AID = disguised_bl_id( bl->id );
  1303. #else
  1304. p.GID = disguised_bl_id( bl->id );
  1305. #endif
  1306. #else
  1307. p.GID = disguised_bl_id( bl->id );
  1308. #endif
  1309. clif_send(&p,sizeof(p),bl,SELF);
  1310. }
  1311. }
  1312. //Modifies the buffer for disguise characters and sends it to self.
  1313. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1314. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1315. {
  1316. #if PACKETVER >= 20091103
  1317. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1318. WBUFL(buf,5)=-bl->id;
  1319. #elif PACKETVER >= 20071106
  1320. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1321. WBUFL(buf,3)=-bl->id;
  1322. #else
  1323. WBUFL(buf,2)=-bl->id;
  1324. #endif
  1325. clif_send(buf, len, bl, SELF);
  1326. }
  1327. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1328. /// 01b0 <id>.L <type>.B <value>.L
  1329. /// type:
  1330. /// unused
  1331. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, map_session_data *sd)
  1332. {
  1333. nullpo_retv(bl);
  1334. if(!pcdb_checkid(class_))
  1335. {// player classes yield missing sprites
  1336. unsigned char buf[16];
  1337. WBUFW(buf,0)=0x1b0;
  1338. WBUFL(buf,2)=bl->id;
  1339. WBUFB(buf,6)=type;
  1340. WBUFL(buf,7)=class_;
  1341. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1342. }
  1343. }
  1344. void clif_servantball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1345. struct PACKET_ZC_SPIRITS p = {};
  1346. p.PacketType = HEADER_ZC_SPIRITS;
  1347. p.AID = sd.bl.id;
  1348. p.num = sd.servantball;
  1349. if( target == nullptr ){
  1350. target = &sd.bl;
  1351. }
  1352. clif_send( &p, sizeof( p ), target, send_target );
  1353. }
  1354. void clif_abyssball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1355. struct PACKET_ZC_SPIRITS p = {};
  1356. p.PacketType = HEADER_ZC_SPIRITS;
  1357. p.AID = sd.bl.id;
  1358. p.num = sd.abyssball;
  1359. if( target == nullptr ){
  1360. target = &sd.bl;
  1361. }
  1362. clif_send( &p, sizeof( p ), target, send_target );
  1363. }
  1364. /// Notifies the client of an object's Millenium Shields.
  1365. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1366. {
  1367. nullpo_retv(sd);
  1368. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD) == nullptr)
  1369. return;
  1370. WFIFOHEAD(fd, packet_len(0x440));
  1371. WFIFOW(fd, 0) = 0x440;
  1372. WFIFOL(fd, 2) = sd->bl.id;
  1373. WFIFOW(fd, 6) = sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2;
  1374. WFIFOW(fd, 8) = 0;
  1375. WFIFOSET(fd, packet_len(0x440));
  1376. }
  1377. /*==========================================
  1378. * Kagerou/Oboro amulet spirit
  1379. *------------------------------------------*/
  1380. static void clif_spiritcharm_single(int fd, map_session_data *sd)
  1381. {
  1382. WFIFOHEAD(fd, packet_len(0x08cf));
  1383. WFIFOW(fd,0)=0x08cf;
  1384. WFIFOL(fd,2)=sd->bl.id;
  1385. WFIFOW(fd,6)=sd->spiritcharm_type;
  1386. WFIFOW(fd,8)=sd->spiritcharm;
  1387. WFIFOSET(fd, packet_len(0x08cf));
  1388. }
  1389. /*==========================================
  1390. * Enchanting Shadow / Shadow Scar Spirit
  1391. *------------------------------------------*/
  1392. void clif_enchantingshadow_spirit(unit_data &ud) {
  1393. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1394. PACKET_ZC_TARGET_SPIRITS p = {};
  1395. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1396. p.GID = ud.bl->id;
  1397. p.unknown_val = 0;
  1398. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1399. clif_send(&p, sizeof(p), ud.bl, AREA);
  1400. #endif
  1401. }
  1402. /*==========================================
  1403. * Run when player changes map / refreshes
  1404. * Tells its client to display all weather settings being used by this map
  1405. *------------------------------------------*/
  1406. static void clif_weather_check(map_session_data *sd)
  1407. {
  1408. int16 m = sd->bl.m;
  1409. int fd = sd->fd;
  1410. if (map_getmapflag(m, MF_SNOW)
  1411. || map_getmapflag(m, MF_CLOUDS)
  1412. || map_getmapflag(m, MF_FOG)
  1413. || map_getmapflag(m, MF_FIREWORKS)
  1414. || map_getmapflag(m, MF_SAKURA)
  1415. || map_getmapflag(m, MF_LEAVES)
  1416. || map_getmapflag(m, MF_CLOUDS2))
  1417. {
  1418. if (map_getmapflag(m, MF_SNOW))
  1419. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1420. if (map_getmapflag(m, MF_CLOUDS))
  1421. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1422. if (map_getmapflag(m, MF_CLOUDS2))
  1423. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1424. if (map_getmapflag(m, MF_FOG))
  1425. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1426. if (map_getmapflag(m, MF_FIREWORKS)) {
  1427. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1428. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1429. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1430. }
  1431. if (map_getmapflag(m, MF_SAKURA))
  1432. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1433. if (map_getmapflag(m, MF_LEAVES))
  1434. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1435. }
  1436. }
  1437. /**
  1438. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1439. **/
  1440. void clif_weather(int16 m)
  1441. {
  1442. struct s_mapiterator* iter;
  1443. map_session_data *sd=NULL;
  1444. iter = mapit_getallusers();
  1445. for( sd = (map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (map_session_data*)mapit_next(iter) )
  1446. {
  1447. if( sd->bl.m == m )
  1448. clif_weather_check(sd);
  1449. }
  1450. mapit_free(iter);
  1451. }
  1452. /**
  1453. * Hide a NPC from the effects of Maya Purple card.
  1454. * @param bl: Block data
  1455. * @return True if NPC is disabled or false otherwise
  1456. */
  1457. static inline bool clif_npc_mayapurple(block_list *bl) {
  1458. nullpo_retr(false, bl);
  1459. if (bl->type == BL_NPC) {
  1460. npc_data *nd = map_id2nd(bl->id);
  1461. // TODO: Confirm if waitingroom cause any special cases
  1462. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1463. return true;
  1464. }
  1465. return false;
  1466. }
  1467. /**
  1468. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1469. **/
  1470. int clif_spawn( struct block_list *bl, bool walking ){
  1471. struct view_data *vd;
  1472. vd = status_get_viewdata(bl);
  1473. if( !vd || vd->class_ == JT_INVISIBLE )
  1474. return 0;
  1475. // Hide NPC from Maya Purple card
  1476. if (clif_npc_mayapurple(bl))
  1477. return 0;
  1478. if( bl->type == BL_NPC && !vd->dead_sit ){
  1479. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1480. }else{
  1481. clif_spawn_unit( bl, AREA_WOS );
  1482. }
  1483. if (vd->cloth_color)
  1484. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1485. if (vd->body_style)
  1486. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1487. switch (bl->type)
  1488. {
  1489. case BL_PC:
  1490. {
  1491. TBL_PC *sd = ((TBL_PC*)bl);
  1492. if (sd->spiritball > 0)
  1493. clif_spiritball(&sd->bl);
  1494. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  1495. clif_millenniumshield(&sd->bl, sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2);
  1496. if (sd->soulball > 0)
  1497. clif_soulball(sd);
  1498. if (sd->servantball > 0)
  1499. clif_servantball( *sd );
  1500. if (sd->abyssball > 0)
  1501. clif_abyssball( *sd );
  1502. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1503. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1504. else if(sd->state.size==SZ_MEDIUM)
  1505. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1506. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1507. clif_sendbgemblem_area(sd);
  1508. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1509. clif_spiritcharm(sd);
  1510. if (sd->status.robe)
  1511. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1512. clif_efst_status_change_sub(bl, bl, AREA);
  1513. clif_hat_effects(sd,bl,AREA);
  1514. }
  1515. break;
  1516. case BL_MOB:
  1517. {
  1518. TBL_MOB *md = ((TBL_MOB*)bl);
  1519. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1520. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1521. else if(md->special_state.size==SZ_MEDIUM)
  1522. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1523. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1524. clif_summon_init(*md);
  1525. }
  1526. break;
  1527. case BL_NPC:
  1528. {
  1529. TBL_NPC *nd = ((TBL_NPC*)bl);
  1530. if( nd->size == SZ_BIG )
  1531. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1532. else if( nd->size == SZ_MEDIUM )
  1533. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1534. clif_efst_status_change_sub(bl, bl, AREA);
  1535. clif_progressbar_npc_area(nd);
  1536. }
  1537. break;
  1538. case BL_PET:
  1539. if (vd->head_bottom)
  1540. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1541. break;
  1542. }
  1543. return 0;
  1544. }
  1545. /// Sends information about owned homunculus to the client . [orn]
  1546. /// 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)
  1547. /// 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)
  1548. void clif_hominfo( map_session_data *sd, struct homun_data *hd, int flag ){
  1549. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1550. nullpo_retv( sd );
  1551. nullpo_retv( hd );
  1552. struct status_data *status = &hd->battle_status;
  1553. struct PACKET_ZC_PROPERTY_HOMUN p;
  1554. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1555. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1556. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1557. 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 );
  1558. p.level = hd->homunculus.level;
  1559. p.hunger = hd->homunculus.hunger;
  1560. p.intimacy = hd->homunculus.intimacy / 100;
  1561. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1562. p.itemId = 0; // equip id
  1563. #endif
  1564. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1565. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1566. p.hit = status->hit;
  1567. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1568. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1569. }else{
  1570. p.crit = status->cri / 10;
  1571. }
  1572. #ifdef RENEWAL
  1573. p.def = status->def + status->def2;
  1574. p.mdef = status->mdef + status->mdef2;
  1575. #else
  1576. p.def = status->def + status->vit;
  1577. p.mdef = status->mdef;
  1578. #endif
  1579. p.flee = status->flee;
  1580. p.amotion = (flag) ? 0 : status->amotion;
  1581. #if PACKETVER >= 20141016
  1582. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1583. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1584. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1585. p.hp = status->hp / ( status->max_hp / 100 );
  1586. p.maxHp = 100;
  1587. }else{
  1588. p.hp = status->hp;
  1589. p.maxHp = status->max_hp;
  1590. }
  1591. #else
  1592. if( status->max_hp > INT16_MAX ){
  1593. p.hp = status->hp / ( status->max_hp / 100 );
  1594. p.maxHp = 100;
  1595. }else{
  1596. p.hp = status->hp;
  1597. p.maxHp = status->max_hp;
  1598. }
  1599. #endif
  1600. if( status->max_sp > INT16_MAX ){
  1601. p.sp = status->sp / ( status->max_sp / 100 );
  1602. p.maxSp = 100;
  1603. }else{
  1604. p.sp = status->sp;
  1605. p.maxSp = status->max_sp;
  1606. }
  1607. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1608. p.exp = hd->homunculus.exp;
  1609. p.expNext = hd->exp_next;
  1610. #else
  1611. p.exp = (uint32)hd->homunculus.exp;
  1612. p.expNext = (uint32)hd->exp_next;
  1613. #endif
  1614. switch( hom_class2type( hd->homunculus.class_ ) ){
  1615. case HT_REG:
  1616. case HT_EVO:
  1617. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1618. p.expNext = 0;
  1619. }
  1620. break;
  1621. case HT_S:
  1622. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1623. p.expNext = 0;
  1624. }
  1625. break;
  1626. }
  1627. p.skillPoints = hd->homunculus.skillpts;
  1628. p.range = status_get_range( &hd->bl );
  1629. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1630. #endif
  1631. }
  1632. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1633. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1634. /// type:
  1635. /// unused
  1636. /// state:
  1637. /// 0 = pre-init
  1638. /// 1 = intimacy
  1639. /// 2 = hunger
  1640. /// 3 = accessory?
  1641. /// ? = ignored
  1642. void clif_send_homdata(map_session_data *sd, int state, int param)
  1643. { //[orn]
  1644. int fd = sd->fd;
  1645. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1646. hom_calc_skilltree(sd->hd, 0);
  1647. WFIFOHEAD(fd, packet_len(0x230));
  1648. WFIFOW(fd,0)=0x230;
  1649. WFIFOB(fd,2)=0;
  1650. WFIFOB(fd,3)=state;
  1651. WFIFOL(fd,4)=sd->hd->bl.id;
  1652. WFIFOL(fd,8)=param;
  1653. WFIFOSET(fd,packet_len(0x230));
  1654. }
  1655. int clif_homskillinfoblock(map_session_data *sd)
  1656. { //[orn]
  1657. struct homun_data *hd;
  1658. int fd = sd->fd;
  1659. int i, len=4;
  1660. nullpo_ret(sd);
  1661. hd = sd->hd;
  1662. if ( !hd )
  1663. return 0 ;
  1664. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1665. WFIFOW(fd,0)=0x235;
  1666. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1667. int id = hd->homunculus.hskill[i].id;
  1668. if( id != 0 ){
  1669. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1670. short idx = hom_skill_get_index(id);
  1671. if (idx == -1)
  1672. continue;
  1673. WFIFOW(fd,len ) = id;
  1674. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1675. WFIFOW(fd,len+4) = 0;
  1676. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1677. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1678. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1679. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1680. 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;
  1681. len+=37;
  1682. }
  1683. }
  1684. WFIFOW(fd,2)=len;
  1685. WFIFOSET(fd,len);
  1686. return 0;
  1687. }
  1688. void clif_homskillup(map_session_data *sd, uint16 skill_id)
  1689. { //[orn]
  1690. struct homun_data *hd;
  1691. int fd;
  1692. short idx = -1;
  1693. nullpo_retv(sd);
  1694. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1695. return;
  1696. fd = sd->fd;
  1697. hd = sd->hd;
  1698. WFIFOHEAD(fd, packet_len(0x239));
  1699. WFIFOW(fd,0) = 0x239;
  1700. WFIFOW(fd,2) = skill_id;
  1701. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1702. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1703. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1704. 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;
  1705. WFIFOSET(fd,packet_len(0x239));
  1706. }
  1707. /// Result of request to feed a homun/merc.
  1708. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1709. /// result:
  1710. /// 0 = failure
  1711. /// 1 = success
  1712. void clif_hom_food( map_session_data *sd, int foodid, int fail ){
  1713. nullpo_retv( sd );
  1714. struct PACKET_ZC_FEED_MER p;
  1715. p.packetType = 0x22f;
  1716. p.result = fail;
  1717. p.itemId = client_nameid( foodid );
  1718. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1719. }
  1720. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1721. /// 0087 <walk start time>.L <walk data>.6B
  1722. void clif_walkok(map_session_data *sd)
  1723. {
  1724. int fd=sd->fd;
  1725. WFIFOHEAD(fd, packet_len(0x87));
  1726. WFIFOW(fd,0)=0x87;
  1727. WFIFOL(fd,2)=client_tick(gettick());
  1728. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1729. WFIFOSET(fd,packet_len(0x87));
  1730. }
  1731. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1732. status_change *sc = NULL;
  1733. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1734. clif_ally_only = true;
  1735. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1736. if(vd->cloth_color)
  1737. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1738. if(vd->body_style)
  1739. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1740. switch(bl->type) {
  1741. case BL_PC:
  1742. {
  1743. TBL_PC *sd = ((TBL_PC*)bl);
  1744. // clif_movepc(sd);
  1745. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1746. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1747. else if(sd->state.size==SZ_MEDIUM)
  1748. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1749. if (sd->status.robe)
  1750. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1751. }
  1752. break;
  1753. case BL_MOB:
  1754. {
  1755. TBL_MOB *md = ((TBL_MOB*)bl);
  1756. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1757. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1758. else if(md->special_state.size==SZ_MEDIUM)
  1759. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1760. }
  1761. break;
  1762. case BL_PET:
  1763. if(vd->head_bottom) // needed to display pet equip properly
  1764. clif_pet_equip_area((TBL_PET*)bl);
  1765. break;
  1766. }
  1767. clif_ally_only = false;
  1768. }
  1769. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1770. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1771. /// Note: unit must not be self
  1772. void clif_move(struct unit_data *ud)
  1773. {
  1774. unsigned char buf[16];
  1775. struct view_data* vd;
  1776. struct block_list* bl = ud->bl;
  1777. status_change *sc = NULL;
  1778. vd = status_get_viewdata(bl);
  1779. if (!vd )
  1780. return;
  1781. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1782. else if( vd->class_ == JT_INVISIBLE ){
  1783. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1784. if(disguised(bl)) {
  1785. WBUFW(buf,0)=0x86;
  1786. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1787. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1788. WBUFL(buf,12)=client_tick(gettick());
  1789. clif_send(buf, packet_len(0x86), bl, SELF);
  1790. }
  1791. return;
  1792. }
  1793. // Hide NPC from Maya Purple card
  1794. if (clif_npc_mayapurple(bl))
  1795. return;
  1796. if (ud->state.speed_changed) {
  1797. // Since we don't know how to update the speed of other objects,
  1798. // use the old walk packet to update the data.
  1799. ud->state.speed_changed = 0;
  1800. clif_move2(bl, vd, ud);
  1801. return;
  1802. }
  1803. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1804. clif_ally_only = true;
  1805. WBUFW(buf,0)=0x86;
  1806. WBUFL(buf,2)=bl->id;
  1807. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1808. WBUFL(buf,12)=client_tick(gettick());
  1809. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1810. if (disguised(bl)) {
  1811. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1812. clif_send(buf, packet_len(0x86), bl, SELF);
  1813. }
  1814. clif_ally_only = false;
  1815. }
  1816. /*==========================================
  1817. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1818. *------------------------------------------*/
  1819. static TIMER_FUNC(clif_delayquit){
  1820. map_session_data *sd = NULL;
  1821. //Remove player from map server
  1822. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1823. map_quit(sd);
  1824. return 0;
  1825. }
  1826. /*==========================================
  1827. *
  1828. *------------------------------------------*/
  1829. void clif_quitsave(int fd,map_session_data *sd) {
  1830. if (!battle_config.prevent_logout ||
  1831. sd->canlog_tick == 0 ||
  1832. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1833. map_quit(sd);
  1834. else if (session_isValid(sd->fd)) {
  1835. //Disassociate session from player (session is deleted after this function was called)
  1836. //And set a timer to make him quit later.
  1837. session[sd->fd]->session_data = NULL;
  1838. sd->fd = 0;
  1839. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1840. }
  1841. }
  1842. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1843. /// 0091 <map name>.16B <x>.W <y>.W
  1844. void clif_changemap(map_session_data *sd, short m, int x, int y)
  1845. {
  1846. nullpo_retv(sd);
  1847. int fd = sd->fd;
  1848. WFIFOHEAD(fd,packet_len(0x91));
  1849. WFIFOW(fd,0) = 0x91;
  1850. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1851. WFIFOW(fd,18) = x;
  1852. WFIFOW(fd,20) = y;
  1853. WFIFOSET(fd,packet_len(0x91));
  1854. }
  1855. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1856. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1857. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1858. void clif_changemapserver(map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1859. {
  1860. int fd;
  1861. #if PACKETVER >= 20170315
  1862. int cmd = 0xac7;
  1863. #else
  1864. int cmd = 0x92;
  1865. #endif
  1866. nullpo_retv(sd);
  1867. fd = sd->fd;
  1868. WFIFOHEAD(fd,packet_len(cmd));
  1869. WFIFOW(fd,0) = cmd;
  1870. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1871. WFIFOW(fd,18) = x;
  1872. WFIFOW(fd,20) = y;
  1873. WFIFOL(fd,22) = htonl(ip);
  1874. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1875. #if PACKETVER >= 20170315
  1876. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1877. #endif
  1878. WFIFOSET(fd,packet_len(cmd));
  1879. }
  1880. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1881. /// This function combines both calls and allows to simplify the calling code
  1882. void clif_blown(struct block_list *bl)
  1883. {
  1884. clif_slide(bl, bl->x, bl->y);
  1885. clif_fixpos(bl);
  1886. }
  1887. /// Visually moves(slides) a character to x,y. If the target cell
  1888. /// isn't walkable, the char doesn't move at all. If the char is
  1889. /// sitting it will stand up (ZC_STOPMOVE).
  1890. /// 0088 <id>.L <x>.W <y>.W
  1891. void clif_fixpos(struct block_list *bl)
  1892. {
  1893. unsigned char buf[10];
  1894. nullpo_retv(bl);
  1895. WBUFW(buf,0) = 0x88;
  1896. WBUFL(buf,2) = bl->id;
  1897. WBUFW(buf,6) = bl->x;
  1898. WBUFW(buf,8) = bl->y;
  1899. clif_send(buf, packet_len(0x88), bl, AREA);
  1900. if( disguised(bl) ) {
  1901. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1902. clif_send(buf, packet_len(0x88), bl, SELF);
  1903. }
  1904. }
  1905. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1906. /// 00c4 <shop id>.L
  1907. void clif_npcbuysell(map_session_data* sd, int id)
  1908. {
  1909. int fd;
  1910. nullpo_retv(sd);
  1911. fd=sd->fd;
  1912. WFIFOHEAD(fd, packet_len(0xc4));
  1913. WFIFOW(fd,0)=0xc4;
  1914. WFIFOL(fd,2)=id;
  1915. WFIFOSET(fd,packet_len(0xc4));
  1916. }
  1917. /// Presents list of items, that can be bought in an NPC shop.
  1918. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1919. void clif_buylist( map_session_data *sd, struct npc_data *nd ){
  1920. nullpo_retv( sd );
  1921. nullpo_retv( nd );
  1922. int fd = sd->fd;
  1923. if( !session_isActive( fd ) ){
  1924. return;
  1925. }
  1926. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1927. WFIFOHEAD( fd, len );
  1928. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1929. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1930. int count = 0;
  1931. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1932. int val = nd->u.shop.shop_item[i].value;
  1933. p->items[count].price = val;
  1934. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1935. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1936. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1937. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1938. std::shared_ptr<item_data> id = item_db.find(nd->u.shop.shop_item[i].nameid);
  1939. p->items[count].viewSprite = id->look;
  1940. p->items[count].location = pc_equippoint_sub( sd, id.get() );
  1941. #endif
  1942. count++;
  1943. }
  1944. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1945. WFIFOSET( fd, p->packetLength );
  1946. }
  1947. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1948. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1949. void clif_selllist(map_session_data *sd)
  1950. {
  1951. int fd,i,c=0,val;
  1952. struct npc_data *nd;
  1953. nullpo_retv(sd);
  1954. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1955. return;
  1956. fd=sd->fd;
  1957. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1958. WFIFOW(fd,0)=0xc7;
  1959. for( i = 0; i < MAX_INVENTORY; i++ )
  1960. {
  1961. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1962. {
  1963. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1964. continue;
  1965. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1966. val = 0;
  1967. else {
  1968. val = sd->inventory_data[i]->value_sell;
  1969. if( val < 0 )
  1970. continue;
  1971. }
  1972. WFIFOW(fd,4+c*10)=i+2;
  1973. WFIFOL(fd,6+c*10)=val;
  1974. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1975. c++;
  1976. }
  1977. }
  1978. WFIFOW(fd,2)=c*10+4;
  1979. WFIFOSET(fd,WFIFOW(fd,2));
  1980. }
  1981. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1982. /// 09d4
  1983. void clif_parse_NPCShopClosed(int fd, map_session_data *sd) {
  1984. // TODO: State tracking?
  1985. sd->npc_shopid = 0;
  1986. }
  1987. /**
  1988. * Presents list of items, that can be sold to a Market shop.
  1989. * @author: Ind and Yommy
  1990. **/
  1991. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1992. void clif_npc_market_open(map_session_data *sd, struct npc_data *nd) {
  1993. #if PACKETVER >= 20131223
  1994. nullpo_retv( sd );
  1995. nullpo_retv( nd );
  1996. if( sd->state.trading ){
  1997. return;
  1998. }
  1999. int fd = sd->fd;
  2000. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  2001. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  2002. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  2003. int count = 0;
  2004. for( int i = 0; i < nd->u.shop.count; i++ ){
  2005. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  2006. if( !item->nameid ){
  2007. continue;
  2008. }
  2009. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  2010. if( !id ){
  2011. continue;
  2012. }
  2013. // Out of stock
  2014. if( item->qty == 0 ){
  2015. continue;
  2016. }
  2017. p->list[count].nameid = client_nameid( item->nameid );
  2018. p->list[count].type = itemtype( item->nameid );
  2019. p->list[count].price = item->value;
  2020. p->list[count].qty = item->qty;
  2021. p->list[count].weight = id->weight;
  2022. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2023. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2024. #endif
  2025. count++;
  2026. }
  2027. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2028. WFIFOSET( fd, p->packetLength );
  2029. sd->state.trading = 1;
  2030. #endif
  2031. }
  2032. /// Closes the Market shop window.
  2033. void clif_parse_NPCMarketClosed(int fd, map_session_data *sd) {
  2034. nullpo_retv(sd);
  2035. sd->npc_shopid = 0;
  2036. sd->state.trading = 0;
  2037. }
  2038. /// Purchase item from Market shop.
  2039. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2040. void clif_npc_market_purchase_ack( map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2041. #if PACKETVER >= 20131223
  2042. nullpo_retv( sd );
  2043. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2044. nullpo_retv( nd );
  2045. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2046. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2047. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2048. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2049. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2050. #else
  2051. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2052. #endif
  2053. if( p->result ){
  2054. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2055. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2056. // Not found
  2057. if( j == nd->u.shop.count ){
  2058. continue;
  2059. }
  2060. p->list[count].ITID = client_nameid( list[i].nameid );
  2061. p->list[count].qty = list[i].qty;
  2062. p->list[count].price = nd->u.shop.shop_item[j].value;
  2063. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2064. count++;
  2065. }
  2066. }
  2067. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2068. #endif
  2069. }
  2070. /// Purchase item from Market shop.
  2071. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2072. void clif_parse_NPCMarketPurchase(int fd, map_session_data *sd) {
  2073. #if PACKETVER >= 20131223
  2074. nullpo_retv( sd );
  2075. if( !sd->npc_shopid ){
  2076. return;
  2077. }
  2078. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2079. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2080. std::vector<s_npc_buy_list> items;
  2081. items.reserve( count );
  2082. for( int i = 0; i < count; i++ ){
  2083. s_npc_buy_list item = {};
  2084. item.nameid = p->list[i].ITID;
  2085. item.qty = p->list[i].qty;
  2086. items.push_back( item );
  2087. }
  2088. e_purchase_result res = npc_buylist( sd, items );
  2089. clif_npc_market_purchase_ack( sd, res, items );
  2090. #endif
  2091. }
  2092. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2093. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2094. /// Client behavior (dialog window):
  2095. /// - disable mouse targeting
  2096. /// - open the dialog window
  2097. /// - set npcid of dialog window (0 by default)
  2098. /// - if set to clear on next mes, clear contents
  2099. /// - append this text
  2100. void clif_scriptmes( map_session_data& sd, uint32 npcid, const char *mes ){
  2101. struct PACKET_ZC_SAY_DIALOG* p = (struct PACKET_ZC_SAY_DIALOG*)packet_buffer;
  2102. int16 length = (int16)( strlen( mes ) + 1 );
  2103. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2104. p->PacketLength = sizeof( *p ) + length;
  2105. p->NpcID = npcid;
  2106. safestrncpy( p->message, mes, length );
  2107. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2108. }
  2109. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2110. /// 00b5 <npc id>.L
  2111. /// Client behavior (dialog window):
  2112. /// - disable mouse targeting
  2113. /// - open the dialog window
  2114. /// - add 'next' button
  2115. /// When 'next' is pressed:
  2116. /// - 00B9 <npcid of dialog window>.L
  2117. /// - set to clear on next mes
  2118. /// - remove 'next' button
  2119. void clif_scriptnext( map_session_data& sd, uint32 npcid ){
  2120. struct PACKET_ZC_WAIT_DIALOG p = {};
  2121. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2122. p.NpcID = npcid;
  2123. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2124. }
  2125. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2126. /// 00b6 <npc id>.L
  2127. /// Client behavior:
  2128. /// - if dialog window is open:
  2129. /// - remove 'next' button
  2130. /// - add 'close' button
  2131. /// - else:
  2132. /// - enable mouse targeting
  2133. /// - close the dialog window
  2134. /// - close the menu window
  2135. /// When 'close' is pressed:
  2136. /// - enable mouse targeting
  2137. /// - close the dialog window
  2138. /// - close the menu window
  2139. /// - 0146 <npcid of dialog window>.L
  2140. void clif_scriptclose(map_session_data *sd, int npcid)
  2141. {
  2142. int fd;
  2143. nullpo_retv(sd);
  2144. fd=sd->fd;
  2145. WFIFOHEAD(fd, packet_len(0xb6));
  2146. WFIFOW(fd,0)=0xb6;
  2147. WFIFOL(fd,2)=npcid;
  2148. WFIFOSET(fd,packet_len(0xb6));
  2149. }
  2150. /**
  2151. * Close script when player is idle
  2152. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2153. * @author [Ind/Hercules]
  2154. * @param sd : player pointer
  2155. * @param npcid : npc gid to close
  2156. */
  2157. void clif_scriptclear( map_session_data& sd, int npcid ){
  2158. struct PACKET_ZC_CLEAR_DIALOG p = {};
  2159. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2160. p.GID = npcid;
  2161. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2162. }
  2163. /*==========================================
  2164. *
  2165. *------------------------------------------*/
  2166. void clif_sendfakenpc(map_session_data *sd, int npcid) {
  2167. unsigned char *buf;
  2168. int fd = sd->fd;
  2169. sd->state.using_fake_npc = 1;
  2170. WFIFOHEAD(fd, packet_len(0x78));
  2171. buf = WFIFOP(fd,0);
  2172. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2173. WBUFW(buf,0)=0x78;
  2174. #if PACKETVER >= 20071106
  2175. WBUFB(buf,2) = 0; // object type
  2176. buf = WFIFOP(fd,1);
  2177. #endif
  2178. WBUFL(buf,2)=npcid;
  2179. WBUFW(buf,14)=111;
  2180. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2181. WBUFB(buf,49)=5;
  2182. WBUFB(buf,50)=5;
  2183. WFIFOSET(fd, packet_len(0x78));
  2184. }
  2185. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2186. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2187. /// Client behavior:
  2188. /// - disable mouse targeting
  2189. /// - close the menu window
  2190. /// - open the menu window
  2191. /// - add options to the menu (separated in the text by ":")
  2192. /// - set npcid of menu window
  2193. /// - if dialog window is open:
  2194. /// - remove 'next' button
  2195. /// When 'ok' is pressed:
  2196. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2197. /// - close the menu window
  2198. /// When 'cancel' is pressed:
  2199. /// - 00B8 <npcid of menu window>.L <-1>.B
  2200. /// - enable mouse targeting
  2201. /// - close a bunch of windows...
  2202. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2203. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2204. /// TODO investigate behavior of other windows [FlavioJS]
  2205. void clif_scriptmenu(map_session_data* sd, int npcid, const char* mes)
  2206. {
  2207. int fd = sd->fd;
  2208. int slen = strlen(mes) + 9;
  2209. struct block_list *bl = NULL;
  2210. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2211. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2212. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2213. clif_sendfakenpc(sd, npcid);
  2214. WFIFOHEAD(fd, slen);
  2215. WFIFOW(fd,0)=0xb7;
  2216. WFIFOW(fd,2)=slen;
  2217. WFIFOL(fd,4)=npcid;
  2218. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2219. WFIFOSET(fd,WFIFOW(fd,2));
  2220. }
  2221. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2222. /// 0142 <npc id>.L
  2223. /// Client behavior (inputnum window):
  2224. /// - if npcid exists in the client:
  2225. /// - open the inputnum window
  2226. /// - set npcid of inputnum window
  2227. /// When 'ok' is pressed:
  2228. /// - if inputnum window has text:
  2229. /// - if npcid exists in the client:
  2230. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2231. /// - close inputnum window
  2232. void clif_scriptinput(map_session_data *sd, int npcid)
  2233. {
  2234. int fd;
  2235. struct block_list *bl = NULL;
  2236. nullpo_retv(sd);
  2237. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2238. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2239. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2240. clif_sendfakenpc(sd, npcid);
  2241. fd=sd->fd;
  2242. WFIFOHEAD(fd, packet_len(0x142));
  2243. WFIFOW(fd,0)=0x142;
  2244. WFIFOL(fd,2)=npcid;
  2245. WFIFOSET(fd,packet_len(0x142));
  2246. }
  2247. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2248. /// 01d4 <npc id>.L
  2249. /// Client behavior (inputstr window):
  2250. /// - if npcid is 0 or npcid exists in the client:
  2251. /// - open the inputstr window
  2252. /// - set npcid of inputstr window
  2253. /// When 'ok' is pressed:
  2254. /// - if inputstr window has text and isn't an insult(manner.txt):
  2255. /// - if npcid is 0 or npcid exists in the client:
  2256. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2257. /// - close inputstr window
  2258. void clif_scriptinputstr(map_session_data *sd, int npcid)
  2259. {
  2260. int fd;
  2261. struct block_list *bl = NULL;
  2262. nullpo_retv(sd);
  2263. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2264. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2265. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2266. clif_sendfakenpc(sd, npcid);
  2267. fd=sd->fd;
  2268. WFIFOHEAD(fd, packet_len(0x1d4));
  2269. WFIFOW(fd,0)=0x1d4;
  2270. WFIFOL(fd,2)=npcid;
  2271. WFIFOSET(fd,packet_len(0x1d4));
  2272. }
  2273. /// Marks a position on client's minimap (ZC_COMPASS).
  2274. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2275. /// npc id:
  2276. /// is ignored in the client
  2277. /// type:
  2278. /// 0 = display mark for 15 seconds
  2279. /// 1 = display mark until dead or teleported
  2280. /// 2 = remove mark
  2281. /// color:
  2282. /// 0x00RRGGBB
  2283. void clif_viewpoint(map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2284. {
  2285. int fd;
  2286. nullpo_retv(sd);
  2287. fd=sd->fd;
  2288. WFIFOHEAD(fd, packet_len(0x144));
  2289. WFIFOW(fd,0)=0x144;
  2290. WFIFOL(fd,2)=npc_id;
  2291. WFIFOL(fd,6)=type;
  2292. WFIFOL(fd,10)=x;
  2293. WFIFOL(fd,14)=y;
  2294. WFIFOB(fd,18)=id;
  2295. WFIFOL(fd,19)=color;
  2296. WFIFOSET(fd,packet_len(0x144));
  2297. }
  2298. /// Displays an illustration image.
  2299. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2300. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2301. /// type:
  2302. /// 0 = bottom left corner
  2303. /// 1 = bottom middle
  2304. /// 2 = bottom right corner
  2305. /// 3 = middle of screen, inside a movable window
  2306. /// 4 = middle of screen, movable with a close button, chrome-less
  2307. /// 255 = clear all displayed cutins
  2308. void clif_cutin(map_session_data* sd, const char* image, int type)
  2309. {
  2310. int fd;
  2311. nullpo_retv(sd);
  2312. fd=sd->fd;
  2313. WFIFOHEAD(fd, packet_len(0x1b3));
  2314. WFIFOW(fd,0)=0x1b3;
  2315. strncpy(WFIFOCP(fd,2),image,64);
  2316. WFIFOB(fd,66)=type;
  2317. WFIFOSET(fd,packet_len(0x1b3));
  2318. }
  2319. /*==========================================
  2320. * Fills in card data from the given item and into the buffer. [Skotlex]
  2321. *------------------------------------------*/
  2322. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2323. nullpo_retv( buf );
  2324. // Blank data
  2325. if( item == nullptr ){
  2326. buf->card[0] = 0;
  2327. buf->card[1] = 0;
  2328. buf->card[2] = 0;
  2329. buf->card[3] = 0;
  2330. return;
  2331. }
  2332. // Pet eggs
  2333. if( item->card[0] == CARD0_PET ){
  2334. buf->card[0] = 0;
  2335. buf->card[1] = 0;
  2336. // Pet intimacy
  2337. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2338. buf->card[2] = item->card[3] >> 1;
  2339. // Pet renamed flag
  2340. buf->card[3] = item->card[3] & 1;
  2341. return;
  2342. }
  2343. // Forged/created items
  2344. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2345. buf->card[0] = item->card[0];
  2346. buf->card[1] = item->card[1];
  2347. buf->card[2] = item->card[2];
  2348. buf->card[3] = item->card[3];
  2349. return;
  2350. }
  2351. int i = 0, j;
  2352. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2353. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2354. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2355. }
  2356. // Normal items.
  2357. for( int k = 0; k < 4; k++, i++ ){
  2358. if( item->card[i] > 0 ){
  2359. buf->card[k] = client_nameid( item->card[i] );
  2360. }else{
  2361. buf->card[k] = 0;
  2362. }
  2363. }
  2364. }
  2365. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2366. /// A maximum of 5 random options can be supported.
  2367. static void clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item& it ){
  2368. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2369. if( it.option[i].id ){
  2370. buf[i].index = it.option[i].id; // OptIndex
  2371. buf[i].value = it.option[i].value; // Value
  2372. buf[i].param = it.option[i].param; // Param1
  2373. }else{
  2374. buf[i].index = 0;
  2375. buf[i].value = 0;
  2376. buf[i].param = 0;
  2377. }
  2378. }
  2379. #if MAX_ITEM_RDM_OPT < 5
  2380. for( ; i < 5; i++ ){
  2381. buf[i].index = 0; // OptIndex
  2382. buf[i].value = 0; // Value
  2383. buf[i].param = 0; // Param1
  2384. }
  2385. #endif
  2386. }
  2387. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2388. /// 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)
  2389. /// 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)
  2390. /// 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)
  2391. /// 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)
  2392. /// 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)
  2393. /// 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)
  2394. void clif_additem( map_session_data *sd, int n, int amount, unsigned char fail ){
  2395. nullpo_retv( sd );
  2396. int fd = sd->fd;
  2397. if( !session_isActive( fd ) ){
  2398. return;
  2399. }
  2400. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2401. if( fail ){
  2402. p = {};
  2403. }else{
  2404. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2405. return;
  2406. }
  2407. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2408. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2409. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2410. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2411. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2412. p.location = pc_equippoint(sd,n);
  2413. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2414. #if PACKETVER >= 20061218
  2415. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2416. #if PACKETVER >= 20071002
  2417. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2418. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2419. */
  2420. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2421. #if PACKETVER >= 20150226
  2422. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[n] );
  2423. #if PACKETVER >= 20160921
  2424. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2425. p.look = sd->inventory_data[n]->look;
  2426. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2427. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2428. #endif
  2429. #endif
  2430. #endif
  2431. #endif
  2432. #endif
  2433. }
  2434. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2435. p.Index = client_index( n );
  2436. p.count = amount;
  2437. p.result = fail;
  2438. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2439. }
  2440. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2441. /// 00af <index>.W <amount>.W
  2442. void clif_dropitem(map_session_data *sd,int n,int amount)
  2443. {
  2444. int fd;
  2445. nullpo_retv(sd);
  2446. fd=sd->fd;
  2447. WFIFOHEAD(fd, packet_len(0xaf));
  2448. WFIFOW(fd,0)=0xaf;
  2449. WFIFOW(fd,2)=n+2;
  2450. WFIFOW(fd,4)=amount;
  2451. WFIFOSET(fd,packet_len(0xaf));
  2452. }
  2453. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2454. /// 07fa <delete type>.W <index>.W <amount>.W
  2455. /// delete type:
  2456. /// 0 = Normal
  2457. /// 1 = Item used for a skill
  2458. /// 2 = Refine failed
  2459. /// 3 = Material changed
  2460. /// 4 = Moved to storage
  2461. /// 5 = Moved to cart
  2462. /// 6 = Item sold
  2463. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2464. void clif_delitem(map_session_data *sd,int n,int amount, short reason)
  2465. {
  2466. #if PACKETVER < 20091117
  2467. clif_dropitem(sd,n,amount);
  2468. #else
  2469. int fd;
  2470. nullpo_retv(sd);
  2471. fd=sd->fd;
  2472. WFIFOHEAD(fd, packet_len(0x7fa));
  2473. WFIFOW(fd,0)=0x7fa;
  2474. WFIFOW(fd,2)=reason;
  2475. WFIFOW(fd,4)=n+2;
  2476. WFIFOW(fd,6)=amount;
  2477. WFIFOSET(fd,packet_len(0x7fa));
  2478. #endif
  2479. }
  2480. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2481. nullpo_retv( p );
  2482. nullpo_retv( it );
  2483. nullpo_retv( id );
  2484. p->index = idx;
  2485. p->ITID = client_nameid( it->nameid );
  2486. p->type = itemtype( it->nameid );
  2487. #if PACKETVER < 20120925
  2488. p->IsIdentified = it->identify ? 1 : 0;
  2489. #endif
  2490. p->location = eqp_pos;
  2491. p->WearState = it->equip;
  2492. #if PACKETVER < 20120925
  2493. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2494. #endif
  2495. p->RefiningLevel = it->refine;
  2496. clif_addcards( &p->slot, it );
  2497. #if PACKETVER >= 20071002
  2498. p->HireExpireDate = it->expire_time;
  2499. #endif
  2500. #if PACKETVER >= 20080102
  2501. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2502. #endif
  2503. #if PACKETVER >= 20100629
  2504. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2505. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2506. #endif
  2507. #if PACKETVER >= 20120925
  2508. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2509. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2510. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2511. p->Flag.SpareBits = 0;
  2512. #endif
  2513. #if PACKETVER >= 20150226
  2514. clif_add_random_options( p->option_data, *it );
  2515. // Client ingores the value anyway and recalculates it
  2516. p->option_count = 0;
  2517. #endif
  2518. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2519. p->enchantgrade = it->enchantgrade;
  2520. #endif
  2521. }
  2522. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2523. nullpo_retv(p);
  2524. nullpo_retv(i);
  2525. nullpo_retv(id);
  2526. p->index = idx;
  2527. p->ITID = client_nameid( i->nameid );
  2528. p->type = itemtype( i->nameid );
  2529. #if PACKETVER < 20120925
  2530. p->IsIdentified = i->identify ? 1 : 0;
  2531. #endif
  2532. p->count = i->amount;
  2533. p->WearState = id->equip;
  2534. #if PACKETVER >= 5
  2535. clif_addcards( &p->slot, i );
  2536. #endif
  2537. #if PACKETVER >= 20080102
  2538. p->HireExpireDate = i->expire_time;
  2539. #endif
  2540. #if PACKETVER >= 20120925
  2541. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2542. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2543. p->Flag.SpareBits = 0;
  2544. #endif
  2545. }
  2546. static void clif_inventoryStart( map_session_data *sd, e_inventory_type type, const char *name ){
  2547. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2548. nullpo_retv(sd);
  2549. nullpo_retv(name);
  2550. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2551. memset(buf, 0, sizeof(buf));
  2552. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2553. p->packetType = HEADER_ZC_INVENTORY_START;
  2554. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2555. p->invType = type;
  2556. #endif
  2557. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2558. int strLen = (int)safestrnlen(name, 24) + 1;
  2559. if (strLen > 24)
  2560. strLen = 24;
  2561. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2562. p->packetLength = len;
  2563. safestrncpy(p->name, name, strLen);
  2564. #else
  2565. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2566. safestrncpy(p->name, name, NAME_LENGTH);
  2567. #endif
  2568. clif_send( p, len, &sd->bl, SELF );
  2569. #endif
  2570. }
  2571. static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
  2572. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2573. nullpo_retv(sd);
  2574. struct PACKET_ZC_INVENTORY_END p;
  2575. p.packetType = HEADER_ZC_INVENTORY_END;
  2576. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2577. p.invType = type;
  2578. #endif
  2579. p.flag = 0;
  2580. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2581. #endif
  2582. }
  2583. void clif_favorite_item(map_session_data* sd, unsigned short index);
  2584. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2585. void clif_inventorylist( map_session_data *sd ){
  2586. nullpo_retv( sd );
  2587. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2588. e_inventory_type type = INVTYPE_INVENTORY;
  2589. clif_inventoryStart( sd, type, "" );
  2590. #endif
  2591. static struct packet_itemlist_normal itemlist_normal;
  2592. static struct packet_itemlist_equip itemlist_equip;
  2593. int equip = 0;
  2594. int normal = 0;
  2595. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2596. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2597. continue;
  2598. }
  2599. // Non-stackable (Equippable)
  2600. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2601. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2602. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2603. itemlist_equip.PacketType = inventorylistequipType;
  2604. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2605. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2606. itemlist_equip.invType = type;
  2607. #endif
  2608. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2609. equip = 0;
  2610. }
  2611. // Stackable (Normal)
  2612. }else{
  2613. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2614. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2615. itemlist_normal.PacketType = inventorylistnormalType;
  2616. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2617. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2618. itemlist_normal.invType = type;
  2619. #endif
  2620. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2621. normal = 0;
  2622. }
  2623. }
  2624. }
  2625. if( normal ){
  2626. itemlist_normal.PacketType = inventorylistnormalType;
  2627. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2628. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2629. itemlist_normal.invType = type;
  2630. #endif
  2631. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2632. }
  2633. if( sd->equip_index[EQI_AMMO] >= 0 )
  2634. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2635. if( equip ) {
  2636. itemlist_equip.PacketType = inventorylistequipType;
  2637. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2638. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2639. itemlist_equip.invType = type;
  2640. #endif
  2641. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2642. }
  2643. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2644. clif_inventoryEnd( sd, type );
  2645. #endif
  2646. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2647. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2648. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2649. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2650. continue;
  2651. if ( sd->inventory.u.items_inventory[i].favorite )
  2652. clif_favorite_item(sd, i);
  2653. }
  2654. #endif
  2655. }
  2656. //Required when items break/get-repaired. Only sends equippable item list.
  2657. void clif_equiplist( map_session_data *sd ){
  2658. // TODO: implement again => only send equip part
  2659. clif_inventorylist( sd );
  2660. }
  2661. void clif_storagelist(map_session_data* sd, struct item* items, int items_length, const char *storename){
  2662. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2663. e_inventory_type type = INVTYPE_STORAGE;
  2664. clif_inventoryStart( sd, type, storename );
  2665. #endif
  2666. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2667. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2668. int equip = 0;
  2669. int normal = 0;
  2670. for( int i = 0; i < items_length; i++ ){
  2671. if( items[i].nameid == 0 ){
  2672. continue;
  2673. }
  2674. struct item_data* id = itemdb_search( items[i].nameid );
  2675. // Non-stackable (Equippable)
  2676. if( !itemdb_isstackable2( id ) ){
  2677. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2678. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2679. storage_itemlist_equip.PacketType = storageListEquipType;
  2680. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2681. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2682. storage_itemlist_equip.invType = type;
  2683. #elif PACKETVER >= 20120925
  2684. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2685. #endif
  2686. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2687. equip = 0;
  2688. }
  2689. // Stackable (Normal)
  2690. }else{
  2691. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2692. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2693. storage_itemlist_normal.PacketType = storageListNormalType;
  2694. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2695. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2696. storage_itemlist_normal.invType = type;
  2697. #elif PACKETVER >= 20120925
  2698. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2699. #endif
  2700. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2701. normal = 0;
  2702. }
  2703. }
  2704. }
  2705. if( 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. }
  2715. if( equip ) {
  2716. storage_itemlist_equip.PacketType = storageListEquipType;
  2717. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2718. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2719. storage_itemlist_equip.invType = type;
  2720. #elif PACKETVER >= 20120925
  2721. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2722. #endif
  2723. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2724. }
  2725. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2726. clif_inventoryEnd( sd, type );
  2727. #endif
  2728. }
  2729. void clif_cartlist( map_session_data *sd ){
  2730. nullpo_retv( sd );
  2731. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2732. e_inventory_type type = INVTYPE_CART;
  2733. clif_inventoryStart( sd, type, "" );
  2734. #endif
  2735. static struct packet_itemlist_normal itemlist_normal;
  2736. static struct packet_itemlist_equip itemlist_equip;
  2737. int normal = 0;
  2738. int equip = 0;
  2739. for( int i = 0; i < MAX_CART; i++ ){
  2740. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2741. continue;
  2742. }
  2743. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2744. // Non-stackable (Equippable)
  2745. if( !itemdb_isstackable2(id) ){
  2746. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2747. // Stackable (Normal)
  2748. }else{
  2749. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2750. }
  2751. }
  2752. if( normal ){
  2753. itemlist_normal.PacketType = cartlistnormalType;
  2754. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2755. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2756. itemlist_normal.invType = type;
  2757. #endif
  2758. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2759. }
  2760. if( equip ){
  2761. itemlist_equip.PacketType = cartlistequipType;
  2762. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2763. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2764. itemlist_equip.invType = type;
  2765. #endif
  2766. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2767. }
  2768. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2769. clif_inventoryEnd( sd, type );
  2770. #endif
  2771. }
  2772. /// Removes cart (ZC_CARTOFF).
  2773. /// 012b
  2774. /// Client behaviour:
  2775. /// Closes the cart storage and removes all it's items from memory.
  2776. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2777. void clif_clearcart(int fd)
  2778. {
  2779. WFIFOHEAD(fd, packet_len(0x12b));
  2780. WFIFOW(fd,0) = 0x12b;
  2781. WFIFOSET(fd, packet_len(0x12b));
  2782. }
  2783. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2784. /// 01eb <account id>.L <x>.W <y>.W
  2785. void clif_guild_xy(map_session_data *sd)
  2786. {
  2787. unsigned char buf[10];
  2788. nullpo_retv(sd);
  2789. WBUFW(buf,0)=0x1eb;
  2790. WBUFL(buf,2)=sd->status.account_id;
  2791. WBUFW(buf,6)=sd->bl.x;
  2792. WBUFW(buf,8)=sd->bl.y;
  2793. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2794. }
  2795. /*==========================================
  2796. * Sends x/y dot to a single fd. [Skotlex]
  2797. *------------------------------------------*/
  2798. void clif_guild_xy_single(int fd, map_session_data *sd)
  2799. {
  2800. if( sd->bg_id )
  2801. return;
  2802. WFIFOHEAD(fd,packet_len(0x1eb));
  2803. WFIFOW(fd,0)=0x1eb;
  2804. WFIFOL(fd,2)=sd->status.account_id;
  2805. WFIFOW(fd,6)=sd->bl.x;
  2806. WFIFOW(fd,8)=sd->bl.y;
  2807. WFIFOSET(fd,packet_len(0x1eb));
  2808. }
  2809. // Guild XY locators [Valaris]
  2810. void clif_guild_xy_remove(map_session_data *sd)
  2811. {
  2812. unsigned char buf[10];
  2813. nullpo_retv(sd);
  2814. WBUFW(buf,0)=0x1eb;
  2815. WBUFL(buf,2)=sd->status.account_id;
  2816. WBUFW(buf,6)=-1;
  2817. WBUFW(buf,8)=-1;
  2818. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2819. }
  2820. /*==========================================
  2821. *
  2822. *------------------------------------------*/
  2823. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2824. map_session_data* sd = va_arg( ap, map_session_data* );
  2825. map_session_data* tsd = BL_CAST( BL_PC, bl );
  2826. nullpo_ret(sd);
  2827. nullpo_ret(tsd);
  2828. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2829. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2830. }
  2831. return 0;
  2832. }
  2833. /*==========================================
  2834. * Server tells all players that are allowed to view HP bars
  2835. * and are nearby 'sd' that 'sd' hp bar was updated.
  2836. *------------------------------------------*/
  2837. static int clif_hpmeter(map_session_data *sd)
  2838. {
  2839. nullpo_ret(sd);
  2840. 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);
  2841. return 0;
  2842. }
  2843. /**
  2844. * Send HP bar update to others.
  2845. * @param sd: Player invoking update
  2846. */
  2847. void clif_update_hp(map_session_data &sd) {
  2848. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2849. clif_hpmeter(&sd);
  2850. if (!battle_config.party_hp_mode && sd.status.party_id)
  2851. clif_party_hp( sd );
  2852. if (sd.bg_id)
  2853. clif_bg_hp(&sd);
  2854. }
  2855. /// Notifies client of a character parameter change.
  2856. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2857. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2858. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2859. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2860. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2861. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2862. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2863. /// TODO: Extract individual packets.
  2864. /// FIXME: Packet lengths from packet_len(cmd)
  2865. void clif_updatestatus(map_session_data *sd,int type)
  2866. {
  2867. int fd,len=8;
  2868. nullpo_retv(sd);
  2869. fd=sd->fd;
  2870. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2871. return;
  2872. WFIFOHEAD(fd, 14);
  2873. WFIFOW(fd,0)=0xb0;
  2874. WFIFOW(fd,2)=type;
  2875. switch(type){
  2876. // 00b0
  2877. case SP_WEIGHT:
  2878. pc_updateweightstatus(sd);
  2879. WFIFOHEAD(fd,14);
  2880. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2881. WFIFOW(fd,2)=type;
  2882. WFIFOL(fd,4)=sd->weight;
  2883. break;
  2884. case SP_MAXWEIGHT:
  2885. WFIFOL(fd,4)=sd->max_weight;
  2886. break;
  2887. case SP_SPEED:
  2888. WFIFOL(fd,4)=sd->battle_status.speed;
  2889. break;
  2890. case SP_BASELEVEL:
  2891. WFIFOL(fd,4)=sd->status.base_level;
  2892. break;
  2893. case SP_JOBLEVEL:
  2894. WFIFOL(fd,4)=sd->status.job_level;
  2895. break;
  2896. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2897. WFIFOL(fd,4)=sd->status.karma;
  2898. break;
  2899. case SP_MANNER:
  2900. WFIFOL(fd,4)=sd->status.manner;
  2901. break;
  2902. case SP_STATUSPOINT:
  2903. WFIFOL(fd,4)=sd->status.status_point;
  2904. break;
  2905. case SP_SKILLPOINT:
  2906. WFIFOL(fd,4)=sd->status.skill_point;
  2907. break;
  2908. case SP_HIT:
  2909. WFIFOL(fd,4)=sd->battle_status.hit;
  2910. break;
  2911. case SP_FLEE1:
  2912. WFIFOL(fd,4)=sd->battle_status.flee;
  2913. break;
  2914. case SP_FLEE2:
  2915. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2916. break;
  2917. case SP_MAXHP:
  2918. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2919. break;
  2920. case SP_MAXSP:
  2921. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2922. break;
  2923. case SP_HP:
  2924. // On officials the HP never go below 1, even if you die [Lemongrass]
  2925. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2926. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2927. break;
  2928. case SP_SP:
  2929. WFIFOL(fd,4)=sd->battle_status.sp;
  2930. break;
  2931. case SP_ASPD:
  2932. WFIFOL(fd,4)=sd->battle_status.amotion;
  2933. break;
  2934. case SP_ATK1:
  2935. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2936. break;
  2937. case SP_DEF1:
  2938. WFIFOL(fd,4)=pc_leftside_def(sd);
  2939. break;
  2940. case SP_MDEF1:
  2941. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2942. break;
  2943. case SP_ATK2:
  2944. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2945. break;
  2946. case SP_DEF2:
  2947. WFIFOL(fd,4)=pc_rightside_def(sd);
  2948. break;
  2949. case SP_MDEF2: {
  2950. //negative check (in case you have something like Berserk active)
  2951. int mdef2 = pc_rightside_mdef(sd);
  2952. WFIFOL(fd,4)=
  2953. #ifndef RENEWAL
  2954. ( mdef2 < 0 ) ? 0 :
  2955. #endif
  2956. mdef2;
  2957. }
  2958. break;
  2959. case SP_CRITICAL:
  2960. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2961. break;
  2962. case SP_MATK1:
  2963. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2964. break;
  2965. case SP_MATK2:
  2966. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2967. break;
  2968. case SP_ZENY:
  2969. WFIFOW(fd,0)=0xb1;
  2970. WFIFOL(fd,4)=sd->status.zeny;
  2971. break;
  2972. #if PACKETVER >= 20170830
  2973. case SP_BASEEXP:
  2974. WFIFOW(fd,0)=0xacb;
  2975. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2976. len = packet_len(0xacb);
  2977. break;
  2978. case SP_JOBEXP:
  2979. WFIFOW(fd,0)=0xacb;
  2980. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2981. len = packet_len(0xacb);
  2982. break;
  2983. case SP_NEXTBASEEXP:
  2984. WFIFOW(fd,0)=0xacb;
  2985. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  2986. len = packet_len(0xacb);
  2987. break;
  2988. case SP_NEXTJOBEXP:
  2989. WFIFOW(fd,0)=0xacb;
  2990. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  2991. len = packet_len(0xacb);
  2992. break;
  2993. #else
  2994. case SP_BASEEXP:
  2995. WFIFOW(fd,0)=0xb1;
  2996. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  2997. break;
  2998. case SP_JOBEXP:
  2999. WFIFOW(fd,0)=0xb1;
  3000. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3001. break;
  3002. case SP_NEXTBASEEXP:
  3003. WFIFOW(fd,0)=0xb1;
  3004. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3005. break;
  3006. case SP_NEXTJOBEXP:
  3007. WFIFOW(fd,0)=0xb1;
  3008. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3009. break;
  3010. #endif
  3011. /**
  3012. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3013. **/
  3014. case SP_USTR:
  3015. case SP_UAGI:
  3016. case SP_UVIT:
  3017. case SP_UINT:
  3018. case SP_UDEX:
  3019. case SP_ULUK:
  3020. WFIFOW(fd,0)=0xbe;
  3021. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3022. len=5;
  3023. break;
  3024. /**
  3025. * Tells the client how far it is allowed to attack (weapon range)
  3026. **/
  3027. case SP_ATTACKRANGE:
  3028. WFIFOW(fd,0)=0x13a;
  3029. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3030. len=4;
  3031. break;
  3032. case SP_STR:
  3033. WFIFOW(fd,0)=0x141;
  3034. WFIFOL(fd,2)=type;
  3035. WFIFOL(fd,6)=sd->status.str;
  3036. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3037. len=14;
  3038. break;
  3039. case SP_AGI:
  3040. WFIFOW(fd,0)=0x141;
  3041. WFIFOL(fd,2)=type;
  3042. WFIFOL(fd,6)=sd->status.agi;
  3043. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3044. len=14;
  3045. break;
  3046. case SP_VIT:
  3047. WFIFOW(fd,0)=0x141;
  3048. WFIFOL(fd,2)=type;
  3049. WFIFOL(fd,6)=sd->status.vit;
  3050. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3051. len=14;
  3052. break;
  3053. case SP_INT:
  3054. WFIFOW(fd,0)=0x141;
  3055. WFIFOL(fd,2)=type;
  3056. WFIFOL(fd,6)=sd->status.int_;
  3057. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3058. len=14;
  3059. break;
  3060. case SP_DEX:
  3061. WFIFOW(fd,0)=0x141;
  3062. WFIFOL(fd,2)=type;
  3063. WFIFOL(fd,6)=sd->status.dex;
  3064. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3065. len=14;
  3066. break;
  3067. case SP_LUK:
  3068. WFIFOW(fd,0)=0x141;
  3069. WFIFOL(fd,2)=type;
  3070. WFIFOL(fd,6)=sd->status.luk;
  3071. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3072. len=14;
  3073. break;
  3074. case SP_CARTINFO:
  3075. WFIFOW(fd,0)=0x121;
  3076. WFIFOW(fd,2)=sd->cart_num;
  3077. WFIFOW(fd,4)=MAX_CART;
  3078. WFIFOL(fd,6)=sd->cart_weight;
  3079. WFIFOL(fd,10)=sd->cart_weight_max;
  3080. len=14;
  3081. break;
  3082. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3083. case SP_AP:
  3084. WFIFOL(fd, 4) = sd->battle_status.ap;
  3085. break;
  3086. case SP_TRAITPOINT:
  3087. WFIFOL(fd, 4) = sd->status.trait_point;
  3088. break;
  3089. case SP_MAXAP:
  3090. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3091. break;
  3092. case SP_POW:
  3093. WFIFOW(fd, 0) = 0x141;
  3094. WFIFOL(fd, 2) = type;
  3095. WFIFOL(fd, 6) = sd->status.pow;
  3096. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3097. len = 14;
  3098. break;
  3099. case SP_STA:
  3100. WFIFOW(fd, 0) = 0x141;
  3101. WFIFOL(fd, 2) = type;
  3102. WFIFOL(fd, 6) = sd->status.sta;
  3103. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3104. len = 14;
  3105. break;
  3106. case SP_WIS:
  3107. WFIFOW(fd, 0) = 0x141;
  3108. WFIFOL(fd, 2) = type;
  3109. WFIFOL(fd, 6) = sd->status.wis;
  3110. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3111. len = 14;
  3112. break;
  3113. case SP_SPL:
  3114. WFIFOW(fd, 0) = 0x141;
  3115. WFIFOL(fd, 2) = type;
  3116. WFIFOL(fd, 6) = sd->status.spl;
  3117. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3118. len = 14;
  3119. break;
  3120. case SP_CON:
  3121. WFIFOW(fd, 0) = 0x141;
  3122. WFIFOL(fd, 2) = type;
  3123. WFIFOL(fd, 6) = sd->status.con;
  3124. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3125. len = 14;
  3126. break;
  3127. case SP_CRT:
  3128. WFIFOW(fd, 0) = 0x141;
  3129. WFIFOL(fd, 2) = type;
  3130. WFIFOL(fd, 6) = sd->status.crt;
  3131. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3132. len = 14;
  3133. break;
  3134. case SP_UPOW:
  3135. case SP_USTA:
  3136. case SP_UWIS:
  3137. case SP_USPL:
  3138. case SP_UCON:
  3139. case SP_UCRT:
  3140. WFIFOW(fd, 0) = 0xbe;
  3141. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3142. len = 5;
  3143. break;
  3144. case SP_PATK:
  3145. WFIFOL(fd, 4) = sd->battle_status.patk;
  3146. break;
  3147. case SP_SMATK:
  3148. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3149. break;
  3150. case SP_RES:
  3151. WFIFOL(fd, 4) = sd->battle_status.res;
  3152. break;
  3153. case SP_MRES:
  3154. WFIFOL(fd, 4) = sd->battle_status.mres;
  3155. break;
  3156. case SP_HPLUS:
  3157. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3158. break;
  3159. case SP_CRATE:
  3160. WFIFOL(fd, 4) = sd->battle_status.crate;
  3161. break;
  3162. #else
  3163. case SP_AP:
  3164. case SP_TRAITPOINT:
  3165. case SP_MAXAP:
  3166. case SP_POW:
  3167. case SP_STA:
  3168. case SP_WIS:
  3169. case SP_SPL:
  3170. case SP_CON:
  3171. case SP_CRT:
  3172. case SP_UPOW:
  3173. case SP_USTA:
  3174. case SP_UWIS:
  3175. case SP_USPL:
  3176. case SP_UCON:
  3177. case SP_UCRT:
  3178. case SP_PATK:
  3179. case SP_SMATK:
  3180. case SP_RES:
  3181. case SP_MRES:
  3182. case SP_HPLUS:
  3183. case SP_CRATE:
  3184. // 4th job status are not supported by older clients
  3185. return;
  3186. #endif
  3187. default:
  3188. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3189. return;
  3190. }
  3191. WFIFOSET(fd,len);
  3192. // Additional update packets that should be sent right after
  3193. switch( type ){
  3194. case SP_BASELEVEL:
  3195. if( sd->status.party_id ){
  3196. struct party_data* p;
  3197. int i;
  3198. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3199. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3200. if( i < MAX_PARTY ){
  3201. p->party.member[i].lv = sd->status.base_level;
  3202. clif_party_job_and_level( *sd );
  3203. }
  3204. }
  3205. }
  3206. break;
  3207. case SP_HP:
  3208. clif_update_hp(*sd);
  3209. break;
  3210. }
  3211. }
  3212. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3213. /// 01ab <account id>.L <var id>.W <value>.L
  3214. void clif_changestatus(map_session_data* sd,int type,int val)
  3215. {
  3216. unsigned char buf[12];
  3217. nullpo_retv(sd);
  3218. WBUFW(buf,0)=0x1ab;
  3219. WBUFL(buf,2)=sd->bl.id;
  3220. WBUFW(buf,6)=type;
  3221. switch(type)
  3222. {
  3223. case SP_MANNER:
  3224. WBUFL(buf,8)=val;
  3225. break;
  3226. default:
  3227. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3228. return;
  3229. }
  3230. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3231. }
  3232. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3233. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3234. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3235. struct PACKET_ZC_SPRITE_CHANGE p;
  3236. p.packetType = sendLookType;
  3237. p.AID = id;
  3238. p.type = type;
  3239. p.val = val;
  3240. #if PACKETVER >= 4
  3241. p.val2 = val2;
  3242. #endif
  3243. clif_send( &p, sizeof( p ), bl, target );
  3244. }
  3245. /// Updates sprite/style properties of an object.
  3246. void clif_changelook(struct block_list *bl, int type, int val) {
  3247. map_session_data* sd;
  3248. status_change* sc;
  3249. struct view_data* vd;
  3250. enum send_target target = AREA;
  3251. int val2 = 0;
  3252. nullpo_retv(bl);
  3253. sd = BL_CAST(BL_PC, bl);
  3254. sc = status_get_sc(bl);
  3255. vd = status_get_viewdata(bl);
  3256. if( vd ) //temp hack to let Warp Portal change appearance
  3257. switch(type) {
  3258. case LOOK_WEAPON:
  3259. if (sd) {
  3260. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3261. val = vd->weapon;
  3262. }
  3263. else
  3264. vd->weapon = val;
  3265. break;
  3266. case LOOK_SHIELD:
  3267. if (sd) {
  3268. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3269. val = vd->shield;
  3270. }
  3271. else
  3272. vd->shield = val;
  3273. break;
  3274. case LOOK_BASE:
  3275. if (!sd)
  3276. break;
  3277. if ( val == JT_INVISIBLE )
  3278. return;
  3279. if (sd->sc.option&OPTION_COSTUME)
  3280. vd->weapon = vd->shield = 0;
  3281. if (!vd->cloth_color)
  3282. break;
  3283. if (sd) {
  3284. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3285. vd->cloth_color = 0;
  3286. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3287. vd->cloth_color = 0;
  3288. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3289. vd->cloth_color = 0;
  3290. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3291. vd->cloth_color = 0;
  3292. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3293. vd->cloth_color = 0;
  3294. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3295. vd->body_style = 0;
  3296. }
  3297. break;
  3298. case LOOK_HAIR:
  3299. vd->hair_style = val;
  3300. break;
  3301. case LOOK_HEAD_BOTTOM:
  3302. vd->head_bottom = val;
  3303. break;
  3304. case LOOK_HEAD_TOP:
  3305. vd->head_top = val;
  3306. break;
  3307. case LOOK_HEAD_MID:
  3308. vd->head_mid = val;
  3309. break;
  3310. case LOOK_HAIR_COLOR:
  3311. vd->hair_color = val;
  3312. break;
  3313. case LOOK_CLOTHES_COLOR:
  3314. if (val && sd) {
  3315. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3316. val = 0;
  3317. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3318. val = 0;
  3319. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3320. val = 0;
  3321. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3322. val = 0;
  3323. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3324. val = 0;
  3325. }
  3326. vd->cloth_color = val;
  3327. break;
  3328. case LOOK_SHOES:
  3329. #if PACKETVER > 3
  3330. if (sd) {
  3331. int n;
  3332. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3333. if(sd->inventory_data[n]->view_id > 0)
  3334. val = sd->inventory_data[n]->view_id;
  3335. else
  3336. val = sd->inventory.u.items_inventory[n].nameid;
  3337. } else
  3338. val = 0;
  3339. }
  3340. #endif
  3341. //Shoes? No packet uses this....
  3342. break;
  3343. case LOOK_BODY:
  3344. // unknown purpose
  3345. break;
  3346. case LOOK_ROBE:
  3347. #if PACKETVER < 20110111
  3348. return;
  3349. #else
  3350. vd->robe = val;
  3351. #endif
  3352. break;
  3353. case LOOK_BODY2:
  3354. #if PACKETVER < 20150513
  3355. return;
  3356. #else
  3357. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3358. val = 0;
  3359. vd->body_style = val;
  3360. #endif
  3361. break;
  3362. }
  3363. // prevent leaking the presence of GM-hidden objects
  3364. if( sc && sc->option&OPTION_INVISIBLE )
  3365. target = SELF;
  3366. #if PACKETVER < 4
  3367. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3368. #else
  3369. if (bl->type != BL_NPC) {
  3370. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3371. type = LOOK_WEAPON;
  3372. val = (vd ? vd->weapon : 0);
  3373. val2 = (vd ? vd->shield : 0);
  3374. }
  3375. if (disguised(bl)) {
  3376. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3377. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3378. } else
  3379. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3380. } else
  3381. unit_refresh(bl);
  3382. #endif
  3383. }
  3384. //Sends a change-base-look packet required for traps as they are triggered.
  3385. void clif_changetraplook(struct block_list *bl,int val) {
  3386. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3387. }
  3388. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3389. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3390. clif_sprite_change(bl, id, type, val, 0, target);
  3391. }
  3392. /// Character status (ZC_STATUS).
  3393. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3394. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3395. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3396. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3397. void clif_initialstatus(map_session_data *sd) {
  3398. int fd, mdef2;
  3399. unsigned char *buf;
  3400. nullpo_retv(sd);
  3401. fd=sd->fd;
  3402. WFIFOHEAD(fd, packet_len(0xbd));
  3403. buf = WFIFOP(fd,0);
  3404. WBUFW(buf,0) = 0xbd;
  3405. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3406. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3407. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3408. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3409. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3410. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3411. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3412. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3413. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3414. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3415. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3416. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3417. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3418. WBUFW(buf,16) = pc_leftside_atk(sd);
  3419. WBUFW(buf,18) = pc_rightside_atk(sd);
  3420. WBUFW(buf,20) = pc_rightside_matk(sd);
  3421. WBUFW(buf,22) = pc_leftside_matk(sd);
  3422. WBUFW(buf,24) = pc_leftside_def(sd);
  3423. WBUFW(buf,26) = pc_rightside_def(sd);
  3424. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3425. mdef2 = pc_rightside_mdef(sd);
  3426. WBUFW(buf,30) =
  3427. #ifndef RENEWAL
  3428. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3429. #endif
  3430. mdef2;
  3431. WBUFW(buf,32) = sd->battle_status.hit;
  3432. WBUFW(buf,34) = sd->battle_status.flee;
  3433. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3434. WBUFW(buf,38) = sd->battle_status.cri/10;
  3435. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3436. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3437. WFIFOSET(fd, packet_len(0xbd));
  3438. clif_updatestatus(sd, SP_STR);
  3439. clif_updatestatus(sd, SP_AGI);
  3440. clif_updatestatus(sd, SP_VIT);
  3441. clif_updatestatus(sd, SP_INT);
  3442. clif_updatestatus(sd, SP_DEX);
  3443. clif_updatestatus(sd, SP_LUK);
  3444. clif_updatestatus(sd, SP_ATTACKRANGE);
  3445. clif_updatestatus(sd, SP_ASPD);
  3446. #ifdef RENEWAL
  3447. clif_updatestatus(sd, SP_POW);
  3448. clif_updatestatus(sd, SP_STA);
  3449. clif_updatestatus(sd, SP_WIS);
  3450. clif_updatestatus(sd, SP_SPL);
  3451. clif_updatestatus(sd, SP_CON);
  3452. clif_updatestatus(sd, SP_CRT);
  3453. clif_updatestatus(sd, SP_PATK);
  3454. clif_updatestatus(sd, SP_SMATK);
  3455. clif_updatestatus(sd, SP_RES);
  3456. clif_updatestatus(sd, SP_MRES);
  3457. clif_updatestatus(sd, SP_HPLUS);
  3458. clif_updatestatus(sd, SP_CRATE);
  3459. clif_updatestatus(sd, SP_TRAITPOINT);
  3460. clif_updatestatus(sd, SP_AP);
  3461. clif_updatestatus(sd, SP_MAXAP);
  3462. clif_updatestatus(sd, SP_UPOW);
  3463. clif_updatestatus(sd, SP_USTA);
  3464. clif_updatestatus(sd, SP_UWIS);
  3465. clif_updatestatus(sd, SP_USPL);
  3466. clif_updatestatus(sd, SP_UCON);
  3467. clif_updatestatus(sd, SP_UCRT);
  3468. #endif
  3469. }
  3470. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3471. /// 013c <index>.W
  3472. void clif_arrowequip(map_session_data *sd,int val) {
  3473. int fd;
  3474. nullpo_retv(sd);
  3475. #if PACKETVER >= 20121128
  3476. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3477. #endif
  3478. fd=sd->fd;
  3479. WFIFOHEAD(fd, packet_len(0x013c));
  3480. WFIFOW(fd,0) = 0x013c;
  3481. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3482. WFIFOSET(fd, packet_len(0x013c));
  3483. }
  3484. /// Ammunition action message (ZC_ACTION_FAILURE).
  3485. /// 013b <type>.W
  3486. /// type:
  3487. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3488. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3489. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3490. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3491. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3492. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3493. void clif_arrow_fail(map_session_data *sd,int type) {
  3494. int fd;
  3495. nullpo_retv(sd);
  3496. fd=sd->fd;
  3497. WFIFOHEAD(fd, packet_len(0x013b));
  3498. WFIFOW(fd,0) = 0x013b;
  3499. WFIFOW(fd,2) = type;
  3500. WFIFOSET(fd, packet_len(0x013b));
  3501. }
  3502. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3503. /// 01ad <packet len>.W { <name id>.W }*
  3504. void clif_arrow_create_list( map_session_data *sd ){
  3505. nullpo_retv( sd );
  3506. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3507. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3508. int count = 0;
  3509. for (const auto &it : skill_arrow_db) {
  3510. t_itemid nameid = it.second->nameid;
  3511. if( !item_db.exists( nameid ) ){
  3512. continue;
  3513. }
  3514. int index = pc_search_inventory( sd, nameid );
  3515. if( index < 0 ){
  3516. continue;
  3517. }
  3518. if( sd->inventory.u.items_inventory[index].equip ){
  3519. continue;
  3520. }
  3521. if( !sd->inventory.u.items_inventory[index].identify ){
  3522. continue;
  3523. }
  3524. p->items[count].itemId = client_nameid( nameid );
  3525. count++;
  3526. }
  3527. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3528. clif_send( p, p->packetLength, &sd->bl, SELF );
  3529. if( count > 0 ){
  3530. sd->menuskill_id = AC_MAKINGARROW;
  3531. sd->menuskill_val = count;
  3532. }
  3533. }
  3534. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3535. /// 00bc <status id>.W <result>.B <value>.B
  3536. /// status id:
  3537. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3538. /// result:
  3539. /// 0 = failure
  3540. /// 1 = success
  3541. void clif_statusupack(map_session_data *sd,int type,int ok,int val) {
  3542. int fd;
  3543. nullpo_retv(sd);
  3544. fd=sd->fd;
  3545. WFIFOHEAD(fd, packet_len(0xbc));
  3546. WFIFOW(fd,0) = 0xbc;
  3547. WFIFOW(fd,2) = type;
  3548. WFIFOB(fd,4) = ok;
  3549. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3550. WFIFOSET(fd, packet_len(0xbc));
  3551. }
  3552. /// Notifies the client about the result of a request to equip an item.
  3553. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3554. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3555. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3556. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3557. /// @ok: //inversed forv2 v5
  3558. /// 0 = failure
  3559. /// 1 = success
  3560. /// 2 = failure due to low level
  3561. void clif_equipitemack( map_session_data& sd, uint8 flag, int index, int pos ){
  3562. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3563. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3564. p.index = client_index( index );
  3565. p.wearLocation = pos;
  3566. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3567. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3568. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3569. }else{
  3570. p.wItemSpriteNumber = 0;
  3571. }
  3572. #endif
  3573. p.result = flag;
  3574. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3575. }
  3576. /// Notifies the client about the result of a request to take off an item.
  3577. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3578. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3579. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3580. /// @ok : //inversed for v2 v5
  3581. /// 0 = failure
  3582. /// 1 = success
  3583. void clif_unequipitemack(map_session_data *sd,int n,int pos,int ok)
  3584. {
  3585. int fd, header, offs = 0;
  3586. #if PACKETVER >= 20130000
  3587. header = 0x99a;
  3588. ok = ok ? 0 : 1;
  3589. #elif PACKETVER >= 20110824
  3590. header = 0x8d1;
  3591. ok = ok ? 0 : 1;
  3592. #else
  3593. header = 0xac;
  3594. #endif
  3595. nullpo_retv(sd);
  3596. fd=sd->fd;
  3597. WFIFOHEAD(fd, packet_len(header));
  3598. WFIFOW(fd,offs+0) = header;
  3599. WFIFOW(fd,offs+2) = n+2;
  3600. #if PACKETVER >= 20130000
  3601. WFIFOL(fd,offs+4) = pos;
  3602. offs += 2;
  3603. #else
  3604. WFIFOW(fd,offs+4) = pos;
  3605. #endif
  3606. WFIFOB(fd,offs+6) = ok;
  3607. WFIFOSET(fd, packet_len(header));
  3608. }
  3609. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3610. /// 019b <id>.L <effect id>.L
  3611. /// effect id:
  3612. /// 0 = base level up
  3613. /// 1 = job level up
  3614. /// 2 = refine failure
  3615. /// 3 = refine success
  3616. /// 4 = game over
  3617. /// 5 = pharmacy success
  3618. /// 6 = pharmacy failure
  3619. /// 7 = base level up (super novice)
  3620. /// 8 = job level up (super novice)
  3621. /// 9 = base level up (taekwon)
  3622. void clif_misceffect(struct block_list* bl,int type)
  3623. {
  3624. unsigned char buf[32];
  3625. nullpo_retv(bl);
  3626. WBUFW(buf,0) = 0x19b;
  3627. WBUFL(buf,2) = bl->id;
  3628. WBUFL(buf,6) = type;
  3629. clif_send(buf,packet_len(0x19b),bl,AREA);
  3630. }
  3631. /// Notifies clients in the area of a state change.
  3632. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3633. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3634. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3635. nullpo_retv( bl );
  3636. status_change* sc = status_get_sc( bl );
  3637. //How can an option change if there's no sc?
  3638. if( sc == nullptr ){
  3639. return;
  3640. }
  3641. map_session_data* sd = BL_CAST( BL_PC, bl );
  3642. struct PACKET_ZC_STATE_CHANGE p;
  3643. p.packetType = HEADER_ZC_STATE_CHANGE;
  3644. p.AID = bl->id;
  3645. p.bodyState = sc->opt1;
  3646. p.healthState = sc->opt2;
  3647. p.effectState = sc->option;
  3648. p.isPKModeON = sd ? sd->status.karma : false;
  3649. if( target == nullptr ){
  3650. if( disguised( bl ) ){
  3651. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3652. p.AID = disguised_bl_id( p.AID );
  3653. clif_send( &p, sizeof( p ), bl, SELF );
  3654. p.AID = disguised_bl_id( p.AID );
  3655. p.effectState = OPTION_INVISIBLE;
  3656. clif_send( &p, sizeof( p ), bl, SELF );
  3657. }else{
  3658. clif_send( &p, sizeof( p ), bl, AREA );
  3659. }
  3660. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3661. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3662. if( sc->getSCE(SC_PROVOKE) ){
  3663. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3664. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3665. }
  3666. }else{
  3667. if( disguised( bl ) ){
  3668. p.AID = disguised_bl_id( p.AID );
  3669. clif_send( &p, sizeof( p ), target, SELF );
  3670. p.AID = disguised_bl_id( p.AID );
  3671. p.effectState = OPTION_INVISIBLE;
  3672. clif_send( &p, sizeof( p ), target, SELF );
  3673. }else{
  3674. clif_send( &p, sizeof( p ), target, SELF );
  3675. }
  3676. }
  3677. }
  3678. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3679. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3680. void clif_changeoption2(struct block_list* bl)
  3681. {
  3682. unsigned char buf[20];
  3683. status_change *sc;
  3684. sc = status_get_sc(bl);
  3685. if (!sc) return; //How can an option change if there's no sc?
  3686. WBUFW(buf,0) = 0x28a;
  3687. WBUFL(buf,2) = bl->id;
  3688. WBUFL(buf,6) = sc->option;
  3689. WBUFL(buf,10) = clif_setlevel(bl);
  3690. WBUFL(buf,14) = sc->opt3;
  3691. if(disguised(bl)) {
  3692. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3693. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3694. clif_send(buf,packet_len(0x28a),bl,SELF);
  3695. WBUFL(buf,2) = bl->id;
  3696. WBUFL(buf,6) = OPTION_INVISIBLE;
  3697. clif_send(buf,packet_len(0x28a),bl,SELF);
  3698. } else
  3699. clif_send(buf,packet_len(0x28a),bl,AREA);
  3700. }
  3701. /// Notifies the client about the result of an item use request.
  3702. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3703. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3704. void clif_useitemack( map_session_data *sd, int index, int amount, bool ok ){
  3705. nullpo_retv( sd );
  3706. int fd = sd->fd;
  3707. if( !session_isActive( fd ) ){
  3708. return;
  3709. }
  3710. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3711. return;
  3712. }
  3713. struct PACKET_ZC_USE_ITEM_ACK p;
  3714. p.packetType = useItemAckType;
  3715. p.index = index + 2;
  3716. #if PACKETVER > 3
  3717. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3718. p.AID = sd->bl.id;
  3719. #endif
  3720. p.amount = amount;
  3721. p.result = ok;
  3722. if( !ok ){
  3723. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3724. }else{
  3725. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3726. }
  3727. }
  3728. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3729. /// 00d6 <flag>.B
  3730. /// flag:
  3731. /// 0 = Room has been successfully created (opens chat room)
  3732. /// 1 = Room limit exceeded
  3733. /// 2 = Same room already exists
  3734. void clif_createchat(map_session_data* sd, int flag)
  3735. {
  3736. int fd;
  3737. nullpo_retv(sd);
  3738. fd = sd->fd;
  3739. WFIFOHEAD(fd,packet_len(0xd6));
  3740. WFIFOW(fd,0) = 0xd6;
  3741. WFIFOB(fd,2) = flag;
  3742. WFIFOSET(fd,packet_len(0xd6));
  3743. }
  3744. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3745. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3746. /// type:
  3747. /// 0 = private (password protected)
  3748. /// 1 = public
  3749. /// 2 = arena (npc waiting room)
  3750. /// 3 = PK zone (non-clickable)
  3751. void clif_dispchat(struct chat_data* cd, int fd)
  3752. {
  3753. unsigned char buf[128];
  3754. uint8 type;
  3755. if( cd == NULL || cd->owner == NULL )
  3756. return;
  3757. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3758. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3759. : 1;
  3760. WBUFW(buf, 0) = 0xd7;
  3761. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3762. WBUFL(buf, 4) = cd->owner->id;
  3763. WBUFL(buf, 8) = cd->bl.id;
  3764. WBUFW(buf,12) = cd->limit;
  3765. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3766. WBUFB(buf,16) = type;
  3767. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3768. if( session_isActive(fd) ) {
  3769. WFIFOHEAD(fd,WBUFW(buf,2));
  3770. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3771. WFIFOSET(fd,WBUFW(buf,2));
  3772. } else {
  3773. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3774. }
  3775. }
  3776. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3777. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3778. /// type:
  3779. /// 0 = private (password protected)
  3780. /// 1 = public
  3781. /// 2 = arena (npc waiting room)
  3782. /// 3 = PK zone (non-clickable)
  3783. void clif_changechatstatus(struct chat_data* cd)
  3784. {
  3785. unsigned char buf[128];
  3786. uint8 type;
  3787. if( cd == NULL || cd->usersd[0] == NULL )
  3788. return;
  3789. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3790. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3791. : 1;
  3792. WBUFW(buf, 0) = 0xdf;
  3793. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3794. WBUFL(buf, 4) = cd->owner->id;
  3795. WBUFL(buf, 8) = cd->bl.id;
  3796. WBUFW(buf,12) = cd->limit;
  3797. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3798. WBUFB(buf,16) = type;
  3799. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3800. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3801. }
  3802. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3803. /// 00d8 <chat id>.L
  3804. void clif_clearchat(struct chat_data *cd,int fd)
  3805. {
  3806. unsigned char buf[32];
  3807. nullpo_retv(cd);
  3808. WBUFW(buf,0) = 0xd8;
  3809. WBUFL(buf,2) = cd->bl.id;
  3810. if( session_isActive(fd) ) {
  3811. WFIFOHEAD(fd,packet_len(0xd8));
  3812. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3813. WFIFOSET(fd,packet_len(0xd8));
  3814. } else {
  3815. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3816. }
  3817. }
  3818. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3819. /// 00da <result>.B
  3820. /// result:
  3821. /// 0 = room full
  3822. /// 1 = wrong password
  3823. /// 2 = kicked
  3824. /// 3 = success (no message)
  3825. /// 4 = no enough zeny
  3826. /// 5 = too low level
  3827. /// 6 = too high level
  3828. /// 7 = unsuitable job class
  3829. void clif_joinchatfail(map_session_data *sd,int flag)
  3830. {
  3831. int fd;
  3832. nullpo_retv(sd);
  3833. fd = sd->fd;
  3834. WFIFOHEAD(fd,packet_len(0xda));
  3835. WFIFOW(fd,0) = 0xda;
  3836. WFIFOB(fd,2) = flag;
  3837. WFIFOSET(fd,packet_len(0xda));
  3838. }
  3839. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3840. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3841. /// role:
  3842. /// 0 = owner (menu)
  3843. /// 1 = normal
  3844. void clif_joinchatok(map_session_data *sd,struct chat_data* cd)
  3845. {
  3846. int fd;
  3847. int i,t;
  3848. nullpo_retv(sd);
  3849. nullpo_retv(cd);
  3850. fd = sd->fd;
  3851. if (!session_isActive(fd))
  3852. return;
  3853. t = (int)(cd->owner->type == BL_NPC);
  3854. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3855. WFIFOW(fd, 0) = 0xdb;
  3856. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3857. WFIFOL(fd, 4) = cd->bl.id;
  3858. if(cd->owner->type == BL_NPC){
  3859. WFIFOL(fd, 30) = 1;
  3860. WFIFOL(fd, 8) = 0;
  3861. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3862. for (i = 0; i < cd->users; i++) {
  3863. WFIFOL(fd, 8+(i+1)*28) = 1;
  3864. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3865. }
  3866. }else{
  3867. for (i = 0; i < cd->users; i++) {
  3868. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3869. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3870. }
  3871. }
  3872. WFIFOSET(fd, WFIFOW(fd, 2));
  3873. }
  3874. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3875. /// 00dc <users>.W <name>.24B
  3876. void clif_addchat(struct chat_data* cd,map_session_data *sd)
  3877. {
  3878. unsigned char buf[29];
  3879. nullpo_retv(sd);
  3880. nullpo_retv(cd);
  3881. WBUFW(buf, 0) = 0xdc;
  3882. WBUFW(buf, 2) = cd->users;
  3883. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3884. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3885. }
  3886. /// Announce the new owner (ZC_ROLE_CHANGE).
  3887. /// 00e1 <role>.L <nick>.24B
  3888. /// role:
  3889. /// 0 = owner (menu)
  3890. /// 1 = normal
  3891. void clif_changechatowner(struct chat_data* cd, map_session_data* sd)
  3892. {
  3893. unsigned char buf[64];
  3894. nullpo_retv(sd);
  3895. nullpo_retv(cd);
  3896. WBUFW(buf, 0) = 0xe1;
  3897. WBUFL(buf, 2) = 1;
  3898. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3899. WBUFW(buf,30) = 0xe1;
  3900. WBUFL(buf,32) = 0;
  3901. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3902. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3903. }
  3904. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3905. /// 00dd <users>.W <nick>.24B <flag>.B
  3906. /// flag:
  3907. /// 0 = left
  3908. /// 1 = kicked
  3909. void clif_leavechat(struct chat_data* cd, map_session_data* sd, bool flag)
  3910. {
  3911. unsigned char buf[32];
  3912. nullpo_retv(sd);
  3913. nullpo_retv(cd);
  3914. WBUFW(buf, 0) = 0xdd;
  3915. WBUFW(buf, 2) = cd->users-1;
  3916. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3917. WBUFB(buf,28) = flag;
  3918. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3919. }
  3920. /// Opens a trade request window from char 'name'.
  3921. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3922. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3923. void clif_traderequest(map_session_data* sd, const char* name)
  3924. {
  3925. int fd = sd->fd;
  3926. #if PACKETVER < 6
  3927. WFIFOHEAD(fd,packet_len(0xe5));
  3928. WFIFOW(fd,0) = 0xe5;
  3929. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3930. WFIFOSET(fd,packet_len(0xe5));
  3931. #else
  3932. map_session_data* tsd = map_id2sd(sd->trade_partner);
  3933. if( !tsd ) return;
  3934. WFIFOHEAD(fd,packet_len(0x1f4));
  3935. WFIFOW(fd,0) = 0x1f4;
  3936. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3937. WFIFOL(fd,26) = tsd->status.char_id;
  3938. WFIFOW(fd,30) = tsd->status.base_level;
  3939. WFIFOSET(fd,packet_len(0x1f4));
  3940. #endif
  3941. }
  3942. /// Reply to a trade-request.
  3943. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3944. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3945. /// result:
  3946. /// 0 = Char is too far
  3947. /// 1 = Character does not exist
  3948. /// 2 = Trade failed
  3949. /// 3 = Accept
  3950. /// 4 = Cancel
  3951. /// 5 = Busy
  3952. void clif_tradestart(map_session_data* sd, uint8 type)
  3953. {
  3954. int fd = sd->fd;
  3955. map_session_data* tsd = map_id2sd(sd->trade_partner);
  3956. if( PACKETVER < 6 || !tsd ) {
  3957. WFIFOHEAD(fd,packet_len(0xe7));
  3958. WFIFOW(fd,0) = 0xe7;
  3959. WFIFOB(fd,2) = type;
  3960. WFIFOSET(fd,packet_len(0xe7));
  3961. } else {
  3962. WFIFOHEAD(fd,packet_len(0x1f5));
  3963. WFIFOW(fd,0) = 0x1f5;
  3964. WFIFOB(fd,2) = type;
  3965. WFIFOL(fd,3) = tsd->status.char_id;
  3966. WFIFOW(fd,7) = tsd->status.base_level;
  3967. WFIFOSET(fd,packet_len(0x1f5));
  3968. }
  3969. }
  3970. /// Notifies the client about an item from other player in current trade.
  3971. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3972. /// 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)
  3973. /// 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)
  3974. void clif_tradeadditem( map_session_data* sd, map_session_data* tsd, int index, int amount ){
  3975. nullpo_retv( sd );
  3976. nullpo_retv( tsd );
  3977. int fd = tsd->fd;
  3978. if( !session_isActive( fd ) ){
  3979. return;
  3980. }
  3981. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3982. if( index ){
  3983. index = server_index( index );
  3984. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3985. return;
  3986. }
  3987. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3988. #if PACKETVER >= 20100223
  3989. p.itemType = sd->inventory_data[index]->type;
  3990. #endif
  3991. p.identified = sd->inventory.u.items_inventory[index].identify;
  3992. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3993. p.refine = sd->inventory.u.items_inventory[index].refine;
  3994. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3995. #if PACKETVER >= 20150226
  3996. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[index] );
  3997. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3998. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  3999. p.look = sd->inventory_data[index]->look;
  4000. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4001. #endif
  4002. #endif
  4003. }else{
  4004. p = {};
  4005. }
  4006. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4007. p.amount = amount;
  4008. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4009. }
  4010. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4011. /// 00ea <index>.W <result>.B
  4012. /// result:
  4013. /// 0 = success
  4014. /// 1 = overweight
  4015. /// 2 = trade canceled
  4016. void clif_tradeitemok(map_session_data& sd, int index, e_exitem_add_result result)
  4017. {
  4018. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4019. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4020. p.index = client_index(index);
  4021. p.result = static_cast<uint8>(result);
  4022. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4023. }
  4024. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4025. /// 00ec <who>.B
  4026. /// who:
  4027. /// 0 = self
  4028. /// 1 = other player
  4029. void clif_tradedeal_lock(map_session_data* sd, int fail)
  4030. {
  4031. int fd;
  4032. nullpo_retv(sd);
  4033. fd = sd->fd;
  4034. WFIFOHEAD(fd,packet_len(0xec));
  4035. WFIFOW(fd,0) = 0xec;
  4036. WFIFOB(fd,2) = fail;
  4037. WFIFOSET(fd,packet_len(0xec));
  4038. }
  4039. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4040. /// 00ee
  4041. void clif_tradecancelled(map_session_data* sd)
  4042. {
  4043. int fd;
  4044. nullpo_retv(sd);
  4045. fd = sd->fd;
  4046. WFIFOHEAD(fd,packet_len(0xee));
  4047. WFIFOW(fd,0) = 0xee;
  4048. WFIFOSET(fd,packet_len(0xee));
  4049. }
  4050. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4051. /// 00f0 <result>.B
  4052. /// result:
  4053. /// 0 = success
  4054. /// 1 = failure
  4055. void clif_tradecompleted(map_session_data* sd, int fail)
  4056. {
  4057. int fd;
  4058. nullpo_retv(sd);
  4059. fd = sd->fd;
  4060. WFIFOHEAD(fd,packet_len(0xf0));
  4061. WFIFOW(fd,0) = 0xf0;
  4062. WFIFOB(fd,2) = fail;
  4063. WFIFOSET(fd,packet_len(0xf0));
  4064. }
  4065. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4066. /// 00f1
  4067. /// NOTE: Unknown purpose. Items are not removed until the window is
  4068. /// refreshed (ex. by putting another item in there).
  4069. void clif_tradeundo(map_session_data* sd)
  4070. {
  4071. int fd = sd->fd;
  4072. WFIFOHEAD(fd,packet_len(0xf1));
  4073. WFIFOW(fd,0) = 0xf1;
  4074. WFIFOSET(fd,packet_len(0xf1));
  4075. }
  4076. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4077. /// 00f2 <current count>.W <max count>.W
  4078. void clif_updatestorageamount(map_session_data* sd, int amount, int max_amount)
  4079. {
  4080. int fd;
  4081. nullpo_retv(sd);
  4082. fd=sd->fd;
  4083. WFIFOHEAD(fd,packet_len(0xf2));
  4084. WFIFOW(fd,0) = 0xf2;
  4085. WFIFOW(fd,2) = amount;
  4086. WFIFOW(fd,4) = max_amount;
  4087. WFIFOSET(fd,packet_len(0xf2));
  4088. }
  4089. /// Notifies the client of an item being added to the storage.
  4090. /// 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)
  4091. /// 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)
  4092. /// 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)
  4093. void clif_storageitemadded( map_session_data* sd, struct item* i, int index, int amount ){
  4094. nullpo_retv( sd );
  4095. nullpo_retv( i );
  4096. int fd = sd->fd;
  4097. if( !session_isActive( fd ) ){
  4098. return;
  4099. }
  4100. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4101. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4102. p.index = client_storage_index( index ); // index
  4103. p.amount = amount; // amount
  4104. p.itemId = client_nameid( i->nameid ); // id
  4105. #if PACKETVER >= 5
  4106. p.itemType = itemtype( i->nameid ); //type
  4107. #endif
  4108. p.identified = i->identify; //identify flag
  4109. p.damaged = i->attribute; // attribute
  4110. p.refine = i->refine; //refine
  4111. clif_addcards( &p.slot, i );
  4112. #if PACKETVER >= 20150226
  4113. clif_add_random_options( p.option_data, *i );
  4114. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4115. p.enchantgrade = i->enchantgrade;
  4116. #endif
  4117. #endif
  4118. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4119. }
  4120. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4121. /// 00f6 <index>.W <amount>.L
  4122. void clif_storageitemremoved(map_session_data* sd, int index, int amount)
  4123. {
  4124. int fd;
  4125. nullpo_retv(sd);
  4126. fd=sd->fd;
  4127. WFIFOHEAD(fd,packet_len(0xf6));
  4128. WFIFOW(fd,0)=0xf6; // Storage item removed
  4129. WFIFOW(fd,2)=client_storage_index(index);
  4130. WFIFOL(fd,4)=amount;
  4131. WFIFOSET(fd,packet_len(0xf6));
  4132. }
  4133. /// Closes storage (ZC_CLOSE_STORE).
  4134. /// 00f8
  4135. void clif_storageclose(map_session_data* sd)
  4136. {
  4137. int fd;
  4138. nullpo_retv(sd);
  4139. fd=sd->fd;
  4140. WFIFOHEAD(fd,packet_len(0xf8));
  4141. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4142. WFIFOSET(fd,packet_len(0xf8));
  4143. }
  4144. /// Notifies clients in an area of a player's souls.
  4145. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4146. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4147. /// 0b73 <id>.L <amount>.W
  4148. void clif_soulball( map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4149. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4150. struct PACKET_ZC_SOULENERGY p = {};
  4151. p.PacketType = HEADER_ZC_SOULENERGY;
  4152. #else
  4153. struct PACKET_ZC_SPIRITS p = {};
  4154. p.PacketType = HEADER_ZC_SPIRITS;
  4155. #endif
  4156. p.AID = sd->bl.id;
  4157. p.num = sd->soulball;
  4158. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4159. }
  4160. /*==========================================
  4161. * Server tells 'sd' player client the abouts of 'dstsd' player
  4162. *------------------------------------------*/
  4163. static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
  4164. {
  4165. struct block_list *d_bl;
  4166. int i;
  4167. if( dstsd->chatID ) {
  4168. struct chat_data *cd = NULL;
  4169. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4170. clif_dispchat(cd,sd->fd);
  4171. } else if( dstsd->state.vending )
  4172. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4173. else if( dstsd->state.buyingstore )
  4174. clif_buyingstore_entry( *dstsd, &sd->bl );
  4175. if(dstsd->spiritball > 0)
  4176. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4177. if (dstsd->sc.getSCE(SC_MILLENNIUMSHIELD))
  4178. clif_millenniumshield_single(sd->fd, dstsd);
  4179. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4180. clif_spiritcharm_single(sd->fd, dstsd);
  4181. if (dstsd->soulball > 0)
  4182. clif_soulball( dstsd, &sd->bl, SELF );
  4183. if (dstsd->servantball > 0)
  4184. clif_servantball( *dstsd, &sd->bl, SELF );
  4185. if (dstsd->abyssball > 0)
  4186. clif_abyssball( *dstsd, &sd->bl, SELF );
  4187. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4188. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4189. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4190. )
  4191. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4192. // display link (sd - dstsd) to sd
  4193. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4194. if( i < MAX_DEVOTION )
  4195. clif_devotion(&sd->bl, sd);
  4196. // display links (dstsd - devotees) to sd
  4197. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4198. if( i < MAX_DEVOTION )
  4199. clif_devotion(&dstsd->bl, sd);
  4200. // display link (dstsd - crusader) to sd
  4201. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != NULL )
  4202. clif_devotion(d_bl, sd);
  4203. }
  4204. void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
  4205. struct unit_data *ud;
  4206. struct view_data *vd;
  4207. bool option = false;
  4208. unsigned int option_val = 0;
  4209. vd = status_get_viewdata(bl);
  4210. if (!vd || vd->class_ == JT_INVISIBLE)
  4211. return;
  4212. // Hide NPC from Maya Purple card
  4213. if (clif_npc_mayapurple(bl))
  4214. return;
  4215. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4216. // Do not send anything
  4217. return;
  4218. }
  4219. ud = unit_bl2ud(bl);
  4220. if( ud && ud->walktimer != INVALID_TIMER ){
  4221. clif_set_unit_walking( bl, sd, ud, SELF );
  4222. }else{
  4223. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4224. }
  4225. if (vd->cloth_color)
  4226. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4227. if (vd->body_style)
  4228. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4229. switch (bl->type)
  4230. {
  4231. case BL_PC:
  4232. {
  4233. TBL_PC* tsd = (TBL_PC*)bl;
  4234. clif_getareachar_pc(sd, tsd);
  4235. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4236. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4237. else if(tsd->state.size==SZ_MEDIUM)
  4238. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4239. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4240. clif_sendbgemblem_single(sd->fd,tsd);
  4241. if ( tsd->status.robe )
  4242. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4243. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4244. clif_hat_effects(sd,bl,SELF);
  4245. }
  4246. break;
  4247. case BL_MER: // Devotion Effects
  4248. if( ((TBL_MER*)bl)->devotion_flag )
  4249. clif_devotion(bl, sd);
  4250. break;
  4251. case BL_NPC:
  4252. {
  4253. TBL_NPC* nd = (TBL_NPC*)bl;
  4254. if( nd->chat_id )
  4255. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4256. if( nd->size == SZ_BIG )
  4257. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4258. else if( nd->size == SZ_MEDIUM )
  4259. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4260. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4261. clif_progressbar_npc(nd, sd);
  4262. }
  4263. break;
  4264. case BL_MOB:
  4265. {
  4266. TBL_MOB* md = (TBL_MOB*)bl;
  4267. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4268. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4269. else if(md->special_state.size==SZ_MEDIUM)
  4270. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4271. #if PACKETVER >= 20120404
  4272. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4273. int i;
  4274. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4275. if( md->dmglog[i].id == sd->status.char_id )
  4276. clif_monster_hp_bar(md, sd->fd);
  4277. }
  4278. #endif
  4279. }
  4280. break;
  4281. case BL_PET:
  4282. if (vd->head_bottom)
  4283. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4284. break;
  4285. }
  4286. }
  4287. //Modifies the type of damage according to status changes [Skotlex]
  4288. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4289. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4290. {
  4291. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4292. }
  4293. /*==========================================
  4294. * Estimates walk delay based on the damage criteria. [Skotlex]
  4295. *------------------------------------------*/
  4296. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4297. {
  4298. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4299. return 0;
  4300. if (bl->type == BL_PC) {
  4301. if (battle_config.pc_walk_delay_rate != 100)
  4302. delay = delay*battle_config.pc_walk_delay_rate/100;
  4303. } else
  4304. if (battle_config.walk_delay_rate != 100)
  4305. delay = delay*battle_config.walk_delay_rate/100;
  4306. if (div_ > 1) //Multi-hit skills mean higher delays.
  4307. delay += battle_config.multihit_delay*(div_-1);
  4308. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4309. }
  4310. /*========================================== [Playtester]
  4311. * Returns hallucination damage the client displays
  4312. *------------------------------------------*/
  4313. static int clif_hallucination_damage()
  4314. {
  4315. int digit = rnd() % 5 + 1;
  4316. switch (digit)
  4317. {
  4318. case 1:
  4319. return (rnd() % 10);
  4320. case 2:
  4321. return (rnd() % 100);
  4322. case 3:
  4323. return (rnd() % 1000);
  4324. case 4:
  4325. return (rnd() % 10000);
  4326. }
  4327. return (rnd() % 32767);
  4328. }
  4329. /// Sends a 'damage' packet (src performs action on dst)
  4330. /// 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)
  4331. /// 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)
  4332. /// 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)
  4333. /// type:
  4334. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4335. /// 1 = pick up item
  4336. /// 2 = sit down
  4337. /// 3 = stand up
  4338. /// 4 = damage (endure)
  4339. /// 5 = (splash?)
  4340. /// 6 = (skill?)
  4341. /// 7 = (repeat damage?)
  4342. /// 8 = multi-hit damage
  4343. /// 9 = multi-hit damage (endure)
  4344. /// 10 = critical hit
  4345. /// 11 = lucky dodge
  4346. /// 12 = (touch skill?)
  4347. /// 13 = multi-hit critical
  4348. 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)
  4349. {
  4350. unsigned char buf[34];
  4351. status_change *sc;
  4352. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4353. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4354. #if PACKETVER < 20071113
  4355. const int cmd = 0x8a;
  4356. int offset = 0;
  4357. #elif PACKETVER < 20131223
  4358. const int cmd = 0x2e1;
  4359. int offset = 2;
  4360. #else
  4361. const int cmd = 0x8c8;
  4362. int offset = 3;
  4363. #endif
  4364. nullpo_ret(src);
  4365. nullpo_ret(dst);
  4366. if (type != DMG_MULTI_HIT_CRITICAL)
  4367. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4368. sc = status_get_sc(dst);
  4369. if(sc && sc->count) {
  4370. if(sc->getSCE(SC_HALLUCINATION)) {
  4371. damage = clif_hallucination_damage();
  4372. if(damage2) damage2 = clif_hallucination_damage();
  4373. }
  4374. }
  4375. WBUFW(buf,0) = cmd;
  4376. WBUFL(buf,2) = src->id;
  4377. WBUFL(buf,6) = dst->id;
  4378. WBUFL(buf,10) = client_tick(tick);
  4379. WBUFL(buf,14) = sdelay;
  4380. WBUFL(buf,18) = ddelay;
  4381. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4382. #if PACKETVER < 20071113
  4383. WBUFW(buf,22) = damage ? div : 0;
  4384. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4385. #else
  4386. WBUFL(buf, 22) = damage ? div : 0;
  4387. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4388. #endif
  4389. } else {
  4390. #if PACKETVER < 20071113
  4391. WBUFW(buf,22) = min(damage, INT16_MAX);
  4392. WBUFW(buf,27+offset) = damage2;
  4393. #else
  4394. WBUFL(buf,22) = damage;
  4395. WBUFL(buf,27+offset) = damage2;
  4396. #endif
  4397. }
  4398. #if PACKETVER >= 20131223
  4399. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4400. #endif
  4401. WBUFW(buf,24+offset) = div;
  4402. WBUFB(buf,26+offset) = type;
  4403. if(disguised(dst)) {
  4404. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4405. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4406. clif_send(buf, packet_len(cmd), dst, SELF);
  4407. } else
  4408. clif_send(buf, packet_len(cmd), dst, AREA);
  4409. if(disguised(src)) {
  4410. WBUFL(buf,2) = disguised_bl_id( src->id );
  4411. if (disguised(dst))
  4412. WBUFL(buf,6) = dst->id;
  4413. #if PACKETVER < 20071113
  4414. if(damage > 0) WBUFW(buf,22) = -1;
  4415. if(damage2 > 0) WBUFW(buf,27) = -1;
  4416. #else
  4417. if(damage > 0) WBUFL(buf,22) = -1;
  4418. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4419. #endif
  4420. clif_send(buf,packet_len(cmd),src,SELF);
  4421. }
  4422. if(src == dst) {
  4423. unit_setdir(src, unit_getdir(src));
  4424. }
  4425. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4426. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4427. //Return adjusted can't walk delay for further processing.
  4428. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4429. }
  4430. /*==========================================
  4431. * src picks up dst
  4432. *------------------------------------------*/
  4433. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4434. {
  4435. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4436. unsigned char buf[32];
  4437. nullpo_retv(src);
  4438. nullpo_retv(dst);
  4439. WBUFW(buf, 0) = 0x8a;
  4440. WBUFL(buf, 2) = src->id;
  4441. WBUFL(buf, 6) = dst->id;
  4442. WBUFB(buf,26) = 1;
  4443. clif_send(buf, packet_len(0x8a), src, AREA);
  4444. }
  4445. /*==========================================
  4446. * inform clients in area that `bl` is sitting
  4447. *------------------------------------------*/
  4448. void clif_sitting(struct block_list* bl)
  4449. {
  4450. unsigned char buf[32];
  4451. nullpo_retv(bl);
  4452. WBUFW(buf, 0) = 0x8a;
  4453. WBUFL(buf, 2) = bl->id;
  4454. WBUFB(buf,26) = 2;
  4455. clif_send(buf, packet_len(0x8a), bl, AREA);
  4456. if(disguised(bl)) {
  4457. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4458. clif_send(buf, packet_len(0x8a), bl, SELF);
  4459. }
  4460. }
  4461. /*==========================================
  4462. * inform clients in area that `bl` is standing
  4463. *------------------------------------------*/
  4464. void clif_standing(struct block_list* bl)
  4465. {
  4466. unsigned char buf[32];
  4467. nullpo_retv(bl);
  4468. WBUFW(buf, 0) = 0x8a;
  4469. WBUFL(buf, 2) = bl->id;
  4470. WBUFB(buf,26) = 3;
  4471. clif_send(buf, packet_len(0x8a), bl, AREA);
  4472. if(disguised(bl)) {
  4473. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4474. clif_send(buf, packet_len(0x8a), bl, SELF);
  4475. }
  4476. }
  4477. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4478. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4479. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4480. {
  4481. unsigned char buf[32];
  4482. WBUFW(buf,0) = 0x192;
  4483. WBUFW(buf,2) = x;
  4484. WBUFW(buf,4) = y;
  4485. WBUFW(buf,6) = type;
  4486. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4487. if( session_isActive(fd) )
  4488. {
  4489. WFIFOHEAD(fd,packet_len(0x192));
  4490. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4491. WFIFOSET(fd,packet_len(0x192));
  4492. }
  4493. else
  4494. {
  4495. struct block_list dummy_bl;
  4496. dummy_bl.type = BL_NUL;
  4497. dummy_bl.x = x;
  4498. dummy_bl.y = y;
  4499. dummy_bl.m = m;
  4500. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4501. }
  4502. }
  4503. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4504. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4505. void clif_getareachar_item( map_session_data* sd,struct flooritem_data* fitem ){
  4506. nullpo_retv( sd );
  4507. nullpo_retv( fitem );
  4508. struct PACKET_ZC_ITEM_ENTRY p;
  4509. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4510. p.AID = fitem->bl.id;
  4511. p.itemId = client_nameid( fitem->item.nameid );
  4512. p.identify = fitem->item.identify;
  4513. p.x = fitem->bl.x;
  4514. p.y = fitem->bl.y;
  4515. p.amount = fitem->item.amount;
  4516. p.subX = fitem->subx;
  4517. p.subY = fitem->suby;
  4518. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4519. }
  4520. /// Notifes client about Graffiti
  4521. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4522. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4523. unsigned char buf[128];
  4524. nullpo_retv(bl);
  4525. nullpo_retv(unit);
  4526. WBUFW(buf, 0) = 0x1c9;
  4527. WBUFL(buf, 2) = unit->bl.id;
  4528. WBUFL(buf, 6) = unit->group->src_id;
  4529. WBUFW(buf,10) = unit->bl.x;
  4530. WBUFW(buf,12) = unit->bl.y;
  4531. WBUFB(buf,14) = unit->group->unit_id;
  4532. WBUFB(buf,15) = 1;
  4533. WBUFB(buf,16) = 1;
  4534. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4535. clif_send(buf,packet_len(0x1c9),bl,target);
  4536. }
  4537. /// Notifies the client of a skill unit.
  4538. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4539. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4540. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4541. /// 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)
  4542. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4543. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4544. unsigned char buf[128];
  4545. nullpo_retv(bl);
  4546. nullpo_retv(unit);
  4547. if (bl->type == BL_PC)
  4548. fd = ((TBL_PC*)bl)->fd;
  4549. if (unit->group->state.guildaura)
  4550. return;
  4551. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4552. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4553. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4554. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4555. else
  4556. unit_id = unit->group->unit_id;
  4557. if (!visible)
  4558. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4559. #if PACKETVER >= 3
  4560. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4561. clif_graffiti(bl, unit, target);
  4562. return;
  4563. }
  4564. #endif
  4565. #if PACKETVER <= 20120702
  4566. header = 0x011f;
  4567. //#if PACKETVER < 20110718
  4568. // header = 0x011f;
  4569. //#elif PACKETVER < 20121212
  4570. // header = 0x08c7;
  4571. #elif PACKETVER < 20130731
  4572. header = 0x099f;
  4573. #else
  4574. header = 0x09ca;
  4575. #endif
  4576. len = packet_len(header);
  4577. WBUFW(buf,pos) = header;
  4578. if (header != 0x011f) {
  4579. WBUFW(buf, pos+2) = len;
  4580. pos += 2;
  4581. }
  4582. WBUFL(buf,pos+2) = unit->bl.id;
  4583. WBUFL(buf,pos+6) = unit->group->src_id;
  4584. WBUFW(buf,pos+10) = unit->bl.x;
  4585. WBUFW(buf,pos+12) = unit->bl.y;
  4586. switch (header) {
  4587. case 0x011f:
  4588. WBUFB(buf,pos+14) = unit_id;
  4589. WBUFB(buf,pos+15) = visible;
  4590. break;
  4591. case 0x08c7:
  4592. WBUFB(buf,pos+14) = unit_id;
  4593. WBUFW(buf,pos+15) = unit->range;
  4594. WBUFB(buf,pos+17) = visible;
  4595. break;
  4596. case 0x099f:
  4597. WBUFL(buf,pos+14) = unit_id;
  4598. WBUFW(buf,pos+18) = unit->range;
  4599. WBUFB(buf,pos+20) = visible;
  4600. break;
  4601. case 0x09ca:
  4602. WBUFL(buf,pos+14) = unit_id;
  4603. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4604. WBUFB(buf,pos+19) = visible;
  4605. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4606. break;
  4607. }
  4608. clif_send(buf, len, bl, target);
  4609. if (unit->group->skill_id == WZ_ICEWALL)
  4610. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4611. }
  4612. /// 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)
  4613. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4614. unsigned char buf[128];
  4615. nullpo_retv(bl);
  4616. WBUFW(buf, 0) = 0x09ca;
  4617. WBUFW(buf, 2) = packet_len(0x09ca);
  4618. WBUFL(buf, 4) = 1000;
  4619. WBUFL(buf, 8) = 2000;
  4620. WBUFW(buf, 12) = x;
  4621. WBUFW(buf, 14) = y;
  4622. WBUFL(buf, 16) = unit_id;
  4623. WBUFB(buf, 20) = (unsigned char)range;
  4624. WBUFB(buf, 21) = 1;
  4625. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4626. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4627. }
  4628. /*==========================================
  4629. * Server tells client to remove unit of id 'unit->bl.id'
  4630. *------------------------------------------*/
  4631. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4632. {
  4633. nullpo_retv(unit);
  4634. WFIFOHEAD(fd,packet_len(0x120));
  4635. WFIFOW(fd, 0)=0x120;
  4636. WFIFOL(fd, 2)=unit->bl.id;
  4637. WFIFOSET(fd,packet_len(0x120));
  4638. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4639. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4640. }
  4641. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4642. /// 0120 <id>.L
  4643. void clif_skill_delunit(struct skill_unit *unit)
  4644. {
  4645. unsigned char buf[16];
  4646. nullpo_retv(unit);
  4647. WBUFW(buf, 0)=0x120;
  4648. WBUFL(buf, 2)=unit->bl.id;
  4649. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4650. }
  4651. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4652. /// 01ac <id>.L
  4653. /// Only affects units with class [139,153] client-side.
  4654. void clif_skillunit_update(struct block_list* bl)
  4655. {
  4656. unsigned char buf[6];
  4657. nullpo_retv(bl);
  4658. WBUFW(buf,0) = 0x1ac;
  4659. WBUFL(buf,2) = bl->id;
  4660. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4661. }
  4662. /*==========================================
  4663. *
  4664. *------------------------------------------*/
  4665. static int clif_getareachar(struct block_list* bl,va_list ap)
  4666. {
  4667. map_session_data *sd;
  4668. nullpo_ret(bl);
  4669. sd=va_arg(ap,map_session_data*);
  4670. if (!clif_session_isValid(sd))
  4671. return 0;
  4672. switch(bl->type){
  4673. case BL_ITEM:
  4674. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4675. break;
  4676. case BL_SKILL:
  4677. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4678. break;
  4679. default:
  4680. if(&sd->bl == bl)
  4681. break;
  4682. clif_getareachar_unit(sd,bl);
  4683. break;
  4684. }
  4685. return 0;
  4686. }
  4687. /*==========================================
  4688. * tbl has gone out of view-size of bl
  4689. *------------------------------------------*/
  4690. int clif_outsight(struct block_list *bl,va_list ap)
  4691. {
  4692. struct block_list *tbl;
  4693. struct view_data *vd;
  4694. TBL_PC *sd, *tsd;
  4695. tbl=va_arg(ap,struct block_list*);
  4696. if(bl == tbl) return 0;
  4697. sd = BL_CAST(BL_PC, bl);
  4698. tsd = BL_CAST(BL_PC, tbl);
  4699. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4700. nullpo_ret(bl);
  4701. switch(bl->type){
  4702. case BL_PC:
  4703. if(sd->vd.class_ != JT_INVISIBLE)
  4704. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4705. if(sd->chatID){
  4706. struct chat_data *cd;
  4707. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4708. if(cd->usersd[0]==sd)
  4709. clif_dispchat(cd,tsd->fd);
  4710. }
  4711. if(sd->state.vending)
  4712. clif_closevendingboard(bl,tsd->fd);
  4713. if(sd->state.buyingstore)
  4714. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4715. break;
  4716. case BL_ITEM:
  4717. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4718. break;
  4719. case BL_SKILL:
  4720. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4721. break;
  4722. case BL_NPC:
  4723. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4724. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4725. break;
  4726. default:
  4727. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4728. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4729. break;
  4730. }
  4731. }
  4732. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4733. nullpo_ret(tbl);
  4734. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4735. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4736. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4737. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4738. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4739. }
  4740. return 0;
  4741. }
  4742. /*==========================================
  4743. * tbl has come into view of bl
  4744. *------------------------------------------*/
  4745. int clif_insight(struct block_list *bl,va_list ap)
  4746. {
  4747. struct block_list *tbl;
  4748. TBL_PC *sd, *tsd;
  4749. tbl=va_arg(ap,struct block_list*);
  4750. if (bl == tbl) return 0;
  4751. sd = BL_CAST(BL_PC, bl);
  4752. tsd = BL_CAST(BL_PC, tbl);
  4753. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4754. switch(bl->type){
  4755. case BL_ITEM:
  4756. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4757. break;
  4758. case BL_SKILL:
  4759. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4760. break;
  4761. default:
  4762. clif_getareachar_unit(tsd,bl);
  4763. break;
  4764. }
  4765. }
  4766. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4767. clif_getareachar_unit(sd,tbl);
  4768. }
  4769. return 0;
  4770. }
  4771. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4772. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4773. void clif_skillinfoblock(map_session_data *sd)
  4774. {
  4775. int fd;
  4776. int i,len,id;
  4777. nullpo_retv(sd);
  4778. fd = sd->fd;
  4779. if (!session_isActive(fd))
  4780. return;
  4781. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4782. WFIFOW(fd,0) = 0x10f;
  4783. bool haveCallPartnerSkill = false;
  4784. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4785. {
  4786. if( (id = sd->status.skill[i].id) != 0 )
  4787. {
  4788. // workaround for bugreport:5348
  4789. if (len + 37 > 8192)
  4790. break;
  4791. // skip WE_CALLPARTNER and send it in special way
  4792. if (id == WE_CALLPARTNER) {
  4793. haveCallPartnerSkill = true;
  4794. continue;
  4795. }
  4796. WFIFOW(fd,len) = id;
  4797. WFIFOL(fd,len+2) = skill_get_inf(id);
  4798. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4799. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4800. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4801. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4802. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4803. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4804. else
  4805. WFIFOB(fd,len+36) = 0;
  4806. len += 37;
  4807. }
  4808. }
  4809. WFIFOW(fd,2)=len;
  4810. WFIFOSET(fd,len);
  4811. // adoption fix
  4812. if (haveCallPartnerSkill) {
  4813. clif_addskill(sd, WE_CALLPARTNER);
  4814. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4815. }
  4816. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4817. for ( ; i < MAX_SKILL; i++)
  4818. {
  4819. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4820. {
  4821. clif_addskill(sd, id);
  4822. clif_skillinfo(sd, id, 0);
  4823. }
  4824. }
  4825. }
  4826. /**
  4827. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4828. **/
  4829. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4830. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4831. void clif_addskill(map_session_data *sd, int skill_id)
  4832. {
  4833. nullpo_retv(sd);
  4834. int fd = sd->fd;
  4835. uint16 idx = skill_get_index(skill_id);
  4836. if (!session_isActive(fd) || !idx)
  4837. return;
  4838. if( sd->status.skill[idx].id <= 0 )
  4839. return;
  4840. WFIFOHEAD(fd, packet_len(0x111));
  4841. WFIFOW(fd,0) = 0x111;
  4842. WFIFOW(fd,2) = skill_id;
  4843. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4844. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4845. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4846. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4847. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4848. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4849. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4850. else
  4851. WFIFOB(fd,38) = 0;
  4852. WFIFOSET(fd,packet_len(0x111));
  4853. }
  4854. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4855. /// 0441 <skill id>.W
  4856. void clif_deleteskill(map_session_data *sd, int skill_id)
  4857. {
  4858. #if PACKETVER >= 20081217
  4859. nullpo_retv(sd);
  4860. int fd = sd->fd;
  4861. uint16 idx = skill_get_index(skill_id);
  4862. if (!session_isActive(fd) || !idx)
  4863. return;
  4864. WFIFOHEAD(fd,packet_len(0x441));
  4865. WFIFOW(fd,0) = 0x441;
  4866. WFIFOW(fd,2) = skill_id;
  4867. WFIFOSET(fd,packet_len(0x441));
  4868. #endif
  4869. clif_skillinfoblock(sd);
  4870. }
  4871. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4872. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4873. void clif_skillup(map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4874. nullpo_retv(sd);
  4875. int fd = sd->fd;
  4876. uint16 idx = skill_get_index(skill_id);
  4877. if (!session_isActive(fd) || !idx)
  4878. return;
  4879. WFIFOHEAD(fd, packet_len(0x10e));
  4880. WFIFOW(fd, 0) = 0x10e;
  4881. WFIFOW(fd, 2) = skill_id;
  4882. WFIFOW(fd, 4) = lv;
  4883. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4884. WFIFOW(fd, 8) = range;
  4885. WFIFOB(fd, 10) = upgradable;
  4886. WFIFOSET(fd, packet_len(0x10e));
  4887. }
  4888. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4889. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4890. void clif_skillinfo(map_session_data *sd,int skill_id, int inf)
  4891. {
  4892. nullpo_retv(sd);
  4893. const int fd = sd->fd;
  4894. uint16 idx = skill_get_index(skill_id);
  4895. if (!session_isActive(fd) || !idx)
  4896. return;
  4897. WFIFOHEAD(fd,packet_len(0x7e1));
  4898. WFIFOW(fd,0) = 0x7e1;
  4899. WFIFOW(fd,2) = skill_id;
  4900. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4901. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4902. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4903. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4904. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4905. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4906. else
  4907. WFIFOB(fd,14) = 0;
  4908. WFIFOSET(fd,packet_len(0x7e1));
  4909. }
  4910. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4911. #if PACKETVER >= 20151223
  4912. if( !battle_config.show_skill_scale ){
  4913. return;
  4914. }
  4915. struct PACKET_ZC_SKILL_SCALE p;
  4916. p.PacketType = skillscale;
  4917. p.AID = src_id;
  4918. p.skill_id = skill_id;
  4919. p.skill_lv = skill_lv;
  4920. p.x = x;
  4921. p.y = y;
  4922. p.casttime = casttime;
  4923. if( disguised( bl ) ){
  4924. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4925. p.AID = disguised_bl_id( bl->id );
  4926. clif_send( &p, sizeof( p ), bl, SELF );
  4927. }else{
  4928. clif_send( &p, sizeof( p ), bl, AREA );
  4929. }
  4930. #endif
  4931. }
  4932. /// Notifies clients in area, that an object is about to use a skill.
  4933. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4934. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4935. /// property:
  4936. /// 0 = Yellow cast aura
  4937. /// 1 = Water elemental cast aura
  4938. /// 2 = Earth elemental cast aura
  4939. /// 3 = Fire elemental cast aura
  4940. /// 4 = Wind elemental cast aura
  4941. /// 5 = Poison elemental cast aura
  4942. /// 6 = Holy elemental cast aura
  4943. /// ? = like 0
  4944. /// is disposable:
  4945. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4946. /// 1 = no text
  4947. 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)
  4948. {
  4949. #if PACKETVER < 20091124
  4950. const int cmd = 0x13e;
  4951. #else
  4952. const int cmd = 0x7fb;
  4953. #endif
  4954. unsigned char buf[32];
  4955. WBUFW(buf,0) = cmd;
  4956. WBUFL(buf,2) = src_id;
  4957. WBUFL(buf,6) = dst_id;
  4958. WBUFW(buf,10) = dst_x;
  4959. WBUFW(buf,12) = dst_y;
  4960. WBUFW(buf,14) = skill_id;
  4961. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4962. WBUFL(buf,20) = casttime;
  4963. #if PACKETVER >= 20091124
  4964. WBUFB(buf,24) = 0; // isDisposable
  4965. #endif
  4966. if (disguised(bl)) {
  4967. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4968. WBUFL(buf,2) = disguised_bl_id( src_id );
  4969. clif_send(buf,packet_len(cmd), bl, SELF);
  4970. } else
  4971. clif_send(buf,packet_len(cmd), bl, AREA);
  4972. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4973. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4974. }
  4975. }
  4976. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4977. /// 01b9 <id>.L
  4978. void clif_skillcastcancel(struct block_list* bl)
  4979. {
  4980. unsigned char buf[16];
  4981. nullpo_retv(bl);
  4982. WBUFW(buf,0) = 0x1b9;
  4983. WBUFL(buf,2) = bl->id;
  4984. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4985. }
  4986. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4987. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4988. /// num (only used when skill id = NV_BASIC and cause = 0):
  4989. /// 0 = "skill failed" MsgStringTable[159]
  4990. /// 1 = "no emotions" MsgStringTable[160]
  4991. /// 2 = "no sit" MsgStringTable[161]
  4992. /// 3 = "no chat" MsgStringTable[162]
  4993. /// 4 = "no party" MsgStringTable[163]
  4994. /// 5 = "no shout" MsgStringTable[164]
  4995. /// 6 = "no PKing" MsgStringTable[165]
  4996. /// 7 = "no alligning" MsgStringTable[383]
  4997. /// ? = ignored
  4998. /// cause:
  4999. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5000. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5001. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5002. /// "skill failed" MsgStringTable[204] (otherwise)
  5003. /// ... = @see enum useskill_fail_cause
  5004. /// ? = ignored
  5005. ///
  5006. /// if(result!=0) doesn't display any of the previous messages
  5007. /// Note: when this packet is received an unknown flag is always set to 0,
  5008. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5009. void clif_skill_fail( map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5010. nullpo_retv( sd );
  5011. int fd = sd->fd;
  5012. if( !session_isActive( fd ) ){
  5013. return;
  5014. }
  5015. if(battle_config.display_skill_fail&1)
  5016. return; //Disable all skill failed messages
  5017. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5018. return; //Disable delay failed messages
  5019. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5020. return;
  5021. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5022. return;
  5023. struct PACKET_ZC_ACK_TOUSESKILL p;
  5024. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5025. p.skillId = skill_id;
  5026. p.btype = btype;
  5027. p.itemId = itemId;
  5028. p.flag = 0; // 0 - failed
  5029. p.cause = cause;
  5030. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5031. }
  5032. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5033. /// 043d <skill ID>.W <tick>.L
  5034. void clif_skill_cooldown(map_session_data *sd, uint16 skill_id, t_tick tick)
  5035. {
  5036. #if PACKETVER>=20081112
  5037. int fd;
  5038. nullpo_retv(sd);
  5039. fd=sd->fd;
  5040. WFIFOHEAD(fd,packet_len(0x43d));
  5041. WFIFOW(fd,0) = 0x43d;
  5042. WFIFOW(fd,2) = skill_id;
  5043. WFIFOL(fd,4) = client_tick(tick);
  5044. WFIFOSET(fd,packet_len(0x43d));
  5045. #endif
  5046. }
  5047. /// Skill attack effect and damage.
  5048. /// 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)
  5049. /// 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)
  5050. 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)
  5051. {
  5052. unsigned char buf[64];
  5053. status_change *sc;
  5054. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5055. nullpo_ret(src);
  5056. nullpo_ret(dst);
  5057. type = clif_calc_delay(type,div,damage,ddelay);
  5058. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5059. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5060. damage = clif_hallucination_damage();
  5061. }
  5062. #if PACKETVER < 3
  5063. WBUFW(buf,0)=0x114;
  5064. WBUFW(buf,2)=skill_id;
  5065. WBUFL(buf,4)=src->id;
  5066. WBUFL(buf,8)=dst->id;
  5067. WBUFL(buf,12)=client_tick(tick);
  5068. WBUFL(buf,16)=sdelay;
  5069. WBUFL(buf,20)=ddelay;
  5070. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5071. WBUFW(buf,24)=damage?div:0;
  5072. } else {
  5073. WBUFW(buf,24)=damage;
  5074. }
  5075. WBUFW(buf,26)=skill_lv;
  5076. WBUFW(buf,28)=div;
  5077. WBUFB(buf,30)=type;
  5078. if (disguised(dst)) {
  5079. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5080. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5081. clif_send(buf,packet_len(0x114),dst,SELF);
  5082. } else
  5083. clif_send(buf,packet_len(0x114),dst,AREA);
  5084. if(disguised(src)) {
  5085. WBUFL(buf,4)=disguised_bl_id(src->id);
  5086. if (disguised(dst))
  5087. WBUFL(buf,8)=dst->id;
  5088. if(damage > 0)
  5089. WBUFW(buf,24)=-1;
  5090. clif_send(buf,packet_len(0x114),src,SELF);
  5091. }
  5092. #else
  5093. WBUFW(buf,0)=0x1de;
  5094. WBUFW(buf,2)=skill_id;
  5095. WBUFL(buf,4)=src->id;
  5096. WBUFL(buf,8)=dst->id;
  5097. WBUFL(buf,12)=client_tick(tick);
  5098. WBUFL(buf,16)=sdelay;
  5099. WBUFL(buf,20)=ddelay;
  5100. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5101. WBUFL(buf,24)=damage?div:0;
  5102. } else {
  5103. WBUFL(buf,24)=damage;
  5104. }
  5105. WBUFW(buf,28)=skill_lv;
  5106. WBUFW(buf,30)=div;
  5107. // For some reason, late 2013 and newer clients have
  5108. // a issue that causes players and monsters to endure
  5109. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5110. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5111. #if PACKETVER < 20131223
  5112. WBUFB(buf,32)=type;
  5113. #else
  5114. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5115. #endif
  5116. if (disguised(dst)) {
  5117. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5118. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5119. clif_send(buf,packet_len(0x1de),dst,SELF);
  5120. } else
  5121. clif_send(buf,packet_len(0x1de),dst,AREA);
  5122. if(disguised(src)) {
  5123. WBUFL(buf,4)=disguised_bl_id(src->id);
  5124. if (disguised(dst))
  5125. WBUFL(buf,8)=dst->id;
  5126. if(damage > 0)
  5127. WBUFL(buf,24)=-1;
  5128. clif_send(buf,packet_len(0x1de),src,SELF);
  5129. }
  5130. #endif
  5131. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5132. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5133. }
  5134. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5135. /// 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
  5136. /*
  5137. 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)
  5138. {
  5139. unsigned char buf[64];
  5140. status_change *sc;
  5141. nullpo_ret(src);
  5142. nullpo_ret(dst);
  5143. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5144. type = clif_calc_delay(type,div,damage,ddelay);
  5145. sc = status_get_sc(dst);
  5146. if(sc && sc->count) {
  5147. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5148. damage = clif_hallucination_damage();
  5149. }
  5150. WBUFW(buf,0)=0x115;
  5151. WBUFW(buf,2)=skill_id;
  5152. WBUFL(buf,4)=src->id;
  5153. WBUFL(buf,8)=dst->id;
  5154. WBUFL(buf,12)=client_tick(tick);
  5155. WBUFL(buf,16)=sdelay;
  5156. WBUFL(buf,20)=ddelay;
  5157. WBUFW(buf,24)=dst->x;
  5158. WBUFW(buf,26)=dst->y;
  5159. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5160. WBUFW(buf,28)=damage?div:0;
  5161. } else {
  5162. WBUFW(buf,28)=damage;
  5163. }
  5164. WBUFW(buf,30)=skill_lv;
  5165. WBUFW(buf,32)=div;
  5166. WBUFB(buf,34)=type;
  5167. clif_send(buf,packet_len(0x115),src,AREA);
  5168. if(disguised(src)) {
  5169. WBUFL(buf,4)=disguised_bl_id(src->id);
  5170. if(damage > 0)
  5171. WBUFW(buf,28)=-1;
  5172. clif_send(buf,packet_len(0x115),src,SELF);
  5173. }
  5174. if (disguised(dst)) {
  5175. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5176. if (disguised(src))
  5177. WBUFL(buf,4)=src->id;
  5178. else if(damage > 0)
  5179. WBUFW(buf,28)=-1;
  5180. clif_send(buf,packet_len(0x115),dst,SELF);
  5181. }
  5182. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5183. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5184. }
  5185. */
  5186. /// Non-damaging skill effect
  5187. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5188. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5189. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5190. {
  5191. unsigned char buf[17];
  5192. #if PACKETVER < 20130731
  5193. const int cmd = 0x11a;
  5194. #else
  5195. const int cmd = 0x9cb;
  5196. #endif
  5197. int offset = 0;
  5198. bool success = ( tick != 0 );
  5199. nullpo_ret(dst);
  5200. WBUFW(buf,0) = cmd;
  5201. WBUFW(buf,2) = skill_id;
  5202. #if PACKETVER < 20130731
  5203. WBUFW(buf,4) = min(heal, INT16_MAX);
  5204. #else
  5205. WBUFL(buf,4) = min(heal, INT32_MAX);
  5206. offset += 2;
  5207. #endif
  5208. WBUFL(buf,6+offset) = dst->id;
  5209. WBUFL(buf,10+offset) = src ? src->id : 0;
  5210. WBUFB(buf,14+offset) = success;
  5211. if (disguised(dst)) {
  5212. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5213. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5214. clif_send(buf, packet_len(cmd), dst, SELF);
  5215. } else
  5216. clif_send(buf, packet_len(cmd), dst, AREA);
  5217. if(src && disguised(src)) {
  5218. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5219. if (disguised(dst))
  5220. WBUFL(buf,6+offset) = dst->id;
  5221. clif_send(buf, packet_len(cmd), src, SELF);
  5222. }
  5223. return success;
  5224. }
  5225. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5226. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5227. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5228. {
  5229. unsigned char buf[32];
  5230. nullpo_retv(src);
  5231. WBUFW(buf,0)=0x117;
  5232. WBUFW(buf,2)=skill_id;
  5233. WBUFL(buf,4)=src->id;
  5234. WBUFW(buf,8)=val;
  5235. WBUFW(buf,10)=x;
  5236. WBUFW(buf,12)=y;
  5237. WBUFL(buf,14)=client_tick(tick);
  5238. if(disguised(src)) {
  5239. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5240. WBUFL(buf,4)=disguised_bl_id(src->id);
  5241. clif_send(buf,packet_len(0x117),src,SELF);
  5242. } else
  5243. clif_send(buf,packet_len(0x117),src,AREA);
  5244. }
  5245. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5246. /// 011c <skill id>.W { <map name>.16B }*4
  5247. void clif_skill_warppoint(map_session_data* sd, uint16 skill_id, uint16 skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  5248. {
  5249. int fd;
  5250. nullpo_retv(sd);
  5251. fd = sd->fd;
  5252. WFIFOHEAD(fd,packet_len(0x11c));
  5253. WFIFOW(fd,0) = 0x11c;
  5254. WFIFOW(fd,2) = skill_id;
  5255. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5256. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5257. else // normal map name
  5258. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5259. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5260. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5261. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5262. WFIFOSET(fd,packet_len(0x11c));
  5263. sd->menuskill_id = skill_id;
  5264. if (skill_id == AL_WARP) {
  5265. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5266. sd->state.workinprogress = WIP_DISABLE_ALL;
  5267. } else
  5268. sd->menuskill_val = skill_lv;
  5269. }
  5270. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5271. /// 011e <type>.B
  5272. /// type:
  5273. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5274. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5275. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5276. ///
  5277. /// @param sd Who receives the message
  5278. /// @param type What message
  5279. void clif_skill_memomessage(map_session_data* sd, int type)
  5280. {
  5281. int fd;
  5282. nullpo_retv(sd);
  5283. fd=sd->fd;
  5284. WFIFOHEAD(fd,packet_len(0x11e));
  5285. WFIFOW(fd,0)=0x11e;
  5286. WFIFOB(fd,2)=type;
  5287. WFIFOSET(fd,packet_len(0x11e));
  5288. }
  5289. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5290. /// 0189 <type>.W
  5291. /// type:
  5292. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5293. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5294. ///
  5295. /// @param sd Who receives the message
  5296. /// @param type What message
  5297. void clif_skill_teleportmessage(map_session_data *sd, int type)
  5298. {
  5299. int fd;
  5300. nullpo_retv(sd);
  5301. fd=sd->fd;
  5302. WFIFOHEAD(fd,packet_len(0x189));
  5303. WFIFOW(fd,0)=0x189;
  5304. WFIFOW(fd,2)=type;
  5305. WFIFOSET(fd,packet_len(0x189));
  5306. }
  5307. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5308. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5309. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5310. void clif_skill_estimation(map_session_data *sd,struct block_list *dst)
  5311. {
  5312. struct status_data *status;
  5313. unsigned char buf[64];
  5314. int i, fix;
  5315. nullpo_retv(sd);
  5316. nullpo_retv(dst);
  5317. if( dst->type != BL_MOB )
  5318. return;
  5319. status = status_get_status_data(dst);
  5320. WBUFW(buf, 0)=0x18c;
  5321. WBUFW(buf, 2)=status_get_class(dst);
  5322. WBUFW(buf, 4)=status_get_lv(dst);
  5323. WBUFW(buf, 6)=status->size;
  5324. WBUFL(buf, 8)=status->hp;
  5325. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5326. +(battle_config.estimation_type&2?status->def2:0);
  5327. WBUFW(buf,14)=status->race;
  5328. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5329. +(battle_config.estimation_type&2?status->mdef2:0);
  5330. WBUFW(buf,18)= status->def_ele;
  5331. for(i=0;i<9;i++)
  5332. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5333. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5334. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5335. }
  5336. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5337. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5338. /// material id:
  5339. /// unused by the client
  5340. void clif_skill_produce_mix_list( map_session_data *sd, int skill_id, int trigger ){
  5341. nullpo_retv(sd);
  5342. int fd = sd->fd;
  5343. if( !session_isActive( fd ) ){
  5344. return;
  5345. }
  5346. if (sd->menuskill_id == skill_id)
  5347. return; //Avoid resending the menu twice or more times...
  5348. if (skill_id == GC_CREATENEWPOISON)
  5349. skill_id = GC_RESEARCHNEWPOISON;
  5350. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5351. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5352. p->packetType = 0x18d;
  5353. int count = 0;
  5354. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5355. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5356. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5357. )
  5358. {
  5359. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5360. p->items[count].material[0] = 0;
  5361. p->items[count].material[1] = 0;
  5362. p->items[count].material[2] = 0;
  5363. count++;
  5364. }
  5365. }
  5366. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5367. WFIFOSET( fd, p->packetLength );
  5368. if( count > 0 ){
  5369. sd->menuskill_id = skill_id;
  5370. sd->menuskill_val = trigger;
  5371. return;
  5372. }
  5373. }
  5374. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5375. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5376. /// mk type:
  5377. /// 1 = cooking
  5378. /// 2 = arrow
  5379. /// 3 = elemental
  5380. /// 4 = GN_MIX_COOKING
  5381. /// 5 = GN_MAKEBOMB
  5382. /// 6 = GN_S_PHARMACY
  5383. /// 7 = MT_M_MACHINE - Unconfirmed
  5384. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5385. void clif_cooking_list( map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5386. nullpo_retv( sd );
  5387. // Avoid resending the menu twice or more times...
  5388. if( sd->menuskill_id == skill_id ){
  5389. return;
  5390. }
  5391. int fd = sd->fd;
  5392. if( !session_isActive( fd ) ){
  5393. return;
  5394. }
  5395. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5396. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5397. p->packetType = 0x25a;
  5398. p->makeItem = list_type; // list type
  5399. int count = 0;
  5400. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5401. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5402. continue;
  5403. }
  5404. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5405. count++;
  5406. }
  5407. if( count > 0 || skill_id == AM_PHARMACY ){
  5408. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5409. WFIFOSET( fd, p->packetLength );
  5410. sd->menuskill_id = skill_id;
  5411. sd->menuskill_val = trigger;
  5412. sd->menuskill_val2 = qty; // amount.
  5413. }else{
  5414. clif_menuskill_clear(sd);
  5415. #if PACKETVER >= 20090922
  5416. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5417. #else
  5418. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5419. WFIFOSET( fd, p->packetLength );
  5420. #endif
  5421. }
  5422. }
  5423. /// Notifies clients of a status change.
  5424. /// 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)]
  5425. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5426. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5427. /// @param bl Sends packet to clients around this object
  5428. /// @param id ID of object that has this effect
  5429. /// @param type Status icon see enum efst_type
  5430. /// @param flag 1:Active, 0:Deactive
  5431. /// @param tick Duration in ms
  5432. /// @param val1
  5433. /// @param val2
  5434. /// @param val3
  5435. 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)
  5436. {
  5437. unsigned char buf[32];
  5438. if (type == EFST_BLANK) //It shows nothing on the client...
  5439. return;
  5440. if (type == EFST_POSTDELAY && tick == 0)
  5441. return;
  5442. nullpo_retv(bl);
  5443. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5444. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5445. tick = 200;
  5446. #if PACKETVER >= 20120618
  5447. if (flag && battle_config.display_status_timers)
  5448. WBUFW(buf,0) = 0x983;
  5449. else
  5450. #elif PACKETVER >= 20090121
  5451. if (flag && battle_config.display_status_timers)
  5452. WBUFW(buf,0) = 0x43f;
  5453. else
  5454. #endif
  5455. WBUFW(buf,0) = 0x196;
  5456. WBUFW(buf,2) = type;
  5457. WBUFL(buf,4) = id;
  5458. WBUFB(buf,8) = flag;
  5459. #if PACKETVER >= 20120618
  5460. if (flag && battle_config.display_status_timers) {
  5461. if (tick <= 0)
  5462. tick = 9999; // this is indeed what official servers do
  5463. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5464. WBUFL(buf,13) = client_tick(tick);
  5465. WBUFL(buf,17) = val1;
  5466. WBUFL(buf,21) = val2;
  5467. WBUFL(buf,25) = val3;
  5468. }
  5469. #elif PACKETVER >= 20090121
  5470. if (flag && battle_config.display_status_timers) {
  5471. if (tick <= 0)
  5472. tick = 9999; // this is indeed what official servers do
  5473. WBUFL(buf,9) = client_tick(tick);
  5474. WBUFL(buf,13) = val1;
  5475. WBUFL(buf,17) = val2;
  5476. WBUFL(buf,21) = val3;
  5477. }
  5478. #endif
  5479. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5480. }
  5481. /* Sends status effect to clients around the bl
  5482. * @param bl Object that has the effect
  5483. * @param type Status icon see enum efst_type
  5484. * @param flag 1:Active, 0:Deactive
  5485. * @param tick Duration in ms
  5486. * @param val1
  5487. * @param val2
  5488. * @param val3
  5489. */
  5490. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5491. map_session_data *sd = NULL;
  5492. if (type == EFST_BLANK) //It shows nothing on the client...
  5493. return;
  5494. if (type == EFST_POSTDELAY && tick == 0)
  5495. return;
  5496. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5497. return;
  5498. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5499. // Older clients display normal riding icon.
  5500. if (type == EFST_MADOGEAR)
  5501. type = EFST_RIDING;
  5502. #endif
  5503. nullpo_retv(bl);
  5504. sd = BL_CAST(BL_PC, bl);
  5505. if (!(status_efst_get_bl_type((efst_type)type)&bl->type)) // only send status changes that actually matter to the client
  5506. return;
  5507. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5508. }
  5509. /**
  5510. * Send any active EFST to those around.
  5511. * @param tbl: Unit to send the packet to
  5512. * @param bl: Objects walking into view
  5513. * @param target: Client send type
  5514. */
  5515. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5516. unsigned char i;
  5517. struct sc_display_entry **sc_display;
  5518. unsigned char sc_display_count;
  5519. bool spheres_sent;
  5520. nullpo_retv(bl);
  5521. switch( bl->type ){
  5522. case BL_PC: {
  5523. map_session_data* sd = (map_session_data*)bl;
  5524. sc_display = sd->sc_display;
  5525. sc_display_count = sd->sc_display_count;
  5526. spheres_sent = !sd->state.connect_new;
  5527. }
  5528. break;
  5529. case BL_NPC: {
  5530. struct npc_data* nd = (struct npc_data*)bl;
  5531. sc_display = nd->sc_display;
  5532. sc_display_count = nd->sc_display_count;
  5533. spheres_sent = true;
  5534. }
  5535. break;
  5536. default:
  5537. return;
  5538. }
  5539. for (i = 0; i < sc_display_count; i++) {
  5540. enum sc_type type = sc_display[i]->type;
  5541. status_change *sc = status_get_sc(bl);
  5542. const struct TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : NULL);
  5543. t_tick tick = 0;
  5544. if (td)
  5545. tick = DIFF_TICK(td->tick, gettick());
  5546. // Status changes that need special handling
  5547. switch( type ){
  5548. case SC_SPHERE_1:
  5549. case SC_SPHERE_2:
  5550. case SC_SPHERE_3:
  5551. case SC_SPHERE_4:
  5552. case SC_SPHERE_5:
  5553. if( spheres_sent ){
  5554. target = AREA_WOS;
  5555. }
  5556. break;
  5557. case SC_HELLS_PLANT:
  5558. if( sc && sc->getSCE(type) ){
  5559. tick = sc->getSCE(type)->val4;
  5560. }
  5561. break;
  5562. }
  5563. #if PACKETVER > 20120418
  5564. 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);
  5565. #else
  5566. 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);
  5567. #endif
  5568. }
  5569. }
  5570. /// Notifies the client when a player enters the screen with an active EFST.
  5571. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5572. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5573. 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) {
  5574. #if PACKETVER >= 20111108
  5575. unsigned char buf[32];
  5576. #if PACKETVER >= 20120618
  5577. const int cmd = 0x984;
  5578. #elif PACKETVER >= 20111108
  5579. const int cmd = 0x8ff;
  5580. #endif
  5581. int offset = 0;
  5582. if (type == EFST_BLANK)
  5583. return;
  5584. nullpo_retv(bl);
  5585. if (tick <= 0)
  5586. tick = 9999;
  5587. WBUFW(buf,offset + 0) = cmd;
  5588. WBUFL(buf,offset + 2) = tid;
  5589. WBUFW(buf,offset + 6) = type;
  5590. #if PACKETVER >= 20111108
  5591. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5592. #if PACKETVER >= 20120618
  5593. WBUFL(buf,offset + 12) = client_tick(tick);
  5594. offset += 4;
  5595. #endif
  5596. WBUFL(buf,offset + 12) = val1;
  5597. WBUFL(buf,offset + 16) = val2;
  5598. WBUFL(buf,offset + 20) = val3;
  5599. #endif
  5600. clif_send(buf,packet_len(cmd),bl,target);
  5601. #endif
  5602. }
  5603. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5604. /// 008e <packet len>.W <message>.?B
  5605. void clif_displaymessage(const int fd, const char* mes)
  5606. {
  5607. nullpo_retv(mes);
  5608. if( session_isActive( fd ) ){
  5609. char *message, *line;
  5610. message = aStrdup(mes);
  5611. line = strtok(message, "\n");
  5612. while(line != NULL) {
  5613. #if PACKETVER == 20141022
  5614. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5615. /** so we redirect to ZC_NPC_CHAT **/
  5616. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5617. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5618. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5619. if (len > 0) {
  5620. WFIFOHEAD(fd, 13 + len);
  5621. WFIFOW(fd, 0) = 0x2C1;
  5622. WFIFOW(fd, 2) = 13 + len;
  5623. WFIFOL(fd, 4) = 0;
  5624. WFIFOL(fd, 8) = color;
  5625. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5626. WFIFOSET(fd, WFIFOW(fd, 2));
  5627. }
  5628. #else
  5629. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5630. int len = strnlen(line, CHAT_SIZE_MAX);
  5631. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5632. WFIFOHEAD(fd, 5 + len);
  5633. WFIFOW(fd,0) = 0x8e;
  5634. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5635. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5636. WFIFOSET(fd, 5 + len);
  5637. }
  5638. #endif
  5639. line = strtok(NULL, "\n");
  5640. }
  5641. aFree(message);
  5642. }
  5643. }
  5644. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5645. /// 009a <packet len>.W <message>.?B
  5646. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5647. {
  5648. nullpo_retv(mes);
  5649. if (len < 2)
  5650. return;
  5651. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5652. p->packetType = HEADER_ZC_BROADCAST;
  5653. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5654. if( ( type&BC_BLUE ) != 0 ){
  5655. const char* color = "blue";
  5656. int16 length = (int16)strlen( color );
  5657. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5658. strcpy( p->message, color );
  5659. strncpy( &p->message[length], mes, len );
  5660. p->PacketLength += length;
  5661. }else if( ( type&BC_WOE ) != 0 ){
  5662. const char* color = "ssss";
  5663. int16 length = (int16)strlen( color );
  5664. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5665. strcpy( p->message, color );
  5666. strncpy( &p->message[length], mes, len );
  5667. p->PacketLength += length;
  5668. }else{
  5669. strncpy( p->message, mes, len );
  5670. }
  5671. clif_send( p, p->PacketLength, bl, target );
  5672. }
  5673. /*==========================================
  5674. * Displays a message on a 'bl' to all it's nearby clients
  5675. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5676. *------------------------------------------*/
  5677. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5678. nullpo_retv(bl);
  5679. nullpo_retv(message);
  5680. int16 len = (int16)( strlen( message ) + 1 );
  5681. if( len > CHAT_SIZE_MAX ) {
  5682. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5683. len = CHAT_SIZE_MAX;
  5684. }
  5685. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5686. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5687. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5688. p->GID = bl->id;
  5689. safestrncpy( p->Message, message, len );
  5690. clif_send( p, p->PacketLength, bl, target );
  5691. }
  5692. /// Send broadcast message with font formatting.
  5693. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5694. 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)
  5695. {
  5696. nullpo_retv(mes);
  5697. if (len < 2)
  5698. return;
  5699. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5700. p->packetType = HEADER_ZC_BROADCAST2;
  5701. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5702. p->fontColor = fontColor;
  5703. p->fontType = fontType;
  5704. p->fontSize = fontSize;
  5705. p->fontAlign = fontAlign;
  5706. p->fontY = fontY;
  5707. strncpy( p->message, mes, len );
  5708. clif_send( p, p->PacketLength, bl, target );
  5709. }
  5710. /*
  5711. * Display *msg to all *users in channel
  5712. */
  5713. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5714. DBIterator *iter;
  5715. map_session_data *user;
  5716. unsigned short msg_len = 0, len = 0;
  5717. unsigned char buf[CHAT_SIZE_MAX];
  5718. if (!channel || !msg)
  5719. return;
  5720. msg_len = (unsigned short)(strlen(msg) + 1);
  5721. if( msg_len > sizeof(buf)-12 ) {
  5722. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5723. msg_len = sizeof(buf)-12;
  5724. }
  5725. WBUFW(buf,0) = 0x2C1;
  5726. WBUFW(buf,2) = (len = msg_len + 12);
  5727. WBUFL(buf,4) = 0;
  5728. WBUFL(buf,8) = color;
  5729. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5730. iter = db_iterator(channel->users);
  5731. for( user = (map_session_data *)dbi_first(iter); dbi_exists(iter); user = (map_session_data *)dbi_next(iter) ) {
  5732. clif_send(buf, len, &user->bl, SELF);
  5733. }
  5734. dbi_destroy(iter);
  5735. }
  5736. /// Displays heal effect.
  5737. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5738. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5739. /// var id:
  5740. /// 5 = HP (SP_HP)
  5741. /// 7 = SP (SP_SP)
  5742. /// ? = ignored
  5743. void clif_heal(int fd,int type,int val) {
  5744. #if PACKETVER < 20141022
  5745. const int cmd = 0x13d;
  5746. #else
  5747. const int cmd = 0xa27;
  5748. #endif
  5749. WFIFOHEAD(fd, packet_len(cmd));
  5750. WFIFOW(fd,0) = cmd;
  5751. WFIFOW(fd,2) = type;
  5752. #if PACKETVER < 20141022
  5753. WFIFOW(fd,4) = min(val, INT16_MAX);
  5754. #else
  5755. WFIFOL(fd,4) = min(val, INT32_MAX);
  5756. #endif
  5757. WFIFOSET(fd, packet_len(cmd));
  5758. }
  5759. /// Displays resurrection effect (ZC_RESURRECTION).
  5760. /// 0148 <id>.L <type>.W
  5761. /// type:
  5762. /// ignored
  5763. void clif_resurrection(struct block_list *bl,int type)
  5764. {
  5765. unsigned char buf[16];
  5766. nullpo_retv(bl);
  5767. WBUFW(buf,0)=0x148;
  5768. WBUFL(buf,2)=bl->id;
  5769. WBUFW(buf,6)=0;
  5770. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5771. if (disguised(bl))
  5772. clif_spawn(bl);
  5773. }
  5774. /// Sets the map property
  5775. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5776. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5777. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5778. {
  5779. #if PACKETVER >= 20121010
  5780. short cmd = 0x99b;
  5781. unsigned char buf[8];
  5782. #else
  5783. short cmd = 0x199;
  5784. unsigned char buf[4];
  5785. #endif
  5786. WBUFW(buf,0)=cmd;
  5787. WBUFW(buf,2)=property;
  5788. #if PACKETVER >= 20121010
  5789. struct map_data *mapdata = map_getmapdata(bl->m);
  5790. map_session_data *sd = BL_CAST(BL_PC, bl);
  5791. WBUFL(buf,4) = ((mapdata->flag[MF_PVP] || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5792. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5793. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5794. ((mapdata->flag[MF_FORCEMINEFFECT] || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5795. ((mapdata->flag[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
  5796. ((mapdata->flag[MF_PVP])<<5)| // COUNT_PK - Show the PvP counter
  5797. ((mapdata->flag[MF_PARTYLOCK])<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5798. ((mapdata->flag[MF_BATTLEGROUND])<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5799. ((mapdata->flag[MF_NOCOSTUME])<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5800. ((!mapdata->flag[MF_NOUSECART])<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5801. ((!mapdata->flag[MF_NOSUNMOONSTARMIRACLE])<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5802. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5803. #endif
  5804. clif_send(buf,packet_len(cmd),bl,t);
  5805. }
  5806. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5807. /// 01d6 <type>.W
  5808. void clif_map_type(map_session_data* sd, enum map_type type)
  5809. {
  5810. int fd;
  5811. nullpo_retv(sd);
  5812. fd=sd->fd;
  5813. WFIFOHEAD(fd,packet_len(0x1D6));
  5814. WFIFOW(fd,0)=0x1D6;
  5815. WFIFOW(fd,2)=type;
  5816. WFIFOSET(fd,packet_len(0x1D6));
  5817. }
  5818. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5819. /// 019a <id>.L <ranking>.L <total>.L
  5820. void clif_pvpset(map_session_data *sd,int pvprank,int pvpnum,int type)
  5821. {
  5822. if(type == 2) {
  5823. int fd = sd->fd;
  5824. WFIFOHEAD(fd,packet_len(0x19a));
  5825. WFIFOW(fd,0) = 0x19a;
  5826. WFIFOL(fd,2) = sd->bl.id;
  5827. WFIFOL(fd,6) = pvprank;
  5828. WFIFOL(fd,10) = pvpnum;
  5829. WFIFOSET(fd,packet_len(0x19a));
  5830. } else {
  5831. unsigned char buf[32];
  5832. WBUFW(buf,0) = 0x19a;
  5833. WBUFL(buf,2) = sd->bl.id;
  5834. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5835. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5836. else
  5837. WBUFL(buf,6) = pvprank;
  5838. WBUFL(buf,10) = pvpnum;
  5839. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5840. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5841. else if(!type)
  5842. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5843. else
  5844. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5845. }
  5846. }
  5847. /*==========================================
  5848. *
  5849. *------------------------------------------*/
  5850. void clif_map_property_mapall(int map_idx, enum map_property property)
  5851. {
  5852. struct block_list bl;
  5853. bl.id = 0;
  5854. bl.type = BL_NUL;
  5855. bl.m = map_idx;
  5856. clif_map_property( &bl, property, ALL_SAMEMAP );
  5857. }
  5858. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5859. /// 0188 <result>.W <index>.W <refine>.W
  5860. /// result:
  5861. /// 0 = success
  5862. /// 1 = failure
  5863. /// 2 = downgrade
  5864. void clif_refine(int fd, int fail, int index, int val)
  5865. {
  5866. WFIFOHEAD(fd,packet_len(0x188));
  5867. WFIFOW(fd,0)=0x188;
  5868. WFIFOW(fd,2)=fail;
  5869. WFIFOW(fd,4)=index+2;
  5870. WFIFOW(fd,6)=val;
  5871. WFIFOSET(fd,packet_len(0x188));
  5872. }
  5873. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5874. /// 0223 <result>.L <nameid>.W
  5875. /// result:
  5876. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5877. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5878. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5879. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5880. void clif_upgrademessage( map_session_data* sd, int result, t_itemid item_id ){
  5881. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5882. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5883. p.result = result;
  5884. p.itemId = client_nameid( item_id );
  5885. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5886. }
  5887. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5888. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5889. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5890. void clif_wis_message(map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5891. int fd;
  5892. nullpo_retv(sd);
  5893. fd = sd->fd;
  5894. #if PACKETVER < 20091104
  5895. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5896. WFIFOW(fd,0) = 0x97;
  5897. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5898. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5899. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5900. WFIFOSET(fd,WFIFOW(fd,2));
  5901. #else
  5902. map_session_data *ssd = map_nick2sd(nick,false);
  5903. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5904. WFIFOW(fd,0) = 0x97;
  5905. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5906. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5907. // If it is not a message from the server or a player from another map-server
  5908. if( ssd ){
  5909. gmlvl = pc_get_group_level(ssd);
  5910. }
  5911. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5912. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5913. WFIFOSET(fd,WFIFOW(fd,2));
  5914. #endif
  5915. }
  5916. /// Inform the player about the result of his whisper action
  5917. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5918. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5919. /// result:
  5920. /// 0 = success to send wisper
  5921. /// 1 = target character is not loged in
  5922. /// 2 = ignored by target
  5923. /// 3 = everyone ignored by target
  5924. void clif_wis_end(int fd, int result)
  5925. {
  5926. map_session_data *sd = (session_isActive(fd) ? (map_session_data *)session[fd]->session_data : NULL);
  5927. #if PACKETVER < 20131223
  5928. const int cmd = 0x98;
  5929. #else
  5930. const int cmd = 0x9df;
  5931. #endif
  5932. if (!sd)
  5933. return;
  5934. WFIFOHEAD(fd,packet_len(cmd));
  5935. WFIFOW(fd,0) = cmd;
  5936. WFIFOB(fd,2) = (char)result;
  5937. #if PACKETVER >= 20131223
  5938. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5939. #endif
  5940. WFIFOSET(fd,packet_len(cmd));
  5941. }
  5942. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5943. /// 0194 <char id>.L <name>.24B
  5944. /// 0af7 <flag>.W <char id>.L <name>.24B
  5945. void clif_solved_charname(int fd, int charid, const char* name)
  5946. {
  5947. #if PACKETVER >= 20180221
  5948. WFIFOHEAD(fd,packet_len(0xaf7));
  5949. WFIFOW(fd,0) = 0xaf7;
  5950. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5951. WFIFOL(fd,4) = charid;
  5952. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5953. WFIFOSET(fd,packet_len(0x0af7));
  5954. #else
  5955. WFIFOHEAD(fd,packet_len(0x194));
  5956. WFIFOW(fd,0)=0x194;
  5957. WFIFOL(fd,2)=charid;
  5958. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5959. WFIFOSET(fd,packet_len(0x194));
  5960. #endif
  5961. }
  5962. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5963. /// 017b <packet len>.W { <name id>.W }*
  5964. void clif_use_card(map_session_data *sd,int idx)
  5965. {
  5966. int i,c,ep;
  5967. int fd=sd->fd;
  5968. nullpo_retv(sd);
  5969. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5970. return;
  5971. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5972. return; //Avoid parsing invalid item indexes (no card/no item)
  5973. ep=sd->inventory_data[idx]->equip;
  5974. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5975. WFIFOW(fd,0)=0x17b;
  5976. for(i=c=0;i<MAX_INVENTORY;i++){
  5977. int j;
  5978. if(sd->inventory_data[i] == NULL)
  5979. continue;
  5980. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5981. continue;
  5982. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5983. continue;
  5984. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5985. continue;
  5986. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5987. continue;
  5988. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5989. continue;
  5990. 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.
  5991. continue;
  5992. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5993. if( j == sd->inventory_data[i]->slots ) // No room
  5994. continue;
  5995. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5996. continue;
  5997. WFIFOW(fd,4+c*2)=i+2;
  5998. c++;
  5999. }
  6000. if( !c ) return; // no item is available for card insertion
  6001. WFIFOW(fd,2)=4+c*2;
  6002. WFIFOSET(fd,WFIFOW(fd,2));
  6003. }
  6004. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6005. /// 017d <equip index>.W <card index>.W <result>.B
  6006. /// result:
  6007. /// 0 = success
  6008. /// 1 = failure
  6009. void clif_insert_card(map_session_data *sd,int idx_equip,int idx_card,int flag)
  6010. {
  6011. int fd;
  6012. nullpo_retv(sd);
  6013. fd=sd->fd;
  6014. WFIFOHEAD(fd,packet_len(0x17d));
  6015. WFIFOW(fd,0)=0x17d;
  6016. WFIFOW(fd,2)=idx_equip+2;
  6017. WFIFOW(fd,4)=idx_card+2;
  6018. WFIFOB(fd,6)=flag;
  6019. WFIFOSET(fd,packet_len(0x17d));
  6020. }
  6021. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6022. /// 0177 <packet len>.W { <index>.W }*
  6023. void clif_item_identify_list(map_session_data *sd)
  6024. {
  6025. int i,c;
  6026. int fd;
  6027. nullpo_retv(sd);
  6028. fd=sd->fd;
  6029. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6030. WFIFOW(fd,0)=0x177;
  6031. for(i=c=0;i<MAX_INVENTORY;i++){
  6032. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6033. WFIFOW(fd,c*2+4)=client_index(i);
  6034. c++;
  6035. }
  6036. }
  6037. if(c > 0) {
  6038. WFIFOW(fd,2)=c*2+4;
  6039. WFIFOSET(fd,WFIFOW(fd,2));
  6040. sd->menuskill_id = MC_IDENTIFY;
  6041. sd->menuskill_val = c;
  6042. sd->state.workinprogress = WIP_DISABLE_ALL;
  6043. }
  6044. }
  6045. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6046. /// 0179 <index>.W <result>.B
  6047. void clif_item_identified(map_session_data *sd,int idx,int flag)
  6048. {
  6049. int fd;
  6050. nullpo_retv(sd);
  6051. fd=sd->fd;
  6052. WFIFOHEAD(fd,packet_len(0x179));
  6053. WFIFOW(fd, 0)=0x179;
  6054. WFIFOW(fd, 2)=idx+2;
  6055. WFIFOB(fd, 4)=flag;
  6056. WFIFOSET(fd,packet_len(0x179));
  6057. }
  6058. /// Presents a list of items that can be repaired.
  6059. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6060. void clif_item_repair_list( map_session_data *sd,map_session_data *dstsd, int lv ){
  6061. nullpo_retv( sd );
  6062. nullpo_retv( dstsd );
  6063. int fd = sd->fd;
  6064. if( !session_isActive( fd ) ){
  6065. return;
  6066. }
  6067. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6068. // Preallocate the maximum size
  6069. WFIFOHEAD( fd, len );
  6070. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6071. int c = 0;
  6072. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6073. 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)){
  6074. p->items[c].index = i;
  6075. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6076. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6077. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6078. c++;
  6079. }
  6080. }
  6081. if( c > 0 ){
  6082. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6083. // Recalculate real length
  6084. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6085. p->packetLength = len;
  6086. WFIFOSET( fd, len );
  6087. sd->menuskill_id = BS_REPAIRWEAPON;
  6088. sd->menuskill_val = dstsd->bl.id;
  6089. sd->menuskill_val2 = lv;
  6090. }else{
  6091. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6092. }
  6093. }
  6094. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6095. /// 01fe <index>.W <result>.B
  6096. /// index:
  6097. /// ignored (inventory index)
  6098. /// result:
  6099. /// 0 = Item repair success.
  6100. /// 1 = Item repair failure.
  6101. void clif_item_repaireffect(map_session_data *sd,int idx,int flag)
  6102. {
  6103. int fd;
  6104. nullpo_retv(sd);
  6105. fd = sd->fd;
  6106. WFIFOHEAD(fd,packet_len(0x1fe));
  6107. WFIFOW(fd, 0)=0x1fe;
  6108. WFIFOW(fd, 2)=idx+2;
  6109. WFIFOB(fd, 4)=flag;
  6110. WFIFOSET(fd,packet_len(0x1fe));
  6111. }
  6112. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6113. /// 02bb <equip location>.W <account id>.L
  6114. void clif_item_damaged(map_session_data* sd, unsigned short position)
  6115. {
  6116. int fd = sd->fd;
  6117. WFIFOHEAD(fd,packet_len(0x2bb));
  6118. WFIFOW(fd,0) = 0x2bb;
  6119. WFIFOW(fd,2) = position;
  6120. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6121. WFIFOSET(fd,packet_len(0x2bb));
  6122. }
  6123. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6124. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6125. void clif_item_refine_list( map_session_data *sd ){
  6126. nullpo_retv( sd );
  6127. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6128. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6129. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6130. int refine_item[MAX_WEAPON_LEVEL];
  6131. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6132. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6133. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6134. #ifdef RENEWAL
  6135. refine_item[4] = -1;
  6136. #endif
  6137. int count = 0;
  6138. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6139. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6140. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6141. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6142. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6143. p->items[count].index = client_index( i );
  6144. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6145. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6146. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6147. count++;
  6148. }
  6149. }
  6150. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6151. clif_send( p, p->packetLength, &sd->bl, SELF );
  6152. if( count > 0 ){
  6153. sd->menuskill_id = WS_WEAPONREFINE;
  6154. sd->menuskill_val = skill_lv;
  6155. }
  6156. }
  6157. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6158. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6159. void clif_item_skill( map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6160. nullpo_retv( sd );
  6161. struct PACKET_ZC_AUTORUN_SKILL p;
  6162. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6163. p.skill_id = skill_id;
  6164. p.skill_type = skill_get_inf( skill_id );
  6165. p.skill_lv = skill_lv;
  6166. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6167. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6168. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6169. p.up_flag = false;
  6170. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6171. }
  6172. /// Adds an item to character's cart.
  6173. /// 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)
  6174. /// 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)
  6175. /// 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)
  6176. void clif_cart_additem( map_session_data *sd, int n, int amount ){
  6177. nullpo_retv( sd );
  6178. int fd = sd->fd;
  6179. if( !session_isActive( fd ) ){
  6180. return;
  6181. }
  6182. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6183. return;
  6184. }
  6185. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6186. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6187. p.index = client_index( n );
  6188. p.amount = amount;
  6189. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6190. #if PACKETVER >= 5
  6191. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6192. #endif
  6193. p.identified = sd->cart.u.items_cart[n].identify;
  6194. p.damaged = sd->cart.u.items_cart[n].attribute;
  6195. p.refine = sd->cart.u.items_cart[n].refine;
  6196. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6197. #if PACKETVER >= 20150226
  6198. clif_add_random_options( p.option_data, sd->cart.u.items_cart[n] );
  6199. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6200. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6201. #endif
  6202. #endif
  6203. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6204. }
  6205. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6206. /* Acknowledge an item have been added to cart
  6207. * 012c <result>B
  6208. * result :
  6209. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6210. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6211. */
  6212. void clif_cart_additem_ack(map_session_data *sd, uint8 flag)
  6213. {
  6214. int fd;
  6215. unsigned char *buf;
  6216. nullpo_retv(sd);
  6217. fd = sd->fd;
  6218. buf = WFIFOP(fd,0);
  6219. WBUFW(buf,0) = 0x12c;
  6220. WBUFB(buf,2) = flag;
  6221. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6222. }
  6223. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6224. void clif_bank_open( map_session_data& sd ){
  6225. #if PACKETVER >= 20130717
  6226. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6227. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6228. p.unknown = 0;
  6229. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6230. #endif
  6231. }
  6232. /*
  6233. * Request to Open the banking system
  6234. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6235. */
  6236. void clif_parse_BankOpen(int fd, map_session_data* sd) {
  6237. //TODO check if preventing trade or stuff like that
  6238. //also mark something in case char ain't available for saving, should we check now ?
  6239. nullpo_retv(sd);
  6240. if( !battle_config.feature_banking ) {
  6241. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6242. return;
  6243. }
  6244. else {
  6245. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6246. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6247. if(sd->status.account_id == aid){
  6248. sd->state.banking = 1;
  6249. //request save ?
  6250. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6251. //on succes open bank ?
  6252. clif_bank_open( *sd );
  6253. }
  6254. }
  6255. }
  6256. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6257. void clif_bank_close( map_session_data& sd ){
  6258. #if PACKETVER >= 20130717
  6259. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6260. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6261. p.unknown = 0;
  6262. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6263. #endif
  6264. }
  6265. /*
  6266. * Request to close the banking system
  6267. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6268. */
  6269. void clif_parse_BankClose(int fd, map_session_data* sd) {
  6270. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6271. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6272. nullpo_retv(sd);
  6273. if( !battle_config.feature_banking ) {
  6274. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6275. //still allow to go trough to not stuck player if we have disable it while they was in
  6276. }
  6277. if(sd->status.account_id == aid){
  6278. sd->state.banking = 0;
  6279. clif_bank_close( *sd );
  6280. }
  6281. }
  6282. /*
  6283. * Display how much we got in bank (I suppose)
  6284. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6285. */
  6286. void clif_Bank_Check( map_session_data& sd ){
  6287. #if PACKETVER >= 20130717
  6288. struct PACKET_ZC_BANKING_CHECK p = {};
  6289. p.packetType = HEADER_ZC_BANKING_CHECK;
  6290. p.money = sd.bank_vault;
  6291. p.reason = 0;
  6292. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6293. #endif
  6294. }
  6295. /*
  6296. * Requesting the data in bank
  6297. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6298. */
  6299. void clif_parse_BankCheck(int fd, map_session_data* sd) {
  6300. nullpo_retv(sd);
  6301. if( !battle_config.feature_banking ) {
  6302. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6303. return;
  6304. }
  6305. else {
  6306. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6307. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6308. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6309. clif_Bank_Check( *sd );
  6310. }
  6311. }
  6312. /*
  6313. * Acknowledge of deposit some money in bank
  6314. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6315. */
  6316. void clif_bank_deposit( map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6317. #if PACKETVER >= 20130717
  6318. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6319. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6320. p.money = sd.bank_vault;
  6321. p.zeny = sd.status.zeny;
  6322. p.reason = reason;
  6323. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6324. #endif
  6325. }
  6326. /*
  6327. * Request saving some money in bank
  6328. * @author : original [Yommy/Hercules]
  6329. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6330. */
  6331. void clif_parse_BankDeposit(int fd, map_session_data* sd) {
  6332. nullpo_retv(sd);
  6333. if( !battle_config.feature_banking ) {
  6334. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6335. return;
  6336. }
  6337. else {
  6338. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6339. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6340. int money = RFIFOL(fd,info->pos[1]);
  6341. if(sd->status.account_id == aid){
  6342. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6343. clif_bank_deposit( *sd, reason );
  6344. }
  6345. }
  6346. }
  6347. /*
  6348. * Acknowledge of withdrawing some money from bank
  6349. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6350. */
  6351. void clif_bank_withdraw( map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6352. #if PACKETVER >= 20130717
  6353. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6354. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6355. p.reason = reason;
  6356. p.money = sd.bank_vault;
  6357. p.zeny = sd.status.zeny;
  6358. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6359. #endif
  6360. }
  6361. /*
  6362. * Request Withdrawing some money from bank
  6363. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6364. */
  6365. void clif_parse_BankWithdraw(int fd, map_session_data* sd) {
  6366. nullpo_retv(sd);
  6367. if( !battle_config.feature_banking ) {
  6368. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6369. return;
  6370. }
  6371. else {
  6372. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6373. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6374. int money = RFIFOL(fd,info->pos[1]);
  6375. if(sd->status.account_id == aid){
  6376. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6377. clif_bank_withdraw( *sd, reason );
  6378. }
  6379. }
  6380. }
  6381. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6382. /// 0125 <index>.W <amount>.L
  6383. void clif_cart_delitem(map_session_data *sd,int n,int amount)
  6384. {
  6385. int fd;
  6386. nullpo_retv(sd);
  6387. fd=sd->fd;
  6388. WFIFOHEAD(fd,packet_len(0x125));
  6389. WFIFOW(fd,0)=0x125;
  6390. WFIFOW(fd,2)=n+2;
  6391. WFIFOL(fd,4)=amount;
  6392. WFIFOSET(fd,packet_len(0x125));
  6393. }
  6394. /// Opens the shop creation menu (ZC_OPENSTORE).
  6395. /// 012d <num>.W
  6396. /// num:
  6397. /// number of allowed item slots
  6398. void clif_openvendingreq(map_session_data* sd, int num)
  6399. {
  6400. int fd;
  6401. nullpo_retv(sd);
  6402. fd = sd->fd;
  6403. WFIFOHEAD(fd,packet_len(0x12d));
  6404. WFIFOW(fd,0) = 0x12d;
  6405. WFIFOW(fd,2) = num;
  6406. WFIFOSET(fd,packet_len(0x12d));
  6407. }
  6408. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6409. /// 0131 <owner id>.L <message>.80B
  6410. void clif_showvendingboard( map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6411. if( tbl == nullptr ){
  6412. tbl = &sd.bl;
  6413. target = AREA_WOS;
  6414. }
  6415. struct PACKET_ZC_STORE_ENTRY p = {};
  6416. p.packetType = HEADER_ZC_STORE_ENTRY;
  6417. p.makerAID = sd.status.account_id;
  6418. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6419. clif_send( &p, sizeof( p ), tbl, target );
  6420. }
  6421. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6422. /// 0132 <owner id>.L
  6423. void clif_closevendingboard(struct block_list* bl, int fd)
  6424. {
  6425. unsigned char buf[16];
  6426. nullpo_retv(bl);
  6427. WBUFW(buf,0) = 0x132;
  6428. WBUFL(buf,2) = bl->id;
  6429. if( session_isActive(fd) ) {
  6430. WFIFOHEAD(fd,packet_len(0x132));
  6431. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6432. WFIFOSET(fd,packet_len(0x132));
  6433. } else {
  6434. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6435. }
  6436. }
  6437. /// Sends a list of items in a shop.
  6438. /// 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)
  6439. /// 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)
  6440. void clif_vendinglist( map_session_data* sd, map_session_data* vsd ){
  6441. nullpo_retv( sd );
  6442. nullpo_retv( vsd );
  6443. nullpo_retv( vsd->vending );
  6444. int fd = sd->fd;
  6445. if( !session_isActive( fd ) ){
  6446. return;
  6447. }
  6448. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6449. WFIFOHEAD( fd, len );
  6450. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6451. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6452. p->packetLength = len;
  6453. p->AID = vsd->status.account_id;
  6454. #if PACKETVER >= 20100105
  6455. p->venderId = vsd->vender_id;
  6456. #endif
  6457. for( int i = 0; i < vsd->vend_num; i++ ){
  6458. int index = vsd->vending[i].index;
  6459. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6460. p->items[i].price = vsd->vending[i].value;
  6461. p->items[i].amount = vsd->vending[i].amount;
  6462. p->items[i].index = client_index( index );
  6463. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6464. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6465. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6466. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6467. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6468. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6469. #if PACKETVER >= 20150226
  6470. clif_add_random_options( p->items[i].option_data, vsd->cart.u.items_cart[index] );
  6471. #if PACKETVER >= 20160921
  6472. p->items[i].location = pc_equippoint_sub( sd, data );
  6473. p->items[i].viewSprite = data->look;
  6474. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6475. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6476. #endif
  6477. #endif
  6478. #endif
  6479. }
  6480. WFIFOSET( fd, len );
  6481. }
  6482. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6483. /// 0135 <index>.W <amount>.W <result>.B
  6484. /// result:
  6485. /// 0 = success
  6486. /// 1 = not enough zeny
  6487. /// 2 = overweight
  6488. /// 4 = out of stock
  6489. /// 5 = "cannot use an npc shop while in a trade"
  6490. /// 6 = Because the store information was incorrect the item was not purchased.
  6491. /// 7 = No sales information.
  6492. void clif_buyvending(map_session_data* sd, int index, int amount, int fail)
  6493. {
  6494. int fd;
  6495. nullpo_retv(sd);
  6496. fd = sd->fd;
  6497. WFIFOHEAD(fd,packet_len(0x135));
  6498. WFIFOW(fd,0) = 0x135;
  6499. WFIFOW(fd,2) = index+2;
  6500. WFIFOW(fd,4) = amount;
  6501. WFIFOB(fd,6) = fail;
  6502. WFIFOSET(fd,packet_len(0x135));
  6503. }
  6504. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6505. /// 0a28 <Result>.B
  6506. /// result:
  6507. /// 0 = Successed
  6508. /// 1 = Failed
  6509. void clif_openvending_ack(map_session_data* sd, int result)
  6510. {
  6511. int fd;
  6512. nullpo_retv(sd);
  6513. fd = sd->fd;
  6514. WFIFOHEAD(fd, 3);
  6515. WFIFOW(fd,0) = 0xa28;
  6516. WFIFOB(fd,2) = result;
  6517. WFIFOSET(fd, 3);
  6518. }
  6519. /// Shop creation success.
  6520. /// 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)
  6521. void clif_openvending( map_session_data* sd, int id, struct s_vending* vending ){
  6522. nullpo_retv( sd );
  6523. nullpo_retv( vending );
  6524. int fd = sd->fd;
  6525. if( !session_isActive( fd ) ){
  6526. return;
  6527. }
  6528. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6529. WFIFOHEAD( fd, len );
  6530. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6531. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6532. p->packetLength = len;
  6533. p->AID = id;
  6534. for( int i = 0; i < sd->vend_num; i++ ) {
  6535. int index = vending[i].index;
  6536. p->items[i].price = vending[i].value;
  6537. p->items[i].index = client_index( index );
  6538. p->items[i].amount = vending[i].amount;
  6539. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6540. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6541. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6542. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6543. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6544. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6545. #if PACKETVER >= 20150226
  6546. clif_add_random_options( p->items[i].option_data, sd->cart.u.items_cart[index] );
  6547. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6548. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6549. #endif
  6550. #endif
  6551. }
  6552. WFIFOSET( fd, len );
  6553. #if PACKETVER >= 20141022
  6554. /// 0 = Successed
  6555. /// 1 = Failed
  6556. clif_openvending_ack( sd, 0 );
  6557. #endif
  6558. }
  6559. /// Inform merchant that someone has bought an item.
  6560. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6561. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6562. void clif_vendingreport(map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6563. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6564. const int cmd = 0x137;
  6565. #else
  6566. const int cmd = 0x9e5;
  6567. #endif
  6568. int fd = sd->fd;
  6569. nullpo_retv(sd);
  6570. WFIFOHEAD(fd,packet_len(cmd));
  6571. WFIFOW(fd,0) = cmd;
  6572. WFIFOW(fd,2) = index+2;
  6573. WFIFOW(fd,4) = amount;
  6574. #if PACKETVER >= 20141016
  6575. WFIFOL(fd,6) = char_id; // GID
  6576. WFIFOL(fd,10) = (int)time(NULL); // Date
  6577. WFIFOL(fd,14) = zeny; // zeny
  6578. #endif
  6579. WFIFOSET(fd,packet_len(cmd));
  6580. }
  6581. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6582. /// 00fa <result>.B
  6583. /// result:
  6584. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6585. /// 1 = MsgStringTable[78]="party name already exists"
  6586. /// 2 = MsgStringTable[79]="already in a party"
  6587. /// 3 = cannot organize parties on this map
  6588. /// ? = nothing
  6589. void clif_party_created( map_session_data& sd, int result ){
  6590. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6591. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6592. p.result = result;
  6593. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6594. }
  6595. /// Adds new member to a party.
  6596. /// 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)
  6597. /// 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)
  6598. /// 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)
  6599. /// role:
  6600. /// 0 = leader
  6601. /// 1 = normal
  6602. /// state:
  6603. /// 0 = connected
  6604. /// 1 = disconnected
  6605. void clif_party_member_info( struct party_data& party, map_session_data& sd ){
  6606. int id = party_getmemberid( &party, &sd );
  6607. if( id < 0 ){
  6608. return;
  6609. }
  6610. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6611. p.packetType = partymemberinfo;
  6612. p.AID = sd.status.account_id;
  6613. #if PACKETVER >= 20171207
  6614. p.GID = sd.status.char_id;
  6615. #endif
  6616. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6617. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6618. p.class_ = sd.status.class_;
  6619. p.baseLevel = sd.status.base_level;
  6620. #endif
  6621. p.x = sd.bl.x;
  6622. p.y = sd.bl.y;
  6623. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6624. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6625. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6626. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6627. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6628. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6629. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6630. }
  6631. /// Sends party information (ZC_GROUP_LIST).
  6632. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6633. /// role:
  6634. /// 0 = leader
  6635. /// 1 = normal
  6636. /// state:
  6637. /// 0 = connected
  6638. /// 1 = disconnected
  6639. /// 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
  6640. void clif_party_info( struct party_data& party, map_session_data* sd ){
  6641. send_target target;
  6642. if( sd == nullptr ){
  6643. sd = party_getavailablesd( &party );
  6644. if( sd == nullptr ){
  6645. // Nobody is online to notify
  6646. return;
  6647. }
  6648. // Send to whole party
  6649. target = PARTY;
  6650. }else{
  6651. // Send only to self
  6652. target = SELF;
  6653. }
  6654. struct PACKET_ZC_GROUP_LIST* p = (struct PACKET_ZC_GROUP_LIST*)packet_buffer;
  6655. p->packetType = partyinfo;
  6656. p->packetLen = sizeof( *p );
  6657. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6658. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6659. struct party_member& m = party.party.member[i];
  6660. if( m.account_id == 0 ){
  6661. continue;
  6662. }
  6663. struct PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6664. member.AID = m.account_id;
  6665. #if PACKETVER >= 20171207
  6666. member.GID = m.char_id;
  6667. #endif
  6668. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6669. mapindex_getmapname_ext( mapindex_id2name( m.map ), member.mapName );
  6670. member.leader = ( m.leader ) ? 0 : 1;
  6671. member.offline = ( m.online ) ? 0 : 1;
  6672. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6673. member.class_ = m.class_;
  6674. member.baseLevel = m.lv;
  6675. #endif
  6676. c++;
  6677. p->packetLen += sizeof( member );
  6678. }
  6679. clif_send( p, p->packetLen, &sd->bl, target );
  6680. }
  6681. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6682. /// 02c9 <flag>.B
  6683. /// flag:
  6684. /// 0 = allow party invites
  6685. /// 1 = auto-deny party invites
  6686. void clif_partyinvitationstate( map_session_data& sd ){
  6687. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6688. struct PACKET_ZC_PARTY_CONFIG p = {};
  6689. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6690. p.denyPartyInvites = 0; // TODO: not implemented
  6691. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6692. #endif
  6693. }
  6694. /// Party invitation request.
  6695. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6696. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6697. void clif_party_invite( map_session_data& sd, map_session_data& tsd ){
  6698. struct party_data* party = party_search( sd.status.party_id );
  6699. if( party == nullptr ){
  6700. return;
  6701. }
  6702. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6703. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6704. p.GRID = party->party.party_id;
  6705. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6706. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6707. }
  6708. /// Party invite result.
  6709. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6710. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6711. /// result=0 : char is already in a party -> MsgStringTable[80]
  6712. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6713. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6714. /// result=3 : party is full -> MsgStringTable[83]
  6715. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6716. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6717. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6718. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6719. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6720. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6721. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6722. void clif_party_invite_reply( map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6723. #if PACKETVER < 20070904
  6724. if( reply == PARTY_REPLY_OFFLINE ){
  6725. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6726. return;
  6727. }
  6728. #endif
  6729. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6730. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6731. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6732. p.result = reply;
  6733. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6734. }
  6735. /// Updates party settings.
  6736. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6737. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6738. /// exp option:
  6739. /// 0 = exp sharing disabled
  6740. /// 1 = exp sharing enabled
  6741. /// 2 = cannot change exp sharing
  6742. ///
  6743. /// flag:
  6744. /// 0 = send to party
  6745. /// 1 = send to sd
  6746. void clif_party_option(struct party_data *p,map_session_data *sd,int flag)
  6747. {
  6748. unsigned char buf[16];
  6749. #if PACKETVER < 20090603
  6750. const int cmd = 0x101;
  6751. #else
  6752. const int cmd = 0x7d8;
  6753. #endif
  6754. nullpo_retv(p);
  6755. if(!sd && flag==0){
  6756. int i;
  6757. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6758. if (i < MAX_PARTY)
  6759. sd = p->data[i].sd;
  6760. }
  6761. if(!sd) return;
  6762. WBUFW(buf,0)=cmd;
  6763. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6764. #if PACKETVER >= 20090603
  6765. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6766. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6767. #endif
  6768. if(flag==0)
  6769. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6770. else
  6771. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6772. }
  6773. /**
  6774. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6775. * @param sd Send the notification for this player
  6776. * @param account_id Account ID of kicked member
  6777. * @param name Name of kicked member
  6778. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6779. * @param target Send target
  6780. **/
  6781. void clif_party_withdraw( map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6782. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6783. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6784. p.AID = account_id;
  6785. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6786. p.result = result;
  6787. clif_send( &p, sizeof( p ), &sd.bl, target );
  6788. }
  6789. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6790. /// 0109 <packet len>.W <account id>.L <message>.?B
  6791. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, int len ){
  6792. map_session_data* sd = party_getavailablesd( &party );
  6793. if( sd == nullptr ){
  6794. return;
  6795. }
  6796. if (len > CHAT_SIZE_MAX) {
  6797. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6798. len = CHAT_SIZE_MAX;
  6799. }
  6800. struct PACKET_ZC_NOTIFY_CHAT_PARTY* p = (struct PACKET_ZC_NOTIFY_CHAT_PARTY*)packet_buffer;
  6801. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6802. p->PacketLength = sizeof( *p ) + len;
  6803. p->AID = account_id;
  6804. safestrncpy( p->chatMsg, mes, len );
  6805. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6806. }
  6807. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6808. /// 0107 <account id>.L <x>.W <y>.W
  6809. void clif_party_xy( map_session_data& sd ){
  6810. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6811. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6812. p.AID = sd.status.account_id;
  6813. p.xPos = sd.bl.x;
  6814. p.yPos = sd.bl.y;
  6815. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6816. }
  6817. /*==========================================
  6818. * Sends x/y dot to a single fd. [Skotlex]
  6819. *------------------------------------------*/
  6820. void clif_party_xy_single( map_session_data& sd, map_session_data& tsd ){
  6821. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6822. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6823. p.AID = sd.status.account_id;
  6824. p.xPos = sd.bl.x;
  6825. p.yPos = sd.bl.y;
  6826. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6827. }
  6828. /// Updates HP bar of a party member.
  6829. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6830. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6831. void clif_party_hp( map_session_data& sd ){
  6832. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6833. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6834. p.AID = sd.status.account_id;
  6835. #if PACKETVER < 20100119
  6836. // To correctly display the %hp bar. [Skotlex]
  6837. if( sd.battle_status.max_hp > INT16_MAX ){
  6838. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6839. p.maxhp = 100;
  6840. }else{
  6841. p.hp = sd.battle_status.hp;
  6842. p.maxhp = sd.battle_status.max_hp;
  6843. }
  6844. #else
  6845. p.hp = sd.battle_status.hp;
  6846. p.maxhp = sd.battle_status.max_hp;
  6847. #endif
  6848. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6849. }
  6850. /// Notifies the party members of a character's death or revival.
  6851. /// 0AB2 <GID>.L <dead>.B
  6852. void clif_party_dead( map_session_data& sd ){
  6853. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6854. struct PACKET_ZC_GROUP_ISALIVE p = {};
  6855. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6856. p.AID = sd.status.account_id;
  6857. p.isDead = pc_isdead( &sd );
  6858. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6859. #endif
  6860. }
  6861. /// Updates the job and level of a party member
  6862. /// 0abd <account id>.L <job>.W <level>.W
  6863. void clif_party_job_and_level( map_session_data& sd ){
  6864. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  6865. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  6866. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  6867. p.AID = sd.status.account_id;
  6868. p.job = sd.status.class_;
  6869. p.level = sd.status.base_level;
  6870. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6871. #endif
  6872. }
  6873. /*==========================================
  6874. * Sends HP bar to a single fd. [Skotlex]
  6875. *------------------------------------------*/
  6876. void clif_hpmeter_single( map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  6877. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6878. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6879. p.AID = id;
  6880. #if PACKETVER < 20100119
  6881. // To correctly display the %hp bar. [Skotlex]
  6882. if( maxhp > INT16_MAX ){
  6883. p.hp = hp / ( maxhp / 100 );
  6884. p.maxhp = 100;
  6885. }else{
  6886. p.hp = hp;
  6887. p.maxhp = maxhp;
  6888. }
  6889. #else
  6890. p.hp = hp;
  6891. p.maxhp = maxhp;
  6892. #endif
  6893. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6894. }
  6895. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6896. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6897. void clif_movetoattack(map_session_data *sd,struct block_list *bl)
  6898. {
  6899. int fd;
  6900. nullpo_retv(sd);
  6901. nullpo_retv(bl);
  6902. fd=sd->fd;
  6903. WFIFOHEAD(fd,packet_len(0x139));
  6904. WFIFOW(fd, 0)=0x139;
  6905. WFIFOL(fd, 2)=bl->id;
  6906. WFIFOW(fd, 6)=bl->x;
  6907. WFIFOW(fd, 8)=bl->y;
  6908. WFIFOW(fd,10)=sd->bl.x;
  6909. WFIFOW(fd,12)=sd->bl.y;
  6910. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6911. WFIFOSET(fd,packet_len(0x139));
  6912. }
  6913. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6914. /// 018f <result>.W <name id>.W
  6915. /// result:
  6916. /// 0 = success
  6917. /// 1 = failure
  6918. /// 2 = success (alchemist)
  6919. /// 3 = failure (alchemist)
  6920. void clif_produceeffect(map_session_data* sd,int flag, t_itemid nameid){
  6921. nullpo_retv( sd );
  6922. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6923. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6924. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6925. p.result = flag;
  6926. p.itemId = client_nameid( nameid );
  6927. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6928. }
  6929. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6930. /// 019e
  6931. void clif_catch_process(map_session_data *sd)
  6932. {
  6933. int fd;
  6934. nullpo_retv(sd);
  6935. fd=sd->fd;
  6936. WFIFOHEAD(fd,packet_len(0x19e));
  6937. WFIFOW(fd,0)=0x19e;
  6938. WFIFOSET(fd,packet_len(0x19e));
  6939. }
  6940. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6941. /// 01a0 <result>.B
  6942. /// 0 = failure
  6943. /// 1 = success
  6944. void clif_pet_roulette(map_session_data *sd,int data)
  6945. {
  6946. int fd;
  6947. nullpo_retv(sd);
  6948. fd=sd->fd;
  6949. WFIFOHEAD(fd,packet_len(0x1a0));
  6950. WFIFOW(fd,0)=0x1a0;
  6951. WFIFOB(fd,2)=data;
  6952. WFIFOSET(fd,packet_len(0x1a0));
  6953. }
  6954. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6955. /// 01a6 <packet len>.W { <index>.W }*
  6956. void clif_sendegg(map_session_data *sd)
  6957. {
  6958. int i,n=0,fd;
  6959. nullpo_retv(sd);
  6960. fd=sd->fd;
  6961. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6962. clif_displaymessage(fd, msg_txt(sd,666));
  6963. return;
  6964. }
  6965. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6966. WFIFOW(fd,0)=0x1a6;
  6967. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6968. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  6969. sd->inventory_data[i]->type != IT_PETEGG ||
  6970. sd->inventory.u.items_inventory[i].amount <= 0)
  6971. continue;
  6972. WFIFOW(fd,n*2+4)=client_index(i);
  6973. n++;
  6974. }
  6975. WFIFOW(fd,2)=4+n*2;
  6976. WFIFOSET(fd,WFIFOW(fd,2));
  6977. sd->menuskill_id = SA_TAMINGMONSTER;
  6978. sd->menuskill_val = -1;
  6979. }
  6980. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6981. /// 01a4 <type>.B <id>.L <data>.L
  6982. /// type:
  6983. /// 0 = pre-init (data = 0)
  6984. /// 1 = intimacy (data = 0~4)
  6985. /// 2 = hunger (data = 0~4)
  6986. /// 3 = accessory
  6987. /// 4 = performance (data = 1~3: normal, 4: special)
  6988. /// 5 = hairstyle
  6989. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6990. ///
  6991. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6992. void clif_send_petdata(map_session_data* sd, struct pet_data* pd, int type, int param)
  6993. {
  6994. uint8 buf[16];
  6995. nullpo_retv(pd);
  6996. WBUFW(buf,0) = 0x1a4;
  6997. WBUFB(buf,2) = type;
  6998. WBUFL(buf,3) = pd->bl.id;
  6999. WBUFL(buf,7) = param;
  7000. if (sd)
  7001. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7002. else
  7003. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7004. }
  7005. /// Pet's base data (ZC_PROPERTY_PET).
  7006. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7007. void clif_send_petstatus(map_session_data *sd)
  7008. {
  7009. int fd;
  7010. struct s_pet *pet;
  7011. nullpo_retv(sd);
  7012. nullpo_retv(sd->pd);
  7013. fd=sd->fd;
  7014. pet = &sd->pd->pet;
  7015. WFIFOHEAD(fd,packet_len(0x1a2));
  7016. WFIFOW(fd,0)=0x1a2;
  7017. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7018. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7019. WFIFOW(fd,27)=pet->level;
  7020. WFIFOW(fd,29)=pet->hungry;
  7021. WFIFOW(fd,31)=pet->intimate;
  7022. WFIFOW(fd,33)=pet->equip;
  7023. #if PACKETVER >= 20081126
  7024. WFIFOW(fd,35)=pet->class_;
  7025. #endif
  7026. WFIFOSET(fd,packet_len(0x1a2));
  7027. }
  7028. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7029. /// 01aa <id>.L <data>.L
  7030. /// data:
  7031. /// @see CZ_PET_ACT.
  7032. void clif_pet_emotion(struct pet_data *pd,int param)
  7033. {
  7034. unsigned char buf[16];
  7035. nullpo_retv(pd);
  7036. memset(buf,0,packet_len(0x1aa));
  7037. WBUFW(buf,0)=0x1aa;
  7038. WBUFL(buf,2)=pd->bl.id;
  7039. WBUFL(buf,6)=param;
  7040. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7041. }
  7042. /// Result of request to feed a pet (ZC_FEED_PET).
  7043. /// 01a3 <result>.B <name id>.W
  7044. /// result:
  7045. /// 0 = failure
  7046. /// 1 = success
  7047. void clif_pet_food( map_session_data *sd, int foodid,int fail ){
  7048. nullpo_retv( sd );
  7049. struct PACKET_ZC_FEED_PET p;
  7050. p.packetType = 0x1a3;
  7051. p.result = fail;
  7052. p.itemId = client_nameid( foodid );
  7053. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7054. }
  7055. /// Send pet auto feed info.
  7056. void clif_pet_autofeed_status(map_session_data* sd, bool force) {
  7057. #if PACKETVER >= 20141008
  7058. nullpo_retv(sd);
  7059. if (force || battle_config.pet_autofeed_always) {
  7060. // Always send ON or OFF
  7061. if (sd->pd && battle_config.feature_pet_autofeed) {
  7062. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7063. }
  7064. else {
  7065. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7066. }
  7067. }
  7068. else {
  7069. // Only send when enabled
  7070. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7071. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7072. }
  7073. }
  7074. #endif
  7075. }
  7076. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7077. /// 01cd { <skill id>.L }*7
  7078. void clif_autospell(map_session_data *sd,uint16 skill_lv)
  7079. {
  7080. nullpo_retv(sd);
  7081. int fd = sd->fd;
  7082. #ifdef RENEWAL
  7083. uint16 autospell_skill[][2] = {
  7084. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7085. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7086. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7087. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7088. };
  7089. int count = 0;
  7090. WFIFOHEAD(fd, 2 * 6 + 4);
  7091. WFIFOW(fd, 0) = 0x442;
  7092. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7093. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7094. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7095. count++;
  7096. }
  7097. }
  7098. WFIFOW(fd, 2) = 8 + count * 2;
  7099. WFIFOL(fd, 4) = count;
  7100. WFIFOSET(fd, WFIFOW(fd, 2));
  7101. #else
  7102. WFIFOHEAD(fd,packet_len(0x1cd));
  7103. WFIFOW(fd, 0)=0x1cd;
  7104. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7105. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7106. else
  7107. WFIFOL(fd,2)= 0x00000000;
  7108. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7109. WFIFOL(fd,6)= MG_COLDBOLT;
  7110. else
  7111. WFIFOL(fd,6)= 0x00000000;
  7112. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7113. WFIFOL(fd,10)= MG_FIREBOLT;
  7114. else
  7115. WFIFOL(fd,10)= 0x00000000;
  7116. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7117. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7118. else
  7119. WFIFOL(fd,14)= 0x00000000;
  7120. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7121. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7122. else
  7123. WFIFOL(fd,18)= 0x00000000;
  7124. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7125. WFIFOL(fd,22)= MG_FIREBALL;
  7126. else
  7127. WFIFOL(fd,22)= 0x00000000;
  7128. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7129. WFIFOL(fd,26)= MG_FROSTDIVER;
  7130. else
  7131. WFIFOL(fd,26)= 0x00000000;
  7132. WFIFOSET(fd,packet_len(0x1cd));
  7133. #endif
  7134. sd->menuskill_id = SA_AUTOSPELL;
  7135. sd->menuskill_val = skill_lv;
  7136. }
  7137. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7138. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7139. void clif_devotion(struct block_list *src, map_session_data *tsd)
  7140. {
  7141. unsigned char buf[56];
  7142. nullpo_retv(src);
  7143. memset(buf,0,packet_len(0x1cf));
  7144. WBUFW(buf,0) = 0x1cf;
  7145. WBUFL(buf,2) = src->id;
  7146. if( src->type == BL_MER )
  7147. {
  7148. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7149. if( md && md->master && md->devotion_flag )
  7150. WBUFL(buf,6) = md->master->bl.id;
  7151. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7152. }
  7153. else
  7154. {
  7155. int i;
  7156. map_session_data *sd = BL_CAST(BL_PC,src);
  7157. if( sd == NULL )
  7158. return;
  7159. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7160. WBUFL(buf,6+4*i) = sd->devotion[i];
  7161. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7162. }
  7163. if( tsd )
  7164. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7165. else
  7166. clif_send(buf, packet_len(0x1cf), src, AREA);
  7167. }
  7168. /// Notifies the client of an object's spirits.
  7169. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7170. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7171. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7172. nullpo_retv( bl );
  7173. struct PACKET_ZC_SPIRITS p = {};
  7174. p.PacketType = HEADER_ZC_SPIRITS;
  7175. p.AID = bl->id;
  7176. switch( bl->type ){
  7177. case BL_PC:
  7178. p.num = ( (map_session_data*)bl )->spiritball;
  7179. break;
  7180. case BL_HOM:
  7181. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7182. break;
  7183. }
  7184. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7185. }
  7186. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7187. /// 01d2 <account id>.L <delay>.L
  7188. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7189. {
  7190. unsigned char buf[32];
  7191. nullpo_retv(bl);
  7192. WBUFW(buf,0)=0x1d2;
  7193. WBUFL(buf,2)=bl->id;
  7194. WBUFL(buf,6)=client_tick(wait);
  7195. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7196. }
  7197. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7198. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7199. /// flag:
  7200. /// 0 = inactive
  7201. /// 1 = active
  7202. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7203. {
  7204. unsigned char buf[32];
  7205. nullpo_retv(src);
  7206. WBUFW(buf,0)=0x1d1;
  7207. WBUFL(buf,2)=src->id;
  7208. WBUFL(buf,6)=dst_id;
  7209. WBUFL(buf,10)=active;
  7210. clif_send(buf,packet_len(0x1d1),src,AREA);
  7211. }
  7212. /// MVP effect (ZC_MVP).
  7213. /// 010c <account id>.L
  7214. void clif_mvp_effect(map_session_data *sd)
  7215. {
  7216. unsigned char buf[16];
  7217. nullpo_retv(sd);
  7218. WBUFW(buf,0)=0x10c;
  7219. WBUFL(buf,2)=sd->bl.id;
  7220. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7221. }
  7222. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7223. /// 010a <name id>.W
  7224. void clif_mvp_item( map_session_data *sd, t_itemid nameid ){
  7225. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7226. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7227. p.itemId = client_nameid( nameid );
  7228. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7229. }
  7230. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7231. /// 010b <exp>.L
  7232. void clif_mvp_exp(map_session_data *sd, t_exp exp) {
  7233. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7234. if (battle_config.mvp_exp_reward_message) {
  7235. char e_msg[CHAT_SIZE_MAX];
  7236. sprintf(e_msg, msg_txt(sd, 717), exp);
  7237. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7238. }
  7239. #else
  7240. int fd;
  7241. nullpo_retv(sd);
  7242. fd = sd->fd;
  7243. WFIFOHEAD(fd, packet_len(0x10b));
  7244. WFIFOW(fd,0) = 0x10b;
  7245. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7246. WFIFOSET(fd, packet_len(0x10b));
  7247. #endif
  7248. }
  7249. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7250. /// 010d
  7251. ///
  7252. /// "You are the MVP, but cannot obtain the reward because
  7253. /// you are overweight."
  7254. void clif_mvp_noitem(map_session_data* sd)
  7255. {
  7256. int fd = sd->fd;
  7257. WFIFOHEAD(fd,packet_len(0x10d));
  7258. WFIFOW(fd,0) = 0x10d;
  7259. WFIFOSET(fd,packet_len(0x10d));
  7260. }
  7261. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7262. /// 0167 <result>.B
  7263. /// result:
  7264. /// 0 = "Guild has been created."
  7265. /// 1 = "You are already in a Guild."
  7266. /// 2 = "That Guild Name already exists."
  7267. /// 3 = "You need the neccessary item to create a Guild."
  7268. void clif_guild_created(map_session_data *sd,int flag)
  7269. {
  7270. int fd;
  7271. nullpo_retv(sd);
  7272. fd=sd->fd;
  7273. WFIFOHEAD(fd,packet_len(0x167));
  7274. WFIFOW(fd,0)=0x167;
  7275. WFIFOB(fd,2)=flag;
  7276. WFIFOSET(fd,packet_len(0x167));
  7277. }
  7278. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7279. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7280. /// mode:
  7281. /// &0x01 = allow invite
  7282. /// &0x10 = allow expel
  7283. void clif_guild_belonginfo( map_session_data& sd ){
  7284. if( sd.guild == nullptr ){
  7285. return;
  7286. }
  7287. struct guild& guild = *sd.guild;
  7288. int position = guild_getposition( &sd );
  7289. if( position < 0 ){
  7290. return;
  7291. }
  7292. struct PACKET_ZC_UPDATE_GDID p = {};
  7293. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7294. p.guildId = guild.guild_id;
  7295. p.emblemVersion = guild.emblem_id;
  7296. p.mode = guild.position[position].mode;
  7297. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7298. p.interSid = 0; // InterSID (unknown purpose)
  7299. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7300. #if PACKETVER_MAIN_NUM >= 20220216
  7301. p.masterGID = guild.member[0].char_id;
  7302. #endif
  7303. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7304. }
  7305. /// Guild member login notice.
  7306. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7307. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7308. /// status:
  7309. /// 0 = offline
  7310. /// 1 = online
  7311. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7312. {
  7313. unsigned char buf[64];
  7314. map_session_data* sd;
  7315. nullpo_retv(g);
  7316. WBUFW(buf, 0)=0x1f2;
  7317. WBUFL(buf, 2)=g->member[idx].account_id;
  7318. WBUFL(buf, 6)=g->member[idx].char_id;
  7319. WBUFL(buf,10)=flag;
  7320. if( ( sd = g->member[idx].sd ) != NULL )
  7321. {
  7322. WBUFW(buf,14) = sd->status.sex;
  7323. WBUFW(buf,16) = sd->status.hair;
  7324. WBUFW(buf,18) = sd->status.hair_color;
  7325. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7326. }
  7327. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7328. {
  7329. WBUFW(buf,14) = 0;
  7330. WBUFW(buf,16) = 0;
  7331. WBUFW(buf,18) = 0;
  7332. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7333. }
  7334. }
  7335. // Function `clif_guild_memberlogin_notice` sends info about
  7336. // logins and logouts of a guild member to the rest members.
  7337. // But at the 1st time (after a player login or map changing)
  7338. // the client won't show the message.
  7339. // So I suggest use this function for sending "first-time-info"
  7340. // to some player on entering the game or changing location.
  7341. // At next time the client would always show the message.
  7342. // The function sends all the statuses in the single packet
  7343. // to economize traffic. [LuzZza]
  7344. void clif_guild_send_onlineinfo(map_session_data *sd)
  7345. {
  7346. struct guild *g;
  7347. unsigned char buf[14*128];
  7348. int i, count=0, p_len;
  7349. nullpo_retv(sd);
  7350. p_len = packet_len(0x16d);
  7351. if(!(g = sd->guild))
  7352. return;
  7353. for(i=0; i<g->max_member; i++) {
  7354. if(g->member[i].account_id > 0 &&
  7355. g->member[i].account_id != sd->status.account_id) {
  7356. WBUFW(buf,count*p_len) = 0x16d;
  7357. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7358. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7359. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7360. count++;
  7361. }
  7362. }
  7363. clif_send(buf, p_len*count, &sd->bl, SELF);
  7364. }
  7365. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7366. /// 014e <menu flag>.L
  7367. /// menu flag:
  7368. /// 0x00 = Basic Info (always on)
  7369. /// &0x01 = Member manager
  7370. /// &0x02 = Positions
  7371. /// &0x04 = Skills
  7372. /// &0x10 = Expulsion list
  7373. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7374. /// &0x80 = Notice
  7375. void clif_guild_masterormember(map_session_data *sd)
  7376. {
  7377. int fd;
  7378. nullpo_retv(sd);
  7379. fd=sd->fd;
  7380. WFIFOHEAD(fd,packet_len(0x14e));
  7381. WFIFOW(fd,0) = 0x14e;
  7382. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7383. WFIFOSET(fd,packet_len(0x14e));
  7384. }
  7385. /// Guild basic information (Territories [Valaris])
  7386. /// 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)
  7387. /// 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)
  7388. /// 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)
  7389. void clif_guild_basicinfo( map_session_data& sd ){
  7390. if( sd.guild == nullptr ){
  7391. return;
  7392. }
  7393. struct guild& guild = *sd.guild;
  7394. struct PACKET_ZC_GUILD_INFO p = {};
  7395. p.PacketType = HEADER_ZC_GUILD_INFO;
  7396. p.GDID = guild.guild_id;
  7397. p.level = guild.guild_lv;
  7398. p.userNum = guild.connect_member;
  7399. p.maxUserNum = guild.max_member;
  7400. p.userAverageLevel = guild.average_lv;
  7401. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7402. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7403. p.point = 0; // Tax Points
  7404. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7405. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7406. p.emblemVersion = guild.emblem_id;
  7407. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7408. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( &guild ) ), sizeof( p.manageLand ) );
  7409. p.zeny = 0;
  7410. #if PACKETVER >= 20200902
  7411. p.masterGID = guild.member[0].char_id; // leader
  7412. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7413. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7414. p.masterGID = guild.member[0].char_id; // leader
  7415. #else
  7416. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7417. #endif
  7418. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7419. }
  7420. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7421. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7422. void clif_guild_allianceinfo(map_session_data *sd)
  7423. {
  7424. int fd,i,c;
  7425. struct guild *g;
  7426. nullpo_retv(sd);
  7427. if( (g = sd->guild) == NULL )
  7428. return;
  7429. fd = sd->fd;
  7430. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7431. WFIFOW(fd, 0)=0x14c;
  7432. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7433. struct guild_alliance *a=&g->alliance[i];
  7434. if(a->guild_id>0){
  7435. WFIFOL(fd,c*32+4)=a->opposition;
  7436. WFIFOL(fd,c*32+8)=a->guild_id;
  7437. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7438. c++;
  7439. }
  7440. }
  7441. WFIFOW(fd, 2)=c*32+4;
  7442. WFIFOSET(fd,WFIFOW(fd,2));
  7443. }
  7444. /// Guild member manager information
  7445. /// 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)
  7446. /// state:
  7447. /// 0 = offline
  7448. /// 1 = online
  7449. /// memo:
  7450. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7451. /// 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)
  7452. void clif_guild_memberlist( map_session_data& sd ){
  7453. if( sd.guild == nullptr ){
  7454. return;
  7455. }
  7456. struct guild& guild = *sd.guild;
  7457. struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer;
  7458. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7459. p->packetLength = sizeof( *p );
  7460. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7461. struct guild_member& member = guild.member[i];
  7462. if( member.account_id == 0 ){
  7463. continue;
  7464. }
  7465. struct GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7466. member_info.AID = member.account_id;
  7467. member_info.GID = member.char_id;
  7468. member_info.head = member.hair;
  7469. member_info.headPalette = member.hair_color;
  7470. member_info.sex = member.gender;
  7471. member_info.job = member.class_;
  7472. member_info.level = member.lv;
  7473. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7474. member_info.currentState = member.online;
  7475. member_info.positionID = member.position;
  7476. #if PACKETVER >= 20200902
  7477. member_info.lastLoginTime = member.last_login;
  7478. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7479. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7480. member_info.lastLoginTime = member.last_login;
  7481. #else
  7482. 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.
  7483. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7484. #endif
  7485. c++;
  7486. p->packetLength += sizeof( member_info );
  7487. }
  7488. clif_send( p, p->packetLength, &sd.bl, SELF );
  7489. }
  7490. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7491. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7492. void clif_guild_positionnamelist(map_session_data *sd)
  7493. {
  7494. int i,fd;
  7495. struct guild *g;
  7496. nullpo_retv(sd);
  7497. if( (g = sd->guild) == NULL )
  7498. return;
  7499. fd = sd->fd;
  7500. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7501. WFIFOW(fd, 0)=0x166;
  7502. for(i=0;i<MAX_GUILDPOSITION;i++){
  7503. WFIFOL(fd,i*28+4)=i;
  7504. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7505. }
  7506. WFIFOW(fd,2)=i*28+4;
  7507. WFIFOSET(fd,WFIFOW(fd,2));
  7508. }
  7509. /// Guild position information (ZC_POSITION_INFO).
  7510. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7511. /// mode:
  7512. /// &0x01 = allow invite
  7513. /// &0x10 = allow expel
  7514. /// ranking:
  7515. /// TODO
  7516. void clif_guild_positioninfolist(map_session_data *sd)
  7517. {
  7518. int i,fd;
  7519. struct guild *g;
  7520. nullpo_retv(sd);
  7521. if( (g = sd->guild) == NULL )
  7522. return;
  7523. fd = sd->fd;
  7524. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7525. WFIFOW(fd, 0)=0x160;
  7526. for(i=0;i<MAX_GUILDPOSITION;i++){
  7527. struct guild_position *p=&g->position[i];
  7528. WFIFOL(fd,i*16+ 4)=i;
  7529. WFIFOL(fd,i*16+ 8)=p->mode;
  7530. WFIFOL(fd,i*16+12)=i;
  7531. WFIFOL(fd,i*16+16)=p->exp_mode;
  7532. }
  7533. WFIFOW(fd, 2)=i*16+4;
  7534. WFIFOSET(fd,WFIFOW(fd,2));
  7535. }
  7536. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7537. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7538. /// mode:
  7539. /// &0x01 = allow invite
  7540. /// &0x10 = allow expel
  7541. /// ranking:
  7542. /// TODO
  7543. void clif_guild_positionchanged(struct guild *g,int idx)
  7544. {
  7545. // FIXME: This packet is intended to update the clients after a
  7546. // commit of position info changes, not sending one packet per
  7547. // position.
  7548. map_session_data *sd;
  7549. unsigned char buf[128];
  7550. nullpo_retv(g);
  7551. WBUFW(buf, 0)=0x174;
  7552. WBUFW(buf, 2)=44; // packet len
  7553. // GUILD_REG_POSITION_INFO{
  7554. WBUFL(buf, 4)=idx;
  7555. WBUFL(buf, 8)=g->position[idx].mode;
  7556. WBUFL(buf,12)=idx;
  7557. WBUFL(buf,16)=g->position[idx].exp_mode;
  7558. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7559. // }*
  7560. if( (sd=guild_getavailablesd(g))!=NULL )
  7561. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7562. }
  7563. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7564. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7565. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7566. {
  7567. // FIXME: This packet is intended to update the clients after a
  7568. // commit of member position assignment changes, not sending one
  7569. // packet per position.
  7570. map_session_data *sd;
  7571. unsigned char buf[64];
  7572. nullpo_retv(g);
  7573. WBUFW(buf, 0)=0x156;
  7574. WBUFW(buf, 2)=16; // packet len
  7575. // MEMBER_POSITION_INFO{
  7576. WBUFL(buf, 4)=g->member[idx].account_id;
  7577. WBUFL(buf, 8)=g->member[idx].char_id;
  7578. WBUFL(buf,12)=g->member[idx].position;
  7579. // }*
  7580. if( (sd=guild_getavailablesd(g))!=NULL )
  7581. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7582. }
  7583. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7584. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7585. void clif_guild_emblem(map_session_data *sd,struct guild *g)
  7586. {
  7587. int fd;
  7588. nullpo_retv(sd);
  7589. nullpo_retv(g);
  7590. fd = sd->fd;
  7591. if( g->emblem_len <= 0 )
  7592. return;
  7593. WFIFOHEAD(fd,g->emblem_len+12);
  7594. WFIFOW(fd,0)=0x152;
  7595. WFIFOW(fd,2)=g->emblem_len+12;
  7596. WFIFOL(fd,4)=g->guild_id;
  7597. WFIFOL(fd,8)=g->emblem_id;
  7598. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7599. WFIFOSET(fd,WFIFOW(fd,2));
  7600. }
  7601. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7602. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7603. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7604. void clif_guild_emblem_area(struct block_list* bl)
  7605. {
  7606. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7607. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7608. PACKET_ZC_CHANGE_GUILD p{};
  7609. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7610. p.guild_id = status_get_guild_id(bl);
  7611. p.emblem_id = status_get_emblem_id(bl);
  7612. #if PACKETVER < 20190724
  7613. p.aid = bl->id;
  7614. #else
  7615. p.unknown = 0;
  7616. #endif
  7617. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7618. }
  7619. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7620. /// 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 }*
  7621. void clif_guild_skillinfo(map_session_data* sd)
  7622. {
  7623. int fd;
  7624. struct guild* g;
  7625. int i,c;
  7626. nullpo_retv(sd);
  7627. if( (g = sd->guild) == NULL )
  7628. return;
  7629. fd = sd->fd;
  7630. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7631. WFIFOW(fd,0) = 0x0162;
  7632. WFIFOW(fd,4) = g->skill_point;
  7633. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7634. {
  7635. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7636. {
  7637. int id = g->skill[i].id;
  7638. int p = 6 + c*37;
  7639. WFIFOW(fd,p+0) = id;
  7640. WFIFOL(fd,p+2) = skill_get_inf(id);
  7641. WFIFOW(fd,p+6) = g->skill[i].lv;
  7642. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7643. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7644. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7645. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7646. c++;
  7647. }
  7648. }
  7649. WFIFOW(fd,2) = 6 + c*37;
  7650. WFIFOSET(fd,WFIFOW(fd,2));
  7651. }
  7652. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7653. /// 016f <subject>.60B <notice>.120B
  7654. void clif_guild_notice(map_session_data* sd)
  7655. {
  7656. struct guild* g;
  7657. nullpo_retv(sd);
  7658. nullpo_retv(g = sd->guild);
  7659. int fd = sd->fd;
  7660. if ( !session_isActive(fd) )
  7661. return;
  7662. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7663. return;
  7664. WFIFOHEAD(fd,packet_len(0x16f));
  7665. WFIFOW(fd,0) = 0x16f;
  7666. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7667. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7668. WFIFOSET(fd,packet_len(0x16f));
  7669. }
  7670. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7671. /// 016a <guild id>.L <guild name>.24B
  7672. void clif_guild_invite(map_session_data *sd,struct guild *g)
  7673. {
  7674. int fd;
  7675. nullpo_retv(sd);
  7676. nullpo_retv(g);
  7677. fd=sd->fd;
  7678. WFIFOHEAD(fd,packet_len(0x16a));
  7679. WFIFOW(fd,0)=0x16a;
  7680. WFIFOL(fd,2)=g->guild_id;
  7681. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7682. WFIFOSET(fd,packet_len(0x16a));
  7683. }
  7684. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7685. /// 0169 <answer>.B
  7686. /// answer:
  7687. /// 0 = Already in guild.
  7688. /// 1 = Offer rejected.
  7689. /// 2 = Offer accepted.
  7690. /// 3 = Guild full.
  7691. void clif_guild_inviteack(map_session_data *sd,int flag)
  7692. {
  7693. int fd;
  7694. nullpo_retv(sd);
  7695. fd=sd->fd;
  7696. WFIFOHEAD(fd,packet_len(0x169));
  7697. WFIFOW(fd,0)=0x169;
  7698. WFIFOB(fd,2)=flag;
  7699. WFIFOSET(fd,packet_len(0x169));
  7700. }
  7701. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7702. /// 015a <char name>.24B <reason>.40B
  7703. void clif_guild_leave(map_session_data *sd,const char *name,const char *mes)
  7704. {
  7705. unsigned char buf[128];
  7706. nullpo_retv(sd);
  7707. WBUFW(buf, 0)=0x15a;
  7708. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7709. memcpy(WBUFP(buf,26),mes,40);
  7710. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7711. }
  7712. /// Notifies clients of a guild of an expelled member.
  7713. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7714. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7715. void clif_guild_expulsion(map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7716. {
  7717. unsigned char buf[128];
  7718. #if PACKETVER < 20100803
  7719. const unsigned short cmd = 0x15c;
  7720. #else
  7721. const unsigned short cmd = 0x839;
  7722. #endif
  7723. nullpo_retv(sd);
  7724. WBUFW(buf,0) = cmd;
  7725. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7726. safestrncpy(WBUFCP(buf,26), mes, 40);
  7727. #if PACKETVER < 20100803
  7728. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7729. #endif
  7730. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7731. }
  7732. /// Guild expulsion list (ZC_BAN_LIST).
  7733. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7734. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7735. void clif_guild_expulsionlist(map_session_data* sd)
  7736. {
  7737. #if PACKETVER < 20100803
  7738. const int offset = NAME_LENGTH*2+40;
  7739. #else
  7740. const int offset = NAME_LENGTH+40;
  7741. #endif
  7742. int fd, i, c = 0;
  7743. struct guild* g;
  7744. nullpo_retv(sd);
  7745. if( (g = sd->guild) == NULL )
  7746. return;
  7747. fd = sd->fd;
  7748. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7749. WFIFOW(fd,0) = 0x163;
  7750. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7751. {
  7752. struct guild_expulsion* e = &g->expulsion[i];
  7753. if( e->account_id > 0 )
  7754. {
  7755. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7756. #if PACKETVER < 20100803
  7757. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7758. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7759. #else
  7760. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7761. #endif
  7762. c++;
  7763. }
  7764. }
  7765. WFIFOW(fd,2) = 4 + c*offset;
  7766. WFIFOSET(fd,WFIFOW(fd,2));
  7767. }
  7768. /// Guild chat message (ZC_GUILD_CHAT).
  7769. /// 017f <packet len>.W <message>.?B
  7770. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7771. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7772. map_session_data *sd;
  7773. uint8 buf[256];
  7774. if( len == 0 )
  7775. {
  7776. return;
  7777. }
  7778. else if( len > sizeof(buf)-5 )
  7779. {
  7780. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7781. len = sizeof(buf)-5;
  7782. }
  7783. WBUFW(buf, 0) = 0x17f;
  7784. WBUFW(buf, 2) = len + 5;
  7785. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7786. if ((sd = guild_getavailablesd(g)) != NULL)
  7787. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7788. }
  7789. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7790. /// 0171 <inviter account id>.L <guild name>.24B
  7791. void clif_guild_reqalliance(map_session_data *sd,uint32 account_id,const char *name)
  7792. {
  7793. int fd;
  7794. nullpo_retv(sd);
  7795. fd=sd->fd;
  7796. WFIFOHEAD(fd,packet_len(0x171));
  7797. WFIFOW(fd,0)=0x171;
  7798. WFIFOL(fd,2)=account_id;
  7799. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7800. WFIFOSET(fd,packet_len(0x171));
  7801. }
  7802. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7803. /// 0173 <answer>.B
  7804. /// answer:
  7805. /// 0 = Already allied.
  7806. /// 1 = You rejected the offer.
  7807. /// 2 = You accepted the offer.
  7808. /// 3 = They have too any alliances.
  7809. /// 4 = You have too many alliances.
  7810. /// 5 = Alliances are disabled.
  7811. void clif_guild_allianceack(map_session_data *sd,int flag)
  7812. {
  7813. int fd;
  7814. nullpo_retv(sd);
  7815. fd=sd->fd;
  7816. WFIFOHEAD(fd,packet_len(0x173));
  7817. WFIFOW(fd,0)=0x173;
  7818. WFIFOL(fd,2)=flag;
  7819. WFIFOSET(fd,packet_len(0x173));
  7820. }
  7821. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7822. /// 0184 <other guild id>.L <relation>.L
  7823. /// relation:
  7824. /// 0 = Ally
  7825. /// 1 = Enemy
  7826. void clif_guild_delalliance(map_session_data *sd,int guild_id,int flag)
  7827. {
  7828. nullpo_retv(sd);
  7829. int fd = sd->fd;
  7830. if ( !session_isActive(fd) )
  7831. return;
  7832. WFIFOHEAD(fd,packet_len(0x184));
  7833. WFIFOW(fd,0)=0x184;
  7834. WFIFOL(fd,2)=guild_id;
  7835. WFIFOL(fd,6)=flag;
  7836. WFIFOSET(fd,packet_len(0x184));
  7837. }
  7838. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7839. /// 0181 <result>.B
  7840. /// result:
  7841. /// 0 = Antagonist has been set.
  7842. /// 1 = Guild has too many Antagonists.
  7843. /// 2 = Already set as an Antagonist.
  7844. /// 3 = Antagonists are disabled.
  7845. void clif_guild_oppositionack(map_session_data *sd,int flag)
  7846. {
  7847. int fd;
  7848. nullpo_retv(sd);
  7849. fd=sd->fd;
  7850. WFIFOHEAD(fd,packet_len(0x181));
  7851. WFIFOW(fd,0)=0x181;
  7852. WFIFOB(fd,2)=flag;
  7853. WFIFOSET(fd,packet_len(0x181));
  7854. }
  7855. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7856. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7857. /*
  7858. void clif_guild_allianceadded(struct guild *g,int idx)
  7859. {
  7860. unsigned char buf[64];
  7861. WBUFW(buf,0)=0x185;
  7862. WBUFL(buf,2)=g->alliance[idx].opposition;
  7863. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7864. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7865. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7866. }
  7867. */
  7868. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7869. /// 015e <reason>.L
  7870. /// 0 = success
  7871. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7872. /// 2 = there are still members in the guild
  7873. void clif_guild_broken(map_session_data *sd,int flag)
  7874. {
  7875. int fd;
  7876. nullpo_retv(sd);
  7877. fd=sd->fd;
  7878. WFIFOHEAD(fd,packet_len(0x15e));
  7879. WFIFOW(fd,0)=0x15e;
  7880. WFIFOL(fd,2)=flag;
  7881. WFIFOSET(fd,packet_len(0x15e));
  7882. }
  7883. /// Displays emotion on an object (ZC_EMOTION).
  7884. /// 00c0 <id>.L <type>.B
  7885. /// type:
  7886. /// enum emotion_type
  7887. void clif_emotion(struct block_list *bl,int type)
  7888. {
  7889. unsigned char buf[8];
  7890. nullpo_retv(bl);
  7891. WBUFW(buf,0)=0xc0;
  7892. WBUFL(buf,2)=bl->id;
  7893. WBUFB(buf,6)=type;
  7894. clif_send(buf,packet_len(0xc0),bl,AREA);
  7895. }
  7896. /// Displays the contents of a talkiebox trap.
  7897. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7898. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7899. nullpo_retv( bl );
  7900. nullpo_retv( talkie );
  7901. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7902. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7903. p.aid = bl->id;
  7904. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7905. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7906. }
  7907. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7908. /// 01ea <id>.L
  7909. void clif_wedding_effect(struct block_list *bl)
  7910. {
  7911. unsigned char buf[6];
  7912. nullpo_retv(bl);
  7913. WBUFW(buf,0) = 0x1ea;
  7914. WBUFL(buf,2) = bl->id;
  7915. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7916. }
  7917. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7918. /// 01e6 <partner name>.24B
  7919. void clif_callpartner(map_session_data& sd)
  7920. {
  7921. PACKET_ZC_COUPLENAME p = { 0 };
  7922. p.packetType = HEADER_ZC_COUPLENAME;
  7923. if( sd.status.partner_id ) {
  7924. map_session_data *p_sd = pc_get_partner(&sd);
  7925. if (p_sd != nullptr && !p_sd->state.autotrade)
  7926. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  7927. else
  7928. p.name[0] = 0;
  7929. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7930. p.name[0] = 0;
  7931. }
  7932. clif_send(&p, sizeof(p), &sd.bl, AREA);
  7933. }
  7934. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7935. /// 01e4
  7936. /// This packet while still implemented by the client is no longer being officially used.
  7937. /*
  7938. void clif_marriage_process(map_session_data *sd)
  7939. {
  7940. int fd;
  7941. nullpo_retv(sd);
  7942. fd=sd->fd;
  7943. WFIFOHEAD(fd,packet_len(0x1e4));
  7944. WFIFOW(fd,0)=0x1e4;
  7945. WFIFOSET(fd,packet_len(0x1e4));
  7946. }
  7947. */
  7948. /// Notice of divorce (ZC_DIVORCE).
  7949. /// 0205 <partner name>.24B
  7950. void clif_divorced(map_session_data* sd, const char* name)
  7951. {
  7952. int fd;
  7953. nullpo_retv(sd);
  7954. fd=sd->fd;
  7955. WFIFOHEAD(fd,packet_len(0x205));
  7956. WFIFOW(fd,0)=0x205;
  7957. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7958. WFIFOSET(fd, packet_len(0x205));
  7959. }
  7960. /// Marriage proposal (ZC_REQ_COUPLE).
  7961. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7962. /// This packet while still implemented by the client is no longer being officially used.
  7963. /*
  7964. void clif_marriage_proposal(int fd, map_session_data *sd, map_session_data* ssd)
  7965. {
  7966. nullpo_retv(sd);
  7967. WFIFOHEAD(fd,packet_len(0x1e2));
  7968. WFIFOW(fd,0) = 0x1e2;
  7969. WFIFOL(fd,2) = ssd->status.account_id;
  7970. WFIFOL(fd,6) = ssd->status.char_id;
  7971. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7972. WFIFOSET(fd, packet_len(0x1e2));
  7973. }
  7974. */
  7975. /*==========================================
  7976. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7977. *------------------------------------------*/
  7978. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7979. {
  7980. unsigned char buf[256];
  7981. if( len == 0 ) {
  7982. return;
  7983. } else if( len > sizeof(buf)-5 ) {
  7984. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7985. len = sizeof(buf)-5;
  7986. }
  7987. WBUFW(buf, 0) = 0x17f;
  7988. WBUFW(buf, 2) = len + 5;
  7989. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7990. clif_send(buf, WBUFW(buf,2), src, target);
  7991. }
  7992. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7993. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7994. /// 00cd <result>.B
  7995. /// result:
  7996. /// 0 = failure
  7997. /// 1 = success
  7998. void clif_GM_kickack(map_session_data *sd, int id)
  7999. {
  8000. int fd;
  8001. nullpo_retv(sd);
  8002. fd = sd->fd;
  8003. WFIFOHEAD(fd,packet_len(0xcd));
  8004. WFIFOW(fd,0) = 0xcd;
  8005. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8006. WFIFOSET(fd, packet_len(0xcd));
  8007. }
  8008. void clif_GM_kick(map_session_data *sd, map_session_data *tsd)
  8009. {
  8010. nullpo_retv(tsd);
  8011. if (sd == NULL)
  8012. tsd->state.keepshop = true;
  8013. if (session_isActive(tsd->fd))
  8014. clif_authfail_fd(tsd->fd, 15);
  8015. else
  8016. map_quit(tsd);
  8017. if (sd)
  8018. clif_GM_kickack(sd, tsd->status.account_id);
  8019. }
  8020. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8021. /// 014a <result>.L
  8022. /// result:
  8023. /// 0 = "A manner point has been successfully aligned."
  8024. /// 1 = MP_FAILURE_EXHAUST
  8025. /// 2 = MP_FAILURE_ALREADY_GIVING
  8026. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8027. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8028. /// 5 = "You got a good point from %s."
  8029. void clif_manner_message(map_session_data* sd, uint32 type)
  8030. {
  8031. int fd;
  8032. nullpo_retv(sd);
  8033. fd = sd->fd;
  8034. WFIFOHEAD(fd,packet_len(0x14a));
  8035. WFIFOW(fd,0) = 0x14a;
  8036. WFIFOL(fd,2) = type;
  8037. WFIFOSET(fd, packet_len(0x14a));
  8038. }
  8039. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8040. /// 014b <type>.B <GM name>.24B
  8041. /// type:
  8042. /// 0 = positive (unmute)
  8043. /// 1 = negative (mute)
  8044. void clif_GM_silence(map_session_data* sd, map_session_data* tsd, uint8 type)
  8045. {
  8046. int fd;
  8047. nullpo_retv(sd);
  8048. nullpo_retv(tsd);
  8049. fd = tsd->fd;
  8050. WFIFOHEAD(fd,packet_len(0x14b));
  8051. WFIFOW(fd,0) = 0x14b;
  8052. WFIFOB(fd,2) = type;
  8053. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8054. WFIFOSET(fd, packet_len(0x14b));
  8055. }
  8056. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8057. /// 00d1 <type>.B <result>.B
  8058. /// type:
  8059. /// 0 = /ex (deny)
  8060. /// 1 = /in (allow)
  8061. /// result:
  8062. /// 0 = success
  8063. /// 1 = failure
  8064. /// 2 = too many blocks
  8065. void clif_wisexin(map_session_data *sd,int type,int flag)
  8066. {
  8067. int fd;
  8068. nullpo_retv(sd);
  8069. fd=sd->fd;
  8070. WFIFOHEAD(fd,packet_len(0xd1));
  8071. WFIFOW(fd,0)=0xd1;
  8072. WFIFOB(fd,2)=type;
  8073. WFIFOB(fd,3)=flag;
  8074. WFIFOSET(fd,packet_len(0xd1));
  8075. }
  8076. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8077. /// 00d2 <type>.B <result>.B
  8078. /// type:
  8079. /// 0 = /exall (deny)
  8080. /// 1 = /inall (allow)
  8081. /// result:
  8082. /// 0 = success
  8083. /// 1 = failure
  8084. void clif_wisall(map_session_data *sd,int type,int flag)
  8085. {
  8086. int fd;
  8087. nullpo_retv(sd);
  8088. fd=sd->fd;
  8089. WFIFOHEAD(fd,packet_len(0xd2));
  8090. WFIFOW(fd,0)=0xd2;
  8091. WFIFOB(fd,2)=type;
  8092. WFIFOB(fd,3)=flag;
  8093. WFIFOSET(fd,packet_len(0xd2));
  8094. }
  8095. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8096. /// 07fe <bgm>.24B
  8097. void clif_playBGM( map_session_data& sd, const char* name ){
  8098. #if PACKETVER_MAIN_NUM >= 20220504
  8099. struct PACKET_ZC_PLAY_NPC_BGM* p = (struct PACKET_ZC_PLAY_NPC_BGM*)packet_buffer;
  8100. int16 length = (int16)( strlen( name ) + 1 );
  8101. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8102. p->PacketLength = sizeof( *p ) + length;
  8103. p->playType = 0; // TODO: implement, send loop for the time being
  8104. safestrncpy( p->bgm, name, length );
  8105. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8106. #elif PACKETVER >= 20091201
  8107. struct PACKET_ZC_PLAY_NPC_BGM p = {};
  8108. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8109. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8110. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8111. #endif
  8112. }
  8113. /// Plays/stops a wave sound (ZC_SOUND).
  8114. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8115. /// file name:
  8116. /// relative to data\wav
  8117. /// act:
  8118. /// 0 = play (once)
  8119. /// 1 = play (repeat, does not work)
  8120. /// 2 = stops all sound instances of file name (does not work)
  8121. /// term:
  8122. /// unknown purpose, only relevant to act = 1
  8123. /// npc id:
  8124. /// The accustic direction of the sound is determined by the
  8125. /// relative position of the NPC to the player (3D sound).
  8126. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8127. struct PACKET_ZC_SOUND p = {};
  8128. p.PacketType = HEADER_ZC_SOUND;
  8129. safestrncpy( p.name, name, sizeof( p.name ) );
  8130. p.act = type;
  8131. p.term = 0; // TODO: implement
  8132. p.AID = bl.id;
  8133. clif_send( &p, sizeof( p ), &bl, target );
  8134. }
  8135. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8136. /// 01f3 <id>.L <effect id>.L
  8137. /// effect id:
  8138. /// @see doc/effect_list.txt
  8139. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8140. {
  8141. unsigned char buf[24];
  8142. nullpo_retv(bl);
  8143. memset(buf, 0, packet_len(0x1f3));
  8144. WBUFW(buf,0) = 0x1f3;
  8145. WBUFL(buf,2) = bl->id;
  8146. WBUFL(buf,6) = type;
  8147. clif_send(buf, packet_len(0x1f3), bl, target);
  8148. if (disguised(bl)) {
  8149. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8150. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8151. }
  8152. }
  8153. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8154. {
  8155. WFIFOHEAD(fd,10);
  8156. WFIFOW(fd,0) = 0x1f3;
  8157. WFIFOL(fd,2) = bl->id;
  8158. WFIFOL(fd,6) = type;
  8159. WFIFOSET(fd,10);
  8160. }
  8161. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8162. /// 0284 <id>.L <effect id>.L <num data>.L
  8163. /// effect id:
  8164. /// @see doc/effect_list.txt
  8165. /// num data:
  8166. /// effect-dependent value
  8167. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8168. {
  8169. uint8 buf[14];
  8170. WBUFW(buf,0) = 0x284;
  8171. WBUFL(buf,2) = bl->id;
  8172. WBUFL(buf,6) = effect_id;
  8173. WBUFL(buf,10) = num;
  8174. clif_send(buf, packet_len(0x284), bl, target);
  8175. if( disguised(bl) )
  8176. {
  8177. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8178. clif_send(buf, packet_len(0x284), bl, SELF);
  8179. }
  8180. }
  8181. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8182. {
  8183. #if PACKETVER >= 20181002
  8184. nullpo_retv( bl_src );
  8185. nullpo_retv( bl_target );
  8186. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8187. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8188. p.aid = bl_src->id;
  8189. p.effectId = effect;
  8190. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8191. if( disguised(bl_src) )
  8192. {
  8193. p.aid = disguised_bl_id( bl_src->id );
  8194. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8195. }
  8196. #endif
  8197. }
  8198. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8199. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8200. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, map_session_data *sd) {
  8201. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8202. uint8 buf[CHAT_SIZE_MAX];
  8203. nullpo_retv(bl);
  8204. if (msg_len > sizeof(buf) - 12) {
  8205. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8206. msg_len = sizeof(buf) - 12;
  8207. }
  8208. if (rgb2bgr)
  8209. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8210. WBUFW(buf,0) = 0x2C1;
  8211. WBUFW(buf,2) = msg_len + 12;
  8212. WBUFL(buf,4) = bl->id;
  8213. WBUFL(buf,8) = color;
  8214. memcpy(WBUFCP(buf,12), msg, msg_len);
  8215. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8216. }
  8217. /**
  8218. * Notifies the client that the storage window is still open
  8219. *
  8220. * Should only be used in cases where the client closed the
  8221. * storage window without server's consent
  8222. */
  8223. void clif_refresh_storagewindow(map_session_data *sd) {
  8224. // Notify the client that the storage is open
  8225. if( sd->state.storage_flag == 1 ) {
  8226. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8227. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8228. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8229. }
  8230. // Notify the client that the gstorage is open otherwise it will
  8231. // remain locked forever and nobody will be able to access it
  8232. if( sd->state.storage_flag == 2 ) {
  8233. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8234. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8235. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8236. else {
  8237. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8238. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8239. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8240. }
  8241. }
  8242. // Notify the client that the premium storage is open
  8243. if (sd->state.storage_flag == 3) {
  8244. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8245. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8246. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8247. }
  8248. }
  8249. // refresh the client's screen, getting rid of any effects
  8250. void clif_refresh(map_session_data *sd)
  8251. {
  8252. nullpo_retv(sd);
  8253. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8254. clif_inventorylist(sd);
  8255. clif_equipswitch_list(sd);
  8256. if(pc_iscarton(sd)) {
  8257. clif_cartlist(sd);
  8258. clif_updatestatus(sd,SP_CARTINFO);
  8259. }
  8260. clif_updatestatus(sd,SP_WEIGHT);
  8261. clif_updatestatus(sd,SP_MAXWEIGHT);
  8262. clif_updatestatus(sd,SP_STR);
  8263. clif_updatestatus(sd,SP_AGI);
  8264. clif_updatestatus(sd,SP_VIT);
  8265. clif_updatestatus(sd,SP_INT);
  8266. clif_updatestatus(sd,SP_DEX);
  8267. clif_updatestatus(sd,SP_LUK);
  8268. #ifdef RENEWAL
  8269. clif_updatestatus(sd,SP_POW);
  8270. clif_updatestatus(sd,SP_STA);
  8271. clif_updatestatus(sd,SP_WIS);
  8272. clif_updatestatus(sd,SP_SPL);
  8273. clif_updatestatus(sd,SP_CON);
  8274. clif_updatestatus(sd,SP_CRT);
  8275. #endif
  8276. if (sd->spiritball)
  8277. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8278. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  8279. clif_millenniumshield_single(sd->fd, sd);
  8280. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8281. clif_spiritcharm_single(sd->fd, sd);
  8282. if (sd->soulball)
  8283. clif_soulball( sd, &sd->bl, SELF );
  8284. if (sd->servantball)
  8285. clif_servantball( *sd, &sd->bl, SELF );
  8286. if (sd->abyssball)
  8287. clif_abyssball( *sd, &sd->bl, SELF );
  8288. if (sd->vd.cloth_color)
  8289. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8290. if (sd->vd.body_style)
  8291. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8292. if(hom_is_active(sd->hd))
  8293. clif_send_homdata(sd,SP_ACK,0);
  8294. if( sd->md ) {
  8295. clif_mercenary_info(sd);
  8296. clif_mercenary_skillblock(sd);
  8297. }
  8298. if( sd->ed )
  8299. clif_elemental_info(sd);
  8300. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8301. clif_weather_check(sd);
  8302. if( sd->chatID )
  8303. chat_leavechat(sd,0);
  8304. if( sd->state.vending )
  8305. clif_openvending(sd, sd->bl.id, sd->vending);
  8306. if( pc_issit(sd) )
  8307. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8308. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8309. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8310. else
  8311. clif_changed_dir(&sd->bl, SELF);
  8312. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8313. //Issue #2143
  8314. //Cancel Trading State
  8315. if (sd->state.trading)
  8316. trade_tradecancel(sd);
  8317. //Cancel Buying/Selling State
  8318. if (sd->state.buyingstore)
  8319. buyingstore_close(sd);
  8320. mail_clear(sd);
  8321. clif_loadConfirm( sd );
  8322. if( disguised(&sd->bl) ) {/* refresh-da */
  8323. short disguise = sd->disguise;
  8324. pc_disguise(sd, 0);
  8325. pc_disguise(sd, disguise);
  8326. }
  8327. clif_refresh_storagewindow(sd);
  8328. }
  8329. /// Updates the object's (bl) name on client.
  8330. /// Used to update when a char leaves a party/guild. [Skotlex]
  8331. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8332. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8333. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8334. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8335. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8336. nullpo_retv( src );
  8337. nullpo_retv( bl );
  8338. switch( bl->type ){
  8339. case BL_PC: {
  8340. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8341. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8342. packet.gid = bl->id;
  8343. map_session_data *sd = (map_session_data *)bl;
  8344. //Requesting your own "shadow" name. [Skotlex]
  8345. if( src == bl && target == SELF && sd->disguise ){
  8346. packet.gid = -bl->id;
  8347. }
  8348. if( sd->fakename[0] ) {
  8349. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8350. clif_send( &packet, sizeof(packet), src, target );
  8351. return;
  8352. }
  8353. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8354. party_data *p = nullptr;
  8355. if( sd->status.party_id ){
  8356. p = party_search( sd->status.party_id );
  8357. }
  8358. // do not display party unless the player is also in a guild
  8359. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8360. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8361. }
  8362. if( sd->guild ){
  8363. int position;
  8364. // Will get the position of the guild the player is in
  8365. position = guild_getposition( sd );
  8366. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8367. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8368. }else if( sd->clan ){
  8369. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8370. }
  8371. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8372. packet.title_id = sd->status.title_id; // Title ID
  8373. #endif
  8374. clif_send(&packet, sizeof(packet), src, target);
  8375. }
  8376. break;
  8377. //[blackhole89]
  8378. case BL_HOM:
  8379. case BL_MER:
  8380. case BL_PET:
  8381. case BL_NPC:
  8382. case BL_ELEM: {
  8383. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8384. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8385. packet.gid = bl->id;
  8386. switch (bl->type) {
  8387. case BL_HOM:
  8388. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8389. break;
  8390. case BL_MER:
  8391. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8392. break;
  8393. case BL_PET:
  8394. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8395. break;
  8396. case BL_NPC:
  8397. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8398. break;
  8399. case BL_ELEM:
  8400. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8401. break;
  8402. }
  8403. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8404. unit_data *ud = unit_bl2ud(bl);
  8405. if (ud != nullptr) {
  8406. memcpy(packet.title, ud->title, NAME_LENGTH);
  8407. packet.groupId = ud->group_id;
  8408. }
  8409. #endif
  8410. clif_send(&packet, sizeof(packet), src, target);
  8411. }
  8412. break;
  8413. case BL_MOB: {
  8414. mob_data *md = (mob_data *)bl;
  8415. if( md->guardian_data && md->guardian_data->guild_id ){
  8416. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8417. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8418. packet.gid = bl->id;
  8419. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8420. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8421. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8422. clif_send(&packet, sizeof(packet), src, target);
  8423. }else if( battle_config.show_mob_info ){
  8424. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8425. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8426. packet.gid = bl->id;
  8427. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8428. char mobhp[50], *str_p = mobhp;
  8429. if( battle_config.show_mob_info&4 ){
  8430. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8431. }
  8432. if( battle_config.show_mob_info&1 ){
  8433. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8434. }
  8435. if( battle_config.show_mob_info&2 ){
  8436. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8437. }
  8438. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8439. if( str_p != mobhp ){
  8440. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8441. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8442. }
  8443. clif_send(&packet, sizeof(packet), src, target);
  8444. } else {
  8445. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8446. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8447. packet.gid = bl->id;
  8448. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8449. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8450. unit_data *ud = unit_bl2ud(bl);
  8451. if (ud != nullptr) {
  8452. memcpy(packet.title, ud->title, NAME_LENGTH);
  8453. packet.groupId = ud->group_id;
  8454. }
  8455. #endif
  8456. clif_send(&packet, sizeof(packet), src, target);
  8457. }
  8458. }
  8459. break;
  8460. case BL_CHAT:
  8461. case BL_SKILL:
  8462. // Newer clients request this, but do not need an answer
  8463. return;
  8464. default:
  8465. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8466. return;
  8467. }
  8468. }
  8469. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8470. /// 01ff <id>.L <x>.W <y>.W
  8471. ///
  8472. /// Visually moves(instant) a character to x,y. The char moves even
  8473. /// when the target cell isn't walkable. If the char is sitting it
  8474. /// stays that way.
  8475. void clif_slide(struct block_list *bl, int x, int y)
  8476. {
  8477. unsigned char buf[10];
  8478. nullpo_retv(bl);
  8479. WBUFW(buf, 0) = 0x01ff;
  8480. WBUFL(buf, 2) = bl->id;
  8481. WBUFW(buf, 6) = x;
  8482. WBUFW(buf, 8) = y;
  8483. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8484. if( disguised(bl) )
  8485. {
  8486. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8487. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8488. }
  8489. }
  8490. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8491. /// 008d <packet len>.W <id>.L <message>.?B
  8492. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8493. {
  8494. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8495. int len_mes = strlen(mes)+1; //Account for \0
  8496. if (len_mes > sizeof(buf)-8) {
  8497. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8498. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8499. }
  8500. // send message to others
  8501. if (flag == AREA) {
  8502. WBUFW(buf,0) = 0x8d;
  8503. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8504. WBUFL(buf,4) = bl->id;
  8505. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8506. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8507. }
  8508. // send back message to the speaker
  8509. if( bl->type == BL_PC ) {
  8510. WBUFW(buf,0) = 0x8e;
  8511. WBUFW(buf, 2) = len_mes + 4;
  8512. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8513. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8514. }
  8515. }
  8516. /*==========================
  8517. * Minimap fix [Kevin]
  8518. * Remove dot from minimap
  8519. *--------------------------*/
  8520. void clif_party_xy_remove(map_session_data* sd)
  8521. {
  8522. nullpo_retv(sd);
  8523. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8524. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8525. p.AID = sd->status.account_id;
  8526. p.xPos = -1;
  8527. p.yPos = -1;
  8528. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8529. }
  8530. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8531. /// 0215 <msg id>.L
  8532. /// msg id:
  8533. /// 0x15 = End all negative status (PA_GOSPEL)
  8534. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8535. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8536. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8537. /// 0x19 = All stats +20 (PA_GOSPEL)
  8538. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8539. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8540. /// 0x1e = DEF +25% (PA_GOSPEL)
  8541. /// 0x1f = ATK +100% (PA_GOSPEL)
  8542. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8543. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8544. /// ? = nothing
  8545. void clif_gospel_info(map_session_data *sd, int type)
  8546. {
  8547. int fd=sd->fd;
  8548. WFIFOHEAD(fd,packet_len(0x215));
  8549. WFIFOW(fd,0)=0x215;
  8550. WFIFOL(fd,2)=type;
  8551. WFIFOSET(fd, packet_len(0x215));
  8552. }
  8553. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8554. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8555. /// result:
  8556. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8557. /// star:
  8558. /// 0 = Place of the Sun
  8559. /// 1 = Place of the Moon
  8560. /// 2 = Place of the Stars
  8561. /// 1 = Star Gladiator %s's %s: <mapname>
  8562. /// star:
  8563. /// 0 = Place of the Sun
  8564. /// 1 = Place of the Moon
  8565. /// 2 = Place of the Stars
  8566. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8567. /// star:
  8568. /// 0 = Target of the Sun
  8569. /// 1 = Target of the Moon
  8570. /// 2 = Target of the Stars
  8571. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8572. /// star:
  8573. /// 0 = Monster of the Sun
  8574. /// 1 = Monster of the Moon
  8575. /// 2 = Monster of the Stars
  8576. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8577. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8578. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8579. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8580. /// 40 = Target HP : <monster_id used as HP>
  8581. void clif_starskill(map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8582. {
  8583. int fd = sd->fd;
  8584. WFIFOHEAD(fd,packet_len(0x20e));
  8585. WFIFOW(fd,0) = 0x20e;
  8586. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8587. WFIFOL(fd,26) = monster_id;
  8588. WFIFOB(fd,30) = star;
  8589. WFIFOB(fd,31) = result;
  8590. WFIFOSET(fd,packet_len(0x20e));
  8591. }
  8592. /*==========================================
  8593. * Info about Star Glaldiator save map [Komurka]
  8594. * type: 1: Information, 0: Map registered
  8595. *------------------------------------------*/
  8596. void clif_feel_info(map_session_data* sd, unsigned char feel_level, unsigned char type)
  8597. {
  8598. char mapname[MAP_NAME_LENGTH_EXT];
  8599. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8600. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8601. }
  8602. /*==========================================
  8603. * Info about Star Glaldiator hate mob [Komurka]
  8604. * type: 1: Register mob, 0: Information.
  8605. *------------------------------------------*/
  8606. void clif_hate_info(map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8607. {
  8608. if( pcdb_checkid(class_) ) {
  8609. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8610. } else if( mobdb_checkid(class_) ) {
  8611. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8612. } else {
  8613. 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);
  8614. }
  8615. }
  8616. /*==========================================
  8617. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8618. *------------------------------------------*/
  8619. void clif_mission_info(map_session_data *sd, int mob_id, unsigned char progress)
  8620. {
  8621. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8622. }
  8623. /*==========================================
  8624. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8625. *------------------------------------------*/
  8626. void clif_feel_hate_reset(map_session_data *sd)
  8627. {
  8628. clif_starskill(sd, "", 0, 0, 30);
  8629. }
  8630. /// Send out reply to configuration change
  8631. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8632. /// type: see enum e_config_type
  8633. /// value:
  8634. /// false = disabled
  8635. /// true = enabled
  8636. void clif_configuration( map_session_data* sd, enum e_config_type type, bool enabled ){
  8637. int fd;
  8638. nullpo_retv(sd);
  8639. fd = sd->fd;
  8640. WFIFOHEAD(fd, packet_len(0x2d9));
  8641. WFIFOW(fd, 0) = 0x2d9;
  8642. WFIFOL(fd, 2) = type;
  8643. WFIFOL(fd, 6) = enabled;
  8644. WFIFOSET(fd, packet_len(0x2d9));
  8645. }
  8646. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8647. /// 02da <open equip window>.B
  8648. /// open equip window:
  8649. /// 0 = disabled
  8650. /// 1 = enabled
  8651. void clif_equipcheckbox(map_session_data* sd)
  8652. {
  8653. int fd;
  8654. nullpo_retv(sd);
  8655. fd = sd->fd;
  8656. WFIFOHEAD(fd, packet_len(0x2da));
  8657. WFIFOW(fd, 0) = 0x2da;
  8658. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8659. WFIFOSET(fd, packet_len(0x2da));
  8660. }
  8661. /// Sends info about a player's equipped items.
  8662. /// 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)
  8663. /// 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)
  8664. /// 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)
  8665. /// 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)
  8666. /// 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)
  8667. /// 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)
  8668. void clif_viewequip_ack( map_session_data* sd, map_session_data* tsd ){
  8669. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8670. nullpo_retv( sd );
  8671. nullpo_retv( tsd );
  8672. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8673. int equip = 0;
  8674. for( int i = 0; i < EQI_MAX; i++ ){
  8675. int k = tsd->equip_index[i];
  8676. if( k >= 0 ){
  8677. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8678. continue;
  8679. }
  8680. if( !tsd->inventory.u.items_inventory[k].equip ){
  8681. continue;
  8682. }
  8683. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8684. continue;
  8685. }
  8686. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8687. }
  8688. }
  8689. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8690. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8691. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8692. p->job = tsd->status.class_;
  8693. p->head = tsd->vd.hair_style;
  8694. p->accessory = tsd->vd.head_bottom;
  8695. p->accessory2 = tsd->vd.head_mid;
  8696. p->accessory3 = tsd->vd.head_top;
  8697. #if PACKETVER >= 20110111
  8698. p->robe = tsd->vd.robe;
  8699. #endif
  8700. p->headpalette = tsd->vd.hair_color;
  8701. p->bodypalette = tsd->vd.cloth_color;
  8702. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8703. p->body2 = tsd->vd.body_style;
  8704. #endif
  8705. p->sex = tsd->vd.sex;
  8706. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8707. #endif
  8708. }
  8709. /// Display msgstringtable.txt string (ZC_MSG).
  8710. /// 0291 <message>.W
  8711. void clif_msg(map_session_data* sd, unsigned short id)
  8712. {
  8713. int fd;
  8714. nullpo_retv(sd);
  8715. fd = sd->fd;
  8716. WFIFOHEAD(fd, packet_len(0x291));
  8717. WFIFOW(fd, 0) = 0x291;
  8718. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8719. WFIFOSET(fd, packet_len(0x291));
  8720. }
  8721. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8722. /// 0x7e2 <message>.W <value>.L
  8723. void clif_msg_value(map_session_data* sd, unsigned short id, int value)
  8724. {
  8725. int fd = sd->fd;
  8726. WFIFOHEAD(fd, packet_len(0x7e2));
  8727. WFIFOW(fd,0) = 0x7e2;
  8728. WFIFOW(fd,2) = id;
  8729. WFIFOL(fd,4) = value;
  8730. WFIFOSET(fd, packet_len(0x7e2));
  8731. }
  8732. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8733. /// 07e6 <skill id>.W <msg id>.L
  8734. ///
  8735. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8736. /// "[SkillName] Message"
  8737. void clif_msg_skill(map_session_data* sd, uint16 skill_id, int msg_id)
  8738. {
  8739. int fd = sd->fd;
  8740. WFIFOHEAD(fd, packet_len(0x7e6));
  8741. WFIFOW(fd,0) = 0x7e6;
  8742. WFIFOW(fd,2) = skill_id;
  8743. WFIFOL(fd,4) = msg_id;
  8744. WFIFOSET(fd, packet_len(0x7e6));
  8745. }
  8746. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8747. /// 09cd <msg id>.W <color>.L
  8748. void clif_msg_color( map_session_data *sd, uint16 msg_id, uint32 color ){
  8749. nullpo_retv(sd);
  8750. int fd = sd->fd;
  8751. WFIFOHEAD(fd, packet_len(0x9cd));
  8752. WFIFOW(fd, 0) = 0x9cd;
  8753. WFIFOW(fd, 2) = msg_id;
  8754. WFIFOL(fd, 4) = color;
  8755. WFIFOSET(fd, packet_len(0x9cd));
  8756. }
  8757. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8758. /// Returns true if the packet was parsed successfully.
  8759. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8760. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8761. static bool clif_process_message(map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8762. const char* seperator = " : ";
  8763. int fd;
  8764. struct s_packet_db* info;
  8765. uint16 packetLength, inputLength;
  8766. const char *input, *name, *message;
  8767. size_t nameLength, messageLength;
  8768. fd = sd->fd;
  8769. info = &packet_db[RFIFOW(fd,0)];
  8770. packetLength = RFIFOW(fd,info->pos[0]);
  8771. input = RFIFOCP(fd,info->pos[1]);
  8772. // basic structure check for the 4-byte header
  8773. if( packetLength < 4 ){
  8774. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8775. return false;
  8776. }else{
  8777. inputLength = packetLength - 4;
  8778. }
  8779. // process <name> part of the packet
  8780. if( whisperFormat ) {
  8781. // name has fixed width
  8782. if( inputLength < NAME_LENGTH + 1 ) {
  8783. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8784. return false;
  8785. }
  8786. name = input;
  8787. // validate name
  8788. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8789. // only restriction is that the name must be zero-terminated
  8790. if( name[nameLength] != '\0' ) {
  8791. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8792. return false;
  8793. }
  8794. message = input + NAME_LENGTH;
  8795. messageLength = inputLength - NAME_LENGTH;
  8796. }else{
  8797. // name and message are separated by ' : '
  8798. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8799. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8800. // check if there's enough data provided
  8801. if( inputLength < nameLength + seperatorLength + 1 ){
  8802. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8803. return false;
  8804. }
  8805. name = input;
  8806. // validate name
  8807. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8808. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8809. {
  8810. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8811. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8812. set_eof(sd->fd); // Just kick them out to correct it.
  8813. return false;
  8814. }
  8815. message = input + nameLength + seperatorLength;
  8816. messageLength = inputLength - nameLength - seperatorLength;
  8817. }
  8818. #if PACKETVER < 20151001
  8819. // the declared length must match real length
  8820. if( messageLength != strnlen(message, messageLength)+1 ) {
  8821. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8822. return false;
  8823. }
  8824. // verify <message> part of the packet
  8825. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8826. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8827. return false;
  8828. }
  8829. #else
  8830. // No zero termination anymore
  8831. messageLength += 1;
  8832. #endif
  8833. // messages mustn't be too long
  8834. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8835. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8836. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8837. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8838. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8839. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8840. return false;
  8841. }
  8842. // If it is not a whisper message, set the name to the fakename of the player
  8843. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8844. strcpy( out_name, sd->fakename );
  8845. }else{
  8846. safestrncpy( out_name, name, nameLength + 1 );
  8847. }
  8848. safestrncpy( out_message, message, messageLength );
  8849. if( whisperFormat ){
  8850. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8851. out_full_message[nameLength] = '\0';
  8852. }else{
  8853. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8854. }
  8855. if( is_atcommand( fd, sd, out_message, 1 ) )
  8856. return false;
  8857. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8858. return false; //no "chatting" while muted.
  8859. if( battle_config.min_chat_delay ) { //[Skotlex]
  8860. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8861. return false;
  8862. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8863. }
  8864. if (battle_config.idletime_option&IDLE_CHAT)
  8865. sd->idletime = last_tick;
  8866. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8867. sd->idletime_hom = last_tick;
  8868. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8869. sd->idletime_mer = last_tick;
  8870. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8871. return true;
  8872. }
  8873. /**
  8874. * Displays a message if the player enters a PK Zone (during pk_mode)
  8875. * @param sd: Player data
  8876. */
  8877. inline void clif_pk_mode_message(map_session_data * sd)
  8878. {
  8879. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8880. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8881. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8882. char output[CHAT_SIZE_MAX];
  8883. // 1504: You've entered a PK Zone (safe until level %d).
  8884. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8885. battle_config.pk_min_level);
  8886. clif_showscript(&sd->bl, output, SELF);
  8887. } else {
  8888. // 1503: You've entered a PK Zone.
  8889. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8890. }
  8891. }
  8892. return;
  8893. }
  8894. // ---------------------
  8895. // clif_parse_wanttoconnect
  8896. // ---------------------
  8897. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8898. // error codes:
  8899. // 0 - Success
  8900. // 1 - Unknown packet_ver
  8901. // 2 - Invalid account_id
  8902. // 3 - Invalid char_id
  8903. // 4 - Invalid login_id1 (reserved)
  8904. // 5 - Invalid client_tick (reserved)
  8905. // 6 - Invalid sex
  8906. // Only the first 'invalid' error that appears is used.
  8907. static int clif_parse_WantToConnection_sub(int fd)
  8908. {
  8909. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8910. unsigned short cmd;
  8911. //By default, start searching on the default one.
  8912. cmd = RFIFOW(fd, 0);
  8913. packet_len = RFIFOREST(fd);
  8914. // FIXME: If the packet is not received at once, this will FAIL.
  8915. // Figure out, when it happens, that only part of the packet is
  8916. // received, or fix the function to be able to deal with that
  8917. // case.
  8918. if( packet_len != packet_db[cmd].len )
  8919. return 1; /* wrong length */
  8920. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8921. return 2; /* invalid account_id */
  8922. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8923. return 3; /* invalid char_id */
  8924. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8925. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8926. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8927. return 6; /* invalid sex */
  8928. else
  8929. return 0;
  8930. }
  8931. /// Request to connect to map-server.
  8932. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8933. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8934. /// There are various variants of this packet, some of them have padding between fields.
  8935. void clif_parse_WantToConnection(int fd, map_session_data* sd)
  8936. {
  8937. struct block_list* bl;
  8938. struct auth_node* node;
  8939. int cmd, account_id, char_id, login_id1, sex, err;
  8940. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8941. if (sd) {
  8942. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8943. return;
  8944. }
  8945. cmd = RFIFOW(fd, 0);
  8946. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8947. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8948. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8949. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8950. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8951. err = clif_parse_WantToConnection_sub(fd);
  8952. if( err ){ // connection rejected
  8953. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8954. err == 1 ? "." :
  8955. err == 2 ? ", possibly for having an invalid account_id." :
  8956. err == 3 ? ", possibly for having an invalid char_id." :
  8957. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8958. err == 4 ? ", possibly for having an invalid login_id1." :
  8959. err == 5 ? ", possibly for having an invalid client_tick." :
  8960. */
  8961. err == 6 ? ", possibly for having an invalid sex." :
  8962. ". ERROR invalid error code"));
  8963. WFIFOHEAD(fd,packet_len(0x6a));
  8964. WFIFOW(fd,0) = 0x6a;
  8965. WFIFOB(fd,2) = err;
  8966. WFIFOSET(fd,packet_len(0x6a));
  8967. #ifdef DUMP_INVALID_PACKET
  8968. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8969. #endif
  8970. RFIFOSKIP(fd, RFIFOREST(fd));
  8971. set_eof(fd);
  8972. return;
  8973. }
  8974. if( !global_core->is_running() ){ // not allowed
  8975. clif_authfail_fd(fd,1);// server closed
  8976. return;
  8977. }
  8978. //Check for double login.
  8979. bl = map_id2bl(account_id);
  8980. if(bl && bl->type != BL_PC) {
  8981. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8982. WFIFOHEAD(fd,packet_len(0x6a));
  8983. WFIFOW(fd,0) = 0x6a;
  8984. WFIFOB(fd,2) = 3; // Rejected by server
  8985. WFIFOSET(fd,packet_len(0x6a));
  8986. set_eof(fd);
  8987. return;
  8988. }
  8989. if (bl ||
  8990. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8991. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8992. {
  8993. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8994. return;
  8995. }
  8996. CREATE(sd, TBL_PC, 1);
  8997. // placement new
  8998. new(sd) map_session_data();
  8999. sd->fd = fd;
  9000. #ifdef PACKET_OBFUSCATION
  9001. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9002. #endif
  9003. session[fd]->session_data = sd;
  9004. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9005. #if PACKETVER < 20070521
  9006. WFIFOHEAD(fd,4);
  9007. WFIFOL(fd,0) = sd->bl.id;
  9008. WFIFOSET(fd,4);
  9009. #else
  9010. WFIFOHEAD(fd,packet_len(0x283));
  9011. WFIFOW(fd,0) = 0x283;
  9012. WFIFOL(fd,2) = sd->bl.id;
  9013. WFIFOSET(fd,packet_len(0x283));
  9014. #endif
  9015. chrif_authreq(sd,false);
  9016. }
  9017. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9018. /// 007d
  9019. void clif_parse_LoadEndAck(int fd,map_session_data *sd)
  9020. {
  9021. bool guild_notice = false;
  9022. if(sd->bl.prev != NULL)
  9023. return;
  9024. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9025. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9026. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9027. sd->state.connect_new = 0;
  9028. return;
  9029. }
  9030. if (sd->state.rewarp) { //Rewarp player.
  9031. sd->state.rewarp = 0;
  9032. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9033. return;
  9034. }
  9035. sd->state.warping = 0;
  9036. // look
  9037. #if PACKETVER < 4
  9038. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9039. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9040. #else
  9041. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9042. #endif
  9043. pc_set_costume_view(sd);
  9044. if(sd->vd.cloth_color)
  9045. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9046. if(sd->vd.body_style)
  9047. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9048. // item
  9049. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9050. pc_checkitem(sd);
  9051. clif_equipswitch_list(sd);
  9052. // cart
  9053. if(pc_iscarton(sd)) {
  9054. clif_cartlist(sd);
  9055. clif_updatestatus(sd,SP_CARTINFO);
  9056. }
  9057. // weight
  9058. clif_updatestatus(sd,SP_WEIGHT);
  9059. clif_updatestatus(sd,SP_MAXWEIGHT);
  9060. // guild
  9061. // (needs to go before clif_spawn() to show guild emblems correctly)
  9062. if(sd->status.guild_id)
  9063. guild_send_memberinfoshort(sd,1);
  9064. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9065. if(battle_config.pc_invincible_time > 0) {
  9066. if(mapdata_flag_gvg(mapdata))
  9067. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9068. else
  9069. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9070. }
  9071. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9072. map_spawnmobs(sd->bl.m);
  9073. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9074. mapdata->users_pvp++;
  9075. }
  9076. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9077. // reset the callshop flag if the player changes map
  9078. sd->state.callshop = 0;
  9079. if(map_addblock(&sd->bl))
  9080. return;
  9081. clif_spawn(&sd->bl);
  9082. // Party
  9083. // (needs to go after clif_spawn() to show hp bars correctly)
  9084. if(sd->status.party_id) {
  9085. party_send_movemap(sd);
  9086. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9087. }
  9088. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9089. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9090. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9091. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9092. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9093. sd->pvp_rank = 0;
  9094. sd->pvp_lastusers = 0;
  9095. sd->pvp_point = 5;
  9096. sd->pvp_won = 0;
  9097. sd->pvp_lost = 0;
  9098. }
  9099. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9100. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9101. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9102. else if (mapdata->flag[MF_GVG_DUNGEON])
  9103. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9104. else if( mapdata_flag_gvg(mapdata) )
  9105. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9106. else
  9107. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9108. // info about nearby objects
  9109. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9110. 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);
  9111. // pet
  9112. if( sd->pd ) {
  9113. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9114. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9115. pet_return_egg( sd, sd->pd );
  9116. } else {
  9117. if(map_addblock(&sd->pd->bl))
  9118. return;
  9119. clif_spawn(&sd->pd->bl);
  9120. clif_send_petdata(sd,sd->pd,0,0);
  9121. clif_send_petstatus(sd);
  9122. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9123. }
  9124. }
  9125. //homunculus [blackhole89]
  9126. if( hom_is_active(sd->hd) ) {
  9127. if(map_addblock(&sd->hd->bl))
  9128. return;
  9129. clif_spawn(&sd->hd->bl);
  9130. clif_send_homdata(sd,SP_ACK,0);
  9131. clif_hominfo(sd,sd->hd,1);
  9132. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9133. clif_homskillinfoblock(sd);
  9134. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9135. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9136. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9137. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9138. }
  9139. if( sd->md ) {
  9140. if(map_addblock(&sd->md->bl))
  9141. return;
  9142. clif_spawn(&sd->md->bl);
  9143. clif_mercenary_info(sd);
  9144. clif_mercenary_skillblock(sd);
  9145. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9146. }
  9147. if( sd->ed ) {
  9148. if (map_addblock(&sd->ed->bl))
  9149. return;
  9150. clif_spawn(&sd->ed->bl);
  9151. clif_elemental_info(sd);
  9152. clif_elemental_updatestatus(sd,SP_HP);
  9153. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9154. clif_elemental_updatestatus(sd,SP_SP);
  9155. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9156. }
  9157. if(sd->state.connect_new) {
  9158. int lv;
  9159. guild_notice = true;
  9160. clif_skillinfoblock(sd);
  9161. clif_hotkeys_send(sd,0);
  9162. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9163. clif_hotkeys_send(sd,1);
  9164. #endif
  9165. clif_updatestatus(sd,SP_BASEEXP);
  9166. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9167. clif_updatestatus(sd,SP_JOBEXP);
  9168. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9169. clif_updatestatus(sd,SP_SKILLPOINT);
  9170. clif_initialstatus(sd);
  9171. if (sd->sc.option&OPTION_FALCON)
  9172. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9173. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9174. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9175. else if (sd->sc.option&OPTION_WUGRIDER)
  9176. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9177. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9178. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9179. if(sd->status.manner < 0)
  9180. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9181. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9182. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9183. if(sd->bl.m == sd->feel_map[0].m
  9184. || sd->bl.m == sd->feel_map[1].m
  9185. || sd->bl.m == sd->feel_map[2].m)
  9186. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9187. }
  9188. if(sd->pd && sd->pd->pet.intimate > 900)
  9189. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9190. if(hom_is_active(sd->hd))
  9191. hom_init_timers(sd->hd);
  9192. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9193. sd->state.night = 1;
  9194. clif_status_load(&sd->bl, EFST_SKE, 1);
  9195. }
  9196. // Notify everyone that this char logged in [Skotlex].
  9197. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9198. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9199. //Login Event
  9200. npc_script_event(sd, NPCE_LOGIN);
  9201. }
  9202. // Set facing direction before check below to update client
  9203. if (battle_config.spawn_direction)
  9204. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9205. } else {
  9206. //For some reason the client "loses" these on warp/map-change.
  9207. clif_updatestatus(sd,SP_STR);
  9208. clif_updatestatus(sd,SP_AGI);
  9209. clif_updatestatus(sd,SP_VIT);
  9210. clif_updatestatus(sd,SP_INT);
  9211. clif_updatestatus(sd,SP_DEX);
  9212. clif_updatestatus(sd,SP_LUK);
  9213. #ifdef RENEWAL
  9214. clif_updatestatus(sd,SP_POW);
  9215. clif_updatestatus(sd,SP_STA);
  9216. clif_updatestatus(sd,SP_WIS);
  9217. clif_updatestatus(sd,SP_SPL);
  9218. clif_updatestatus(sd,SP_CON);
  9219. clif_updatestatus(sd,SP_CRT);
  9220. #endif
  9221. // abort currently running script
  9222. sd->state.using_fake_npc = 0;
  9223. sd->state.menu_or_input = 0;
  9224. sd->npc_menu = 0;
  9225. if(sd->npc_id)
  9226. npc_event_dequeue(sd);
  9227. }
  9228. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9229. clif_partyinvitationstate( *sd );
  9230. #if PACKETVER >= 20070918
  9231. clif_equipcheckbox(sd);
  9232. #endif
  9233. clif_pet_autofeed_status(sd,false);
  9234. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9235. #if PACKETVER >= 20170920
  9236. if( battle_config.homunculus_autofeed_always ){
  9237. // Always send ON or OFF
  9238. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9239. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9240. }else{
  9241. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9242. }
  9243. }else{
  9244. // Only send when enabled
  9245. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9246. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9247. }
  9248. }
  9249. #endif
  9250. clif_reputation_list( *sd );
  9251. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9252. clif_guild_notice(sd); // Displays after VIP
  9253. guild_notice = false; // Do not display it twice
  9254. }
  9255. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9256. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9257. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9258. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9259. }
  9260. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9261. { //Display night.
  9262. if( !sd->state.night )
  9263. {
  9264. sd->state.night = 1;
  9265. clif_status_load(&sd->bl, EFST_SKE, 1);
  9266. }
  9267. }
  9268. else if( sd->state.night )
  9269. { //Clear night display.
  9270. sd->state.night = 0;
  9271. clif_status_load(&sd->bl, EFST_SKE, 0);
  9272. }
  9273. if( mapdata->flag[MF_BATTLEGROUND] )
  9274. {
  9275. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9276. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9277. clif_bg_updatescore_single(sd);
  9278. }
  9279. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9280. {
  9281. char output[128];
  9282. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9283. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9284. }
  9285. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9286. mapdata->hpmeter_visible++;
  9287. sd->state.hpmeter_visible = 1;
  9288. }
  9289. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9290. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9291. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9292. #ifdef VIP_ENABLE
  9293. if (!sd->state.connect_new &&
  9294. !sd->vip.disableshowrate &&
  9295. sd->state.pmap != sd->bl.m &&
  9296. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9297. )
  9298. {
  9299. clif_display_pinfo( *sd );
  9300. }
  9301. #endif
  9302. // Instances do not need their own channels
  9303. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9304. channel_mjoin(sd); //join new map
  9305. clif_pk_mode_message(sd);
  9306. }
  9307. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9308. clif_guild_notice(sd); // Displays at end
  9309. }
  9310. mail_clear(sd);
  9311. /* Guild Aura Init */
  9312. if( sd->guild && sd->state.gmaster_flag ) {
  9313. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9314. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9315. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9316. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9317. }
  9318. if( sd->state.vending ) { /* show we have a vending */
  9319. clif_openvending(sd,sd->bl.id,sd->vending);
  9320. clif_showvendingboard( *sd );
  9321. }
  9322. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9323. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9324. npc_script_event(sd, NPCE_LOADMAP);
  9325. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9326. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9327. if (sd->sc.opt2) //Client loses these on warp.
  9328. clif_changeoption(&sd->bl);
  9329. 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)) {
  9330. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9331. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9332. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9333. }
  9334. clif_weather_check(sd);
  9335. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9336. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9337. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9338. else
  9339. sd->areanpc.clear();
  9340. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9341. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9342. pc_setdead(sd);
  9343. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9344. if(pc_isdead(sd))
  9345. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9346. else {
  9347. skill_usave_trigger(sd);
  9348. if (battle_config.spawn_direction)
  9349. clif_changed_dir(&sd->bl, SELF);
  9350. }
  9351. // Trigger skill effects if you appear standing on them
  9352. if(!battle_config.pc_invincible_time)
  9353. skill_unit_move(&sd->bl,gettick(),1);
  9354. pc_show_questinfo_reinit(sd);
  9355. pc_show_questinfo(sd);
  9356. #if PACKETVER >= 20150513
  9357. if( sd->mail.inbox.unread ){
  9358. clif_Mail_new(sd, 0, NULL, NULL);
  9359. }
  9360. #endif
  9361. sd->state.connect_new = 0;
  9362. sd->state.changemap = false;
  9363. }
  9364. /// Server's tick (ZC_NOTIFY_TIME).
  9365. /// 007f <time>.L
  9366. void clif_notify_time(map_session_data* sd, t_tick time)
  9367. {
  9368. int fd = sd->fd;
  9369. WFIFOHEAD(fd,packet_len(0x7f));
  9370. WFIFOW(fd,0) = 0x7f;
  9371. WFIFOL(fd,2) = client_tick(time);
  9372. WFIFOSET(fd,packet_len(0x7f));
  9373. }
  9374. /// Request for server's tick.
  9375. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9376. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9377. /// There are various variants of this packet, some of them have padding between fields.
  9378. void clif_parse_TickSend(int fd, map_session_data *sd)
  9379. {
  9380. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9381. clif_notify_time(sd, gettick());
  9382. }
  9383. /// Sends hotkey bar.
  9384. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9385. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9386. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9387. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9388. void clif_hotkeys_send( map_session_data *sd, int tab ){
  9389. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9390. nullpo_retv( sd );
  9391. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9392. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9393. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9394. if( tab == 0 ){
  9395. p.rotate = sd->status.hotkey_rowshift;
  9396. }else{
  9397. p.rotate = sd->status.hotkey_rowshift2;
  9398. }
  9399. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9400. p.tab = tab;
  9401. #endif
  9402. #endif
  9403. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9404. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9405. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9406. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9407. }
  9408. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9409. #endif
  9410. }
  9411. /// Request to update a position on the hotkey row bar
  9412. void clif_parse_HotkeyRowShift( int fd, map_session_data *sd ){
  9413. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9414. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9415. if( p->tab == 0 ){
  9416. sd->status.hotkey_rowshift = p->rowshift;
  9417. }else{
  9418. sd->status.hotkey_rowshift2 = p->rowshift;
  9419. }
  9420. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9421. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9422. sd->status.hotkey_rowshift = p->rowshift;
  9423. #endif
  9424. }
  9425. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9426. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9427. void clif_parse_Hotkey(int fd, map_session_data *sd) {
  9428. #ifdef HOTKEY_SAVING
  9429. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9430. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9431. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9432. if( idx >= MAX_HOTKEYS_DB ){
  9433. return;
  9434. }
  9435. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9436. sd->status.hotkeys[idx].id = p->hotkey.id;
  9437. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9438. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9439. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9440. const unsigned short idx = p->index;
  9441. if( idx >= MAX_HOTKEYS_DB ){
  9442. return;
  9443. }
  9444. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9445. sd->status.hotkeys[idx].id = p->hotkey.id;
  9446. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9447. #endif
  9448. #endif
  9449. }
  9450. /// Displays cast-like progress bar (ZC_PROGRESS).
  9451. /// 02f0 <color>.L <time>.L
  9452. void clif_progressbar(map_session_data * sd, unsigned long color, unsigned int second)
  9453. {
  9454. int fd = sd->fd;
  9455. WFIFOHEAD(fd,packet_len(0x2f0));
  9456. WFIFOW(fd,0) = 0x2f0;
  9457. WFIFOL(fd,2) = color;
  9458. WFIFOL(fd,6) = second;
  9459. WFIFOSET(fd,packet_len(0x2f0));
  9460. }
  9461. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9462. /// 02f2
  9463. void clif_progressbar_abort(map_session_data * sd)
  9464. {
  9465. int fd = sd->fd;
  9466. WFIFOHEAD(fd,packet_len(0x2f2));
  9467. WFIFOW(fd,0) = 0x2f2;
  9468. WFIFOSET(fd,packet_len(0x2f2));
  9469. }
  9470. /// Notification from the client, that the progress bar has reached 100%.
  9471. /// 02f1 (CZ_PROGRESS)
  9472. void clif_parse_progressbar(int fd, map_session_data * sd){
  9473. // No progressbar active, ignore it
  9474. if( !sd->progressbar.npc_id ){
  9475. return;
  9476. }
  9477. int npc_id = sd->progressbar.npc_id;
  9478. bool closing = false;
  9479. // Check if the progress was canceled
  9480. if( gettick() < sd->progressbar.timeout && sd->st ){
  9481. closing = true;
  9482. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9483. // If a message window was open, offer a close button to the user
  9484. if( sd->st->mes_active ){
  9485. clif_scriptclose( sd, npc_id );
  9486. }
  9487. }
  9488. sd->progressbar.npc_id = 0;
  9489. sd->progressbar.timeout = 0;
  9490. sd->state.workinprogress = WIP_DISABLE_NONE;
  9491. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9492. sd->idletime = last_tick;
  9493. }
  9494. npc_scriptcont(sd, npc_id, closing);
  9495. }
  9496. /// Displays cast-like progress bar on a NPC
  9497. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9498. void clif_progressbar_npc( struct npc_data *nd, map_session_data* sd ){
  9499. #if PACKETVER >= 20130821
  9500. unsigned char buf[14];
  9501. if( nd->progressbar.timeout > 0 ){
  9502. WBUFW(buf,0) = 0x9d1;
  9503. WBUFL(buf,2) = nd->bl.id;
  9504. WBUFL(buf,6) = nd->progressbar.color;
  9505. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9506. if( sd ){
  9507. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9508. }else{
  9509. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9510. }
  9511. }
  9512. #endif
  9513. }
  9514. /// Request to walk to a certain position on the current map.
  9515. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9516. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9517. /// There are various variants of this packet, some of them have padding between fields.
  9518. void clif_parse_WalkToXY(int fd, map_session_data *sd)
  9519. {
  9520. short x, y;
  9521. if (pc_isdead(sd)) {
  9522. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9523. return;
  9524. }
  9525. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9526. ; //You CAN walk on this OPT1 value.
  9527. else if (sd->progressbar.npc_id) {
  9528. clif_progressbar_abort(sd);
  9529. return; // First walk attempt cancels the progress bar
  9530. } else if (pc_cant_act(sd))
  9531. return;
  9532. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9533. return;
  9534. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9535. //A move command one cell west is only valid if the target cell is free
  9536. if(battle_config.official_cell_stack_limit > 0
  9537. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9538. return;
  9539. // Cloaking wall check is actually updated when you click to process next movement
  9540. // not when you move each cell. This is official behaviour.
  9541. if (sd->sc.getSCE(SC_CLOAKING))
  9542. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9543. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9544. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9545. pc_delinvincibletimer(sd);
  9546. //Set last idle time... [Skotlex]
  9547. if (battle_config.idletime_option&IDLE_WALK)
  9548. sd->idletime = last_tick;
  9549. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9550. sd->idletime_hom = last_tick;
  9551. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9552. sd->idletime_mer = last_tick;
  9553. unit_walktoxy(&sd->bl, x, y, 4);
  9554. }
  9555. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9556. /// 018b <result>.W
  9557. /// result:
  9558. /// 0 = disconnect (quit)
  9559. /// 1 = cannot disconnect (wait 10 seconds)
  9560. /// ? = ignored
  9561. void clif_disconnect_ack(map_session_data* sd, short result)
  9562. {
  9563. int fd = sd->fd;
  9564. WFIFOHEAD(fd,packet_len(0x18b));
  9565. WFIFOW(fd,0) = 0x18b;
  9566. WFIFOW(fd,2) = result;
  9567. WFIFOSET(fd,packet_len(0x18b));
  9568. }
  9569. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9570. /// 018a <type>.W
  9571. /// type:
  9572. /// 0 = quit
  9573. void clif_parse_QuitGame(int fd, map_session_data *sd)
  9574. {
  9575. /* Rovert's prevent logout option fixed [Valaris] */
  9576. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9577. 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) &&
  9578. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9579. {
  9580. pc_damage_log_clear(sd,0);
  9581. clif_disconnect_ack(sd, 0);
  9582. flush_fifo( fd );
  9583. if( battle_config.drop_connection_on_quit ){
  9584. set_eof( fd );
  9585. }
  9586. } else {
  9587. clif_disconnect_ack(sd, 1);
  9588. }
  9589. }
  9590. /// Requesting unit's name.
  9591. /// 0094 <id>.L (CZ_REQNAME)
  9592. /// 0368 <id>.L (CZ_REQNAME2)
  9593. /// There are various variants of this packet, some of them have padding between fields.
  9594. void clif_parse_GetCharNameRequest(int fd, map_session_data *sd)
  9595. {
  9596. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9597. struct block_list* bl;
  9598. //status_change *sc;
  9599. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9600. id = sd->bl.id;
  9601. bl = map_id2bl(id);
  9602. if( bl == NULL )
  9603. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9604. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9605. return; // Block namerequests past view range
  9606. // 'see people in GM hide' cheat detection
  9607. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9608. sc = status_get_sc(bl);
  9609. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9610. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9611. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9612. ) {
  9613. char gm_msg[256];
  9614. 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);
  9615. ShowWarning(gm_msg);
  9616. // information is sent to all online GMs
  9617. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9618. return;
  9619. }
  9620. */
  9621. clif_name(&sd->bl,bl,SELF);
  9622. }
  9623. /// Validates and processes global messages
  9624. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9625. /// There are various variants of this packet.
  9626. void clif_parse_GlobalMessage(int fd, map_session_data* sd)
  9627. {
  9628. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9629. size_t length;
  9630. // validate packet and retrieve name and message
  9631. if( !clif_process_message(sd, false, name, message, output ) )
  9632. return;
  9633. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9634. channel_send(sd->gcbind,sd,message);
  9635. return;
  9636. }
  9637. // send message to others (using the send buffer for temp. storage)
  9638. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9639. length = strlen(output) + 1;
  9640. // send back message to the speaker
  9641. WFIFOHEAD(fd,4+length);
  9642. WFIFOW(fd,0) = 0x8e;
  9643. WFIFOW(fd,2) = (uint16)(4+length);
  9644. safestrncpy(WFIFOCP(fd,4), output, length );
  9645. WFIFOSET(fd, WFIFOW(fd,2));
  9646. #ifdef PCRE_SUPPORT
  9647. // trigger listening npcs
  9648. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9649. #endif
  9650. // Chat logging type 'O' / Global Chat
  9651. 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);
  9652. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9653. }
  9654. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9655. /// Request to warp to a map on given coordinates.
  9656. /// 0140 <map name>.16B <x>.W <y>.W
  9657. void clif_parse_MapMove(int fd, map_session_data *sd)
  9658. {
  9659. char command[MAP_NAME_LENGTH_EXT+25];
  9660. char* map_name;
  9661. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9662. map_name = RFIFOCP(fd,info->pos[0]);
  9663. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9664. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9665. RFIFOW(fd,info->pos[1]), //x
  9666. RFIFOW(fd,info->pos[2])); //y
  9667. is_atcommand(fd, sd, command, 1);
  9668. }
  9669. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9670. /// 009c <id>.L <head dir>.W <dir>.B
  9671. /// head dir:
  9672. /// 0 = straight
  9673. /// 1 = turned CW
  9674. /// 2 = turned CCW
  9675. /// dir:
  9676. /// 0 = north
  9677. /// 1 = northwest
  9678. /// 2 = west
  9679. /// 3 = southwest
  9680. /// 4 = south
  9681. /// 5 = southeast
  9682. /// 6 = east
  9683. /// 7 = northeast
  9684. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9685. {
  9686. unsigned char buf[64];
  9687. WBUFW(buf,0) = 0x9c;
  9688. WBUFL(buf,2) = bl->id;
  9689. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9690. WBUFB(buf,8) = unit_getdir(bl);
  9691. clif_send(buf, packet_len(0x9c), bl, target);
  9692. if (disguised(bl)) {
  9693. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9694. WBUFW(buf,6) = 0;
  9695. clif_send(buf, packet_len(0x9c), bl, SELF);
  9696. }
  9697. }
  9698. /// Request to change own body and head direction.
  9699. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9700. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9701. /// There are various variants of this packet, some of them have padding between fields.
  9702. void clif_parse_ChangeDir(int fd, map_session_data *sd)
  9703. {
  9704. unsigned char headdir, dir;
  9705. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9706. headdir = RFIFOB(fd,info->pos[0]);
  9707. dir = RFIFOB(fd,info->pos[1]);
  9708. pc_setdir(sd, dir, headdir);
  9709. clif_changed_dir(&sd->bl, AREA_WOS);
  9710. }
  9711. /// Request to show an emotion (CZ_REQ_EMOTION).
  9712. /// 00bf <type>.B
  9713. /// type:
  9714. /// @see enum emotion_type
  9715. void clif_parse_Emotion(int fd, map_session_data *sd)
  9716. {
  9717. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9718. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9719. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9720. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9721. return;
  9722. }
  9723. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9724. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9725. sd->emotionlasttime = time(NULL);
  9726. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9727. return;
  9728. }
  9729. sd->emotionlasttime = time(NULL);
  9730. if (battle_config.idletime_option&IDLE_EMOTION)
  9731. sd->idletime = last_tick;
  9732. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9733. sd->idletime_hom = last_tick;
  9734. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9735. sd->idletime_mer = last_tick;
  9736. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9737. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9738. return;
  9739. }
  9740. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9741. emoticon = rnd()%6+ET_DICE1;
  9742. }
  9743. clif_emotion(&sd->bl, emoticon);
  9744. } else
  9745. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9746. }
  9747. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9748. /// 00c2 <count>.L
  9749. void clif_user_count(map_session_data* sd, int count)
  9750. {
  9751. int fd = sd->fd;
  9752. WFIFOHEAD(fd,packet_len(0xc2));
  9753. WFIFOW(fd,0) = 0xc2;
  9754. WFIFOL(fd,2) = count;
  9755. WFIFOSET(fd,packet_len(0xc2));
  9756. }
  9757. /// /w /who (CZ_REQ_USER_COUNT).
  9758. /// Request to display amount of currently connected players.
  9759. /// 00c1
  9760. void clif_parse_HowManyConnections(int fd, map_session_data *sd)
  9761. {
  9762. clif_user_count(sd, map_getusers());
  9763. }
  9764. void clif_parse_ActionRequest_sub(map_session_data *sd, int action_type, int target_id, t_tick tick)
  9765. {
  9766. if (pc_isdead(sd)) {
  9767. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9768. return;
  9769. }
  9770. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9771. if (action_type != 0x00 && action_type != 0x07) {
  9772. if (sd->sc.cant.interact)
  9773. return;
  9774. pc_stop_walking(sd, 1);
  9775. }
  9776. pc_stop_attack(sd);
  9777. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9778. target_id = sd->bl.id;
  9779. switch(action_type)
  9780. {
  9781. case 0x00: // once attack
  9782. case 0x07: // continuous attack
  9783. if( pc_cant_act(sd) )
  9784. return;
  9785. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9786. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9787. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9788. return;
  9789. }
  9790. }
  9791. pc_delinvincibletimer(sd);
  9792. if (battle_config.idletime_option&IDLE_ATTACK)
  9793. sd->idletime = last_tick;
  9794. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9795. sd->idletime_hom = last_tick;
  9796. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9797. sd->idletime_mer = last_tick;
  9798. unit_attack(&sd->bl, target_id, action_type != 0);
  9799. break;
  9800. case 0x02: // sitdown
  9801. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9802. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9803. break;
  9804. }
  9805. if(pc_issit(sd)) {
  9806. //Bugged client? Just refresh them.
  9807. clif_sitting(&sd->bl);
  9808. return;
  9809. }
  9810. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9811. break;
  9812. if (sd->sc.count && (
  9813. sd->sc.getSCE(SC_DANCING) ||
  9814. (sd->sc.getSCE(SC_GRAVITATION) && sd->sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9815. )) //No sitting during these states either.
  9816. break;
  9817. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9818. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9819. break;
  9820. }
  9821. if (battle_config.idletime_option&IDLE_SIT)
  9822. sd->idletime = last_tick;
  9823. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9824. sd->idletime_hom = last_tick;
  9825. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9826. sd->idletime_mer = last_tick;
  9827. pc_setsit(sd);
  9828. skill_sit(sd, true);
  9829. clif_sitting(&sd->bl);
  9830. break;
  9831. case 0x03: // standup
  9832. if (!pc_issit(sd)) {
  9833. //Bugged client? Just refresh them.
  9834. clif_standing(&sd->bl);
  9835. return;
  9836. }
  9837. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9838. break;
  9839. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9840. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9841. break;
  9842. }
  9843. if (pc_setstand(sd, false)) {
  9844. if (battle_config.idletime_option&IDLE_SIT)
  9845. sd->idletime = last_tick;
  9846. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9847. sd->idletime_hom = last_tick;
  9848. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9849. sd->idletime_mer = last_tick;
  9850. skill_sit(sd, false);
  9851. clif_standing(&sd->bl);
  9852. }
  9853. break;
  9854. }
  9855. }
  9856. /// Request for an action.
  9857. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9858. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9859. /// action:
  9860. /// 0 = attack
  9861. /// 1 = pick up item
  9862. /// 2 = sit down
  9863. /// 3 = stand up
  9864. /// 7 = continous attack
  9865. /// 12 = (touch skill?)
  9866. /// There are various variants of this packet, some of them have padding between fields.
  9867. void clif_parse_ActionRequest(int fd, map_session_data *sd)
  9868. {
  9869. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9870. clif_parse_ActionRequest_sub(sd,
  9871. RFIFOB(fd,info->pos[1]),
  9872. RFIFOL(fd,info->pos[0]),
  9873. gettick()
  9874. );
  9875. }
  9876. /// Response to the death/system menu (CZ_RESTART).
  9877. /// 00b2 <type>.B
  9878. /// type:
  9879. /// 0 = restart (respawn)
  9880. /// 1 = char-select (disconnect)
  9881. void clif_parse_Restart(int fd, map_session_data *sd)
  9882. {
  9883. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9884. case 0x00:
  9885. pc_respawn(sd,CLR_OUTSIGHT);
  9886. break;
  9887. case 0x01:
  9888. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9889. 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) &&
  9890. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9891. { //Send to char-server for character selection.
  9892. pc_damage_log_clear(sd,0);
  9893. chrif_charselectreq(sd, session[fd]->client_addr);
  9894. } else {
  9895. clif_disconnect_ack(sd, 1);
  9896. }
  9897. break;
  9898. }
  9899. }
  9900. /// Validates and processes whispered messages (CZ_WHISPER).
  9901. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9902. void clif_parse_WisMessage(int fd, map_session_data* sd)
  9903. {
  9904. map_session_data* dstsd;
  9905. int i;
  9906. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9907. // validate packet and retrieve name and message
  9908. if( !clif_process_message( sd, true, target, message, output ) )
  9909. return;
  9910. // Chat logging type 'W' / Whisper
  9911. 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);
  9912. //-------------------------------------------------------//
  9913. // Lordalfa - Paperboy - To whisper NPC commands //
  9914. //-------------------------------------------------------//
  9915. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9916. {
  9917. char* str = target+4; //Skip the NPC: string part.
  9918. struct npc_data* npc;
  9919. if ((npc = npc_name2id(str))) {
  9920. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9921. char *split;
  9922. char event[EVENT_NAME_LENGTH];
  9923. str = message;
  9924. // skip codepage indicator, if detected
  9925. if( str[0] == '|' && strlen(str) >= 4 )
  9926. str += 3;
  9927. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9928. split = strchr(str,'#');
  9929. if( split == NULL ) { // use the remaining string
  9930. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9931. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9932. split_data[i][0] = '\0';
  9933. break;
  9934. }
  9935. *split = '\0';
  9936. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9937. str = split+1;
  9938. }
  9939. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9940. char variablename[CHAT_SIZE_MAX];
  9941. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9942. set_var_str( sd, variablename, split_data[i] );
  9943. }
  9944. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9945. npc_event(sd,event,0); // Calls the NPC label
  9946. return;
  9947. }
  9948. } else if( target[0] == '#' ) {
  9949. struct Channel *channel = NULL;
  9950. char* chname = target;
  9951. channel = channel_name2channel(chname,sd,3);
  9952. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9953. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9954. channel_send(channel,sd,message);
  9955. }
  9956. else if( channel->pass[0] == '\0') { //no pass needed
  9957. if (channel_join(channel,sd)==0)
  9958. channel_send(channel,sd,message); //join success
  9959. }
  9960. else {
  9961. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9962. }
  9963. return;
  9964. }
  9965. }
  9966. // searching destination character
  9967. dstsd = map_nick2sd(target,false);
  9968. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9969. // player is not on this map-server
  9970. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9971. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9972. // and if we ask for 'Test', we must not contact 'test' player
  9973. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9974. intif_wis_message(sd, target, message, strlen(message) + 1);
  9975. return;
  9976. }
  9977. // if player ignores everyone
  9978. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9979. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9980. clif_wis_end(fd, 1); // 1: target character is not logged in
  9981. else
  9982. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9983. return;
  9984. }
  9985. // if player is autotrading
  9986. if (dstsd->state.autotrade == 1){
  9987. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9988. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9989. return;
  9990. }
  9991. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9992. // if player ignores the source character
  9993. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9994. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9995. clif_wis_end(fd, 2); // 2: ignored by target
  9996. return;
  9997. }
  9998. }
  9999. // notify sender of success
  10000. clif_wis_end(fd, 0); // 0: success to send wisper
  10001. // Normal message
  10002. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10003. }
  10004. /// /b /nb (CZ_BROADCAST).
  10005. /// Request to broadcast a message on whole server.
  10006. /// 0099 <packet len>.W <text>.?B 00
  10007. void clif_parse_Broadcast(int fd, map_session_data* sd) {
  10008. char command[CHAT_SIZE_MAX+11];
  10009. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10010. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10011. char* msg = RFIFOCP(fd,info->pos[1]);
  10012. // as the length varies depending on the command used, just block unreasonably long strings
  10013. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10014. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10015. is_atcommand(fd, sd, command, 1);
  10016. }
  10017. /// Request to pick up an item.
  10018. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10019. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10020. /// There are various variants of this packet, some of them have padding between fields.
  10021. void clif_parse_TakeItem(int fd, map_session_data *sd)
  10022. {
  10023. struct flooritem_data *fitem;
  10024. int map_object_id;
  10025. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10026. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10027. do {
  10028. if (pc_isdead(sd)) {
  10029. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10030. break;
  10031. }
  10032. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10033. break;
  10034. if (pc_cant_act(sd))
  10035. break;
  10036. if (!pc_takeitem(sd, fitem))
  10037. break;
  10038. return;
  10039. } while (0);
  10040. // Client REQUIRES a fail packet or you can no longer pick items.
  10041. clif_additem(sd,0,0,6);
  10042. }
  10043. /// Request to drop an item.
  10044. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10045. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10046. /// There are various variants of this packet, some of them have padding between fields.
  10047. void clif_parse_DropItem(int fd, map_session_data *sd){
  10048. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10049. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10050. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10051. for(;;) {
  10052. if (pc_isdead(sd))
  10053. break;
  10054. if (pc_cant_act2(sd) || sd->npc_id)
  10055. break;
  10056. if (sd->sc.cant.drop)
  10057. break;
  10058. if (!pc_dropitem(sd, item_index, item_amount))
  10059. break;
  10060. if (battle_config.idletime_option&IDLE_DROPITEM)
  10061. sd->idletime = last_tick;
  10062. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10063. sd->idletime_hom = last_tick;
  10064. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10065. sd->idletime_mer = last_tick;
  10066. return;
  10067. }
  10068. //Because the client does not like being ignored.
  10069. clif_dropitem(sd, item_index,0);
  10070. }
  10071. /// Request to use an item.
  10072. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10073. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10074. /// There are various variants of this packet, some of them have padding between fields.
  10075. void clif_parse_UseItem(int fd, map_session_data *sd)
  10076. {
  10077. int n;
  10078. if (pc_isdead(sd)) {
  10079. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10080. return;
  10081. }
  10082. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10083. clif_msg(sd, WORK_IN_PROGRESS);
  10084. return;
  10085. }
  10086. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10087. if (battle_config.idletime_option&IDLE_USEITEM)
  10088. sd->idletime = last_tick;
  10089. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10090. sd->idletime_hom = last_tick;
  10091. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10092. sd->idletime_mer = last_tick;
  10093. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10094. if(n <0 || n >= MAX_INVENTORY)
  10095. return;
  10096. if (!pc_useitem(sd,n))
  10097. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10098. }
  10099. /// Request to equip an item
  10100. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10101. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10102. void clif_parse_EquipItem(int fd,map_session_data *sd)
  10103. {
  10104. int index;
  10105. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10106. if(pc_isdead(sd)) {
  10107. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10108. return;
  10109. }
  10110. index = RFIFOW(fd,info->pos[0])-2;
  10111. if (index < 0 || index >= MAX_INVENTORY)
  10112. return; //Out of bounds check.
  10113. if(sd->npc_id && !sd->npc_item_flag) {
  10114. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10115. return;
  10116. } else if (sd->state.storage_flag || sd->sc.opt1)
  10117. ; //You can equip/unequip stuff while storage is open/under status changes
  10118. else if (pc_cant_act2(sd))
  10119. return;
  10120. if(!sd->inventory.u.items_inventory[index].identify) {
  10121. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10122. return;
  10123. }
  10124. if(!sd->inventory_data[index])
  10125. return;
  10126. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10127. pet_equipitem(sd,index);
  10128. return;
  10129. }
  10130. if (battle_config.idletime_option&IDLE_USEITEM)
  10131. sd->idletime = last_tick;
  10132. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10133. sd->idletime_hom = last_tick;
  10134. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10135. sd->idletime_mer = last_tick;
  10136. //Client doesn't send the position for ammo.
  10137. if(sd->inventory_data[index]->type == IT_AMMO)
  10138. pc_equipitem(sd,index,EQP_AMMO);
  10139. else {
  10140. int req_pos;
  10141. #if PACKETVER >= 20120925
  10142. req_pos = RFIFOL(fd,info->pos[1]);
  10143. #else
  10144. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10145. #endif
  10146. pc_equipitem(sd,index,req_pos);
  10147. }
  10148. }
  10149. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10150. /// 00ab <index>.W
  10151. void clif_parse_UnequipItem(int fd,map_session_data *sd)
  10152. {
  10153. int index;
  10154. if(pc_isdead(sd)) {
  10155. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10156. return;
  10157. }
  10158. if (sd->npc_id && !sd->npc_item_flag) {
  10159. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10160. return;
  10161. } else if (sd->state.storage_flag || sd->sc.opt1)
  10162. ; //You can equip/unequip stuff while storage is open/under status changes
  10163. else if (pc_cant_act2(sd))
  10164. return;
  10165. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10166. if (battle_config.idletime_option&IDLE_USEITEM)
  10167. sd->idletime = last_tick;
  10168. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10169. sd->idletime_hom = last_tick;
  10170. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10171. sd->idletime_mer = last_tick;
  10172. pc_unequipitem(sd,index,1);
  10173. }
  10174. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10175. /// 0090 <id>.L <type>.B
  10176. /// type:
  10177. /// 1 = click
  10178. void clif_parse_NpcClicked(int fd,map_session_data *sd)
  10179. {
  10180. struct block_list *bl;
  10181. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10182. if(pc_isdead(sd)) {
  10183. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10184. return;
  10185. }
  10186. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10187. #ifdef RENEWAL
  10188. clif_msg( sd, WORK_IN_PROGRESS );
  10189. #endif
  10190. return;
  10191. }
  10192. if( sd->state.mail_writing )
  10193. return;
  10194. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10195. //type = RFIFOB(fd,info->pos[1]);
  10196. if (!bl) return;
  10197. switch (bl->type) {
  10198. case BL_MOB:
  10199. case BL_PC:
  10200. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10201. break;
  10202. case BL_NPC:
  10203. #ifdef RENEWAL
  10204. 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
  10205. clif_msg(sd, WORK_IN_PROGRESS);
  10206. break;
  10207. }
  10208. #endif
  10209. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10210. struct npc_data* nd = (struct npc_data*)bl;
  10211. // Progressbar is running
  10212. if( nd->progressbar.timeout > 0 ){
  10213. return;
  10214. }
  10215. npc_click(sd,nd);
  10216. }
  10217. break;
  10218. }
  10219. }
  10220. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10221. /// 00c5 <id>.L <type>.B
  10222. /// type:
  10223. /// 0 = buy
  10224. /// 1 = sell
  10225. void clif_parse_NpcBuySellSelected(int fd,map_session_data *sd)
  10226. {
  10227. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10228. if (sd->state.trading)
  10229. return;
  10230. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10231. }
  10232. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10233. /// 00ca <result>.B
  10234. /// result:
  10235. /// 0 = "The deal has successfully completed."
  10236. /// 1 = "You do not have enough zeny."
  10237. /// 2 = "You are over your Weight Limit."
  10238. /// 3 = "Out of the maximum capacity, you have too many items."
  10239. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10240. /// 10 = "Props open-air store sales will be traded in RODEX"
  10241. /// 11 = "The exchange failed."
  10242. /// 12 = "The exchange was well done."
  10243. /// 13 = "The item is already sold and out of stock."
  10244. /// 14 = "There is not enough goods to exchange."
  10245. void clif_npc_buy_result( map_session_data* sd, e_purchase_result result ){
  10246. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10247. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10248. p.result = (uint8)result;
  10249. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10250. }
  10251. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10252. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10253. void clif_parse_NpcBuyListSend( int fd, map_session_data* sd ){
  10254. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10255. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10256. e_purchase_result result;
  10257. if( sd->state.trading || !sd->npc_shopid )
  10258. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10259. else{
  10260. std::vector<s_npc_buy_list> items = {};
  10261. items.reserve( n );
  10262. for( uint16 i = 0; i < n; i++ ){
  10263. s_npc_buy_list item = {};
  10264. item.nameid = p->items[i].itemId;
  10265. item.qty = p->items[i].amount;
  10266. items.push_back( item );
  10267. }
  10268. result = npc_buylist( sd, items );
  10269. }
  10270. sd->npc_shopid = 0; //Clear shop data.
  10271. clif_npc_buy_result(sd, result);
  10272. }
  10273. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10274. /// 00cb <result>.B
  10275. /// result:
  10276. /// 0 = "The deal has successfully completed."
  10277. /// 1 = "The deal has failed."
  10278. void clif_npc_sell_result(map_session_data* sd, unsigned char result)
  10279. {
  10280. int fd = sd->fd;
  10281. WFIFOHEAD(fd,packet_len(0xcb));
  10282. WFIFOW(fd,0) = 0xcb;
  10283. WFIFOB(fd,2) = result;
  10284. WFIFOSET(fd,packet_len(0xcb));
  10285. }
  10286. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10287. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10288. void clif_parse_NpcSellListSend(int fd,map_session_data *sd)
  10289. {
  10290. int fail=0,n;
  10291. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10292. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10293. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10294. if (sd->state.trading || !sd->npc_shopid)
  10295. fail = 1;
  10296. else
  10297. fail = npc_selllist(sd, n, p->sellList);
  10298. sd->npc_shopid = 0; //Clear shop data.
  10299. clif_npc_sell_result(sd, fail);
  10300. }
  10301. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10302. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10303. /// type:
  10304. /// 0 = private
  10305. /// 1 = public
  10306. void clif_parse_CreateChatRoom(int fd, map_session_data* sd)
  10307. {
  10308. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10309. int len = RFIFOW(fd,info->pos[0])-15;
  10310. int limit = RFIFOW(fd,info->pos[1]);
  10311. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10312. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10313. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10314. char s_password[CHATROOM_PASS_SIZE];
  10315. char s_title[CHATROOM_TITLE_SIZE];
  10316. if (sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM)
  10317. return;
  10318. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10319. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10320. return;
  10321. }
  10322. if( npc_isnear(&sd->bl) ) {
  10323. // uncomment to send msg_txt.
  10324. //char output[150];
  10325. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10326. //clif_displaymessage(sd->fd, output);
  10327. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10328. return;
  10329. }
  10330. if( len <= 0 )
  10331. return; // invalid input
  10332. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10333. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10334. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10335. }
  10336. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10337. /// 00d9 <chat ID>.L <passwd>.8B
  10338. void clif_parse_ChatAddMember(int fd, map_session_data* sd){
  10339. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10340. int chatid = RFIFOL(fd,info->pos[0]);
  10341. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10342. chat_joinchat(sd,chatid,password);
  10343. }
  10344. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10345. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10346. /// type:
  10347. /// 0 = private
  10348. /// 1 = public
  10349. void clif_parse_ChatRoomStatusChange(int fd, map_session_data* sd){
  10350. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10351. int len = RFIFOW(fd,info->pos[0])-15;
  10352. int limit = RFIFOW(fd,info->pos[1]);
  10353. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10354. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10355. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10356. char s_password[CHATROOM_PASS_SIZE];
  10357. char s_title[CHATROOM_TITLE_SIZE];
  10358. if( len <= 0 )
  10359. return; // invalid input
  10360. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10361. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10362. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10363. }
  10364. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10365. /// 00e0 <role>.L <nick>.24B
  10366. /// role:
  10367. /// 0 = owner
  10368. /// 1 = normal
  10369. void clif_parse_ChangeChatOwner(int fd, map_session_data* sd)
  10370. {
  10371. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10372. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10373. }
  10374. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10375. /// 00e2 <name>.24B
  10376. void clif_parse_KickFromChat(int fd,map_session_data *sd)
  10377. {
  10378. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10379. }
  10380. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10381. /// 00e3
  10382. void clif_parse_ChatLeave(int fd, map_session_data* sd)
  10383. {
  10384. chat_leavechat(sd,0);
  10385. }
  10386. //Handles notifying asker and rejecter of what has just ocurred.
  10387. //Type is used to determine the correct msg_txt to use:
  10388. //0:
  10389. static void clif_noask_sub(map_session_data *sd, map_session_data *tsd, int type)
  10390. {
  10391. const char* msg;
  10392. char output[256];
  10393. // Your request has been rejected by autoreject option.
  10394. msg = msg_txt(sd,392);
  10395. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10396. //Notice that a request was rejected.
  10397. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10398. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10399. }
  10400. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10401. /// 00e4 <account id>.L
  10402. void clif_parse_TradeRequest(int fd,map_session_data *sd)
  10403. {
  10404. map_session_data *t_sd;
  10405. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10406. if(!sd->chatID && pc_cant_act(sd))
  10407. return; //You can trade while in a chatroom.
  10408. if(t_sd){
  10409. // @noask [LuzZza]
  10410. if(t_sd->state.noask) {
  10411. clif_noask_sub(sd, t_sd, 0);
  10412. return;
  10413. }
  10414. if (t_sd->state.mail_writing) {
  10415. int old = sd->trade_partner;
  10416. // Fake trading
  10417. sd->trade_partner = t_sd->status.account_id;
  10418. clif_tradestart(sd, 5);
  10419. // Restore old state
  10420. sd->trade_partner = old;
  10421. return;
  10422. }
  10423. }
  10424. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10425. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10426. return;
  10427. }
  10428. trade_traderequest(sd,t_sd);
  10429. }
  10430. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10431. /// 00e6 <result>.B
  10432. /// result:
  10433. /// 3 = accepted
  10434. /// 4 = rejected
  10435. void clif_parse_TradeAck(int fd,map_session_data *sd)
  10436. {
  10437. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10438. }
  10439. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10440. /// 00e8 <index>.W <amount>.L
  10441. void clif_parse_TradeAddItem(int fd,map_session_data *sd)
  10442. {
  10443. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10444. short index = RFIFOW(fd,info->pos[0]);
  10445. int amount = RFIFOL(fd,info->pos[1]);
  10446. if( index == 0 )
  10447. trade_tradeaddzeny(sd, amount);
  10448. else
  10449. trade_tradeadditem(sd, server_index(index), (short)amount);
  10450. }
  10451. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10452. /// 00eb
  10453. void clif_parse_TradeOk(int fd,map_session_data *sd)
  10454. {
  10455. trade_tradeok(sd);
  10456. }
  10457. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10458. /// 00ed
  10459. void clif_parse_TradeCancel(int fd,map_session_data *sd)
  10460. {
  10461. trade_tradecancel(sd);
  10462. }
  10463. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10464. /// 00ef
  10465. void clif_parse_TradeCommit(int fd,map_session_data *sd)
  10466. {
  10467. trade_tradecommit(sd);
  10468. }
  10469. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10470. /// 0118
  10471. void clif_parse_StopAttack(int fd,map_session_data *sd)
  10472. {
  10473. pc_stop_attack(sd);
  10474. if (sd) sd->ud.state.attack_continue = 0;
  10475. }
  10476. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10477. /// 0126 <index>.W <amount>.L
  10478. void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
  10479. if (pc_istrading(sd))
  10480. return;
  10481. if (!pc_iscarton(sd))
  10482. return;
  10483. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10484. return;
  10485. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10486. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10487. }
  10488. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10489. /// 0127 <index>.W <amount>.L
  10490. void clif_parse_GetItemFromCart(int fd,map_session_data *sd)
  10491. {
  10492. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10493. if (!pc_iscarton(sd))
  10494. return;
  10495. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10496. return;
  10497. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10498. }
  10499. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10500. /// 012a
  10501. void clif_parse_RemoveOption(int fd,map_session_data *sd)
  10502. {
  10503. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10504. #ifdef NEW_CARTS
  10505. && sd->sc.getSCE(SC_PUSH_CART) )
  10506. pc_setcart(sd,0);
  10507. #else
  10508. )
  10509. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10510. #endif
  10511. else // priority to remove this option before we can clear cart
  10512. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10513. }
  10514. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10515. /// 097f <Length>.W <identity>.L <type>.B
  10516. void clif_SelectCart(map_session_data *sd) {
  10517. #if PACKETVER >= 20150826
  10518. int i = 0, carts = 3;
  10519. int fd = sd->fd;
  10520. WFIFOHEAD(fd,8 + carts);
  10521. WFIFOW(fd,0) = 0x97f;
  10522. WFIFOW(fd,2) = 8 + carts;
  10523. WFIFOL(fd,4) = sd->status.account_id;
  10524. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10525. for( i = 0; i < carts; i++ ) {
  10526. WFIFOB(fd,8 + i) = 10 + i;
  10527. }
  10528. WFIFOSET(fd,8 + carts);
  10529. #endif
  10530. }
  10531. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10532. /// 0980 <identity>.L <type>.B
  10533. void clif_parse_SelectCart(int fd,map_session_data *sd) {
  10534. #if PACKETVER >= 20150826
  10535. int type;
  10536. // Check identity
  10537. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10538. return;
  10539. type = (int)RFIFOB(fd,6);
  10540. // Check type
  10541. if( type < 10 || type > 12 )
  10542. return;
  10543. pc_setcart(sd, type);
  10544. #endif
  10545. }
  10546. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10547. /// 01af <num>.W
  10548. void clif_parse_ChangeCart(int fd,map_session_data *sd)
  10549. {// TODO: State tracking?
  10550. int type;
  10551. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10552. return;
  10553. #ifdef RENEWAL
  10554. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10555. clif_msg(sd, WORK_IN_PROGRESS);
  10556. return;
  10557. }
  10558. #endif
  10559. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10560. if(
  10561. #ifdef NEW_CARTS
  10562. #if PACKETVER >= 20191106
  10563. (type == 13 && sd->status.base_level > 100) ||
  10564. #endif
  10565. (type == 9 && sd->status.base_level > 130) ||
  10566. (type == 8 && sd->status.base_level > 120) ||
  10567. (type == 7 && sd->status.base_level > 110) ||
  10568. (type == 6 && sd->status.base_level > 100) ||
  10569. #endif
  10570. (type == 5 && sd->status.base_level > 90) ||
  10571. (type == 4 && sd->status.base_level > 80) ||
  10572. (type == 3 && sd->status.base_level > 65) ||
  10573. (type == 2 && sd->status.base_level > 40) ||
  10574. (type == 1))
  10575. pc_setcart(sd, type);
  10576. }
  10577. /// Request to increase status (CZ_STATUS_CHANGE).
  10578. /// 00bb <status id>.W <amount>.B
  10579. /// status id:
  10580. /// SP_STR ~ SP_LUK
  10581. /// amount:
  10582. /// Old clients always send 1 for this, even when using /str+ and the like.
  10583. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10584. void clif_parse_StatusUp(int fd,map_session_data *sd)
  10585. {
  10586. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10587. if( increase_amount < 0 ) {
  10588. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10589. fd, increase_amount);
  10590. }
  10591. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10592. }
  10593. /// Request to increase trait status.
  10594. /// 0b24 <status id>.W <amount>.W
  10595. /// status id:
  10596. /// SP_POW ~ SP_CON
  10597. /// amount:
  10598. /// The amount to increase the trait status
  10599. void clif_parse_traitstatus_up( int fd, map_session_data *sd ){
  10600. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10601. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10602. if( p->amount < 0 ){
  10603. 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 );
  10604. return;
  10605. }
  10606. pc_traitstatusup( sd, p->type, p->amount );
  10607. #endif
  10608. }
  10609. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10610. /// 0112 <skill id>.W
  10611. void clif_parse_SkillUp(int fd,map_session_data *sd)
  10612. {
  10613. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10614. }
  10615. 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)
  10616. {
  10617. int lv;
  10618. if( !hd )
  10619. return;
  10620. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10621. clif_emotion(&hd->bl, ET_THINK);
  10622. return;
  10623. }
  10624. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10625. target_id = hd->bl.id;
  10626. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10627. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10628. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10629. clif_emotion(&hd->bl, ET_THINK);
  10630. if (hd->master)
  10631. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10632. return;
  10633. }
  10634. lv = hom_checkskill(hd, skill_id);
  10635. if( skill_lv > lv )
  10636. skill_lv = lv;
  10637. if( skill_lv )
  10638. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10639. }
  10640. 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)
  10641. {
  10642. int lv;
  10643. if( !hd )
  10644. return;
  10645. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10646. clif_emotion(&hd->bl, ET_THINK);
  10647. return;
  10648. }
  10649. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10650. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10651. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10652. clif_emotion(&hd->bl, ET_THINK);
  10653. if (hd->master)
  10654. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10655. return;
  10656. }
  10657. #ifdef RENEWAL
  10658. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10659. #else
  10660. if (hd->sc.getSCE(SC_BASILICA))
  10661. #endif
  10662. return;
  10663. lv = hom_checkskill(hd, skill_id);
  10664. if( skill_lv > lv )
  10665. skill_lv = lv;
  10666. if( skill_lv )
  10667. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10668. }
  10669. 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)
  10670. {
  10671. int lv;
  10672. if( !md )
  10673. return;
  10674. if( skill_isNotOk_mercenary(skill_id, md) )
  10675. return;
  10676. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10677. target_id = md->bl.id;
  10678. if( md->ud.skilltimer != INVALID_TIMER )
  10679. {
  10680. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10681. }
  10682. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10683. return;
  10684. lv = mercenary_checkskill(md, skill_id);
  10685. if( skill_lv > lv )
  10686. skill_lv = lv;
  10687. if( skill_lv )
  10688. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10689. }
  10690. 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)
  10691. {
  10692. int lv;
  10693. if( !md )
  10694. return;
  10695. if( skill_isNotOk_mercenary(skill_id, md) )
  10696. return;
  10697. if( md->ud.skilltimer != INVALID_TIMER )
  10698. return;
  10699. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10700. {
  10701. if (md->master)
  10702. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10703. return;
  10704. }
  10705. #ifdef RENEWAL
  10706. if (md->sc.getSCE(SC_BASILICA_CELL))
  10707. #else
  10708. if (md->sc.getSCE(SC_BASILICA))
  10709. #endif
  10710. return;
  10711. lv = mercenary_checkskill(md, skill_id);
  10712. if( skill_lv > lv )
  10713. skill_lv = lv;
  10714. if( skill_lv )
  10715. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10716. }
  10717. void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10718. t_tick tick = gettick();
  10719. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10720. int inf = skill_get_inf(skill_id);
  10721. if (inf&INF_GROUND_SKILL || !inf)
  10722. return; //Using a ground/passive skill on a target? WRONG.
  10723. if (sd->state.block_action & PCBLOCK_SKILL) {
  10724. clif_msg(sd, WORK_IN_PROGRESS);
  10725. return;
  10726. }
  10727. if( SKILL_CHK_HOMUN(skill_id) ) {
  10728. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10729. return;
  10730. }
  10731. if( SKILL_CHK_MERC(skill_id) ) {
  10732. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10733. return;
  10734. }
  10735. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10736. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10737. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10738. sd->idletime = last_tick;
  10739. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10740. sd->idletime_hom = last_tick;
  10741. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10742. sd->idletime_mer = last_tick;
  10743. if( sd->npc_id ){
  10744. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10745. #ifdef RENEWAL
  10746. clif_msg( sd, WORK_IN_PROGRESS );
  10747. #endif
  10748. return;
  10749. }
  10750. }
  10751. if ((pc_cant_act2(sd) || sd->chatID) &&
  10752. skill_id != RK_REFRESH &&
  10753. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10754. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10755. return;
  10756. if( pc_issit(sd) )
  10757. return;
  10758. if( skill_isNotOk(skill_id, sd) )
  10759. return;
  10760. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10761. target_id = sd->bl.id; // never trust the client
  10762. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10763. target_id = sd->bl.id;
  10764. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10765. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10766. return;
  10767. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10768. if( sd->skillitem != skill_id ) {
  10769. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10770. return;
  10771. }
  10772. }
  10773. if( sd->sc.option&OPTION_COSTUME )
  10774. return;
  10775. #ifndef RENEWAL
  10776. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10777. return; // On basilica only caster can use Basilica again to stop it.
  10778. #endif
  10779. if( sd->menuskill_id ) {
  10780. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10781. clif_menuskill_clear(sd); //Cancel pet capture.
  10782. }else if( sd->menuskill_id == SG_FEEL ){
  10783. clif_menuskill_clear( sd ); // Cancel selection
  10784. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10785. return; //Can't use skills while a menu is open.
  10786. }
  10787. if( sd->skillitem == skill_id ) {
  10788. if( skill_lv != sd->skillitemlv )
  10789. skill_lv = sd->skillitemlv;
  10790. if( !(inf&INF_SELF_SKILL) )
  10791. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10792. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10793. return;
  10794. }
  10795. sd->skillitem = sd->skillitemlv = 0;
  10796. if( SKILL_CHK_GUILD(skill_id) ) {
  10797. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10798. skill_lv = guild_checkskill(sd->guild, skill_id);
  10799. else
  10800. skill_lv = 0;
  10801. } else {
  10802. if( skill_id != ALL_EQSWITCH ){
  10803. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10804. }
  10805. }
  10806. pc_delinvincibletimer(sd);
  10807. if( skill_lv )
  10808. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10809. }
  10810. /// Request to use a targeted skill.
  10811. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10812. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10813. /// There are various variants of this packet, some of them have padding between fields.
  10814. void clif_parse_UseSkillToId( int fd, map_session_data *sd ){
  10815. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10816. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10817. }
  10818. /*==========================================
  10819. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10820. *------------------------------------------*/
  10821. static void clif_parse_UseSkillToPosSub(int fd, map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10822. {
  10823. t_tick tick = gettick();
  10824. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10825. return; //Using a target skill on the ground? WRONG.
  10826. if (sd->state.block_action & PCBLOCK_SKILL) {
  10827. clif_msg(sd, WORK_IN_PROGRESS);
  10828. return;
  10829. }
  10830. if( SKILL_CHK_HOMUN(skill_id) ) {
  10831. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10832. return;
  10833. }
  10834. if( SKILL_CHK_MERC(skill_id) ) {
  10835. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10836. return;
  10837. }
  10838. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10839. #ifdef RENEWAL
  10840. clif_msg( sd, WORK_IN_PROGRESS );
  10841. #endif
  10842. return;
  10843. }
  10844. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10845. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10846. sd->idletime = last_tick;
  10847. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10848. sd->idletime_hom = last_tick;
  10849. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10850. sd->idletime_mer = last_tick;
  10851. if( skill_isNotOk(skill_id, sd) )
  10852. return;
  10853. if( skillmoreinfo != -1 ) {
  10854. if( pc_issit(sd) ) {
  10855. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10856. return;
  10857. }
  10858. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10859. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10860. }
  10861. if( sd->ud.skilltimer != INVALID_TIMER )
  10862. return;
  10863. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10864. if( sd->skillitem != skill_id ) {
  10865. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10866. return;
  10867. }
  10868. }
  10869. if( sd->sc.option&OPTION_COSTUME )
  10870. return;
  10871. #ifndef RENEWAL
  10872. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10873. return; // On basilica only caster can use Basilica again to stop it.
  10874. #endif
  10875. if( sd->menuskill_id ) {
  10876. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10877. clif_menuskill_clear(sd); //Cancel pet capture.
  10878. }else if( sd->menuskill_id == SG_FEEL ){
  10879. clif_menuskill_clear( sd ); // Cancel selection
  10880. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10881. return; //Can't use skills while a menu is open.
  10882. }
  10883. pc_delinvincibletimer(sd);
  10884. if( sd->skillitem == skill_id ) {
  10885. if( skill_lv != sd->skillitemlv )
  10886. skill_lv = sd->skillitemlv;
  10887. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10888. } else {
  10889. int lv;
  10890. sd->skillitem = sd->skillitemlv = 0;
  10891. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10892. if( skill_lv > lv )
  10893. skill_lv = lv;
  10894. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10895. }
  10896. }
  10897. }
  10898. /// Request to use a ground skill.
  10899. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10900. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10901. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10902. /// There are various variants of this packet, some of them have padding between fields.
  10903. void clif_parse_UseSkillToPos(int fd, map_session_data *sd)
  10904. {
  10905. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10906. if (pc_cant_act(sd))
  10907. return;
  10908. if (pc_issit(sd))
  10909. return;
  10910. clif_parse_UseSkillToPosSub(fd, sd,
  10911. RFIFOW(fd,info->pos[0]), //skill lv
  10912. RFIFOW(fd,info->pos[1]), //skill num
  10913. RFIFOW(fd,info->pos[2]), //pos x
  10914. RFIFOW(fd,info->pos[3]), //pos y
  10915. // TODO: find out what this is intended to do
  10916. //RFIFOB(fd, info->pos[4])
  10917. -1 //Skill more info.
  10918. );
  10919. }
  10920. /// Request to use a ground skill with text.
  10921. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10922. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10923. /// There are various variants of this packet, some of them have padding between fields.
  10924. void clif_parse_UseSkillToPosMoreInfo(int fd, map_session_data *sd)
  10925. {
  10926. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10927. if (pc_cant_act(sd))
  10928. return;
  10929. if (pc_issit(sd))
  10930. return;
  10931. clif_parse_UseSkillToPosSub(fd, sd,
  10932. RFIFOW(fd,info->pos[0]), //Skill lv
  10933. RFIFOW(fd,info->pos[1]), //Skill num
  10934. RFIFOW(fd,info->pos[2]), //pos x
  10935. RFIFOW(fd,info->pos[3]), //pos y
  10936. info->pos[4] //skill more info
  10937. );
  10938. }
  10939. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10940. /// 011b <skill id>.W <map name>.16B
  10941. void clif_parse_UseSkillMap(int fd, map_session_data* sd)
  10942. {
  10943. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10944. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10945. char map_name[MAP_NAME_LENGTH];
  10946. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10947. sd->state.workinprogress = WIP_DISABLE_NONE;
  10948. if(skill_id != sd->menuskill_id)
  10949. return;
  10950. //It is possible to use teleport with the storage window open bugreport:8027
  10951. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10952. clif_menuskill_clear(sd);
  10953. return;
  10954. }
  10955. pc_delinvincibletimer(sd);
  10956. skill_castend_map(sd,skill_id,map_name);
  10957. }
  10958. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10959. /// 011d
  10960. void clif_parse_RequestMemo(int fd,map_session_data *sd)
  10961. {
  10962. if (!pc_isdead(sd))
  10963. pc_memo(sd,-1);
  10964. }
  10965. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10966. /// 018e <name id>.W { <material id>.W }*3
  10967. void clif_parse_ProduceMix(int fd,map_session_data *sd){
  10968. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10969. switch( sd->menuskill_id ) {
  10970. case -1:
  10971. case AM_PHARMACY:
  10972. case RK_RUNEMASTERY:
  10973. case GC_RESEARCHNEWPOISON:
  10974. break;
  10975. default:
  10976. return;
  10977. }
  10978. if (pc_istrading(sd)) {
  10979. //Make it fail to avoid shop exploits where you sell something different than you see.
  10980. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10981. clif_menuskill_clear(sd);
  10982. return;
  10983. }
  10984. int produce_idx;
  10985. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10986. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10987. clif_menuskill_clear(sd);
  10988. }
  10989. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10990. /// 025b <mk type>.W <name id>.W
  10991. /// mk type:
  10992. /// 1 = cooking
  10993. /// 2 = arrow
  10994. /// 3 = elemental
  10995. /// 4 = GN_MIX_COOKING
  10996. /// 5 = GN_MAKEBOMB
  10997. /// 6 = GN_S_PHARMACY
  10998. /// 7 = MT_M_MACHINE - Unconfirmed
  10999. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11000. void clif_parse_Cooking(int fd,map_session_data *sd) {
  11001. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11002. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11003. short food_idx = -1;
  11004. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11005. return;
  11006. if (pc_istrading(sd)) {
  11007. //Make it fail to avoid shop exploits where you sell something different than you see.
  11008. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11009. clif_menuskill_clear(sd);
  11010. return;
  11011. }
  11012. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11013. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11014. clif_menuskill_clear(sd);
  11015. }
  11016. /// Answer to repair weapon item selection dialog
  11017. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11018. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11019. void clif_parse_RepairItem( int fd, map_session_data *sd ){
  11020. // Hercules has wrong date -> use correct one here
  11021. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11022. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11023. #else
  11024. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11025. #endif
  11026. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11027. return;
  11028. if (pc_istrading(sd)) {
  11029. //Make it fail to avoid shop exploits where you sell something different than you see.
  11030. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11031. clif_menuskill_clear(sd);
  11032. return;
  11033. }
  11034. skill_repairweapon( sd, p->item.index );
  11035. clif_menuskill_clear(sd);
  11036. }
  11037. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11038. /// 0222 <index>.L
  11039. void clif_parse_WeaponRefine( int fd, map_session_data *sd ){
  11040. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11041. return;
  11042. if (pc_istrading(sd)) {
  11043. //Make it fail to avoid shop exploits where you sell something different than you see.
  11044. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11045. clif_menuskill_clear(sd);
  11046. return;
  11047. }
  11048. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11049. clif_menuskill_clear(sd);
  11050. }
  11051. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11052. /// 00b8 <npc id>.L <choice>.B
  11053. /// choice:
  11054. /// 1~254 = menu item
  11055. /// 255 = cancel
  11056. /// NOTE: If there were more than 254 items in the list, choice
  11057. /// overflows to choice%256.
  11058. void clif_parse_NpcSelectMenu(int fd,map_session_data *sd){
  11059. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11060. int npc_id = RFIFOL(fd,info->pos[0]);
  11061. uint8 select = RFIFOB(fd,info->pos[1]);
  11062. #ifdef SECURE_NPCTIMEOUT
  11063. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11064. return;
  11065. #endif
  11066. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11067. TBL_NPC* nd = map_id2nd(npc_id);
  11068. 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);
  11069. clif_GM_kick(NULL,sd);
  11070. return;
  11071. }
  11072. sd->npc_menu = select;
  11073. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11074. sd->idletime = last_tick;
  11075. }
  11076. npc_scriptcont(sd,npc_id, false);
  11077. }
  11078. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11079. /// 00b9 <npc id>.L
  11080. void clif_parse_NpcNextClicked(int fd,map_session_data *sd)
  11081. {
  11082. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11083. sd->idletime = last_tick;
  11084. }
  11085. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11086. }
  11087. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11088. /// 0143 <npc id>.L <value>.L
  11089. void clif_parse_NpcAmountInput(int fd,map_session_data *sd){
  11090. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11091. int npcid = RFIFOL(fd,info->pos[0]);
  11092. int amount = (int)RFIFOL(fd,info->pos[1]);
  11093. sd->npc_amount = amount;
  11094. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11095. sd->idletime = last_tick;
  11096. }
  11097. npc_scriptcont(sd, npcid, false);
  11098. }
  11099. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11100. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11101. void clif_parse_NpcStringInput(int fd, map_session_data* sd){
  11102. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11103. int message_len = RFIFOW(fd,info->pos[0])-8;
  11104. int npcid = RFIFOL(fd,info->pos[1]);
  11105. const char* message = RFIFOCP(fd,info->pos[2]);
  11106. if( message_len <= 0 )
  11107. return; // invalid input
  11108. #if PACKETVER >= 20151001
  11109. message_len++;
  11110. #endif
  11111. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11112. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11113. sd->idletime = last_tick;
  11114. }
  11115. npc_scriptcont(sd, npcid, false);
  11116. }
  11117. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11118. /// 0146 <npc id>.L
  11119. void clif_parse_NpcCloseClicked(int fd,map_session_data *sd)
  11120. {
  11121. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11122. return;
  11123. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11124. sd->idletime = last_tick;
  11125. }
  11126. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11127. }
  11128. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11129. /// 0178 <index>.W
  11130. /// index:
  11131. /// -1 = cancel
  11132. void clif_parse_ItemIdentify(int fd,map_session_data *sd) {
  11133. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11134. if (sd->menuskill_id != MC_IDENTIFY)
  11135. return;
  11136. // Ignore the request
  11137. // - Invalid item index
  11138. // - Invalid item ID or item doesn't exist
  11139. // - Item is already identified
  11140. if (idx < 0 || idx >= MAX_INVENTORY ||
  11141. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11142. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11143. sd->state.workinprogress = WIP_DISABLE_NONE;
  11144. clif_menuskill_clear(sd);
  11145. return;
  11146. }
  11147. skill_identify(sd, idx);
  11148. clif_menuskill_clear(sd);
  11149. }
  11150. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11151. /// 01ae <name id>.W
  11152. void clif_parse_SelectArrow(int fd,map_session_data *sd) {
  11153. if (pc_istrading(sd)) {
  11154. //Make it fail to avoid shop exploits where you sell something different than you see.
  11155. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11156. clif_menuskill_clear(sd);
  11157. return;
  11158. }
  11159. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11160. switch (sd->menuskill_id) {
  11161. case AC_MAKINGARROW:
  11162. skill_arrow_create(sd,p->itemId);
  11163. break;
  11164. case SA_CREATECON:
  11165. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11166. break;
  11167. case GC_POISONINGWEAPON:
  11168. skill_poisoningweapon(sd,p->itemId);
  11169. break;
  11170. case NC_MAGICDECOY:
  11171. skill_magicdecoy(sd,p->itemId);
  11172. break;
  11173. }
  11174. clif_menuskill_clear(sd);
  11175. }
  11176. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11177. /// 01ce <skill id>.L
  11178. void clif_parse_AutoSpell(int fd,map_session_data *sd)
  11179. {
  11180. if (sd->menuskill_id != SA_AUTOSPELL)
  11181. return;
  11182. sd->state.workinprogress = WIP_DISABLE_NONE;
  11183. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11184. clif_menuskill_clear(sd);
  11185. }
  11186. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11187. /// 017a <card index>.W
  11188. void clif_parse_UseCard(int fd,map_session_data *sd)
  11189. {
  11190. if (sd->state.trading != 0)
  11191. return;
  11192. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11193. }
  11194. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11195. /// 017c <card index>.W <equip index>.W
  11196. void clif_parse_InsertCard(int fd,map_session_data *sd)
  11197. {
  11198. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11199. if (sd->state.trading != 0)
  11200. return;
  11201. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11202. }
  11203. /// Request of character's name by char ID.
  11204. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11205. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11206. /// There are various variants of this packet, some of them have padding between fields.
  11207. void clif_parse_SolveCharName(int fd, map_session_data *sd)
  11208. {
  11209. int charid;
  11210. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11211. map_reqnickdb(sd, charid);
  11212. }
  11213. /// /resetskill /resetstate (CZ_RESET).
  11214. /// Request to reset stats or skills.
  11215. /// 0197 <type>.W
  11216. /// type:
  11217. /// 0 = state
  11218. /// 1 = skill
  11219. void clif_parse_ResetChar(int fd, map_session_data *sd) {
  11220. char cmd[15];
  11221. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11222. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11223. else
  11224. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11225. is_atcommand(fd, sd, cmd, 1);
  11226. }
  11227. /// /lb /nlb (CZ_LOCALBROADCAST).
  11228. /// Request to broadcast a message on current map.
  11229. /// 019c <packet len>.W <text>.?B
  11230. void clif_parse_LocalBroadcast(int fd, map_session_data* sd)
  11231. {
  11232. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11233. char command[CHAT_SIZE_MAX+16];
  11234. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11235. char* msg = RFIFOCP(fd,info->pos[1]);
  11236. // as the length varies depending on the command used, just block unreasonably long strings
  11237. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11238. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11239. is_atcommand(fd, sd, command, 1);
  11240. }
  11241. /// Request to move an item from inventory to storage.
  11242. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11243. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11244. /// There are various variants of this packet, some of them have padding between fields.
  11245. void clif_parse_MoveToKafra(int fd, map_session_data *sd)
  11246. {
  11247. int item_index, item_amount;
  11248. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11249. if (pc_istrading(sd))
  11250. return;
  11251. item_index = RFIFOW(fd,info->pos[0])-2;
  11252. item_amount = RFIFOL(fd,info->pos[1]);
  11253. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11254. return;
  11255. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11256. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11257. return;
  11258. }
  11259. if (sd->state.storage_flag == 1)
  11260. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11261. else
  11262. if (sd->state.storage_flag == 2)
  11263. storage_guild_storageadd(sd, item_index, item_amount);
  11264. else if (sd->state.storage_flag == 3)
  11265. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11266. }
  11267. /// Request to move an item from storage to inventory.
  11268. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11269. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11270. /// There are various variants of this packet, some of them have padding between fields.
  11271. void clif_parse_MoveFromKafra(int fd,map_session_data *sd)
  11272. {
  11273. int item_index, item_amount;
  11274. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11275. item_index = RFIFOW(fd,info->pos[0])-1;
  11276. item_amount = RFIFOL(fd,info->pos[1]);
  11277. if (sd->state.storage_flag == 1)
  11278. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11279. else if(sd->state.storage_flag == 2)
  11280. storage_guild_storageget(sd, item_index, item_amount);
  11281. else if(sd->state.storage_flag == 3)
  11282. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11283. }
  11284. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11285. /// 0129 <index>.W <amount>.L
  11286. void clif_parse_MoveToKafraFromCart(int fd, map_session_data *sd){
  11287. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11288. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11289. int amount = RFIFOL(fd,info->pos[1]);
  11290. if( sd->state.vending )
  11291. return;
  11292. if (!pc_iscarton(sd))
  11293. return;
  11294. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11295. return;
  11296. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11297. return;
  11298. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11299. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11300. return;
  11301. }
  11302. if (sd->state.storage_flag == 1)
  11303. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11304. else if (sd->state.storage_flag == 2)
  11305. storage_guild_storageaddfromcart(sd, idx, amount);
  11306. else if (sd->state.storage_flag == 3)
  11307. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11308. }
  11309. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11310. /// 0128 <index>.W <amount>.L
  11311. void clif_parse_MoveFromKafraToCart(int fd, map_session_data *sd){
  11312. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11313. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11314. int amount = RFIFOL(fd,info->pos[1]);
  11315. if( sd->state.vending )
  11316. return;
  11317. if (!pc_iscarton(sd))
  11318. return;
  11319. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11320. return;
  11321. if (sd->state.storage_flag == 1)
  11322. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11323. else
  11324. if (sd->state.storage_flag == 2)
  11325. storage_guild_storagegettocart(sd, idx, amount);
  11326. else if (sd->state.storage_flag == 3)
  11327. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11328. }
  11329. /// Request to close storage (CZ_CLOSE_STORE).
  11330. /// 00f7
  11331. void clif_parse_CloseKafra(int fd, map_session_data *sd)
  11332. {
  11333. if( sd->state.storage_flag == 1 )
  11334. storage_storageclose(sd);
  11335. else
  11336. if( sd->state.storage_flag == 2 )
  11337. storage_guild_storageclose(sd);
  11338. else if( sd->state.storage_flag == 3 )
  11339. storage_premiumStorage_close(sd);
  11340. }
  11341. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11342. /// 023a <info>.W
  11343. /// info:
  11344. /// 0 = password has not been set yet
  11345. /// 1 = storage is password-protected
  11346. /// 8 = too many wrong passwords
  11347. /// ? = ignored
  11348. /// NOTE: This packet is only available on certain non-kRO clients.
  11349. void clif_storagepassword(map_session_data* sd, short info)
  11350. {
  11351. int fd = sd->fd;
  11352. WFIFOHEAD(fd,packet_len(0x23a));
  11353. WFIFOW(fd,0) = 0x23a;
  11354. WFIFOW(fd,2) = info;
  11355. WFIFOSET(fd,packet_len(0x23a));
  11356. }
  11357. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11358. /// 023b <type>.W <password>.16B <new password>.16B
  11359. /// type:
  11360. /// 2 = change password
  11361. /// 3 = check password
  11362. /// NOTE: This packet is only available on certain non-kRO clients.
  11363. void clif_parse_StoragePassword(int fd, map_session_data *sd){ //@TODO
  11364. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11365. // int type = RFIFOW(fd,info->pos[0]);
  11366. // char* password = RFIFOP(fd,info->pos[1]);
  11367. // char* new_password = RFIFOP(fd,info->pos[2]);
  11368. // storage_changepass(sd,password,new_password);
  11369. }
  11370. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11371. /// 023c <result>.W <error count>.W
  11372. /// result:
  11373. /// 4 = password change success
  11374. /// 5 = password change failure
  11375. /// 6 = password check success
  11376. /// 7 = password check failure
  11377. /// 8 = too many wrong passwords
  11378. /// ? = ignored
  11379. /// NOTE: This packet is only available on certain non-kRO clients.
  11380. void clif_storagepassword_result(map_session_data* sd, short result, short error_count)
  11381. {
  11382. int fd = sd->fd;
  11383. WFIFOHEAD(fd,packet_len(0x23c));
  11384. WFIFOW(fd,0) = 0x23c;
  11385. WFIFOW(fd,2) = result;
  11386. WFIFOW(fd,4) = error_count;
  11387. WFIFOSET(fd,packet_len(0x23c));
  11388. }
  11389. /// Party creation request
  11390. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11391. void clif_parse_CreateParty(int fd, map_session_data *sd){
  11392. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11393. name[NAME_LENGTH-1] = '\0';
  11394. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11395. clif_displaymessage(fd, msg_txt(sd,227));
  11396. return;
  11397. }
  11398. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11399. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11400. return;
  11401. }
  11402. party_create(sd,name,0,0);
  11403. }
  11404. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11405. void clif_parse_CreateParty2(int fd, map_session_data *sd){
  11406. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11407. char* name = RFIFOCP(fd,info->pos[0]);
  11408. int item1 = RFIFOB(fd,info->pos[1]);
  11409. int item2 = RFIFOB(fd,info->pos[2]);
  11410. name[NAME_LENGTH-1] = '\0';
  11411. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11412. clif_displaymessage(fd, msg_txt(sd,227));
  11413. return;
  11414. }
  11415. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11416. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11417. return;
  11418. }
  11419. party_create(sd,name,item1,item2);
  11420. }
  11421. /// Party invitation request
  11422. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11423. void clif_parse_PartyInvite(int fd, map_session_data *sd)
  11424. {
  11425. map_session_data *t_sd;
  11426. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11427. clif_displaymessage(fd, msg_txt(sd,227));
  11428. return;
  11429. }
  11430. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11431. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11432. clif_noask_sub(sd, t_sd, 1);
  11433. return;
  11434. }
  11435. party_invite(sd, t_sd);
  11436. }
  11437. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11438. void clif_parse_PartyInvite2(int fd, map_session_data *sd){
  11439. map_session_data *t_sd;
  11440. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11441. name[NAME_LENGTH-1] = '\0';
  11442. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11443. clif_displaymessage(fd, msg_txt(sd,227));
  11444. return;
  11445. }
  11446. t_sd = map_nick2sd(name,false);
  11447. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11448. clif_noask_sub(sd, t_sd, 1);
  11449. return;
  11450. }
  11451. party_invite(sd, t_sd);
  11452. }
  11453. /// Party invitation reply
  11454. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11455. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11456. /// flag:
  11457. /// 0 = reject
  11458. /// 1 = accept
  11459. void clif_parse_ReplyPartyInvite(int fd,map_session_data *sd)
  11460. {
  11461. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11462. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11463. RFIFOL(fd,info->pos[1]));
  11464. }
  11465. //(CZ_PARTY_JOIN_REQ_ACK)
  11466. void clif_parse_ReplyPartyInvite2(int fd,map_session_data *sd)
  11467. {
  11468. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11469. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11470. RFIFOB(fd,info->pos[1]));
  11471. }
  11472. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11473. /// 0100
  11474. void clif_parse_LeaveParty(int fd, map_session_data *sd)
  11475. {
  11476. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11477. clif_displaymessage(fd, msg_txt(sd,227));
  11478. return;
  11479. }
  11480. party_leave(sd);
  11481. }
  11482. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11483. /// 0103 <account id>.L <char name>.24B
  11484. void clif_parse_RemovePartyMember(int fd, map_session_data *sd)
  11485. {
  11486. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11487. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11488. clif_displaymessage(fd, msg_txt(sd,227));
  11489. return;
  11490. }
  11491. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11492. RFIFOCP(fd,info->pos[1]));
  11493. }
  11494. /// Request to change party options.
  11495. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11496. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11497. void clif_parse_PartyChangeOption(int fd, map_session_data *sd)
  11498. {
  11499. struct party_data *p;
  11500. int i,expflag;
  11501. int cmd = RFIFOW(fd,0);
  11502. struct s_packet_db* info = &packet_db[cmd];
  11503. if( !sd->status.party_id )
  11504. return;
  11505. p = party_search(sd->status.party_id);
  11506. if( p == NULL )
  11507. return;
  11508. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11509. if( i == MAX_PARTY )
  11510. return; //Shouldn't happen
  11511. if( !p->party.member[i].leader )
  11512. return;
  11513. expflag = RFIFOL(fd,info->pos[0]);
  11514. if(cmd == 0x0102){ //Client can't change the item-field
  11515. party_changeoption(sd, expflag, p->party.item);
  11516. }
  11517. else {
  11518. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11519. party_changeoption(sd, expflag, itemflag);
  11520. }
  11521. }
  11522. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11523. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11524. void clif_parse_PartyMessage(int fd, map_session_data* sd){
  11525. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11526. // validate packet and retrieve name and message
  11527. if( !clif_process_message( sd, false, name, message, output ) )
  11528. return;
  11529. party_send_message(sd, output, strlen(output) + 1 );
  11530. }
  11531. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11532. /// 07da <account id>.L
  11533. void clif_parse_PartyChangeLeader(int fd, map_session_data* sd){
  11534. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11535. }
  11536. /// Party Booking in KRO [Spiria]
  11537. ///
  11538. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11539. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11540. void clif_parse_PartyBookingRegisterReq(int fd, map_session_data* sd){
  11541. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11542. short level = RFIFOW(fd,info->pos[0]);
  11543. short mapid = RFIFOW(fd,info->pos[1]);
  11544. int idxpbj = info->pos[2];
  11545. short job[MAX_PARTY_BOOKING_JOBS];
  11546. int i;
  11547. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11548. job[i] = RFIFOB(fd,idxpbj+i*2);
  11549. party_booking_register(sd, level, mapid, job);
  11550. }
  11551. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11552. /// 0803 <result>.W
  11553. /// result:
  11554. /// 0 = success
  11555. /// 1 = failure
  11556. /// 2 = already registered
  11557. void clif_PartyBookingRegisterAck(map_session_data *sd, int flag)
  11558. {
  11559. int fd = sd->fd;
  11560. WFIFOHEAD(fd,packet_len(0x803));
  11561. WFIFOW(fd,0) = 0x803;
  11562. WFIFOW(fd,2) = flag;
  11563. WFIFOSET(fd,packet_len(0x803));
  11564. }
  11565. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11566. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11567. void clif_parse_PartyBookingSearchReq(int fd, map_session_data* sd){
  11568. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11569. short level = RFIFOW(fd,info->pos[0]);
  11570. short mapid = RFIFOW(fd,info->pos[1]);
  11571. short job = RFIFOW(fd,info->pos[2]);
  11572. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11573. short resultcount = RFIFOW(fd,info->pos[4]);
  11574. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11575. }
  11576. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11577. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11578. /// more results:
  11579. /// 0 = no
  11580. /// 1 = yes
  11581. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11582. {
  11583. int i, j;
  11584. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11585. struct party_booking_ad_info *pb_ad;
  11586. WFIFOHEAD(fd,size*count + 5);
  11587. WFIFOW(fd,0) = 0x805;
  11588. WFIFOW(fd,2) = size*count + 5;
  11589. WFIFOB(fd,4) = more_result;
  11590. for(i=0; i<count; i++)
  11591. {
  11592. pb_ad = results[i];
  11593. WFIFOL(fd,i*size+5) = pb_ad->index;
  11594. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11595. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11596. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11597. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11598. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11599. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11600. }
  11601. WFIFOSET(fd,WFIFOW(fd,2));
  11602. }
  11603. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11604. /// 0806
  11605. void clif_parse_PartyBookingDeleteReq(int fd, map_session_data* sd)
  11606. {
  11607. if(party_booking_delete(sd))
  11608. clif_PartyBookingDeleteAck(sd, 0);
  11609. }
  11610. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11611. /// 0807 <result>.W
  11612. /// result:
  11613. /// 0 = success
  11614. /// 1 = success (auto-removed expired ad)
  11615. /// 2 = failure
  11616. /// 3 = nothing registered
  11617. void clif_PartyBookingDeleteAck(map_session_data* sd, int flag)
  11618. {
  11619. int fd = sd->fd;
  11620. WFIFOHEAD(fd,packet_len(0x807));
  11621. WFIFOW(fd,0) = 0x807;
  11622. WFIFOW(fd,2) = flag;
  11623. WFIFOSET(fd,packet_len(0x807));
  11624. }
  11625. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11626. /// 0808 { <job>.W }*6
  11627. void clif_parse_PartyBookingUpdateReq(int fd, map_session_data* sd)
  11628. {
  11629. short job[MAX_PARTY_BOOKING_JOBS];
  11630. int i;
  11631. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11632. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11633. job[i] = RFIFOW(fd,idxpbu+i*2);
  11634. party_booking_update(sd, job);
  11635. }
  11636. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11637. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11638. void clif_PartyBookingInsertNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11639. {
  11640. int i;
  11641. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11642. if(pb_ad == NULL) return;
  11643. WBUFW(buf,0) = 0x809;
  11644. WBUFL(buf,2) = pb_ad->index;
  11645. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11646. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11647. WBUFW(buf,34) = pb_ad->p_detail.level;
  11648. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11649. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11650. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11651. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11652. }
  11653. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11654. /// 080a <index>.L { <job>.W }*6
  11655. void clif_PartyBookingUpdateNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11656. {
  11657. int i;
  11658. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11659. if(pb_ad == NULL) return;
  11660. WBUFW(buf,0) = 0x80a;
  11661. WBUFL(buf,2) = pb_ad->index;
  11662. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11663. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11664. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11665. }
  11666. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11667. /// 080b <index>.L
  11668. void clif_PartyBookingDeleteNotify(map_session_data* sd, int index)
  11669. {
  11670. uint8 buf[6];
  11671. WBUFW(buf,0) = 0x80b;
  11672. WBUFL(buf,2) = index;
  11673. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11674. }
  11675. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11676. /// 012e
  11677. void clif_parse_CloseVending(int fd, map_session_data* sd)
  11678. {
  11679. vending_closevending(sd);
  11680. }
  11681. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11682. /// 0130 <account id>.L
  11683. void clif_parse_VendingListReq(int fd, map_session_data* sd)
  11684. {
  11685. if( sd->npc_id ) {// using an NPC
  11686. return;
  11687. }
  11688. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11689. }
  11690. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11691. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11692. void clif_parse_PurchaseReq(int fd, map_session_data* sd){
  11693. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11694. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11695. // whether it fails or not, the buy window is closed
  11696. sd->vended_id = 0;
  11697. }
  11698. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11699. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11700. void clif_parse_PurchaseReq2(int fd, map_session_data* sd){
  11701. #if PACKETVER >= 20100105
  11702. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11703. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11704. // whether it fails or not, the buy window is closed
  11705. sd->vended_id = 0;
  11706. #endif
  11707. }
  11708. /// Confirm or cancel the shop preparation window.
  11709. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11710. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11711. /// result:
  11712. /// 0 = canceled
  11713. /// 1 = open
  11714. void clif_parse_OpenVending(int fd, map_session_data* sd){
  11715. int cmd = RFIFOW(fd,0);
  11716. struct s_packet_db* info = &packet_db[cmd];
  11717. short len = (short)RFIFOW(fd,info->pos[0]);
  11718. const char* message = RFIFOCP(fd,info->pos[1]);
  11719. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11720. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11721. len -= 84;
  11722. }
  11723. else { //(CZ_REQ_OPENSTORE2)
  11724. bool flag;
  11725. len -= 85;
  11726. flag = RFIFOB(fd,info->pos[2]) != 0;
  11727. if (!flag) {
  11728. sd->state.prevend = 0;
  11729. sd->state.workinprogress = WIP_DISABLE_NONE;
  11730. }
  11731. }
  11732. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11733. return;
  11734. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11735. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11736. return;
  11737. }
  11738. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11739. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11740. return;
  11741. }
  11742. if( message[0] == '\0' ) // invalid input
  11743. return;
  11744. vending_openvending(sd, message, data, len/8, NULL);
  11745. }
  11746. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11747. /// 0165 <char id>.L <guild name>.24B
  11748. void clif_parse_CreateGuild(int fd,map_session_data *sd){
  11749. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11750. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11751. name[NAME_LENGTH-1] = '\0';
  11752. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11753. clif_displaymessage(fd, msg_txt(sd,228));
  11754. return;
  11755. }
  11756. if(sd->clan){
  11757. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11758. return;
  11759. }
  11760. guild_create(sd, name);
  11761. }
  11762. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11763. /// 014d
  11764. void clif_parse_GuildCheckMaster(int fd, map_session_data *sd)
  11765. {
  11766. clif_guild_masterormember(sd);
  11767. }
  11768. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11769. /// 014f <type>.L
  11770. /// type:
  11771. /// 0 = basic info
  11772. /// 1 = member manager
  11773. /// 2 = positions
  11774. /// 3 = skills
  11775. /// 4 = expulsion list
  11776. /// 5 = unknown (GM_ALLGUILDLIST)
  11777. /// 6 = notice
  11778. void clif_parse_GuildRequestInfo(int fd, map_session_data *sd)
  11779. {
  11780. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11781. if( !sd->status.guild_id && !sd->bg_id )
  11782. return;
  11783. switch( type )
  11784. {
  11785. case 0: // Basic Information Guild, hostile alliance information
  11786. clif_guild_basicinfo( *sd );
  11787. clif_guild_allianceinfo(sd);
  11788. break;
  11789. case 1: // Members list, list job title
  11790. clif_guild_positionnamelist(sd);
  11791. clif_guild_memberlist( *sd );
  11792. break;
  11793. case 2: // List job title, title information list
  11794. clif_guild_positionnamelist(sd);
  11795. clif_guild_positioninfolist(sd);
  11796. break;
  11797. case 3: // Skill list
  11798. clif_guild_skillinfo(sd);
  11799. break;
  11800. case 4: // Expulsion list
  11801. clif_guild_expulsionlist(sd);
  11802. break;
  11803. default:
  11804. ShowError("clif: guild request info: unknown type %d\n", type);
  11805. break;
  11806. }
  11807. }
  11808. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11809. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11810. void clif_parse_GuildChangePositionInfo(int fd, map_session_data *sd)
  11811. {
  11812. int i;
  11813. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11814. int len = RFIFOW(fd,info->pos[0]);
  11815. int idxgpos = info->pos[1];
  11816. if(!sd->state.gmaster_flag)
  11817. return;
  11818. for(i = idxgpos; i < len; i += 40 ){
  11819. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11820. }
  11821. }
  11822. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11823. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11824. void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){
  11825. if(!sd->state.gmaster_flag)
  11826. return;
  11827. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11828. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11829. for( int16 i = 0; i < entries; i++ ){
  11830. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11831. // Guild leadership change
  11832. if( entry.position == 0 ){
  11833. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11834. clif_msg( sd, GUILD_MASTER_WOE );
  11835. return;
  11836. }
  11837. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11838. clif_msg( sd, GUILD_MASTER_DELAY );
  11839. return;
  11840. }
  11841. guild_gm_change( sd->status.guild_id, entry.CID );
  11842. // No further entries will be processed - the requesting player lost his guild master status
  11843. return;
  11844. }else if( entry.position > 0 ){
  11845. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11846. }
  11847. }
  11848. }
  11849. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11850. /// 0151 <guild id>.L
  11851. void clif_parse_GuildRequestEmblem(int fd,map_session_data *sd)
  11852. {
  11853. struct guild* g;
  11854. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11855. if( (g = guild_search(guild_id)) != NULL )
  11856. clif_guild_emblem(sd,g);
  11857. }
  11858. /// Validates data of a guild emblem (compressed bitmap)
  11859. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11860. EMBVALIDATE_SUCCESS = 0,
  11861. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11862. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  11863. };
  11864. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11865. {
  11866. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11867. unsigned long buf_len = sizeof(buf);
  11868. int offset = 0;
  11869. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11870. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11871. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11872. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11873. ))
  11874. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11875. if(inter_config.emblem_transparency_limit != 100) {
  11876. int i, transcount = 1, tmp[3];
  11877. for(i = offset; i < buf_len-1; i++) {
  11878. int j = i%3;
  11879. tmp[j] = RBUFL(buf,i);
  11880. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11881. transcount++;
  11882. }
  11883. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  11884. return EMBVALIDATE_ERR_TRANSPARENCY;
  11885. }
  11886. return EMBVALIDATE_SUCCESS;
  11887. }
  11888. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11889. /// 0153 <packet len>.W <emblem data>.?B
  11890. void clif_parse_GuildChangeEmblem(int fd,map_session_data *sd){
  11891. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11892. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11893. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11894. int emb_val=0;
  11895. if( !emblem_len || !sd->state.gmaster_flag )
  11896. return;
  11897. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  11898. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11899. return;
  11900. }
  11901. emb_val = clif_validate_emblem(emblem, emblem_len);
  11902. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11903. 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);
  11904. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11905. return;
  11906. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11907. char output[128];
  11908. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  11909. 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"
  11910. return;
  11911. }
  11912. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11913. }
  11914. /// Request to update the guild emblem id (version, according to Gravity)
  11915. /// 0b46 <guild id>.L <version>.L
  11916. void clif_parse_GuildChangeEmblem2(int fd, map_session_data* sd) {
  11917. nullpo_retv(sd);
  11918. #if PACKETVER >= 20190724
  11919. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11920. guild* g = sd->guild;
  11921. if (g == nullptr || g->guild_id != p->guild_id)
  11922. return;
  11923. if (!sd->state.gmaster_flag)
  11924. return;
  11925. if (!inter_config.emblem_woe_change && is_agit_start()) {
  11926. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11927. return;
  11928. }
  11929. guild_change_emblem_version(sd, p->version);
  11930. #endif
  11931. }
  11932. /// Guild notice update request (CZ_GUILD_NOTICE).
  11933. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11934. void clif_parse_GuildChangeNotice(int fd, map_session_data* sd){
  11935. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11936. int guild_id = RFIFOL(fd,info->pos[0]);
  11937. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11938. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11939. if(!sd->state.gmaster_flag)
  11940. return;
  11941. // compensate for some client defects when using multilanguage mode
  11942. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11943. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11944. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11945. guild_change_notice(sd, guild_id, msg1, msg2);
  11946. }
  11947. // Helper function for guild invite functions
  11948. int clif_sub_guild_invite(int fd, map_session_data *sd, map_session_data *t_sd)
  11949. {
  11950. if (t_sd == NULL) // not online or does not exist
  11951. return 1;
  11952. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11953. clif_displaymessage(fd, msg_txt(sd,228));
  11954. return 1;
  11955. }
  11956. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11957. clif_noask_sub(sd, t_sd, 2);
  11958. return 1;
  11959. }
  11960. // Players in a clan can not join a guild
  11961. if(t_sd && t_sd->clan){
  11962. return 1;
  11963. }
  11964. guild_invite(sd, t_sd);
  11965. return 0;
  11966. }
  11967. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11968. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11969. void clif_parse_GuildInvite(int fd,map_session_data *sd){
  11970. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11971. map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11972. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11973. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11974. if (clif_sub_guild_invite(fd, sd, t_sd))
  11975. return;
  11976. }
  11977. /// Guild invite request (/guildinvite)
  11978. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11979. void
  11980. clif_parse_GuildInvite2(int fd, map_session_data *sd) {
  11981. map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11982. if (clif_sub_guild_invite(fd, sd, t_sd))
  11983. return;
  11984. }
  11985. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11986. /// 016b <guild id>.L <answer>.L
  11987. /// answer:
  11988. /// 0 = refuse
  11989. /// 1 = accept
  11990. void clif_parse_GuildReplyInvite(int fd,map_session_data *sd){
  11991. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11992. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11993. RFIFOL(fd,info->pos[1]));
  11994. }
  11995. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11996. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11997. void clif_parse_GuildLeave(int fd,map_session_data *sd){
  11998. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11999. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12000. clif_displaymessage(fd, msg_txt(sd,228));
  12001. return;
  12002. }
  12003. if( sd->bg_id ) {
  12004. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12005. return;
  12006. }
  12007. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12008. RFIFOL(fd,info->pos[1]),
  12009. RFIFOL(fd,info->pos[2]),
  12010. RFIFOCP(fd,info->pos[3]));
  12011. }
  12012. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12013. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12014. void clif_parse_GuildExpulsion(int fd,map_session_data *sd){
  12015. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12016. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12017. { // Guild locked.
  12018. clif_displaymessage(fd, msg_txt(sd,228));
  12019. return;
  12020. }
  12021. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12022. RFIFOL(fd,info->pos[1]),
  12023. RFIFOL(fd,info->pos[2]),
  12024. RFIFOCP(fd,info->pos[3]));
  12025. }
  12026. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12027. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12028. void clif_parse_GuildMessage(int fd, map_session_data* sd){
  12029. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12030. // validate packet and retrieve name and message
  12031. if( !clif_process_message( sd, false, name, message, output ) )
  12032. return;
  12033. if( sd->bg_id )
  12034. bg_send_message(sd, output, strlen(output) );
  12035. else
  12036. guild_send_message(sd, output, strlen(output) );
  12037. }
  12038. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12039. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12040. void clif_parse_GuildRequestAlliance(int fd, map_session_data *sd)
  12041. {
  12042. map_session_data *t_sd;
  12043. if(!sd->state.gmaster_flag)
  12044. return;
  12045. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12046. clif_displaymessage(fd, msg_txt(sd,228));
  12047. return;
  12048. }
  12049. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12050. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12051. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12052. // @noask [LuzZza]
  12053. if(t_sd && t_sd->state.noask) {
  12054. clif_noask_sub(sd, t_sd, 3);
  12055. return;
  12056. }
  12057. guild_reqalliance(sd,t_sd);
  12058. }
  12059. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12060. /// 0172 <inviter account id>.L <answer>.L
  12061. /// answer:
  12062. /// 0 = refuse
  12063. /// 1 = accept
  12064. void clif_parse_GuildReplyAlliance(int fd, map_session_data *sd){
  12065. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12066. guild_reply_reqalliance(sd,
  12067. RFIFOL(fd,info->pos[0]),
  12068. RFIFOL(fd,info->pos[1]));
  12069. }
  12070. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12071. /// 0183 <opponent guild id>.L <relation>.L
  12072. /// relation:
  12073. /// 0 = Ally
  12074. /// 1 = Enemy
  12075. void clif_parse_GuildDelAlliance(int fd, map_session_data *sd){
  12076. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12077. if(!sd->state.gmaster_flag)
  12078. return;
  12079. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12080. clif_displaymessage(fd, msg_txt(sd,228));
  12081. return;
  12082. }
  12083. guild_delalliance(sd,
  12084. RFIFOL(fd,info->pos[0]),
  12085. RFIFOL(fd,info->pos[1]));
  12086. }
  12087. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12088. /// 0180 <account id>.L
  12089. void clif_parse_GuildOpposition(int fd, map_session_data *sd)
  12090. {
  12091. map_session_data *t_sd;
  12092. if(!sd->state.gmaster_flag)
  12093. return;
  12094. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12095. clif_displaymessage(fd, msg_txt(sd,228));
  12096. return;
  12097. }
  12098. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12099. // @noask [LuzZza]
  12100. if(t_sd && t_sd->state.noask) {
  12101. clif_noask_sub(sd, t_sd, 4);
  12102. return;
  12103. }
  12104. guild_opposition(sd,t_sd);
  12105. }
  12106. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12107. /// 015d <key>.40B
  12108. /// key:
  12109. /// now guild name; might have been (intended) email, since the
  12110. /// field name and size is same as the one in CH_DELETE_CHAR.
  12111. void clif_parse_GuildBreak(int fd, map_session_data *sd)
  12112. {
  12113. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12114. clif_displaymessage(fd, msg_txt(sd,228));
  12115. return;
  12116. }
  12117. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12118. }
  12119. /// Pet
  12120. ///
  12121. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12122. /// 01a1 <type>.B
  12123. /// type:
  12124. /// 0 = pet information
  12125. /// 1 = feed
  12126. /// 2 = performance
  12127. /// 3 = return to egg
  12128. /// 4 = unequip accessory
  12129. void clif_parse_PetMenu(int fd, map_session_data *sd){
  12130. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12131. }
  12132. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12133. /// 019f <id>.L
  12134. void clif_parse_CatchPet(int fd, map_session_data *sd){
  12135. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12136. }
  12137. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12138. /// 01a7 <index>.W
  12139. void clif_parse_SelectEgg(int fd, map_session_data *sd){
  12140. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12141. return;
  12142. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12143. clif_menuskill_clear(sd);
  12144. }
  12145. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12146. /// 01a9 <data>.L
  12147. /// data:
  12148. /// is either emotion (@see enum emotion_type) or a compound value
  12149. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12150. /// entry (given in parentheses) in data\pettalktable.xml
  12151. /// act id:
  12152. /// 0 = feeding
  12153. /// 1 = hunting
  12154. /// 2 = danger
  12155. /// 3 = dead
  12156. /// 4 = normal (stand)
  12157. /// 5 = special performance (perfor_s)
  12158. /// 6 = level up (levelup)
  12159. /// 7 = performance 1 (perfor_1)
  12160. /// 8 = performance 2 (perfor_2)
  12161. /// 9 = performance 3 (perfor_3)
  12162. /// 10 = log-in greeting (connect)
  12163. /// hungry value:
  12164. /// 0 = very hungry (hungry)
  12165. /// 1 = hungry (bit_hungry)
  12166. /// 2 = satisfied (noting)
  12167. /// 3 = stuffed (full)
  12168. /// 4 = full (so_full)
  12169. void clif_parse_SendEmotion(int fd, map_session_data *sd)
  12170. {
  12171. if(sd->pd)
  12172. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12173. }
  12174. /// Request to change pet's name (CZ_RENAME_PET).
  12175. /// 01a5 <name>.24B
  12176. void clif_parse_ChangePetName(int fd, map_session_data *sd)
  12177. {
  12178. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12179. }
  12180. /// /kill (CZ_DISCONNECT_CHARACTER).
  12181. /// Request to disconnect a character.
  12182. /// 00cc <account id>.L
  12183. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12184. void clif_parse_GMKick(int fd, map_session_data *sd)
  12185. {
  12186. struct block_list *target;
  12187. int tid;
  12188. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12189. target = map_id2bl(tid);
  12190. if (!target) {
  12191. clif_GM_kickack(sd, 0);
  12192. return;
  12193. }
  12194. switch (target->type) {
  12195. case BL_PC:
  12196. {
  12197. char command[NAME_LENGTH+6];
  12198. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12199. is_atcommand(fd, sd, command, 1);
  12200. }
  12201. break;
  12202. /**
  12203. * This one does not invoke any atcommand, so we need to check for permissions.
  12204. */
  12205. case BL_MOB:
  12206. {
  12207. char command[100];
  12208. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12209. clif_GM_kickack(sd, 0);
  12210. return;
  12211. }
  12212. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12213. log_atcommand(sd, command);
  12214. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12215. }
  12216. break;
  12217. case BL_NPC:
  12218. {
  12219. struct npc_data* nd = (struct npc_data *)target;
  12220. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12221. npc_unload_duplicates(nd);
  12222. npc_unload(nd,true);
  12223. npc_read_event_script();
  12224. }
  12225. }
  12226. break;
  12227. default:
  12228. clif_GM_kickack(sd, 0);
  12229. }
  12230. }
  12231. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12232. /// Request to disconnect all characters.
  12233. /// 00ce
  12234. void clif_parse_GMKickAll(int fd, map_session_data* sd) {
  12235. char cmd[15];
  12236. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12237. is_atcommand(fd, sd, cmd, 1);
  12238. }
  12239. /// /remove (CZ_REMOVE_AID).
  12240. /// Request to warp to a character with given login ID.
  12241. /// 01ba <account name>.24B
  12242. /// /shift (CZ_SHIFT).
  12243. /// Request to warp to a character with given name.
  12244. /// 01bb <char name>.24B
  12245. void clif_parse_GMShift(int fd, map_session_data *sd)
  12246. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12247. char *player_name;
  12248. char command[NAME_LENGTH+8];
  12249. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12250. player_name[NAME_LENGTH-1] = '\0';
  12251. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12252. is_atcommand(fd, sd, command, 1);
  12253. }
  12254. /// /remove (CZ_REMOVE_AID_SSO).
  12255. /// Request to warp to a character with given account ID.
  12256. /// 0843 <account id>.L
  12257. void clif_parse_GMRemove2(int fd, map_session_data* sd)
  12258. {
  12259. uint32 account_id;
  12260. map_session_data* pl_sd;
  12261. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12262. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12263. char command[NAME_LENGTH+8];
  12264. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12265. is_atcommand(fd, sd, command, 1);
  12266. }
  12267. }
  12268. /// /recall (CZ_RECALL).
  12269. /// Request to summon a player with given login ID to own position.
  12270. /// 01bc <account name>.24B
  12271. /// /summon (CZ_RECALL_GID).
  12272. /// Request to summon a player with given name to own position.
  12273. /// 01bd <char name>.24B
  12274. void clif_parse_GMRecall(int fd, map_session_data *sd)
  12275. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12276. char *player_name;
  12277. char command [NAME_LENGTH+8];
  12278. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12279. player_name[NAME_LENGTH-1] = '\0';
  12280. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12281. is_atcommand(fd, sd, command, 1);
  12282. }
  12283. /// /recall (CZ_RECALL_SSO).
  12284. /// Request to summon a player with given account ID to own position.
  12285. /// 0842 <account id>.L
  12286. void clif_parse_GMRecall2(int fd, map_session_data* sd)
  12287. {
  12288. uint32 account_id;
  12289. map_session_data* pl_sd;
  12290. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12291. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12292. char command[NAME_LENGTH+8];
  12293. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12294. is_atcommand(fd, sd, command, 1);
  12295. }
  12296. }
  12297. /// /item /monster (CZ_ITEM_CREATE).
  12298. /// Request to execute GM commands.
  12299. /// Usage:
  12300. /// /item n - summon n monster or acquire n item/s
  12301. /// /item money - grants 2147483647 zenies
  12302. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12303. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12304. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12305. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12306. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12307. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12308. /// 013f <item/mob name>.24B
  12309. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12310. void clif_parse_GM_Item_Monster(int fd, map_session_data *sd)
  12311. {
  12312. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12313. int mob_id = 0;
  12314. StringBuf command;
  12315. char *str;
  12316. //#if PACKETVER >= 20131218
  12317. // char str[100];
  12318. //#else
  12319. // char str[24];
  12320. //#endif
  12321. str = RFIFOCP(fd,info->pos[0]);
  12322. if (!str || str[0] == '\0')
  12323. return;
  12324. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12325. return;
  12326. trim(str);
  12327. // Zeny
  12328. if( strcmpi(str, "money") == 0 ) {
  12329. StringBuf_Init(&command);
  12330. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12331. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12332. StringBuf_Destroy(&command);
  12333. return;
  12334. }
  12335. std::shared_ptr<item_data> id = item_db.searchname( str );
  12336. // Item
  12337. if( id ){
  12338. StringBuf_Init(&command);
  12339. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12340. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12341. }else{
  12342. if (id->flag.guid)
  12343. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12344. else
  12345. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12346. }
  12347. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12348. StringBuf_Destroy(&command);
  12349. return;
  12350. }
  12351. // Monster
  12352. if ((mob_id = mobdb_searchname(str)) == 0)
  12353. mob_id = mobdb_checkid(atoi(str));
  12354. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12355. if( mob != nullptr ) {
  12356. StringBuf_Init(&command);
  12357. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12358. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12359. StringBuf_Destroy(&command);
  12360. return;
  12361. }
  12362. }
  12363. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12364. /// 019d <effect state>.L
  12365. /// effect state:
  12366. /// TODO: Any OPTION_* ?
  12367. void clif_parse_GMHide(int fd, map_session_data *sd) {
  12368. char cmd[6];
  12369. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12370. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12371. is_atcommand(fd, sd, cmd, 1);
  12372. }
  12373. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12374. /// 0149 <account id>.L <type>.B <value>.W
  12375. /// type:
  12376. /// 0 = positive points
  12377. /// 1 = negative points
  12378. /// 2 = self mute (+10 minutes)
  12379. void clif_parse_GMReqNoChat(int fd,map_session_data *sd)
  12380. {
  12381. int id, type, value;
  12382. map_session_data *dstsd;
  12383. char command[NAME_LENGTH+15];
  12384. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12385. id = RFIFOL(fd,info->pos[0]);
  12386. type = RFIFOB(fd,info->pos[1]);
  12387. value = RFIFOW(fd,info->pos[2]);
  12388. if( type == 0 )
  12389. value = -value;
  12390. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12391. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12392. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12393. return;
  12394. dstsd = map_id2sd(id);
  12395. if( dstsd == NULL )
  12396. return;
  12397. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12398. is_atcommand(fd, sd, command, 1);
  12399. }
  12400. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12401. /// GM adjustment of a player's manner value by -60.
  12402. /// 0212 <char name>.24B
  12403. void clif_parse_GMRc(int fd, map_session_data* sd)
  12404. {
  12405. char command[NAME_LENGTH+15];
  12406. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12407. name[NAME_LENGTH-1] = '\0';
  12408. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12409. is_atcommand(fd, sd, command, 1);
  12410. }
  12411. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12412. /// 01e0 <account id>.L <account name>.24B
  12413. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12414. {
  12415. WFIFOHEAD(fd,packet_len(0x1e0));
  12416. WFIFOW(fd,0) = 0x1e0;
  12417. WFIFOL(fd,2) = account_id;
  12418. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12419. WFIFOSET(fd,packet_len(0x1e0));
  12420. }
  12421. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12422. /// 01df <account id>.L
  12423. //! TODO: Figure out how does this actually work
  12424. void clif_parse_GMReqAccountName(int fd, map_session_data *sd)
  12425. {
  12426. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12427. /*
  12428. char query[30];
  12429. safesnprintf(query,sizeof(query),"%d", account_id);
  12430. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12431. */
  12432. clif_account_name(fd, account_id, "");
  12433. }
  12434. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12435. /// GM single cell type change request.
  12436. /// 0198 <x>.W <y>.W <type>.W
  12437. /// type:
  12438. /// 0 = not walkable
  12439. /// 1 = walkable
  12440. void clif_parse_GMChangeMapType(int fd, map_session_data *sd)
  12441. {
  12442. int x,y,type;
  12443. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12444. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12445. return;
  12446. x = RFIFOW(fd,info->pos[0]);
  12447. y = RFIFOW(fd,info->pos[1]);
  12448. type = RFIFOW(fd,info->pos[2]);
  12449. map_setgatcell(sd->bl.m,x,y,type);
  12450. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12451. //FIXME: once players leave the map, the client 'forgets' this information.
  12452. }
  12453. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12454. /// Request to allow/deny whispers from a nick.
  12455. /// 00cf <nick>.24B <type>.B
  12456. /// type:
  12457. /// 0 = (/ex nick) deny speech from nick
  12458. /// 1 = (/in nick) allow speech from nick
  12459. void clif_parse_PMIgnore(int fd, map_session_data* sd)
  12460. {
  12461. char* nick;
  12462. uint8 type;
  12463. int i;
  12464. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12465. nick = RFIFOCP(fd,info->pos[0]);
  12466. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12467. type = RFIFOB(fd,info->pos[1]);
  12468. if( type == 0 ) { // Add name to ignore list (block)
  12469. if (strcmp(wisp_server_name, nick) == 0) {
  12470. clif_wisexin(sd, type, 1); // fail
  12471. return;
  12472. }
  12473. // try to find a free spot, while checking for duplicates at the same time
  12474. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12475. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12476. clif_wisexin(sd, type, 2); // too many blocks
  12477. return;
  12478. }
  12479. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12480. clif_wisexin(sd, type, 0); // Aegis reports success.
  12481. return;
  12482. }
  12483. //Insert in position i
  12484. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12485. } else { // Remove name from ignore list (unblock)
  12486. // find entry
  12487. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12488. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12489. clif_wisexin(sd, type, 1); // fail
  12490. return;
  12491. }
  12492. // move everything one place down to overwrite removed entry
  12493. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12494. // wipe last entry
  12495. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12496. }
  12497. clif_wisexin(sd, type, 0); // success
  12498. }
  12499. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12500. /// Request to allow/deny all whispers.
  12501. /// 00d0 <type>.B
  12502. /// type:
  12503. /// 0 = (/exall) deny all speech
  12504. /// 1 = (/inall) allow all speech
  12505. void clif_parse_PMIgnoreAll(int fd, map_session_data *sd)
  12506. {
  12507. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12508. if( type == 0 ) {// Deny all
  12509. if( sd->state.ignoreAll ) {
  12510. flag = 1; // fail
  12511. } else {
  12512. sd->state.ignoreAll = 1;
  12513. flag = 0; // success
  12514. }
  12515. } else {//Unblock everyone
  12516. if( sd->state.ignoreAll ) {
  12517. sd->state.ignoreAll = 0;
  12518. flag = 0; // success
  12519. } else {
  12520. if (sd->ignore[0].name[0] != '\0')
  12521. { //Wipe the ignore list.
  12522. memset(sd->ignore, 0, sizeof(sd->ignore));
  12523. flag = 0; // success
  12524. } else {
  12525. flag = 1; // fail
  12526. }
  12527. }
  12528. }
  12529. clif_wisall(sd, type, flag);
  12530. }
  12531. /// Whisper ignore list (ZC_WHISPER_LIST).
  12532. /// 00d4 <packet len>.W { <char name>.24B }*
  12533. void clif_PMIgnoreList(map_session_data* sd)
  12534. {
  12535. int i, fd = sd->fd;
  12536. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12537. WFIFOW(fd,0) = 0xd4;
  12538. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12539. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12540. }
  12541. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12542. WFIFOSET(fd,WFIFOW(fd,2));
  12543. }
  12544. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12545. /// 00d3
  12546. void clif_parse_PMIgnoreList(int fd,map_session_data *sd)
  12547. {
  12548. clif_PMIgnoreList(sd);
  12549. }
  12550. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12551. /// 01e7
  12552. void clif_parse_NoviceDoriDori(int fd, map_session_data *sd)
  12553. {
  12554. if (sd->state.doridori) return;
  12555. switch (sd->class_&MAPID_UPPERMASK) {
  12556. case MAPID_SOUL_LINKER:
  12557. case MAPID_STAR_GLADIATOR:
  12558. case MAPID_TAEKWON:
  12559. if (!sd->state.rest)
  12560. break;
  12561. case MAPID_SUPER_NOVICE:
  12562. case MAPID_SUPER_BABY:
  12563. case MAPID_SUPER_NOVICE_E:
  12564. case MAPID_SUPER_BABY_E:
  12565. sd->state.doridori=1;
  12566. break;
  12567. }
  12568. }
  12569. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12570. /// 01ed
  12571. /// Note: This packet is caused by 7 lines of any text, followed by
  12572. /// the prayer and an another line of any text. The prayer is
  12573. /// defined by lines 790~793 in data\msgstringtable.txt
  12574. /// "Dear angel, can you hear my voice?"
  12575. /// "I am" (space separated player name) "Super Novice~"
  12576. /// "Help me out~ Please~ T_T"
  12577. void clif_parse_NoviceExplosionSpirits(int fd, map_session_data *sd)
  12578. {
  12579. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12580. t_exp next = pc_nextbaseexp(sd);
  12581. if( next ) {
  12582. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12583. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12584. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12585. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12586. }
  12587. }
  12588. }
  12589. }
  12590. /// Friends List
  12591. ///
  12592. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12593. /// 0206 <account id>.L <char id>.L <state>.B
  12594. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12595. /// state:
  12596. /// 0 = online
  12597. /// 1 = offline
  12598. void clif_friendslist_toggle(map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12599. {
  12600. int i, fd = sd->fd;
  12601. //Seek friend.
  12602. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12603. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12604. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12605. return; //Not found
  12606. WFIFOHEAD(fd,packet_len(0x206));
  12607. WFIFOW(fd, 0) = 0x206;
  12608. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12609. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12610. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12611. #if PACKETVER >= 20180221
  12612. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12613. #endif
  12614. WFIFOSET(fd, packet_len(0x206));
  12615. }
  12616. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12617. int clif_friendslist_toggle_sub(map_session_data *sd,va_list ap)
  12618. {
  12619. uint32 account_id, char_id, online;
  12620. account_id = va_arg(ap, int);
  12621. char_id = va_arg(ap, int);
  12622. online = va_arg(ap, int);
  12623. clif_friendslist_toggle(sd, account_id, char_id, online);
  12624. return 0;
  12625. }
  12626. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12627. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12628. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12629. void clif_friendslist_send( map_session_data& sd ){
  12630. struct PACKET_ZC_FRIENDS_LIST* p = (struct PACKET_ZC_FRIENDS_LIST*)packet_buffer;
  12631. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12632. p->PacketLength = sizeof( *p );
  12633. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12634. struct PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12635. f.AID = sd.status.friends[i].account_id;
  12636. f.CID = sd.status.friends[i].char_id;
  12637. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12638. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12639. #endif
  12640. c++;
  12641. p->PacketLength += sizeof( f );
  12642. }
  12643. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12644. // Sending the online players
  12645. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12646. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12647. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12648. }
  12649. }
  12650. }
  12651. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12652. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12653. /// result:
  12654. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12655. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12656. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12657. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12658. void clif_friendslist_reqack(map_session_data *sd, map_session_data *f_sd, int type)
  12659. {
  12660. int fd;
  12661. nullpo_retv(sd);
  12662. fd = sd->fd;
  12663. WFIFOHEAD(fd,packet_len(0x209));
  12664. WFIFOW(fd,0) = 0x209;
  12665. WFIFOW(fd,2) = type;
  12666. if (f_sd) {
  12667. WFIFOL(fd,4) = f_sd->status.account_id;
  12668. WFIFOL(fd,8) = f_sd->status.char_id;
  12669. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12670. }
  12671. WFIFOSET(fd, packet_len(0x209));
  12672. }
  12673. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12674. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12675. void clif_friendlist_req(map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12676. {
  12677. int fd = sd->fd;
  12678. WFIFOHEAD(fd,packet_len(0x207));
  12679. WFIFOW(fd,0) = 0x207;
  12680. WFIFOL(fd,2) = account_id;
  12681. WFIFOL(fd,6) = char_id;
  12682. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12683. WFIFOSET(fd,packet_len(0x207));
  12684. }
  12685. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12686. /// 0202 <name>.24B
  12687. void clif_parse_FriendsListAdd(int fd, map_session_data *sd)
  12688. {
  12689. map_session_data *f_sd;
  12690. int i;
  12691. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12692. // Friend doesn't exist (no player with this name)
  12693. if (f_sd == NULL) {
  12694. clif_displaymessage(fd, msg_txt(sd,3));
  12695. return;
  12696. }
  12697. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12698. return;
  12699. }
  12700. // ensure that the request player's friend list is not full
  12701. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12702. if( i == MAX_FRIENDS ){
  12703. clif_friendslist_reqack(sd, f_sd, 2);
  12704. return;
  12705. }
  12706. // @noask [LuzZza]
  12707. if(f_sd->state.noask) {
  12708. clif_noask_sub(sd, f_sd, 5);
  12709. return;
  12710. }
  12711. // Friend already exists
  12712. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12713. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12714. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12715. return;
  12716. }
  12717. }
  12718. f_sd->friend_req = sd->status.char_id;
  12719. sd->friend_req = f_sd->status.char_id;
  12720. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12721. }
  12722. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12723. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12724. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12725. /// reply:
  12726. /// 0 = rejected
  12727. /// 1 = accepted
  12728. void clif_parse_FriendsListReply(int fd, map_session_data *sd)
  12729. {
  12730. map_session_data *f_sd;
  12731. uint32 account_id;
  12732. char reply;
  12733. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12734. account_id = RFIFOL(fd,info->pos[0]);
  12735. //char_id = RFIFOL(fd,info->pos[1]);
  12736. #if PACKETVER < 6
  12737. reply = RFIFOB(fd,info->pos[2]);
  12738. #else
  12739. reply = RFIFOL(fd,info->pos[2]);
  12740. #endif
  12741. if( sd->bl.id == account_id ) {// adding oneself as friend
  12742. return;
  12743. }
  12744. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12745. if (f_sd == NULL)
  12746. return;
  12747. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12748. clif_friendslist_reqack(f_sd, sd, 1);
  12749. else {
  12750. int i;
  12751. // Find an empty slot
  12752. for (i = 0; i < MAX_FRIENDS; i++)
  12753. if (f_sd->status.friends[i].char_id == 0)
  12754. break;
  12755. if (i == MAX_FRIENDS) {
  12756. clif_friendslist_reqack(f_sd, sd, 2);
  12757. return;
  12758. }
  12759. f_sd->status.friends[i].account_id = sd->status.account_id;
  12760. f_sd->status.friends[i].char_id = sd->status.char_id;
  12761. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12762. clif_friendslist_reqack(f_sd, sd, 0);
  12763. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12764. if (battle_config.friend_auto_add) {
  12765. // Also add f_sd to sd's friendlist.
  12766. for (i = 0; i < MAX_FRIENDS; i++) {
  12767. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12768. return; //No need to add anything.
  12769. if (sd->status.friends[i].char_id == 0)
  12770. break;
  12771. }
  12772. if (i == MAX_FRIENDS) {
  12773. clif_friendslist_reqack(sd, f_sd, 2);
  12774. return;
  12775. }
  12776. sd->status.friends[i].account_id = f_sd->status.account_id;
  12777. sd->status.friends[i].char_id = f_sd->status.char_id;
  12778. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12779. clif_friendslist_reqack(sd, f_sd, 0);
  12780. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12781. }
  12782. }
  12783. }
  12784. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12785. /// 0203 <account id>.L <char id>.L
  12786. void clif_parse_FriendsListRemove(int fd, map_session_data *sd)
  12787. {
  12788. map_session_data *f_sd = NULL;
  12789. uint32 account_id, char_id;
  12790. int i, j;
  12791. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12792. account_id = RFIFOL(fd,info->pos[0]);
  12793. char_id = RFIFOL(fd,info->pos[1]);
  12794. // Search friend
  12795. for (i = 0; i < MAX_FRIENDS &&
  12796. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12797. if (i == MAX_FRIENDS) {
  12798. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12799. return;
  12800. }
  12801. //remove from friend's list first
  12802. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12803. for (i = 0; i < MAX_FRIENDS &&
  12804. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12805. if (i != MAX_FRIENDS) {
  12806. // move all chars up
  12807. for(j = i + 1; j < MAX_FRIENDS; j++)
  12808. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12809. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12810. //should the guy be notified of some message? we should add it here if so
  12811. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12812. WFIFOW(f_sd->fd,0) = 0x20a;
  12813. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12814. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12815. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12816. }
  12817. } else { //friend not online -- ask char server to delete from his friendlist
  12818. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12819. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12820. return;
  12821. }
  12822. }
  12823. // We can now delete from original requester
  12824. for (i = 0; i < MAX_FRIENDS &&
  12825. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12826. // move all chars up
  12827. for(j = i + 1; j < MAX_FRIENDS; j++)
  12828. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12829. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12830. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12831. WFIFOHEAD(fd,packet_len(0x20a));
  12832. WFIFOW(fd,0) = 0x20a;
  12833. WFIFOL(fd,2) = account_id;
  12834. WFIFOL(fd,6) = char_id;
  12835. WFIFOSET(fd, packet_len(0x20a));
  12836. }
  12837. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12838. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12839. void clif_PVPInfo(map_session_data* sd)
  12840. {
  12841. int fd = sd->fd;
  12842. WFIFOHEAD(fd,packet_len(0x210));
  12843. WFIFOW(fd,0) = 0x210;
  12844. WFIFOL(fd,2) = sd->status.char_id;
  12845. WFIFOL(fd,6) = sd->status.account_id;
  12846. WFIFOL(fd,10) = sd->pvp_won; // times won
  12847. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12848. WFIFOL(fd,18) = sd->pvp_point;
  12849. WFIFOSET(fd, packet_len(0x210));
  12850. }
  12851. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12852. /// 020f <char id>.L <account id>.L
  12853. void clif_parse_PVPInfo(int fd,map_session_data *sd)
  12854. {
  12855. // TODO: Is there a way to use this on an another player (char/acc id)?
  12856. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12857. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12858. clif_PVPInfo(sd);
  12859. }
  12860. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12861. /// 0254 <which>.B
  12862. /// which: (unused atm for security purpose)
  12863. /// 0 = sun
  12864. /// 1 = moon
  12865. /// 2 = star
  12866. void clif_parse_FeelSaveOk(int fd,map_session_data *sd)
  12867. {
  12868. int i;
  12869. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12870. if (sd->menuskill_id != SG_FEEL)
  12871. return;
  12872. i = sd->menuskill_val-1;
  12873. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12874. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12875. sd->feel_map[i].m = sd->bl.m;
  12876. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12877. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12878. // clif_misceffect2(&sd->bl, 0x1b0);
  12879. // clif_misceffect2(&sd->bl, 0x21f);
  12880. clif_feel_info(sd, i, 0);
  12881. clif_menuskill_clear(sd);
  12882. }
  12883. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12884. /// 0253 <which>.B
  12885. /// which:
  12886. /// 0 = sun
  12887. /// 1 = moon
  12888. /// 2 = star
  12889. void clif_feel_req(int fd, map_session_data *sd, uint16 skill_lv)
  12890. {
  12891. WFIFOHEAD(fd,packet_len(0x253));
  12892. WFIFOW(fd,0)=0x253;
  12893. WFIFOB(fd,2)=TOB(skill_lv-1);
  12894. WFIFOSET(fd, packet_len(0x253));
  12895. sd->menuskill_id = SG_FEEL;
  12896. sd->menuskill_val = skill_lv;
  12897. }
  12898. /// Request to change homunculus' name (CZ_RENAME_MER).
  12899. /// 0231 <name>.24B
  12900. void clif_parse_ChangeHomunculusName(int fd, map_session_data *sd){
  12901. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12902. }
  12903. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12904. /// 0234 <id>.L
  12905. void clif_parse_HomMoveToMaster(int fd, map_session_data *sd){
  12906. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12907. struct block_list *bl = NULL;
  12908. struct unit_data *ud = NULL;
  12909. if( sd->md && sd->md->bl.id == id )
  12910. bl = &sd->md->bl;
  12911. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12912. bl = &sd->hd->bl; // Moving Homunculus
  12913. else
  12914. return;
  12915. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12916. ud = unit_bl2ud(bl);
  12917. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12918. }
  12919. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12920. /// 0232 <id>.L <position data>.3B
  12921. void clif_parse_HomMoveTo(int fd, map_session_data *sd){
  12922. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12923. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12924. struct block_list *bl = NULL;
  12925. short x, y;
  12926. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12927. if( sd->md && sd->md->bl.id == id )
  12928. bl = &sd->md->bl; // Moving Mercenary
  12929. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12930. bl = &sd->hd->bl; // Moving Homunculus
  12931. else
  12932. return;
  12933. unit_walktoxy(bl, x, y, 4);
  12934. }
  12935. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12936. /// 0233 <id>.L <target id>.L <action>.B
  12937. /// action:
  12938. /// always 0
  12939. void clif_parse_HomAttack(int fd,map_session_data *sd)
  12940. {
  12941. struct block_list *bl = NULL;
  12942. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12943. int id = RFIFOL(fd,info->pos[0]);
  12944. int target_id = RFIFOL(fd,info->pos[1]);
  12945. int action_type = RFIFOB(fd,info->pos[2]);
  12946. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12947. bl = &sd->hd->bl;
  12948. else if( sd->md && sd->md->bl.id == id )
  12949. bl = &sd->md->bl;
  12950. else return;
  12951. unit_stop_attack(bl);
  12952. unit_attack(bl, target_id, action_type != 0);
  12953. }
  12954. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12955. /// 022d <type>.W <command>.B
  12956. /// type:
  12957. /// always 0
  12958. /// command:
  12959. /// 0 = homunculus information
  12960. /// 1 = feed
  12961. /// 2 = delete
  12962. void clif_parse_HomMenu(int fd, map_session_data *sd)
  12963. { //[orn]
  12964. int cmd = RFIFOW(fd,0);
  12965. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12966. if(!hom_is_active(sd->hd))
  12967. return;
  12968. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12969. }
  12970. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12971. /// 0292
  12972. void clif_parse_AutoRevive(int fd, map_session_data *sd)
  12973. {
  12974. pc_revive_item(sd);
  12975. }
  12976. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12977. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12978. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12979. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12980. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12981. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12982. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12983. void clif_check(int fd, map_session_data* pl_sd)
  12984. {
  12985. WFIFOHEAD(fd,packet_len(0x214));
  12986. WFIFOW(fd, 0) = 0x214;
  12987. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12988. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12989. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12990. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12991. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12992. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12993. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12994. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12995. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12996. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12997. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12998. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12999. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13000. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13001. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13002. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13003. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13004. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13005. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13006. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13007. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13008. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13009. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13010. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13011. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13012. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13013. WFIFOSET(fd,packet_len(0x214));
  13014. }
  13015. /// /check (CZ_REQ_STATUS_GM).
  13016. /// Request character's status values.
  13017. /// 0213 <char name>.24B
  13018. void clif_parse_Check(int fd, map_session_data *sd)
  13019. {
  13020. char charname[NAME_LENGTH];
  13021. map_session_data* pl_sd;
  13022. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13023. return;
  13024. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13025. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13026. {
  13027. return;
  13028. }
  13029. clif_check(fd, pl_sd);
  13030. }
  13031. /// MAIL SYSTEM
  13032. /// By Zephyrus
  13033. ///
  13034. /// Notification about the result of adding an item to mail
  13035. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13036. /// result:
  13037. /// 0 = success
  13038. /// 1 = failure
  13039. /// 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)
  13040. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13041. /// result:
  13042. /// 0 = success
  13043. /// 1 = over weight
  13044. /// 2 = fatal error
  13045. void clif_Mail_setattachment( map_session_data* sd, int index, int amount, uint8 flag ){
  13046. int fd = sd->fd;
  13047. #if PACKETVER < 20150513
  13048. WFIFOHEAD(fd,packet_len(0x255));
  13049. WFIFOW(fd,0) = 0x255;
  13050. WFIFOW(fd,2) = index;
  13051. WFIFOB(fd,4) = flag;
  13052. WFIFOSET(fd,packet_len(0x255));
  13053. #else
  13054. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13055. if( flag ){
  13056. memset( &p, 0, sizeof( p ) );
  13057. }else{
  13058. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13059. p.index = index;
  13060. p.count = amount;
  13061. p.itemId = client_nameid( item->nameid );
  13062. p.type = itemtype( item->nameid );
  13063. p.IsIdentified = item->identify ? 1 : 0;
  13064. p.IsDamaged = item->attribute ? 1 : 0;
  13065. p.refiningLevel = item->refine;
  13066. clif_addcards( &p.slot, item );
  13067. clif_add_random_options( p.optionData, *item );
  13068. p.weight = 0;
  13069. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13070. if( sd->mail.item[i].nameid == 0 ){
  13071. continue;
  13072. }
  13073. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13074. }
  13075. p.favorite = item->favorite;
  13076. p.location = pc_equippoint( sd, server_index( index ) );
  13077. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13078. p.grade = item->enchantgrade;
  13079. #endif
  13080. }
  13081. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13082. p.result = flag;
  13083. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13084. #endif
  13085. }
  13086. /// Notification about the result of retrieving a mail attachment
  13087. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13088. /// result:
  13089. /// 0 = success
  13090. /// 1 = failure
  13091. /// 2 = too many items
  13092. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13093. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13094. void clif_mail_getattachment(map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13095. #if PACKETVER < 20150513
  13096. int fd = sd->fd;
  13097. WFIFOHEAD(fd,packet_len(0x245));
  13098. WFIFOW(fd,0) = 0x245;
  13099. WFIFOB(fd,2) = result;
  13100. WFIFOSET(fd,packet_len(0x245));
  13101. #else
  13102. switch( type ){
  13103. case MAIL_ATT_ITEM:
  13104. case MAIL_ATT_ZENY:
  13105. break;
  13106. default:
  13107. return;
  13108. }
  13109. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13110. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13111. p.MailID = msg->id;
  13112. p.opentype = msg->type;
  13113. p.result = result;
  13114. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13115. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13116. #endif
  13117. }
  13118. /// Notification about the result of sending a mail
  13119. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13120. /// result:
  13121. /// 0 = success
  13122. /// 1 = recipinent does not exist
  13123. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13124. void clif_Mail_send(map_session_data* sd, enum mail_send_result result){
  13125. #if PACKETVER < 20150513
  13126. int fd = sd->fd;
  13127. WFIFOHEAD(fd,packet_len(0x249));
  13128. WFIFOW(fd,0) = 0x249;
  13129. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13130. WFIFOSET(fd,packet_len(0x249));
  13131. #else
  13132. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13133. p.PacketType = rodexwriteresult;
  13134. p.result = result;
  13135. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13136. #endif
  13137. }
  13138. /// Notification about the result of deleting a mail.
  13139. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13140. /// result:
  13141. /// 0 = success
  13142. /// 1 = failure
  13143. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13144. void clif_mail_delete( map_session_data* sd, struct mail_message *msg, bool success ){
  13145. #if PACKETVER < 20150513
  13146. int fd = sd->fd;
  13147. WFIFOHEAD(fd, packet_len(0x257));
  13148. WFIFOW(fd,0) = 0x257;
  13149. WFIFOL(fd,2) = msg->id;
  13150. WFIFOW(fd,6) = !success;
  13151. WFIFOSET(fd, packet_len(0x257));
  13152. #else
  13153. // This is only a success notification
  13154. if( success ){
  13155. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13156. p.PacketType = rodexdelete;
  13157. p.opentype = msg->type;
  13158. p.MailID = msg->id;
  13159. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13160. }
  13161. #endif
  13162. }
  13163. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13164. /// 0274 <mail id>.L <result>.W
  13165. /// result:
  13166. /// 0 = success
  13167. /// 1 = failure
  13168. void clif_Mail_return(int fd, int mail_id, short fail)
  13169. {
  13170. WFIFOHEAD(fd,packet_len(0x274));
  13171. WFIFOW(fd,0) = 0x274;
  13172. WFIFOL(fd,2) = mail_id;
  13173. WFIFOW(fd,6) = fail;
  13174. WFIFOSET(fd,packet_len(0x274));
  13175. }
  13176. /// Notification about new mail.
  13177. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13178. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13179. void clif_Mail_new(map_session_data* sd, int mail_id, const char *sender, const char *title){
  13180. #if PACKETVER < 20150513
  13181. int fd = sd->fd;
  13182. WFIFOHEAD(fd,packet_len(0x24a));
  13183. WFIFOW(fd,0) = 0x24a;
  13184. WFIFOL(fd,2) = mail_id;
  13185. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13186. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13187. WFIFOSET(fd,packet_len(0x24a));
  13188. #else
  13189. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13190. p.PacketType = rodexicon;
  13191. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13192. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13193. #endif
  13194. }
  13195. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13196. /// 0260 <type>.L
  13197. /// type:
  13198. /// 0 = open
  13199. /// 1 = close
  13200. void clif_Mail_window(int fd, int flag)
  13201. {
  13202. WFIFOHEAD(fd,packet_len(0x260));
  13203. WFIFOW(fd,0) = 0x260;
  13204. WFIFOL(fd,2) = flag;
  13205. WFIFOSET(fd,packet_len(0x260));
  13206. }
  13207. /// Lists mails stored in inbox.
  13208. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13209. /// read:
  13210. /// 0 = unread
  13211. /// 1 = read
  13212. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13213. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13214. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13215. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13216. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13217. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13218. void clif_Mail_refreshinbox(map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13219. #if PACKETVER < 20150513
  13220. int fd = sd->fd;
  13221. struct mail_data *md = &sd->mail.inbox;
  13222. struct mail_message *msg;
  13223. int len, i, j;
  13224. len = 8 + (73 * md->amount);
  13225. WFIFOHEAD(fd,len);
  13226. WFIFOW(fd,0) = 0x240;
  13227. WFIFOW(fd,2) = len;
  13228. WFIFOL(fd,4) = md->amount;
  13229. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13230. {
  13231. msg = &md->msg[i];
  13232. if (msg->id < 1)
  13233. continue;
  13234. WFIFOL(fd,8+73*j) = msg->id;
  13235. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13236. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13237. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13238. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13239. j++;
  13240. }
  13241. WFIFOSET(fd,len);
  13242. if( md->full ) {// TODO: is this official?
  13243. char output[100];
  13244. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13245. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13246. }
  13247. #else
  13248. int fd = sd->fd;
  13249. struct mail_data *md = &sd->mail.inbox;
  13250. struct mail_message *msg;
  13251. int i, j, k, offset, titleLength;
  13252. uint8 mailType, amount, remaining;
  13253. uint32 now = (uint32)time(NULL);
  13254. #if PACKETVER >= 20170419
  13255. int cmd = 0xac2;
  13256. #elif PACKETVER >= 20160601
  13257. int cmd = 0xa7d;
  13258. #else
  13259. int cmd = 0x9f0;
  13260. #endif
  13261. if( battle_config.mail_daily_count ){
  13262. mail_refresh_remaining_amount(sd);
  13263. }
  13264. #if PACKETVER >= 20170419
  13265. // Always send all
  13266. i = md->amount;
  13267. #else
  13268. // If a starting mail id was sent
  13269. if( mailID != 0 ){
  13270. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13271. // Unknown mail
  13272. if( i == md->amount ){
  13273. // Ignore the request for now
  13274. return; // TODO: Should we just show the first page instead?
  13275. }
  13276. // It was actually the oldest/first mail, there is no further page
  13277. if( i == 0 ){
  13278. return;
  13279. }
  13280. // We actually want the next/older mail
  13281. i -= 1;
  13282. }else{
  13283. i = md->amount;
  13284. }
  13285. #endif
  13286. // Count the remaining mails from the starting mail or the beginning
  13287. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13288. for( j = i, remaining = 0; j >= 0; j-- ){
  13289. msg = &md->msg[j];
  13290. if (msg->id < 1)
  13291. continue;
  13292. #if PACKETVER < 20170419
  13293. if (msg->type != type)
  13294. continue;
  13295. #endif
  13296. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13297. continue;
  13298. remaining++;
  13299. }
  13300. #if PACKETVER >= 20170419
  13301. // Always send all
  13302. amount = remaining;
  13303. #else
  13304. if( remaining > MAIL_PAGE_SIZE ){
  13305. amount = MAIL_PAGE_SIZE;
  13306. }else{
  13307. amount = remaining;
  13308. }
  13309. #endif
  13310. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13311. WFIFOW(fd, 0) = cmd;
  13312. #if PACKETVER >= 20170419
  13313. WFIFOB(fd, 4) = 1; // Unknown
  13314. offset = 5;
  13315. #else
  13316. WFIFOB(fd, 4) = type;
  13317. WFIFOB(fd, 5) = amount;
  13318. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13319. offset = 7;
  13320. #endif
  13321. for( amount = 0; i >= 0; i-- ){
  13322. msg = &md->msg[i];
  13323. if (msg->id < 1)
  13324. continue;
  13325. #if PACKETVER < 20170419
  13326. if (msg->type != type)
  13327. continue;
  13328. #endif
  13329. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13330. continue;
  13331. #if PACKETVER >= 20170419
  13332. WFIFOB(fd, offset) = msg->type;
  13333. offset += 1;
  13334. #endif
  13335. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13336. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13337. mailType = MAIL_TYPE_TEXT; // Normal letter
  13338. if( msg->zeny > 0 ){
  13339. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13340. }
  13341. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13342. if( msg->item[k].nameid > 0 ){
  13343. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13344. break;
  13345. }
  13346. }
  13347. #if PACKETVER >= 20170419
  13348. // If it came from an npc?
  13349. if( !msg->send_id ){
  13350. mailType |= MAIL_TYPE_NPC;
  13351. }
  13352. #endif
  13353. WFIFOB(fd, offset + 9) = mailType;
  13354. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13355. #if PACKETVER < 20170419
  13356. // How much time has passed since you received the mail
  13357. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13358. offset += 4;
  13359. #endif
  13360. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13361. if( msg->scheduled_deletion > 0 ){
  13362. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13363. }else{
  13364. // Fake the scheduled deletion to one year in the future
  13365. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13366. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13367. }
  13368. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13369. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13370. offset += 40 + titleLength;
  13371. }
  13372. WFIFOW(fd, 2) = (int16)offset;
  13373. WFIFOSET(fd, offset);
  13374. #endif
  13375. }
  13376. /// Mail inbox list request.
  13377. /// 023f (CZ_MAIL_GET_LIST)
  13378. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13379. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13380. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13381. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13382. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13383. void clif_parse_Mail_refreshinbox(int fd, map_session_data *sd){
  13384. if( mail_invalid_operation( sd ) ){
  13385. return;
  13386. }
  13387. #if PACKETVER < 20150513
  13388. struct mail_data* md = &sd->mail.inbox;
  13389. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13390. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13391. else
  13392. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13393. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13394. mail_removezeny(sd, false);
  13395. #else
  13396. int cmd = RFIFOW(fd, 0);
  13397. #if PACKETVER < 20170419
  13398. uint8 openType = RFIFOB(fd, 2);
  13399. uint64 mailId = RFIFOQ(fd, 3);
  13400. #else
  13401. uint8 openType;
  13402. uint64 mailId = RFIFOQ(fd, 2);
  13403. int i;
  13404. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13405. if( i == MAIL_MAX_INBOX ){
  13406. openType = MAIL_INBOX_NORMAL;
  13407. mailId = 0;
  13408. }else{
  13409. openType = sd->mail.inbox.msg[i].type;
  13410. mailId = 0;
  13411. }
  13412. #endif
  13413. switch( openType ){
  13414. case MAIL_INBOX_NORMAL:
  13415. case MAIL_INBOX_ACCOUNT:
  13416. case MAIL_INBOX_RETURNED:
  13417. break;
  13418. default:
  13419. // Unknown type: ignore request
  13420. return;
  13421. }
  13422. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13423. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13424. return;
  13425. }
  13426. // If it is not a next page request
  13427. if( cmd != 0x9ee ){
  13428. mailId = 0;
  13429. }
  13430. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13431. #endif
  13432. }
  13433. /// Opens a mail
  13434. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13435. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13436. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13437. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13438. /// { }*n
  13439. // TODO: Packet description => for repeated block
  13440. void clif_Mail_read( map_session_data *sd, int mail_id ){
  13441. int i, fd = sd->fd;
  13442. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13443. if( i == MAIL_MAX_INBOX ) {
  13444. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13445. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13446. return;
  13447. } else {
  13448. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13449. struct item *item;
  13450. int msg_len = strlen(msg->body);
  13451. if( msg_len == 0 ) {
  13452. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13453. msg_len = strlen(msg->body);
  13454. }
  13455. #if PACKETVER < 20150513
  13456. item = &msg->item[0];
  13457. int len = 101 + msg_len;
  13458. WFIFOHEAD(fd,len);
  13459. WFIFOW(fd,0) = 0x242;
  13460. WFIFOW(fd,2) = len;
  13461. WFIFOL(fd,4) = msg->id;
  13462. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13463. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13464. WFIFOL(fd,72) = 0;
  13465. WFIFOL(fd,76) = msg->zeny;
  13466. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13467. if( item->nameid && data != nullptr ) {
  13468. WFIFOL(fd,80) = item->amount;
  13469. WFIFOW(fd,84) = client_nameid( item->nameid );
  13470. WFIFOW(fd,86) = itemtype( item->nameid );
  13471. WFIFOB(fd,88) = item->identify;
  13472. WFIFOB(fd,89) = item->attribute;
  13473. WFIFOB(fd,90) = item->refine;
  13474. WFIFOW(fd,91) = item->card[0];
  13475. WFIFOW(fd,93) = item->card[1];
  13476. WFIFOW(fd,95) = item->card[2];
  13477. WFIFOW(fd,97) = item->card[3];
  13478. } else // no item, set all to zero
  13479. memset(WFIFOP(fd,80), 0x00, 19);
  13480. WFIFOB(fd,99) = (unsigned char)msg_len;
  13481. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13482. WFIFOSET(fd,len);
  13483. #else
  13484. msg_len += 1; // Zero Termination
  13485. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13486. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13487. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13488. p->opentype = msg->type;
  13489. p->MailID = msg->id;
  13490. p->TextcontentsLength = msg_len;
  13491. p->zeny = msg->zeny;
  13492. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13493. p->PacketLength += p->TextcontentsLength;
  13494. p->ItemCnt = 0;
  13495. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13496. item = &msg->item[j];
  13497. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13498. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13499. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13500. mailitem->ITID = client_nameid( item->nameid );
  13501. mailitem->count = item->amount;
  13502. mailitem->type = itemtype( item->nameid );
  13503. mailitem->IsIdentified = item->identify ? 1 : 0;
  13504. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13505. mailitem->refiningLevel = item->refine;
  13506. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13507. mailitem->viewSprite = data->look;
  13508. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13509. clif_addcards( &mailitem->slot, item );
  13510. clif_add_random_options( mailitem->option_data, *item );
  13511. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13512. mailitem->grade = item->enchantgrade;
  13513. #endif
  13514. p->PacketLength += sizeof( *mailitem );
  13515. p->ItemCnt++;
  13516. }
  13517. }
  13518. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13519. #endif
  13520. if (msg->status == MAIL_UNREAD) {
  13521. msg->status = MAIL_READ;
  13522. intif_Mail_read(mail_id);
  13523. clif_parse_Mail_refreshinbox(fd, sd);
  13524. sd->mail.inbox.unread--;
  13525. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13526. }
  13527. }
  13528. }
  13529. /// Request to open a mail.
  13530. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13531. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13532. void clif_parse_Mail_read(int fd, map_session_data *sd){
  13533. #if PACKETVER < 20150513
  13534. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13535. #else
  13536. //uint8 openType = RFIFOB(fd, 2);
  13537. int mail_id = (int)RFIFOQ(fd, 3);
  13538. #endif
  13539. if( mail_id <= 0 )
  13540. return;
  13541. if( mail_invalid_operation(sd) )
  13542. return;
  13543. clif_Mail_read(sd, mail_id);
  13544. }
  13545. /// Allow a player to begin writing a mail
  13546. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13547. void clif_send_Mail_beginwrite_ack( map_session_data *sd, char* name, bool success ){
  13548. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13549. p.PacketType = rodexopenwrite;
  13550. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13551. p.result = success;
  13552. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13553. }
  13554. /// Request to start writing a mail
  13555. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13556. void clif_parse_Mail_beginwrite( int fd, map_session_data *sd ){
  13557. char name[NAME_LENGTH];
  13558. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13559. if( mail_invalid_operation( sd ) ){
  13560. return;
  13561. }
  13562. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13563. clif_send_Mail_beginwrite_ack(sd, name, false);
  13564. return;
  13565. }
  13566. mail_clear(sd);
  13567. sd->state.mail_writing = true;
  13568. clif_send_Mail_beginwrite_ack(sd, name,true);
  13569. }
  13570. /// Notification that the client cancelled writing a mail
  13571. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13572. void clif_parse_Mail_cancelwrite( int fd, map_session_data *sd ){
  13573. sd->state.mail_writing = false;
  13574. }
  13575. /// Give the client information about the recipient, if available
  13576. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13577. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13578. void clif_Mail_Receiver_Ack( map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13579. #if PACKETVER >= 20141119
  13580. PACKET_ZC_CHECKNAME p = { 0 };
  13581. p.PacketType = HEADER_ZC_CHECKNAME;
  13582. p.CharId = char_id;
  13583. p.Class = class_;
  13584. p.BaseLevel = level;
  13585. #if PACKETVER >= 20160302
  13586. strncpy(p.Name, name, NAME_LENGTH);
  13587. #endif
  13588. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13589. #endif
  13590. }
  13591. /// Request information about the recipient
  13592. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13593. void clif_parse_Mail_Receiver_Check(int fd, map_session_data *sd) {
  13594. #if PACKETVER >= 20140423
  13595. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13596. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13597. #else
  13598. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13599. #endif
  13600. static char name[NAME_LENGTH];
  13601. if( mail_invalid_operation( sd ) ){
  13602. return;
  13603. }
  13604. safestrncpy(name, p->Name, NAME_LENGTH);
  13605. intif_mail_checkreceiver(sd, name);
  13606. #endif
  13607. }
  13608. /// Request to receive mail's attachment.
  13609. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13610. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13611. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13612. void clif_parse_Mail_getattach( int fd, map_session_data *sd ){
  13613. int i;
  13614. struct mail_message* msg;
  13615. #if PACKETVER < 20150513
  13616. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13617. int attachment = MAIL_ATT_ALL;
  13618. #else
  13619. uint16 packet_id = RFIFOW(fd, 0);
  13620. int mail_id = (int)RFIFOQ(fd, 2);
  13621. //int openType = RFIFOB(fd, 10);
  13622. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13623. #endif
  13624. if( !chrif_isconnected() )
  13625. return;
  13626. if( mail_id <= 0 )
  13627. return;
  13628. if( mail_invalid_operation(sd) )
  13629. return;
  13630. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13631. if( i == MAIL_MAX_INBOX )
  13632. return;
  13633. msg = &sd->mail.inbox.msg[i];
  13634. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13635. attachment &= ~MAIL_ATT_ZENY;
  13636. }
  13637. if( attachment&MAIL_ATT_ITEM ){
  13638. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13639. // No items were found
  13640. if( i == MAIL_MAX_ITEM ){
  13641. attachment &= ~MAIL_ATT_ITEM;
  13642. }
  13643. }
  13644. // Either no attachment requested at all or there are no zeny or items in the mail
  13645. if( attachment == MAIL_ATT_NONE ){
  13646. return;
  13647. }
  13648. if( attachment&MAIL_ATT_ZENY ){
  13649. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13650. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13651. return;
  13652. }else{
  13653. // Store the pending zeny (required for the "retrieve all" feature)
  13654. sd->mail.pending_zeny += msg->zeny;
  13655. // To make sure another request fails
  13656. msg->zeny = 0;
  13657. }
  13658. }
  13659. if( attachment&MAIL_ATT_ITEM ){
  13660. int slots = 0, totalweight = 0;
  13661. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13662. struct item* item = &msg->item[i];
  13663. if( item->nameid > 0 && item->amount > 0 ){
  13664. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13665. if(data == nullptr)
  13666. continue;
  13667. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13668. case CHKADDITEM_NEW:
  13669. slots += data->inventorySlotNeeded( item->amount );
  13670. break;
  13671. case CHKADDITEM_OVERAMOUNT:
  13672. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13673. return;
  13674. }
  13675. totalweight += data->weight * item->amount;
  13676. }
  13677. }
  13678. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13679. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13680. return;
  13681. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13682. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13683. return;
  13684. }
  13685. // To make sure another request fails
  13686. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13687. // Store the pending weight (required for the "retrieve all" feature)
  13688. sd->mail.pending_weight += totalweight;
  13689. // Store the pending slots (required for the "retrieve all" feature)
  13690. sd->mail.pending_slots += slots;
  13691. }
  13692. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13693. }
  13694. /// Request to delete a mail.
  13695. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13696. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13697. void clif_parse_Mail_delete(int fd, map_session_data *sd){
  13698. #if PACKETVER < 20150513
  13699. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13700. #else
  13701. //int openType = RFIFOB(fd, 2);
  13702. int mail_id = (int)RFIFOQ(fd, 3);
  13703. #endif
  13704. int i, j;
  13705. if( !chrif_isconnected() )
  13706. return;
  13707. if( mail_id <= 0 )
  13708. return;
  13709. if( mail_invalid_operation(sd) )
  13710. return;
  13711. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13712. if (i < MAIL_MAX_INBOX) {
  13713. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13714. // can't delete mail without removing zeny first
  13715. if( msg->zeny > 0 ){
  13716. clif_mail_delete(sd, msg, false);
  13717. return;
  13718. }
  13719. // can't delete mail without removing attachment(s) first
  13720. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13721. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13722. clif_mail_delete(sd, msg, false);
  13723. return;
  13724. }
  13725. }
  13726. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13727. sd->mail.inbox.unread--;
  13728. clif_Mail_new(sd,0,NULL,NULL);
  13729. }
  13730. }
  13731. }
  13732. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13733. /// 0273 <mail id>.L <receive name>.24B
  13734. void clif_parse_Mail_return(int fd, map_session_data *sd){
  13735. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13736. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13737. //ShowDump( p, sizeof( p ) );
  13738. int mail_id = p->msgId;
  13739. // not supported for now
  13740. return;
  13741. #else
  13742. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13743. #endif
  13744. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13745. int i;
  13746. if( mail_id <= 0 )
  13747. return;
  13748. if( mail_invalid_operation(sd) )
  13749. return;
  13750. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13751. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13752. intif_Mail_return(sd->status.char_id, mail_id);
  13753. else
  13754. clif_Mail_return(sd->fd, mail_id, 1);
  13755. }
  13756. /// Request to add an item or Zeny to mail.
  13757. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13758. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13759. void clif_parse_Mail_setattach(int fd, map_session_data *sd){
  13760. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13761. uint16 idx = RFIFOW(fd,info->pos[0]);
  13762. #if PACKETVER < 20150513
  13763. int amount = RFIFOL(fd,info->pos[1]);
  13764. #else
  13765. int amount = RFIFOW(fd,info->pos[1]);
  13766. #endif
  13767. unsigned char flag;
  13768. if( !chrif_isconnected() )
  13769. return;
  13770. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13771. return;
  13772. if (sd->inventory_data[server_index(idx)] == nullptr)
  13773. return;
  13774. if( mail_invalid_operation( sd ) ){
  13775. return;
  13776. }
  13777. flag = mail_setitem(sd, idx, amount);
  13778. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13779. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13780. }else{
  13781. clif_Mail_setattachment(sd,idx,amount,flag);
  13782. }
  13783. }
  13784. /// Remove an item from a mail
  13785. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13786. void clif_mail_removeitem( map_session_data* sd, bool success, int index, int amount ){
  13787. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13788. p.PacketType = rodexremoveitem;
  13789. p.result = success;
  13790. p.index = index;
  13791. p.cnt = amount;
  13792. int total = 0;
  13793. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13794. if( sd->mail.item[i].nameid == 0 ){
  13795. break;
  13796. }
  13797. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13798. }
  13799. p.weight = total;
  13800. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13801. }
  13802. /// Request to reset mail item and/or Zeny
  13803. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13804. /// type:
  13805. /// 0 = reset all
  13806. /// 1 = remove item
  13807. /// 2 = remove zeny
  13808. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13809. void clif_parse_Mail_winopen(int fd, map_session_data *sd)
  13810. {
  13811. #if PACKETVER < 20150513
  13812. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13813. if (type == 0 || type == 1)
  13814. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13815. if (type == 0 || type == 2)
  13816. mail_removezeny(sd, false);
  13817. #else
  13818. uint16 index = RFIFOW(fd, 2);
  13819. uint16 count = RFIFOW(fd, 4);
  13820. mail_removeitem(sd,0,index,count);
  13821. #endif
  13822. }
  13823. /// Request to send mail
  13824. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13825. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13826. /// 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)
  13827. void clif_parse_Mail_send(int fd, map_session_data *sd){
  13828. #if PACKETVER < 20150513
  13829. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13830. if( !chrif_isconnected() )
  13831. return;
  13832. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13833. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13834. return;
  13835. }
  13836. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13837. #else
  13838. uint16 length = RFIFOW(fd, 2);
  13839. if( length < 0x3e ){
  13840. ShowWarning("Too short...\n");
  13841. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13842. return;
  13843. }
  13844. if( mail_invalid_operation( sd ) ){
  13845. return;
  13846. }
  13847. // Forged request without a begin writing packet?
  13848. if( !sd->state.mail_writing ){
  13849. return; // Ignore it
  13850. }
  13851. char receiver[NAME_LENGTH];
  13852. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13853. // char sender[NAME_LENGTH];
  13854. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13855. uint64 zeny = RFIFOQ(fd, 52);
  13856. uint16 titleLength = RFIFOW(fd, 60);
  13857. uint16 textLength = RFIFOW(fd, 62);
  13858. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13859. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13860. char title[MAIL_TITLE_LENGTH];
  13861. char text[MAIL_BODY_LENGTH];
  13862. #if PACKETVER <= 20160330
  13863. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13864. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13865. #else
  13866. // 64 = <char id>.L
  13867. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13868. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13869. #endif
  13870. if( zeny > 0 ){
  13871. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13872. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13873. return;
  13874. }
  13875. }
  13876. mail_send(sd, receiver, title, text, realTextLength);
  13877. #endif
  13878. }
  13879. /// AUCTION SYSTEM
  13880. /// By Zephyrus
  13881. ///
  13882. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13883. /// 025f <type>.L
  13884. /// type:
  13885. /// 0 = open
  13886. /// 1 = close
  13887. void clif_Auction_openwindow(map_session_data *sd)
  13888. {
  13889. int fd = sd->fd;
  13890. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13891. return;
  13892. if( !battle_config.feature_auction )
  13893. return;
  13894. WFIFOHEAD(fd,packet_len(0x25f));
  13895. WFIFOW(fd,0) = 0x25f;
  13896. WFIFOL(fd,2) = 0;
  13897. WFIFOSET(fd,packet_len(0x25f));
  13898. }
  13899. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13900. /// 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 }*
  13901. void clif_Auction_results(map_session_data *sd, short count, short pages, uint8 *buf)
  13902. {
  13903. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13904. struct auction_data auction;
  13905. WFIFOHEAD(fd,12 + (count * 83));
  13906. WFIFOW(fd,0) = 0x252;
  13907. WFIFOW(fd,2) = 12 + (count * 83);
  13908. WFIFOL(fd,4) = pages;
  13909. WFIFOL(fd,8) = count;
  13910. for( i = 0; i < count; i++ ) {
  13911. int k = 12 + (i * 83);
  13912. memcpy(&auction, RBUFP(buf,i * len), len);
  13913. WFIFOL(fd,k) = auction.auction_id;
  13914. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13915. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13916. WFIFOL(fd,30+k) = auction.type;
  13917. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13918. WFIFOB(fd,36+k) = auction.item.identify;
  13919. WFIFOB(fd,37+k) = auction.item.attribute;
  13920. WFIFOB(fd,38+k) = auction.item.refine;
  13921. WFIFOW(fd,39+k) = auction.item.card[0];
  13922. WFIFOW(fd,41+k) = auction.item.card[1];
  13923. WFIFOW(fd,43+k) = auction.item.card[2];
  13924. WFIFOW(fd,45+k) = auction.item.card[3];
  13925. WFIFOL(fd,47+k) = auction.price;
  13926. WFIFOL(fd,51+k) = auction.buynow;
  13927. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13928. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13929. }
  13930. WFIFOSET(fd,WFIFOW(fd,2));
  13931. }
  13932. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13933. /// 0256 <index>.W <result>.B
  13934. /// result:
  13935. /// 0 = success
  13936. /// 1 = failure
  13937. static void clif_Auction_setitem(int fd, int index, bool fail)
  13938. {
  13939. WFIFOHEAD(fd,packet_len(0x256));
  13940. WFIFOW(fd,0) = 0x256;
  13941. WFIFOW(fd,2) = index;
  13942. WFIFOB(fd,4) = fail;
  13943. WFIFOSET(fd,packet_len(0x256));
  13944. }
  13945. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13946. /// 024b <type>.W
  13947. /// type:
  13948. /// 0 = create (any other action in auction window)
  13949. /// 1 = cancel (cancel pressed on register tab)
  13950. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13951. void clif_parse_Auction_cancelreg(int fd, map_session_data *sd){
  13952. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13953. if( sd->auction.amount > 0 )
  13954. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13955. sd->auction.amount = 0;
  13956. }
  13957. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13958. /// 024c <index>.W <count>.L
  13959. void clif_parse_Auction_setitem(int fd, map_session_data *sd){
  13960. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13961. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13962. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13963. if( !battle_config.feature_auction )
  13964. return;
  13965. if( sd->auction.amount > 0 )
  13966. sd->auction.amount = 0;
  13967. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13968. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13969. return;
  13970. }
  13971. 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.
  13972. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13973. return;
  13974. }
  13975. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  13976. 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) )
  13977. { // Consumable or pets are not allowed
  13978. clif_Auction_setitem(sd->fd, idx, true);
  13979. return;
  13980. }
  13981. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13982. !sd->inventory.u.items_inventory[idx].identify ||
  13983. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13984. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13985. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13986. clif_Auction_setitem(sd->fd, idx, true);
  13987. return;
  13988. }
  13989. sd->auction.index = idx;
  13990. sd->auction.amount = amount;
  13991. clif_Auction_setitem(fd, idx + 2, false);
  13992. }
  13993. /// Result from an auction action (ZC_AUCTION_RESULT).
  13994. /// 0250 <result>.B
  13995. /// result:
  13996. /// 0 = You have failed to bid into the auction
  13997. /// 1 = You have successfully bid in the auction
  13998. /// 2 = The auction has been canceled
  13999. /// 3 = An auction with at least one bidder cannot be canceled
  14000. /// 4 = You cannot register more than 5 items in an auction at a time
  14001. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14002. /// 6 = You have won the auction
  14003. /// 7 = You have failed to win the auction
  14004. /// 8 = You do not have enough Zeny
  14005. /// 9 = You cannot place more than 5 bids at a time
  14006. void clif_Auction_message(int fd, unsigned char flag)
  14007. {
  14008. WFIFOHEAD(fd,packet_len(0x250));
  14009. WFIFOW(fd,0) = 0x250;
  14010. WFIFOB(fd,2) = flag;
  14011. WFIFOSET(fd,packet_len(0x250));
  14012. }
  14013. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14014. /// 025e <result>.W
  14015. /// result:
  14016. /// 0 = You have ended the auction
  14017. /// 1 = You cannot end the auction
  14018. /// 2 = Auction ID is incorrect
  14019. void clif_Auction_close(int fd, unsigned char flag)
  14020. {
  14021. WFIFOHEAD(fd,packet_len(0x25e));
  14022. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14023. WFIFOW(fd,2) = flag;
  14024. WFIFOSET(fd,packet_len(0x25e));
  14025. }
  14026. /// Request to add an auction (CZ_AUCTION_ADD).
  14027. /// 024d <now money>.L <max money>.L <delete hour>.W
  14028. void clif_parse_Auction_register(int fd, map_session_data *sd)
  14029. {
  14030. struct auction_data auction;
  14031. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14032. if( !battle_config.feature_auction )
  14033. return;
  14034. auction.price = RFIFOL(fd,info->pos[0]);
  14035. auction.buynow = RFIFOL(fd,info->pos[1]);
  14036. auction.hours = RFIFOW(fd,info->pos[2]);
  14037. // Invalid Situations...
  14038. if( sd->auction.amount < 1 ) {
  14039. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14040. return;
  14041. }
  14042. if( auction.price >= auction.buynow ) {
  14043. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14044. return;
  14045. }
  14046. if( auction.hours < 1 || auction.hours > 48 ) {
  14047. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14048. return;
  14049. }
  14050. // Auction checks...
  14051. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14052. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14053. clif_Auction_message(fd, 2); // The auction has been canceled
  14054. return;
  14055. }
  14056. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14057. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14058. return;
  14059. }
  14060. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14061. auction.buynow = battle_config.auction_maximumprice;
  14062. if( auction.price >= auction.buynow )
  14063. auction.price = auction.buynow - 1;
  14064. }
  14065. auction.auction_id = 0;
  14066. auction.seller_id = sd->status.char_id;
  14067. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14068. auction.buyer_id = 0;
  14069. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14070. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14071. {
  14072. clif_Auction_message(fd, 2); // The auction has been canceled
  14073. return;
  14074. }
  14075. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14076. if( id == nullptr )
  14077. { // Just in case
  14078. clif_Auction_message(fd, 2); // The auction has been canceled
  14079. return;
  14080. }
  14081. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14082. auction.type = id->type;
  14083. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14084. auction.item.amount = 1;
  14085. auction.timestamp = 0;
  14086. if( !intif_Auction_register(&auction) )
  14087. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14088. else
  14089. {
  14090. int zeny = auction.hours*battle_config.auction_feeperhour;
  14091. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14092. sd->auction.amount = 0;
  14093. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  14094. }
  14095. }
  14096. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14097. /// 024e <auction id>.L
  14098. void clif_parse_Auction_cancel(int fd, map_session_data *sd){
  14099. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14100. intif_Auction_cancel(sd->status.char_id, auction_id);
  14101. }
  14102. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14103. /// 025d <auction id>.L
  14104. void clif_parse_Auction_close(int fd, map_session_data *sd){
  14105. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14106. intif_Auction_close(sd->status.char_id, auction_id);
  14107. }
  14108. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14109. /// 024f <auction id>.L <money>.L
  14110. void clif_parse_Auction_bid(int fd, map_session_data *sd){
  14111. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14112. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14113. int bid = RFIFOL(fd,info->pos[1]);
  14114. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14115. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14116. return;
  14117. }
  14118. if( bid <= 0 )
  14119. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14120. else if( bid > sd->status.zeny )
  14121. clif_Auction_message(fd, 8); // You do not have enough zeny
  14122. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14123. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14124. else {
  14125. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14126. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14127. }
  14128. }
  14129. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14130. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14131. /// search type:
  14132. /// 0 = armor
  14133. /// 1 = weapon
  14134. /// 2 = card
  14135. /// 3 = misc
  14136. /// 4 = name search
  14137. /// 5 = auction id search
  14138. void clif_parse_Auction_search(int fd, map_session_data* sd){
  14139. char search_text[NAME_LENGTH];
  14140. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14141. short type = RFIFOW(fd,info->pos[0]);
  14142. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14143. int page = RFIFOW(fd,info->pos[3]);
  14144. if( !battle_config.feature_auction )
  14145. return;
  14146. clif_parse_Auction_cancelreg(fd, sd);
  14147. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14148. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14149. }
  14150. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14151. /// 025c <type>.W
  14152. /// type:
  14153. /// 0 = sell (own auctions)
  14154. /// 1 = buy (own bids)
  14155. void clif_parse_Auction_buysell(int fd, map_session_data* sd)
  14156. {
  14157. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14158. if( !battle_config.feature_auction )
  14159. return;
  14160. clif_parse_Auction_cancelreg(fd, sd);
  14161. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14162. }
  14163. /// CASH/POINT SHOP
  14164. ///
  14165. void clif_cashshop_open( map_session_data* sd, int tab ){
  14166. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14167. nullpo_retv( sd );
  14168. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14169. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14170. p.cashPoints = sd->cashPoints;
  14171. p.kafraPoints = sd->kafraPoints;
  14172. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14173. p.tab = tab;
  14174. #endif
  14175. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14176. #endif
  14177. }
  14178. void clif_parse_cashshop_open_request( int fd, map_session_data* sd ){
  14179. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14180. nullpo_retv( sd );
  14181. int tab = 0;
  14182. #if PACKETVER >= 20191224
  14183. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14184. tab = p->tab;
  14185. #endif
  14186. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14187. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14188. return;
  14189. }
  14190. sd->state.cashshop_open = true;
  14191. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14192. clif_cashshop_open( sd, tab );
  14193. #endif
  14194. }
  14195. void clif_parse_cashshop_close( int fd, map_session_data* sd ){
  14196. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14197. sd->state.cashshop_open = false;
  14198. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14199. // No need to do anything here
  14200. #endif
  14201. }
  14202. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14203. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14204. void clif_parse_CashShopReqTab(int fd, map_session_data *sd) {
  14205. // [4144] packet exists only in 2011 and was dropped after
  14206. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14207. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14208. int j;
  14209. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14210. return;
  14211. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14212. WFIFOW(fd, 0) = 0x8c0;
  14213. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14214. WFIFOL(fd, 4) = tab;
  14215. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14216. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14217. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14218. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14219. }
  14220. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14221. #endif
  14222. }
  14223. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14224. void clif_cashshop_list( map_session_data* sd ){
  14225. nullpo_retv( sd );
  14226. int fd = sd->fd;
  14227. if( !session_isActive( fd ) ){
  14228. return;
  14229. }
  14230. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14231. // Skip empty tabs, the client only expects filled ones
  14232. if( cash_shop_items[tab].count == 0 ){
  14233. continue;
  14234. }
  14235. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14236. WFIFOHEAD( fd, len );
  14237. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14238. p->packetType = 0x8ca;
  14239. p->packetLength = len;
  14240. p->count = cash_shop_items[tab].count;
  14241. p->tabNum = tab;
  14242. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14243. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14244. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14245. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14246. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14247. if( id == nullptr ){
  14248. p->items[i].location = 0;
  14249. p->items[i].viewSprite = 0;
  14250. }else{
  14251. p->items[i].location = pc_equippoint_sub( sd, id );
  14252. p->items[i].viewSprite = id->look;
  14253. }
  14254. #endif
  14255. }
  14256. WFIFOSET( fd, len );
  14257. }
  14258. }
  14259. void clif_parse_cashshop_list_request( int fd, map_session_data* sd ){
  14260. if( !sd->status.cashshop_sent ) {
  14261. clif_cashshop_list( sd );
  14262. #if PACKETVER_SUPPORTS_SALES
  14263. sale_notify_login(sd);
  14264. #endif
  14265. sd->status.cashshop_sent = true;
  14266. }
  14267. }
  14268. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14269. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14270. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14271. void clif_cashshop_show( map_session_data *sd, struct npc_data *nd ){
  14272. nullpo_retv( sd );
  14273. nullpo_retv( nd );
  14274. int fd = sd->fd;
  14275. if( !session_isActive( fd ) ){
  14276. return;
  14277. }
  14278. sd->npc_shopid = nd->bl.id;
  14279. int cost[2] = { 0, 0 };
  14280. npc_shop_currency_type( sd, nd, cost, true );
  14281. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14282. WFIFOHEAD( fd, len );
  14283. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14284. p->packetType = 0x287;
  14285. p->packetLength = len;
  14286. p->cashPoints = cost[0];
  14287. #if PACKETVER >= 20070711
  14288. p->kafraPoints = cost[1];
  14289. #endif
  14290. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14291. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14292. p->items[i].price = nd->u.shop.shop_item[i].value;
  14293. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14294. p->items[i].itemType = itemtype( id->nameid );
  14295. p->items[i].itemId = client_nameid( id->nameid );
  14296. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14297. p->items[i].location = pc_equippoint_sub( sd, id );
  14298. p->items[i].viewSprite = id->look;
  14299. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14300. #endif
  14301. }
  14302. WFIFOSET( fd, len );
  14303. }
  14304. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14305. /// 0289 <cash point>.L <error>.W
  14306. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14307. /// error:
  14308. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14309. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14310. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14311. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14312. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14313. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14314. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14315. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14316. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14317. void clif_cashshop_ack(map_session_data* sd, int error)
  14318. {
  14319. int fd, cost[2] = { 0, 0 };
  14320. struct npc_data *nd;
  14321. nullpo_retv(sd);
  14322. fd = sd->fd;
  14323. nd = map_id2nd(sd->npc_shopid);
  14324. npc_shop_currency_type(sd, nd, cost, false);
  14325. WFIFOHEAD(fd, packet_len(0x289));
  14326. WFIFOW(fd,0) = 0x289;
  14327. WFIFOL(fd,2) = cost[0];
  14328. #if PACKETVER < 20070711
  14329. WFIFOW(fd,6) = TOW(error);
  14330. #else
  14331. WFIFOL(fd,6) = cost[1];
  14332. WFIFOW(fd,10) = TOW(error);
  14333. #endif
  14334. WFIFOSET(fd, packet_len(0x289));
  14335. }
  14336. void clif_cashshop_result( map_session_data *sd, t_itemid item_id, uint16 result ){
  14337. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14338. nullpo_retv( sd );
  14339. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14340. packet.packetType = 0x849;
  14341. if( item_id != 0 ){
  14342. packet.itemId = client_nameid( item_id );
  14343. }else{
  14344. packet.itemId = 0;
  14345. }
  14346. packet.result = result;
  14347. packet.cashPoints = sd->cashPoints;
  14348. packet.kafraPoints = sd->kafraPoints;
  14349. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14350. #endif
  14351. }
  14352. /// Request to buy item(s) from cash shop.
  14353. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14354. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14355. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14356. void clif_parse_npccashshop_buy( int fd, map_session_data *sd ){
  14357. nullpo_retv( sd );
  14358. if( sd->state.trading || !sd->npc_shopid ){
  14359. clif_cashshop_ack( sd, 1 );
  14360. return;
  14361. }
  14362. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14363. #if PACKETVER < 20070711
  14364. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14365. #elif PACKETVER < 20101116
  14366. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14367. #else
  14368. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14369. 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 ){
  14370. 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 );
  14371. return;
  14372. }
  14373. std::vector<s_npc_buy_list> item_list = {};
  14374. item_list.reserve( p->count );
  14375. for( int i = 0; i < p->count; i++ ){
  14376. s_npc_buy_list item = {};
  14377. item.nameid = p->items[i].itemId;
  14378. item.qty = p->items[i].amount;
  14379. item_list.push_back( item );
  14380. }
  14381. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14382. #endif
  14383. }
  14384. /// Request to buy item(s) from cash shop.
  14385. /// 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)
  14386. void clif_parse_cashshop_buy( int fd, map_session_data *sd ){
  14387. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14388. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14389. 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 ){
  14390. 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 );
  14391. return;
  14392. }
  14393. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14394. }
  14395. /// Adoption System
  14396. ///
  14397. /// Adoption message (ZC_BABYMSG).
  14398. /// 0216 <msg>.L
  14399. /// msg:
  14400. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14401. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14402. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14403. void clif_Adopt_reply(map_session_data *sd, int type)
  14404. {
  14405. int fd = sd->fd;
  14406. WFIFOHEAD(fd,6);
  14407. WFIFOW(fd,0) = 0x216;
  14408. WFIFOL(fd,2) = type;
  14409. WFIFOSET(fd,6);
  14410. }
  14411. /// Adoption confirmation (ZC_REQ_BABY).
  14412. /// 01f6 <account id>.L <char id>.L <name>.B
  14413. void clif_Adopt_request(map_session_data *sd, map_session_data *src, int p_id)
  14414. {
  14415. int fd = sd->fd;
  14416. WFIFOHEAD(fd,34);
  14417. WFIFOW(fd,0) = 0x1f6;
  14418. WFIFOL(fd,2) = src->status.account_id;
  14419. WFIFOL(fd,6) = p_id;
  14420. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14421. WFIFOSET(fd,34);
  14422. }
  14423. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14424. /// 01f9 <account id>.L
  14425. void clif_parse_Adopt_request(int fd, map_session_data *sd)
  14426. {
  14427. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14428. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14429. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14430. {
  14431. tsd->adopt_invite = sd->status.account_id;
  14432. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14433. }
  14434. }
  14435. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14436. /// 01f7 <account id>.L <char id>.L <answer>.L
  14437. /// answer:
  14438. /// 0 = rejected
  14439. /// 1 = accepted
  14440. void clif_parse_Adopt_reply(int fd, map_session_data *sd){
  14441. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14442. int p1_id = RFIFOL(fd,info->pos[0]);
  14443. int p2_id = RFIFOL(fd,info->pos[1]);
  14444. int result = RFIFOL(fd,info->pos[2]);
  14445. map_session_data* p1_sd = map_id2sd(p1_id);
  14446. map_session_data* p2_sd = map_id2sd(p2_id);
  14447. int pid = sd->adopt_invite;
  14448. sd->adopt_invite = 0;
  14449. if( p1_sd == NULL || p2_sd == NULL )
  14450. return; // Both players need to be online
  14451. if( pid != p1_sd->status.account_id )
  14452. return; // Incorrect values
  14453. if( result == 0 )
  14454. return; // Rejected
  14455. pc_adoption(p1_sd, p2_sd, sd);
  14456. }
  14457. /// Convex Mirror (ZC_BOSS_INFO).
  14458. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14459. /// infoType:
  14460. /// BOSS_INFO_NOT = No boss on this map.
  14461. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14462. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14463. /// BOSS_INFO_DEAD = Boss is dead.
  14464. void clif_bossmapinfo(map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14465. {
  14466. int fd = sd->fd;
  14467. WFIFOHEAD(fd,70);
  14468. memset(WFIFOP(fd,0),0,70);
  14469. WFIFOW(fd,0) = 0x293;
  14470. switch (flag) {
  14471. case BOSS_INFO_NOT:
  14472. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14473. // No data required
  14474. break;
  14475. case BOSS_INFO_ALIVE:
  14476. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14477. // Update X/Y
  14478. WFIFOL(fd,3) = md->bl.x;
  14479. WFIFOL(fd,7) = md->bl.y;
  14480. break;
  14481. case BOSS_INFO_ALIVE_WITHMSG:
  14482. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14483. // Current X/Y
  14484. WFIFOL(fd,3) = md->bl.x;
  14485. WFIFOL(fd,7) = md->bl.y;
  14486. break;
  14487. case BOSS_INFO_DEAD:
  14488. {
  14489. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14490. unsigned int seconds;
  14491. int hours, minutes;
  14492. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14493. hours = seconds / (60 * 60);
  14494. seconds = seconds - (60 * 60 * hours);
  14495. minutes = seconds / 60;
  14496. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14497. // Add respawn info
  14498. WFIFOW(fd,11) = hours; // Hours
  14499. WFIFOW(fd,13) = minutes; // Minutes
  14500. }
  14501. break;
  14502. }
  14503. if (md != NULL)
  14504. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14505. WFIFOSET(fd,70);
  14506. }
  14507. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14508. /// 02d6 <account id>.L
  14509. void clif_parse_ViewPlayerEquip(int fd, map_session_data* sd)
  14510. {
  14511. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14512. map_session_data* tsd = map_id2sd(aid);
  14513. if (!tsd)
  14514. return;
  14515. if (sd->bl.m != tsd->bl.m)
  14516. return;
  14517. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14518. clif_viewequip_ack(sd, tsd);
  14519. else
  14520. clif_msg(sd, VIEW_EQUIP_FAIL);
  14521. }
  14522. /// Request to a configuration.
  14523. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14524. /// type: see enum e_config_type
  14525. /// flag:
  14526. /// false = disabled
  14527. /// true = enabled
  14528. void clif_parse_configuration( int fd, map_session_data* sd ){
  14529. int cmd = RFIFOW(fd,0);
  14530. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14531. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14532. switch( type ){
  14533. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14534. sd->status.show_equip = flag;
  14535. break;
  14536. case CONFIG_CALL:
  14537. sd->status.disable_call = flag;
  14538. break;
  14539. case CONFIG_PET_AUTOFEED:
  14540. // Player can not click this if he does not have a pet
  14541. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14542. return;
  14543. }
  14544. sd->pd->pet.autofeed = flag;
  14545. break;
  14546. case CONFIG_HOMUNCULUS_AUTOFEED:
  14547. // Player can not click this if he does not have a homunculus or it is vaporized
  14548. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14549. return;
  14550. }
  14551. sd->hd->homunculus.autofeed = flag;
  14552. break;
  14553. default:
  14554. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14555. return;
  14556. }
  14557. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14558. }
  14559. /// Request to change party invitation tick.
  14560. /// value:
  14561. /// 0 = disabled
  14562. /// 1 = enabled
  14563. void clif_parse_PartyTick(int fd, map_session_data* sd)
  14564. {
  14565. bool flag = RFIFOB(fd,6) ? true : false;
  14566. sd->status.allow_party = flag;
  14567. clif_partytickack(sd, flag);
  14568. }
  14569. /// Questlog System [Kevin] [Inkfish]
  14570. ///
  14571. /**
  14572. * Safe check to init packet len & quest num for player.
  14573. * @param def_len
  14574. * @param info_len Length of each quest info.
  14575. * @param avail_quests Avail quests that player has.
  14576. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14577. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14578. **/
  14579. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14580. (*limit_out) = (0xFFFF - def_len) / info_len;
  14581. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14582. (*len_out) = ((*limit_out) * info_len) + def_len;
  14583. }
  14584. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14585. std::string race_name;
  14586. switch( objective->race ){
  14587. case RC_FORMLESS: race_name = "Formless"; break;
  14588. case RC_UNDEAD: race_name = "Undead"; break;
  14589. case RC_BRUTE: race_name = "Brute"; break;
  14590. case RC_PLANT: race_name = "Plant"; break;
  14591. case RC_INSECT: race_name = "Insect"; break;
  14592. case RC_FISH: race_name = "Fish"; break;
  14593. case RC_DEMON: race_name = "Demon"; break;
  14594. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14595. case RC_ANGEL: race_name = "Angel"; break;
  14596. case RC_DRAGON: race_name = "Dragon"; break;
  14597. default:
  14598. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14599. // Fallthrough
  14600. case RC_ALL: race_name = ""; break;
  14601. }
  14602. std::string size_name;
  14603. switch( objective->size ){
  14604. case SZ_SMALL: size_name = "Small"; break;
  14605. case SZ_MEDIUM: size_name = "Medium"; break;
  14606. case SZ_BIG: size_name = "Large"; break;
  14607. default:
  14608. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14609. // Fallthrough
  14610. case SZ_ALL: size_name = ""; break;
  14611. }
  14612. std::string ele_name;
  14613. switch( objective->element ){
  14614. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14615. case ELE_WATER: ele_name = "Water Element"; break;
  14616. case ELE_EARTH: ele_name = "Earth Element"; break;
  14617. case ELE_FIRE: ele_name = "Fire Element"; break;
  14618. case ELE_WIND: ele_name = "Wind Element"; break;
  14619. case ELE_POISON: ele_name = "Poison Element"; break;
  14620. case ELE_HOLY: ele_name = "Holy Element"; break;
  14621. case ELE_DARK: ele_name = "Shadow Element"; break;
  14622. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14623. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14624. default:
  14625. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14626. // Fallthrough
  14627. case ELE_ALL: ele_name = ""; break;
  14628. }
  14629. std::string str;
  14630. if( !objective->map_name.empty() ){
  14631. str += objective->map_name;
  14632. }
  14633. if( !race_name.empty() ){
  14634. if( !str.empty() ){
  14635. str += ", ";
  14636. }
  14637. str += race_name;
  14638. }
  14639. if( !size_name.empty() ){
  14640. if( !str.empty() ){
  14641. str += ", ";
  14642. }
  14643. str += size_name;
  14644. }
  14645. if( !ele_name.empty() ){
  14646. if( !str.empty() ){
  14647. str += ", ";
  14648. }
  14649. str += ele_name;
  14650. }
  14651. return str;
  14652. }
  14653. /// Sends list of all quest states
  14654. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14655. /// 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)
  14656. /// 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)
  14657. void clif_quest_send_list(map_session_data *sd)
  14658. {
  14659. nullpo_retv(sd);
  14660. int fd = sd->fd;
  14661. int i;
  14662. int offset = 8;
  14663. int limit = 0;
  14664. #if PACKETVER >= 20141022
  14665. #if PACKETVER >= 20150513
  14666. int size = 22 + NAME_LENGTH;
  14667. #else
  14668. int size = 10 + NAME_LENGTH;
  14669. #endif
  14670. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14671. WFIFOHEAD(fd,i);
  14672. #if PACKETVER >= 20150513
  14673. WFIFOW(fd, 0) = 0x9f8;
  14674. #else
  14675. WFIFOW(fd, 0) = 0x97a;
  14676. #endif
  14677. WFIFOL(fd, 4) = limit;
  14678. for (i = 0; i < limit; i++) {
  14679. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14680. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14681. offset += 4;
  14682. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14683. offset++;
  14684. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14685. offset += 4;
  14686. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14687. offset += 4;
  14688. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14689. offset += 2;
  14690. if (!qi->objectives.empty()) {
  14691. std::shared_ptr<s_mob_db> mob;
  14692. for (int j = 0; j < qi->objectives.size(); j++) {
  14693. mob = mob_db.find(qi->objectives[j]->mob_id);
  14694. e_race race = qi->objectives[j]->race;
  14695. e_size size = qi->objectives[j]->size;
  14696. e_element element = qi->objectives[j]->element;
  14697. #if PACKETVER >= 20150513
  14698. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14699. offset += 4;
  14700. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14701. offset += 4;
  14702. #endif
  14703. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14704. offset += 4;
  14705. #if PACKETVER >= 20150513
  14706. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14707. offset += 2;
  14708. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14709. offset += 2;
  14710. #endif
  14711. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14712. offset += 2;
  14713. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14714. offset += 2;
  14715. if (mob && qi->objectives[j]->mob_id > 0)
  14716. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14717. else
  14718. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14719. offset += NAME_LENGTH;
  14720. }
  14721. }
  14722. }
  14723. WFIFOW(fd, 2) = offset;
  14724. WFIFOSET(fd, offset);
  14725. #else
  14726. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14727. WFIFOHEAD(fd,i);
  14728. WFIFOW(fd, 0) = 0x2b1;
  14729. WFIFOL(fd, 4) = limit;
  14730. for (i = 0; i < limit; i++) {
  14731. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14732. offset += 4;
  14733. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14734. offset += 1;
  14735. }
  14736. WFIFOW(fd, 2) = offset;
  14737. WFIFOSET(fd, offset);
  14738. #endif
  14739. }
  14740. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14741. /// 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
  14742. void clif_quest_send_mission(map_session_data *sd)
  14743. {
  14744. nullpo_retv(sd);
  14745. int fd = sd->fd;
  14746. int limit = 0;
  14747. int len = sd->avail_quests*104+8;
  14748. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14749. WFIFOHEAD(fd, len);
  14750. WFIFOW(fd, 0) = 0x2b2;
  14751. WFIFOW(fd, 2) = len;
  14752. WFIFOL(fd, 4) = limit;
  14753. for (int i = 0; i < limit; i++) {
  14754. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14755. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14756. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14757. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14758. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14759. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14760. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14761. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14762. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14763. if (mob && qi->objectives[j]->mob_id > 0)
  14764. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14765. else
  14766. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14767. }
  14768. }
  14769. WFIFOSET(fd, len);
  14770. }
  14771. /// Notification about a new quest
  14772. /// 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)
  14773. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14774. /// 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)
  14775. void clif_quest_add(map_session_data *sd, struct quest *qd)
  14776. {
  14777. nullpo_retv(sd);
  14778. nullpo_retv(qd);
  14779. int fd = sd->fd;
  14780. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14781. if (!qi)
  14782. return;
  14783. #if PACKETVER >= 20150513
  14784. int cmd = 0x9f9;
  14785. #else
  14786. int cmd = 0x2b3;
  14787. #endif
  14788. WFIFOHEAD(fd, packet_len(cmd));
  14789. WFIFOW(fd, 0) = cmd;
  14790. WFIFOL(fd, 2) = qd->quest_id;
  14791. WFIFOB(fd, 6) = qd->state;
  14792. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14793. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14794. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14795. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14796. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14797. e_race race = qi->objectives[i]->race;
  14798. e_size size = qi->objectives[i]->size;
  14799. e_element element = qi->objectives[i]->element;
  14800. #if PACKETVER >= 20150513
  14801. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14802. offset += 4;
  14803. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14804. offset += 4;
  14805. #endif
  14806. 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
  14807. offset += 4;
  14808. #if PACKETVER >= 20150513
  14809. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14810. offset += 2;
  14811. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14812. offset += 2;
  14813. #endif
  14814. WFIFOW(fd, offset) = qd->count[i];
  14815. offset += 2;
  14816. if (mob && qi->objectives[i]->mob_id > 0)
  14817. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14818. else
  14819. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14820. offset += NAME_LENGTH;
  14821. }
  14822. WFIFOSET(fd, packet_len(cmd));
  14823. #if PACKETVER >= 20150513
  14824. int len = 4 + qi->objectives.size() * 12;
  14825. WFIFOHEAD(fd, len);
  14826. WFIFOW(fd, 0) = 0x8fe;
  14827. WFIFOW(fd, 2) = len;
  14828. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14829. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14830. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14831. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14832. WFIFOW(fd, offset + 10) = qd->count[i];
  14833. }
  14834. WFIFOSET(fd, len);
  14835. #endif
  14836. }
  14837. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14838. /// 02b4 <quest id>.L
  14839. void clif_quest_delete(map_session_data *sd, int quest_id)
  14840. {
  14841. int fd = sd->fd;
  14842. WFIFOHEAD(fd, packet_len(0x2b4));
  14843. WFIFOW(fd, 0) = 0x2b4;
  14844. WFIFOL(fd, 2) = quest_id;
  14845. WFIFOSET(fd, packet_len(0x2b4));
  14846. }
  14847. /// Notification of an update to the hunting mission counter
  14848. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14849. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14850. void clif_quest_update_objective(map_session_data *sd, struct quest *qd)
  14851. {
  14852. int fd = sd->fd;
  14853. int offset = 6;
  14854. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14855. int len = qi->objectives.size() * 12 + 6;
  14856. #if PACKETVER >= 20150513
  14857. int cmd = 0x9fa;
  14858. #else
  14859. int cmd = 0x2b5;
  14860. #endif
  14861. WFIFOHEAD(fd, len);
  14862. WFIFOW(fd, 0) = cmd;
  14863. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14864. for (int i = 0; i < qi->objectives.size(); i++) {
  14865. WFIFOL(fd, offset) = qd->quest_id;
  14866. offset += 4;
  14867. #if PACKETVER >= 20150513
  14868. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14869. offset += 4;
  14870. #else
  14871. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14872. offset += 4;
  14873. #endif
  14874. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14875. offset += 2;
  14876. WFIFOW(fd, offset) = qd->count[i];
  14877. offset += 2;
  14878. }
  14879. WFIFOW(fd, 2) = offset;
  14880. WFIFOSET(fd, offset);
  14881. }
  14882. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14883. /// 02b6 <quest id>.L <active>.B
  14884. void clif_parse_questStateAck(int fd, map_session_data *sd)
  14885. {
  14886. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14887. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14888. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14889. }
  14890. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14891. /// 02b7 <quest id>.L <active>.B
  14892. void clif_quest_update_status(map_session_data *sd, int quest_id, bool active)
  14893. {
  14894. int fd = sd->fd;
  14895. WFIFOHEAD(fd, packet_len(0x2b7));
  14896. WFIFOW(fd, 0) = 0x2b7;
  14897. WFIFOL(fd, 2) = quest_id;
  14898. WFIFOB(fd, 6) = active;
  14899. WFIFOSET(fd, packet_len(0x2b7));
  14900. }
  14901. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14902. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14903. /// effect:
  14904. /// 0 = none
  14905. /// 1 = exclamation mark icon
  14906. /// 2 = question mark icon
  14907. /// color:
  14908. /// 0 = yellow
  14909. /// 1 = orange
  14910. /// 2 = green
  14911. /// 3 = purple
  14912. void clif_quest_show_event(map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14913. {
  14914. #if PACKETVER >= 20090218
  14915. nullpo_retv(sd);
  14916. nullpo_retv(bl);
  14917. int fd = sd->fd;
  14918. WFIFOHEAD(fd, packet_len(0x446));
  14919. WFIFOW(fd, 0) = 0x446;
  14920. WFIFOL(fd, 2) = bl->id;
  14921. WFIFOW(fd, 6) = bl->x;
  14922. WFIFOW(fd, 8) = bl->y;
  14923. WFIFOW(fd, 10) = effect;
  14924. WFIFOW(fd, 12) = color;
  14925. WFIFOSET(fd, packet_len(0x446));
  14926. #endif
  14927. }
  14928. /// Mercenary System
  14929. ///
  14930. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14931. /// 02a2 <var id>.W <value>.L
  14932. void clif_mercenary_updatestatus(map_session_data *sd, int type)
  14933. {
  14934. s_mercenary_data *md;
  14935. struct status_data *status;
  14936. int fd;
  14937. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14938. return;
  14939. fd = sd->fd;
  14940. status = &md->battle_status;
  14941. WFIFOHEAD(fd,packet_len(0x2a2));
  14942. WFIFOW(fd,0) = 0x2a2;
  14943. WFIFOW(fd,2) = type;
  14944. switch( type ) {
  14945. case SP_ATK1:
  14946. {
  14947. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14948. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14949. }
  14950. break;
  14951. case SP_MATK1:
  14952. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14953. break;
  14954. case SP_HIT:
  14955. WFIFOL(fd,4) = status->hit;
  14956. break;
  14957. case SP_CRITICAL:
  14958. WFIFOL(fd,4) = status->cri/10;
  14959. break;
  14960. case SP_DEF1:
  14961. WFIFOL(fd,4) = status->def;
  14962. break;
  14963. case SP_MDEF1:
  14964. WFIFOL(fd,4) = status->mdef;
  14965. break;
  14966. case SP_MERCFLEE:
  14967. WFIFOL(fd,4) = status->flee;
  14968. break;
  14969. case SP_ASPD:
  14970. WFIFOL(fd,4) = status->amotion;
  14971. break;
  14972. case SP_HP:
  14973. WFIFOL(fd,4) = status->hp;
  14974. break;
  14975. case SP_MAXHP:
  14976. WFIFOL(fd,4) = status->max_hp;
  14977. break;
  14978. case SP_SP:
  14979. WFIFOL(fd,4) = status->sp;
  14980. break;
  14981. case SP_MAXSP:
  14982. WFIFOL(fd,4) = status->max_sp;
  14983. break;
  14984. case SP_MERCKILLS:
  14985. WFIFOL(fd,4) = md->mercenary.kill_count;
  14986. break;
  14987. case SP_MERCFAITH:
  14988. WFIFOL(fd,4) = mercenary_get_faith(md);
  14989. break;
  14990. }
  14991. WFIFOSET(fd,packet_len(0x2a2));
  14992. }
  14993. /// Mercenary base status data (ZC_MER_INIT).
  14994. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14995. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14996. /// <calls>.L <kills>.L <atk range>.W
  14997. void clif_mercenary_info(map_session_data *sd)
  14998. {
  14999. int fd;
  15000. s_mercenary_data *md;
  15001. struct status_data *status;
  15002. int atk;
  15003. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15004. return;
  15005. fd = sd->fd;
  15006. status = &md->battle_status;
  15007. WFIFOHEAD(fd,packet_len(0x29b));
  15008. WFIFOW(fd,0) = 0x29b;
  15009. WFIFOL(fd,2) = md->bl.id;
  15010. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15011. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15012. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15013. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15014. WFIFOW(fd,10) = status->hit;
  15015. WFIFOW(fd,12) = status->cri/10;
  15016. WFIFOW(fd,14) = status->def;
  15017. WFIFOW(fd,16) = status->mdef;
  15018. WFIFOW(fd,18) = status->flee;
  15019. WFIFOW(fd,20) = status->amotion;
  15020. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15021. WFIFOW(fd,46) = md->db->lv;
  15022. WFIFOL(fd,48) = status->hp;
  15023. WFIFOL(fd,52) = status->max_hp;
  15024. WFIFOL(fd,56) = status->sp;
  15025. WFIFOL(fd,60) = status->max_sp;
  15026. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15027. WFIFOW(fd,68) = mercenary_get_faith(md);
  15028. WFIFOL(fd,70) = mercenary_get_calls(md);
  15029. WFIFOL(fd,74) = md->mercenary.kill_count;
  15030. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15031. WFIFOSET(fd,packet_len(0x29b));
  15032. }
  15033. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15034. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15035. void clif_mercenary_skillblock(map_session_data *sd)
  15036. {
  15037. s_mercenary_data *md;
  15038. int fd, len = 4;
  15039. if( sd == NULL || (md = sd->md) == NULL )
  15040. return;
  15041. fd = sd->fd;
  15042. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15043. WFIFOW(fd,0) = 0x29d;
  15044. for (const auto &it : md->db->skill) {
  15045. uint16 id = it.first;
  15046. if (!SKILL_CHK_MERC(id))
  15047. continue;
  15048. uint16 lv = it.second;
  15049. WFIFOW(fd,len) = id;
  15050. WFIFOL(fd,len+2) = skill_get_inf(id);
  15051. WFIFOW(fd,len+6) = lv;
  15052. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15053. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15054. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15055. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15056. len += 37;
  15057. }
  15058. WFIFOW(fd,2) = len;
  15059. WFIFOSET(fd,len);
  15060. }
  15061. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15062. /// 029f <command>.B
  15063. /// 1 = mercenary information
  15064. /// 2 = delete
  15065. void clif_parse_mercenary_action(int fd, map_session_data* sd)
  15066. {
  15067. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15068. if( sd->md == NULL )
  15069. return;
  15070. if( option == 2 ) mercenary_delete(sd->md, 2);
  15071. }
  15072. /// Mercenary Message
  15073. /// message:
  15074. /// 0 = Mercenary soldier's duty hour is over.
  15075. /// 1 = Your mercenary soldier has been killed.
  15076. /// 2 = Your mercenary soldier has been fired.
  15077. /// 3 = Your mercenary soldier has ran away.
  15078. void clif_mercenary_message(map_session_data* sd, int message){
  15079. clif_msg(sd, MERC_MSG_BASE + message);
  15080. }
  15081. /// Notification about the remaining time of a rental item.
  15082. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15083. void clif_rental_time( map_session_data* sd, t_itemid nameid, int seconds ){
  15084. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15085. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15086. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15087. p.itemId = client_nameid( nameid );
  15088. p.seconds = seconds;
  15089. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15090. }
  15091. /// Deletes a rental item from client's inventory.
  15092. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15093. void clif_rental_expired( map_session_data* sd, int index, t_itemid nameid ){
  15094. // '<ItemName>' item has been deleted from the Inventory
  15095. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15096. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15097. p.index = client_index( index );
  15098. p.itemId = client_nameid( nameid );
  15099. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15100. }
  15101. /// Book Reading (ZC_READ_BOOK).
  15102. /// 0294 <book id>.L <page>.L
  15103. void clif_readbook(int fd, int book_id, int page)
  15104. {
  15105. WFIFOHEAD(fd,packet_len(0x294));
  15106. WFIFOW(fd,0) = 0x294;
  15107. WFIFOL(fd,2) = book_id;
  15108. WFIFOL(fd,6) = page;
  15109. WFIFOSET(fd,packet_len(0x294));
  15110. }
  15111. /// Battlegrounds
  15112. ///
  15113. /// Updates HP bar of a camp member.
  15114. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15115. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15116. void clif_bg_hp(map_session_data *sd) {
  15117. #if PACKETVER < 20140613
  15118. unsigned char buf[34];
  15119. const int cmd = 0x2e0;
  15120. #else
  15121. unsigned char buf[14];
  15122. const int cmd = 0xa0e;
  15123. #endif
  15124. nullpo_retv(sd);
  15125. WBUFW(buf,0) = cmd;
  15126. WBUFL(buf,2) = sd->status.account_id;
  15127. #if PACKETVER < 20140613
  15128. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15129. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15130. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15131. WBUFW(buf,32) = 100;
  15132. } else {
  15133. WBUFW(buf,30) = sd->battle_status.hp;
  15134. WBUFW(buf,32) = sd->battle_status.max_hp;
  15135. }
  15136. #else
  15137. if( sd->battle_status.max_hp > INT32_MAX ) {
  15138. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15139. WBUFL(buf,10) = 100;
  15140. } else {
  15141. WBUFL(buf,6) = sd->battle_status.hp;
  15142. WBUFL(buf,10) = sd->battle_status.max_hp;
  15143. }
  15144. #endif
  15145. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15146. }
  15147. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15148. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15149. void clif_bg_xy(map_session_data *sd)
  15150. {
  15151. unsigned char buf[36];
  15152. nullpo_retv(sd);
  15153. WBUFW(buf,0)=0x2df;
  15154. WBUFL(buf,2)=sd->status.account_id;
  15155. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15156. WBUFW(buf,30)=sd->status.class_;
  15157. WBUFW(buf,32)=sd->bl.x;
  15158. WBUFW(buf,34)=sd->bl.y;
  15159. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15160. }
  15161. void clif_bg_xy_remove(map_session_data *sd)
  15162. {
  15163. unsigned char buf[36];
  15164. nullpo_retv(sd);
  15165. WBUFW(buf,0)=0x2df;
  15166. WBUFL(buf,2)=sd->status.account_id;
  15167. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15168. WBUFW(buf,30)=0;
  15169. WBUFW(buf,32)=-1;
  15170. WBUFW(buf,34)=-1;
  15171. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15172. }
  15173. /// Notifies clients of a battleground message.
  15174. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15175. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15176. map_session_data *sd = bg_getavailablesd( bg );
  15177. if( sd == nullptr ){
  15178. return;
  15179. }
  15180. // limit length
  15181. len = min( len + 1, CHAT_SIZE_MAX );
  15182. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15183. WBUFW(buf,0) = 0x2dc;
  15184. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15185. WBUFL(buf,4) = src_id;
  15186. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15187. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15188. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15189. }
  15190. /// Validates and processes battlechat messages.
  15191. /// All messages that are sent after enabling battleground chat with /battlechat.
  15192. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15193. void clif_parse_BattleChat(int fd, map_session_data* sd){
  15194. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15195. if( !clif_process_message( sd, false, name, message, output ) )
  15196. return;
  15197. bg_send_message(sd, output, strlen(output) );
  15198. }
  15199. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15200. /// 02de <camp A points>.W <camp B points>.W
  15201. void clif_bg_updatescore(int16 m)
  15202. {
  15203. struct block_list bl;
  15204. unsigned char buf[6];
  15205. struct map_data *mapdata = map_getmapdata(m);
  15206. bl.id = 0;
  15207. bl.type = BL_NUL;
  15208. bl.m = m;
  15209. WBUFW(buf,0) = 0x2de;
  15210. WBUFW(buf,2) = mapdata->bgscore_lion;
  15211. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15212. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15213. }
  15214. void clif_bg_updatescore_single(map_session_data *sd)
  15215. {
  15216. int fd;
  15217. nullpo_retv(sd);
  15218. fd = sd->fd;
  15219. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15220. WFIFOHEAD(fd,packet_len(0x2de));
  15221. WFIFOW(fd,0) = 0x2de;
  15222. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15223. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15224. WFIFOSET(fd,packet_len(0x2de));
  15225. }
  15226. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15227. /// 02dd <account id>.L <name>.24B <camp>.W
  15228. void clif_sendbgemblem_area(map_session_data *sd)
  15229. {
  15230. unsigned char buf[33];
  15231. nullpo_retv(sd);
  15232. WBUFW(buf, 0) = 0x2dd;
  15233. WBUFL(buf,2) = sd->bl.id;
  15234. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15235. WBUFW(buf,30) = sd->bg_id;
  15236. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15237. }
  15238. void clif_sendbgemblem_single(int fd, map_session_data *sd)
  15239. {
  15240. nullpo_retv(sd);
  15241. WFIFOHEAD(fd,32);
  15242. WFIFOW(fd,0) = 0x2dd;
  15243. WFIFOL(fd,2) = sd->bl.id;
  15244. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15245. WFIFOW(fd,30) = sd->bg_id;
  15246. WFIFOSET(fd,packet_len(0x2dd));
  15247. }
  15248. /// Battlegrounds queue incoming apply request from client.
  15249. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15250. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15251. void clif_parse_bg_queue_apply_request(int fd, map_session_data *sd)
  15252. {
  15253. if (!battle_config.feature_bgqueue)
  15254. return;
  15255. nullpo_retv(sd);
  15256. short type = RFIFOW(fd,2);
  15257. char name[NAME_LENGTH];
  15258. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15259. if (sd->bg_queue_id > 0) {
  15260. //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);
  15261. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15262. return;
  15263. } else if (type == 1) // Solo
  15264. bg_queue_join_solo(name, sd);
  15265. else if (type == 2) // Party
  15266. bg_queue_join_party(name, sd);
  15267. else if (type == 4) // Guild
  15268. bg_queue_join_guild(name, sd);
  15269. else {
  15270. 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);
  15271. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15272. return;
  15273. }
  15274. }
  15275. /// Outgoing battlegrounds queue apply result.
  15276. /// Result types: @see e_bg_queue_apply_ack
  15277. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15278. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, map_session_data *sd)
  15279. {
  15280. nullpo_retv(sd);
  15281. int fd = sd->fd;
  15282. WFIFOHEAD(fd, packet_len(0x8d8));
  15283. WFIFOW(fd,0) = 0x8d8;
  15284. WFIFOB(fd,2) = result;
  15285. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15286. WFIFOSET(fd, packet_len(0x8d8));
  15287. }
  15288. /// Outgoing battlegrounds queue apply notification.
  15289. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15290. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15291. void clif_bg_queue_apply_notify(const char *name, map_session_data *sd)
  15292. {
  15293. nullpo_retv(sd);
  15294. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15295. if (queue == nullptr) {
  15296. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15297. return;
  15298. }
  15299. int fd = sd->fd;
  15300. WFIFOHEAD(fd, packet_len(0x8d9));
  15301. WFIFOW(fd,0) = 0x8d9;
  15302. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15303. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15304. WFIFOSET(fd, packet_len(0x8d9));
  15305. }
  15306. /// Battlegrounds queue outgoing cancel result.
  15307. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15308. void clif_bg_queue_cancel_result(bool success, const char *name, map_session_data *sd)
  15309. {
  15310. nullpo_retv(sd);
  15311. int fd = sd->fd;
  15312. WFIFOHEAD(fd, packet_len(0x8d8));
  15313. WFIFOW(fd,0) = 0x8db;
  15314. WFIFOB(fd,2) = success;
  15315. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15316. WFIFOSET(fd, packet_len(0x8d8));
  15317. }
  15318. /// Battlegrounds queue incoming cancel request from client.
  15319. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15320. void clif_parse_bg_queue_cancel_request(int fd, map_session_data *sd)
  15321. {
  15322. if (!battle_config.feature_bgqueue)
  15323. return;
  15324. nullpo_retv(sd);
  15325. bool success;
  15326. if (sd->bg_queue_id > 0) {
  15327. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15328. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15329. 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.
  15330. else
  15331. success = bg_queue_leave(sd);
  15332. } else {
  15333. 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);
  15334. success = false;
  15335. }
  15336. char name[NAME_LENGTH];
  15337. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15338. clif_bg_queue_cancel_result(success, name, sd);
  15339. }
  15340. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15341. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15342. void clif_bg_queue_lobby_notify(const char *name, map_session_data *sd)
  15343. {
  15344. nullpo_retv(sd);
  15345. int fd = sd->fd;
  15346. WFIFOHEAD(fd, packet_len(0x8df));
  15347. WFIFOW(fd,0) = 0x8df;
  15348. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15349. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15350. WFIFOSET(fd, packet_len(0x8df));
  15351. }
  15352. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15353. /// Result types: 1(Accept), 2(Decline).
  15354. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15355. void clif_parse_bg_queue_lobby_reply(int fd, map_session_data *sd)
  15356. {
  15357. nullpo_retv(sd);
  15358. if(sd->bg_queue_id > 0) {
  15359. uint8 result = RFIFOB(fd, 2);
  15360. if(result == 1) { // Accept
  15361. bg_queue_on_accept_invite(sd);
  15362. } else if(result == 2) { // Decline
  15363. bg_queue_leave(sd);
  15364. clif_bg_queue_entry_init(sd);
  15365. }
  15366. }
  15367. }
  15368. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15369. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15370. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, map_session_data *sd)
  15371. {
  15372. nullpo_retv(sd);
  15373. int fd = sd->fd;
  15374. WFIFOHEAD(fd, packet_len(0x8e1));
  15375. WFIFOW(fd,0) = 0x8e1;
  15376. WFIFOB(fd,2) = result;
  15377. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15378. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15379. WFIFOSET(fd, packet_len(0x8e1));
  15380. }
  15381. /// Battlegrounds queue incoming queue number request from client.
  15382. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15383. void clif_parse_bg_queue_request_queue_number(int fd, map_session_data *sd)
  15384. {
  15385. nullpo_retv(sd);
  15386. char name[NAME_LENGTH];
  15387. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15388. clif_bg_queue_apply_notify(name, sd);
  15389. }
  15390. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15391. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15392. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15393. void clif_bg_queue_entry_init(map_session_data *sd)
  15394. {
  15395. nullpo_retv(sd);
  15396. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15397. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15398. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15399. }
  15400. /// Custom Fonts (ZC_NOTIFY_FONT).
  15401. /// 02ef <account_id>.L <font id>.W
  15402. void clif_font(map_session_data *sd)
  15403. {
  15404. #if PACKETVER >= 20080102
  15405. unsigned char buf[8];
  15406. nullpo_retv(sd);
  15407. WBUFW(buf,0) = 0x2ef;
  15408. WBUFL(buf,2) = sd->bl.id;
  15409. WBUFW(buf,6) = sd->status.font;
  15410. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15411. #endif
  15412. }
  15413. /// Required to start the instancing information window on Client
  15414. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15415. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15416. void clif_instance_create(int instance_id, int num)
  15417. {
  15418. #if PACKETVER >= 20071128
  15419. map_session_data *sd = NULL;
  15420. enum send_target target = PARTY;
  15421. unsigned char buf[65];
  15422. instance_getsd(instance_id, sd, &target);
  15423. if (!sd)
  15424. return;
  15425. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15426. if (!db)
  15427. return;
  15428. WBUFW(buf,0) = 0x2cb;
  15429. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15430. WBUFW(buf,63) = num;
  15431. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15432. #endif
  15433. return;
  15434. }
  15435. /// To announce Instancing queue creation if no maps available
  15436. /// S 0x2cc <Standby Position>.W
  15437. void clif_instance_changewait(int instance_id, int num)
  15438. {
  15439. #if PACKETVER >= 20071128
  15440. map_session_data *sd = NULL;
  15441. enum send_target target = PARTY;
  15442. unsigned char buf[4];
  15443. instance_getsd(instance_id, sd, &target);
  15444. if (!sd)
  15445. return;
  15446. WBUFW(buf,0) = 0x2cc;
  15447. WBUFW(buf,2) = num;
  15448. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15449. #endif
  15450. return;
  15451. }
  15452. /// Notify the current status to members
  15453. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15454. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15455. {
  15456. #if PACKETVER >= 20071128
  15457. map_session_data *sd = NULL;
  15458. enum send_target target = PARTY;
  15459. unsigned char buf[71];
  15460. instance_getsd(instance_id, sd, &target);
  15461. if (!sd)
  15462. return;
  15463. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15464. if (!db)
  15465. return;
  15466. WBUFW(buf,0) = 0x2cd;
  15467. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15468. WBUFL(buf,63) = limit1;
  15469. WBUFL(buf,67) = limit2;
  15470. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15471. #endif
  15472. return;
  15473. }
  15474. /// Notify a status change to members
  15475. /// S 0x2ce <Message ID>.L
  15476. /// 0 = Notification (EnterLimitDate update?)
  15477. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15478. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15479. /// 3 = The Memorial Dungeon has been removed.
  15480. /// 4 = Create failure (removes the instance window)
  15481. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15482. {
  15483. #if PACKETVER >= 20071128
  15484. map_session_data *sd = NULL;
  15485. enum send_target target = PARTY;
  15486. unsigned char buf[10];
  15487. instance_getsd(instance_id, sd, &target);
  15488. if (!sd)
  15489. return;
  15490. WBUFW(buf,0) = 0x2ce;
  15491. WBUFL(buf,2) = type;
  15492. WBUFL(buf,6) = limit;
  15493. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15494. #endif
  15495. return;
  15496. }
  15497. /// Destroy an instance from the status window
  15498. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15499. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15500. {
  15501. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15502. return;
  15503. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15504. switch (p->command) {
  15505. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15506. instance_destroy_command(sd);
  15507. break;
  15508. }
  15509. }
  15510. void clif_instance_info( map_session_data& sd ){
  15511. if( sd.instance_id > 0 ){
  15512. instance_reqinfo( &sd, sd.instance_id );
  15513. }
  15514. if( sd.status.party_id > 0 ){
  15515. struct party_data* p = party_search( sd.status.party_id );
  15516. if( p != nullptr && p->instance_id > 0 ){
  15517. instance_reqinfo( &sd, p->instance_id );
  15518. }
  15519. }
  15520. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15521. instance_reqinfo( &sd, sd.guild->instance_id );
  15522. }
  15523. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15524. instance_reqinfo( &sd, sd.clan->instance_id );
  15525. }
  15526. }
  15527. /// Notifies clients about item picked up by a party member.
  15528. /// 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)
  15529. void clif_party_show_picker( map_session_data* sd, struct item* item_data ){
  15530. #if PACKETVER >= 20071002
  15531. nullpo_retv( sd );
  15532. nullpo_retv( item_data );
  15533. struct item_data* id = itemdb_search( item_data->nameid );
  15534. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15535. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15536. p.AID = sd->status.account_id;
  15537. p.itemId = client_nameid( item_data->nameid );
  15538. p.identified = item_data->identify;
  15539. p.damaged = item_data->attribute;
  15540. p.refine = item_data->refine;
  15541. clif_addcards( &p.slot, item_data );
  15542. p.location = id->equip; // equip location
  15543. p.itemType = itemtype( id->nameid ); // item type
  15544. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15545. p.grade = item_data->enchantgrade;
  15546. #endif
  15547. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15548. #endif
  15549. }
  15550. /** Display gained exp.
  15551. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15552. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15553. * amount: INT32_MIN ~ INT32_MAX
  15554. * var id:
  15555. * SP_BASEEXP, SP_JOBEXP
  15556. * exp type:
  15557. * 0 = normal exp gained/lost
  15558. * 1 = quest exp gained/lost
  15559. * @param sd Player
  15560. * @param exp EXP value gained/loss
  15561. * @param type SP_BASEEXP, SP_JOBEXP
  15562. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15563. * @param lost True:if losing EXP
  15564. */
  15565. void clif_displayexp(map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15566. {
  15567. int fd;
  15568. int offset;
  15569. #if PACKETVER >= 20170830
  15570. int cmd = 0xacc;
  15571. #else
  15572. int cmd = 0x7f6;
  15573. #endif
  15574. nullpo_retv(sd);
  15575. fd = sd->fd;
  15576. WFIFOHEAD(fd, packet_len(cmd));
  15577. WFIFOW(fd,0) = cmd;
  15578. WFIFOL(fd,2) = sd->bl.id;
  15579. #if PACKETVER >= 20170830
  15580. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15581. offset = 4;
  15582. #else
  15583. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15584. offset = 0;
  15585. #endif
  15586. WFIFOW(fd,10+offset) = type;
  15587. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15588. WFIFOSET(fd,packet_len(cmd));
  15589. }
  15590. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15591. /// type:
  15592. /// 0 = Displays 'value' for 5 seconds.
  15593. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15594. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15595. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15596. /// value:
  15597. /// 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).
  15598. void clif_showdigit(map_session_data* sd, unsigned char type, int value)
  15599. {
  15600. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15601. WFIFOW(sd->fd,0) = 0x1b1;
  15602. WFIFOB(sd->fd,2) = type;
  15603. WFIFOL(sd->fd,3) = value;
  15604. WFIFOSET(sd->fd, packet_len(0x1b1));
  15605. }
  15606. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15607. /// 021d <state>.L
  15608. /// state:
  15609. /// 0 = Full effects
  15610. /// 1 = Reduced effects
  15611. ///
  15612. /// NOTE: The state is used on Aegis for sending skill unit packet
  15613. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15614. /// whenever possible. Due to the way the decision check is
  15615. /// constructed, this state tracking was rendered useless,
  15616. /// as the only skill unit, that is sent with 0x1c9 is
  15617. /// Graffiti.
  15618. void clif_parse_LessEffect(int fd, map_session_data* sd){
  15619. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15620. sd->state.lesseffect = ( isLess != 0 );
  15621. }
  15622. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15623. void clif_parse_ItemListWindowSelected(int fd, map_session_data* sd) {
  15624. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15625. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15626. int type = RFIFOL(fd,info->pos[1]);
  15627. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15628. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15629. if( sd->state.trading || sd->npc_shopid )
  15630. return;
  15631. if( flag == 0 || n == 0) {
  15632. clif_menuskill_clear(sd);
  15633. return; // Canceled by player.
  15634. }
  15635. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15636. clif_menuskill_clear(sd);
  15637. return; // Prevent hacking.
  15638. }
  15639. switch( type ) {
  15640. case 0: // Change Material
  15641. skill_changematerial(sd,n,item_list);
  15642. break;
  15643. case 1: // Level 1: Pure to Rough
  15644. case 2: // Level 2: Rough to Pure
  15645. skill_elementalanalysis(sd,n,type,item_list);
  15646. break;
  15647. }
  15648. clif_menuskill_clear(sd);
  15649. return;
  15650. }
  15651. /*==========================================
  15652. * Elemental System
  15653. *==========================================*/
  15654. void clif_elemental_updatestatus(map_session_data *sd, int type) {
  15655. s_elemental_data *ed;
  15656. struct status_data *status;
  15657. int fd;
  15658. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15659. return;
  15660. fd = sd->fd;
  15661. status = &ed->battle_status;
  15662. WFIFOHEAD(fd,8);
  15663. WFIFOW(fd,0) = 0x81e;
  15664. WFIFOW(fd,2) = type;
  15665. switch( type ) {
  15666. case SP_HP:
  15667. WFIFOL(fd,4) = status->hp;
  15668. break;
  15669. case SP_MAXHP:
  15670. WFIFOL(fd,4) = status->max_hp;
  15671. break;
  15672. case SP_SP:
  15673. WFIFOL(fd,4) = status->sp;
  15674. break;
  15675. case SP_MAXSP:
  15676. WFIFOL(fd,4) = status->max_sp;
  15677. break;
  15678. }
  15679. WFIFOSET(fd,8);
  15680. }
  15681. void clif_elemental_info(map_session_data *sd) {
  15682. int fd;
  15683. s_elemental_data *ed;
  15684. struct status_data *status;
  15685. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15686. return;
  15687. fd = sd->fd;
  15688. status = &ed->battle_status;
  15689. WFIFOHEAD(fd,22);
  15690. WFIFOW(fd, 0) = 0x81d;
  15691. WFIFOL(fd, 2) = ed->bl.id;
  15692. WFIFOL(fd, 6) = status->hp;
  15693. WFIFOL(fd,10) = status->max_hp;
  15694. WFIFOL(fd,14) = status->sp;
  15695. WFIFOL(fd,18) = status->max_sp;
  15696. WFIFOSET(fd,22);
  15697. }
  15698. /// Buying Store System
  15699. ///
  15700. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15701. /// 0810 <slots>.B
  15702. void clif_buyingstore_open(map_session_data* sd)
  15703. {
  15704. int fd = sd->fd;
  15705. WFIFOHEAD(fd,packet_len(0x810));
  15706. WFIFOW(fd,0) = 0x810;
  15707. WFIFOB(fd,2) = sd->buyingstore.slots;
  15708. WFIFOSET(fd,packet_len(0x810));
  15709. }
  15710. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15711. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15712. /// result:
  15713. /// 0 = cancel
  15714. /// 1 = open
  15715. static void clif_parse_ReqOpenBuyingStore( int fd, map_session_data* sd ){
  15716. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15717. // TODO: Make this check global for all variable length packets.
  15718. // minimum packet length
  15719. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15720. 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 );
  15721. return;
  15722. }
  15723. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15724. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15725. return;
  15726. }
  15727. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15728. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15729. return;
  15730. }
  15731. char storename[MESSAGE_SIZE];
  15732. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15733. // so that buyingstore_create knows, how many elements it has access to
  15734. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15735. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15736. 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 ) );
  15737. return;
  15738. }
  15739. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15740. }
  15741. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15742. /// 0812 <result>.W <total weight>.L
  15743. /// result:
  15744. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15745. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15746. /// 8 = "No sale (purchase) information available." (0x705)
  15747. /// ? = nothing
  15748. void clif_buyingstore_open_failed(map_session_data* sd, unsigned short result, unsigned int weight)
  15749. {
  15750. int fd = sd->fd;
  15751. WFIFOHEAD(fd,packet_len(0x812));
  15752. WFIFOW(fd,0) = 0x812;
  15753. WFIFOW(fd,2) = result;
  15754. WFIFOL(fd,4) = weight;
  15755. WFIFOSET(fd,packet_len(0x812));
  15756. }
  15757. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15758. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15759. void clif_buyingstore_myitemlist( map_session_data* sd ){
  15760. nullpo_retv( sd );
  15761. int fd = sd->fd;
  15762. if( !session_isActive( fd ) ){
  15763. return;
  15764. }
  15765. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15766. WFIFOHEAD( fd, length );
  15767. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15768. p->packetType = 0x813;
  15769. p->packetLength = length;
  15770. p->AID = sd->bl.id;
  15771. p->zenyLimit = sd->buyingstore.zenylimit;
  15772. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15773. p->items[i].price = sd->buyingstore.items[i].price;
  15774. p->items[i].amount = sd->buyingstore.items[i].amount;
  15775. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15776. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15777. }
  15778. WFIFOSET( fd, p->packetLength );
  15779. }
  15780. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15781. /// 0814 <account id>.L <store name>.80B
  15782. void clif_buyingstore_entry( map_session_data& sd, struct block_list* tbl ){
  15783. #if PACKETVER >= 20100420
  15784. enum send_target target;
  15785. if( tbl == nullptr ){
  15786. tbl = &sd.bl;
  15787. target = AREA_WOS;
  15788. }else{
  15789. target = SELF;
  15790. }
  15791. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15792. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15793. p.makerAID = sd.status.account_id;
  15794. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15795. clif_send( &p, sizeof( p ), tbl, target );
  15796. #endif
  15797. }
  15798. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15799. /// 0815
  15800. static void clif_parse_ReqCloseBuyingStore(int fd, map_session_data* sd)
  15801. {
  15802. buyingstore_close(sd);
  15803. }
  15804. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15805. /// 0816 <account id>.L
  15806. void clif_buyingstore_disappear_entry( map_session_data& sd, struct block_list* tbl ){
  15807. #if PACKETVER >= 20100309
  15808. enum send_target target;
  15809. if( tbl == nullptr ){
  15810. tbl = &sd.bl;
  15811. target = AREA_WOS;
  15812. }else{
  15813. target = SELF;
  15814. }
  15815. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15816. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15817. p.makerAID = sd.status.account_id;
  15818. clif_send( &p, sizeof( p ), tbl, target );
  15819. #endif
  15820. }
  15821. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15822. /// 0817 <account id>.L
  15823. static void clif_parse_ReqClickBuyingStore(int fd, map_session_data* sd)
  15824. {
  15825. uint32 account_id;
  15826. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15827. buyingstore_open(sd, account_id);
  15828. }
  15829. /// Sends buying store item list.
  15830. /// 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)
  15831. void clif_buyingstore_itemlist( map_session_data* sd, map_session_data* pl_sd ){
  15832. nullpo_retv( sd );
  15833. nullpo_retv( pl_sd );
  15834. int fd = sd->fd;
  15835. if( !session_isActive( fd ) ){
  15836. return;
  15837. }
  15838. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15839. WFIFOHEAD( fd, length );
  15840. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15841. p->packetType = 0x818;
  15842. p->packetLength = length;
  15843. p->AID = pl_sd->bl.id;
  15844. p->storeId = pl_sd->buyer_id;
  15845. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15846. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15847. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15848. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15849. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15850. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15851. }
  15852. WFIFOSET( fd, p->packetLength );
  15853. }
  15854. /// Request to sell items to a buying store.
  15855. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15856. static void clif_parse_ReqTradeBuyingStore( int fd, map_session_data* sd ){
  15857. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15858. // minimum packet length
  15859. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15860. 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 );
  15861. return;
  15862. }
  15863. // so that buyingstore_trade knows, how many elements it has access to
  15864. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15865. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15866. 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 ) );
  15867. return;
  15868. }
  15869. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15870. }
  15871. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15872. /// 081a <result>.W
  15873. /// result:
  15874. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15875. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15876. /// ? = nothing
  15877. void clif_buyingstore_trade_failed_buyer(map_session_data* sd, short result)
  15878. {
  15879. int fd = sd->fd;
  15880. WFIFOHEAD(fd,packet_len(0x81a));
  15881. WFIFOW(fd,0) = 0x81a;
  15882. WFIFOW(fd,2) = result;
  15883. WFIFOSET(fd,packet_len(0x81a));
  15884. }
  15885. /// Updates the zeny limit and an item in the buying store item list.
  15886. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15887. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15888. void clif_buyingstore_update_item( map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15889. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15890. p.packetType = buyingStoreUpdateItemType;
  15891. p.itemId = client_nameid( nameid );
  15892. p.amount = amount;
  15893. p.zenyLimit = sd->buyingstore.zenylimit;
  15894. #if PACKETVER >= 20141016
  15895. p.zeny = zeny;
  15896. p.charId = char_id; // GID
  15897. p.updateTime = (int)time(NULL);
  15898. #endif
  15899. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15900. }
  15901. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15902. /// 081c <index>.W <amount>.W <price>.L
  15903. /// message:
  15904. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15905. ///
  15906. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15907. void clif_buyingstore_delete_item(map_session_data* sd, short index, unsigned short amount, int price)
  15908. {
  15909. int fd = sd->fd;
  15910. WFIFOHEAD(fd,packet_len(0x81c));
  15911. WFIFOW(fd,0) = 0x81c;
  15912. WFIFOW(fd,2) = client_index( index );
  15913. WFIFOW(fd,4) = amount;
  15914. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15915. WFIFOSET(fd,packet_len(0x81c));
  15916. }
  15917. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15918. /// 0824 <result>.W <name id>.W
  15919. /// result:
  15920. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15921. /// 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)
  15922. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15923. /// ? = nothing
  15924. void clif_buyingstore_trade_failed_seller( map_session_data* sd, short result, t_itemid nameid ){
  15925. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15926. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15927. p.result = result;
  15928. p.itemId = client_nameid( nameid );
  15929. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15930. }
  15931. /// Search Store Info System
  15932. ///
  15933. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15934. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15935. /// type:
  15936. /// 0 = Vending
  15937. /// 1 = Buying Store
  15938. ///
  15939. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15940. /// amount of card slots. If the client does not know about the item it
  15941. /// cannot be searched.
  15942. static void clif_parse_SearchStoreInfo( int fd, map_session_data *sd ){
  15943. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15944. // minimum packet length
  15945. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15946. 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 );
  15947. return;
  15948. }
  15949. // check, if there is enough data for the claimed count of items
  15950. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15951. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15952. 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 ) );
  15953. return;
  15954. }
  15955. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15956. if( count < p->itemsCount + p->cardsCount ){
  15957. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15958. return;
  15959. }
  15960. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15961. }
  15962. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15963. /// 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 }*
  15964. /// is first page:
  15965. /// 0 = appends to existing results
  15966. /// 1 = clears previous results before displaying this result set
  15967. /// is next page:
  15968. /// 0 = no "next" label
  15969. /// 1 = "next" label to retrieve more results
  15970. void clif_search_store_info_ack( map_session_data* sd ){
  15971. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  15972. nullpo_retv( sd );
  15973. int fd = sd->fd;
  15974. if( !session_isActive( fd ) ){
  15975. return;
  15976. }
  15977. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15978. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  15979. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15980. WFIFOHEAD( fd, len );
  15981. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15982. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15983. p->packetLength = len;
  15984. p->firstPage = !sd->searchstore.pages;
  15985. p->nextPage = searchstore_querynext( sd );
  15986. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15987. for( int i = 0; i < end - start; i++ ) {
  15988. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  15989. p->items[i].storeId = ssitem->store_id;
  15990. p->items[i].AID = ssitem->account_id;
  15991. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15992. p->items[i].itemId = client_nameid( ssitem->nameid );
  15993. p->items[i].itemType = itemtype( ssitem->nameid );
  15994. p->items[i].price = ssitem->price;
  15995. p->items[i].amount = ssitem->amount;
  15996. p->items[i].refine = ssitem->refine;
  15997. // make-up an item for clif_addcards
  15998. struct item it = {};
  15999. for( int j = 0; j < MAX_SLOTS; j++ ){
  16000. it.card[j] = ssitem->card[j];
  16001. }
  16002. it.nameid = ssitem->nameid;
  16003. it.amount = ssitem->amount;
  16004. clif_addcards( &p->items[i].slot, &it );
  16005. #if PACKETVER >= 20150226
  16006. clif_add_random_options( p->items[i].option_data, it );
  16007. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16008. p->items[i].grade = ssitem->enchantgrade;
  16009. #endif
  16010. #endif
  16011. }
  16012. WFIFOSET( fd, len );
  16013. #endif
  16014. }
  16015. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16016. /// 0837 <reason>.B
  16017. /// reason:
  16018. /// 0 = "No matching stores were found." (0x70b)
  16019. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16020. /// 2 = "You cannot search anymore." (0x706)
  16021. /// 3 = "You cannot search yet." (0x708)
  16022. /// 4 = "No sale (purchase) information available." (0x705)
  16023. void clif_search_store_info_failed(map_session_data* sd, unsigned char reason)
  16024. {
  16025. int fd = sd->fd;
  16026. WFIFOHEAD(fd,packet_len(0x837));
  16027. WFIFOW(fd,0) = 0x837;
  16028. WFIFOB(fd,2) = reason;
  16029. WFIFOSET(fd,packet_len(0x837));
  16030. }
  16031. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16032. /// 0838
  16033. static void clif_parse_SearchStoreInfoNextPage(int fd, map_session_data* sd)
  16034. {
  16035. searchstore_next(sd);
  16036. }
  16037. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16038. /// 083a <type>.W <remaining uses>.B
  16039. /// type:
  16040. /// 0 = Search Stores
  16041. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16042. void clif_open_search_store_info(map_session_data* sd)
  16043. {
  16044. int fd = sd->fd;
  16045. WFIFOHEAD(fd,packet_len(0x83a));
  16046. WFIFOW(fd,0) = 0x83a;
  16047. WFIFOW(fd,2) = sd->searchstore.effect;
  16048. #if PACKETVER > 20100701
  16049. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16050. #endif
  16051. WFIFOSET(fd,packet_len(0x83a));
  16052. }
  16053. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16054. /// 083b
  16055. static void clif_parse_CloseSearchStoreInfo(int fd, map_session_data* sd)
  16056. {
  16057. searchstore_close(sd);
  16058. }
  16059. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16060. /// 083c <account id>.L <store id>.L <nameid>.W
  16061. static void clif_parse_SearchStoreInfoListItemClick( int fd, map_session_data* sd ){
  16062. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16063. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16064. }
  16065. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16066. /// 083d <xPos>.W <yPos>.W
  16067. void clif_search_store_info_click_ack(map_session_data* sd, short x, short y)
  16068. {
  16069. int fd = sd->fd;
  16070. WFIFOHEAD(fd,packet_len(0x83d));
  16071. WFIFOW(fd,0) = 0x83d;
  16072. WFIFOW(fd,2) = x;
  16073. WFIFOW(fd,4) = y;
  16074. WFIFOSET(fd,packet_len(0x83d));
  16075. }
  16076. /// Parse function for packet debugging.
  16077. void clif_parse_debug(int fd,map_session_data *sd)
  16078. {
  16079. int cmd, packet_len;
  16080. // clif_parse ensures, that there is at least 2 bytes of data
  16081. cmd = RFIFOW(fd,0);
  16082. if( sd ) {
  16083. packet_len = packet_db[cmd].len;
  16084. if( packet_len == 0 )
  16085. {// unknown
  16086. packet_len = RFIFOREST(fd);
  16087. }
  16088. else if( packet_len == -1 )
  16089. {// variable length
  16090. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16091. }
  16092. 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);
  16093. }
  16094. else
  16095. {
  16096. packet_len = RFIFOREST(fd);
  16097. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16098. }
  16099. ShowDump(RFIFOP(fd,0), packet_len);
  16100. }
  16101. /*==========================================
  16102. * Server tells client to display a window similar to Magnifier (item) one
  16103. * Server populates the window with avilable elemental converter options according to player's inventory
  16104. *------------------------------------------*/
  16105. void clif_elementalconverter_list( map_session_data *sd ){
  16106. nullpo_retv( sd );
  16107. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16108. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16109. int count = 0;
  16110. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16111. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16112. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16113. count++;
  16114. }
  16115. }
  16116. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16117. clif_send( p, p->packetLength, &sd->bl, SELF );
  16118. if( count > 0 ){
  16119. sd->menuskill_id = SA_CREATECON;
  16120. sd->menuskill_val = count;
  16121. }
  16122. }
  16123. /**
  16124. * Rune Knight
  16125. **/
  16126. void clif_millenniumshield(struct block_list *bl, short shields) {
  16127. #if PACKETVER >= 20081217
  16128. unsigned char buf[10];
  16129. WBUFW(buf,0) = 0x440;
  16130. WBUFL(buf,2) = bl->id;
  16131. WBUFW(buf,6) = shields;
  16132. WBUFW(buf,8) = 0;
  16133. clif_send(buf,packet_len(0x440),bl,AREA);
  16134. #endif
  16135. }
  16136. /**
  16137. * Mechanic
  16138. **/
  16139. /*==========================================
  16140. * Magic Decoy Material List
  16141. *------------------------------------------*/
  16142. void clif_magicdecoy_list( map_session_data *sd, uint16 skill_lv, short x, short y ){
  16143. nullpo_retv( sd );
  16144. int fd = sd->fd;
  16145. if( !session_isActive( fd ) ){
  16146. return;
  16147. }
  16148. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16149. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16150. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16151. int count = 0;
  16152. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16153. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16154. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16155. count++;
  16156. }
  16157. }
  16158. if( count > 0 ) {
  16159. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16160. WFIFOSET( fd, p->packetLength );
  16161. sd->menuskill_id = NC_MAGICDECOY;
  16162. sd->menuskill_val = skill_lv;
  16163. sd->sc.comet_x = x;
  16164. sd->sc.comet_y = y;
  16165. }else{
  16166. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16167. }
  16168. }
  16169. /*==========================================
  16170. * Guillotine Cross Poisons List
  16171. *------------------------------------------*/
  16172. void clif_poison_list( map_session_data *sd, uint16 skill_lv ){
  16173. nullpo_retv( sd );
  16174. int fd = sd->fd;
  16175. if( !session_isActive( fd ) ){
  16176. return;
  16177. }
  16178. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16179. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16180. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16181. int count = 0;
  16182. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16183. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16184. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16185. count++;
  16186. }
  16187. }
  16188. if( count > 0 ){
  16189. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16190. WFIFOSET( fd, p->packetLength );
  16191. sd->menuskill_id = GC_POISONINGWEAPON;
  16192. sd->menuskill_val = skill_lv;
  16193. }else{
  16194. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16195. }
  16196. }
  16197. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16198. int clif_autoshadowspell_list(map_session_data *sd) {
  16199. int fd, i, c;
  16200. nullpo_ret(sd);
  16201. fd = sd->fd;
  16202. if( !session_isActive(fd) )
  16203. return 0;
  16204. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16205. return 0;
  16206. WFIFOHEAD(fd, 2 * 6 + 4);
  16207. WFIFOW(fd,0) = 0x442;
  16208. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16209. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16210. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16211. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16212. {
  16213. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16214. c++;
  16215. }
  16216. if( c > 0 ) {
  16217. WFIFOW(fd,2) = 8 + c * 2;
  16218. WFIFOL(fd,4) = c;
  16219. WFIFOSET(fd,WFIFOW(fd,2));
  16220. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16221. sd->menuskill_val = c;
  16222. } else {
  16223. status_change_end(&sd->bl,SC_STOP);
  16224. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16225. }
  16226. return 1;
  16227. }
  16228. /*===========================================
  16229. * Skill list for Four Elemental Analysis
  16230. * and Change Material skills.
  16231. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16232. *------------------------------------------*/
  16233. int clif_skill_itemlistwindow( map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16234. #if PACKETVER >= 20090922
  16235. int fd = sd->fd;
  16236. nullpo_ret(sd);
  16237. sd->menuskill_id = skill_id; // To prevent hacking.
  16238. sd->menuskill_val = skill_lv;
  16239. if( skill_id == GN_CHANGEMATERIAL )
  16240. skill_lv = 0; // Changematerial
  16241. WFIFOHEAD(fd, packet_len(0x7e3));
  16242. WFIFOW(fd,0) = 0x7e3;
  16243. WFIFOL(fd,2) = skill_lv;
  16244. WFIFOL(fd,4) = 0;
  16245. WFIFOSET(fd, packet_len(0x7e3));
  16246. #endif
  16247. return 1;
  16248. }
  16249. /*==========================================
  16250. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16251. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16252. * RFIFOL(fd,2) - type (currently not used)
  16253. *------------------------------------------*/
  16254. void clif_parse_SkillSelectMenu(int fd, map_session_data *sd) {
  16255. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16256. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16257. if (sd->menuskill_id == SA_AUTOSPELL) {
  16258. sd->state.workinprogress = WIP_DISABLE_NONE;
  16259. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16260. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16261. if (pc_istrading(sd)) {
  16262. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16263. clif_menuskill_clear(sd);
  16264. return;
  16265. }
  16266. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16267. } else
  16268. return;
  16269. clif_menuskill_clear(sd);
  16270. }
  16271. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16272. /// 08cf <id>.L <type>.W <num>.W
  16273. void clif_spiritcharm(map_session_data *sd) {
  16274. unsigned char buf[10];
  16275. nullpo_retv(sd);
  16276. WBUFW(buf,0) = 0x08cf;
  16277. WBUFL(buf,2) = sd->bl.id;
  16278. WBUFW(buf,6) = sd->spiritcharm_type;
  16279. WBUFW(buf,8) = sd->spiritcharm;
  16280. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16281. }
  16282. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16283. /// 0907 <index>.W
  16284. ///
  16285. /// R 0908 <index>.w <type>.b
  16286. /// type:
  16287. /// 0 = move item to personal tab
  16288. /// 1 = move item to normal tab
  16289. void clif_parse_MoveItem(int fd, map_session_data *sd) {
  16290. #if PACKETVER >= 20111122
  16291. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16292. int index = RFIFOW(fd,info->pos[0]) - 2;
  16293. int type = RFIFOB(fd, info->pos[1]);
  16294. /* can't move while dead. */
  16295. if(pc_isdead(sd)) {
  16296. return;
  16297. }
  16298. if (index < 0 || index >= MAX_INVENTORY)
  16299. return;
  16300. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16301. sd->inventory.u.items_inventory[index].favorite = 0;
  16302. else if( type == 0 )
  16303. sd->inventory.u.items_inventory[index].favorite = 1;
  16304. else
  16305. return;/* nothing to do. */
  16306. clif_favorite_item(sd, index);
  16307. #endif
  16308. }
  16309. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16310. /// 0900 <index>.W <favorite>.B
  16311. void clif_favorite_item(map_session_data* sd, unsigned short index) {
  16312. int fd = sd->fd;
  16313. WFIFOHEAD(fd,packet_len(0x908));
  16314. WFIFOW(fd,0) = 0x908;
  16315. WFIFOW(fd,2) = index+2;
  16316. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16317. WFIFOSET(fd,packet_len(0x908));
  16318. }
  16319. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16320. void clif_snap( struct block_list *bl, short x, short y ) {
  16321. unsigned char buf[10];
  16322. WBUFW(buf,0) = 0x8d2;
  16323. WBUFL(buf,2) = bl->id;
  16324. WBUFW(buf,6) = x;
  16325. WBUFW(buf,8) = y;
  16326. if( disguised(bl) )
  16327. {
  16328. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16329. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16330. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16331. } else
  16332. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16333. }
  16334. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16335. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16336. #if PACKETVER >= 20120404
  16337. WFIFOHEAD(fd,packet_len(0x977));
  16338. WFIFOW(fd,0) = 0x977;
  16339. WFIFOL(fd,2) = md->bl.id;
  16340. WFIFOL(fd,6) = md->status.hp;
  16341. WFIFOL(fd,10) = md->status.max_hp;
  16342. WFIFOSET(fd,packet_len(0x977));
  16343. #endif
  16344. }
  16345. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16346. void __attribute__ ((unused)) clif_parse_dull(int fd, map_session_data *sd) {
  16347. return;
  16348. }
  16349. void clif_partytickack(map_session_data* sd, bool flag) {
  16350. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16351. WFIFOW(sd->fd,0) = 0x2c9;
  16352. WFIFOB(sd->fd,2) = flag;
  16353. WFIFOSET(sd->fd, packet_len(0x2c9));
  16354. }
  16355. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16356. /// 0979 <world name>.24B <char name>.24B
  16357. void clif_ackworldinfo(map_session_data* sd) {
  16358. int fd;
  16359. nullpo_retv(sd);
  16360. fd = sd->fd;
  16361. WFIFOHEAD(fd,packet_len(0x979));
  16362. WFIFOW(fd,0)=0x979;
  16363. //AID -> world name ?
  16364. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16365. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16366. WFIFOSET(fd,packet_len(0x979));
  16367. }
  16368. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16369. /// 0978 <AID>.L
  16370. void clif_parse_reqworldinfo(int fd,map_session_data *sd) {
  16371. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16372. if(sd)
  16373. clif_ackworldinfo(sd);
  16374. }
  16375. static void clif_loadConfirm( map_session_data *sd ){
  16376. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16377. nullpo_retv( sd );
  16378. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16379. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16380. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16381. clif_instance_info( *sd );
  16382. #endif
  16383. }
  16384. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16385. /// 0447
  16386. void clif_parse_blocking_playcancel( int fd, map_session_data *sd ){
  16387. clif_loadConfirm( sd );
  16388. }
  16389. /// req world info (CZ_CLIENT_VERSION)
  16390. /// 044A <version>.L
  16391. void clif_parse_client_version(int fd, map_session_data *sd) {
  16392. //if(sd)
  16393. ;
  16394. }
  16395. /// Ranking list
  16396. /// ranking pointlist { <name>.24B <point>.L }*10
  16397. void clif_sub_ranklist(unsigned char *buf,int idx,map_session_data* sd, enum e_rank rankingtype){
  16398. struct fame_list* list;
  16399. int i, size = MAX_FAME_LIST;
  16400. switch(rankingtype) {
  16401. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16402. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16403. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16404. // PK currently unsupported
  16405. case RANK_KILLER: list = NULL; size = 0; break;
  16406. default:
  16407. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16408. return;
  16409. }
  16410. //Packet size limits this list to 10 elements. [Skotlex]
  16411. for (i = 0; i < min(10,size); i++) {
  16412. if (list[i].id > 0) {
  16413. const char* name;
  16414. if (strcmp(list[i].name, "-") == 0 &&
  16415. (name = map_charid2nick(list[i].id)) != NULL)
  16416. {
  16417. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16418. } else {
  16419. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16420. }
  16421. } else {
  16422. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16423. }
  16424. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16425. }
  16426. for(;i < 10; i++) { //In case the MAX is less than 10.
  16427. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16428. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16429. }
  16430. }
  16431. /// Request for the blacksmith ranklist.
  16432. /// /blacksmith command sends this packet to the server.
  16433. /// 0217 (CZ_BLACKSMITH_RANK)
  16434. void clif_parse_Blacksmith( int fd, map_session_data *sd ){
  16435. clif_ranklist(sd,RANK_BLACKSMITH);
  16436. }
  16437. /// Request for the alchemist ranklist.
  16438. /// /alchemist command sends this packet to the server.
  16439. /// 0218 (CZ_ALCHEMIST_RANK)
  16440. void clif_parse_Alchemist( int fd, map_session_data *sd ){
  16441. clif_ranklist(sd,RANK_ALCHEMIST);
  16442. }
  16443. /// Request for the taekwon ranklist.
  16444. /// /taekwon command sends this packet to the server.
  16445. /// 0225 (CZ_TAEKWON_RANK)
  16446. void clif_parse_Taekwon( int fd, map_session_data *sd ){
  16447. clif_ranklist(sd,RANK_TAEKWON);
  16448. }
  16449. /// Request for the killer ranklist.
  16450. /// /pk command sends this packet to the server.
  16451. /// 0237 (CZ_KILLER_RANK)
  16452. void clif_parse_RankingPk( int fd, map_session_data *sd ){
  16453. clif_ranklist(sd,RANK_KILLER);
  16454. }
  16455. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16456. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16457. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16458. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16459. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16460. void clif_ranklist(map_session_data *sd, int16 rankingType) {
  16461. enum e_rank rank;
  16462. #if PACKETVER < 20130710
  16463. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16464. short cmd;
  16465. switch( rankingType ){
  16466. case RANK_BLACKSMITH: cmd = 0x219; break;
  16467. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16468. case RANK_TAEKWON: cmd = 0x226; break;
  16469. case RANK_KILLER: cmd = 0x238; break;
  16470. default:
  16471. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16472. return;
  16473. }
  16474. // Can be safely casted here, since we validated it before
  16475. rank = (enum e_rank)rankingType;
  16476. WBUFW(buf,0) = cmd;
  16477. clif_sub_ranklist(buf,2,sd,rank);
  16478. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16479. #else
  16480. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16481. int mypoint = 0;
  16482. switch( rankingType ){
  16483. case RANK_BLACKSMITH:
  16484. case RANK_ALCHEMIST:
  16485. case RANK_TAEKWON:
  16486. case RANK_KILLER:
  16487. break;
  16488. default:
  16489. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16490. return;
  16491. }
  16492. // Can be safely casted here, since we validated it before
  16493. rank = (enum e_rank)rankingType;
  16494. WBUFW(buf,0) = 0x97d;
  16495. WBUFW(buf,2) = rank;
  16496. clif_sub_ranklist(buf,4,sd,rank);
  16497. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16498. case MAPID_BLACKSMITH:
  16499. case MAPID_ALCHEMIST:
  16500. case MAPID_TAEKWON:
  16501. mypoint = sd->status.fame;
  16502. }
  16503. WBUFL(buf,284) = mypoint; //mypoint
  16504. clif_send(buf, 288, &sd->bl, SELF);
  16505. #endif
  16506. }
  16507. /*
  16508. * 097c <type> (CZ_REQ_RANKING)
  16509. * type
  16510. * 0: /blacksmith
  16511. * 1: /alchemist
  16512. * 2: /taekwon
  16513. * 3: /pk
  16514. * */
  16515. void clif_parse_ranklist(int fd,map_session_data *sd) {
  16516. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16517. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16518. clif_ranklist(sd,rankingtype);
  16519. }
  16520. /// Updates the fame rank points for the given ranking.
  16521. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16522. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16523. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16524. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16525. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16526. int fd = sd.fd;
  16527. #if PACKETVER < 20130710
  16528. short cmd;
  16529. switch(rankingtype){
  16530. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16531. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16532. case RANK_TAEKWON: cmd = 0x224; break;
  16533. default:
  16534. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16535. return;
  16536. }
  16537. WFIFOHEAD(fd,packet_len(cmd));
  16538. WFIFOW(fd,0) = cmd;
  16539. WFIFOL(fd,2) = point;
  16540. WFIFOL(fd,6) = sd.status.fame;
  16541. WFIFOSET(fd, packet_len(cmd));
  16542. #else
  16543. WFIFOHEAD(fd,packet_len(0x97e));
  16544. WFIFOW(fd,0) = 0x97e;
  16545. WFIFOW(fd,2) = rankingtype;
  16546. WFIFOL(fd,4) = point;
  16547. WFIFOL(fd,8) = sd.status.fame;
  16548. WFIFOSET(fd,packet_len(0x97e));
  16549. #endif
  16550. }
  16551. /**
  16552. * Transmit personal information to player. (rates)
  16553. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16554. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16555. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16556. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16557. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16558. * FIXME!
  16559. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16560. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16561. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16562. */
  16563. #ifdef VIP_ENABLE
  16564. void clif_display_pinfo( map_session_data& sd ){
  16565. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16566. // 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]
  16567. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16568. /**
  16569. * EXP
  16570. */
  16571. //0:PCRoom
  16572. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16573. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16574. details_bexp[PINFO_BASIC] = 0;
  16575. else {
  16576. if (details_bexp[PINFO_BASIC] < 100) {
  16577. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16578. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16579. } else
  16580. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16581. }
  16582. //1:Premium
  16583. if( pc_isvip( &sd ) ){
  16584. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16585. if (details_bexp[PINFO_PREMIUM] < 0)
  16586. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16587. } else
  16588. details_bexp[PINFO_PREMIUM] = 0;
  16589. //2:Server
  16590. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16591. if (details_bexp[PINFO_SERVER] == 100)
  16592. details_bexp[PINFO_SERVER] = 0;
  16593. else {
  16594. if (details_bexp[PINFO_SERVER] < 100) {
  16595. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16596. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16597. } else
  16598. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16599. }
  16600. //3:TPLUS
  16601. details_bexp[PINFO_CAFE] = 0;
  16602. /**
  16603. * Drop rate
  16604. */
  16605. //0:PCRoom
  16606. details_drop[PINFO_BASIC] = 0;
  16607. //1:Premium
  16608. if( pc_isvip( &sd ) ){
  16609. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16610. if (details_drop[PINFO_PREMIUM] < 0)
  16611. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16612. } else
  16613. details_drop[PINFO_PREMIUM] = 0;
  16614. //2:Server
  16615. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16616. if (details_drop[PINFO_SERVER] == 100)
  16617. details_drop[PINFO_SERVER] = 0;
  16618. else {
  16619. if (details_drop[PINFO_SERVER] < 100) {
  16620. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16621. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16622. } else
  16623. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16624. }
  16625. //3:TPLUS
  16626. details_drop[PINFO_CAFE] = 0;
  16627. /**
  16628. * Penalty rate
  16629. */
  16630. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16631. //0:PCRoom
  16632. details_penalty[PINFO_BASIC] = 0;
  16633. //1:Premium
  16634. if( pc_isvip( &sd ) ){
  16635. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16636. if (details_penalty[PINFO_PREMIUM] == 100)
  16637. details_penalty[PINFO_PREMIUM] = 0;
  16638. else {
  16639. if (details_penalty[PINFO_PREMIUM] < 100) {
  16640. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16641. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16642. } else
  16643. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16644. }
  16645. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16646. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16647. } else
  16648. details_penalty[PINFO_PREMIUM] = 0;
  16649. //2:Server
  16650. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16651. if (details_penalty[PINFO_SERVER] == 100)
  16652. details_penalty[PINFO_SERVER] = 0;
  16653. else {
  16654. if (details_penalty[PINFO_SERVER] < 100) {
  16655. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16656. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16657. } else
  16658. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16659. }
  16660. //3:TPLUS
  16661. details_penalty[PINFO_CAFE] = 0;
  16662. struct PACKET_ZC_PERSONAL_INFOMATION* p = (struct PACKET_ZC_PERSONAL_INFOMATION*)packet_buffer;
  16663. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16664. p->length = sizeof( *p ) + PINFO_MAX * sizeof( p->details[0] );
  16665. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16666. p->total_exp = 100 * 1000;
  16667. p->total_death = 100 * 1000;
  16668. p->total_drop = 100 * 1000;
  16669. #else
  16670. p->total_exp = 100;
  16671. p->total_death = 100;
  16672. p->total_drop = 100;
  16673. #endif
  16674. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16675. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16676. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16677. p->details[i].exp = details_bexp[i] * 1000;
  16678. p->details[i].death = details_penalty[i] * 1000;
  16679. p->details[i].drop = details_drop[i] * 1000;
  16680. #else
  16681. p->details[i].exp = details_bexp[i];
  16682. p->details[i].death = details_penalty[i];
  16683. p->details[i].drop = details_drop[i];
  16684. #endif
  16685. p->total_exp += p->details[i].exp;
  16686. p->total_death += p->details[i].death;
  16687. p->total_drop += p->details[i].drop;
  16688. }
  16689. clif_send( p, p->length, &sd.bl, SELF );
  16690. #endif
  16691. }
  16692. #endif
  16693. void clif_parse_GMFullStrip(int fd, map_session_data *sd) {
  16694. char cmd[30];
  16695. int t_aid = RFIFOL(fd,2);
  16696. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16697. is_atcommand(fd, sd, cmd, 1);
  16698. }
  16699. /**
  16700. * Marks Crimson Marker target on mini-map to the caster
  16701. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16702. * @param fd
  16703. * @param bl Crimson Marker target
  16704. **/
  16705. void clif_crimson_marker( map_session_data& sd, struct block_list& bl, bool remove ){
  16706. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16707. struct PACKET_ZC_C_MARKERINFO p = {};
  16708. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16709. p.AID = bl.id;
  16710. if( remove ){
  16711. p.xPos = -1;
  16712. p.yPos = -1;
  16713. }else{
  16714. p.xPos = bl.x;
  16715. p.yPos = bl.y;
  16716. }
  16717. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16718. #endif
  16719. }
  16720. /**
  16721. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16722. **/
  16723. void clif_notify_bindOnEquip( map_session_data& sd, int16 index ){
  16724. #if PACKETVER >= 20070227
  16725. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16726. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16727. p.index = client_index( index );
  16728. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16729. #endif
  16730. }
  16731. /**
  16732. * [Ind/Hercules]
  16733. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16734. **/
  16735. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16736. char buf[256];
  16737. size_t len;
  16738. nullpo_retv(bl);
  16739. if(!message)
  16740. return;
  16741. len = strlen(message)+1;
  16742. if( len > sizeof(buf)-8 ) {
  16743. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16744. len = sizeof(buf)-8;
  16745. }
  16746. WBUFW(buf,0) = 0x8b3;
  16747. WBUFW(buf,2) = (uint16)(len+8);
  16748. WBUFL(buf,4) = bl->id;
  16749. safestrncpy(WBUFCP(buf,8), message, len);
  16750. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16751. }
  16752. /**
  16753. * [Ind/Hercules]
  16754. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16755. **/
  16756. void clif_party_leaderchanged(map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16757. unsigned char buf[10];
  16758. nullpo_retv(sd);
  16759. WBUFW(buf,0) = 0x7fc;
  16760. WBUFL(buf,2) = prev_leader_aid;
  16761. WBUFL(buf,6) = new_leader_aid;
  16762. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16763. }
  16764. /**
  16765. * Sends a clan message to a player
  16766. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16767. **/
  16768. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16769. #if PACKETVER >= 20131223
  16770. map_session_data *sd;
  16771. uint8 buf[256];
  16772. if( len == 0 ){
  16773. return;
  16774. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16775. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16776. len = sizeof(buf)-5-NAME_LENGTH;
  16777. }
  16778. WBUFW(buf, 0) = 0x98e;
  16779. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16780. // 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
  16781. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16782. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16783. if((sd = clan_getavailablesd(clan)) != NULL)
  16784. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16785. #endif
  16786. }
  16787. /**
  16788. * Parses a clan message from a player.
  16789. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16790. **/
  16791. void clif_parse_clan_chat( int fd, map_session_data* sd ){
  16792. #if PACKETVER >= 20131223
  16793. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16794. // validate packet and retrieve name and message
  16795. if( !clif_process_message(sd, false, name, message, output ) )
  16796. return;
  16797. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16798. #endif
  16799. }
  16800. /**
  16801. * Sends the basic clan informations to the client.
  16802. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16803. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16804. **/
  16805. void clif_clan_basicinfo( map_session_data *sd ){
  16806. #if PACKETVER >= 20131223
  16807. int fd, offset, length, i, flag;
  16808. struct clan* clan;
  16809. char mapname[MAP_NAME_LENGTH_EXT];
  16810. nullpo_retv( sd );
  16811. nullpo_retv( clan = sd->clan );
  16812. // Check if the player has a valid session and is not autotrading
  16813. if( !clif_session_isValid( sd ) ){
  16814. return;
  16815. }
  16816. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16817. fd = sd->fd;
  16818. WFIFOHEAD(fd,length);
  16819. memset( WFIFOP(fd, 0), 0, length );
  16820. WFIFOW( fd, 0 ) = 0x98a;
  16821. WFIFOL( fd, 4 ) = clan->id;
  16822. offset = 8;
  16823. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16824. offset += NAME_LENGTH;
  16825. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16826. offset += NAME_LENGTH;
  16827. mapindex_getmapname_ext( clan->map, mapname );
  16828. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16829. offset += MAP_NAME_LENGTH_EXT;
  16830. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16831. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16832. for( flag = 0; flag < 2; flag++ ){
  16833. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16834. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16835. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16836. offset += NAME_LENGTH;
  16837. }
  16838. }
  16839. }
  16840. WFIFOW( fd, 2 ) = offset;
  16841. WFIFOSET(fd,offset);
  16842. #endif
  16843. }
  16844. /**
  16845. * Updates the online and maximum player count of a clan.
  16846. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16847. **/
  16848. void clif_clan_onlinecount( struct clan* clan ){
  16849. #if PACKETVER >= 20131223
  16850. uint8 buf[6];
  16851. map_session_data *sd;
  16852. WBUFW(buf,0) = 0x988;
  16853. WBUFW(buf,2) = clan->connect_member;
  16854. WBUFW(buf,4) = clan->max_member;
  16855. if((sd = clan_getavailablesd(clan)) != NULL)
  16856. clif_send(buf, 6, &sd->bl, CLAN);
  16857. #endif
  16858. }
  16859. /**
  16860. * Notifies the client that the player has left his clan.
  16861. * 0989 (ZC_ACK_CLAN_LEAVE)
  16862. **/
  16863. void clif_clan_leave( map_session_data* sd ){
  16864. #if PACKETVER >= 20131223
  16865. int fd;
  16866. nullpo_retv( sd );
  16867. if( !clif_session_isValid( sd ) ){
  16868. return;
  16869. }
  16870. fd = sd->fd;
  16871. WFIFOHEAD(fd,2);
  16872. WFIFOW(fd,0) = 0x989;
  16873. WFIFOSET(fd,2);
  16874. #endif
  16875. }
  16876. /**
  16877. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16878. * 0A2F <result>.B <title_id>.L
  16879. */
  16880. void clif_change_title_ack(map_session_data *sd, unsigned char result, unsigned long title_id)
  16881. {
  16882. #if PACKETVER >= 20150513
  16883. int fd;
  16884. nullpo_retv(sd);
  16885. if (!clif_session_isValid(sd))
  16886. return;
  16887. fd = sd->fd;
  16888. WFIFOHEAD(fd, packet_len(0xa2f));
  16889. WFIFOW(fd, 0) = 0xa2f;
  16890. WFIFOB(fd, 2) = result;
  16891. WFIFOL(fd, 3) = title_id;
  16892. WFIFOSET(fd, packet_len(0xa2f));
  16893. #endif
  16894. }
  16895. /**
  16896. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16897. * 0A2E <title_id>.L
  16898. */
  16899. void clif_parse_change_title(int fd, map_session_data *sd)
  16900. {
  16901. int title_id;
  16902. nullpo_retv(sd);
  16903. title_id = RFIFOL(fd, 2);
  16904. if( title_id == sd->status.title_id ){
  16905. // It is exactly the same as the old one
  16906. return;
  16907. }else if( title_id <= 0 ){
  16908. sd->status.title_id = 0;
  16909. }else{
  16910. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16911. clif_change_title_ack(sd, 1, title_id);
  16912. return;
  16913. }
  16914. sd->status.title_id = title_id;
  16915. }
  16916. clif_name_area(&sd->bl);
  16917. clif_change_title_ack(sd, 0, title_id);
  16918. }
  16919. #ifdef DUMP_UNKNOWN_PACKET
  16920. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16921. {
  16922. const char* packet_txt = "save/packet.txt";
  16923. FILE* fp;
  16924. time_t time_server;
  16925. struct tm *datetime;
  16926. char datestr[512];
  16927. time(&time_server); // get time in seconds since 1/1/1970
  16928. datetime = localtime(&time_server); // convert seconds in structure
  16929. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16930. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16931. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16932. if( sd ) {
  16933. 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);
  16934. } else {
  16935. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16936. }
  16937. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16938. fprintf(fp, "\n");
  16939. fclose(fp);
  16940. } else {
  16941. ShowError("Failed to write '%s'.\n", packet_txt);
  16942. // Dump on console instead
  16943. if( sd ) {
  16944. 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);
  16945. } else {
  16946. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16947. }
  16948. ShowDump(RFIFOP(fd,0), packet_len);
  16949. }
  16950. }
  16951. #endif
  16952. /// Roulette System
  16953. /// Author: Yommy
  16954. void roulette_generate_bonus( map_session_data& sd ){
  16955. if( battle_config.feature_roulette_bonus_reward && sd.roulette.bonusItemID == 0 ){
  16956. int next_stage = 0;
  16957. if( sd.roulette_point.bronze > 0 ){
  16958. next_stage = 0;
  16959. }else if( sd.roulette_point.silver > 9 ){
  16960. next_stage = 2;
  16961. }else if( sd.roulette_point.gold > 9 ){
  16962. next_stage = 4;
  16963. }
  16964. // Get bonus item stage only from current stage or higher
  16965. int reward_stage = rnd_value( next_stage, MAX_ROULETTE_LEVEL - 1 );
  16966. sd.roulette.bonusItemID = rd.nameid[reward_stage][rnd()%rd.items[reward_stage]];
  16967. }else{
  16968. sd.roulette.bonusItemID = 0;
  16969. }
  16970. }
  16971. /// Opens the roulette window
  16972. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16973. void clif_roulette_open( map_session_data* sd ){
  16974. nullpo_retv( sd );
  16975. roulette_generate_bonus( *sd );
  16976. struct packet_roulette_open_ack p;
  16977. p.PacketType = 0xa1a;
  16978. p.Result = 0; // result
  16979. p.Serial = 0; // serial
  16980. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16981. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16982. p.AdditionItemID = sd->roulette.bonusItemID;
  16983. p.GoldPoint = sd->roulette_point.gold;
  16984. p.SilverPoint = sd->roulette_point.silver;
  16985. p.BronzePoint = sd->roulette_point.bronze;
  16986. sd->state.roulette_open = true;
  16987. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16988. }
  16989. /// Request to open the roulette window
  16990. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16991. void clif_parse_roulette_open( int fd, map_session_data* sd ){
  16992. nullpo_retv(sd);
  16993. if (!battle_config.feature_roulette) {
  16994. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16995. return;
  16996. }
  16997. clif_roulette_open(sd);
  16998. }
  16999. /// Sends the info about the available roulette rewards to the client
  17000. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17001. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17002. void clif_roulette_info( map_session_data* sd ){
  17003. nullpo_retv(sd);
  17004. struct packet_roulette_info_ack p;
  17005. p.PacketType = rouletteinfoackType;
  17006. p.PacketLength = sizeof(p);
  17007. p.RouletteSerial = 1;
  17008. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17009. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17010. p.ItemInfo[count].Row = i;
  17011. p.ItemInfo[count].Position = j;
  17012. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17013. p.ItemInfo[count].Count = rd.qty[i][j];
  17014. #if PACKETVER >= 20180511
  17015. p.ItemInfo[count].unused = 0;
  17016. #endif
  17017. count++;
  17018. }
  17019. }
  17020. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17021. }
  17022. /// Request the roulette reward data
  17023. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17024. void clif_parse_roulette_info( int fd, map_session_data* sd ){
  17025. nullpo_retv(sd);
  17026. if (!battle_config.feature_roulette) {
  17027. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17028. return;
  17029. }
  17030. clif_roulette_info(sd);
  17031. }
  17032. /// Notification of the client that the roulette window was closed
  17033. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17034. void clif_parse_roulette_close( int fd, map_session_data* sd ){
  17035. nullpo_retv(sd);
  17036. if (!battle_config.feature_roulette) {
  17037. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17038. return;
  17039. }
  17040. sd->state.roulette_open = false;
  17041. }
  17042. /// Response to a item reward request
  17043. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17044. static void clif_roulette_recvitem_ack(map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17045. #if PACKETVER >= 20141016
  17046. nullpo_retv(sd);
  17047. struct packet_roulette_itemrecv_ack p;
  17048. p.PacketType = roulettercvitemackType;
  17049. p.Result = type;
  17050. p.AdditionItemID = sd->roulette.bonusItemID;
  17051. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17052. #endif
  17053. }
  17054. /**
  17055. * Claim roulette reward
  17056. * @param sd Player
  17057. * @return 0:Success
  17058. **/
  17059. static uint8 clif_roulette_getitem(map_session_data *sd) {
  17060. struct item it;
  17061. uint8 res = 1;
  17062. unsigned short factor = 1;
  17063. nullpo_retr(1, sd);
  17064. if (sd->roulette.prizeIdx < 0)
  17065. return RECV_ITEM_FAILED;
  17066. memset(&it, 0, sizeof(it));
  17067. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17068. it.identify = 1;
  17069. if( sd->roulette.bonusItemID != 0 ){
  17070. if( sd->roulette.bonusItemID == it.nameid && battle_config.feature_roulette_bonus_reward && !( rd.flag[sd->roulette.prizeStage][sd->roulette.prizeIdx]&1 ) ){
  17071. factor = 2;
  17072. // Reset the Bonus Item to trigger new calculation
  17073. sd->roulette.bonusItemID = 0;
  17074. }else{
  17075. for( int i = 0; i < MAX_ROULETTE_LEVEL && sd->roulette.bonusItemID != 0; i++ ){
  17076. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i && sd->roulette.bonusItemID != 0; j++ ){
  17077. if( rd.nameid[i][j] == sd->roulette.bonusItemID ){
  17078. // 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
  17079. if( sd->roulette.prizeStage >= i ){
  17080. // Reset the Bonus Item to trigger new calculation and to cancel the loops
  17081. sd->roulette.bonusItemID = 0;
  17082. }
  17083. }
  17084. }
  17085. }
  17086. }
  17087. }
  17088. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx] * factor, LOG_TYPE_ROULETTE)) == 0) {
  17089. ; // onSuccess
  17090. }
  17091. if( sd->roulette.bonusItemID == 0 ){
  17092. roulette_generate_bonus( *sd );
  17093. }
  17094. sd->roulette.claimPrize = false;
  17095. sd->roulette.prizeStage = 0;
  17096. sd->roulette.prizeIdx = -1;
  17097. sd->roulette.stage = 0;
  17098. return res;
  17099. }
  17100. /// Update Roulette window with current stats
  17101. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17102. void clif_roulette_generate( map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17103. nullpo_retv( sd );
  17104. struct packet_roulette_generate_ack p;
  17105. p.PacketType = roulettgenerateackType;
  17106. p.Result = result;
  17107. p.Step = stage;
  17108. p.Idx = prizeIdx;
  17109. p.AdditionItemID = battle_config.feature_roulette_bonus_reward ? bonusItemID : 0;
  17110. p.RemainGold = sd->roulette_point.gold;
  17111. p.RemainSilver = sd->roulette_point.silver;
  17112. p.RemainBronze = sd->roulette_point.bronze;
  17113. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17114. }
  17115. /// Request to start the roulette
  17116. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17117. void clif_parse_roulette_generate( int fd, map_session_data* sd ){
  17118. enum GENERATE_ROULETTE_ACK result;
  17119. nullpo_retv(sd);
  17120. if (!battle_config.feature_roulette) {
  17121. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17122. return;
  17123. }
  17124. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17125. return;
  17126. }
  17127. // Player has not claimed his prize yet
  17128. if( sd->roulette.claimPrize ){
  17129. clif_roulette_getitem( sd );
  17130. }
  17131. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17132. // Make sure everything is reset
  17133. sd->roulette.stage = 0;
  17134. sd->roulette.claimPrize = false;
  17135. sd->roulette.prizeStage = 0;
  17136. sd->roulette.prizeIdx = -1;
  17137. }
  17138. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17139. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17140. }else{
  17141. if (!sd->roulette.stage) {
  17142. if (sd->roulette_point.bronze > 0) {
  17143. sd->roulette_point.bronze -= 1;
  17144. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17145. } else if (sd->roulette_point.silver > 9) {
  17146. sd->roulette_point.silver -= 10;
  17147. sd->roulette.stage = 2;
  17148. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17149. } else if (sd->roulette_point.gold > 9) {
  17150. sd->roulette_point.gold -= 10;
  17151. sd->roulette.stage = 4;
  17152. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17153. }
  17154. }
  17155. sd->roulette.prizeStage = sd->roulette.stage;
  17156. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17157. sd->roulette.claimPrize = true;
  17158. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17159. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17160. result = GENERATE_ROULETTE_LOSING;
  17161. sd->roulette.stage = 0;
  17162. }else{
  17163. result = GENERATE_ROULETTE_SUCCESS;
  17164. sd->roulette.stage++;
  17165. }
  17166. }
  17167. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx), sd->roulette.bonusItemID);
  17168. }
  17169. /// Request to claim a prize
  17170. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17171. void clif_parse_roulette_item( int fd, map_session_data* sd ){
  17172. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17173. nullpo_retv(sd);
  17174. if (!battle_config.feature_roulette) {
  17175. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17176. return;
  17177. }
  17178. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17179. return;
  17180. }
  17181. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17182. switch (clif_roulette_getitem(sd)) {
  17183. case ADDITEM_SUCCESS:
  17184. type = RECV_ITEM_SUCCESS;
  17185. break;
  17186. case ADDITEM_INVALID:
  17187. case ADDITEM_OVERITEM:
  17188. case ADDITEM_OVERAMOUNT:
  17189. type = RECV_ITEM_OVERCOUNT;
  17190. break;
  17191. case ADDITEM_OVERWEIGHT:
  17192. type = RECV_ITEM_OVERWEIGHT;
  17193. break;
  17194. case ADDITEM_STACKLIMIT:
  17195. default:
  17196. type = RECV_ITEM_FAILED;
  17197. break;
  17198. }
  17199. }
  17200. clif_roulette_recvitem_ack(sd,type);
  17201. }
  17202. /// MERGE ITEM
  17203. /**
  17204. * Acknowledge the client about item merger result
  17205. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17206. * @param fd
  17207. * @param sd
  17208. **/
  17209. void clif_merge_item_ack( map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17210. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17211. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17212. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17213. if( type == MERGE_ITEM_SUCCESS ){
  17214. p.index = client_index( index );
  17215. }else{
  17216. p.index = index;
  17217. }
  17218. p.amount = count;
  17219. p.reason = type;
  17220. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17221. #endif
  17222. }
  17223. /**
  17224. * Check if item has the pair to be merged
  17225. * @param sd
  17226. * @param it Item
  17227. * @return True if has pair, False if not
  17228. **/
  17229. static bool clif_merge_item_has_pair(map_session_data *sd, struct item *it) {
  17230. struct item *it_;
  17231. unsigned short i;
  17232. nullpo_retr(false, sd);
  17233. 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);
  17234. if (i < MAX_INVENTORY)
  17235. return true;
  17236. return false;
  17237. }
  17238. /**
  17239. * Check if item can be merged
  17240. * @param id Item Data
  17241. * @param it Item
  17242. * @return True if can be merged, False if not
  17243. **/
  17244. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17245. if (!id || !it)
  17246. return false;
  17247. if (id->type == IT_CASH)
  17248. return false;
  17249. if (!itemdb_isstackable2(id))
  17250. return false;
  17251. if (itemdb_isspecial(it->card[0]))
  17252. return false;
  17253. if (!it->unique_id)
  17254. return false;
  17255. return true;
  17256. }
  17257. /**
  17258. * Open available item to be merged.
  17259. * Only show 1 item in 1 process.
  17260. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17261. * @param sd
  17262. **/
  17263. void clif_merge_item_open( map_session_data& sd ){
  17264. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17265. struct PACKET_ZC_MERGE_ITEM_OPEN* p = (struct PACKET_ZC_MERGE_ITEM_OPEN*)packet_buffer;
  17266. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17267. p->packetLen = sizeof( *p );
  17268. int n = 0;
  17269. // Get entries
  17270. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17271. struct item* it = &sd.inventory.u.items_inventory[i];
  17272. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17273. continue;
  17274. }
  17275. if( clif_merge_item_has_pair( &sd, it ) ){
  17276. p->items[n++].index = client_index( i );
  17277. p->packetLen += sizeof( p->items[0] );
  17278. }
  17279. }
  17280. // No item need to be merged
  17281. if( n < 2 ){
  17282. clif_msg( &sd, MERGE_ITEM_NOT_AVAILABLE );
  17283. return;
  17284. }
  17285. clif_send( p, p->packetLen, &sd.bl, SELF );
  17286. #endif
  17287. }
  17288. /**
  17289. * Process item merger
  17290. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17291. * @param fd
  17292. * @param sd
  17293. **/
  17294. void clif_parse_merge_item_req(int fd, map_session_data* sd) {
  17295. struct s_packet_db *info = NULL;
  17296. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17297. unsigned int count = 0;
  17298. struct item_data *id = NULL;
  17299. nullpo_retv(sd);
  17300. if (!clif_session_isValid(sd))
  17301. return;
  17302. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17303. return;
  17304. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17305. if (n < 2) { // No item need to be merged
  17306. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17307. return;
  17308. }
  17309. for (i = 0, j = 0; i < n; i++) {
  17310. uint16 idx = server_index( RFIFOW( fd, info->pos[1] + i * 2 ) );
  17311. if( idx >= MAX_INVENTORY ){
  17312. return;
  17313. }
  17314. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17315. continue;
  17316. indexes[j] = idx;
  17317. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17318. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_NOT_MERGE );
  17319. return;
  17320. }
  17321. count += sd->inventory.u.items_inventory[idx].amount;
  17322. j++;
  17323. }
  17324. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17325. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17326. return;
  17327. }
  17328. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17329. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17330. return;
  17331. }
  17332. // Merrrrge!!!!
  17333. for (i = 1; i < n; i++) {
  17334. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17335. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17336. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17337. sd->inventory_data[idx] = NULL;
  17338. clif_delitem(sd, idx, amt, 0);
  17339. }
  17340. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17341. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, indexes[0], count );
  17342. }
  17343. /**
  17344. * Cancel item merge
  17345. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17346. * @param fd
  17347. * @param sd
  17348. **/
  17349. void clif_parse_merge_item_cancel(int fd, map_session_data* sd) {
  17350. return; // Nothing todo yet
  17351. }
  17352. static std::string clif_hide_name(const char* original_name)
  17353. {
  17354. std::string censored(original_name);
  17355. int hide = min(battle_config.broadcast_hide_name, censored.length() - 1);
  17356. censored.replace(censored.length() - hide, hide, hide, '*');
  17357. return censored;
  17358. }
  17359. /**
  17360. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17361. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17362. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17363. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17364. **/
  17365. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17366. char name[NAME_LENGTH];
  17367. if( battle_config.broadcast_hide_name ){
  17368. std::string dispname = clif_hide_name(char_name);
  17369. safestrncpy(name, dispname.c_str(), sizeof(name));
  17370. }else{
  17371. safestrncpy( name, char_name, sizeof( name ) );
  17372. }
  17373. switch( type ){
  17374. case ITEMOBTAIN_TYPE_BOXITEM:
  17375. #if PACKETVER >= 20091201
  17376. {
  17377. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17378. p.PacketType = package_item_announceType;
  17379. p.PacketLength = sizeof( p );
  17380. p.type = type;
  17381. p.ItemID = client_nameid( nameid );
  17382. p.len = NAME_LENGTH;
  17383. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17384. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17385. p.BoxItemID = client_nameid( container );
  17386. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17387. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17388. p.refineLevel = 0; // TODO: implement
  17389. #endif
  17390. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17391. }
  17392. #endif
  17393. break;
  17394. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17395. case ITEMOBTAIN_TYPE_NPC:
  17396. {
  17397. struct packet_item_drop_announce p;
  17398. p.PacketType = item_drop_announceType;
  17399. p.type = type;
  17400. p.ItemID = client_nameid( nameid );
  17401. p.len = NAME_LENGTH;
  17402. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17403. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17404. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17405. p.monsterNameLen = NAME_LENGTH;
  17406. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17407. }else{
  17408. p.monsterNameLen = 0;
  17409. p.monsterName[0] = '\0';
  17410. }
  17411. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17412. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17413. #else
  17414. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17415. #endif
  17416. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17417. }
  17418. break;
  17419. }
  17420. }
  17421. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17422. /// 0A02 <view>.W
  17423. /// Value <flag> has the following effects:
  17424. /// 1: Open a Dress Room window.
  17425. void clif_dressing_room(map_session_data *sd, int flag) {
  17426. #if PACKETVER >= 20150513
  17427. int fd = sd->fd;
  17428. nullpo_retv(sd);
  17429. WFIFOHEAD(fd, packet_len(0xa02));
  17430. WFIFOW(fd,0) = 0xa02;
  17431. WFIFOW(fd,2) = flag;
  17432. WFIFOSET(fd, packet_len(0xa02));
  17433. #endif
  17434. }
  17435. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17436. /// 0A35 <result>.W
  17437. void clif_parse_Oneclick_Itemidentify(int fd, map_session_data *sd) {
  17438. #if PACKETVER >= 20150513
  17439. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17440. // Ignore the request
  17441. // - Invalid item index
  17442. // - Invalid item ID or item doesn't exist
  17443. // - Item is already identified
  17444. if (idx < 0 || idx >= MAX_INVENTORY ||
  17445. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17446. sd->inventory.u.items_inventory[idx].identify)
  17447. return;
  17448. // Ignore the request - No magnifiers in inventory
  17449. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17450. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17451. return;
  17452. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17453. return;
  17454. skill_identify(sd, idx);
  17455. #endif
  17456. }
  17457. /// Starts navigation to the given target on client side
  17458. void clif_navigateTo(map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17459. #if PACKETVER >= 20111010
  17460. int fd = sd->fd;
  17461. WFIFOHEAD(fd,27);
  17462. WFIFOW(fd,0) = 0x08e2;
  17463. // How detailed will our navigation be?
  17464. if( mob_id > 0 ){
  17465. x = 0;
  17466. y = 0;
  17467. WFIFOB(fd,2) = 3; // monster with destination field
  17468. }else if( x > 0 && y > 0 ){
  17469. WFIFOB(fd,2) = 0; // with coordinates
  17470. }else{
  17471. x = 0;
  17472. y = 0;
  17473. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17474. }
  17475. // Which services can be used for transportation?
  17476. WFIFOB(fd,3) = flag;
  17477. // If this flag is set, the navigation window will not be opened up
  17478. WFIFOB(fd,4) = hideWindow;
  17479. // Target map
  17480. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17481. // Target x
  17482. WFIFOW(fd,21) = x;
  17483. // Target y
  17484. WFIFOW(fd,23) = y;
  17485. // Target monster ID
  17486. WFIFOW(fd,25) = mob_id;
  17487. WFIFOSET(fd,27);
  17488. #endif
  17489. }
  17490. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17491. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17492. void clif_hat_effects( map_session_data* sd, struct block_list* bl, enum send_target target ){
  17493. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17494. map_session_data *tsd;
  17495. struct block_list* tbl;
  17496. if( target == SELF ){
  17497. tsd = BL_CAST(BL_PC,bl);
  17498. tbl = &sd->bl;
  17499. }else{
  17500. tsd = sd;
  17501. tbl = bl;
  17502. }
  17503. nullpo_retv( tsd );
  17504. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17505. return;
  17506. }
  17507. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17508. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17509. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17510. p->aid = tsd->bl.id;
  17511. p->status = 1;
  17512. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17513. p->effects[i] = tsd->hatEffects[i];
  17514. }
  17515. clif_send( p, p->packetLength, tbl, target );
  17516. #endif
  17517. }
  17518. void clif_hat_effect_single( map_session_data* sd, uint16 effectId, bool enable ){
  17519. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17520. nullpo_retv( sd );
  17521. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17522. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17523. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17524. p->aid = sd->bl.id;
  17525. p->status = enable;
  17526. p->effects[0] = effectId;
  17527. clif_send( p, p->packetLength, &sd->bl, AREA );
  17528. #endif
  17529. }
  17530. /// Notify the client that a sale has started
  17531. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17532. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17533. #if PACKETVER_SUPPORTS_SALES
  17534. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17535. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17536. p.itemId = client_nameid( sale_item->nameid );
  17537. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17538. clif_send( &p, sizeof( p ), bl, target );
  17539. #endif
  17540. }
  17541. /// Notify the client that a sale has ended
  17542. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17543. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17544. #if PACKETVER_SUPPORTS_SALES
  17545. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17546. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17547. p.itemId = client_nameid( sale_item->nameid );
  17548. clif_send( &p, sizeof( p ), bl, target );
  17549. #endif
  17550. }
  17551. /// Update the remaining amount of a sale item.
  17552. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17553. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17554. #if PACKETVER_SUPPORTS_SALES
  17555. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17556. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17557. p.itemId = client_nameid( sale_item->nameid );
  17558. p.amount = sale_item->amount;
  17559. clif_send( &p, sizeof( p ), bl, target );
  17560. #endif
  17561. }
  17562. /// The client requested a refresh of the current remaining count of a sale item
  17563. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17564. void clif_parse_sale_refresh( int fd, map_session_data* sd ){
  17565. #if PACKETVER_SUPPORTS_SALES
  17566. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17567. struct sale_item_data* sale;
  17568. if( p->AID != sd->status.account_id ){
  17569. return;
  17570. }
  17571. sale = sale_find_item( p->itemId, true );
  17572. if( sale == NULL ){
  17573. return;
  17574. }
  17575. clif_sale_amount(sale, &sd->bl, SELF);
  17576. #endif
  17577. }
  17578. /// Opens the sale administration window on the client
  17579. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17580. void clif_sale_open( map_session_data* sd ){
  17581. #if PACKETVER_SUPPORTS_SALES
  17582. nullpo_retv(sd);
  17583. if( sd->state.sale_open ){
  17584. return;
  17585. }
  17586. sd->state.sale_open = true;
  17587. int fd = sd->fd;
  17588. WFIFOHEAD(fd, 2);
  17589. WFIFOW(fd, 0) = 0x9b5;
  17590. WFIFOSET(fd, 2);
  17591. #endif
  17592. }
  17593. /// Client request to open the sale administration window.
  17594. /// This is sent by /limitedsale
  17595. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17596. void clif_parse_sale_open( int fd, map_session_data* sd ){
  17597. #if PACKETVER_SUPPORTS_SALES
  17598. nullpo_retv(sd);
  17599. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17600. return;
  17601. }
  17602. char command[CHAT_SIZE_MAX];
  17603. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17604. is_atcommand(fd, sd, command, 1);
  17605. #endif
  17606. }
  17607. /// Closes the sale administration window on the client.
  17608. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17609. void clif_sale_close(map_session_data* sd) {
  17610. #if PACKETVER_SUPPORTS_SALES
  17611. nullpo_retv(sd);
  17612. if( !sd->state.sale_open ){
  17613. return;
  17614. }
  17615. sd->state.sale_open = false;
  17616. int fd = sd->fd;
  17617. WFIFOHEAD(fd, 2);
  17618. WFIFOW(fd, 0) = 0x9bd;
  17619. WFIFOSET(fd, 2);
  17620. #endif
  17621. }
  17622. /// Client request to close the sale administration window.
  17623. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17624. void clif_parse_sale_close(int fd, map_session_data* sd) {
  17625. #if PACKETVER_SUPPORTS_SALES
  17626. nullpo_retv(sd);
  17627. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17628. return;
  17629. }
  17630. clif_sale_close(sd);
  17631. #endif
  17632. }
  17633. /// Reply to a item search request for item sale administration.
  17634. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17635. void clif_sale_search_reply( map_session_data* sd, struct cash_item_data* item ){
  17636. #if PACKETVER_SUPPORTS_SALES
  17637. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17638. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17639. if( item != NULL ){
  17640. p.result = 0;
  17641. p.itemId = client_nameid( item->nameid );
  17642. p.price = item->price;
  17643. }else{
  17644. p.result = 1;
  17645. p.itemId = 0;
  17646. p.price = 0;
  17647. }
  17648. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17649. #endif
  17650. }
  17651. /// Search request for an item sale administration.
  17652. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17653. void clif_parse_sale_search( int fd, map_session_data* sd ){
  17654. #if PACKETVER_SUPPORTS_SALES
  17655. char item_name[ITEM_NAME_LENGTH];
  17656. nullpo_retv(sd);
  17657. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17658. return;
  17659. }
  17660. if( !sd->state.sale_open ){
  17661. return;
  17662. }
  17663. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17664. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17665. if( id ){
  17666. int i;
  17667. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17668. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17669. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17670. return;
  17671. }
  17672. }
  17673. }
  17674. // not found
  17675. clif_sale_search_reply( sd, NULL );
  17676. #endif
  17677. }
  17678. /// Reply if an item was successfully put on sale or not.
  17679. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17680. void clif_sale_add_reply( map_session_data* sd, enum e_sale_add_result result ){
  17681. #if PACKETVER_SUPPORTS_SALES
  17682. int fd = sd->fd;
  17683. WFIFOHEAD(fd, 4);
  17684. WFIFOW(fd, 0) = 0x9af;
  17685. WFIFOW(fd, 2) = (uint16)result;
  17686. WFIFOSET(fd, 4);
  17687. #endif
  17688. }
  17689. /// A client request to put an item on sale.
  17690. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17691. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17692. void clif_parse_sale_add( int fd, map_session_data* sd ){
  17693. #if PACKETVER_SUPPORTS_SALES
  17694. nullpo_retv( sd );
  17695. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17696. if( p->AID != sd->status.account_id ){
  17697. return;
  17698. }
  17699. if( !sd->state.sale_open ){
  17700. return;
  17701. }
  17702. time_t endTime = p->startTime + p->hours * 60 * 60;
  17703. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17704. #endif
  17705. }
  17706. /// Reply to an item removal from sale.
  17707. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17708. void clif_sale_remove_reply( map_session_data* sd, bool failed ){
  17709. #if PACKETVER_SUPPORTS_SALES
  17710. int fd = sd->fd;
  17711. WFIFOHEAD(fd, 4);
  17712. WFIFOW(fd, 0) = 0x9b1;
  17713. WFIFOW(fd, 2) = failed;
  17714. WFIFOSET(fd, 4);
  17715. #endif
  17716. }
  17717. /// Request to remove an item from sale.
  17718. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17719. void clif_parse_sale_remove( int fd, map_session_data* sd ){
  17720. #if PACKETVER_SUPPORTS_SALES
  17721. nullpo_retv( sd );
  17722. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17723. if( p->AID != sd->status.account_id ){
  17724. return;
  17725. }
  17726. if( !sd->state.sale_open ){
  17727. return;
  17728. }
  17729. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17730. #endif
  17731. }
  17732. /// Achievement System
  17733. /// Author: Luxuri, Aleos
  17734. /**
  17735. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17736. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17737. */
  17738. void clif_achievement_list_all(map_session_data *sd)
  17739. {
  17740. nullpo_retv(sd);
  17741. if (!battle_config.feature_achievement) {
  17742. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17743. return;
  17744. }
  17745. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17746. if (count == 0)
  17747. return;
  17748. int len = (50 * count) + 22;
  17749. int fd = sd->fd;
  17750. int *info = achievement_level(sd, true);
  17751. WFIFOHEAD(fd,len);
  17752. WFIFOW(fd, 0) = 0xa23;
  17753. WFIFOW(fd, 2) = len;
  17754. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17755. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17756. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17757. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17758. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17759. for (int i = 0; i < count; i++) {
  17760. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17761. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17762. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17763. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17764. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17765. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17766. }
  17767. WFIFOSET(fd, len);
  17768. }
  17769. /**
  17770. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17771. * 0a24 <ACHPoint>.L
  17772. */
  17773. void clif_achievement_update(map_session_data *sd, struct achievement *ach, int count)
  17774. {
  17775. nullpo_retv(sd);
  17776. if (!battle_config.feature_achievement) {
  17777. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17778. return;
  17779. }
  17780. int fd = sd->fd;
  17781. int *info = achievement_level(sd, true);
  17782. WFIFOHEAD(fd, packet_len(0xa24));
  17783. WFIFOW(fd, 0) = 0xa24;
  17784. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17785. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17786. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17787. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17788. if (ach) {
  17789. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17790. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17791. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17792. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17793. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17794. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17795. } else
  17796. memset(WFIFOP(fd, 16), 0, 40);
  17797. WFIFOSET(fd, packet_len(0xa24));
  17798. }
  17799. /**
  17800. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17801. * 0a25 <achievementID>.L
  17802. */
  17803. void clif_parse_AchievementCheckReward(int fd, map_session_data *sd)
  17804. {
  17805. nullpo_retv(sd);
  17806. if( sd->achievement_data.save )
  17807. intif_achievement_save(sd);
  17808. achievement_check_reward(sd, RFIFOL(fd,2));
  17809. }
  17810. /**
  17811. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17812. * 0a26 <result>.W <achievementID>.L
  17813. */
  17814. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17815. {
  17816. WFIFOHEAD(fd, packet_len(0xa26));
  17817. WFIFOW(fd, 0) = 0xa26;
  17818. WFIFOB(fd, 2) = result;
  17819. WFIFOL(fd, 3) = achievement_id;
  17820. WFIFOSET(fd, packet_len(0xa26));
  17821. }
  17822. /// Process the pet evolution request
  17823. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17824. void clif_parse_pet_evolution( int fd, map_session_data *sd ){
  17825. #if PACKETVER >= 20141008
  17826. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17827. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17828. if (!pet) {
  17829. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17830. return;
  17831. }
  17832. pet_evolution(sd, pet->class_);
  17833. #endif
  17834. }
  17835. /// Sends the result of the evolution to the client.
  17836. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17837. void clif_pet_evolution_result( map_session_data* sd, e_pet_evolution_result result ){
  17838. #if PACKETVER >= 20141008
  17839. int fd = sd->fd;
  17840. WFIFOHEAD(fd, packet_len(0x9fc));
  17841. WFIFOW(fd, 0) = 0x9fc;
  17842. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17843. WFIFOSET(fd, packet_len(0x9fc));
  17844. #endif
  17845. }
  17846. /*
  17847. * This packet is sent by /changedress or /nocosplay
  17848. *
  17849. * 0ae8
  17850. */
  17851. void clif_parse_changedress( int fd, map_session_data* sd ){
  17852. #if PACKETVER >= 20180103
  17853. char command[CHAT_SIZE_MAX];
  17854. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17855. is_atcommand( fd, sd, command, 1 );
  17856. #endif
  17857. }
  17858. /// Opens an UI window of the given type and initializes it with the given data
  17859. /// 0AE2 <type>.B <data>.L
  17860. void clif_ui_open( map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  17861. #if PACKETVER >= 20151202
  17862. // If the UI requires state tracking
  17863. switch( ui_type ){
  17864. case OUT_UI_STYLIST:
  17865. sd.state.stylist_open = true;
  17866. break;
  17867. case OUT_UI_ENCHANTGRADE:
  17868. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  17869. sd.state.enchantgrade_open = true;
  17870. break;
  17871. #else
  17872. return;
  17873. #endif
  17874. }
  17875. struct PACKET_ZC_UI_OPEN p = {};
  17876. p.PacketType = HEADER_ZC_UI_OPEN;
  17877. p.UIType = ui_type;
  17878. #if PACKETVER >= 20171122
  17879. p.data = data;
  17880. #endif
  17881. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17882. #endif
  17883. }
  17884. /// Request to open an UI window of the given type
  17885. /// 0A68 <type>.B
  17886. void clif_parse_open_ui( int fd, map_session_data* sd ){
  17887. switch( RFIFOB(fd,2) ){
  17888. case IN_UI_ATTENDANCE:
  17889. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17890. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17891. }else if( pc_attendance_enabled() ){
  17892. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17893. }else{
  17894. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17895. }
  17896. break;
  17897. #if PACKETVER >= 20160316
  17898. case IN_UI_MACRO_REGISTER:
  17899. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  17900. break;
  17901. case IN_UI_MACRO_DETECTOR:
  17902. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  17903. break;
  17904. #endif
  17905. }
  17906. }
  17907. /// Response for attedance request
  17908. /// 0AF0 <unknown>.L <data>.L
  17909. void clif_attendence_response( map_session_data *sd, int32 data ){
  17910. nullpo_retv(sd);
  17911. int fd = sd->fd;
  17912. WFIFOHEAD(fd,packet_len(0xAF0));
  17913. WFIFOW(fd,0) = 0xAF0;
  17914. WFIFOL(fd,2) = 0;
  17915. WFIFOL(fd,6) = data;
  17916. WFIFOSET(fd,packet_len(0xAF0));
  17917. }
  17918. /// Request from the client to retrieve today's attendance reward
  17919. /// 0AEF
  17920. void clif_parse_attendance_request( int fd, map_session_data* sd ){
  17921. pc_attendance_claim_reward(sd);
  17922. }
  17923. /// Send out the percentage of weight that causes it to be displayed in red.
  17924. /// 0ADE <percentage>.L
  17925. void clif_weight_limit( map_session_data* sd ){
  17926. #if PACKETVER >= 20171025
  17927. nullpo_retv(sd);
  17928. int fd = sd->fd;
  17929. WFIFOHEAD(fd, packet_len(0xADE));
  17930. WFIFOW(fd, 0) = 0xADE;
  17931. #ifdef RENEWAL
  17932. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17933. #else
  17934. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17935. #endif
  17936. WFIFOSET(fd, packet_len(0xADE));
  17937. #endif
  17938. }
  17939. enum e_private_airship_response : uint32{
  17940. PRIVATEAIRSHIP_OK,
  17941. PRIVATEAIRSHIP_RETRY,
  17942. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17943. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17944. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17945. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17946. };
  17947. /// Send out the response to a private airship request
  17948. /// 0A4A <response>.L
  17949. void clif_private_airship_response( map_session_data* sd, enum e_private_airship_response response ){
  17950. #if PACKETVER >= 20180321
  17951. nullpo_retv( sd );
  17952. int fd = sd->fd;
  17953. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17954. WFIFOW( fd, 0 ) = 0xA4A;
  17955. WFIFOL( fd, 2 ) = response;
  17956. WFIFOSET( fd, packet_len( 0xA4A ) );
  17957. #endif
  17958. }
  17959. /// Parses a request for a private airship
  17960. /// 0A49 <mapname>.16B <itemid>.W
  17961. void clif_parse_private_airship_request( int fd, map_session_data* sd ){
  17962. #if PACKETVER >= 20180321
  17963. // Check if the feature is enabled
  17964. if( !battle_config.feature_privateairship ){
  17965. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17966. return;
  17967. }
  17968. // Check if the player is allowed to warp from the source map
  17969. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17970. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17971. return;
  17972. }
  17973. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17974. char mapname[MAP_NAME_LENGTH_EXT];
  17975. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17976. int16 mapindex = mapindex_name2id( mapname );
  17977. // Check if we know the mapname
  17978. if( mapindex < 0 ){
  17979. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17980. return;
  17981. }
  17982. int16 mapid = map_mapindex2mapid( mapindex );
  17983. // Check if the map is available on this server
  17984. if( mapid < 0 ){
  17985. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17986. return;
  17987. }
  17988. // Check if the player tried to warp to the map he is on
  17989. if( sd->bl.m == mapid ){
  17990. // This is blocked by the client, but just to be sure
  17991. return;
  17992. }
  17993. // This can only be a hack, so we prevent it
  17994. if( map_getmapdata( mapid )->instance_id ){
  17995. // Ignore requests to warp directly into a running instance
  17996. return;
  17997. }
  17998. // Check if the player is allowed to warp to the target map
  17999. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18000. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18001. return;
  18002. }
  18003. t_itemid item_id = p->ItemID;
  18004. // Check if the item sent by the client is known to us
  18005. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18006. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18007. return;
  18008. }
  18009. int idx = pc_search_inventory( sd, item_id );
  18010. // Check if the player has the item at all
  18011. if( idx < 0 ){
  18012. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18013. return;
  18014. }
  18015. // Delete the chosen item
  18016. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18017. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18018. return;
  18019. }
  18020. // Warp the player to a random spot on the destination map
  18021. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18022. #endif
  18023. }
  18024. /// Sends out the usage history of the guild storage
  18025. /// 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
  18026. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18027. void clif_guild_storage_log( map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18028. #if PACKETVER >= 20140205
  18029. nullpo_retv( sd );
  18030. int fd = sd->fd;
  18031. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18032. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18033. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18034. }else{
  18035. log.clear();
  18036. }
  18037. WFIFOHEAD( fd, size );
  18038. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18039. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18040. p->PacketLength = size;
  18041. p->result = result;
  18042. p->amount = (uint16)log.size();
  18043. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18044. for( int i = 0; i < log.size(); i++ ){
  18045. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18046. struct guild_log_entry& entry = log[i];
  18047. item->id = entry.id;
  18048. item->itemId = client_nameid( entry.item.nameid );
  18049. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18050. item->action = entry.amount > 0; // action = true(put), false(get)
  18051. item->refine = entry.item.refine;
  18052. item->uniqueId = entry.item.unique_id;
  18053. item->IsIdentified = entry.item.identify;
  18054. item->itemType = itemtype( entry.item.nameid );
  18055. clif_addcards( &item->slot, &entry.item );
  18056. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18057. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18058. item->attribute = entry.item.attribute;
  18059. }
  18060. }
  18061. WFIFOSET( fd, p->PacketLength );
  18062. #endif
  18063. }
  18064. /// Activates the client camera info or updates the client camera with the given values.
  18065. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18066. void clif_camerainfo( map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18067. #if PACKETVER >= 20160525
  18068. int fd = sd->fd;
  18069. WFIFOHEAD(fd, packet_len(0xa78));
  18070. WFIFOW(fd, 0) = 0xa78;
  18071. WFIFOB(fd, 2) = show;
  18072. WFIFOF(fd, 3) = range;
  18073. WFIFOF(fd, 7) = rotation;
  18074. WFIFOF(fd, 11) = latitude;
  18075. WFIFOSET(fd, packet_len(0xa78));
  18076. #endif
  18077. }
  18078. /// Activates or deactives the client camera info or updates the camera settings.
  18079. /// This packet is triggered by /viewpointvalue or /setcamera
  18080. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18081. void clif_parse_camerainfo( int fd, map_session_data* sd ){
  18082. char command[CHAT_SIZE_MAX];
  18083. // /viewpointvalue
  18084. if( RFIFOB( fd, 2 ) == 1 ){
  18085. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18086. // /setcamera
  18087. }else{
  18088. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18089. }
  18090. is_atcommand( fd, sd, command, 1 );
  18091. }
  18092. /// Send the full list of items in the equip switch window
  18093. /// 0a9b <length>.W { <index>.W <position>.L }*
  18094. void clif_equipswitch_list( map_session_data* sd ){
  18095. #if PACKETVER >= 20170208
  18096. int fd = sd->fd;
  18097. int offset, i, position;
  18098. WFIFOW(fd, 0) = 0xa9b;
  18099. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18100. short index = sd->equip_switch_index[i];
  18101. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18102. WFIFOW(fd, offset) = index + 2;
  18103. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18104. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18105. offset += 6;
  18106. }
  18107. }
  18108. WFIFOW(fd, 2) = offset;
  18109. WFIFOSET(fd, offset);
  18110. #endif
  18111. }
  18112. /// Acknowledgement for removing an equip to the equip switch window
  18113. /// 0a9a <index>.W <position.>.L <failure>.W
  18114. void clif_equipswitch_remove( map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18115. #if PACKETVER >= 20170208
  18116. int fd = sd->fd;
  18117. WFIFOHEAD(fd, packet_len(0xa9a));
  18118. WFIFOW(fd, 0) = 0xa9a;
  18119. WFIFOW(fd, 2) = index + 2;
  18120. WFIFOL(fd, 4) = pos;
  18121. WFIFOW(fd, 8) = failed;
  18122. WFIFOSET(fd, packet_len(0xa9a));
  18123. #endif
  18124. }
  18125. /// Request to remove an equip from the equip switch window
  18126. /// 0a99 <index>.W <position>.L <= 20170502
  18127. /// 0a99 <index>.W
  18128. void clif_parse_equipswitch_remove( int fd, map_session_data* sd ){
  18129. #if PACKETVER >= 20170208
  18130. uint16 index = RFIFOW(fd, 2) - 2;
  18131. bool removed = false;
  18132. if( !battle_config.feature_equipswitch ){
  18133. return;
  18134. }
  18135. // Check if the index is valid
  18136. if( index >= MAX_INVENTORY ){
  18137. return;
  18138. }
  18139. pc_equipswitch_remove( sd, index );
  18140. #endif
  18141. }
  18142. /// Acknowledgement for adding an equip to the equip switch window
  18143. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18144. /// 0a98 <index>.W <position.>.L <flag>.W
  18145. void clif_equipswitch_add( map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18146. #if PACKETVER >= 20170208
  18147. int fd = sd->fd;
  18148. WFIFOHEAD(fd, packet_len(0xa98));
  18149. WFIFOW(fd, 0) = 0xa98;
  18150. WFIFOW(fd, 2) = index + 2;
  18151. WFIFOL(fd, 4) = pos;
  18152. #if PACKETVER <= 20170502
  18153. WFIFOL(fd, 8) = flag;
  18154. #else
  18155. WFIFOW(fd, 8) = flag;
  18156. #endif
  18157. WFIFOSET(fd,packet_len(0xa98));
  18158. #endif
  18159. }
  18160. /// Request to add an equip to the equip switch window
  18161. /// 0a97 <index>.W <position>.L
  18162. void clif_parse_equipswitch_add( int fd, map_session_data* sd ){
  18163. #if PACKETVER >= 20170208
  18164. uint16 index = RFIFOW(fd, 2) - 2;
  18165. uint32 position = RFIFOL(fd, 4);
  18166. if( !battle_config.feature_equipswitch ){
  18167. return;
  18168. }
  18169. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18170. return;
  18171. }
  18172. if( sd->state.trading || sd->npc_shopid ){
  18173. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18174. return;
  18175. }
  18176. if( sd->inventory_data[index]->type == IT_AMMO ){
  18177. position = EQP_AMMO;
  18178. }
  18179. pc_equipitem( sd, index, position, true );
  18180. #endif
  18181. }
  18182. /// Acknowledgement packet for the full equip switch
  18183. /// 0a9d <failed>.W
  18184. void clif_equipswitch_reply( map_session_data* sd, bool failed ){
  18185. #if PACKETVER >= 20170208
  18186. int fd = sd->fd;
  18187. WFIFOHEAD(fd, packet_len(0xa9d));
  18188. WFIFOW(fd, 0) = 0xa9d;
  18189. WFIFOW(fd, 2) = failed;
  18190. WFIFOSET(fd, packet_len(0xa9d));
  18191. #endif
  18192. }
  18193. /// Request to do a full equip switch
  18194. /// 0a9c
  18195. void clif_parse_equipswitch_request( int fd, map_session_data* sd ){
  18196. #if PACKETVER >= 20170208
  18197. int i;
  18198. t_tick tick = gettick();
  18199. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18200. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18201. // Client will not let you send a request
  18202. return;
  18203. }
  18204. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18205. if( !battle_config.feature_equipswitch ){
  18206. return;
  18207. }
  18208. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18209. if( i == EQI_MAX ){
  18210. // client will show: "There is no item to replace." and should not even come here
  18211. clif_equipswitch_reply( sd, false );
  18212. return;
  18213. }
  18214. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18215. return;
  18216. }
  18217. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18218. #endif
  18219. }
  18220. /// Request to do a single equip switch
  18221. /// 0ace <index>.W
  18222. void clif_parse_equipswitch_request_single( int fd, map_session_data* sd ){
  18223. #if PACKETVER >= 20170502
  18224. uint16 index = RFIFOW(fd, 2) - 2;
  18225. if( !battle_config.feature_equipswitch ){
  18226. return;
  18227. }
  18228. // Check if the index is valid
  18229. if( index >= MAX_INVENTORY ){
  18230. return;
  18231. }
  18232. // Check if the item exists
  18233. if (sd->inventory_data[index] == nullptr)
  18234. return;
  18235. // Check if the item was already added to equip switch
  18236. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18237. if( sd->npc_id ){
  18238. #ifdef RENEWAL
  18239. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18240. clif_msg( sd, WORK_IN_PROGRESS );
  18241. return;
  18242. }
  18243. #endif
  18244. if( !sd->npc_item_flag ){
  18245. return;
  18246. }
  18247. }
  18248. pc_equipswitch( sd, index );
  18249. return;
  18250. }
  18251. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18252. #endif
  18253. }
  18254. void clif_parse_StartUseSkillToId( int fd, map_session_data* sd ){
  18255. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18256. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18257. // Only rolling cutter is supported for now
  18258. if( p->skillId != GC_ROLLINGCUTTER ){
  18259. return;
  18260. }
  18261. // Already running - cant happen on officials, since only one skill is supported
  18262. if( sd->skill_keep_using.skill_id != 0 ){
  18263. return;
  18264. }
  18265. sd->skill_keep_using.tid = INVALID_TIMER;
  18266. sd->skill_keep_using.skill_id = p->skillId;
  18267. sd->skill_keep_using.level = p->skillLv;
  18268. sd->skill_keep_using.target = p->targetId;
  18269. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18270. #endif
  18271. }
  18272. void clif_parse_StopUseSkillToId( int fd, map_session_data* sd ){
  18273. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18274. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18275. // Not running
  18276. if( sd->skill_keep_using.skill_id == 0 ){
  18277. return;
  18278. }
  18279. #if 0
  18280. // Hack
  18281. if( p->skillId != sd->skill_keep_using.skill_id ){
  18282. return;
  18283. }
  18284. #endif
  18285. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18286. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18287. sd->skill_keep_using.tid = INVALID_TIMER;
  18288. }
  18289. sd->skill_keep_using.skill_id = 0;
  18290. sd->skill_keep_using.level = 0;
  18291. sd->skill_keep_using.target = 0;
  18292. #endif
  18293. }
  18294. void clif_ping( map_session_data* sd ){
  18295. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18296. nullpo_retv( sd );
  18297. int fd = sd->fd;
  18298. if( !session_isActive( fd ) ){
  18299. return;
  18300. }
  18301. struct PACKET_ZC_PING_LIVE p = {};
  18302. p.packetType = HEADER_ZC_PING_LIVE;
  18303. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18304. #endif
  18305. }
  18306. int clif_ping_timer_sub( map_session_data *sd, va_list ap ){
  18307. nullpo_ret( sd );
  18308. int fd = sd->fd;
  18309. if( !session_isActive( fd ) ){
  18310. return 0;
  18311. }
  18312. t_tick tick = va_arg( ap, t_tick );
  18313. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18314. clif_ping( sd );
  18315. }
  18316. return 0;
  18317. }
  18318. TIMER_FUNC( clif_ping_timer ){
  18319. map_foreachpc( clif_ping_timer_sub, gettick() );
  18320. return 0;
  18321. }
  18322. /**
  18323. * Opens the refine UI on the designated client.
  18324. * 0aa0
  18325. */
  18326. void clif_refineui_open( map_session_data* sd ){
  18327. #if PACKETVER >= 20161012
  18328. nullpo_retv( sd );
  18329. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18330. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18331. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18332. sd->state.refineui_open = true;
  18333. #endif
  18334. }
  18335. /**
  18336. * Parses cancel/close of the refine UI on client side.
  18337. * 0aa4
  18338. */
  18339. void clif_parse_refineui_close( int fd, map_session_data* sd ){
  18340. #if PACKETVER >= 20161012
  18341. sd->state.refineui_open = false;
  18342. #endif
  18343. }
  18344. /**
  18345. * Adds the selected item into the refine UI and sends the possible materials
  18346. * to the client.
  18347. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18348. */
  18349. void clif_refineui_info( map_session_data* sd, uint16 index ){
  18350. #if PACKETVER >= 20161012
  18351. int fd = sd->fd;
  18352. // Get the item db reference
  18353. struct item_data* id = sd->inventory_data[index];
  18354. // No item data was found
  18355. if( id == NULL ){
  18356. return;
  18357. }
  18358. // Check the inventory
  18359. struct item* item = &sd->inventory.u.items_inventory[index];
  18360. // No item was found at the given index
  18361. if( item == NULL ){
  18362. return;
  18363. }
  18364. // Check if the item is identified
  18365. if( !item->identify ){
  18366. return;
  18367. }
  18368. // Check if the item is broken
  18369. if( item->attribute ){
  18370. return;
  18371. }
  18372. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18373. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18374. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18375. p->itemIndex = client_index( index );
  18376. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18377. // No possibilities were found
  18378. if( info == nullptr ){
  18379. p->blacksmithBlessing = 0;
  18380. }else{
  18381. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18382. uint16 count = 0;
  18383. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18384. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18385. if( cost != nullptr ){
  18386. p->req[count].itemId = client_nameid( cost->nameid );
  18387. p->req[count].chance = (uint8)( cost->chance / 100 );
  18388. p->req[count].zeny = cost->zeny;
  18389. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18390. count++;
  18391. }
  18392. }
  18393. }
  18394. clif_send( p, p->packetLength, &sd->bl, SELF );
  18395. #endif
  18396. }
  18397. /**
  18398. * Client request to add an item to the refine UI.
  18399. * 0aa1 <index>.W
  18400. */
  18401. void clif_parse_refineui_add( int fd, map_session_data* sd ){
  18402. #if PACKETVER >= 20161012
  18403. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18404. uint16 index = server_index( p->index );
  18405. // Check if the refine UI is open
  18406. if( !sd->state.refineui_open ){
  18407. return;
  18408. }
  18409. // Check if the index is valid
  18410. if( index >= MAX_INVENTORY ){
  18411. return;
  18412. }
  18413. // Send out the requirements for the refine process
  18414. clif_refineui_info( sd, index );
  18415. #endif
  18416. }
  18417. /**
  18418. * Client requests to try to refine an item.
  18419. * 0aa3 <index>.W <material>.W <catalyst>.B
  18420. */
  18421. void clif_parse_refineui_refine( int fd, map_session_data* sd ){
  18422. #if PACKETVER >= 20161012
  18423. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18424. uint16 index = server_index( p->index );
  18425. t_itemid material = p->itemId;
  18426. int16 j;
  18427. // Check if the refine UI is open
  18428. if( !sd->state.refineui_open ){
  18429. return;
  18430. }
  18431. // Check if the index is valid
  18432. if( index >= MAX_INVENTORY ){
  18433. return;
  18434. }
  18435. // Get the item db reference
  18436. struct item_data* id = sd->inventory_data[index];
  18437. // No item data was found
  18438. if( id == NULL ){
  18439. return;
  18440. }
  18441. // Check the inventory
  18442. struct item* item = &sd->inventory.u.items_inventory[index];
  18443. // No item was found at the given index
  18444. if( item == NULL ){
  18445. return;
  18446. }
  18447. // Check if the item is identified
  18448. if( !item->identify ){
  18449. return;
  18450. }
  18451. // Check if the item is broken
  18452. if( item->attribute ){
  18453. return;
  18454. }
  18455. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18456. // No refine possible
  18457. if( info == nullptr ){
  18458. return;
  18459. }
  18460. // No possibilities were found
  18461. if( info->costs.empty() ){
  18462. return;
  18463. }
  18464. // Check if the player has the selected material
  18465. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18466. return;
  18467. }
  18468. int16 blacksmith_index = -1;
  18469. uint16 blacksmith_amount = 0;
  18470. // Check if the player has enough blacksmith blessings
  18471. if( p->blacksmithBlessing != 0 ){
  18472. blacksmith_amount = info->blessing_amount;
  18473. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18474. if( blacksmith_amount == 0 ){
  18475. return;
  18476. }
  18477. // Check if the player has blacksmith blessings
  18478. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18479. return;
  18480. }
  18481. // Check if the player has enough blacksmith blessings
  18482. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18483. return;
  18484. }
  18485. }
  18486. std::shared_ptr<s_refine_cost> cost = nullptr;
  18487. for( const auto& pair : info->costs ){
  18488. if( pair.second->nameid == material ){
  18489. cost = pair.second;
  18490. break;
  18491. }
  18492. }
  18493. // The material was not in the list of possible materials
  18494. if( cost == nullptr ){
  18495. return;
  18496. }
  18497. // Try to pay for the refine
  18498. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18499. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18500. return;
  18501. }
  18502. // Delete the required material
  18503. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18504. return;
  18505. }
  18506. // Delete the required blacksmith blessings
  18507. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18508. return;
  18509. }
  18510. // Try to refine the item
  18511. if( cost->chance >= ( rnd() % 10000 ) ){
  18512. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18513. // Success
  18514. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18515. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18516. clif_misceffect( &sd->bl, 3 );
  18517. clif_refine( fd, 0, index, item->refine );
  18518. if (info->broadcast_success) {
  18519. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18520. }
  18521. if( id->type == IT_WEAPON ){
  18522. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18523. }
  18524. clif_refineui_info( sd, index );
  18525. }else{
  18526. // Failure
  18527. if (info->broadcast_failure) {
  18528. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18529. }
  18530. // Blacksmith blessings were used to prevent breaking and downgrading
  18531. if( blacksmith_amount > 0 ){
  18532. clif_refine( fd, 3, index, item->refine );
  18533. clif_refineui_info( sd, index );
  18534. // Delete the item if it is breakable
  18535. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18536. clif_refine( fd, 1, index, item->refine );
  18537. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18538. // Downgrade the item if necessary
  18539. }else if( cost->downgrade_amount > 0 ){
  18540. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18541. clif_refine( fd, 2, index, item->refine );
  18542. clif_refineui_info(sd, index);
  18543. // Only show failure, but dont do anything
  18544. }else{
  18545. clif_refine( fd, 3, index, item->refine );
  18546. clif_refineui_info( sd, index );
  18547. }
  18548. clif_misceffect( &sd->bl, 2 );
  18549. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18550. }
  18551. #endif
  18552. }
  18553. void clif_unequipall_reply( map_session_data* sd, bool failed ){
  18554. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18555. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18556. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18557. p.result = failed;
  18558. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18559. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18560. }
  18561. void clif_parse_unequipall( int fd, map_session_data* sd ){
  18562. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18563. if( pc_cant_act( sd ) ){
  18564. clif_unequipall_reply( sd, true );
  18565. return;
  18566. }
  18567. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18568. if( sd->equip_index[i] >= 0 ){
  18569. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18570. }
  18571. }
  18572. clif_unequipall_reply( sd, false );
  18573. #endif
  18574. }
  18575. void clif_stylist_response( map_session_data* sd, bool failed ){
  18576. #if PACKETVER >= 20151104
  18577. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18578. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18579. p.flag = failed;
  18580. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18581. if( !failed ){
  18582. sd->state.stylist_open = false;
  18583. }
  18584. #endif
  18585. }
  18586. bool clif_parse_stylist_buy_sub( map_session_data* sd, _look look, int16 index ){
  18587. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18588. if( list == nullptr ){
  18589. return false;
  18590. }
  18591. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18592. if( entry == nullptr ){
  18593. return false;
  18594. }
  18595. std::shared_ptr<s_stylist_costs> costs;
  18596. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18597. costs = entry->doram;
  18598. }else{
  18599. costs = entry->human;
  18600. }
  18601. if( costs == nullptr ){
  18602. return false;
  18603. }
  18604. if( sd->status.zeny < costs->price ){
  18605. return false;
  18606. }
  18607. int16 inventoryIndex = -1;
  18608. if( costs->requiredItem != 0 ){
  18609. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18610. if( inventoryIndex < 0 ){
  18611. // No other option
  18612. if( costs->requiredItemBox == 0 ){
  18613. return false;
  18614. }
  18615. // Check if the box that contains the item is in the inventory
  18616. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18617. // The box containing the item also does not exist
  18618. if( inventoryIndex < 0 ){
  18619. return false;
  18620. }
  18621. }
  18622. }else if( costs->requiredItemBox != 0 ){
  18623. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18624. if( inventoryIndex < 0 ){
  18625. return false;
  18626. }
  18627. }
  18628. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18629. return false;
  18630. }
  18631. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18632. return false;
  18633. }
  18634. switch( look ){
  18635. case LOOK_HAIR:
  18636. case LOOK_HAIR_COLOR:
  18637. case LOOK_CLOTHES_COLOR:
  18638. case LOOK_BODY2:
  18639. pc_changelook( sd, look, entry->value );
  18640. break;
  18641. case LOOK_HEAD_BOTTOM:
  18642. case LOOK_HEAD_MID:
  18643. case LOOK_HEAD_TOP: {
  18644. struct mail_message msg = {};
  18645. msg.dest_id = sd->status.char_id;
  18646. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18647. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18648. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18649. msg.item[0].nameid = entry->value;
  18650. msg.item[0].identify = 1;
  18651. msg.item[0].amount = 1;
  18652. msg.status = MAIL_NEW;
  18653. msg.type = MAIL_INBOX_NORMAL;
  18654. msg.timestamp = time( nullptr );
  18655. intif_Mail_send( 0, &msg );
  18656. } break;
  18657. }
  18658. return true;
  18659. }
  18660. void clif_parse_stylist_buy( int fd, map_session_data* sd ){
  18661. #if PACKETVER >= 20151104
  18662. #if PACKETVER >= 20180516
  18663. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18664. #else
  18665. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18666. #endif
  18667. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18668. clif_stylist_response( sd, true );
  18669. return;
  18670. }
  18671. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18672. clif_stylist_response( sd, true );
  18673. return;
  18674. }
  18675. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18676. clif_stylist_response( sd, true );
  18677. return;
  18678. }
  18679. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18680. clif_stylist_response( sd, true );
  18681. return;
  18682. }
  18683. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18684. clif_stylist_response( sd, true );
  18685. return;
  18686. }
  18687. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18688. clif_stylist_response( sd, true );
  18689. return;
  18690. }
  18691. #if PACKETVER >= 20180516
  18692. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18693. clif_stylist_response( sd, true );
  18694. return;
  18695. }
  18696. #endif
  18697. clif_stylist_response( sd, false );
  18698. #endif
  18699. }
  18700. void clif_parse_stylist_close( int fd, map_session_data* sd ){
  18701. #if PACKETVER >= 20151104
  18702. sd->state.stylist_open = false;
  18703. #endif
  18704. }
  18705. void clif_inventory_expansion_info( map_session_data* sd ){
  18706. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18707. nullpo_retv( sd );
  18708. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18709. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18710. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18711. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18712. #endif
  18713. }
  18714. enum class e_inventory_expansion_response : uint8{
  18715. ASK_CONFIRMATION = 0,
  18716. FAILED,
  18717. BUSY,
  18718. MISSING_ITEM,
  18719. MAXIMUM_REACHED
  18720. };
  18721. void clif_inventory_expansion_response( map_session_data* sd, e_inventory_expansion_response response ){
  18722. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18723. nullpo_retv( sd );
  18724. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18725. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18726. p.result = (uint8)response;
  18727. p.itemId = sd->state.inventory_expansion_confirmation;
  18728. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18729. #endif
  18730. }
  18731. void clif_parse_inventory_expansion_request( int fd, map_session_data* sd ){
  18732. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18733. // Check if player is dead or busy with other stuff
  18734. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18735. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18736. return;
  18737. }
  18738. // Check if the player already reached the maximum
  18739. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18740. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18741. return;
  18742. }
  18743. static std::map<t_itemid, uint16> items = {
  18744. // The order of entries in this list defines which will be used first
  18745. // This order and the usable items are hardcoded into the client
  18746. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18747. { ITEMID_INVENTORY_EX_EVT, 10 },
  18748. { ITEMID_INVENTORY_EX_DIS, 10 },
  18749. { ITEMID_INVENTORY_EX, 10 },
  18750. };
  18751. int16 index = -1;
  18752. bool found_over_limit = false;
  18753. for( const auto& entry : items ){
  18754. // Check if the player has the required item
  18755. index = pc_search_inventory( sd, entry.first );
  18756. // Found an item
  18757. if( index >= 0 ){
  18758. // Check if the player would exceed the maximum
  18759. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18760. found_over_limit = true;
  18761. }else{
  18762. found_over_limit = false;
  18763. sd->state.inventory_expansion_confirmation = entry.first;
  18764. sd->state.inventory_expansion_amount = entry.second;
  18765. break;
  18766. }
  18767. }
  18768. }
  18769. // Check if an item was found
  18770. if( sd->state.inventory_expansion_confirmation == 0 ){
  18771. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18772. return;
  18773. }
  18774. // Check if an item would have been found, but the player would exceed the maximum
  18775. if( found_over_limit ){
  18776. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18777. return;
  18778. }
  18779. // The player met all requirements => ask him for confirmation
  18780. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18781. #endif
  18782. }
  18783. enum class e_inventory_expansion_result : uint8{
  18784. SUCCESS = 0,
  18785. FAILED,
  18786. BUSY,
  18787. MISSING_ITEM,
  18788. MAXIMUM_REACHED
  18789. };
  18790. void clif_inventory_expansion_result( map_session_data* sd, e_inventory_expansion_result result ){
  18791. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18792. nullpo_retv( sd );
  18793. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18794. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18795. p.result = (uint8)result;
  18796. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18797. // Reset the state tracking
  18798. sd->state.inventory_expansion_confirmation = 0;
  18799. sd->state.inventory_expansion_amount = 0;
  18800. #endif
  18801. }
  18802. void clif_parse_inventory_expansion_confirm( int fd, map_session_data* sd ){
  18803. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18804. if( sd->state.inventory_expansion_confirmation == 0 ){
  18805. return;
  18806. }
  18807. // Check if player is dead
  18808. if( pc_isdead( sd ) ){
  18809. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18810. return;
  18811. }
  18812. // Check if the player already reached the maximum
  18813. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18814. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18815. return;
  18816. }
  18817. // Check if the player has the required item
  18818. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18819. // The player did not have the item anymore
  18820. if( index < 0 ){
  18821. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18822. return;
  18823. }
  18824. // Check if the player would exceed the maximum
  18825. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18826. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18827. return;
  18828. }
  18829. // Delete the required item
  18830. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18831. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18832. return;
  18833. }
  18834. // Increase the slots
  18835. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18836. // Save player data (slots) and inventory data (removed item)
  18837. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18838. // Inform the player of success
  18839. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18840. clif_inventory_expansion_info( sd );
  18841. #endif
  18842. }
  18843. void clif_parse_inventory_expansion_reject( int fd, map_session_data* sd ){
  18844. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18845. sd->state.inventory_expansion_confirmation = 0;
  18846. sd->state.inventory_expansion_amount = 0;
  18847. #endif
  18848. }
  18849. void clif_barter_open( map_session_data& sd, struct npc_data& nd ){
  18850. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18851. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18852. return;
  18853. }
  18854. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18855. if( barter == nullptr ){
  18856. return;
  18857. }
  18858. sd.state.barter_open = true;
  18859. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18860. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18861. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  18862. int16 count = 0;
  18863. for( const auto& itemPair : barter->items ){
  18864. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  18865. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18866. item->nameid = client_nameid( id->nameid );
  18867. item->type = itemtype( id->nameid );
  18868. if( itemPair.second->stockLimited ){
  18869. item->amount = itemPair.second->stock;
  18870. }else{
  18871. item->amount = -1;
  18872. }
  18873. item->weight = id->weight;
  18874. item->index = itemPair.second->index;
  18875. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18876. item->viewSprite = id->look;
  18877. item->location = pc_equippoint_sub( &sd, id.get() );
  18878. #endif
  18879. // Use a loop if someone did not start with index 0
  18880. for( const auto& requirementPair : itemPair.second->requirements ){
  18881. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18882. item->currencyNameid = client_nameid( requirement->nameid );
  18883. item->currencyAmount = requirement->amount;
  18884. // It is a normal barter, cancel after first entry
  18885. break;
  18886. }
  18887. p->packetLength += (int16)( sizeof( *item ) );
  18888. count++;
  18889. }
  18890. clif_send( p, p->packetLength, &sd.bl, SELF );
  18891. #endif
  18892. }
  18893. void clif_parse_barter_close( int fd, map_session_data* sd ){
  18894. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18895. if( sd->state.barter_open ){
  18896. sd->npc_shopid = 0;
  18897. sd->state.barter_open = false;
  18898. }
  18899. #endif
  18900. }
  18901. void clif_parse_barter_buy( int fd, map_session_data* sd ){
  18902. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18903. // No shop open
  18904. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  18905. return;
  18906. }
  18907. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18908. // Unknown shop
  18909. if( nd == nullptr ){
  18910. return;
  18911. }
  18912. // Not a barter
  18913. if( nd->subtype != NPCTYPE_BARTER ){
  18914. return;
  18915. }
  18916. // It is an extended barter
  18917. if( nd->u.barter.extended ){
  18918. return;
  18919. }
  18920. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  18921. if( barter == nullptr ){
  18922. return;
  18923. }
  18924. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  18925. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  18926. // Empty purchase list
  18927. if( entries == 0 ){
  18928. return;
  18929. }
  18930. std::vector<s_barter_purchase> purchases;
  18931. purchases.reserve( entries );
  18932. // Make sure each shop index and target item id is only used once
  18933. for( int i = 0; i < entries; i++ ){
  18934. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  18935. // Invalid shop index
  18936. if( item == nullptr ){
  18937. return;
  18938. }
  18939. for( int j = i + 1; j < entries; j++ ){
  18940. // Same shop index
  18941. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  18942. return;
  18943. }
  18944. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  18945. // Invalid shop index
  18946. if( item2 == nullptr ){
  18947. return;
  18948. }
  18949. // Same target item id
  18950. if( item->nameid == item2->nameid ){
  18951. return;
  18952. }
  18953. }
  18954. s_barter_purchase purchase = {};
  18955. purchase.item = item;
  18956. purchase.amount = p->list[i].amount;
  18957. purchases.push_back( purchase );
  18958. }
  18959. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  18960. #endif
  18961. }
  18962. void clif_barter_extended_open( map_session_data& sd, struct npc_data& nd ){
  18963. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18964. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  18965. return;
  18966. }
  18967. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18968. if( barter == nullptr ){
  18969. return;
  18970. }
  18971. sd.state.barter_extended_open = true;
  18972. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18973. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  18974. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  18975. p->items_count = 0;
  18976. for( const auto& itemPair : barter->items ){
  18977. // Needs dynamic calculation, because of variable currencies
  18978. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  18979. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18980. item->nameid = client_nameid( id->nameid );
  18981. item->type = itemtype( id->nameid );
  18982. if( itemPair.second->stockLimited ){
  18983. item->amount = itemPair.second->stock;
  18984. }else{
  18985. item->amount = -1;
  18986. }
  18987. item->weight = id->weight;
  18988. item->index = itemPair.second->index;
  18989. item->zeny = itemPair.second->price;
  18990. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18991. item->viewSprite = id->look;
  18992. item->location = pc_equippoint_sub( &sd, id.get() );
  18993. #endif
  18994. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  18995. p->items_count++;
  18996. item->currency_count = 0;
  18997. for( const auto& requirementPair : itemPair.second->requirements ){
  18998. // Needs dynamic calculation, because of variable currencies
  18999. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19000. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19001. req->nameid = requirement->nameid;
  19002. if( requirement->refine >= 0 ){
  19003. req->refine_level = requirement->refine;
  19004. }else{
  19005. req->refine_level = 0;
  19006. }
  19007. req->amount = requirement->amount;
  19008. req->type = itemtype( requirement->nameid );
  19009. p->packetLength += (int16)( sizeof( *req ) );
  19010. item->currency_count++;
  19011. }
  19012. }
  19013. clif_send( p, p->packetLength, &sd.bl, SELF );
  19014. #endif
  19015. }
  19016. void clif_parse_barter_extended_close( int fd, map_session_data* sd ){
  19017. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19018. if( sd->state.barter_extended_open ){
  19019. sd->npc_shopid = 0;
  19020. sd->state.barter_extended_open = false;
  19021. }
  19022. #endif
  19023. }
  19024. void clif_parse_barter_extended_buy( int fd, map_session_data* sd ){
  19025. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19026. // No shop open
  19027. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19028. return;
  19029. }
  19030. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19031. // Unknown shop
  19032. if( nd == nullptr ){
  19033. return;
  19034. }
  19035. // Not a barter
  19036. if( nd->subtype != NPCTYPE_BARTER ){
  19037. return;
  19038. }
  19039. // Not an extended barter
  19040. if( !nd->u.barter.extended ){
  19041. return;
  19042. }
  19043. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19044. if( barter == nullptr ){
  19045. return;
  19046. }
  19047. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19048. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19049. // Empty purchase list
  19050. if( entries == 0 ){
  19051. return;
  19052. }
  19053. std::vector<s_barter_purchase> purchases;
  19054. purchases.reserve( entries );
  19055. // Make sure each shop index and target item id is only used once
  19056. for( int i = 0; i < entries; i++ ){
  19057. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19058. // Invalid shop index
  19059. if( item == nullptr ){
  19060. return;
  19061. }
  19062. for( int j = i + 1; j < entries; j++ ){
  19063. // Same shop index
  19064. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19065. return;
  19066. }
  19067. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19068. // Invalid shop index
  19069. if( item2 == nullptr ){
  19070. return;
  19071. }
  19072. // Same target item id
  19073. if( item->nameid == item2->nameid ){
  19074. return;
  19075. }
  19076. }
  19077. s_barter_purchase purchase = {};
  19078. purchase.item = item;
  19079. purchase.amount = p->list[i].amount;
  19080. purchases.push_back( purchase );
  19081. }
  19082. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19083. #endif
  19084. }
  19085. void clif_summon_init(struct mob_data& md) {
  19086. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19087. struct block_list* master_bl = battle_get_master(&md.bl);
  19088. if( master_bl == nullptr ){
  19089. return;
  19090. }
  19091. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19092. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19093. p.summonAID = md.bl.id;
  19094. p.CurrentHP = md.status.hp;
  19095. p.MaxHP = md.status.max_hp;
  19096. clif_send( &p, sizeof( p ), master_bl, SELF );
  19097. #endif
  19098. }
  19099. void clif_summon_hp_bar(struct mob_data& md) {
  19100. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19101. struct block_list* master_bl = battle_get_master(&md.bl);
  19102. if( master_bl == nullptr ){
  19103. return;
  19104. }
  19105. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19106. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19107. p.summonAID = md.bl.id;
  19108. p.VarId = SP_HP; // HP parameter
  19109. p.Value = md.status.hp;
  19110. clif_send( &p, sizeof( p ), master_bl, SELF );
  19111. #endif
  19112. }
  19113. void clif_laphine_synthesis_open( map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19114. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19115. nullpo_retv( sd );
  19116. sd->state.laphine_synthesis = synthesis->item_id;
  19117. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19118. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19119. p.itemId = client_nameid( synthesis->item_id );
  19120. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19121. #endif
  19122. }
  19123. void clif_parse_laphine_synthesis_close( int fd, map_session_data* sd ){
  19124. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19125. sd->state.laphine_synthesis = 0;
  19126. #endif
  19127. }
  19128. enum e_laphine_synthesis_result : int16{
  19129. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19130. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19131. LAPHINE_SYNTHESIS_ITEM = 7
  19132. };
  19133. void clif_laphine_synthesis_result( map_session_data* sd, enum e_laphine_synthesis_result result ){
  19134. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19135. nullpo_retv( sd );
  19136. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19137. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19138. p.result = result;
  19139. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19140. #endif
  19141. }
  19142. void clif_parse_laphine_synthesis( int fd, map_session_data* sd ){
  19143. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19144. if( sd->state.laphine_synthesis == 0 ){
  19145. return;
  19146. }
  19147. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19148. if( sd->state.laphine_synthesis != p->itemId ){
  19149. return;
  19150. }
  19151. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19152. if( synthesis == nullptr ){
  19153. return;
  19154. }
  19155. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19156. // Player sent more or less than actually required
  19157. if( count != synthesis->requiredRequirements ){
  19158. return;
  19159. }
  19160. // Check for duplicates
  19161. for( size_t i = 0; i < count; i++ ){
  19162. for( size_t j = i + 1; j < count; j++ ){
  19163. if( p->items[i].index == p->items[j].index ){
  19164. return;
  19165. }
  19166. }
  19167. }
  19168. for( size_t i = 0; i < count; i++ ){
  19169. int16 index = server_index( p->items[i].index );
  19170. if( index >= MAX_INVENTORY ){
  19171. return;
  19172. }
  19173. if( sd->inventory_data[i] == nullptr ){
  19174. return;
  19175. }
  19176. struct item* item = &sd->inventory.u.items_inventory[index];
  19177. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19178. if( requirement == nullptr ){
  19179. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19180. return;
  19181. }
  19182. if( p->items[i].count != requirement->amount ){
  19183. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19184. return;
  19185. }
  19186. if( item->amount < requirement->amount ){
  19187. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19188. return;
  19189. }
  19190. if( item->refine < synthesis->minimumRefine ){
  19191. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19192. return;
  19193. }
  19194. if( item->refine > synthesis->maximumRefine ){
  19195. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19196. return;
  19197. }
  19198. if( item->equip != 0 ){
  19199. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19200. return;
  19201. }
  19202. if( item->equipSwitch != 0 ){
  19203. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19204. return;
  19205. }
  19206. }
  19207. // If triggered from item
  19208. if( sd->itemid == sd->state.laphine_synthesis ){
  19209. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19210. if( index < 0 ){
  19211. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19212. return;
  19213. }
  19214. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19215. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19216. return;
  19217. }
  19218. }
  19219. }
  19220. for( size_t i = 0; i < count; i++ ){
  19221. int16 index = server_index( p->items[i].index );
  19222. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19223. return;
  19224. }
  19225. }
  19226. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19227. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19228. #endif
  19229. }
  19230. void clif_laphine_upgrade_open( map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19231. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19232. nullpo_retv( sd );
  19233. sd->state.laphine_upgrade = upgrade->item_id;
  19234. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19235. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19236. p.itemId = client_nameid( upgrade->item_id );
  19237. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19238. #endif
  19239. }
  19240. void clif_parse_laphine_upgrade_close( int fd, map_session_data* sd ){
  19241. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19242. sd->state.laphine_upgrade = 0;
  19243. #endif
  19244. }
  19245. void clif_laphine_upgrade_result( map_session_data *sd, bool failed ){
  19246. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19247. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19248. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19249. p.result = failed;
  19250. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19251. #endif
  19252. }
  19253. static void clif_item_preview( map_session_data *sd, int16 index ){
  19254. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19255. nullpo_retv( sd );
  19256. struct item* item = &sd->inventory.u.items_inventory[index];
  19257. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19258. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19259. p.index = client_index( index );
  19260. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19261. p.isDamaged = item->attribute != 0;
  19262. #endif
  19263. p.refiningLevel = item->refine;
  19264. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19265. p.grade = item->enchantgrade;
  19266. #endif
  19267. clif_addcards( &p.slot, item );
  19268. clif_add_random_options( p.option_data, *item );
  19269. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19270. #endif
  19271. }
  19272. void clif_parse_laphine_upgrade( int fd, map_session_data* sd ){
  19273. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19274. if( sd->state.laphine_upgrade == 0 ){
  19275. return;
  19276. }
  19277. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19278. if( sd->state.laphine_upgrade != p->itemId ){
  19279. return;
  19280. }
  19281. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19282. if( upgrade == nullptr ){
  19283. return;
  19284. }
  19285. uint16 index = server_index( p->index );
  19286. if( index >= MAX_INVENTORY ){
  19287. return;
  19288. }
  19289. if( sd->inventory_data[index] == nullptr ){
  19290. return;
  19291. }
  19292. struct item* item = &sd->inventory.u.items_inventory[index];
  19293. // Not a valid target item
  19294. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19295. clif_laphine_upgrade_result( sd, true );
  19296. return;
  19297. }
  19298. // If target item is not identified
  19299. if( item->identify == 0 ){
  19300. clif_laphine_upgrade_result( sd, true );
  19301. return;
  19302. }
  19303. // If target item is equipped
  19304. if( item->equip != 0 ){
  19305. clif_laphine_upgrade_result( sd, true );
  19306. return;
  19307. }
  19308. // If target item is in equipswitch
  19309. if( item->equipSwitch != 0 ){
  19310. clif_laphine_upgrade_result( sd, true );
  19311. return;
  19312. }
  19313. // Check minimum refine requirement
  19314. if( item->refine < upgrade->minimumRefine ){
  19315. clif_laphine_upgrade_result( sd, true );
  19316. return;
  19317. }
  19318. // Check maximum refine requirement
  19319. if( item->refine > upgrade->maximumRefine ){
  19320. clif_laphine_upgrade_result( sd, true );
  19321. return;
  19322. }
  19323. // If no cards are allowed
  19324. if( !upgrade->cardsAllowed ){
  19325. for( int i = 0; i < MAX_SLOTS; i++ ){
  19326. if( item->card[i] != 0 ){
  19327. clif_laphine_upgrade_result( sd, true );
  19328. return;
  19329. }
  19330. }
  19331. }
  19332. // If random options are required
  19333. if( upgrade->requiredRandomOptions > 0 ){
  19334. int i;
  19335. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19336. if( item->option[i].id != 0 ){
  19337. break;
  19338. }
  19339. }
  19340. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19341. clif_laphine_upgrade_result( sd, true );
  19342. return;
  19343. }
  19344. }
  19345. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19346. if( index2 < 0 ){
  19347. clif_laphine_upgrade_result( sd, true );
  19348. return;
  19349. }
  19350. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19351. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19352. return;
  19353. }
  19354. }
  19355. // Log removal of item
  19356. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19357. // Visually remove it from the client
  19358. clif_delitem( sd, index, 1, 0 );
  19359. // Apply the random options
  19360. if( upgrade->randomOptionGroup != nullptr ){
  19361. upgrade->randomOptionGroup->apply( *item );
  19362. }
  19363. // Change the refine rate if needed
  19364. if( upgrade->resultRefine > 0 ){
  19365. // Absolute refine level change
  19366. item->refine = max( item->refine, upgrade->resultRefine );
  19367. }else if( upgrade->resultRefineMaximum > 0 ){
  19368. // If a minimum is specified it can also downgrade
  19369. if( upgrade->resultRefineMinimum ){
  19370. item->refine = rnd_value( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum );
  19371. }else{
  19372. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19373. item->refine = rnd_value( item->refine, upgrade->resultRefineMaximum );
  19374. }
  19375. }else if( upgrade->resultRefineMinimum > 0 ){
  19376. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19377. item->refine = rnd_value( upgrade->resultRefineMinimum, MAX_REFINE );
  19378. }
  19379. // Log retrieving the item again -> with the new options
  19380. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19381. // Make it visible for the client again
  19382. clif_additem( sd, index, 1, 0 );
  19383. // Open a preview of the item
  19384. clif_item_preview( sd, index );
  19385. // Tell the client we are done
  19386. clif_laphine_upgrade_result( sd, false );
  19387. #endif
  19388. }
  19389. void clif_enchantgrade_add( map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19390. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19391. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19392. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19393. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19394. if( index < UINT16_MAX ){
  19395. p->index = client_index( index );
  19396. if( sd.inventory.u.items_inventory[index].refine >= gradeLevel->refine ){
  19397. p->success_chance = gradeLevel->chance / 100;
  19398. }else{
  19399. p->success_chance = 0;
  19400. }
  19401. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19402. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19403. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19404. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19405. // Not displayed by client
  19406. p->protect_itemid = 0;
  19407. p->protect_amount = 0;
  19408. int i = 0;
  19409. for( const auto& pair : gradeLevel->options ){
  19410. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19411. p->material_info[i].nameid = client_nameid( option->item );
  19412. p->material_info[i].amount = option->amount;
  19413. p->material_info[i].price = option->zeny;
  19414. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19415. p->material_info[i].breakable = option->breaking_rate > 0;
  19416. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19417. i++;
  19418. }
  19419. }else{
  19420. p->index = -1;
  19421. p->success_chance = 0;
  19422. p->blessing_info.id = 0;
  19423. p->blessing_info.amount = 0;
  19424. p->blessing_info.max_blessing = 0;
  19425. p->blessing_info.bonus = 0;
  19426. p->protect_itemid = 0;
  19427. p->protect_amount = 0;
  19428. }
  19429. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19430. #endif
  19431. }
  19432. void clif_parse_enchantgrade_add( int fd, map_session_data* sd ){
  19433. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19434. nullpo_retv( sd );
  19435. if( !sd->state.enchantgrade_open ){
  19436. return;
  19437. }
  19438. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19439. uint16 index = server_index( p->index );
  19440. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19441. return;
  19442. }
  19443. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19444. // Unsupported item type - no answer, because client should have actually prevented this request
  19445. if( enchantgrade == nullptr ){
  19446. return;
  19447. }
  19448. // Item can't be enhanced
  19449. if( !sd->inventory_data[index]->flag.gradable ){
  19450. return;
  19451. }
  19452. uint16 level = 0;
  19453. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19454. level = sd->inventory_data[index]->weapon_level;
  19455. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19456. level = sd->inventory_data[index]->armor_level;
  19457. }
  19458. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19459. // Cannot upgrade this weapon or armor level
  19460. if( enchantgradelevels == enchantgrade->levels.end() ){
  19461. clif_enchantgrade_add( *sd );
  19462. return;
  19463. }
  19464. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19465. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19466. if( enchantgradelevel == nullptr ){
  19467. return;
  19468. }
  19469. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19470. #endif
  19471. }
  19472. /// <summary>
  19473. /// Sends the result for trying to enchant an item
  19474. /// </summary>
  19475. /// <param name="sd">The player session</param>
  19476. /// <param name="index">The target item</param>
  19477. /// <param name="result">
  19478. /// 0= The grade has been successfully upgraded.
  19479. /// 1= Refinement failed.
  19480. /// 2= The refine level has decreased.
  19481. /// 3= Equipment destroyed.
  19482. /// 4= The equipment is protected.
  19483. /// </param>
  19484. void clif_enchantgrade_result( map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19485. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19486. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19487. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19488. p.index = client_index( index );
  19489. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19490. p.result = result;
  19491. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19492. #endif
  19493. }
  19494. void clif_enchantgrade_announce( map_session_data& sd, struct item& item, bool success ){
  19495. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19496. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19497. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19498. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19499. p.itemId = client_nameid( item.nameid );
  19500. p.grade = item.enchantgrade;
  19501. p.status = success;
  19502. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19503. #endif
  19504. }
  19505. void clif_parse_enchantgrade_start( int fd, map_session_data* sd ){
  19506. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19507. nullpo_retv( sd );
  19508. if( !sd->state.enchantgrade_open ){
  19509. return;
  19510. }
  19511. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19512. uint16 index = server_index( p->index );
  19513. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19514. return;
  19515. }
  19516. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19517. // Unsupported item type - no answer
  19518. if( enchantgrade == nullptr ){
  19519. return;
  19520. }
  19521. uint16 level = 0;
  19522. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19523. level = sd->inventory_data[index]->weapon_level;
  19524. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19525. level = sd->inventory_data[index]->armor_level;
  19526. }
  19527. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19528. // Cannot upgrade this weapon or armor level - no answer
  19529. if( enchantgradelevels == enchantgrade->levels.end() ){
  19530. return;
  19531. }
  19532. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19533. // Cannot increase enchantgrade any further - no answer
  19534. if( enchantgradelevel == nullptr ){
  19535. return;
  19536. }
  19537. // Not refined enough
  19538. if( sd->inventory.u.items_inventory[index].refine < enchantgradelevel->refine ){
  19539. return;
  19540. }
  19541. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19542. // Unknown option id - no answer
  19543. if( option == nullptr ){
  19544. return;
  19545. }
  19546. // Not enough zeny
  19547. if( sd->status.zeny < option->zeny ){
  19548. return;
  19549. }
  19550. uint16 totalChance = enchantgradelevel->chance;
  19551. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19552. std::unordered_map<uint16, uint16> requiredItems;
  19553. if( p->blessing_flag ){
  19554. // If the catalysator item is the same as the option item build the sum of amounts
  19555. if( enchantgradelevel->catalyst.item == option->item ){
  19556. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19557. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19558. if( index < 0 ){
  19559. return;
  19560. }
  19561. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19562. return;
  19563. }
  19564. requiredItems[index] = amount;
  19565. }else{
  19566. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19567. // Check catalysator item
  19568. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19569. if( index < 0 ){
  19570. return;
  19571. }
  19572. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19573. return;
  19574. }
  19575. requiredItems[index] = amount;
  19576. // Check option item
  19577. index = pc_search_inventory( sd, option->item );
  19578. if( index < 0 ){
  19579. return;
  19580. }
  19581. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19582. return;
  19583. }
  19584. requiredItems[index] = option->amount;
  19585. }
  19586. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19587. }else{
  19588. // Check option item
  19589. int16 index = pc_search_inventory( sd, option->item );
  19590. if( index < 0 ){
  19591. return;
  19592. }
  19593. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19594. return;
  19595. }
  19596. requiredItems[index] = option->amount;
  19597. }
  19598. // All items should be there, start deleting
  19599. for( const auto& pair : requiredItems ){
  19600. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19601. return;
  19602. }
  19603. }
  19604. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE, nullptr ) > 0 ){
  19605. return;
  19606. }
  19607. if( rnd()%10000 < totalChance ){
  19608. // Log removal of item
  19609. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19610. // Increase enchantgrade
  19611. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19612. // On successful enchantgrade increase the refine is reset
  19613. sd->inventory.u.items_inventory[index].refine = 0;
  19614. // Log retrieving the item again -> with the new refine and enchantgrade
  19615. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19616. // Show success
  19617. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19618. // Check if it has to be announced
  19619. if( enchantgradelevel->announceSuccess ){
  19620. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19621. }
  19622. }else{
  19623. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19624. if( enchantgradelevel->announceFail ){
  19625. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19626. }
  19627. // Delete the item if it is breakable
  19628. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19629. // Delete the item
  19630. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19631. // Show failure
  19632. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19633. // Downgrade the item if necessary
  19634. }else if( option->downgrade_amount > 0 ){
  19635. // Log removal of item
  19636. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19637. // Decrease refine level
  19638. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19639. // Log retrieving the item again -> with the new refine
  19640. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19641. // Show downgrade
  19642. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19643. // Only show failure, but dont do anything
  19644. }else{
  19645. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19646. }
  19647. }
  19648. #endif
  19649. }
  19650. void clif_parse_enchantgrade_close( int fd, map_session_data* sd ){
  19651. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19652. nullpo_retv( sd );
  19653. sd->state.enchantgrade_open = false;
  19654. #endif
  19655. }
  19656. void clif_reputation_type( map_session_data& sd, int64 type, int64 points ){
  19657. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19658. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19659. p->packetType = HEADER_ZC_REPUTE_INFO;
  19660. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19661. p->success = true;
  19662. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19663. entry->type = type;
  19664. entry->points = points;
  19665. clif_send( p, p->packetLength, &sd.bl, SELF );
  19666. #endif
  19667. }
  19668. void clif_reputation_list( map_session_data& sd ){
  19669. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19670. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19671. p->packetType = HEADER_ZC_REPUTE_INFO;
  19672. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19673. p->success = true;
  19674. size_t index = 0;
  19675. for( const auto& entry : reputation_db ){
  19676. std::shared_ptr<s_reputation> reputation = entry.second;
  19677. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19678. list_entry->type = reputation->id;
  19679. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19680. p->packetLength += sizeof( *list_entry );
  19681. index++;
  19682. }
  19683. clif_send( p, p->packetLength, &sd.bl, SELF );
  19684. #endif
  19685. }
  19686. void clif_item_reform_open( map_session_data& sd, t_itemid item ){
  19687. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19688. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19689. p.packetType = HEADER_ZC_OPEN_REFORM_UI;
  19690. p.itemId = item;
  19691. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19692. sd.state.item_reform = item;
  19693. #endif
  19694. }
  19695. void clif_parse_item_reform_close( int fd, map_session_data* sd ){
  19696. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19697. sd->state.item_reform = 0;
  19698. #endif
  19699. }
  19700. void clif_item_reform_result( map_session_data& sd, uint16 index, uint8 result ){
  19701. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19702. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19703. p.packetType = HEADER_ZC_ITEM_REFORM_ACK;
  19704. p.index = client_index( index );
  19705. p.result = result;
  19706. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19707. if( result == 0 ){
  19708. // Client closes the window on success
  19709. sd.state.item_reform = 0;
  19710. }
  19711. #endif
  19712. }
  19713. void clif_parse_item_reform_start( int fd, map_session_data* sd ){
  19714. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19715. // Not opened
  19716. if( sd->state.item_reform == 0 ){
  19717. return;
  19718. }
  19719. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19720. // Item mismatch
  19721. if( p->itemId != sd->state.item_reform ){
  19722. return;
  19723. }
  19724. uint16 index = server_index( p->index );
  19725. if( index >= MAX_INVENTORY ){
  19726. return;
  19727. }
  19728. if( sd->inventory_data[index] == nullptr ){
  19729. return;
  19730. }
  19731. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19732. if( reform == nullptr ){
  19733. return;
  19734. }
  19735. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19736. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19737. if( base == nullptr ){
  19738. return;
  19739. }
  19740. // If target item is not identified
  19741. if( selected_item.identify == 0 ){
  19742. return;
  19743. }
  19744. // If target item is equipped
  19745. if( selected_item.equip != 0 ){
  19746. return;
  19747. }
  19748. // Check minimum refine requirement
  19749. if( selected_item.refine < base->minimumRefine ){
  19750. return;
  19751. }
  19752. // Check maximum refine requirement
  19753. if( selected_item.refine > base->maximumRefine ){
  19754. return;
  19755. }
  19756. // If no cards are allowed
  19757. if( !base->cardsAllowed ){
  19758. for( int i = 0; i < MAX_SLOTS; i++ ){
  19759. if( selected_item.card[i] != 0 ){
  19760. return;
  19761. }
  19762. }
  19763. }
  19764. // If random options are required
  19765. if( base->requiredRandomOptions > 0 ){
  19766. int i;
  19767. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19768. if( selected_item.option[i].id != 0 ){
  19769. break;
  19770. }
  19771. }
  19772. if( ( i + 1 ) < base->requiredRandomOptions ){
  19773. return;
  19774. }
  19775. }
  19776. std::unordered_map<uint16, uint16> materials;
  19777. // Check if all materials exist
  19778. for( const auto& material : base->materials ){
  19779. int16 material_index = pc_search_inventory( sd, material.first );
  19780. if( material_index < 0 ){
  19781. return;
  19782. }
  19783. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19784. return;
  19785. }
  19786. materials[material_index] = material.second;
  19787. }
  19788. // Remove the material
  19789. for( const auto& material : materials ){
  19790. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19791. return;
  19792. }
  19793. }
  19794. // If triggered from item
  19795. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19796. return;
  19797. }
  19798. // Log removal of item
  19799. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19800. // Visually remove it from the client
  19801. clif_delitem( sd, index, 1, 0 );
  19802. // Apply the random options
  19803. if( base->randomOptionGroup != nullptr ){
  19804. base->randomOptionGroup->apply( selected_item );
  19805. }
  19806. // Change the refine rate if needed
  19807. if( base->refineChange != 0 ){
  19808. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19809. }
  19810. // Remove all cards and socket enchants
  19811. if( base->clearSlots ){
  19812. for( int i = 0; i < MAX_SLOTS; i++ ){
  19813. selected_item.card[i] = 0;
  19814. }
  19815. }
  19816. // Remove the current enchantgrade
  19817. if( base->removeEnchantgrade ){
  19818. selected_item.enchantgrade = 0;
  19819. }
  19820. // Finally change the item id
  19821. selected_item.nameid = base->resultItemId;
  19822. // Link inventory data cache to the new item
  19823. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19824. // Log retrieving the item again -> with the new options
  19825. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19826. // Make it visible for the client again
  19827. clif_additem( sd, index, 1, 0 );
  19828. clif_item_reform_result( *sd, index, 0 );
  19829. #endif
  19830. }
  19831. void clif_enchantwindow_open( map_session_data& sd, uint64 clientLuaIndex ){
  19832. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19833. // Hardcoded clientside check
  19834. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19835. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  19836. sd.state.item_enchant_index = 0;
  19837. return;
  19838. }
  19839. struct PACKET_ZC_UI_OPEN_V3 p = {};
  19840. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19841. p.type = OUT_UI_ENCHANT;
  19842. p.data = clientLuaIndex;
  19843. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19844. sd.state.item_enchant_index = clientLuaIndex;
  19845. #endif
  19846. }
  19847. void clif_enchantwindow_result( map_session_data& sd, bool success, t_itemid enchant = 0 ){
  19848. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19849. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  19850. p.packetType = HEADER_ZC_RESPONSE_ENCHANT;
  19851. if( success ){
  19852. p.messageId = C_ENCHANT_SUCCESS;
  19853. }else{
  19854. p.messageId = C_ENCHANT_FAILURE;
  19855. }
  19856. p.enchantItemId = enchant;
  19857. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19858. sd.state.item_enchant_index = 0;
  19859. #endif
  19860. }
  19861. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  19862. if( selected_item.equip != 0 ){
  19863. return false;
  19864. }
  19865. if( selected_item.equipSwitch != 0 ){
  19866. return false;
  19867. }
  19868. if( selected_item.attribute != 0 ){
  19869. return false;
  19870. }
  19871. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  19872. return false;
  19873. }
  19874. if( selected_item.refine < enchant->minimumRefine ){
  19875. return false;
  19876. }
  19877. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  19878. return false;
  19879. }
  19880. if( !enchant->allowRandomOptions ){
  19881. for( const s_item_randomoption& option : selected_item.option ){
  19882. if( option.id != 0 ){
  19883. return false;
  19884. }
  19885. }
  19886. }
  19887. return true;
  19888. }
  19889. void clif_parse_enchantwindow_general( int fd, map_session_data* sd ){
  19890. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19891. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  19892. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19893. return;
  19894. }
  19895. uint16 index = server_index( p->index );
  19896. if( index >= MAX_INVENTORY ){
  19897. return;
  19898. }
  19899. if( sd->inventory_data[index] == nullptr ){
  19900. return;
  19901. }
  19902. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19903. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  19904. if( enchant == nullptr ){
  19905. return;
  19906. }
  19907. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19908. return;
  19909. }
  19910. uint16 slot = MAX_SLOTS;
  19911. for( uint16 nextSlot : enchant->order ){
  19912. if( selected_item.card[nextSlot] == 0 ){
  19913. slot = nextSlot;
  19914. break;
  19915. }
  19916. }
  19917. if( slot == MAX_SLOTS ){
  19918. return;
  19919. }
  19920. if( slot < sd->inventory_data[index]->slots ){
  19921. return;
  19922. }
  19923. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19924. if( enchant_slot == nullptr ){
  19925. return;
  19926. }
  19927. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  19928. if( enchants_for_enchantgrade == nullptr ){
  19929. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  19930. clif_enchantwindow_result( *sd, false );
  19931. return;
  19932. }
  19933. if( sd->status.zeny < enchant_slot->normal.zeny ){
  19934. return;
  19935. }
  19936. std::unordered_map<uint16, uint16> materials;
  19937. for( const auto& entry : enchant_slot->normal.materials ){
  19938. int16 idx = pc_search_inventory( sd, entry.first );
  19939. if( idx < 0 ){
  19940. return;
  19941. }
  19942. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19943. return;
  19944. }
  19945. materials[idx] = entry.second;
  19946. }
  19947. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  19948. return;
  19949. }
  19950. for( const auto& entry : materials ){
  19951. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  19952. return;
  19953. }
  19954. }
  19955. uint32 chance = enchant_slot->normal.chance;
  19956. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  19957. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  19958. }
  19959. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  19960. clif_enchantwindow_result( *sd, false );
  19961. return;
  19962. }
  19963. // Log removal of item
  19964. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  19965. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  19966. bool enchanted = false;
  19967. for( int i = 0; i < maximum; i++ ){
  19968. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19969. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  19970. selected_item.card[slot] = normal_enchant->item_id;
  19971. enchanted = true;
  19972. break;
  19973. }
  19974. }
  19975. if( !enchanted ){
  19976. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19977. selected_item.card[slot] = normal_enchant->item_id;
  19978. }
  19979. // Log retrieving the item again -> with the new enchant
  19980. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  19981. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  19982. #endif
  19983. }
  19984. void clif_parse_enchantwindow_perfect( int fd, map_session_data* sd ){
  19985. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19986. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  19987. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19988. return;
  19989. }
  19990. uint16 index = server_index( p->index );
  19991. if( index >= MAX_INVENTORY ){
  19992. return;
  19993. }
  19994. if( sd->inventory_data[index] == nullptr ){
  19995. return;
  19996. }
  19997. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19998. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  19999. if( enchant == nullptr ){
  20000. return;
  20001. }
  20002. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20003. return;
  20004. }
  20005. uint16 slot = MAX_SLOTS;
  20006. for( uint16 nextSlot : enchant->order ){
  20007. if( selected_item.card[nextSlot] == 0 ){
  20008. slot = nextSlot;
  20009. break;
  20010. }
  20011. }
  20012. if( slot == MAX_SLOTS ){
  20013. return;
  20014. }
  20015. if( slot < sd->inventory_data[index]->slots ){
  20016. return;
  20017. }
  20018. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20019. if( enchant_slot == nullptr ){
  20020. return;
  20021. }
  20022. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->itemId );
  20023. if( perfect_enchant == nullptr ){
  20024. return;
  20025. }
  20026. if( sd->status.zeny < perfect_enchant->zeny ){
  20027. return;
  20028. }
  20029. std::unordered_map<uint16, uint16> materials;
  20030. for( const auto& entry : perfect_enchant->materials ){
  20031. int16 idx = pc_search_inventory( sd, entry.first );
  20032. if( idx < 0 ){
  20033. return;
  20034. }
  20035. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20036. return;
  20037. }
  20038. materials[idx] = entry.second;
  20039. }
  20040. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20041. return;
  20042. }
  20043. for( const auto& entry : materials ){
  20044. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20045. return;
  20046. }
  20047. }
  20048. // Log removal of item
  20049. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20050. selected_item.card[slot] = perfect_enchant->item_id;
  20051. // Log retrieving the item again -> with the new enchant
  20052. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20053. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20054. #endif
  20055. }
  20056. void clif_parse_enchantwindow_upgrade( int fd, map_session_data* sd ){
  20057. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20058. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20059. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20060. return;
  20061. }
  20062. uint16 index = server_index( p->index );
  20063. if( index >= MAX_INVENTORY ){
  20064. return;
  20065. }
  20066. if( sd->inventory_data[index] == nullptr ){
  20067. return;
  20068. }
  20069. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20070. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20071. if( enchant == nullptr ){
  20072. return;
  20073. }
  20074. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20075. return;
  20076. }
  20077. uint16 slot = p->slot;
  20078. if( slot >= MAX_SLOTS ){
  20079. return;
  20080. }
  20081. if( slot < sd->inventory_data[index]->slots ){
  20082. return;
  20083. }
  20084. if( selected_item.card[slot] == 0 ){
  20085. return;
  20086. }
  20087. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20088. if( enchant_slot == nullptr ){
  20089. return;
  20090. }
  20091. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20092. if( upgrade == nullptr ){
  20093. return;
  20094. }
  20095. if( sd->status.zeny < upgrade->zeny ){
  20096. return;
  20097. }
  20098. std::unordered_map<uint16, uint16> materials;
  20099. for( const auto& entry : upgrade->materials ){
  20100. int16 idx = pc_search_inventory( sd, entry.first );
  20101. if( idx < 0 ){
  20102. return;
  20103. }
  20104. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20105. return;
  20106. }
  20107. materials[idx] = entry.second;
  20108. }
  20109. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20110. return;
  20111. }
  20112. for( const auto& entry : materials ){
  20113. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20114. return;
  20115. }
  20116. }
  20117. // Log removal of item
  20118. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20119. selected_item.card[slot] = upgrade->upgrade_item_id;
  20120. // Log retrieving the item again -> with the new enchant
  20121. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20122. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20123. #endif
  20124. }
  20125. void clif_parse_enchantwindow_reset( int fd, map_session_data* sd ){
  20126. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20127. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20128. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20129. return;
  20130. }
  20131. uint16 index = server_index( p->index );
  20132. if( index >= MAX_INVENTORY ){
  20133. return;
  20134. }
  20135. if( sd->inventory_data[index] == nullptr ){
  20136. return;
  20137. }
  20138. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20139. if( selected_item.equip != 0 ){
  20140. return;
  20141. }
  20142. if( selected_item.equipSwitch != 0 ){
  20143. return;
  20144. }
  20145. if( selected_item.attribute != 0 ){
  20146. return;
  20147. }
  20148. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20149. if( enchant == nullptr ){
  20150. return;
  20151. }
  20152. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20153. return;
  20154. }
  20155. if( selected_item.refine < enchant->minimumRefine ){
  20156. return;
  20157. }
  20158. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20159. return;
  20160. }
  20161. bool is_enchanted = false;
  20162. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20163. if( selected_item.card[i] != 0 ){
  20164. is_enchanted = true;
  20165. break;
  20166. }
  20167. }
  20168. if( !is_enchanted ){
  20169. return;
  20170. }
  20171. if( sd->status.zeny < enchant->reset.zeny ){
  20172. return;
  20173. }
  20174. std::unordered_map<uint16, uint16> materials;
  20175. for( const auto& entry : enchant->reset.materials ){
  20176. int16 idx = pc_search_inventory( sd, entry.first );
  20177. if( idx < 0 ){
  20178. return;
  20179. }
  20180. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20181. return;
  20182. }
  20183. materials[idx] = entry.second;
  20184. }
  20185. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20186. return;
  20187. }
  20188. for( const auto& entry : materials ){
  20189. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20190. return;
  20191. }
  20192. }
  20193. uint32 chance = enchant->reset.chance;
  20194. if( chance == 0 ){
  20195. return;
  20196. }
  20197. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20198. clif_enchantwindow_result( *sd, false );
  20199. return;
  20200. }
  20201. // Log removal of item
  20202. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20203. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20204. selected_item.card[i] = 0;
  20205. }
  20206. // Log retrieving the item again -> with the new enchant
  20207. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20208. clif_enchantwindow_result( *sd, true );
  20209. #endif
  20210. }
  20211. void clif_parse_enchantwindow_close( int fd, map_session_data* sd ){
  20212. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20213. sd->state.item_enchant_index = 0;
  20214. #endif
  20215. }
  20216. void clif_parse_itempackage_select( int fd, map_session_data* sd ){
  20217. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20218. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20219. if( p->AID != sd->status.account_id ){
  20220. return;
  20221. }
  20222. uint16 index = server_index( p->index );
  20223. if( index >= MAX_INVENTORY ){
  20224. return;
  20225. }
  20226. if( sd->inventory_data[index] == nullptr ){
  20227. return;
  20228. }
  20229. if( sd->inventory_data[index]->nameid != p->itemID ){
  20230. return;
  20231. }
  20232. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20233. return;
  20234. }
  20235. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20236. if( package == nullptr ){
  20237. return;
  20238. }
  20239. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20240. if( group == nullptr ){
  20241. return;
  20242. }
  20243. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20244. return;
  20245. }
  20246. for( const auto& entry : group->items ){
  20247. struct item item = {};
  20248. item.nameid = entry.second->item_id;
  20249. item.identify = 1;
  20250. item.refine = (char)entry.second->refine;
  20251. if( entry.second->rentalhours ){
  20252. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20253. }
  20254. // Check if it is a pet egg
  20255. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20256. if( pet != nullptr ){
  20257. for( int i = 0; i < entry.second->amount; i++ ){
  20258. pet_create_egg( sd, item.nameid );
  20259. }
  20260. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20261. for( int i = 0; i < entry.second->amount; i++ ){
  20262. // New random options on each iteration
  20263. if( entry.second->randomOptionGroup != nullptr ){
  20264. entry.second->randomOptionGroup->apply( item );
  20265. }
  20266. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20267. }
  20268. }else{
  20269. if( entry.second->randomOptionGroup != nullptr ){
  20270. entry.second->randomOptionGroup->apply( item );
  20271. }
  20272. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20273. }
  20274. }
  20275. #endif
  20276. }
  20277. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20278. {
  20279. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20280. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20281. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20282. p.itemId = itemId;
  20283. p.refine_level = level;
  20284. p.status = (int8)success;
  20285. if (battle_config.broadcast_hide_name) {
  20286. std::string dispname = clif_hide_name(sd.status.name);
  20287. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20288. }
  20289. else {
  20290. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20291. }
  20292. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20293. #endif
  20294. }
  20295. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20296. #if PACKETVER >= 20160316
  20297. nullpo_retv(sd);
  20298. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20299. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20300. return;
  20301. }
  20302. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20303. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20304. #endif
  20305. }
  20306. void clif_captcha_upload_request(map_session_data &sd) {
  20307. #if PACKETVER >= 20160330
  20308. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20309. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20310. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20311. if (sd.captcha_upload.cd != nullptr) {
  20312. p.captchaFlag = 0;
  20313. } else {
  20314. p.captchaFlag = 1;
  20315. }
  20316. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20317. #endif
  20318. }
  20319. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20320. #if PACKETVER >= 20160316
  20321. nullpo_retv(sd);
  20322. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20323. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20324. return;
  20325. }
  20326. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20327. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20328. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20329. return;
  20330. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20331. return;
  20332. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20333. #endif
  20334. }
  20335. void clif_captcha_upload_end(map_session_data &sd) {
  20336. #if PACKETVER >= 20160330
  20337. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20338. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20339. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20340. #endif
  20341. }
  20342. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20343. #if PACKETVER >= 20160323
  20344. nullpo_retv(sd);
  20345. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20346. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20347. return;
  20348. }
  20349. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20350. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20351. #endif
  20352. }
  20353. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20354. #if PACKETVER >= 20160330
  20355. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20356. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20357. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20358. if (cd == nullptr) {
  20359. p.captchaFlag = 1;
  20360. p.imageSize = 0;
  20361. } else {
  20362. p.captchaFlag = 0;
  20363. p.imageSize = cd->image_size;
  20364. }
  20365. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20366. if (cd != nullptr) {
  20367. for (uint16 offset = 0; offset < cd->image_size;) {
  20368. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20369. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20370. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20371. p2->PacketLength = (int16)(sizeof(PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20372. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20373. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20374. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20375. offset += chunk_size;
  20376. }
  20377. }
  20378. #endif
  20379. }
  20380. void clif_macro_detector_request(map_session_data &sd) {
  20381. #if PACKETVER >= 20160330
  20382. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20383. if (cd == nullptr) {
  20384. return;
  20385. }
  20386. // Send preview initialization request to the client.
  20387. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20388. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20389. p.imageSize = cd->image_size;
  20390. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20391. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20392. for (uint16 offset = 0; offset < cd->image_size;) {
  20393. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20394. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20395. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20396. p2->PacketLength = (int16)(sizeof(PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20397. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20398. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20399. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20400. offset += chunk_size;
  20401. }
  20402. #endif
  20403. }
  20404. void clif_macro_detector_request_show(map_session_data &sd) {
  20405. #if PACKETVER >= 20160330
  20406. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20407. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20408. p.retryCount = sd.macro_detect.retry;
  20409. p.timeout = battle_config.macro_detection_timeout;
  20410. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20411. #endif
  20412. }
  20413. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20414. #if PACKETVER >= 20160316
  20415. nullpo_retv(sd);
  20416. if (sd->macro_detect.retry != 0) {
  20417. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20418. clif_macro_detector_request_show(*sd);
  20419. }
  20420. #endif
  20421. }
  20422. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20423. #if PACKETVER >= 20160316
  20424. nullpo_retv(sd);
  20425. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20426. pc_macro_detector_process_answer(*sd, p->answer);
  20427. #endif
  20428. }
  20429. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20430. #if PACKETVER >= 20160330
  20431. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20432. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20433. p.status = stype;
  20434. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20435. #endif
  20436. }
  20437. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20438. #if PACKETVER >= 20160330
  20439. nullpo_retv(sd);
  20440. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20441. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20442. return;
  20443. }
  20444. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20445. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20446. #endif
  20447. }
  20448. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20449. #if PACKETVER >= 20160330
  20450. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *p = (PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *)packet_buffer;
  20451. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20452. p->PacketLength = static_cast<int16>(sizeof(PACKET_ZC_ACK_PLAYER_AID_IN_RANGE) + sizeof(uint32) * aid_list.size());
  20453. for (size_t i = 0; i < aid_list.size(); i++)
  20454. p->AID[i] = aid_list[static_cast<int32>(i)];
  20455. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20456. #endif
  20457. }
  20458. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20459. #if PACKETVER >= 20160316
  20460. nullpo_retv(sd);
  20461. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20462. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20463. return;
  20464. }
  20465. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20466. map_session_data *tsd = map_id2sd(p->AID);
  20467. if (tsd == nullptr) {
  20468. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20469. return;
  20470. }
  20471. if (tsd->macro_detect.retry != 0) {
  20472. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20473. return;
  20474. }
  20475. if (captcha_db.empty()) {
  20476. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20477. return;
  20478. }
  20479. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20480. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20481. #endif
  20482. }
  20483. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20484. #if PACKETVER >= 20160330
  20485. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20486. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20487. p.status = stype;
  20488. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20489. #endif
  20490. }
  20491. void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ){
  20492. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20493. struct PACKET_ZC_DYNAMICNPC_CREATE_RESULT p = {};
  20494. p.packetType = HEADER_ZC_DYNAMICNPC_CREATE_RESULT;
  20495. p.result = result;
  20496. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20497. #endif
  20498. }
  20499. void clif_partybooking_ask( map_session_data* sd, map_session_data* joining_sd ){
  20500. #if PACKETVER >= 20191204
  20501. struct PACKET_ZC_PARTY_REQ_MASTER_TO_JOIN p = { 0 };
  20502. p.packetType = HEADER_ZC_PARTY_REQ_MASTER_TO_JOIN;
  20503. p.CID = joining_sd->status.char_id;
  20504. p.AID = joining_sd->status.account_id;
  20505. safestrncpy( p.name, joining_sd->status.name, NAME_LENGTH );
  20506. p.x = joining_sd->status.base_level;
  20507. p.y = joining_sd->status.class_;
  20508. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20509. #endif
  20510. }
  20511. void clif_parse_partybooking_join( int fd, map_session_data* sd ){
  20512. #if PACKETVER >= 20191204
  20513. struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20514. // Character is already in a party
  20515. if( sd->status.party_id != 0 ){
  20516. return;
  20517. }
  20518. map_session_data* tsd = map_charid2sd( p->CID );
  20519. // Target player is offline
  20520. if( tsd == nullptr ){
  20521. return;
  20522. }
  20523. if( tsd->status.account_id != p->AID ){
  20524. return;
  20525. }
  20526. struct s_party_booking_requirement requirement;
  20527. if( !party_booking_load( tsd->status.account_id, tsd->status.char_id, &requirement ) ){
  20528. return;
  20529. }
  20530. if( sd->status.base_level < requirement.minimum_level ){
  20531. return;
  20532. }
  20533. if( sd->status.base_level > requirement.maximum_level ){
  20534. return;
  20535. }
  20536. // Already requested to join this party
  20537. if( util::vector_exists( tsd->party_booking_requests, sd->status.char_id ) ){
  20538. return;
  20539. }
  20540. // Store information that the player tried to join the party
  20541. tsd->party_booking_requests.push_back( sd->status.char_id );
  20542. clif_partybooking_ask( tsd, sd );
  20543. #endif
  20544. }
  20545. void clif_partybooking_reply( map_session_data* sd, map_session_data* party_leader_sd, bool accepted ){
  20546. #if PACKETVER >= 20191204
  20547. struct PACKET_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER p = { 0 };
  20548. if( party_leader_sd->status.party_id == 0 ){
  20549. return;
  20550. }
  20551. struct party_data* party = party_search( party_leader_sd->status.party_id );
  20552. if( party == nullptr ){
  20553. return;
  20554. }
  20555. p.packetType = HEADER_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER;
  20556. safestrncpy( p.player_name, party_leader_sd->status.name, NAME_LENGTH );
  20557. safestrncpy( p.party_name, party->party.name, NAME_LENGTH );
  20558. p.AID = party_leader_sd->status.account_id;
  20559. p.refused = !accepted;
  20560. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20561. #endif
  20562. }
  20563. void clif_parse_partybooking_reply( int fd, map_session_data* sd ){
  20564. #if PACKETVER >= 20191204
  20565. struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20566. map_session_data* tsd = map_charid2sd( p->CID );
  20567. // Target player is offline
  20568. if( tsd == nullptr ){
  20569. return;
  20570. }
  20571. if( tsd->status.account_id != p->AID ){
  20572. return;
  20573. }
  20574. // Check if the player even requested to join the party
  20575. if( !util::vector_exists( sd->party_booking_requests, p->CID ) ){
  20576. return;
  20577. }
  20578. util::vector_erase_if_exists( sd->party_booking_requests, p->CID );
  20579. // Only party leaders can reply
  20580. if( !party_isleader( sd ) ){
  20581. return;
  20582. }
  20583. if( p->accept ){
  20584. party_join( tsd, sd->status.party_id );
  20585. }
  20586. clif_partybooking_reply( tsd, sd, p->accept );
  20587. #endif
  20588. }
  20589. /*==========================================
  20590. * Main client packet processing function
  20591. *------------------------------------------*/
  20592. static int clif_parse(int fd)
  20593. {
  20594. int cmd, packet_len;
  20595. TBL_PC* sd;
  20596. int pnum;
  20597. #ifdef PACKET_OBFUSCATION
  20598. int cmd2;
  20599. #endif
  20600. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20601. // Note: "click masters" can do 80+ clicks in 10 seconds
  20602. 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]
  20603. { // begin main client packet processing loop
  20604. sd = (TBL_PC *)session[fd]->session_data;
  20605. if (session[fd]->flag.eof) {
  20606. if (sd) {
  20607. if (sd->state.autotrade) {
  20608. //Disassociate character from the socket connection.
  20609. session[fd]->session_data = NULL;
  20610. sd->fd = 0;
  20611. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20612. } else
  20613. if (sd->state.active) {
  20614. // Player logout display [Valaris]
  20615. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20616. clif_quitsave(fd, sd);
  20617. } else {
  20618. //Unusual logout (during log on/off/map-changer procedure)
  20619. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20620. map_quit(sd);
  20621. }
  20622. } else {
  20623. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20624. }
  20625. do_close(fd);
  20626. return 0;
  20627. }
  20628. if (RFIFOREST(fd) < 2)
  20629. return 0;
  20630. cmd = RFIFOW(fd, 0);
  20631. #ifdef PACKET_OBFUSCATION
  20632. // Check if it is a player that tries to connect to the map server.
  20633. if( sd ){
  20634. // Decrypt the current packet ID with the last key stored in the session.
  20635. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20636. }else{
  20637. // Store the original value for checking
  20638. cmd2 = cmd;
  20639. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20640. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20641. }
  20642. #endif
  20643. // filter out invalid / unsupported packets
  20644. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20645. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20646. #ifdef DUMP_INVALID_PACKET
  20647. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20648. #endif
  20649. #ifdef PACKET_OBFUSCATION_WARN
  20650. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20651. if( !sd ){
  20652. #ifdef PACKET_OBFUSCATION
  20653. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20654. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20655. }
  20656. #else
  20657. // Try to use the initial keys for the decryption of the packet ID.
  20658. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20659. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20660. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20661. }
  20662. #endif
  20663. }
  20664. #endif
  20665. set_eof(fd);
  20666. return 0;
  20667. }
  20668. // determine real packet length
  20669. packet_len = packet_db[cmd].len;
  20670. if (packet_len == -1) { // variable-length packet
  20671. if (RFIFOREST(fd) < 4)
  20672. return 0;
  20673. packet_len = RFIFOW(fd,2);
  20674. if (packet_len < 4 || packet_len > 32768) {
  20675. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20676. #ifdef DUMP_INVALID_PACKET
  20677. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20678. #endif
  20679. set_eof(fd);
  20680. return 0;
  20681. }
  20682. }
  20683. if ((int)RFIFOREST(fd) < packet_len){
  20684. 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 );
  20685. #ifdef DUMP_INVALID_PACKET
  20686. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20687. #endif
  20688. set_eof( fd );
  20689. return 0; // not enough data received to form the packet
  20690. }
  20691. #ifdef PACKET_OBFUSCATION
  20692. RFIFOW(fd, 0) = cmd;
  20693. if (sd)
  20694. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20695. #endif
  20696. if( packet_db[cmd].func == clif_parse_debug )
  20697. packet_db[cmd].func(fd, sd);
  20698. else if( packet_db[cmd].func != NULL ) {
  20699. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20700. ; //Only valid packet when there is no session
  20701. else
  20702. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20703. ; //Only valid packet when player is not on a map
  20704. else
  20705. packet_db[cmd].func(fd, sd);
  20706. }
  20707. #ifdef DUMP_UNKNOWN_PACKET
  20708. else DumpUnknown(fd,sd,cmd,packet_len);
  20709. #endif
  20710. RFIFOSKIP(fd, packet_len);
  20711. }; // main loop end
  20712. return 0;
  20713. }
  20714. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, map_session_data *), ... ){
  20715. va_list argp;
  20716. int i;
  20717. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20718. return;
  20719. packet_db[cmd].len = length;
  20720. packet_db[cmd].func = func;
  20721. va_start(argp, func);
  20722. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20723. int offset = va_arg(argp, int);
  20724. if( offset == 0 ){
  20725. break;
  20726. }
  20727. packet_db[cmd].pos[i] = offset;
  20728. }
  20729. if( i == MAX_PACKET_POS ){
  20730. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20731. }
  20732. va_end(argp);
  20733. }
  20734. /*==========================================
  20735. * Reads packets and setups its array reference
  20736. *------------------------------------------*/
  20737. void packetdb_readdb(){
  20738. memset(packet_db,0,sizeof(packet_db));
  20739. #include "clif_packetdb.hpp"
  20740. #include "clif_shuffle.hpp"
  20741. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20742. #ifdef PACKET_OBFUSCATION
  20743. 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]);
  20744. #else
  20745. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20746. #endif
  20747. }
  20748. /*==========================================
  20749. *
  20750. *------------------------------------------*/
  20751. void do_init_clif(void) {
  20752. const int colors[COLOR_MAX] = {
  20753. 0x00FF00, // COLOR_DEFAULT
  20754. 0xFF0000, // COLOR_RED
  20755. 0xFFFFFF, // COLOR_WHITE
  20756. 0xFFFF00, // COLOR_YELLOW
  20757. 0x00FFFF, // COLOR_CYAN
  20758. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20759. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20760. };
  20761. /**
  20762. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20763. **/
  20764. for( int i = 0; i < COLOR_MAX; i++ ){
  20765. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20766. }
  20767. packetdb_readdb();
  20768. set_defaultparse(clif_parse);
  20769. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20770. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20771. exit(EXIT_FAILURE);
  20772. }
  20773. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20774. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20775. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20776. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20777. if( battle_config.ping_timer_interval > 0 ){
  20778. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20779. }
  20780. #endif
  20781. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20782. }
  20783. void do_final_clif(void) {
  20784. ers_destroy(delay_clearunit_ers);
  20785. }