clif.cpp 723 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081
  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(struct map_session_data *sd);
  79. static void clif_loadConfirm( struct 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(struct 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. struct map_session_data *sd;
  342. unsigned char *buf;
  343. int len, type, fd;
  344. nullpo_ret(bl);
  345. nullpo_ret(sd = (struct 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. struct map_session_data *ssd = (struct 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.data[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. struct 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(struct 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. struct 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(struct 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. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  931. struct 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. struct map_session_data* sd = (struct 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. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1083. struct 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, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1220. nullpo_retv( bl );
  1221. nullpo_retv( ud );
  1222. struct map_session_data* sd;
  1223. struct 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, struct 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( struct 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( struct 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.data[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.data[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, struct 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(struct 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. struct map_session_data *sd=NULL;
  1444. iter = mapit_getallusers();
  1445. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct 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.data[SC_MILLENNIUMSHIELD])
  1495. clif_millenniumshield(&sd->bl, sd->sc.data[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( struct 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(struct 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(struct 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(struct 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( struct 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(struct 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. struct 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. struct 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. struct 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,struct 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(struct 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(struct 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(struct 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( struct 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(struct 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, struct 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(struct 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, struct 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( struct 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, struct 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( struct 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( struct 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(struct 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( struct 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(struct 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(struct 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(struct 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(struct 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(struct 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(struct 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 uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2368. nullpo_retr( 0, it );
  2369. uint8 count = 0;
  2370. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2371. if( it->option[i].id ){
  2372. buf[i].index = it->option[i].id; // OptIndex
  2373. buf[i].value = it->option[i].value; // Value
  2374. buf[i].param = it->option[i].param; // Param1
  2375. count++;
  2376. }else{
  2377. buf[i].index = 0;
  2378. buf[i].value = 0;
  2379. buf[i].param = 0;
  2380. }
  2381. }
  2382. #if MAX_ITEM_RDM_OPT < 5
  2383. for( ; i < 5; i++ ){
  2384. buf[i].index = 0; // OptIndex
  2385. buf[i].value = 0; // Value
  2386. buf[i].param = 0; // Param1
  2387. }
  2388. #endif
  2389. return count;
  2390. }
  2391. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2392. /// 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)
  2393. /// 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)
  2394. /// 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)
  2395. /// 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)
  2396. /// 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)
  2397. /// 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)
  2398. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2399. nullpo_retv( sd );
  2400. int fd = sd->fd;
  2401. if( !session_isActive( fd ) ){
  2402. return;
  2403. }
  2404. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2405. if( fail ){
  2406. p = {};
  2407. }else{
  2408. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2409. return;
  2410. }
  2411. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2412. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2413. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2414. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2415. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2416. p.location = pc_equippoint(sd,n);
  2417. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2418. #if PACKETVER >= 20061218
  2419. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2420. #if PACKETVER >= 20071002
  2421. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2422. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2423. */
  2424. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2425. #if PACKETVER >= 20150226
  2426. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2427. #if PACKETVER >= 20160921
  2428. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2429. p.look = sd->inventory_data[n]->look;
  2430. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2431. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2432. #endif
  2433. #endif
  2434. #endif
  2435. #endif
  2436. #endif
  2437. }
  2438. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2439. p.Index = client_index( n );
  2440. p.count = amount;
  2441. p.result = fail;
  2442. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2443. }
  2444. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2445. /// 00af <index>.W <amount>.W
  2446. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2447. {
  2448. int fd;
  2449. nullpo_retv(sd);
  2450. fd=sd->fd;
  2451. WFIFOHEAD(fd, packet_len(0xaf));
  2452. WFIFOW(fd,0)=0xaf;
  2453. WFIFOW(fd,2)=n+2;
  2454. WFIFOW(fd,4)=amount;
  2455. WFIFOSET(fd,packet_len(0xaf));
  2456. }
  2457. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2458. /// 07fa <delete type>.W <index>.W <amount>.W
  2459. /// delete type:
  2460. /// 0 = Normal
  2461. /// 1 = Item used for a skill
  2462. /// 2 = Refine failed
  2463. /// 3 = Material changed
  2464. /// 4 = Moved to storage
  2465. /// 5 = Moved to cart
  2466. /// 6 = Item sold
  2467. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2468. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2469. {
  2470. #if PACKETVER < 20091117
  2471. clif_dropitem(sd,n,amount);
  2472. #else
  2473. int fd;
  2474. nullpo_retv(sd);
  2475. fd=sd->fd;
  2476. WFIFOHEAD(fd, packet_len(0x7fa));
  2477. WFIFOW(fd,0)=0x7fa;
  2478. WFIFOW(fd,2)=reason;
  2479. WFIFOW(fd,4)=n+2;
  2480. WFIFOW(fd,6)=amount;
  2481. WFIFOSET(fd,packet_len(0x7fa));
  2482. #endif
  2483. }
  2484. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2485. nullpo_retv( p );
  2486. nullpo_retv( it );
  2487. nullpo_retv( id );
  2488. p->index = idx;
  2489. p->ITID = client_nameid( it->nameid );
  2490. p->type = itemtype( it->nameid );
  2491. #if PACKETVER < 20120925
  2492. p->IsIdentified = it->identify ? 1 : 0;
  2493. #endif
  2494. p->location = eqp_pos;
  2495. p->WearState = it->equip;
  2496. #if PACKETVER < 20120925
  2497. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2498. #endif
  2499. p->RefiningLevel = it->refine;
  2500. clif_addcards( &p->slot, it );
  2501. #if PACKETVER >= 20071002
  2502. p->HireExpireDate = it->expire_time;
  2503. #endif
  2504. #if PACKETVER >= 20080102
  2505. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2506. #endif
  2507. #if PACKETVER >= 20100629
  2508. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2509. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2510. #endif
  2511. #if PACKETVER >= 20120925
  2512. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2513. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2514. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2515. p->Flag.SpareBits = 0;
  2516. #endif
  2517. #if PACKETVER >= 20150226
  2518. p->option_count = clif_add_random_options( p->option_data, it );
  2519. #endif
  2520. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2521. p->enchantgrade = it->enchantgrade;
  2522. #endif
  2523. }
  2524. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2525. nullpo_retv(p);
  2526. nullpo_retv(i);
  2527. nullpo_retv(id);
  2528. p->index = idx;
  2529. p->ITID = client_nameid( i->nameid );
  2530. p->type = itemtype( i->nameid );
  2531. #if PACKETVER < 20120925
  2532. p->IsIdentified = i->identify ? 1 : 0;
  2533. #endif
  2534. p->count = i->amount;
  2535. p->WearState = id->equip;
  2536. #if PACKETVER >= 5
  2537. clif_addcards( &p->slot, i );
  2538. #endif
  2539. #if PACKETVER >= 20080102
  2540. p->HireExpireDate = i->expire_time;
  2541. #endif
  2542. #if PACKETVER >= 20120925
  2543. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2544. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2545. p->Flag.SpareBits = 0;
  2546. #endif
  2547. }
  2548. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2549. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2550. nullpo_retv(sd);
  2551. nullpo_retv(name);
  2552. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2553. memset(buf, 0, sizeof(buf));
  2554. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2555. p->packetType = HEADER_ZC_INVENTORY_START;
  2556. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2557. p->invType = type;
  2558. #endif
  2559. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2560. int strLen = (int)safestrnlen(name, 24) + 1;
  2561. if (strLen > 24)
  2562. strLen = 24;
  2563. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2564. p->packetLength = len;
  2565. safestrncpy(p->name, name, strLen);
  2566. #else
  2567. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2568. safestrncpy(p->name, name, NAME_LENGTH);
  2569. #endif
  2570. clif_send( p, len, &sd->bl, SELF );
  2571. #endif
  2572. }
  2573. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2574. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2575. nullpo_retv(sd);
  2576. struct PACKET_ZC_INVENTORY_END p;
  2577. p.packetType = HEADER_ZC_INVENTORY_END;
  2578. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2579. p.invType = type;
  2580. #endif
  2581. p.flag = 0;
  2582. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2583. #endif
  2584. }
  2585. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2586. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2587. void clif_inventorylist( struct map_session_data *sd ){
  2588. nullpo_retv( sd );
  2589. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2590. e_inventory_type type = INVTYPE_INVENTORY;
  2591. clif_inventoryStart( sd, type, "" );
  2592. #endif
  2593. static struct packet_itemlist_normal itemlist_normal;
  2594. static struct packet_itemlist_equip itemlist_equip;
  2595. int equip = 0;
  2596. int normal = 0;
  2597. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2598. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2599. continue;
  2600. }
  2601. // Non-stackable (Equippable)
  2602. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2603. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2604. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2605. itemlist_equip.PacketType = inventorylistequipType;
  2606. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2607. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2608. itemlist_equip.invType = type;
  2609. #endif
  2610. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2611. equip = 0;
  2612. }
  2613. // Stackable (Normal)
  2614. }else{
  2615. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2616. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2617. itemlist_normal.PacketType = inventorylistnormalType;
  2618. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2619. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2620. itemlist_normal.invType = type;
  2621. #endif
  2622. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2623. normal = 0;
  2624. }
  2625. }
  2626. }
  2627. if( normal ){
  2628. itemlist_normal.PacketType = inventorylistnormalType;
  2629. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2630. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2631. itemlist_normal.invType = type;
  2632. #endif
  2633. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2634. }
  2635. if( sd->equip_index[EQI_AMMO] >= 0 )
  2636. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2637. if( equip ) {
  2638. itemlist_equip.PacketType = inventorylistequipType;
  2639. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2640. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2641. itemlist_equip.invType = type;
  2642. #endif
  2643. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2644. }
  2645. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2646. clif_inventoryEnd( sd, type );
  2647. #endif
  2648. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2649. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2650. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2651. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2652. continue;
  2653. if ( sd->inventory.u.items_inventory[i].favorite )
  2654. clif_favorite_item(sd, i);
  2655. }
  2656. #endif
  2657. }
  2658. //Required when items break/get-repaired. Only sends equippable item list.
  2659. void clif_equiplist( struct map_session_data *sd ){
  2660. // TODO: implement again => only send equip part
  2661. clif_inventorylist( sd );
  2662. }
  2663. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2664. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2665. e_inventory_type type = INVTYPE_STORAGE;
  2666. clif_inventoryStart( sd, type, storename );
  2667. #endif
  2668. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2669. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2670. int equip = 0;
  2671. int normal = 0;
  2672. for( int i = 0; i < items_length; i++ ){
  2673. if( items[i].nameid == 0 ){
  2674. continue;
  2675. }
  2676. struct item_data* id = itemdb_search( items[i].nameid );
  2677. // Non-stackable (Equippable)
  2678. if( !itemdb_isstackable2( id ) ){
  2679. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2680. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2681. storage_itemlist_equip.PacketType = storageListEquipType;
  2682. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2683. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2684. storage_itemlist_equip.invType = type;
  2685. #elif PACKETVER >= 20120925
  2686. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2687. #endif
  2688. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2689. equip = 0;
  2690. }
  2691. // Stackable (Normal)
  2692. }else{
  2693. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2694. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2695. storage_itemlist_normal.PacketType = storageListNormalType;
  2696. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2697. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2698. storage_itemlist_normal.invType = type;
  2699. #elif PACKETVER >= 20120925
  2700. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2701. #endif
  2702. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2703. normal = 0;
  2704. }
  2705. }
  2706. }
  2707. if( normal ){
  2708. storage_itemlist_normal.PacketType = storageListNormalType;
  2709. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2710. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2711. storage_itemlist_normal.invType = type;
  2712. #elif PACKETVER >= 20120925
  2713. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2714. #endif
  2715. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2716. }
  2717. if( equip ) {
  2718. storage_itemlist_equip.PacketType = storageListEquipType;
  2719. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2720. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2721. storage_itemlist_equip.invType = type;
  2722. #elif PACKETVER >= 20120925
  2723. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2724. #endif
  2725. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2726. }
  2727. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2728. clif_inventoryEnd( sd, type );
  2729. #endif
  2730. }
  2731. void clif_cartlist( struct map_session_data *sd ){
  2732. nullpo_retv( sd );
  2733. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2734. e_inventory_type type = INVTYPE_CART;
  2735. clif_inventoryStart( sd, type, "" );
  2736. #endif
  2737. static struct packet_itemlist_normal itemlist_normal;
  2738. static struct packet_itemlist_equip itemlist_equip;
  2739. int normal = 0;
  2740. int equip = 0;
  2741. for( int i = 0; i < MAX_CART; i++ ){
  2742. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2743. continue;
  2744. }
  2745. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2746. // Non-stackable (Equippable)
  2747. if( !itemdb_isstackable2(id) ){
  2748. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2749. // Stackable (Normal)
  2750. }else{
  2751. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2752. }
  2753. }
  2754. if( normal ){
  2755. itemlist_normal.PacketType = cartlistnormalType;
  2756. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2757. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2758. itemlist_normal.invType = type;
  2759. #endif
  2760. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2761. }
  2762. if( equip ){
  2763. itemlist_equip.PacketType = cartlistequipType;
  2764. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2765. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2766. itemlist_equip.invType = type;
  2767. #endif
  2768. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2769. }
  2770. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2771. clif_inventoryEnd( sd, type );
  2772. #endif
  2773. }
  2774. /// Removes cart (ZC_CARTOFF).
  2775. /// 012b
  2776. /// Client behaviour:
  2777. /// Closes the cart storage and removes all it's items from memory.
  2778. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2779. void clif_clearcart(int fd)
  2780. {
  2781. WFIFOHEAD(fd, packet_len(0x12b));
  2782. WFIFOW(fd,0) = 0x12b;
  2783. WFIFOSET(fd, packet_len(0x12b));
  2784. }
  2785. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2786. /// 01eb <account id>.L <x>.W <y>.W
  2787. void clif_guild_xy(struct map_session_data *sd)
  2788. {
  2789. unsigned char buf[10];
  2790. nullpo_retv(sd);
  2791. WBUFW(buf,0)=0x1eb;
  2792. WBUFL(buf,2)=sd->status.account_id;
  2793. WBUFW(buf,6)=sd->bl.x;
  2794. WBUFW(buf,8)=sd->bl.y;
  2795. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2796. }
  2797. /*==========================================
  2798. * Sends x/y dot to a single fd. [Skotlex]
  2799. *------------------------------------------*/
  2800. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2801. {
  2802. if( sd->bg_id )
  2803. return;
  2804. WFIFOHEAD(fd,packet_len(0x1eb));
  2805. WFIFOW(fd,0)=0x1eb;
  2806. WFIFOL(fd,2)=sd->status.account_id;
  2807. WFIFOW(fd,6)=sd->bl.x;
  2808. WFIFOW(fd,8)=sd->bl.y;
  2809. WFIFOSET(fd,packet_len(0x1eb));
  2810. }
  2811. // Guild XY locators [Valaris]
  2812. void clif_guild_xy_remove(struct map_session_data *sd)
  2813. {
  2814. unsigned char buf[10];
  2815. nullpo_retv(sd);
  2816. WBUFW(buf,0)=0x1eb;
  2817. WBUFL(buf,2)=sd->status.account_id;
  2818. WBUFW(buf,6)=-1;
  2819. WBUFW(buf,8)=-1;
  2820. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2821. }
  2822. /*==========================================
  2823. *
  2824. *------------------------------------------*/
  2825. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2826. struct map_session_data* sd = va_arg( ap, struct map_session_data* );
  2827. struct map_session_data* tsd = BL_CAST( BL_PC, bl );
  2828. nullpo_ret(sd);
  2829. nullpo_ret(tsd);
  2830. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2831. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2832. }
  2833. return 0;
  2834. }
  2835. /*==========================================
  2836. * Server tells all players that are allowed to view HP bars
  2837. * and are nearby 'sd' that 'sd' hp bar was updated.
  2838. *------------------------------------------*/
  2839. static int clif_hpmeter(struct map_session_data *sd)
  2840. {
  2841. nullpo_ret(sd);
  2842. 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);
  2843. return 0;
  2844. }
  2845. /**
  2846. * Send HP bar update to others.
  2847. * @param sd: Player invoking update
  2848. */
  2849. void clif_update_hp(map_session_data &sd) {
  2850. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2851. clif_hpmeter(&sd);
  2852. if (!battle_config.party_hp_mode && sd.status.party_id)
  2853. clif_party_hp( sd );
  2854. if (sd.bg_id)
  2855. clif_bg_hp(&sd);
  2856. }
  2857. /// Notifies client of a character parameter change.
  2858. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2859. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2860. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2861. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2862. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2863. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2864. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2865. /// TODO: Extract individual packets.
  2866. /// FIXME: Packet lengths from packet_len(cmd)
  2867. void clif_updatestatus(struct map_session_data *sd,int type)
  2868. {
  2869. int fd,len=8;
  2870. nullpo_retv(sd);
  2871. fd=sd->fd;
  2872. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2873. return;
  2874. WFIFOHEAD(fd, 14);
  2875. WFIFOW(fd,0)=0xb0;
  2876. WFIFOW(fd,2)=type;
  2877. switch(type){
  2878. // 00b0
  2879. case SP_WEIGHT:
  2880. pc_updateweightstatus(sd);
  2881. WFIFOHEAD(fd,14);
  2882. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2883. WFIFOW(fd,2)=type;
  2884. WFIFOL(fd,4)=sd->weight;
  2885. break;
  2886. case SP_MAXWEIGHT:
  2887. WFIFOL(fd,4)=sd->max_weight;
  2888. break;
  2889. case SP_SPEED:
  2890. WFIFOL(fd,4)=sd->battle_status.speed;
  2891. break;
  2892. case SP_BASELEVEL:
  2893. WFIFOL(fd,4)=sd->status.base_level;
  2894. break;
  2895. case SP_JOBLEVEL:
  2896. WFIFOL(fd,4)=sd->status.job_level;
  2897. break;
  2898. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2899. WFIFOL(fd,4)=sd->status.karma;
  2900. break;
  2901. case SP_MANNER:
  2902. WFIFOL(fd,4)=sd->status.manner;
  2903. break;
  2904. case SP_STATUSPOINT:
  2905. WFIFOL(fd,4)=sd->status.status_point;
  2906. break;
  2907. case SP_SKILLPOINT:
  2908. WFIFOL(fd,4)=sd->status.skill_point;
  2909. break;
  2910. case SP_HIT:
  2911. WFIFOL(fd,4)=sd->battle_status.hit;
  2912. break;
  2913. case SP_FLEE1:
  2914. WFIFOL(fd,4)=sd->battle_status.flee;
  2915. break;
  2916. case SP_FLEE2:
  2917. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2918. break;
  2919. case SP_MAXHP:
  2920. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2921. break;
  2922. case SP_MAXSP:
  2923. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2924. break;
  2925. case SP_HP:
  2926. // On officials the HP never go below 1, even if you die [Lemongrass]
  2927. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2928. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2929. break;
  2930. case SP_SP:
  2931. WFIFOL(fd,4)=sd->battle_status.sp;
  2932. break;
  2933. case SP_ASPD:
  2934. WFIFOL(fd,4)=sd->battle_status.amotion;
  2935. break;
  2936. case SP_ATK1:
  2937. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2938. break;
  2939. case SP_DEF1:
  2940. WFIFOL(fd,4)=pc_leftside_def(sd);
  2941. break;
  2942. case SP_MDEF1:
  2943. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2944. break;
  2945. case SP_ATK2:
  2946. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2947. break;
  2948. case SP_DEF2:
  2949. WFIFOL(fd,4)=pc_rightside_def(sd);
  2950. break;
  2951. case SP_MDEF2: {
  2952. //negative check (in case you have something like Berserk active)
  2953. int mdef2 = pc_rightside_mdef(sd);
  2954. WFIFOL(fd,4)=
  2955. #ifndef RENEWAL
  2956. ( mdef2 < 0 ) ? 0 :
  2957. #endif
  2958. mdef2;
  2959. }
  2960. break;
  2961. case SP_CRITICAL:
  2962. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2963. break;
  2964. case SP_MATK1:
  2965. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2966. break;
  2967. case SP_MATK2:
  2968. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2969. break;
  2970. case SP_ZENY:
  2971. WFIFOW(fd,0)=0xb1;
  2972. WFIFOL(fd,4)=sd->status.zeny;
  2973. break;
  2974. #if PACKETVER >= 20170830
  2975. case SP_BASEEXP:
  2976. WFIFOW(fd,0)=0xacb;
  2977. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2978. len = packet_len(0xacb);
  2979. break;
  2980. case SP_JOBEXP:
  2981. WFIFOW(fd,0)=0xacb;
  2982. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2983. len = packet_len(0xacb);
  2984. break;
  2985. case SP_NEXTBASEEXP:
  2986. WFIFOW(fd,0)=0xacb;
  2987. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  2988. len = packet_len(0xacb);
  2989. break;
  2990. case SP_NEXTJOBEXP:
  2991. WFIFOW(fd,0)=0xacb;
  2992. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  2993. len = packet_len(0xacb);
  2994. break;
  2995. #else
  2996. case SP_BASEEXP:
  2997. WFIFOW(fd,0)=0xb1;
  2998. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  2999. break;
  3000. case SP_JOBEXP:
  3001. WFIFOW(fd,0)=0xb1;
  3002. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3003. break;
  3004. case SP_NEXTBASEEXP:
  3005. WFIFOW(fd,0)=0xb1;
  3006. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3007. break;
  3008. case SP_NEXTJOBEXP:
  3009. WFIFOW(fd,0)=0xb1;
  3010. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3011. break;
  3012. #endif
  3013. /**
  3014. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3015. **/
  3016. case SP_USTR:
  3017. case SP_UAGI:
  3018. case SP_UVIT:
  3019. case SP_UINT:
  3020. case SP_UDEX:
  3021. case SP_ULUK:
  3022. WFIFOW(fd,0)=0xbe;
  3023. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3024. len=5;
  3025. break;
  3026. /**
  3027. * Tells the client how far it is allowed to attack (weapon range)
  3028. **/
  3029. case SP_ATTACKRANGE:
  3030. WFIFOW(fd,0)=0x13a;
  3031. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3032. len=4;
  3033. break;
  3034. case SP_STR:
  3035. WFIFOW(fd,0)=0x141;
  3036. WFIFOL(fd,2)=type;
  3037. WFIFOL(fd,6)=sd->status.str;
  3038. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3039. len=14;
  3040. break;
  3041. case SP_AGI:
  3042. WFIFOW(fd,0)=0x141;
  3043. WFIFOL(fd,2)=type;
  3044. WFIFOL(fd,6)=sd->status.agi;
  3045. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3046. len=14;
  3047. break;
  3048. case SP_VIT:
  3049. WFIFOW(fd,0)=0x141;
  3050. WFIFOL(fd,2)=type;
  3051. WFIFOL(fd,6)=sd->status.vit;
  3052. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3053. len=14;
  3054. break;
  3055. case SP_INT:
  3056. WFIFOW(fd,0)=0x141;
  3057. WFIFOL(fd,2)=type;
  3058. WFIFOL(fd,6)=sd->status.int_;
  3059. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3060. len=14;
  3061. break;
  3062. case SP_DEX:
  3063. WFIFOW(fd,0)=0x141;
  3064. WFIFOL(fd,2)=type;
  3065. WFIFOL(fd,6)=sd->status.dex;
  3066. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3067. len=14;
  3068. break;
  3069. case SP_LUK:
  3070. WFIFOW(fd,0)=0x141;
  3071. WFIFOL(fd,2)=type;
  3072. WFIFOL(fd,6)=sd->status.luk;
  3073. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3074. len=14;
  3075. break;
  3076. case SP_CARTINFO:
  3077. WFIFOW(fd,0)=0x121;
  3078. WFIFOW(fd,2)=sd->cart_num;
  3079. WFIFOW(fd,4)=MAX_CART;
  3080. WFIFOL(fd,6)=sd->cart_weight;
  3081. WFIFOL(fd,10)=sd->cart_weight_max;
  3082. len=14;
  3083. break;
  3084. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3085. case SP_AP:
  3086. WFIFOL(fd, 4) = sd->battle_status.ap;
  3087. break;
  3088. case SP_TRAITPOINT:
  3089. WFIFOL(fd, 4) = sd->status.trait_point;
  3090. break;
  3091. case SP_MAXAP:
  3092. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3093. break;
  3094. case SP_POW:
  3095. WFIFOW(fd, 0) = 0x141;
  3096. WFIFOL(fd, 2) = type;
  3097. WFIFOL(fd, 6) = sd->status.pow;
  3098. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3099. len = 14;
  3100. break;
  3101. case SP_STA:
  3102. WFIFOW(fd, 0) = 0x141;
  3103. WFIFOL(fd, 2) = type;
  3104. WFIFOL(fd, 6) = sd->status.sta;
  3105. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3106. len = 14;
  3107. break;
  3108. case SP_WIS:
  3109. WFIFOW(fd, 0) = 0x141;
  3110. WFIFOL(fd, 2) = type;
  3111. WFIFOL(fd, 6) = sd->status.wis;
  3112. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3113. len = 14;
  3114. break;
  3115. case SP_SPL:
  3116. WFIFOW(fd, 0) = 0x141;
  3117. WFIFOL(fd, 2) = type;
  3118. WFIFOL(fd, 6) = sd->status.spl;
  3119. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3120. len = 14;
  3121. break;
  3122. case SP_CON:
  3123. WFIFOW(fd, 0) = 0x141;
  3124. WFIFOL(fd, 2) = type;
  3125. WFIFOL(fd, 6) = sd->status.con;
  3126. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3127. len = 14;
  3128. break;
  3129. case SP_CRT:
  3130. WFIFOW(fd, 0) = 0x141;
  3131. WFIFOL(fd, 2) = type;
  3132. WFIFOL(fd, 6) = sd->status.crt;
  3133. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3134. len = 14;
  3135. break;
  3136. case SP_UPOW:
  3137. case SP_USTA:
  3138. case SP_UWIS:
  3139. case SP_USPL:
  3140. case SP_UCON:
  3141. case SP_UCRT:
  3142. WFIFOW(fd, 0) = 0xbe;
  3143. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3144. len = 5;
  3145. break;
  3146. case SP_PATK:
  3147. WFIFOL(fd, 4) = sd->battle_status.patk;
  3148. break;
  3149. case SP_SMATK:
  3150. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3151. break;
  3152. case SP_RES:
  3153. WFIFOL(fd, 4) = sd->battle_status.res;
  3154. break;
  3155. case SP_MRES:
  3156. WFIFOL(fd, 4) = sd->battle_status.mres;
  3157. break;
  3158. case SP_HPLUS:
  3159. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3160. break;
  3161. case SP_CRATE:
  3162. WFIFOL(fd, 4) = sd->battle_status.crate;
  3163. break;
  3164. #else
  3165. case SP_AP:
  3166. case SP_TRAITPOINT:
  3167. case SP_MAXAP:
  3168. case SP_POW:
  3169. case SP_STA:
  3170. case SP_WIS:
  3171. case SP_SPL:
  3172. case SP_CON:
  3173. case SP_CRT:
  3174. case SP_UPOW:
  3175. case SP_USTA:
  3176. case SP_UWIS:
  3177. case SP_USPL:
  3178. case SP_UCON:
  3179. case SP_UCRT:
  3180. case SP_PATK:
  3181. case SP_SMATK:
  3182. case SP_RES:
  3183. case SP_MRES:
  3184. case SP_HPLUS:
  3185. case SP_CRATE:
  3186. // 4th job status are not supported by older clients
  3187. return;
  3188. #endif
  3189. default:
  3190. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3191. return;
  3192. }
  3193. WFIFOSET(fd,len);
  3194. // Additional update packets that should be sent right after
  3195. switch( type ){
  3196. case SP_BASELEVEL:
  3197. if( sd->status.party_id ){
  3198. struct party_data* p;
  3199. int i;
  3200. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3201. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3202. if( i < MAX_PARTY ){
  3203. p->party.member[i].lv = sd->status.base_level;
  3204. clif_party_job_and_level( *sd );
  3205. }
  3206. }
  3207. }
  3208. break;
  3209. case SP_HP:
  3210. clif_update_hp(*sd);
  3211. break;
  3212. }
  3213. }
  3214. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3215. /// 01ab <account id>.L <var id>.W <value>.L
  3216. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3217. {
  3218. unsigned char buf[12];
  3219. nullpo_retv(sd);
  3220. WBUFW(buf,0)=0x1ab;
  3221. WBUFL(buf,2)=sd->bl.id;
  3222. WBUFW(buf,6)=type;
  3223. switch(type)
  3224. {
  3225. case SP_MANNER:
  3226. WBUFL(buf,8)=val;
  3227. break;
  3228. default:
  3229. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3230. return;
  3231. }
  3232. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3233. }
  3234. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3235. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3236. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3237. struct PACKET_ZC_SPRITE_CHANGE p;
  3238. p.packetType = sendLookType;
  3239. p.AID = id;
  3240. p.type = type;
  3241. p.val = val;
  3242. #if PACKETVER >= 4
  3243. p.val2 = val2;
  3244. #endif
  3245. clif_send( &p, sizeof( p ), bl, target );
  3246. }
  3247. /// Updates sprite/style properties of an object.
  3248. void clif_changelook(struct block_list *bl, int type, int val) {
  3249. struct map_session_data* sd;
  3250. struct status_change* sc;
  3251. struct view_data* vd;
  3252. enum send_target target = AREA;
  3253. int val2 = 0;
  3254. nullpo_retv(bl);
  3255. sd = BL_CAST(BL_PC, bl);
  3256. sc = status_get_sc(bl);
  3257. vd = status_get_viewdata(bl);
  3258. if( vd ) //temp hack to let Warp Portal change appearance
  3259. switch(type) {
  3260. case LOOK_WEAPON:
  3261. if (sd) {
  3262. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3263. val = vd->weapon;
  3264. }
  3265. else
  3266. vd->weapon = val;
  3267. break;
  3268. case LOOK_SHIELD:
  3269. if (sd) {
  3270. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3271. val = vd->shield;
  3272. }
  3273. else
  3274. vd->shield = val;
  3275. break;
  3276. case LOOK_BASE:
  3277. if (!sd)
  3278. break;
  3279. if ( val == JT_INVISIBLE )
  3280. return;
  3281. if (sd->sc.option&OPTION_COSTUME)
  3282. vd->weapon = vd->shield = 0;
  3283. if (!vd->cloth_color)
  3284. break;
  3285. if (sd) {
  3286. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3287. vd->cloth_color = 0;
  3288. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3289. vd->cloth_color = 0;
  3290. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3291. vd->cloth_color = 0;
  3292. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3293. vd->cloth_color = 0;
  3294. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3295. vd->cloth_color = 0;
  3296. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3297. vd->body_style = 0;
  3298. }
  3299. break;
  3300. case LOOK_HAIR:
  3301. vd->hair_style = val;
  3302. break;
  3303. case LOOK_HEAD_BOTTOM:
  3304. vd->head_bottom = val;
  3305. break;
  3306. case LOOK_HEAD_TOP:
  3307. vd->head_top = val;
  3308. break;
  3309. case LOOK_HEAD_MID:
  3310. vd->head_mid = val;
  3311. break;
  3312. case LOOK_HAIR_COLOR:
  3313. vd->hair_color = val;
  3314. break;
  3315. case LOOK_CLOTHES_COLOR:
  3316. if (val && sd) {
  3317. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3318. val = 0;
  3319. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3320. val = 0;
  3321. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3322. val = 0;
  3323. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3324. val = 0;
  3325. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3326. val = 0;
  3327. }
  3328. vd->cloth_color = val;
  3329. break;
  3330. case LOOK_SHOES:
  3331. #if PACKETVER > 3
  3332. if (sd) {
  3333. int n;
  3334. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3335. if(sd->inventory_data[n]->view_id > 0)
  3336. val = sd->inventory_data[n]->view_id;
  3337. else
  3338. val = sd->inventory.u.items_inventory[n].nameid;
  3339. } else
  3340. val = 0;
  3341. }
  3342. #endif
  3343. //Shoes? No packet uses this....
  3344. break;
  3345. case LOOK_BODY:
  3346. // unknown purpose
  3347. break;
  3348. case LOOK_ROBE:
  3349. #if PACKETVER < 20110111
  3350. return;
  3351. #else
  3352. vd->robe = val;
  3353. #endif
  3354. break;
  3355. case LOOK_BODY2:
  3356. #if PACKETVER < 20150513
  3357. return;
  3358. #else
  3359. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3360. val = 0;
  3361. vd->body_style = val;
  3362. #endif
  3363. break;
  3364. }
  3365. // prevent leaking the presence of GM-hidden objects
  3366. if( sc && sc->option&OPTION_INVISIBLE )
  3367. target = SELF;
  3368. #if PACKETVER < 4
  3369. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3370. #else
  3371. if (bl->type != BL_NPC) {
  3372. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3373. type = LOOK_WEAPON;
  3374. val = (vd ? vd->weapon : 0);
  3375. val2 = (vd ? vd->shield : 0);
  3376. }
  3377. if (disguised(bl)) {
  3378. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3379. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3380. } else
  3381. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3382. } else
  3383. unit_refresh(bl);
  3384. #endif
  3385. }
  3386. //Sends a change-base-look packet required for traps as they are triggered.
  3387. void clif_changetraplook(struct block_list *bl,int val) {
  3388. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3389. }
  3390. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3391. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3392. clif_sprite_change(bl, id, type, val, 0, target);
  3393. }
  3394. /// Character status (ZC_STATUS).
  3395. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3396. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3397. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3398. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3399. void clif_initialstatus(struct map_session_data *sd) {
  3400. int fd, mdef2;
  3401. unsigned char *buf;
  3402. nullpo_retv(sd);
  3403. fd=sd->fd;
  3404. WFIFOHEAD(fd, packet_len(0xbd));
  3405. buf = WFIFOP(fd,0);
  3406. WBUFW(buf,0) = 0xbd;
  3407. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3408. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3409. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3410. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3411. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3412. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3413. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3414. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3415. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3416. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3417. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3418. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3419. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3420. WBUFW(buf,16) = pc_leftside_atk(sd);
  3421. WBUFW(buf,18) = pc_rightside_atk(sd);
  3422. WBUFW(buf,20) = pc_rightside_matk(sd);
  3423. WBUFW(buf,22) = pc_leftside_matk(sd);
  3424. WBUFW(buf,24) = pc_leftside_def(sd);
  3425. WBUFW(buf,26) = pc_rightside_def(sd);
  3426. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3427. mdef2 = pc_rightside_mdef(sd);
  3428. WBUFW(buf,30) =
  3429. #ifndef RENEWAL
  3430. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3431. #endif
  3432. mdef2;
  3433. WBUFW(buf,32) = sd->battle_status.hit;
  3434. WBUFW(buf,34) = sd->battle_status.flee;
  3435. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3436. WBUFW(buf,38) = sd->battle_status.cri/10;
  3437. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3438. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3439. WFIFOSET(fd, packet_len(0xbd));
  3440. clif_updatestatus(sd, SP_STR);
  3441. clif_updatestatus(sd, SP_AGI);
  3442. clif_updatestatus(sd, SP_VIT);
  3443. clif_updatestatus(sd, SP_INT);
  3444. clif_updatestatus(sd, SP_DEX);
  3445. clif_updatestatus(sd, SP_LUK);
  3446. clif_updatestatus(sd, SP_ATTACKRANGE);
  3447. clif_updatestatus(sd, SP_ASPD);
  3448. #ifdef RENEWAL
  3449. clif_updatestatus(sd, SP_POW);
  3450. clif_updatestatus(sd, SP_STA);
  3451. clif_updatestatus(sd, SP_WIS);
  3452. clif_updatestatus(sd, SP_SPL);
  3453. clif_updatestatus(sd, SP_CON);
  3454. clif_updatestatus(sd, SP_CRT);
  3455. clif_updatestatus(sd, SP_PATK);
  3456. clif_updatestatus(sd, SP_SMATK);
  3457. clif_updatestatus(sd, SP_RES);
  3458. clif_updatestatus(sd, SP_MRES);
  3459. clif_updatestatus(sd, SP_HPLUS);
  3460. clif_updatestatus(sd, SP_CRATE);
  3461. clif_updatestatus(sd, SP_TRAITPOINT);
  3462. clif_updatestatus(sd, SP_AP);
  3463. clif_updatestatus(sd, SP_MAXAP);
  3464. clif_updatestatus(sd, SP_UPOW);
  3465. clif_updatestatus(sd, SP_USTA);
  3466. clif_updatestatus(sd, SP_UWIS);
  3467. clif_updatestatus(sd, SP_USPL);
  3468. clif_updatestatus(sd, SP_UCON);
  3469. clif_updatestatus(sd, SP_UCRT);
  3470. #endif
  3471. }
  3472. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3473. /// 013c <index>.W
  3474. void clif_arrowequip(struct map_session_data *sd,int val) {
  3475. int fd;
  3476. nullpo_retv(sd);
  3477. #if PACKETVER >= 20121128
  3478. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3479. #endif
  3480. fd=sd->fd;
  3481. WFIFOHEAD(fd, packet_len(0x013c));
  3482. WFIFOW(fd,0) = 0x013c;
  3483. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3484. WFIFOSET(fd, packet_len(0x013c));
  3485. }
  3486. /// Ammunition action message (ZC_ACTION_FAILURE).
  3487. /// 013b <type>.W
  3488. /// type:
  3489. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3490. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3491. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3492. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3493. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3494. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3495. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3496. int fd;
  3497. nullpo_retv(sd);
  3498. fd=sd->fd;
  3499. WFIFOHEAD(fd, packet_len(0x013b));
  3500. WFIFOW(fd,0) = 0x013b;
  3501. WFIFOW(fd,2) = type;
  3502. WFIFOSET(fd, packet_len(0x013b));
  3503. }
  3504. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3505. /// 01ad <packet len>.W { <name id>.W }*
  3506. void clif_arrow_create_list( struct map_session_data *sd ){
  3507. nullpo_retv( sd );
  3508. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3509. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3510. int count = 0;
  3511. for (const auto &it : skill_arrow_db) {
  3512. t_itemid nameid = it.second->nameid;
  3513. if( !item_db.exists( nameid ) ){
  3514. continue;
  3515. }
  3516. int index = pc_search_inventory( sd, nameid );
  3517. if( index < 0 ){
  3518. continue;
  3519. }
  3520. if( sd->inventory.u.items_inventory[index].equip ){
  3521. continue;
  3522. }
  3523. if( !sd->inventory.u.items_inventory[index].identify ){
  3524. continue;
  3525. }
  3526. p->items[count].itemId = client_nameid( nameid );
  3527. count++;
  3528. }
  3529. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3530. clif_send( p, p->packetLength, &sd->bl, SELF );
  3531. if( count > 0 ){
  3532. sd->menuskill_id = AC_MAKINGARROW;
  3533. sd->menuskill_val = count;
  3534. }
  3535. }
  3536. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3537. /// 00bc <status id>.W <result>.B <value>.B
  3538. /// status id:
  3539. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3540. /// result:
  3541. /// 0 = failure
  3542. /// 1 = success
  3543. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3544. int fd;
  3545. nullpo_retv(sd);
  3546. fd=sd->fd;
  3547. WFIFOHEAD(fd, packet_len(0xbc));
  3548. WFIFOW(fd,0) = 0xbc;
  3549. WFIFOW(fd,2) = type;
  3550. WFIFOB(fd,4) = ok;
  3551. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3552. WFIFOSET(fd, packet_len(0xbc));
  3553. }
  3554. /// Notifies the client about the result of a request to equip an item.
  3555. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3556. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3557. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3558. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3559. /// @ok: //inversed forv2 v5
  3560. /// 0 = failure
  3561. /// 1 = success
  3562. /// 2 = failure due to low level
  3563. void clif_equipitemack( struct map_session_data& sd, uint8 flag, int index, int pos ){
  3564. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3565. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3566. p.index = client_index( index );
  3567. p.wearLocation = pos;
  3568. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3569. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3570. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3571. }else{
  3572. p.wItemSpriteNumber = 0;
  3573. }
  3574. #endif
  3575. p.result = flag;
  3576. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3577. }
  3578. /// Notifies the client about the result of a request to take off an item.
  3579. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3580. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3581. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3582. /// @ok : //inversed for v2 v5
  3583. /// 0 = failure
  3584. /// 1 = success
  3585. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3586. {
  3587. int fd, header, offs = 0;
  3588. #if PACKETVER >= 20130000
  3589. header = 0x99a;
  3590. ok = ok ? 0 : 1;
  3591. #elif PACKETVER >= 20110824
  3592. header = 0x8d1;
  3593. ok = ok ? 0 : 1;
  3594. #else
  3595. header = 0xac;
  3596. #endif
  3597. nullpo_retv(sd);
  3598. fd=sd->fd;
  3599. WFIFOHEAD(fd, packet_len(header));
  3600. WFIFOW(fd,offs+0) = header;
  3601. WFIFOW(fd,offs+2) = n+2;
  3602. #if PACKETVER >= 20130000
  3603. WFIFOL(fd,offs+4) = pos;
  3604. offs += 2;
  3605. #else
  3606. WFIFOW(fd,offs+4) = pos;
  3607. #endif
  3608. WFIFOB(fd,offs+6) = ok;
  3609. WFIFOSET(fd, packet_len(header));
  3610. }
  3611. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3612. /// 019b <id>.L <effect id>.L
  3613. /// effect id:
  3614. /// 0 = base level up
  3615. /// 1 = job level up
  3616. /// 2 = refine failure
  3617. /// 3 = refine success
  3618. /// 4 = game over
  3619. /// 5 = pharmacy success
  3620. /// 6 = pharmacy failure
  3621. /// 7 = base level up (super novice)
  3622. /// 8 = job level up (super novice)
  3623. /// 9 = base level up (taekwon)
  3624. void clif_misceffect(struct block_list* bl,int type)
  3625. {
  3626. unsigned char buf[32];
  3627. nullpo_retv(bl);
  3628. WBUFW(buf,0) = 0x19b;
  3629. WBUFL(buf,2) = bl->id;
  3630. WBUFL(buf,6) = type;
  3631. clif_send(buf,packet_len(0x19b),bl,AREA);
  3632. }
  3633. /// Notifies clients in the area of a state change.
  3634. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3635. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3636. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3637. nullpo_retv( bl );
  3638. struct status_change* sc = status_get_sc( bl );
  3639. //How can an option change if there's no sc?
  3640. if( sc == nullptr ){
  3641. return;
  3642. }
  3643. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3644. struct PACKET_ZC_STATE_CHANGE p;
  3645. p.packetType = HEADER_ZC_STATE_CHANGE;
  3646. p.AID = bl->id;
  3647. p.bodyState = sc->opt1;
  3648. p.healthState = sc->opt2;
  3649. p.effectState = sc->option;
  3650. p.isPKModeON = sd ? sd->status.karma : false;
  3651. if( target == nullptr ){
  3652. if( disguised( bl ) ){
  3653. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3654. p.AID = disguised_bl_id( p.AID );
  3655. clif_send( &p, sizeof( p ), bl, SELF );
  3656. p.AID = disguised_bl_id( p.AID );
  3657. p.effectState = OPTION_INVISIBLE;
  3658. clif_send( &p, sizeof( p ), bl, SELF );
  3659. }else{
  3660. clif_send( &p, sizeof( p ), bl, AREA );
  3661. }
  3662. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3663. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3664. if( sc->data[SC_PROVOKE] ){
  3665. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3666. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3667. }
  3668. }else{
  3669. if( disguised( bl ) ){
  3670. p.AID = disguised_bl_id( p.AID );
  3671. clif_send( &p, sizeof( p ), target, SELF );
  3672. p.AID = disguised_bl_id( p.AID );
  3673. p.effectState = OPTION_INVISIBLE;
  3674. clif_send( &p, sizeof( p ), target, SELF );
  3675. }else{
  3676. clif_send( &p, sizeof( p ), target, SELF );
  3677. }
  3678. }
  3679. }
  3680. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3681. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3682. void clif_changeoption2(struct block_list* bl)
  3683. {
  3684. unsigned char buf[20];
  3685. struct status_change *sc;
  3686. sc = status_get_sc(bl);
  3687. if (!sc) return; //How can an option change if there's no sc?
  3688. WBUFW(buf,0) = 0x28a;
  3689. WBUFL(buf,2) = bl->id;
  3690. WBUFL(buf,6) = sc->option;
  3691. WBUFL(buf,10) = clif_setlevel(bl);
  3692. WBUFL(buf,14) = sc->opt3;
  3693. if(disguised(bl)) {
  3694. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3695. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3696. clif_send(buf,packet_len(0x28a),bl,SELF);
  3697. WBUFL(buf,2) = bl->id;
  3698. WBUFL(buf,6) = OPTION_INVISIBLE;
  3699. clif_send(buf,packet_len(0x28a),bl,SELF);
  3700. } else
  3701. clif_send(buf,packet_len(0x28a),bl,AREA);
  3702. }
  3703. /// Notifies the client about the result of an item use request.
  3704. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3705. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3706. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3707. nullpo_retv( sd );
  3708. int fd = sd->fd;
  3709. if( !session_isActive( fd ) ){
  3710. return;
  3711. }
  3712. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3713. return;
  3714. }
  3715. struct PACKET_ZC_USE_ITEM_ACK p;
  3716. p.packetType = useItemAckType;
  3717. p.index = index + 2;
  3718. #if PACKETVER > 3
  3719. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3720. p.AID = sd->bl.id;
  3721. #endif
  3722. p.amount = amount;
  3723. p.result = ok;
  3724. if( !ok ){
  3725. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3726. }else{
  3727. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3728. }
  3729. }
  3730. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3731. /// 00d6 <flag>.B
  3732. /// flag:
  3733. /// 0 = Room has been successfully created (opens chat room)
  3734. /// 1 = Room limit exceeded
  3735. /// 2 = Same room already exists
  3736. void clif_createchat(struct map_session_data* sd, int flag)
  3737. {
  3738. int fd;
  3739. nullpo_retv(sd);
  3740. fd = sd->fd;
  3741. WFIFOHEAD(fd,packet_len(0xd6));
  3742. WFIFOW(fd,0) = 0xd6;
  3743. WFIFOB(fd,2) = flag;
  3744. WFIFOSET(fd,packet_len(0xd6));
  3745. }
  3746. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3747. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3748. /// type:
  3749. /// 0 = private (password protected)
  3750. /// 1 = public
  3751. /// 2 = arena (npc waiting room)
  3752. /// 3 = PK zone (non-clickable)
  3753. void clif_dispchat(struct chat_data* cd, int fd)
  3754. {
  3755. unsigned char buf[128];
  3756. uint8 type;
  3757. if( cd == NULL || cd->owner == NULL )
  3758. return;
  3759. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3760. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3761. : 1;
  3762. WBUFW(buf, 0) = 0xd7;
  3763. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3764. WBUFL(buf, 4) = cd->owner->id;
  3765. WBUFL(buf, 8) = cd->bl.id;
  3766. WBUFW(buf,12) = cd->limit;
  3767. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3768. WBUFB(buf,16) = type;
  3769. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3770. if( session_isActive(fd) ) {
  3771. WFIFOHEAD(fd,WBUFW(buf,2));
  3772. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3773. WFIFOSET(fd,WBUFW(buf,2));
  3774. } else {
  3775. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3776. }
  3777. }
  3778. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3779. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3780. /// type:
  3781. /// 0 = private (password protected)
  3782. /// 1 = public
  3783. /// 2 = arena (npc waiting room)
  3784. /// 3 = PK zone (non-clickable)
  3785. void clif_changechatstatus(struct chat_data* cd)
  3786. {
  3787. unsigned char buf[128];
  3788. uint8 type;
  3789. if( cd == NULL || cd->usersd[0] == NULL )
  3790. return;
  3791. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3792. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3793. : 1;
  3794. WBUFW(buf, 0) = 0xdf;
  3795. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3796. WBUFL(buf, 4) = cd->owner->id;
  3797. WBUFL(buf, 8) = cd->bl.id;
  3798. WBUFW(buf,12) = cd->limit;
  3799. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3800. WBUFB(buf,16) = type;
  3801. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3802. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3803. }
  3804. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3805. /// 00d8 <chat id>.L
  3806. void clif_clearchat(struct chat_data *cd,int fd)
  3807. {
  3808. unsigned char buf[32];
  3809. nullpo_retv(cd);
  3810. WBUFW(buf,0) = 0xd8;
  3811. WBUFL(buf,2) = cd->bl.id;
  3812. if( session_isActive(fd) ) {
  3813. WFIFOHEAD(fd,packet_len(0xd8));
  3814. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3815. WFIFOSET(fd,packet_len(0xd8));
  3816. } else {
  3817. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3818. }
  3819. }
  3820. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3821. /// 00da <result>.B
  3822. /// result:
  3823. /// 0 = room full
  3824. /// 1 = wrong password
  3825. /// 2 = kicked
  3826. /// 3 = success (no message)
  3827. /// 4 = no enough zeny
  3828. /// 5 = too low level
  3829. /// 6 = too high level
  3830. /// 7 = unsuitable job class
  3831. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3832. {
  3833. int fd;
  3834. nullpo_retv(sd);
  3835. fd = sd->fd;
  3836. WFIFOHEAD(fd,packet_len(0xda));
  3837. WFIFOW(fd,0) = 0xda;
  3838. WFIFOB(fd,2) = flag;
  3839. WFIFOSET(fd,packet_len(0xda));
  3840. }
  3841. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3842. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3843. /// role:
  3844. /// 0 = owner (menu)
  3845. /// 1 = normal
  3846. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3847. {
  3848. int fd;
  3849. int i,t;
  3850. nullpo_retv(sd);
  3851. nullpo_retv(cd);
  3852. fd = sd->fd;
  3853. if (!session_isActive(fd))
  3854. return;
  3855. t = (int)(cd->owner->type == BL_NPC);
  3856. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3857. WFIFOW(fd, 0) = 0xdb;
  3858. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3859. WFIFOL(fd, 4) = cd->bl.id;
  3860. if(cd->owner->type == BL_NPC){
  3861. WFIFOL(fd, 30) = 1;
  3862. WFIFOL(fd, 8) = 0;
  3863. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3864. for (i = 0; i < cd->users; i++) {
  3865. WFIFOL(fd, 8+(i+1)*28) = 1;
  3866. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3867. }
  3868. }else{
  3869. for (i = 0; i < cd->users; i++) {
  3870. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3871. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3872. }
  3873. }
  3874. WFIFOSET(fd, WFIFOW(fd, 2));
  3875. }
  3876. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3877. /// 00dc <users>.W <name>.24B
  3878. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3879. {
  3880. unsigned char buf[29];
  3881. nullpo_retv(sd);
  3882. nullpo_retv(cd);
  3883. WBUFW(buf, 0) = 0xdc;
  3884. WBUFW(buf, 2) = cd->users;
  3885. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3886. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3887. }
  3888. /// Announce the new owner (ZC_ROLE_CHANGE).
  3889. /// 00e1 <role>.L <nick>.24B
  3890. /// role:
  3891. /// 0 = owner (menu)
  3892. /// 1 = normal
  3893. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3894. {
  3895. unsigned char buf[64];
  3896. nullpo_retv(sd);
  3897. nullpo_retv(cd);
  3898. WBUFW(buf, 0) = 0xe1;
  3899. WBUFL(buf, 2) = 1;
  3900. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3901. WBUFW(buf,30) = 0xe1;
  3902. WBUFL(buf,32) = 0;
  3903. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3904. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3905. }
  3906. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3907. /// 00dd <users>.W <nick>.24B <flag>.B
  3908. /// flag:
  3909. /// 0 = left
  3910. /// 1 = kicked
  3911. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3912. {
  3913. unsigned char buf[32];
  3914. nullpo_retv(sd);
  3915. nullpo_retv(cd);
  3916. WBUFW(buf, 0) = 0xdd;
  3917. WBUFW(buf, 2) = cd->users-1;
  3918. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3919. WBUFB(buf,28) = flag;
  3920. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3921. }
  3922. /// Opens a trade request window from char 'name'.
  3923. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3924. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3925. void clif_traderequest(struct map_session_data* sd, const char* name)
  3926. {
  3927. int fd = sd->fd;
  3928. #if PACKETVER < 6
  3929. WFIFOHEAD(fd,packet_len(0xe5));
  3930. WFIFOW(fd,0) = 0xe5;
  3931. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3932. WFIFOSET(fd,packet_len(0xe5));
  3933. #else
  3934. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3935. if( !tsd ) return;
  3936. WFIFOHEAD(fd,packet_len(0x1f4));
  3937. WFIFOW(fd,0) = 0x1f4;
  3938. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3939. WFIFOL(fd,26) = tsd->status.char_id;
  3940. WFIFOW(fd,30) = tsd->status.base_level;
  3941. WFIFOSET(fd,packet_len(0x1f4));
  3942. #endif
  3943. }
  3944. /// Reply to a trade-request.
  3945. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3946. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3947. /// result:
  3948. /// 0 = Char is too far
  3949. /// 1 = Character does not exist
  3950. /// 2 = Trade failed
  3951. /// 3 = Accept
  3952. /// 4 = Cancel
  3953. /// 5 = Busy
  3954. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3955. {
  3956. int fd = sd->fd;
  3957. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3958. if( PACKETVER < 6 || !tsd ) {
  3959. WFIFOHEAD(fd,packet_len(0xe7));
  3960. WFIFOW(fd,0) = 0xe7;
  3961. WFIFOB(fd,2) = type;
  3962. WFIFOSET(fd,packet_len(0xe7));
  3963. } else {
  3964. WFIFOHEAD(fd,packet_len(0x1f5));
  3965. WFIFOW(fd,0) = 0x1f5;
  3966. WFIFOB(fd,2) = type;
  3967. WFIFOL(fd,3) = tsd->status.char_id;
  3968. WFIFOW(fd,7) = tsd->status.base_level;
  3969. WFIFOSET(fd,packet_len(0x1f5));
  3970. }
  3971. }
  3972. /// Notifies the client about an item from other player in current trade.
  3973. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3974. /// 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)
  3975. /// 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)
  3976. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  3977. nullpo_retv( sd );
  3978. nullpo_retv( tsd );
  3979. int fd = tsd->fd;
  3980. if( !session_isActive( fd ) ){
  3981. return;
  3982. }
  3983. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3984. if( index ){
  3985. index = server_index( index );
  3986. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3987. return;
  3988. }
  3989. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3990. #if PACKETVER >= 20100223
  3991. p.itemType = sd->inventory_data[index]->type;
  3992. #endif
  3993. p.identified = sd->inventory.u.items_inventory[index].identify;
  3994. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3995. p.refine = sd->inventory.u.items_inventory[index].refine;
  3996. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3997. #if PACKETVER >= 20150226
  3998. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  3999. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4000. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4001. p.look = sd->inventory_data[index]->look;
  4002. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4003. #endif
  4004. #endif
  4005. }else{
  4006. p = {};
  4007. }
  4008. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4009. p.amount = amount;
  4010. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4011. }
  4012. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4013. /// 00ea <index>.W <result>.B
  4014. /// result:
  4015. /// 0 = success
  4016. /// 1 = overweight
  4017. /// 2 = trade canceled
  4018. void clif_tradeitemok(struct map_session_data& sd, int index, e_exitem_add_result result)
  4019. {
  4020. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4021. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4022. p.index = client_index(index);
  4023. p.result = static_cast<uint8>(result);
  4024. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4025. }
  4026. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4027. /// 00ec <who>.B
  4028. /// who:
  4029. /// 0 = self
  4030. /// 1 = other player
  4031. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  4032. {
  4033. int fd;
  4034. nullpo_retv(sd);
  4035. fd = sd->fd;
  4036. WFIFOHEAD(fd,packet_len(0xec));
  4037. WFIFOW(fd,0) = 0xec;
  4038. WFIFOB(fd,2) = fail;
  4039. WFIFOSET(fd,packet_len(0xec));
  4040. }
  4041. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4042. /// 00ee
  4043. void clif_tradecancelled(struct map_session_data* sd)
  4044. {
  4045. int fd;
  4046. nullpo_retv(sd);
  4047. fd = sd->fd;
  4048. WFIFOHEAD(fd,packet_len(0xee));
  4049. WFIFOW(fd,0) = 0xee;
  4050. WFIFOSET(fd,packet_len(0xee));
  4051. }
  4052. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4053. /// 00f0 <result>.B
  4054. /// result:
  4055. /// 0 = success
  4056. /// 1 = failure
  4057. void clif_tradecompleted(struct map_session_data* sd, int fail)
  4058. {
  4059. int fd;
  4060. nullpo_retv(sd);
  4061. fd = sd->fd;
  4062. WFIFOHEAD(fd,packet_len(0xf0));
  4063. WFIFOW(fd,0) = 0xf0;
  4064. WFIFOB(fd,2) = fail;
  4065. WFIFOSET(fd,packet_len(0xf0));
  4066. }
  4067. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4068. /// 00f1
  4069. /// NOTE: Unknown purpose. Items are not removed until the window is
  4070. /// refreshed (ex. by putting another item in there).
  4071. void clif_tradeundo(struct map_session_data* sd)
  4072. {
  4073. int fd = sd->fd;
  4074. WFIFOHEAD(fd,packet_len(0xf1));
  4075. WFIFOW(fd,0) = 0xf1;
  4076. WFIFOSET(fd,packet_len(0xf1));
  4077. }
  4078. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4079. /// 00f2 <current count>.W <max count>.W
  4080. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  4081. {
  4082. int fd;
  4083. nullpo_retv(sd);
  4084. fd=sd->fd;
  4085. WFIFOHEAD(fd,packet_len(0xf2));
  4086. WFIFOW(fd,0) = 0xf2;
  4087. WFIFOW(fd,2) = amount;
  4088. WFIFOW(fd,4) = max_amount;
  4089. WFIFOSET(fd,packet_len(0xf2));
  4090. }
  4091. /// Notifies the client of an item being added to the storage.
  4092. /// 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)
  4093. /// 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)
  4094. /// 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)
  4095. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  4096. nullpo_retv( sd );
  4097. nullpo_retv( i );
  4098. int fd = sd->fd;
  4099. if( !session_isActive( fd ) ){
  4100. return;
  4101. }
  4102. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4103. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4104. p.index = client_storage_index( index ); // index
  4105. p.amount = amount; // amount
  4106. p.itemId = client_nameid( i->nameid ); // id
  4107. #if PACKETVER >= 5
  4108. p.itemType = itemtype( i->nameid ); //type
  4109. #endif
  4110. p.identified = i->identify; //identify flag
  4111. p.damaged = i->attribute; // attribute
  4112. p.refine = i->refine; //refine
  4113. clif_addcards( &p.slot, i );
  4114. #if PACKETVER >= 20150226
  4115. clif_add_random_options( p.option_data, i );
  4116. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4117. p.enchantgrade = i->enchantgrade;
  4118. #endif
  4119. #endif
  4120. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4121. }
  4122. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4123. /// 00f6 <index>.W <amount>.L
  4124. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4125. {
  4126. int fd;
  4127. nullpo_retv(sd);
  4128. fd=sd->fd;
  4129. WFIFOHEAD(fd,packet_len(0xf6));
  4130. WFIFOW(fd,0)=0xf6; // Storage item removed
  4131. WFIFOW(fd,2)=client_storage_index(index);
  4132. WFIFOL(fd,4)=amount;
  4133. WFIFOSET(fd,packet_len(0xf6));
  4134. }
  4135. /// Closes storage (ZC_CLOSE_STORE).
  4136. /// 00f8
  4137. void clif_storageclose(struct map_session_data* sd)
  4138. {
  4139. int fd;
  4140. nullpo_retv(sd);
  4141. fd=sd->fd;
  4142. WFIFOHEAD(fd,packet_len(0xf8));
  4143. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4144. WFIFOSET(fd,packet_len(0xf8));
  4145. }
  4146. /// Notifies clients in an area of a player's souls.
  4147. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4148. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4149. /// 0b73 <id>.L <amount>.W
  4150. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4151. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4152. struct PACKET_ZC_SOULENERGY p = {};
  4153. p.PacketType = HEADER_ZC_SOULENERGY;
  4154. #else
  4155. struct PACKET_ZC_SPIRITS p = {};
  4156. p.PacketType = HEADER_ZC_SPIRITS;
  4157. #endif
  4158. p.AID = sd->bl.id;
  4159. p.num = sd->soulball;
  4160. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4161. }
  4162. /*==========================================
  4163. * Server tells 'sd' player client the abouts of 'dstsd' player
  4164. *------------------------------------------*/
  4165. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4166. {
  4167. struct block_list *d_bl;
  4168. int i;
  4169. if( dstsd->chatID ) {
  4170. struct chat_data *cd = NULL;
  4171. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4172. clif_dispchat(cd,sd->fd);
  4173. } else if( dstsd->state.vending )
  4174. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4175. else if( dstsd->state.buyingstore )
  4176. clif_buyingstore_entry( *dstsd, &sd->bl );
  4177. if(dstsd->spiritball > 0)
  4178. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4179. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4180. clif_millenniumshield_single(sd->fd, dstsd);
  4181. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4182. clif_spiritcharm_single(sd->fd, dstsd);
  4183. if (dstsd->soulball > 0)
  4184. clif_soulball( dstsd, &sd->bl, SELF );
  4185. if (dstsd->servantball > 0)
  4186. clif_servantball( *dstsd, &sd->bl, SELF );
  4187. if (dstsd->abyssball > 0)
  4188. clif_abyssball( *dstsd, &sd->bl, SELF );
  4189. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4190. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4191. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4192. )
  4193. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4194. // display link (sd - dstsd) to sd
  4195. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4196. if( i < MAX_DEVOTION )
  4197. clif_devotion(&sd->bl, sd);
  4198. // display links (dstsd - devotees) to sd
  4199. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4200. if( i < MAX_DEVOTION )
  4201. clif_devotion(&dstsd->bl, sd);
  4202. // display link (dstsd - crusader) to sd
  4203. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4204. clif_devotion(d_bl, sd);
  4205. }
  4206. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4207. struct unit_data *ud;
  4208. struct view_data *vd;
  4209. bool option = false;
  4210. unsigned int option_val = 0;
  4211. vd = status_get_viewdata(bl);
  4212. if (!vd || vd->class_ == JT_INVISIBLE)
  4213. return;
  4214. // Hide NPC from Maya Purple card
  4215. if (clif_npc_mayapurple(bl))
  4216. return;
  4217. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4218. // Do not send anything
  4219. return;
  4220. }
  4221. ud = unit_bl2ud(bl);
  4222. if( ud && ud->walktimer != INVALID_TIMER ){
  4223. clif_set_unit_walking( bl, sd, ud, SELF );
  4224. }else{
  4225. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4226. }
  4227. if (vd->cloth_color)
  4228. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4229. if (vd->body_style)
  4230. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4231. switch (bl->type)
  4232. {
  4233. case BL_PC:
  4234. {
  4235. TBL_PC* tsd = (TBL_PC*)bl;
  4236. clif_getareachar_pc(sd, tsd);
  4237. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4238. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4239. else if(tsd->state.size==SZ_MEDIUM)
  4240. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4241. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4242. clif_sendbgemblem_single(sd->fd,tsd);
  4243. if ( tsd->status.robe )
  4244. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4245. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4246. clif_hat_effects(sd,bl,SELF);
  4247. }
  4248. break;
  4249. case BL_MER: // Devotion Effects
  4250. if( ((TBL_MER*)bl)->devotion_flag )
  4251. clif_devotion(bl, sd);
  4252. break;
  4253. case BL_NPC:
  4254. {
  4255. TBL_NPC* nd = (TBL_NPC*)bl;
  4256. if( nd->chat_id )
  4257. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4258. if( nd->size == SZ_BIG )
  4259. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4260. else if( nd->size == SZ_MEDIUM )
  4261. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4262. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4263. clif_progressbar_npc(nd, sd);
  4264. }
  4265. break;
  4266. case BL_MOB:
  4267. {
  4268. TBL_MOB* md = (TBL_MOB*)bl;
  4269. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4270. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4271. else if(md->special_state.size==SZ_MEDIUM)
  4272. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4273. #if PACKETVER >= 20120404
  4274. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4275. int i;
  4276. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4277. if( md->dmglog[i].id == sd->status.char_id )
  4278. clif_monster_hp_bar(md, sd->fd);
  4279. }
  4280. #endif
  4281. }
  4282. break;
  4283. case BL_PET:
  4284. if (vd->head_bottom)
  4285. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4286. break;
  4287. }
  4288. }
  4289. //Modifies the type of damage according to status changes [Skotlex]
  4290. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4291. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4292. {
  4293. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4294. }
  4295. /*==========================================
  4296. * Estimates walk delay based on the damage criteria. [Skotlex]
  4297. *------------------------------------------*/
  4298. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4299. {
  4300. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4301. return 0;
  4302. if (bl->type == BL_PC) {
  4303. if (battle_config.pc_walk_delay_rate != 100)
  4304. delay = delay*battle_config.pc_walk_delay_rate/100;
  4305. } else
  4306. if (battle_config.walk_delay_rate != 100)
  4307. delay = delay*battle_config.walk_delay_rate/100;
  4308. if (div_ > 1) //Multi-hit skills mean higher delays.
  4309. delay += battle_config.multihit_delay*(div_-1);
  4310. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4311. }
  4312. /*========================================== [Playtester]
  4313. * Returns hallucination damage the client displays
  4314. *------------------------------------------*/
  4315. static int clif_hallucination_damage()
  4316. {
  4317. int digit = rnd() % 5 + 1;
  4318. switch (digit)
  4319. {
  4320. case 1:
  4321. return (rnd() % 10);
  4322. case 2:
  4323. return (rnd() % 100);
  4324. case 3:
  4325. return (rnd() % 1000);
  4326. case 4:
  4327. return (rnd() % 10000);
  4328. }
  4329. return (rnd() % 32767);
  4330. }
  4331. /// Sends a 'damage' packet (src performs action on dst)
  4332. /// 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)
  4333. /// 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)
  4334. /// 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)
  4335. /// type:
  4336. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4337. /// 1 = pick up item
  4338. /// 2 = sit down
  4339. /// 3 = stand up
  4340. /// 4 = damage (endure)
  4341. /// 5 = (splash?)
  4342. /// 6 = (skill?)
  4343. /// 7 = (repeat damage?)
  4344. /// 8 = multi-hit damage
  4345. /// 9 = multi-hit damage (endure)
  4346. /// 10 = critical hit
  4347. /// 11 = lucky dodge
  4348. /// 12 = (touch skill?)
  4349. /// 13 = multi-hit critical
  4350. 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)
  4351. {
  4352. unsigned char buf[34];
  4353. struct status_change *sc;
  4354. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4355. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4356. #if PACKETVER < 20071113
  4357. const int cmd = 0x8a;
  4358. int offset = 0;
  4359. #elif PACKETVER < 20131223
  4360. const int cmd = 0x2e1;
  4361. int offset = 2;
  4362. #else
  4363. const int cmd = 0x8c8;
  4364. int offset = 3;
  4365. #endif
  4366. nullpo_ret(src);
  4367. nullpo_ret(dst);
  4368. if (type != DMG_MULTI_HIT_CRITICAL)
  4369. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4370. sc = status_get_sc(dst);
  4371. if(sc && sc->count) {
  4372. if(sc->data[SC_HALLUCINATION]) {
  4373. damage = clif_hallucination_damage();
  4374. if(damage2) damage2 = clif_hallucination_damage();
  4375. }
  4376. }
  4377. WBUFW(buf,0) = cmd;
  4378. WBUFL(buf,2) = src->id;
  4379. WBUFL(buf,6) = dst->id;
  4380. WBUFL(buf,10) = client_tick(tick);
  4381. WBUFL(buf,14) = sdelay;
  4382. WBUFL(buf,18) = ddelay;
  4383. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4384. #if PACKETVER < 20071113
  4385. WBUFW(buf,22) = damage ? div : 0;
  4386. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4387. #else
  4388. WBUFL(buf, 22) = damage ? div : 0;
  4389. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4390. #endif
  4391. } else {
  4392. #if PACKETVER < 20071113
  4393. WBUFW(buf,22) = min(damage, INT16_MAX);
  4394. WBUFW(buf,27+offset) = damage2;
  4395. #else
  4396. WBUFL(buf,22) = damage;
  4397. WBUFL(buf,27+offset) = damage2;
  4398. #endif
  4399. }
  4400. #if PACKETVER >= 20131223
  4401. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4402. #endif
  4403. WBUFW(buf,24+offset) = div;
  4404. WBUFB(buf,26+offset) = type;
  4405. if(disguised(dst)) {
  4406. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4407. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4408. clif_send(buf, packet_len(cmd), dst, SELF);
  4409. } else
  4410. clif_send(buf, packet_len(cmd), dst, AREA);
  4411. if(disguised(src)) {
  4412. WBUFL(buf,2) = disguised_bl_id( src->id );
  4413. if (disguised(dst))
  4414. WBUFL(buf,6) = dst->id;
  4415. #if PACKETVER < 20071113
  4416. if(damage > 0) WBUFW(buf,22) = -1;
  4417. if(damage2 > 0) WBUFW(buf,27) = -1;
  4418. #else
  4419. if(damage > 0) WBUFL(buf,22) = -1;
  4420. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4421. #endif
  4422. clif_send(buf,packet_len(cmd),src,SELF);
  4423. }
  4424. if(src == dst) {
  4425. unit_setdir(src, unit_getdir(src));
  4426. }
  4427. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4428. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4429. //Return adjusted can't walk delay for further processing.
  4430. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4431. }
  4432. /*==========================================
  4433. * src picks up dst
  4434. *------------------------------------------*/
  4435. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4436. {
  4437. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4438. unsigned char buf[32];
  4439. nullpo_retv(src);
  4440. nullpo_retv(dst);
  4441. WBUFW(buf, 0) = 0x8a;
  4442. WBUFL(buf, 2) = src->id;
  4443. WBUFL(buf, 6) = dst->id;
  4444. WBUFB(buf,26) = 1;
  4445. clif_send(buf, packet_len(0x8a), src, AREA);
  4446. }
  4447. /*==========================================
  4448. * inform clients in area that `bl` is sitting
  4449. *------------------------------------------*/
  4450. void clif_sitting(struct block_list* bl)
  4451. {
  4452. unsigned char buf[32];
  4453. nullpo_retv(bl);
  4454. WBUFW(buf, 0) = 0x8a;
  4455. WBUFL(buf, 2) = bl->id;
  4456. WBUFB(buf,26) = 2;
  4457. clif_send(buf, packet_len(0x8a), bl, AREA);
  4458. if(disguised(bl)) {
  4459. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4460. clif_send(buf, packet_len(0x8a), bl, SELF);
  4461. }
  4462. }
  4463. /*==========================================
  4464. * inform clients in area that `bl` is standing
  4465. *------------------------------------------*/
  4466. void clif_standing(struct block_list* bl)
  4467. {
  4468. unsigned char buf[32];
  4469. nullpo_retv(bl);
  4470. WBUFW(buf, 0) = 0x8a;
  4471. WBUFL(buf, 2) = bl->id;
  4472. WBUFB(buf,26) = 3;
  4473. clif_send(buf, packet_len(0x8a), bl, AREA);
  4474. if(disguised(bl)) {
  4475. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4476. clif_send(buf, packet_len(0x8a), bl, SELF);
  4477. }
  4478. }
  4479. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4480. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4481. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4482. {
  4483. unsigned char buf[32];
  4484. WBUFW(buf,0) = 0x192;
  4485. WBUFW(buf,2) = x;
  4486. WBUFW(buf,4) = y;
  4487. WBUFW(buf,6) = type;
  4488. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4489. if( session_isActive(fd) )
  4490. {
  4491. WFIFOHEAD(fd,packet_len(0x192));
  4492. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4493. WFIFOSET(fd,packet_len(0x192));
  4494. }
  4495. else
  4496. {
  4497. struct block_list dummy_bl;
  4498. dummy_bl.type = BL_NUL;
  4499. dummy_bl.x = x;
  4500. dummy_bl.y = y;
  4501. dummy_bl.m = m;
  4502. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4503. }
  4504. }
  4505. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4506. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4507. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4508. nullpo_retv( sd );
  4509. nullpo_retv( fitem );
  4510. struct PACKET_ZC_ITEM_ENTRY p;
  4511. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4512. p.AID = fitem->bl.id;
  4513. p.itemId = client_nameid( fitem->item.nameid );
  4514. p.identify = fitem->item.identify;
  4515. p.x = fitem->bl.x;
  4516. p.y = fitem->bl.y;
  4517. p.amount = fitem->item.amount;
  4518. p.subX = fitem->subx;
  4519. p.subY = fitem->suby;
  4520. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4521. }
  4522. /// Notifes client about Graffiti
  4523. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4524. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4525. unsigned char buf[128];
  4526. nullpo_retv(bl);
  4527. nullpo_retv(unit);
  4528. WBUFW(buf, 0) = 0x1c9;
  4529. WBUFL(buf, 2) = unit->bl.id;
  4530. WBUFL(buf, 6) = unit->group->src_id;
  4531. WBUFW(buf,10) = unit->bl.x;
  4532. WBUFW(buf,12) = unit->bl.y;
  4533. WBUFB(buf,14) = unit->group->unit_id;
  4534. WBUFB(buf,15) = 1;
  4535. WBUFB(buf,16) = 1;
  4536. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4537. clif_send(buf,packet_len(0x1c9),bl,target);
  4538. }
  4539. /// Notifies the client of a skill unit.
  4540. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4541. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4542. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4543. /// 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)
  4544. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4545. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4546. unsigned char buf[128];
  4547. nullpo_retv(bl);
  4548. nullpo_retv(unit);
  4549. if (bl->type == BL_PC)
  4550. fd = ((TBL_PC*)bl)->fd;
  4551. if (unit->group->state.guildaura)
  4552. return;
  4553. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4554. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4555. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4556. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4557. else
  4558. unit_id = unit->group->unit_id;
  4559. if (!visible)
  4560. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4561. #if PACKETVER >= 3
  4562. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4563. clif_graffiti(bl, unit, target);
  4564. return;
  4565. }
  4566. #endif
  4567. #if PACKETVER <= 20120702
  4568. header = 0x011f;
  4569. //#if PACKETVER < 20110718
  4570. // header = 0x011f;
  4571. //#elif PACKETVER < 20121212
  4572. // header = 0x08c7;
  4573. #elif PACKETVER < 20130731
  4574. header = 0x099f;
  4575. #else
  4576. header = 0x09ca;
  4577. #endif
  4578. len = packet_len(header);
  4579. WBUFW(buf,pos) = header;
  4580. if (header != 0x011f) {
  4581. WBUFW(buf, pos+2) = len;
  4582. pos += 2;
  4583. }
  4584. WBUFL(buf,pos+2) = unit->bl.id;
  4585. WBUFL(buf,pos+6) = unit->group->src_id;
  4586. WBUFW(buf,pos+10) = unit->bl.x;
  4587. WBUFW(buf,pos+12) = unit->bl.y;
  4588. switch (header) {
  4589. case 0x011f:
  4590. WBUFB(buf,pos+14) = unit_id;
  4591. WBUFB(buf,pos+15) = visible;
  4592. break;
  4593. case 0x08c7:
  4594. WBUFB(buf,pos+14) = unit_id;
  4595. WBUFW(buf,pos+15) = unit->range;
  4596. WBUFB(buf,pos+17) = visible;
  4597. break;
  4598. case 0x099f:
  4599. WBUFL(buf,pos+14) = unit_id;
  4600. WBUFW(buf,pos+18) = unit->range;
  4601. WBUFB(buf,pos+20) = visible;
  4602. break;
  4603. case 0x09ca:
  4604. WBUFL(buf,pos+14) = unit_id;
  4605. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4606. WBUFB(buf,pos+19) = visible;
  4607. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4608. break;
  4609. }
  4610. clif_send(buf, len, bl, target);
  4611. if (unit->group->skill_id == WZ_ICEWALL)
  4612. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4613. }
  4614. /// 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)
  4615. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4616. unsigned char buf[128];
  4617. nullpo_retv(bl);
  4618. WBUFW(buf, 0) = 0x09ca;
  4619. WBUFW(buf, 2) = packet_len(0x09ca);
  4620. WBUFL(buf, 4) = 1000;
  4621. WBUFL(buf, 8) = 2000;
  4622. WBUFW(buf, 12) = x;
  4623. WBUFW(buf, 14) = y;
  4624. WBUFL(buf, 16) = unit_id;
  4625. WBUFB(buf, 20) = (unsigned char)range;
  4626. WBUFB(buf, 21) = 1;
  4627. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4628. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4629. }
  4630. /*==========================================
  4631. * Server tells client to remove unit of id 'unit->bl.id'
  4632. *------------------------------------------*/
  4633. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4634. {
  4635. nullpo_retv(unit);
  4636. WFIFOHEAD(fd,packet_len(0x120));
  4637. WFIFOW(fd, 0)=0x120;
  4638. WFIFOL(fd, 2)=unit->bl.id;
  4639. WFIFOSET(fd,packet_len(0x120));
  4640. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4641. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4642. }
  4643. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4644. /// 0120 <id>.L
  4645. void clif_skill_delunit(struct skill_unit *unit)
  4646. {
  4647. unsigned char buf[16];
  4648. nullpo_retv(unit);
  4649. WBUFW(buf, 0)=0x120;
  4650. WBUFL(buf, 2)=unit->bl.id;
  4651. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4652. }
  4653. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4654. /// 01ac <id>.L
  4655. /// Only affects units with class [139,153] client-side.
  4656. void clif_skillunit_update(struct block_list* bl)
  4657. {
  4658. unsigned char buf[6];
  4659. nullpo_retv(bl);
  4660. WBUFW(buf,0) = 0x1ac;
  4661. WBUFL(buf,2) = bl->id;
  4662. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4663. }
  4664. /*==========================================
  4665. *
  4666. *------------------------------------------*/
  4667. static int clif_getareachar(struct block_list* bl,va_list ap)
  4668. {
  4669. struct map_session_data *sd;
  4670. nullpo_ret(bl);
  4671. sd=va_arg(ap,struct map_session_data*);
  4672. if (!clif_session_isValid(sd))
  4673. return 0;
  4674. switch(bl->type){
  4675. case BL_ITEM:
  4676. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4677. break;
  4678. case BL_SKILL:
  4679. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4680. break;
  4681. default:
  4682. if(&sd->bl == bl)
  4683. break;
  4684. clif_getareachar_unit(sd,bl);
  4685. break;
  4686. }
  4687. return 0;
  4688. }
  4689. /*==========================================
  4690. * tbl has gone out of view-size of bl
  4691. *------------------------------------------*/
  4692. int clif_outsight(struct block_list *bl,va_list ap)
  4693. {
  4694. struct block_list *tbl;
  4695. struct view_data *vd;
  4696. TBL_PC *sd, *tsd;
  4697. tbl=va_arg(ap,struct block_list*);
  4698. if(bl == tbl) return 0;
  4699. sd = BL_CAST(BL_PC, bl);
  4700. tsd = BL_CAST(BL_PC, tbl);
  4701. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4702. nullpo_ret(bl);
  4703. switch(bl->type){
  4704. case BL_PC:
  4705. if(sd->vd.class_ != JT_INVISIBLE)
  4706. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4707. if(sd->chatID){
  4708. struct chat_data *cd;
  4709. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4710. if(cd->usersd[0]==sd)
  4711. clif_dispchat(cd,tsd->fd);
  4712. }
  4713. if(sd->state.vending)
  4714. clif_closevendingboard(bl,tsd->fd);
  4715. if(sd->state.buyingstore)
  4716. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4717. break;
  4718. case BL_ITEM:
  4719. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4720. break;
  4721. case BL_SKILL:
  4722. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4723. break;
  4724. case BL_NPC:
  4725. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4726. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4727. break;
  4728. default:
  4729. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4730. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4731. break;
  4732. }
  4733. }
  4734. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4735. nullpo_ret(tbl);
  4736. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4737. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4738. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4739. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4740. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4741. }
  4742. return 0;
  4743. }
  4744. /*==========================================
  4745. * tbl has come into view of bl
  4746. *------------------------------------------*/
  4747. int clif_insight(struct block_list *bl,va_list ap)
  4748. {
  4749. struct block_list *tbl;
  4750. TBL_PC *sd, *tsd;
  4751. tbl=va_arg(ap,struct block_list*);
  4752. if (bl == tbl) return 0;
  4753. sd = BL_CAST(BL_PC, bl);
  4754. tsd = BL_CAST(BL_PC, tbl);
  4755. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4756. switch(bl->type){
  4757. case BL_ITEM:
  4758. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4759. break;
  4760. case BL_SKILL:
  4761. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4762. break;
  4763. default:
  4764. clif_getareachar_unit(tsd,bl);
  4765. break;
  4766. }
  4767. }
  4768. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4769. clif_getareachar_unit(sd,tbl);
  4770. }
  4771. return 0;
  4772. }
  4773. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4774. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4775. void clif_skillinfoblock(struct map_session_data *sd)
  4776. {
  4777. int fd;
  4778. int i,len,id;
  4779. nullpo_retv(sd);
  4780. fd = sd->fd;
  4781. if (!session_isActive(fd))
  4782. return;
  4783. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4784. WFIFOW(fd,0) = 0x10f;
  4785. bool haveCallPartnerSkill = false;
  4786. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4787. {
  4788. if( (id = sd->status.skill[i].id) != 0 )
  4789. {
  4790. // workaround for bugreport:5348
  4791. if (len + 37 > 8192)
  4792. break;
  4793. // skip WE_CALLPARTNER and send it in special way
  4794. if (id == WE_CALLPARTNER) {
  4795. haveCallPartnerSkill = true;
  4796. continue;
  4797. }
  4798. WFIFOW(fd,len) = id;
  4799. WFIFOL(fd,len+2) = skill_get_inf(id);
  4800. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4801. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4802. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4803. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4804. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4805. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4806. else
  4807. WFIFOB(fd,len+36) = 0;
  4808. len += 37;
  4809. }
  4810. }
  4811. WFIFOW(fd,2)=len;
  4812. WFIFOSET(fd,len);
  4813. // adoption fix
  4814. if (haveCallPartnerSkill) {
  4815. clif_addskill(sd, WE_CALLPARTNER);
  4816. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4817. }
  4818. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4819. for ( ; i < MAX_SKILL; i++)
  4820. {
  4821. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4822. {
  4823. clif_addskill(sd, id);
  4824. clif_skillinfo(sd, id, 0);
  4825. }
  4826. }
  4827. }
  4828. /**
  4829. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4830. **/
  4831. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4832. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4833. void clif_addskill(struct map_session_data *sd, int skill_id)
  4834. {
  4835. nullpo_retv(sd);
  4836. int fd = sd->fd;
  4837. uint16 idx = skill_get_index(skill_id);
  4838. if (!session_isActive(fd) || !idx)
  4839. return;
  4840. if( sd->status.skill[idx].id <= 0 )
  4841. return;
  4842. WFIFOHEAD(fd, packet_len(0x111));
  4843. WFIFOW(fd,0) = 0x111;
  4844. WFIFOW(fd,2) = skill_id;
  4845. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4846. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4847. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4848. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4849. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4850. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4851. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4852. else
  4853. WFIFOB(fd,38) = 0;
  4854. WFIFOSET(fd,packet_len(0x111));
  4855. }
  4856. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4857. /// 0441 <skill id>.W
  4858. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4859. {
  4860. #if PACKETVER >= 20081217
  4861. nullpo_retv(sd);
  4862. int fd = sd->fd;
  4863. uint16 idx = skill_get_index(skill_id);
  4864. if (!session_isActive(fd) || !idx)
  4865. return;
  4866. WFIFOHEAD(fd,packet_len(0x441));
  4867. WFIFOW(fd,0) = 0x441;
  4868. WFIFOW(fd,2) = skill_id;
  4869. WFIFOSET(fd,packet_len(0x441));
  4870. #endif
  4871. clif_skillinfoblock(sd);
  4872. }
  4873. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4874. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4875. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4876. nullpo_retv(sd);
  4877. int fd = sd->fd;
  4878. uint16 idx = skill_get_index(skill_id);
  4879. if (!session_isActive(fd) || !idx)
  4880. return;
  4881. WFIFOHEAD(fd, packet_len(0x10e));
  4882. WFIFOW(fd, 0) = 0x10e;
  4883. WFIFOW(fd, 2) = skill_id;
  4884. WFIFOW(fd, 4) = lv;
  4885. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4886. WFIFOW(fd, 8) = range;
  4887. WFIFOB(fd, 10) = upgradable;
  4888. WFIFOSET(fd, packet_len(0x10e));
  4889. }
  4890. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4891. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4892. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4893. {
  4894. nullpo_retv(sd);
  4895. const int fd = sd->fd;
  4896. uint16 idx = skill_get_index(skill_id);
  4897. if (!session_isActive(fd) || !idx)
  4898. return;
  4899. WFIFOHEAD(fd,packet_len(0x7e1));
  4900. WFIFOW(fd,0) = 0x7e1;
  4901. WFIFOW(fd,2) = skill_id;
  4902. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4903. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4904. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4905. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4906. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4907. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4908. else
  4909. WFIFOB(fd,14) = 0;
  4910. WFIFOSET(fd,packet_len(0x7e1));
  4911. }
  4912. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4913. #if PACKETVER >= 20151223
  4914. if( !battle_config.show_skill_scale ){
  4915. return;
  4916. }
  4917. struct PACKET_ZC_SKILL_SCALE p;
  4918. p.PacketType = skillscale;
  4919. p.AID = src_id;
  4920. p.skill_id = skill_id;
  4921. p.skill_lv = skill_lv;
  4922. p.x = x;
  4923. p.y = y;
  4924. p.casttime = casttime;
  4925. if( disguised( bl ) ){
  4926. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4927. p.AID = disguised_bl_id( bl->id );
  4928. clif_send( &p, sizeof( p ), bl, SELF );
  4929. }else{
  4930. clif_send( &p, sizeof( p ), bl, AREA );
  4931. }
  4932. #endif
  4933. }
  4934. /// Notifies clients in area, that an object is about to use a skill.
  4935. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4936. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4937. /// property:
  4938. /// 0 = Yellow cast aura
  4939. /// 1 = Water elemental cast aura
  4940. /// 2 = Earth elemental cast aura
  4941. /// 3 = Fire elemental cast aura
  4942. /// 4 = Wind elemental cast aura
  4943. /// 5 = Poison elemental cast aura
  4944. /// 6 = Holy elemental cast aura
  4945. /// ? = like 0
  4946. /// is disposable:
  4947. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4948. /// 1 = no text
  4949. 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)
  4950. {
  4951. #if PACKETVER < 20091124
  4952. const int cmd = 0x13e;
  4953. #else
  4954. const int cmd = 0x7fb;
  4955. #endif
  4956. unsigned char buf[32];
  4957. WBUFW(buf,0) = cmd;
  4958. WBUFL(buf,2) = src_id;
  4959. WBUFL(buf,6) = dst_id;
  4960. WBUFW(buf,10) = dst_x;
  4961. WBUFW(buf,12) = dst_y;
  4962. WBUFW(buf,14) = skill_id;
  4963. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4964. WBUFL(buf,20) = casttime;
  4965. #if PACKETVER >= 20091124
  4966. WBUFB(buf,24) = 0; // isDisposable
  4967. #endif
  4968. if (disguised(bl)) {
  4969. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4970. WBUFL(buf,2) = disguised_bl_id( src_id );
  4971. clif_send(buf,packet_len(cmd), bl, SELF);
  4972. } else
  4973. clif_send(buf,packet_len(cmd), bl, AREA);
  4974. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4975. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4976. }
  4977. }
  4978. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4979. /// 01b9 <id>.L
  4980. void clif_skillcastcancel(struct block_list* bl)
  4981. {
  4982. unsigned char buf[16];
  4983. nullpo_retv(bl);
  4984. WBUFW(buf,0) = 0x1b9;
  4985. WBUFL(buf,2) = bl->id;
  4986. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4987. }
  4988. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4989. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4990. /// num (only used when skill id = NV_BASIC and cause = 0):
  4991. /// 0 = "skill failed" MsgStringTable[159]
  4992. /// 1 = "no emotions" MsgStringTable[160]
  4993. /// 2 = "no sit" MsgStringTable[161]
  4994. /// 3 = "no chat" MsgStringTable[162]
  4995. /// 4 = "no party" MsgStringTable[163]
  4996. /// 5 = "no shout" MsgStringTable[164]
  4997. /// 6 = "no PKing" MsgStringTable[165]
  4998. /// 7 = "no alligning" MsgStringTable[383]
  4999. /// ? = ignored
  5000. /// cause:
  5001. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5002. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5003. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5004. /// "skill failed" MsgStringTable[204] (otherwise)
  5005. /// ... = @see enum useskill_fail_cause
  5006. /// ? = ignored
  5007. ///
  5008. /// if(result!=0) doesn't display any of the previous messages
  5009. /// Note: when this packet is received an unknown flag is always set to 0,
  5010. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5011. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5012. nullpo_retv( sd );
  5013. int fd = sd->fd;
  5014. if( !session_isActive( fd ) ){
  5015. return;
  5016. }
  5017. if(battle_config.display_skill_fail&1)
  5018. return; //Disable all skill failed messages
  5019. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5020. return; //Disable delay failed messages
  5021. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5022. return;
  5023. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5024. return;
  5025. struct PACKET_ZC_ACK_TOUSESKILL p;
  5026. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5027. p.skillId = skill_id;
  5028. p.btype = btype;
  5029. p.itemId = itemId;
  5030. p.flag = 0; // 0 - failed
  5031. p.cause = cause;
  5032. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5033. }
  5034. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5035. /// 043d <skill ID>.W <tick>.L
  5036. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  5037. {
  5038. #if PACKETVER>=20081112
  5039. int fd;
  5040. nullpo_retv(sd);
  5041. fd=sd->fd;
  5042. WFIFOHEAD(fd,packet_len(0x43d));
  5043. WFIFOW(fd,0) = 0x43d;
  5044. WFIFOW(fd,2) = skill_id;
  5045. WFIFOL(fd,4) = client_tick(tick);
  5046. WFIFOSET(fd,packet_len(0x43d));
  5047. #endif
  5048. }
  5049. /// Skill attack effect and damage.
  5050. /// 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)
  5051. /// 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)
  5052. 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)
  5053. {
  5054. unsigned char buf[64];
  5055. struct status_change *sc;
  5056. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5057. nullpo_ret(src);
  5058. nullpo_ret(dst);
  5059. type = clif_calc_delay(type,div,damage,ddelay);
  5060. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5061. if(sc->data[SC_HALLUCINATION] && damage)
  5062. damage = clif_hallucination_damage();
  5063. }
  5064. #if PACKETVER < 3
  5065. WBUFW(buf,0)=0x114;
  5066. WBUFW(buf,2)=skill_id;
  5067. WBUFL(buf,4)=src->id;
  5068. WBUFL(buf,8)=dst->id;
  5069. WBUFL(buf,12)=client_tick(tick);
  5070. WBUFL(buf,16)=sdelay;
  5071. WBUFL(buf,20)=ddelay;
  5072. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5073. WBUFW(buf,24)=damage?div:0;
  5074. } else {
  5075. WBUFW(buf,24)=damage;
  5076. }
  5077. WBUFW(buf,26)=skill_lv;
  5078. WBUFW(buf,28)=div;
  5079. WBUFB(buf,30)=type;
  5080. if (disguised(dst)) {
  5081. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5082. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5083. clif_send(buf,packet_len(0x114),dst,SELF);
  5084. } else
  5085. clif_send(buf,packet_len(0x114),dst,AREA);
  5086. if(disguised(src)) {
  5087. WBUFL(buf,4)=disguised_bl_id(src->id);
  5088. if (disguised(dst))
  5089. WBUFL(buf,8)=dst->id;
  5090. if(damage > 0)
  5091. WBUFW(buf,24)=-1;
  5092. clif_send(buf,packet_len(0x114),src,SELF);
  5093. }
  5094. #else
  5095. WBUFW(buf,0)=0x1de;
  5096. WBUFW(buf,2)=skill_id;
  5097. WBUFL(buf,4)=src->id;
  5098. WBUFL(buf,8)=dst->id;
  5099. WBUFL(buf,12)=client_tick(tick);
  5100. WBUFL(buf,16)=sdelay;
  5101. WBUFL(buf,20)=ddelay;
  5102. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5103. WBUFL(buf,24)=damage?div:0;
  5104. } else {
  5105. WBUFL(buf,24)=damage;
  5106. }
  5107. WBUFW(buf,28)=skill_lv;
  5108. WBUFW(buf,30)=div;
  5109. // For some reason, late 2013 and newer clients have
  5110. // a issue that causes players and monsters to endure
  5111. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5112. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5113. #if PACKETVER < 20131223
  5114. WBUFB(buf,32)=type;
  5115. #else
  5116. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5117. #endif
  5118. if (disguised(dst)) {
  5119. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5120. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5121. clif_send(buf,packet_len(0x1de),dst,SELF);
  5122. } else
  5123. clif_send(buf,packet_len(0x1de),dst,AREA);
  5124. if(disguised(src)) {
  5125. WBUFL(buf,4)=disguised_bl_id(src->id);
  5126. if (disguised(dst))
  5127. WBUFL(buf,8)=dst->id;
  5128. if(damage > 0)
  5129. WBUFL(buf,24)=-1;
  5130. clif_send(buf,packet_len(0x1de),src,SELF);
  5131. }
  5132. #endif
  5133. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5134. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5135. }
  5136. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5137. /// 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
  5138. /*
  5139. 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)
  5140. {
  5141. unsigned char buf[64];
  5142. struct status_change *sc;
  5143. nullpo_ret(src);
  5144. nullpo_ret(dst);
  5145. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5146. type = clif_calc_delay(type,div,damage,ddelay);
  5147. sc = status_get_sc(dst);
  5148. if(sc && sc->count) {
  5149. if(sc->data[SC_HALLUCINATION] && damage)
  5150. damage = clif_hallucination_damage();
  5151. }
  5152. WBUFW(buf,0)=0x115;
  5153. WBUFW(buf,2)=skill_id;
  5154. WBUFL(buf,4)=src->id;
  5155. WBUFL(buf,8)=dst->id;
  5156. WBUFL(buf,12)=client_tick(tick);
  5157. WBUFL(buf,16)=sdelay;
  5158. WBUFL(buf,20)=ddelay;
  5159. WBUFW(buf,24)=dst->x;
  5160. WBUFW(buf,26)=dst->y;
  5161. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5162. WBUFW(buf,28)=damage?div:0;
  5163. } else {
  5164. WBUFW(buf,28)=damage;
  5165. }
  5166. WBUFW(buf,30)=skill_lv;
  5167. WBUFW(buf,32)=div;
  5168. WBUFB(buf,34)=type;
  5169. clif_send(buf,packet_len(0x115),src,AREA);
  5170. if(disguised(src)) {
  5171. WBUFL(buf,4)=disguised_bl_id(src->id);
  5172. if(damage > 0)
  5173. WBUFW(buf,28)=-1;
  5174. clif_send(buf,packet_len(0x115),src,SELF);
  5175. }
  5176. if (disguised(dst)) {
  5177. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5178. if (disguised(src))
  5179. WBUFL(buf,4)=src->id;
  5180. else if(damage > 0)
  5181. WBUFW(buf,28)=-1;
  5182. clif_send(buf,packet_len(0x115),dst,SELF);
  5183. }
  5184. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5185. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5186. }
  5187. */
  5188. /// Non-damaging skill effect
  5189. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5190. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5191. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5192. {
  5193. unsigned char buf[17];
  5194. #if PACKETVER < 20130731
  5195. const int cmd = 0x11a;
  5196. #else
  5197. const int cmd = 0x9cb;
  5198. #endif
  5199. int offset = 0;
  5200. bool success = ( tick != 0 );
  5201. nullpo_ret(dst);
  5202. WBUFW(buf,0) = cmd;
  5203. WBUFW(buf,2) = skill_id;
  5204. #if PACKETVER < 20130731
  5205. WBUFW(buf,4) = min(heal, INT16_MAX);
  5206. #else
  5207. WBUFL(buf,4) = min(heal, INT32_MAX);
  5208. offset += 2;
  5209. #endif
  5210. WBUFL(buf,6+offset) = dst->id;
  5211. WBUFL(buf,10+offset) = src ? src->id : 0;
  5212. WBUFB(buf,14+offset) = success;
  5213. if (disguised(dst)) {
  5214. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5215. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5216. clif_send(buf, packet_len(cmd), dst, SELF);
  5217. } else
  5218. clif_send(buf, packet_len(cmd), dst, AREA);
  5219. if(src && disguised(src)) {
  5220. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5221. if (disguised(dst))
  5222. WBUFL(buf,6+offset) = dst->id;
  5223. clif_send(buf, packet_len(cmd), src, SELF);
  5224. }
  5225. return success;
  5226. }
  5227. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5228. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5229. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5230. {
  5231. unsigned char buf[32];
  5232. nullpo_retv(src);
  5233. WBUFW(buf,0)=0x117;
  5234. WBUFW(buf,2)=skill_id;
  5235. WBUFL(buf,4)=src->id;
  5236. WBUFW(buf,8)=val;
  5237. WBUFW(buf,10)=x;
  5238. WBUFW(buf,12)=y;
  5239. WBUFL(buf,14)=client_tick(tick);
  5240. if(disguised(src)) {
  5241. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5242. WBUFL(buf,4)=disguised_bl_id(src->id);
  5243. clif_send(buf,packet_len(0x117),src,SELF);
  5244. } else
  5245. clif_send(buf,packet_len(0x117),src,AREA);
  5246. }
  5247. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5248. /// 011c <skill id>.W { <map name>.16B }*4
  5249. void clif_skill_warppoint(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  5250. {
  5251. int fd;
  5252. nullpo_retv(sd);
  5253. fd = sd->fd;
  5254. WFIFOHEAD(fd,packet_len(0x11c));
  5255. WFIFOW(fd,0) = 0x11c;
  5256. WFIFOW(fd,2) = skill_id;
  5257. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5258. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5259. else // normal map name
  5260. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5261. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5262. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5263. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5264. WFIFOSET(fd,packet_len(0x11c));
  5265. sd->menuskill_id = skill_id;
  5266. if (skill_id == AL_WARP) {
  5267. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5268. sd->state.workinprogress = WIP_DISABLE_ALL;
  5269. } else
  5270. sd->menuskill_val = skill_lv;
  5271. }
  5272. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5273. /// 011e <type>.B
  5274. /// type:
  5275. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5276. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5277. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5278. ///
  5279. /// @param sd Who receives the message
  5280. /// @param type What message
  5281. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5282. {
  5283. int fd;
  5284. nullpo_retv(sd);
  5285. fd=sd->fd;
  5286. WFIFOHEAD(fd,packet_len(0x11e));
  5287. WFIFOW(fd,0)=0x11e;
  5288. WFIFOB(fd,2)=type;
  5289. WFIFOSET(fd,packet_len(0x11e));
  5290. }
  5291. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5292. /// 0189 <type>.W
  5293. /// type:
  5294. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5295. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5296. ///
  5297. /// @param sd Who receives the message
  5298. /// @param type What message
  5299. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5300. {
  5301. int fd;
  5302. nullpo_retv(sd);
  5303. fd=sd->fd;
  5304. WFIFOHEAD(fd,packet_len(0x189));
  5305. WFIFOW(fd,0)=0x189;
  5306. WFIFOW(fd,2)=type;
  5307. WFIFOSET(fd,packet_len(0x189));
  5308. }
  5309. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5310. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5311. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5312. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5313. {
  5314. struct status_data *status;
  5315. unsigned char buf[64];
  5316. int i, fix;
  5317. nullpo_retv(sd);
  5318. nullpo_retv(dst);
  5319. if( dst->type != BL_MOB )
  5320. return;
  5321. status = status_get_status_data(dst);
  5322. WBUFW(buf, 0)=0x18c;
  5323. WBUFW(buf, 2)=status_get_class(dst);
  5324. WBUFW(buf, 4)=status_get_lv(dst);
  5325. WBUFW(buf, 6)=status->size;
  5326. WBUFL(buf, 8)=status->hp;
  5327. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5328. +(battle_config.estimation_type&2?status->def2:0);
  5329. WBUFW(buf,14)=status->race;
  5330. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5331. +(battle_config.estimation_type&2?status->mdef2:0);
  5332. WBUFW(buf,18)= status->def_ele;
  5333. for(i=0;i<9;i++)
  5334. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5335. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5336. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5337. }
  5338. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5339. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5340. /// material id:
  5341. /// unused by the client
  5342. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5343. nullpo_retv(sd);
  5344. int fd = sd->fd;
  5345. if( !session_isActive( fd ) ){
  5346. return;
  5347. }
  5348. if (sd->menuskill_id == skill_id)
  5349. return; //Avoid resending the menu twice or more times...
  5350. if (skill_id == GC_CREATENEWPOISON)
  5351. skill_id = GC_RESEARCHNEWPOISON;
  5352. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5353. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5354. p->packetType = 0x18d;
  5355. int count = 0;
  5356. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5357. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5358. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5359. )
  5360. {
  5361. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5362. p->items[count].material[0] = 0;
  5363. p->items[count].material[1] = 0;
  5364. p->items[count].material[2] = 0;
  5365. count++;
  5366. }
  5367. }
  5368. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5369. WFIFOSET( fd, p->packetLength );
  5370. if( count > 0 ){
  5371. sd->menuskill_id = skill_id;
  5372. sd->menuskill_val = trigger;
  5373. return;
  5374. }
  5375. }
  5376. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5377. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5378. /// mk type:
  5379. /// 1 = cooking
  5380. /// 2 = arrow
  5381. /// 3 = elemental
  5382. /// 4 = GN_MIX_COOKING
  5383. /// 5 = GN_MAKEBOMB
  5384. /// 6 = GN_S_PHARMACY
  5385. /// 7 = MT_M_MACHINE - Unconfirmed
  5386. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5387. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5388. nullpo_retv( sd );
  5389. // Avoid resending the menu twice or more times...
  5390. if( sd->menuskill_id == skill_id ){
  5391. return;
  5392. }
  5393. int fd = sd->fd;
  5394. if( !session_isActive( fd ) ){
  5395. return;
  5396. }
  5397. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5398. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5399. p->packetType = 0x25a;
  5400. p->makeItem = list_type; // list type
  5401. int count = 0;
  5402. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5403. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5404. continue;
  5405. }
  5406. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5407. count++;
  5408. }
  5409. if( count > 0 || skill_id == AM_PHARMACY ){
  5410. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5411. WFIFOSET( fd, p->packetLength );
  5412. sd->menuskill_id = skill_id;
  5413. sd->menuskill_val = trigger;
  5414. sd->menuskill_val2 = qty; // amount.
  5415. }else{
  5416. clif_menuskill_clear(sd);
  5417. #if PACKETVER >= 20090922
  5418. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5419. #else
  5420. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5421. WFIFOSET( fd, p->packetLength );
  5422. #endif
  5423. }
  5424. }
  5425. /// Notifies clients of a status change.
  5426. /// 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)]
  5427. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5428. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5429. /// @param bl Sends packet to clients around this object
  5430. /// @param id ID of object that has this effect
  5431. /// @param type Status icon see enum efst_type
  5432. /// @param flag 1:Active, 0:Deactive
  5433. /// @param tick Duration in ms
  5434. /// @param val1
  5435. /// @param val2
  5436. /// @param val3
  5437. 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)
  5438. {
  5439. unsigned char buf[32];
  5440. if (type == EFST_BLANK) //It shows nothing on the client...
  5441. return;
  5442. if (type == EFST_POSTDELAY && tick == 0)
  5443. return;
  5444. nullpo_retv(bl);
  5445. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5446. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5447. tick = 200;
  5448. #if PACKETVER >= 20120618
  5449. if (flag && battle_config.display_status_timers)
  5450. WBUFW(buf,0) = 0x983;
  5451. else
  5452. #elif PACKETVER >= 20090121
  5453. if (flag && battle_config.display_status_timers)
  5454. WBUFW(buf,0) = 0x43f;
  5455. else
  5456. #endif
  5457. WBUFW(buf,0) = 0x196;
  5458. WBUFW(buf,2) = type;
  5459. WBUFL(buf,4) = id;
  5460. WBUFB(buf,8) = flag;
  5461. #if PACKETVER >= 20120618
  5462. if (flag && battle_config.display_status_timers) {
  5463. if (tick <= 0)
  5464. tick = 9999; // this is indeed what official servers do
  5465. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5466. WBUFL(buf,13) = client_tick(tick);
  5467. WBUFL(buf,17) = val1;
  5468. WBUFL(buf,21) = val2;
  5469. WBUFL(buf,25) = val3;
  5470. }
  5471. #elif PACKETVER >= 20090121
  5472. if (flag && battle_config.display_status_timers) {
  5473. if (tick <= 0)
  5474. tick = 9999; // this is indeed what official servers do
  5475. WBUFL(buf,9) = client_tick(tick);
  5476. WBUFL(buf,13) = val1;
  5477. WBUFL(buf,17) = val2;
  5478. WBUFL(buf,21) = val3;
  5479. }
  5480. #endif
  5481. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5482. }
  5483. /* Sends status effect to clients around the bl
  5484. * @param bl Object that has the effect
  5485. * @param type Status icon see enum efst_type
  5486. * @param flag 1:Active, 0:Deactive
  5487. * @param tick Duration in ms
  5488. * @param val1
  5489. * @param val2
  5490. * @param val3
  5491. */
  5492. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5493. struct map_session_data *sd = NULL;
  5494. if (type == EFST_BLANK) //It shows nothing on the client...
  5495. return;
  5496. if (type == EFST_POSTDELAY && tick == 0)
  5497. return;
  5498. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5499. return;
  5500. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5501. // Older clients display normal riding icon.
  5502. if (type == EFST_MADOGEAR)
  5503. type = EFST_RIDING;
  5504. #endif
  5505. nullpo_retv(bl);
  5506. sd = BL_CAST(BL_PC, bl);
  5507. if (!(status_efst_get_bl_type((efst_type)type)&bl->type)) // only send status changes that actually matter to the client
  5508. return;
  5509. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5510. }
  5511. /**
  5512. * Send any active EFST to those around.
  5513. * @param tbl: Unit to send the packet to
  5514. * @param bl: Objects walking into view
  5515. * @param target: Client send type
  5516. */
  5517. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5518. unsigned char i;
  5519. struct sc_display_entry **sc_display;
  5520. unsigned char sc_display_count;
  5521. bool spheres_sent;
  5522. nullpo_retv(bl);
  5523. switch( bl->type ){
  5524. case BL_PC: {
  5525. struct map_session_data* sd = (struct map_session_data*)bl;
  5526. sc_display = sd->sc_display;
  5527. sc_display_count = sd->sc_display_count;
  5528. spheres_sent = !sd->state.connect_new;
  5529. }
  5530. break;
  5531. case BL_NPC: {
  5532. struct npc_data* nd = (struct npc_data*)bl;
  5533. sc_display = nd->sc_display;
  5534. sc_display_count = nd->sc_display_count;
  5535. spheres_sent = true;
  5536. }
  5537. break;
  5538. default:
  5539. return;
  5540. }
  5541. for (i = 0; i < sc_display_count; i++) {
  5542. enum sc_type type = sc_display[i]->type;
  5543. struct status_change *sc = status_get_sc(bl);
  5544. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5545. t_tick tick = 0;
  5546. if (td)
  5547. tick = DIFF_TICK(td->tick, gettick());
  5548. // Status changes that need special handling
  5549. switch( type ){
  5550. case SC_SPHERE_1:
  5551. case SC_SPHERE_2:
  5552. case SC_SPHERE_3:
  5553. case SC_SPHERE_4:
  5554. case SC_SPHERE_5:
  5555. if( spheres_sent ){
  5556. target = AREA_WOS;
  5557. }
  5558. break;
  5559. case SC_HELLS_PLANT:
  5560. if( sc && sc->data[type] ){
  5561. tick = sc->data[type]->val4;
  5562. }
  5563. break;
  5564. }
  5565. #if PACKETVER > 20120418
  5566. 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);
  5567. #else
  5568. 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);
  5569. #endif
  5570. }
  5571. }
  5572. /// Notifies the client when a player enters the screen with an active EFST.
  5573. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5574. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5575. 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) {
  5576. #if PACKETVER >= 20111108
  5577. unsigned char buf[32];
  5578. #if PACKETVER >= 20120618
  5579. const int cmd = 0x984;
  5580. #elif PACKETVER >= 20111108
  5581. const int cmd = 0x8ff;
  5582. #endif
  5583. int offset = 0;
  5584. if (type == EFST_BLANK)
  5585. return;
  5586. nullpo_retv(bl);
  5587. if (tick <= 0)
  5588. tick = 9999;
  5589. WBUFW(buf,offset + 0) = cmd;
  5590. WBUFL(buf,offset + 2) = tid;
  5591. WBUFW(buf,offset + 6) = type;
  5592. #if PACKETVER >= 20111108
  5593. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5594. #if PACKETVER >= 20120618
  5595. WBUFL(buf,offset + 12) = client_tick(tick);
  5596. offset += 4;
  5597. #endif
  5598. WBUFL(buf,offset + 12) = val1;
  5599. WBUFL(buf,offset + 16) = val2;
  5600. WBUFL(buf,offset + 20) = val3;
  5601. #endif
  5602. clif_send(buf,packet_len(cmd),bl,target);
  5603. #endif
  5604. }
  5605. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5606. /// 008e <packet len>.W <message>.?B
  5607. void clif_displaymessage(const int fd, const char* mes)
  5608. {
  5609. nullpo_retv(mes);
  5610. if( session_isActive( fd ) ){
  5611. char *message, *line;
  5612. message = aStrdup(mes);
  5613. line = strtok(message, "\n");
  5614. while(line != NULL) {
  5615. #if PACKETVER == 20141022
  5616. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5617. /** so we redirect to ZC_NPC_CHAT **/
  5618. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5619. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5620. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5621. if (len > 0) {
  5622. WFIFOHEAD(fd, 13 + len);
  5623. WFIFOW(fd, 0) = 0x2C1;
  5624. WFIFOW(fd, 2) = 13 + len;
  5625. WFIFOL(fd, 4) = 0;
  5626. WFIFOL(fd, 8) = color;
  5627. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5628. WFIFOSET(fd, WFIFOW(fd, 2));
  5629. }
  5630. #else
  5631. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5632. int len = strnlen(line, CHAT_SIZE_MAX);
  5633. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5634. WFIFOHEAD(fd, 5 + len);
  5635. WFIFOW(fd,0) = 0x8e;
  5636. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5637. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5638. WFIFOSET(fd, 5 + len);
  5639. }
  5640. #endif
  5641. line = strtok(NULL, "\n");
  5642. }
  5643. aFree(message);
  5644. }
  5645. }
  5646. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5647. /// 009a <packet len>.W <message>.?B
  5648. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5649. {
  5650. nullpo_retv(mes);
  5651. if (len < 2)
  5652. return;
  5653. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5654. p->packetType = HEADER_ZC_BROADCAST;
  5655. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5656. if( ( type&BC_BLUE ) != 0 ){
  5657. const char* color = "blue";
  5658. int16 length = (int16)strlen( color );
  5659. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5660. strcpy( p->message, color );
  5661. strncpy( &p->message[length], mes, len );
  5662. p->PacketLength += length;
  5663. }else if( ( type&BC_WOE ) != 0 ){
  5664. const char* color = "ssss";
  5665. int16 length = (int16)strlen( color );
  5666. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5667. strcpy( p->message, color );
  5668. strncpy( &p->message[length], mes, len );
  5669. p->PacketLength += length;
  5670. }else{
  5671. strncpy( p->message, mes, len );
  5672. }
  5673. clif_send( p, p->PacketLength, bl, target );
  5674. }
  5675. /*==========================================
  5676. * Displays a message on a 'bl' to all it's nearby clients
  5677. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5678. *------------------------------------------*/
  5679. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5680. nullpo_retv(bl);
  5681. nullpo_retv(message);
  5682. int16 len = (int16)( strlen( message ) + 1 );
  5683. if( len > CHAT_SIZE_MAX ) {
  5684. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5685. len = CHAT_SIZE_MAX;
  5686. }
  5687. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5688. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5689. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5690. p->GID = bl->id;
  5691. safestrncpy( p->Message, message, len );
  5692. clif_send( p, p->PacketLength, bl, target );
  5693. }
  5694. /// Send broadcast message with font formatting.
  5695. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5696. 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)
  5697. {
  5698. nullpo_retv(mes);
  5699. if (len < 2)
  5700. return;
  5701. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5702. p->packetType = HEADER_ZC_BROADCAST2;
  5703. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5704. p->fontColor = fontColor;
  5705. p->fontType = fontType;
  5706. p->fontSize = fontSize;
  5707. p->fontAlign = fontAlign;
  5708. p->fontY = fontY;
  5709. strncpy( p->message, mes, len );
  5710. clif_send( p, p->PacketLength, bl, target );
  5711. }
  5712. /*
  5713. * Display *msg to all *users in channel
  5714. */
  5715. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5716. DBIterator *iter;
  5717. struct map_session_data *user;
  5718. unsigned short msg_len = 0, len = 0;
  5719. unsigned char buf[CHAT_SIZE_MAX];
  5720. if (!channel || !msg)
  5721. return;
  5722. msg_len = (unsigned short)(strlen(msg) + 1);
  5723. if( msg_len > sizeof(buf)-12 ) {
  5724. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5725. msg_len = sizeof(buf)-12;
  5726. }
  5727. WBUFW(buf,0) = 0x2C1;
  5728. WBUFW(buf,2) = (len = msg_len + 12);
  5729. WBUFL(buf,4) = 0;
  5730. WBUFL(buf,8) = color;
  5731. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5732. iter = db_iterator(channel->users);
  5733. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5734. clif_send(buf, len, &user->bl, SELF);
  5735. }
  5736. dbi_destroy(iter);
  5737. }
  5738. /// Displays heal effect.
  5739. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5740. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5741. /// var id:
  5742. /// 5 = HP (SP_HP)
  5743. /// 7 = SP (SP_SP)
  5744. /// ? = ignored
  5745. void clif_heal(int fd,int type,int val) {
  5746. #if PACKETVER < 20141022
  5747. const int cmd = 0x13d;
  5748. #else
  5749. const int cmd = 0xa27;
  5750. #endif
  5751. WFIFOHEAD(fd, packet_len(cmd));
  5752. WFIFOW(fd,0) = cmd;
  5753. WFIFOW(fd,2) = type;
  5754. #if PACKETVER < 20141022
  5755. WFIFOW(fd,4) = min(val, INT16_MAX);
  5756. #else
  5757. WFIFOL(fd,4) = min(val, INT32_MAX);
  5758. #endif
  5759. WFIFOSET(fd, packet_len(cmd));
  5760. }
  5761. /// Displays resurrection effect (ZC_RESURRECTION).
  5762. /// 0148 <id>.L <type>.W
  5763. /// type:
  5764. /// ignored
  5765. void clif_resurrection(struct block_list *bl,int type)
  5766. {
  5767. unsigned char buf[16];
  5768. nullpo_retv(bl);
  5769. WBUFW(buf,0)=0x148;
  5770. WBUFL(buf,2)=bl->id;
  5771. WBUFW(buf,6)=0;
  5772. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5773. if (disguised(bl))
  5774. clif_spawn(bl);
  5775. }
  5776. /// Sets the map property
  5777. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5778. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5779. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5780. {
  5781. #if PACKETVER >= 20121010
  5782. short cmd = 0x99b;
  5783. unsigned char buf[8];
  5784. #else
  5785. short cmd = 0x199;
  5786. unsigned char buf[4];
  5787. #endif
  5788. WBUFW(buf,0)=cmd;
  5789. WBUFW(buf,2)=property;
  5790. #if PACKETVER >= 20121010
  5791. struct map_data *mapdata = map_getmapdata(bl->m);
  5792. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  5793. WBUFL(buf,4) = ((mapdata->flag[MF_PVP] || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5794. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5795. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5796. ((mapdata->flag[MF_FORCEMINEFFECT] || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5797. ((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
  5798. ((mapdata->flag[MF_PVP])<<5)| // COUNT_PK - Show the PvP counter
  5799. ((mapdata->flag[MF_PARTYLOCK])<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5800. ((mapdata->flag[MF_BATTLEGROUND])<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5801. ((mapdata->flag[MF_NOCOSTUME])<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5802. ((!mapdata->flag[MF_NOUSECART])<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5803. ((!mapdata->flag[MF_NOSUNMOONSTARMIRACLE])<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5804. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5805. #endif
  5806. clif_send(buf,packet_len(cmd),bl,t);
  5807. }
  5808. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5809. /// 01d6 <type>.W
  5810. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5811. {
  5812. int fd;
  5813. nullpo_retv(sd);
  5814. fd=sd->fd;
  5815. WFIFOHEAD(fd,packet_len(0x1D6));
  5816. WFIFOW(fd,0)=0x1D6;
  5817. WFIFOW(fd,2)=type;
  5818. WFIFOSET(fd,packet_len(0x1D6));
  5819. }
  5820. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5821. /// 019a <id>.L <ranking>.L <total>.L
  5822. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5823. {
  5824. if(type == 2) {
  5825. int fd = sd->fd;
  5826. WFIFOHEAD(fd,packet_len(0x19a));
  5827. WFIFOW(fd,0) = 0x19a;
  5828. WFIFOL(fd,2) = sd->bl.id;
  5829. WFIFOL(fd,6) = pvprank;
  5830. WFIFOL(fd,10) = pvpnum;
  5831. WFIFOSET(fd,packet_len(0x19a));
  5832. } else {
  5833. unsigned char buf[32];
  5834. WBUFW(buf,0) = 0x19a;
  5835. WBUFL(buf,2) = sd->bl.id;
  5836. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5837. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5838. else
  5839. WBUFL(buf,6) = pvprank;
  5840. WBUFL(buf,10) = pvpnum;
  5841. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5842. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5843. else if(!type)
  5844. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5845. else
  5846. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5847. }
  5848. }
  5849. /*==========================================
  5850. *
  5851. *------------------------------------------*/
  5852. void clif_map_property_mapall(int map_idx, enum map_property property)
  5853. {
  5854. struct block_list bl;
  5855. bl.id = 0;
  5856. bl.type = BL_NUL;
  5857. bl.m = map_idx;
  5858. clif_map_property( &bl, property, ALL_SAMEMAP );
  5859. }
  5860. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5861. /// 0188 <result>.W <index>.W <refine>.W
  5862. /// result:
  5863. /// 0 = success
  5864. /// 1 = failure
  5865. /// 2 = downgrade
  5866. void clif_refine(int fd, int fail, int index, int val)
  5867. {
  5868. WFIFOHEAD(fd,packet_len(0x188));
  5869. WFIFOW(fd,0)=0x188;
  5870. WFIFOW(fd,2)=fail;
  5871. WFIFOW(fd,4)=index+2;
  5872. WFIFOW(fd,6)=val;
  5873. WFIFOSET(fd,packet_len(0x188));
  5874. }
  5875. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5876. /// 0223 <result>.L <nameid>.W
  5877. /// result:
  5878. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5879. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5880. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5881. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5882. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5883. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5884. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5885. p.result = result;
  5886. p.itemId = client_nameid( item_id );
  5887. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5888. }
  5889. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5890. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5891. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5892. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5893. int fd;
  5894. nullpo_retv(sd);
  5895. fd = sd->fd;
  5896. #if PACKETVER < 20091104
  5897. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5898. WFIFOW(fd,0) = 0x97;
  5899. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5900. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5901. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5902. WFIFOSET(fd,WFIFOW(fd,2));
  5903. #else
  5904. struct map_session_data *ssd = map_nick2sd(nick,false);
  5905. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5906. WFIFOW(fd,0) = 0x97;
  5907. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5908. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5909. // If it is not a message from the server or a player from another map-server
  5910. if( ssd ){
  5911. gmlvl = pc_get_group_level(ssd);
  5912. }
  5913. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5914. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5915. WFIFOSET(fd,WFIFOW(fd,2));
  5916. #endif
  5917. }
  5918. /// Inform the player about the result of his whisper action
  5919. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5920. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5921. /// result:
  5922. /// 0 = success to send wisper
  5923. /// 1 = target character is not loged in
  5924. /// 2 = ignored by target
  5925. /// 3 = everyone ignored by target
  5926. void clif_wis_end(int fd, int result)
  5927. {
  5928. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5929. #if PACKETVER < 20131223
  5930. const int cmd = 0x98;
  5931. #else
  5932. const int cmd = 0x9df;
  5933. #endif
  5934. if (!sd)
  5935. return;
  5936. WFIFOHEAD(fd,packet_len(cmd));
  5937. WFIFOW(fd,0) = cmd;
  5938. WFIFOB(fd,2) = (char)result;
  5939. #if PACKETVER >= 20131223
  5940. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5941. #endif
  5942. WFIFOSET(fd,packet_len(cmd));
  5943. }
  5944. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5945. /// 0194 <char id>.L <name>.24B
  5946. /// 0af7 <flag>.W <char id>.L <name>.24B
  5947. void clif_solved_charname(int fd, int charid, const char* name)
  5948. {
  5949. #if PACKETVER >= 20180221
  5950. WFIFOHEAD(fd,packet_len(0xaf7));
  5951. WFIFOW(fd,0) = 0xaf7;
  5952. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5953. WFIFOL(fd,4) = charid;
  5954. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5955. WFIFOSET(fd,packet_len(0x0af7));
  5956. #else
  5957. WFIFOHEAD(fd,packet_len(0x194));
  5958. WFIFOW(fd,0)=0x194;
  5959. WFIFOL(fd,2)=charid;
  5960. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5961. WFIFOSET(fd,packet_len(0x194));
  5962. #endif
  5963. }
  5964. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5965. /// 017b <packet len>.W { <name id>.W }*
  5966. void clif_use_card(struct map_session_data *sd,int idx)
  5967. {
  5968. int i,c,ep;
  5969. int fd=sd->fd;
  5970. nullpo_retv(sd);
  5971. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5972. return;
  5973. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5974. return; //Avoid parsing invalid item indexes (no card/no item)
  5975. ep=sd->inventory_data[idx]->equip;
  5976. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5977. WFIFOW(fd,0)=0x17b;
  5978. for(i=c=0;i<MAX_INVENTORY;i++){
  5979. int j;
  5980. if(sd->inventory_data[i] == NULL)
  5981. continue;
  5982. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5983. continue;
  5984. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5985. continue;
  5986. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5987. continue;
  5988. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5989. continue;
  5990. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5991. continue;
  5992. 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.
  5993. continue;
  5994. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5995. if( j == sd->inventory_data[i]->slots ) // No room
  5996. continue;
  5997. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5998. continue;
  5999. WFIFOW(fd,4+c*2)=i+2;
  6000. c++;
  6001. }
  6002. if( !c ) return; // no item is available for card insertion
  6003. WFIFOW(fd,2)=4+c*2;
  6004. WFIFOSET(fd,WFIFOW(fd,2));
  6005. }
  6006. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6007. /// 017d <equip index>.W <card index>.W <result>.B
  6008. /// result:
  6009. /// 0 = success
  6010. /// 1 = failure
  6011. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  6012. {
  6013. int fd;
  6014. nullpo_retv(sd);
  6015. fd=sd->fd;
  6016. WFIFOHEAD(fd,packet_len(0x17d));
  6017. WFIFOW(fd,0)=0x17d;
  6018. WFIFOW(fd,2)=idx_equip+2;
  6019. WFIFOW(fd,4)=idx_card+2;
  6020. WFIFOB(fd,6)=flag;
  6021. WFIFOSET(fd,packet_len(0x17d));
  6022. }
  6023. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6024. /// 0177 <packet len>.W { <index>.W }*
  6025. void clif_item_identify_list(struct map_session_data *sd)
  6026. {
  6027. int i,c;
  6028. int fd;
  6029. nullpo_retv(sd);
  6030. fd=sd->fd;
  6031. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6032. WFIFOW(fd,0)=0x177;
  6033. for(i=c=0;i<MAX_INVENTORY;i++){
  6034. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6035. WFIFOW(fd,c*2+4)=client_index(i);
  6036. c++;
  6037. }
  6038. }
  6039. if(c > 0) {
  6040. WFIFOW(fd,2)=c*2+4;
  6041. WFIFOSET(fd,WFIFOW(fd,2));
  6042. sd->menuskill_id = MC_IDENTIFY;
  6043. sd->menuskill_val = c;
  6044. sd->state.workinprogress = WIP_DISABLE_ALL;
  6045. }
  6046. }
  6047. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6048. /// 0179 <index>.W <result>.B
  6049. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  6050. {
  6051. int fd;
  6052. nullpo_retv(sd);
  6053. fd=sd->fd;
  6054. WFIFOHEAD(fd,packet_len(0x179));
  6055. WFIFOW(fd, 0)=0x179;
  6056. WFIFOW(fd, 2)=idx+2;
  6057. WFIFOB(fd, 4)=flag;
  6058. WFIFOSET(fd,packet_len(0x179));
  6059. }
  6060. /// Presents a list of items that can be repaired.
  6061. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6062. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  6063. nullpo_retv( sd );
  6064. nullpo_retv( dstsd );
  6065. int fd = sd->fd;
  6066. if( !session_isActive( fd ) ){
  6067. return;
  6068. }
  6069. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6070. // Preallocate the maximum size
  6071. WFIFOHEAD( fd, len );
  6072. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6073. int c = 0;
  6074. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6075. 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)){
  6076. p->items[c].index = i;
  6077. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6078. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6079. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6080. c++;
  6081. }
  6082. }
  6083. if( c > 0 ){
  6084. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6085. // Recalculate real length
  6086. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6087. p->packetLength = len;
  6088. WFIFOSET( fd, len );
  6089. sd->menuskill_id = BS_REPAIRWEAPON;
  6090. sd->menuskill_val = dstsd->bl.id;
  6091. sd->menuskill_val2 = lv;
  6092. }else{
  6093. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6094. }
  6095. }
  6096. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6097. /// 01fe <index>.W <result>.B
  6098. /// index:
  6099. /// ignored (inventory index)
  6100. /// result:
  6101. /// 0 = Item repair success.
  6102. /// 1 = Item repair failure.
  6103. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  6104. {
  6105. int fd;
  6106. nullpo_retv(sd);
  6107. fd = sd->fd;
  6108. WFIFOHEAD(fd,packet_len(0x1fe));
  6109. WFIFOW(fd, 0)=0x1fe;
  6110. WFIFOW(fd, 2)=idx+2;
  6111. WFIFOB(fd, 4)=flag;
  6112. WFIFOSET(fd,packet_len(0x1fe));
  6113. }
  6114. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6115. /// 02bb <equip location>.W <account id>.L
  6116. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  6117. {
  6118. int fd = sd->fd;
  6119. WFIFOHEAD(fd,packet_len(0x2bb));
  6120. WFIFOW(fd,0) = 0x2bb;
  6121. WFIFOW(fd,2) = position;
  6122. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6123. WFIFOSET(fd,packet_len(0x2bb));
  6124. }
  6125. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6126. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6127. void clif_item_refine_list( struct map_session_data *sd ){
  6128. nullpo_retv( sd );
  6129. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6130. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6131. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6132. int refine_item[MAX_WEAPON_LEVEL];
  6133. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6134. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6135. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6136. #ifdef RENEWAL
  6137. refine_item[4] = -1;
  6138. #endif
  6139. int count = 0;
  6140. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6141. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6142. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6143. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6144. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6145. p->items[count].index = client_index( i );
  6146. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6147. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6148. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6149. count++;
  6150. }
  6151. }
  6152. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6153. clif_send( p, p->packetLength, &sd->bl, SELF );
  6154. if( count > 0 ){
  6155. sd->menuskill_id = WS_WEAPONREFINE;
  6156. sd->menuskill_val = skill_lv;
  6157. }
  6158. }
  6159. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6160. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6161. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6162. nullpo_retv( sd );
  6163. struct PACKET_ZC_AUTORUN_SKILL p;
  6164. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6165. p.skill_id = skill_id;
  6166. p.skill_type = skill_get_inf( skill_id );
  6167. p.skill_lv = skill_lv;
  6168. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6169. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6170. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6171. p.up_flag = false;
  6172. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6173. }
  6174. /// Adds an item to character's cart.
  6175. /// 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)
  6176. /// 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)
  6177. /// 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)
  6178. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6179. nullpo_retv( sd );
  6180. int fd = sd->fd;
  6181. if( !session_isActive( fd ) ){
  6182. return;
  6183. }
  6184. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6185. return;
  6186. }
  6187. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6188. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6189. p.index = client_index( n );
  6190. p.amount = amount;
  6191. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6192. #if PACKETVER >= 5
  6193. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6194. #endif
  6195. p.identified = sd->cart.u.items_cart[n].identify;
  6196. p.damaged = sd->cart.u.items_cart[n].attribute;
  6197. p.refine = sd->cart.u.items_cart[n].refine;
  6198. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6199. #if PACKETVER >= 20150226
  6200. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6201. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6202. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6203. #endif
  6204. #endif
  6205. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6206. }
  6207. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6208. /* Acknowledge an item have been added to cart
  6209. * 012c <result>B
  6210. * result :
  6211. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6212. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6213. */
  6214. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6215. {
  6216. int fd;
  6217. unsigned char *buf;
  6218. nullpo_retv(sd);
  6219. fd = sd->fd;
  6220. buf = WFIFOP(fd,0);
  6221. WBUFW(buf,0) = 0x12c;
  6222. WBUFB(buf,2) = flag;
  6223. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6224. }
  6225. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6226. void clif_bank_open( struct map_session_data& sd ){
  6227. #if PACKETVER >= 20130717
  6228. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6229. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6230. p.unknown = 0;
  6231. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6232. #endif
  6233. }
  6234. /*
  6235. * Request to Open the banking system
  6236. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6237. */
  6238. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6239. //TODO check if preventing trade or stuff like that
  6240. //also mark something in case char ain't available for saving, should we check now ?
  6241. nullpo_retv(sd);
  6242. if( !battle_config.feature_banking ) {
  6243. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6244. return;
  6245. }
  6246. else {
  6247. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6248. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6249. if(sd->status.account_id == aid){
  6250. sd->state.banking = 1;
  6251. //request save ?
  6252. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6253. //on succes open bank ?
  6254. clif_bank_open( *sd );
  6255. }
  6256. }
  6257. }
  6258. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6259. void clif_bank_close( struct map_session_data& sd ){
  6260. #if PACKETVER >= 20130717
  6261. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6262. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6263. p.unknown = 0;
  6264. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6265. #endif
  6266. }
  6267. /*
  6268. * Request to close the banking system
  6269. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6270. */
  6271. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6272. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6273. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6274. nullpo_retv(sd);
  6275. if( !battle_config.feature_banking ) {
  6276. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6277. //still allow to go trough to not stuck player if we have disable it while they was in
  6278. }
  6279. if(sd->status.account_id == aid){
  6280. sd->state.banking = 0;
  6281. clif_bank_close( *sd );
  6282. }
  6283. }
  6284. /*
  6285. * Display how much we got in bank (I suppose)
  6286. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6287. */
  6288. void clif_Bank_Check( struct map_session_data& sd ){
  6289. #if PACKETVER >= 20130717
  6290. struct PACKET_ZC_BANKING_CHECK p = {};
  6291. p.packetType = HEADER_ZC_BANKING_CHECK;
  6292. p.money = sd.bank_vault;
  6293. p.reason = 0;
  6294. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6295. #endif
  6296. }
  6297. /*
  6298. * Requesting the data in bank
  6299. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6300. */
  6301. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6302. nullpo_retv(sd);
  6303. if( !battle_config.feature_banking ) {
  6304. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6305. return;
  6306. }
  6307. else {
  6308. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6309. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6310. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6311. clif_Bank_Check( *sd );
  6312. }
  6313. }
  6314. /*
  6315. * Acknowledge of deposit some money in bank
  6316. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6317. */
  6318. void clif_bank_deposit( struct map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6319. #if PACKETVER >= 20130717
  6320. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6321. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6322. p.money = sd.bank_vault;
  6323. p.zeny = sd.status.zeny;
  6324. p.reason = reason;
  6325. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6326. #endif
  6327. }
  6328. /*
  6329. * Request saving some money in bank
  6330. * @author : original [Yommy/Hercules]
  6331. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6332. */
  6333. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6334. nullpo_retv(sd);
  6335. if( !battle_config.feature_banking ) {
  6336. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6337. return;
  6338. }
  6339. else {
  6340. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6341. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6342. int money = RFIFOL(fd,info->pos[1]);
  6343. if(sd->status.account_id == aid){
  6344. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6345. clif_bank_deposit( *sd, reason );
  6346. }
  6347. }
  6348. }
  6349. /*
  6350. * Acknowledge of withdrawing some money from bank
  6351. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6352. */
  6353. void clif_bank_withdraw( struct map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6354. #if PACKETVER >= 20130717
  6355. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6356. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6357. p.reason = reason;
  6358. p.money = sd.bank_vault;
  6359. p.zeny = sd.status.zeny;
  6360. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6361. #endif
  6362. }
  6363. /*
  6364. * Request Withdrawing some money from bank
  6365. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6366. */
  6367. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6368. nullpo_retv(sd);
  6369. if( !battle_config.feature_banking ) {
  6370. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6371. return;
  6372. }
  6373. else {
  6374. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6375. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6376. int money = RFIFOL(fd,info->pos[1]);
  6377. if(sd->status.account_id == aid){
  6378. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6379. clif_bank_withdraw( *sd, reason );
  6380. }
  6381. }
  6382. }
  6383. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6384. /// 0125 <index>.W <amount>.L
  6385. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6386. {
  6387. int fd;
  6388. nullpo_retv(sd);
  6389. fd=sd->fd;
  6390. WFIFOHEAD(fd,packet_len(0x125));
  6391. WFIFOW(fd,0)=0x125;
  6392. WFIFOW(fd,2)=n+2;
  6393. WFIFOL(fd,4)=amount;
  6394. WFIFOSET(fd,packet_len(0x125));
  6395. }
  6396. /// Opens the shop creation menu (ZC_OPENSTORE).
  6397. /// 012d <num>.W
  6398. /// num:
  6399. /// number of allowed item slots
  6400. void clif_openvendingreq(struct map_session_data* sd, int num)
  6401. {
  6402. int fd;
  6403. nullpo_retv(sd);
  6404. fd = sd->fd;
  6405. WFIFOHEAD(fd,packet_len(0x12d));
  6406. WFIFOW(fd,0) = 0x12d;
  6407. WFIFOW(fd,2) = num;
  6408. WFIFOSET(fd,packet_len(0x12d));
  6409. }
  6410. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6411. /// 0131 <owner id>.L <message>.80B
  6412. void clif_showvendingboard( struct map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6413. if( tbl == nullptr ){
  6414. tbl = &sd.bl;
  6415. target = AREA_WOS;
  6416. }
  6417. struct PACKET_ZC_STORE_ENTRY p = {};
  6418. p.packetType = HEADER_ZC_STORE_ENTRY;
  6419. p.makerAID = sd.status.account_id;
  6420. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6421. clif_send( &p, sizeof( p ), tbl, target );
  6422. }
  6423. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6424. /// 0132 <owner id>.L
  6425. void clif_closevendingboard(struct block_list* bl, int fd)
  6426. {
  6427. unsigned char buf[16];
  6428. nullpo_retv(bl);
  6429. WBUFW(buf,0) = 0x132;
  6430. WBUFL(buf,2) = bl->id;
  6431. if( session_isActive(fd) ) {
  6432. WFIFOHEAD(fd,packet_len(0x132));
  6433. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6434. WFIFOSET(fd,packet_len(0x132));
  6435. } else {
  6436. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6437. }
  6438. }
  6439. /// Sends a list of items in a shop.
  6440. /// 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)
  6441. /// 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)
  6442. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6443. nullpo_retv( sd );
  6444. nullpo_retv( vsd );
  6445. nullpo_retv( vsd->vending );
  6446. int fd = sd->fd;
  6447. if( !session_isActive( fd ) ){
  6448. return;
  6449. }
  6450. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6451. WFIFOHEAD( fd, len );
  6452. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6453. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6454. p->packetLength = len;
  6455. p->AID = vsd->status.account_id;
  6456. #if PACKETVER >= 20100105
  6457. p->venderId = vsd->vender_id;
  6458. #endif
  6459. for( int i = 0; i < vsd->vend_num; i++ ){
  6460. int index = vsd->vending[i].index;
  6461. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6462. p->items[i].price = vsd->vending[i].value;
  6463. p->items[i].amount = vsd->vending[i].amount;
  6464. p->items[i].index = client_index( index );
  6465. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6466. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6467. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6468. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6469. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6470. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6471. #if PACKETVER >= 20150226
  6472. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6473. #if PACKETVER >= 20160921
  6474. p->items[i].location = pc_equippoint_sub( sd, data );
  6475. p->items[i].viewSprite = data->look;
  6476. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6477. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6478. #endif
  6479. #endif
  6480. #endif
  6481. }
  6482. WFIFOSET( fd, len );
  6483. }
  6484. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6485. /// 0135 <index>.W <amount>.W <result>.B
  6486. /// result:
  6487. /// 0 = success
  6488. /// 1 = not enough zeny
  6489. /// 2 = overweight
  6490. /// 4 = out of stock
  6491. /// 5 = "cannot use an npc shop while in a trade"
  6492. /// 6 = Because the store information was incorrect the item was not purchased.
  6493. /// 7 = No sales information.
  6494. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6495. {
  6496. int fd;
  6497. nullpo_retv(sd);
  6498. fd = sd->fd;
  6499. WFIFOHEAD(fd,packet_len(0x135));
  6500. WFIFOW(fd,0) = 0x135;
  6501. WFIFOW(fd,2) = index+2;
  6502. WFIFOW(fd,4) = amount;
  6503. WFIFOB(fd,6) = fail;
  6504. WFIFOSET(fd,packet_len(0x135));
  6505. }
  6506. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6507. /// 0a28 <Result>.B
  6508. /// result:
  6509. /// 0 = Successed
  6510. /// 1 = Failed
  6511. void clif_openvending_ack(struct map_session_data* sd, int result)
  6512. {
  6513. int fd;
  6514. nullpo_retv(sd);
  6515. fd = sd->fd;
  6516. WFIFOHEAD(fd, 3);
  6517. WFIFOW(fd,0) = 0xa28;
  6518. WFIFOB(fd,2) = result;
  6519. WFIFOSET(fd, 3);
  6520. }
  6521. /// Shop creation success.
  6522. /// 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)
  6523. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6524. nullpo_retv( sd );
  6525. nullpo_retv( vending );
  6526. int fd = sd->fd;
  6527. if( !session_isActive( fd ) ){
  6528. return;
  6529. }
  6530. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6531. WFIFOHEAD( fd, len );
  6532. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6533. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6534. p->packetLength = len;
  6535. p->AID = id;
  6536. for( int i = 0; i < sd->vend_num; i++ ) {
  6537. int index = vending[i].index;
  6538. p->items[i].price = vending[i].value;
  6539. p->items[i].index = client_index( index );
  6540. p->items[i].amount = vending[i].amount;
  6541. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6542. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6543. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6544. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6545. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6546. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6547. #if PACKETVER >= 20150226
  6548. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6549. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6550. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6551. #endif
  6552. #endif
  6553. }
  6554. WFIFOSET( fd, len );
  6555. #if PACKETVER >= 20141022
  6556. /// 0 = Successed
  6557. /// 1 = Failed
  6558. clif_openvending_ack( sd, 0 );
  6559. #endif
  6560. }
  6561. /// Inform merchant that someone has bought an item.
  6562. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6563. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6564. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6565. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6566. const int cmd = 0x137;
  6567. #else
  6568. const int cmd = 0x9e5;
  6569. #endif
  6570. int fd = sd->fd;
  6571. nullpo_retv(sd);
  6572. WFIFOHEAD(fd,packet_len(cmd));
  6573. WFIFOW(fd,0) = cmd;
  6574. WFIFOW(fd,2) = index+2;
  6575. WFIFOW(fd,4) = amount;
  6576. #if PACKETVER >= 20141016
  6577. WFIFOL(fd,6) = char_id; // GID
  6578. WFIFOL(fd,10) = (int)time(NULL); // Date
  6579. WFIFOL(fd,14) = zeny; // zeny
  6580. #endif
  6581. WFIFOSET(fd,packet_len(cmd));
  6582. }
  6583. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6584. /// 00fa <result>.B
  6585. /// result:
  6586. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6587. /// 1 = MsgStringTable[78]="party name already exists"
  6588. /// 2 = MsgStringTable[79]="already in a party"
  6589. /// 3 = cannot organize parties on this map
  6590. /// ? = nothing
  6591. void clif_party_created( struct map_session_data& sd, int result ){
  6592. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6593. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6594. p.result = result;
  6595. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6596. }
  6597. /// Adds new member to a party.
  6598. /// 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)
  6599. /// 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)
  6600. /// 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)
  6601. /// role:
  6602. /// 0 = leader
  6603. /// 1 = normal
  6604. /// state:
  6605. /// 0 = connected
  6606. /// 1 = disconnected
  6607. void clif_party_member_info( struct party_data& party, struct map_session_data& sd ){
  6608. int id = party_getmemberid( &party, &sd );
  6609. if( id < 0 ){
  6610. return;
  6611. }
  6612. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6613. p.packetType = partymemberinfo;
  6614. p.AID = sd.status.account_id;
  6615. #if PACKETVER >= 20171207
  6616. p.GID = sd.status.char_id;
  6617. #endif
  6618. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6619. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6620. p.class_ = sd.status.class_;
  6621. p.baseLevel = sd.status.base_level;
  6622. #endif
  6623. p.x = sd.bl.x;
  6624. p.y = sd.bl.y;
  6625. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6626. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6627. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6628. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6629. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6630. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6631. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6632. }
  6633. /// Sends party information (ZC_GROUP_LIST).
  6634. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6635. /// role:
  6636. /// 0 = leader
  6637. /// 1 = normal
  6638. /// state:
  6639. /// 0 = connected
  6640. /// 1 = disconnected
  6641. /// 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
  6642. void clif_party_info( struct party_data& party, struct map_session_data* sd ){
  6643. send_target target;
  6644. if( sd == nullptr ){
  6645. sd = party_getavailablesd( &party );
  6646. if( sd == nullptr ){
  6647. // Nobody is online to notify
  6648. return;
  6649. }
  6650. // Send to whole party
  6651. target = PARTY;
  6652. }else{
  6653. // Send only to self
  6654. target = SELF;
  6655. }
  6656. struct PACKET_ZC_GROUP_LIST* p = (struct PACKET_ZC_GROUP_LIST*)packet_buffer;
  6657. p->packetType = partyinfo;
  6658. p->packetLen = sizeof( *p );
  6659. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6660. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6661. struct party_member& m = party.party.member[i];
  6662. if( m.account_id == 0 ){
  6663. continue;
  6664. }
  6665. struct PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6666. member.AID = m.account_id;
  6667. #if PACKETVER >= 20171207
  6668. member.GID = m.char_id;
  6669. #endif
  6670. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6671. mapindex_getmapname_ext( mapindex_id2name( m.map ), member.mapName );
  6672. member.leader = ( m.leader ) ? 0 : 1;
  6673. member.offline = ( m.online ) ? 0 : 1;
  6674. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6675. member.class_ = m.class_;
  6676. member.baseLevel = m.lv;
  6677. #endif
  6678. c++;
  6679. p->packetLen += sizeof( member );
  6680. }
  6681. clif_send( p, p->packetLen, &sd->bl, target );
  6682. }
  6683. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6684. /// 02c9 <flag>.B
  6685. /// flag:
  6686. /// 0 = allow party invites
  6687. /// 1 = auto-deny party invites
  6688. void clif_partyinvitationstate( struct map_session_data& sd ){
  6689. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6690. struct PACKET_ZC_PARTY_CONFIG p = {};
  6691. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6692. p.denyPartyInvites = 0; // TODO: not implemented
  6693. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6694. #endif
  6695. }
  6696. /// Party invitation request.
  6697. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6698. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6699. void clif_party_invite( struct map_session_data& sd, struct map_session_data& tsd ){
  6700. struct party_data* party = party_search( sd.status.party_id );
  6701. if( party == nullptr ){
  6702. return;
  6703. }
  6704. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6705. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6706. p.GRID = party->party.party_id;
  6707. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6708. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6709. }
  6710. /// Party invite result.
  6711. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6712. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6713. /// result=0 : char is already in a party -> MsgStringTable[80]
  6714. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6715. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6716. /// result=3 : party is full -> MsgStringTable[83]
  6717. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6718. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6719. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6720. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6721. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6722. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6723. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6724. void clif_party_invite_reply( struct map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6725. #if PACKETVER < 20070904
  6726. if( reply == PARTY_REPLY_OFFLINE ){
  6727. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6728. return;
  6729. }
  6730. #endif
  6731. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6732. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6733. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6734. p.result = reply;
  6735. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6736. }
  6737. /// Updates party settings.
  6738. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6739. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6740. /// exp option:
  6741. /// 0 = exp sharing disabled
  6742. /// 1 = exp sharing enabled
  6743. /// 2 = cannot change exp sharing
  6744. ///
  6745. /// flag:
  6746. /// 0 = send to party
  6747. /// 1 = send to sd
  6748. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6749. {
  6750. unsigned char buf[16];
  6751. #if PACKETVER < 20090603
  6752. const int cmd = 0x101;
  6753. #else
  6754. const int cmd = 0x7d8;
  6755. #endif
  6756. nullpo_retv(p);
  6757. if(!sd && flag==0){
  6758. int i;
  6759. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6760. if (i < MAX_PARTY)
  6761. sd = p->data[i].sd;
  6762. }
  6763. if(!sd) return;
  6764. WBUFW(buf,0)=cmd;
  6765. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6766. #if PACKETVER >= 20090603
  6767. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6768. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6769. #endif
  6770. if(flag==0)
  6771. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6772. else
  6773. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6774. }
  6775. /**
  6776. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6777. * @param sd Send the notification for this player
  6778. * @param account_id Account ID of kicked member
  6779. * @param name Name of kicked member
  6780. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6781. * @param target Send target
  6782. **/
  6783. void clif_party_withdraw( struct map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6784. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6785. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6786. p.AID = account_id;
  6787. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6788. p.result = result;
  6789. clif_send( &p, sizeof( p ), &sd.bl, target );
  6790. }
  6791. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6792. /// 0109 <packet len>.W <account id>.L <message>.?B
  6793. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, int len ){
  6794. struct map_session_data* sd = party_getavailablesd( &party );
  6795. if( sd == nullptr ){
  6796. return;
  6797. }
  6798. if (len > CHAT_SIZE_MAX) {
  6799. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6800. len = CHAT_SIZE_MAX;
  6801. }
  6802. struct PACKET_ZC_NOTIFY_CHAT_PARTY* p = (struct PACKET_ZC_NOTIFY_CHAT_PARTY*)packet_buffer;
  6803. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6804. p->PacketLength = sizeof( *p ) + len;
  6805. p->AID = account_id;
  6806. safestrncpy( p->chatMsg, mes, len );
  6807. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6808. }
  6809. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6810. /// 0107 <account id>.L <x>.W <y>.W
  6811. void clif_party_xy( struct map_session_data& sd ){
  6812. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6813. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6814. p.AID = sd.status.account_id;
  6815. p.xPos = sd.bl.x;
  6816. p.yPos = sd.bl.y;
  6817. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6818. }
  6819. /*==========================================
  6820. * Sends x/y dot to a single fd. [Skotlex]
  6821. *------------------------------------------*/
  6822. void clif_party_xy_single( struct map_session_data& sd, struct map_session_data& tsd ){
  6823. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6824. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6825. p.AID = sd.status.account_id;
  6826. p.xPos = sd.bl.x;
  6827. p.yPos = sd.bl.y;
  6828. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6829. }
  6830. /// Updates HP bar of a party member.
  6831. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6832. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6833. void clif_party_hp( struct map_session_data& sd ){
  6834. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6835. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6836. p.AID = sd.status.account_id;
  6837. #if PACKETVER < 20100119
  6838. // To correctly display the %hp bar. [Skotlex]
  6839. if( sd.battle_status.max_hp > INT16_MAX ){
  6840. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6841. p.maxhp = 100;
  6842. }else{
  6843. p.hp = sd.battle_status.hp;
  6844. p.maxhp = sd.battle_status.max_hp;
  6845. }
  6846. #else
  6847. p.hp = sd.battle_status.hp;
  6848. p.maxhp = sd.battle_status.max_hp;
  6849. #endif
  6850. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6851. }
  6852. /// Notifies the party members of a character's death or revival.
  6853. /// 0AB2 <GID>.L <dead>.B
  6854. void clif_party_dead( struct map_session_data& sd ){
  6855. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6856. struct PACKET_ZC_GROUP_ISALIVE p = {};
  6857. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6858. p.AID = sd.status.account_id;
  6859. p.isDead = pc_isdead( &sd );
  6860. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6861. #endif
  6862. }
  6863. /// Updates the job and level of a party member
  6864. /// 0abd <account id>.L <job>.W <level>.W
  6865. void clif_party_job_and_level( struct map_session_data& sd ){
  6866. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  6867. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  6868. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  6869. p.AID = sd.status.account_id;
  6870. p.job = sd.status.class_;
  6871. p.level = sd.status.base_level;
  6872. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6873. #endif
  6874. }
  6875. /*==========================================
  6876. * Sends HP bar to a single fd. [Skotlex]
  6877. *------------------------------------------*/
  6878. void clif_hpmeter_single( struct map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  6879. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6880. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6881. p.AID = id;
  6882. #if PACKETVER < 20100119
  6883. // To correctly display the %hp bar. [Skotlex]
  6884. if( maxhp > INT16_MAX ){
  6885. p.hp = hp / ( maxhp / 100 );
  6886. p.maxhp = 100;
  6887. }else{
  6888. p.hp = hp;
  6889. p.maxhp = maxhp;
  6890. }
  6891. #else
  6892. p.hp = hp;
  6893. p.maxhp = maxhp;
  6894. #endif
  6895. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6896. }
  6897. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6898. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6899. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6900. {
  6901. int fd;
  6902. nullpo_retv(sd);
  6903. nullpo_retv(bl);
  6904. fd=sd->fd;
  6905. WFIFOHEAD(fd,packet_len(0x139));
  6906. WFIFOW(fd, 0)=0x139;
  6907. WFIFOL(fd, 2)=bl->id;
  6908. WFIFOW(fd, 6)=bl->x;
  6909. WFIFOW(fd, 8)=bl->y;
  6910. WFIFOW(fd,10)=sd->bl.x;
  6911. WFIFOW(fd,12)=sd->bl.y;
  6912. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6913. WFIFOSET(fd,packet_len(0x139));
  6914. }
  6915. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6916. /// 018f <result>.W <name id>.W
  6917. /// result:
  6918. /// 0 = success
  6919. /// 1 = failure
  6920. /// 2 = success (alchemist)
  6921. /// 3 = failure (alchemist)
  6922. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  6923. nullpo_retv( sd );
  6924. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6925. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6926. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6927. p.result = flag;
  6928. p.itemId = client_nameid( nameid );
  6929. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6930. }
  6931. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6932. /// 019e
  6933. void clif_catch_process(struct map_session_data *sd)
  6934. {
  6935. int fd;
  6936. nullpo_retv(sd);
  6937. fd=sd->fd;
  6938. WFIFOHEAD(fd,packet_len(0x19e));
  6939. WFIFOW(fd,0)=0x19e;
  6940. WFIFOSET(fd,packet_len(0x19e));
  6941. }
  6942. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6943. /// 01a0 <result>.B
  6944. /// 0 = failure
  6945. /// 1 = success
  6946. void clif_pet_roulette(struct map_session_data *sd,int data)
  6947. {
  6948. int fd;
  6949. nullpo_retv(sd);
  6950. fd=sd->fd;
  6951. WFIFOHEAD(fd,packet_len(0x1a0));
  6952. WFIFOW(fd,0)=0x1a0;
  6953. WFIFOB(fd,2)=data;
  6954. WFIFOSET(fd,packet_len(0x1a0));
  6955. }
  6956. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6957. /// 01a6 <packet len>.W { <index>.W }*
  6958. void clif_sendegg(struct map_session_data *sd)
  6959. {
  6960. int i,n=0,fd;
  6961. nullpo_retv(sd);
  6962. fd=sd->fd;
  6963. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6964. clif_displaymessage(fd, msg_txt(sd,666));
  6965. return;
  6966. }
  6967. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6968. WFIFOW(fd,0)=0x1a6;
  6969. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6970. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  6971. sd->inventory_data[i]->type != IT_PETEGG ||
  6972. sd->inventory.u.items_inventory[i].amount <= 0)
  6973. continue;
  6974. WFIFOW(fd,n*2+4)=client_index(i);
  6975. n++;
  6976. }
  6977. WFIFOW(fd,2)=4+n*2;
  6978. WFIFOSET(fd,WFIFOW(fd,2));
  6979. sd->menuskill_id = SA_TAMINGMONSTER;
  6980. sd->menuskill_val = -1;
  6981. }
  6982. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6983. /// 01a4 <type>.B <id>.L <data>.L
  6984. /// type:
  6985. /// 0 = pre-init (data = 0)
  6986. /// 1 = intimacy (data = 0~4)
  6987. /// 2 = hunger (data = 0~4)
  6988. /// 3 = accessory
  6989. /// 4 = performance (data = 1~3: normal, 4: special)
  6990. /// 5 = hairstyle
  6991. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6992. ///
  6993. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6994. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6995. {
  6996. uint8 buf[16];
  6997. nullpo_retv(pd);
  6998. WBUFW(buf,0) = 0x1a4;
  6999. WBUFB(buf,2) = type;
  7000. WBUFL(buf,3) = pd->bl.id;
  7001. WBUFL(buf,7) = param;
  7002. if (sd)
  7003. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7004. else
  7005. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7006. }
  7007. /// Pet's base data (ZC_PROPERTY_PET).
  7008. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7009. void clif_send_petstatus(struct map_session_data *sd)
  7010. {
  7011. int fd;
  7012. struct s_pet *pet;
  7013. nullpo_retv(sd);
  7014. nullpo_retv(sd->pd);
  7015. fd=sd->fd;
  7016. pet = &sd->pd->pet;
  7017. WFIFOHEAD(fd,packet_len(0x1a2));
  7018. WFIFOW(fd,0)=0x1a2;
  7019. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7020. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7021. WFIFOW(fd,27)=pet->level;
  7022. WFIFOW(fd,29)=pet->hungry;
  7023. WFIFOW(fd,31)=pet->intimate;
  7024. WFIFOW(fd,33)=pet->equip;
  7025. #if PACKETVER >= 20081126
  7026. WFIFOW(fd,35)=pet->class_;
  7027. #endif
  7028. WFIFOSET(fd,packet_len(0x1a2));
  7029. }
  7030. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7031. /// 01aa <id>.L <data>.L
  7032. /// data:
  7033. /// @see CZ_PET_ACT.
  7034. void clif_pet_emotion(struct pet_data *pd,int param)
  7035. {
  7036. unsigned char buf[16];
  7037. nullpo_retv(pd);
  7038. memset(buf,0,packet_len(0x1aa));
  7039. WBUFW(buf,0)=0x1aa;
  7040. WBUFL(buf,2)=pd->bl.id;
  7041. WBUFL(buf,6)=param;
  7042. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7043. }
  7044. /// Result of request to feed a pet (ZC_FEED_PET).
  7045. /// 01a3 <result>.B <name id>.W
  7046. /// result:
  7047. /// 0 = failure
  7048. /// 1 = success
  7049. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  7050. nullpo_retv( sd );
  7051. struct PACKET_ZC_FEED_PET p;
  7052. p.packetType = 0x1a3;
  7053. p.result = fail;
  7054. p.itemId = client_nameid( foodid );
  7055. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7056. }
  7057. /// Send pet auto feed info.
  7058. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  7059. #if PACKETVER >= 20141008
  7060. nullpo_retv(sd);
  7061. if (force || battle_config.pet_autofeed_always) {
  7062. // Always send ON or OFF
  7063. if (sd->pd && battle_config.feature_pet_autofeed) {
  7064. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7065. }
  7066. else {
  7067. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7068. }
  7069. }
  7070. else {
  7071. // Only send when enabled
  7072. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7073. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7074. }
  7075. }
  7076. #endif
  7077. }
  7078. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7079. /// 01cd { <skill id>.L }*7
  7080. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  7081. {
  7082. nullpo_retv(sd);
  7083. int fd = sd->fd;
  7084. #ifdef RENEWAL
  7085. uint16 autospell_skill[][2] = {
  7086. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7087. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7088. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7089. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7090. };
  7091. int count = 0;
  7092. WFIFOHEAD(fd, 2 * 6 + 4);
  7093. WFIFOW(fd, 0) = 0x442;
  7094. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7095. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7096. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7097. count++;
  7098. }
  7099. }
  7100. WFIFOW(fd, 2) = 8 + count * 2;
  7101. WFIFOL(fd, 4) = count;
  7102. WFIFOSET(fd, WFIFOW(fd, 2));
  7103. #else
  7104. WFIFOHEAD(fd,packet_len(0x1cd));
  7105. WFIFOW(fd, 0)=0x1cd;
  7106. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7107. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7108. else
  7109. WFIFOL(fd,2)= 0x00000000;
  7110. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7111. WFIFOL(fd,6)= MG_COLDBOLT;
  7112. else
  7113. WFIFOL(fd,6)= 0x00000000;
  7114. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7115. WFIFOL(fd,10)= MG_FIREBOLT;
  7116. else
  7117. WFIFOL(fd,10)= 0x00000000;
  7118. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7119. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7120. else
  7121. WFIFOL(fd,14)= 0x00000000;
  7122. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7123. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7124. else
  7125. WFIFOL(fd,18)= 0x00000000;
  7126. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7127. WFIFOL(fd,22)= MG_FIREBALL;
  7128. else
  7129. WFIFOL(fd,22)= 0x00000000;
  7130. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7131. WFIFOL(fd,26)= MG_FROSTDIVER;
  7132. else
  7133. WFIFOL(fd,26)= 0x00000000;
  7134. WFIFOSET(fd,packet_len(0x1cd));
  7135. #endif
  7136. sd->menuskill_id = SA_AUTOSPELL;
  7137. sd->menuskill_val = skill_lv;
  7138. }
  7139. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7140. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7141. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7142. {
  7143. unsigned char buf[56];
  7144. nullpo_retv(src);
  7145. memset(buf,0,packet_len(0x1cf));
  7146. WBUFW(buf,0) = 0x1cf;
  7147. WBUFL(buf,2) = src->id;
  7148. if( src->type == BL_MER )
  7149. {
  7150. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7151. if( md && md->master && md->devotion_flag )
  7152. WBUFL(buf,6) = md->master->bl.id;
  7153. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7154. }
  7155. else
  7156. {
  7157. int i;
  7158. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7159. if( sd == NULL )
  7160. return;
  7161. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7162. WBUFL(buf,6+4*i) = sd->devotion[i];
  7163. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7164. }
  7165. if( tsd )
  7166. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7167. else
  7168. clif_send(buf, packet_len(0x1cf), src, AREA);
  7169. }
  7170. /// Notifies the client of an object's spirits.
  7171. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7172. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7173. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7174. nullpo_retv( bl );
  7175. struct PACKET_ZC_SPIRITS p = {};
  7176. p.PacketType = HEADER_ZC_SPIRITS;
  7177. p.AID = bl->id;
  7178. switch( bl->type ){
  7179. case BL_PC:
  7180. p.num = ( (struct map_session_data*)bl )->spiritball;
  7181. break;
  7182. case BL_HOM:
  7183. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7184. break;
  7185. }
  7186. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7187. }
  7188. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7189. /// 01d2 <account id>.L <delay>.L
  7190. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7191. {
  7192. unsigned char buf[32];
  7193. nullpo_retv(bl);
  7194. WBUFW(buf,0)=0x1d2;
  7195. WBUFL(buf,2)=bl->id;
  7196. WBUFL(buf,6)=client_tick(wait);
  7197. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7198. }
  7199. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7200. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7201. /// flag:
  7202. /// 0 = inactive
  7203. /// 1 = active
  7204. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7205. {
  7206. unsigned char buf[32];
  7207. nullpo_retv(src);
  7208. WBUFW(buf,0)=0x1d1;
  7209. WBUFL(buf,2)=src->id;
  7210. WBUFL(buf,6)=dst_id;
  7211. WBUFL(buf,10)=active;
  7212. clif_send(buf,packet_len(0x1d1),src,AREA);
  7213. }
  7214. /// MVP effect (ZC_MVP).
  7215. /// 010c <account id>.L
  7216. void clif_mvp_effect(struct map_session_data *sd)
  7217. {
  7218. unsigned char buf[16];
  7219. nullpo_retv(sd);
  7220. WBUFW(buf,0)=0x10c;
  7221. WBUFL(buf,2)=sd->bl.id;
  7222. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7223. }
  7224. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7225. /// 010a <name id>.W
  7226. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7227. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7228. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7229. p.itemId = client_nameid( nameid );
  7230. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7231. }
  7232. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7233. /// 010b <exp>.L
  7234. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7235. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7236. if (battle_config.mvp_exp_reward_message) {
  7237. char e_msg[CHAT_SIZE_MAX];
  7238. sprintf(e_msg, msg_txt(sd, 717), exp);
  7239. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7240. }
  7241. #else
  7242. int fd;
  7243. nullpo_retv(sd);
  7244. fd = sd->fd;
  7245. WFIFOHEAD(fd, packet_len(0x10b));
  7246. WFIFOW(fd,0) = 0x10b;
  7247. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7248. WFIFOSET(fd, packet_len(0x10b));
  7249. #endif
  7250. }
  7251. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7252. /// 010d
  7253. ///
  7254. /// "You are the MVP, but cannot obtain the reward because
  7255. /// you are overweight."
  7256. void clif_mvp_noitem(struct map_session_data* sd)
  7257. {
  7258. int fd = sd->fd;
  7259. WFIFOHEAD(fd,packet_len(0x10d));
  7260. WFIFOW(fd,0) = 0x10d;
  7261. WFIFOSET(fd,packet_len(0x10d));
  7262. }
  7263. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7264. /// 0167 <result>.B
  7265. /// result:
  7266. /// 0 = "Guild has been created."
  7267. /// 1 = "You are already in a Guild."
  7268. /// 2 = "That Guild Name already exists."
  7269. /// 3 = "You need the neccessary item to create a Guild."
  7270. void clif_guild_created(struct map_session_data *sd,int flag)
  7271. {
  7272. int fd;
  7273. nullpo_retv(sd);
  7274. fd=sd->fd;
  7275. WFIFOHEAD(fd,packet_len(0x167));
  7276. WFIFOW(fd,0)=0x167;
  7277. WFIFOB(fd,2)=flag;
  7278. WFIFOSET(fd,packet_len(0x167));
  7279. }
  7280. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7281. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7282. /// mode:
  7283. /// &0x01 = allow invite
  7284. /// &0x10 = allow expel
  7285. void clif_guild_belonginfo( struct map_session_data& sd ){
  7286. if( sd.guild == nullptr ){
  7287. return;
  7288. }
  7289. struct guild& guild = *sd.guild;
  7290. int position = guild_getposition( &sd );
  7291. if( position < 0 ){
  7292. return;
  7293. }
  7294. struct PACKET_ZC_UPDATE_GDID p = {};
  7295. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7296. p.guildId = guild.guild_id;
  7297. p.emblemVersion = guild.emblem_id;
  7298. p.mode = guild.position[position].mode;
  7299. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7300. p.interSid = 0; // InterSID (unknown purpose)
  7301. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7302. #if PACKETVER_MAIN_NUM >= 20220216
  7303. p.masterGID = guild.member[0].char_id;
  7304. #endif
  7305. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7306. }
  7307. /// Guild member login notice.
  7308. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7309. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7310. /// status:
  7311. /// 0 = offline
  7312. /// 1 = online
  7313. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7314. {
  7315. unsigned char buf[64];
  7316. struct map_session_data* sd;
  7317. nullpo_retv(g);
  7318. WBUFW(buf, 0)=0x1f2;
  7319. WBUFL(buf, 2)=g->member[idx].account_id;
  7320. WBUFL(buf, 6)=g->member[idx].char_id;
  7321. WBUFL(buf,10)=flag;
  7322. if( ( sd = g->member[idx].sd ) != NULL )
  7323. {
  7324. WBUFW(buf,14) = sd->status.sex;
  7325. WBUFW(buf,16) = sd->status.hair;
  7326. WBUFW(buf,18) = sd->status.hair_color;
  7327. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7328. }
  7329. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7330. {
  7331. WBUFW(buf,14) = 0;
  7332. WBUFW(buf,16) = 0;
  7333. WBUFW(buf,18) = 0;
  7334. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7335. }
  7336. }
  7337. // Function `clif_guild_memberlogin_notice` sends info about
  7338. // logins and logouts of a guild member to the rest members.
  7339. // But at the 1st time (after a player login or map changing)
  7340. // the client won't show the message.
  7341. // So I suggest use this function for sending "first-time-info"
  7342. // to some player on entering the game or changing location.
  7343. // At next time the client would always show the message.
  7344. // The function sends all the statuses in the single packet
  7345. // to economize traffic. [LuzZza]
  7346. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7347. {
  7348. struct guild *g;
  7349. unsigned char buf[14*128];
  7350. int i, count=0, p_len;
  7351. nullpo_retv(sd);
  7352. p_len = packet_len(0x16d);
  7353. if(!(g = sd->guild))
  7354. return;
  7355. for(i=0; i<g->max_member; i++) {
  7356. if(g->member[i].account_id > 0 &&
  7357. g->member[i].account_id != sd->status.account_id) {
  7358. WBUFW(buf,count*p_len) = 0x16d;
  7359. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7360. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7361. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7362. count++;
  7363. }
  7364. }
  7365. clif_send(buf, p_len*count, &sd->bl, SELF);
  7366. }
  7367. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7368. /// 014e <menu flag>.L
  7369. /// menu flag:
  7370. /// 0x00 = Basic Info (always on)
  7371. /// &0x01 = Member manager
  7372. /// &0x02 = Positions
  7373. /// &0x04 = Skills
  7374. /// &0x10 = Expulsion list
  7375. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7376. /// &0x80 = Notice
  7377. void clif_guild_masterormember(struct map_session_data *sd)
  7378. {
  7379. int fd;
  7380. nullpo_retv(sd);
  7381. fd=sd->fd;
  7382. WFIFOHEAD(fd,packet_len(0x14e));
  7383. WFIFOW(fd,0) = 0x14e;
  7384. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7385. WFIFOSET(fd,packet_len(0x14e));
  7386. }
  7387. /// Guild basic information (Territories [Valaris])
  7388. /// 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)
  7389. /// 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)
  7390. /// 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)
  7391. void clif_guild_basicinfo( struct map_session_data& sd ){
  7392. if( sd.guild == nullptr ){
  7393. return;
  7394. }
  7395. struct guild& guild = *sd.guild;
  7396. struct PACKET_ZC_GUILD_INFO p = {};
  7397. p.PacketType = HEADER_ZC_GUILD_INFO;
  7398. p.GDID = guild.guild_id;
  7399. p.level = guild.guild_lv;
  7400. p.userNum = guild.connect_member;
  7401. p.maxUserNum = guild.max_member;
  7402. p.userAverageLevel = guild.average_lv;
  7403. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7404. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7405. p.point = 0; // Tax Points
  7406. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7407. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7408. p.emblemVersion = guild.emblem_id;
  7409. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7410. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( &guild ) ), sizeof( p.manageLand ) );
  7411. p.zeny = 0;
  7412. #if PACKETVER >= 20200902
  7413. p.masterGID = guild.member[0].char_id; // leader
  7414. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7415. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7416. p.masterGID = guild.member[0].char_id; // leader
  7417. #else
  7418. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7419. #endif
  7420. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7421. }
  7422. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7423. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7424. void clif_guild_allianceinfo(struct map_session_data *sd)
  7425. {
  7426. int fd,i,c;
  7427. struct guild *g;
  7428. nullpo_retv(sd);
  7429. if( (g = sd->guild) == NULL )
  7430. return;
  7431. fd = sd->fd;
  7432. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7433. WFIFOW(fd, 0)=0x14c;
  7434. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7435. struct guild_alliance *a=&g->alliance[i];
  7436. if(a->guild_id>0){
  7437. WFIFOL(fd,c*32+4)=a->opposition;
  7438. WFIFOL(fd,c*32+8)=a->guild_id;
  7439. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7440. c++;
  7441. }
  7442. }
  7443. WFIFOW(fd, 2)=c*32+4;
  7444. WFIFOSET(fd,WFIFOW(fd,2));
  7445. }
  7446. /// Guild member manager information
  7447. /// 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)
  7448. /// state:
  7449. /// 0 = offline
  7450. /// 1 = online
  7451. /// memo:
  7452. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7453. /// 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)
  7454. void clif_guild_memberlist( struct map_session_data& sd ){
  7455. if( sd.guild == nullptr ){
  7456. return;
  7457. }
  7458. struct guild& guild = *sd.guild;
  7459. struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer;
  7460. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7461. p->packetLength = sizeof( *p );
  7462. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7463. struct guild_member& member = guild.member[i];
  7464. if( member.account_id == 0 ){
  7465. continue;
  7466. }
  7467. struct GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7468. member_info.AID = member.account_id;
  7469. member_info.GID = member.char_id;
  7470. member_info.head = member.hair;
  7471. member_info.headPalette = member.hair_color;
  7472. member_info.sex = member.gender;
  7473. member_info.job = member.class_;
  7474. member_info.level = member.lv;
  7475. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7476. member_info.currentState = member.online;
  7477. member_info.positionID = member.position;
  7478. #if PACKETVER >= 20200902
  7479. member_info.lastLoginTime = member.last_login;
  7480. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7481. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7482. member_info.lastLoginTime = member.last_login;
  7483. #else
  7484. 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.
  7485. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7486. #endif
  7487. c++;
  7488. p->packetLength += sizeof( member_info );
  7489. }
  7490. clif_send( p, p->packetLength, &sd.bl, SELF );
  7491. }
  7492. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7493. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7494. void clif_guild_positionnamelist(struct map_session_data *sd)
  7495. {
  7496. int i,fd;
  7497. struct guild *g;
  7498. nullpo_retv(sd);
  7499. if( (g = sd->guild) == NULL )
  7500. return;
  7501. fd = sd->fd;
  7502. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7503. WFIFOW(fd, 0)=0x166;
  7504. for(i=0;i<MAX_GUILDPOSITION;i++){
  7505. WFIFOL(fd,i*28+4)=i;
  7506. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7507. }
  7508. WFIFOW(fd,2)=i*28+4;
  7509. WFIFOSET(fd,WFIFOW(fd,2));
  7510. }
  7511. /// Guild position information (ZC_POSITION_INFO).
  7512. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7513. /// mode:
  7514. /// &0x01 = allow invite
  7515. /// &0x10 = allow expel
  7516. /// ranking:
  7517. /// TODO
  7518. void clif_guild_positioninfolist(struct map_session_data *sd)
  7519. {
  7520. int i,fd;
  7521. struct guild *g;
  7522. nullpo_retv(sd);
  7523. if( (g = sd->guild) == NULL )
  7524. return;
  7525. fd = sd->fd;
  7526. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7527. WFIFOW(fd, 0)=0x160;
  7528. for(i=0;i<MAX_GUILDPOSITION;i++){
  7529. struct guild_position *p=&g->position[i];
  7530. WFIFOL(fd,i*16+ 4)=i;
  7531. WFIFOL(fd,i*16+ 8)=p->mode;
  7532. WFIFOL(fd,i*16+12)=i;
  7533. WFIFOL(fd,i*16+16)=p->exp_mode;
  7534. }
  7535. WFIFOW(fd, 2)=i*16+4;
  7536. WFIFOSET(fd,WFIFOW(fd,2));
  7537. }
  7538. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7539. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7540. /// mode:
  7541. /// &0x01 = allow invite
  7542. /// &0x10 = allow expel
  7543. /// ranking:
  7544. /// TODO
  7545. void clif_guild_positionchanged(struct guild *g,int idx)
  7546. {
  7547. // FIXME: This packet is intended to update the clients after a
  7548. // commit of position info changes, not sending one packet per
  7549. // position.
  7550. struct map_session_data *sd;
  7551. unsigned char buf[128];
  7552. nullpo_retv(g);
  7553. WBUFW(buf, 0)=0x174;
  7554. WBUFW(buf, 2)=44; // packet len
  7555. // GUILD_REG_POSITION_INFO{
  7556. WBUFL(buf, 4)=idx;
  7557. WBUFL(buf, 8)=g->position[idx].mode;
  7558. WBUFL(buf,12)=idx;
  7559. WBUFL(buf,16)=g->position[idx].exp_mode;
  7560. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7561. // }*
  7562. if( (sd=guild_getavailablesd(g))!=NULL )
  7563. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7564. }
  7565. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7566. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7567. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7568. {
  7569. // FIXME: This packet is intended to update the clients after a
  7570. // commit of member position assignment changes, not sending one
  7571. // packet per position.
  7572. struct map_session_data *sd;
  7573. unsigned char buf[64];
  7574. nullpo_retv(g);
  7575. WBUFW(buf, 0)=0x156;
  7576. WBUFW(buf, 2)=16; // packet len
  7577. // MEMBER_POSITION_INFO{
  7578. WBUFL(buf, 4)=g->member[idx].account_id;
  7579. WBUFL(buf, 8)=g->member[idx].char_id;
  7580. WBUFL(buf,12)=g->member[idx].position;
  7581. // }*
  7582. if( (sd=guild_getavailablesd(g))!=NULL )
  7583. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7584. }
  7585. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7586. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7587. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7588. {
  7589. int fd;
  7590. nullpo_retv(sd);
  7591. nullpo_retv(g);
  7592. fd = sd->fd;
  7593. if( g->emblem_len <= 0 )
  7594. return;
  7595. WFIFOHEAD(fd,g->emblem_len+12);
  7596. WFIFOW(fd,0)=0x152;
  7597. WFIFOW(fd,2)=g->emblem_len+12;
  7598. WFIFOL(fd,4)=g->guild_id;
  7599. WFIFOL(fd,8)=g->emblem_id;
  7600. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7601. WFIFOSET(fd,WFIFOW(fd,2));
  7602. }
  7603. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7604. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7605. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7606. void clif_guild_emblem_area(struct block_list* bl)
  7607. {
  7608. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7609. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7610. PACKET_ZC_CHANGE_GUILD p{};
  7611. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7612. p.guild_id = status_get_guild_id(bl);
  7613. p.emblem_id = status_get_emblem_id(bl);
  7614. #if PACKETVER < 20190724
  7615. p.aid = bl->id;
  7616. #else
  7617. p.unknown = 0;
  7618. #endif
  7619. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7620. }
  7621. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7622. /// 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 }*
  7623. void clif_guild_skillinfo(struct map_session_data* sd)
  7624. {
  7625. int fd;
  7626. struct guild* g;
  7627. int i,c;
  7628. nullpo_retv(sd);
  7629. if( (g = sd->guild) == NULL )
  7630. return;
  7631. fd = sd->fd;
  7632. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7633. WFIFOW(fd,0) = 0x0162;
  7634. WFIFOW(fd,4) = g->skill_point;
  7635. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7636. {
  7637. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7638. {
  7639. int id = g->skill[i].id;
  7640. int p = 6 + c*37;
  7641. WFIFOW(fd,p+0) = id;
  7642. WFIFOL(fd,p+2) = skill_get_inf(id);
  7643. WFIFOW(fd,p+6) = g->skill[i].lv;
  7644. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7645. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7646. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7647. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7648. c++;
  7649. }
  7650. }
  7651. WFIFOW(fd,2) = 6 + c*37;
  7652. WFIFOSET(fd,WFIFOW(fd,2));
  7653. }
  7654. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7655. /// 016f <subject>.60B <notice>.120B
  7656. void clif_guild_notice(struct map_session_data* sd)
  7657. {
  7658. struct guild* g;
  7659. nullpo_retv(sd);
  7660. nullpo_retv(g = sd->guild);
  7661. int fd = sd->fd;
  7662. if ( !session_isActive(fd) )
  7663. return;
  7664. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7665. return;
  7666. WFIFOHEAD(fd,packet_len(0x16f));
  7667. WFIFOW(fd,0) = 0x16f;
  7668. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7669. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7670. WFIFOSET(fd,packet_len(0x16f));
  7671. }
  7672. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7673. /// 016a <guild id>.L <guild name>.24B
  7674. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7675. {
  7676. int fd;
  7677. nullpo_retv(sd);
  7678. nullpo_retv(g);
  7679. fd=sd->fd;
  7680. WFIFOHEAD(fd,packet_len(0x16a));
  7681. WFIFOW(fd,0)=0x16a;
  7682. WFIFOL(fd,2)=g->guild_id;
  7683. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7684. WFIFOSET(fd,packet_len(0x16a));
  7685. }
  7686. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7687. /// 0169 <answer>.B
  7688. /// answer:
  7689. /// 0 = Already in guild.
  7690. /// 1 = Offer rejected.
  7691. /// 2 = Offer accepted.
  7692. /// 3 = Guild full.
  7693. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7694. {
  7695. int fd;
  7696. nullpo_retv(sd);
  7697. fd=sd->fd;
  7698. WFIFOHEAD(fd,packet_len(0x169));
  7699. WFIFOW(fd,0)=0x169;
  7700. WFIFOB(fd,2)=flag;
  7701. WFIFOSET(fd,packet_len(0x169));
  7702. }
  7703. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7704. /// 015a <char name>.24B <reason>.40B
  7705. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7706. {
  7707. unsigned char buf[128];
  7708. nullpo_retv(sd);
  7709. WBUFW(buf, 0)=0x15a;
  7710. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7711. memcpy(WBUFP(buf,26),mes,40);
  7712. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7713. }
  7714. /// Notifies clients of a guild of an expelled member.
  7715. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7716. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7717. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7718. {
  7719. unsigned char buf[128];
  7720. #if PACKETVER < 20100803
  7721. const unsigned short cmd = 0x15c;
  7722. #else
  7723. const unsigned short cmd = 0x839;
  7724. #endif
  7725. nullpo_retv(sd);
  7726. WBUFW(buf,0) = cmd;
  7727. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7728. safestrncpy(WBUFCP(buf,26), mes, 40);
  7729. #if PACKETVER < 20100803
  7730. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7731. #endif
  7732. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7733. }
  7734. /// Guild expulsion list (ZC_BAN_LIST).
  7735. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7736. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7737. void clif_guild_expulsionlist(struct map_session_data* sd)
  7738. {
  7739. #if PACKETVER < 20100803
  7740. const int offset = NAME_LENGTH*2+40;
  7741. #else
  7742. const int offset = NAME_LENGTH+40;
  7743. #endif
  7744. int fd, i, c = 0;
  7745. struct guild* g;
  7746. nullpo_retv(sd);
  7747. if( (g = sd->guild) == NULL )
  7748. return;
  7749. fd = sd->fd;
  7750. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7751. WFIFOW(fd,0) = 0x163;
  7752. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7753. {
  7754. struct guild_expulsion* e = &g->expulsion[i];
  7755. if( e->account_id > 0 )
  7756. {
  7757. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7758. #if PACKETVER < 20100803
  7759. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7760. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7761. #else
  7762. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7763. #endif
  7764. c++;
  7765. }
  7766. }
  7767. WFIFOW(fd,2) = 4 + c*offset;
  7768. WFIFOSET(fd,WFIFOW(fd,2));
  7769. }
  7770. /// Guild chat message (ZC_GUILD_CHAT).
  7771. /// 017f <packet len>.W <message>.?B
  7772. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7773. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7774. struct map_session_data *sd;
  7775. uint8 buf[256];
  7776. if( len == 0 )
  7777. {
  7778. return;
  7779. }
  7780. else if( len > sizeof(buf)-5 )
  7781. {
  7782. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7783. len = sizeof(buf)-5;
  7784. }
  7785. WBUFW(buf, 0) = 0x17f;
  7786. WBUFW(buf, 2) = len + 5;
  7787. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7788. if ((sd = guild_getavailablesd(g)) != NULL)
  7789. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7790. }
  7791. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7792. /// 0171 <inviter account id>.L <guild name>.24B
  7793. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7794. {
  7795. int fd;
  7796. nullpo_retv(sd);
  7797. fd=sd->fd;
  7798. WFIFOHEAD(fd,packet_len(0x171));
  7799. WFIFOW(fd,0)=0x171;
  7800. WFIFOL(fd,2)=account_id;
  7801. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7802. WFIFOSET(fd,packet_len(0x171));
  7803. }
  7804. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7805. /// 0173 <answer>.B
  7806. /// answer:
  7807. /// 0 = Already allied.
  7808. /// 1 = You rejected the offer.
  7809. /// 2 = You accepted the offer.
  7810. /// 3 = They have too any alliances.
  7811. /// 4 = You have too many alliances.
  7812. /// 5 = Alliances are disabled.
  7813. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7814. {
  7815. int fd;
  7816. nullpo_retv(sd);
  7817. fd=sd->fd;
  7818. WFIFOHEAD(fd,packet_len(0x173));
  7819. WFIFOW(fd,0)=0x173;
  7820. WFIFOL(fd,2)=flag;
  7821. WFIFOSET(fd,packet_len(0x173));
  7822. }
  7823. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7824. /// 0184 <other guild id>.L <relation>.L
  7825. /// relation:
  7826. /// 0 = Ally
  7827. /// 1 = Enemy
  7828. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7829. {
  7830. nullpo_retv(sd);
  7831. int fd = sd->fd;
  7832. if ( !session_isActive(fd) )
  7833. return;
  7834. WFIFOHEAD(fd,packet_len(0x184));
  7835. WFIFOW(fd,0)=0x184;
  7836. WFIFOL(fd,2)=guild_id;
  7837. WFIFOL(fd,6)=flag;
  7838. WFIFOSET(fd,packet_len(0x184));
  7839. }
  7840. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7841. /// 0181 <result>.B
  7842. /// result:
  7843. /// 0 = Antagonist has been set.
  7844. /// 1 = Guild has too many Antagonists.
  7845. /// 2 = Already set as an Antagonist.
  7846. /// 3 = Antagonists are disabled.
  7847. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7848. {
  7849. int fd;
  7850. nullpo_retv(sd);
  7851. fd=sd->fd;
  7852. WFIFOHEAD(fd,packet_len(0x181));
  7853. WFIFOW(fd,0)=0x181;
  7854. WFIFOB(fd,2)=flag;
  7855. WFIFOSET(fd,packet_len(0x181));
  7856. }
  7857. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7858. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7859. /*
  7860. void clif_guild_allianceadded(struct guild *g,int idx)
  7861. {
  7862. unsigned char buf[64];
  7863. WBUFW(buf,0)=0x185;
  7864. WBUFL(buf,2)=g->alliance[idx].opposition;
  7865. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7866. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7867. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7868. }
  7869. */
  7870. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7871. /// 015e <reason>.L
  7872. /// 0 = success
  7873. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7874. /// 2 = there are still members in the guild
  7875. void clif_guild_broken(struct map_session_data *sd,int flag)
  7876. {
  7877. int fd;
  7878. nullpo_retv(sd);
  7879. fd=sd->fd;
  7880. WFIFOHEAD(fd,packet_len(0x15e));
  7881. WFIFOW(fd,0)=0x15e;
  7882. WFIFOL(fd,2)=flag;
  7883. WFIFOSET(fd,packet_len(0x15e));
  7884. }
  7885. /// Displays emotion on an object (ZC_EMOTION).
  7886. /// 00c0 <id>.L <type>.B
  7887. /// type:
  7888. /// enum emotion_type
  7889. void clif_emotion(struct block_list *bl,int type)
  7890. {
  7891. unsigned char buf[8];
  7892. nullpo_retv(bl);
  7893. WBUFW(buf,0)=0xc0;
  7894. WBUFL(buf,2)=bl->id;
  7895. WBUFB(buf,6)=type;
  7896. clif_send(buf,packet_len(0xc0),bl,AREA);
  7897. }
  7898. /// Displays the contents of a talkiebox trap.
  7899. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7900. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7901. nullpo_retv( bl );
  7902. nullpo_retv( talkie );
  7903. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7904. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7905. p.aid = bl->id;
  7906. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7907. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7908. }
  7909. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7910. /// 01ea <id>.L
  7911. void clif_wedding_effect(struct block_list *bl)
  7912. {
  7913. unsigned char buf[6];
  7914. nullpo_retv(bl);
  7915. WBUFW(buf,0) = 0x1ea;
  7916. WBUFL(buf,2) = bl->id;
  7917. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7918. }
  7919. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7920. /// 01e6 <partner name>.24B
  7921. void clif_callpartner(struct map_session_data *sd)
  7922. {
  7923. unsigned char buf[26];
  7924. nullpo_retv(sd);
  7925. WBUFW(buf,0) = 0x1e6;
  7926. if( sd->status.partner_id ) {
  7927. const char *p = map_charid2nick(sd->status.partner_id);
  7928. struct map_session_data *p_sd = pc_get_partner(sd);
  7929. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7930. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7931. else
  7932. WBUFB(buf,2) = 0;
  7933. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7934. WBUFB(buf,2) = 0;
  7935. }
  7936. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7937. }
  7938. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7939. /// 01e4
  7940. /// This packet while still implemented by the client is no longer being officially used.
  7941. /*
  7942. void clif_marriage_process(struct map_session_data *sd)
  7943. {
  7944. int fd;
  7945. nullpo_retv(sd);
  7946. fd=sd->fd;
  7947. WFIFOHEAD(fd,packet_len(0x1e4));
  7948. WFIFOW(fd,0)=0x1e4;
  7949. WFIFOSET(fd,packet_len(0x1e4));
  7950. }
  7951. */
  7952. /// Notice of divorce (ZC_DIVORCE).
  7953. /// 0205 <partner name>.24B
  7954. void clif_divorced(struct map_session_data* sd, const char* name)
  7955. {
  7956. int fd;
  7957. nullpo_retv(sd);
  7958. fd=sd->fd;
  7959. WFIFOHEAD(fd,packet_len(0x205));
  7960. WFIFOW(fd,0)=0x205;
  7961. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7962. WFIFOSET(fd, packet_len(0x205));
  7963. }
  7964. /// Marriage proposal (ZC_REQ_COUPLE).
  7965. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7966. /// This packet while still implemented by the client is no longer being officially used.
  7967. /*
  7968. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7969. {
  7970. nullpo_retv(sd);
  7971. WFIFOHEAD(fd,packet_len(0x1e2));
  7972. WFIFOW(fd,0) = 0x1e2;
  7973. WFIFOL(fd,2) = ssd->status.account_id;
  7974. WFIFOL(fd,6) = ssd->status.char_id;
  7975. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7976. WFIFOSET(fd, packet_len(0x1e2));
  7977. }
  7978. */
  7979. /*==========================================
  7980. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7981. *------------------------------------------*/
  7982. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7983. {
  7984. unsigned char buf[256];
  7985. if( len == 0 ) {
  7986. return;
  7987. } else if( len > sizeof(buf)-5 ) {
  7988. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7989. len = sizeof(buf)-5;
  7990. }
  7991. WBUFW(buf, 0) = 0x17f;
  7992. WBUFW(buf, 2) = len + 5;
  7993. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7994. clif_send(buf, WBUFW(buf,2), src, target);
  7995. }
  7996. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7997. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7998. /// 00cd <result>.B
  7999. /// result:
  8000. /// 0 = failure
  8001. /// 1 = success
  8002. void clif_GM_kickack(struct map_session_data *sd, int id)
  8003. {
  8004. int fd;
  8005. nullpo_retv(sd);
  8006. fd = sd->fd;
  8007. WFIFOHEAD(fd,packet_len(0xcd));
  8008. WFIFOW(fd,0) = 0xcd;
  8009. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8010. WFIFOSET(fd, packet_len(0xcd));
  8011. }
  8012. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  8013. {
  8014. nullpo_retv(tsd);
  8015. if (sd == NULL)
  8016. tsd->state.keepshop = true;
  8017. if (session_isActive(tsd->fd))
  8018. clif_authfail_fd(tsd->fd, 15);
  8019. else
  8020. map_quit(tsd);
  8021. if (sd)
  8022. clif_GM_kickack(sd, tsd->status.account_id);
  8023. }
  8024. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8025. /// 014a <result>.L
  8026. /// result:
  8027. /// 0 = "A manner point has been successfully aligned."
  8028. /// 1 = MP_FAILURE_EXHAUST
  8029. /// 2 = MP_FAILURE_ALREADY_GIVING
  8030. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8031. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8032. /// 5 = "You got a good point from %s."
  8033. void clif_manner_message(struct map_session_data* sd, uint32 type)
  8034. {
  8035. int fd;
  8036. nullpo_retv(sd);
  8037. fd = sd->fd;
  8038. WFIFOHEAD(fd,packet_len(0x14a));
  8039. WFIFOW(fd,0) = 0x14a;
  8040. WFIFOL(fd,2) = type;
  8041. WFIFOSET(fd, packet_len(0x14a));
  8042. }
  8043. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8044. /// 014b <type>.B <GM name>.24B
  8045. /// type:
  8046. /// 0 = positive (unmute)
  8047. /// 1 = negative (mute)
  8048. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  8049. {
  8050. int fd;
  8051. nullpo_retv(sd);
  8052. nullpo_retv(tsd);
  8053. fd = tsd->fd;
  8054. WFIFOHEAD(fd,packet_len(0x14b));
  8055. WFIFOW(fd,0) = 0x14b;
  8056. WFIFOB(fd,2) = type;
  8057. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8058. WFIFOSET(fd, packet_len(0x14b));
  8059. }
  8060. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8061. /// 00d1 <type>.B <result>.B
  8062. /// type:
  8063. /// 0 = /ex (deny)
  8064. /// 1 = /in (allow)
  8065. /// result:
  8066. /// 0 = success
  8067. /// 1 = failure
  8068. /// 2 = too many blocks
  8069. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  8070. {
  8071. int fd;
  8072. nullpo_retv(sd);
  8073. fd=sd->fd;
  8074. WFIFOHEAD(fd,packet_len(0xd1));
  8075. WFIFOW(fd,0)=0xd1;
  8076. WFIFOB(fd,2)=type;
  8077. WFIFOB(fd,3)=flag;
  8078. WFIFOSET(fd,packet_len(0xd1));
  8079. }
  8080. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8081. /// 00d2 <type>.B <result>.B
  8082. /// type:
  8083. /// 0 = /exall (deny)
  8084. /// 1 = /inall (allow)
  8085. /// result:
  8086. /// 0 = success
  8087. /// 1 = failure
  8088. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8089. {
  8090. int fd;
  8091. nullpo_retv(sd);
  8092. fd=sd->fd;
  8093. WFIFOHEAD(fd,packet_len(0xd2));
  8094. WFIFOW(fd,0)=0xd2;
  8095. WFIFOB(fd,2)=type;
  8096. WFIFOB(fd,3)=flag;
  8097. WFIFOSET(fd,packet_len(0xd2));
  8098. }
  8099. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8100. /// 07fe <bgm>.24B
  8101. void clif_playBGM( struct map_session_data& sd, const char* name ){
  8102. #if PACKETVER_MAIN_NUM >= 20220504
  8103. struct PACKET_ZC_PLAY_NPC_BGM* p = (struct PACKET_ZC_PLAY_NPC_BGM*)packet_buffer;
  8104. int16 length = (int16)( strlen( name ) + 1 );
  8105. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8106. p->PacketLength = sizeof( *p ) + length;
  8107. p->playType = 0; // TODO: implement, send loop for the time being
  8108. safestrncpy( p->bgm, name, length );
  8109. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8110. #elif PACKETVER >= 20091201
  8111. struct PACKET_ZC_PLAY_NPC_BGM p = {};
  8112. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8113. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8114. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8115. #endif
  8116. }
  8117. /// Plays/stops a wave sound (ZC_SOUND).
  8118. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8119. /// file name:
  8120. /// relative to data\wav
  8121. /// act:
  8122. /// 0 = play (once)
  8123. /// 1 = play (repeat, does not work)
  8124. /// 2 = stops all sound instances of file name (does not work)
  8125. /// term:
  8126. /// unknown purpose, only relevant to act = 1
  8127. /// npc id:
  8128. /// The accustic direction of the sound is determined by the
  8129. /// relative position of the NPC to the player (3D sound).
  8130. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8131. struct PACKET_ZC_SOUND p = {};
  8132. p.PacketType = HEADER_ZC_SOUND;
  8133. safestrncpy( p.name, name, sizeof( p.name ) );
  8134. p.act = type;
  8135. p.term = 0; // TODO: implement
  8136. p.AID = bl.id;
  8137. clif_send( &p, sizeof( p ), &bl, target );
  8138. }
  8139. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8140. /// 01f3 <id>.L <effect id>.L
  8141. /// effect id:
  8142. /// @see doc/effect_list.txt
  8143. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8144. {
  8145. unsigned char buf[24];
  8146. nullpo_retv(bl);
  8147. memset(buf, 0, packet_len(0x1f3));
  8148. WBUFW(buf,0) = 0x1f3;
  8149. WBUFL(buf,2) = bl->id;
  8150. WBUFL(buf,6) = type;
  8151. clif_send(buf, packet_len(0x1f3), bl, target);
  8152. if (disguised(bl)) {
  8153. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8154. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8155. }
  8156. }
  8157. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8158. {
  8159. WFIFOHEAD(fd,10);
  8160. WFIFOW(fd,0) = 0x1f3;
  8161. WFIFOL(fd,2) = bl->id;
  8162. WFIFOL(fd,6) = type;
  8163. WFIFOSET(fd,10);
  8164. }
  8165. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8166. /// 0284 <id>.L <effect id>.L <num data>.L
  8167. /// effect id:
  8168. /// @see doc/effect_list.txt
  8169. /// num data:
  8170. /// effect-dependent value
  8171. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8172. {
  8173. uint8 buf[14];
  8174. WBUFW(buf,0) = 0x284;
  8175. WBUFL(buf,2) = bl->id;
  8176. WBUFL(buf,6) = effect_id;
  8177. WBUFL(buf,10) = num;
  8178. clif_send(buf, packet_len(0x284), bl, target);
  8179. if( disguised(bl) )
  8180. {
  8181. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8182. clif_send(buf, packet_len(0x284), bl, SELF);
  8183. }
  8184. }
  8185. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8186. {
  8187. #if PACKETVER >= 20181002
  8188. nullpo_retv( bl_src );
  8189. nullpo_retv( bl_target );
  8190. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8191. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8192. p.aid = bl_src->id;
  8193. p.effectId = effect;
  8194. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8195. if( disguised(bl_src) )
  8196. {
  8197. p.aid = disguised_bl_id( bl_src->id );
  8198. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8199. }
  8200. #endif
  8201. }
  8202. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8203. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8204. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, struct map_session_data *sd) {
  8205. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8206. uint8 buf[CHAT_SIZE_MAX];
  8207. nullpo_retv(bl);
  8208. if (msg_len > sizeof(buf) - 12) {
  8209. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8210. msg_len = sizeof(buf) - 12;
  8211. }
  8212. if (rgb2bgr)
  8213. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8214. WBUFW(buf,0) = 0x2C1;
  8215. WBUFW(buf,2) = msg_len + 12;
  8216. WBUFL(buf,4) = bl->id;
  8217. WBUFL(buf,8) = color;
  8218. memcpy(WBUFCP(buf,12), msg, msg_len);
  8219. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8220. }
  8221. /**
  8222. * Notifies the client that the storage window is still open
  8223. *
  8224. * Should only be used in cases where the client closed the
  8225. * storage window without server's consent
  8226. */
  8227. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8228. // Notify the client that the storage is open
  8229. if( sd->state.storage_flag == 1 ) {
  8230. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8231. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8232. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8233. }
  8234. // Notify the client that the gstorage is open otherwise it will
  8235. // remain locked forever and nobody will be able to access it
  8236. if( sd->state.storage_flag == 2 ) {
  8237. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8238. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8239. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8240. else {
  8241. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8242. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8243. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8244. }
  8245. }
  8246. // Notify the client that the premium storage is open
  8247. if (sd->state.storage_flag == 3) {
  8248. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8249. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8250. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8251. }
  8252. }
  8253. // refresh the client's screen, getting rid of any effects
  8254. void clif_refresh(struct map_session_data *sd)
  8255. {
  8256. nullpo_retv(sd);
  8257. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8258. clif_inventorylist(sd);
  8259. clif_equipswitch_list(sd);
  8260. if(pc_iscarton(sd)) {
  8261. clif_cartlist(sd);
  8262. clif_updatestatus(sd,SP_CARTINFO);
  8263. }
  8264. clif_updatestatus(sd,SP_WEIGHT);
  8265. clif_updatestatus(sd,SP_MAXWEIGHT);
  8266. clif_updatestatus(sd,SP_STR);
  8267. clif_updatestatus(sd,SP_AGI);
  8268. clif_updatestatus(sd,SP_VIT);
  8269. clif_updatestatus(sd,SP_INT);
  8270. clif_updatestatus(sd,SP_DEX);
  8271. clif_updatestatus(sd,SP_LUK);
  8272. #ifdef RENEWAL
  8273. clif_updatestatus(sd,SP_POW);
  8274. clif_updatestatus(sd,SP_STA);
  8275. clif_updatestatus(sd,SP_WIS);
  8276. clif_updatestatus(sd,SP_SPL);
  8277. clif_updatestatus(sd,SP_CON);
  8278. clif_updatestatus(sd,SP_CRT);
  8279. #endif
  8280. if (sd->spiritball)
  8281. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8282. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8283. clif_millenniumshield_single(sd->fd, sd);
  8284. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8285. clif_spiritcharm_single(sd->fd, sd);
  8286. if (sd->soulball)
  8287. clif_soulball( sd, &sd->bl, SELF );
  8288. if (sd->servantball)
  8289. clif_servantball( *sd, &sd->bl, SELF );
  8290. if (sd->abyssball)
  8291. clif_abyssball( *sd, &sd->bl, SELF );
  8292. if (sd->vd.cloth_color)
  8293. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8294. if (sd->vd.body_style)
  8295. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8296. if(hom_is_active(sd->hd))
  8297. clif_send_homdata(sd,SP_ACK,0);
  8298. if( sd->md ) {
  8299. clif_mercenary_info(sd);
  8300. clif_mercenary_skillblock(sd);
  8301. }
  8302. if( sd->ed )
  8303. clif_elemental_info(sd);
  8304. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8305. clif_weather_check(sd);
  8306. if( sd->chatID )
  8307. chat_leavechat(sd,0);
  8308. if( sd->state.vending )
  8309. clif_openvending(sd, sd->bl.id, sd->vending);
  8310. if( pc_issit(sd) )
  8311. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8312. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8313. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8314. else
  8315. clif_changed_dir(&sd->bl, SELF);
  8316. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8317. //Issue #2143
  8318. //Cancel Trading State
  8319. if (sd->state.trading)
  8320. trade_tradecancel(sd);
  8321. //Cancel Buying/Selling State
  8322. if (sd->state.buyingstore)
  8323. buyingstore_close(sd);
  8324. mail_clear(sd);
  8325. clif_loadConfirm( sd );
  8326. if( disguised(&sd->bl) ) {/* refresh-da */
  8327. short disguise = sd->disguise;
  8328. pc_disguise(sd, 0);
  8329. pc_disguise(sd, disguise);
  8330. }
  8331. clif_refresh_storagewindow(sd);
  8332. }
  8333. /// Updates the object's (bl) name on client.
  8334. /// Used to update when a char leaves a party/guild. [Skotlex]
  8335. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8336. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8337. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8338. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8339. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8340. nullpo_retv( src );
  8341. nullpo_retv( bl );
  8342. switch( bl->type ){
  8343. case BL_PC: {
  8344. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8345. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8346. packet.gid = bl->id;
  8347. map_session_data *sd = (map_session_data *)bl;
  8348. //Requesting your own "shadow" name. [Skotlex]
  8349. if( src == bl && target == SELF && sd->disguise ){
  8350. packet.gid = -bl->id;
  8351. }
  8352. if( sd->fakename[0] ) {
  8353. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8354. clif_send( &packet, sizeof(packet), src, target );
  8355. return;
  8356. }
  8357. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8358. party_data *p = nullptr;
  8359. if( sd->status.party_id ){
  8360. p = party_search( sd->status.party_id );
  8361. }
  8362. // do not display party unless the player is also in a guild
  8363. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8364. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8365. }
  8366. if( sd->guild ){
  8367. int position;
  8368. // Will get the position of the guild the player is in
  8369. position = guild_getposition( sd );
  8370. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8371. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8372. }else if( sd->clan ){
  8373. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8374. }
  8375. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8376. packet.title_id = sd->status.title_id; // Title ID
  8377. #endif
  8378. clif_send(&packet, sizeof(packet), src, target);
  8379. }
  8380. break;
  8381. //[blackhole89]
  8382. case BL_HOM:
  8383. case BL_MER:
  8384. case BL_PET:
  8385. case BL_NPC:
  8386. case BL_ELEM: {
  8387. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8388. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8389. packet.gid = bl->id;
  8390. switch (bl->type) {
  8391. case BL_HOM:
  8392. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8393. break;
  8394. case BL_MER:
  8395. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8396. break;
  8397. case BL_PET:
  8398. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8399. break;
  8400. case BL_NPC:
  8401. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8402. break;
  8403. case BL_ELEM:
  8404. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8405. break;
  8406. }
  8407. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8408. unit_data *ud = unit_bl2ud(bl);
  8409. if (ud != nullptr) {
  8410. memcpy(packet.title, ud->title, NAME_LENGTH);
  8411. packet.groupId = ud->group_id;
  8412. }
  8413. #endif
  8414. clif_send(&packet, sizeof(packet), src, target);
  8415. }
  8416. break;
  8417. case BL_MOB: {
  8418. mob_data *md = (mob_data *)bl;
  8419. if( md->guardian_data && md->guardian_data->guild_id ){
  8420. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8421. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8422. packet.gid = bl->id;
  8423. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8424. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8425. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8426. clif_send(&packet, sizeof(packet), src, target);
  8427. }else if( battle_config.show_mob_info ){
  8428. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8429. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8430. packet.gid = bl->id;
  8431. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8432. char mobhp[50], *str_p = mobhp;
  8433. if( battle_config.show_mob_info&4 ){
  8434. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8435. }
  8436. if( battle_config.show_mob_info&1 ){
  8437. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8438. }
  8439. if( battle_config.show_mob_info&2 ){
  8440. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8441. }
  8442. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8443. if( str_p != mobhp ){
  8444. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8445. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8446. }
  8447. clif_send(&packet, sizeof(packet), src, target);
  8448. } else {
  8449. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8450. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8451. packet.gid = bl->id;
  8452. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8453. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8454. unit_data *ud = unit_bl2ud(bl);
  8455. if (ud != nullptr) {
  8456. memcpy(packet.title, ud->title, NAME_LENGTH);
  8457. packet.groupId = ud->group_id;
  8458. }
  8459. #endif
  8460. clif_send(&packet, sizeof(packet), src, target);
  8461. }
  8462. }
  8463. break;
  8464. case BL_CHAT:
  8465. case BL_SKILL:
  8466. // Newer clients request this, but do not need an answer
  8467. return;
  8468. default:
  8469. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8470. return;
  8471. }
  8472. }
  8473. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8474. /// 01ff <id>.L <x>.W <y>.W
  8475. ///
  8476. /// Visually moves(instant) a character to x,y. The char moves even
  8477. /// when the target cell isn't walkable. If the char is sitting it
  8478. /// stays that way.
  8479. void clif_slide(struct block_list *bl, int x, int y)
  8480. {
  8481. unsigned char buf[10];
  8482. nullpo_retv(bl);
  8483. WBUFW(buf, 0) = 0x01ff;
  8484. WBUFL(buf, 2) = bl->id;
  8485. WBUFW(buf, 6) = x;
  8486. WBUFW(buf, 8) = y;
  8487. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8488. if( disguised(bl) )
  8489. {
  8490. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8491. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8492. }
  8493. }
  8494. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8495. /// 008d <packet len>.W <id>.L <message>.?B
  8496. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8497. {
  8498. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8499. int len_mes = strlen(mes)+1; //Account for \0
  8500. if (len_mes > sizeof(buf)-8) {
  8501. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8502. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8503. }
  8504. // send message to others
  8505. if (flag == AREA) {
  8506. WBUFW(buf,0) = 0x8d;
  8507. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8508. WBUFL(buf,4) = bl->id;
  8509. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8510. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8511. }
  8512. // send back message to the speaker
  8513. if( bl->type == BL_PC ) {
  8514. WBUFW(buf,0) = 0x8e;
  8515. WBUFW(buf, 2) = len_mes + 4;
  8516. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8517. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8518. }
  8519. }
  8520. /*==========================
  8521. * Minimap fix [Kevin]
  8522. * Remove dot from minimap
  8523. *--------------------------*/
  8524. void clif_party_xy_remove(struct map_session_data* sd)
  8525. {
  8526. nullpo_retv(sd);
  8527. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8528. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8529. p.AID = sd->status.account_id;
  8530. p.xPos = -1;
  8531. p.yPos = -1;
  8532. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8533. }
  8534. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8535. /// 0215 <msg id>.L
  8536. /// msg id:
  8537. /// 0x15 = End all negative status (PA_GOSPEL)
  8538. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8539. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8540. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8541. /// 0x19 = All stats +20 (PA_GOSPEL)
  8542. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8543. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8544. /// 0x1e = DEF +25% (PA_GOSPEL)
  8545. /// 0x1f = ATK +100% (PA_GOSPEL)
  8546. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8547. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8548. /// ? = nothing
  8549. void clif_gospel_info(struct map_session_data *sd, int type)
  8550. {
  8551. int fd=sd->fd;
  8552. WFIFOHEAD(fd,packet_len(0x215));
  8553. WFIFOW(fd,0)=0x215;
  8554. WFIFOL(fd,2)=type;
  8555. WFIFOSET(fd, packet_len(0x215));
  8556. }
  8557. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8558. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8559. /// result:
  8560. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8561. /// star:
  8562. /// 0 = Place of the Sun
  8563. /// 1 = Place of the Moon
  8564. /// 2 = Place of the Stars
  8565. /// 1 = Star Gladiator %s's %s: <mapname>
  8566. /// star:
  8567. /// 0 = Place of the Sun
  8568. /// 1 = Place of the Moon
  8569. /// 2 = Place of the Stars
  8570. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8571. /// star:
  8572. /// 0 = Target of the Sun
  8573. /// 1 = Target of the Moon
  8574. /// 2 = Target of the Stars
  8575. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8576. /// star:
  8577. /// 0 = Monster of the Sun
  8578. /// 1 = Monster of the Moon
  8579. /// 2 = Monster of the Stars
  8580. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8581. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8582. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8583. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8584. /// 40 = Target HP : <monster_id used as HP>
  8585. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8586. {
  8587. int fd = sd->fd;
  8588. WFIFOHEAD(fd,packet_len(0x20e));
  8589. WFIFOW(fd,0) = 0x20e;
  8590. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8591. WFIFOL(fd,26) = monster_id;
  8592. WFIFOB(fd,30) = star;
  8593. WFIFOB(fd,31) = result;
  8594. WFIFOSET(fd,packet_len(0x20e));
  8595. }
  8596. /*==========================================
  8597. * Info about Star Glaldiator save map [Komurka]
  8598. * type: 1: Information, 0: Map registered
  8599. *------------------------------------------*/
  8600. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8601. {
  8602. char mapname[MAP_NAME_LENGTH_EXT];
  8603. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8604. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8605. }
  8606. /*==========================================
  8607. * Info about Star Glaldiator hate mob [Komurka]
  8608. * type: 1: Register mob, 0: Information.
  8609. *------------------------------------------*/
  8610. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8611. {
  8612. if( pcdb_checkid(class_) ) {
  8613. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8614. } else if( mobdb_checkid(class_) ) {
  8615. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8616. } else {
  8617. 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);
  8618. }
  8619. }
  8620. /*==========================================
  8621. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8622. *------------------------------------------*/
  8623. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8624. {
  8625. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8626. }
  8627. /*==========================================
  8628. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8629. *------------------------------------------*/
  8630. void clif_feel_hate_reset(struct map_session_data *sd)
  8631. {
  8632. clif_starskill(sd, "", 0, 0, 30);
  8633. }
  8634. /// Send out reply to configuration change
  8635. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8636. /// type: see enum e_config_type
  8637. /// value:
  8638. /// false = disabled
  8639. /// true = enabled
  8640. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8641. int fd;
  8642. nullpo_retv(sd);
  8643. fd = sd->fd;
  8644. WFIFOHEAD(fd, packet_len(0x2d9));
  8645. WFIFOW(fd, 0) = 0x2d9;
  8646. WFIFOL(fd, 2) = type;
  8647. WFIFOL(fd, 6) = enabled;
  8648. WFIFOSET(fd, packet_len(0x2d9));
  8649. }
  8650. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8651. /// 02da <open equip window>.B
  8652. /// open equip window:
  8653. /// 0 = disabled
  8654. /// 1 = enabled
  8655. void clif_equipcheckbox(struct map_session_data* sd)
  8656. {
  8657. int fd;
  8658. nullpo_retv(sd);
  8659. fd = sd->fd;
  8660. WFIFOHEAD(fd, packet_len(0x2da));
  8661. WFIFOW(fd, 0) = 0x2da;
  8662. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8663. WFIFOSET(fd, packet_len(0x2da));
  8664. }
  8665. /// Sends info about a player's equipped items.
  8666. /// 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)
  8667. /// 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)
  8668. /// 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)
  8669. /// 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)
  8670. /// 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)
  8671. /// 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)
  8672. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8673. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8674. nullpo_retv( sd );
  8675. nullpo_retv( tsd );
  8676. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8677. int equip = 0;
  8678. for( int i = 0; i < EQI_MAX; i++ ){
  8679. int k = tsd->equip_index[i];
  8680. if( k >= 0 ){
  8681. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8682. continue;
  8683. }
  8684. if( !tsd->inventory.u.items_inventory[k].equip ){
  8685. continue;
  8686. }
  8687. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8688. continue;
  8689. }
  8690. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8691. }
  8692. }
  8693. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8694. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8695. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8696. p->job = tsd->status.class_;
  8697. p->head = tsd->vd.hair_style;
  8698. p->accessory = tsd->vd.head_bottom;
  8699. p->accessory2 = tsd->vd.head_mid;
  8700. p->accessory3 = tsd->vd.head_top;
  8701. #if PACKETVER >= 20110111
  8702. p->robe = tsd->vd.robe;
  8703. #endif
  8704. p->headpalette = tsd->vd.hair_color;
  8705. p->bodypalette = tsd->vd.cloth_color;
  8706. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8707. p->body2 = tsd->vd.body_style;
  8708. #endif
  8709. p->sex = tsd->vd.sex;
  8710. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8711. #endif
  8712. }
  8713. /// Display msgstringtable.txt string (ZC_MSG).
  8714. /// 0291 <message>.W
  8715. void clif_msg(struct map_session_data* sd, unsigned short id)
  8716. {
  8717. int fd;
  8718. nullpo_retv(sd);
  8719. fd = sd->fd;
  8720. WFIFOHEAD(fd, packet_len(0x291));
  8721. WFIFOW(fd, 0) = 0x291;
  8722. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8723. WFIFOSET(fd, packet_len(0x291));
  8724. }
  8725. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8726. /// 0x7e2 <message>.W <value>.L
  8727. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8728. {
  8729. int fd = sd->fd;
  8730. WFIFOHEAD(fd, packet_len(0x7e2));
  8731. WFIFOW(fd,0) = 0x7e2;
  8732. WFIFOW(fd,2) = id;
  8733. WFIFOL(fd,4) = value;
  8734. WFIFOSET(fd, packet_len(0x7e2));
  8735. }
  8736. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8737. /// 07e6 <skill id>.W <msg id>.L
  8738. ///
  8739. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8740. /// "[SkillName] Message"
  8741. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8742. {
  8743. int fd = sd->fd;
  8744. WFIFOHEAD(fd, packet_len(0x7e6));
  8745. WFIFOW(fd,0) = 0x7e6;
  8746. WFIFOW(fd,2) = skill_id;
  8747. WFIFOL(fd,4) = msg_id;
  8748. WFIFOSET(fd, packet_len(0x7e6));
  8749. }
  8750. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8751. /// 09cd <msg id>.W <color>.L
  8752. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8753. nullpo_retv(sd);
  8754. int fd = sd->fd;
  8755. WFIFOHEAD(fd, packet_len(0x9cd));
  8756. WFIFOW(fd, 0) = 0x9cd;
  8757. WFIFOW(fd, 2) = msg_id;
  8758. WFIFOL(fd, 4) = color;
  8759. WFIFOSET(fd, packet_len(0x9cd));
  8760. }
  8761. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8762. /// Returns true if the packet was parsed successfully.
  8763. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8764. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8765. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8766. const char* seperator = " : ";
  8767. int fd;
  8768. struct s_packet_db* info;
  8769. uint16 packetLength, inputLength;
  8770. const char *input, *name, *message;
  8771. size_t nameLength, messageLength;
  8772. fd = sd->fd;
  8773. info = &packet_db[RFIFOW(fd,0)];
  8774. packetLength = RFIFOW(fd,info->pos[0]);
  8775. input = RFIFOCP(fd,info->pos[1]);
  8776. // basic structure check for the 4-byte header
  8777. if( packetLength < 4 ){
  8778. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8779. return false;
  8780. }else{
  8781. inputLength = packetLength - 4;
  8782. }
  8783. // process <name> part of the packet
  8784. if( whisperFormat ) {
  8785. // name has fixed width
  8786. if( inputLength < NAME_LENGTH + 1 ) {
  8787. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8788. return false;
  8789. }
  8790. name = input;
  8791. // validate name
  8792. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8793. // only restriction is that the name must be zero-terminated
  8794. if( name[nameLength] != '\0' ) {
  8795. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8796. return false;
  8797. }
  8798. message = input + NAME_LENGTH;
  8799. messageLength = inputLength - NAME_LENGTH;
  8800. }else{
  8801. // name and message are separated by ' : '
  8802. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8803. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8804. // check if there's enough data provided
  8805. if( inputLength < nameLength + seperatorLength + 1 ){
  8806. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8807. return false;
  8808. }
  8809. name = input;
  8810. // validate name
  8811. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8812. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8813. {
  8814. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8815. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8816. set_eof(sd->fd); // Just kick them out to correct it.
  8817. return false;
  8818. }
  8819. message = input + nameLength + seperatorLength;
  8820. messageLength = inputLength - nameLength - seperatorLength;
  8821. }
  8822. #if PACKETVER < 20151001
  8823. // the declared length must match real length
  8824. if( messageLength != strnlen(message, messageLength)+1 ) {
  8825. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8826. return false;
  8827. }
  8828. // verify <message> part of the packet
  8829. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8830. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8831. return false;
  8832. }
  8833. #else
  8834. // No zero termination anymore
  8835. messageLength += 1;
  8836. #endif
  8837. // messages mustn't be too long
  8838. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8839. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8840. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8841. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8842. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8843. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8844. return false;
  8845. }
  8846. // If it is not a whisper message, set the name to the fakename of the player
  8847. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8848. strcpy( out_name, sd->fakename );
  8849. }else{
  8850. safestrncpy( out_name, name, nameLength + 1 );
  8851. }
  8852. safestrncpy( out_message, message, messageLength );
  8853. if( whisperFormat ){
  8854. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8855. out_full_message[nameLength] = '\0';
  8856. }else{
  8857. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8858. }
  8859. if( is_atcommand( fd, sd, out_message, 1 ) )
  8860. return false;
  8861. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8862. return false; //no "chatting" while muted.
  8863. if( battle_config.min_chat_delay ) { //[Skotlex]
  8864. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8865. return false;
  8866. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8867. }
  8868. if (battle_config.idletime_option&IDLE_CHAT)
  8869. sd->idletime = last_tick;
  8870. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8871. sd->idletime_hom = last_tick;
  8872. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8873. sd->idletime_mer = last_tick;
  8874. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8875. return true;
  8876. }
  8877. /**
  8878. * Displays a message if the player enters a PK Zone (during pk_mode)
  8879. * @param sd: Player data
  8880. */
  8881. inline void clif_pk_mode_message(struct map_session_data * sd)
  8882. {
  8883. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8884. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8885. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8886. char output[CHAT_SIZE_MAX];
  8887. // 1504: You've entered a PK Zone (safe until level %d).
  8888. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8889. battle_config.pk_min_level);
  8890. clif_showscript(&sd->bl, output, SELF);
  8891. } else {
  8892. // 1503: You've entered a PK Zone.
  8893. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8894. }
  8895. }
  8896. return;
  8897. }
  8898. // ---------------------
  8899. // clif_parse_wanttoconnect
  8900. // ---------------------
  8901. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8902. // error codes:
  8903. // 0 - Success
  8904. // 1 - Unknown packet_ver
  8905. // 2 - Invalid account_id
  8906. // 3 - Invalid char_id
  8907. // 4 - Invalid login_id1 (reserved)
  8908. // 5 - Invalid client_tick (reserved)
  8909. // 6 - Invalid sex
  8910. // Only the first 'invalid' error that appears is used.
  8911. static int clif_parse_WantToConnection_sub(int fd)
  8912. {
  8913. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8914. unsigned short cmd;
  8915. //By default, start searching on the default one.
  8916. cmd = RFIFOW(fd, 0);
  8917. packet_len = RFIFOREST(fd);
  8918. // FIXME: If the packet is not received at once, this will FAIL.
  8919. // Figure out, when it happens, that only part of the packet is
  8920. // received, or fix the function to be able to deal with that
  8921. // case.
  8922. if( packet_len != packet_db[cmd].len )
  8923. return 1; /* wrong length */
  8924. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8925. return 2; /* invalid account_id */
  8926. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8927. return 3; /* invalid char_id */
  8928. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8929. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8930. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8931. return 6; /* invalid sex */
  8932. else
  8933. return 0;
  8934. }
  8935. /// Request to connect to map-server.
  8936. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8937. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8938. /// There are various variants of this packet, some of them have padding between fields.
  8939. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8940. {
  8941. struct block_list* bl;
  8942. struct auth_node* node;
  8943. int cmd, account_id, char_id, login_id1, sex, err;
  8944. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8945. if (sd) {
  8946. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8947. return;
  8948. }
  8949. cmd = RFIFOW(fd, 0);
  8950. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8951. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8952. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8953. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8954. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8955. err = clif_parse_WantToConnection_sub(fd);
  8956. if( err ){ // connection rejected
  8957. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8958. err == 1 ? "." :
  8959. err == 2 ? ", possibly for having an invalid account_id." :
  8960. err == 3 ? ", possibly for having an invalid char_id." :
  8961. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8962. err == 4 ? ", possibly for having an invalid login_id1." :
  8963. err == 5 ? ", possibly for having an invalid client_tick." :
  8964. */
  8965. err == 6 ? ", possibly for having an invalid sex." :
  8966. ". ERROR invalid error code"));
  8967. WFIFOHEAD(fd,packet_len(0x6a));
  8968. WFIFOW(fd,0) = 0x6a;
  8969. WFIFOB(fd,2) = err;
  8970. WFIFOSET(fd,packet_len(0x6a));
  8971. #ifdef DUMP_INVALID_PACKET
  8972. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8973. #endif
  8974. RFIFOSKIP(fd, RFIFOREST(fd));
  8975. set_eof(fd);
  8976. return;
  8977. }
  8978. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8979. clif_authfail_fd(fd,1);// server closed
  8980. return;
  8981. }
  8982. //Check for double login.
  8983. bl = map_id2bl(account_id);
  8984. if(bl && bl->type != BL_PC) {
  8985. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8986. WFIFOHEAD(fd,packet_len(0x6a));
  8987. WFIFOW(fd,0) = 0x6a;
  8988. WFIFOB(fd,2) = 3; // Rejected by server
  8989. WFIFOSET(fd,packet_len(0x6a));
  8990. set_eof(fd);
  8991. return;
  8992. }
  8993. if (bl ||
  8994. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8995. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8996. {
  8997. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8998. return;
  8999. }
  9000. CREATE(sd, TBL_PC, 1);
  9001. sd->fd = fd;
  9002. #ifdef PACKET_OBFUSCATION
  9003. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9004. #endif
  9005. session[fd]->session_data = sd;
  9006. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9007. #if PACKETVER < 20070521
  9008. WFIFOHEAD(fd,4);
  9009. WFIFOL(fd,0) = sd->bl.id;
  9010. WFIFOSET(fd,4);
  9011. #else
  9012. WFIFOHEAD(fd,packet_len(0x283));
  9013. WFIFOW(fd,0) = 0x283;
  9014. WFIFOL(fd,2) = sd->bl.id;
  9015. WFIFOSET(fd,packet_len(0x283));
  9016. #endif
  9017. chrif_authreq(sd,false);
  9018. }
  9019. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9020. /// 007d
  9021. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  9022. {
  9023. bool guild_notice = false;
  9024. if(sd->bl.prev != NULL)
  9025. return;
  9026. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9027. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9028. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9029. sd->state.connect_new = 0;
  9030. return;
  9031. }
  9032. if (sd->state.rewarp) { //Rewarp player.
  9033. sd->state.rewarp = 0;
  9034. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9035. return;
  9036. }
  9037. sd->state.warping = 0;
  9038. // look
  9039. #if PACKETVER < 4
  9040. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9041. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9042. #else
  9043. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9044. #endif
  9045. pc_set_costume_view(sd);
  9046. if(sd->vd.cloth_color)
  9047. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9048. if(sd->vd.body_style)
  9049. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9050. // item
  9051. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9052. pc_checkitem(sd);
  9053. clif_equipswitch_list(sd);
  9054. // cart
  9055. if(pc_iscarton(sd)) {
  9056. clif_cartlist(sd);
  9057. clif_updatestatus(sd,SP_CARTINFO);
  9058. }
  9059. // weight
  9060. clif_updatestatus(sd,SP_WEIGHT);
  9061. clif_updatestatus(sd,SP_MAXWEIGHT);
  9062. // guild
  9063. // (needs to go before clif_spawn() to show guild emblems correctly)
  9064. if(sd->status.guild_id)
  9065. guild_send_memberinfoshort(sd,1);
  9066. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9067. if(battle_config.pc_invincible_time > 0) {
  9068. if(mapdata_flag_gvg(mapdata))
  9069. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9070. else
  9071. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9072. }
  9073. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9074. map_spawnmobs(sd->bl.m);
  9075. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9076. mapdata->users_pvp++;
  9077. }
  9078. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9079. // reset the callshop flag if the player changes map
  9080. sd->state.callshop = 0;
  9081. if(map_addblock(&sd->bl))
  9082. return;
  9083. clif_spawn(&sd->bl);
  9084. // Party
  9085. // (needs to go after clif_spawn() to show hp bars correctly)
  9086. if(sd->status.party_id) {
  9087. party_send_movemap(sd);
  9088. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9089. }
  9090. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9091. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9092. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9093. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9094. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9095. sd->pvp_rank = 0;
  9096. sd->pvp_lastusers = 0;
  9097. sd->pvp_point = 5;
  9098. sd->pvp_won = 0;
  9099. sd->pvp_lost = 0;
  9100. }
  9101. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9102. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9103. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9104. else if (mapdata->flag[MF_GVG_DUNGEON])
  9105. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9106. else if( mapdata_flag_gvg(mapdata) )
  9107. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9108. else
  9109. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9110. // info about nearby objects
  9111. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9112. 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);
  9113. // pet
  9114. if( sd->pd ) {
  9115. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9116. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9117. pet_return_egg( sd, sd->pd );
  9118. } else {
  9119. if(map_addblock(&sd->pd->bl))
  9120. return;
  9121. clif_spawn(&sd->pd->bl);
  9122. clif_send_petdata(sd,sd->pd,0,0);
  9123. clif_send_petstatus(sd);
  9124. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9125. }
  9126. }
  9127. //homunculus [blackhole89]
  9128. if( hom_is_active(sd->hd) ) {
  9129. if(map_addblock(&sd->hd->bl))
  9130. return;
  9131. clif_spawn(&sd->hd->bl);
  9132. clif_send_homdata(sd,SP_ACK,0);
  9133. clif_hominfo(sd,sd->hd,1);
  9134. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9135. clif_homskillinfoblock(sd);
  9136. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9137. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9138. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9139. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9140. }
  9141. if( sd->md ) {
  9142. if(map_addblock(&sd->md->bl))
  9143. return;
  9144. clif_spawn(&sd->md->bl);
  9145. clif_mercenary_info(sd);
  9146. clif_mercenary_skillblock(sd);
  9147. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9148. }
  9149. if( sd->ed ) {
  9150. if (map_addblock(&sd->ed->bl))
  9151. return;
  9152. clif_spawn(&sd->ed->bl);
  9153. clif_elemental_info(sd);
  9154. clif_elemental_updatestatus(sd,SP_HP);
  9155. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9156. clif_elemental_updatestatus(sd,SP_SP);
  9157. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9158. }
  9159. if(sd->state.connect_new) {
  9160. int lv;
  9161. guild_notice = true;
  9162. clif_skillinfoblock(sd);
  9163. clif_hotkeys_send(sd,0);
  9164. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9165. clif_hotkeys_send(sd,1);
  9166. #endif
  9167. clif_updatestatus(sd,SP_BASEEXP);
  9168. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9169. clif_updatestatus(sd,SP_JOBEXP);
  9170. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9171. clif_updatestatus(sd,SP_SKILLPOINT);
  9172. clif_initialstatus(sd);
  9173. if (sd->sc.option&OPTION_FALCON)
  9174. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9175. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9176. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9177. else if (sd->sc.option&OPTION_WUGRIDER)
  9178. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9179. else if (sd->sc.data[SC_ALL_RIDING])
  9180. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9181. if(sd->status.manner < 0)
  9182. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9183. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9184. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9185. if(sd->bl.m == sd->feel_map[0].m
  9186. || sd->bl.m == sd->feel_map[1].m
  9187. || sd->bl.m == sd->feel_map[2].m)
  9188. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9189. }
  9190. if(sd->pd && sd->pd->pet.intimate > 900)
  9191. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9192. if(hom_is_active(sd->hd))
  9193. hom_init_timers(sd->hd);
  9194. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9195. sd->state.night = 1;
  9196. clif_status_load(&sd->bl, EFST_SKE, 1);
  9197. }
  9198. // Notify everyone that this char logged in [Skotlex].
  9199. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9200. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9201. //Login Event
  9202. npc_script_event(sd, NPCE_LOGIN);
  9203. }
  9204. // Set facing direction before check below to update client
  9205. if (battle_config.spawn_direction)
  9206. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9207. } else {
  9208. //For some reason the client "loses" these on warp/map-change.
  9209. clif_updatestatus(sd,SP_STR);
  9210. clif_updatestatus(sd,SP_AGI);
  9211. clif_updatestatus(sd,SP_VIT);
  9212. clif_updatestatus(sd,SP_INT);
  9213. clif_updatestatus(sd,SP_DEX);
  9214. clif_updatestatus(sd,SP_LUK);
  9215. #ifdef RENEWAL
  9216. clif_updatestatus(sd,SP_POW);
  9217. clif_updatestatus(sd,SP_STA);
  9218. clif_updatestatus(sd,SP_WIS);
  9219. clif_updatestatus(sd,SP_SPL);
  9220. clif_updatestatus(sd,SP_CON);
  9221. clif_updatestatus(sd,SP_CRT);
  9222. #endif
  9223. // abort currently running script
  9224. sd->state.using_fake_npc = 0;
  9225. sd->state.menu_or_input = 0;
  9226. sd->npc_menu = 0;
  9227. if(sd->npc_id)
  9228. npc_event_dequeue(sd);
  9229. }
  9230. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9231. clif_partyinvitationstate( *sd );
  9232. #if PACKETVER >= 20070918
  9233. clif_equipcheckbox(sd);
  9234. #endif
  9235. clif_pet_autofeed_status(sd,false);
  9236. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9237. #if PACKETVER >= 20170920
  9238. if( battle_config.homunculus_autofeed_always ){
  9239. // Always send ON or OFF
  9240. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9241. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9242. }else{
  9243. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9244. }
  9245. }else{
  9246. // Only send when enabled
  9247. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9248. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9249. }
  9250. }
  9251. #endif
  9252. clif_reputation_list( *sd );
  9253. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9254. clif_guild_notice(sd); // Displays after VIP
  9255. guild_notice = false; // Do not display it twice
  9256. }
  9257. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9258. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9259. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9260. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9261. }
  9262. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9263. { //Display night.
  9264. if( !sd->state.night )
  9265. {
  9266. sd->state.night = 1;
  9267. clif_status_load(&sd->bl, EFST_SKE, 1);
  9268. }
  9269. }
  9270. else if( sd->state.night )
  9271. { //Clear night display.
  9272. sd->state.night = 0;
  9273. clif_status_load(&sd->bl, EFST_SKE, 0);
  9274. }
  9275. if( mapdata->flag[MF_BATTLEGROUND] )
  9276. {
  9277. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9278. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9279. clif_bg_updatescore_single(sd);
  9280. }
  9281. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9282. {
  9283. char output[128];
  9284. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9285. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9286. }
  9287. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9288. mapdata->hpmeter_visible++;
  9289. sd->state.hpmeter_visible = 1;
  9290. }
  9291. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9292. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9293. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9294. #ifdef VIP_ENABLE
  9295. if (!sd->state.connect_new &&
  9296. !sd->vip.disableshowrate &&
  9297. sd->state.pmap != sd->bl.m &&
  9298. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9299. )
  9300. {
  9301. clif_display_pinfo( *sd );
  9302. }
  9303. #endif
  9304. // Instances do not need their own channels
  9305. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9306. channel_mjoin(sd); //join new map
  9307. clif_pk_mode_message(sd);
  9308. }
  9309. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9310. clif_guild_notice(sd); // Displays at end
  9311. }
  9312. mail_clear(sd);
  9313. /* Guild Aura Init */
  9314. if( sd->guild && sd->state.gmaster_flag ) {
  9315. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9316. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9317. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9318. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9319. }
  9320. if( sd->state.vending ) { /* show we have a vending */
  9321. clif_openvending(sd,sd->bl.id,sd->vending);
  9322. clif_showvendingboard( *sd );
  9323. }
  9324. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9325. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9326. npc_script_event(sd, NPCE_LOADMAP);
  9327. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9328. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9329. if (sd->sc.opt2) //Client loses these on warp.
  9330. clif_changeoption(&sd->bl);
  9331. if ((sd->sc.data[SC_MONSTER_TRANSFORM] || sd->sc.data[SC_ACTIVE_MONSTER_TRANSFORM]) && battle_config.mon_trans_disable_in_gvg && mapdata_flag_gvg2(mapdata)) {
  9332. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9333. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9334. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9335. }
  9336. clif_weather_check(sd);
  9337. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9338. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9339. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9340. else
  9341. sd->areanpc.clear();
  9342. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9343. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9344. pc_setdead(sd);
  9345. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9346. if(pc_isdead(sd))
  9347. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9348. else {
  9349. skill_usave_trigger(sd);
  9350. if (battle_config.spawn_direction)
  9351. clif_changed_dir(&sd->bl, SELF);
  9352. }
  9353. // Trigger skill effects if you appear standing on them
  9354. if(!battle_config.pc_invincible_time)
  9355. skill_unit_move(&sd->bl,gettick(),1);
  9356. pc_show_questinfo_reinit(sd);
  9357. pc_show_questinfo(sd);
  9358. #if PACKETVER >= 20150513
  9359. if( sd->mail.inbox.unread ){
  9360. clif_Mail_new(sd, 0, NULL, NULL);
  9361. }
  9362. #endif
  9363. sd->state.connect_new = 0;
  9364. sd->state.changemap = false;
  9365. }
  9366. /// Server's tick (ZC_NOTIFY_TIME).
  9367. /// 007f <time>.L
  9368. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9369. {
  9370. int fd = sd->fd;
  9371. WFIFOHEAD(fd,packet_len(0x7f));
  9372. WFIFOW(fd,0) = 0x7f;
  9373. WFIFOL(fd,2) = client_tick(time);
  9374. WFIFOSET(fd,packet_len(0x7f));
  9375. }
  9376. /// Request for server's tick.
  9377. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9378. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9379. /// There are various variants of this packet, some of them have padding between fields.
  9380. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9381. {
  9382. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9383. clif_notify_time(sd, gettick());
  9384. }
  9385. /// Sends hotkey bar.
  9386. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9387. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9388. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9389. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9390. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9391. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9392. nullpo_retv( sd );
  9393. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9394. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9395. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9396. if( tab == 0 ){
  9397. p.rotate = sd->status.hotkey_rowshift;
  9398. }else{
  9399. p.rotate = sd->status.hotkey_rowshift2;
  9400. }
  9401. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9402. p.tab = tab;
  9403. #endif
  9404. #endif
  9405. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9406. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9407. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9408. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9409. }
  9410. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9411. #endif
  9412. }
  9413. /// Request to update a position on the hotkey row bar
  9414. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9415. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9416. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9417. if( p->tab == 0 ){
  9418. sd->status.hotkey_rowshift = p->rowshift;
  9419. }else{
  9420. sd->status.hotkey_rowshift2 = p->rowshift;
  9421. }
  9422. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9423. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9424. sd->status.hotkey_rowshift = p->rowshift;
  9425. #endif
  9426. }
  9427. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9428. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9429. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9430. #ifdef HOTKEY_SAVING
  9431. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9432. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9433. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9434. if( idx >= MAX_HOTKEYS_DB ){
  9435. return;
  9436. }
  9437. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9438. sd->status.hotkeys[idx].id = p->hotkey.id;
  9439. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9440. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9441. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9442. const unsigned short idx = p->index;
  9443. if( idx >= MAX_HOTKEYS_DB ){
  9444. return;
  9445. }
  9446. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9447. sd->status.hotkeys[idx].id = p->hotkey.id;
  9448. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9449. #endif
  9450. #endif
  9451. }
  9452. /// Displays cast-like progress bar (ZC_PROGRESS).
  9453. /// 02f0 <color>.L <time>.L
  9454. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9455. {
  9456. int fd = sd->fd;
  9457. WFIFOHEAD(fd,packet_len(0x2f0));
  9458. WFIFOW(fd,0) = 0x2f0;
  9459. WFIFOL(fd,2) = color;
  9460. WFIFOL(fd,6) = second;
  9461. WFIFOSET(fd,packet_len(0x2f0));
  9462. }
  9463. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9464. /// 02f2
  9465. void clif_progressbar_abort(struct map_session_data * sd)
  9466. {
  9467. int fd = sd->fd;
  9468. WFIFOHEAD(fd,packet_len(0x2f2));
  9469. WFIFOW(fd,0) = 0x2f2;
  9470. WFIFOSET(fd,packet_len(0x2f2));
  9471. }
  9472. /// Notification from the client, that the progress bar has reached 100%.
  9473. /// 02f1 (CZ_PROGRESS)
  9474. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9475. // No progressbar active, ignore it
  9476. if( !sd->progressbar.npc_id ){
  9477. return;
  9478. }
  9479. int npc_id = sd->progressbar.npc_id;
  9480. bool closing = false;
  9481. // Check if the progress was canceled
  9482. if( gettick() < sd->progressbar.timeout && sd->st ){
  9483. closing = true;
  9484. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9485. // If a message window was open, offer a close button to the user
  9486. if( sd->st->mes_active ){
  9487. clif_scriptclose( sd, npc_id );
  9488. }
  9489. }
  9490. sd->progressbar.npc_id = 0;
  9491. sd->progressbar.timeout = 0;
  9492. sd->state.workinprogress = WIP_DISABLE_NONE;
  9493. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9494. sd->idletime = last_tick;
  9495. }
  9496. npc_scriptcont(sd, npc_id, closing);
  9497. }
  9498. /// Displays cast-like progress bar on a NPC
  9499. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9500. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9501. #if PACKETVER >= 20130821
  9502. unsigned char buf[14];
  9503. if( nd->progressbar.timeout > 0 ){
  9504. WBUFW(buf,0) = 0x9d1;
  9505. WBUFL(buf,2) = nd->bl.id;
  9506. WBUFL(buf,6) = nd->progressbar.color;
  9507. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9508. if( sd ){
  9509. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9510. }else{
  9511. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9512. }
  9513. }
  9514. #endif
  9515. }
  9516. /// Request to walk to a certain position on the current map.
  9517. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9518. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9519. /// There are various variants of this packet, some of them have padding between fields.
  9520. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9521. {
  9522. short x, y;
  9523. if (pc_isdead(sd)) {
  9524. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9525. return;
  9526. }
  9527. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9528. ; //You CAN walk on this OPT1 value.
  9529. else if (sd->progressbar.npc_id) {
  9530. clif_progressbar_abort(sd);
  9531. return; // First walk attempt cancels the progress bar
  9532. } else if (pc_cant_act(sd))
  9533. return;
  9534. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9535. return;
  9536. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9537. //A move command one cell west is only valid if the target cell is free
  9538. if(battle_config.official_cell_stack_limit > 0
  9539. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9540. return;
  9541. // Cloaking wall check is actually updated when you click to process next movement
  9542. // not when you move each cell. This is official behaviour.
  9543. if (sd->sc.data[SC_CLOAKING])
  9544. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9545. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9546. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9547. pc_delinvincibletimer(sd);
  9548. //Set last idle time... [Skotlex]
  9549. if (battle_config.idletime_option&IDLE_WALK)
  9550. sd->idletime = last_tick;
  9551. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9552. sd->idletime_hom = last_tick;
  9553. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9554. sd->idletime_mer = last_tick;
  9555. unit_walktoxy(&sd->bl, x, y, 4);
  9556. }
  9557. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9558. /// 018b <result>.W
  9559. /// result:
  9560. /// 0 = disconnect (quit)
  9561. /// 1 = cannot disconnect (wait 10 seconds)
  9562. /// ? = ignored
  9563. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9564. {
  9565. int fd = sd->fd;
  9566. WFIFOHEAD(fd,packet_len(0x18b));
  9567. WFIFOW(fd,0) = 0x18b;
  9568. WFIFOW(fd,2) = result;
  9569. WFIFOSET(fd,packet_len(0x18b));
  9570. }
  9571. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9572. /// 018a <type>.W
  9573. /// type:
  9574. /// 0 = quit
  9575. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9576. {
  9577. /* Rovert's prevent logout option fixed [Valaris] */
  9578. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9579. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] && !sd->sc.data[SC_NEWMOON] &&
  9580. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9581. {
  9582. pc_damage_log_clear(sd,0);
  9583. clif_disconnect_ack(sd, 0);
  9584. flush_fifo( fd );
  9585. if( battle_config.drop_connection_on_quit ){
  9586. set_eof( fd );
  9587. }
  9588. } else {
  9589. clif_disconnect_ack(sd, 1);
  9590. }
  9591. }
  9592. /// Requesting unit's name.
  9593. /// 0094 <id>.L (CZ_REQNAME)
  9594. /// 0368 <id>.L (CZ_REQNAME2)
  9595. /// There are various variants of this packet, some of them have padding between fields.
  9596. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9597. {
  9598. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9599. struct block_list* bl;
  9600. //struct status_change *sc;
  9601. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9602. id = sd->bl.id;
  9603. bl = map_id2bl(id);
  9604. if( bl == NULL )
  9605. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9606. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9607. return; // Block namerequests past view range
  9608. // 'see people in GM hide' cheat detection
  9609. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9610. sc = status_get_sc(bl);
  9611. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9612. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9613. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9614. ) {
  9615. char gm_msg[256];
  9616. 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);
  9617. ShowWarning(gm_msg);
  9618. // information is sent to all online GMs
  9619. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9620. return;
  9621. }
  9622. */
  9623. clif_name(&sd->bl,bl,SELF);
  9624. }
  9625. /// Validates and processes global messages
  9626. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9627. /// There are various variants of this packet.
  9628. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9629. {
  9630. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9631. size_t length;
  9632. // validate packet and retrieve name and message
  9633. if( !clif_process_message(sd, false, name, message, output ) )
  9634. return;
  9635. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9636. channel_send(sd->gcbind,sd,message);
  9637. return;
  9638. }
  9639. // send message to others (using the send buffer for temp. storage)
  9640. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9641. length = strlen(output) + 1;
  9642. // send back message to the speaker
  9643. WFIFOHEAD(fd,4+length);
  9644. WFIFOW(fd,0) = 0x8e;
  9645. WFIFOW(fd,2) = (uint16)(4+length);
  9646. safestrncpy(WFIFOCP(fd,4), output, length );
  9647. WFIFOSET(fd, WFIFOW(fd,2));
  9648. #ifdef PCRE_SUPPORT
  9649. // trigger listening npcs
  9650. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9651. #endif
  9652. // Chat logging type 'O' / Global Chat
  9653. 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);
  9654. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9655. }
  9656. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9657. /// Request to warp to a map on given coordinates.
  9658. /// 0140 <map name>.16B <x>.W <y>.W
  9659. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9660. {
  9661. char command[MAP_NAME_LENGTH_EXT+25];
  9662. char* map_name;
  9663. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9664. map_name = RFIFOCP(fd,info->pos[0]);
  9665. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9666. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9667. RFIFOW(fd,info->pos[1]), //x
  9668. RFIFOW(fd,info->pos[2])); //y
  9669. is_atcommand(fd, sd, command, 1);
  9670. }
  9671. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9672. /// 009c <id>.L <head dir>.W <dir>.B
  9673. /// head dir:
  9674. /// 0 = straight
  9675. /// 1 = turned CW
  9676. /// 2 = turned CCW
  9677. /// dir:
  9678. /// 0 = north
  9679. /// 1 = northwest
  9680. /// 2 = west
  9681. /// 3 = southwest
  9682. /// 4 = south
  9683. /// 5 = southeast
  9684. /// 6 = east
  9685. /// 7 = northeast
  9686. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9687. {
  9688. unsigned char buf[64];
  9689. WBUFW(buf,0) = 0x9c;
  9690. WBUFL(buf,2) = bl->id;
  9691. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9692. WBUFB(buf,8) = unit_getdir(bl);
  9693. clif_send(buf, packet_len(0x9c), bl, target);
  9694. if (disguised(bl)) {
  9695. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9696. WBUFW(buf,6) = 0;
  9697. clif_send(buf, packet_len(0x9c), bl, SELF);
  9698. }
  9699. }
  9700. /// Request to change own body and head direction.
  9701. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9702. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9703. /// There are various variants of this packet, some of them have padding between fields.
  9704. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9705. {
  9706. unsigned char headdir, dir;
  9707. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9708. headdir = RFIFOB(fd,info->pos[0]);
  9709. dir = RFIFOB(fd,info->pos[1]);
  9710. pc_setdir(sd, dir, headdir);
  9711. clif_changed_dir(&sd->bl, AREA_WOS);
  9712. }
  9713. /// Request to show an emotion (CZ_REQ_EMOTION).
  9714. /// 00bf <type>.B
  9715. /// type:
  9716. /// @see enum emotion_type
  9717. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9718. {
  9719. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9720. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9721. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9722. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9723. return;
  9724. }
  9725. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9726. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9727. sd->emotionlasttime = time(NULL);
  9728. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9729. return;
  9730. }
  9731. sd->emotionlasttime = time(NULL);
  9732. if (battle_config.idletime_option&IDLE_EMOTION)
  9733. sd->idletime = last_tick;
  9734. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9735. sd->idletime_hom = last_tick;
  9736. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9737. sd->idletime_mer = last_tick;
  9738. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9739. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9740. return;
  9741. }
  9742. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9743. emoticon = rnd()%6+ET_DICE1;
  9744. }
  9745. clif_emotion(&sd->bl, emoticon);
  9746. } else
  9747. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9748. }
  9749. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9750. /// 00c2 <count>.L
  9751. void clif_user_count(struct map_session_data* sd, int count)
  9752. {
  9753. int fd = sd->fd;
  9754. WFIFOHEAD(fd,packet_len(0xc2));
  9755. WFIFOW(fd,0) = 0xc2;
  9756. WFIFOL(fd,2) = count;
  9757. WFIFOSET(fd,packet_len(0xc2));
  9758. }
  9759. /// /w /who (CZ_REQ_USER_COUNT).
  9760. /// Request to display amount of currently connected players.
  9761. /// 00c1
  9762. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9763. {
  9764. clif_user_count(sd, map_getusers());
  9765. }
  9766. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9767. {
  9768. if (pc_isdead(sd)) {
  9769. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9770. return;
  9771. }
  9772. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9773. if (action_type != 0x00 && action_type != 0x07) {
  9774. if (sd->sc.cant.interact)
  9775. return;
  9776. pc_stop_walking(sd, 1);
  9777. }
  9778. pc_stop_attack(sd);
  9779. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9780. target_id = sd->bl.id;
  9781. switch(action_type)
  9782. {
  9783. case 0x00: // once attack
  9784. case 0x07: // continuous attack
  9785. if( pc_cant_act(sd) )
  9786. return;
  9787. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9788. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9789. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9790. return;
  9791. }
  9792. }
  9793. pc_delinvincibletimer(sd);
  9794. if (battle_config.idletime_option&IDLE_ATTACK)
  9795. sd->idletime = last_tick;
  9796. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9797. sd->idletime_hom = last_tick;
  9798. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9799. sd->idletime_mer = last_tick;
  9800. unit_attack(&sd->bl, target_id, action_type != 0);
  9801. break;
  9802. case 0x02: // sitdown
  9803. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9804. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9805. break;
  9806. }
  9807. if(pc_issit(sd)) {
  9808. //Bugged client? Just refresh them.
  9809. clif_sitting(&sd->bl);
  9810. return;
  9811. }
  9812. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9813. break;
  9814. if (sd->sc.count && (
  9815. sd->sc.data[SC_DANCING] ||
  9816. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9817. )) //No sitting during these states either.
  9818. break;
  9819. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9820. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9821. break;
  9822. }
  9823. if (battle_config.idletime_option&IDLE_SIT)
  9824. sd->idletime = last_tick;
  9825. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9826. sd->idletime_hom = last_tick;
  9827. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9828. sd->idletime_mer = last_tick;
  9829. pc_setsit(sd);
  9830. skill_sit(sd, true);
  9831. clif_sitting(&sd->bl);
  9832. break;
  9833. case 0x03: // standup
  9834. if (!pc_issit(sd)) {
  9835. //Bugged client? Just refresh them.
  9836. clif_standing(&sd->bl);
  9837. return;
  9838. }
  9839. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9840. break;
  9841. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9842. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9843. break;
  9844. }
  9845. if (pc_setstand(sd, false)) {
  9846. if (battle_config.idletime_option&IDLE_SIT)
  9847. sd->idletime = last_tick;
  9848. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9849. sd->idletime_hom = last_tick;
  9850. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9851. sd->idletime_mer = last_tick;
  9852. skill_sit(sd, false);
  9853. clif_standing(&sd->bl);
  9854. }
  9855. break;
  9856. }
  9857. }
  9858. /// Request for an action.
  9859. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9860. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9861. /// action:
  9862. /// 0 = attack
  9863. /// 1 = pick up item
  9864. /// 2 = sit down
  9865. /// 3 = stand up
  9866. /// 7 = continous attack
  9867. /// 12 = (touch skill?)
  9868. /// There are various variants of this packet, some of them have padding between fields.
  9869. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9870. {
  9871. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9872. clif_parse_ActionRequest_sub(sd,
  9873. RFIFOB(fd,info->pos[1]),
  9874. RFIFOL(fd,info->pos[0]),
  9875. gettick()
  9876. );
  9877. }
  9878. /// Response to the death/system menu (CZ_RESTART).
  9879. /// 00b2 <type>.B
  9880. /// type:
  9881. /// 0 = restart (respawn)
  9882. /// 1 = char-select (disconnect)
  9883. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9884. {
  9885. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9886. case 0x00:
  9887. pc_respawn(sd,CLR_OUTSIGHT);
  9888. break;
  9889. case 0x01:
  9890. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9891. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] && !sd->sc.data[SC_NEWMOON] &&
  9892. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9893. { //Send to char-server for character selection.
  9894. pc_damage_log_clear(sd,0);
  9895. chrif_charselectreq(sd, session[fd]->client_addr);
  9896. } else {
  9897. clif_disconnect_ack(sd, 1);
  9898. }
  9899. break;
  9900. }
  9901. }
  9902. /// Validates and processes whispered messages (CZ_WHISPER).
  9903. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9904. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9905. {
  9906. struct map_session_data* dstsd;
  9907. int i;
  9908. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9909. // validate packet and retrieve name and message
  9910. if( !clif_process_message( sd, true, target, message, output ) )
  9911. return;
  9912. // Chat logging type 'W' / Whisper
  9913. 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);
  9914. //-------------------------------------------------------//
  9915. // Lordalfa - Paperboy - To whisper NPC commands //
  9916. //-------------------------------------------------------//
  9917. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9918. {
  9919. char* str = target+4; //Skip the NPC: string part.
  9920. struct npc_data* npc;
  9921. if ((npc = npc_name2id(str))) {
  9922. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9923. char *split;
  9924. char event[EVENT_NAME_LENGTH];
  9925. str = message;
  9926. // skip codepage indicator, if detected
  9927. if( str[0] == '|' && strlen(str) >= 4 )
  9928. str += 3;
  9929. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9930. split = strchr(str,'#');
  9931. if( split == NULL ) { // use the remaining string
  9932. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9933. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9934. split_data[i][0] = '\0';
  9935. break;
  9936. }
  9937. *split = '\0';
  9938. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9939. str = split+1;
  9940. }
  9941. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9942. char variablename[CHAT_SIZE_MAX];
  9943. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9944. set_var_str( sd, variablename, split_data[i] );
  9945. }
  9946. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9947. npc_event(sd,event,0); // Calls the NPC label
  9948. return;
  9949. }
  9950. } else if( target[0] == '#' ) {
  9951. struct Channel *channel = NULL;
  9952. char* chname = target;
  9953. channel = channel_name2channel(chname,sd,3);
  9954. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9955. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9956. channel_send(channel,sd,message);
  9957. }
  9958. else if( channel->pass[0] == '\0') { //no pass needed
  9959. if (channel_join(channel,sd)==0)
  9960. channel_send(channel,sd,message); //join success
  9961. }
  9962. else {
  9963. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9964. }
  9965. return;
  9966. }
  9967. }
  9968. // searching destination character
  9969. dstsd = map_nick2sd(target,false);
  9970. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9971. // player is not on this map-server
  9972. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9973. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9974. // and if we ask for 'Test', we must not contact 'test' player
  9975. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9976. intif_wis_message(sd, target, message, strlen(message) + 1);
  9977. return;
  9978. }
  9979. // if player ignores everyone
  9980. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9981. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9982. clif_wis_end(fd, 1); // 1: target character is not logged in
  9983. else
  9984. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9985. return;
  9986. }
  9987. // if player is autotrading
  9988. if (dstsd->state.autotrade == 1){
  9989. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9990. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9991. return;
  9992. }
  9993. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9994. // if player ignores the source character
  9995. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9996. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9997. clif_wis_end(fd, 2); // 2: ignored by target
  9998. return;
  9999. }
  10000. }
  10001. // notify sender of success
  10002. clif_wis_end(fd, 0); // 0: success to send wisper
  10003. // Normal message
  10004. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10005. }
  10006. /// /b /nb (CZ_BROADCAST).
  10007. /// Request to broadcast a message on whole server.
  10008. /// 0099 <packet len>.W <text>.?B 00
  10009. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  10010. char command[CHAT_SIZE_MAX+11];
  10011. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10012. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10013. char* msg = RFIFOCP(fd,info->pos[1]);
  10014. // as the length varies depending on the command used, just block unreasonably long strings
  10015. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10016. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10017. is_atcommand(fd, sd, command, 1);
  10018. }
  10019. /// Request to pick up an item.
  10020. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10021. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10022. /// There are various variants of this packet, some of them have padding between fields.
  10023. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  10024. {
  10025. struct flooritem_data *fitem;
  10026. int map_object_id;
  10027. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10028. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10029. do {
  10030. if (pc_isdead(sd)) {
  10031. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10032. break;
  10033. }
  10034. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10035. break;
  10036. if (pc_cant_act(sd))
  10037. break;
  10038. if (!pc_takeitem(sd, fitem))
  10039. break;
  10040. return;
  10041. } while (0);
  10042. // Client REQUIRES a fail packet or you can no longer pick items.
  10043. clif_additem(sd,0,0,6);
  10044. }
  10045. /// Request to drop an item.
  10046. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10047. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10048. /// There are various variants of this packet, some of them have padding between fields.
  10049. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  10050. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10051. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10052. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10053. for(;;) {
  10054. if (pc_isdead(sd))
  10055. break;
  10056. if (pc_cant_act2(sd) || sd->npc_id)
  10057. break;
  10058. if (sd->sc.cant.drop)
  10059. break;
  10060. if (!pc_dropitem(sd, item_index, item_amount))
  10061. break;
  10062. if (battle_config.idletime_option&IDLE_DROPITEM)
  10063. sd->idletime = last_tick;
  10064. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10065. sd->idletime_hom = last_tick;
  10066. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10067. sd->idletime_mer = last_tick;
  10068. return;
  10069. }
  10070. //Because the client does not like being ignored.
  10071. clif_dropitem(sd, item_index,0);
  10072. }
  10073. /// Request to use an item.
  10074. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10075. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10076. /// There are various variants of this packet, some of them have padding between fields.
  10077. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  10078. {
  10079. int n;
  10080. if (pc_isdead(sd)) {
  10081. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10082. return;
  10083. }
  10084. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10085. clif_msg(sd, WORK_IN_PROGRESS);
  10086. return;
  10087. }
  10088. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10089. if (battle_config.idletime_option&IDLE_USEITEM)
  10090. sd->idletime = last_tick;
  10091. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10092. sd->idletime_hom = last_tick;
  10093. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10094. sd->idletime_mer = last_tick;
  10095. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10096. if(n <0 || n >= MAX_INVENTORY)
  10097. return;
  10098. if (!pc_useitem(sd,n))
  10099. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10100. }
  10101. /// Request to equip an item
  10102. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10103. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10104. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10105. {
  10106. int index;
  10107. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10108. if(pc_isdead(sd)) {
  10109. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10110. return;
  10111. }
  10112. index = RFIFOW(fd,info->pos[0])-2;
  10113. if (index < 0 || index >= MAX_INVENTORY)
  10114. return; //Out of bounds check.
  10115. if(sd->npc_id && !sd->npc_item_flag) {
  10116. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10117. return;
  10118. } else if (sd->state.storage_flag || sd->sc.opt1)
  10119. ; //You can equip/unequip stuff while storage is open/under status changes
  10120. else if (pc_cant_act2(sd))
  10121. return;
  10122. if(!sd->inventory.u.items_inventory[index].identify) {
  10123. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10124. return;
  10125. }
  10126. if(!sd->inventory_data[index])
  10127. return;
  10128. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10129. pet_equipitem(sd,index);
  10130. return;
  10131. }
  10132. if (battle_config.idletime_option&IDLE_USEITEM)
  10133. sd->idletime = last_tick;
  10134. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10135. sd->idletime_hom = last_tick;
  10136. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10137. sd->idletime_mer = last_tick;
  10138. //Client doesn't send the position for ammo.
  10139. if(sd->inventory_data[index]->type == IT_AMMO)
  10140. pc_equipitem(sd,index,EQP_AMMO);
  10141. else {
  10142. int req_pos;
  10143. #if PACKETVER >= 20120925
  10144. req_pos = RFIFOL(fd,info->pos[1]);
  10145. #else
  10146. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10147. #endif
  10148. pc_equipitem(sd,index,req_pos);
  10149. }
  10150. }
  10151. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10152. /// 00ab <index>.W
  10153. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10154. {
  10155. int index;
  10156. if(pc_isdead(sd)) {
  10157. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10158. return;
  10159. }
  10160. if (sd->npc_id && !sd->npc_item_flag) {
  10161. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10162. return;
  10163. } else if (sd->state.storage_flag || sd->sc.opt1)
  10164. ; //You can equip/unequip stuff while storage is open/under status changes
  10165. else if (pc_cant_act2(sd))
  10166. return;
  10167. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10168. if (battle_config.idletime_option&IDLE_USEITEM)
  10169. sd->idletime = last_tick;
  10170. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10171. sd->idletime_hom = last_tick;
  10172. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10173. sd->idletime_mer = last_tick;
  10174. pc_unequipitem(sd,index,1);
  10175. }
  10176. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10177. /// 0090 <id>.L <type>.B
  10178. /// type:
  10179. /// 1 = click
  10180. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10181. {
  10182. struct block_list *bl;
  10183. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10184. if(pc_isdead(sd)) {
  10185. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10186. return;
  10187. }
  10188. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10189. #ifdef RENEWAL
  10190. clif_msg( sd, WORK_IN_PROGRESS );
  10191. #endif
  10192. return;
  10193. }
  10194. if( sd->state.mail_writing )
  10195. return;
  10196. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10197. //type = RFIFOB(fd,info->pos[1]);
  10198. if (!bl) return;
  10199. switch (bl->type) {
  10200. case BL_MOB:
  10201. case BL_PC:
  10202. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10203. break;
  10204. case BL_NPC:
  10205. #ifdef RENEWAL
  10206. 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
  10207. clif_msg(sd, WORK_IN_PROGRESS);
  10208. break;
  10209. }
  10210. #endif
  10211. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10212. struct npc_data* nd = (struct npc_data*)bl;
  10213. // Progressbar is running
  10214. if( nd->progressbar.timeout > 0 ){
  10215. return;
  10216. }
  10217. npc_click(sd,nd);
  10218. }
  10219. break;
  10220. }
  10221. }
  10222. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10223. /// 00c5 <id>.L <type>.B
  10224. /// type:
  10225. /// 0 = buy
  10226. /// 1 = sell
  10227. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10228. {
  10229. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10230. if (sd->state.trading)
  10231. return;
  10232. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10233. }
  10234. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10235. /// 00ca <result>.B
  10236. /// result:
  10237. /// 0 = "The deal has successfully completed."
  10238. /// 1 = "You do not have enough zeny."
  10239. /// 2 = "You are over your Weight Limit."
  10240. /// 3 = "Out of the maximum capacity, you have too many items."
  10241. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10242. /// 10 = "Props open-air store sales will be traded in RODEX"
  10243. /// 11 = "The exchange failed."
  10244. /// 12 = "The exchange was well done."
  10245. /// 13 = "The item is already sold and out of stock."
  10246. /// 14 = "There is not enough goods to exchange."
  10247. void clif_npc_buy_result( struct map_session_data* sd, e_purchase_result result ){
  10248. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10249. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10250. p.result = (uint8)result;
  10251. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10252. }
  10253. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10254. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10255. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10256. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10257. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10258. e_purchase_result result;
  10259. if( sd->state.trading || !sd->npc_shopid )
  10260. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10261. else{
  10262. std::vector<s_npc_buy_list> items = {};
  10263. items.reserve( n );
  10264. for( uint16 i = 0; i < n; i++ ){
  10265. s_npc_buy_list item = {};
  10266. item.nameid = p->items[i].itemId;
  10267. item.qty = p->items[i].amount;
  10268. items.push_back( item );
  10269. }
  10270. result = npc_buylist( sd, items );
  10271. }
  10272. sd->npc_shopid = 0; //Clear shop data.
  10273. clif_npc_buy_result(sd, result);
  10274. }
  10275. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10276. /// 00cb <result>.B
  10277. /// result:
  10278. /// 0 = "The deal has successfully completed."
  10279. /// 1 = "The deal has failed."
  10280. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10281. {
  10282. int fd = sd->fd;
  10283. WFIFOHEAD(fd,packet_len(0xcb));
  10284. WFIFOW(fd,0) = 0xcb;
  10285. WFIFOB(fd,2) = result;
  10286. WFIFOSET(fd,packet_len(0xcb));
  10287. }
  10288. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10289. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10290. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10291. {
  10292. int fail=0,n;
  10293. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10294. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10295. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10296. if (sd->state.trading || !sd->npc_shopid)
  10297. fail = 1;
  10298. else
  10299. fail = npc_selllist(sd, n, p->sellList);
  10300. sd->npc_shopid = 0; //Clear shop data.
  10301. clif_npc_sell_result(sd, fail);
  10302. }
  10303. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10304. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10305. /// type:
  10306. /// 0 = private
  10307. /// 1 = public
  10308. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10309. {
  10310. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10311. int len = RFIFOW(fd,info->pos[0])-15;
  10312. int limit = RFIFOW(fd,info->pos[1]);
  10313. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10314. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10315. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10316. char s_password[CHATROOM_PASS_SIZE];
  10317. char s_title[CHATROOM_TITLE_SIZE];
  10318. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10319. return;
  10320. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10321. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10322. return;
  10323. }
  10324. if( npc_isnear(&sd->bl) ) {
  10325. // uncomment to send msg_txt.
  10326. //char output[150];
  10327. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10328. //clif_displaymessage(sd->fd, output);
  10329. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10330. return;
  10331. }
  10332. if( len <= 0 )
  10333. return; // invalid input
  10334. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10335. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10336. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10337. }
  10338. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10339. /// 00d9 <chat ID>.L <passwd>.8B
  10340. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10341. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10342. int chatid = RFIFOL(fd,info->pos[0]);
  10343. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10344. chat_joinchat(sd,chatid,password);
  10345. }
  10346. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10347. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10348. /// type:
  10349. /// 0 = private
  10350. /// 1 = public
  10351. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10352. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10353. int len = RFIFOW(fd,info->pos[0])-15;
  10354. int limit = RFIFOW(fd,info->pos[1]);
  10355. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10356. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10357. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10358. char s_password[CHATROOM_PASS_SIZE];
  10359. char s_title[CHATROOM_TITLE_SIZE];
  10360. if( len <= 0 )
  10361. return; // invalid input
  10362. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10363. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10364. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10365. }
  10366. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10367. /// 00e0 <role>.L <nick>.24B
  10368. /// role:
  10369. /// 0 = owner
  10370. /// 1 = normal
  10371. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10372. {
  10373. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10374. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10375. }
  10376. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10377. /// 00e2 <name>.24B
  10378. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10379. {
  10380. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10381. }
  10382. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10383. /// 00e3
  10384. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10385. {
  10386. chat_leavechat(sd,0);
  10387. }
  10388. //Handles notifying asker and rejecter of what has just ocurred.
  10389. //Type is used to determine the correct msg_txt to use:
  10390. //0:
  10391. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10392. {
  10393. const char* msg;
  10394. char output[256];
  10395. // Your request has been rejected by autoreject option.
  10396. msg = msg_txt(sd,392);
  10397. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10398. //Notice that a request was rejected.
  10399. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10400. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10401. }
  10402. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10403. /// 00e4 <account id>.L
  10404. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10405. {
  10406. struct map_session_data *t_sd;
  10407. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10408. if(!sd->chatID && pc_cant_act(sd))
  10409. return; //You can trade while in a chatroom.
  10410. if(t_sd){
  10411. // @noask [LuzZza]
  10412. if(t_sd->state.noask) {
  10413. clif_noask_sub(sd, t_sd, 0);
  10414. return;
  10415. }
  10416. if (t_sd->state.mail_writing) {
  10417. int old = sd->trade_partner;
  10418. // Fake trading
  10419. sd->trade_partner = t_sd->status.account_id;
  10420. clif_tradestart(sd, 5);
  10421. // Restore old state
  10422. sd->trade_partner = old;
  10423. return;
  10424. }
  10425. }
  10426. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10427. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10428. return;
  10429. }
  10430. trade_traderequest(sd,t_sd);
  10431. }
  10432. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10433. /// 00e6 <result>.B
  10434. /// result:
  10435. /// 3 = accepted
  10436. /// 4 = rejected
  10437. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10438. {
  10439. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10440. }
  10441. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10442. /// 00e8 <index>.W <amount>.L
  10443. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10444. {
  10445. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10446. short index = RFIFOW(fd,info->pos[0]);
  10447. int amount = RFIFOL(fd,info->pos[1]);
  10448. if( index == 0 )
  10449. trade_tradeaddzeny(sd, amount);
  10450. else
  10451. trade_tradeadditem(sd, server_index(index), (short)amount);
  10452. }
  10453. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10454. /// 00eb
  10455. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10456. {
  10457. trade_tradeok(sd);
  10458. }
  10459. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10460. /// 00ed
  10461. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10462. {
  10463. trade_tradecancel(sd);
  10464. }
  10465. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10466. /// 00ef
  10467. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10468. {
  10469. trade_tradecommit(sd);
  10470. }
  10471. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10472. /// 0118
  10473. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10474. {
  10475. pc_stop_attack(sd);
  10476. if (sd) sd->ud.state.attack_continue = 0;
  10477. }
  10478. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10479. /// 0126 <index>.W <amount>.L
  10480. void clif_parse_PutItemToCart( int fd, struct map_session_data *sd ){
  10481. if (pc_istrading(sd))
  10482. return;
  10483. if (!pc_iscarton(sd))
  10484. return;
  10485. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10486. return;
  10487. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10488. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10489. }
  10490. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10491. /// 0127 <index>.W <amount>.L
  10492. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10493. {
  10494. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10495. if (!pc_iscarton(sd))
  10496. return;
  10497. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10498. return;
  10499. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10500. }
  10501. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10502. /// 012a
  10503. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10504. {
  10505. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10506. #ifdef NEW_CARTS
  10507. && sd->sc.data[SC_PUSH_CART] )
  10508. pc_setcart(sd,0);
  10509. #else
  10510. )
  10511. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10512. #endif
  10513. else // priority to remove this option before we can clear cart
  10514. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10515. }
  10516. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10517. /// 097f <Length>.W <identity>.L <type>.B
  10518. void clif_SelectCart(struct map_session_data *sd) {
  10519. #if PACKETVER >= 20150826
  10520. int i = 0, carts = 3;
  10521. int fd = sd->fd;
  10522. WFIFOHEAD(fd,8 + carts);
  10523. WFIFOW(fd,0) = 0x97f;
  10524. WFIFOW(fd,2) = 8 + carts;
  10525. WFIFOL(fd,4) = sd->status.account_id;
  10526. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10527. for( i = 0; i < carts; i++ ) {
  10528. WFIFOB(fd,8 + i) = 10 + i;
  10529. }
  10530. WFIFOSET(fd,8 + carts);
  10531. #endif
  10532. }
  10533. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10534. /// 0980 <identity>.L <type>.B
  10535. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10536. #if PACKETVER >= 20150826
  10537. int type;
  10538. // Check identity
  10539. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10540. return;
  10541. type = (int)RFIFOB(fd,6);
  10542. // Check type
  10543. if( type < 10 || type > 12 )
  10544. return;
  10545. pc_setcart(sd, type);
  10546. #endif
  10547. }
  10548. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10549. /// 01af <num>.W
  10550. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10551. {// TODO: State tracking?
  10552. int type;
  10553. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10554. return;
  10555. #ifdef RENEWAL
  10556. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10557. clif_msg(sd, WORK_IN_PROGRESS);
  10558. return;
  10559. }
  10560. #endif
  10561. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10562. if(
  10563. #ifdef NEW_CARTS
  10564. #if PACKETVER >= 20191106
  10565. (type == 13 && sd->status.base_level > 100) ||
  10566. #endif
  10567. (type == 9 && sd->status.base_level > 130) ||
  10568. (type == 8 && sd->status.base_level > 120) ||
  10569. (type == 7 && sd->status.base_level > 110) ||
  10570. (type == 6 && sd->status.base_level > 100) ||
  10571. #endif
  10572. (type == 5 && sd->status.base_level > 90) ||
  10573. (type == 4 && sd->status.base_level > 80) ||
  10574. (type == 3 && sd->status.base_level > 65) ||
  10575. (type == 2 && sd->status.base_level > 40) ||
  10576. (type == 1))
  10577. pc_setcart(sd, type);
  10578. }
  10579. /// Request to increase status (CZ_STATUS_CHANGE).
  10580. /// 00bb <status id>.W <amount>.B
  10581. /// status id:
  10582. /// SP_STR ~ SP_LUK
  10583. /// amount:
  10584. /// Old clients always send 1 for this, even when using /str+ and the like.
  10585. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10586. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10587. {
  10588. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10589. if( increase_amount < 0 ) {
  10590. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10591. fd, increase_amount);
  10592. }
  10593. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10594. }
  10595. /// Request to increase trait status.
  10596. /// 0b24 <status id>.W <amount>.W
  10597. /// status id:
  10598. /// SP_POW ~ SP_CON
  10599. /// amount:
  10600. /// The amount to increase the trait status
  10601. void clif_parse_traitstatus_up( int fd, struct map_session_data *sd ){
  10602. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10603. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10604. if( p->amount < 0 ){
  10605. 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 );
  10606. return;
  10607. }
  10608. pc_traitstatusup( sd, p->type, p->amount );
  10609. #endif
  10610. }
  10611. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10612. /// 0112 <skill id>.W
  10613. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10614. {
  10615. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10616. }
  10617. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10618. {
  10619. int lv;
  10620. if( !hd )
  10621. return;
  10622. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10623. clif_emotion(&hd->bl, ET_THINK);
  10624. return;
  10625. }
  10626. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10627. target_id = hd->bl.id;
  10628. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10629. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10630. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10631. clif_emotion(&hd->bl, ET_THINK);
  10632. if (hd->master)
  10633. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10634. return;
  10635. }
  10636. lv = hom_checkskill(hd, skill_id);
  10637. if( skill_lv > lv )
  10638. skill_lv = lv;
  10639. if( skill_lv )
  10640. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10641. }
  10642. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10643. {
  10644. int lv;
  10645. if( !hd )
  10646. return;
  10647. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10648. clif_emotion(&hd->bl, ET_THINK);
  10649. return;
  10650. }
  10651. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10652. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10653. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10654. clif_emotion(&hd->bl, ET_THINK);
  10655. if (hd->master)
  10656. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10657. return;
  10658. }
  10659. #ifdef RENEWAL
  10660. if (hd->sc.data[SC_BASILICA_CELL])
  10661. #else
  10662. if (hd->sc.data[SC_BASILICA])
  10663. #endif
  10664. return;
  10665. lv = hom_checkskill(hd, skill_id);
  10666. if( skill_lv > lv )
  10667. skill_lv = lv;
  10668. if( skill_lv )
  10669. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10670. }
  10671. static void clif_parse_UseSkillToId_mercenary(s_mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10672. {
  10673. int lv;
  10674. if( !md )
  10675. return;
  10676. if( skill_isNotOk_mercenary(skill_id, md) )
  10677. return;
  10678. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10679. target_id = md->bl.id;
  10680. if( md->ud.skilltimer != INVALID_TIMER )
  10681. {
  10682. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10683. }
  10684. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10685. return;
  10686. lv = mercenary_checkskill(md, skill_id);
  10687. if( skill_lv > lv )
  10688. skill_lv = lv;
  10689. if( skill_lv )
  10690. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10691. }
  10692. static void clif_parse_UseSkillToPos_mercenary(s_mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10693. {
  10694. int lv;
  10695. if( !md )
  10696. return;
  10697. if( skill_isNotOk_mercenary(skill_id, md) )
  10698. return;
  10699. if( md->ud.skilltimer != INVALID_TIMER )
  10700. return;
  10701. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10702. {
  10703. if (md->master)
  10704. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10705. return;
  10706. }
  10707. #ifdef RENEWAL
  10708. if (md->sc.data[SC_BASILICA_CELL])
  10709. #else
  10710. if (md->sc.data[SC_BASILICA])
  10711. #endif
  10712. return;
  10713. lv = mercenary_checkskill(md, skill_id);
  10714. if( skill_lv > lv )
  10715. skill_lv = lv;
  10716. if( skill_lv )
  10717. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10718. }
  10719. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10720. t_tick tick = gettick();
  10721. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10722. int inf = skill_get_inf(skill_id);
  10723. if (inf&INF_GROUND_SKILL || !inf)
  10724. return; //Using a ground/passive skill on a target? WRONG.
  10725. if (sd->state.block_action & PCBLOCK_SKILL) {
  10726. clif_msg(sd, WORK_IN_PROGRESS);
  10727. return;
  10728. }
  10729. if( SKILL_CHK_HOMUN(skill_id) ) {
  10730. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10731. return;
  10732. }
  10733. if( SKILL_CHK_MERC(skill_id) ) {
  10734. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10735. return;
  10736. }
  10737. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10738. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10739. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10740. sd->idletime = last_tick;
  10741. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10742. sd->idletime_hom = last_tick;
  10743. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10744. sd->idletime_mer = last_tick;
  10745. if( sd->npc_id ){
  10746. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10747. #ifdef RENEWAL
  10748. clif_msg( sd, WORK_IN_PROGRESS );
  10749. #endif
  10750. return;
  10751. }
  10752. }
  10753. if ((pc_cant_act2(sd) || sd->chatID) &&
  10754. skill_id != RK_REFRESH &&
  10755. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10756. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10757. return;
  10758. if( pc_issit(sd) )
  10759. return;
  10760. if( skill_isNotOk(skill_id, sd) )
  10761. return;
  10762. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10763. target_id = sd->bl.id; // never trust the client
  10764. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10765. target_id = sd->bl.id;
  10766. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10767. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10768. return;
  10769. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10770. if( sd->skillitem != skill_id ) {
  10771. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10772. return;
  10773. }
  10774. }
  10775. if( sd->sc.option&OPTION_COSTUME )
  10776. return;
  10777. #ifndef RENEWAL
  10778. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10779. return; // On basilica only caster can use Basilica again to stop it.
  10780. #endif
  10781. if( sd->menuskill_id ) {
  10782. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10783. clif_menuskill_clear(sd); //Cancel pet capture.
  10784. }else if( sd->menuskill_id == SG_FEEL ){
  10785. clif_menuskill_clear( sd ); // Cancel selection
  10786. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10787. return; //Can't use skills while a menu is open.
  10788. }
  10789. if( sd->skillitem == skill_id ) {
  10790. if( skill_lv != sd->skillitemlv )
  10791. skill_lv = sd->skillitemlv;
  10792. if( !(inf&INF_SELF_SKILL) )
  10793. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10794. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10795. return;
  10796. }
  10797. sd->skillitem = sd->skillitemlv = 0;
  10798. if( SKILL_CHK_GUILD(skill_id) ) {
  10799. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10800. skill_lv = guild_checkskill(sd->guild, skill_id);
  10801. else
  10802. skill_lv = 0;
  10803. } else {
  10804. if( skill_id != ALL_EQSWITCH ){
  10805. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10806. }
  10807. }
  10808. pc_delinvincibletimer(sd);
  10809. if( skill_lv )
  10810. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10811. }
  10812. /// Request to use a targeted skill.
  10813. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10814. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10815. /// There are various variants of this packet, some of them have padding between fields.
  10816. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10817. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10818. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10819. }
  10820. /*==========================================
  10821. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10822. *------------------------------------------*/
  10823. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10824. {
  10825. t_tick tick = gettick();
  10826. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10827. return; //Using a target skill on the ground? WRONG.
  10828. if (sd->state.block_action & PCBLOCK_SKILL) {
  10829. clif_msg(sd, WORK_IN_PROGRESS);
  10830. return;
  10831. }
  10832. if( SKILL_CHK_HOMUN(skill_id) ) {
  10833. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10834. return;
  10835. }
  10836. if( SKILL_CHK_MERC(skill_id) ) {
  10837. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10838. return;
  10839. }
  10840. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10841. #ifdef RENEWAL
  10842. clif_msg( sd, WORK_IN_PROGRESS );
  10843. #endif
  10844. return;
  10845. }
  10846. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10847. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10848. sd->idletime = last_tick;
  10849. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10850. sd->idletime_hom = last_tick;
  10851. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10852. sd->idletime_mer = last_tick;
  10853. if( skill_isNotOk(skill_id, sd) )
  10854. return;
  10855. if( skillmoreinfo != -1 ) {
  10856. if( pc_issit(sd) ) {
  10857. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10858. return;
  10859. }
  10860. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10861. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10862. }
  10863. if( sd->ud.skilltimer != INVALID_TIMER )
  10864. return;
  10865. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10866. if( sd->skillitem != skill_id ) {
  10867. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10868. return;
  10869. }
  10870. }
  10871. if( sd->sc.option&OPTION_COSTUME )
  10872. return;
  10873. #ifndef RENEWAL
  10874. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10875. return; // On basilica only caster can use Basilica again to stop it.
  10876. #endif
  10877. if( sd->menuskill_id ) {
  10878. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10879. clif_menuskill_clear(sd); //Cancel pet capture.
  10880. }else if( sd->menuskill_id == SG_FEEL ){
  10881. clif_menuskill_clear( sd ); // Cancel selection
  10882. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10883. return; //Can't use skills while a menu is open.
  10884. }
  10885. pc_delinvincibletimer(sd);
  10886. if( sd->skillitem == skill_id ) {
  10887. if( skill_lv != sd->skillitemlv )
  10888. skill_lv = sd->skillitemlv;
  10889. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10890. } else {
  10891. int lv;
  10892. sd->skillitem = sd->skillitemlv = 0;
  10893. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10894. if( skill_lv > lv )
  10895. skill_lv = lv;
  10896. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10897. }
  10898. }
  10899. }
  10900. /// Request to use a ground skill.
  10901. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10902. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10903. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10904. /// There are various variants of this packet, some of them have padding between fields.
  10905. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10906. {
  10907. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10908. if (pc_cant_act(sd))
  10909. return;
  10910. if (pc_issit(sd))
  10911. return;
  10912. clif_parse_UseSkillToPosSub(fd, sd,
  10913. RFIFOW(fd,info->pos[0]), //skill lv
  10914. RFIFOW(fd,info->pos[1]), //skill num
  10915. RFIFOW(fd,info->pos[2]), //pos x
  10916. RFIFOW(fd,info->pos[3]), //pos y
  10917. // TODO: find out what this is intended to do
  10918. //RFIFOB(fd, info->pos[4])
  10919. -1 //Skill more info.
  10920. );
  10921. }
  10922. /// Request to use a ground skill with text.
  10923. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10924. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10925. /// There are various variants of this packet, some of them have padding between fields.
  10926. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10927. {
  10928. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10929. if (pc_cant_act(sd))
  10930. return;
  10931. if (pc_issit(sd))
  10932. return;
  10933. clif_parse_UseSkillToPosSub(fd, sd,
  10934. RFIFOW(fd,info->pos[0]), //Skill lv
  10935. RFIFOW(fd,info->pos[1]), //Skill num
  10936. RFIFOW(fd,info->pos[2]), //pos x
  10937. RFIFOW(fd,info->pos[3]), //pos y
  10938. info->pos[4] //skill more info
  10939. );
  10940. }
  10941. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10942. /// 011b <skill id>.W <map name>.16B
  10943. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10944. {
  10945. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10946. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10947. char map_name[MAP_NAME_LENGTH];
  10948. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10949. sd->state.workinprogress = WIP_DISABLE_NONE;
  10950. if(skill_id != sd->menuskill_id)
  10951. return;
  10952. //It is possible to use teleport with the storage window open bugreport:8027
  10953. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10954. clif_menuskill_clear(sd);
  10955. return;
  10956. }
  10957. pc_delinvincibletimer(sd);
  10958. skill_castend_map(sd,skill_id,map_name);
  10959. }
  10960. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10961. /// 011d
  10962. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10963. {
  10964. if (!pc_isdead(sd))
  10965. pc_memo(sd,-1);
  10966. }
  10967. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10968. /// 018e <name id>.W { <material id>.W }*3
  10969. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10970. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10971. switch( sd->menuskill_id ) {
  10972. case -1:
  10973. case AM_PHARMACY:
  10974. case RK_RUNEMASTERY:
  10975. case GC_RESEARCHNEWPOISON:
  10976. break;
  10977. default:
  10978. return;
  10979. }
  10980. if (pc_istrading(sd)) {
  10981. //Make it fail to avoid shop exploits where you sell something different than you see.
  10982. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10983. clif_menuskill_clear(sd);
  10984. return;
  10985. }
  10986. int produce_idx;
  10987. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10988. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10989. clif_menuskill_clear(sd);
  10990. }
  10991. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10992. /// 025b <mk type>.W <name id>.W
  10993. /// mk type:
  10994. /// 1 = cooking
  10995. /// 2 = arrow
  10996. /// 3 = elemental
  10997. /// 4 = GN_MIX_COOKING
  10998. /// 5 = GN_MAKEBOMB
  10999. /// 6 = GN_S_PHARMACY
  11000. /// 7 = MT_M_MACHINE - Unconfirmed
  11001. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11002. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  11003. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11004. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11005. short food_idx = -1;
  11006. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11007. return;
  11008. if (pc_istrading(sd)) {
  11009. //Make it fail to avoid shop exploits where you sell something different than you see.
  11010. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11011. clif_menuskill_clear(sd);
  11012. return;
  11013. }
  11014. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11015. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11016. clif_menuskill_clear(sd);
  11017. }
  11018. /// Answer to repair weapon item selection dialog
  11019. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11020. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11021. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  11022. // Hercules has wrong date -> use correct one here
  11023. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11024. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11025. #else
  11026. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11027. #endif
  11028. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11029. return;
  11030. if (pc_istrading(sd)) {
  11031. //Make it fail to avoid shop exploits where you sell something different than you see.
  11032. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11033. clif_menuskill_clear(sd);
  11034. return;
  11035. }
  11036. skill_repairweapon( sd, p->item.index );
  11037. clif_menuskill_clear(sd);
  11038. }
  11039. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11040. /// 0222 <index>.L
  11041. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  11042. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11043. return;
  11044. if (pc_istrading(sd)) {
  11045. //Make it fail to avoid shop exploits where you sell something different than you see.
  11046. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11047. clif_menuskill_clear(sd);
  11048. return;
  11049. }
  11050. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11051. clif_menuskill_clear(sd);
  11052. }
  11053. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11054. /// 00b8 <npc id>.L <choice>.B
  11055. /// choice:
  11056. /// 1~254 = menu item
  11057. /// 255 = cancel
  11058. /// NOTE: If there were more than 254 items in the list, choice
  11059. /// overflows to choice%256.
  11060. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  11061. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11062. int npc_id = RFIFOL(fd,info->pos[0]);
  11063. uint8 select = RFIFOB(fd,info->pos[1]);
  11064. #ifdef SECURE_NPCTIMEOUT
  11065. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11066. return;
  11067. #endif
  11068. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11069. TBL_NPC* nd = map_id2nd(npc_id);
  11070. 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);
  11071. clif_GM_kick(NULL,sd);
  11072. return;
  11073. }
  11074. sd->npc_menu = select;
  11075. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11076. sd->idletime = last_tick;
  11077. }
  11078. npc_scriptcont(sd,npc_id, false);
  11079. }
  11080. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11081. /// 00b9 <npc id>.L
  11082. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  11083. {
  11084. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11085. sd->idletime = last_tick;
  11086. }
  11087. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11088. }
  11089. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11090. /// 0143 <npc id>.L <value>.L
  11091. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  11092. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11093. int npcid = RFIFOL(fd,info->pos[0]);
  11094. int amount = (int)RFIFOL(fd,info->pos[1]);
  11095. sd->npc_amount = amount;
  11096. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11097. sd->idletime = last_tick;
  11098. }
  11099. npc_scriptcont(sd, npcid, false);
  11100. }
  11101. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11102. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11103. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  11104. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11105. int message_len = RFIFOW(fd,info->pos[0])-8;
  11106. int npcid = RFIFOL(fd,info->pos[1]);
  11107. const char* message = RFIFOCP(fd,info->pos[2]);
  11108. if( message_len <= 0 )
  11109. return; // invalid input
  11110. #if PACKETVER >= 20151001
  11111. message_len++;
  11112. #endif
  11113. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11114. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11115. sd->idletime = last_tick;
  11116. }
  11117. npc_scriptcont(sd, npcid, false);
  11118. }
  11119. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11120. /// 0146 <npc id>.L
  11121. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11122. {
  11123. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11124. return;
  11125. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11126. sd->idletime = last_tick;
  11127. }
  11128. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11129. }
  11130. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11131. /// 0178 <index>.W
  11132. /// index:
  11133. /// -1 = cancel
  11134. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11135. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11136. if (sd->menuskill_id != MC_IDENTIFY)
  11137. return;
  11138. // Ignore the request
  11139. // - Invalid item index
  11140. // - Invalid item ID or item doesn't exist
  11141. // - Item is already identified
  11142. if (idx < 0 || idx >= MAX_INVENTORY ||
  11143. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11144. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11145. sd->state.workinprogress = WIP_DISABLE_NONE;
  11146. clif_menuskill_clear(sd);
  11147. return;
  11148. }
  11149. skill_identify(sd, idx);
  11150. clif_menuskill_clear(sd);
  11151. }
  11152. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11153. /// 01ae <name id>.W
  11154. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11155. if (pc_istrading(sd)) {
  11156. //Make it fail to avoid shop exploits where you sell something different than you see.
  11157. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11158. clif_menuskill_clear(sd);
  11159. return;
  11160. }
  11161. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11162. switch (sd->menuskill_id) {
  11163. case AC_MAKINGARROW:
  11164. skill_arrow_create(sd,p->itemId);
  11165. break;
  11166. case SA_CREATECON:
  11167. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11168. break;
  11169. case GC_POISONINGWEAPON:
  11170. skill_poisoningweapon(sd,p->itemId);
  11171. break;
  11172. case NC_MAGICDECOY:
  11173. skill_magicdecoy(sd,p->itemId);
  11174. break;
  11175. }
  11176. clif_menuskill_clear(sd);
  11177. }
  11178. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11179. /// 01ce <skill id>.L
  11180. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11181. {
  11182. if (sd->menuskill_id != SA_AUTOSPELL)
  11183. return;
  11184. sd->state.workinprogress = WIP_DISABLE_NONE;
  11185. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11186. clif_menuskill_clear(sd);
  11187. }
  11188. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11189. /// 017a <card index>.W
  11190. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11191. {
  11192. if (sd->state.trading != 0)
  11193. return;
  11194. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11195. }
  11196. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11197. /// 017c <card index>.W <equip index>.W
  11198. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11199. {
  11200. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11201. if (sd->state.trading != 0)
  11202. return;
  11203. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11204. }
  11205. /// Request of character's name by char ID.
  11206. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11207. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11208. /// There are various variants of this packet, some of them have padding between fields.
  11209. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11210. {
  11211. int charid;
  11212. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11213. map_reqnickdb(sd, charid);
  11214. }
  11215. /// /resetskill /resetstate (CZ_RESET).
  11216. /// Request to reset stats or skills.
  11217. /// 0197 <type>.W
  11218. /// type:
  11219. /// 0 = state
  11220. /// 1 = skill
  11221. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11222. char cmd[15];
  11223. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11224. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11225. else
  11226. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11227. is_atcommand(fd, sd, cmd, 1);
  11228. }
  11229. /// /lb /nlb (CZ_LOCALBROADCAST).
  11230. /// Request to broadcast a message on current map.
  11231. /// 019c <packet len>.W <text>.?B
  11232. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11233. {
  11234. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11235. char command[CHAT_SIZE_MAX+16];
  11236. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11237. char* msg = RFIFOCP(fd,info->pos[1]);
  11238. // as the length varies depending on the command used, just block unreasonably long strings
  11239. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11240. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11241. is_atcommand(fd, sd, command, 1);
  11242. }
  11243. /// Request to move an item from inventory to storage.
  11244. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11245. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11246. /// There are various variants of this packet, some of them have padding between fields.
  11247. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11248. {
  11249. int item_index, item_amount;
  11250. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11251. if (pc_istrading(sd))
  11252. return;
  11253. item_index = RFIFOW(fd,info->pos[0])-2;
  11254. item_amount = RFIFOL(fd,info->pos[1]);
  11255. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11256. return;
  11257. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11258. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11259. return;
  11260. }
  11261. if (sd->state.storage_flag == 1)
  11262. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11263. else
  11264. if (sd->state.storage_flag == 2)
  11265. storage_guild_storageadd(sd, item_index, item_amount);
  11266. else if (sd->state.storage_flag == 3)
  11267. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11268. }
  11269. /// Request to move an item from storage to inventory.
  11270. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11271. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11272. /// There are various variants of this packet, some of them have padding between fields.
  11273. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11274. {
  11275. int item_index, item_amount;
  11276. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11277. item_index = RFIFOW(fd,info->pos[0])-1;
  11278. item_amount = RFIFOL(fd,info->pos[1]);
  11279. if (sd->state.storage_flag == 1)
  11280. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11281. else if(sd->state.storage_flag == 2)
  11282. storage_guild_storageget(sd, item_index, item_amount);
  11283. else if(sd->state.storage_flag == 3)
  11284. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11285. }
  11286. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11287. /// 0129 <index>.W <amount>.L
  11288. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11289. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11290. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11291. int amount = RFIFOL(fd,info->pos[1]);
  11292. if( sd->state.vending )
  11293. return;
  11294. if (!pc_iscarton(sd))
  11295. return;
  11296. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11297. return;
  11298. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11299. return;
  11300. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11301. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11302. return;
  11303. }
  11304. if (sd->state.storage_flag == 1)
  11305. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11306. else if (sd->state.storage_flag == 2)
  11307. storage_guild_storageaddfromcart(sd, idx, amount);
  11308. else if (sd->state.storage_flag == 3)
  11309. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11310. }
  11311. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11312. /// 0128 <index>.W <amount>.L
  11313. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11314. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11315. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11316. int amount = RFIFOL(fd,info->pos[1]);
  11317. if( sd->state.vending )
  11318. return;
  11319. if (!pc_iscarton(sd))
  11320. return;
  11321. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11322. return;
  11323. if (sd->state.storage_flag == 1)
  11324. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11325. else
  11326. if (sd->state.storage_flag == 2)
  11327. storage_guild_storagegettocart(sd, idx, amount);
  11328. else if (sd->state.storage_flag == 3)
  11329. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11330. }
  11331. /// Request to close storage (CZ_CLOSE_STORE).
  11332. /// 00f7
  11333. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11334. {
  11335. if( sd->state.storage_flag == 1 )
  11336. storage_storageclose(sd);
  11337. else
  11338. if( sd->state.storage_flag == 2 )
  11339. storage_guild_storageclose(sd);
  11340. else if( sd->state.storage_flag == 3 )
  11341. storage_premiumStorage_close(sd);
  11342. }
  11343. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11344. /// 023a <info>.W
  11345. /// info:
  11346. /// 0 = password has not been set yet
  11347. /// 1 = storage is password-protected
  11348. /// 8 = too many wrong passwords
  11349. /// ? = ignored
  11350. /// NOTE: This packet is only available on certain non-kRO clients.
  11351. void clif_storagepassword(struct map_session_data* sd, short info)
  11352. {
  11353. int fd = sd->fd;
  11354. WFIFOHEAD(fd,packet_len(0x23a));
  11355. WFIFOW(fd,0) = 0x23a;
  11356. WFIFOW(fd,2) = info;
  11357. WFIFOSET(fd,packet_len(0x23a));
  11358. }
  11359. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11360. /// 023b <type>.W <password>.16B <new password>.16B
  11361. /// type:
  11362. /// 2 = change password
  11363. /// 3 = check password
  11364. /// NOTE: This packet is only available on certain non-kRO clients.
  11365. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11366. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11367. // int type = RFIFOW(fd,info->pos[0]);
  11368. // char* password = RFIFOP(fd,info->pos[1]);
  11369. // char* new_password = RFIFOP(fd,info->pos[2]);
  11370. // storage_changepass(sd,password,new_password);
  11371. }
  11372. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11373. /// 023c <result>.W <error count>.W
  11374. /// result:
  11375. /// 4 = password change success
  11376. /// 5 = password change failure
  11377. /// 6 = password check success
  11378. /// 7 = password check failure
  11379. /// 8 = too many wrong passwords
  11380. /// ? = ignored
  11381. /// NOTE: This packet is only available on certain non-kRO clients.
  11382. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11383. {
  11384. int fd = sd->fd;
  11385. WFIFOHEAD(fd,packet_len(0x23c));
  11386. WFIFOW(fd,0) = 0x23c;
  11387. WFIFOW(fd,2) = result;
  11388. WFIFOW(fd,4) = error_count;
  11389. WFIFOSET(fd,packet_len(0x23c));
  11390. }
  11391. /// Party creation request
  11392. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11393. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11394. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11395. name[NAME_LENGTH-1] = '\0';
  11396. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11397. clif_displaymessage(fd, msg_txt(sd,227));
  11398. return;
  11399. }
  11400. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11401. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11402. return;
  11403. }
  11404. party_create(sd,name,0,0);
  11405. }
  11406. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11407. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11408. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11409. char* name = RFIFOCP(fd,info->pos[0]);
  11410. int item1 = RFIFOB(fd,info->pos[1]);
  11411. int item2 = RFIFOB(fd,info->pos[2]);
  11412. name[NAME_LENGTH-1] = '\0';
  11413. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11414. clif_displaymessage(fd, msg_txt(sd,227));
  11415. return;
  11416. }
  11417. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11418. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11419. return;
  11420. }
  11421. party_create(sd,name,item1,item2);
  11422. }
  11423. /// Party invitation request
  11424. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11425. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11426. {
  11427. struct map_session_data *t_sd;
  11428. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11429. clif_displaymessage(fd, msg_txt(sd,227));
  11430. return;
  11431. }
  11432. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11433. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11434. clif_noask_sub(sd, t_sd, 1);
  11435. return;
  11436. }
  11437. party_invite(sd, t_sd);
  11438. }
  11439. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11440. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11441. struct map_session_data *t_sd;
  11442. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11443. name[NAME_LENGTH-1] = '\0';
  11444. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11445. clif_displaymessage(fd, msg_txt(sd,227));
  11446. return;
  11447. }
  11448. t_sd = map_nick2sd(name,false);
  11449. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11450. clif_noask_sub(sd, t_sd, 1);
  11451. return;
  11452. }
  11453. party_invite(sd, t_sd);
  11454. }
  11455. /// Party invitation reply
  11456. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11457. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11458. /// flag:
  11459. /// 0 = reject
  11460. /// 1 = accept
  11461. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11462. {
  11463. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11464. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11465. RFIFOL(fd,info->pos[1]));
  11466. }
  11467. //(CZ_PARTY_JOIN_REQ_ACK)
  11468. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11469. {
  11470. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11471. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11472. RFIFOB(fd,info->pos[1]));
  11473. }
  11474. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11475. /// 0100
  11476. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11477. {
  11478. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11479. clif_displaymessage(fd, msg_txt(sd,227));
  11480. return;
  11481. }
  11482. party_leave(sd);
  11483. }
  11484. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11485. /// 0103 <account id>.L <char name>.24B
  11486. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11487. {
  11488. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11489. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11490. clif_displaymessage(fd, msg_txt(sd,227));
  11491. return;
  11492. }
  11493. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11494. RFIFOCP(fd,info->pos[1]));
  11495. }
  11496. /// Request to change party options.
  11497. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11498. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11499. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11500. {
  11501. struct party_data *p;
  11502. int i,expflag;
  11503. int cmd = RFIFOW(fd,0);
  11504. struct s_packet_db* info = &packet_db[cmd];
  11505. if( !sd->status.party_id )
  11506. return;
  11507. p = party_search(sd->status.party_id);
  11508. if( p == NULL )
  11509. return;
  11510. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11511. if( i == MAX_PARTY )
  11512. return; //Shouldn't happen
  11513. if( !p->party.member[i].leader )
  11514. return;
  11515. expflag = RFIFOL(fd,info->pos[0]);
  11516. if(cmd == 0x0102){ //Client can't change the item-field
  11517. party_changeoption(sd, expflag, p->party.item);
  11518. }
  11519. else {
  11520. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11521. party_changeoption(sd, expflag, itemflag);
  11522. }
  11523. }
  11524. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11525. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11526. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11527. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11528. // validate packet and retrieve name and message
  11529. if( !clif_process_message( sd, false, name, message, output ) )
  11530. return;
  11531. party_send_message(sd, output, strlen(output) + 1 );
  11532. }
  11533. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11534. /// 07da <account id>.L
  11535. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11536. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11537. }
  11538. /// Party Booking in KRO [Spiria]
  11539. ///
  11540. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11541. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11542. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11543. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11544. short level = RFIFOW(fd,info->pos[0]);
  11545. short mapid = RFIFOW(fd,info->pos[1]);
  11546. int idxpbj = info->pos[2];
  11547. short job[MAX_PARTY_BOOKING_JOBS];
  11548. int i;
  11549. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11550. job[i] = RFIFOB(fd,idxpbj+i*2);
  11551. party_booking_register(sd, level, mapid, job);
  11552. }
  11553. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11554. /// 0803 <result>.W
  11555. /// result:
  11556. /// 0 = success
  11557. /// 1 = failure
  11558. /// 2 = already registered
  11559. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11560. {
  11561. int fd = sd->fd;
  11562. WFIFOHEAD(fd,packet_len(0x803));
  11563. WFIFOW(fd,0) = 0x803;
  11564. WFIFOW(fd,2) = flag;
  11565. WFIFOSET(fd,packet_len(0x803));
  11566. }
  11567. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11568. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11569. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11570. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11571. short level = RFIFOW(fd,info->pos[0]);
  11572. short mapid = RFIFOW(fd,info->pos[1]);
  11573. short job = RFIFOW(fd,info->pos[2]);
  11574. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11575. short resultcount = RFIFOW(fd,info->pos[4]);
  11576. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11577. }
  11578. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11579. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11580. /// more results:
  11581. /// 0 = no
  11582. /// 1 = yes
  11583. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11584. {
  11585. int i, j;
  11586. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11587. struct party_booking_ad_info *pb_ad;
  11588. WFIFOHEAD(fd,size*count + 5);
  11589. WFIFOW(fd,0) = 0x805;
  11590. WFIFOW(fd,2) = size*count + 5;
  11591. WFIFOB(fd,4) = more_result;
  11592. for(i=0; i<count; i++)
  11593. {
  11594. pb_ad = results[i];
  11595. WFIFOL(fd,i*size+5) = pb_ad->index;
  11596. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11597. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11598. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11599. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11600. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11601. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11602. }
  11603. WFIFOSET(fd,WFIFOW(fd,2));
  11604. }
  11605. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11606. /// 0806
  11607. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11608. {
  11609. if(party_booking_delete(sd))
  11610. clif_PartyBookingDeleteAck(sd, 0);
  11611. }
  11612. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11613. /// 0807 <result>.W
  11614. /// result:
  11615. /// 0 = success
  11616. /// 1 = success (auto-removed expired ad)
  11617. /// 2 = failure
  11618. /// 3 = nothing registered
  11619. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11620. {
  11621. int fd = sd->fd;
  11622. WFIFOHEAD(fd,packet_len(0x807));
  11623. WFIFOW(fd,0) = 0x807;
  11624. WFIFOW(fd,2) = flag;
  11625. WFIFOSET(fd,packet_len(0x807));
  11626. }
  11627. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11628. /// 0808 { <job>.W }*6
  11629. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11630. {
  11631. short job[MAX_PARTY_BOOKING_JOBS];
  11632. int i;
  11633. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11634. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11635. job[i] = RFIFOW(fd,idxpbu+i*2);
  11636. party_booking_update(sd, job);
  11637. }
  11638. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11639. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11640. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11641. {
  11642. int i;
  11643. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11644. if(pb_ad == NULL) return;
  11645. WBUFW(buf,0) = 0x809;
  11646. WBUFL(buf,2) = pb_ad->index;
  11647. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11648. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11649. WBUFW(buf,34) = pb_ad->p_detail.level;
  11650. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11651. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11652. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11653. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11654. }
  11655. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11656. /// 080a <index>.L { <job>.W }*6
  11657. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11658. {
  11659. int i;
  11660. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11661. if(pb_ad == NULL) return;
  11662. WBUFW(buf,0) = 0x80a;
  11663. WBUFL(buf,2) = pb_ad->index;
  11664. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11665. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11666. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11667. }
  11668. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11669. /// 080b <index>.L
  11670. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11671. {
  11672. uint8 buf[6];
  11673. WBUFW(buf,0) = 0x80b;
  11674. WBUFL(buf,2) = index;
  11675. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11676. }
  11677. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11678. /// 012e
  11679. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11680. {
  11681. vending_closevending(sd);
  11682. }
  11683. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11684. /// 0130 <account id>.L
  11685. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11686. {
  11687. if( sd->npc_id ) {// using an NPC
  11688. return;
  11689. }
  11690. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11691. }
  11692. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11693. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11694. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11695. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11696. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11697. // whether it fails or not, the buy window is closed
  11698. sd->vended_id = 0;
  11699. }
  11700. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11701. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11702. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11703. #if PACKETVER >= 20100105
  11704. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11705. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11706. // whether it fails or not, the buy window is closed
  11707. sd->vended_id = 0;
  11708. #endif
  11709. }
  11710. /// Confirm or cancel the shop preparation window.
  11711. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11712. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11713. /// result:
  11714. /// 0 = canceled
  11715. /// 1 = open
  11716. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11717. int cmd = RFIFOW(fd,0);
  11718. struct s_packet_db* info = &packet_db[cmd];
  11719. short len = (short)RFIFOW(fd,info->pos[0]);
  11720. const char* message = RFIFOCP(fd,info->pos[1]);
  11721. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11722. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11723. len -= 84;
  11724. }
  11725. else { //(CZ_REQ_OPENSTORE2)
  11726. bool flag;
  11727. len -= 85;
  11728. flag = RFIFOB(fd,info->pos[2]) != 0;
  11729. if (!flag) {
  11730. sd->state.prevend = 0;
  11731. sd->state.workinprogress = WIP_DISABLE_NONE;
  11732. }
  11733. }
  11734. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11735. return;
  11736. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11737. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11738. return;
  11739. }
  11740. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11741. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11742. return;
  11743. }
  11744. if( message[0] == '\0' ) // invalid input
  11745. return;
  11746. vending_openvending(sd, message, data, len/8, NULL);
  11747. }
  11748. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11749. /// 0165 <char id>.L <guild name>.24B
  11750. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11751. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11752. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11753. name[NAME_LENGTH-1] = '\0';
  11754. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11755. clif_displaymessage(fd, msg_txt(sd,228));
  11756. return;
  11757. }
  11758. if(sd->clan){
  11759. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11760. return;
  11761. }
  11762. guild_create(sd, name);
  11763. }
  11764. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11765. /// 014d
  11766. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11767. {
  11768. clif_guild_masterormember(sd);
  11769. }
  11770. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11771. /// 014f <type>.L
  11772. /// type:
  11773. /// 0 = basic info
  11774. /// 1 = member manager
  11775. /// 2 = positions
  11776. /// 3 = skills
  11777. /// 4 = expulsion list
  11778. /// 5 = unknown (GM_ALLGUILDLIST)
  11779. /// 6 = notice
  11780. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11781. {
  11782. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11783. if( !sd->status.guild_id && !sd->bg_id )
  11784. return;
  11785. switch( type )
  11786. {
  11787. case 0: // Basic Information Guild, hostile alliance information
  11788. clif_guild_basicinfo( *sd );
  11789. clif_guild_allianceinfo(sd);
  11790. break;
  11791. case 1: // Members list, list job title
  11792. clif_guild_positionnamelist(sd);
  11793. clif_guild_memberlist( *sd );
  11794. break;
  11795. case 2: // List job title, title information list
  11796. clif_guild_positionnamelist(sd);
  11797. clif_guild_positioninfolist(sd);
  11798. break;
  11799. case 3: // Skill list
  11800. clif_guild_skillinfo(sd);
  11801. break;
  11802. case 4: // Expulsion list
  11803. clif_guild_expulsionlist(sd);
  11804. break;
  11805. default:
  11806. ShowError("clif: guild request info: unknown type %d\n", type);
  11807. break;
  11808. }
  11809. }
  11810. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11811. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11812. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11813. {
  11814. int i;
  11815. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11816. int len = RFIFOW(fd,info->pos[0]);
  11817. int idxgpos = info->pos[1];
  11818. if(!sd->state.gmaster_flag)
  11819. return;
  11820. for(i = idxgpos; i < len; i += 40 ){
  11821. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11822. }
  11823. }
  11824. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11825. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11826. void clif_parse_GuildChangeMemberPosition( int fd, struct map_session_data *sd ){
  11827. if(!sd->state.gmaster_flag)
  11828. return;
  11829. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11830. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11831. for( int16 i = 0; i < entries; i++ ){
  11832. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11833. // Guild leadership change
  11834. if( entry.position == 0 ){
  11835. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11836. clif_msg( sd, GUILD_MASTER_WOE );
  11837. return;
  11838. }
  11839. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11840. clif_msg( sd, GUILD_MASTER_DELAY );
  11841. return;
  11842. }
  11843. guild_gm_change( sd->status.guild_id, entry.CID );
  11844. // No further entries will be processed - the requesting player lost his guild master status
  11845. return;
  11846. }else if( entry.position > 0 ){
  11847. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11848. }
  11849. }
  11850. }
  11851. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11852. /// 0151 <guild id>.L
  11853. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11854. {
  11855. struct guild* g;
  11856. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11857. if( (g = guild_search(guild_id)) != NULL )
  11858. clif_guild_emblem(sd,g);
  11859. }
  11860. /// Validates data of a guild emblem (compressed bitmap)
  11861. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11862. EMBVALIDATE_SUCCESS = 0,
  11863. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11864. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  11865. };
  11866. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11867. {
  11868. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11869. unsigned long buf_len = sizeof(buf);
  11870. int offset = 0;
  11871. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11872. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11873. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11874. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11875. ))
  11876. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11877. if(inter_config.emblem_transparency_limit != 100) {
  11878. int i, transcount = 1, tmp[3];
  11879. for(i = offset; i < buf_len-1; i++) {
  11880. int j = i%3;
  11881. tmp[j] = RBUFL(buf,i);
  11882. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11883. transcount++;
  11884. }
  11885. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  11886. return EMBVALIDATE_ERR_TRANSPARENCY;
  11887. }
  11888. return EMBVALIDATE_SUCCESS;
  11889. }
  11890. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11891. /// 0153 <packet len>.W <emblem data>.?B
  11892. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11893. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11894. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11895. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11896. int emb_val=0;
  11897. if( !emblem_len || !sd->state.gmaster_flag )
  11898. return;
  11899. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  11900. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11901. return;
  11902. }
  11903. emb_val = clif_validate_emblem(emblem, emblem_len);
  11904. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11905. 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);
  11906. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11907. return;
  11908. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11909. char output[128];
  11910. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  11911. 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"
  11912. return;
  11913. }
  11914. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11915. }
  11916. /// Request to update the guild emblem id (version, according to Gravity)
  11917. /// 0b46 <guild id>.L <version>.L
  11918. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  11919. nullpo_retv(sd);
  11920. #if PACKETVER >= 20190724
  11921. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11922. guild* g = sd->guild;
  11923. if (g == nullptr || g->guild_id != p->guild_id)
  11924. return;
  11925. if (!sd->state.gmaster_flag)
  11926. return;
  11927. if (!inter_config.emblem_woe_change && is_agit_start()) {
  11928. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11929. return;
  11930. }
  11931. guild_change_emblem_version(sd, p->version);
  11932. #endif
  11933. }
  11934. /// Guild notice update request (CZ_GUILD_NOTICE).
  11935. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11936. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11937. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11938. int guild_id = RFIFOL(fd,info->pos[0]);
  11939. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11940. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11941. if(!sd->state.gmaster_flag)
  11942. return;
  11943. // compensate for some client defects when using multilanguage mode
  11944. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11945. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11946. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11947. guild_change_notice(sd, guild_id, msg1, msg2);
  11948. }
  11949. // Helper function for guild invite functions
  11950. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11951. {
  11952. if (t_sd == NULL) // not online or does not exist
  11953. return 1;
  11954. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11955. clif_displaymessage(fd, msg_txt(sd,228));
  11956. return 1;
  11957. }
  11958. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11959. clif_noask_sub(sd, t_sd, 2);
  11960. return 1;
  11961. }
  11962. // Players in a clan can not join a guild
  11963. if(t_sd && t_sd->clan){
  11964. return 1;
  11965. }
  11966. guild_invite(sd, t_sd);
  11967. return 0;
  11968. }
  11969. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11970. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11971. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11972. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11973. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11974. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11975. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11976. if (clif_sub_guild_invite(fd, sd, t_sd))
  11977. return;
  11978. }
  11979. /// Guild invite request (/guildinvite)
  11980. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11981. void
  11982. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11983. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11984. if (clif_sub_guild_invite(fd, sd, t_sd))
  11985. return;
  11986. }
  11987. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11988. /// 016b <guild id>.L <answer>.L
  11989. /// answer:
  11990. /// 0 = refuse
  11991. /// 1 = accept
  11992. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11993. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11994. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11995. RFIFOL(fd,info->pos[1]));
  11996. }
  11997. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11998. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11999. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  12000. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12001. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12002. clif_displaymessage(fd, msg_txt(sd,228));
  12003. return;
  12004. }
  12005. if( sd->bg_id ) {
  12006. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12007. return;
  12008. }
  12009. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12010. RFIFOL(fd,info->pos[1]),
  12011. RFIFOL(fd,info->pos[2]),
  12012. RFIFOCP(fd,info->pos[3]));
  12013. }
  12014. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12015. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12016. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  12017. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12018. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12019. { // Guild locked.
  12020. clif_displaymessage(fd, msg_txt(sd,228));
  12021. return;
  12022. }
  12023. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12024. RFIFOL(fd,info->pos[1]),
  12025. RFIFOL(fd,info->pos[2]),
  12026. RFIFOCP(fd,info->pos[3]));
  12027. }
  12028. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12029. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12030. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  12031. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12032. // validate packet and retrieve name and message
  12033. if( !clif_process_message( sd, false, name, message, output ) )
  12034. return;
  12035. if( sd->bg_id )
  12036. bg_send_message(sd, output, strlen(output) );
  12037. else
  12038. guild_send_message(sd, output, strlen(output) );
  12039. }
  12040. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12041. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12042. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  12043. {
  12044. struct map_session_data *t_sd;
  12045. if(!sd->state.gmaster_flag)
  12046. return;
  12047. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12048. clif_displaymessage(fd, msg_txt(sd,228));
  12049. return;
  12050. }
  12051. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12052. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12053. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12054. // @noask [LuzZza]
  12055. if(t_sd && t_sd->state.noask) {
  12056. clif_noask_sub(sd, t_sd, 3);
  12057. return;
  12058. }
  12059. guild_reqalliance(sd,t_sd);
  12060. }
  12061. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12062. /// 0172 <inviter account id>.L <answer>.L
  12063. /// answer:
  12064. /// 0 = refuse
  12065. /// 1 = accept
  12066. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  12067. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12068. guild_reply_reqalliance(sd,
  12069. RFIFOL(fd,info->pos[0]),
  12070. RFIFOL(fd,info->pos[1]));
  12071. }
  12072. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12073. /// 0183 <opponent guild id>.L <relation>.L
  12074. /// relation:
  12075. /// 0 = Ally
  12076. /// 1 = Enemy
  12077. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  12078. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12079. if(!sd->state.gmaster_flag)
  12080. return;
  12081. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12082. clif_displaymessage(fd, msg_txt(sd,228));
  12083. return;
  12084. }
  12085. guild_delalliance(sd,
  12086. RFIFOL(fd,info->pos[0]),
  12087. RFIFOL(fd,info->pos[1]));
  12088. }
  12089. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12090. /// 0180 <account id>.L
  12091. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  12092. {
  12093. struct map_session_data *t_sd;
  12094. if(!sd->state.gmaster_flag)
  12095. return;
  12096. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12097. clif_displaymessage(fd, msg_txt(sd,228));
  12098. return;
  12099. }
  12100. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12101. // @noask [LuzZza]
  12102. if(t_sd && t_sd->state.noask) {
  12103. clif_noask_sub(sd, t_sd, 4);
  12104. return;
  12105. }
  12106. guild_opposition(sd,t_sd);
  12107. }
  12108. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12109. /// 015d <key>.40B
  12110. /// key:
  12111. /// now guild name; might have been (intended) email, since the
  12112. /// field name and size is same as the one in CH_DELETE_CHAR.
  12113. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  12114. {
  12115. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12116. clif_displaymessage(fd, msg_txt(sd,228));
  12117. return;
  12118. }
  12119. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12120. }
  12121. /// Pet
  12122. ///
  12123. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12124. /// 01a1 <type>.B
  12125. /// type:
  12126. /// 0 = pet information
  12127. /// 1 = feed
  12128. /// 2 = performance
  12129. /// 3 = return to egg
  12130. /// 4 = unequip accessory
  12131. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12132. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12133. }
  12134. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12135. /// 019f <id>.L
  12136. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12137. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12138. }
  12139. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12140. /// 01a7 <index>.W
  12141. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12142. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12143. return;
  12144. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12145. clif_menuskill_clear(sd);
  12146. }
  12147. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12148. /// 01a9 <data>.L
  12149. /// data:
  12150. /// is either emotion (@see enum emotion_type) or a compound value
  12151. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12152. /// entry (given in parentheses) in data\pettalktable.xml
  12153. /// act id:
  12154. /// 0 = feeding
  12155. /// 1 = hunting
  12156. /// 2 = danger
  12157. /// 3 = dead
  12158. /// 4 = normal (stand)
  12159. /// 5 = special performance (perfor_s)
  12160. /// 6 = level up (levelup)
  12161. /// 7 = performance 1 (perfor_1)
  12162. /// 8 = performance 2 (perfor_2)
  12163. /// 9 = performance 3 (perfor_3)
  12164. /// 10 = log-in greeting (connect)
  12165. /// hungry value:
  12166. /// 0 = very hungry (hungry)
  12167. /// 1 = hungry (bit_hungry)
  12168. /// 2 = satisfied (noting)
  12169. /// 3 = stuffed (full)
  12170. /// 4 = full (so_full)
  12171. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12172. {
  12173. if(sd->pd)
  12174. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12175. }
  12176. /// Request to change pet's name (CZ_RENAME_PET).
  12177. /// 01a5 <name>.24B
  12178. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12179. {
  12180. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12181. }
  12182. /// /kill (CZ_DISCONNECT_CHARACTER).
  12183. /// Request to disconnect a character.
  12184. /// 00cc <account id>.L
  12185. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12186. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12187. {
  12188. struct block_list *target;
  12189. int tid;
  12190. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12191. target = map_id2bl(tid);
  12192. if (!target) {
  12193. clif_GM_kickack(sd, 0);
  12194. return;
  12195. }
  12196. switch (target->type) {
  12197. case BL_PC:
  12198. {
  12199. char command[NAME_LENGTH+6];
  12200. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12201. is_atcommand(fd, sd, command, 1);
  12202. }
  12203. break;
  12204. /**
  12205. * This one does not invoke any atcommand, so we need to check for permissions.
  12206. */
  12207. case BL_MOB:
  12208. {
  12209. char command[100];
  12210. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12211. clif_GM_kickack(sd, 0);
  12212. return;
  12213. }
  12214. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12215. log_atcommand(sd, command);
  12216. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12217. }
  12218. break;
  12219. case BL_NPC:
  12220. {
  12221. struct npc_data* nd = (struct npc_data *)target;
  12222. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12223. npc_unload_duplicates(nd);
  12224. npc_unload(nd,true);
  12225. npc_read_event_script();
  12226. }
  12227. }
  12228. break;
  12229. default:
  12230. clif_GM_kickack(sd, 0);
  12231. }
  12232. }
  12233. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12234. /// Request to disconnect all characters.
  12235. /// 00ce
  12236. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12237. char cmd[15];
  12238. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12239. is_atcommand(fd, sd, cmd, 1);
  12240. }
  12241. /// /remove (CZ_REMOVE_AID).
  12242. /// Request to warp to a character with given login ID.
  12243. /// 01ba <account name>.24B
  12244. /// /shift (CZ_SHIFT).
  12245. /// Request to warp to a character with given name.
  12246. /// 01bb <char name>.24B
  12247. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12248. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12249. char *player_name;
  12250. char command[NAME_LENGTH+8];
  12251. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12252. player_name[NAME_LENGTH-1] = '\0';
  12253. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12254. is_atcommand(fd, sd, command, 1);
  12255. }
  12256. /// /remove (CZ_REMOVE_AID_SSO).
  12257. /// Request to warp to a character with given account ID.
  12258. /// 0843 <account id>.L
  12259. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12260. {
  12261. uint32 account_id;
  12262. struct map_session_data* pl_sd;
  12263. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12264. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12265. char command[NAME_LENGTH+8];
  12266. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12267. is_atcommand(fd, sd, command, 1);
  12268. }
  12269. }
  12270. /// /recall (CZ_RECALL).
  12271. /// Request to summon a player with given login ID to own position.
  12272. /// 01bc <account name>.24B
  12273. /// /summon (CZ_RECALL_GID).
  12274. /// Request to summon a player with given name to own position.
  12275. /// 01bd <char name>.24B
  12276. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12277. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12278. char *player_name;
  12279. char command [NAME_LENGTH+8];
  12280. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12281. player_name[NAME_LENGTH-1] = '\0';
  12282. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12283. is_atcommand(fd, sd, command, 1);
  12284. }
  12285. /// /recall (CZ_RECALL_SSO).
  12286. /// Request to summon a player with given account ID to own position.
  12287. /// 0842 <account id>.L
  12288. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12289. {
  12290. uint32 account_id;
  12291. struct map_session_data* pl_sd;
  12292. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12293. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12294. char command[NAME_LENGTH+8];
  12295. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12296. is_atcommand(fd, sd, command, 1);
  12297. }
  12298. }
  12299. /// /item /monster (CZ_ITEM_CREATE).
  12300. /// Request to execute GM commands.
  12301. /// Usage:
  12302. /// /item n - summon n monster or acquire n item/s
  12303. /// /item money - grants 2147483647 zenies
  12304. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12305. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12306. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12307. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12308. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12309. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12310. /// 013f <item/mob name>.24B
  12311. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12312. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12313. {
  12314. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12315. int mob_id = 0;
  12316. StringBuf command;
  12317. char *str;
  12318. //#if PACKETVER >= 20131218
  12319. // char str[100];
  12320. //#else
  12321. // char str[24];
  12322. //#endif
  12323. str = RFIFOCP(fd,info->pos[0]);
  12324. if (!str || str[0] == '\0')
  12325. return;
  12326. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12327. return;
  12328. trim(str);
  12329. // Zeny
  12330. if( strcmpi(str, "money") == 0 ) {
  12331. StringBuf_Init(&command);
  12332. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12333. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12334. StringBuf_Destroy(&command);
  12335. return;
  12336. }
  12337. std::shared_ptr<item_data> id = item_db.searchname( str );
  12338. // Item
  12339. if( id ){
  12340. StringBuf_Init(&command);
  12341. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12342. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12343. }else{
  12344. if (id->flag.guid)
  12345. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12346. else
  12347. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12348. }
  12349. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12350. StringBuf_Destroy(&command);
  12351. return;
  12352. }
  12353. // Monster
  12354. if ((mob_id = mobdb_searchname(str)) == 0)
  12355. mob_id = mobdb_checkid(atoi(str));
  12356. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12357. if( mob != nullptr ) {
  12358. StringBuf_Init(&command);
  12359. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12360. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12361. StringBuf_Destroy(&command);
  12362. return;
  12363. }
  12364. }
  12365. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12366. /// 019d <effect state>.L
  12367. /// effect state:
  12368. /// TODO: Any OPTION_* ?
  12369. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12370. char cmd[6];
  12371. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12372. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12373. is_atcommand(fd, sd, cmd, 1);
  12374. }
  12375. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12376. /// 0149 <account id>.L <type>.B <value>.W
  12377. /// type:
  12378. /// 0 = positive points
  12379. /// 1 = negative points
  12380. /// 2 = self mute (+10 minutes)
  12381. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12382. {
  12383. int id, type, value;
  12384. struct map_session_data *dstsd;
  12385. char command[NAME_LENGTH+15];
  12386. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12387. id = RFIFOL(fd,info->pos[0]);
  12388. type = RFIFOB(fd,info->pos[1]);
  12389. value = RFIFOW(fd,info->pos[2]);
  12390. if( type == 0 )
  12391. value = -value;
  12392. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12393. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12394. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12395. return;
  12396. dstsd = map_id2sd(id);
  12397. if( dstsd == NULL )
  12398. return;
  12399. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12400. is_atcommand(fd, sd, command, 1);
  12401. }
  12402. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12403. /// GM adjustment of a player's manner value by -60.
  12404. /// 0212 <char name>.24B
  12405. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12406. {
  12407. char command[NAME_LENGTH+15];
  12408. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12409. name[NAME_LENGTH-1] = '\0';
  12410. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12411. is_atcommand(fd, sd, command, 1);
  12412. }
  12413. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12414. /// 01e0 <account id>.L <account name>.24B
  12415. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12416. {
  12417. WFIFOHEAD(fd,packet_len(0x1e0));
  12418. WFIFOW(fd,0) = 0x1e0;
  12419. WFIFOL(fd,2) = account_id;
  12420. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12421. WFIFOSET(fd,packet_len(0x1e0));
  12422. }
  12423. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12424. /// 01df <account id>.L
  12425. //! TODO: Figure out how does this actually work
  12426. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12427. {
  12428. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12429. /*
  12430. char query[30];
  12431. safesnprintf(query,sizeof(query),"%d", account_id);
  12432. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12433. */
  12434. clif_account_name(fd, account_id, "");
  12435. }
  12436. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12437. /// GM single cell type change request.
  12438. /// 0198 <x>.W <y>.W <type>.W
  12439. /// type:
  12440. /// 0 = not walkable
  12441. /// 1 = walkable
  12442. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12443. {
  12444. int x,y,type;
  12445. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12446. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12447. return;
  12448. x = RFIFOW(fd,info->pos[0]);
  12449. y = RFIFOW(fd,info->pos[1]);
  12450. type = RFIFOW(fd,info->pos[2]);
  12451. map_setgatcell(sd->bl.m,x,y,type);
  12452. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12453. //FIXME: once players leave the map, the client 'forgets' this information.
  12454. }
  12455. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12456. /// Request to allow/deny whispers from a nick.
  12457. /// 00cf <nick>.24B <type>.B
  12458. /// type:
  12459. /// 0 = (/ex nick) deny speech from nick
  12460. /// 1 = (/in nick) allow speech from nick
  12461. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12462. {
  12463. char* nick;
  12464. uint8 type;
  12465. int i;
  12466. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12467. nick = RFIFOCP(fd,info->pos[0]);
  12468. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12469. type = RFIFOB(fd,info->pos[1]);
  12470. if( type == 0 ) { // Add name to ignore list (block)
  12471. if (strcmp(wisp_server_name, nick) == 0) {
  12472. clif_wisexin(sd, type, 1); // fail
  12473. return;
  12474. }
  12475. // try to find a free spot, while checking for duplicates at the same time
  12476. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12477. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12478. clif_wisexin(sd, type, 2); // too many blocks
  12479. return;
  12480. }
  12481. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12482. clif_wisexin(sd, type, 0); // Aegis reports success.
  12483. return;
  12484. }
  12485. //Insert in position i
  12486. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12487. } else { // Remove name from ignore list (unblock)
  12488. // find entry
  12489. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12490. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12491. clif_wisexin(sd, type, 1); // fail
  12492. return;
  12493. }
  12494. // move everything one place down to overwrite removed entry
  12495. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12496. // wipe last entry
  12497. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12498. }
  12499. clif_wisexin(sd, type, 0); // success
  12500. }
  12501. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12502. /// Request to allow/deny all whispers.
  12503. /// 00d0 <type>.B
  12504. /// type:
  12505. /// 0 = (/exall) deny all speech
  12506. /// 1 = (/inall) allow all speech
  12507. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12508. {
  12509. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12510. if( type == 0 ) {// Deny all
  12511. if( sd->state.ignoreAll ) {
  12512. flag = 1; // fail
  12513. } else {
  12514. sd->state.ignoreAll = 1;
  12515. flag = 0; // success
  12516. }
  12517. } else {//Unblock everyone
  12518. if( sd->state.ignoreAll ) {
  12519. sd->state.ignoreAll = 0;
  12520. flag = 0; // success
  12521. } else {
  12522. if (sd->ignore[0].name[0] != '\0')
  12523. { //Wipe the ignore list.
  12524. memset(sd->ignore, 0, sizeof(sd->ignore));
  12525. flag = 0; // success
  12526. } else {
  12527. flag = 1; // fail
  12528. }
  12529. }
  12530. }
  12531. clif_wisall(sd, type, flag);
  12532. }
  12533. /// Whisper ignore list (ZC_WHISPER_LIST).
  12534. /// 00d4 <packet len>.W { <char name>.24B }*
  12535. void clif_PMIgnoreList(struct map_session_data* sd)
  12536. {
  12537. int i, fd = sd->fd;
  12538. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12539. WFIFOW(fd,0) = 0xd4;
  12540. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12541. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12542. }
  12543. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12544. WFIFOSET(fd,WFIFOW(fd,2));
  12545. }
  12546. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12547. /// 00d3
  12548. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12549. {
  12550. clif_PMIgnoreList(sd);
  12551. }
  12552. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12553. /// 01e7
  12554. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12555. {
  12556. if (sd->state.doridori) return;
  12557. switch (sd->class_&MAPID_UPPERMASK) {
  12558. case MAPID_SOUL_LINKER:
  12559. case MAPID_STAR_GLADIATOR:
  12560. case MAPID_TAEKWON:
  12561. if (!sd->state.rest)
  12562. break;
  12563. case MAPID_SUPER_NOVICE:
  12564. case MAPID_SUPER_BABY:
  12565. case MAPID_SUPER_NOVICE_E:
  12566. case MAPID_SUPER_BABY_E:
  12567. sd->state.doridori=1;
  12568. break;
  12569. }
  12570. }
  12571. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12572. /// 01ed
  12573. /// Note: This packet is caused by 7 lines of any text, followed by
  12574. /// the prayer and an another line of any text. The prayer is
  12575. /// defined by lines 790~793 in data\msgstringtable.txt
  12576. /// "Dear angel, can you hear my voice?"
  12577. /// "I am" (space separated player name) "Super Novice~"
  12578. /// "Help me out~ Please~ T_T"
  12579. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12580. {
  12581. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12582. t_exp next = pc_nextbaseexp(sd);
  12583. if( next ) {
  12584. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12585. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12586. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12587. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12588. }
  12589. }
  12590. }
  12591. }
  12592. /// Friends List
  12593. ///
  12594. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12595. /// 0206 <account id>.L <char id>.L <state>.B
  12596. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12597. /// state:
  12598. /// 0 = online
  12599. /// 1 = offline
  12600. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12601. {
  12602. int i, fd = sd->fd;
  12603. //Seek friend.
  12604. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12605. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12606. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12607. return; //Not found
  12608. WFIFOHEAD(fd,packet_len(0x206));
  12609. WFIFOW(fd, 0) = 0x206;
  12610. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12611. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12612. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12613. #if PACKETVER >= 20180221
  12614. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12615. #endif
  12616. WFIFOSET(fd, packet_len(0x206));
  12617. }
  12618. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12619. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12620. {
  12621. uint32 account_id, char_id, online;
  12622. account_id = va_arg(ap, int);
  12623. char_id = va_arg(ap, int);
  12624. online = va_arg(ap, int);
  12625. clif_friendslist_toggle(sd, account_id, char_id, online);
  12626. return 0;
  12627. }
  12628. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12629. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12630. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12631. void clif_friendslist_send( struct map_session_data& sd ){
  12632. struct PACKET_ZC_FRIENDS_LIST* p = (struct PACKET_ZC_FRIENDS_LIST*)packet_buffer;
  12633. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12634. p->PacketLength = sizeof( *p );
  12635. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12636. struct PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12637. f.AID = sd.status.friends[i].account_id;
  12638. f.CID = sd.status.friends[i].char_id;
  12639. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12640. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12641. #endif
  12642. c++;
  12643. p->PacketLength += sizeof( f );
  12644. }
  12645. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12646. // Sending the online players
  12647. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12648. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12649. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12650. }
  12651. }
  12652. }
  12653. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12654. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12655. /// result:
  12656. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12657. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12658. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12659. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12660. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12661. {
  12662. int fd;
  12663. nullpo_retv(sd);
  12664. fd = sd->fd;
  12665. WFIFOHEAD(fd,packet_len(0x209));
  12666. WFIFOW(fd,0) = 0x209;
  12667. WFIFOW(fd,2) = type;
  12668. if (f_sd) {
  12669. WFIFOL(fd,4) = f_sd->status.account_id;
  12670. WFIFOL(fd,8) = f_sd->status.char_id;
  12671. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12672. }
  12673. WFIFOSET(fd, packet_len(0x209));
  12674. }
  12675. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12676. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12677. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12678. {
  12679. int fd = sd->fd;
  12680. WFIFOHEAD(fd,packet_len(0x207));
  12681. WFIFOW(fd,0) = 0x207;
  12682. WFIFOL(fd,2) = account_id;
  12683. WFIFOL(fd,6) = char_id;
  12684. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12685. WFIFOSET(fd,packet_len(0x207));
  12686. }
  12687. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12688. /// 0202 <name>.24B
  12689. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12690. {
  12691. struct map_session_data *f_sd;
  12692. int i;
  12693. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12694. // Friend doesn't exist (no player with this name)
  12695. if (f_sd == NULL) {
  12696. clif_displaymessage(fd, msg_txt(sd,3));
  12697. return;
  12698. }
  12699. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12700. return;
  12701. }
  12702. // ensure that the request player's friend list is not full
  12703. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12704. if( i == MAX_FRIENDS ){
  12705. clif_friendslist_reqack(sd, f_sd, 2);
  12706. return;
  12707. }
  12708. // @noask [LuzZza]
  12709. if(f_sd->state.noask) {
  12710. clif_noask_sub(sd, f_sd, 5);
  12711. return;
  12712. }
  12713. // Friend already exists
  12714. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12715. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12716. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12717. return;
  12718. }
  12719. }
  12720. f_sd->friend_req = sd->status.char_id;
  12721. sd->friend_req = f_sd->status.char_id;
  12722. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12723. }
  12724. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12725. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12726. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12727. /// reply:
  12728. /// 0 = rejected
  12729. /// 1 = accepted
  12730. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12731. {
  12732. struct map_session_data *f_sd;
  12733. uint32 account_id;
  12734. char reply;
  12735. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12736. account_id = RFIFOL(fd,info->pos[0]);
  12737. //char_id = RFIFOL(fd,info->pos[1]);
  12738. #if PACKETVER < 6
  12739. reply = RFIFOB(fd,info->pos[2]);
  12740. #else
  12741. reply = RFIFOL(fd,info->pos[2]);
  12742. #endif
  12743. if( sd->bl.id == account_id ) {// adding oneself as friend
  12744. return;
  12745. }
  12746. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12747. if (f_sd == NULL)
  12748. return;
  12749. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12750. clif_friendslist_reqack(f_sd, sd, 1);
  12751. else {
  12752. int i;
  12753. // Find an empty slot
  12754. for (i = 0; i < MAX_FRIENDS; i++)
  12755. if (f_sd->status.friends[i].char_id == 0)
  12756. break;
  12757. if (i == MAX_FRIENDS) {
  12758. clif_friendslist_reqack(f_sd, sd, 2);
  12759. return;
  12760. }
  12761. f_sd->status.friends[i].account_id = sd->status.account_id;
  12762. f_sd->status.friends[i].char_id = sd->status.char_id;
  12763. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12764. clif_friendslist_reqack(f_sd, sd, 0);
  12765. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12766. if (battle_config.friend_auto_add) {
  12767. // Also add f_sd to sd's friendlist.
  12768. for (i = 0; i < MAX_FRIENDS; i++) {
  12769. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12770. return; //No need to add anything.
  12771. if (sd->status.friends[i].char_id == 0)
  12772. break;
  12773. }
  12774. if (i == MAX_FRIENDS) {
  12775. clif_friendslist_reqack(sd, f_sd, 2);
  12776. return;
  12777. }
  12778. sd->status.friends[i].account_id = f_sd->status.account_id;
  12779. sd->status.friends[i].char_id = f_sd->status.char_id;
  12780. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12781. clif_friendslist_reqack(sd, f_sd, 0);
  12782. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12783. }
  12784. }
  12785. }
  12786. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12787. /// 0203 <account id>.L <char id>.L
  12788. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12789. {
  12790. struct map_session_data *f_sd = NULL;
  12791. uint32 account_id, char_id;
  12792. int i, j;
  12793. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12794. account_id = RFIFOL(fd,info->pos[0]);
  12795. char_id = RFIFOL(fd,info->pos[1]);
  12796. // Search friend
  12797. for (i = 0; i < MAX_FRIENDS &&
  12798. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12799. if (i == MAX_FRIENDS) {
  12800. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12801. return;
  12802. }
  12803. //remove from friend's list first
  12804. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12805. for (i = 0; i < MAX_FRIENDS &&
  12806. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12807. if (i != MAX_FRIENDS) {
  12808. // move all chars up
  12809. for(j = i + 1; j < MAX_FRIENDS; j++)
  12810. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12811. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12812. //should the guy be notified of some message? we should add it here if so
  12813. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12814. WFIFOW(f_sd->fd,0) = 0x20a;
  12815. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12816. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12817. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12818. }
  12819. } else { //friend not online -- ask char server to delete from his friendlist
  12820. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12821. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12822. return;
  12823. }
  12824. }
  12825. // We can now delete from original requester
  12826. for (i = 0; i < MAX_FRIENDS &&
  12827. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12828. // move all chars up
  12829. for(j = i + 1; j < MAX_FRIENDS; j++)
  12830. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12831. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12832. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12833. WFIFOHEAD(fd,packet_len(0x20a));
  12834. WFIFOW(fd,0) = 0x20a;
  12835. WFIFOL(fd,2) = account_id;
  12836. WFIFOL(fd,6) = char_id;
  12837. WFIFOSET(fd, packet_len(0x20a));
  12838. }
  12839. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12840. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12841. void clif_PVPInfo(struct map_session_data* sd)
  12842. {
  12843. int fd = sd->fd;
  12844. WFIFOHEAD(fd,packet_len(0x210));
  12845. WFIFOW(fd,0) = 0x210;
  12846. WFIFOL(fd,2) = sd->status.char_id;
  12847. WFIFOL(fd,6) = sd->status.account_id;
  12848. WFIFOL(fd,10) = sd->pvp_won; // times won
  12849. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12850. WFIFOL(fd,18) = sd->pvp_point;
  12851. WFIFOSET(fd, packet_len(0x210));
  12852. }
  12853. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12854. /// 020f <char id>.L <account id>.L
  12855. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12856. {
  12857. // TODO: Is there a way to use this on an another player (char/acc id)?
  12858. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12859. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12860. clif_PVPInfo(sd);
  12861. }
  12862. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12863. /// 0254 <which>.B
  12864. /// which: (unused atm for security purpose)
  12865. /// 0 = sun
  12866. /// 1 = moon
  12867. /// 2 = star
  12868. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12869. {
  12870. int i;
  12871. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12872. if (sd->menuskill_id != SG_FEEL)
  12873. return;
  12874. i = sd->menuskill_val-1;
  12875. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12876. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12877. sd->feel_map[i].m = sd->bl.m;
  12878. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12879. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12880. // clif_misceffect2(&sd->bl, 0x1b0);
  12881. // clif_misceffect2(&sd->bl, 0x21f);
  12882. clif_feel_info(sd, i, 0);
  12883. clif_menuskill_clear(sd);
  12884. }
  12885. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12886. /// 0253 <which>.B
  12887. /// which:
  12888. /// 0 = sun
  12889. /// 1 = moon
  12890. /// 2 = star
  12891. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12892. {
  12893. WFIFOHEAD(fd,packet_len(0x253));
  12894. WFIFOW(fd,0)=0x253;
  12895. WFIFOB(fd,2)=TOB(skill_lv-1);
  12896. WFIFOSET(fd, packet_len(0x253));
  12897. sd->menuskill_id = SG_FEEL;
  12898. sd->menuskill_val = skill_lv;
  12899. }
  12900. /// Request to change homunculus' name (CZ_RENAME_MER).
  12901. /// 0231 <name>.24B
  12902. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12903. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12904. }
  12905. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12906. /// 0234 <id>.L
  12907. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12908. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12909. struct block_list *bl = NULL;
  12910. struct unit_data *ud = NULL;
  12911. if( sd->md && sd->md->bl.id == id )
  12912. bl = &sd->md->bl;
  12913. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12914. bl = &sd->hd->bl; // Moving Homunculus
  12915. else
  12916. return;
  12917. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12918. ud = unit_bl2ud(bl);
  12919. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12920. }
  12921. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12922. /// 0232 <id>.L <position data>.3B
  12923. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12924. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12925. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12926. struct block_list *bl = NULL;
  12927. short x, y;
  12928. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12929. if( sd->md && sd->md->bl.id == id )
  12930. bl = &sd->md->bl; // Moving Mercenary
  12931. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12932. bl = &sd->hd->bl; // Moving Homunculus
  12933. else
  12934. return;
  12935. unit_walktoxy(bl, x, y, 4);
  12936. }
  12937. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12938. /// 0233 <id>.L <target id>.L <action>.B
  12939. /// action:
  12940. /// always 0
  12941. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12942. {
  12943. struct block_list *bl = NULL;
  12944. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12945. int id = RFIFOL(fd,info->pos[0]);
  12946. int target_id = RFIFOL(fd,info->pos[1]);
  12947. int action_type = RFIFOB(fd,info->pos[2]);
  12948. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12949. bl = &sd->hd->bl;
  12950. else if( sd->md && sd->md->bl.id == id )
  12951. bl = &sd->md->bl;
  12952. else return;
  12953. unit_stop_attack(bl);
  12954. unit_attack(bl, target_id, action_type != 0);
  12955. }
  12956. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12957. /// 022d <type>.W <command>.B
  12958. /// type:
  12959. /// always 0
  12960. /// command:
  12961. /// 0 = homunculus information
  12962. /// 1 = feed
  12963. /// 2 = delete
  12964. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12965. { //[orn]
  12966. int cmd = RFIFOW(fd,0);
  12967. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12968. if(!hom_is_active(sd->hd))
  12969. return;
  12970. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12971. }
  12972. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12973. /// 0292
  12974. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12975. {
  12976. pc_revive_item(sd);
  12977. }
  12978. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12979. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12980. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12981. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12982. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12983. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12984. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12985. void clif_check(int fd, struct map_session_data* pl_sd)
  12986. {
  12987. WFIFOHEAD(fd,packet_len(0x214));
  12988. WFIFOW(fd, 0) = 0x214;
  12989. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12990. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12991. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12992. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12993. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12994. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12995. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12996. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12997. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12998. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12999. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13000. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13001. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13002. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13003. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13004. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13005. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13006. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13007. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13008. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13009. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13010. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13011. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13012. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13013. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13014. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13015. WFIFOSET(fd,packet_len(0x214));
  13016. }
  13017. /// /check (CZ_REQ_STATUS_GM).
  13018. /// Request character's status values.
  13019. /// 0213 <char name>.24B
  13020. void clif_parse_Check(int fd, struct map_session_data *sd)
  13021. {
  13022. char charname[NAME_LENGTH];
  13023. struct map_session_data* pl_sd;
  13024. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13025. return;
  13026. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13027. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13028. {
  13029. return;
  13030. }
  13031. clif_check(fd, pl_sd);
  13032. }
  13033. /// MAIL SYSTEM
  13034. /// By Zephyrus
  13035. ///
  13036. /// Notification about the result of adding an item to mail
  13037. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13038. /// result:
  13039. /// 0 = success
  13040. /// 1 = failure
  13041. /// 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)
  13042. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13043. /// result:
  13044. /// 0 = success
  13045. /// 1 = over weight
  13046. /// 2 = fatal error
  13047. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  13048. int fd = sd->fd;
  13049. #if PACKETVER < 20150513
  13050. WFIFOHEAD(fd,packet_len(0x255));
  13051. WFIFOW(fd,0) = 0x255;
  13052. WFIFOW(fd,2) = index;
  13053. WFIFOB(fd,4) = flag;
  13054. WFIFOSET(fd,packet_len(0x255));
  13055. #else
  13056. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13057. if( flag ){
  13058. memset( &p, 0, sizeof( p ) );
  13059. }else{
  13060. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13061. p.index = index;
  13062. p.count = amount;
  13063. p.itemId = client_nameid( item->nameid );
  13064. p.type = itemtype( item->nameid );
  13065. p.IsIdentified = item->identify ? 1 : 0;
  13066. p.IsDamaged = item->attribute ? 1 : 0;
  13067. p.refiningLevel = item->refine;
  13068. clif_addcards( &p.slot, item );
  13069. clif_add_random_options( p.optionData, item );
  13070. p.weight = 0;
  13071. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13072. if( sd->mail.item[i].nameid == 0 ){
  13073. continue;
  13074. }
  13075. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13076. }
  13077. p.favorite = item->favorite;
  13078. p.location = pc_equippoint( sd, server_index( index ) );
  13079. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13080. p.grade = item->enchantgrade;
  13081. #endif
  13082. }
  13083. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13084. p.result = flag;
  13085. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13086. #endif
  13087. }
  13088. /// Notification about the result of retrieving a mail attachment
  13089. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13090. /// result:
  13091. /// 0 = success
  13092. /// 1 = failure
  13093. /// 2 = too many items
  13094. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13095. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13096. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13097. #if PACKETVER < 20150513
  13098. int fd = sd->fd;
  13099. WFIFOHEAD(fd,packet_len(0x245));
  13100. WFIFOW(fd,0) = 0x245;
  13101. WFIFOB(fd,2) = result;
  13102. WFIFOSET(fd,packet_len(0x245));
  13103. #else
  13104. switch( type ){
  13105. case MAIL_ATT_ITEM:
  13106. case MAIL_ATT_ZENY:
  13107. break;
  13108. default:
  13109. return;
  13110. }
  13111. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13112. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13113. p.MailID = msg->id;
  13114. p.opentype = msg->type;
  13115. p.result = result;
  13116. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13117. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13118. #endif
  13119. }
  13120. /// Notification about the result of sending a mail
  13121. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13122. /// result:
  13123. /// 0 = success
  13124. /// 1 = recipinent does not exist
  13125. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13126. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13127. #if PACKETVER < 20150513
  13128. int fd = sd->fd;
  13129. WFIFOHEAD(fd,packet_len(0x249));
  13130. WFIFOW(fd,0) = 0x249;
  13131. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13132. WFIFOSET(fd,packet_len(0x249));
  13133. #else
  13134. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13135. p.PacketType = rodexwriteresult;
  13136. p.result = result;
  13137. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13138. #endif
  13139. }
  13140. /// Notification about the result of deleting a mail.
  13141. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13142. /// result:
  13143. /// 0 = success
  13144. /// 1 = failure
  13145. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13146. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13147. #if PACKETVER < 20150513
  13148. int fd = sd->fd;
  13149. WFIFOHEAD(fd, packet_len(0x257));
  13150. WFIFOW(fd,0) = 0x257;
  13151. WFIFOL(fd,2) = msg->id;
  13152. WFIFOW(fd,6) = !success;
  13153. WFIFOSET(fd, packet_len(0x257));
  13154. #else
  13155. // This is only a success notification
  13156. if( success ){
  13157. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13158. p.PacketType = rodexdelete;
  13159. p.opentype = msg->type;
  13160. p.MailID = msg->id;
  13161. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13162. }
  13163. #endif
  13164. }
  13165. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13166. /// 0274 <mail id>.L <result>.W
  13167. /// result:
  13168. /// 0 = success
  13169. /// 1 = failure
  13170. void clif_Mail_return(int fd, int mail_id, short fail)
  13171. {
  13172. WFIFOHEAD(fd,packet_len(0x274));
  13173. WFIFOW(fd,0) = 0x274;
  13174. WFIFOL(fd,2) = mail_id;
  13175. WFIFOW(fd,6) = fail;
  13176. WFIFOSET(fd,packet_len(0x274));
  13177. }
  13178. /// Notification about new mail.
  13179. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13180. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13181. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13182. #if PACKETVER < 20150513
  13183. int fd = sd->fd;
  13184. WFIFOHEAD(fd,packet_len(0x24a));
  13185. WFIFOW(fd,0) = 0x24a;
  13186. WFIFOL(fd,2) = mail_id;
  13187. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13188. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13189. WFIFOSET(fd,packet_len(0x24a));
  13190. #else
  13191. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13192. p.PacketType = rodexicon;
  13193. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13194. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13195. #endif
  13196. }
  13197. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13198. /// 0260 <type>.L
  13199. /// type:
  13200. /// 0 = open
  13201. /// 1 = close
  13202. void clif_Mail_window(int fd, int flag)
  13203. {
  13204. WFIFOHEAD(fd,packet_len(0x260));
  13205. WFIFOW(fd,0) = 0x260;
  13206. WFIFOL(fd,2) = flag;
  13207. WFIFOSET(fd,packet_len(0x260));
  13208. }
  13209. /// Lists mails stored in inbox.
  13210. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13211. /// read:
  13212. /// 0 = unread
  13213. /// 1 = read
  13214. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13215. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13216. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13217. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13218. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13219. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13220. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13221. #if PACKETVER < 20150513
  13222. int fd = sd->fd;
  13223. struct mail_data *md = &sd->mail.inbox;
  13224. struct mail_message *msg;
  13225. int len, i, j;
  13226. len = 8 + (73 * md->amount);
  13227. WFIFOHEAD(fd,len);
  13228. WFIFOW(fd,0) = 0x240;
  13229. WFIFOW(fd,2) = len;
  13230. WFIFOL(fd,4) = md->amount;
  13231. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13232. {
  13233. msg = &md->msg[i];
  13234. if (msg->id < 1)
  13235. continue;
  13236. WFIFOL(fd,8+73*j) = msg->id;
  13237. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13238. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13239. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13240. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13241. j++;
  13242. }
  13243. WFIFOSET(fd,len);
  13244. if( md->full ) {// TODO: is this official?
  13245. char output[100];
  13246. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13247. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13248. }
  13249. #else
  13250. int fd = sd->fd;
  13251. struct mail_data *md = &sd->mail.inbox;
  13252. struct mail_message *msg;
  13253. int i, j, k, offset, titleLength;
  13254. uint8 mailType, amount, remaining;
  13255. uint32 now = (uint32)time(NULL);
  13256. #if PACKETVER >= 20170419
  13257. int cmd = 0xac2;
  13258. #elif PACKETVER >= 20160601
  13259. int cmd = 0xa7d;
  13260. #else
  13261. int cmd = 0x9f0;
  13262. #endif
  13263. if( battle_config.mail_daily_count ){
  13264. mail_refresh_remaining_amount(sd);
  13265. }
  13266. #if PACKETVER >= 20170419
  13267. // Always send all
  13268. i = md->amount;
  13269. #else
  13270. // If a starting mail id was sent
  13271. if( mailID != 0 ){
  13272. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13273. // Unknown mail
  13274. if( i == md->amount ){
  13275. // Ignore the request for now
  13276. return; // TODO: Should we just show the first page instead?
  13277. }
  13278. // It was actually the oldest/first mail, there is no further page
  13279. if( i == 0 ){
  13280. return;
  13281. }
  13282. // We actually want the next/older mail
  13283. i -= 1;
  13284. }else{
  13285. i = md->amount;
  13286. }
  13287. #endif
  13288. // Count the remaining mails from the starting mail or the beginning
  13289. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13290. for( j = i, remaining = 0; j >= 0; j-- ){
  13291. msg = &md->msg[j];
  13292. if (msg->id < 1)
  13293. continue;
  13294. #if PACKETVER < 20170419
  13295. if (msg->type != type)
  13296. continue;
  13297. #endif
  13298. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13299. continue;
  13300. remaining++;
  13301. }
  13302. #if PACKETVER >= 20170419
  13303. // Always send all
  13304. amount = remaining;
  13305. #else
  13306. if( remaining > MAIL_PAGE_SIZE ){
  13307. amount = MAIL_PAGE_SIZE;
  13308. }else{
  13309. amount = remaining;
  13310. }
  13311. #endif
  13312. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13313. WFIFOW(fd, 0) = cmd;
  13314. #if PACKETVER >= 20170419
  13315. WFIFOB(fd, 4) = 1; // Unknown
  13316. offset = 5;
  13317. #else
  13318. WFIFOB(fd, 4) = type;
  13319. WFIFOB(fd, 5) = amount;
  13320. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13321. offset = 7;
  13322. #endif
  13323. for( amount = 0; i >= 0; i-- ){
  13324. msg = &md->msg[i];
  13325. if (msg->id < 1)
  13326. continue;
  13327. #if PACKETVER < 20170419
  13328. if (msg->type != type)
  13329. continue;
  13330. #endif
  13331. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13332. continue;
  13333. #if PACKETVER >= 20170419
  13334. WFIFOB(fd, offset) = msg->type;
  13335. offset += 1;
  13336. #endif
  13337. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13338. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13339. mailType = MAIL_TYPE_TEXT; // Normal letter
  13340. if( msg->zeny > 0 ){
  13341. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13342. }
  13343. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13344. if( msg->item[k].nameid > 0 ){
  13345. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13346. break;
  13347. }
  13348. }
  13349. #if PACKETVER >= 20170419
  13350. // If it came from an npc?
  13351. if( !msg->send_id ){
  13352. mailType |= MAIL_TYPE_NPC;
  13353. }
  13354. #endif
  13355. WFIFOB(fd, offset + 9) = mailType;
  13356. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13357. #if PACKETVER < 20170419
  13358. // How much time has passed since you received the mail
  13359. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13360. offset += 4;
  13361. #endif
  13362. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13363. if( msg->scheduled_deletion > 0 ){
  13364. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13365. }else{
  13366. // Fake the scheduled deletion to one year in the future
  13367. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13368. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13369. }
  13370. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13371. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13372. offset += 40 + titleLength;
  13373. }
  13374. WFIFOW(fd, 2) = (int16)offset;
  13375. WFIFOSET(fd, offset);
  13376. #endif
  13377. }
  13378. /// Mail inbox list request.
  13379. /// 023f (CZ_MAIL_GET_LIST)
  13380. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13381. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13382. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13383. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13384. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13385. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13386. if( mail_invalid_operation( sd ) ){
  13387. return;
  13388. }
  13389. #if PACKETVER < 20150513
  13390. struct mail_data* md = &sd->mail.inbox;
  13391. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13392. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13393. else
  13394. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13395. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13396. mail_removezeny(sd, false);
  13397. #else
  13398. int cmd = RFIFOW(fd, 0);
  13399. #if PACKETVER < 20170419
  13400. uint8 openType = RFIFOB(fd, 2);
  13401. uint64 mailId = RFIFOQ(fd, 3);
  13402. #else
  13403. uint8 openType;
  13404. uint64 mailId = RFIFOQ(fd, 2);
  13405. int i;
  13406. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13407. if( i == MAIL_MAX_INBOX ){
  13408. openType = MAIL_INBOX_NORMAL;
  13409. mailId = 0;
  13410. }else{
  13411. openType = sd->mail.inbox.msg[i].type;
  13412. mailId = 0;
  13413. }
  13414. #endif
  13415. switch( openType ){
  13416. case MAIL_INBOX_NORMAL:
  13417. case MAIL_INBOX_ACCOUNT:
  13418. case MAIL_INBOX_RETURNED:
  13419. break;
  13420. default:
  13421. // Unknown type: ignore request
  13422. return;
  13423. }
  13424. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13425. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13426. return;
  13427. }
  13428. // If it is not a next page request
  13429. if( cmd != 0x9ee ){
  13430. mailId = 0;
  13431. }
  13432. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13433. #endif
  13434. }
  13435. /// Opens a mail
  13436. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13437. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13438. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13439. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13440. /// { }*n
  13441. // TODO: Packet description => for repeated block
  13442. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13443. int i, fd = sd->fd;
  13444. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13445. if( i == MAIL_MAX_INBOX ) {
  13446. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13447. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13448. return;
  13449. } else {
  13450. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13451. struct item *item;
  13452. int msg_len = strlen(msg->body);
  13453. if( msg_len == 0 ) {
  13454. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13455. msg_len = strlen(msg->body);
  13456. }
  13457. #if PACKETVER < 20150513
  13458. item = &msg->item[0];
  13459. int len = 101 + msg_len;
  13460. WFIFOHEAD(fd,len);
  13461. WFIFOW(fd,0) = 0x242;
  13462. WFIFOW(fd,2) = len;
  13463. WFIFOL(fd,4) = msg->id;
  13464. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13465. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13466. WFIFOL(fd,72) = 0;
  13467. WFIFOL(fd,76) = msg->zeny;
  13468. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13469. if( item->nameid && data != nullptr ) {
  13470. WFIFOL(fd,80) = item->amount;
  13471. WFIFOW(fd,84) = client_nameid( item->nameid );
  13472. WFIFOW(fd,86) = itemtype( item->nameid );
  13473. WFIFOB(fd,88) = item->identify;
  13474. WFIFOB(fd,89) = item->attribute;
  13475. WFIFOB(fd,90) = item->refine;
  13476. WFIFOW(fd,91) = item->card[0];
  13477. WFIFOW(fd,93) = item->card[1];
  13478. WFIFOW(fd,95) = item->card[2];
  13479. WFIFOW(fd,97) = item->card[3];
  13480. } else // no item, set all to zero
  13481. memset(WFIFOP(fd,80), 0x00, 19);
  13482. WFIFOB(fd,99) = (unsigned char)msg_len;
  13483. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13484. WFIFOSET(fd,len);
  13485. #else
  13486. msg_len += 1; // Zero Termination
  13487. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13488. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13489. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13490. p->opentype = msg->type;
  13491. p->MailID = msg->id;
  13492. p->TextcontentsLength = msg_len;
  13493. p->zeny = msg->zeny;
  13494. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13495. p->PacketLength += p->TextcontentsLength;
  13496. p->ItemCnt = 0;
  13497. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13498. item = &msg->item[j];
  13499. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13500. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13501. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13502. mailitem->ITID = client_nameid( item->nameid );
  13503. mailitem->count = item->amount;
  13504. mailitem->type = itemtype( item->nameid );
  13505. mailitem->IsIdentified = item->identify ? 1 : 0;
  13506. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13507. mailitem->refiningLevel = item->refine;
  13508. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13509. mailitem->viewSprite = data->look;
  13510. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13511. clif_addcards( &mailitem->slot, item );
  13512. clif_add_random_options( mailitem->option_data, item );
  13513. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13514. mailitem->grade = item->enchantgrade;
  13515. #endif
  13516. p->PacketLength += sizeof( *mailitem );
  13517. p->ItemCnt++;
  13518. }
  13519. }
  13520. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13521. #endif
  13522. if (msg->status == MAIL_UNREAD) {
  13523. msg->status = MAIL_READ;
  13524. intif_Mail_read(mail_id);
  13525. clif_parse_Mail_refreshinbox(fd, sd);
  13526. sd->mail.inbox.unread--;
  13527. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13528. }
  13529. }
  13530. }
  13531. /// Request to open a mail.
  13532. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13533. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13534. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13535. #if PACKETVER < 20150513
  13536. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13537. #else
  13538. //uint8 openType = RFIFOB(fd, 2);
  13539. int mail_id = (int)RFIFOQ(fd, 3);
  13540. #endif
  13541. if( mail_id <= 0 )
  13542. return;
  13543. if( mail_invalid_operation(sd) )
  13544. return;
  13545. clif_Mail_read(sd, mail_id);
  13546. }
  13547. /// Allow a player to begin writing a mail
  13548. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13549. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13550. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13551. p.PacketType = rodexopenwrite;
  13552. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13553. p.result = success;
  13554. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13555. }
  13556. /// Request to start writing a mail
  13557. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13558. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13559. char name[NAME_LENGTH];
  13560. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13561. if( mail_invalid_operation( sd ) ){
  13562. return;
  13563. }
  13564. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13565. clif_send_Mail_beginwrite_ack(sd, name, false);
  13566. return;
  13567. }
  13568. mail_clear(sd);
  13569. sd->state.mail_writing = true;
  13570. clif_send_Mail_beginwrite_ack(sd, name,true);
  13571. }
  13572. /// Notification that the client cancelled writing a mail
  13573. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13574. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13575. sd->state.mail_writing = false;
  13576. }
  13577. /// Give the client information about the recipient, if available
  13578. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13579. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13580. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13581. #if PACKETVER >= 20141119
  13582. PACKET_ZC_CHECKNAME p = { 0 };
  13583. p.PacketType = HEADER_ZC_CHECKNAME;
  13584. p.CharId = char_id;
  13585. p.Class = class_;
  13586. p.BaseLevel = level;
  13587. #if PACKETVER >= 20160302
  13588. strncpy(p.Name, name, NAME_LENGTH);
  13589. #endif
  13590. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13591. #endif
  13592. }
  13593. /// Request information about the recipient
  13594. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13595. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13596. #if PACKETVER >= 20140423
  13597. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13598. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13599. #else
  13600. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13601. #endif
  13602. static char name[NAME_LENGTH];
  13603. if( mail_invalid_operation( sd ) ){
  13604. return;
  13605. }
  13606. safestrncpy(name, p->Name, NAME_LENGTH);
  13607. intif_mail_checkreceiver(sd, name);
  13608. #endif
  13609. }
  13610. /// Request to receive mail's attachment.
  13611. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13612. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13613. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13614. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13615. int i;
  13616. struct mail_message* msg;
  13617. #if PACKETVER < 20150513
  13618. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13619. int attachment = MAIL_ATT_ALL;
  13620. #else
  13621. uint16 packet_id = RFIFOW(fd, 0);
  13622. int mail_id = (int)RFIFOQ(fd, 2);
  13623. //int openType = RFIFOB(fd, 10);
  13624. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13625. #endif
  13626. if( !chrif_isconnected() )
  13627. return;
  13628. if( mail_id <= 0 )
  13629. return;
  13630. if( mail_invalid_operation(sd) )
  13631. return;
  13632. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13633. if( i == MAIL_MAX_INBOX )
  13634. return;
  13635. msg = &sd->mail.inbox.msg[i];
  13636. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13637. attachment &= ~MAIL_ATT_ZENY;
  13638. }
  13639. if( attachment&MAIL_ATT_ITEM ){
  13640. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13641. // No items were found
  13642. if( i == MAIL_MAX_ITEM ){
  13643. attachment &= ~MAIL_ATT_ITEM;
  13644. }
  13645. }
  13646. // Either no attachment requested at all or there are no zeny or items in the mail
  13647. if( attachment == MAIL_ATT_NONE ){
  13648. return;
  13649. }
  13650. if( attachment&MAIL_ATT_ZENY ){
  13651. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13652. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13653. return;
  13654. }else{
  13655. // Store the pending zeny (required for the "retrieve all" feature)
  13656. sd->mail.pending_zeny += msg->zeny;
  13657. // To make sure another request fails
  13658. msg->zeny = 0;
  13659. }
  13660. }
  13661. if( attachment&MAIL_ATT_ITEM ){
  13662. int slots = 0, totalweight = 0;
  13663. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13664. struct item* item = &msg->item[i];
  13665. if( item->nameid > 0 && item->amount > 0 ){
  13666. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13667. if(data == nullptr)
  13668. continue;
  13669. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13670. case CHKADDITEM_NEW:
  13671. slots += data->inventorySlotNeeded( item->amount );
  13672. break;
  13673. case CHKADDITEM_OVERAMOUNT:
  13674. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13675. return;
  13676. }
  13677. totalweight += data->weight * item->amount;
  13678. }
  13679. }
  13680. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13681. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13682. return;
  13683. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13684. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13685. return;
  13686. }
  13687. // To make sure another request fails
  13688. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13689. // Store the pending weight (required for the "retrieve all" feature)
  13690. sd->mail.pending_weight += totalweight;
  13691. // Store the pending slots (required for the "retrieve all" feature)
  13692. sd->mail.pending_slots += slots;
  13693. }
  13694. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13695. }
  13696. /// Request to delete a mail.
  13697. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13698. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13699. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13700. #if PACKETVER < 20150513
  13701. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13702. #else
  13703. //int openType = RFIFOB(fd, 2);
  13704. int mail_id = (int)RFIFOQ(fd, 3);
  13705. #endif
  13706. int i, j;
  13707. if( !chrif_isconnected() )
  13708. return;
  13709. if( mail_id <= 0 )
  13710. return;
  13711. if( mail_invalid_operation(sd) )
  13712. return;
  13713. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13714. if (i < MAIL_MAX_INBOX) {
  13715. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13716. // can't delete mail without removing zeny first
  13717. if( msg->zeny > 0 ){
  13718. clif_mail_delete(sd, msg, false);
  13719. return;
  13720. }
  13721. // can't delete mail without removing attachment(s) first
  13722. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13723. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13724. clif_mail_delete(sd, msg, false);
  13725. return;
  13726. }
  13727. }
  13728. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13729. sd->mail.inbox.unread--;
  13730. clif_Mail_new(sd,0,NULL,NULL);
  13731. }
  13732. }
  13733. }
  13734. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13735. /// 0273 <mail id>.L <receive name>.24B
  13736. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13737. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13738. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13739. //ShowDump( p, sizeof( p ) );
  13740. int mail_id = p->msgId;
  13741. // not supported for now
  13742. return;
  13743. #else
  13744. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13745. #endif
  13746. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13747. int i;
  13748. if( mail_id <= 0 )
  13749. return;
  13750. if( mail_invalid_operation(sd) )
  13751. return;
  13752. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13753. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13754. intif_Mail_return(sd->status.char_id, mail_id);
  13755. else
  13756. clif_Mail_return(sd->fd, mail_id, 1);
  13757. }
  13758. /// Request to add an item or Zeny to mail.
  13759. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13760. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13761. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13762. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13763. uint16 idx = RFIFOW(fd,info->pos[0]);
  13764. #if PACKETVER < 20150513
  13765. int amount = RFIFOL(fd,info->pos[1]);
  13766. #else
  13767. int amount = RFIFOW(fd,info->pos[1]);
  13768. #endif
  13769. unsigned char flag;
  13770. if( !chrif_isconnected() )
  13771. return;
  13772. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13773. return;
  13774. if (sd->inventory_data[server_index(idx)] == nullptr)
  13775. return;
  13776. if( mail_invalid_operation( sd ) ){
  13777. return;
  13778. }
  13779. flag = mail_setitem(sd, idx, amount);
  13780. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13781. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13782. }else{
  13783. clif_Mail_setattachment(sd,idx,amount,flag);
  13784. }
  13785. }
  13786. /// Remove an item from a mail
  13787. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13788. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13789. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13790. p.PacketType = rodexremoveitem;
  13791. p.result = success;
  13792. p.index = index;
  13793. p.cnt = amount;
  13794. int total = 0;
  13795. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13796. if( sd->mail.item[i].nameid == 0 ){
  13797. break;
  13798. }
  13799. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13800. }
  13801. p.weight = total;
  13802. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13803. }
  13804. /// Request to reset mail item and/or Zeny
  13805. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13806. /// type:
  13807. /// 0 = reset all
  13808. /// 1 = remove item
  13809. /// 2 = remove zeny
  13810. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13811. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13812. {
  13813. #if PACKETVER < 20150513
  13814. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13815. if (type == 0 || type == 1)
  13816. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13817. if (type == 0 || type == 2)
  13818. mail_removezeny(sd, false);
  13819. #else
  13820. uint16 index = RFIFOW(fd, 2);
  13821. uint16 count = RFIFOW(fd, 4);
  13822. mail_removeitem(sd,0,index,count);
  13823. #endif
  13824. }
  13825. /// Request to send mail
  13826. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13827. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13828. /// 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)
  13829. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13830. #if PACKETVER < 20150513
  13831. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13832. if( !chrif_isconnected() )
  13833. return;
  13834. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13835. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13836. return;
  13837. }
  13838. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13839. #else
  13840. uint16 length = RFIFOW(fd, 2);
  13841. if( length < 0x3e ){
  13842. ShowWarning("Too short...\n");
  13843. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13844. return;
  13845. }
  13846. if( mail_invalid_operation( sd ) ){
  13847. return;
  13848. }
  13849. // Forged request without a begin writing packet?
  13850. if( !sd->state.mail_writing ){
  13851. return; // Ignore it
  13852. }
  13853. char receiver[NAME_LENGTH];
  13854. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13855. // char sender[NAME_LENGTH];
  13856. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13857. uint64 zeny = RFIFOQ(fd, 52);
  13858. uint16 titleLength = RFIFOW(fd, 60);
  13859. uint16 textLength = RFIFOW(fd, 62);
  13860. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13861. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13862. char title[MAIL_TITLE_LENGTH];
  13863. char text[MAIL_BODY_LENGTH];
  13864. #if PACKETVER <= 20160330
  13865. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13866. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13867. #else
  13868. // 64 = <char id>.L
  13869. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13870. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13871. #endif
  13872. if( zeny > 0 ){
  13873. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13874. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13875. return;
  13876. }
  13877. }
  13878. mail_send(sd, receiver, title, text, realTextLength);
  13879. #endif
  13880. }
  13881. /// AUCTION SYSTEM
  13882. /// By Zephyrus
  13883. ///
  13884. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13885. /// 025f <type>.L
  13886. /// type:
  13887. /// 0 = open
  13888. /// 1 = close
  13889. void clif_Auction_openwindow(struct map_session_data *sd)
  13890. {
  13891. int fd = sd->fd;
  13892. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13893. return;
  13894. if( !battle_config.feature_auction )
  13895. return;
  13896. WFIFOHEAD(fd,packet_len(0x25f));
  13897. WFIFOW(fd,0) = 0x25f;
  13898. WFIFOL(fd,2) = 0;
  13899. WFIFOSET(fd,packet_len(0x25f));
  13900. }
  13901. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13902. /// 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 }*
  13903. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13904. {
  13905. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13906. struct auction_data auction;
  13907. WFIFOHEAD(fd,12 + (count * 83));
  13908. WFIFOW(fd,0) = 0x252;
  13909. WFIFOW(fd,2) = 12 + (count * 83);
  13910. WFIFOL(fd,4) = pages;
  13911. WFIFOL(fd,8) = count;
  13912. for( i = 0; i < count; i++ ) {
  13913. int k = 12 + (i * 83);
  13914. memcpy(&auction, RBUFP(buf,i * len), len);
  13915. WFIFOL(fd,k) = auction.auction_id;
  13916. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13917. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13918. WFIFOL(fd,30+k) = auction.type;
  13919. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13920. WFIFOB(fd,36+k) = auction.item.identify;
  13921. WFIFOB(fd,37+k) = auction.item.attribute;
  13922. WFIFOB(fd,38+k) = auction.item.refine;
  13923. WFIFOW(fd,39+k) = auction.item.card[0];
  13924. WFIFOW(fd,41+k) = auction.item.card[1];
  13925. WFIFOW(fd,43+k) = auction.item.card[2];
  13926. WFIFOW(fd,45+k) = auction.item.card[3];
  13927. WFIFOL(fd,47+k) = auction.price;
  13928. WFIFOL(fd,51+k) = auction.buynow;
  13929. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13930. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13931. }
  13932. WFIFOSET(fd,WFIFOW(fd,2));
  13933. }
  13934. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13935. /// 0256 <index>.W <result>.B
  13936. /// result:
  13937. /// 0 = success
  13938. /// 1 = failure
  13939. static void clif_Auction_setitem(int fd, int index, bool fail)
  13940. {
  13941. WFIFOHEAD(fd,packet_len(0x256));
  13942. WFIFOW(fd,0) = 0x256;
  13943. WFIFOW(fd,2) = index;
  13944. WFIFOB(fd,4) = fail;
  13945. WFIFOSET(fd,packet_len(0x256));
  13946. }
  13947. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13948. /// 024b <type>.W
  13949. /// type:
  13950. /// 0 = create (any other action in auction window)
  13951. /// 1 = cancel (cancel pressed on register tab)
  13952. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13953. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13954. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13955. if( sd->auction.amount > 0 )
  13956. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13957. sd->auction.amount = 0;
  13958. }
  13959. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13960. /// 024c <index>.W <count>.L
  13961. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13962. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13963. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13964. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13965. if( !battle_config.feature_auction )
  13966. return;
  13967. if( sd->auction.amount > 0 )
  13968. sd->auction.amount = 0;
  13969. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13970. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13971. return;
  13972. }
  13973. 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.
  13974. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13975. return;
  13976. }
  13977. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  13978. 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) )
  13979. { // Consumable or pets are not allowed
  13980. clif_Auction_setitem(sd->fd, idx, true);
  13981. return;
  13982. }
  13983. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13984. !sd->inventory.u.items_inventory[idx].identify ||
  13985. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13986. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13987. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13988. clif_Auction_setitem(sd->fd, idx, true);
  13989. return;
  13990. }
  13991. sd->auction.index = idx;
  13992. sd->auction.amount = amount;
  13993. clif_Auction_setitem(fd, idx + 2, false);
  13994. }
  13995. /// Result from an auction action (ZC_AUCTION_RESULT).
  13996. /// 0250 <result>.B
  13997. /// result:
  13998. /// 0 = You have failed to bid into the auction
  13999. /// 1 = You have successfully bid in the auction
  14000. /// 2 = The auction has been canceled
  14001. /// 3 = An auction with at least one bidder cannot be canceled
  14002. /// 4 = You cannot register more than 5 items in an auction at a time
  14003. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14004. /// 6 = You have won the auction
  14005. /// 7 = You have failed to win the auction
  14006. /// 8 = You do not have enough Zeny
  14007. /// 9 = You cannot place more than 5 bids at a time
  14008. void clif_Auction_message(int fd, unsigned char flag)
  14009. {
  14010. WFIFOHEAD(fd,packet_len(0x250));
  14011. WFIFOW(fd,0) = 0x250;
  14012. WFIFOB(fd,2) = flag;
  14013. WFIFOSET(fd,packet_len(0x250));
  14014. }
  14015. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14016. /// 025e <result>.W
  14017. /// result:
  14018. /// 0 = You have ended the auction
  14019. /// 1 = You cannot end the auction
  14020. /// 2 = Auction ID is incorrect
  14021. void clif_Auction_close(int fd, unsigned char flag)
  14022. {
  14023. WFIFOHEAD(fd,packet_len(0x25e));
  14024. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14025. WFIFOW(fd,2) = flag;
  14026. WFIFOSET(fd,packet_len(0x25e));
  14027. }
  14028. /// Request to add an auction (CZ_AUCTION_ADD).
  14029. /// 024d <now money>.L <max money>.L <delete hour>.W
  14030. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  14031. {
  14032. struct auction_data auction;
  14033. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14034. if( !battle_config.feature_auction )
  14035. return;
  14036. auction.price = RFIFOL(fd,info->pos[0]);
  14037. auction.buynow = RFIFOL(fd,info->pos[1]);
  14038. auction.hours = RFIFOW(fd,info->pos[2]);
  14039. // Invalid Situations...
  14040. if( sd->auction.amount < 1 ) {
  14041. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14042. return;
  14043. }
  14044. if( auction.price >= auction.buynow ) {
  14045. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14046. return;
  14047. }
  14048. if( auction.hours < 1 || auction.hours > 48 ) {
  14049. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14050. return;
  14051. }
  14052. // Auction checks...
  14053. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14054. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14055. clif_Auction_message(fd, 2); // The auction has been canceled
  14056. return;
  14057. }
  14058. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14059. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14060. return;
  14061. }
  14062. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14063. auction.buynow = battle_config.auction_maximumprice;
  14064. if( auction.price >= auction.buynow )
  14065. auction.price = auction.buynow - 1;
  14066. }
  14067. auction.auction_id = 0;
  14068. auction.seller_id = sd->status.char_id;
  14069. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14070. auction.buyer_id = 0;
  14071. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14072. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14073. {
  14074. clif_Auction_message(fd, 2); // The auction has been canceled
  14075. return;
  14076. }
  14077. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14078. if( id == nullptr )
  14079. { // Just in case
  14080. clif_Auction_message(fd, 2); // The auction has been canceled
  14081. return;
  14082. }
  14083. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14084. auction.type = id->type;
  14085. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14086. auction.item.amount = 1;
  14087. auction.timestamp = 0;
  14088. if( !intif_Auction_register(&auction) )
  14089. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14090. else
  14091. {
  14092. int zeny = auction.hours*battle_config.auction_feeperhour;
  14093. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14094. sd->auction.amount = 0;
  14095. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  14096. }
  14097. }
  14098. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14099. /// 024e <auction id>.L
  14100. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  14101. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14102. intif_Auction_cancel(sd->status.char_id, auction_id);
  14103. }
  14104. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14105. /// 025d <auction id>.L
  14106. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  14107. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14108. intif_Auction_close(sd->status.char_id, auction_id);
  14109. }
  14110. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14111. /// 024f <auction id>.L <money>.L
  14112. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  14113. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14114. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14115. int bid = RFIFOL(fd,info->pos[1]);
  14116. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14117. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14118. return;
  14119. }
  14120. if( bid <= 0 )
  14121. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14122. else if( bid > sd->status.zeny )
  14123. clif_Auction_message(fd, 8); // You do not have enough zeny
  14124. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14125. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14126. else {
  14127. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14128. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14129. }
  14130. }
  14131. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14132. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14133. /// search type:
  14134. /// 0 = armor
  14135. /// 1 = weapon
  14136. /// 2 = card
  14137. /// 3 = misc
  14138. /// 4 = name search
  14139. /// 5 = auction id search
  14140. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  14141. char search_text[NAME_LENGTH];
  14142. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14143. short type = RFIFOW(fd,info->pos[0]);
  14144. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14145. int page = RFIFOW(fd,info->pos[3]);
  14146. if( !battle_config.feature_auction )
  14147. return;
  14148. clif_parse_Auction_cancelreg(fd, sd);
  14149. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14150. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14151. }
  14152. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14153. /// 025c <type>.W
  14154. /// type:
  14155. /// 0 = sell (own auctions)
  14156. /// 1 = buy (own bids)
  14157. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  14158. {
  14159. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14160. if( !battle_config.feature_auction )
  14161. return;
  14162. clif_parse_Auction_cancelreg(fd, sd);
  14163. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14164. }
  14165. /// CASH/POINT SHOP
  14166. ///
  14167. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  14168. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14169. nullpo_retv( sd );
  14170. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14171. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14172. p.cashPoints = sd->cashPoints;
  14173. p.kafraPoints = sd->kafraPoints;
  14174. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14175. p.tab = tab;
  14176. #endif
  14177. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14178. #endif
  14179. }
  14180. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  14181. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14182. nullpo_retv( sd );
  14183. int tab = 0;
  14184. #if PACKETVER >= 20191224
  14185. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14186. tab = p->tab;
  14187. #endif
  14188. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14189. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14190. return;
  14191. }
  14192. sd->state.cashshop_open = true;
  14193. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14194. clif_cashshop_open( sd, tab );
  14195. #endif
  14196. }
  14197. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14198. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14199. sd->state.cashshop_open = false;
  14200. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14201. // No need to do anything here
  14202. #endif
  14203. }
  14204. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14205. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14206. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14207. // [4144] packet exists only in 2011 and was dropped after
  14208. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14209. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14210. int j;
  14211. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14212. return;
  14213. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14214. WFIFOW(fd, 0) = 0x8c0;
  14215. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14216. WFIFOL(fd, 4) = tab;
  14217. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14218. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14219. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14220. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14221. }
  14222. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14223. #endif
  14224. }
  14225. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14226. void clif_cashshop_list( struct map_session_data* sd ){
  14227. nullpo_retv( sd );
  14228. int fd = sd->fd;
  14229. if( !session_isActive( fd ) ){
  14230. return;
  14231. }
  14232. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14233. // Skip empty tabs, the client only expects filled ones
  14234. if( cash_shop_items[tab].count == 0 ){
  14235. continue;
  14236. }
  14237. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14238. WFIFOHEAD( fd, len );
  14239. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14240. p->packetType = 0x8ca;
  14241. p->packetLength = len;
  14242. p->count = cash_shop_items[tab].count;
  14243. p->tabNum = tab;
  14244. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14245. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14246. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14247. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14248. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14249. if( id == nullptr ){
  14250. p->items[i].location = 0;
  14251. p->items[i].viewSprite = 0;
  14252. }else{
  14253. p->items[i].location = pc_equippoint_sub( sd, id );
  14254. p->items[i].viewSprite = id->look;
  14255. }
  14256. #endif
  14257. }
  14258. WFIFOSET( fd, len );
  14259. }
  14260. }
  14261. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14262. if( !sd->status.cashshop_sent ) {
  14263. clif_cashshop_list( sd );
  14264. #if PACKETVER_SUPPORTS_SALES
  14265. sale_notify_login(sd);
  14266. #endif
  14267. sd->status.cashshop_sent = true;
  14268. }
  14269. }
  14270. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14271. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14272. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14273. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14274. nullpo_retv( sd );
  14275. nullpo_retv( nd );
  14276. int fd = sd->fd;
  14277. if( !session_isActive( fd ) ){
  14278. return;
  14279. }
  14280. sd->npc_shopid = nd->bl.id;
  14281. int cost[2] = { 0, 0 };
  14282. npc_shop_currency_type( sd, nd, cost, true );
  14283. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14284. WFIFOHEAD( fd, len );
  14285. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14286. p->packetType = 0x287;
  14287. p->packetLength = len;
  14288. p->cashPoints = cost[0];
  14289. #if PACKETVER >= 20070711
  14290. p->kafraPoints = cost[1];
  14291. #endif
  14292. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14293. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14294. p->items[i].price = nd->u.shop.shop_item[i].value;
  14295. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14296. p->items[i].itemType = itemtype( id->nameid );
  14297. p->items[i].itemId = client_nameid( id->nameid );
  14298. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14299. p->items[i].location = pc_equippoint_sub( sd, id );
  14300. p->items[i].viewSprite = id->look;
  14301. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14302. #endif
  14303. }
  14304. WFIFOSET( fd, len );
  14305. }
  14306. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14307. /// 0289 <cash point>.L <error>.W
  14308. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14309. /// error:
  14310. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14311. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14312. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14313. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14314. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14315. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14316. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14317. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14318. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14319. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14320. {
  14321. int fd, cost[2] = { 0, 0 };
  14322. struct npc_data *nd;
  14323. nullpo_retv(sd);
  14324. fd = sd->fd;
  14325. nd = map_id2nd(sd->npc_shopid);
  14326. npc_shop_currency_type(sd, nd, cost, false);
  14327. WFIFOHEAD(fd, packet_len(0x289));
  14328. WFIFOW(fd,0) = 0x289;
  14329. WFIFOL(fd,2) = cost[0];
  14330. #if PACKETVER < 20070711
  14331. WFIFOW(fd,6) = TOW(error);
  14332. #else
  14333. WFIFOL(fd,6) = cost[1];
  14334. WFIFOW(fd,10) = TOW(error);
  14335. #endif
  14336. WFIFOSET(fd, packet_len(0x289));
  14337. }
  14338. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14339. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14340. nullpo_retv( sd );
  14341. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14342. packet.packetType = 0x849;
  14343. if( item_id != 0 ){
  14344. packet.itemId = client_nameid( item_id );
  14345. }else{
  14346. packet.itemId = 0;
  14347. }
  14348. packet.result = result;
  14349. packet.cashPoints = sd->cashPoints;
  14350. packet.kafraPoints = sd->kafraPoints;
  14351. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14352. #endif
  14353. }
  14354. /// Request to buy item(s) from cash shop.
  14355. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14356. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14357. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14358. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14359. nullpo_retv( sd );
  14360. if( sd->state.trading || !sd->npc_shopid ){
  14361. clif_cashshop_ack( sd, 1 );
  14362. return;
  14363. }
  14364. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14365. #if PACKETVER < 20070711
  14366. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14367. #elif PACKETVER < 20101116
  14368. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14369. #else
  14370. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14371. 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 ){
  14372. 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 );
  14373. return;
  14374. }
  14375. std::vector<s_npc_buy_list> item_list = {};
  14376. item_list.reserve( p->count );
  14377. for( int i = 0; i < p->count; i++ ){
  14378. s_npc_buy_list item = {};
  14379. item.nameid = p->items[i].itemId;
  14380. item.qty = p->items[i].amount;
  14381. item_list.push_back( item );
  14382. }
  14383. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14384. #endif
  14385. }
  14386. /// Request to buy item(s) from cash shop.
  14387. /// 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)
  14388. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14389. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14390. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14391. 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 ){
  14392. 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 );
  14393. return;
  14394. }
  14395. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14396. }
  14397. /// Adoption System
  14398. ///
  14399. /// Adoption message (ZC_BABYMSG).
  14400. /// 0216 <msg>.L
  14401. /// msg:
  14402. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14403. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14404. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14405. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14406. {
  14407. int fd = sd->fd;
  14408. WFIFOHEAD(fd,6);
  14409. WFIFOW(fd,0) = 0x216;
  14410. WFIFOL(fd,2) = type;
  14411. WFIFOSET(fd,6);
  14412. }
  14413. /// Adoption confirmation (ZC_REQ_BABY).
  14414. /// 01f6 <account id>.L <char id>.L <name>.B
  14415. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14416. {
  14417. int fd = sd->fd;
  14418. WFIFOHEAD(fd,34);
  14419. WFIFOW(fd,0) = 0x1f6;
  14420. WFIFOL(fd,2) = src->status.account_id;
  14421. WFIFOL(fd,6) = p_id;
  14422. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14423. WFIFOSET(fd,34);
  14424. }
  14425. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14426. /// 01f9 <account id>.L
  14427. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14428. {
  14429. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14430. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14431. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14432. {
  14433. tsd->adopt_invite = sd->status.account_id;
  14434. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14435. }
  14436. }
  14437. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14438. /// 01f7 <account id>.L <char id>.L <answer>.L
  14439. /// answer:
  14440. /// 0 = rejected
  14441. /// 1 = accepted
  14442. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14443. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14444. int p1_id = RFIFOL(fd,info->pos[0]);
  14445. int p2_id = RFIFOL(fd,info->pos[1]);
  14446. int result = RFIFOL(fd,info->pos[2]);
  14447. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14448. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14449. int pid = sd->adopt_invite;
  14450. sd->adopt_invite = 0;
  14451. if( p1_sd == NULL || p2_sd == NULL )
  14452. return; // Both players need to be online
  14453. if( pid != p1_sd->status.account_id )
  14454. return; // Incorrect values
  14455. if( result == 0 )
  14456. return; // Rejected
  14457. pc_adoption(p1_sd, p2_sd, sd);
  14458. }
  14459. /// Convex Mirror (ZC_BOSS_INFO).
  14460. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14461. /// infoType:
  14462. /// BOSS_INFO_NOT = No boss on this map.
  14463. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14464. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14465. /// BOSS_INFO_DEAD = Boss is dead.
  14466. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14467. {
  14468. int fd = sd->fd;
  14469. WFIFOHEAD(fd,70);
  14470. memset(WFIFOP(fd,0),0,70);
  14471. WFIFOW(fd,0) = 0x293;
  14472. switch (flag) {
  14473. case BOSS_INFO_NOT:
  14474. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14475. // No data required
  14476. break;
  14477. case BOSS_INFO_ALIVE:
  14478. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14479. // Update X/Y
  14480. WFIFOL(fd,3) = md->bl.x;
  14481. WFIFOL(fd,7) = md->bl.y;
  14482. break;
  14483. case BOSS_INFO_ALIVE_WITHMSG:
  14484. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14485. // Current X/Y
  14486. WFIFOL(fd,3) = md->bl.x;
  14487. WFIFOL(fd,7) = md->bl.y;
  14488. break;
  14489. case BOSS_INFO_DEAD:
  14490. {
  14491. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14492. unsigned int seconds;
  14493. int hours, minutes;
  14494. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14495. hours = seconds / (60 * 60);
  14496. seconds = seconds - (60 * 60 * hours);
  14497. minutes = seconds / 60;
  14498. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14499. // Add respawn info
  14500. WFIFOW(fd,11) = hours; // Hours
  14501. WFIFOW(fd,13) = minutes; // Minutes
  14502. }
  14503. break;
  14504. }
  14505. if (md != NULL)
  14506. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14507. WFIFOSET(fd,70);
  14508. }
  14509. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14510. /// 02d6 <account id>.L
  14511. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14512. {
  14513. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14514. struct map_session_data* tsd = map_id2sd(aid);
  14515. if (!tsd)
  14516. return;
  14517. if (sd->bl.m != tsd->bl.m)
  14518. return;
  14519. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14520. clif_viewequip_ack(sd, tsd);
  14521. else
  14522. clif_msg(sd, VIEW_EQUIP_FAIL);
  14523. }
  14524. /// Request to a configuration.
  14525. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14526. /// type: see enum e_config_type
  14527. /// flag:
  14528. /// false = disabled
  14529. /// true = enabled
  14530. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14531. int cmd = RFIFOW(fd,0);
  14532. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14533. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14534. switch( type ){
  14535. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14536. sd->status.show_equip = flag;
  14537. break;
  14538. case CONFIG_CALL:
  14539. sd->status.disable_call = flag;
  14540. break;
  14541. case CONFIG_PET_AUTOFEED:
  14542. // Player can not click this if he does not have a pet
  14543. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14544. return;
  14545. }
  14546. sd->pd->pet.autofeed = flag;
  14547. break;
  14548. case CONFIG_HOMUNCULUS_AUTOFEED:
  14549. // Player can not click this if he does not have a homunculus or it is vaporized
  14550. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14551. return;
  14552. }
  14553. sd->hd->homunculus.autofeed = flag;
  14554. break;
  14555. default:
  14556. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14557. return;
  14558. }
  14559. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14560. }
  14561. /// Request to change party invitation tick.
  14562. /// value:
  14563. /// 0 = disabled
  14564. /// 1 = enabled
  14565. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14566. {
  14567. bool flag = RFIFOB(fd,6) ? true : false;
  14568. sd->status.allow_party = flag;
  14569. clif_partytickack(sd, flag);
  14570. }
  14571. /// Questlog System [Kevin] [Inkfish]
  14572. ///
  14573. /**
  14574. * Safe check to init packet len & quest num for player.
  14575. * @param def_len
  14576. * @param info_len Length of each quest info.
  14577. * @param avail_quests Avail quests that player has.
  14578. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14579. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14580. **/
  14581. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14582. (*limit_out) = (0xFFFF - def_len) / info_len;
  14583. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14584. (*len_out) = ((*limit_out) * info_len) + def_len;
  14585. }
  14586. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14587. std::string race_name;
  14588. switch( objective->race ){
  14589. case RC_FORMLESS: race_name = "Formless"; break;
  14590. case RC_UNDEAD: race_name = "Undead"; break;
  14591. case RC_BRUTE: race_name = "Brute"; break;
  14592. case RC_PLANT: race_name = "Plant"; break;
  14593. case RC_INSECT: race_name = "Insect"; break;
  14594. case RC_FISH: race_name = "Fish"; break;
  14595. case RC_DEMON: race_name = "Demon"; break;
  14596. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14597. case RC_ANGEL: race_name = "Angel"; break;
  14598. case RC_DRAGON: race_name = "Dragon"; break;
  14599. default:
  14600. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14601. // Fallthrough
  14602. case RC_ALL: race_name = ""; break;
  14603. }
  14604. std::string size_name;
  14605. switch( objective->size ){
  14606. case SZ_SMALL: size_name = "Small"; break;
  14607. case SZ_MEDIUM: size_name = "Medium"; break;
  14608. case SZ_BIG: size_name = "Large"; break;
  14609. default:
  14610. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14611. // Fallthrough
  14612. case SZ_ALL: size_name = ""; break;
  14613. }
  14614. std::string ele_name;
  14615. switch( objective->element ){
  14616. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14617. case ELE_WATER: ele_name = "Water Element"; break;
  14618. case ELE_EARTH: ele_name = "Earth Element"; break;
  14619. case ELE_FIRE: ele_name = "Fire Element"; break;
  14620. case ELE_WIND: ele_name = "Wind Element"; break;
  14621. case ELE_POISON: ele_name = "Poison Element"; break;
  14622. case ELE_HOLY: ele_name = "Holy Element"; break;
  14623. case ELE_DARK: ele_name = "Shadow Element"; break;
  14624. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14625. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14626. default:
  14627. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14628. // Fallthrough
  14629. case ELE_ALL: ele_name = ""; break;
  14630. }
  14631. std::string str;
  14632. if( !objective->map_name.empty() ){
  14633. str += objective->map_name;
  14634. }
  14635. if( !race_name.empty() ){
  14636. if( !str.empty() ){
  14637. str += ", ";
  14638. }
  14639. str += race_name;
  14640. }
  14641. if( !size_name.empty() ){
  14642. if( !str.empty() ){
  14643. str += ", ";
  14644. }
  14645. str += size_name;
  14646. }
  14647. if( !ele_name.empty() ){
  14648. if( !str.empty() ){
  14649. str += ", ";
  14650. }
  14651. str += ele_name;
  14652. }
  14653. return str;
  14654. }
  14655. /// Sends list of all quest states
  14656. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14657. /// 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)
  14658. /// 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)
  14659. void clif_quest_send_list(struct map_session_data *sd)
  14660. {
  14661. nullpo_retv(sd);
  14662. int fd = sd->fd;
  14663. int i;
  14664. int offset = 8;
  14665. int limit = 0;
  14666. #if PACKETVER >= 20141022
  14667. #if PACKETVER >= 20150513
  14668. int size = 22 + NAME_LENGTH;
  14669. #else
  14670. int size = 10 + NAME_LENGTH;
  14671. #endif
  14672. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14673. WFIFOHEAD(fd,i);
  14674. #if PACKETVER >= 20150513
  14675. WFIFOW(fd, 0) = 0x9f8;
  14676. #else
  14677. WFIFOW(fd, 0) = 0x97a;
  14678. #endif
  14679. WFIFOL(fd, 4) = limit;
  14680. for (i = 0; i < limit; i++) {
  14681. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14682. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14683. offset += 4;
  14684. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14685. offset++;
  14686. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14687. offset += 4;
  14688. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14689. offset += 4;
  14690. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14691. offset += 2;
  14692. if (!qi->objectives.empty()) {
  14693. std::shared_ptr<s_mob_db> mob;
  14694. for (int j = 0; j < qi->objectives.size(); j++) {
  14695. mob = mob_db.find(qi->objectives[j]->mob_id);
  14696. e_race race = qi->objectives[j]->race;
  14697. e_size size = qi->objectives[j]->size;
  14698. e_element element = qi->objectives[j]->element;
  14699. #if PACKETVER >= 20150513
  14700. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14701. offset += 4;
  14702. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14703. offset += 4;
  14704. #endif
  14705. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14706. offset += 4;
  14707. #if PACKETVER >= 20150513
  14708. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14709. offset += 2;
  14710. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14711. offset += 2;
  14712. #endif
  14713. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14714. offset += 2;
  14715. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14716. offset += 2;
  14717. if (mob && qi->objectives[j]->mob_id > 0)
  14718. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14719. else
  14720. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14721. offset += NAME_LENGTH;
  14722. }
  14723. }
  14724. }
  14725. WFIFOW(fd, 2) = offset;
  14726. WFIFOSET(fd, offset);
  14727. #else
  14728. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14729. WFIFOHEAD(fd,i);
  14730. WFIFOW(fd, 0) = 0x2b1;
  14731. WFIFOL(fd, 4) = limit;
  14732. for (i = 0; i < limit; i++) {
  14733. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14734. offset += 4;
  14735. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14736. offset += 1;
  14737. }
  14738. WFIFOW(fd, 2) = offset;
  14739. WFIFOSET(fd, offset);
  14740. #endif
  14741. }
  14742. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14743. /// 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
  14744. void clif_quest_send_mission(struct map_session_data *sd)
  14745. {
  14746. nullpo_retv(sd);
  14747. int fd = sd->fd;
  14748. int limit = 0;
  14749. int len = sd->avail_quests*104+8;
  14750. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14751. WFIFOHEAD(fd, len);
  14752. WFIFOW(fd, 0) = 0x2b2;
  14753. WFIFOW(fd, 2) = len;
  14754. WFIFOL(fd, 4) = limit;
  14755. for (int i = 0; i < limit; i++) {
  14756. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14757. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14758. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14759. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14760. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14761. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14762. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14763. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14764. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14765. if (mob && qi->objectives[j]->mob_id > 0)
  14766. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14767. else
  14768. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14769. }
  14770. }
  14771. WFIFOSET(fd, len);
  14772. }
  14773. /// Notification about a new quest
  14774. /// 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)
  14775. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14776. /// 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)
  14777. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14778. {
  14779. nullpo_retv(sd);
  14780. nullpo_retv(qd);
  14781. int fd = sd->fd;
  14782. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14783. if (!qi)
  14784. return;
  14785. #if PACKETVER >= 20150513
  14786. int cmd = 0x9f9;
  14787. #else
  14788. int cmd = 0x2b3;
  14789. #endif
  14790. WFIFOHEAD(fd, packet_len(cmd));
  14791. WFIFOW(fd, 0) = cmd;
  14792. WFIFOL(fd, 2) = qd->quest_id;
  14793. WFIFOB(fd, 6) = qd->state;
  14794. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14795. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14796. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14797. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14798. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14799. e_race race = qi->objectives[i]->race;
  14800. e_size size = qi->objectives[i]->size;
  14801. e_element element = qi->objectives[i]->element;
  14802. #if PACKETVER >= 20150513
  14803. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14804. offset += 4;
  14805. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14806. offset += 4;
  14807. #endif
  14808. 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
  14809. offset += 4;
  14810. #if PACKETVER >= 20150513
  14811. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14812. offset += 2;
  14813. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14814. offset += 2;
  14815. #endif
  14816. WFIFOW(fd, offset) = qd->count[i];
  14817. offset += 2;
  14818. if (mob && qi->objectives[i]->mob_id > 0)
  14819. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14820. else
  14821. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14822. offset += NAME_LENGTH;
  14823. }
  14824. WFIFOSET(fd, packet_len(cmd));
  14825. #if PACKETVER >= 20150513
  14826. int len = 4 + qi->objectives.size() * 12;
  14827. WFIFOHEAD(fd, len);
  14828. WFIFOW(fd, 0) = 0x8fe;
  14829. WFIFOW(fd, 2) = len;
  14830. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14831. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14832. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14833. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14834. WFIFOW(fd, offset + 10) = qd->count[i];
  14835. }
  14836. WFIFOSET(fd, len);
  14837. #endif
  14838. }
  14839. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14840. /// 02b4 <quest id>.L
  14841. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14842. {
  14843. int fd = sd->fd;
  14844. WFIFOHEAD(fd, packet_len(0x2b4));
  14845. WFIFOW(fd, 0) = 0x2b4;
  14846. WFIFOL(fd, 2) = quest_id;
  14847. WFIFOSET(fd, packet_len(0x2b4));
  14848. }
  14849. /// Notification of an update to the hunting mission counter
  14850. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14851. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14852. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  14853. {
  14854. int fd = sd->fd;
  14855. int offset = 6;
  14856. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14857. int len = qi->objectives.size() * 12 + 6;
  14858. #if PACKETVER >= 20150513
  14859. int cmd = 0x9fa;
  14860. #else
  14861. int cmd = 0x2b5;
  14862. #endif
  14863. WFIFOHEAD(fd, len);
  14864. WFIFOW(fd, 0) = cmd;
  14865. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14866. for (int i = 0; i < qi->objectives.size(); i++) {
  14867. WFIFOL(fd, offset) = qd->quest_id;
  14868. offset += 4;
  14869. #if PACKETVER >= 20150513
  14870. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14871. offset += 4;
  14872. #else
  14873. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14874. offset += 4;
  14875. #endif
  14876. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14877. offset += 2;
  14878. WFIFOW(fd, offset) = qd->count[i];
  14879. offset += 2;
  14880. }
  14881. WFIFOW(fd, 2) = offset;
  14882. WFIFOSET(fd, offset);
  14883. }
  14884. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14885. /// 02b6 <quest id>.L <active>.B
  14886. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14887. {
  14888. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14889. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14890. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14891. }
  14892. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14893. /// 02b7 <quest id>.L <active>.B
  14894. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14895. {
  14896. int fd = sd->fd;
  14897. WFIFOHEAD(fd, packet_len(0x2b7));
  14898. WFIFOW(fd, 0) = 0x2b7;
  14899. WFIFOL(fd, 2) = quest_id;
  14900. WFIFOB(fd, 6) = active;
  14901. WFIFOSET(fd, packet_len(0x2b7));
  14902. }
  14903. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14904. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14905. /// effect:
  14906. /// 0 = none
  14907. /// 1 = exclamation mark icon
  14908. /// 2 = question mark icon
  14909. /// color:
  14910. /// 0 = yellow
  14911. /// 1 = orange
  14912. /// 2 = green
  14913. /// 3 = purple
  14914. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14915. {
  14916. #if PACKETVER >= 20090218
  14917. nullpo_retv(sd);
  14918. nullpo_retv(bl);
  14919. int fd = sd->fd;
  14920. WFIFOHEAD(fd, packet_len(0x446));
  14921. WFIFOW(fd, 0) = 0x446;
  14922. WFIFOL(fd, 2) = bl->id;
  14923. WFIFOW(fd, 6) = bl->x;
  14924. WFIFOW(fd, 8) = bl->y;
  14925. WFIFOW(fd, 10) = effect;
  14926. WFIFOW(fd, 12) = color;
  14927. WFIFOSET(fd, packet_len(0x446));
  14928. #endif
  14929. }
  14930. /// Mercenary System
  14931. ///
  14932. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14933. /// 02a2 <var id>.W <value>.L
  14934. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14935. {
  14936. s_mercenary_data *md;
  14937. struct status_data *status;
  14938. int fd;
  14939. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14940. return;
  14941. fd = sd->fd;
  14942. status = &md->battle_status;
  14943. WFIFOHEAD(fd,packet_len(0x2a2));
  14944. WFIFOW(fd,0) = 0x2a2;
  14945. WFIFOW(fd,2) = type;
  14946. switch( type ) {
  14947. case SP_ATK1:
  14948. {
  14949. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14950. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14951. }
  14952. break;
  14953. case SP_MATK1:
  14954. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14955. break;
  14956. case SP_HIT:
  14957. WFIFOL(fd,4) = status->hit;
  14958. break;
  14959. case SP_CRITICAL:
  14960. WFIFOL(fd,4) = status->cri/10;
  14961. break;
  14962. case SP_DEF1:
  14963. WFIFOL(fd,4) = status->def;
  14964. break;
  14965. case SP_MDEF1:
  14966. WFIFOL(fd,4) = status->mdef;
  14967. break;
  14968. case SP_MERCFLEE:
  14969. WFIFOL(fd,4) = status->flee;
  14970. break;
  14971. case SP_ASPD:
  14972. WFIFOL(fd,4) = status->amotion;
  14973. break;
  14974. case SP_HP:
  14975. WFIFOL(fd,4) = status->hp;
  14976. break;
  14977. case SP_MAXHP:
  14978. WFIFOL(fd,4) = status->max_hp;
  14979. break;
  14980. case SP_SP:
  14981. WFIFOL(fd,4) = status->sp;
  14982. break;
  14983. case SP_MAXSP:
  14984. WFIFOL(fd,4) = status->max_sp;
  14985. break;
  14986. case SP_MERCKILLS:
  14987. WFIFOL(fd,4) = md->mercenary.kill_count;
  14988. break;
  14989. case SP_MERCFAITH:
  14990. WFIFOL(fd,4) = mercenary_get_faith(md);
  14991. break;
  14992. }
  14993. WFIFOSET(fd,packet_len(0x2a2));
  14994. }
  14995. /// Mercenary base status data (ZC_MER_INIT).
  14996. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14997. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14998. /// <calls>.L <kills>.L <atk range>.W
  14999. void clif_mercenary_info(struct map_session_data *sd)
  15000. {
  15001. int fd;
  15002. s_mercenary_data *md;
  15003. struct status_data *status;
  15004. int atk;
  15005. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15006. return;
  15007. fd = sd->fd;
  15008. status = &md->battle_status;
  15009. WFIFOHEAD(fd,packet_len(0x29b));
  15010. WFIFOW(fd,0) = 0x29b;
  15011. WFIFOL(fd,2) = md->bl.id;
  15012. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15013. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15014. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15015. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15016. WFIFOW(fd,10) = status->hit;
  15017. WFIFOW(fd,12) = status->cri/10;
  15018. WFIFOW(fd,14) = status->def;
  15019. WFIFOW(fd,16) = status->mdef;
  15020. WFIFOW(fd,18) = status->flee;
  15021. WFIFOW(fd,20) = status->amotion;
  15022. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15023. WFIFOW(fd,46) = md->db->lv;
  15024. WFIFOL(fd,48) = status->hp;
  15025. WFIFOL(fd,52) = status->max_hp;
  15026. WFIFOL(fd,56) = status->sp;
  15027. WFIFOL(fd,60) = status->max_sp;
  15028. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15029. WFIFOW(fd,68) = mercenary_get_faith(md);
  15030. WFIFOL(fd,70) = mercenary_get_calls(md);
  15031. WFIFOL(fd,74) = md->mercenary.kill_count;
  15032. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15033. WFIFOSET(fd,packet_len(0x29b));
  15034. }
  15035. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15036. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15037. void clif_mercenary_skillblock(struct map_session_data *sd)
  15038. {
  15039. s_mercenary_data *md;
  15040. int fd, len = 4;
  15041. if( sd == NULL || (md = sd->md) == NULL )
  15042. return;
  15043. fd = sd->fd;
  15044. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15045. WFIFOW(fd,0) = 0x29d;
  15046. for (const auto &it : md->db->skill) {
  15047. uint16 id = it.first;
  15048. if (!SKILL_CHK_MERC(id))
  15049. continue;
  15050. uint16 lv = it.second;
  15051. WFIFOW(fd,len) = id;
  15052. WFIFOL(fd,len+2) = skill_get_inf(id);
  15053. WFIFOW(fd,len+6) = lv;
  15054. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15055. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15056. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15057. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15058. len += 37;
  15059. }
  15060. WFIFOW(fd,2) = len;
  15061. WFIFOSET(fd,len);
  15062. }
  15063. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15064. /// 029f <command>.B
  15065. /// 1 = mercenary information
  15066. /// 2 = delete
  15067. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  15068. {
  15069. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15070. if( sd->md == NULL )
  15071. return;
  15072. if( option == 2 ) mercenary_delete(sd->md, 2);
  15073. }
  15074. /// Mercenary Message
  15075. /// message:
  15076. /// 0 = Mercenary soldier's duty hour is over.
  15077. /// 1 = Your mercenary soldier has been killed.
  15078. /// 2 = Your mercenary soldier has been fired.
  15079. /// 3 = Your mercenary soldier has ran away.
  15080. void clif_mercenary_message(struct map_session_data* sd, int message){
  15081. clif_msg(sd, MERC_MSG_BASE + message);
  15082. }
  15083. /// Notification about the remaining time of a rental item.
  15084. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15085. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  15086. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15087. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15088. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15089. p.itemId = client_nameid( nameid );
  15090. p.seconds = seconds;
  15091. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15092. }
  15093. /// Deletes a rental item from client's inventory.
  15094. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15095. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  15096. // '<ItemName>' item has been deleted from the Inventory
  15097. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15098. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15099. p.index = client_index( index );
  15100. p.itemId = client_nameid( nameid );
  15101. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15102. }
  15103. /// Book Reading (ZC_READ_BOOK).
  15104. /// 0294 <book id>.L <page>.L
  15105. void clif_readbook(int fd, int book_id, int page)
  15106. {
  15107. WFIFOHEAD(fd,packet_len(0x294));
  15108. WFIFOW(fd,0) = 0x294;
  15109. WFIFOL(fd,2) = book_id;
  15110. WFIFOL(fd,6) = page;
  15111. WFIFOSET(fd,packet_len(0x294));
  15112. }
  15113. /// Battlegrounds
  15114. ///
  15115. /// Updates HP bar of a camp member.
  15116. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15117. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15118. void clif_bg_hp(struct map_session_data *sd) {
  15119. #if PACKETVER < 20140613
  15120. unsigned char buf[34];
  15121. const int cmd = 0x2e0;
  15122. #else
  15123. unsigned char buf[14];
  15124. const int cmd = 0xa0e;
  15125. #endif
  15126. nullpo_retv(sd);
  15127. WBUFW(buf,0) = cmd;
  15128. WBUFL(buf,2) = sd->status.account_id;
  15129. #if PACKETVER < 20140613
  15130. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15131. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15132. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15133. WBUFW(buf,32) = 100;
  15134. } else {
  15135. WBUFW(buf,30) = sd->battle_status.hp;
  15136. WBUFW(buf,32) = sd->battle_status.max_hp;
  15137. }
  15138. #else
  15139. if( sd->battle_status.max_hp > INT32_MAX ) {
  15140. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15141. WBUFL(buf,10) = 100;
  15142. } else {
  15143. WBUFL(buf,6) = sd->battle_status.hp;
  15144. WBUFL(buf,10) = sd->battle_status.max_hp;
  15145. }
  15146. #endif
  15147. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15148. }
  15149. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15150. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15151. void clif_bg_xy(struct map_session_data *sd)
  15152. {
  15153. unsigned char buf[36];
  15154. nullpo_retv(sd);
  15155. WBUFW(buf,0)=0x2df;
  15156. WBUFL(buf,2)=sd->status.account_id;
  15157. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15158. WBUFW(buf,30)=sd->status.class_;
  15159. WBUFW(buf,32)=sd->bl.x;
  15160. WBUFW(buf,34)=sd->bl.y;
  15161. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15162. }
  15163. void clif_bg_xy_remove(struct map_session_data *sd)
  15164. {
  15165. unsigned char buf[36];
  15166. nullpo_retv(sd);
  15167. WBUFW(buf,0)=0x2df;
  15168. WBUFL(buf,2)=sd->status.account_id;
  15169. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15170. WBUFW(buf,30)=0;
  15171. WBUFW(buf,32)=-1;
  15172. WBUFW(buf,34)=-1;
  15173. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15174. }
  15175. /// Notifies clients of a battleground message.
  15176. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15177. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15178. struct map_session_data *sd = bg_getavailablesd( bg );
  15179. if( sd == nullptr ){
  15180. return;
  15181. }
  15182. // limit length
  15183. len = min( len + 1, CHAT_SIZE_MAX );
  15184. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15185. WBUFW(buf,0) = 0x2dc;
  15186. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15187. WBUFL(buf,4) = src_id;
  15188. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15189. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15190. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15191. }
  15192. /// Validates and processes battlechat messages.
  15193. /// All messages that are sent after enabling battleground chat with /battlechat.
  15194. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15195. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  15196. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15197. if( !clif_process_message( sd, false, name, message, output ) )
  15198. return;
  15199. bg_send_message(sd, output, strlen(output) );
  15200. }
  15201. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15202. /// 02de <camp A points>.W <camp B points>.W
  15203. void clif_bg_updatescore(int16 m)
  15204. {
  15205. struct block_list bl;
  15206. unsigned char buf[6];
  15207. struct map_data *mapdata = map_getmapdata(m);
  15208. bl.id = 0;
  15209. bl.type = BL_NUL;
  15210. bl.m = m;
  15211. WBUFW(buf,0) = 0x2de;
  15212. WBUFW(buf,2) = mapdata->bgscore_lion;
  15213. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15214. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15215. }
  15216. void clif_bg_updatescore_single(struct map_session_data *sd)
  15217. {
  15218. int fd;
  15219. nullpo_retv(sd);
  15220. fd = sd->fd;
  15221. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15222. WFIFOHEAD(fd,packet_len(0x2de));
  15223. WFIFOW(fd,0) = 0x2de;
  15224. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15225. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15226. WFIFOSET(fd,packet_len(0x2de));
  15227. }
  15228. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15229. /// 02dd <account id>.L <name>.24B <camp>.W
  15230. void clif_sendbgemblem_area(struct map_session_data *sd)
  15231. {
  15232. unsigned char buf[33];
  15233. nullpo_retv(sd);
  15234. WBUFW(buf, 0) = 0x2dd;
  15235. WBUFL(buf,2) = sd->bl.id;
  15236. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15237. WBUFW(buf,30) = sd->bg_id;
  15238. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15239. }
  15240. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15241. {
  15242. nullpo_retv(sd);
  15243. WFIFOHEAD(fd,32);
  15244. WFIFOW(fd,0) = 0x2dd;
  15245. WFIFOL(fd,2) = sd->bl.id;
  15246. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15247. WFIFOW(fd,30) = sd->bg_id;
  15248. WFIFOSET(fd,packet_len(0x2dd));
  15249. }
  15250. /// Battlegrounds queue incoming apply request from client.
  15251. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15252. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15253. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15254. {
  15255. if (!battle_config.feature_bgqueue)
  15256. return;
  15257. nullpo_retv(sd);
  15258. short type = RFIFOW(fd,2);
  15259. char name[NAME_LENGTH];
  15260. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15261. if (sd->bg_queue_id > 0) {
  15262. //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);
  15263. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15264. return;
  15265. } else if (type == 1) // Solo
  15266. bg_queue_join_solo(name, sd);
  15267. else if (type == 2) // Party
  15268. bg_queue_join_party(name, sd);
  15269. else if (type == 4) // Guild
  15270. bg_queue_join_guild(name, sd);
  15271. else {
  15272. 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);
  15273. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15274. return;
  15275. }
  15276. }
  15277. /// Outgoing battlegrounds queue apply result.
  15278. /// Result types: @see e_bg_queue_apply_ack
  15279. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15280. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15281. {
  15282. nullpo_retv(sd);
  15283. int fd = sd->fd;
  15284. WFIFOHEAD(fd, packet_len(0x8d8));
  15285. WFIFOW(fd,0) = 0x8d8;
  15286. WFIFOB(fd,2) = result;
  15287. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15288. WFIFOSET(fd, packet_len(0x8d8));
  15289. }
  15290. /// Outgoing battlegrounds queue apply notification.
  15291. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15292. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15293. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15294. {
  15295. nullpo_retv(sd);
  15296. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15297. if (queue == nullptr) {
  15298. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15299. return;
  15300. }
  15301. int fd = sd->fd;
  15302. WFIFOHEAD(fd, packet_len(0x8d9));
  15303. WFIFOW(fd,0) = 0x8d9;
  15304. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15305. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15306. WFIFOSET(fd, packet_len(0x8d9));
  15307. }
  15308. /// Battlegrounds queue outgoing cancel result.
  15309. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15310. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15311. {
  15312. nullpo_retv(sd);
  15313. int fd = sd->fd;
  15314. WFIFOHEAD(fd, packet_len(0x8d8));
  15315. WFIFOW(fd,0) = 0x8db;
  15316. WFIFOB(fd,2) = success;
  15317. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15318. WFIFOSET(fd, packet_len(0x8d8));
  15319. }
  15320. /// Battlegrounds queue incoming cancel request from client.
  15321. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15322. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15323. {
  15324. if (!battle_config.feature_bgqueue)
  15325. return;
  15326. nullpo_retv(sd);
  15327. bool success;
  15328. if (sd->bg_queue_id > 0) {
  15329. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15330. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15331. 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.
  15332. else
  15333. success = bg_queue_leave(sd);
  15334. } else {
  15335. 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);
  15336. success = false;
  15337. }
  15338. char name[NAME_LENGTH];
  15339. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15340. clif_bg_queue_cancel_result(success, name, sd);
  15341. }
  15342. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15343. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15344. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15345. {
  15346. nullpo_retv(sd);
  15347. int fd = sd->fd;
  15348. WFIFOHEAD(fd, packet_len(0x8df));
  15349. WFIFOW(fd,0) = 0x8df;
  15350. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15351. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15352. WFIFOSET(fd, packet_len(0x8df));
  15353. }
  15354. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15355. /// Result types: 1(Accept), 2(Decline).
  15356. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15357. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15358. {
  15359. nullpo_retv(sd);
  15360. if(sd->bg_queue_id > 0) {
  15361. uint8 result = RFIFOB(fd, 2);
  15362. if(result == 1) { // Accept
  15363. bg_queue_on_accept_invite(sd);
  15364. } else if(result == 2) { // Decline
  15365. bg_queue_leave(sd);
  15366. clif_bg_queue_entry_init(sd);
  15367. }
  15368. }
  15369. }
  15370. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15371. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15372. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15373. {
  15374. nullpo_retv(sd);
  15375. int fd = sd->fd;
  15376. WFIFOHEAD(fd, packet_len(0x8e1));
  15377. WFIFOW(fd,0) = 0x8e1;
  15378. WFIFOB(fd,2) = result;
  15379. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15380. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15381. WFIFOSET(fd, packet_len(0x8e1));
  15382. }
  15383. /// Battlegrounds queue incoming queue number request from client.
  15384. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15385. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15386. {
  15387. nullpo_retv(sd);
  15388. char name[NAME_LENGTH];
  15389. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15390. clif_bg_queue_apply_notify(name, sd);
  15391. }
  15392. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15393. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15394. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15395. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15396. {
  15397. nullpo_retv(sd);
  15398. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15399. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15400. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15401. }
  15402. /// Custom Fonts (ZC_NOTIFY_FONT).
  15403. /// 02ef <account_id>.L <font id>.W
  15404. void clif_font(struct map_session_data *sd)
  15405. {
  15406. #if PACKETVER >= 20080102
  15407. unsigned char buf[8];
  15408. nullpo_retv(sd);
  15409. WBUFW(buf,0) = 0x2ef;
  15410. WBUFL(buf,2) = sd->bl.id;
  15411. WBUFW(buf,6) = sd->status.font;
  15412. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15413. #endif
  15414. }
  15415. /// Required to start the instancing information window on Client
  15416. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15417. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15418. void clif_instance_create(int instance_id, int num)
  15419. {
  15420. #if PACKETVER >= 20071128
  15421. struct map_session_data *sd = NULL;
  15422. enum send_target target = PARTY;
  15423. unsigned char buf[65];
  15424. instance_getsd(instance_id, sd, &target);
  15425. if (!sd)
  15426. return;
  15427. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15428. if (!db)
  15429. return;
  15430. WBUFW(buf,0) = 0x2cb;
  15431. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15432. WBUFW(buf,63) = num;
  15433. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15434. #endif
  15435. return;
  15436. }
  15437. /// To announce Instancing queue creation if no maps available
  15438. /// S 0x2cc <Standby Position>.W
  15439. void clif_instance_changewait(int instance_id, int num)
  15440. {
  15441. #if PACKETVER >= 20071128
  15442. struct map_session_data *sd = NULL;
  15443. enum send_target target = PARTY;
  15444. unsigned char buf[4];
  15445. instance_getsd(instance_id, sd, &target);
  15446. if (!sd)
  15447. return;
  15448. WBUFW(buf,0) = 0x2cc;
  15449. WBUFW(buf,2) = num;
  15450. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15451. #endif
  15452. return;
  15453. }
  15454. /// Notify the current status to members
  15455. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15456. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15457. {
  15458. #if PACKETVER >= 20071128
  15459. struct map_session_data *sd = NULL;
  15460. enum send_target target = PARTY;
  15461. unsigned char buf[71];
  15462. instance_getsd(instance_id, sd, &target);
  15463. if (!sd)
  15464. return;
  15465. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15466. if (!db)
  15467. return;
  15468. WBUFW(buf,0) = 0x2cd;
  15469. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15470. WBUFL(buf,63) = limit1;
  15471. WBUFL(buf,67) = limit2;
  15472. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15473. #endif
  15474. return;
  15475. }
  15476. /// Notify a status change to members
  15477. /// S 0x2ce <Message ID>.L
  15478. /// 0 = Notification (EnterLimitDate update?)
  15479. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15480. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15481. /// 3 = The Memorial Dungeon has been removed.
  15482. /// 4 = Create failure (removes the instance window)
  15483. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15484. {
  15485. #if PACKETVER >= 20071128
  15486. struct map_session_data *sd = NULL;
  15487. enum send_target target = PARTY;
  15488. unsigned char buf[10];
  15489. instance_getsd(instance_id, sd, &target);
  15490. if (!sd)
  15491. return;
  15492. WBUFW(buf,0) = 0x2ce;
  15493. WBUFL(buf,2) = type;
  15494. WBUFL(buf,6) = limit;
  15495. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15496. #endif
  15497. return;
  15498. }
  15499. /// Destroy an instance from the status window
  15500. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15501. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15502. {
  15503. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15504. return;
  15505. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15506. switch (p->command) {
  15507. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15508. instance_destroy_command(sd);
  15509. break;
  15510. }
  15511. }
  15512. void clif_instance_info( struct map_session_data& sd ){
  15513. if( sd.instance_id > 0 ){
  15514. instance_reqinfo( &sd, sd.instance_id );
  15515. }
  15516. if( sd.status.party_id > 0 ){
  15517. struct party_data* p = party_search( sd.status.party_id );
  15518. if( p != nullptr && p->instance_id > 0 ){
  15519. instance_reqinfo( &sd, p->instance_id );
  15520. }
  15521. }
  15522. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15523. instance_reqinfo( &sd, sd.guild->instance_id );
  15524. }
  15525. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15526. instance_reqinfo( &sd, sd.clan->instance_id );
  15527. }
  15528. }
  15529. /// Notifies clients about item picked up by a party member.
  15530. /// 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)
  15531. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15532. #if PACKETVER >= 20071002
  15533. nullpo_retv( sd );
  15534. nullpo_retv( item_data );
  15535. struct item_data* id = itemdb_search( item_data->nameid );
  15536. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15537. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15538. p.AID = sd->status.account_id;
  15539. p.itemId = client_nameid( item_data->nameid );
  15540. p.identified = item_data->identify;
  15541. p.damaged = item_data->attribute;
  15542. p.refine = item_data->refine;
  15543. clif_addcards( &p.slot, item_data );
  15544. p.location = id->equip; // equip location
  15545. p.itemType = itemtype( id->nameid ); // item type
  15546. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15547. p.grade = item_data->enchantgrade;
  15548. #endif
  15549. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15550. #endif
  15551. }
  15552. /** Display gained exp.
  15553. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15554. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15555. * amount: INT32_MIN ~ INT32_MAX
  15556. * var id:
  15557. * SP_BASEEXP, SP_JOBEXP
  15558. * exp type:
  15559. * 0 = normal exp gained/lost
  15560. * 1 = quest exp gained/lost
  15561. * @param sd Player
  15562. * @param exp EXP value gained/loss
  15563. * @param type SP_BASEEXP, SP_JOBEXP
  15564. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15565. * @param lost True:if losing EXP
  15566. */
  15567. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15568. {
  15569. int fd;
  15570. int offset;
  15571. #if PACKETVER >= 20170830
  15572. int cmd = 0xacc;
  15573. #else
  15574. int cmd = 0x7f6;
  15575. #endif
  15576. nullpo_retv(sd);
  15577. fd = sd->fd;
  15578. WFIFOHEAD(fd, packet_len(cmd));
  15579. WFIFOW(fd,0) = cmd;
  15580. WFIFOL(fd,2) = sd->bl.id;
  15581. #if PACKETVER >= 20170830
  15582. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15583. offset = 4;
  15584. #else
  15585. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15586. offset = 0;
  15587. #endif
  15588. WFIFOW(fd,10+offset) = type;
  15589. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15590. WFIFOSET(fd,packet_len(cmd));
  15591. }
  15592. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15593. /// type:
  15594. /// 0 = Displays 'value' for 5 seconds.
  15595. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15596. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15597. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15598. /// value:
  15599. /// 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).
  15600. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15601. {
  15602. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15603. WFIFOW(sd->fd,0) = 0x1b1;
  15604. WFIFOB(sd->fd,2) = type;
  15605. WFIFOL(sd->fd,3) = value;
  15606. WFIFOSET(sd->fd, packet_len(0x1b1));
  15607. }
  15608. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15609. /// 021d <state>.L
  15610. /// state:
  15611. /// 0 = Full effects
  15612. /// 1 = Reduced effects
  15613. ///
  15614. /// NOTE: The state is used on Aegis for sending skill unit packet
  15615. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15616. /// whenever possible. Due to the way the decision check is
  15617. /// constructed, this state tracking was rendered useless,
  15618. /// as the only skill unit, that is sent with 0x1c9 is
  15619. /// Graffiti.
  15620. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15621. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15622. sd->state.lesseffect = ( isLess != 0 );
  15623. }
  15624. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15625. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15626. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15627. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15628. int type = RFIFOL(fd,info->pos[1]);
  15629. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15630. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15631. if( sd->state.trading || sd->npc_shopid )
  15632. return;
  15633. if( flag == 0 || n == 0) {
  15634. clif_menuskill_clear(sd);
  15635. return; // Canceled by player.
  15636. }
  15637. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15638. clif_menuskill_clear(sd);
  15639. return; // Prevent hacking.
  15640. }
  15641. switch( type ) {
  15642. case 0: // Change Material
  15643. skill_changematerial(sd,n,item_list);
  15644. break;
  15645. case 1: // Level 1: Pure to Rough
  15646. case 2: // Level 2: Rough to Pure
  15647. skill_elementalanalysis(sd,n,type,item_list);
  15648. break;
  15649. }
  15650. clif_menuskill_clear(sd);
  15651. return;
  15652. }
  15653. /*==========================================
  15654. * Elemental System
  15655. *==========================================*/
  15656. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15657. s_elemental_data *ed;
  15658. struct status_data *status;
  15659. int fd;
  15660. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15661. return;
  15662. fd = sd->fd;
  15663. status = &ed->battle_status;
  15664. WFIFOHEAD(fd,8);
  15665. WFIFOW(fd,0) = 0x81e;
  15666. WFIFOW(fd,2) = type;
  15667. switch( type ) {
  15668. case SP_HP:
  15669. WFIFOL(fd,4) = status->hp;
  15670. break;
  15671. case SP_MAXHP:
  15672. WFIFOL(fd,4) = status->max_hp;
  15673. break;
  15674. case SP_SP:
  15675. WFIFOL(fd,4) = status->sp;
  15676. break;
  15677. case SP_MAXSP:
  15678. WFIFOL(fd,4) = status->max_sp;
  15679. break;
  15680. }
  15681. WFIFOSET(fd,8);
  15682. }
  15683. void clif_elemental_info(struct map_session_data *sd) {
  15684. int fd;
  15685. s_elemental_data *ed;
  15686. struct status_data *status;
  15687. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15688. return;
  15689. fd = sd->fd;
  15690. status = &ed->battle_status;
  15691. WFIFOHEAD(fd,22);
  15692. WFIFOW(fd, 0) = 0x81d;
  15693. WFIFOL(fd, 2) = ed->bl.id;
  15694. WFIFOL(fd, 6) = status->hp;
  15695. WFIFOL(fd,10) = status->max_hp;
  15696. WFIFOL(fd,14) = status->sp;
  15697. WFIFOL(fd,18) = status->max_sp;
  15698. WFIFOSET(fd,22);
  15699. }
  15700. /// Buying Store System
  15701. ///
  15702. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15703. /// 0810 <slots>.B
  15704. void clif_buyingstore_open(struct map_session_data* sd)
  15705. {
  15706. int fd = sd->fd;
  15707. WFIFOHEAD(fd,packet_len(0x810));
  15708. WFIFOW(fd,0) = 0x810;
  15709. WFIFOB(fd,2) = sd->buyingstore.slots;
  15710. WFIFOSET(fd,packet_len(0x810));
  15711. }
  15712. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15713. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15714. /// result:
  15715. /// 0 = cancel
  15716. /// 1 = open
  15717. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15718. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15719. // TODO: Make this check global for all variable length packets.
  15720. // minimum packet length
  15721. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15722. 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 );
  15723. return;
  15724. }
  15725. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15726. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15727. return;
  15728. }
  15729. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15730. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15731. return;
  15732. }
  15733. char storename[MESSAGE_SIZE];
  15734. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15735. // so that buyingstore_create knows, how many elements it has access to
  15736. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15737. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15738. 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 ) );
  15739. return;
  15740. }
  15741. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15742. }
  15743. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15744. /// 0812 <result>.W <total weight>.L
  15745. /// result:
  15746. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15747. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15748. /// 8 = "No sale (purchase) information available." (0x705)
  15749. /// ? = nothing
  15750. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15751. {
  15752. int fd = sd->fd;
  15753. WFIFOHEAD(fd,packet_len(0x812));
  15754. WFIFOW(fd,0) = 0x812;
  15755. WFIFOW(fd,2) = result;
  15756. WFIFOL(fd,4) = weight;
  15757. WFIFOSET(fd,packet_len(0x812));
  15758. }
  15759. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15760. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15761. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15762. nullpo_retv( sd );
  15763. int fd = sd->fd;
  15764. if( !session_isActive( fd ) ){
  15765. return;
  15766. }
  15767. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15768. WFIFOHEAD( fd, length );
  15769. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15770. p->packetType = 0x813;
  15771. p->packetLength = length;
  15772. p->AID = sd->bl.id;
  15773. p->zenyLimit = sd->buyingstore.zenylimit;
  15774. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15775. p->items[i].price = sd->buyingstore.items[i].price;
  15776. p->items[i].amount = sd->buyingstore.items[i].amount;
  15777. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15778. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15779. }
  15780. WFIFOSET( fd, p->packetLength );
  15781. }
  15782. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15783. /// 0814 <account id>.L <store name>.80B
  15784. void clif_buyingstore_entry( struct map_session_data& sd, struct block_list* tbl ){
  15785. #if PACKETVER >= 20100420
  15786. enum send_target target;
  15787. if( tbl == nullptr ){
  15788. tbl = &sd.bl;
  15789. target = AREA_WOS;
  15790. }else{
  15791. target = SELF;
  15792. }
  15793. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15794. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15795. p.makerAID = sd.status.account_id;
  15796. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15797. clif_send( &p, sizeof( p ), tbl, target );
  15798. #endif
  15799. }
  15800. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15801. /// 0815
  15802. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15803. {
  15804. buyingstore_close(sd);
  15805. }
  15806. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15807. /// 0816 <account id>.L
  15808. void clif_buyingstore_disappear_entry( struct map_session_data& sd, struct block_list* tbl ){
  15809. #if PACKETVER >= 20100309
  15810. enum send_target target;
  15811. if( tbl == nullptr ){
  15812. tbl = &sd.bl;
  15813. target = AREA_WOS;
  15814. }else{
  15815. target = SELF;
  15816. }
  15817. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15818. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15819. p.makerAID = sd.status.account_id;
  15820. clif_send( &p, sizeof( p ), tbl, target );
  15821. #endif
  15822. }
  15823. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15824. /// 0817 <account id>.L
  15825. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15826. {
  15827. uint32 account_id;
  15828. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15829. buyingstore_open(sd, account_id);
  15830. }
  15831. /// Sends buying store item list.
  15832. /// 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)
  15833. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15834. nullpo_retv( sd );
  15835. nullpo_retv( pl_sd );
  15836. int fd = sd->fd;
  15837. if( !session_isActive( fd ) ){
  15838. return;
  15839. }
  15840. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15841. WFIFOHEAD( fd, length );
  15842. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15843. p->packetType = 0x818;
  15844. p->packetLength = length;
  15845. p->AID = pl_sd->bl.id;
  15846. p->storeId = pl_sd->buyer_id;
  15847. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15848. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15849. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15850. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15851. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15852. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15853. }
  15854. WFIFOSET( fd, p->packetLength );
  15855. }
  15856. /// Request to sell items to a buying store.
  15857. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15858. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15859. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15860. // minimum packet length
  15861. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15862. 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 );
  15863. return;
  15864. }
  15865. // so that buyingstore_trade knows, how many elements it has access to
  15866. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15867. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15868. 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 ) );
  15869. return;
  15870. }
  15871. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15872. }
  15873. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15874. /// 081a <result>.W
  15875. /// result:
  15876. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15877. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15878. /// ? = nothing
  15879. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15880. {
  15881. int fd = sd->fd;
  15882. WFIFOHEAD(fd,packet_len(0x81a));
  15883. WFIFOW(fd,0) = 0x81a;
  15884. WFIFOW(fd,2) = result;
  15885. WFIFOSET(fd,packet_len(0x81a));
  15886. }
  15887. /// Updates the zeny limit and an item in the buying store item list.
  15888. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15889. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15890. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15891. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15892. p.packetType = buyingStoreUpdateItemType;
  15893. p.itemId = client_nameid( nameid );
  15894. p.amount = amount;
  15895. p.zenyLimit = sd->buyingstore.zenylimit;
  15896. #if PACKETVER >= 20141016
  15897. p.zeny = zeny;
  15898. p.charId = char_id; // GID
  15899. p.updateTime = (int)time(NULL);
  15900. #endif
  15901. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15902. }
  15903. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15904. /// 081c <index>.W <amount>.W <price>.L
  15905. /// message:
  15906. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15907. ///
  15908. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15909. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15910. {
  15911. int fd = sd->fd;
  15912. WFIFOHEAD(fd,packet_len(0x81c));
  15913. WFIFOW(fd,0) = 0x81c;
  15914. WFIFOW(fd,2) = client_index( index );
  15915. WFIFOW(fd,4) = amount;
  15916. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15917. WFIFOSET(fd,packet_len(0x81c));
  15918. }
  15919. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15920. /// 0824 <result>.W <name id>.W
  15921. /// result:
  15922. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15923. /// 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)
  15924. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15925. /// ? = nothing
  15926. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  15927. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15928. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15929. p.result = result;
  15930. p.itemId = client_nameid( nameid );
  15931. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15932. }
  15933. /// Search Store Info System
  15934. ///
  15935. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15936. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15937. /// type:
  15938. /// 0 = Vending
  15939. /// 1 = Buying Store
  15940. ///
  15941. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15942. /// amount of card slots. If the client does not know about the item it
  15943. /// cannot be searched.
  15944. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  15945. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15946. // minimum packet length
  15947. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15948. 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 );
  15949. return;
  15950. }
  15951. // check, if there is enough data for the claimed count of items
  15952. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15953. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15954. 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 ) );
  15955. return;
  15956. }
  15957. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15958. if( count < p->itemsCount + p->cardsCount ){
  15959. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15960. return;
  15961. }
  15962. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15963. }
  15964. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15965. /// 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 }*
  15966. /// is first page:
  15967. /// 0 = appends to existing results
  15968. /// 1 = clears previous results before displaying this result set
  15969. /// is next page:
  15970. /// 0 = no "next" label
  15971. /// 1 = "next" label to retrieve more results
  15972. void clif_search_store_info_ack( struct map_session_data* sd ){
  15973. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  15974. nullpo_retv( sd );
  15975. int fd = sd->fd;
  15976. if( !session_isActive( fd ) ){
  15977. return;
  15978. }
  15979. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15980. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  15981. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15982. WFIFOHEAD( fd, len );
  15983. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15984. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15985. p->packetLength = len;
  15986. p->firstPage = !sd->searchstore.pages;
  15987. p->nextPage = searchstore_querynext( sd );
  15988. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15989. for( int i = 0; i < end - start; i++ ) {
  15990. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  15991. p->items[i].storeId = ssitem->store_id;
  15992. p->items[i].AID = ssitem->account_id;
  15993. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15994. p->items[i].itemId = client_nameid( ssitem->nameid );
  15995. p->items[i].itemType = itemtype( ssitem->nameid );
  15996. p->items[i].price = ssitem->price;
  15997. p->items[i].amount = ssitem->amount;
  15998. p->items[i].refine = ssitem->refine;
  15999. // make-up an item for clif_addcards
  16000. struct item it = {};
  16001. for( int j = 0; j < MAX_SLOTS; j++ ){
  16002. it.card[j] = ssitem->card[j];
  16003. }
  16004. it.nameid = ssitem->nameid;
  16005. it.amount = ssitem->amount;
  16006. clif_addcards( &p->items[i].slot, &it );
  16007. #if PACKETVER >= 20150226
  16008. clif_add_random_options( p->items[i].option_data, &it );
  16009. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16010. p->items[i].grade = ssitem->enchantgrade;
  16011. #endif
  16012. #endif
  16013. }
  16014. WFIFOSET( fd, len );
  16015. #endif
  16016. }
  16017. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16018. /// 0837 <reason>.B
  16019. /// reason:
  16020. /// 0 = "No matching stores were found." (0x70b)
  16021. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16022. /// 2 = "You cannot search anymore." (0x706)
  16023. /// 3 = "You cannot search yet." (0x708)
  16024. /// 4 = "No sale (purchase) information available." (0x705)
  16025. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  16026. {
  16027. int fd = sd->fd;
  16028. WFIFOHEAD(fd,packet_len(0x837));
  16029. WFIFOW(fd,0) = 0x837;
  16030. WFIFOB(fd,2) = reason;
  16031. WFIFOSET(fd,packet_len(0x837));
  16032. }
  16033. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16034. /// 0838
  16035. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  16036. {
  16037. searchstore_next(sd);
  16038. }
  16039. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16040. /// 083a <type>.W <remaining uses>.B
  16041. /// type:
  16042. /// 0 = Search Stores
  16043. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16044. void clif_open_search_store_info(struct map_session_data* sd)
  16045. {
  16046. int fd = sd->fd;
  16047. WFIFOHEAD(fd,packet_len(0x83a));
  16048. WFIFOW(fd,0) = 0x83a;
  16049. WFIFOW(fd,2) = sd->searchstore.effect;
  16050. #if PACKETVER > 20100701
  16051. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16052. #endif
  16053. WFIFOSET(fd,packet_len(0x83a));
  16054. }
  16055. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16056. /// 083b
  16057. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  16058. {
  16059. searchstore_close(sd);
  16060. }
  16061. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16062. /// 083c <account id>.L <store id>.L <nameid>.W
  16063. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  16064. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16065. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16066. }
  16067. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16068. /// 083d <xPos>.W <yPos>.W
  16069. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  16070. {
  16071. int fd = sd->fd;
  16072. WFIFOHEAD(fd,packet_len(0x83d));
  16073. WFIFOW(fd,0) = 0x83d;
  16074. WFIFOW(fd,2) = x;
  16075. WFIFOW(fd,4) = y;
  16076. WFIFOSET(fd,packet_len(0x83d));
  16077. }
  16078. /// Parse function for packet debugging.
  16079. void clif_parse_debug(int fd,struct map_session_data *sd)
  16080. {
  16081. int cmd, packet_len;
  16082. // clif_parse ensures, that there is at least 2 bytes of data
  16083. cmd = RFIFOW(fd,0);
  16084. if( sd ) {
  16085. packet_len = packet_db[cmd].len;
  16086. if( packet_len == 0 )
  16087. {// unknown
  16088. packet_len = RFIFOREST(fd);
  16089. }
  16090. else if( packet_len == -1 )
  16091. {// variable length
  16092. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16093. }
  16094. 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);
  16095. }
  16096. else
  16097. {
  16098. packet_len = RFIFOREST(fd);
  16099. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16100. }
  16101. ShowDump(RFIFOP(fd,0), packet_len);
  16102. }
  16103. /*==========================================
  16104. * Server tells client to display a window similar to Magnifier (item) one
  16105. * Server populates the window with avilable elemental converter options according to player's inventory
  16106. *------------------------------------------*/
  16107. void clif_elementalconverter_list( struct map_session_data *sd ){
  16108. nullpo_retv( sd );
  16109. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16110. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16111. int count = 0;
  16112. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16113. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16114. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16115. count++;
  16116. }
  16117. }
  16118. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16119. clif_send( p, p->packetLength, &sd->bl, SELF );
  16120. if( count > 0 ){
  16121. sd->menuskill_id = SA_CREATECON;
  16122. sd->menuskill_val = count;
  16123. }
  16124. }
  16125. /**
  16126. * Rune Knight
  16127. **/
  16128. void clif_millenniumshield(struct block_list *bl, short shields) {
  16129. #if PACKETVER >= 20081217
  16130. unsigned char buf[10];
  16131. WBUFW(buf,0) = 0x440;
  16132. WBUFL(buf,2) = bl->id;
  16133. WBUFW(buf,6) = shields;
  16134. WBUFW(buf,8) = 0;
  16135. clif_send(buf,packet_len(0x440),bl,AREA);
  16136. #endif
  16137. }
  16138. /**
  16139. * Mechanic
  16140. **/
  16141. /*==========================================
  16142. * Magic Decoy Material List
  16143. *------------------------------------------*/
  16144. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  16145. nullpo_retv( sd );
  16146. int fd = sd->fd;
  16147. if( !session_isActive( fd ) ){
  16148. return;
  16149. }
  16150. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16151. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16152. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16153. int count = 0;
  16154. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16155. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16156. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16157. count++;
  16158. }
  16159. }
  16160. if( count > 0 ) {
  16161. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16162. WFIFOSET( fd, p->packetLength );
  16163. sd->menuskill_id = NC_MAGICDECOY;
  16164. sd->menuskill_val = skill_lv;
  16165. sd->sc.comet_x = x;
  16166. sd->sc.comet_y = y;
  16167. }else{
  16168. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16169. }
  16170. }
  16171. /*==========================================
  16172. * Guillotine Cross Poisons List
  16173. *------------------------------------------*/
  16174. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16175. nullpo_retv( sd );
  16176. int fd = sd->fd;
  16177. if( !session_isActive( fd ) ){
  16178. return;
  16179. }
  16180. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16181. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16182. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16183. int count = 0;
  16184. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16185. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16186. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16187. count++;
  16188. }
  16189. }
  16190. if( count > 0 ){
  16191. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16192. WFIFOSET( fd, p->packetLength );
  16193. sd->menuskill_id = GC_POISONINGWEAPON;
  16194. sd->menuskill_val = skill_lv;
  16195. }else{
  16196. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16197. }
  16198. }
  16199. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16200. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16201. int fd, i, c;
  16202. nullpo_ret(sd);
  16203. fd = sd->fd;
  16204. if( !session_isActive(fd) )
  16205. return 0;
  16206. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16207. return 0;
  16208. WFIFOHEAD(fd, 2 * 6 + 4);
  16209. WFIFOW(fd,0) = 0x442;
  16210. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16211. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16212. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16213. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16214. {
  16215. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16216. c++;
  16217. }
  16218. if( c > 0 ) {
  16219. WFIFOW(fd,2) = 8 + c * 2;
  16220. WFIFOL(fd,4) = c;
  16221. WFIFOSET(fd,WFIFOW(fd,2));
  16222. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16223. sd->menuskill_val = c;
  16224. } else {
  16225. status_change_end(&sd->bl,SC_STOP);
  16226. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16227. }
  16228. return 1;
  16229. }
  16230. /*===========================================
  16231. * Skill list for Four Elemental Analysis
  16232. * and Change Material skills.
  16233. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16234. *------------------------------------------*/
  16235. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16236. #if PACKETVER >= 20090922
  16237. int fd = sd->fd;
  16238. nullpo_ret(sd);
  16239. sd->menuskill_id = skill_id; // To prevent hacking.
  16240. sd->menuskill_val = skill_lv;
  16241. if( skill_id == GN_CHANGEMATERIAL )
  16242. skill_lv = 0; // Changematerial
  16243. WFIFOHEAD(fd, packet_len(0x7e3));
  16244. WFIFOW(fd,0) = 0x7e3;
  16245. WFIFOL(fd,2) = skill_lv;
  16246. WFIFOL(fd,4) = 0;
  16247. WFIFOSET(fd, packet_len(0x7e3));
  16248. #endif
  16249. return 1;
  16250. }
  16251. /*==========================================
  16252. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16253. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16254. * RFIFOL(fd,2) - type (currently not used)
  16255. *------------------------------------------*/
  16256. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16257. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16258. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16259. if (sd->menuskill_id == SA_AUTOSPELL) {
  16260. sd->state.workinprogress = WIP_DISABLE_NONE;
  16261. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16262. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16263. if (pc_istrading(sd)) {
  16264. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16265. clif_menuskill_clear(sd);
  16266. return;
  16267. }
  16268. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16269. } else
  16270. return;
  16271. clif_menuskill_clear(sd);
  16272. }
  16273. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16274. /// 08cf <id>.L <type>.W <num>.W
  16275. void clif_spiritcharm(struct map_session_data *sd) {
  16276. unsigned char buf[10];
  16277. nullpo_retv(sd);
  16278. WBUFW(buf,0) = 0x08cf;
  16279. WBUFL(buf,2) = sd->bl.id;
  16280. WBUFW(buf,6) = sd->spiritcharm_type;
  16281. WBUFW(buf,8) = sd->spiritcharm;
  16282. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16283. }
  16284. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16285. /// 0907 <index>.W
  16286. ///
  16287. /// R 0908 <index>.w <type>.b
  16288. /// type:
  16289. /// 0 = move item to personal tab
  16290. /// 1 = move item to normal tab
  16291. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16292. #if PACKETVER >= 20111122
  16293. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16294. int index = RFIFOW(fd,info->pos[0]) - 2;
  16295. int type = RFIFOB(fd, info->pos[1]);
  16296. /* can't move while dead. */
  16297. if(pc_isdead(sd)) {
  16298. return;
  16299. }
  16300. if (index < 0 || index >= MAX_INVENTORY)
  16301. return;
  16302. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16303. sd->inventory.u.items_inventory[index].favorite = 0;
  16304. else if( type == 0 )
  16305. sd->inventory.u.items_inventory[index].favorite = 1;
  16306. else
  16307. return;/* nothing to do. */
  16308. clif_favorite_item(sd, index);
  16309. #endif
  16310. }
  16311. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16312. /// 0900 <index>.W <favorite>.B
  16313. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16314. int fd = sd->fd;
  16315. WFIFOHEAD(fd,packet_len(0x908));
  16316. WFIFOW(fd,0) = 0x908;
  16317. WFIFOW(fd,2) = index+2;
  16318. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16319. WFIFOSET(fd,packet_len(0x908));
  16320. }
  16321. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16322. void clif_snap( struct block_list *bl, short x, short y ) {
  16323. unsigned char buf[10];
  16324. WBUFW(buf,0) = 0x8d2;
  16325. WBUFL(buf,2) = bl->id;
  16326. WBUFW(buf,6) = x;
  16327. WBUFW(buf,8) = y;
  16328. if( disguised(bl) )
  16329. {
  16330. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16331. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16332. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16333. } else
  16334. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16335. }
  16336. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16337. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16338. #if PACKETVER >= 20120404
  16339. WFIFOHEAD(fd,packet_len(0x977));
  16340. WFIFOW(fd,0) = 0x977;
  16341. WFIFOL(fd,2) = md->bl.id;
  16342. WFIFOL(fd,6) = md->status.hp;
  16343. WFIFOL(fd,10) = md->status.max_hp;
  16344. WFIFOSET(fd,packet_len(0x977));
  16345. #endif
  16346. }
  16347. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16348. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16349. return;
  16350. }
  16351. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16352. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16353. WFIFOW(sd->fd,0) = 0x2c9;
  16354. WFIFOB(sd->fd,2) = flag;
  16355. WFIFOSET(sd->fd, packet_len(0x2c9));
  16356. }
  16357. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16358. /// 0979 <world name>.24B <char name>.24B
  16359. void clif_ackworldinfo(struct map_session_data* sd) {
  16360. int fd;
  16361. nullpo_retv(sd);
  16362. fd = sd->fd;
  16363. WFIFOHEAD(fd,packet_len(0x979));
  16364. WFIFOW(fd,0)=0x979;
  16365. //AID -> world name ?
  16366. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16367. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16368. WFIFOSET(fd,packet_len(0x979));
  16369. }
  16370. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16371. /// 0978 <AID>.L
  16372. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16373. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16374. if(sd)
  16375. clif_ackworldinfo(sd);
  16376. }
  16377. static void clif_loadConfirm( struct map_session_data *sd ){
  16378. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16379. nullpo_retv( sd );
  16380. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16381. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16382. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16383. clif_instance_info( *sd );
  16384. #endif
  16385. }
  16386. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16387. /// 0447
  16388. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16389. clif_loadConfirm( sd );
  16390. }
  16391. /// req world info (CZ_CLIENT_VERSION)
  16392. /// 044A <version>.L
  16393. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16394. //if(sd)
  16395. ;
  16396. }
  16397. /// Ranking list
  16398. /// ranking pointlist { <name>.24B <point>.L }*10
  16399. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16400. struct fame_list* list;
  16401. int i, size = MAX_FAME_LIST;
  16402. switch(rankingtype) {
  16403. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16404. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16405. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16406. // PK currently unsupported
  16407. case RANK_KILLER: list = NULL; size = 0; break;
  16408. default:
  16409. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16410. return;
  16411. }
  16412. //Packet size limits this list to 10 elements. [Skotlex]
  16413. for (i = 0; i < min(10,size); i++) {
  16414. if (list[i].id > 0) {
  16415. const char* name;
  16416. if (strcmp(list[i].name, "-") == 0 &&
  16417. (name = map_charid2nick(list[i].id)) != NULL)
  16418. {
  16419. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16420. } else {
  16421. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16422. }
  16423. } else {
  16424. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16425. }
  16426. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16427. }
  16428. for(;i < 10; i++) { //In case the MAX is less than 10.
  16429. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16430. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16431. }
  16432. }
  16433. /// Request for the blacksmith ranklist.
  16434. /// /blacksmith command sends this packet to the server.
  16435. /// 0217 (CZ_BLACKSMITH_RANK)
  16436. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16437. clif_ranklist(sd,RANK_BLACKSMITH);
  16438. }
  16439. /// Request for the alchemist ranklist.
  16440. /// /alchemist command sends this packet to the server.
  16441. /// 0218 (CZ_ALCHEMIST_RANK)
  16442. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16443. clif_ranklist(sd,RANK_ALCHEMIST);
  16444. }
  16445. /// Request for the taekwon ranklist.
  16446. /// /taekwon command sends this packet to the server.
  16447. /// 0225 (CZ_TAEKWON_RANK)
  16448. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16449. clif_ranklist(sd,RANK_TAEKWON);
  16450. }
  16451. /// Request for the killer ranklist.
  16452. /// /pk command sends this packet to the server.
  16453. /// 0237 (CZ_KILLER_RANK)
  16454. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16455. clif_ranklist(sd,RANK_KILLER);
  16456. }
  16457. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16458. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16459. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16460. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16461. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16462. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16463. enum e_rank rank;
  16464. #if PACKETVER < 20130710
  16465. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16466. short cmd;
  16467. switch( rankingType ){
  16468. case RANK_BLACKSMITH: cmd = 0x219; break;
  16469. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16470. case RANK_TAEKWON: cmd = 0x226; break;
  16471. case RANK_KILLER: cmd = 0x238; break;
  16472. default:
  16473. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16474. return;
  16475. }
  16476. // Can be safely casted here, since we validated it before
  16477. rank = (enum e_rank)rankingType;
  16478. WBUFW(buf,0) = cmd;
  16479. clif_sub_ranklist(buf,2,sd,rank);
  16480. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16481. #else
  16482. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16483. int mypoint = 0;
  16484. switch( rankingType ){
  16485. case RANK_BLACKSMITH:
  16486. case RANK_ALCHEMIST:
  16487. case RANK_TAEKWON:
  16488. case RANK_KILLER:
  16489. break;
  16490. default:
  16491. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16492. return;
  16493. }
  16494. // Can be safely casted here, since we validated it before
  16495. rank = (enum e_rank)rankingType;
  16496. WBUFW(buf,0) = 0x97d;
  16497. WBUFW(buf,2) = rank;
  16498. clif_sub_ranklist(buf,4,sd,rank);
  16499. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16500. case MAPID_BLACKSMITH:
  16501. case MAPID_ALCHEMIST:
  16502. case MAPID_TAEKWON:
  16503. mypoint = sd->status.fame;
  16504. }
  16505. WBUFL(buf,284) = mypoint; //mypoint
  16506. clif_send(buf, 288, &sd->bl, SELF);
  16507. #endif
  16508. }
  16509. /*
  16510. * 097c <type> (CZ_REQ_RANKING)
  16511. * type
  16512. * 0: /blacksmith
  16513. * 1: /alchemist
  16514. * 2: /taekwon
  16515. * 3: /pk
  16516. * */
  16517. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16518. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16519. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16520. clif_ranklist(sd,rankingtype);
  16521. }
  16522. /// Updates the fame rank points for the given ranking.
  16523. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16524. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16525. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16526. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16527. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16528. int fd = sd.fd;
  16529. #if PACKETVER < 20130710
  16530. short cmd;
  16531. switch(rankingtype){
  16532. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16533. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16534. case RANK_TAEKWON: cmd = 0x224; break;
  16535. default:
  16536. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16537. return;
  16538. }
  16539. WFIFOHEAD(fd,packet_len(cmd));
  16540. WFIFOW(fd,0) = cmd;
  16541. WFIFOL(fd,2) = point;
  16542. WFIFOL(fd,6) = sd.status.fame;
  16543. WFIFOSET(fd, packet_len(cmd));
  16544. #else
  16545. WFIFOHEAD(fd,packet_len(0x97e));
  16546. WFIFOW(fd,0) = 0x97e;
  16547. WFIFOW(fd,2) = rankingtype;
  16548. WFIFOL(fd,4) = point;
  16549. WFIFOL(fd,8) = sd.status.fame;
  16550. WFIFOSET(fd,packet_len(0x97e));
  16551. #endif
  16552. }
  16553. /**
  16554. * Transmit personal information to player. (rates)
  16555. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16556. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16557. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16558. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16559. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16560. * FIXME!
  16561. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16562. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16563. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16564. */
  16565. #ifdef VIP_ENABLE
  16566. void clif_display_pinfo( struct map_session_data& sd ){
  16567. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16568. // 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]
  16569. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16570. /**
  16571. * EXP
  16572. */
  16573. //0:PCRoom
  16574. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16575. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16576. details_bexp[PINFO_BASIC] = 0;
  16577. else {
  16578. if (details_bexp[PINFO_BASIC] < 100) {
  16579. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16580. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16581. } else
  16582. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16583. }
  16584. //1:Premium
  16585. if( pc_isvip( &sd ) ){
  16586. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16587. if (details_bexp[PINFO_PREMIUM] < 0)
  16588. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16589. } else
  16590. details_bexp[PINFO_PREMIUM] = 0;
  16591. //2:Server
  16592. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16593. if (details_bexp[PINFO_SERVER] == 100)
  16594. details_bexp[PINFO_SERVER] = 0;
  16595. else {
  16596. if (details_bexp[PINFO_SERVER] < 100) {
  16597. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16598. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16599. } else
  16600. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16601. }
  16602. //3:TPLUS
  16603. details_bexp[PINFO_CAFE] = 0;
  16604. /**
  16605. * Drop rate
  16606. */
  16607. //0:PCRoom
  16608. details_drop[PINFO_BASIC] = 0;
  16609. //1:Premium
  16610. if( pc_isvip( &sd ) ){
  16611. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16612. if (details_drop[PINFO_PREMIUM] < 0)
  16613. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16614. } else
  16615. details_drop[PINFO_PREMIUM] = 0;
  16616. //2:Server
  16617. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16618. if (details_drop[PINFO_SERVER] == 100)
  16619. details_drop[PINFO_SERVER] = 0;
  16620. else {
  16621. if (details_drop[PINFO_SERVER] < 100) {
  16622. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16623. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16624. } else
  16625. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16626. }
  16627. //3:TPLUS
  16628. details_drop[PINFO_CAFE] = 0;
  16629. /**
  16630. * Penalty rate
  16631. */
  16632. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16633. //0:PCRoom
  16634. details_penalty[PINFO_BASIC] = 0;
  16635. //1:Premium
  16636. if( pc_isvip( &sd ) ){
  16637. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16638. if (details_penalty[PINFO_PREMIUM] == 100)
  16639. details_penalty[PINFO_PREMIUM] = 0;
  16640. else {
  16641. if (details_penalty[PINFO_PREMIUM] < 100) {
  16642. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16643. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16644. } else
  16645. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16646. }
  16647. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16648. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16649. } else
  16650. details_penalty[PINFO_PREMIUM] = 0;
  16651. //2:Server
  16652. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16653. if (details_penalty[PINFO_SERVER] == 100)
  16654. details_penalty[PINFO_SERVER] = 0;
  16655. else {
  16656. if (details_penalty[PINFO_SERVER] < 100) {
  16657. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16658. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16659. } else
  16660. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16661. }
  16662. //3:TPLUS
  16663. details_penalty[PINFO_CAFE] = 0;
  16664. struct PACKET_ZC_PERSONAL_INFOMATION* p = (struct PACKET_ZC_PERSONAL_INFOMATION*)packet_buffer;
  16665. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16666. p->length = sizeof( *p ) + PINFO_MAX * sizeof( p->details[0] );
  16667. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16668. p->total_exp = 100 * 1000;
  16669. p->total_death = 100 * 1000;
  16670. p->total_drop = 100 * 1000;
  16671. #else
  16672. p->total_exp = 100;
  16673. p->total_death = 100;
  16674. p->total_drop = 100;
  16675. #endif
  16676. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16677. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16678. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16679. p->details[i].exp = details_bexp[i] * 1000;
  16680. p->details[i].death = details_penalty[i] * 1000;
  16681. p->details[i].drop = details_drop[i] * 1000;
  16682. #else
  16683. p->details[i].exp = details_bexp[i];
  16684. p->details[i].death = details_penalty[i];
  16685. p->details[i].drop = details_drop[i];
  16686. #endif
  16687. p->total_exp += p->details[i].exp;
  16688. p->total_death += p->details[i].death;
  16689. p->total_drop += p->details[i].drop;
  16690. }
  16691. clif_send( p, p->length, &sd.bl, SELF );
  16692. #endif
  16693. }
  16694. #endif
  16695. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16696. char cmd[30];
  16697. int t_aid = RFIFOL(fd,2);
  16698. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16699. is_atcommand(fd, sd, cmd, 1);
  16700. }
  16701. /**
  16702. * Marks Crimson Marker target on mini-map to the caster
  16703. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16704. * @param fd
  16705. * @param bl Crimson Marker target
  16706. **/
  16707. void clif_crimson_marker( struct map_session_data& sd, struct block_list& bl, bool remove ){
  16708. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16709. struct PACKET_ZC_C_MARKERINFO p = {};
  16710. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16711. p.AID = bl.id;
  16712. if( remove ){
  16713. p.xPos = -1;
  16714. p.yPos = -1;
  16715. }else{
  16716. p.xPos = bl.x;
  16717. p.yPos = bl.y;
  16718. }
  16719. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16720. #endif
  16721. }
  16722. /**
  16723. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16724. **/
  16725. void clif_notify_bindOnEquip( struct map_session_data& sd, int16 index ){
  16726. #if PACKETVER >= 20070227
  16727. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16728. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16729. p.index = client_index( index );
  16730. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16731. #endif
  16732. }
  16733. /**
  16734. * [Ind/Hercules]
  16735. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16736. **/
  16737. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16738. char buf[256];
  16739. size_t len;
  16740. nullpo_retv(bl);
  16741. if(!message)
  16742. return;
  16743. len = strlen(message)+1;
  16744. if( len > sizeof(buf)-8 ) {
  16745. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16746. len = sizeof(buf)-8;
  16747. }
  16748. WBUFW(buf,0) = 0x8b3;
  16749. WBUFW(buf,2) = (uint16)(len+8);
  16750. WBUFL(buf,4) = bl->id;
  16751. safestrncpy(WBUFCP(buf,8), message, len);
  16752. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16753. }
  16754. /**
  16755. * [Ind/Hercules]
  16756. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16757. **/
  16758. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16759. unsigned char buf[10];
  16760. nullpo_retv(sd);
  16761. WBUFW(buf,0) = 0x7fc;
  16762. WBUFL(buf,2) = prev_leader_aid;
  16763. WBUFL(buf,6) = new_leader_aid;
  16764. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16765. }
  16766. /**
  16767. * Sends a clan message to a player
  16768. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16769. **/
  16770. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16771. #if PACKETVER >= 20131223
  16772. struct map_session_data *sd;
  16773. uint8 buf[256];
  16774. if( len == 0 ){
  16775. return;
  16776. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16777. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16778. len = sizeof(buf)-5-NAME_LENGTH;
  16779. }
  16780. WBUFW(buf, 0) = 0x98e;
  16781. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16782. // 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
  16783. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16784. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16785. if((sd = clan_getavailablesd(clan)) != NULL)
  16786. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16787. #endif
  16788. }
  16789. /**
  16790. * Parses a clan message from a player.
  16791. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16792. **/
  16793. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16794. #if PACKETVER >= 20131223
  16795. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16796. // validate packet and retrieve name and message
  16797. if( !clif_process_message(sd, false, name, message, output ) )
  16798. return;
  16799. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16800. #endif
  16801. }
  16802. /**
  16803. * Sends the basic clan informations to the client.
  16804. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16805. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16806. **/
  16807. void clif_clan_basicinfo( struct map_session_data *sd ){
  16808. #if PACKETVER >= 20131223
  16809. int fd, offset, length, i, flag;
  16810. struct clan* clan;
  16811. char mapname[MAP_NAME_LENGTH_EXT];
  16812. nullpo_retv( sd );
  16813. nullpo_retv( clan = sd->clan );
  16814. // Check if the player has a valid session and is not autotrading
  16815. if( !clif_session_isValid( sd ) ){
  16816. return;
  16817. }
  16818. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16819. fd = sd->fd;
  16820. WFIFOHEAD(fd,length);
  16821. memset( WFIFOP(fd, 0), 0, length );
  16822. WFIFOW( fd, 0 ) = 0x98a;
  16823. WFIFOL( fd, 4 ) = clan->id;
  16824. offset = 8;
  16825. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16826. offset += NAME_LENGTH;
  16827. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16828. offset += NAME_LENGTH;
  16829. mapindex_getmapname_ext( clan->map, mapname );
  16830. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16831. offset += MAP_NAME_LENGTH_EXT;
  16832. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16833. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16834. for( flag = 0; flag < 2; flag++ ){
  16835. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16836. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16837. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16838. offset += NAME_LENGTH;
  16839. }
  16840. }
  16841. }
  16842. WFIFOW( fd, 2 ) = offset;
  16843. WFIFOSET(fd,offset);
  16844. #endif
  16845. }
  16846. /**
  16847. * Updates the online and maximum player count of a clan.
  16848. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16849. **/
  16850. void clif_clan_onlinecount( struct clan* clan ){
  16851. #if PACKETVER >= 20131223
  16852. uint8 buf[6];
  16853. struct map_session_data *sd;
  16854. WBUFW(buf,0) = 0x988;
  16855. WBUFW(buf,2) = clan->connect_member;
  16856. WBUFW(buf,4) = clan->max_member;
  16857. if((sd = clan_getavailablesd(clan)) != NULL)
  16858. clif_send(buf, 6, &sd->bl, CLAN);
  16859. #endif
  16860. }
  16861. /**
  16862. * Notifies the client that the player has left his clan.
  16863. * 0989 (ZC_ACK_CLAN_LEAVE)
  16864. **/
  16865. void clif_clan_leave( struct map_session_data* sd ){
  16866. #if PACKETVER >= 20131223
  16867. int fd;
  16868. nullpo_retv( sd );
  16869. if( !clif_session_isValid( sd ) ){
  16870. return;
  16871. }
  16872. fd = sd->fd;
  16873. WFIFOHEAD(fd,2);
  16874. WFIFOW(fd,0) = 0x989;
  16875. WFIFOSET(fd,2);
  16876. #endif
  16877. }
  16878. /**
  16879. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16880. * 0A2F <result>.B <title_id>.L
  16881. */
  16882. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16883. {
  16884. #if PACKETVER >= 20150513
  16885. int fd;
  16886. nullpo_retv(sd);
  16887. if (!clif_session_isValid(sd))
  16888. return;
  16889. fd = sd->fd;
  16890. WFIFOHEAD(fd, packet_len(0xa2f));
  16891. WFIFOW(fd, 0) = 0xa2f;
  16892. WFIFOB(fd, 2) = result;
  16893. WFIFOL(fd, 3) = title_id;
  16894. WFIFOSET(fd, packet_len(0xa2f));
  16895. #endif
  16896. }
  16897. /**
  16898. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16899. * 0A2E <title_id>.L
  16900. */
  16901. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16902. {
  16903. int title_id;
  16904. nullpo_retv(sd);
  16905. title_id = RFIFOL(fd, 2);
  16906. if( title_id == sd->status.title_id ){
  16907. // It is exactly the same as the old one
  16908. return;
  16909. }else if( title_id <= 0 ){
  16910. sd->status.title_id = 0;
  16911. }else{
  16912. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16913. clif_change_title_ack(sd, 1, title_id);
  16914. return;
  16915. }
  16916. sd->status.title_id = title_id;
  16917. }
  16918. clif_name_area(&sd->bl);
  16919. clif_change_title_ack(sd, 0, title_id);
  16920. }
  16921. #ifdef DUMP_UNKNOWN_PACKET
  16922. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16923. {
  16924. const char* packet_txt = "save/packet.txt";
  16925. FILE* fp;
  16926. time_t time_server;
  16927. struct tm *datetime;
  16928. char datestr[512];
  16929. time(&time_server); // get time in seconds since 1/1/1970
  16930. datetime = localtime(&time_server); // convert seconds in structure
  16931. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16932. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16933. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16934. if( sd ) {
  16935. 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);
  16936. } else {
  16937. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16938. }
  16939. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16940. fprintf(fp, "\n");
  16941. fclose(fp);
  16942. } else {
  16943. ShowError("Failed to write '%s'.\n", packet_txt);
  16944. // Dump on console instead
  16945. if( sd ) {
  16946. 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);
  16947. } else {
  16948. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16949. }
  16950. ShowDump(RFIFOP(fd,0), packet_len);
  16951. }
  16952. }
  16953. #endif
  16954. /// Roulette System
  16955. /// Author: Yommy
  16956. /// Opens the roulette window
  16957. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16958. void clif_roulette_open( struct map_session_data* sd ){
  16959. nullpo_retv( sd );
  16960. struct packet_roulette_open_ack p;
  16961. p.PacketType = 0xa1a;
  16962. p.Result = 0; // result
  16963. p.Serial = 0; // serial
  16964. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16965. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16966. p.AdditionItemID = -1; //! TODO: Display bonus item
  16967. p.GoldPoint = sd->roulette_point.gold;
  16968. p.SilverPoint = sd->roulette_point.silver;
  16969. p.BronzePoint = sd->roulette_point.bronze;
  16970. sd->state.roulette_open = true;
  16971. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16972. }
  16973. /// Request to open the roulette window
  16974. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16975. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16976. nullpo_retv(sd);
  16977. if (!battle_config.feature_roulette) {
  16978. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16979. return;
  16980. }
  16981. clif_roulette_open(sd);
  16982. }
  16983. /// Sends the info about the available roulette rewards to the client
  16984. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16985. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16986. void clif_roulette_info( struct map_session_data* sd ){
  16987. nullpo_retv(sd);
  16988. struct packet_roulette_info_ack p;
  16989. p.PacketType = rouletteinfoackType;
  16990. p.PacketLength = sizeof(p);
  16991. p.RouletteSerial = 1;
  16992. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16993. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16994. p.ItemInfo[count].Row = i;
  16995. p.ItemInfo[count].Position = j;
  16996. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  16997. p.ItemInfo[count].Count = rd.qty[i][j];
  16998. #if PACKETVER >= 20180511
  16999. p.ItemInfo[count].unused = 0;
  17000. #endif
  17001. count++;
  17002. }
  17003. }
  17004. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17005. }
  17006. /// Request the roulette reward data
  17007. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17008. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  17009. nullpo_retv(sd);
  17010. if (!battle_config.feature_roulette) {
  17011. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17012. return;
  17013. }
  17014. clif_roulette_info(sd);
  17015. }
  17016. /// Notification of the client that the roulette window was closed
  17017. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17018. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  17019. nullpo_retv(sd);
  17020. if (!battle_config.feature_roulette) {
  17021. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17022. return;
  17023. }
  17024. sd->state.roulette_open = false;
  17025. }
  17026. /// Response to a item reward request
  17027. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17028. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17029. #if PACKETVER >= 20141016
  17030. nullpo_retv(sd);
  17031. struct packet_roulette_itemrecv_ack p;
  17032. p.PacketType = roulettercvitemackType;
  17033. p.Result = type;
  17034. p.AdditionItemID = 0; //! TODO: Additional item
  17035. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17036. #endif
  17037. }
  17038. /**
  17039. * Claim roulette reward
  17040. * @param sd Player
  17041. * @return 0:Success
  17042. **/
  17043. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  17044. struct item it;
  17045. uint8 res = 1;
  17046. nullpo_retr(1, sd);
  17047. if (sd->roulette.prizeIdx < 0)
  17048. return RECV_ITEM_FAILED;
  17049. memset(&it, 0, sizeof(it));
  17050. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17051. it.identify = 1;
  17052. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  17053. ; // onSuccess
  17054. }
  17055. sd->roulette.claimPrize = false;
  17056. sd->roulette.prizeStage = 0;
  17057. sd->roulette.prizeIdx = -1;
  17058. sd->roulette.stage = 0;
  17059. return res;
  17060. }
  17061. /// Update Roulette window with current stats
  17062. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17063. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17064. nullpo_retv( sd );
  17065. struct packet_roulette_generate_ack p;
  17066. p.PacketType = roulettgenerateackType;
  17067. p.Result = result;
  17068. p.Step = stage;
  17069. p.Idx = prizeIdx;
  17070. p.AdditionItemID = bonusItemID;
  17071. p.RemainGold = sd->roulette_point.gold;
  17072. p.RemainSilver = sd->roulette_point.silver;
  17073. p.RemainBronze = sd->roulette_point.bronze;
  17074. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17075. }
  17076. /// Request to start the roulette
  17077. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17078. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  17079. enum GENERATE_ROULETTE_ACK result;
  17080. nullpo_retv(sd);
  17081. if (!battle_config.feature_roulette) {
  17082. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17083. return;
  17084. }
  17085. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17086. return;
  17087. }
  17088. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17089. sd->roulette.stage = 0;
  17090. sd->roulette.claimPrize = false;
  17091. sd->roulette.prizeStage = 0;
  17092. sd->roulette.prizeIdx = -1;
  17093. }
  17094. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17095. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17096. }else{
  17097. if (!sd->roulette.stage) {
  17098. if (sd->roulette_point.bronze > 0) {
  17099. sd->roulette_point.bronze -= 1;
  17100. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17101. } else if (sd->roulette_point.silver > 9) {
  17102. sd->roulette_point.silver -= 10;
  17103. sd->roulette.stage = 2;
  17104. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17105. } else if (sd->roulette_point.gold > 9) {
  17106. sd->roulette_point.gold -= 10;
  17107. sd->roulette.stage = 4;
  17108. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17109. }
  17110. }
  17111. sd->roulette.prizeStage = sd->roulette.stage;
  17112. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17113. sd->roulette.claimPrize = true;
  17114. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17115. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17116. result = GENERATE_ROULETTE_LOSING;
  17117. sd->roulette.stage = 0;
  17118. }else{
  17119. result = GENERATE_ROULETTE_SUCCESS;
  17120. sd->roulette.stage++;
  17121. }
  17122. }
  17123. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17124. }
  17125. /// Request to claim a prize
  17126. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17127. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17128. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17129. nullpo_retv(sd);
  17130. if (!battle_config.feature_roulette) {
  17131. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17132. return;
  17133. }
  17134. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17135. return;
  17136. }
  17137. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17138. switch (clif_roulette_getitem(sd)) {
  17139. case ADDITEM_SUCCESS:
  17140. type = RECV_ITEM_SUCCESS;
  17141. break;
  17142. case ADDITEM_INVALID:
  17143. case ADDITEM_OVERITEM:
  17144. case ADDITEM_OVERAMOUNT:
  17145. type = RECV_ITEM_OVERCOUNT;
  17146. break;
  17147. case ADDITEM_OVERWEIGHT:
  17148. type = RECV_ITEM_OVERWEIGHT;
  17149. break;
  17150. case ADDITEM_STACKLIMIT:
  17151. default:
  17152. type = RECV_ITEM_FAILED;
  17153. break;
  17154. }
  17155. }
  17156. clif_roulette_recvitem_ack(sd,type);
  17157. }
  17158. /// MERGE ITEM
  17159. /**
  17160. * Acknowledge the client about item merger result
  17161. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17162. * @param fd
  17163. * @param sd
  17164. **/
  17165. void clif_merge_item_ack( struct map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17166. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17167. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17168. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17169. if( type == MERGE_ITEM_SUCCESS ){
  17170. p.index = client_index( index );
  17171. }else{
  17172. p.index = index;
  17173. }
  17174. p.amount = count;
  17175. p.reason = type;
  17176. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17177. #endif
  17178. }
  17179. /**
  17180. * Check if item has the pair to be merged
  17181. * @param sd
  17182. * @param it Item
  17183. * @return True if has pair, False if not
  17184. **/
  17185. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17186. struct item *it_;
  17187. unsigned short i;
  17188. nullpo_retr(false, sd);
  17189. 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);
  17190. if (i < MAX_INVENTORY)
  17191. return true;
  17192. return false;
  17193. }
  17194. /**
  17195. * Check if item can be merged
  17196. * @param id Item Data
  17197. * @param it Item
  17198. * @return True if can be merged, False if not
  17199. **/
  17200. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17201. if (!id || !it)
  17202. return false;
  17203. if (id->type == IT_CASH)
  17204. return false;
  17205. if (!itemdb_isstackable2(id))
  17206. return false;
  17207. if (itemdb_isspecial(it->card[0]))
  17208. return false;
  17209. if (!it->unique_id)
  17210. return false;
  17211. return true;
  17212. }
  17213. /**
  17214. * Open available item to be merged.
  17215. * Only show 1 item in 1 process.
  17216. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17217. * @param sd
  17218. **/
  17219. void clif_merge_item_open( struct map_session_data& sd ){
  17220. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17221. struct PACKET_ZC_MERGE_ITEM_OPEN* p = (struct PACKET_ZC_MERGE_ITEM_OPEN*)packet_buffer;
  17222. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17223. p->packetLen = sizeof( *p );
  17224. int n = 0;
  17225. // Get entries
  17226. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17227. struct item* it = &sd.inventory.u.items_inventory[i];
  17228. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17229. continue;
  17230. }
  17231. if( clif_merge_item_has_pair( &sd, it ) ){
  17232. p->items[n++].index = client_index( i );
  17233. p->packetLen += sizeof( p->items[0] );
  17234. }
  17235. }
  17236. // No item need to be merged
  17237. if( n < 2 ){
  17238. clif_msg( &sd, MERGE_ITEM_NOT_AVAILABLE );
  17239. return;
  17240. }
  17241. clif_send( p, p->packetLen, &sd.bl, SELF );
  17242. #endif
  17243. }
  17244. /**
  17245. * Process item merger
  17246. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17247. * @param fd
  17248. * @param sd
  17249. **/
  17250. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17251. struct s_packet_db *info = NULL;
  17252. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17253. unsigned int count = 0;
  17254. struct item_data *id = NULL;
  17255. nullpo_retv(sd);
  17256. if (!clif_session_isValid(sd))
  17257. return;
  17258. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17259. return;
  17260. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17261. if (n < 2) { // No item need to be merged
  17262. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17263. return;
  17264. }
  17265. for (i = 0, j = 0; i < n; i++) {
  17266. uint16 idx = server_index( RFIFOW( fd, info->pos[1] + i * 2 ) );
  17267. if( idx >= MAX_INVENTORY ){
  17268. return;
  17269. }
  17270. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17271. continue;
  17272. indexes[j] = idx;
  17273. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17274. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_NOT_MERGE );
  17275. return;
  17276. }
  17277. count += sd->inventory.u.items_inventory[idx].amount;
  17278. j++;
  17279. }
  17280. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17281. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17282. return;
  17283. }
  17284. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17285. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17286. return;
  17287. }
  17288. // Merrrrge!!!!
  17289. for (i = 1; i < n; i++) {
  17290. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17291. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17292. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17293. sd->inventory_data[idx] = NULL;
  17294. clif_delitem(sd, idx, amt, 0);
  17295. }
  17296. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17297. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, indexes[0], count );
  17298. }
  17299. /**
  17300. * Cancel item merge
  17301. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17302. * @param fd
  17303. * @param sd
  17304. **/
  17305. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17306. return; // Nothing todo yet
  17307. }
  17308. static std::string clif_hide_name(const char* original_name)
  17309. {
  17310. std::string censored(original_name);
  17311. int hide = min(battle_config.broadcast_hide_name, censored.length() - 1);
  17312. censored.replace(censored.length() - hide, hide, hide, '*');
  17313. return censored;
  17314. }
  17315. /**
  17316. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17317. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17318. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17319. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17320. **/
  17321. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17322. char name[NAME_LENGTH];
  17323. if( battle_config.broadcast_hide_name ){
  17324. std::string dispname = clif_hide_name(char_name);
  17325. safestrncpy(name, dispname.c_str(), sizeof(name));
  17326. }else{
  17327. safestrncpy( name, char_name, sizeof( name ) );
  17328. }
  17329. switch( type ){
  17330. case ITEMOBTAIN_TYPE_BOXITEM:
  17331. #if PACKETVER >= 20091201
  17332. {
  17333. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17334. p.PacketType = package_item_announceType;
  17335. p.PacketLength = sizeof( p );
  17336. p.type = type;
  17337. p.ItemID = client_nameid( nameid );
  17338. p.len = NAME_LENGTH;
  17339. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17340. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17341. p.BoxItemID = client_nameid( container );
  17342. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17343. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17344. p.refineLevel = 0; // TODO: implement
  17345. #endif
  17346. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17347. }
  17348. #endif
  17349. break;
  17350. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17351. case ITEMOBTAIN_TYPE_NPC:
  17352. {
  17353. struct packet_item_drop_announce p;
  17354. p.PacketType = item_drop_announceType;
  17355. p.type = type;
  17356. p.ItemID = client_nameid( nameid );
  17357. p.len = NAME_LENGTH;
  17358. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17359. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17360. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17361. p.monsterNameLen = NAME_LENGTH;
  17362. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17363. }else{
  17364. p.monsterNameLen = 0;
  17365. p.monsterName[0] = '\0';
  17366. }
  17367. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17368. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17369. #else
  17370. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17371. #endif
  17372. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17373. }
  17374. break;
  17375. }
  17376. }
  17377. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17378. /// 0A02 <view>.W
  17379. /// Value <flag> has the following effects:
  17380. /// 1: Open a Dress Room window.
  17381. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17382. #if PACKETVER >= 20150513
  17383. int fd = sd->fd;
  17384. nullpo_retv(sd);
  17385. WFIFOHEAD(fd, packet_len(0xa02));
  17386. WFIFOW(fd,0) = 0xa02;
  17387. WFIFOW(fd,2) = flag;
  17388. WFIFOSET(fd, packet_len(0xa02));
  17389. #endif
  17390. }
  17391. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17392. /// 0A35 <result>.W
  17393. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17394. #if PACKETVER >= 20150513
  17395. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17396. // Ignore the request
  17397. // - Invalid item index
  17398. // - Invalid item ID or item doesn't exist
  17399. // - Item is already identified
  17400. if (idx < 0 || idx >= MAX_INVENTORY ||
  17401. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17402. sd->inventory.u.items_inventory[idx].identify)
  17403. return;
  17404. // Ignore the request - No magnifiers in inventory
  17405. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17406. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17407. return;
  17408. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17409. return;
  17410. skill_identify(sd, idx);
  17411. #endif
  17412. }
  17413. /// Starts navigation to the given target on client side
  17414. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17415. #if PACKETVER >= 20111010
  17416. int fd = sd->fd;
  17417. WFIFOHEAD(fd,27);
  17418. WFIFOW(fd,0) = 0x08e2;
  17419. // How detailed will our navigation be?
  17420. if( mob_id > 0 ){
  17421. x = 0;
  17422. y = 0;
  17423. WFIFOB(fd,2) = 3; // monster with destination field
  17424. }else if( x > 0 && y > 0 ){
  17425. WFIFOB(fd,2) = 0; // with coordinates
  17426. }else{
  17427. x = 0;
  17428. y = 0;
  17429. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17430. }
  17431. // Which services can be used for transportation?
  17432. WFIFOB(fd,3) = flag;
  17433. // If this flag is set, the navigation window will not be opened up
  17434. WFIFOB(fd,4) = hideWindow;
  17435. // Target map
  17436. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17437. // Target x
  17438. WFIFOW(fd,21) = x;
  17439. // Target y
  17440. WFIFOW(fd,23) = y;
  17441. // Target monster ID
  17442. WFIFOW(fd,25) = mob_id;
  17443. WFIFOSET(fd,27);
  17444. #endif
  17445. }
  17446. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17447. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17448. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17449. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17450. struct map_session_data *tsd;
  17451. struct block_list* tbl;
  17452. if( target == SELF ){
  17453. tsd = BL_CAST(BL_PC,bl);
  17454. tbl = &sd->bl;
  17455. }else{
  17456. tsd = sd;
  17457. tbl = bl;
  17458. }
  17459. nullpo_retv( tsd );
  17460. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17461. return;
  17462. }
  17463. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17464. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17465. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17466. p->aid = tsd->bl.id;
  17467. p->status = 1;
  17468. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17469. p->effects[i] = tsd->hatEffects[i];
  17470. }
  17471. clif_send( p, p->packetLength, tbl, target );
  17472. #endif
  17473. }
  17474. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17475. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17476. nullpo_retv( sd );
  17477. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17478. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17479. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17480. p->aid = sd->bl.id;
  17481. p->status = enable;
  17482. p->effects[0] = effectId;
  17483. clif_send( p, p->packetLength, &sd->bl, AREA );
  17484. #endif
  17485. }
  17486. /// Notify the client that a sale has started
  17487. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17488. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17489. #if PACKETVER_SUPPORTS_SALES
  17490. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17491. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17492. p.itemId = client_nameid( sale_item->nameid );
  17493. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17494. clif_send( &p, sizeof( p ), bl, target );
  17495. #endif
  17496. }
  17497. /// Notify the client that a sale has ended
  17498. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17499. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17500. #if PACKETVER_SUPPORTS_SALES
  17501. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17502. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17503. p.itemId = client_nameid( sale_item->nameid );
  17504. clif_send( &p, sizeof( p ), bl, target );
  17505. #endif
  17506. }
  17507. /// Update the remaining amount of a sale item.
  17508. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17509. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17510. #if PACKETVER_SUPPORTS_SALES
  17511. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17512. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17513. p.itemId = client_nameid( sale_item->nameid );
  17514. p.amount = sale_item->amount;
  17515. clif_send( &p, sizeof( p ), bl, target );
  17516. #endif
  17517. }
  17518. /// The client requested a refresh of the current remaining count of a sale item
  17519. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17520. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17521. #if PACKETVER_SUPPORTS_SALES
  17522. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17523. struct sale_item_data* sale;
  17524. if( p->AID != sd->status.account_id ){
  17525. return;
  17526. }
  17527. sale = sale_find_item( p->itemId, true );
  17528. if( sale == NULL ){
  17529. return;
  17530. }
  17531. clif_sale_amount(sale, &sd->bl, SELF);
  17532. #endif
  17533. }
  17534. /// Opens the sale administration window on the client
  17535. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17536. void clif_sale_open( struct map_session_data* sd ){
  17537. #if PACKETVER_SUPPORTS_SALES
  17538. nullpo_retv(sd);
  17539. if( sd->state.sale_open ){
  17540. return;
  17541. }
  17542. sd->state.sale_open = true;
  17543. int fd = sd->fd;
  17544. WFIFOHEAD(fd, 2);
  17545. WFIFOW(fd, 0) = 0x9b5;
  17546. WFIFOSET(fd, 2);
  17547. #endif
  17548. }
  17549. /// Client request to open the sale administration window.
  17550. /// This is sent by /limitedsale
  17551. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17552. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17553. #if PACKETVER_SUPPORTS_SALES
  17554. nullpo_retv(sd);
  17555. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17556. return;
  17557. }
  17558. char command[CHAT_SIZE_MAX];
  17559. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17560. is_atcommand(fd, sd, command, 1);
  17561. #endif
  17562. }
  17563. /// Closes the sale administration window on the client.
  17564. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17565. void clif_sale_close(struct map_session_data* sd) {
  17566. #if PACKETVER_SUPPORTS_SALES
  17567. nullpo_retv(sd);
  17568. if( !sd->state.sale_open ){
  17569. return;
  17570. }
  17571. sd->state.sale_open = false;
  17572. int fd = sd->fd;
  17573. WFIFOHEAD(fd, 2);
  17574. WFIFOW(fd, 0) = 0x9bd;
  17575. WFIFOSET(fd, 2);
  17576. #endif
  17577. }
  17578. /// Client request to close the sale administration window.
  17579. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17580. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17581. #if PACKETVER_SUPPORTS_SALES
  17582. nullpo_retv(sd);
  17583. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17584. return;
  17585. }
  17586. clif_sale_close(sd);
  17587. #endif
  17588. }
  17589. /// Reply to a item search request for item sale administration.
  17590. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17591. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17592. #if PACKETVER_SUPPORTS_SALES
  17593. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17594. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17595. if( item != NULL ){
  17596. p.result = 0;
  17597. p.itemId = client_nameid( item->nameid );
  17598. p.price = item->price;
  17599. }else{
  17600. p.result = 1;
  17601. p.itemId = 0;
  17602. p.price = 0;
  17603. }
  17604. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17605. #endif
  17606. }
  17607. /// Search request for an item sale administration.
  17608. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17609. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17610. #if PACKETVER_SUPPORTS_SALES
  17611. char item_name[ITEM_NAME_LENGTH];
  17612. nullpo_retv(sd);
  17613. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17614. return;
  17615. }
  17616. if( !sd->state.sale_open ){
  17617. return;
  17618. }
  17619. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17620. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17621. if( id ){
  17622. int i;
  17623. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17624. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17625. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17626. return;
  17627. }
  17628. }
  17629. }
  17630. // not found
  17631. clif_sale_search_reply( sd, NULL );
  17632. #endif
  17633. }
  17634. /// Reply if an item was successfully put on sale or not.
  17635. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17636. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17637. #if PACKETVER_SUPPORTS_SALES
  17638. int fd = sd->fd;
  17639. WFIFOHEAD(fd, 4);
  17640. WFIFOW(fd, 0) = 0x9af;
  17641. WFIFOW(fd, 2) = (uint16)result;
  17642. WFIFOSET(fd, 4);
  17643. #endif
  17644. }
  17645. /// A client request to put an item on sale.
  17646. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17647. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17648. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17649. #if PACKETVER_SUPPORTS_SALES
  17650. nullpo_retv( sd );
  17651. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17652. if( p->AID != sd->status.account_id ){
  17653. return;
  17654. }
  17655. if( !sd->state.sale_open ){
  17656. return;
  17657. }
  17658. time_t endTime = p->startTime + p->hours * 60 * 60;
  17659. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17660. #endif
  17661. }
  17662. /// Reply to an item removal from sale.
  17663. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17664. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17665. #if PACKETVER_SUPPORTS_SALES
  17666. int fd = sd->fd;
  17667. WFIFOHEAD(fd, 4);
  17668. WFIFOW(fd, 0) = 0x9b1;
  17669. WFIFOW(fd, 2) = failed;
  17670. WFIFOSET(fd, 4);
  17671. #endif
  17672. }
  17673. /// Request to remove an item from sale.
  17674. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17675. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17676. #if PACKETVER_SUPPORTS_SALES
  17677. nullpo_retv( sd );
  17678. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17679. if( p->AID != sd->status.account_id ){
  17680. return;
  17681. }
  17682. if( !sd->state.sale_open ){
  17683. return;
  17684. }
  17685. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17686. #endif
  17687. }
  17688. /// Achievement System
  17689. /// Author: Luxuri, Aleos
  17690. /**
  17691. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17692. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17693. */
  17694. void clif_achievement_list_all(struct map_session_data *sd)
  17695. {
  17696. nullpo_retv(sd);
  17697. if (!battle_config.feature_achievement) {
  17698. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17699. return;
  17700. }
  17701. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17702. if (count == 0)
  17703. return;
  17704. int len = (50 * count) + 22;
  17705. int fd = sd->fd;
  17706. int *info = achievement_level(sd, true);
  17707. WFIFOHEAD(fd,len);
  17708. WFIFOW(fd, 0) = 0xa23;
  17709. WFIFOW(fd, 2) = len;
  17710. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17711. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17712. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17713. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17714. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17715. for (int i = 0; i < count; i++) {
  17716. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17717. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17718. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17719. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17720. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17721. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17722. }
  17723. WFIFOSET(fd, len);
  17724. }
  17725. /**
  17726. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17727. * 0a24 <ACHPoint>.L
  17728. */
  17729. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17730. {
  17731. nullpo_retv(sd);
  17732. if (!battle_config.feature_achievement) {
  17733. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17734. return;
  17735. }
  17736. int fd = sd->fd;
  17737. int *info = achievement_level(sd, true);
  17738. WFIFOHEAD(fd, packet_len(0xa24));
  17739. WFIFOW(fd, 0) = 0xa24;
  17740. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17741. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17742. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17743. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17744. if (ach) {
  17745. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17746. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17747. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17748. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17749. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17750. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17751. } else
  17752. memset(WFIFOP(fd, 16), 0, 40);
  17753. WFIFOSET(fd, packet_len(0xa24));
  17754. }
  17755. /**
  17756. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17757. * 0a25 <achievementID>.L
  17758. */
  17759. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17760. {
  17761. nullpo_retv(sd);
  17762. if( sd->achievement_data.save )
  17763. intif_achievement_save(sd);
  17764. achievement_check_reward(sd, RFIFOL(fd,2));
  17765. }
  17766. /**
  17767. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17768. * 0a26 <result>.W <achievementID>.L
  17769. */
  17770. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17771. {
  17772. WFIFOHEAD(fd, packet_len(0xa26));
  17773. WFIFOW(fd, 0) = 0xa26;
  17774. WFIFOB(fd, 2) = result;
  17775. WFIFOL(fd, 3) = achievement_id;
  17776. WFIFOSET(fd, packet_len(0xa26));
  17777. }
  17778. /// Process the pet evolution request
  17779. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17780. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17781. #if PACKETVER >= 20141008
  17782. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17783. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17784. if (!pet) {
  17785. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17786. return;
  17787. }
  17788. pet_evolution(sd, pet->class_);
  17789. #endif
  17790. }
  17791. /// Sends the result of the evolution to the client.
  17792. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17793. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17794. #if PACKETVER >= 20141008
  17795. int fd = sd->fd;
  17796. WFIFOHEAD(fd, packet_len(0x9fc));
  17797. WFIFOW(fd, 0) = 0x9fc;
  17798. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17799. WFIFOSET(fd, packet_len(0x9fc));
  17800. #endif
  17801. }
  17802. /*
  17803. * This packet is sent by /changedress or /nocosplay
  17804. *
  17805. * 0ae8
  17806. */
  17807. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17808. #if PACKETVER >= 20180103
  17809. char command[CHAT_SIZE_MAX];
  17810. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17811. is_atcommand( fd, sd, command, 1 );
  17812. #endif
  17813. }
  17814. /// Opens an UI window of the given type and initializes it with the given data
  17815. /// 0AE2 <type>.B <data>.L
  17816. void clif_ui_open( struct map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  17817. #if PACKETVER >= 20151202
  17818. // If the UI requires state tracking
  17819. switch( ui_type ){
  17820. case OUT_UI_STYLIST:
  17821. sd.state.stylist_open = true;
  17822. break;
  17823. case OUT_UI_ENCHANTGRADE:
  17824. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  17825. sd.state.enchantgrade_open = true;
  17826. break;
  17827. #else
  17828. return;
  17829. #endif
  17830. }
  17831. struct PACKET_ZC_UI_OPEN p = {};
  17832. p.PacketType = HEADER_ZC_UI_OPEN;
  17833. p.UIType = ui_type;
  17834. #if PACKETVER >= 20171122
  17835. p.data = data;
  17836. #endif
  17837. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17838. #endif
  17839. }
  17840. /// Request to open an UI window of the given type
  17841. /// 0A68 <type>.B
  17842. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17843. switch( RFIFOB(fd,2) ){
  17844. case IN_UI_ATTENDANCE:
  17845. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17846. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17847. }else if( pc_attendance_enabled() ){
  17848. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17849. }else{
  17850. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17851. }
  17852. break;
  17853. #if PACKETVER >= 20160316
  17854. case IN_UI_MACRO_REGISTER:
  17855. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  17856. break;
  17857. case IN_UI_MACRO_DETECTOR:
  17858. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  17859. break;
  17860. #endif
  17861. }
  17862. }
  17863. /// Response for attedance request
  17864. /// 0AF0 <unknown>.L <data>.L
  17865. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17866. nullpo_retv(sd);
  17867. int fd = sd->fd;
  17868. WFIFOHEAD(fd,packet_len(0xAF0));
  17869. WFIFOW(fd,0) = 0xAF0;
  17870. WFIFOL(fd,2) = 0;
  17871. WFIFOL(fd,6) = data;
  17872. WFIFOSET(fd,packet_len(0xAF0));
  17873. }
  17874. /// Request from the client to retrieve today's attendance reward
  17875. /// 0AEF
  17876. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17877. pc_attendance_claim_reward(sd);
  17878. }
  17879. /// Send out the percentage of weight that causes it to be displayed in red.
  17880. /// 0ADE <percentage>.L
  17881. void clif_weight_limit( struct map_session_data* sd ){
  17882. #if PACKETVER >= 20171025
  17883. nullpo_retv(sd);
  17884. int fd = sd->fd;
  17885. WFIFOHEAD(fd, packet_len(0xADE));
  17886. WFIFOW(fd, 0) = 0xADE;
  17887. #ifdef RENEWAL
  17888. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17889. #else
  17890. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17891. #endif
  17892. WFIFOSET(fd, packet_len(0xADE));
  17893. #endif
  17894. }
  17895. enum e_private_airship_response : uint32{
  17896. PRIVATEAIRSHIP_OK,
  17897. PRIVATEAIRSHIP_RETRY,
  17898. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17899. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17900. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17901. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17902. };
  17903. /// Send out the response to a private airship request
  17904. /// 0A4A <response>.L
  17905. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17906. #if PACKETVER >= 20180321
  17907. nullpo_retv( sd );
  17908. int fd = sd->fd;
  17909. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17910. WFIFOW( fd, 0 ) = 0xA4A;
  17911. WFIFOL( fd, 2 ) = response;
  17912. WFIFOSET( fd, packet_len( 0xA4A ) );
  17913. #endif
  17914. }
  17915. /// Parses a request for a private airship
  17916. /// 0A49 <mapname>.16B <itemid>.W
  17917. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17918. #if PACKETVER >= 20180321
  17919. // Check if the feature is enabled
  17920. if( !battle_config.feature_privateairship ){
  17921. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17922. return;
  17923. }
  17924. // Check if the player is allowed to warp from the source map
  17925. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17926. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17927. return;
  17928. }
  17929. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17930. char mapname[MAP_NAME_LENGTH_EXT];
  17931. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17932. int16 mapindex = mapindex_name2id( mapname );
  17933. // Check if we know the mapname
  17934. if( mapindex < 0 ){
  17935. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17936. return;
  17937. }
  17938. int16 mapid = map_mapindex2mapid( mapindex );
  17939. // Check if the map is available on this server
  17940. if( mapid < 0 ){
  17941. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17942. return;
  17943. }
  17944. // Check if the player tried to warp to the map he is on
  17945. if( sd->bl.m == mapid ){
  17946. // This is blocked by the client, but just to be sure
  17947. return;
  17948. }
  17949. // This can only be a hack, so we prevent it
  17950. if( map_getmapdata( mapid )->instance_id ){
  17951. // Ignore requests to warp directly into a running instance
  17952. return;
  17953. }
  17954. // Check if the player is allowed to warp to the target map
  17955. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17956. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17957. return;
  17958. }
  17959. t_itemid item_id = p->ItemID;
  17960. // Check if the item sent by the client is known to us
  17961. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17962. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17963. return;
  17964. }
  17965. int idx = pc_search_inventory( sd, item_id );
  17966. // Check if the player has the item at all
  17967. if( idx < 0 ){
  17968. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17969. return;
  17970. }
  17971. // Delete the chosen item
  17972. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17973. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17974. return;
  17975. }
  17976. // Warp the player to a random spot on the destination map
  17977. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17978. #endif
  17979. }
  17980. /// Sends out the usage history of the guild storage
  17981. /// 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
  17982. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17983. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17984. #if PACKETVER >= 20140205
  17985. nullpo_retv( sd );
  17986. int fd = sd->fd;
  17987. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17988. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17989. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17990. }else{
  17991. log.clear();
  17992. }
  17993. WFIFOHEAD( fd, size );
  17994. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  17995. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17996. p->PacketLength = size;
  17997. p->result = result;
  17998. p->amount = (uint16)log.size();
  17999. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18000. for( int i = 0; i < log.size(); i++ ){
  18001. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18002. struct guild_log_entry& entry = log[i];
  18003. item->id = entry.id;
  18004. item->itemId = client_nameid( entry.item.nameid );
  18005. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18006. item->action = entry.amount > 0; // action = true(put), false(get)
  18007. item->refine = entry.item.refine;
  18008. item->uniqueId = entry.item.unique_id;
  18009. item->IsIdentified = entry.item.identify;
  18010. item->itemType = itemtype( entry.item.nameid );
  18011. clif_addcards( &item->slot, &entry.item );
  18012. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18013. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18014. item->attribute = entry.item.attribute;
  18015. }
  18016. }
  18017. WFIFOSET( fd, p->PacketLength );
  18018. #endif
  18019. }
  18020. /// Activates the client camera info or updates the client camera with the given values.
  18021. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18022. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18023. #if PACKETVER >= 20160525
  18024. int fd = sd->fd;
  18025. WFIFOHEAD(fd, packet_len(0xa78));
  18026. WFIFOW(fd, 0) = 0xa78;
  18027. WFIFOB(fd, 2) = show;
  18028. WFIFOF(fd, 3) = range;
  18029. WFIFOF(fd, 7) = rotation;
  18030. WFIFOF(fd, 11) = latitude;
  18031. WFIFOSET(fd, packet_len(0xa78));
  18032. #endif
  18033. }
  18034. /// Activates or deactives the client camera info or updates the camera settings.
  18035. /// This packet is triggered by /viewpointvalue or /setcamera
  18036. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18037. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  18038. char command[CHAT_SIZE_MAX];
  18039. // /viewpointvalue
  18040. if( RFIFOB( fd, 2 ) == 1 ){
  18041. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18042. // /setcamera
  18043. }else{
  18044. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18045. }
  18046. is_atcommand( fd, sd, command, 1 );
  18047. }
  18048. /// Send the full list of items in the equip switch window
  18049. /// 0a9b <length>.W { <index>.W <position>.L }*
  18050. void clif_equipswitch_list( struct map_session_data* sd ){
  18051. #if PACKETVER >= 20170208
  18052. int fd = sd->fd;
  18053. int offset, i, position;
  18054. WFIFOW(fd, 0) = 0xa9b;
  18055. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18056. short index = sd->equip_switch_index[i];
  18057. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18058. WFIFOW(fd, offset) = index + 2;
  18059. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18060. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18061. offset += 6;
  18062. }
  18063. }
  18064. WFIFOW(fd, 2) = offset;
  18065. WFIFOSET(fd, offset);
  18066. #endif
  18067. }
  18068. /// Acknowledgement for removing an equip to the equip switch window
  18069. /// 0a9a <index>.W <position.>.L <failure>.W
  18070. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18071. #if PACKETVER >= 20170208
  18072. int fd = sd->fd;
  18073. WFIFOHEAD(fd, packet_len(0xa9a));
  18074. WFIFOW(fd, 0) = 0xa9a;
  18075. WFIFOW(fd, 2) = index + 2;
  18076. WFIFOL(fd, 4) = pos;
  18077. WFIFOW(fd, 8) = failed;
  18078. WFIFOSET(fd, packet_len(0xa9a));
  18079. #endif
  18080. }
  18081. /// Request to remove an equip from the equip switch window
  18082. /// 0a99 <index>.W <position>.L <= 20170502
  18083. /// 0a99 <index>.W
  18084. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  18085. #if PACKETVER >= 20170208
  18086. uint16 index = RFIFOW(fd, 2) - 2;
  18087. bool removed = false;
  18088. if( !battle_config.feature_equipswitch ){
  18089. return;
  18090. }
  18091. // Check if the index is valid
  18092. if( index >= MAX_INVENTORY ){
  18093. return;
  18094. }
  18095. pc_equipswitch_remove( sd, index );
  18096. #endif
  18097. }
  18098. /// Acknowledgement for adding an equip to the equip switch window
  18099. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18100. /// 0a98 <index>.W <position.>.L <flag>.W
  18101. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18102. #if PACKETVER >= 20170208
  18103. int fd = sd->fd;
  18104. WFIFOHEAD(fd, packet_len(0xa98));
  18105. WFIFOW(fd, 0) = 0xa98;
  18106. WFIFOW(fd, 2) = index + 2;
  18107. WFIFOL(fd, 4) = pos;
  18108. #if PACKETVER <= 20170502
  18109. WFIFOL(fd, 8) = flag;
  18110. #else
  18111. WFIFOW(fd, 8) = flag;
  18112. #endif
  18113. WFIFOSET(fd,packet_len(0xa98));
  18114. #endif
  18115. }
  18116. /// Request to add an equip to the equip switch window
  18117. /// 0a97 <index>.W <position>.L
  18118. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  18119. #if PACKETVER >= 20170208
  18120. uint16 index = RFIFOW(fd, 2) - 2;
  18121. uint32 position = RFIFOL(fd, 4);
  18122. if( !battle_config.feature_equipswitch ){
  18123. return;
  18124. }
  18125. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18126. return;
  18127. }
  18128. if( sd->state.trading || sd->npc_shopid ){
  18129. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18130. return;
  18131. }
  18132. if( sd->inventory_data[index]->type == IT_AMMO ){
  18133. position = EQP_AMMO;
  18134. }
  18135. pc_equipitem( sd, index, position, true );
  18136. #endif
  18137. }
  18138. /// Acknowledgement packet for the full equip switch
  18139. /// 0a9d <failed>.W
  18140. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  18141. #if PACKETVER >= 20170208
  18142. int fd = sd->fd;
  18143. WFIFOHEAD(fd, packet_len(0xa9d));
  18144. WFIFOW(fd, 0) = 0xa9d;
  18145. WFIFOW(fd, 2) = failed;
  18146. WFIFOSET(fd, packet_len(0xa9d));
  18147. #endif
  18148. }
  18149. /// Request to do a full equip switch
  18150. /// 0a9c
  18151. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18152. #if PACKETVER >= 20170208
  18153. int i;
  18154. t_tick tick = gettick();
  18155. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18156. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18157. // Client will not let you send a request
  18158. return;
  18159. }
  18160. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18161. if( !battle_config.feature_equipswitch ){
  18162. return;
  18163. }
  18164. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18165. if( i == EQI_MAX ){
  18166. // client will show: "There is no item to replace." and should not even come here
  18167. clif_equipswitch_reply( sd, false );
  18168. return;
  18169. }
  18170. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18171. return;
  18172. }
  18173. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18174. #endif
  18175. }
  18176. /// Request to do a single equip switch
  18177. /// 0ace <index>.W
  18178. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18179. #if PACKETVER >= 20170502
  18180. uint16 index = RFIFOW(fd, 2) - 2;
  18181. if( !battle_config.feature_equipswitch ){
  18182. return;
  18183. }
  18184. // Check if the index is valid
  18185. if( index >= MAX_INVENTORY ){
  18186. return;
  18187. }
  18188. // Check if the item exists
  18189. if (sd->inventory_data[index] == nullptr)
  18190. return;
  18191. // Check if the item was already added to equip switch
  18192. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18193. if( sd->npc_id ){
  18194. #ifdef RENEWAL
  18195. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18196. clif_msg( sd, WORK_IN_PROGRESS );
  18197. return;
  18198. }
  18199. #endif
  18200. if( !sd->npc_item_flag ){
  18201. return;
  18202. }
  18203. }
  18204. pc_equipswitch( sd, index );
  18205. return;
  18206. }
  18207. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18208. #endif
  18209. }
  18210. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18211. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18212. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18213. // Only rolling cutter is supported for now
  18214. if( p->skillId != GC_ROLLINGCUTTER ){
  18215. return;
  18216. }
  18217. // Already running - cant happen on officials, since only one skill is supported
  18218. if( sd->skill_keep_using.skill_id != 0 ){
  18219. return;
  18220. }
  18221. sd->skill_keep_using.tid = INVALID_TIMER;
  18222. sd->skill_keep_using.skill_id = p->skillId;
  18223. sd->skill_keep_using.level = p->skillLv;
  18224. sd->skill_keep_using.target = p->targetId;
  18225. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18226. #endif
  18227. }
  18228. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18229. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18230. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18231. // Not running
  18232. if( sd->skill_keep_using.skill_id == 0 ){
  18233. return;
  18234. }
  18235. #if 0
  18236. // Hack
  18237. if( p->skillId != sd->skill_keep_using.skill_id ){
  18238. return;
  18239. }
  18240. #endif
  18241. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18242. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18243. sd->skill_keep_using.tid = INVALID_TIMER;
  18244. }
  18245. sd->skill_keep_using.skill_id = 0;
  18246. sd->skill_keep_using.level = 0;
  18247. sd->skill_keep_using.target = 0;
  18248. #endif
  18249. }
  18250. void clif_ping( struct map_session_data* sd ){
  18251. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18252. nullpo_retv( sd );
  18253. int fd = sd->fd;
  18254. if( !session_isActive( fd ) ){
  18255. return;
  18256. }
  18257. struct PACKET_ZC_PING_LIVE p = {};
  18258. p.packetType = HEADER_ZC_PING_LIVE;
  18259. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18260. #endif
  18261. }
  18262. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18263. nullpo_ret( sd );
  18264. int fd = sd->fd;
  18265. if( !session_isActive( fd ) ){
  18266. return 0;
  18267. }
  18268. t_tick tick = va_arg( ap, t_tick );
  18269. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18270. clif_ping( sd );
  18271. }
  18272. return 0;
  18273. }
  18274. TIMER_FUNC( clif_ping_timer ){
  18275. map_foreachpc( clif_ping_timer_sub, gettick() );
  18276. return 0;
  18277. }
  18278. /**
  18279. * Opens the refine UI on the designated client.
  18280. * 0aa0
  18281. */
  18282. void clif_refineui_open( struct map_session_data* sd ){
  18283. #if PACKETVER >= 20161012
  18284. nullpo_retv( sd );
  18285. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18286. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18287. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18288. sd->state.refineui_open = true;
  18289. #endif
  18290. }
  18291. /**
  18292. * Parses cancel/close of the refine UI on client side.
  18293. * 0aa4
  18294. */
  18295. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18296. #if PACKETVER >= 20161012
  18297. sd->state.refineui_open = false;
  18298. #endif
  18299. }
  18300. /**
  18301. * Adds the selected item into the refine UI and sends the possible materials
  18302. * to the client.
  18303. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18304. */
  18305. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18306. #if PACKETVER >= 20161012
  18307. int fd = sd->fd;
  18308. // Get the item db reference
  18309. struct item_data* id = sd->inventory_data[index];
  18310. // No item data was found
  18311. if( id == NULL ){
  18312. return;
  18313. }
  18314. // Check the inventory
  18315. struct item* item = &sd->inventory.u.items_inventory[index];
  18316. // No item was found at the given index
  18317. if( item == NULL ){
  18318. return;
  18319. }
  18320. // Check if the item is identified
  18321. if( !item->identify ){
  18322. return;
  18323. }
  18324. // Check if the item is broken
  18325. if( item->attribute ){
  18326. return;
  18327. }
  18328. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18329. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18330. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18331. p->itemIndex = client_index( index );
  18332. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18333. // No possibilities were found
  18334. if( info == nullptr ){
  18335. p->blacksmithBlessing = 0;
  18336. }else{
  18337. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18338. uint16 count = 0;
  18339. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18340. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18341. if( cost != nullptr ){
  18342. p->req[count].itemId = client_nameid( cost->nameid );
  18343. p->req[count].chance = (uint8)( cost->chance / 100 );
  18344. p->req[count].zeny = cost->zeny;
  18345. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18346. count++;
  18347. }
  18348. }
  18349. }
  18350. clif_send( p, p->packetLength, &sd->bl, SELF );
  18351. #endif
  18352. }
  18353. /**
  18354. * Client request to add an item to the refine UI.
  18355. * 0aa1 <index>.W
  18356. */
  18357. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18358. #if PACKETVER >= 20161012
  18359. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18360. uint16 index = server_index( p->index );
  18361. // Check if the refine UI is open
  18362. if( !sd->state.refineui_open ){
  18363. return;
  18364. }
  18365. // Check if the index is valid
  18366. if( index >= MAX_INVENTORY ){
  18367. return;
  18368. }
  18369. // Send out the requirements for the refine process
  18370. clif_refineui_info( sd, index );
  18371. #endif
  18372. }
  18373. /**
  18374. * Client requests to try to refine an item.
  18375. * 0aa3 <index>.W <material>.W <catalyst>.B
  18376. */
  18377. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18378. #if PACKETVER >= 20161012
  18379. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18380. uint16 index = server_index( p->index );
  18381. t_itemid material = p->itemId;
  18382. int16 j;
  18383. // Check if the refine UI is open
  18384. if( !sd->state.refineui_open ){
  18385. return;
  18386. }
  18387. // Check if the index is valid
  18388. if( index >= MAX_INVENTORY ){
  18389. return;
  18390. }
  18391. // Get the item db reference
  18392. struct item_data* id = sd->inventory_data[index];
  18393. // No item data was found
  18394. if( id == NULL ){
  18395. return;
  18396. }
  18397. // Check the inventory
  18398. struct item* item = &sd->inventory.u.items_inventory[index];
  18399. // No item was found at the given index
  18400. if( item == NULL ){
  18401. return;
  18402. }
  18403. // Check if the item is identified
  18404. if( !item->identify ){
  18405. return;
  18406. }
  18407. // Check if the item is broken
  18408. if( item->attribute ){
  18409. return;
  18410. }
  18411. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18412. // No refine possible
  18413. if( info == nullptr ){
  18414. return;
  18415. }
  18416. // No possibilities were found
  18417. if( info->costs.empty() ){
  18418. return;
  18419. }
  18420. // Check if the player has the selected material
  18421. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18422. return;
  18423. }
  18424. int16 blacksmith_index = -1;
  18425. uint16 blacksmith_amount = 0;
  18426. // Check if the player has enough blacksmith blessings
  18427. if( p->blacksmithBlessing != 0 ){
  18428. blacksmith_amount = info->blessing_amount;
  18429. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18430. if( blacksmith_amount == 0 ){
  18431. return;
  18432. }
  18433. // Check if the player has blacksmith blessings
  18434. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18435. return;
  18436. }
  18437. // Check if the player has enough blacksmith blessings
  18438. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18439. return;
  18440. }
  18441. }
  18442. std::shared_ptr<s_refine_cost> cost = nullptr;
  18443. for( const auto& pair : info->costs ){
  18444. if( pair.second->nameid == material ){
  18445. cost = pair.second;
  18446. break;
  18447. }
  18448. }
  18449. // The material was not in the list of possible materials
  18450. if( cost == nullptr ){
  18451. return;
  18452. }
  18453. // Try to pay for the refine
  18454. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18455. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18456. return;
  18457. }
  18458. // Delete the required material
  18459. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18460. return;
  18461. }
  18462. // Delete the required blacksmith blessings
  18463. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18464. return;
  18465. }
  18466. // Try to refine the item
  18467. if( cost->chance >= ( rnd() % 10000 ) ){
  18468. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18469. // Success
  18470. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18471. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18472. clif_misceffect( &sd->bl, 3 );
  18473. clif_refine( fd, 0, index, item->refine );
  18474. if (info->broadcast_success) {
  18475. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18476. }
  18477. if( id->type == IT_WEAPON ){
  18478. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18479. }
  18480. clif_refineui_info( sd, index );
  18481. }else{
  18482. // Failure
  18483. if (info->broadcast_failure) {
  18484. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18485. }
  18486. // Blacksmith blessings were used to prevent breaking and downgrading
  18487. if( blacksmith_amount > 0 ){
  18488. clif_refine( fd, 3, index, item->refine );
  18489. clif_refineui_info( sd, index );
  18490. // Delete the item if it is breakable
  18491. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18492. clif_refine( fd, 1, index, item->refine );
  18493. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18494. // Downgrade the item if necessary
  18495. }else if( cost->downgrade_amount > 0 ){
  18496. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18497. clif_refine( fd, 2, index, item->refine );
  18498. clif_refineui_info(sd, index);
  18499. // Only show failure, but dont do anything
  18500. }else{
  18501. clif_refine( fd, 3, index, item->refine );
  18502. clif_refineui_info( sd, index );
  18503. }
  18504. clif_misceffect( &sd->bl, 2 );
  18505. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18506. }
  18507. #endif
  18508. }
  18509. void clif_unequipall_reply( struct map_session_data* sd, bool failed ){
  18510. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18511. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18512. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18513. p.result = failed;
  18514. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18515. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18516. }
  18517. void clif_parse_unequipall( int fd, struct map_session_data* sd ){
  18518. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18519. if( pc_cant_act( sd ) ){
  18520. clif_unequipall_reply( sd, true );
  18521. return;
  18522. }
  18523. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18524. if( sd->equip_index[i] >= 0 ){
  18525. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18526. }
  18527. }
  18528. clif_unequipall_reply( sd, false );
  18529. #endif
  18530. }
  18531. void clif_stylist_response( struct map_session_data* sd, bool failed ){
  18532. #if PACKETVER >= 20151104
  18533. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18534. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18535. p.flag = failed;
  18536. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18537. if( !failed ){
  18538. sd->state.stylist_open = false;
  18539. }
  18540. #endif
  18541. }
  18542. bool clif_parse_stylist_buy_sub( struct map_session_data* sd, _look look, int16 index ){
  18543. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18544. if( list == nullptr ){
  18545. return false;
  18546. }
  18547. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18548. if( entry == nullptr ){
  18549. return false;
  18550. }
  18551. std::shared_ptr<s_stylist_costs> costs;
  18552. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18553. costs = entry->doram;
  18554. }else{
  18555. costs = entry->human;
  18556. }
  18557. if( costs == nullptr ){
  18558. return false;
  18559. }
  18560. if( sd->status.zeny < costs->price ){
  18561. return false;
  18562. }
  18563. int16 inventoryIndex = -1;
  18564. if( costs->requiredItem != 0 ){
  18565. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18566. if( inventoryIndex < 0 ){
  18567. // No other option
  18568. if( costs->requiredItemBox == 0 ){
  18569. return false;
  18570. }
  18571. // Check if the box that contains the item is in the inventory
  18572. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18573. // The box containing the item also does not exist
  18574. if( inventoryIndex < 0 ){
  18575. return false;
  18576. }
  18577. }
  18578. }else if( costs->requiredItemBox != 0 ){
  18579. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18580. if( inventoryIndex < 0 ){
  18581. return false;
  18582. }
  18583. }
  18584. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18585. return false;
  18586. }
  18587. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18588. return false;
  18589. }
  18590. switch( look ){
  18591. case LOOK_HAIR:
  18592. case LOOK_HAIR_COLOR:
  18593. case LOOK_CLOTHES_COLOR:
  18594. case LOOK_BODY2:
  18595. pc_changelook( sd, look, entry->value );
  18596. break;
  18597. case LOOK_HEAD_BOTTOM:
  18598. case LOOK_HEAD_MID:
  18599. case LOOK_HEAD_TOP: {
  18600. struct mail_message msg = {};
  18601. msg.dest_id = sd->status.char_id;
  18602. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18603. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18604. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18605. msg.item[0].nameid = entry->value;
  18606. msg.item[0].identify = 1;
  18607. msg.item[0].amount = 1;
  18608. msg.status = MAIL_NEW;
  18609. msg.type = MAIL_INBOX_NORMAL;
  18610. msg.timestamp = time( nullptr );
  18611. intif_Mail_send( 0, &msg );
  18612. } break;
  18613. }
  18614. return true;
  18615. }
  18616. void clif_parse_stylist_buy( int fd, struct map_session_data* sd ){
  18617. #if PACKETVER >= 20151104
  18618. #if PACKETVER >= 20180516
  18619. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18620. #else
  18621. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18622. #endif
  18623. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18624. clif_stylist_response( sd, true );
  18625. return;
  18626. }
  18627. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18628. clif_stylist_response( sd, true );
  18629. return;
  18630. }
  18631. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18632. clif_stylist_response( sd, true );
  18633. return;
  18634. }
  18635. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18636. clif_stylist_response( sd, true );
  18637. return;
  18638. }
  18639. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18640. clif_stylist_response( sd, true );
  18641. return;
  18642. }
  18643. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18644. clif_stylist_response( sd, true );
  18645. return;
  18646. }
  18647. #if PACKETVER >= 20180516
  18648. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18649. clif_stylist_response( sd, true );
  18650. return;
  18651. }
  18652. #endif
  18653. clif_stylist_response( sd, false );
  18654. #endif
  18655. }
  18656. void clif_parse_stylist_close( int fd, struct map_session_data* sd ){
  18657. #if PACKETVER >= 20151104
  18658. sd->state.stylist_open = false;
  18659. #endif
  18660. }
  18661. void clif_inventory_expansion_info( struct map_session_data* sd ){
  18662. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18663. nullpo_retv( sd );
  18664. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18665. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18666. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18667. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18668. #endif
  18669. }
  18670. enum class e_inventory_expansion_response : uint8{
  18671. ASK_CONFIRMATION = 0,
  18672. FAILED,
  18673. BUSY,
  18674. MISSING_ITEM,
  18675. MAXIMUM_REACHED
  18676. };
  18677. void clif_inventory_expansion_response( struct map_session_data* sd, e_inventory_expansion_response response ){
  18678. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18679. nullpo_retv( sd );
  18680. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18681. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18682. p.result = (uint8)response;
  18683. p.itemId = sd->state.inventory_expansion_confirmation;
  18684. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18685. #endif
  18686. }
  18687. void clif_parse_inventory_expansion_request( int fd, struct map_session_data* sd ){
  18688. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18689. // Check if player is dead or busy with other stuff
  18690. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18691. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18692. return;
  18693. }
  18694. // Check if the player already reached the maximum
  18695. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18696. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18697. return;
  18698. }
  18699. static std::map<t_itemid, uint16> items = {
  18700. // The order of entries in this list defines which will be used first
  18701. // This order and the usable items are hardcoded into the client
  18702. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18703. { ITEMID_INVENTORY_EX_EVT, 10 },
  18704. { ITEMID_INVENTORY_EX_DIS, 10 },
  18705. { ITEMID_INVENTORY_EX, 10 },
  18706. };
  18707. int16 index = -1;
  18708. bool found_over_limit = false;
  18709. for( const auto& entry : items ){
  18710. // Check if the player has the required item
  18711. index = pc_search_inventory( sd, entry.first );
  18712. // Found an item
  18713. if( index >= 0 ){
  18714. // Check if the player would exceed the maximum
  18715. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18716. found_over_limit = true;
  18717. }else{
  18718. found_over_limit = false;
  18719. sd->state.inventory_expansion_confirmation = entry.first;
  18720. sd->state.inventory_expansion_amount = entry.second;
  18721. break;
  18722. }
  18723. }
  18724. }
  18725. // Check if an item was found
  18726. if( sd->state.inventory_expansion_confirmation == 0 ){
  18727. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18728. return;
  18729. }
  18730. // Check if an item would have been found, but the player would exceed the maximum
  18731. if( found_over_limit ){
  18732. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18733. return;
  18734. }
  18735. // The player met all requirements => ask him for confirmation
  18736. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18737. #endif
  18738. }
  18739. enum class e_inventory_expansion_result : uint8{
  18740. SUCCESS = 0,
  18741. FAILED,
  18742. BUSY,
  18743. MISSING_ITEM,
  18744. MAXIMUM_REACHED
  18745. };
  18746. void clif_inventory_expansion_result( struct map_session_data* sd, e_inventory_expansion_result result ){
  18747. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18748. nullpo_retv( sd );
  18749. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18750. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18751. p.result = (uint8)result;
  18752. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18753. // Reset the state tracking
  18754. sd->state.inventory_expansion_confirmation = 0;
  18755. sd->state.inventory_expansion_amount = 0;
  18756. #endif
  18757. }
  18758. void clif_parse_inventory_expansion_confirm( int fd, struct map_session_data* sd ){
  18759. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18760. if( sd->state.inventory_expansion_confirmation == 0 ){
  18761. return;
  18762. }
  18763. // Check if player is dead
  18764. if( pc_isdead( sd ) ){
  18765. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18766. return;
  18767. }
  18768. // Check if the player already reached the maximum
  18769. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18770. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18771. return;
  18772. }
  18773. // Check if the player has the required item
  18774. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18775. // The player did not have the item anymore
  18776. if( index < 0 ){
  18777. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18778. return;
  18779. }
  18780. // Check if the player would exceed the maximum
  18781. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18782. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18783. return;
  18784. }
  18785. // Delete the required item
  18786. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18787. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18788. return;
  18789. }
  18790. // Increase the slots
  18791. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18792. // Save player data (slots) and inventory data (removed item)
  18793. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18794. // Inform the player of success
  18795. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18796. clif_inventory_expansion_info( sd );
  18797. #endif
  18798. }
  18799. void clif_parse_inventory_expansion_reject( int fd, struct map_session_data* sd ){
  18800. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18801. sd->state.inventory_expansion_confirmation = 0;
  18802. sd->state.inventory_expansion_amount = 0;
  18803. #endif
  18804. }
  18805. void clif_barter_open( struct map_session_data& sd, struct npc_data& nd ){
  18806. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18807. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18808. return;
  18809. }
  18810. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18811. if( barter == nullptr ){
  18812. return;
  18813. }
  18814. sd.state.barter_open = true;
  18815. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18816. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18817. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  18818. int16 count = 0;
  18819. for( const auto& itemPair : barter->items ){
  18820. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  18821. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18822. item->nameid = client_nameid( id->nameid );
  18823. item->type = itemtype( id->nameid );
  18824. if( itemPair.second->stockLimited ){
  18825. item->amount = itemPair.second->stock;
  18826. }else{
  18827. item->amount = -1;
  18828. }
  18829. item->weight = id->weight;
  18830. item->index = itemPair.second->index;
  18831. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18832. item->viewSprite = id->look;
  18833. item->location = pc_equippoint_sub( &sd, id.get() );
  18834. #endif
  18835. // Use a loop if someone did not start with index 0
  18836. for( const auto& requirementPair : itemPair.second->requirements ){
  18837. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18838. item->currencyNameid = client_nameid( requirement->nameid );
  18839. item->currencyAmount = requirement->amount;
  18840. // It is a normal barter, cancel after first entry
  18841. break;
  18842. }
  18843. p->packetLength += (int16)( sizeof( *item ) );
  18844. count++;
  18845. }
  18846. clif_send( p, p->packetLength, &sd.bl, SELF );
  18847. #endif
  18848. }
  18849. void clif_parse_barter_close( int fd, struct map_session_data* sd ){
  18850. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18851. if( sd->state.barter_open ){
  18852. sd->npc_shopid = 0;
  18853. sd->state.barter_open = false;
  18854. }
  18855. #endif
  18856. }
  18857. void clif_parse_barter_buy( int fd, struct map_session_data* sd ){
  18858. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18859. // No shop open
  18860. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  18861. return;
  18862. }
  18863. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18864. // Unknown shop
  18865. if( nd == nullptr ){
  18866. return;
  18867. }
  18868. // Not a barter
  18869. if( nd->subtype != NPCTYPE_BARTER ){
  18870. return;
  18871. }
  18872. // It is an extended barter
  18873. if( nd->u.barter.extended ){
  18874. return;
  18875. }
  18876. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  18877. if( barter == nullptr ){
  18878. return;
  18879. }
  18880. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  18881. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  18882. // Empty purchase list
  18883. if( entries == 0 ){
  18884. return;
  18885. }
  18886. std::vector<s_barter_purchase> purchases;
  18887. purchases.reserve( entries );
  18888. // Make sure each shop index and target item id is only used once
  18889. for( int i = 0; i < entries; i++ ){
  18890. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  18891. // Invalid shop index
  18892. if( item == nullptr ){
  18893. return;
  18894. }
  18895. for( int j = i + 1; j < entries; j++ ){
  18896. // Same shop index
  18897. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  18898. return;
  18899. }
  18900. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  18901. // Invalid shop index
  18902. if( item2 == nullptr ){
  18903. return;
  18904. }
  18905. // Same target item id
  18906. if( item->nameid == item2->nameid ){
  18907. return;
  18908. }
  18909. }
  18910. s_barter_purchase purchase = {};
  18911. purchase.item = item;
  18912. purchase.amount = p->list[i].amount;
  18913. purchases.push_back( purchase );
  18914. }
  18915. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  18916. #endif
  18917. }
  18918. void clif_barter_extended_open( struct map_session_data& sd, struct npc_data& nd ){
  18919. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18920. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  18921. return;
  18922. }
  18923. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18924. if( barter == nullptr ){
  18925. return;
  18926. }
  18927. sd.state.barter_extended_open = true;
  18928. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18929. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  18930. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  18931. p->items_count = 0;
  18932. for( const auto& itemPair : barter->items ){
  18933. // Needs dynamic calculation, because of variable currencies
  18934. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  18935. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18936. item->nameid = client_nameid( id->nameid );
  18937. item->type = itemtype( id->nameid );
  18938. if( itemPair.second->stockLimited ){
  18939. item->amount = itemPair.second->stock;
  18940. }else{
  18941. item->amount = -1;
  18942. }
  18943. item->weight = id->weight;
  18944. item->index = itemPair.second->index;
  18945. item->zeny = itemPair.second->price;
  18946. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18947. item->viewSprite = id->look;
  18948. item->location = pc_equippoint_sub( &sd, id.get() );
  18949. #endif
  18950. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  18951. p->items_count++;
  18952. item->currency_count = 0;
  18953. for( const auto& requirementPair : itemPair.second->requirements ){
  18954. // Needs dynamic calculation, because of variable currencies
  18955. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  18956. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18957. req->nameid = requirement->nameid;
  18958. if( requirement->refine >= 0 ){
  18959. req->refine_level = requirement->refine;
  18960. }else{
  18961. req->refine_level = 0;
  18962. }
  18963. req->amount = requirement->amount;
  18964. req->type = itemtype( requirement->nameid );
  18965. p->packetLength += (int16)( sizeof( *req ) );
  18966. item->currency_count++;
  18967. }
  18968. }
  18969. clif_send( p, p->packetLength, &sd.bl, SELF );
  18970. #endif
  18971. }
  18972. void clif_parse_barter_extended_close( int fd, struct map_session_data* sd ){
  18973. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18974. if( sd->state.barter_extended_open ){
  18975. sd->npc_shopid = 0;
  18976. sd->state.barter_extended_open = false;
  18977. }
  18978. #endif
  18979. }
  18980. void clif_parse_barter_extended_buy( int fd, struct map_session_data* sd ){
  18981. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18982. // No shop open
  18983. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  18984. return;
  18985. }
  18986. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18987. // Unknown shop
  18988. if( nd == nullptr ){
  18989. return;
  18990. }
  18991. // Not a barter
  18992. if( nd->subtype != NPCTYPE_BARTER ){
  18993. return;
  18994. }
  18995. // Not an extended barter
  18996. if( !nd->u.barter.extended ){
  18997. return;
  18998. }
  18999. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19000. if( barter == nullptr ){
  19001. return;
  19002. }
  19003. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19004. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19005. // Empty purchase list
  19006. if( entries == 0 ){
  19007. return;
  19008. }
  19009. std::vector<s_barter_purchase> purchases;
  19010. purchases.reserve( entries );
  19011. // Make sure each shop index and target item id is only used once
  19012. for( int i = 0; i < entries; i++ ){
  19013. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19014. // Invalid shop index
  19015. if( item == nullptr ){
  19016. return;
  19017. }
  19018. for( int j = i + 1; j < entries; j++ ){
  19019. // Same shop index
  19020. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19021. return;
  19022. }
  19023. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19024. // Invalid shop index
  19025. if( item2 == nullptr ){
  19026. return;
  19027. }
  19028. // Same target item id
  19029. if( item->nameid == item2->nameid ){
  19030. return;
  19031. }
  19032. }
  19033. s_barter_purchase purchase = {};
  19034. purchase.item = item;
  19035. purchase.amount = p->list[i].amount;
  19036. purchases.push_back( purchase );
  19037. }
  19038. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19039. #endif
  19040. }
  19041. void clif_summon_init(struct mob_data& md) {
  19042. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19043. struct block_list* master_bl = battle_get_master(&md.bl);
  19044. if( master_bl == nullptr ){
  19045. return;
  19046. }
  19047. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19048. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19049. p.summonAID = md.bl.id;
  19050. p.CurrentHP = md.status.hp;
  19051. p.MaxHP = md.status.max_hp;
  19052. clif_send( &p, sizeof( p ), master_bl, SELF );
  19053. #endif
  19054. }
  19055. void clif_summon_hp_bar(struct mob_data& md) {
  19056. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19057. struct block_list* master_bl = battle_get_master(&md.bl);
  19058. if( master_bl == nullptr ){
  19059. return;
  19060. }
  19061. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19062. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19063. p.summonAID = md.bl.id;
  19064. p.VarId = SP_HP; // HP parameter
  19065. p.Value = md.status.hp;
  19066. clif_send( &p, sizeof( p ), master_bl, SELF );
  19067. #endif
  19068. }
  19069. void clif_laphine_synthesis_open( struct map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19070. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19071. nullpo_retv( sd );
  19072. sd->state.laphine_synthesis = synthesis->item_id;
  19073. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19074. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19075. p.itemId = client_nameid( synthesis->item_id );
  19076. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19077. #endif
  19078. }
  19079. void clif_parse_laphine_synthesis_close( int fd, struct map_session_data* sd ){
  19080. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19081. sd->state.laphine_synthesis = 0;
  19082. #endif
  19083. }
  19084. enum e_laphine_synthesis_result : int16{
  19085. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19086. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19087. LAPHINE_SYNTHESIS_ITEM = 7
  19088. };
  19089. void clif_laphine_synthesis_result( struct map_session_data* sd, enum e_laphine_synthesis_result result ){
  19090. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19091. nullpo_retv( sd );
  19092. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19093. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19094. p.result = result;
  19095. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19096. #endif
  19097. }
  19098. void clif_parse_laphine_synthesis( int fd, struct map_session_data* sd ){
  19099. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19100. if( sd->state.laphine_synthesis == 0 ){
  19101. return;
  19102. }
  19103. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19104. if( sd->state.laphine_synthesis != p->itemId ){
  19105. return;
  19106. }
  19107. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19108. if( synthesis == nullptr ){
  19109. return;
  19110. }
  19111. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19112. // Player sent more or less than actually required
  19113. if( count != synthesis->requiredRequirements ){
  19114. return;
  19115. }
  19116. // Check for duplicates
  19117. for( size_t i = 0; i < count; i++ ){
  19118. for( size_t j = i + 1; j < count; j++ ){
  19119. if( p->items[i].index == p->items[j].index ){
  19120. return;
  19121. }
  19122. }
  19123. }
  19124. for( size_t i = 0; i < count; i++ ){
  19125. int16 index = server_index( p->items[i].index );
  19126. if( index >= MAX_INVENTORY ){
  19127. return;
  19128. }
  19129. if( sd->inventory_data[i] == nullptr ){
  19130. return;
  19131. }
  19132. struct item* item = &sd->inventory.u.items_inventory[index];
  19133. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19134. if( requirement == nullptr ){
  19135. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19136. return;
  19137. }
  19138. if( p->items[i].count != requirement->amount ){
  19139. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19140. return;
  19141. }
  19142. if( item->amount < requirement->amount ){
  19143. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19144. return;
  19145. }
  19146. if( item->refine < synthesis->minimumRefine ){
  19147. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19148. return;
  19149. }
  19150. if( item->refine > synthesis->maximumRefine ){
  19151. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19152. return;
  19153. }
  19154. if( item->equip != 0 ){
  19155. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19156. return;
  19157. }
  19158. if( item->equipSwitch != 0 ){
  19159. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19160. return;
  19161. }
  19162. }
  19163. // If triggered from item
  19164. if( sd->itemid == sd->state.laphine_synthesis ){
  19165. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19166. if( index < 0 ){
  19167. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19168. return;
  19169. }
  19170. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19171. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19172. return;
  19173. }
  19174. }
  19175. }
  19176. for( size_t i = 0; i < count; i++ ){
  19177. int16 index = server_index( p->items[i].index );
  19178. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19179. return;
  19180. }
  19181. }
  19182. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19183. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19184. #endif
  19185. }
  19186. void clif_laphine_upgrade_open( struct map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19187. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19188. nullpo_retv( sd );
  19189. sd->state.laphine_upgrade = upgrade->item_id;
  19190. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19191. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19192. p.itemId = client_nameid( upgrade->item_id );
  19193. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19194. #endif
  19195. }
  19196. void clif_parse_laphine_upgrade_close( int fd, struct map_session_data* sd ){
  19197. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19198. sd->state.laphine_upgrade = 0;
  19199. #endif
  19200. }
  19201. void clif_laphine_upgrade_result( struct map_session_data *sd, bool failed ){
  19202. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19203. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19204. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19205. p.result = failed;
  19206. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19207. #endif
  19208. }
  19209. static void clif_item_preview( struct map_session_data *sd, int16 index ){
  19210. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19211. nullpo_retv( sd );
  19212. struct item* item = &sd->inventory.u.items_inventory[index];
  19213. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19214. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19215. p.index = client_index( index );
  19216. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19217. p.isDamaged = item->attribute != 0;
  19218. #endif
  19219. p.refiningLevel = item->refine;
  19220. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19221. p.grade = item->enchantgrade;
  19222. #endif
  19223. clif_addcards( &p.slot, item );
  19224. clif_add_random_options( p.option_data, item );
  19225. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19226. #endif
  19227. }
  19228. void clif_parse_laphine_upgrade( int fd, struct map_session_data* sd ){
  19229. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19230. if( sd->state.laphine_upgrade == 0 ){
  19231. return;
  19232. }
  19233. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19234. if( sd->state.laphine_upgrade != p->itemId ){
  19235. return;
  19236. }
  19237. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19238. if( upgrade == nullptr ){
  19239. return;
  19240. }
  19241. uint16 index = server_index( p->index );
  19242. if( index >= MAX_INVENTORY ){
  19243. return;
  19244. }
  19245. if( sd->inventory_data[index] == nullptr ){
  19246. return;
  19247. }
  19248. struct item* item = &sd->inventory.u.items_inventory[index];
  19249. // Not a valid target item
  19250. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19251. clif_laphine_upgrade_result( sd, true );
  19252. return;
  19253. }
  19254. // If target item is not identified
  19255. if( item->identify == 0 ){
  19256. clif_laphine_upgrade_result( sd, true );
  19257. return;
  19258. }
  19259. // If target item is equipped
  19260. if( item->equip != 0 ){
  19261. clif_laphine_upgrade_result( sd, true );
  19262. return;
  19263. }
  19264. // If target item is in equipswitch
  19265. if( item->equipSwitch != 0 ){
  19266. clif_laphine_upgrade_result( sd, true );
  19267. return;
  19268. }
  19269. // Check minimum refine requirement
  19270. if( item->refine < upgrade->minimumRefine ){
  19271. clif_laphine_upgrade_result( sd, true );
  19272. return;
  19273. }
  19274. // Check maximum refine requirement
  19275. if( item->refine > upgrade->maximumRefine ){
  19276. clif_laphine_upgrade_result( sd, true );
  19277. return;
  19278. }
  19279. // If no cards are allowed
  19280. if( !upgrade->cardsAllowed ){
  19281. for( int i = 0; i < MAX_SLOTS; i++ ){
  19282. if( item->card[i] != 0 ){
  19283. clif_laphine_upgrade_result( sd, true );
  19284. return;
  19285. }
  19286. }
  19287. }
  19288. // If random options are required
  19289. if( upgrade->requiredRandomOptions > 0 ){
  19290. int i;
  19291. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19292. if( item->option[i].id != 0 ){
  19293. break;
  19294. }
  19295. }
  19296. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19297. clif_laphine_upgrade_result( sd, true );
  19298. return;
  19299. }
  19300. }
  19301. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19302. if( index2 < 0 ){
  19303. clif_laphine_upgrade_result( sd, true );
  19304. return;
  19305. }
  19306. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19307. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19308. return;
  19309. }
  19310. }
  19311. // Log removal of item
  19312. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19313. // Visually remove it from the client
  19314. clif_delitem( sd, index, 1, 0 );
  19315. // Apply the random options
  19316. if( upgrade->randomOptionGroup != nullptr ){
  19317. upgrade->randomOptionGroup->apply( *item );
  19318. }
  19319. // Change the refine rate if needed
  19320. if( upgrade->resultRefine > 0 ){
  19321. // Absolute refine level change
  19322. item->refine = max( item->refine, upgrade->resultRefine );
  19323. }else if( upgrade->resultRefineMaximum > 0 ){
  19324. // If a minimum is specified it can also downgrade
  19325. if( upgrade->resultRefineMinimum ){
  19326. item->refine = rnd_value( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum );
  19327. }else{
  19328. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19329. item->refine = rnd_value( item->refine, upgrade->resultRefineMaximum );
  19330. }
  19331. }else if( upgrade->resultRefineMinimum > 0 ){
  19332. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19333. item->refine = rnd_value( upgrade->resultRefineMinimum, MAX_REFINE );
  19334. }
  19335. // Log retrieving the item again -> with the new options
  19336. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19337. // Make it visible for the client again
  19338. clif_additem( sd, index, 1, 0 );
  19339. // Open a preview of the item
  19340. clif_item_preview( sd, index );
  19341. // Tell the client we are done
  19342. clif_laphine_upgrade_result( sd, false );
  19343. #endif
  19344. }
  19345. void clif_enchantgrade_add( struct map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19346. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19347. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19348. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19349. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19350. if( index < UINT16_MAX ){
  19351. p->index = client_index( index );
  19352. if( sd.inventory.u.items_inventory[index].refine >= gradeLevel->refine ){
  19353. p->success_chance = gradeLevel->chance / 100;
  19354. }else{
  19355. p->success_chance = 0;
  19356. }
  19357. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19358. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19359. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19360. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19361. // Not displayed by client
  19362. p->protect_itemid = 0;
  19363. p->protect_amount = 0;
  19364. int i = 0;
  19365. for( const auto& pair : gradeLevel->options ){
  19366. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19367. p->material_info[i].nameid = client_nameid( option->item );
  19368. p->material_info[i].amount = option->amount;
  19369. p->material_info[i].price = option->zeny;
  19370. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19371. p->material_info[i].breakable = option->breaking_rate > 0;
  19372. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19373. i++;
  19374. }
  19375. }else{
  19376. p->index = -1;
  19377. p->success_chance = 0;
  19378. p->blessing_info.id = 0;
  19379. p->blessing_info.amount = 0;
  19380. p->blessing_info.max_blessing = 0;
  19381. p->blessing_info.bonus = 0;
  19382. p->protect_itemid = 0;
  19383. p->protect_amount = 0;
  19384. }
  19385. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19386. #endif
  19387. }
  19388. void clif_parse_enchantgrade_add( int fd, struct map_session_data* sd ){
  19389. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19390. nullpo_retv( sd );
  19391. if( !sd->state.enchantgrade_open ){
  19392. return;
  19393. }
  19394. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19395. uint16 index = server_index( p->index );
  19396. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19397. return;
  19398. }
  19399. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19400. // Unsupported item type - no answer, because client should have actually prevented this request
  19401. if( enchantgrade == nullptr ){
  19402. return;
  19403. }
  19404. // Item can't be enhanced
  19405. if( !sd->inventory_data[index]->flag.gradable ){
  19406. return;
  19407. }
  19408. uint16 level = 0;
  19409. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19410. level = sd->inventory_data[index]->weapon_level;
  19411. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19412. level = sd->inventory_data[index]->armor_level;
  19413. }
  19414. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19415. // Cannot upgrade this weapon or armor level
  19416. if( enchantgradelevels == enchantgrade->levels.end() ){
  19417. clif_enchantgrade_add( *sd );
  19418. return;
  19419. }
  19420. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19421. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19422. if( enchantgradelevel == nullptr ){
  19423. return;
  19424. }
  19425. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19426. #endif
  19427. }
  19428. /// <summary>
  19429. /// Sends the result for trying to enchant an item
  19430. /// </summary>
  19431. /// <param name="sd">The player session</param>
  19432. /// <param name="index">The target item</param>
  19433. /// <param name="result">
  19434. /// 0= The grade has been successfully upgraded.
  19435. /// 1= Refinement failed.
  19436. /// 2= The refine level has decreased.
  19437. /// 3= Equipment destroyed.
  19438. /// 4= The equipment is protected.
  19439. /// </param>
  19440. void clif_enchantgrade_result( struct map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19441. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19442. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19443. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19444. p.index = client_index( index );
  19445. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19446. p.result = result;
  19447. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19448. #endif
  19449. }
  19450. void clif_enchantgrade_announce( struct map_session_data& sd, struct item& item, bool success ){
  19451. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19452. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19453. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19454. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19455. p.itemId = client_nameid( item.nameid );
  19456. p.grade = item.enchantgrade;
  19457. p.status = success;
  19458. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19459. #endif
  19460. }
  19461. void clif_parse_enchantgrade_start( int fd, struct map_session_data* sd ){
  19462. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19463. nullpo_retv( sd );
  19464. if( !sd->state.enchantgrade_open ){
  19465. return;
  19466. }
  19467. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19468. uint16 index = server_index( p->index );
  19469. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19470. return;
  19471. }
  19472. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19473. // Unsupported item type - no answer
  19474. if( enchantgrade == nullptr ){
  19475. return;
  19476. }
  19477. uint16 level = 0;
  19478. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19479. level = sd->inventory_data[index]->weapon_level;
  19480. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19481. level = sd->inventory_data[index]->armor_level;
  19482. }
  19483. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19484. // Cannot upgrade this weapon or armor level - no answer
  19485. if( enchantgradelevels == enchantgrade->levels.end() ){
  19486. return;
  19487. }
  19488. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19489. // Cannot increase enchantgrade any further - no answer
  19490. if( enchantgradelevel == nullptr ){
  19491. return;
  19492. }
  19493. // Not refined enough
  19494. if( sd->inventory.u.items_inventory[index].refine < enchantgradelevel->refine ){
  19495. return;
  19496. }
  19497. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19498. // Unknown option id - no answer
  19499. if( option == nullptr ){
  19500. return;
  19501. }
  19502. // Not enough zeny
  19503. if( sd->status.zeny < option->zeny ){
  19504. return;
  19505. }
  19506. uint16 totalChance = enchantgradelevel->chance;
  19507. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19508. std::unordered_map<uint16, uint16> requiredItems;
  19509. if( p->blessing_flag ){
  19510. // If the catalysator item is the same as the option item build the sum of amounts
  19511. if( enchantgradelevel->catalyst.item == option->item ){
  19512. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19513. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19514. if( index < 0 ){
  19515. return;
  19516. }
  19517. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19518. return;
  19519. }
  19520. requiredItems[index] = amount;
  19521. }else{
  19522. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19523. // Check catalysator item
  19524. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19525. if( index < 0 ){
  19526. return;
  19527. }
  19528. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19529. return;
  19530. }
  19531. requiredItems[index] = amount;
  19532. // Check option item
  19533. index = pc_search_inventory( sd, option->item );
  19534. if( index < 0 ){
  19535. return;
  19536. }
  19537. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19538. return;
  19539. }
  19540. requiredItems[index] = option->amount;
  19541. }
  19542. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19543. }else{
  19544. // Check option item
  19545. int16 index = pc_search_inventory( sd, option->item );
  19546. if( index < 0 ){
  19547. return;
  19548. }
  19549. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19550. return;
  19551. }
  19552. requiredItems[index] = option->amount;
  19553. }
  19554. // All items should be there, start deleting
  19555. for( const auto& pair : requiredItems ){
  19556. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19557. return;
  19558. }
  19559. }
  19560. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE, nullptr ) > 0 ){
  19561. return;
  19562. }
  19563. if( rnd()%10000 < totalChance ){
  19564. // Log removal of item
  19565. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19566. // Increase enchantgrade
  19567. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19568. // On successful enchantgrade increase the refine is reset
  19569. sd->inventory.u.items_inventory[index].refine = 0;
  19570. // Log retrieving the item again -> with the new refine and enchantgrade
  19571. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19572. // Show success
  19573. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19574. // Check if it has to be announced
  19575. if( enchantgradelevel->announce ){
  19576. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19577. }
  19578. }else{
  19579. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19580. if( enchantgradelevel->announce ){
  19581. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19582. }
  19583. // Delete the item if it is breakable
  19584. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19585. // Delete the item
  19586. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19587. // Show failure
  19588. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19589. // Downgrade the item if necessary
  19590. }else if( option->downgrade_amount > 0 ){
  19591. // Log removal of item
  19592. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19593. // Decrease refine level
  19594. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19595. // Log retrieving the item again -> with the new refine
  19596. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19597. // Show downgrade
  19598. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19599. // Only show failure, but dont do anything
  19600. }else{
  19601. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19602. }
  19603. }
  19604. #endif
  19605. }
  19606. void clif_parse_enchantgrade_close( int fd, struct map_session_data* sd ){
  19607. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19608. nullpo_retv( sd );
  19609. sd->state.enchantgrade_open = false;
  19610. #endif
  19611. }
  19612. void clif_reputation_type( struct map_session_data& sd, int64 type, int64 points ){
  19613. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19614. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19615. p->packetType = HEADER_ZC_REPUTE_INFO;
  19616. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19617. p->success = true;
  19618. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19619. entry->type = type;
  19620. entry->points = points;
  19621. clif_send( p, p->packetLength, &sd.bl, SELF );
  19622. #endif
  19623. }
  19624. void clif_reputation_list( struct map_session_data& sd ){
  19625. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19626. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19627. p->packetType = HEADER_ZC_REPUTE_INFO;
  19628. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19629. p->success = true;
  19630. size_t index = 0;
  19631. for( const auto& entry : reputation_db ){
  19632. std::shared_ptr<s_reputation> reputation = entry.second;
  19633. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19634. list_entry->type = reputation->id;
  19635. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19636. p->packetLength += sizeof( *list_entry );
  19637. index++;
  19638. }
  19639. clif_send( p, p->packetLength, &sd.bl, SELF );
  19640. #endif
  19641. }
  19642. void clif_item_reform_open( struct map_session_data& sd, t_itemid item ){
  19643. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19644. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19645. p.packetType = HEADER_ZC_OPEN_REFORM_UI;
  19646. p.itemId = item;
  19647. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19648. sd.state.item_reform = item;
  19649. #endif
  19650. }
  19651. void clif_parse_item_reform_close( int fd, struct map_session_data* sd ){
  19652. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19653. sd->state.item_reform = 0;
  19654. #endif
  19655. }
  19656. void clif_item_reform_result( struct map_session_data& sd, uint16 index, uint8 result ){
  19657. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19658. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19659. p.packetType = HEADER_ZC_ITEM_REFORM_ACK;
  19660. p.index = client_index( index );
  19661. p.result = result;
  19662. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19663. if( result == 0 ){
  19664. // Client closes the window on success
  19665. sd.state.item_reform = 0;
  19666. }
  19667. #endif
  19668. }
  19669. void clif_parse_item_reform_start( int fd, struct map_session_data* sd ){
  19670. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19671. // Not opened
  19672. if( sd->state.item_reform == 0 ){
  19673. return;
  19674. }
  19675. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19676. // Item mismatch
  19677. if( p->itemId != sd->state.item_reform ){
  19678. return;
  19679. }
  19680. uint16 index = server_index( p->index );
  19681. if( index >= MAX_INVENTORY ){
  19682. return;
  19683. }
  19684. if( sd->inventory_data[index] == nullptr ){
  19685. return;
  19686. }
  19687. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19688. if( reform == nullptr ){
  19689. return;
  19690. }
  19691. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19692. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19693. if( base == nullptr ){
  19694. return;
  19695. }
  19696. // If target item is not identified
  19697. if( selected_item.identify == 0 ){
  19698. return;
  19699. }
  19700. // If target item is equipped
  19701. if( selected_item.equip != 0 ){
  19702. return;
  19703. }
  19704. // Check minimum refine requirement
  19705. if( selected_item.refine < base->minimumRefine ){
  19706. return;
  19707. }
  19708. // Check maximum refine requirement
  19709. if( selected_item.refine > base->maximumRefine ){
  19710. return;
  19711. }
  19712. // If no cards are allowed
  19713. if( !base->cardsAllowed ){
  19714. for( int i = 0; i < MAX_SLOTS; i++ ){
  19715. if( selected_item.card[i] != 0 ){
  19716. return;
  19717. }
  19718. }
  19719. }
  19720. // If random options are required
  19721. if( base->requiredRandomOptions > 0 ){
  19722. int i;
  19723. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19724. if( selected_item.option[i].id != 0 ){
  19725. break;
  19726. }
  19727. }
  19728. if( ( i + 1 ) < base->requiredRandomOptions ){
  19729. return;
  19730. }
  19731. }
  19732. std::unordered_map<uint16, uint16> materials;
  19733. // Check if all materials exist
  19734. for( const auto& material : base->materials ){
  19735. int16 material_index = pc_search_inventory( sd, material.first );
  19736. if( material_index < 0 ){
  19737. return;
  19738. }
  19739. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19740. return;
  19741. }
  19742. materials[material_index] = material.second;
  19743. }
  19744. // Remove the material
  19745. for( const auto& material : materials ){
  19746. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19747. return;
  19748. }
  19749. }
  19750. // If triggered from item
  19751. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19752. return;
  19753. }
  19754. // Log removal of item
  19755. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19756. // Visually remove it from the client
  19757. clif_delitem( sd, index, 1, 0 );
  19758. // Apply the random options
  19759. if( base->randomOptionGroup != nullptr ){
  19760. base->randomOptionGroup->apply( selected_item );
  19761. }
  19762. // Change the refine rate if needed
  19763. if( base->refineChange != 0 ){
  19764. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19765. }
  19766. // Remove all cards and socket enchants
  19767. if( base->clearSlots ){
  19768. for( int i = 0; i < MAX_SLOTS; i++ ){
  19769. selected_item.card[i] = 0;
  19770. }
  19771. }
  19772. // Remove the current enchantgrade
  19773. if( base->removeEnchantgrade ){
  19774. selected_item.enchantgrade = 0;
  19775. }
  19776. // Finally change the item id
  19777. selected_item.nameid = base->resultItemId;
  19778. // Link inventory data cache to the new item
  19779. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19780. // Log retrieving the item again -> with the new options
  19781. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19782. // Make it visible for the client again
  19783. clif_additem( sd, index, 1, 0 );
  19784. clif_item_reform_result( *sd, index, 0 );
  19785. #endif
  19786. }
  19787. void clif_enchantwindow_open( struct map_session_data& sd, uint64 clientLuaIndex ){
  19788. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19789. // Hardcoded clientside check
  19790. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19791. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  19792. sd.state.item_enchant_index = 0;
  19793. return;
  19794. }
  19795. struct PACKET_ZC_UI_OPEN_V3 p = {};
  19796. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19797. p.type = OUT_UI_ENCHANT;
  19798. p.data = clientLuaIndex;
  19799. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19800. sd.state.item_enchant_index = clientLuaIndex;
  19801. #endif
  19802. }
  19803. void clif_enchantwindow_result( struct map_session_data& sd, bool success, t_itemid enchant = 0 ){
  19804. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19805. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  19806. p.packetType = HEADER_ZC_RESPONSE_ENCHANT;
  19807. if( success ){
  19808. p.messageId = C_ENCHANT_SUCCESS;
  19809. }else{
  19810. p.messageId = C_ENCHANT_FAILURE;
  19811. }
  19812. p.enchantItemId = enchant;
  19813. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19814. sd.state.item_enchant_index = 0;
  19815. #endif
  19816. }
  19817. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  19818. if( selected_item.equip != 0 ){
  19819. return false;
  19820. }
  19821. if( selected_item.equipSwitch != 0 ){
  19822. return false;
  19823. }
  19824. if( selected_item.attribute != 0 ){
  19825. return false;
  19826. }
  19827. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  19828. return false;
  19829. }
  19830. if( selected_item.refine < enchant->minimumRefine ){
  19831. return false;
  19832. }
  19833. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  19834. return false;
  19835. }
  19836. if( !enchant->allowRandomOptions ){
  19837. for( const s_item_randomoption& option : selected_item.option ){
  19838. if( option.id != 0 ){
  19839. return false;
  19840. }
  19841. }
  19842. }
  19843. return true;
  19844. }
  19845. void clif_parse_enchantwindow_general( int fd, struct map_session_data* sd ){
  19846. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19847. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  19848. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19849. return;
  19850. }
  19851. uint16 index = server_index( p->index );
  19852. if( index >= MAX_INVENTORY ){
  19853. return;
  19854. }
  19855. if( sd->inventory_data[index] == nullptr ){
  19856. return;
  19857. }
  19858. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19859. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  19860. if( enchant == nullptr ){
  19861. return;
  19862. }
  19863. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19864. return;
  19865. }
  19866. uint16 slot = MAX_SLOTS;
  19867. for( uint16 nextSlot : enchant->order ){
  19868. if( selected_item.card[nextSlot] == 0 ){
  19869. slot = nextSlot;
  19870. break;
  19871. }
  19872. }
  19873. if( slot == MAX_SLOTS ){
  19874. return;
  19875. }
  19876. if( slot < sd->inventory_data[index]->slots ){
  19877. return;
  19878. }
  19879. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19880. if( enchant_slot == nullptr ){
  19881. return;
  19882. }
  19883. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  19884. if( enchants_for_enchantgrade == nullptr ){
  19885. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  19886. clif_enchantwindow_result( *sd, false );
  19887. return;
  19888. }
  19889. if( sd->status.zeny < enchant_slot->normal.zeny ){
  19890. return;
  19891. }
  19892. std::unordered_map<uint16, uint16> materials;
  19893. for( const auto& entry : enchant_slot->normal.materials ){
  19894. int16 idx = pc_search_inventory( sd, entry.first );
  19895. if( idx < 0 ){
  19896. return;
  19897. }
  19898. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19899. return;
  19900. }
  19901. materials[idx] = entry.second;
  19902. }
  19903. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  19904. return;
  19905. }
  19906. for( const auto& entry : materials ){
  19907. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  19908. return;
  19909. }
  19910. }
  19911. uint32 chance = enchant_slot->normal.chance;
  19912. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  19913. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  19914. }
  19915. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  19916. clif_enchantwindow_result( *sd, false );
  19917. return;
  19918. }
  19919. // Log removal of item
  19920. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  19921. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  19922. bool enchanted = false;
  19923. for( int i = 0; i < maximum; i++ ){
  19924. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19925. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  19926. selected_item.card[slot] = normal_enchant->item_id;
  19927. enchanted = true;
  19928. break;
  19929. }
  19930. }
  19931. if( !enchanted ){
  19932. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19933. selected_item.card[slot] = normal_enchant->item_id;
  19934. }
  19935. // Log retrieving the item again -> with the new enchant
  19936. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  19937. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  19938. #endif
  19939. }
  19940. void clif_parse_enchantwindow_perfect( int fd, struct map_session_data* sd ){
  19941. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19942. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  19943. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19944. return;
  19945. }
  19946. uint16 index = server_index( p->index );
  19947. if( index >= MAX_INVENTORY ){
  19948. return;
  19949. }
  19950. if( sd->inventory_data[index] == nullptr ){
  19951. return;
  19952. }
  19953. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19954. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  19955. if( enchant == nullptr ){
  19956. return;
  19957. }
  19958. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19959. return;
  19960. }
  19961. uint16 slot = MAX_SLOTS;
  19962. for( uint16 nextSlot : enchant->order ){
  19963. if( selected_item.card[nextSlot] == 0 ){
  19964. slot = nextSlot;
  19965. break;
  19966. }
  19967. }
  19968. if( slot == MAX_SLOTS ){
  19969. return;
  19970. }
  19971. if( slot < sd->inventory_data[index]->slots ){
  19972. return;
  19973. }
  19974. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19975. if( enchant_slot == nullptr ){
  19976. return;
  19977. }
  19978. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->itemId );
  19979. if( perfect_enchant == nullptr ){
  19980. return;
  19981. }
  19982. if( sd->status.zeny < perfect_enchant->zeny ){
  19983. return;
  19984. }
  19985. std::unordered_map<uint16, uint16> materials;
  19986. for( const auto& entry : perfect_enchant->materials ){
  19987. int16 idx = pc_search_inventory( sd, entry.first );
  19988. if( idx < 0 ){
  19989. return;
  19990. }
  19991. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19992. return;
  19993. }
  19994. materials[idx] = entry.second;
  19995. }
  19996. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  19997. return;
  19998. }
  19999. for( const auto& entry : materials ){
  20000. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20001. return;
  20002. }
  20003. }
  20004. // Log removal of item
  20005. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20006. selected_item.card[slot] = perfect_enchant->item_id;
  20007. // Log retrieving the item again -> with the new enchant
  20008. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20009. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20010. #endif
  20011. }
  20012. void clif_parse_enchantwindow_upgrade( int fd, struct map_session_data* sd ){
  20013. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20014. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20015. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20016. return;
  20017. }
  20018. uint16 index = server_index( p->index );
  20019. if( index >= MAX_INVENTORY ){
  20020. return;
  20021. }
  20022. if( sd->inventory_data[index] == nullptr ){
  20023. return;
  20024. }
  20025. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20026. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20027. if( enchant == nullptr ){
  20028. return;
  20029. }
  20030. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20031. return;
  20032. }
  20033. uint16 slot = p->slot;
  20034. if( slot >= MAX_SLOTS ){
  20035. return;
  20036. }
  20037. if( slot < sd->inventory_data[index]->slots ){
  20038. return;
  20039. }
  20040. if( selected_item.card[slot] == 0 ){
  20041. return;
  20042. }
  20043. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20044. if( enchant_slot == nullptr ){
  20045. return;
  20046. }
  20047. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20048. if( upgrade == nullptr ){
  20049. return;
  20050. }
  20051. if( sd->status.zeny < upgrade->zeny ){
  20052. return;
  20053. }
  20054. std::unordered_map<uint16, uint16> materials;
  20055. for( const auto& entry : upgrade->materials ){
  20056. int16 idx = pc_search_inventory( sd, entry.first );
  20057. if( idx < 0 ){
  20058. return;
  20059. }
  20060. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20061. return;
  20062. }
  20063. materials[idx] = entry.second;
  20064. }
  20065. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20066. return;
  20067. }
  20068. for( const auto& entry : materials ){
  20069. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20070. return;
  20071. }
  20072. }
  20073. // Log removal of item
  20074. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20075. selected_item.card[slot] = upgrade->upgrade_item_id;
  20076. // Log retrieving the item again -> with the new enchant
  20077. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20078. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20079. #endif
  20080. }
  20081. void clif_parse_enchantwindow_reset( int fd, struct map_session_data* sd ){
  20082. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20083. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20084. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20085. return;
  20086. }
  20087. uint16 index = server_index( p->index );
  20088. if( index >= MAX_INVENTORY ){
  20089. return;
  20090. }
  20091. if( sd->inventory_data[index] == nullptr ){
  20092. return;
  20093. }
  20094. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20095. if( selected_item.equip != 0 ){
  20096. return;
  20097. }
  20098. if( selected_item.equipSwitch != 0 ){
  20099. return;
  20100. }
  20101. if( selected_item.attribute != 0 ){
  20102. return;
  20103. }
  20104. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20105. if( enchant == nullptr ){
  20106. return;
  20107. }
  20108. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20109. return;
  20110. }
  20111. if( selected_item.refine < enchant->minimumRefine ){
  20112. return;
  20113. }
  20114. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20115. return;
  20116. }
  20117. bool is_enchanted = false;
  20118. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20119. if( selected_item.card[i] != 0 ){
  20120. is_enchanted = true;
  20121. break;
  20122. }
  20123. }
  20124. if( !is_enchanted ){
  20125. return;
  20126. }
  20127. if( sd->status.zeny < enchant->reset.zeny ){
  20128. return;
  20129. }
  20130. std::unordered_map<uint16, uint16> materials;
  20131. for( const auto& entry : enchant->reset.materials ){
  20132. int16 idx = pc_search_inventory( sd, entry.first );
  20133. if( idx < 0 ){
  20134. return;
  20135. }
  20136. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20137. return;
  20138. }
  20139. materials[idx] = entry.second;
  20140. }
  20141. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20142. return;
  20143. }
  20144. for( const auto& entry : materials ){
  20145. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20146. return;
  20147. }
  20148. }
  20149. uint32 chance = enchant->reset.chance;
  20150. if( chance == 0 ){
  20151. return;
  20152. }
  20153. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20154. clif_enchantwindow_result( *sd, false );
  20155. return;
  20156. }
  20157. // Log removal of item
  20158. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20159. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20160. selected_item.card[i] = 0;
  20161. }
  20162. // Log retrieving the item again -> with the new enchant
  20163. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20164. clif_enchantwindow_result( *sd, true );
  20165. #endif
  20166. }
  20167. void clif_parse_enchantwindow_close( int fd, struct map_session_data* sd ){
  20168. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20169. sd->state.item_enchant_index = 0;
  20170. #endif
  20171. }
  20172. void clif_parse_itempackage_select( int fd, struct map_session_data* sd ){
  20173. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20174. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20175. if( p->AID != sd->status.account_id ){
  20176. return;
  20177. }
  20178. uint16 index = server_index( p->index );
  20179. if( index >= MAX_INVENTORY ){
  20180. return;
  20181. }
  20182. if( sd->inventory_data[index] == nullptr ){
  20183. return;
  20184. }
  20185. if( sd->inventory_data[index]->nameid != p->itemID ){
  20186. return;
  20187. }
  20188. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20189. return;
  20190. }
  20191. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20192. if( package == nullptr ){
  20193. return;
  20194. }
  20195. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20196. if( group == nullptr ){
  20197. return;
  20198. }
  20199. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20200. return;
  20201. }
  20202. for( const auto& entry : group->items ){
  20203. struct item item = {};
  20204. item.nameid = entry.second->item_id;
  20205. item.identify = 1;
  20206. item.refine = (char)entry.second->refine;
  20207. if( entry.second->rentalhours ){
  20208. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20209. }
  20210. // Check if it is a pet egg
  20211. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20212. if( pet != nullptr ){
  20213. for( int i = 0; i < entry.second->amount; i++ ){
  20214. pet_create_egg( sd, item.nameid );
  20215. }
  20216. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20217. for( int i = 0; i < entry.second->amount; i++ ){
  20218. // New random options on each iteration
  20219. if( entry.second->randomOptionGroup != nullptr ){
  20220. entry.second->randomOptionGroup->apply( item );
  20221. }
  20222. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20223. }
  20224. }else{
  20225. if( entry.second->randomOptionGroup != nullptr ){
  20226. entry.second->randomOptionGroup->apply( item );
  20227. }
  20228. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20229. }
  20230. }
  20231. #endif
  20232. }
  20233. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20234. {
  20235. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20236. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20237. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20238. p.itemId = itemId;
  20239. p.refine_level = level;
  20240. p.status = (int8)success;
  20241. if (battle_config.broadcast_hide_name) {
  20242. std::string dispname = clif_hide_name(sd.status.name);
  20243. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20244. }
  20245. else {
  20246. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20247. }
  20248. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20249. #endif
  20250. }
  20251. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20252. #if PACKETVER >= 20160316
  20253. nullpo_retv(sd);
  20254. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20255. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20256. return;
  20257. }
  20258. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20259. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20260. #endif
  20261. }
  20262. void clif_captcha_upload_request(map_session_data &sd) {
  20263. #if PACKETVER >= 20160330
  20264. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20265. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20266. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20267. if (sd.captcha_upload.cd != nullptr) {
  20268. p.captchaFlag = 0;
  20269. } else {
  20270. p.captchaFlag = 1;
  20271. }
  20272. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20273. #endif
  20274. }
  20275. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20276. #if PACKETVER >= 20160316
  20277. nullpo_retv(sd);
  20278. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20279. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20280. return;
  20281. }
  20282. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20283. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20284. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20285. return;
  20286. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20287. return;
  20288. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20289. #endif
  20290. }
  20291. void clif_captcha_upload_end(map_session_data &sd) {
  20292. #if PACKETVER >= 20160330
  20293. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20294. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20295. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20296. #endif
  20297. }
  20298. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20299. #if PACKETVER >= 20160323
  20300. nullpo_retv(sd);
  20301. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20302. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20303. return;
  20304. }
  20305. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20306. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20307. #endif
  20308. }
  20309. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20310. #if PACKETVER >= 20160330
  20311. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20312. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20313. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20314. if (cd == nullptr) {
  20315. p.captchaFlag = 1;
  20316. p.imageSize = 0;
  20317. } else {
  20318. p.captchaFlag = 0;
  20319. p.imageSize = cd->image_size;
  20320. }
  20321. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20322. if (cd != nullptr) {
  20323. for (uint16 offset = 0; offset < cd->image_size;) {
  20324. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20325. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20326. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20327. p2->PacketLength = (int16)(sizeof(PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20328. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20329. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20330. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20331. offset += chunk_size;
  20332. }
  20333. }
  20334. #endif
  20335. }
  20336. void clif_macro_detector_request(map_session_data &sd) {
  20337. #if PACKETVER >= 20160330
  20338. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20339. if (cd == nullptr) {
  20340. return;
  20341. }
  20342. // Send preview initialization request to the client.
  20343. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20344. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20345. p.imageSize = cd->image_size;
  20346. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20347. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20348. for (uint16 offset = 0; offset < cd->image_size;) {
  20349. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20350. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20351. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20352. p2->PacketLength = (int16)(sizeof(PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20353. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20354. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20355. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20356. offset += chunk_size;
  20357. }
  20358. #endif
  20359. }
  20360. void clif_macro_detector_request_show(map_session_data &sd) {
  20361. #if PACKETVER >= 20160330
  20362. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20363. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20364. p.retryCount = sd.macro_detect.retry;
  20365. p.timeout = battle_config.macro_detection_timeout;
  20366. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20367. #endif
  20368. }
  20369. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20370. #if PACKETVER >= 20160316
  20371. nullpo_retv(sd);
  20372. if (sd->macro_detect.retry != 0) {
  20373. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20374. clif_macro_detector_request_show(*sd);
  20375. }
  20376. #endif
  20377. }
  20378. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20379. #if PACKETVER >= 20160316
  20380. nullpo_retv(sd);
  20381. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20382. pc_macro_detector_process_answer(*sd, p->answer);
  20383. #endif
  20384. }
  20385. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20386. #if PACKETVER >= 20160330
  20387. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20388. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20389. p.status = stype;
  20390. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20391. #endif
  20392. }
  20393. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20394. #if PACKETVER >= 20160330
  20395. nullpo_retv(sd);
  20396. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20397. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20398. return;
  20399. }
  20400. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20401. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20402. #endif
  20403. }
  20404. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20405. #if PACKETVER >= 20160330
  20406. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *p = (PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *)packet_buffer;
  20407. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20408. p->PacketLength = static_cast<int16>(sizeof(PACKET_ZC_ACK_PLAYER_AID_IN_RANGE) + sizeof(uint32) * aid_list.size());
  20409. for (size_t i = 0; i < aid_list.size(); i++)
  20410. p->AID[i] = aid_list[static_cast<int32>(i)];
  20411. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20412. #endif
  20413. }
  20414. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20415. #if PACKETVER >= 20160316
  20416. nullpo_retv(sd);
  20417. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20418. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20419. return;
  20420. }
  20421. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20422. map_session_data *tsd = map_id2sd(p->AID);
  20423. if (tsd == nullptr) {
  20424. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20425. return;
  20426. }
  20427. if (tsd->macro_detect.retry != 0) {
  20428. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20429. return;
  20430. }
  20431. if (captcha_db.empty()) {
  20432. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20433. return;
  20434. }
  20435. pc_macro_reporter_process(*sd, *tsd);
  20436. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20437. #endif
  20438. }
  20439. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20440. #if PACKETVER >= 20160330
  20441. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20442. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20443. p.status = stype;
  20444. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20445. #endif
  20446. }
  20447. void clif_goldpc_info( struct map_session_data& sd ){
  20448. #if PACKETVER_MAIN_NUM >= 20140508 || PACKETVER_RE_NUM >= 20140508 || defined(PACKETVER_ZERO)
  20449. if( battle_config.feature_goldpc_active ){
  20450. struct PACKET_ZC_GOLDPCCAFE_POINT p = {};
  20451. p.packetType = HEADER_ZC_GOLDPCCAFE_POINT;
  20452. p.active = true;
  20453. if( battle_config.feature_goldpc_vip && pc_isvip( &sd ) ){
  20454. p.unitPoint = 2;
  20455. }else{
  20456. p.unitPoint = 1;
  20457. }
  20458. p.point = (int32)pc_readparam( &sd, SP_GOLDPC_POINTS );
  20459. if( sd.goldpc_tid != INVALID_TIMER ){
  20460. p.accumulatePlaySecond = (int32)( 3600 - battle_config.feature_goldpc_time + pc_readreg2( &sd, GOLDPC_SECONDS_VAR ) );
  20461. }else{
  20462. p.accumulatePlaySecond = 3600;
  20463. }
  20464. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20465. }
  20466. #endif
  20467. }
  20468. void clif_parse_dynamic_npc( int fd, struct map_session_data* sd ){
  20469. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20470. struct PACKET_CZ_DYNAMICNPC_CREATE_REQUEST* p = (struct PACKET_CZ_DYNAMICNPC_CREATE_REQUEST*)RFIFOP( fd, 0 );
  20471. char npcname[NPC_NAME_LENGTH + 1];
  20472. if( strncasecmp( "GOLDPCCAFE", p->nickname, sizeof( p->nickname ) ) == 0 ){
  20473. safestrncpy( npcname, p->nickname, sizeof( npcname ) );
  20474. }else{
  20475. return;
  20476. }
  20477. struct npc_data* nd = npc_name2id( npcname );
  20478. if( nd == nullptr ){
  20479. ShowError( "clif_parse_dynamic_npc: Original NPC \"%s\" was not found.\n", npcname );
  20480. return;
  20481. }
  20482. npc_duplicate_npc_for_player( *nd, *sd );
  20483. #endif
  20484. }
  20485. /*==========================================
  20486. * Main client packet processing function
  20487. *------------------------------------------*/
  20488. static int clif_parse(int fd)
  20489. {
  20490. int cmd, packet_len;
  20491. TBL_PC* sd;
  20492. int pnum;
  20493. #ifdef PACKET_OBFUSCATION
  20494. int cmd2;
  20495. #endif
  20496. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20497. // Note: "click masters" can do 80+ clicks in 10 seconds
  20498. 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]
  20499. { // begin main client packet processing loop
  20500. sd = (TBL_PC *)session[fd]->session_data;
  20501. if (session[fd]->flag.eof) {
  20502. if (sd) {
  20503. if (sd->state.autotrade) {
  20504. //Disassociate character from the socket connection.
  20505. session[fd]->session_data = NULL;
  20506. sd->fd = 0;
  20507. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20508. } else
  20509. if (sd->state.active) {
  20510. // Player logout display [Valaris]
  20511. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20512. clif_quitsave(fd, sd);
  20513. } else {
  20514. //Unusual logout (during log on/off/map-changer procedure)
  20515. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20516. map_quit(sd);
  20517. }
  20518. } else {
  20519. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20520. }
  20521. do_close(fd);
  20522. return 0;
  20523. }
  20524. if (RFIFOREST(fd) < 2)
  20525. return 0;
  20526. cmd = RFIFOW(fd, 0);
  20527. #ifdef PACKET_OBFUSCATION
  20528. // Check if it is a player that tries to connect to the map server.
  20529. if( sd ){
  20530. // Decrypt the current packet ID with the last key stored in the session.
  20531. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20532. }else{
  20533. // Store the original value for checking
  20534. cmd2 = cmd;
  20535. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20536. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20537. }
  20538. #endif
  20539. // filter out invalid / unsupported packets
  20540. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20541. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20542. #ifdef DUMP_INVALID_PACKET
  20543. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20544. #endif
  20545. #ifdef PACKET_OBFUSCATION_WARN
  20546. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20547. if( !sd ){
  20548. #ifdef PACKET_OBFUSCATION
  20549. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20550. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20551. }
  20552. #else
  20553. // Try to use the initial keys for the decryption of the packet ID.
  20554. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20555. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20556. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20557. }
  20558. #endif
  20559. }
  20560. #endif
  20561. set_eof(fd);
  20562. return 0;
  20563. }
  20564. // determine real packet length
  20565. packet_len = packet_db[cmd].len;
  20566. if (packet_len == -1) { // variable-length packet
  20567. if (RFIFOREST(fd) < 4)
  20568. return 0;
  20569. packet_len = RFIFOW(fd,2);
  20570. if (packet_len < 4 || packet_len > 32768) {
  20571. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20572. #ifdef DUMP_INVALID_PACKET
  20573. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20574. #endif
  20575. set_eof(fd);
  20576. return 0;
  20577. }
  20578. }
  20579. if ((int)RFIFOREST(fd) < packet_len){
  20580. 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 );
  20581. #ifdef DUMP_INVALID_PACKET
  20582. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20583. #endif
  20584. set_eof( fd );
  20585. return 0; // not enough data received to form the packet
  20586. }
  20587. #ifdef PACKET_OBFUSCATION
  20588. RFIFOW(fd, 0) = cmd;
  20589. if (sd)
  20590. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20591. #endif
  20592. if( packet_db[cmd].func == clif_parse_debug )
  20593. packet_db[cmd].func(fd, sd);
  20594. else if( packet_db[cmd].func != NULL ) {
  20595. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20596. ; //Only valid packet when there is no session
  20597. else
  20598. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20599. ; //Only valid packet when player is not on a map
  20600. else
  20601. packet_db[cmd].func(fd, sd);
  20602. }
  20603. #ifdef DUMP_UNKNOWN_PACKET
  20604. else DumpUnknown(fd,sd,cmd,packet_len);
  20605. #endif
  20606. RFIFOSKIP(fd, packet_len);
  20607. }; // main loop end
  20608. return 0;
  20609. }
  20610. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  20611. va_list argp;
  20612. int i;
  20613. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20614. return;
  20615. packet_db[cmd].len = length;
  20616. packet_db[cmd].func = func;
  20617. va_start(argp, func);
  20618. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20619. int offset = va_arg(argp, int);
  20620. if( offset == 0 ){
  20621. break;
  20622. }
  20623. packet_db[cmd].pos[i] = offset;
  20624. }
  20625. if( i == MAX_PACKET_POS ){
  20626. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20627. }
  20628. va_end(argp);
  20629. }
  20630. /*==========================================
  20631. * Reads packets and setups its array reference
  20632. *------------------------------------------*/
  20633. void packetdb_readdb(){
  20634. memset(packet_db,0,sizeof(packet_db));
  20635. #include "clif_packetdb.hpp"
  20636. #include "clif_shuffle.hpp"
  20637. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20638. #ifdef PACKET_OBFUSCATION
  20639. 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]);
  20640. #else
  20641. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20642. #endif
  20643. }
  20644. /*==========================================
  20645. *
  20646. *------------------------------------------*/
  20647. void do_init_clif(void) {
  20648. const int colors[COLOR_MAX] = {
  20649. 0x00FF00, // COLOR_DEFAULT
  20650. 0xFF0000, // COLOR_RED
  20651. 0xFFFFFF, // COLOR_WHITE
  20652. 0xFFFF00, // COLOR_YELLOW
  20653. 0x00FFFF, // COLOR_CYAN
  20654. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20655. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20656. };
  20657. /**
  20658. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20659. **/
  20660. for( int i = 0; i < COLOR_MAX; i++ ){
  20661. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20662. }
  20663. packetdb_readdb();
  20664. set_defaultparse(clif_parse);
  20665. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20666. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20667. exit(EXIT_FAILURE);
  20668. }
  20669. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20670. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20671. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20672. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20673. if( battle_config.ping_timer_interval > 0 ){
  20674. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20675. }
  20676. #endif
  20677. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20678. }
  20679. void do_final_clif(void) {
  20680. ers_destroy(delay_clearunit_ers);
  20681. }