clif.cpp 723 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135
  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. int packet_db_ack[MAX_ACK_FUNC + 1];
  74. // Reuseable global packet buffer to prevent too many allocations
  75. // Take socket.cpp::socket_max_client_packet into consideration
  76. static int8 packet_buffer[UINT16_MAX];
  77. unsigned long color_table[COLOR_MAX];
  78. #include "clif_obfuscation.hpp"
  79. static bool clif_session_isValid(struct map_session_data *sd);
  80. static void clif_loadConfirm( struct map_session_data *sd );
  81. #if PACKETVER >= 20150513
  82. enum mail_type {
  83. MAIL_TYPE_TEXT = 0x0,
  84. MAIL_TYPE_ZENY = 0x2,
  85. MAIL_TYPE_ITEM = 0x4,
  86. MAIL_TYPE_NPC = 0x8
  87. };
  88. #endif
  89. enum e_inventory_type{
  90. INVTYPE_INVENTORY = 0,
  91. INVTYPE_CART = 1,
  92. INVTYPE_STORAGE = 2,
  93. INVTYPE_GUILD_STORAGE = 3,
  94. };
  95. /** Converts item type to display it on client if necessary.
  96. * @param nameid: Item ID
  97. * @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
  98. */
  99. static inline int itemtype(t_itemid nameid) {
  100. 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
  101. int type = id->type;
  102. if( type == IT_SHADOWGEAR ) {
  103. if( id->equip&EQP_SHADOW_WEAPON )
  104. return IT_WEAPON;
  105. else
  106. return IT_ARMOR;
  107. }
  108. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  109. }
  110. // TODO: doc
  111. static inline uint16 client_index( uint16 server_index ){
  112. return server_index + 2;
  113. }
  114. static inline uint16 server_index( uint16 client_index ){
  115. return client_index - 2;
  116. }
  117. static inline uint16 client_storage_index( uint16 server_index ){
  118. return server_index + 1;
  119. }
  120. static inline uint16 server_storage_index( uint16 client_index ){
  121. return client_index - 1;
  122. }
  123. static inline uint32 disguised_bl_id( uint32 bl_id ){
  124. // Casting to prevent a compiler warning
  125. return -((int32)bl_id);
  126. }
  127. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  128. static inline uint32 client_nameid( t_itemid server_nameid ){
  129. t_itemid view = itemdb_viewid( server_nameid );
  130. if( view > 0 ){
  131. return view;
  132. }else{
  133. return server_nameid;
  134. }
  135. }
  136. #else
  137. static inline uint16 client_nameid( t_itemid server_nameid ){
  138. t_itemid view = itemdb_viewid( server_nameid );
  139. if( view > 0 ){
  140. if( view > UINT16_MAX ){
  141. return (uint16)UNKNOWN_ITEM_ID;
  142. }
  143. return (uint16)view;
  144. }else{
  145. if( server_nameid > UINT16_MAX ){
  146. return (uint16)UNKNOWN_ITEM_ID;
  147. }
  148. return (uint16)server_nameid;
  149. }
  150. }
  151. #endif
  152. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  153. p += pos;
  154. p[0] = (uint8)(x>>2);
  155. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  156. p[2] = (uint8)((y<<4) | (dir&0xf));
  157. }
  158. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  159. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  160. p += pos;
  161. p[0] = (uint8)(x0>>2);
  162. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  163. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  164. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  165. p[4] = (uint8)y1;
  166. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  167. }
  168. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  169. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  170. }
  171. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  172. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  173. }
  174. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  175. p += pos;
  176. if( x ) {
  177. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  178. }
  179. if( y ) {
  180. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  181. }
  182. if( dir ) {
  183. dir[0] = ( p[2] & 0x0f );
  184. }
  185. }
  186. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  187. p += pos;
  188. if( x0 ) {
  189. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  190. }
  191. if( y0 ) {
  192. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  193. }
  194. if( x1 ) {
  195. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  196. }
  197. if( y1 ) {
  198. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  199. }
  200. if( sx0 ) {
  201. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  202. }
  203. if( sy0 ) {
  204. sy0[0] = ( p[5] & 0x0f ) >> 0;
  205. }
  206. }
  207. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  208. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  209. }
  210. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  211. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  212. }
  213. //To idenfity disguised characters.
  214. static inline bool disguised(struct block_list* bl) {
  215. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  216. }
  217. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  218. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  219. if( len > max )
  220. len = max;
  221. mes[len-1] = '\0';
  222. return len;
  223. }
  224. static char map_ip_str[128];
  225. static uint32 map_ip;
  226. static uint32 bind_ip = INADDR_ANY;
  227. static uint16 map_port = 5121;
  228. static bool clif_ally_only = false;
  229. int map_fd;
  230. static int clif_parse (int fd);
  231. /*==========================================
  232. * Ip setting of map-server
  233. *------------------------------------------*/
  234. int clif_setip(const char* ip) {
  235. char ip_str[16];
  236. map_ip = host2ip(ip);
  237. if (!map_ip) {
  238. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  239. return 0;
  240. }
  241. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  242. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  243. return 1;
  244. }
  245. void clif_setbindip(const char* ip)
  246. {
  247. bind_ip = host2ip(ip);
  248. if (bind_ip) {
  249. char ip_str[16];
  250. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  251. } else {
  252. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  253. }
  254. }
  255. /*==========================================
  256. * Sets map port to 'port'
  257. * is run from map.cpp upon loading map server configuration
  258. *------------------------------------------*/
  259. void clif_setport(uint16 port)
  260. {
  261. map_port = port;
  262. }
  263. /*==========================================
  264. * Returns map server IP
  265. *------------------------------------------*/
  266. uint32 clif_getip(void)
  267. {
  268. return map_ip;
  269. }
  270. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  271. uint32 clif_refresh_ip(void)
  272. {
  273. uint32 new_ip;
  274. new_ip = host2ip(map_ip_str);
  275. if (new_ip && new_ip != map_ip) {
  276. map_ip = new_ip;
  277. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  278. return map_ip;
  279. }
  280. return 0;
  281. }
  282. /*==========================================
  283. * Returns map port which is set by clif_setport()
  284. *------------------------------------------*/
  285. uint16 clif_getport(void)
  286. {
  287. return map_port;
  288. }
  289. #if PACKETVER >= 20071106
  290. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  291. switch (bl->type) {
  292. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  293. case BL_ITEM: return 0x2; //ITEM_TYPE
  294. case BL_SKILL: return 0x3; //SKILL_TYPE
  295. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  296. case BL_MOB:
  297. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  298. return 0x0; //PC_TYPE
  299. }else{
  300. switch( ( (mob_data*)bl )->special_state.ai ){
  301. case AI_ABR:
  302. return 0xd; //NPC_ABR_TYPE
  303. case AI_BIONIC:
  304. return 0xe; //NPC_BIONIC_TYPE
  305. default:
  306. return 0x5; //NPC_MOB_TYPE
  307. }
  308. }
  309. case BL_NPC:
  310. // From 2017-07-26 on NPC type units can also use player sprites.
  311. // There is one exception and this is if they are walking.
  312. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  313. #if PACKETVER >= 20170726
  314. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0xC; // New walking NPC type
  315. #else
  316. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  317. #endif
  318. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  319. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  320. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  321. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  322. default: return 0x1; //NPC_TYPE
  323. }
  324. }
  325. #endif
  326. static bool clif_session_isValid(struct map_session_data *sd) {
  327. return ( sd != nullptr && session_isActive(sd->fd) );
  328. }
  329. /*==========================================
  330. * sub process of clif_send
  331. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  332. * In order to send area-wise packets, such as:
  333. * - AREA : everyone nearby your area
  334. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  335. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  336. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  337. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  338. *------------------------------------------*/
  339. static int clif_send_sub(struct block_list *bl, va_list ap)
  340. {
  341. struct block_list *src_bl;
  342. struct map_session_data *sd;
  343. unsigned char *buf;
  344. int len, type, fd;
  345. nullpo_ret(bl);
  346. nullpo_ret(sd = (struct map_session_data *)bl);
  347. // Don't send to disconnected clients.
  348. if( !session_isActive( fd = sd->fd ) ){
  349. return 0;
  350. }
  351. buf = va_arg(ap,unsigned char*);
  352. len = va_arg(ap,int);
  353. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  354. type = va_arg(ap,int);
  355. switch(type) {
  356. case AREA_WOS:
  357. if (bl == src_bl)
  358. return 0;
  359. break;
  360. case AREA_WOC:
  361. if (sd->chatID || bl == src_bl)
  362. return 0;
  363. break;
  364. case AREA_WOSC:
  365. {
  366. if(src_bl->type == BL_PC) {
  367. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  368. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  369. return 0;
  370. }
  371. else if(src_bl->type == BL_NPC) {
  372. struct npc_data *nd = (struct npc_data *)src_bl;
  373. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  374. return 0;
  375. }
  376. }
  377. break;
  378. }
  379. /* unless visible, hold it here */
  380. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  381. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  382. return 0;
  383. WFIFOHEAD(fd, len);
  384. if (WFIFOP(fd,0) == buf) {
  385. ShowError("WARNING: Invalid use of clif_send function\n");
  386. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  387. ShowError(" Please correct your code.\n");
  388. // don't send to not move the pointer of the packet for next sessions in the loop
  389. //WFIFOSET(fd,0);//## TODO is this ok?
  390. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  391. return 0;
  392. }
  393. memcpy(WFIFOP(fd,0), buf, len);
  394. WFIFOSET(fd,len);
  395. return 0;
  396. }
  397. /*==========================================
  398. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  399. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  400. *------------------------------------------*/
  401. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  402. {
  403. int i;
  404. struct map_session_data *sd, *tsd;
  405. struct party_data *p = NULL;
  406. struct guild *g = NULL;
  407. std::shared_ptr<s_battleground_data> bg;
  408. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  409. struct s_mapiterator* iter;
  410. if( type != ALL_CLIENT )
  411. nullpo_ret(bl);
  412. sd = BL_CAST(BL_PC, bl);
  413. switch(type) {
  414. case ALL_CLIENT: //All player clients.
  415. iter = mapit_getallusers();
  416. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  417. if( session_isActive( fd = tsd->fd ) ){
  418. WFIFOHEAD( fd, len );
  419. memcpy( WFIFOP( fd, 0 ), buf, len );
  420. WFIFOSET( fd, len );
  421. }
  422. }
  423. mapit_free(iter);
  424. break;
  425. case ALL_SAMEMAP: //All players on the same map
  426. iter = mapit_getallusers();
  427. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  428. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  429. WFIFOHEAD( fd, len );
  430. memcpy( WFIFOP( fd, 0 ), buf, len );
  431. WFIFOSET( fd, len );
  432. }
  433. }
  434. mapit_free(iter);
  435. break;
  436. case AREA:
  437. case AREA_WOSC:
  438. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  439. clif_send (buf, len, bl, SELF);
  440. case AREA_WOC:
  441. case AREA_WOS:
  442. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  443. BL_PC, buf, len, bl, type);
  444. break;
  445. case AREA_CHAT_WOC:
  446. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  447. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  448. break;
  449. case CHAT:
  450. case CHAT_WOS:
  451. {
  452. struct chat_data *cd;
  453. if (sd) {
  454. cd = (struct chat_data*)map_id2bl(sd->chatID);
  455. } else if (bl->type == BL_CHAT) {
  456. cd = (struct chat_data*)bl;
  457. } else break;
  458. if (cd == NULL)
  459. break;
  460. for(i = 0; i < cd->users; i++) {
  461. if (type == CHAT_WOS && cd->usersd[i] == sd)
  462. continue;
  463. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  464. WFIFOHEAD(fd,len);
  465. memcpy(WFIFOP(fd,0), buf, len);
  466. WFIFOSET(fd,len);
  467. }
  468. }
  469. }
  470. break;
  471. case PARTY_AREA:
  472. case PARTY_AREA_WOS:
  473. x0 = bl->x - AREA_SIZE;
  474. y0 = bl->y - AREA_SIZE;
  475. x1 = bl->x + AREA_SIZE;
  476. y1 = bl->y + AREA_SIZE;
  477. case PARTY:
  478. case PARTY_WOS:
  479. case PARTY_SAMEMAP:
  480. case PARTY_SAMEMAP_WOS:
  481. if (sd && sd->status.party_id)
  482. p = party_search(sd->status.party_id);
  483. if (p) {
  484. for(i=0;i<MAX_PARTY;i++){
  485. if( (sd = p->data[i].sd) == NULL )
  486. continue;
  487. if( !session_isActive( fd = sd->fd ) )
  488. continue;
  489. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  490. continue;
  491. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  492. continue;
  493. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  494. continue;
  495. WFIFOHEAD(fd, len);
  496. memcpy(WFIFOP(fd, 0), buf, len);
  497. WFIFOSET(fd, len);
  498. }
  499. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  500. break;
  501. iter = mapit_getallusers();
  502. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  503. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  504. WFIFOHEAD( fd, len );
  505. memcpy( WFIFOP( fd, 0 ), buf, len );
  506. WFIFOSET( tsd->fd, len );
  507. }
  508. }
  509. mapit_free(iter);
  510. }
  511. break;
  512. case DUEL:
  513. case DUEL_WOS:
  514. if (!sd || !sd->duel_group) break; //Invalid usage.
  515. iter = mapit_getallusers();
  516. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  517. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  518. continue;
  519. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  520. WFIFOHEAD( fd, len );
  521. memcpy( WFIFOP( fd, 0 ), buf, len );
  522. WFIFOSET( fd, len );
  523. }
  524. }
  525. mapit_free(iter);
  526. break;
  527. case SELF:
  528. if( clif_session_isValid(sd) ){
  529. fd = sd->fd;
  530. WFIFOHEAD(fd,len);
  531. memcpy(WFIFOP(fd,0), buf, len);
  532. WFIFOSET(fd,len);
  533. }
  534. break;
  535. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  536. case GUILD_AREA:
  537. case GUILD_AREA_WOS:
  538. x0 = bl->x - AREA_SIZE;
  539. y0 = bl->y - AREA_SIZE;
  540. x1 = bl->x + AREA_SIZE;
  541. y1 = bl->y + AREA_SIZE;
  542. case GUILD_SAMEMAP:
  543. case GUILD_SAMEMAP_WOS:
  544. case GUILD:
  545. case GUILD_WOS:
  546. case GUILD_NOBG:
  547. if (sd && sd->status.guild_id)
  548. g = sd->guild;
  549. if (g) {
  550. for(i = 0; i < g->max_member; i++) {
  551. if( (sd = g->member[i].sd) != nullptr ){
  552. if( !session_isActive( fd = sd->fd ) )
  553. continue;
  554. if( type == GUILD_NOBG && sd->bg_id )
  555. continue;
  556. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  557. continue;
  558. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  559. continue;
  560. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  561. continue;
  562. WFIFOHEAD(fd,len);
  563. memcpy(WFIFOP(fd,0), buf, len);
  564. WFIFOSET(fd,len);
  565. }
  566. }
  567. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  568. break;
  569. iter = mapit_getallusers();
  570. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  571. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  572. WFIFOHEAD( fd, len );
  573. memcpy( WFIFOP( fd, 0 ), buf, len );
  574. WFIFOSET( fd, len );
  575. }
  576. }
  577. mapit_free(iter);
  578. }
  579. break;
  580. case BG_AREA:
  581. case BG_AREA_WOS:
  582. x0 = bl->x - AREA_SIZE;
  583. y0 = bl->y - AREA_SIZE;
  584. x1 = bl->x + AREA_SIZE;
  585. y1 = bl->y + AREA_SIZE;
  586. case BG_SAMEMAP:
  587. case BG_SAMEMAP_WOS:
  588. case BG:
  589. case BG_WOS:
  590. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  591. {
  592. for (const auto &member : bg->members) {
  593. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  594. continue;
  595. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  596. continue;
  597. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  598. continue;
  599. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  600. continue;
  601. WFIFOHEAD(fd,len);
  602. memcpy(WFIFOP(fd,0), buf, len);
  603. WFIFOSET(fd,len);
  604. }
  605. }
  606. break;
  607. case CLAN:
  608. if( sd && sd->clan ){
  609. struct clan* clan = sd->clan;
  610. for( i = 0; i < clan->max_member; i++ ){
  611. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  612. continue;
  613. }
  614. WFIFOHEAD(fd,len);
  615. memcpy(WFIFOP(fd,0), buf, len);
  616. WFIFOSET(fd,len);
  617. }
  618. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  619. break;
  620. iter = mapit_getallusers();
  621. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  622. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  623. WFIFOHEAD(fd, len);
  624. memcpy(WFIFOP(fd, 0), buf, len);
  625. WFIFOSET(fd, len);
  626. }
  627. }
  628. mapit_free(iter);
  629. }
  630. break;
  631. default:
  632. ShowError("clif_send: Unrecognized type %d\n",type);
  633. return -1;
  634. }
  635. return 0;
  636. }
  637. /// Notifies the client, that it's connection attempt was accepted.
  638. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  639. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  640. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  641. void clif_authok(struct map_session_data *sd)
  642. {
  643. #if PACKETVER < 20080102
  644. const int cmd = 0x73;
  645. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  646. const int cmd = 0x2eb;
  647. #else
  648. const int cmd = 0xa18;
  649. #endif
  650. int fd = sd->fd;
  651. WFIFOHEAD(fd,packet_len(cmd));
  652. WFIFOW(fd, 0) = cmd;
  653. WFIFOL(fd, 2) = client_tick(gettick());
  654. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  655. WFIFOB(fd, 9) = 5; // ignored
  656. WFIFOB(fd,10) = 5; // ignored
  657. #if PACKETVER >= 20080102
  658. WFIFOW(fd,11) = sd->status.font;
  659. #endif
  660. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  661. WFIFOB(fd,13) = sd->status.sex;
  662. #endif
  663. WFIFOSET(fd,packet_len(cmd));
  664. }
  665. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  666. /// 0074 <error code>.B
  667. /// error code:
  668. /// 0 = client type mismatch
  669. /// 1 = ID mismatch
  670. /// 2 = mobile - out of available time
  671. /// 3 = mobile - already logged in
  672. /// 4 = mobile - waiting state
  673. void clif_authrefuse(int fd, uint8 error_code)
  674. {
  675. WFIFOHEAD(fd,packet_len(0x74));
  676. WFIFOW(fd,0) = 0x74;
  677. WFIFOB(fd,2) = error_code;
  678. WFIFOSET(fd,packet_len(0x74));
  679. }
  680. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  681. /// 0081 <error code>.B
  682. /// error code:
  683. /// 0 = BAN_UNFAIR
  684. /// 1 = server closed -> MsgStringTable[4]
  685. /// 2 = ID already logged in -> MsgStringTable[5]
  686. /// 3 = timeout/too much lag -> MsgStringTable[241]
  687. /// 4 = server full -> MsgStringTable[264]
  688. /// 5 = underaged -> MsgStringTable[305]
  689. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  690. /// 9 = too many connections from this ip -> MsgStringTable[529]
  691. /// 10 = out of available time paid for -> MsgStringTable[530]
  692. /// 11 = BAN_PAY_SUSPEND
  693. /// 12 = BAN_PAY_CHANGE
  694. /// 13 = BAN_PAY_WRONGIP
  695. /// 14 = BAN_PAY_PNGAMEROOM
  696. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  697. /// 16 = BAN_JAPAN_REFUSE1
  698. /// 17 = BAN_JAPAN_REFUSE2
  699. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  700. /// 100 = BAN_PC_IP_UNFAIR
  701. /// 101 = BAN_PC_IP_COUNT_ALL
  702. /// 102 = BAN_PC_IP_COUNT
  703. /// 103 = BAN_GRAVITY_MEM_AGREE
  704. /// 104 = BAN_GAME_MEM_AGREE
  705. /// 105 = BAN_HAN_VALID
  706. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  707. /// 107 = BAN_OVER_CHARACTER_LIST
  708. /// 108 = BAN_IP_BLOCK
  709. /// 109 = BAN_INVALID_PWD_CNT
  710. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  711. /// ? = disconnected -> MsgStringTable[3]
  712. void clif_authfail_fd(int fd, int type)
  713. {
  714. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  715. return;
  716. WFIFOHEAD(fd, packet_len(0x81));
  717. WFIFOW(fd,0) = 0x81;
  718. WFIFOB(fd,2) = type;
  719. WFIFOSET(fd,packet_len(0x81));
  720. set_eof(fd);
  721. }
  722. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  723. /// 00b3 <type>.B
  724. /// type:
  725. /// 1 = disconnect, char-select
  726. /// ? = nothing
  727. void clif_charselectok(int id, uint8 ok)
  728. {
  729. struct map_session_data* sd;
  730. int fd;
  731. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  732. return;
  733. fd = sd->fd;
  734. WFIFOHEAD(fd,packet_len(0xb3));
  735. WFIFOW(fd,0) = 0xb3;
  736. WFIFOB(fd,2) = ok;
  737. WFIFOSET(fd,packet_len(0xb3));
  738. }
  739. /// Makes an item appear on the ground.
  740. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  741. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  742. /// 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)
  743. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  744. nullpo_retv(fitem);
  745. if( fitem->item.nameid == 0 ){
  746. return;
  747. }
  748. struct packet_dropflooritem p;
  749. p.PacketType = dropflooritemType;
  750. p.ITAID = fitem->bl.id;
  751. p.ITID = client_nameid( fitem->item.nameid );
  752. #if PACKETVER >= 20130000 /* not sure date */
  753. p.type = itemtype( fitem->item.nameid );
  754. #endif
  755. p.IsIdentified = fitem->item.identify ? 1 : 0;
  756. p.xPos = fitem->bl.x;
  757. p.yPos = fitem->bl.y;
  758. p.subX = fitem->subx;
  759. p.subY = fitem->suby;
  760. p.count = fitem->item.amount;
  761. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  762. if( canShowEffect ){
  763. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  764. if( dropEffect > 0 ){
  765. p.showdropeffect = 1;
  766. p.dropeffectmode = dropEffect - 1;
  767. }else if (battle_config.rndopt_drop_pillar != 0){
  768. uint8 optionCount = 0;
  769. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  770. if (fitem->item.option[i].id != 0) {
  771. optionCount++;
  772. }
  773. }
  774. if (optionCount > 0) {
  775. p.showdropeffect = 1;
  776. if (optionCount == 1)
  777. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  778. else if (optionCount == 2)
  779. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  780. else
  781. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  782. } else {
  783. p.showdropeffect = 0;
  784. p.dropeffectmode = DROPEFFECT_NONE;
  785. }
  786. } else {
  787. p.showdropeffect = 0;
  788. p.dropeffectmode = DROPEFFECT_NONE;
  789. }
  790. }else{
  791. p.showdropeffect = 0;
  792. p.dropeffectmode = DROPEFFECT_NONE;
  793. }
  794. #endif
  795. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  796. }
  797. /// Makes an item disappear from the ground.
  798. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  799. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  800. {
  801. unsigned char buf[16];
  802. nullpo_retv(fitem);
  803. WBUFW(buf,0) = 0xa1;
  804. WBUFL(buf,2) = fitem->bl.id;
  805. if ( !session_isActive( fd ) ){
  806. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  807. } else {
  808. WFIFOHEAD(fd,packet_len(0xa1));
  809. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  810. WFIFOSET(fd,packet_len(0xa1));
  811. }
  812. }
  813. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  814. /// 0080 <id>.L <type>.B
  815. /// type:
  816. /// 0 = out of sight
  817. /// 1 = died
  818. /// 2 = logged out
  819. /// 3 = teleport
  820. /// 4 = trickdead
  821. void clif_clearunit_single(int id, clr_type type, int fd)
  822. {
  823. WFIFOHEAD(fd, packet_len(0x80));
  824. WFIFOW(fd,0) = 0x80;
  825. WFIFOL(fd,2) = id;
  826. WFIFOB(fd,6) = type;
  827. WFIFOSET(fd, packet_len(0x80));
  828. }
  829. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  830. /// 0080 <id>.L <type>.B
  831. /// type:
  832. /// 0 = out of sight
  833. /// 1 = died
  834. /// 2 = logged out
  835. /// 3 = teleport
  836. /// 4 = trickdead
  837. void clif_clearunit_area(struct block_list* bl, clr_type type)
  838. {
  839. unsigned char buf[8];
  840. nullpo_retv(bl);
  841. WBUFW(buf,0) = 0x80;
  842. WBUFL(buf,2) = bl->id;
  843. WBUFB(buf,6) = type;
  844. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  845. if(disguised(bl)) {
  846. WBUFL(buf,2) = disguised_bl_id( bl->id );
  847. clif_send(buf, packet_len(0x80), bl, SELF);
  848. }
  849. }
  850. /// Used to make monsters with player-sprites disappear after dying
  851. /// like normal monsters, because the client does not remove those
  852. /// automatically.
  853. static TIMER_FUNC(clif_clearunit_delayed_sub){
  854. struct block_list *bl = (struct block_list *)data;
  855. clif_clearunit_area(bl, (clr_type) id);
  856. ers_free(delay_clearunit_ers,bl);
  857. return 0;
  858. }
  859. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  860. {
  861. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  862. memcpy (tbl, bl, sizeof (struct block_list));
  863. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  864. }
  865. void clif_get_weapon_view(struct map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  866. {
  867. if(sd->sc.option&OPTION_COSTUME)
  868. {
  869. *rhand = *lhand = 0;
  870. return;
  871. }
  872. #if PACKETVER < 4
  873. *rhand = sd->status.weapon;
  874. *lhand = sd->status.shield;
  875. #else
  876. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  877. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  878. {
  879. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  880. if (id->view_id > 0)
  881. *rhand = id->view_id;
  882. else
  883. *rhand = id->nameid;
  884. } else
  885. *rhand = 0;
  886. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  887. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  888. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  889. {
  890. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  891. if (id->view_id > 0)
  892. *lhand = id->view_id;
  893. else
  894. *lhand = id->nameid;
  895. } else
  896. *lhand = 0;
  897. #endif
  898. }
  899. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  900. static int clif_setlevel_sub(int lv) {
  901. if( lv < battle_config.max_lv ) {
  902. ;
  903. } else if( lv < battle_config.aura_lv ) {
  904. lv = battle_config.max_lv - 1;
  905. } else {
  906. lv = battle_config.max_lv;
  907. }
  908. return lv;
  909. }
  910. static int clif_setlevel(struct block_list* bl) {
  911. int lv = status_get_lv(bl);
  912. if( battle_config.client_limit_unit_lv&bl->type )
  913. return clif_setlevel_sub(lv);
  914. switch( bl->type ) {
  915. case BL_NPC:
  916. case BL_PET:
  917. // npcs and pets do not have level
  918. return 0;
  919. }
  920. return lv;
  921. }
  922. /*==========================================
  923. * Prepares 'unit standing/spawning' packet
  924. *------------------------------------------*/
  925. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  926. nullpo_retv( bl );
  927. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  928. struct status_change* sc = status_get_sc( bl );
  929. struct view_data* vd = status_get_viewdata( bl );
  930. int g_id = status_get_guild_id( bl );
  931. #if PACKETVER < 20091103
  932. if( !pcdb_checkid( vd->class_ ) ){
  933. struct packet_idle_unit2 p;
  934. p.PacketType = idle_unit2Type;
  935. #if PACKETVER >= 20071106
  936. p.objecttype = clif_bl_type( bl, walking );
  937. #endif
  938. p.GID = bl->id;
  939. p.speed = status_get_speed( bl );
  940. p.bodyState = ( sc ) ? sc->opt1 : 0;
  941. p.healthState = ( sc ) ? sc->opt2 : 0;
  942. p.effectState = ( sc ) ? sc->option : 0;
  943. p.job = vd->class_;
  944. p.head = vd->hair_style;
  945. p.weapon = vd->weapon;
  946. p.accessory = vd->head_bottom;
  947. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  948. // The hell, why flags work like this?
  949. p.shield = status_get_emblem_id( bl );
  950. p.accessory2 = GetWord( g_id, 1 );
  951. p.accessory3 = GetWord( g_id, 0 );
  952. }else{
  953. p.shield = vd->shield;
  954. p.accessory2 = vd->head_top;
  955. p.accessory3 = vd->head_mid;
  956. }
  957. p.headpalette = vd->hair_color;
  958. p.bodypalette = vd->cloth_color;
  959. p.headDir = ( sd )? sd->head_dir : 0;
  960. p.GUID = g_id;
  961. p.GEmblemVer = status_get_emblem_id( bl );
  962. p.honor = ( sd ) ? sd->status.manner : 0;
  963. p.virtue = ( sc ) ? sc->opt3 : 0;
  964. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  965. p.sex = vd->sex;
  966. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  967. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  968. p.state = vd->dead_sit;
  969. p.clevel = clif_setlevel( bl );
  970. clif_send( &p, sizeof( p ), tbl, target );
  971. return;
  972. }
  973. #endif
  974. struct packet_idle_unit p;
  975. p.PacketType = idle_unitType;
  976. #if PACKETVER >= 20091103
  977. p.PacketLength = sizeof(p);
  978. p.objecttype = clif_bl_type( bl, walking );
  979. #endif
  980. #if PACKETVER >= 20131223
  981. p.AID = bl->id;
  982. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  983. #else
  984. p.GID = bl->id;
  985. #endif
  986. p.speed = status_get_speed(bl);
  987. p.bodyState = (sc) ? sc->opt1 : 0;
  988. p.healthState = (sc) ? sc->opt2 : 0;
  989. // npc option changed?
  990. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  991. struct map_session_data* sd = (struct map_session_data*)tbl;
  992. struct npc_data* nd = (struct npc_data*)bl;
  993. int option = (sc) ? sc->option : 0;
  994. if( !nd->vd.dead_sit ){
  995. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  996. option ^= OPTION_CLOAK;
  997. }
  998. }
  999. p.effectState = option;
  1000. }else{
  1001. p.effectState = (sc) ? sc->option : 0;
  1002. }
  1003. p.job = vd->class_;
  1004. p.head = vd->hair_style;
  1005. p.weapon = vd->weapon;
  1006. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1007. p.shield = vd->shield;
  1008. #endif
  1009. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1010. // The hell, why flags work like this?
  1011. p.accessory = status_get_emblem_id( bl );
  1012. p.accessory2 = GetWord( g_id, 1 );
  1013. p.accessory3 = GetWord( g_id, 0 );
  1014. }else{
  1015. p.accessory = vd->head_bottom;
  1016. p.accessory2 = vd->head_top;
  1017. p.accessory3 = vd->head_mid;
  1018. }
  1019. p.headpalette = vd->hair_color;
  1020. p.bodypalette = vd->cloth_color;
  1021. p.headDir = (sd)? sd->head_dir : 0;
  1022. #if PACKETVER >= 20101124
  1023. p.robe = vd->robe;
  1024. #endif
  1025. p.GUID = g_id;
  1026. p.GEmblemVer = status_get_emblem_id( bl );
  1027. p.honor = (sd) ? sd->status.manner : 0;
  1028. p.virtue = (sc) ? sc->opt3 : 0;
  1029. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1030. p.sex = vd->sex;
  1031. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1032. p.xSize = p.ySize = (sd) ? 5 : 0;
  1033. p.state = vd->dead_sit;
  1034. p.clevel = clif_setlevel( bl );
  1035. #if PACKETVER >= 20080102
  1036. p.font = (sd) ? sd->status.font : 0;
  1037. #endif
  1038. #if PACKETVER >= 20120221
  1039. 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 ) ) ){
  1040. p.maxHP = status_get_max_hp(bl);
  1041. p.HP = status_get_hp(bl);
  1042. }else{
  1043. p.maxHP = -1;
  1044. p.HP = -1;
  1045. }
  1046. if( bl->type == BL_MOB ){
  1047. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1048. }else if( bl->type == BL_PET ){
  1049. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1050. }else{
  1051. p.isBoss = BOSSTYPE_NONE;
  1052. }
  1053. #endif
  1054. #if PACKETVER >= 20150513
  1055. p.body = vd->body_style;
  1056. #endif
  1057. /* Might be earlier, this is when the named item bug began */
  1058. #if PACKETVER >= 20131223
  1059. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1060. #endif
  1061. clif_send( &p, sizeof( p ), tbl, target );
  1062. // if disguised, send to self
  1063. if( disguised( bl ) ){
  1064. #if PACKETVER >= 20091103
  1065. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1066. #if PACKETVER >= 20131223
  1067. p.AID = disguised_bl_id( bl->id );
  1068. #else
  1069. p.GID = disguised_bl_id( bl->id );
  1070. #endif
  1071. #else
  1072. p.GID = disguised_bl_id( bl->id );
  1073. #endif
  1074. clif_send(&p, sizeof(p), bl, SELF);
  1075. }
  1076. }
  1077. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1078. nullpo_retv( bl );
  1079. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1080. struct status_change* sc = status_get_sc( bl );
  1081. struct view_data* vd = status_get_viewdata( bl );
  1082. int g_id = status_get_guild_id( bl );
  1083. #if PACKETVER < 20091103
  1084. if( !pcdb_checkid( vd->class_ ) ){
  1085. struct packet_spawn_unit2 p;
  1086. p.PacketType = spawn_unit2Type;
  1087. #if PACKETVER >= 20071106
  1088. p.objecttype = clif_bl_type( bl, false );
  1089. #endif
  1090. p.GID = bl->id;
  1091. p.speed = status_get_speed( bl );
  1092. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1093. p.healthState = ( sc ) ? sc->opt2 : 0;
  1094. p.effectState = ( sc ) ? sc->option : 0;
  1095. p.head = vd->hair_style;
  1096. p.weapon = vd->weapon;
  1097. p.accessory = vd->head_bottom;
  1098. p.job = vd->class_;
  1099. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1100. // The hell, why flags work like this?
  1101. p.shield = status_get_emblem_id( bl );
  1102. p.accessory2 = GetWord( g_id, 1 );
  1103. p.accessory3 = GetWord( g_id, 0 );
  1104. }else{
  1105. p.shield = vd->shield;
  1106. p.accessory2 = vd->head_top;
  1107. p.accessory3 = vd->head_mid;
  1108. }
  1109. p.headpalette = vd->hair_color;
  1110. p.bodypalette = vd->cloth_color;
  1111. p.headDir = ( sd ) ? sd->head_dir : 0;
  1112. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1113. p.sex = vd->sex;
  1114. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1115. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1116. clif_send( &p, sizeof( p ), bl, target );
  1117. return;
  1118. }
  1119. #endif
  1120. struct packet_spawn_unit p;
  1121. p.PacketType = spawn_unitType;
  1122. #if PACKETVER >= 20091103
  1123. p.PacketLength = sizeof(p);
  1124. p.objecttype = clif_bl_type( bl, false );
  1125. #endif
  1126. #if PACKETVER >= 20131223
  1127. p.AID = bl->id;
  1128. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1129. #else
  1130. p.GID = bl->id;
  1131. #endif
  1132. p.speed = status_get_speed( bl );
  1133. p.bodyState = (sc) ? sc->opt1 : 0;
  1134. p.healthState = (sc) ? sc->opt2 : 0;
  1135. p.effectState = (sc) ? sc->option : 0;
  1136. p.job = vd->class_;
  1137. p.head = vd->hair_style;
  1138. p.weapon = vd->weapon;
  1139. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1140. p.shield = vd->shield;
  1141. #endif
  1142. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1143. // The hell, why flags work like this?
  1144. p.accessory = status_get_emblem_id( bl );
  1145. p.accessory2 = GetWord( g_id, 1 );
  1146. p.accessory3 = GetWord( g_id, 0 );
  1147. }else{
  1148. p.accessory = vd->head_bottom;
  1149. p.accessory2 = vd->head_top;
  1150. p.accessory3 = vd->head_mid;
  1151. }
  1152. p.headpalette = vd->hair_color;
  1153. p.bodypalette = vd->cloth_color;
  1154. p.headDir = (sd)? sd->head_dir : 0;
  1155. #if PACKETVER >= 20101124
  1156. p.robe = vd->robe;
  1157. #endif
  1158. p.GUID = g_id;
  1159. p.GEmblemVer = status_get_emblem_id( bl );
  1160. p.honor = (sd) ? sd->status.manner : 0;
  1161. p.virtue = (sc) ? sc->opt3 : 0;
  1162. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1163. p.sex = vd->sex;
  1164. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1165. p.xSize = p.ySize = (sd) ? 5 : 0;
  1166. p.clevel = clif_setlevel( bl );
  1167. #if PACKETVER >= 20080102
  1168. p.font = (sd) ? sd->status.font : 0;
  1169. #endif
  1170. #if PACKETVER >= 20120221
  1171. 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 ) ) ){
  1172. p.maxHP = status_get_max_hp( bl );
  1173. p.HP = status_get_hp( bl );
  1174. }else{
  1175. p.maxHP = -1;
  1176. p.HP = -1;
  1177. }
  1178. if( bl->type == BL_MOB ){
  1179. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1180. }else if( bl->type == BL_PET ){
  1181. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1182. }else{
  1183. p.isBoss = BOSSTYPE_NONE;
  1184. }
  1185. #endif
  1186. #if PACKETVER >= 20150513
  1187. p.body = vd->body_style;
  1188. #endif
  1189. /* Might be earlier, this is when the named item bug began */
  1190. #if PACKETVER >= 20131223
  1191. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1192. #endif
  1193. if( disguised( bl ) ){
  1194. nullpo_retv( sd );
  1195. if( sd->status.class_ != sd->disguise ){
  1196. clif_send( &p, sizeof( p ), bl, target );
  1197. }
  1198. #if PACKETVER >= 20091103
  1199. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1200. #if PACKETVER >= 20131223
  1201. p.AID = disguised_bl_id( bl->id );
  1202. #else
  1203. p.GID = disguised_bl_id( bl->id );
  1204. #endif
  1205. #else
  1206. p.GID = disguised_bl_id( bl->id );
  1207. #endif
  1208. clif_send( &p, sizeof( p ), bl, SELF );
  1209. }else{
  1210. clif_send( &p, sizeof( p ), bl, target );
  1211. }
  1212. }
  1213. /*==========================================
  1214. * Prepares 'unit walking' packet
  1215. *------------------------------------------*/
  1216. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1217. nullpo_retv( bl );
  1218. nullpo_retv( ud );
  1219. struct map_session_data* sd;
  1220. struct status_change* sc = status_get_sc( bl );
  1221. struct view_data* vd = status_get_viewdata( bl );
  1222. struct packet_unit_walking p;
  1223. int g_id = status_get_guild_id(bl);
  1224. sd = BL_CAST(BL_PC, bl);
  1225. p.PacketType = unit_walkingType;
  1226. #if PACKETVER >= 20091103
  1227. p.PacketLength = sizeof(p);
  1228. #endif
  1229. #if PACKETVER >= 20071106
  1230. p.objecttype = clif_bl_type( bl, true );
  1231. #endif
  1232. #if PACKETVER >= 20131223
  1233. p.AID = bl->id;
  1234. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1235. #else
  1236. p.GID = bl->id;
  1237. #endif
  1238. p.speed = status_get_speed(bl);
  1239. p.bodyState = (sc) ? sc->opt1 : 0;
  1240. p.healthState = (sc) ? sc->opt2 : 0;
  1241. p.effectState = (sc) ? sc->option : 0;
  1242. p.job = vd->class_;
  1243. p.head = vd->hair_style;
  1244. p.weapon = vd->weapon;
  1245. p.accessory = vd->head_bottom;
  1246. p.moveStartTime = client_tick(gettick());
  1247. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1248. p.shield = vd->shield;
  1249. #endif
  1250. p.accessory2 = vd->head_top;
  1251. p.accessory3 = vd->head_mid;
  1252. p.headpalette = vd->hair_color;
  1253. p.bodypalette = vd->cloth_color;
  1254. p.headDir = (sd) ? sd->head_dir : 0;
  1255. #if PACKETVER >= 20101124
  1256. p.robe = vd->robe;
  1257. #endif
  1258. p.GUID = g_id;
  1259. p.GEmblemVer = status_get_emblem_id(bl);
  1260. p.honor = (sd) ? sd->status.manner : 0;
  1261. p.virtue = (sc) ? sc->opt3 : 0;
  1262. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1263. p.sex = vd->sex;
  1264. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1265. p.xSize = p.ySize = (sd) ? 5 : 0;
  1266. p.clevel = clif_setlevel(bl);
  1267. #if PACKETVER >= 20080102
  1268. p.font = (sd) ? sd->status.font : 0;
  1269. #endif
  1270. #if PACKETVER >= 20120221
  1271. 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 ) ) ){
  1272. p.maxHP = status_get_max_hp(bl);
  1273. p.HP = status_get_hp(bl);
  1274. } else {
  1275. p.maxHP = -1;
  1276. p.HP = -1;
  1277. }
  1278. if( bl->type == BL_MOB ){
  1279. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1280. }else if( bl->type == BL_PET ){
  1281. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1282. }else{
  1283. p.isBoss = BOSSTYPE_NONE;
  1284. }
  1285. #endif
  1286. #if PACKETVER >= 20150513
  1287. p.body = vd->body_style;
  1288. #endif
  1289. /* Might be earlier, this is when the named item bug began */
  1290. #if PACKETVER >= 20131223
  1291. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1292. #endif
  1293. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1294. // if disguised, send the info to self
  1295. if( disguised( bl ) ){
  1296. #if PACKETVER >= 20091103
  1297. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1298. #if PACKETVER >= 20131223
  1299. p.AID = disguised_bl_id( bl->id );
  1300. #else
  1301. p.GID = disguised_bl_id( bl->id );
  1302. #endif
  1303. #else
  1304. p.GID = disguised_bl_id( bl->id );
  1305. #endif
  1306. clif_send(&p,sizeof(p),bl,SELF);
  1307. }
  1308. }
  1309. //Modifies the buffer for disguise characters and sends it to self.
  1310. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1311. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1312. {
  1313. #if PACKETVER >= 20091103
  1314. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1315. WBUFL(buf,5)=-bl->id;
  1316. #elif PACKETVER >= 20071106
  1317. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1318. WBUFL(buf,3)=-bl->id;
  1319. #else
  1320. WBUFL(buf,2)=-bl->id;
  1321. #endif
  1322. clif_send(buf, len, bl, SELF);
  1323. }
  1324. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1325. /// 01b0 <id>.L <type>.B <value>.L
  1326. /// type:
  1327. /// unused
  1328. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1329. {
  1330. nullpo_retv(bl);
  1331. if(!pcdb_checkid(class_))
  1332. {// player classes yield missing sprites
  1333. unsigned char buf[16];
  1334. WBUFW(buf,0)=0x1b0;
  1335. WBUFL(buf,2)=bl->id;
  1336. WBUFB(buf,6)=type;
  1337. WBUFL(buf,7)=class_;
  1338. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1339. }
  1340. }
  1341. void clif_servantball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1342. struct PACKET_ZC_SPIRITS p = {};
  1343. p.PacketType = HEADER_ZC_SPIRITS;
  1344. p.AID = sd.bl.id;
  1345. p.num = sd.servantball;
  1346. if( target == nullptr ){
  1347. target = &sd.bl;
  1348. }
  1349. clif_send( &p, sizeof( p ), target, send_target );
  1350. }
  1351. void clif_abyssball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1352. struct PACKET_ZC_SPIRITS p = {};
  1353. p.PacketType = HEADER_ZC_SPIRITS;
  1354. p.AID = sd.bl.id;
  1355. p.num = sd.abyssball;
  1356. if( target == nullptr ){
  1357. target = &sd.bl;
  1358. }
  1359. clif_send( &p, sizeof( p ), target, send_target );
  1360. }
  1361. /// Notifies the client of an object's Millenium Shields.
  1362. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1363. {
  1364. nullpo_retv(sd);
  1365. if (sd->sc.data[SC_MILLENNIUMSHIELD] == nullptr)
  1366. return;
  1367. WFIFOHEAD(fd, packet_len(0x440));
  1368. WFIFOW(fd, 0) = 0x440;
  1369. WFIFOL(fd, 2) = sd->bl.id;
  1370. WFIFOW(fd, 6) = sd->sc.data[SC_MILLENNIUMSHIELD]->val2;
  1371. WFIFOW(fd, 8) = 0;
  1372. WFIFOSET(fd, packet_len(0x440));
  1373. }
  1374. /*==========================================
  1375. * Kagerou/Oboro amulet spirit
  1376. *------------------------------------------*/
  1377. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1378. {
  1379. WFIFOHEAD(fd, packet_len(0x08cf));
  1380. WFIFOW(fd,0)=0x08cf;
  1381. WFIFOL(fd,2)=sd->bl.id;
  1382. WFIFOW(fd,6)=sd->spiritcharm_type;
  1383. WFIFOW(fd,8)=sd->spiritcharm;
  1384. WFIFOSET(fd, packet_len(0x08cf));
  1385. }
  1386. /*==========================================
  1387. * Enchanting Shadow / Shadow Scar Spirit
  1388. *------------------------------------------*/
  1389. void clif_enchantingshadow_spirit(unit_data &ud) {
  1390. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1391. PACKET_ZC_TARGET_SPIRITS p = {};
  1392. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1393. p.GID = ud.bl->id;
  1394. p.unknown_val = 0;
  1395. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1396. clif_send(&p, sizeof(p), ud.bl, AREA);
  1397. #endif
  1398. }
  1399. /*==========================================
  1400. * Run when player changes map / refreshes
  1401. * Tells its client to display all weather settings being used by this map
  1402. *------------------------------------------*/
  1403. static void clif_weather_check(struct map_session_data *sd)
  1404. {
  1405. int16 m = sd->bl.m;
  1406. int fd = sd->fd;
  1407. if (map_getmapflag(m, MF_SNOW)
  1408. || map_getmapflag(m, MF_CLOUDS)
  1409. || map_getmapflag(m, MF_FOG)
  1410. || map_getmapflag(m, MF_FIREWORKS)
  1411. || map_getmapflag(m, MF_SAKURA)
  1412. || map_getmapflag(m, MF_LEAVES)
  1413. || map_getmapflag(m, MF_CLOUDS2))
  1414. {
  1415. if (map_getmapflag(m, MF_SNOW))
  1416. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1417. if (map_getmapflag(m, MF_CLOUDS))
  1418. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1419. if (map_getmapflag(m, MF_CLOUDS2))
  1420. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1421. if (map_getmapflag(m, MF_FOG))
  1422. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1423. if (map_getmapflag(m, MF_FIREWORKS)) {
  1424. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1425. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1426. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1427. }
  1428. if (map_getmapflag(m, MF_SAKURA))
  1429. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1430. if (map_getmapflag(m, MF_LEAVES))
  1431. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1432. }
  1433. }
  1434. /**
  1435. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1436. **/
  1437. void clif_weather(int16 m)
  1438. {
  1439. struct s_mapiterator* iter;
  1440. struct map_session_data *sd=NULL;
  1441. iter = mapit_getallusers();
  1442. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1443. {
  1444. if( sd->bl.m == m )
  1445. clif_weather_check(sd);
  1446. }
  1447. mapit_free(iter);
  1448. }
  1449. /**
  1450. * Hide a NPC from the effects of Maya Purple card.
  1451. * @param bl: Block data
  1452. * @return True if NPC is disabled or false otherwise
  1453. */
  1454. static inline bool clif_npc_mayapurple(block_list *bl) {
  1455. nullpo_retr(false, bl);
  1456. if (bl->type == BL_NPC) {
  1457. npc_data *nd = map_id2nd(bl->id);
  1458. // TODO: Confirm if waitingroom cause any special cases
  1459. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1460. return true;
  1461. }
  1462. return false;
  1463. }
  1464. /**
  1465. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1466. **/
  1467. int clif_spawn( struct block_list *bl, bool walking ){
  1468. struct view_data *vd;
  1469. vd = status_get_viewdata(bl);
  1470. if( !vd || vd->class_ == JT_INVISIBLE )
  1471. return 0;
  1472. // Hide NPC from Maya Purple card
  1473. if (clif_npc_mayapurple(bl))
  1474. return 0;
  1475. if( bl->type == BL_NPC && !vd->dead_sit ){
  1476. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1477. }else{
  1478. clif_spawn_unit( bl, AREA_WOS );
  1479. }
  1480. if (vd->cloth_color)
  1481. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1482. if (vd->body_style)
  1483. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1484. switch (bl->type)
  1485. {
  1486. case BL_PC:
  1487. {
  1488. TBL_PC *sd = ((TBL_PC*)bl);
  1489. if (sd->spiritball > 0)
  1490. clif_spiritball(&sd->bl);
  1491. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  1492. clif_millenniumshield(&sd->bl, sd->sc.data[SC_MILLENNIUMSHIELD]->val2);
  1493. if (sd->soulball > 0)
  1494. clif_soulball(sd);
  1495. if (sd->servantball > 0)
  1496. clif_servantball( *sd );
  1497. if (sd->abyssball > 0)
  1498. clif_abyssball( *sd );
  1499. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1500. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1501. else if(sd->state.size==SZ_MEDIUM)
  1502. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1503. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1504. clif_sendbgemblem_area(sd);
  1505. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1506. clif_spiritcharm(sd);
  1507. if (sd->status.robe)
  1508. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1509. clif_efst_status_change_sub(bl, bl, AREA);
  1510. clif_hat_effects(sd,bl,AREA);
  1511. }
  1512. break;
  1513. case BL_MOB:
  1514. {
  1515. TBL_MOB *md = ((TBL_MOB*)bl);
  1516. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1517. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1518. else if(md->special_state.size==SZ_MEDIUM)
  1519. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1520. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1521. clif_summon_init(*md);
  1522. }
  1523. break;
  1524. case BL_NPC:
  1525. {
  1526. TBL_NPC *nd = ((TBL_NPC*)bl);
  1527. if( nd->size == SZ_BIG )
  1528. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1529. else if( nd->size == SZ_MEDIUM )
  1530. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1531. clif_efst_status_change_sub(bl, bl, AREA);
  1532. clif_progressbar_npc_area(nd);
  1533. }
  1534. break;
  1535. case BL_PET:
  1536. if (vd->head_bottom)
  1537. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1538. break;
  1539. }
  1540. return 0;
  1541. }
  1542. /// Sends information about owned homunculus to the client . [orn]
  1543. /// 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)
  1544. /// 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)
  1545. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1546. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1547. nullpo_retv( sd );
  1548. nullpo_retv( hd );
  1549. struct status_data *status = &hd->battle_status;
  1550. struct PACKET_ZC_PROPERTY_HOMUN p;
  1551. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1552. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1553. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1554. 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 );
  1555. p.level = hd->homunculus.level;
  1556. p.hunger = hd->homunculus.hunger;
  1557. p.intimacy = hd->homunculus.intimacy / 100;
  1558. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1559. p.itemId = 0; // equip id
  1560. #endif
  1561. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1562. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1563. p.hit = status->hit;
  1564. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1565. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1566. }else{
  1567. p.crit = status->cri / 10;
  1568. }
  1569. #ifdef RENEWAL
  1570. p.def = status->def + status->def2;
  1571. p.mdef = status->mdef + status->mdef2;
  1572. #else
  1573. p.def = status->def + status->vit;
  1574. p.mdef = status->mdef;
  1575. #endif
  1576. p.flee = status->flee;
  1577. p.amotion = (flag) ? 0 : status->amotion;
  1578. #if PACKETVER >= 20141016
  1579. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1580. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1581. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1582. p.hp = status->hp / ( status->max_hp / 100 );
  1583. p.maxHp = 100;
  1584. }else{
  1585. p.hp = status->hp;
  1586. p.maxHp = status->max_hp;
  1587. }
  1588. #else
  1589. if( status->max_hp > INT16_MAX ){
  1590. p.hp = status->hp / ( status->max_hp / 100 );
  1591. p.maxHp = 100;
  1592. }else{
  1593. p.hp = status->hp;
  1594. p.maxHp = status->max_hp;
  1595. }
  1596. #endif
  1597. if( status->max_sp > INT16_MAX ){
  1598. p.sp = status->sp / ( status->max_sp / 100 );
  1599. p.maxSp = 100;
  1600. }else{
  1601. p.sp = status->sp;
  1602. p.maxSp = status->max_sp;
  1603. }
  1604. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1605. p.exp = hd->homunculus.exp;
  1606. p.expNext = hd->exp_next;
  1607. #else
  1608. p.exp = (uint32)hd->homunculus.exp;
  1609. p.expNext = (uint32)hd->exp_next;
  1610. #endif
  1611. switch( hom_class2type( hd->homunculus.class_ ) ){
  1612. case HT_REG:
  1613. case HT_EVO:
  1614. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1615. p.expNext = 0;
  1616. }
  1617. break;
  1618. case HT_S:
  1619. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1620. p.expNext = 0;
  1621. }
  1622. break;
  1623. }
  1624. p.skillPoints = hd->homunculus.skillpts;
  1625. p.range = status_get_range( &hd->bl );
  1626. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1627. #endif
  1628. }
  1629. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1630. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1631. /// type:
  1632. /// unused
  1633. /// state:
  1634. /// 0 = pre-init
  1635. /// 1 = intimacy
  1636. /// 2 = hunger
  1637. /// 3 = accessory?
  1638. /// ? = ignored
  1639. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1640. { //[orn]
  1641. int fd = sd->fd;
  1642. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1643. hom_calc_skilltree(sd->hd, 0);
  1644. WFIFOHEAD(fd, packet_len(0x230));
  1645. WFIFOW(fd,0)=0x230;
  1646. WFIFOB(fd,2)=0;
  1647. WFIFOB(fd,3)=state;
  1648. WFIFOL(fd,4)=sd->hd->bl.id;
  1649. WFIFOL(fd,8)=param;
  1650. WFIFOSET(fd,packet_len(0x230));
  1651. }
  1652. int clif_homskillinfoblock(struct map_session_data *sd)
  1653. { //[orn]
  1654. struct homun_data *hd;
  1655. int fd = sd->fd;
  1656. int i, len=4;
  1657. nullpo_ret(sd);
  1658. hd = sd->hd;
  1659. if ( !hd )
  1660. return 0 ;
  1661. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1662. WFIFOW(fd,0)=0x235;
  1663. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1664. int id = hd->homunculus.hskill[i].id;
  1665. if( id != 0 ){
  1666. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1667. short idx = hom_skill_get_index(id);
  1668. if (idx == -1)
  1669. continue;
  1670. WFIFOW(fd,len ) = id;
  1671. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1672. WFIFOW(fd,len+4) = 0;
  1673. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1674. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1675. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1676. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1677. 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;
  1678. len+=37;
  1679. }
  1680. }
  1681. WFIFOW(fd,2)=len;
  1682. WFIFOSET(fd,len);
  1683. return 0;
  1684. }
  1685. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1686. { //[orn]
  1687. struct homun_data *hd;
  1688. int fd;
  1689. short idx = -1;
  1690. nullpo_retv(sd);
  1691. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1692. return;
  1693. fd = sd->fd;
  1694. hd = sd->hd;
  1695. WFIFOHEAD(fd, packet_len(0x239));
  1696. WFIFOW(fd,0) = 0x239;
  1697. WFIFOW(fd,2) = skill_id;
  1698. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1699. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1700. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1701. 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;
  1702. WFIFOSET(fd,packet_len(0x239));
  1703. }
  1704. /// Result of request to feed a homun/merc.
  1705. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1706. /// result:
  1707. /// 0 = failure
  1708. /// 1 = success
  1709. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1710. nullpo_retv( sd );
  1711. struct PACKET_ZC_FEED_MER p;
  1712. p.packetType = 0x22f;
  1713. p.result = fail;
  1714. p.itemId = client_nameid( foodid );
  1715. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1716. }
  1717. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1718. /// 0087 <walk start time>.L <walk data>.6B
  1719. void clif_walkok(struct map_session_data *sd)
  1720. {
  1721. int fd=sd->fd;
  1722. WFIFOHEAD(fd, packet_len(0x87));
  1723. WFIFOW(fd,0)=0x87;
  1724. WFIFOL(fd,2)=client_tick(gettick());
  1725. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1726. WFIFOSET(fd,packet_len(0x87));
  1727. }
  1728. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1729. struct status_change *sc = NULL;
  1730. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1731. clif_ally_only = true;
  1732. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1733. if(vd->cloth_color)
  1734. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1735. if(vd->body_style)
  1736. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1737. switch(bl->type) {
  1738. case BL_PC:
  1739. {
  1740. TBL_PC *sd = ((TBL_PC*)bl);
  1741. // clif_movepc(sd);
  1742. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1743. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1744. else if(sd->state.size==SZ_MEDIUM)
  1745. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1746. if (sd->status.robe)
  1747. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1748. }
  1749. break;
  1750. case BL_MOB:
  1751. {
  1752. TBL_MOB *md = ((TBL_MOB*)bl);
  1753. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1754. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1755. else if(md->special_state.size==SZ_MEDIUM)
  1756. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1757. }
  1758. break;
  1759. case BL_PET:
  1760. if(vd->head_bottom) // needed to display pet equip properly
  1761. clif_pet_equip_area((TBL_PET*)bl);
  1762. break;
  1763. }
  1764. clif_ally_only = false;
  1765. }
  1766. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1767. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1768. /// Note: unit must not be self
  1769. void clif_move(struct unit_data *ud)
  1770. {
  1771. unsigned char buf[16];
  1772. struct view_data* vd;
  1773. struct block_list* bl = ud->bl;
  1774. struct status_change *sc = NULL;
  1775. vd = status_get_viewdata(bl);
  1776. if (!vd )
  1777. return;
  1778. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1779. else if( vd->class_ == JT_INVISIBLE ){
  1780. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1781. if(disguised(bl)) {
  1782. WBUFW(buf,0)=0x86;
  1783. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1784. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1785. WBUFL(buf,12)=client_tick(gettick());
  1786. clif_send(buf, packet_len(0x86), bl, SELF);
  1787. }
  1788. return;
  1789. }
  1790. // Hide NPC from Maya Purple card
  1791. if (clif_npc_mayapurple(bl))
  1792. return;
  1793. if (ud->state.speed_changed) {
  1794. // Since we don't know how to update the speed of other objects,
  1795. // use the old walk packet to update the data.
  1796. ud->state.speed_changed = 0;
  1797. clif_move2(bl, vd, ud);
  1798. return;
  1799. }
  1800. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1801. clif_ally_only = true;
  1802. WBUFW(buf,0)=0x86;
  1803. WBUFL(buf,2)=bl->id;
  1804. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1805. WBUFL(buf,12)=client_tick(gettick());
  1806. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1807. if (disguised(bl)) {
  1808. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1809. clif_send(buf, packet_len(0x86), bl, SELF);
  1810. }
  1811. clif_ally_only = false;
  1812. }
  1813. /*==========================================
  1814. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1815. *------------------------------------------*/
  1816. static TIMER_FUNC(clif_delayquit){
  1817. struct map_session_data *sd = NULL;
  1818. //Remove player from map server
  1819. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1820. map_quit(sd);
  1821. return 0;
  1822. }
  1823. /*==========================================
  1824. *
  1825. *------------------------------------------*/
  1826. void clif_quitsave(int fd,struct map_session_data *sd) {
  1827. if (!battle_config.prevent_logout ||
  1828. sd->canlog_tick == 0 ||
  1829. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1830. map_quit(sd);
  1831. else if (session_isValid(sd->fd)) {
  1832. //Disassociate session from player (session is deleted after this function was called)
  1833. //And set a timer to make him quit later.
  1834. session[sd->fd]->session_data = NULL;
  1835. sd->fd = 0;
  1836. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1837. }
  1838. }
  1839. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1840. /// 0091 <map name>.16B <x>.W <y>.W
  1841. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1842. {
  1843. nullpo_retv(sd);
  1844. int fd = sd->fd;
  1845. WFIFOHEAD(fd,packet_len(0x91));
  1846. WFIFOW(fd,0) = 0x91;
  1847. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1848. WFIFOW(fd,18) = x;
  1849. WFIFOW(fd,20) = y;
  1850. WFIFOSET(fd,packet_len(0x91));
  1851. }
  1852. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1853. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1854. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1855. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1856. {
  1857. int fd;
  1858. #if PACKETVER >= 20170315
  1859. int cmd = 0xac7;
  1860. #else
  1861. int cmd = 0x92;
  1862. #endif
  1863. nullpo_retv(sd);
  1864. fd = sd->fd;
  1865. WFIFOHEAD(fd,packet_len(cmd));
  1866. WFIFOW(fd,0) = cmd;
  1867. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1868. WFIFOW(fd,18) = x;
  1869. WFIFOW(fd,20) = y;
  1870. WFIFOL(fd,22) = htonl(ip);
  1871. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1872. #if PACKETVER >= 20170315
  1873. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1874. #endif
  1875. WFIFOSET(fd,packet_len(cmd));
  1876. }
  1877. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1878. /// This function combines both calls and allows to simplify the calling code
  1879. void clif_blown(struct block_list *bl)
  1880. {
  1881. clif_slide(bl, bl->x, bl->y);
  1882. clif_fixpos(bl);
  1883. }
  1884. /// Visually moves(slides) a character to x,y. If the target cell
  1885. /// isn't walkable, the char doesn't move at all. If the char is
  1886. /// sitting it will stand up (ZC_STOPMOVE).
  1887. /// 0088 <id>.L <x>.W <y>.W
  1888. void clif_fixpos(struct block_list *bl)
  1889. {
  1890. unsigned char buf[10];
  1891. nullpo_retv(bl);
  1892. WBUFW(buf,0) = 0x88;
  1893. WBUFL(buf,2) = bl->id;
  1894. WBUFW(buf,6) = bl->x;
  1895. WBUFW(buf,8) = bl->y;
  1896. clif_send(buf, packet_len(0x88), bl, AREA);
  1897. if( disguised(bl) ) {
  1898. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1899. clif_send(buf, packet_len(0x88), bl, SELF);
  1900. }
  1901. }
  1902. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1903. /// 00c4 <shop id>.L
  1904. void clif_npcbuysell(struct map_session_data* sd, int id)
  1905. {
  1906. int fd;
  1907. nullpo_retv(sd);
  1908. fd=sd->fd;
  1909. WFIFOHEAD(fd, packet_len(0xc4));
  1910. WFIFOW(fd,0)=0xc4;
  1911. WFIFOL(fd,2)=id;
  1912. WFIFOSET(fd,packet_len(0xc4));
  1913. }
  1914. /// Presents list of items, that can be bought in an NPC shop.
  1915. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1916. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1917. nullpo_retv( sd );
  1918. nullpo_retv( nd );
  1919. int fd = sd->fd;
  1920. if( !session_isActive( fd ) ){
  1921. return;
  1922. }
  1923. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1924. WFIFOHEAD( fd, len );
  1925. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1926. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1927. int count = 0;
  1928. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1929. int val = nd->u.shop.shop_item[i].value;
  1930. p->items[count].price = val;
  1931. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1932. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1933. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1934. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1935. std::shared_ptr<item_data> id = item_db.find(nd->u.shop.shop_item[i].nameid);
  1936. p->items[count].viewSprite = id->look;
  1937. p->items[count].location = pc_equippoint_sub( sd, id.get() );
  1938. #endif
  1939. count++;
  1940. }
  1941. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1942. WFIFOSET( fd, p->packetLength );
  1943. }
  1944. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1945. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1946. void clif_selllist(struct map_session_data *sd)
  1947. {
  1948. int fd,i,c=0,val;
  1949. struct npc_data *nd;
  1950. nullpo_retv(sd);
  1951. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1952. return;
  1953. fd=sd->fd;
  1954. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1955. WFIFOW(fd,0)=0xc7;
  1956. for( i = 0; i < MAX_INVENTORY; i++ )
  1957. {
  1958. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1959. {
  1960. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1961. continue;
  1962. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1963. val = 0;
  1964. else {
  1965. val = sd->inventory_data[i]->value_sell;
  1966. if( val < 0 )
  1967. continue;
  1968. }
  1969. WFIFOW(fd,4+c*10)=i+2;
  1970. WFIFOL(fd,6+c*10)=val;
  1971. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1972. c++;
  1973. }
  1974. }
  1975. WFIFOW(fd,2)=c*10+4;
  1976. WFIFOSET(fd,WFIFOW(fd,2));
  1977. }
  1978. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1979. /// 09d4
  1980. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1981. // TODO: State tracking?
  1982. sd->npc_shopid = 0;
  1983. }
  1984. /**
  1985. * Presents list of items, that can be sold to a Market shop.
  1986. * @author: Ind and Yommy
  1987. **/
  1988. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1989. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1990. #if PACKETVER >= 20131223
  1991. nullpo_retv( sd );
  1992. nullpo_retv( nd );
  1993. if( sd->state.trading ){
  1994. return;
  1995. }
  1996. int fd = sd->fd;
  1997. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1998. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1999. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  2000. int count = 0;
  2001. for( int i = 0; i < nd->u.shop.count; i++ ){
  2002. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  2003. if( !item->nameid ){
  2004. continue;
  2005. }
  2006. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  2007. if( !id ){
  2008. continue;
  2009. }
  2010. // Out of stock
  2011. if( item->qty == 0 ){
  2012. continue;
  2013. }
  2014. p->list[count].nameid = client_nameid( item->nameid );
  2015. p->list[count].type = itemtype( item->nameid );
  2016. p->list[count].price = item->value;
  2017. p->list[count].qty = item->qty;
  2018. p->list[count].weight = id->weight;
  2019. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2020. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2021. #endif
  2022. count++;
  2023. }
  2024. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2025. WFIFOSET( fd, p->packetLength );
  2026. sd->state.trading = 1;
  2027. #endif
  2028. }
  2029. /// Closes the Market shop window.
  2030. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  2031. nullpo_retv(sd);
  2032. sd->npc_shopid = 0;
  2033. sd->state.trading = 0;
  2034. }
  2035. /// Purchase item from Market shop.
  2036. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2037. void clif_npc_market_purchase_ack( struct map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2038. #if PACKETVER >= 20131223
  2039. nullpo_retv( sd );
  2040. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2041. nullpo_retv( nd );
  2042. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2043. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2044. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2045. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2046. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2047. #else
  2048. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2049. #endif
  2050. if( p->result ){
  2051. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2052. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2053. // Not found
  2054. if( j == nd->u.shop.count ){
  2055. continue;
  2056. }
  2057. p->list[count].ITID = client_nameid( list[i].nameid );
  2058. p->list[count].qty = list[i].qty;
  2059. p->list[count].price = nd->u.shop.shop_item[j].value;
  2060. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2061. count++;
  2062. }
  2063. }
  2064. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2065. #endif
  2066. }
  2067. /// Purchase item from Market shop.
  2068. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2069. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  2070. #if PACKETVER >= 20131223
  2071. nullpo_retv( sd );
  2072. if( !sd->npc_shopid ){
  2073. return;
  2074. }
  2075. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2076. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2077. std::vector<s_npc_buy_list> items;
  2078. items.reserve( count );
  2079. for( int i = 0; i < count; i++ ){
  2080. s_npc_buy_list item = {};
  2081. item.nameid = p->list[i].ITID;
  2082. item.qty = p->list[i].qty;
  2083. items.push_back( item );
  2084. }
  2085. e_purchase_result res = npc_buylist( sd, items );
  2086. clif_npc_market_purchase_ack( sd, res, items );
  2087. #endif
  2088. }
  2089. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2090. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2091. /// Client behavior (dialog window):
  2092. /// - disable mouse targeting
  2093. /// - open the dialog window
  2094. /// - set npcid of dialog window (0 by default)
  2095. /// - if set to clear on next mes, clear contents
  2096. /// - append this text
  2097. void clif_scriptmes( struct map_session_data& sd, uint32 npcid, const char *mes ){
  2098. struct PACKET_ZC_SAY_DIALOG* p = (struct PACKET_ZC_SAY_DIALOG*)packet_buffer;
  2099. int16 length = (int16)( strlen( mes ) + 1 );
  2100. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2101. p->PacketLength = sizeof( *p ) + length;
  2102. p->NpcID = npcid;
  2103. safestrncpy( p->message, mes, length );
  2104. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2105. }
  2106. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2107. /// 00b5 <npc id>.L
  2108. /// Client behavior (dialog window):
  2109. /// - disable mouse targeting
  2110. /// - open the dialog window
  2111. /// - add 'next' button
  2112. /// When 'next' is pressed:
  2113. /// - 00B9 <npcid of dialog window>.L
  2114. /// - set to clear on next mes
  2115. /// - remove 'next' button
  2116. void clif_scriptnext( struct map_session_data& sd, uint32 npcid ){
  2117. struct PACKET_ZC_WAIT_DIALOG p = {};
  2118. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2119. p.NpcID = npcid;
  2120. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2121. }
  2122. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2123. /// 00b6 <npc id>.L
  2124. /// Client behavior:
  2125. /// - if dialog window is open:
  2126. /// - remove 'next' button
  2127. /// - add 'close' button
  2128. /// - else:
  2129. /// - enable mouse targeting
  2130. /// - close the dialog window
  2131. /// - close the menu window
  2132. /// When 'close' is pressed:
  2133. /// - enable mouse targeting
  2134. /// - close the dialog window
  2135. /// - close the menu window
  2136. /// - 0146 <npcid of dialog window>.L
  2137. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2138. {
  2139. int fd;
  2140. nullpo_retv(sd);
  2141. fd=sd->fd;
  2142. WFIFOHEAD(fd, packet_len(0xb6));
  2143. WFIFOW(fd,0)=0xb6;
  2144. WFIFOL(fd,2)=npcid;
  2145. WFIFOSET(fd,packet_len(0xb6));
  2146. }
  2147. /**
  2148. * Close script when player is idle
  2149. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2150. * @author [Ind/Hercules]
  2151. * @param sd : player pointer
  2152. * @param npcid : npc gid to close
  2153. */
  2154. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2155. {
  2156. struct s_packet_db* info;
  2157. int16 len;
  2158. int cmd = 0;
  2159. int fd;
  2160. nullpo_retv(sd);
  2161. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2162. if(!cmd) cmd = 0x8d6; //default
  2163. info = &packet_db[cmd];
  2164. len = info->len;
  2165. fd = sd->fd;
  2166. WFIFOHEAD(fd, len);
  2167. WFIFOW(fd,0)=0x8d6;
  2168. WFIFOL(fd,info->pos[0])=npcid;
  2169. WFIFOSET(fd,len);
  2170. }
  2171. /*==========================================
  2172. *
  2173. *------------------------------------------*/
  2174. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2175. unsigned char *buf;
  2176. int fd = sd->fd;
  2177. sd->state.using_fake_npc = 1;
  2178. WFIFOHEAD(fd, packet_len(0x78));
  2179. buf = WFIFOP(fd,0);
  2180. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2181. WBUFW(buf,0)=0x78;
  2182. #if PACKETVER >= 20071106
  2183. WBUFB(buf,2) = 0; // object type
  2184. buf = WFIFOP(fd,1);
  2185. #endif
  2186. WBUFL(buf,2)=npcid;
  2187. WBUFW(buf,14)=111;
  2188. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2189. WBUFB(buf,49)=5;
  2190. WBUFB(buf,50)=5;
  2191. WFIFOSET(fd, packet_len(0x78));
  2192. }
  2193. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2194. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2195. /// Client behavior:
  2196. /// - disable mouse targeting
  2197. /// - close the menu window
  2198. /// - open the menu window
  2199. /// - add options to the menu (separated in the text by ":")
  2200. /// - set npcid of menu window
  2201. /// - if dialog window is open:
  2202. /// - remove 'next' button
  2203. /// When 'ok' is pressed:
  2204. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2205. /// - close the menu window
  2206. /// When 'cancel' is pressed:
  2207. /// - 00B8 <npcid of menu window>.L <-1>.B
  2208. /// - enable mouse targeting
  2209. /// - close a bunch of windows...
  2210. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2211. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2212. /// TODO investigate behavior of other windows [FlavioJS]
  2213. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2214. {
  2215. int fd = sd->fd;
  2216. int slen = strlen(mes) + 9;
  2217. struct block_list *bl = NULL;
  2218. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2219. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2220. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2221. clif_sendfakenpc(sd, npcid);
  2222. WFIFOHEAD(fd, slen);
  2223. WFIFOW(fd,0)=0xb7;
  2224. WFIFOW(fd,2)=slen;
  2225. WFIFOL(fd,4)=npcid;
  2226. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2227. WFIFOSET(fd,WFIFOW(fd,2));
  2228. }
  2229. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2230. /// 0142 <npc id>.L
  2231. /// Client behavior (inputnum window):
  2232. /// - if npcid exists in the client:
  2233. /// - open the inputnum window
  2234. /// - set npcid of inputnum window
  2235. /// When 'ok' is pressed:
  2236. /// - if inputnum window has text:
  2237. /// - if npcid exists in the client:
  2238. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2239. /// - close inputnum window
  2240. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2241. {
  2242. int fd;
  2243. struct block_list *bl = NULL;
  2244. nullpo_retv(sd);
  2245. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2246. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2247. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2248. clif_sendfakenpc(sd, npcid);
  2249. fd=sd->fd;
  2250. WFIFOHEAD(fd, packet_len(0x142));
  2251. WFIFOW(fd,0)=0x142;
  2252. WFIFOL(fd,2)=npcid;
  2253. WFIFOSET(fd,packet_len(0x142));
  2254. }
  2255. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2256. /// 01d4 <npc id>.L
  2257. /// Client behavior (inputstr window):
  2258. /// - if npcid is 0 or npcid exists in the client:
  2259. /// - open the inputstr window
  2260. /// - set npcid of inputstr window
  2261. /// When 'ok' is pressed:
  2262. /// - if inputstr window has text and isn't an insult(manner.txt):
  2263. /// - if npcid is 0 or npcid exists in the client:
  2264. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2265. /// - close inputstr window
  2266. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2267. {
  2268. int fd;
  2269. struct block_list *bl = NULL;
  2270. nullpo_retv(sd);
  2271. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2272. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2273. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2274. clif_sendfakenpc(sd, npcid);
  2275. fd=sd->fd;
  2276. WFIFOHEAD(fd, packet_len(0x1d4));
  2277. WFIFOW(fd,0)=0x1d4;
  2278. WFIFOL(fd,2)=npcid;
  2279. WFIFOSET(fd,packet_len(0x1d4));
  2280. }
  2281. /// Marks a position on client's minimap (ZC_COMPASS).
  2282. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2283. /// npc id:
  2284. /// is ignored in the client
  2285. /// type:
  2286. /// 0 = display mark for 15 seconds
  2287. /// 1 = display mark until dead or teleported
  2288. /// 2 = remove mark
  2289. /// color:
  2290. /// 0x00RRGGBB
  2291. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2292. {
  2293. int fd;
  2294. nullpo_retv(sd);
  2295. fd=sd->fd;
  2296. WFIFOHEAD(fd, packet_len(0x144));
  2297. WFIFOW(fd,0)=0x144;
  2298. WFIFOL(fd,2)=npc_id;
  2299. WFIFOL(fd,6)=type;
  2300. WFIFOL(fd,10)=x;
  2301. WFIFOL(fd,14)=y;
  2302. WFIFOB(fd,18)=id;
  2303. WFIFOL(fd,19)=color;
  2304. WFIFOSET(fd,packet_len(0x144));
  2305. }
  2306. /// Displays an illustration image.
  2307. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2308. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2309. /// type:
  2310. /// 0 = bottom left corner
  2311. /// 1 = bottom middle
  2312. /// 2 = bottom right corner
  2313. /// 3 = middle of screen, inside a movable window
  2314. /// 4 = middle of screen, movable with a close button, chrome-less
  2315. /// 255 = clear all displayed cutins
  2316. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2317. {
  2318. int fd;
  2319. nullpo_retv(sd);
  2320. fd=sd->fd;
  2321. WFIFOHEAD(fd, packet_len(0x1b3));
  2322. WFIFOW(fd,0)=0x1b3;
  2323. strncpy(WFIFOCP(fd,2),image,64);
  2324. WFIFOB(fd,66)=type;
  2325. WFIFOSET(fd,packet_len(0x1b3));
  2326. }
  2327. /*==========================================
  2328. * Fills in card data from the given item and into the buffer. [Skotlex]
  2329. *------------------------------------------*/
  2330. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2331. nullpo_retv( buf );
  2332. // Blank data
  2333. if( item == nullptr ){
  2334. buf->card[0] = 0;
  2335. buf->card[1] = 0;
  2336. buf->card[2] = 0;
  2337. buf->card[3] = 0;
  2338. return;
  2339. }
  2340. // Pet eggs
  2341. if( item->card[0] == CARD0_PET ){
  2342. buf->card[0] = 0;
  2343. buf->card[1] = 0;
  2344. // Pet intimacy
  2345. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2346. buf->card[2] = item->card[3] >> 1;
  2347. // Pet renamed flag
  2348. buf->card[3] = item->card[3] & 1;
  2349. return;
  2350. }
  2351. // Forged/created items
  2352. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2353. buf->card[0] = item->card[0];
  2354. buf->card[1] = item->card[1];
  2355. buf->card[2] = item->card[2];
  2356. buf->card[3] = item->card[3];
  2357. return;
  2358. }
  2359. int i = 0, j;
  2360. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2361. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2362. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2363. }
  2364. // Normal items.
  2365. for( int k = 0; k < 4; k++, i++ ){
  2366. if( item->card[i] > 0 ){
  2367. buf->card[k] = client_nameid( item->card[i] );
  2368. }else{
  2369. buf->card[k] = 0;
  2370. }
  2371. }
  2372. }
  2373. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2374. /// A maximum of 5 random options can be supported.
  2375. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2376. nullpo_retr( 0, it );
  2377. uint8 count = 0;
  2378. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2379. if( it->option[i].id ){
  2380. buf[i].index = it->option[i].id; // OptIndex
  2381. buf[i].value = it->option[i].value; // Value
  2382. buf[i].param = it->option[i].param; // Param1
  2383. count++;
  2384. }else{
  2385. buf[i].index = 0;
  2386. buf[i].value = 0;
  2387. buf[i].param = 0;
  2388. }
  2389. }
  2390. #if MAX_ITEM_RDM_OPT < 5
  2391. for( ; i < 5; i++ ){
  2392. buf[i].index = 0; // OptIndex
  2393. buf[i].value = 0; // Value
  2394. buf[i].param = 0; // Param1
  2395. }
  2396. #endif
  2397. return count;
  2398. }
  2399. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2400. /// 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)
  2401. /// 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)
  2402. /// 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)
  2403. /// 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)
  2404. /// 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)
  2405. /// 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)
  2406. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2407. nullpo_retv( sd );
  2408. int fd = sd->fd;
  2409. if( !session_isActive( fd ) ){
  2410. return;
  2411. }
  2412. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2413. if( fail ){
  2414. p = {};
  2415. }else{
  2416. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2417. return;
  2418. }
  2419. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2420. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2421. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2422. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2423. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2424. p.location = pc_equippoint(sd,n);
  2425. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2426. #if PACKETVER >= 20061218
  2427. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2428. #if PACKETVER >= 20071002
  2429. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2430. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2431. */
  2432. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2433. #if PACKETVER >= 20150226
  2434. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2435. #if PACKETVER >= 20160921
  2436. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2437. p.look = sd->inventory_data[n]->look;
  2438. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2439. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2440. #endif
  2441. #endif
  2442. #endif
  2443. #endif
  2444. #endif
  2445. }
  2446. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2447. p.Index = client_index( n );
  2448. p.count = amount;
  2449. p.result = fail;
  2450. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2451. }
  2452. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2453. /// 00af <index>.W <amount>.W
  2454. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2455. {
  2456. int fd;
  2457. nullpo_retv(sd);
  2458. fd=sd->fd;
  2459. WFIFOHEAD(fd, packet_len(0xaf));
  2460. WFIFOW(fd,0)=0xaf;
  2461. WFIFOW(fd,2)=n+2;
  2462. WFIFOW(fd,4)=amount;
  2463. WFIFOSET(fd,packet_len(0xaf));
  2464. }
  2465. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2466. /// 07fa <delete type>.W <index>.W <amount>.W
  2467. /// delete type:
  2468. /// 0 = Normal
  2469. /// 1 = Item used for a skill
  2470. /// 2 = Refine failed
  2471. /// 3 = Material changed
  2472. /// 4 = Moved to storage
  2473. /// 5 = Moved to cart
  2474. /// 6 = Item sold
  2475. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2476. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2477. {
  2478. #if PACKETVER < 20091117
  2479. clif_dropitem(sd,n,amount);
  2480. #else
  2481. int fd;
  2482. nullpo_retv(sd);
  2483. fd=sd->fd;
  2484. WFIFOHEAD(fd, packet_len(0x7fa));
  2485. WFIFOW(fd,0)=0x7fa;
  2486. WFIFOW(fd,2)=reason;
  2487. WFIFOW(fd,4)=n+2;
  2488. WFIFOW(fd,6)=amount;
  2489. WFIFOSET(fd,packet_len(0x7fa));
  2490. #endif
  2491. }
  2492. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2493. nullpo_retv( p );
  2494. nullpo_retv( it );
  2495. nullpo_retv( id );
  2496. p->index = idx;
  2497. p->ITID = client_nameid( it->nameid );
  2498. p->type = itemtype( it->nameid );
  2499. #if PACKETVER < 20120925
  2500. p->IsIdentified = it->identify ? 1 : 0;
  2501. #endif
  2502. p->location = eqp_pos;
  2503. p->WearState = it->equip;
  2504. #if PACKETVER < 20120925
  2505. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2506. #endif
  2507. p->RefiningLevel = it->refine;
  2508. clif_addcards( &p->slot, it );
  2509. #if PACKETVER >= 20071002
  2510. p->HireExpireDate = it->expire_time;
  2511. #endif
  2512. #if PACKETVER >= 20080102
  2513. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2514. #endif
  2515. #if PACKETVER >= 20100629
  2516. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2517. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2518. #endif
  2519. #if PACKETVER >= 20120925
  2520. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2521. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2522. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2523. p->Flag.SpareBits = 0;
  2524. #endif
  2525. #if PACKETVER >= 20150226
  2526. p->option_count = clif_add_random_options( p->option_data, it );
  2527. #endif
  2528. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2529. p->enchantgrade = it->enchantgrade;
  2530. #endif
  2531. }
  2532. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2533. nullpo_retv(p);
  2534. nullpo_retv(i);
  2535. nullpo_retv(id);
  2536. p->index = idx;
  2537. p->ITID = client_nameid( i->nameid );
  2538. p->type = itemtype( i->nameid );
  2539. #if PACKETVER < 20120925
  2540. p->IsIdentified = i->identify ? 1 : 0;
  2541. #endif
  2542. p->count = i->amount;
  2543. p->WearState = id->equip;
  2544. #if PACKETVER >= 5
  2545. clif_addcards( &p->slot, i );
  2546. #endif
  2547. #if PACKETVER >= 20080102
  2548. p->HireExpireDate = i->expire_time;
  2549. #endif
  2550. #if PACKETVER >= 20120925
  2551. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2552. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2553. p->Flag.SpareBits = 0;
  2554. #endif
  2555. }
  2556. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2557. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2558. nullpo_retv(sd);
  2559. nullpo_retv(name);
  2560. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2561. memset(buf, 0, sizeof(buf));
  2562. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2563. p->packetType = HEADER_ZC_INVENTORY_START;
  2564. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2565. p->invType = type;
  2566. #endif
  2567. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2568. int strLen = (int)safestrnlen(name, 24) + 1;
  2569. if (strLen > 24)
  2570. strLen = 24;
  2571. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2572. p->packetLength = len;
  2573. safestrncpy(p->name, name, strLen);
  2574. #else
  2575. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2576. safestrncpy(p->name, name, NAME_LENGTH);
  2577. #endif
  2578. clif_send( p, len, &sd->bl, SELF );
  2579. #endif
  2580. }
  2581. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2582. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2583. nullpo_retv(sd);
  2584. struct PACKET_ZC_INVENTORY_END p;
  2585. p.packetType = HEADER_ZC_INVENTORY_END;
  2586. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2587. p.invType = type;
  2588. #endif
  2589. p.flag = 0;
  2590. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2591. #endif
  2592. }
  2593. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2594. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2595. void clif_inventorylist( struct map_session_data *sd ){
  2596. nullpo_retv( sd );
  2597. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2598. e_inventory_type type = INVTYPE_INVENTORY;
  2599. clif_inventoryStart( sd, type, "" );
  2600. #endif
  2601. static struct packet_itemlist_normal itemlist_normal;
  2602. static struct packet_itemlist_equip itemlist_equip;
  2603. int equip = 0;
  2604. int normal = 0;
  2605. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2606. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2607. continue;
  2608. }
  2609. // Non-stackable (Equippable)
  2610. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2611. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2612. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2613. itemlist_equip.PacketType = inventorylistequipType;
  2614. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2615. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2616. itemlist_equip.invType = type;
  2617. #endif
  2618. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2619. equip = 0;
  2620. }
  2621. // Stackable (Normal)
  2622. }else{
  2623. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2624. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2625. itemlist_normal.PacketType = inventorylistnormalType;
  2626. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2627. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2628. itemlist_normal.invType = type;
  2629. #endif
  2630. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2631. normal = 0;
  2632. }
  2633. }
  2634. }
  2635. if( normal ){
  2636. itemlist_normal.PacketType = inventorylistnormalType;
  2637. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2638. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2639. itemlist_normal.invType = type;
  2640. #endif
  2641. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2642. }
  2643. if( sd->equip_index[EQI_AMMO] >= 0 )
  2644. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2645. if( equip ) {
  2646. itemlist_equip.PacketType = inventorylistequipType;
  2647. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2648. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2649. itemlist_equip.invType = type;
  2650. #endif
  2651. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2652. }
  2653. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2654. clif_inventoryEnd( sd, type );
  2655. #endif
  2656. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2657. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2658. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2659. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2660. continue;
  2661. if ( sd->inventory.u.items_inventory[i].favorite )
  2662. clif_favorite_item(sd, i);
  2663. }
  2664. #endif
  2665. }
  2666. //Required when items break/get-repaired. Only sends equippable item list.
  2667. void clif_equiplist( struct map_session_data *sd ){
  2668. // TODO: implement again => only send equip part
  2669. clif_inventorylist( sd );
  2670. }
  2671. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2672. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2673. e_inventory_type type = INVTYPE_STORAGE;
  2674. clif_inventoryStart( sd, type, storename );
  2675. #endif
  2676. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2677. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2678. int equip = 0;
  2679. int normal = 0;
  2680. for( int i = 0; i < items_length; i++ ){
  2681. if( items[i].nameid == 0 ){
  2682. continue;
  2683. }
  2684. struct item_data* id = itemdb_search( items[i].nameid );
  2685. // Non-stackable (Equippable)
  2686. if( !itemdb_isstackable2( id ) ){
  2687. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2688. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2689. storage_itemlist_equip.PacketType = storageListEquipType;
  2690. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2691. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2692. storage_itemlist_equip.invType = type;
  2693. #elif PACKETVER >= 20120925
  2694. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2695. #endif
  2696. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2697. equip = 0;
  2698. }
  2699. // Stackable (Normal)
  2700. }else{
  2701. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2702. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2703. storage_itemlist_normal.PacketType = storageListNormalType;
  2704. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2705. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2706. storage_itemlist_normal.invType = type;
  2707. #elif PACKETVER >= 20120925
  2708. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2709. #endif
  2710. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2711. normal = 0;
  2712. }
  2713. }
  2714. }
  2715. if( normal ){
  2716. storage_itemlist_normal.PacketType = storageListNormalType;
  2717. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2718. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2719. storage_itemlist_normal.invType = type;
  2720. #elif PACKETVER >= 20120925
  2721. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2722. #endif
  2723. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2724. }
  2725. if( equip ) {
  2726. storage_itemlist_equip.PacketType = storageListEquipType;
  2727. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2728. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2729. storage_itemlist_equip.invType = type;
  2730. #elif PACKETVER >= 20120925
  2731. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2732. #endif
  2733. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2734. }
  2735. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2736. clif_inventoryEnd( sd, type );
  2737. #endif
  2738. }
  2739. void clif_cartlist( struct map_session_data *sd ){
  2740. nullpo_retv( sd );
  2741. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2742. e_inventory_type type = INVTYPE_CART;
  2743. clif_inventoryStart( sd, type, "" );
  2744. #endif
  2745. static struct packet_itemlist_normal itemlist_normal;
  2746. static struct packet_itemlist_equip itemlist_equip;
  2747. int normal = 0;
  2748. int equip = 0;
  2749. for( int i = 0; i < MAX_CART; i++ ){
  2750. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2751. continue;
  2752. }
  2753. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2754. // Non-stackable (Equippable)
  2755. if( !itemdb_isstackable2(id) ){
  2756. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2757. // Stackable (Normal)
  2758. }else{
  2759. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2760. }
  2761. }
  2762. if( normal ){
  2763. itemlist_normal.PacketType = cartlistnormalType;
  2764. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2765. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2766. itemlist_normal.invType = type;
  2767. #endif
  2768. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2769. }
  2770. if( equip ){
  2771. itemlist_equip.PacketType = cartlistequipType;
  2772. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2773. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2774. itemlist_equip.invType = type;
  2775. #endif
  2776. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2777. }
  2778. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2779. clif_inventoryEnd( sd, type );
  2780. #endif
  2781. }
  2782. /// Removes cart (ZC_CARTOFF).
  2783. /// 012b
  2784. /// Client behaviour:
  2785. /// Closes the cart storage and removes all it's items from memory.
  2786. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2787. void clif_clearcart(int fd)
  2788. {
  2789. WFIFOHEAD(fd, packet_len(0x12b));
  2790. WFIFOW(fd,0) = 0x12b;
  2791. WFIFOSET(fd, packet_len(0x12b));
  2792. }
  2793. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2794. /// 01eb <account id>.L <x>.W <y>.W
  2795. void clif_guild_xy(struct map_session_data *sd)
  2796. {
  2797. unsigned char buf[10];
  2798. nullpo_retv(sd);
  2799. WBUFW(buf,0)=0x1eb;
  2800. WBUFL(buf,2)=sd->status.account_id;
  2801. WBUFW(buf,6)=sd->bl.x;
  2802. WBUFW(buf,8)=sd->bl.y;
  2803. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2804. }
  2805. /*==========================================
  2806. * Sends x/y dot to a single fd. [Skotlex]
  2807. *------------------------------------------*/
  2808. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2809. {
  2810. if( sd->bg_id )
  2811. return;
  2812. WFIFOHEAD(fd,packet_len(0x1eb));
  2813. WFIFOW(fd,0)=0x1eb;
  2814. WFIFOL(fd,2)=sd->status.account_id;
  2815. WFIFOW(fd,6)=sd->bl.x;
  2816. WFIFOW(fd,8)=sd->bl.y;
  2817. WFIFOSET(fd,packet_len(0x1eb));
  2818. }
  2819. // Guild XY locators [Valaris]
  2820. void clif_guild_xy_remove(struct map_session_data *sd)
  2821. {
  2822. unsigned char buf[10];
  2823. nullpo_retv(sd);
  2824. WBUFW(buf,0)=0x1eb;
  2825. WBUFL(buf,2)=sd->status.account_id;
  2826. WBUFW(buf,6)=-1;
  2827. WBUFW(buf,8)=-1;
  2828. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2829. }
  2830. /*==========================================
  2831. *
  2832. *------------------------------------------*/
  2833. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2834. struct map_session_data* sd = va_arg( ap, struct map_session_data* );
  2835. struct map_session_data* tsd = BL_CAST( BL_PC, bl );
  2836. nullpo_ret(sd);
  2837. nullpo_ret(tsd);
  2838. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2839. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2840. }
  2841. return 0;
  2842. }
  2843. /*==========================================
  2844. * Server tells all players that are allowed to view HP bars
  2845. * and are nearby 'sd' that 'sd' hp bar was updated.
  2846. *------------------------------------------*/
  2847. static int clif_hpmeter(struct map_session_data *sd)
  2848. {
  2849. nullpo_ret(sd);
  2850. 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);
  2851. return 0;
  2852. }
  2853. /**
  2854. * Send HP bar update to others.
  2855. * @param sd: Player invoking update
  2856. */
  2857. void clif_update_hp(map_session_data &sd) {
  2858. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2859. clif_hpmeter(&sd);
  2860. if (!battle_config.party_hp_mode && sd.status.party_id)
  2861. clif_party_hp( sd );
  2862. if (sd.bg_id)
  2863. clif_bg_hp(&sd);
  2864. }
  2865. /// Notifies client of a character parameter change.
  2866. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2867. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2868. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2869. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2870. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2871. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2872. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2873. /// TODO: Extract individual packets.
  2874. /// FIXME: Packet lengths from packet_len(cmd)
  2875. void clif_updatestatus(struct map_session_data *sd,int type)
  2876. {
  2877. int fd,len=8;
  2878. nullpo_retv(sd);
  2879. fd=sd->fd;
  2880. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2881. return;
  2882. WFIFOHEAD(fd, 14);
  2883. WFIFOW(fd,0)=0xb0;
  2884. WFIFOW(fd,2)=type;
  2885. switch(type){
  2886. // 00b0
  2887. case SP_WEIGHT:
  2888. pc_updateweightstatus(sd);
  2889. WFIFOHEAD(fd,14);
  2890. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2891. WFIFOW(fd,2)=type;
  2892. WFIFOL(fd,4)=sd->weight;
  2893. break;
  2894. case SP_MAXWEIGHT:
  2895. WFIFOL(fd,4)=sd->max_weight;
  2896. break;
  2897. case SP_SPEED:
  2898. WFIFOL(fd,4)=sd->battle_status.speed;
  2899. break;
  2900. case SP_BASELEVEL:
  2901. WFIFOL(fd,4)=sd->status.base_level;
  2902. break;
  2903. case SP_JOBLEVEL:
  2904. WFIFOL(fd,4)=sd->status.job_level;
  2905. break;
  2906. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2907. WFIFOL(fd,4)=sd->status.karma;
  2908. break;
  2909. case SP_MANNER:
  2910. WFIFOL(fd,4)=sd->status.manner;
  2911. break;
  2912. case SP_STATUSPOINT:
  2913. WFIFOL(fd,4)=sd->status.status_point;
  2914. break;
  2915. case SP_SKILLPOINT:
  2916. WFIFOL(fd,4)=sd->status.skill_point;
  2917. break;
  2918. case SP_HIT:
  2919. WFIFOL(fd,4)=sd->battle_status.hit;
  2920. break;
  2921. case SP_FLEE1:
  2922. WFIFOL(fd,4)=sd->battle_status.flee;
  2923. break;
  2924. case SP_FLEE2:
  2925. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2926. break;
  2927. case SP_MAXHP:
  2928. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2929. break;
  2930. case SP_MAXSP:
  2931. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2932. break;
  2933. case SP_HP:
  2934. // On officials the HP never go below 1, even if you die [Lemongrass]
  2935. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2936. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2937. break;
  2938. case SP_SP:
  2939. WFIFOL(fd,4)=sd->battle_status.sp;
  2940. break;
  2941. case SP_ASPD:
  2942. WFIFOL(fd,4)=sd->battle_status.amotion;
  2943. break;
  2944. case SP_ATK1:
  2945. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2946. break;
  2947. case SP_DEF1:
  2948. WFIFOL(fd,4)=pc_leftside_def(sd);
  2949. break;
  2950. case SP_MDEF1:
  2951. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2952. break;
  2953. case SP_ATK2:
  2954. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2955. break;
  2956. case SP_DEF2:
  2957. WFIFOL(fd,4)=pc_rightside_def(sd);
  2958. break;
  2959. case SP_MDEF2: {
  2960. //negative check (in case you have something like Berserk active)
  2961. int mdef2 = pc_rightside_mdef(sd);
  2962. WFIFOL(fd,4)=
  2963. #ifndef RENEWAL
  2964. ( mdef2 < 0 ) ? 0 :
  2965. #endif
  2966. mdef2;
  2967. }
  2968. break;
  2969. case SP_CRITICAL:
  2970. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2971. break;
  2972. case SP_MATK1:
  2973. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2974. break;
  2975. case SP_MATK2:
  2976. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2977. break;
  2978. case SP_ZENY:
  2979. WFIFOW(fd,0)=0xb1;
  2980. WFIFOL(fd,4)=sd->status.zeny;
  2981. break;
  2982. #if PACKETVER >= 20170830
  2983. case SP_BASEEXP:
  2984. WFIFOW(fd,0)=0xacb;
  2985. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2986. len = packet_len(0xacb);
  2987. break;
  2988. case SP_JOBEXP:
  2989. WFIFOW(fd,0)=0xacb;
  2990. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2991. len = packet_len(0xacb);
  2992. break;
  2993. case SP_NEXTBASEEXP:
  2994. WFIFOW(fd,0)=0xacb;
  2995. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  2996. len = packet_len(0xacb);
  2997. break;
  2998. case SP_NEXTJOBEXP:
  2999. WFIFOW(fd,0)=0xacb;
  3000. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3001. len = packet_len(0xacb);
  3002. break;
  3003. #else
  3004. case SP_BASEEXP:
  3005. WFIFOW(fd,0)=0xb1;
  3006. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3007. break;
  3008. case SP_JOBEXP:
  3009. WFIFOW(fd,0)=0xb1;
  3010. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3011. break;
  3012. case SP_NEXTBASEEXP:
  3013. WFIFOW(fd,0)=0xb1;
  3014. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3015. break;
  3016. case SP_NEXTJOBEXP:
  3017. WFIFOW(fd,0)=0xb1;
  3018. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3019. break;
  3020. #endif
  3021. /**
  3022. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3023. **/
  3024. case SP_USTR:
  3025. case SP_UAGI:
  3026. case SP_UVIT:
  3027. case SP_UINT:
  3028. case SP_UDEX:
  3029. case SP_ULUK:
  3030. WFIFOW(fd,0)=0xbe;
  3031. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3032. len=5;
  3033. break;
  3034. /**
  3035. * Tells the client how far it is allowed to attack (weapon range)
  3036. **/
  3037. case SP_ATTACKRANGE:
  3038. WFIFOW(fd,0)=0x13a;
  3039. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3040. len=4;
  3041. break;
  3042. case SP_STR:
  3043. WFIFOW(fd,0)=0x141;
  3044. WFIFOL(fd,2)=type;
  3045. WFIFOL(fd,6)=sd->status.str;
  3046. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3047. len=14;
  3048. break;
  3049. case SP_AGI:
  3050. WFIFOW(fd,0)=0x141;
  3051. WFIFOL(fd,2)=type;
  3052. WFIFOL(fd,6)=sd->status.agi;
  3053. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3054. len=14;
  3055. break;
  3056. case SP_VIT:
  3057. WFIFOW(fd,0)=0x141;
  3058. WFIFOL(fd,2)=type;
  3059. WFIFOL(fd,6)=sd->status.vit;
  3060. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3061. len=14;
  3062. break;
  3063. case SP_INT:
  3064. WFIFOW(fd,0)=0x141;
  3065. WFIFOL(fd,2)=type;
  3066. WFIFOL(fd,6)=sd->status.int_;
  3067. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3068. len=14;
  3069. break;
  3070. case SP_DEX:
  3071. WFIFOW(fd,0)=0x141;
  3072. WFIFOL(fd,2)=type;
  3073. WFIFOL(fd,6)=sd->status.dex;
  3074. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3075. len=14;
  3076. break;
  3077. case SP_LUK:
  3078. WFIFOW(fd,0)=0x141;
  3079. WFIFOL(fd,2)=type;
  3080. WFIFOL(fd,6)=sd->status.luk;
  3081. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3082. len=14;
  3083. break;
  3084. case SP_CARTINFO:
  3085. WFIFOW(fd,0)=0x121;
  3086. WFIFOW(fd,2)=sd->cart_num;
  3087. WFIFOW(fd,4)=MAX_CART;
  3088. WFIFOL(fd,6)=sd->cart_weight;
  3089. WFIFOL(fd,10)=sd->cart_weight_max;
  3090. len=14;
  3091. break;
  3092. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3093. case SP_AP:
  3094. WFIFOL(fd, 4) = sd->battle_status.ap;
  3095. break;
  3096. case SP_TRAITPOINT:
  3097. WFIFOL(fd, 4) = sd->status.trait_point;
  3098. break;
  3099. case SP_MAXAP:
  3100. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3101. break;
  3102. case SP_POW:
  3103. WFIFOW(fd, 0) = 0x141;
  3104. WFIFOL(fd, 2) = type;
  3105. WFIFOL(fd, 6) = sd->status.pow;
  3106. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3107. len = 14;
  3108. break;
  3109. case SP_STA:
  3110. WFIFOW(fd, 0) = 0x141;
  3111. WFIFOL(fd, 2) = type;
  3112. WFIFOL(fd, 6) = sd->status.sta;
  3113. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3114. len = 14;
  3115. break;
  3116. case SP_WIS:
  3117. WFIFOW(fd, 0) = 0x141;
  3118. WFIFOL(fd, 2) = type;
  3119. WFIFOL(fd, 6) = sd->status.wis;
  3120. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3121. len = 14;
  3122. break;
  3123. case SP_SPL:
  3124. WFIFOW(fd, 0) = 0x141;
  3125. WFIFOL(fd, 2) = type;
  3126. WFIFOL(fd, 6) = sd->status.spl;
  3127. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3128. len = 14;
  3129. break;
  3130. case SP_CON:
  3131. WFIFOW(fd, 0) = 0x141;
  3132. WFIFOL(fd, 2) = type;
  3133. WFIFOL(fd, 6) = sd->status.con;
  3134. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3135. len = 14;
  3136. break;
  3137. case SP_CRT:
  3138. WFIFOW(fd, 0) = 0x141;
  3139. WFIFOL(fd, 2) = type;
  3140. WFIFOL(fd, 6) = sd->status.crt;
  3141. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3142. len = 14;
  3143. break;
  3144. case SP_UPOW:
  3145. case SP_USTA:
  3146. case SP_UWIS:
  3147. case SP_USPL:
  3148. case SP_UCON:
  3149. case SP_UCRT:
  3150. WFIFOW(fd, 0) = 0xbe;
  3151. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3152. len = 5;
  3153. break;
  3154. case SP_PATK:
  3155. WFIFOL(fd, 4) = sd->battle_status.patk;
  3156. break;
  3157. case SP_SMATK:
  3158. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3159. break;
  3160. case SP_RES:
  3161. WFIFOL(fd, 4) = sd->battle_status.res;
  3162. break;
  3163. case SP_MRES:
  3164. WFIFOL(fd, 4) = sd->battle_status.mres;
  3165. break;
  3166. case SP_HPLUS:
  3167. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3168. break;
  3169. case SP_CRATE:
  3170. WFIFOL(fd, 4) = sd->battle_status.crate;
  3171. break;
  3172. #else
  3173. case SP_AP:
  3174. case SP_TRAITPOINT:
  3175. case SP_MAXAP:
  3176. case SP_POW:
  3177. case SP_STA:
  3178. case SP_WIS:
  3179. case SP_SPL:
  3180. case SP_CON:
  3181. case SP_CRT:
  3182. case SP_UPOW:
  3183. case SP_USTA:
  3184. case SP_UWIS:
  3185. case SP_USPL:
  3186. case SP_UCON:
  3187. case SP_UCRT:
  3188. case SP_PATK:
  3189. case SP_SMATK:
  3190. case SP_RES:
  3191. case SP_MRES:
  3192. case SP_HPLUS:
  3193. case SP_CRATE:
  3194. // 4th job status are not supported by older clients
  3195. return;
  3196. #endif
  3197. default:
  3198. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3199. return;
  3200. }
  3201. WFIFOSET(fd,len);
  3202. // Additional update packets that should be sent right after
  3203. switch( type ){
  3204. case SP_BASELEVEL:
  3205. if( sd->status.party_id ){
  3206. struct party_data* p;
  3207. int i;
  3208. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3209. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3210. if( i < MAX_PARTY ){
  3211. p->party.member[i].lv = sd->status.base_level;
  3212. clif_party_job_and_level( *sd );
  3213. }
  3214. }
  3215. }
  3216. break;
  3217. case SP_HP:
  3218. clif_update_hp(*sd);
  3219. break;
  3220. }
  3221. }
  3222. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3223. /// 01ab <account id>.L <var id>.W <value>.L
  3224. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3225. {
  3226. unsigned char buf[12];
  3227. nullpo_retv(sd);
  3228. WBUFW(buf,0)=0x1ab;
  3229. WBUFL(buf,2)=sd->bl.id;
  3230. WBUFW(buf,6)=type;
  3231. switch(type)
  3232. {
  3233. case SP_MANNER:
  3234. WBUFL(buf,8)=val;
  3235. break;
  3236. default:
  3237. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3238. return;
  3239. }
  3240. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3241. }
  3242. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3243. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3244. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3245. struct PACKET_ZC_SPRITE_CHANGE p;
  3246. p.packetType = sendLookType;
  3247. p.AID = id;
  3248. p.type = type;
  3249. p.val = val;
  3250. #if PACKETVER >= 4
  3251. p.val2 = val2;
  3252. #endif
  3253. clif_send( &p, sizeof( p ), bl, target );
  3254. }
  3255. /// Updates sprite/style properties of an object.
  3256. void clif_changelook(struct block_list *bl, int type, int val) {
  3257. struct map_session_data* sd;
  3258. struct status_change* sc;
  3259. struct view_data* vd;
  3260. enum send_target target = AREA;
  3261. int val2 = 0;
  3262. nullpo_retv(bl);
  3263. sd = BL_CAST(BL_PC, bl);
  3264. sc = status_get_sc(bl);
  3265. vd = status_get_viewdata(bl);
  3266. if( vd ) //temp hack to let Warp Portal change appearance
  3267. switch(type) {
  3268. case LOOK_WEAPON:
  3269. if (sd) {
  3270. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3271. val = vd->weapon;
  3272. }
  3273. else
  3274. vd->weapon = val;
  3275. break;
  3276. case LOOK_SHIELD:
  3277. if (sd) {
  3278. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3279. val = vd->shield;
  3280. }
  3281. else
  3282. vd->shield = val;
  3283. break;
  3284. case LOOK_BASE:
  3285. if (!sd)
  3286. break;
  3287. if ( val == JT_INVISIBLE )
  3288. return;
  3289. if (sd->sc.option&OPTION_COSTUME)
  3290. vd->weapon = vd->shield = 0;
  3291. if (!vd->cloth_color)
  3292. break;
  3293. if (sd) {
  3294. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3295. vd->cloth_color = 0;
  3296. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3297. vd->cloth_color = 0;
  3298. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3299. vd->cloth_color = 0;
  3300. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3301. vd->cloth_color = 0;
  3302. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3303. vd->cloth_color = 0;
  3304. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3305. vd->body_style = 0;
  3306. }
  3307. break;
  3308. case LOOK_HAIR:
  3309. vd->hair_style = val;
  3310. break;
  3311. case LOOK_HEAD_BOTTOM:
  3312. vd->head_bottom = val;
  3313. break;
  3314. case LOOK_HEAD_TOP:
  3315. vd->head_top = val;
  3316. break;
  3317. case LOOK_HEAD_MID:
  3318. vd->head_mid = val;
  3319. break;
  3320. case LOOK_HAIR_COLOR:
  3321. vd->hair_color = val;
  3322. break;
  3323. case LOOK_CLOTHES_COLOR:
  3324. if (val && sd) {
  3325. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3326. val = 0;
  3327. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3328. val = 0;
  3329. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3330. val = 0;
  3331. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3332. val = 0;
  3333. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3334. val = 0;
  3335. }
  3336. vd->cloth_color = val;
  3337. break;
  3338. case LOOK_SHOES:
  3339. #if PACKETVER > 3
  3340. if (sd) {
  3341. int n;
  3342. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3343. if(sd->inventory_data[n]->view_id > 0)
  3344. val = sd->inventory_data[n]->view_id;
  3345. else
  3346. val = sd->inventory.u.items_inventory[n].nameid;
  3347. } else
  3348. val = 0;
  3349. }
  3350. #endif
  3351. //Shoes? No packet uses this....
  3352. break;
  3353. case LOOK_BODY:
  3354. // unknown purpose
  3355. break;
  3356. case LOOK_ROBE:
  3357. #if PACKETVER < 20110111
  3358. return;
  3359. #else
  3360. vd->robe = val;
  3361. #endif
  3362. break;
  3363. case LOOK_BODY2:
  3364. #if PACKETVER < 20150513
  3365. return;
  3366. #else
  3367. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3368. val = 0;
  3369. vd->body_style = val;
  3370. #endif
  3371. break;
  3372. }
  3373. // prevent leaking the presence of GM-hidden objects
  3374. if( sc && sc->option&OPTION_INVISIBLE )
  3375. target = SELF;
  3376. #if PACKETVER < 4
  3377. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3378. #else
  3379. if (bl->type != BL_NPC) {
  3380. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3381. type = LOOK_WEAPON;
  3382. val = (vd ? vd->weapon : 0);
  3383. val2 = (vd ? vd->shield : 0);
  3384. }
  3385. if (disguised(bl)) {
  3386. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3387. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3388. } else
  3389. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3390. } else
  3391. unit_refresh(bl);
  3392. #endif
  3393. }
  3394. //Sends a change-base-look packet required for traps as they are triggered.
  3395. void clif_changetraplook(struct block_list *bl,int val) {
  3396. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3397. }
  3398. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3399. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3400. clif_sprite_change(bl, id, type, val, 0, target);
  3401. }
  3402. /// Character status (ZC_STATUS).
  3403. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3404. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3405. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3406. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3407. void clif_initialstatus(struct map_session_data *sd) {
  3408. int fd, mdef2;
  3409. unsigned char *buf;
  3410. nullpo_retv(sd);
  3411. fd=sd->fd;
  3412. WFIFOHEAD(fd, packet_len(0xbd));
  3413. buf = WFIFOP(fd,0);
  3414. WBUFW(buf,0) = 0xbd;
  3415. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3416. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3417. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3418. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3419. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3420. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3421. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3422. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3423. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3424. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3425. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3426. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3427. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3428. WBUFW(buf,16) = pc_leftside_atk(sd);
  3429. WBUFW(buf,18) = pc_rightside_atk(sd);
  3430. WBUFW(buf,20) = pc_rightside_matk(sd);
  3431. WBUFW(buf,22) = pc_leftside_matk(sd);
  3432. WBUFW(buf,24) = pc_leftside_def(sd);
  3433. WBUFW(buf,26) = pc_rightside_def(sd);
  3434. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3435. mdef2 = pc_rightside_mdef(sd);
  3436. WBUFW(buf,30) =
  3437. #ifndef RENEWAL
  3438. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3439. #endif
  3440. mdef2;
  3441. WBUFW(buf,32) = sd->battle_status.hit;
  3442. WBUFW(buf,34) = sd->battle_status.flee;
  3443. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3444. WBUFW(buf,38) = sd->battle_status.cri/10;
  3445. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3446. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3447. WFIFOSET(fd, packet_len(0xbd));
  3448. clif_updatestatus(sd, SP_STR);
  3449. clif_updatestatus(sd, SP_AGI);
  3450. clif_updatestatus(sd, SP_VIT);
  3451. clif_updatestatus(sd, SP_INT);
  3452. clif_updatestatus(sd, SP_DEX);
  3453. clif_updatestatus(sd, SP_LUK);
  3454. clif_updatestatus(sd, SP_ATTACKRANGE);
  3455. clif_updatestatus(sd, SP_ASPD);
  3456. #ifdef RENEWAL
  3457. clif_updatestatus(sd, SP_POW);
  3458. clif_updatestatus(sd, SP_STA);
  3459. clif_updatestatus(sd, SP_WIS);
  3460. clif_updatestatus(sd, SP_SPL);
  3461. clif_updatestatus(sd, SP_CON);
  3462. clif_updatestatus(sd, SP_CRT);
  3463. clif_updatestatus(sd, SP_PATK);
  3464. clif_updatestatus(sd, SP_SMATK);
  3465. clif_updatestatus(sd, SP_RES);
  3466. clif_updatestatus(sd, SP_MRES);
  3467. clif_updatestatus(sd, SP_HPLUS);
  3468. clif_updatestatus(sd, SP_CRATE);
  3469. clif_updatestatus(sd, SP_TRAITPOINT);
  3470. clif_updatestatus(sd, SP_AP);
  3471. clif_updatestatus(sd, SP_MAXAP);
  3472. clif_updatestatus(sd, SP_UPOW);
  3473. clif_updatestatus(sd, SP_USTA);
  3474. clif_updatestatus(sd, SP_UWIS);
  3475. clif_updatestatus(sd, SP_USPL);
  3476. clif_updatestatus(sd, SP_UCON);
  3477. clif_updatestatus(sd, SP_UCRT);
  3478. #endif
  3479. }
  3480. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3481. /// 013c <index>.W
  3482. void clif_arrowequip(struct map_session_data *sd,int val) {
  3483. int fd;
  3484. nullpo_retv(sd);
  3485. #if PACKETVER >= 20121128
  3486. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3487. #endif
  3488. fd=sd->fd;
  3489. WFIFOHEAD(fd, packet_len(0x013c));
  3490. WFIFOW(fd,0) = 0x013c;
  3491. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3492. WFIFOSET(fd, packet_len(0x013c));
  3493. }
  3494. /// Ammunition action message (ZC_ACTION_FAILURE).
  3495. /// 013b <type>.W
  3496. /// type:
  3497. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3498. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3499. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3500. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3501. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3502. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3503. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3504. int fd;
  3505. nullpo_retv(sd);
  3506. fd=sd->fd;
  3507. WFIFOHEAD(fd, packet_len(0x013b));
  3508. WFIFOW(fd,0) = 0x013b;
  3509. WFIFOW(fd,2) = type;
  3510. WFIFOSET(fd, packet_len(0x013b));
  3511. }
  3512. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3513. /// 01ad <packet len>.W { <name id>.W }*
  3514. void clif_arrow_create_list( struct map_session_data *sd ){
  3515. nullpo_retv( sd );
  3516. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3517. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3518. int count = 0;
  3519. for (const auto &it : skill_arrow_db) {
  3520. t_itemid nameid = it.second->nameid;
  3521. if( !item_db.exists( nameid ) ){
  3522. continue;
  3523. }
  3524. int index = pc_search_inventory( sd, nameid );
  3525. if( index < 0 ){
  3526. continue;
  3527. }
  3528. if( sd->inventory.u.items_inventory[index].equip ){
  3529. continue;
  3530. }
  3531. if( !sd->inventory.u.items_inventory[index].identify ){
  3532. continue;
  3533. }
  3534. p->items[count].itemId = client_nameid( nameid );
  3535. count++;
  3536. }
  3537. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3538. clif_send( p, p->packetLength, &sd->bl, SELF );
  3539. if( count > 0 ){
  3540. sd->menuskill_id = AC_MAKINGARROW;
  3541. sd->menuskill_val = count;
  3542. }
  3543. }
  3544. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3545. /// 00bc <status id>.W <result>.B <value>.B
  3546. /// status id:
  3547. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3548. /// result:
  3549. /// 0 = failure
  3550. /// 1 = success
  3551. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3552. int fd;
  3553. nullpo_retv(sd);
  3554. fd=sd->fd;
  3555. WFIFOHEAD(fd, packet_len(0xbc));
  3556. WFIFOW(fd,0) = 0xbc;
  3557. WFIFOW(fd,2) = type;
  3558. WFIFOB(fd,4) = ok;
  3559. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3560. WFIFOSET(fd, packet_len(0xbc));
  3561. }
  3562. /// Notifies the client about the result of a request to equip an item.
  3563. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3564. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3565. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3566. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3567. /// @ok: //inversed forv2 v5
  3568. /// 0 = failure
  3569. /// 1 = success
  3570. /// 2 = failure due to low level
  3571. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3572. {
  3573. int fd = 0, cmd = 0, look = 0;
  3574. struct s_packet_db *info = NULL;
  3575. nullpo_retv(sd);
  3576. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3577. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3578. return;
  3579. fd = sd->fd;
  3580. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3581. look = sd->inventory_data[n]->look;
  3582. WFIFOHEAD(fd, info->len);
  3583. WFIFOW(fd, 0) = cmd;
  3584. WFIFOW(fd, info->pos[0]) = n+2;
  3585. switch (cmd) {
  3586. case 0xaa:
  3587. WFIFOW(fd, info->pos[1]) = pos;
  3588. #if PACKETVER < 20100629
  3589. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3590. #else
  3591. WFIFOL(fd, info->pos[2]) = look;
  3592. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3593. #endif
  3594. break;
  3595. case 0x8d0:
  3596. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3597. flag = 1;
  3598. case 0x999:
  3599. if (cmd == 0x999)
  3600. WFIFOL(fd, info->pos[1]) = pos;
  3601. else
  3602. WFIFOW(fd, info->pos[1]) = pos;
  3603. WFIFOL(fd, info->pos[2]) = look;
  3604. WFIFOW(fd, info->pos[3]) = flag;
  3605. break;
  3606. }
  3607. WFIFOSET(fd, info->len);
  3608. }
  3609. /// Notifies the client about the result of a request to take off an item.
  3610. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3611. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3612. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3613. /// @ok : //inversed for v2 v5
  3614. /// 0 = failure
  3615. /// 1 = success
  3616. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3617. {
  3618. int fd, header, offs = 0;
  3619. #if PACKETVER >= 20130000
  3620. header = 0x99a;
  3621. ok = ok ? 0 : 1;
  3622. #elif PACKETVER >= 20110824
  3623. header = 0x8d1;
  3624. ok = ok ? 0 : 1;
  3625. #else
  3626. header = 0xac;
  3627. #endif
  3628. nullpo_retv(sd);
  3629. fd=sd->fd;
  3630. WFIFOHEAD(fd, packet_len(header));
  3631. WFIFOW(fd,offs+0) = header;
  3632. WFIFOW(fd,offs+2) = n+2;
  3633. #if PACKETVER >= 20130000
  3634. WFIFOL(fd,offs+4) = pos;
  3635. offs += 2;
  3636. #else
  3637. WFIFOW(fd,offs+4) = pos;
  3638. #endif
  3639. WFIFOB(fd,offs+6) = ok;
  3640. WFIFOSET(fd, packet_len(header));
  3641. }
  3642. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3643. /// 019b <id>.L <effect id>.L
  3644. /// effect id:
  3645. /// 0 = base level up
  3646. /// 1 = job level up
  3647. /// 2 = refine failure
  3648. /// 3 = refine success
  3649. /// 4 = game over
  3650. /// 5 = pharmacy success
  3651. /// 6 = pharmacy failure
  3652. /// 7 = base level up (super novice)
  3653. /// 8 = job level up (super novice)
  3654. /// 9 = base level up (taekwon)
  3655. void clif_misceffect(struct block_list* bl,int type)
  3656. {
  3657. unsigned char buf[32];
  3658. nullpo_retv(bl);
  3659. WBUFW(buf,0) = 0x19b;
  3660. WBUFL(buf,2) = bl->id;
  3661. WBUFL(buf,6) = type;
  3662. clif_send(buf,packet_len(0x19b),bl,AREA);
  3663. }
  3664. /// Notifies clients in the area of a state change.
  3665. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3666. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3667. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3668. nullpo_retv( bl );
  3669. struct status_change* sc = status_get_sc( bl );
  3670. //How can an option change if there's no sc?
  3671. if( sc == nullptr ){
  3672. return;
  3673. }
  3674. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3675. struct PACKET_ZC_STATE_CHANGE p;
  3676. p.packetType = HEADER_ZC_STATE_CHANGE;
  3677. p.AID = bl->id;
  3678. p.bodyState = sc->opt1;
  3679. p.healthState = sc->opt2;
  3680. p.effectState = sc->option;
  3681. p.isPKModeON = sd ? sd->status.karma : false;
  3682. if( target == nullptr ){
  3683. if( disguised( bl ) ){
  3684. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3685. p.AID = disguised_bl_id( p.AID );
  3686. clif_send( &p, sizeof( p ), bl, SELF );
  3687. p.AID = disguised_bl_id( p.AID );
  3688. p.effectState = OPTION_INVISIBLE;
  3689. clif_send( &p, sizeof( p ), bl, SELF );
  3690. }else{
  3691. clif_send( &p, sizeof( p ), bl, AREA );
  3692. }
  3693. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3694. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3695. if( sc->data[SC_PROVOKE] ){
  3696. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3697. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3698. }
  3699. }else{
  3700. if( disguised( bl ) ){
  3701. p.AID = disguised_bl_id( p.AID );
  3702. clif_send( &p, sizeof( p ), target, SELF );
  3703. p.AID = disguised_bl_id( p.AID );
  3704. p.effectState = OPTION_INVISIBLE;
  3705. clif_send( &p, sizeof( p ), target, SELF );
  3706. }else{
  3707. clif_send( &p, sizeof( p ), target, SELF );
  3708. }
  3709. }
  3710. }
  3711. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3712. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3713. void clif_changeoption2(struct block_list* bl)
  3714. {
  3715. unsigned char buf[20];
  3716. struct status_change *sc;
  3717. sc = status_get_sc(bl);
  3718. if (!sc) return; //How can an option change if there's no sc?
  3719. WBUFW(buf,0) = 0x28a;
  3720. WBUFL(buf,2) = bl->id;
  3721. WBUFL(buf,6) = sc->option;
  3722. WBUFL(buf,10) = clif_setlevel(bl);
  3723. WBUFL(buf,14) = sc->opt3;
  3724. if(disguised(bl)) {
  3725. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3726. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3727. clif_send(buf,packet_len(0x28a),bl,SELF);
  3728. WBUFL(buf,2) = bl->id;
  3729. WBUFL(buf,6) = OPTION_INVISIBLE;
  3730. clif_send(buf,packet_len(0x28a),bl,SELF);
  3731. } else
  3732. clif_send(buf,packet_len(0x28a),bl,AREA);
  3733. }
  3734. /// Notifies the client about the result of an item use request.
  3735. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3736. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3737. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3738. nullpo_retv( sd );
  3739. int fd = sd->fd;
  3740. if( !session_isActive( fd ) ){
  3741. return;
  3742. }
  3743. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3744. return;
  3745. }
  3746. struct PACKET_ZC_USE_ITEM_ACK p;
  3747. p.packetType = useItemAckType;
  3748. p.index = index + 2;
  3749. #if PACKETVER > 3
  3750. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3751. p.AID = sd->bl.id;
  3752. #endif
  3753. p.amount = amount;
  3754. p.result = ok;
  3755. if( !ok ){
  3756. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3757. }else{
  3758. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3759. }
  3760. }
  3761. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3762. /// 00d6 <flag>.B
  3763. /// flag:
  3764. /// 0 = Room has been successfully created (opens chat room)
  3765. /// 1 = Room limit exceeded
  3766. /// 2 = Same room already exists
  3767. void clif_createchat(struct map_session_data* sd, int flag)
  3768. {
  3769. int fd;
  3770. nullpo_retv(sd);
  3771. fd = sd->fd;
  3772. WFIFOHEAD(fd,packet_len(0xd6));
  3773. WFIFOW(fd,0) = 0xd6;
  3774. WFIFOB(fd,2) = flag;
  3775. WFIFOSET(fd,packet_len(0xd6));
  3776. }
  3777. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3778. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3779. /// type:
  3780. /// 0 = private (password protected)
  3781. /// 1 = public
  3782. /// 2 = arena (npc waiting room)
  3783. /// 3 = PK zone (non-clickable)
  3784. void clif_dispchat(struct chat_data* cd, int fd)
  3785. {
  3786. unsigned char buf[128];
  3787. uint8 type;
  3788. if( cd == NULL || cd->owner == NULL )
  3789. return;
  3790. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3791. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3792. : 1;
  3793. WBUFW(buf, 0) = 0xd7;
  3794. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3795. WBUFL(buf, 4) = cd->owner->id;
  3796. WBUFL(buf, 8) = cd->bl.id;
  3797. WBUFW(buf,12) = cd->limit;
  3798. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3799. WBUFB(buf,16) = type;
  3800. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3801. if( session_isActive(fd) ) {
  3802. WFIFOHEAD(fd,WBUFW(buf,2));
  3803. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3804. WFIFOSET(fd,WBUFW(buf,2));
  3805. } else {
  3806. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3807. }
  3808. }
  3809. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3810. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3811. /// type:
  3812. /// 0 = private (password protected)
  3813. /// 1 = public
  3814. /// 2 = arena (npc waiting room)
  3815. /// 3 = PK zone (non-clickable)
  3816. void clif_changechatstatus(struct chat_data* cd)
  3817. {
  3818. unsigned char buf[128];
  3819. uint8 type;
  3820. if( cd == NULL || cd->usersd[0] == NULL )
  3821. return;
  3822. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3823. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3824. : 1;
  3825. WBUFW(buf, 0) = 0xdf;
  3826. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3827. WBUFL(buf, 4) = cd->owner->id;
  3828. WBUFL(buf, 8) = cd->bl.id;
  3829. WBUFW(buf,12) = cd->limit;
  3830. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3831. WBUFB(buf,16) = type;
  3832. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3833. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3834. }
  3835. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3836. /// 00d8 <chat id>.L
  3837. void clif_clearchat(struct chat_data *cd,int fd)
  3838. {
  3839. unsigned char buf[32];
  3840. nullpo_retv(cd);
  3841. WBUFW(buf,0) = 0xd8;
  3842. WBUFL(buf,2) = cd->bl.id;
  3843. if( session_isActive(fd) ) {
  3844. WFIFOHEAD(fd,packet_len(0xd8));
  3845. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3846. WFIFOSET(fd,packet_len(0xd8));
  3847. } else {
  3848. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3849. }
  3850. }
  3851. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3852. /// 00da <result>.B
  3853. /// result:
  3854. /// 0 = room full
  3855. /// 1 = wrong password
  3856. /// 2 = kicked
  3857. /// 3 = success (no message)
  3858. /// 4 = no enough zeny
  3859. /// 5 = too low level
  3860. /// 6 = too high level
  3861. /// 7 = unsuitable job class
  3862. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3863. {
  3864. int fd;
  3865. nullpo_retv(sd);
  3866. fd = sd->fd;
  3867. WFIFOHEAD(fd,packet_len(0xda));
  3868. WFIFOW(fd,0) = 0xda;
  3869. WFIFOB(fd,2) = flag;
  3870. WFIFOSET(fd,packet_len(0xda));
  3871. }
  3872. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3873. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3874. /// role:
  3875. /// 0 = owner (menu)
  3876. /// 1 = normal
  3877. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3878. {
  3879. int fd;
  3880. int i,t;
  3881. nullpo_retv(sd);
  3882. nullpo_retv(cd);
  3883. fd = sd->fd;
  3884. if (!session_isActive(fd))
  3885. return;
  3886. t = (int)(cd->owner->type == BL_NPC);
  3887. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3888. WFIFOW(fd, 0) = 0xdb;
  3889. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3890. WFIFOL(fd, 4) = cd->bl.id;
  3891. if(cd->owner->type == BL_NPC){
  3892. WFIFOL(fd, 30) = 1;
  3893. WFIFOL(fd, 8) = 0;
  3894. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3895. for (i = 0; i < cd->users; i++) {
  3896. WFIFOL(fd, 8+(i+1)*28) = 1;
  3897. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3898. }
  3899. }else{
  3900. for (i = 0; i < cd->users; i++) {
  3901. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3902. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3903. }
  3904. }
  3905. WFIFOSET(fd, WFIFOW(fd, 2));
  3906. }
  3907. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3908. /// 00dc <users>.W <name>.24B
  3909. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3910. {
  3911. unsigned char buf[29];
  3912. nullpo_retv(sd);
  3913. nullpo_retv(cd);
  3914. WBUFW(buf, 0) = 0xdc;
  3915. WBUFW(buf, 2) = cd->users;
  3916. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3917. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3918. }
  3919. /// Announce the new owner (ZC_ROLE_CHANGE).
  3920. /// 00e1 <role>.L <nick>.24B
  3921. /// role:
  3922. /// 0 = owner (menu)
  3923. /// 1 = normal
  3924. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3925. {
  3926. unsigned char buf[64];
  3927. nullpo_retv(sd);
  3928. nullpo_retv(cd);
  3929. WBUFW(buf, 0) = 0xe1;
  3930. WBUFL(buf, 2) = 1;
  3931. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3932. WBUFW(buf,30) = 0xe1;
  3933. WBUFL(buf,32) = 0;
  3934. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3935. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3936. }
  3937. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3938. /// 00dd <users>.W <nick>.24B <flag>.B
  3939. /// flag:
  3940. /// 0 = left
  3941. /// 1 = kicked
  3942. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3943. {
  3944. unsigned char buf[32];
  3945. nullpo_retv(sd);
  3946. nullpo_retv(cd);
  3947. WBUFW(buf, 0) = 0xdd;
  3948. WBUFW(buf, 2) = cd->users-1;
  3949. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3950. WBUFB(buf,28) = flag;
  3951. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3952. }
  3953. /// Opens a trade request window from char 'name'.
  3954. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3955. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3956. void clif_traderequest(struct map_session_data* sd, const char* name)
  3957. {
  3958. int fd = sd->fd;
  3959. #if PACKETVER < 6
  3960. WFIFOHEAD(fd,packet_len(0xe5));
  3961. WFIFOW(fd,0) = 0xe5;
  3962. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3963. WFIFOSET(fd,packet_len(0xe5));
  3964. #else
  3965. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3966. if( !tsd ) return;
  3967. WFIFOHEAD(fd,packet_len(0x1f4));
  3968. WFIFOW(fd,0) = 0x1f4;
  3969. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3970. WFIFOL(fd,26) = tsd->status.char_id;
  3971. WFIFOW(fd,30) = tsd->status.base_level;
  3972. WFIFOSET(fd,packet_len(0x1f4));
  3973. #endif
  3974. }
  3975. /// Reply to a trade-request.
  3976. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3977. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3978. /// result:
  3979. /// 0 = Char is too far
  3980. /// 1 = Character does not exist
  3981. /// 2 = Trade failed
  3982. /// 3 = Accept
  3983. /// 4 = Cancel
  3984. /// 5 = Busy
  3985. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3986. {
  3987. int fd = sd->fd;
  3988. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3989. if( PACKETVER < 6 || !tsd ) {
  3990. WFIFOHEAD(fd,packet_len(0xe7));
  3991. WFIFOW(fd,0) = 0xe7;
  3992. WFIFOB(fd,2) = type;
  3993. WFIFOSET(fd,packet_len(0xe7));
  3994. } else {
  3995. WFIFOHEAD(fd,packet_len(0x1f5));
  3996. WFIFOW(fd,0) = 0x1f5;
  3997. WFIFOB(fd,2) = type;
  3998. WFIFOL(fd,3) = tsd->status.char_id;
  3999. WFIFOW(fd,7) = tsd->status.base_level;
  4000. WFIFOSET(fd,packet_len(0x1f5));
  4001. }
  4002. }
  4003. /// Notifies the client about an item from other player in current trade.
  4004. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4005. /// 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)
  4006. /// 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)
  4007. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  4008. nullpo_retv( sd );
  4009. nullpo_retv( tsd );
  4010. int fd = tsd->fd;
  4011. if( !session_isActive( fd ) ){
  4012. return;
  4013. }
  4014. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4015. if( index ){
  4016. index = server_index( index );
  4017. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4018. return;
  4019. }
  4020. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4021. #if PACKETVER >= 20100223
  4022. p.itemType = sd->inventory_data[index]->type;
  4023. #endif
  4024. p.identified = sd->inventory.u.items_inventory[index].identify;
  4025. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4026. p.refine = sd->inventory.u.items_inventory[index].refine;
  4027. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4028. #if PACKETVER >= 20150226
  4029. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  4030. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4031. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4032. p.look = sd->inventory_data[index]->look;
  4033. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4034. #endif
  4035. #endif
  4036. }else{
  4037. p = {};
  4038. }
  4039. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4040. p.amount = amount;
  4041. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4042. }
  4043. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4044. /// 00ea <index>.W <result>.B
  4045. /// result:
  4046. /// 0 = success
  4047. /// 1 = overweight
  4048. /// 2 = trade canceled
  4049. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  4050. {
  4051. int fd;
  4052. nullpo_retv(sd);
  4053. fd = sd->fd;
  4054. WFIFOHEAD(fd,packet_len(0xea));
  4055. WFIFOW(fd,0) = 0xea;
  4056. WFIFOW(fd,2) = index;
  4057. WFIFOB(fd,4) = fail;
  4058. WFIFOSET(fd,packet_len(0xea));
  4059. }
  4060. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4061. /// 00ec <who>.B
  4062. /// who:
  4063. /// 0 = self
  4064. /// 1 = other player
  4065. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  4066. {
  4067. int fd;
  4068. nullpo_retv(sd);
  4069. fd = sd->fd;
  4070. WFIFOHEAD(fd,packet_len(0xec));
  4071. WFIFOW(fd,0) = 0xec;
  4072. WFIFOB(fd,2) = fail;
  4073. WFIFOSET(fd,packet_len(0xec));
  4074. }
  4075. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4076. /// 00ee
  4077. void clif_tradecancelled(struct map_session_data* sd)
  4078. {
  4079. int fd;
  4080. nullpo_retv(sd);
  4081. fd = sd->fd;
  4082. WFIFOHEAD(fd,packet_len(0xee));
  4083. WFIFOW(fd,0) = 0xee;
  4084. WFIFOSET(fd,packet_len(0xee));
  4085. }
  4086. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4087. /// 00f0 <result>.B
  4088. /// result:
  4089. /// 0 = success
  4090. /// 1 = failure
  4091. void clif_tradecompleted(struct map_session_data* sd, int fail)
  4092. {
  4093. int fd;
  4094. nullpo_retv(sd);
  4095. fd = sd->fd;
  4096. WFIFOHEAD(fd,packet_len(0xf0));
  4097. WFIFOW(fd,0) = 0xf0;
  4098. WFIFOB(fd,2) = fail;
  4099. WFIFOSET(fd,packet_len(0xf0));
  4100. }
  4101. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4102. /// 00f1
  4103. /// NOTE: Unknown purpose. Items are not removed until the window is
  4104. /// refreshed (ex. by putting another item in there).
  4105. void clif_tradeundo(struct map_session_data* sd)
  4106. {
  4107. int fd = sd->fd;
  4108. WFIFOHEAD(fd,packet_len(0xf1));
  4109. WFIFOW(fd,0) = 0xf1;
  4110. WFIFOSET(fd,packet_len(0xf1));
  4111. }
  4112. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4113. /// 00f2 <current count>.W <max count>.W
  4114. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  4115. {
  4116. int fd;
  4117. nullpo_retv(sd);
  4118. fd=sd->fd;
  4119. WFIFOHEAD(fd,packet_len(0xf2));
  4120. WFIFOW(fd,0) = 0xf2;
  4121. WFIFOW(fd,2) = amount;
  4122. WFIFOW(fd,4) = max_amount;
  4123. WFIFOSET(fd,packet_len(0xf2));
  4124. }
  4125. /// Notifies the client of an item being added to the storage.
  4126. /// 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)
  4127. /// 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)
  4128. /// 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)
  4129. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  4130. nullpo_retv( sd );
  4131. nullpo_retv( i );
  4132. int fd = sd->fd;
  4133. if( !session_isActive( fd ) ){
  4134. return;
  4135. }
  4136. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4137. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4138. p.index = client_storage_index( index ); // index
  4139. p.amount = amount; // amount
  4140. p.itemId = client_nameid( i->nameid ); // id
  4141. #if PACKETVER >= 5
  4142. p.itemType = itemtype( i->nameid ); //type
  4143. #endif
  4144. p.identified = i->identify; //identify flag
  4145. p.damaged = i->attribute; // attribute
  4146. p.refine = i->refine; //refine
  4147. clif_addcards( &p.slot, i );
  4148. #if PACKETVER >= 20150226
  4149. clif_add_random_options( p.option_data, i );
  4150. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4151. p.enchantgrade = i->enchantgrade;
  4152. #endif
  4153. #endif
  4154. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4155. }
  4156. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4157. /// 00f6 <index>.W <amount>.L
  4158. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4159. {
  4160. int fd;
  4161. nullpo_retv(sd);
  4162. fd=sd->fd;
  4163. WFIFOHEAD(fd,packet_len(0xf6));
  4164. WFIFOW(fd,0)=0xf6; // Storage item removed
  4165. WFIFOW(fd,2)=client_storage_index(index);
  4166. WFIFOL(fd,4)=amount;
  4167. WFIFOSET(fd,packet_len(0xf6));
  4168. }
  4169. /// Closes storage (ZC_CLOSE_STORE).
  4170. /// 00f8
  4171. void clif_storageclose(struct map_session_data* sd)
  4172. {
  4173. int fd;
  4174. nullpo_retv(sd);
  4175. fd=sd->fd;
  4176. WFIFOHEAD(fd,packet_len(0xf8));
  4177. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4178. WFIFOSET(fd,packet_len(0xf8));
  4179. }
  4180. /// Notifies clients in an area of a player's souls.
  4181. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4182. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4183. /// 0b73 <id>.L <amount>.W
  4184. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4185. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4186. struct PACKET_ZC_SOULENERGY p = {};
  4187. p.PacketType = HEADER_ZC_SOULENERGY;
  4188. #else
  4189. struct PACKET_ZC_SPIRITS p = {};
  4190. p.PacketType = HEADER_ZC_SPIRITS;
  4191. #endif
  4192. p.AID = sd->bl.id;
  4193. p.num = sd->soulball;
  4194. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4195. }
  4196. /*==========================================
  4197. * Server tells 'sd' player client the abouts of 'dstsd' player
  4198. *------------------------------------------*/
  4199. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4200. {
  4201. struct block_list *d_bl;
  4202. int i;
  4203. if( dstsd->chatID ) {
  4204. struct chat_data *cd = NULL;
  4205. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4206. clif_dispchat(cd,sd->fd);
  4207. } else if( dstsd->state.vending )
  4208. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4209. else if( dstsd->state.buyingstore )
  4210. clif_buyingstore_entry( *dstsd, &sd->bl );
  4211. if(dstsd->spiritball > 0)
  4212. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4213. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4214. clif_millenniumshield_single(sd->fd, dstsd);
  4215. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4216. clif_spiritcharm_single(sd->fd, dstsd);
  4217. if (dstsd->soulball > 0)
  4218. clif_soulball( dstsd, &sd->bl, SELF );
  4219. if (dstsd->servantball > 0)
  4220. clif_servantball( *dstsd, &sd->bl, SELF );
  4221. if (dstsd->abyssball > 0)
  4222. clif_abyssball( *dstsd, &sd->bl, SELF );
  4223. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4224. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4225. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4226. )
  4227. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4228. // display link (sd - dstsd) to sd
  4229. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4230. if( i < MAX_DEVOTION )
  4231. clif_devotion(&sd->bl, sd);
  4232. // display links (dstsd - devotees) to sd
  4233. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4234. if( i < MAX_DEVOTION )
  4235. clif_devotion(&dstsd->bl, sd);
  4236. // display link (dstsd - crusader) to sd
  4237. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4238. clif_devotion(d_bl, sd);
  4239. }
  4240. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4241. struct unit_data *ud;
  4242. struct view_data *vd;
  4243. bool option = false;
  4244. unsigned int option_val = 0;
  4245. vd = status_get_viewdata(bl);
  4246. if (!vd || vd->class_ == JT_INVISIBLE)
  4247. return;
  4248. // Hide NPC from Maya Purple card
  4249. if (clif_npc_mayapurple(bl))
  4250. return;
  4251. ud = unit_bl2ud(bl);
  4252. if( ud && ud->walktimer != INVALID_TIMER ){
  4253. clif_set_unit_walking( bl, sd, ud, SELF );
  4254. }else{
  4255. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4256. }
  4257. if (vd->cloth_color)
  4258. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4259. if (vd->body_style)
  4260. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4261. switch (bl->type)
  4262. {
  4263. case BL_PC:
  4264. {
  4265. TBL_PC* tsd = (TBL_PC*)bl;
  4266. clif_getareachar_pc(sd, tsd);
  4267. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4268. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4269. else if(tsd->state.size==SZ_MEDIUM)
  4270. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4271. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4272. clif_sendbgemblem_single(sd->fd,tsd);
  4273. if ( tsd->status.robe )
  4274. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4275. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4276. clif_hat_effects(sd,bl,SELF);
  4277. }
  4278. break;
  4279. case BL_MER: // Devotion Effects
  4280. if( ((TBL_MER*)bl)->devotion_flag )
  4281. clif_devotion(bl, sd);
  4282. break;
  4283. case BL_NPC:
  4284. {
  4285. TBL_NPC* nd = (TBL_NPC*)bl;
  4286. if( nd->chat_id )
  4287. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4288. if( nd->size == SZ_BIG )
  4289. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4290. else if( nd->size == SZ_MEDIUM )
  4291. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4292. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4293. clif_progressbar_npc(nd, sd);
  4294. }
  4295. break;
  4296. case BL_MOB:
  4297. {
  4298. TBL_MOB* md = (TBL_MOB*)bl;
  4299. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4300. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4301. else if(md->special_state.size==SZ_MEDIUM)
  4302. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4303. #if PACKETVER >= 20120404
  4304. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4305. int i;
  4306. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4307. if( md->dmglog[i].id == sd->status.char_id )
  4308. clif_monster_hp_bar(md, sd->fd);
  4309. }
  4310. #endif
  4311. }
  4312. break;
  4313. case BL_PET:
  4314. if (vd->head_bottom)
  4315. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4316. break;
  4317. }
  4318. }
  4319. //Modifies the type of damage according to status changes [Skotlex]
  4320. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4321. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4322. {
  4323. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4324. }
  4325. /*==========================================
  4326. * Estimates walk delay based on the damage criteria. [Skotlex]
  4327. *------------------------------------------*/
  4328. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4329. {
  4330. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4331. return 0;
  4332. if (bl->type == BL_PC) {
  4333. if (battle_config.pc_walk_delay_rate != 100)
  4334. delay = delay*battle_config.pc_walk_delay_rate/100;
  4335. } else
  4336. if (battle_config.walk_delay_rate != 100)
  4337. delay = delay*battle_config.walk_delay_rate/100;
  4338. if (div_ > 1) //Multi-hit skills mean higher delays.
  4339. delay += battle_config.multihit_delay*(div_-1);
  4340. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4341. }
  4342. /*========================================== [Playtester]
  4343. * Returns hallucination damage the client displays
  4344. *------------------------------------------*/
  4345. static int clif_hallucination_damage()
  4346. {
  4347. int digit = rnd() % 5 + 1;
  4348. switch (digit)
  4349. {
  4350. case 1:
  4351. return (rnd() % 10);
  4352. case 2:
  4353. return (rnd() % 100);
  4354. case 3:
  4355. return (rnd() % 1000);
  4356. case 4:
  4357. return (rnd() % 10000);
  4358. }
  4359. return (rnd() % 32767);
  4360. }
  4361. /// Sends a 'damage' packet (src performs action on dst)
  4362. /// 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)
  4363. /// 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)
  4364. /// 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)
  4365. /// type:
  4366. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4367. /// 1 = pick up item
  4368. /// 2 = sit down
  4369. /// 3 = stand up
  4370. /// 4 = damage (endure)
  4371. /// 5 = (splash?)
  4372. /// 6 = (skill?)
  4373. /// 7 = (repeat damage?)
  4374. /// 8 = multi-hit damage
  4375. /// 9 = multi-hit damage (endure)
  4376. /// 10 = critical hit
  4377. /// 11 = lucky dodge
  4378. /// 12 = (touch skill?)
  4379. /// 13 = multi-hit critical
  4380. 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)
  4381. {
  4382. unsigned char buf[34];
  4383. struct status_change *sc;
  4384. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4385. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4386. #if PACKETVER < 20071113
  4387. const int cmd = 0x8a;
  4388. int offset = 0;
  4389. #elif PACKETVER < 20131223
  4390. const int cmd = 0x2e1;
  4391. int offset = 2;
  4392. #else
  4393. const int cmd = 0x8c8;
  4394. int offset = 3;
  4395. #endif
  4396. nullpo_ret(src);
  4397. nullpo_ret(dst);
  4398. if (type != DMG_MULTI_HIT_CRITICAL)
  4399. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4400. sc = status_get_sc(dst);
  4401. if(sc && sc->count) {
  4402. if(sc->data[SC_HALLUCINATION]) {
  4403. damage = clif_hallucination_damage();
  4404. if(damage2) damage2 = clif_hallucination_damage();
  4405. }
  4406. }
  4407. WBUFW(buf,0) = cmd;
  4408. WBUFL(buf,2) = src->id;
  4409. WBUFL(buf,6) = dst->id;
  4410. WBUFL(buf,10) = client_tick(tick);
  4411. WBUFL(buf,14) = sdelay;
  4412. WBUFL(buf,18) = ddelay;
  4413. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4414. #if PACKETVER < 20071113
  4415. WBUFW(buf,22) = damage ? div : 0;
  4416. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4417. #else
  4418. WBUFL(buf, 22) = damage ? div : 0;
  4419. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4420. #endif
  4421. } else {
  4422. #if PACKETVER < 20071113
  4423. WBUFW(buf,22) = min(damage, INT16_MAX);
  4424. WBUFW(buf,27+offset) = damage2;
  4425. #else
  4426. WBUFL(buf,22) = damage;
  4427. WBUFL(buf,27+offset) = damage2;
  4428. #endif
  4429. }
  4430. #if PACKETVER >= 20131223
  4431. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4432. #endif
  4433. WBUFW(buf,24+offset) = div;
  4434. WBUFB(buf,26+offset) = type;
  4435. if(disguised(dst)) {
  4436. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4437. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4438. clif_send(buf, packet_len(cmd), dst, SELF);
  4439. } else
  4440. clif_send(buf, packet_len(cmd), dst, AREA);
  4441. if(disguised(src)) {
  4442. WBUFL(buf,2) = disguised_bl_id( src->id );
  4443. if (disguised(dst))
  4444. WBUFL(buf,6) = dst->id;
  4445. #if PACKETVER < 20071113
  4446. if(damage > 0) WBUFW(buf,22) = -1;
  4447. if(damage2 > 0) WBUFW(buf,27) = -1;
  4448. #else
  4449. if(damage > 0) WBUFL(buf,22) = -1;
  4450. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4451. #endif
  4452. clif_send(buf,packet_len(cmd),src,SELF);
  4453. }
  4454. if(src == dst) {
  4455. unit_setdir(src, unit_getdir(src));
  4456. }
  4457. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4458. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4459. //Return adjusted can't walk delay for further processing.
  4460. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4461. }
  4462. /*==========================================
  4463. * src picks up dst
  4464. *------------------------------------------*/
  4465. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4466. {
  4467. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4468. unsigned char buf[32];
  4469. nullpo_retv(src);
  4470. nullpo_retv(dst);
  4471. WBUFW(buf, 0) = 0x8a;
  4472. WBUFL(buf, 2) = src->id;
  4473. WBUFL(buf, 6) = dst->id;
  4474. WBUFB(buf,26) = 1;
  4475. clif_send(buf, packet_len(0x8a), src, AREA);
  4476. }
  4477. /*==========================================
  4478. * inform clients in area that `bl` is sitting
  4479. *------------------------------------------*/
  4480. void clif_sitting(struct block_list* bl)
  4481. {
  4482. unsigned char buf[32];
  4483. nullpo_retv(bl);
  4484. WBUFW(buf, 0) = 0x8a;
  4485. WBUFL(buf, 2) = bl->id;
  4486. WBUFB(buf,26) = 2;
  4487. clif_send(buf, packet_len(0x8a), bl, AREA);
  4488. if(disguised(bl)) {
  4489. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4490. clif_send(buf, packet_len(0x8a), bl, SELF);
  4491. }
  4492. }
  4493. /*==========================================
  4494. * inform clients in area that `bl` is standing
  4495. *------------------------------------------*/
  4496. void clif_standing(struct block_list* bl)
  4497. {
  4498. unsigned char buf[32];
  4499. nullpo_retv(bl);
  4500. WBUFW(buf, 0) = 0x8a;
  4501. WBUFL(buf, 2) = bl->id;
  4502. WBUFB(buf,26) = 3;
  4503. clif_send(buf, packet_len(0x8a), bl, AREA);
  4504. if(disguised(bl)) {
  4505. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4506. clif_send(buf, packet_len(0x8a), bl, SELF);
  4507. }
  4508. }
  4509. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4510. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4511. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4512. {
  4513. unsigned char buf[32];
  4514. WBUFW(buf,0) = 0x192;
  4515. WBUFW(buf,2) = x;
  4516. WBUFW(buf,4) = y;
  4517. WBUFW(buf,6) = type;
  4518. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4519. if( session_isActive(fd) )
  4520. {
  4521. WFIFOHEAD(fd,packet_len(0x192));
  4522. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4523. WFIFOSET(fd,packet_len(0x192));
  4524. }
  4525. else
  4526. {
  4527. struct block_list dummy_bl;
  4528. dummy_bl.type = BL_NUL;
  4529. dummy_bl.x = x;
  4530. dummy_bl.y = y;
  4531. dummy_bl.m = m;
  4532. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4533. }
  4534. }
  4535. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4536. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4537. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4538. nullpo_retv( sd );
  4539. nullpo_retv( fitem );
  4540. struct PACKET_ZC_ITEM_ENTRY p;
  4541. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4542. p.AID = fitem->bl.id;
  4543. p.itemId = client_nameid( fitem->item.nameid );
  4544. p.identify = fitem->item.identify;
  4545. p.x = fitem->bl.x;
  4546. p.y = fitem->bl.y;
  4547. p.amount = fitem->item.amount;
  4548. p.subX = fitem->subx;
  4549. p.subY = fitem->suby;
  4550. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4551. }
  4552. /// Notifes client about Graffiti
  4553. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4554. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4555. unsigned char buf[128];
  4556. nullpo_retv(bl);
  4557. nullpo_retv(unit);
  4558. WBUFW(buf, 0) = 0x1c9;
  4559. WBUFL(buf, 2) = unit->bl.id;
  4560. WBUFL(buf, 6) = unit->group->src_id;
  4561. WBUFW(buf,10) = unit->bl.x;
  4562. WBUFW(buf,12) = unit->bl.y;
  4563. WBUFB(buf,14) = unit->group->unit_id;
  4564. WBUFB(buf,15) = 1;
  4565. WBUFB(buf,16) = 1;
  4566. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4567. clif_send(buf,packet_len(0x1c9),bl,target);
  4568. }
  4569. /// Notifies the client of a skill unit.
  4570. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4571. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4572. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4573. /// 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)
  4574. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4575. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4576. unsigned char buf[128];
  4577. nullpo_retv(bl);
  4578. nullpo_retv(unit);
  4579. if (bl->type == BL_PC)
  4580. fd = ((TBL_PC*)bl)->fd;
  4581. if (unit->group->state.guildaura)
  4582. return;
  4583. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4584. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4585. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4586. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4587. else
  4588. unit_id = unit->group->unit_id;
  4589. if (!visible)
  4590. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4591. #if PACKETVER >= 3
  4592. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4593. clif_graffiti(bl, unit, target);
  4594. return;
  4595. }
  4596. #endif
  4597. #if PACKETVER <= 20120702
  4598. header = 0x011f;
  4599. //#if PACKETVER < 20110718
  4600. // header = 0x011f;
  4601. //#elif PACKETVER < 20121212
  4602. // header = 0x08c7;
  4603. #elif PACKETVER < 20130731
  4604. header = 0x099f;
  4605. #else
  4606. header = 0x09ca;
  4607. #endif
  4608. len = packet_len(header);
  4609. WBUFW(buf,pos) = header;
  4610. if (header != 0x011f) {
  4611. WBUFW(buf, pos+2) = len;
  4612. pos += 2;
  4613. }
  4614. WBUFL(buf,pos+2) = unit->bl.id;
  4615. WBUFL(buf,pos+6) = unit->group->src_id;
  4616. WBUFW(buf,pos+10) = unit->bl.x;
  4617. WBUFW(buf,pos+12) = unit->bl.y;
  4618. switch (header) {
  4619. case 0x011f:
  4620. WBUFB(buf,pos+14) = unit_id;
  4621. WBUFB(buf,pos+15) = visible;
  4622. break;
  4623. case 0x08c7:
  4624. WBUFB(buf,pos+14) = unit_id;
  4625. WBUFW(buf,pos+15) = unit->range;
  4626. WBUFB(buf,pos+17) = visible;
  4627. break;
  4628. case 0x099f:
  4629. WBUFL(buf,pos+14) = unit_id;
  4630. WBUFW(buf,pos+18) = unit->range;
  4631. WBUFB(buf,pos+20) = visible;
  4632. break;
  4633. case 0x09ca:
  4634. WBUFL(buf,pos+14) = unit_id;
  4635. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4636. WBUFB(buf,pos+19) = visible;
  4637. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4638. break;
  4639. }
  4640. clif_send(buf, len, bl, target);
  4641. if (unit->group->skill_id == WZ_ICEWALL)
  4642. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4643. }
  4644. /// 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)
  4645. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4646. unsigned char buf[128];
  4647. nullpo_retv(bl);
  4648. WBUFW(buf, 0) = 0x09ca;
  4649. WBUFW(buf, 2) = packet_len(0x09ca);
  4650. WBUFL(buf, 4) = 1000;
  4651. WBUFL(buf, 8) = 2000;
  4652. WBUFW(buf, 12) = x;
  4653. WBUFW(buf, 14) = y;
  4654. WBUFL(buf, 16) = unit_id;
  4655. WBUFB(buf, 20) = (unsigned char)range;
  4656. WBUFB(buf, 21) = 1;
  4657. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4658. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4659. }
  4660. /*==========================================
  4661. * Server tells client to remove unit of id 'unit->bl.id'
  4662. *------------------------------------------*/
  4663. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4664. {
  4665. nullpo_retv(unit);
  4666. WFIFOHEAD(fd,packet_len(0x120));
  4667. WFIFOW(fd, 0)=0x120;
  4668. WFIFOL(fd, 2)=unit->bl.id;
  4669. WFIFOSET(fd,packet_len(0x120));
  4670. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4671. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4672. }
  4673. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4674. /// 0120 <id>.L
  4675. void clif_skill_delunit(struct skill_unit *unit)
  4676. {
  4677. unsigned char buf[16];
  4678. nullpo_retv(unit);
  4679. WBUFW(buf, 0)=0x120;
  4680. WBUFL(buf, 2)=unit->bl.id;
  4681. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4682. }
  4683. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4684. /// 01ac <id>.L
  4685. /// Only affects units with class [139,153] client-side.
  4686. void clif_skillunit_update(struct block_list* bl)
  4687. {
  4688. unsigned char buf[6];
  4689. nullpo_retv(bl);
  4690. WBUFW(buf,0) = 0x1ac;
  4691. WBUFL(buf,2) = bl->id;
  4692. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4693. }
  4694. /*==========================================
  4695. *
  4696. *------------------------------------------*/
  4697. static int clif_getareachar(struct block_list* bl,va_list ap)
  4698. {
  4699. struct map_session_data *sd;
  4700. nullpo_ret(bl);
  4701. sd=va_arg(ap,struct map_session_data*);
  4702. if (!clif_session_isValid(sd))
  4703. return 0;
  4704. switch(bl->type){
  4705. case BL_ITEM:
  4706. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4707. break;
  4708. case BL_SKILL:
  4709. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4710. break;
  4711. default:
  4712. if(&sd->bl == bl)
  4713. break;
  4714. clif_getareachar_unit(sd,bl);
  4715. break;
  4716. }
  4717. return 0;
  4718. }
  4719. /*==========================================
  4720. * tbl has gone out of view-size of bl
  4721. *------------------------------------------*/
  4722. int clif_outsight(struct block_list *bl,va_list ap)
  4723. {
  4724. struct block_list *tbl;
  4725. struct view_data *vd;
  4726. TBL_PC *sd, *tsd;
  4727. tbl=va_arg(ap,struct block_list*);
  4728. if(bl == tbl) return 0;
  4729. sd = BL_CAST(BL_PC, bl);
  4730. tsd = BL_CAST(BL_PC, tbl);
  4731. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4732. nullpo_ret(bl);
  4733. switch(bl->type){
  4734. case BL_PC:
  4735. if(sd->vd.class_ != JT_INVISIBLE)
  4736. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4737. if(sd->chatID){
  4738. struct chat_data *cd;
  4739. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4740. if(cd->usersd[0]==sd)
  4741. clif_dispchat(cd,tsd->fd);
  4742. }
  4743. if(sd->state.vending)
  4744. clif_closevendingboard(bl,tsd->fd);
  4745. if(sd->state.buyingstore)
  4746. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4747. break;
  4748. case BL_ITEM:
  4749. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4750. break;
  4751. case BL_SKILL:
  4752. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4753. break;
  4754. case BL_NPC:
  4755. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4756. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4757. break;
  4758. default:
  4759. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4760. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4761. break;
  4762. }
  4763. }
  4764. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4765. nullpo_ret(tbl);
  4766. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4767. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4768. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4769. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4770. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4771. }
  4772. return 0;
  4773. }
  4774. /*==========================================
  4775. * tbl has come into view of bl
  4776. *------------------------------------------*/
  4777. int clif_insight(struct block_list *bl,va_list ap)
  4778. {
  4779. struct block_list *tbl;
  4780. TBL_PC *sd, *tsd;
  4781. tbl=va_arg(ap,struct block_list*);
  4782. if (bl == tbl) return 0;
  4783. sd = BL_CAST(BL_PC, bl);
  4784. tsd = BL_CAST(BL_PC, tbl);
  4785. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4786. switch(bl->type){
  4787. case BL_ITEM:
  4788. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4789. break;
  4790. case BL_SKILL:
  4791. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4792. break;
  4793. default:
  4794. clif_getareachar_unit(tsd,bl);
  4795. break;
  4796. }
  4797. }
  4798. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4799. clif_getareachar_unit(sd,tbl);
  4800. }
  4801. return 0;
  4802. }
  4803. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4804. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4805. void clif_skillinfoblock(struct map_session_data *sd)
  4806. {
  4807. int fd;
  4808. int i,len,id;
  4809. nullpo_retv(sd);
  4810. fd = sd->fd;
  4811. if (!session_isActive(fd))
  4812. return;
  4813. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4814. WFIFOW(fd,0) = 0x10f;
  4815. bool haveCallPartnerSkill = false;
  4816. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4817. {
  4818. if( (id = sd->status.skill[i].id) != 0 )
  4819. {
  4820. // workaround for bugreport:5348
  4821. if (len + 37 > 8192)
  4822. break;
  4823. // skip WE_CALLPARTNER and send it in special way
  4824. if (id == WE_CALLPARTNER) {
  4825. haveCallPartnerSkill = true;
  4826. continue;
  4827. }
  4828. WFIFOW(fd,len) = id;
  4829. WFIFOL(fd,len+2) = skill_get_inf(id);
  4830. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4831. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4832. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4833. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4834. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4835. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4836. else
  4837. WFIFOB(fd,len+36) = 0;
  4838. len += 37;
  4839. }
  4840. }
  4841. WFIFOW(fd,2)=len;
  4842. WFIFOSET(fd,len);
  4843. // adoption fix
  4844. if (haveCallPartnerSkill) {
  4845. clif_addskill(sd, WE_CALLPARTNER);
  4846. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4847. }
  4848. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4849. for ( ; i < MAX_SKILL; i++)
  4850. {
  4851. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4852. {
  4853. clif_addskill(sd, id);
  4854. clif_skillinfo(sd, id, 0);
  4855. }
  4856. }
  4857. }
  4858. /**
  4859. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4860. **/
  4861. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4862. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4863. void clif_addskill(struct map_session_data *sd, int skill_id)
  4864. {
  4865. nullpo_retv(sd);
  4866. int fd = sd->fd;
  4867. uint16 idx = skill_get_index(skill_id);
  4868. if (!session_isActive(fd) || !idx)
  4869. return;
  4870. if( sd->status.skill[idx].id <= 0 )
  4871. return;
  4872. WFIFOHEAD(fd, packet_len(0x111));
  4873. WFIFOW(fd,0) = 0x111;
  4874. WFIFOW(fd,2) = skill_id;
  4875. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4876. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4877. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4878. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4879. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4880. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4881. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4882. else
  4883. WFIFOB(fd,38) = 0;
  4884. WFIFOSET(fd,packet_len(0x111));
  4885. }
  4886. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4887. /// 0441 <skill id>.W
  4888. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4889. {
  4890. #if PACKETVER >= 20081217
  4891. nullpo_retv(sd);
  4892. int fd = sd->fd;
  4893. uint16 idx = skill_get_index(skill_id);
  4894. if (!session_isActive(fd) || !idx)
  4895. return;
  4896. WFIFOHEAD(fd,packet_len(0x441));
  4897. WFIFOW(fd,0) = 0x441;
  4898. WFIFOW(fd,2) = skill_id;
  4899. WFIFOSET(fd,packet_len(0x441));
  4900. #endif
  4901. clif_skillinfoblock(sd);
  4902. }
  4903. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4904. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4905. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4906. nullpo_retv(sd);
  4907. int fd = sd->fd;
  4908. uint16 idx = skill_get_index(skill_id);
  4909. if (!session_isActive(fd) || !idx)
  4910. return;
  4911. WFIFOHEAD(fd, packet_len(0x10e));
  4912. WFIFOW(fd, 0) = 0x10e;
  4913. WFIFOW(fd, 2) = skill_id;
  4914. WFIFOW(fd, 4) = lv;
  4915. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4916. WFIFOW(fd, 8) = range;
  4917. WFIFOB(fd, 10) = upgradable;
  4918. WFIFOSET(fd, packet_len(0x10e));
  4919. }
  4920. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4921. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4922. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4923. {
  4924. nullpo_retv(sd);
  4925. const int fd = sd->fd;
  4926. uint16 idx = skill_get_index(skill_id);
  4927. if (!session_isActive(fd) || !idx)
  4928. return;
  4929. WFIFOHEAD(fd,packet_len(0x7e1));
  4930. WFIFOW(fd,0) = 0x7e1;
  4931. WFIFOW(fd,2) = skill_id;
  4932. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4933. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4934. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4935. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4936. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4937. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4938. else
  4939. WFIFOB(fd,14) = 0;
  4940. WFIFOSET(fd,packet_len(0x7e1));
  4941. }
  4942. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4943. #if PACKETVER >= 20151223
  4944. if( !battle_config.show_skill_scale ){
  4945. return;
  4946. }
  4947. struct PACKET_ZC_SKILL_SCALE p;
  4948. p.PacketType = skillscale;
  4949. p.AID = src_id;
  4950. p.skill_id = skill_id;
  4951. p.skill_lv = skill_lv;
  4952. p.x = x;
  4953. p.y = y;
  4954. p.casttime = casttime;
  4955. if( disguised( bl ) ){
  4956. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4957. p.AID = disguised_bl_id( bl->id );
  4958. clif_send( &p, sizeof( p ), bl, SELF );
  4959. }else{
  4960. clif_send( &p, sizeof( p ), bl, AREA );
  4961. }
  4962. #endif
  4963. }
  4964. /// Notifies clients in area, that an object is about to use a skill.
  4965. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4966. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4967. /// property:
  4968. /// 0 = Yellow cast aura
  4969. /// 1 = Water elemental cast aura
  4970. /// 2 = Earth elemental cast aura
  4971. /// 3 = Fire elemental cast aura
  4972. /// 4 = Wind elemental cast aura
  4973. /// 5 = Poison elemental cast aura
  4974. /// 6 = Holy elemental cast aura
  4975. /// ? = like 0
  4976. /// is disposable:
  4977. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4978. /// 1 = no text
  4979. 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)
  4980. {
  4981. #if PACKETVER < 20091124
  4982. const int cmd = 0x13e;
  4983. #else
  4984. const int cmd = 0x7fb;
  4985. #endif
  4986. unsigned char buf[32];
  4987. WBUFW(buf,0) = cmd;
  4988. WBUFL(buf,2) = src_id;
  4989. WBUFL(buf,6) = dst_id;
  4990. WBUFW(buf,10) = dst_x;
  4991. WBUFW(buf,12) = dst_y;
  4992. WBUFW(buf,14) = skill_id;
  4993. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4994. WBUFL(buf,20) = casttime;
  4995. #if PACKETVER >= 20091124
  4996. WBUFB(buf,24) = 0; // isDisposable
  4997. #endif
  4998. if (disguised(bl)) {
  4999. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5000. WBUFL(buf,2) = disguised_bl_id( src_id );
  5001. clif_send(buf,packet_len(cmd), bl, SELF);
  5002. } else
  5003. clif_send(buf,packet_len(cmd), bl, AREA);
  5004. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5005. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5006. }
  5007. }
  5008. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5009. /// 01b9 <id>.L
  5010. void clif_skillcastcancel(struct block_list* bl)
  5011. {
  5012. unsigned char buf[16];
  5013. nullpo_retv(bl);
  5014. WBUFW(buf,0) = 0x1b9;
  5015. WBUFL(buf,2) = bl->id;
  5016. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5017. }
  5018. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5019. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5020. /// num (only used when skill id = NV_BASIC and cause = 0):
  5021. /// 0 = "skill failed" MsgStringTable[159]
  5022. /// 1 = "no emotions" MsgStringTable[160]
  5023. /// 2 = "no sit" MsgStringTable[161]
  5024. /// 3 = "no chat" MsgStringTable[162]
  5025. /// 4 = "no party" MsgStringTable[163]
  5026. /// 5 = "no shout" MsgStringTable[164]
  5027. /// 6 = "no PKing" MsgStringTable[165]
  5028. /// 7 = "no alligning" MsgStringTable[383]
  5029. /// ? = ignored
  5030. /// cause:
  5031. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5032. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5033. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5034. /// "skill failed" MsgStringTable[204] (otherwise)
  5035. /// ... = @see enum useskill_fail_cause
  5036. /// ? = ignored
  5037. ///
  5038. /// if(result!=0) doesn't display any of the previous messages
  5039. /// Note: when this packet is received an unknown flag is always set to 0,
  5040. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5041. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5042. nullpo_retv( sd );
  5043. int fd = sd->fd;
  5044. if( !session_isActive( fd ) ){
  5045. return;
  5046. }
  5047. if(battle_config.display_skill_fail&1)
  5048. return; //Disable all skill failed messages
  5049. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5050. return; //Disable delay failed messages
  5051. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5052. return;
  5053. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5054. return;
  5055. struct PACKET_ZC_ACK_TOUSESKILL p;
  5056. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5057. p.skillId = skill_id;
  5058. p.btype = btype;
  5059. p.itemId = itemId;
  5060. p.flag = 0; // 0 - failed
  5061. p.cause = cause;
  5062. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5063. }
  5064. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5065. /// 043d <skill ID>.W <tick>.L
  5066. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  5067. {
  5068. #if PACKETVER>=20081112
  5069. int fd;
  5070. nullpo_retv(sd);
  5071. fd=sd->fd;
  5072. WFIFOHEAD(fd,packet_len(0x43d));
  5073. WFIFOW(fd,0) = 0x43d;
  5074. WFIFOW(fd,2) = skill_id;
  5075. WFIFOL(fd,4) = client_tick(tick);
  5076. WFIFOSET(fd,packet_len(0x43d));
  5077. #endif
  5078. }
  5079. /// Skill attack effect and damage.
  5080. /// 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)
  5081. /// 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)
  5082. 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)
  5083. {
  5084. unsigned char buf[64];
  5085. struct status_change *sc;
  5086. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5087. nullpo_ret(src);
  5088. nullpo_ret(dst);
  5089. type = clif_calc_delay(type,div,damage,ddelay);
  5090. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5091. if(sc->data[SC_HALLUCINATION] && damage)
  5092. damage = clif_hallucination_damage();
  5093. }
  5094. #if PACKETVER < 3
  5095. WBUFW(buf,0)=0x114;
  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. WBUFW(buf,24)=damage?div:0;
  5104. } else {
  5105. WBUFW(buf,24)=damage;
  5106. }
  5107. WBUFW(buf,26)=skill_lv;
  5108. WBUFW(buf,28)=div;
  5109. WBUFB(buf,30)=type;
  5110. if (disguised(dst)) {
  5111. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5112. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5113. clif_send(buf,packet_len(0x114),dst,SELF);
  5114. } else
  5115. clif_send(buf,packet_len(0x114),dst,AREA);
  5116. if(disguised(src)) {
  5117. WBUFL(buf,4)=disguised_bl_id(src->id);
  5118. if (disguised(dst))
  5119. WBUFL(buf,8)=dst->id;
  5120. if(damage > 0)
  5121. WBUFW(buf,24)=-1;
  5122. clif_send(buf,packet_len(0x114),src,SELF);
  5123. }
  5124. #else
  5125. WBUFW(buf,0)=0x1de;
  5126. WBUFW(buf,2)=skill_id;
  5127. WBUFL(buf,4)=src->id;
  5128. WBUFL(buf,8)=dst->id;
  5129. WBUFL(buf,12)=client_tick(tick);
  5130. WBUFL(buf,16)=sdelay;
  5131. WBUFL(buf,20)=ddelay;
  5132. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5133. WBUFL(buf,24)=damage?div:0;
  5134. } else {
  5135. WBUFL(buf,24)=damage;
  5136. }
  5137. WBUFW(buf,28)=skill_lv;
  5138. WBUFW(buf,30)=div;
  5139. // For some reason, late 2013 and newer clients have
  5140. // a issue that causes players and monsters to endure
  5141. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5142. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5143. #if PACKETVER < 20131223
  5144. WBUFB(buf,32)=type;
  5145. #else
  5146. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5147. #endif
  5148. if (disguised(dst)) {
  5149. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5150. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5151. clif_send(buf,packet_len(0x1de),dst,SELF);
  5152. } else
  5153. clif_send(buf,packet_len(0x1de),dst,AREA);
  5154. if(disguised(src)) {
  5155. WBUFL(buf,4)=disguised_bl_id(src->id);
  5156. if (disguised(dst))
  5157. WBUFL(buf,8)=dst->id;
  5158. if(damage > 0)
  5159. WBUFL(buf,24)=-1;
  5160. clif_send(buf,packet_len(0x1de),src,SELF);
  5161. }
  5162. #endif
  5163. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5164. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5165. }
  5166. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5167. /// 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
  5168. /*
  5169. 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)
  5170. {
  5171. unsigned char buf[64];
  5172. struct status_change *sc;
  5173. nullpo_ret(src);
  5174. nullpo_ret(dst);
  5175. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5176. type = clif_calc_delay(type,div,damage,ddelay);
  5177. sc = status_get_sc(dst);
  5178. if(sc && sc->count) {
  5179. if(sc->data[SC_HALLUCINATION] && damage)
  5180. damage = clif_hallucination_damage();
  5181. }
  5182. WBUFW(buf,0)=0x115;
  5183. WBUFW(buf,2)=skill_id;
  5184. WBUFL(buf,4)=src->id;
  5185. WBUFL(buf,8)=dst->id;
  5186. WBUFL(buf,12)=client_tick(tick);
  5187. WBUFL(buf,16)=sdelay;
  5188. WBUFL(buf,20)=ddelay;
  5189. WBUFW(buf,24)=dst->x;
  5190. WBUFW(buf,26)=dst->y;
  5191. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5192. WBUFW(buf,28)=damage?div:0;
  5193. } else {
  5194. WBUFW(buf,28)=damage;
  5195. }
  5196. WBUFW(buf,30)=skill_lv;
  5197. WBUFW(buf,32)=div;
  5198. WBUFB(buf,34)=type;
  5199. clif_send(buf,packet_len(0x115),src,AREA);
  5200. if(disguised(src)) {
  5201. WBUFL(buf,4)=disguised_bl_id(src->id);
  5202. if(damage > 0)
  5203. WBUFW(buf,28)=-1;
  5204. clif_send(buf,packet_len(0x115),src,SELF);
  5205. }
  5206. if (disguised(dst)) {
  5207. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5208. if (disguised(src))
  5209. WBUFL(buf,4)=src->id;
  5210. else if(damage > 0)
  5211. WBUFW(buf,28)=-1;
  5212. clif_send(buf,packet_len(0x115),dst,SELF);
  5213. }
  5214. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5215. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5216. }
  5217. */
  5218. /// Non-damaging skill effect
  5219. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5220. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5221. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5222. {
  5223. unsigned char buf[17];
  5224. #if PACKETVER < 20130731
  5225. const int cmd = 0x11a;
  5226. #else
  5227. const int cmd = 0x9cb;
  5228. #endif
  5229. int offset = 0;
  5230. bool success = ( tick != 0 );
  5231. nullpo_ret(dst);
  5232. WBUFW(buf,0) = cmd;
  5233. WBUFW(buf,2) = skill_id;
  5234. #if PACKETVER < 20130731
  5235. WBUFW(buf,4) = min(heal, INT16_MAX);
  5236. #else
  5237. WBUFL(buf,4) = min(heal, INT32_MAX);
  5238. offset += 2;
  5239. #endif
  5240. WBUFL(buf,6+offset) = dst->id;
  5241. WBUFL(buf,10+offset) = src ? src->id : 0;
  5242. WBUFB(buf,14+offset) = success;
  5243. if (disguised(dst)) {
  5244. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5245. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5246. clif_send(buf, packet_len(cmd), dst, SELF);
  5247. } else
  5248. clif_send(buf, packet_len(cmd), dst, AREA);
  5249. if(src && disguised(src)) {
  5250. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5251. if (disguised(dst))
  5252. WBUFL(buf,6+offset) = dst->id;
  5253. clif_send(buf, packet_len(cmd), src, SELF);
  5254. }
  5255. return success;
  5256. }
  5257. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5258. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5259. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5260. {
  5261. unsigned char buf[32];
  5262. nullpo_retv(src);
  5263. WBUFW(buf,0)=0x117;
  5264. WBUFW(buf,2)=skill_id;
  5265. WBUFL(buf,4)=src->id;
  5266. WBUFW(buf,8)=val;
  5267. WBUFW(buf,10)=x;
  5268. WBUFW(buf,12)=y;
  5269. WBUFL(buf,14)=client_tick(tick);
  5270. if(disguised(src)) {
  5271. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5272. WBUFL(buf,4)=disguised_bl_id(src->id);
  5273. clif_send(buf,packet_len(0x117),src,SELF);
  5274. } else
  5275. clif_send(buf,packet_len(0x117),src,AREA);
  5276. }
  5277. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5278. /// 011c <skill id>.W { <map name>.16B }*4
  5279. 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)
  5280. {
  5281. int fd;
  5282. nullpo_retv(sd);
  5283. fd = sd->fd;
  5284. WFIFOHEAD(fd,packet_len(0x11c));
  5285. WFIFOW(fd,0) = 0x11c;
  5286. WFIFOW(fd,2) = skill_id;
  5287. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5288. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5289. else // normal map name
  5290. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5291. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5292. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5293. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5294. WFIFOSET(fd,packet_len(0x11c));
  5295. sd->menuskill_id = skill_id;
  5296. if (skill_id == AL_WARP) {
  5297. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5298. sd->state.workinprogress = WIP_DISABLE_ALL;
  5299. } else
  5300. sd->menuskill_val = skill_lv;
  5301. }
  5302. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5303. /// 011e <type>.B
  5304. /// type:
  5305. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5306. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5307. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5308. ///
  5309. /// @param sd Who receives the message
  5310. /// @param type What message
  5311. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5312. {
  5313. int fd;
  5314. nullpo_retv(sd);
  5315. fd=sd->fd;
  5316. WFIFOHEAD(fd,packet_len(0x11e));
  5317. WFIFOW(fd,0)=0x11e;
  5318. WFIFOB(fd,2)=type;
  5319. WFIFOSET(fd,packet_len(0x11e));
  5320. }
  5321. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5322. /// 0189 <type>.W
  5323. /// type:
  5324. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5325. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5326. ///
  5327. /// @param sd Who receives the message
  5328. /// @param type What message
  5329. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5330. {
  5331. int fd;
  5332. nullpo_retv(sd);
  5333. fd=sd->fd;
  5334. WFIFOHEAD(fd,packet_len(0x189));
  5335. WFIFOW(fd,0)=0x189;
  5336. WFIFOW(fd,2)=type;
  5337. WFIFOSET(fd,packet_len(0x189));
  5338. }
  5339. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5340. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5341. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5342. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5343. {
  5344. struct status_data *status;
  5345. unsigned char buf[64];
  5346. int i, fix;
  5347. nullpo_retv(sd);
  5348. nullpo_retv(dst);
  5349. if( dst->type != BL_MOB )
  5350. return;
  5351. status = status_get_status_data(dst);
  5352. WBUFW(buf, 0)=0x18c;
  5353. WBUFW(buf, 2)=status_get_class(dst);
  5354. WBUFW(buf, 4)=status_get_lv(dst);
  5355. WBUFW(buf, 6)=status->size;
  5356. WBUFL(buf, 8)=status->hp;
  5357. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5358. +(battle_config.estimation_type&2?status->def2:0);
  5359. WBUFW(buf,14)=status->race;
  5360. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5361. +(battle_config.estimation_type&2?status->mdef2:0);
  5362. WBUFW(buf,18)= status->def_ele;
  5363. for(i=0;i<9;i++)
  5364. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5365. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5366. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5367. }
  5368. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5369. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5370. /// material id:
  5371. /// unused by the client
  5372. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5373. nullpo_retv(sd);
  5374. int fd = sd->fd;
  5375. if( !session_isActive( fd ) ){
  5376. return;
  5377. }
  5378. if (sd->menuskill_id == skill_id)
  5379. return; //Avoid resending the menu twice or more times...
  5380. if (skill_id == GC_CREATENEWPOISON)
  5381. skill_id = GC_RESEARCHNEWPOISON;
  5382. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5383. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5384. p->packetType = 0x18d;
  5385. int count = 0;
  5386. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5387. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5388. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5389. )
  5390. {
  5391. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5392. p->items[count].material[0] = 0;
  5393. p->items[count].material[1] = 0;
  5394. p->items[count].material[2] = 0;
  5395. count++;
  5396. }
  5397. }
  5398. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5399. WFIFOSET( fd, p->packetLength );
  5400. if( count > 0 ){
  5401. sd->menuskill_id = skill_id;
  5402. sd->menuskill_val = trigger;
  5403. return;
  5404. }
  5405. }
  5406. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5407. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5408. /// mk type:
  5409. /// 1 = cooking
  5410. /// 2 = arrow
  5411. /// 3 = elemental
  5412. /// 4 = GN_MIX_COOKING
  5413. /// 5 = GN_MAKEBOMB
  5414. /// 6 = GN_S_PHARMACY
  5415. /// 7 = MT_M_MACHINE - Unconfirmed
  5416. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5417. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5418. nullpo_retv( sd );
  5419. // Avoid resending the menu twice or more times...
  5420. if( sd->menuskill_id == skill_id ){
  5421. return;
  5422. }
  5423. int fd = sd->fd;
  5424. if( !session_isActive( fd ) ){
  5425. return;
  5426. }
  5427. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5428. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5429. p->packetType = 0x25a;
  5430. p->makeItem = list_type; // list type
  5431. int count = 0;
  5432. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5433. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5434. continue;
  5435. }
  5436. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5437. count++;
  5438. }
  5439. if( count > 0 || skill_id == AM_PHARMACY ){
  5440. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5441. WFIFOSET( fd, p->packetLength );
  5442. sd->menuskill_id = skill_id;
  5443. sd->menuskill_val = trigger;
  5444. sd->menuskill_val2 = qty; // amount.
  5445. }else{
  5446. clif_menuskill_clear(sd);
  5447. #if PACKETVER >= 20090922
  5448. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5449. #else
  5450. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5451. WFIFOSET( fd, p->packetLength );
  5452. #endif
  5453. }
  5454. }
  5455. /// Notifies clients of a status change.
  5456. /// 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)]
  5457. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5458. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5459. /// @param bl Sends packet to clients around this object
  5460. /// @param id ID of object that has this effect
  5461. /// @param type Status icon see enum efst_type
  5462. /// @param flag 1:Active, 0:Deactive
  5463. /// @param tick Duration in ms
  5464. /// @param val1
  5465. /// @param val2
  5466. /// @param val3
  5467. 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)
  5468. {
  5469. unsigned char buf[32];
  5470. if (type == EFST_BLANK) //It shows nothing on the client...
  5471. return;
  5472. if (type == EFST_POSTDELAY && tick == 0)
  5473. return;
  5474. nullpo_retv(bl);
  5475. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5476. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5477. tick = 200;
  5478. #if PACKETVER >= 20120618
  5479. if (flag && battle_config.display_status_timers)
  5480. WBUFW(buf,0) = 0x983;
  5481. else
  5482. #elif PACKETVER >= 20090121
  5483. if (flag && battle_config.display_status_timers)
  5484. WBUFW(buf,0) = 0x43f;
  5485. else
  5486. #endif
  5487. WBUFW(buf,0) = 0x196;
  5488. WBUFW(buf,2) = type;
  5489. WBUFL(buf,4) = id;
  5490. WBUFB(buf,8) = flag;
  5491. #if PACKETVER >= 20120618
  5492. if (flag && battle_config.display_status_timers) {
  5493. if (tick <= 0)
  5494. tick = 9999; // this is indeed what official servers do
  5495. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5496. WBUFL(buf,13) = client_tick(tick);
  5497. WBUFL(buf,17) = val1;
  5498. WBUFL(buf,21) = val2;
  5499. WBUFL(buf,25) = val3;
  5500. }
  5501. #elif PACKETVER >= 20090121
  5502. if (flag && battle_config.display_status_timers) {
  5503. if (tick <= 0)
  5504. tick = 9999; // this is indeed what official servers do
  5505. WBUFL(buf,9) = client_tick(tick);
  5506. WBUFL(buf,13) = val1;
  5507. WBUFL(buf,17) = val2;
  5508. WBUFL(buf,21) = val3;
  5509. }
  5510. #endif
  5511. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5512. }
  5513. /* Sends status effect to clients around the bl
  5514. * @param bl Object that has the effect
  5515. * @param type Status icon see enum efst_type
  5516. * @param flag 1:Active, 0:Deactive
  5517. * @param tick Duration in ms
  5518. * @param val1
  5519. * @param val2
  5520. * @param val3
  5521. */
  5522. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5523. struct map_session_data *sd = NULL;
  5524. if (type == EFST_BLANK) //It shows nothing on the client...
  5525. return;
  5526. if (type == EFST_POSTDELAY && tick == 0)
  5527. return;
  5528. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5529. return;
  5530. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5531. // Older clients display normal riding icon.
  5532. if (type == EFST_MADOGEAR)
  5533. type = EFST_RIDING;
  5534. #endif
  5535. nullpo_retv(bl);
  5536. sd = BL_CAST(BL_PC, bl);
  5537. if (!(status_efst_get_bl_type((efst_type)type)&bl->type)) // only send status changes that actually matter to the client
  5538. return;
  5539. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5540. }
  5541. /**
  5542. * Send any active EFST to those around.
  5543. * @param tbl: Unit to send the packet to
  5544. * @param bl: Objects walking into view
  5545. * @param target: Client send type
  5546. */
  5547. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5548. unsigned char i;
  5549. struct sc_display_entry **sc_display;
  5550. unsigned char sc_display_count;
  5551. bool spheres_sent;
  5552. nullpo_retv(bl);
  5553. switch( bl->type ){
  5554. case BL_PC: {
  5555. struct map_session_data* sd = (struct map_session_data*)bl;
  5556. sc_display = sd->sc_display;
  5557. sc_display_count = sd->sc_display_count;
  5558. spheres_sent = !sd->state.connect_new;
  5559. }
  5560. break;
  5561. case BL_NPC: {
  5562. struct npc_data* nd = (struct npc_data*)bl;
  5563. sc_display = nd->sc_display;
  5564. sc_display_count = nd->sc_display_count;
  5565. spheres_sent = true;
  5566. }
  5567. break;
  5568. default:
  5569. return;
  5570. }
  5571. for (i = 0; i < sc_display_count; i++) {
  5572. enum sc_type type = sc_display[i]->type;
  5573. struct status_change *sc = status_get_sc(bl);
  5574. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5575. t_tick tick = 0;
  5576. if (td)
  5577. tick = DIFF_TICK(td->tick, gettick());
  5578. // Status changes that need special handling
  5579. switch( type ){
  5580. case SC_SPHERE_1:
  5581. case SC_SPHERE_2:
  5582. case SC_SPHERE_3:
  5583. case SC_SPHERE_4:
  5584. case SC_SPHERE_5:
  5585. if( spheres_sent ){
  5586. target = AREA_WOS;
  5587. }
  5588. break;
  5589. case SC_HELLS_PLANT:
  5590. if( sc && sc->data[type] ){
  5591. tick = sc->data[type]->val4;
  5592. }
  5593. break;
  5594. }
  5595. #if PACKETVER > 20120418
  5596. 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);
  5597. #else
  5598. 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);
  5599. #endif
  5600. }
  5601. }
  5602. /// Notifies the client when a player enters the screen with an active EFST.
  5603. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5604. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5605. 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) {
  5606. #if PACKETVER >= 20111108
  5607. unsigned char buf[32];
  5608. #if PACKETVER >= 20120618
  5609. const int cmd = 0x984;
  5610. #elif PACKETVER >= 20111108
  5611. const int cmd = 0x8ff;
  5612. #endif
  5613. int offset = 0;
  5614. if (type == EFST_BLANK)
  5615. return;
  5616. nullpo_retv(bl);
  5617. if (tick <= 0)
  5618. tick = 9999;
  5619. WBUFW(buf,offset + 0) = cmd;
  5620. WBUFL(buf,offset + 2) = tid;
  5621. WBUFW(buf,offset + 6) = type;
  5622. #if PACKETVER >= 20111108
  5623. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5624. #if PACKETVER >= 20120618
  5625. WBUFL(buf,offset + 12) = client_tick(tick);
  5626. offset += 4;
  5627. #endif
  5628. WBUFL(buf,offset + 12) = val1;
  5629. WBUFL(buf,offset + 16) = val2;
  5630. WBUFL(buf,offset + 20) = val3;
  5631. #endif
  5632. clif_send(buf,packet_len(cmd),bl,target);
  5633. #endif
  5634. }
  5635. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5636. /// 008e <packet len>.W <message>.?B
  5637. void clif_displaymessage(const int fd, const char* mes)
  5638. {
  5639. nullpo_retv(mes);
  5640. if( session_isActive( fd ) ){
  5641. char *message, *line;
  5642. message = aStrdup(mes);
  5643. line = strtok(message, "\n");
  5644. while(line != NULL) {
  5645. #if PACKETVER == 20141022
  5646. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5647. /** so we redirect to ZC_NPC_CHAT **/
  5648. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5649. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5650. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5651. if (len > 0) {
  5652. WFIFOHEAD(fd, 13 + len);
  5653. WFIFOW(fd, 0) = 0x2C1;
  5654. WFIFOW(fd, 2) = 13 + len;
  5655. WFIFOL(fd, 4) = 0;
  5656. WFIFOL(fd, 8) = color;
  5657. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5658. WFIFOSET(fd, WFIFOW(fd, 2));
  5659. }
  5660. #else
  5661. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5662. int len = strnlen(line, CHAT_SIZE_MAX);
  5663. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5664. WFIFOHEAD(fd, 5 + len);
  5665. WFIFOW(fd,0) = 0x8e;
  5666. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5667. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5668. WFIFOSET(fd, 5 + len);
  5669. }
  5670. #endif
  5671. line = strtok(NULL, "\n");
  5672. }
  5673. aFree(message);
  5674. }
  5675. }
  5676. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5677. /// 009a <packet len>.W <message>.?B
  5678. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5679. {
  5680. nullpo_retv(mes);
  5681. if (len < 2)
  5682. return;
  5683. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5684. p->packetType = HEADER_ZC_BROADCAST;
  5685. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5686. if( ( type&BC_BLUE ) != 0 ){
  5687. const char* color = "blue";
  5688. int16 length = (int16)strlen( color );
  5689. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5690. strcpy( p->message, color );
  5691. strncpy( &p->message[length], mes, len );
  5692. p->PacketLength += length;
  5693. }else if( ( type&BC_WOE ) != 0 ){
  5694. const char* color = "ssss";
  5695. int16 length = (int16)strlen( color );
  5696. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5697. strcpy( p->message, color );
  5698. strncpy( &p->message[length], mes, len );
  5699. p->PacketLength += length;
  5700. }else{
  5701. strncpy( p->message, mes, len );
  5702. }
  5703. clif_send( p, p->PacketLength, bl, target );
  5704. }
  5705. /*==========================================
  5706. * Displays a message on a 'bl' to all it's nearby clients
  5707. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5708. *------------------------------------------*/
  5709. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5710. nullpo_retv(bl);
  5711. nullpo_retv(message);
  5712. int16 len = (int16)( strlen( message ) + 1 );
  5713. if( len > CHAT_SIZE_MAX ) {
  5714. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5715. len = CHAT_SIZE_MAX;
  5716. }
  5717. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5718. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5719. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5720. p->GID = bl->id;
  5721. safestrncpy( p->Message, message, len );
  5722. clif_send( p, p->PacketLength, bl, target );
  5723. }
  5724. /// Send broadcast message with font formatting.
  5725. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5726. void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  5727. {
  5728. nullpo_retv(mes);
  5729. if (len < 2)
  5730. return;
  5731. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5732. p->packetType = HEADER_ZC_BROADCAST2;
  5733. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5734. p->fontColor = fontColor;
  5735. p->fontType = fontType;
  5736. p->fontSize = fontSize;
  5737. p->fontAlign = fontAlign;
  5738. p->fontY = fontY;
  5739. strncpy( p->message, mes, len );
  5740. clif_send( p, p->PacketLength, bl, target );
  5741. }
  5742. /*
  5743. * Display *msg to all *users in channel
  5744. */
  5745. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5746. DBIterator *iter;
  5747. struct map_session_data *user;
  5748. unsigned short msg_len = 0, len = 0;
  5749. unsigned char buf[CHAT_SIZE_MAX];
  5750. if (!channel || !msg)
  5751. return;
  5752. msg_len = (unsigned short)(strlen(msg) + 1);
  5753. if( msg_len > sizeof(buf)-12 ) {
  5754. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5755. msg_len = sizeof(buf)-12;
  5756. }
  5757. WBUFW(buf,0) = 0x2C1;
  5758. WBUFW(buf,2) = (len = msg_len + 12);
  5759. WBUFL(buf,4) = 0;
  5760. WBUFL(buf,8) = color;
  5761. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5762. iter = db_iterator(channel->users);
  5763. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5764. clif_send(buf, len, &user->bl, SELF);
  5765. }
  5766. dbi_destroy(iter);
  5767. }
  5768. /// Displays heal effect.
  5769. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5770. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5771. /// var id:
  5772. /// 5 = HP (SP_HP)
  5773. /// 7 = SP (SP_SP)
  5774. /// ? = ignored
  5775. void clif_heal(int fd,int type,int val) {
  5776. #if PACKETVER < 20141022
  5777. const int cmd = 0x13d;
  5778. #else
  5779. const int cmd = 0xa27;
  5780. #endif
  5781. WFIFOHEAD(fd, packet_len(cmd));
  5782. WFIFOW(fd,0) = cmd;
  5783. WFIFOW(fd,2) = type;
  5784. #if PACKETVER < 20141022
  5785. WFIFOW(fd,4) = min(val, INT16_MAX);
  5786. #else
  5787. WFIFOL(fd,4) = min(val, INT32_MAX);
  5788. #endif
  5789. WFIFOSET(fd, packet_len(cmd));
  5790. }
  5791. /// Displays resurrection effect (ZC_RESURRECTION).
  5792. /// 0148 <id>.L <type>.W
  5793. /// type:
  5794. /// ignored
  5795. void clif_resurrection(struct block_list *bl,int type)
  5796. {
  5797. unsigned char buf[16];
  5798. nullpo_retv(bl);
  5799. WBUFW(buf,0)=0x148;
  5800. WBUFL(buf,2)=bl->id;
  5801. WBUFW(buf,6)=0;
  5802. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5803. if (disguised(bl))
  5804. clif_spawn(bl);
  5805. }
  5806. /// Sets the map property
  5807. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5808. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5809. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5810. {
  5811. #if PACKETVER >= 20121010
  5812. short cmd = 0x99b;
  5813. unsigned char buf[8];
  5814. #else
  5815. short cmd = 0x199;
  5816. unsigned char buf[4];
  5817. #endif
  5818. WBUFW(buf,0)=cmd;
  5819. WBUFW(buf,2)=property;
  5820. #if PACKETVER >= 20121010
  5821. struct map_data *mapdata = map_getmapdata(bl->m);
  5822. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  5823. WBUFL(buf,4) = ((mapdata->flag[MF_PVP] || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5824. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5825. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5826. ((mapdata->flag[MF_FORCEMINEFFECT] || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5827. ((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
  5828. ((mapdata->flag[MF_PVP])<<5)| // COUNT_PK - Show the PvP counter
  5829. ((mapdata->flag[MF_PARTYLOCK])<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5830. ((mapdata->flag[MF_BATTLEGROUND])<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5831. ((mapdata->flag[MF_NOCOSTUME])<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5832. ((!mapdata->flag[MF_NOUSECART])<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5833. ((!mapdata->flag[MF_NOSUNMOONSTARMIRACLE])<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5834. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5835. #endif
  5836. clif_send(buf,packet_len(cmd),bl,t);
  5837. }
  5838. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5839. /// 01d6 <type>.W
  5840. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5841. {
  5842. int fd;
  5843. nullpo_retv(sd);
  5844. fd=sd->fd;
  5845. WFIFOHEAD(fd,packet_len(0x1D6));
  5846. WFIFOW(fd,0)=0x1D6;
  5847. WFIFOW(fd,2)=type;
  5848. WFIFOSET(fd,packet_len(0x1D6));
  5849. }
  5850. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5851. /// 019a <id>.L <ranking>.L <total>.L
  5852. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5853. {
  5854. if(type == 2) {
  5855. int fd = sd->fd;
  5856. WFIFOHEAD(fd,packet_len(0x19a));
  5857. WFIFOW(fd,0) = 0x19a;
  5858. WFIFOL(fd,2) = sd->bl.id;
  5859. WFIFOL(fd,6) = pvprank;
  5860. WFIFOL(fd,10) = pvpnum;
  5861. WFIFOSET(fd,packet_len(0x19a));
  5862. } else {
  5863. unsigned char buf[32];
  5864. WBUFW(buf,0) = 0x19a;
  5865. WBUFL(buf,2) = sd->bl.id;
  5866. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5867. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5868. else
  5869. WBUFL(buf,6) = pvprank;
  5870. WBUFL(buf,10) = pvpnum;
  5871. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5872. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5873. else if(!type)
  5874. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5875. else
  5876. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5877. }
  5878. }
  5879. /*==========================================
  5880. *
  5881. *------------------------------------------*/
  5882. void clif_map_property_mapall(int map_idx, enum map_property property)
  5883. {
  5884. struct block_list bl;
  5885. bl.id = 0;
  5886. bl.type = BL_NUL;
  5887. bl.m = map_idx;
  5888. clif_map_property( &bl, property, ALL_SAMEMAP );
  5889. }
  5890. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5891. /// 0188 <result>.W <index>.W <refine>.W
  5892. /// result:
  5893. /// 0 = success
  5894. /// 1 = failure
  5895. /// 2 = downgrade
  5896. void clif_refine(int fd, int fail, int index, int val)
  5897. {
  5898. WFIFOHEAD(fd,packet_len(0x188));
  5899. WFIFOW(fd,0)=0x188;
  5900. WFIFOW(fd,2)=fail;
  5901. WFIFOW(fd,4)=index+2;
  5902. WFIFOW(fd,6)=val;
  5903. WFIFOSET(fd,packet_len(0x188));
  5904. }
  5905. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5906. /// 0223 <result>.L <nameid>.W
  5907. /// result:
  5908. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5909. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5910. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5911. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5912. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5913. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5914. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5915. p.result = result;
  5916. p.itemId = client_nameid( item_id );
  5917. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5918. }
  5919. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5920. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5921. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5922. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5923. int fd;
  5924. nullpo_retv(sd);
  5925. fd = sd->fd;
  5926. #if PACKETVER < 20091104
  5927. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5928. WFIFOW(fd,0) = 0x97;
  5929. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5930. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5931. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5932. WFIFOSET(fd,WFIFOW(fd,2));
  5933. #else
  5934. struct map_session_data *ssd = map_nick2sd(nick,false);
  5935. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5936. WFIFOW(fd,0) = 0x97;
  5937. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5938. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5939. // If it is not a message from the server or a player from another map-server
  5940. if( ssd ){
  5941. gmlvl = pc_get_group_level(ssd);
  5942. }
  5943. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5944. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5945. WFIFOSET(fd,WFIFOW(fd,2));
  5946. #endif
  5947. }
  5948. /// Inform the player about the result of his whisper action
  5949. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5950. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5951. /// result:
  5952. /// 0 = success to send wisper
  5953. /// 1 = target character is not loged in
  5954. /// 2 = ignored by target
  5955. /// 3 = everyone ignored by target
  5956. void clif_wis_end(int fd, int result)
  5957. {
  5958. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5959. #if PACKETVER < 20131223
  5960. const int cmd = 0x98;
  5961. #else
  5962. const int cmd = 0x9df;
  5963. #endif
  5964. if (!sd)
  5965. return;
  5966. WFIFOHEAD(fd,packet_len(cmd));
  5967. WFIFOW(fd,0) = cmd;
  5968. WFIFOB(fd,2) = (char)result;
  5969. #if PACKETVER >= 20131223
  5970. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5971. #endif
  5972. WFIFOSET(fd,packet_len(cmd));
  5973. }
  5974. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5975. /// 0194 <char id>.L <name>.24B
  5976. /// 0af7 <flag>.W <char id>.L <name>.24B
  5977. void clif_solved_charname(int fd, int charid, const char* name)
  5978. {
  5979. #if PACKETVER >= 20180221
  5980. WFIFOHEAD(fd,packet_len(0xaf7));
  5981. WFIFOW(fd,0) = 0xaf7;
  5982. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5983. WFIFOL(fd,4) = charid;
  5984. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5985. WFIFOSET(fd,packet_len(0x0af7));
  5986. #else
  5987. WFIFOHEAD(fd,packet_len(0x194));
  5988. WFIFOW(fd,0)=0x194;
  5989. WFIFOL(fd,2)=charid;
  5990. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5991. WFIFOSET(fd,packet_len(0x194));
  5992. #endif
  5993. }
  5994. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5995. /// 017b <packet len>.W { <name id>.W }*
  5996. void clif_use_card(struct map_session_data *sd,int idx)
  5997. {
  5998. int i,c,ep;
  5999. int fd=sd->fd;
  6000. nullpo_retv(sd);
  6001. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6002. return;
  6003. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6004. return; //Avoid parsing invalid item indexes (no card/no item)
  6005. ep=sd->inventory_data[idx]->equip;
  6006. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6007. WFIFOW(fd,0)=0x17b;
  6008. for(i=c=0;i<MAX_INVENTORY;i++){
  6009. int j;
  6010. if(sd->inventory_data[i] == NULL)
  6011. continue;
  6012. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6013. continue;
  6014. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6015. continue;
  6016. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6017. continue;
  6018. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6019. continue;
  6020. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6021. continue;
  6022. 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.
  6023. continue;
  6024. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6025. if( j == sd->inventory_data[i]->slots ) // No room
  6026. continue;
  6027. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6028. continue;
  6029. WFIFOW(fd,4+c*2)=i+2;
  6030. c++;
  6031. }
  6032. if( !c ) return; // no item is available for card insertion
  6033. WFIFOW(fd,2)=4+c*2;
  6034. WFIFOSET(fd,WFIFOW(fd,2));
  6035. }
  6036. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6037. /// 017d <equip index>.W <card index>.W <result>.B
  6038. /// result:
  6039. /// 0 = success
  6040. /// 1 = failure
  6041. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  6042. {
  6043. int fd;
  6044. nullpo_retv(sd);
  6045. fd=sd->fd;
  6046. WFIFOHEAD(fd,packet_len(0x17d));
  6047. WFIFOW(fd,0)=0x17d;
  6048. WFIFOW(fd,2)=idx_equip+2;
  6049. WFIFOW(fd,4)=idx_card+2;
  6050. WFIFOB(fd,6)=flag;
  6051. WFIFOSET(fd,packet_len(0x17d));
  6052. }
  6053. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6054. /// 0177 <packet len>.W { <index>.W }*
  6055. void clif_item_identify_list(struct map_session_data *sd)
  6056. {
  6057. int i,c;
  6058. int fd;
  6059. nullpo_retv(sd);
  6060. fd=sd->fd;
  6061. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6062. WFIFOW(fd,0)=0x177;
  6063. for(i=c=0;i<MAX_INVENTORY;i++){
  6064. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6065. WFIFOW(fd,c*2+4)=client_index(i);
  6066. c++;
  6067. }
  6068. }
  6069. if(c > 0) {
  6070. WFIFOW(fd,2)=c*2+4;
  6071. WFIFOSET(fd,WFIFOW(fd,2));
  6072. sd->menuskill_id = MC_IDENTIFY;
  6073. sd->menuskill_val = c;
  6074. sd->state.workinprogress = WIP_DISABLE_ALL;
  6075. }
  6076. }
  6077. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6078. /// 0179 <index>.W <result>.B
  6079. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  6080. {
  6081. int fd;
  6082. nullpo_retv(sd);
  6083. fd=sd->fd;
  6084. WFIFOHEAD(fd,packet_len(0x179));
  6085. WFIFOW(fd, 0)=0x179;
  6086. WFIFOW(fd, 2)=idx+2;
  6087. WFIFOB(fd, 4)=flag;
  6088. WFIFOSET(fd,packet_len(0x179));
  6089. }
  6090. /// Presents a list of items that can be repaired.
  6091. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6092. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  6093. nullpo_retv( sd );
  6094. nullpo_retv( dstsd );
  6095. int fd = sd->fd;
  6096. if( !session_isActive( fd ) ){
  6097. return;
  6098. }
  6099. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6100. // Preallocate the maximum size
  6101. WFIFOHEAD( fd, len );
  6102. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6103. int c = 0;
  6104. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6105. 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)){
  6106. p->items[c].index = i;
  6107. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6108. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6109. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6110. c++;
  6111. }
  6112. }
  6113. if( c > 0 ){
  6114. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6115. // Recalculate real length
  6116. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6117. p->packetLength = len;
  6118. WFIFOSET( fd, len );
  6119. sd->menuskill_id = BS_REPAIRWEAPON;
  6120. sd->menuskill_val = dstsd->bl.id;
  6121. sd->menuskill_val2 = lv;
  6122. }else{
  6123. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6124. }
  6125. }
  6126. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6127. /// 01fe <index>.W <result>.B
  6128. /// index:
  6129. /// ignored (inventory index)
  6130. /// result:
  6131. /// 0 = Item repair success.
  6132. /// 1 = Item repair failure.
  6133. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  6134. {
  6135. int fd;
  6136. nullpo_retv(sd);
  6137. fd = sd->fd;
  6138. WFIFOHEAD(fd,packet_len(0x1fe));
  6139. WFIFOW(fd, 0)=0x1fe;
  6140. WFIFOW(fd, 2)=idx+2;
  6141. WFIFOB(fd, 4)=flag;
  6142. WFIFOSET(fd,packet_len(0x1fe));
  6143. }
  6144. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6145. /// 02bb <equip location>.W <account id>.L
  6146. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  6147. {
  6148. int fd = sd->fd;
  6149. WFIFOHEAD(fd,packet_len(0x2bb));
  6150. WFIFOW(fd,0) = 0x2bb;
  6151. WFIFOW(fd,2) = position;
  6152. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6153. WFIFOSET(fd,packet_len(0x2bb));
  6154. }
  6155. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6156. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6157. void clif_item_refine_list( struct map_session_data *sd ){
  6158. nullpo_retv( sd );
  6159. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6160. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6161. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6162. int refine_item[MAX_WEAPON_LEVEL];
  6163. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6164. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6165. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6166. #ifdef RENEWAL
  6167. refine_item[4] = -1;
  6168. #endif
  6169. int count = 0;
  6170. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6171. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6172. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6173. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6174. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6175. p->items[count].index = client_index( i );
  6176. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6177. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6178. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6179. count++;
  6180. }
  6181. }
  6182. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6183. clif_send( p, p->packetLength, &sd->bl, SELF );
  6184. if( count > 0 ){
  6185. sd->menuskill_id = WS_WEAPONREFINE;
  6186. sd->menuskill_val = skill_lv;
  6187. }
  6188. }
  6189. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6190. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6191. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6192. nullpo_retv( sd );
  6193. struct PACKET_ZC_AUTORUN_SKILL p;
  6194. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6195. p.skill_id = skill_id;
  6196. p.skill_type = skill_get_inf( skill_id );
  6197. p.skill_lv = skill_lv;
  6198. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6199. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6200. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6201. p.up_flag = false;
  6202. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6203. }
  6204. /// Adds an item to character's cart.
  6205. /// 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)
  6206. /// 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)
  6207. /// 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)
  6208. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6209. nullpo_retv( sd );
  6210. int fd = sd->fd;
  6211. if( !session_isActive( fd ) ){
  6212. return;
  6213. }
  6214. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6215. return;
  6216. }
  6217. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6218. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6219. p.index = client_index( n );
  6220. p.amount = amount;
  6221. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6222. #if PACKETVER >= 5
  6223. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6224. #endif
  6225. p.identified = sd->cart.u.items_cart[n].identify;
  6226. p.damaged = sd->cart.u.items_cart[n].attribute;
  6227. p.refine = sd->cart.u.items_cart[n].refine;
  6228. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6229. #if PACKETVER >= 20150226
  6230. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6231. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6232. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6233. #endif
  6234. #endif
  6235. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6236. }
  6237. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6238. /* Acknowledge an item have been added to cart
  6239. * 012c <result>B
  6240. * result :
  6241. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6242. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6243. */
  6244. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6245. {
  6246. int fd;
  6247. unsigned char *buf;
  6248. nullpo_retv(sd);
  6249. fd = sd->fd;
  6250. buf = WFIFOP(fd,0);
  6251. WBUFW(buf,0) = 0x12c;
  6252. WBUFB(buf,2) = flag;
  6253. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6254. }
  6255. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6256. void clif_bank_open(struct map_session_data *sd){
  6257. int fd;
  6258. nullpo_retv(sd);
  6259. fd = sd->fd;
  6260. WFIFOHEAD(fd,4);
  6261. WFIFOW(fd,0) = 0x09b7;
  6262. WFIFOW(fd,2) = 0;
  6263. WFIFOSET(fd,4);
  6264. }
  6265. /*
  6266. * Request to Open the banking system
  6267. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6268. */
  6269. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6270. //TODO check if preventing trade or stuff like that
  6271. //also mark something in case char ain't available for saving, should we check now ?
  6272. nullpo_retv(sd);
  6273. if( !battle_config.feature_banking ) {
  6274. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6275. return;
  6276. }
  6277. else {
  6278. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6279. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6280. if(sd->status.account_id == aid){
  6281. sd->state.banking = 1;
  6282. //request save ?
  6283. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6284. //on succes open bank ?
  6285. clif_bank_open(sd);
  6286. }
  6287. }
  6288. }
  6289. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6290. void clif_bank_close(struct map_session_data *sd){
  6291. int fd;
  6292. nullpo_retv(sd);
  6293. fd = sd->fd;
  6294. WFIFOHEAD(fd,4);
  6295. WFIFOW(fd,0) = 0x09B9;
  6296. WFIFOW(fd,2) = 0;
  6297. WFIFOSET(fd,4);
  6298. }
  6299. /*
  6300. * Request to close the banking system
  6301. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6302. */
  6303. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6304. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6305. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6306. nullpo_retv(sd);
  6307. if( !battle_config.feature_banking ) {
  6308. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6309. //still allow to go trough to not stuck player if we have disable it while they was in
  6310. }
  6311. if(sd->status.account_id == aid){
  6312. sd->state.banking = 0;
  6313. clif_bank_close(sd);
  6314. }
  6315. }
  6316. /*
  6317. * Display how much we got in bank (I suppose)
  6318. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6319. */
  6320. void clif_Bank_Check(struct map_session_data* sd) {
  6321. unsigned char buf[13];
  6322. struct s_packet_db* info;
  6323. int16 len;
  6324. int cmd = 0;
  6325. nullpo_retv(sd);
  6326. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6327. if(!cmd) cmd = 0x09A6; //default
  6328. info = &packet_db[cmd];
  6329. len = info->len;
  6330. if(!len) return; //version as packet disable
  6331. // sd->state.banking = 1; //mark opening and closing
  6332. WBUFW(buf,0) = cmd;
  6333. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6334. WBUFW(buf,info->pos[1]) = 0; //reason
  6335. clif_send(buf,len,&sd->bl,SELF);
  6336. }
  6337. /*
  6338. * Requesting the data in bank
  6339. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6340. */
  6341. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6342. nullpo_retv(sd);
  6343. if( !battle_config.feature_banking ) {
  6344. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6345. return;
  6346. }
  6347. else {
  6348. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6349. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6350. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6351. clif_Bank_Check(sd);
  6352. }
  6353. }
  6354. /*
  6355. * Acknowledge of deposit some money in bank
  6356. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6357. */
  6358. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6359. unsigned char buf[17];
  6360. struct s_packet_db* info;
  6361. int16 len;
  6362. int cmd =0;
  6363. nullpo_retv(sd);
  6364. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6365. if(!cmd) cmd = 0x09A8;
  6366. info = &packet_db[cmd];
  6367. len = info->len;
  6368. if(!len) return; //version as packet disable
  6369. WBUFW(buf,0) = cmd;
  6370. WBUFW(buf,info->pos[0]) = (short)reason;
  6371. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6372. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6373. clif_send(buf,len,&sd->bl,SELF);
  6374. }
  6375. /*
  6376. * Request saving some money in bank
  6377. * @author : original [Yommy/Hercules]
  6378. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6379. */
  6380. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6381. nullpo_retv(sd);
  6382. if( !battle_config.feature_banking ) {
  6383. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6384. return;
  6385. }
  6386. else {
  6387. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6388. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6389. int money = RFIFOL(fd,info->pos[1]);
  6390. if(sd->status.account_id == aid){
  6391. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6392. clif_bank_deposit(sd,reason);
  6393. }
  6394. }
  6395. }
  6396. /*
  6397. * Acknowledge of withdrawing some money from bank
  6398. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6399. */
  6400. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6401. unsigned char buf[17];
  6402. struct s_packet_db* info;
  6403. int16 len;
  6404. int cmd;
  6405. nullpo_retv(sd);
  6406. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6407. if(!cmd) cmd = 0x09AA;
  6408. info = &packet_db[cmd];
  6409. len = info->len;
  6410. if(!len) return; //version as packet disable
  6411. WBUFW(buf,0) = cmd;
  6412. WBUFW(buf,info->pos[0]) = (short)reason;
  6413. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6414. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6415. clif_send(buf,len,&sd->bl,SELF);
  6416. }
  6417. /*
  6418. * Request Withdrawing some money from bank
  6419. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6420. */
  6421. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6422. nullpo_retv(sd);
  6423. if( !battle_config.feature_banking ) {
  6424. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6425. return;
  6426. }
  6427. else {
  6428. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6429. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6430. int money = RFIFOL(fd,info->pos[1]);
  6431. if(sd->status.account_id == aid){
  6432. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6433. clif_bank_withdraw(sd,reason);
  6434. }
  6435. }
  6436. }
  6437. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6438. /// 0125 <index>.W <amount>.L
  6439. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6440. {
  6441. int fd;
  6442. nullpo_retv(sd);
  6443. fd=sd->fd;
  6444. WFIFOHEAD(fd,packet_len(0x125));
  6445. WFIFOW(fd,0)=0x125;
  6446. WFIFOW(fd,2)=n+2;
  6447. WFIFOL(fd,4)=amount;
  6448. WFIFOSET(fd,packet_len(0x125));
  6449. }
  6450. /// Opens the shop creation menu (ZC_OPENSTORE).
  6451. /// 012d <num>.W
  6452. /// num:
  6453. /// number of allowed item slots
  6454. void clif_openvendingreq(struct map_session_data* sd, int num)
  6455. {
  6456. int fd;
  6457. nullpo_retv(sd);
  6458. fd = sd->fd;
  6459. WFIFOHEAD(fd,packet_len(0x12d));
  6460. WFIFOW(fd,0) = 0x12d;
  6461. WFIFOW(fd,2) = num;
  6462. WFIFOSET(fd,packet_len(0x12d));
  6463. }
  6464. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6465. /// 0131 <owner id>.L <message>.80B
  6466. void clif_showvendingboard( struct map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6467. if( tbl == nullptr ){
  6468. tbl = &sd.bl;
  6469. target = AREA_WOS;
  6470. }
  6471. struct PACKET_ZC_STORE_ENTRY p = {};
  6472. p.packetType = HEADER_ZC_STORE_ENTRY;
  6473. p.makerAID = sd.status.account_id;
  6474. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6475. clif_send( &p, sizeof( p ), tbl, target );
  6476. }
  6477. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6478. /// 0132 <owner id>.L
  6479. void clif_closevendingboard(struct block_list* bl, int fd)
  6480. {
  6481. unsigned char buf[16];
  6482. nullpo_retv(bl);
  6483. WBUFW(buf,0) = 0x132;
  6484. WBUFL(buf,2) = bl->id;
  6485. if( session_isActive(fd) ) {
  6486. WFIFOHEAD(fd,packet_len(0x132));
  6487. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6488. WFIFOSET(fd,packet_len(0x132));
  6489. } else {
  6490. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6491. }
  6492. }
  6493. /// Sends a list of items in a shop.
  6494. /// 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)
  6495. /// 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)
  6496. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6497. nullpo_retv( sd );
  6498. nullpo_retv( vsd );
  6499. nullpo_retv( vsd->vending );
  6500. int fd = sd->fd;
  6501. if( !session_isActive( fd ) ){
  6502. return;
  6503. }
  6504. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6505. WFIFOHEAD( fd, len );
  6506. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6507. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6508. p->packetLength = len;
  6509. p->AID = vsd->status.account_id;
  6510. #if PACKETVER >= 20100105
  6511. p->venderId = vsd->vender_id;
  6512. #endif
  6513. for( int i = 0; i < vsd->vend_num; i++ ){
  6514. int index = vsd->vending[i].index;
  6515. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6516. p->items[i].price = vsd->vending[i].value;
  6517. p->items[i].amount = vsd->vending[i].amount;
  6518. p->items[i].index = client_index( index );
  6519. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6520. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6521. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6522. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6523. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6524. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6525. #if PACKETVER >= 20150226
  6526. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6527. #if PACKETVER >= 20160921
  6528. p->items[i].location = pc_equippoint_sub( sd, data );
  6529. p->items[i].viewSprite = data->look;
  6530. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6531. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6532. #endif
  6533. #endif
  6534. #endif
  6535. }
  6536. WFIFOSET( fd, len );
  6537. }
  6538. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6539. /// 0135 <index>.W <amount>.W <result>.B
  6540. /// result:
  6541. /// 0 = success
  6542. /// 1 = not enough zeny
  6543. /// 2 = overweight
  6544. /// 4 = out of stock
  6545. /// 5 = "cannot use an npc shop while in a trade"
  6546. /// 6 = Because the store information was incorrect the item was not purchased.
  6547. /// 7 = No sales information.
  6548. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6549. {
  6550. int fd;
  6551. nullpo_retv(sd);
  6552. fd = sd->fd;
  6553. WFIFOHEAD(fd,packet_len(0x135));
  6554. WFIFOW(fd,0) = 0x135;
  6555. WFIFOW(fd,2) = index+2;
  6556. WFIFOW(fd,4) = amount;
  6557. WFIFOB(fd,6) = fail;
  6558. WFIFOSET(fd,packet_len(0x135));
  6559. }
  6560. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6561. /// 0a28 <Result>.B
  6562. /// result:
  6563. /// 0 = Successed
  6564. /// 1 = Failed
  6565. void clif_openvending_ack(struct map_session_data* sd, int result)
  6566. {
  6567. int fd;
  6568. nullpo_retv(sd);
  6569. fd = sd->fd;
  6570. WFIFOHEAD(fd, 3);
  6571. WFIFOW(fd,0) = 0xa28;
  6572. WFIFOB(fd,2) = result;
  6573. WFIFOSET(fd, 3);
  6574. }
  6575. /// Shop creation success.
  6576. /// 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)
  6577. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6578. nullpo_retv( sd );
  6579. nullpo_retv( vending );
  6580. int fd = sd->fd;
  6581. if( !session_isActive( fd ) ){
  6582. return;
  6583. }
  6584. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6585. WFIFOHEAD( fd, len );
  6586. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6587. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6588. p->packetLength = len;
  6589. p->AID = id;
  6590. for( int i = 0; i < sd->vend_num; i++ ) {
  6591. int index = vending[i].index;
  6592. p->items[i].price = vending[i].value;
  6593. p->items[i].index = client_index( index );
  6594. p->items[i].amount = vending[i].amount;
  6595. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6596. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6597. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6598. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6599. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6600. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6601. #if PACKETVER >= 20150226
  6602. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6603. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6604. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6605. #endif
  6606. #endif
  6607. }
  6608. WFIFOSET( fd, len );
  6609. #if PACKETVER >= 20141022
  6610. /// 0 = Successed
  6611. /// 1 = Failed
  6612. clif_openvending_ack( sd, 0 );
  6613. #endif
  6614. }
  6615. /// Inform merchant that someone has bought an item.
  6616. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6617. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6618. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6619. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6620. const int cmd = 0x137;
  6621. #else
  6622. const int cmd = 0x9e5;
  6623. #endif
  6624. int fd = sd->fd;
  6625. nullpo_retv(sd);
  6626. WFIFOHEAD(fd,packet_len(cmd));
  6627. WFIFOW(fd,0) = cmd;
  6628. WFIFOW(fd,2) = index+2;
  6629. WFIFOW(fd,4) = amount;
  6630. #if PACKETVER >= 20141016
  6631. WFIFOL(fd,6) = char_id; // GID
  6632. WFIFOL(fd,10) = (int)time(NULL); // Date
  6633. WFIFOL(fd,14) = zeny; // zeny
  6634. #endif
  6635. WFIFOSET(fd,packet_len(cmd));
  6636. }
  6637. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6638. /// 00fa <result>.B
  6639. /// result:
  6640. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6641. /// 1 = MsgStringTable[78]="party name already exists"
  6642. /// 2 = MsgStringTable[79]="already in a party"
  6643. /// 3 = cannot organize parties on this map
  6644. /// ? = nothing
  6645. void clif_party_created( struct map_session_data& sd, int result ){
  6646. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6647. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6648. p.result = result;
  6649. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6650. }
  6651. /// Adds new member to a party.
  6652. /// 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)
  6653. /// 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)
  6654. /// 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)
  6655. /// role:
  6656. /// 0 = leader
  6657. /// 1 = normal
  6658. /// state:
  6659. /// 0 = connected
  6660. /// 1 = disconnected
  6661. void clif_party_member_info( struct party_data& party, struct map_session_data& sd ){
  6662. int id = party_getmemberid( &party, &sd );
  6663. if( id < 0 ){
  6664. return;
  6665. }
  6666. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6667. p.packetType = partymemberinfo;
  6668. p.AID = sd.status.account_id;
  6669. #if PACKETVER >= 20171207
  6670. p.GID = sd.status.char_id;
  6671. #endif
  6672. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6673. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6674. p.class_ = sd.status.class_;
  6675. p.baseLevel = sd.status.base_level;
  6676. #endif
  6677. p.x = sd.bl.x;
  6678. p.y = sd.bl.y;
  6679. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6680. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6681. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6682. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6683. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6684. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6685. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6686. }
  6687. /// Sends party information (ZC_GROUP_LIST).
  6688. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6689. /// role:
  6690. /// 0 = leader
  6691. /// 1 = normal
  6692. /// state:
  6693. /// 0 = connected
  6694. /// 1 = disconnected
  6695. /// 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
  6696. void clif_party_info( struct party_data& party, struct map_session_data* sd ){
  6697. send_target target;
  6698. if( sd == nullptr ){
  6699. sd = party_getavailablesd( &party );
  6700. if( sd == nullptr ){
  6701. // Nobody is online to notify
  6702. return;
  6703. }
  6704. // Send to whole party
  6705. target = PARTY;
  6706. }else{
  6707. // Send only to self
  6708. target = SELF;
  6709. }
  6710. struct PACKET_ZC_GROUP_LIST* p = (struct PACKET_ZC_GROUP_LIST*)packet_buffer;
  6711. p->packetType = partyinfo;
  6712. p->packetLen = sizeof( *p );
  6713. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6714. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6715. struct party_member& m = party.party.member[i];
  6716. if( m.account_id == 0 ){
  6717. continue;
  6718. }
  6719. struct PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6720. member.AID = m.account_id;
  6721. #if PACKETVER >= 20171207
  6722. member.GID = m.char_id;
  6723. #endif
  6724. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6725. mapindex_getmapname_ext( mapindex_id2name( m.map ), member.mapName );
  6726. member.leader = ( m.leader ) ? 0 : 1;
  6727. member.offline = ( m.online ) ? 0 : 1;
  6728. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6729. member.class_ = m.class_;
  6730. member.baseLevel = m.lv;
  6731. #endif
  6732. c++;
  6733. p->packetLen += sizeof( member );
  6734. }
  6735. clif_send( p, p->packetLen, &sd->bl, target );
  6736. }
  6737. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6738. /// 02c9 <flag>.B
  6739. /// flag:
  6740. /// 0 = allow party invites
  6741. /// 1 = auto-deny party invites
  6742. void clif_partyinvitationstate( struct map_session_data& sd ){
  6743. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6744. struct PACKET_ZC_PARTY_CONFIG p = {};
  6745. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6746. p.denyPartyInvites = 0; // TODO: not implemented
  6747. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6748. #endif
  6749. }
  6750. /// Party invitation request.
  6751. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6752. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6753. void clif_party_invite( struct map_session_data& sd, struct map_session_data& tsd ){
  6754. struct party_data* party = party_search( sd.status.party_id );
  6755. if( party == nullptr ){
  6756. return;
  6757. }
  6758. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6759. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6760. p.GRID = party->party.party_id;
  6761. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6762. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6763. }
  6764. /// Party invite result.
  6765. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6766. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6767. /// result=0 : char is already in a party -> MsgStringTable[80]
  6768. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6769. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6770. /// result=3 : party is full -> MsgStringTable[83]
  6771. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6772. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6773. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6774. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6775. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6776. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6777. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6778. void clif_party_invite_reply( struct map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6779. #if PACKETVER < 20070904
  6780. if( reply == PARTY_REPLY_OFFLINE ){
  6781. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6782. return;
  6783. }
  6784. #endif
  6785. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6786. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6787. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6788. p.result = reply;
  6789. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6790. }
  6791. /// Updates party settings.
  6792. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6793. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6794. /// exp option:
  6795. /// 0 = exp sharing disabled
  6796. /// 1 = exp sharing enabled
  6797. /// 2 = cannot change exp sharing
  6798. ///
  6799. /// flag:
  6800. /// 0 = send to party
  6801. /// 1 = send to sd
  6802. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6803. {
  6804. unsigned char buf[16];
  6805. #if PACKETVER < 20090603
  6806. const int cmd = 0x101;
  6807. #else
  6808. const int cmd = 0x7d8;
  6809. #endif
  6810. nullpo_retv(p);
  6811. if(!sd && flag==0){
  6812. int i;
  6813. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6814. if (i < MAX_PARTY)
  6815. sd = p->data[i].sd;
  6816. }
  6817. if(!sd) return;
  6818. WBUFW(buf,0)=cmd;
  6819. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6820. #if PACKETVER >= 20090603
  6821. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6822. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6823. #endif
  6824. if(flag==0)
  6825. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6826. else
  6827. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6828. }
  6829. /**
  6830. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6831. * @param sd Send the notification for this player
  6832. * @param account_id Account ID of kicked member
  6833. * @param name Name of kicked member
  6834. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6835. * @param target Send target
  6836. **/
  6837. 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 ){
  6838. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6839. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6840. p.AID = account_id;
  6841. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6842. p.result = result;
  6843. clif_send( &p, sizeof( p ), &sd.bl, target );
  6844. }
  6845. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6846. /// 0109 <packet len>.W <account id>.L <message>.?B
  6847. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, int len ){
  6848. struct map_session_data* sd = party_getavailablesd( &party );
  6849. if( sd == nullptr ){
  6850. return;
  6851. }
  6852. if (len > CHAT_SIZE_MAX) {
  6853. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6854. len = CHAT_SIZE_MAX;
  6855. }
  6856. struct PACKET_ZC_NOTIFY_CHAT_PARTY* p = (struct PACKET_ZC_NOTIFY_CHAT_PARTY*)packet_buffer;
  6857. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6858. p->PacketLength = sizeof( *p ) + len;
  6859. p->AID = account_id;
  6860. safestrncpy( p->chatMsg, mes, len );
  6861. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6862. }
  6863. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6864. /// 0107 <account id>.L <x>.W <y>.W
  6865. void clif_party_xy( struct map_session_data& sd ){
  6866. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6867. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6868. p.AID = sd.status.account_id;
  6869. p.xPos = sd.bl.x;
  6870. p.yPos = sd.bl.y;
  6871. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6872. }
  6873. /*==========================================
  6874. * Sends x/y dot to a single fd. [Skotlex]
  6875. *------------------------------------------*/
  6876. void clif_party_xy_single( struct map_session_data& sd, struct map_session_data& tsd ){
  6877. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6878. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6879. p.AID = sd.status.account_id;
  6880. p.xPos = sd.bl.x;
  6881. p.yPos = sd.bl.y;
  6882. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6883. }
  6884. /// Updates HP bar of a party member.
  6885. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6886. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6887. void clif_party_hp( struct map_session_data& sd ){
  6888. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6889. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6890. p.AID = sd.status.account_id;
  6891. #if PACKETVER < 20100119
  6892. // To correctly display the %hp bar. [Skotlex]
  6893. if( sd.battle_status.max_hp > INT16_MAX ){
  6894. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6895. p.maxhp = 100;
  6896. }else{
  6897. p.hp = sd.battle_status.hp;
  6898. p.maxhp = sd.battle_status.max_hp;
  6899. }
  6900. #else
  6901. p.hp = sd.battle_status.hp;
  6902. p.maxhp = sd.battle_status.max_hp;
  6903. #endif
  6904. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6905. }
  6906. /// Notifies the party members of a character's death or revival.
  6907. /// 0AB2 <GID>.L <dead>.B
  6908. void clif_party_dead( struct map_session_data& sd ){
  6909. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6910. struct PACKET_ZC_GROUP_ISALIVE p = {};
  6911. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6912. p.AID = sd.status.account_id;
  6913. p.isDead = pc_isdead( &sd );
  6914. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6915. #endif
  6916. }
  6917. /// Updates the job and level of a party member
  6918. /// 0abd <account id>.L <job>.W <level>.W
  6919. void clif_party_job_and_level( struct map_session_data& sd ){
  6920. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  6921. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  6922. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  6923. p.AID = sd.status.account_id;
  6924. p.job = sd.status.class_;
  6925. p.level = sd.status.base_level;
  6926. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6927. #endif
  6928. }
  6929. /*==========================================
  6930. * Sends HP bar to a single fd. [Skotlex]
  6931. *------------------------------------------*/
  6932. void clif_hpmeter_single( struct map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  6933. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6934. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6935. p.AID = id;
  6936. #if PACKETVER < 20100119
  6937. // To correctly display the %hp bar. [Skotlex]
  6938. if( maxhp > INT16_MAX ){
  6939. p.hp = hp / ( maxhp / 100 );
  6940. p.maxhp = 100;
  6941. }else{
  6942. p.hp = hp;
  6943. p.maxhp = maxhp;
  6944. }
  6945. #else
  6946. p.hp = hp;
  6947. p.maxhp = maxhp;
  6948. #endif
  6949. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6950. }
  6951. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6952. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6953. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6954. {
  6955. int fd;
  6956. nullpo_retv(sd);
  6957. nullpo_retv(bl);
  6958. fd=sd->fd;
  6959. WFIFOHEAD(fd,packet_len(0x139));
  6960. WFIFOW(fd, 0)=0x139;
  6961. WFIFOL(fd, 2)=bl->id;
  6962. WFIFOW(fd, 6)=bl->x;
  6963. WFIFOW(fd, 8)=bl->y;
  6964. WFIFOW(fd,10)=sd->bl.x;
  6965. WFIFOW(fd,12)=sd->bl.y;
  6966. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6967. WFIFOSET(fd,packet_len(0x139));
  6968. }
  6969. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6970. /// 018f <result>.W <name id>.W
  6971. /// result:
  6972. /// 0 = success
  6973. /// 1 = failure
  6974. /// 2 = success (alchemist)
  6975. /// 3 = failure (alchemist)
  6976. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  6977. nullpo_retv( sd );
  6978. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6979. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6980. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6981. p.result = flag;
  6982. p.itemId = client_nameid( nameid );
  6983. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6984. }
  6985. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6986. /// 019e
  6987. void clif_catch_process(struct map_session_data *sd)
  6988. {
  6989. int fd;
  6990. nullpo_retv(sd);
  6991. fd=sd->fd;
  6992. WFIFOHEAD(fd,packet_len(0x19e));
  6993. WFIFOW(fd,0)=0x19e;
  6994. WFIFOSET(fd,packet_len(0x19e));
  6995. }
  6996. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6997. /// 01a0 <result>.B
  6998. /// 0 = failure
  6999. /// 1 = success
  7000. void clif_pet_roulette(struct map_session_data *sd,int data)
  7001. {
  7002. int fd;
  7003. nullpo_retv(sd);
  7004. fd=sd->fd;
  7005. WFIFOHEAD(fd,packet_len(0x1a0));
  7006. WFIFOW(fd,0)=0x1a0;
  7007. WFIFOB(fd,2)=data;
  7008. WFIFOSET(fd,packet_len(0x1a0));
  7009. }
  7010. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7011. /// 01a6 <packet len>.W { <index>.W }*
  7012. void clif_sendegg(struct map_session_data *sd)
  7013. {
  7014. int i,n=0,fd;
  7015. nullpo_retv(sd);
  7016. fd=sd->fd;
  7017. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7018. clif_displaymessage(fd, msg_txt(sd,666));
  7019. return;
  7020. }
  7021. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7022. WFIFOW(fd,0)=0x1a6;
  7023. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7024. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7025. sd->inventory_data[i]->type != IT_PETEGG ||
  7026. sd->inventory.u.items_inventory[i].amount <= 0)
  7027. continue;
  7028. WFIFOW(fd,n*2+4)=client_index(i);
  7029. n++;
  7030. }
  7031. WFIFOW(fd,2)=4+n*2;
  7032. WFIFOSET(fd,WFIFOW(fd,2));
  7033. sd->menuskill_id = SA_TAMINGMONSTER;
  7034. sd->menuskill_val = -1;
  7035. }
  7036. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7037. /// 01a4 <type>.B <id>.L <data>.L
  7038. /// type:
  7039. /// 0 = pre-init (data = 0)
  7040. /// 1 = intimacy (data = 0~4)
  7041. /// 2 = hunger (data = 0~4)
  7042. /// 3 = accessory
  7043. /// 4 = performance (data = 1~3: normal, 4: special)
  7044. /// 5 = hairstyle
  7045. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7046. ///
  7047. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7048. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  7049. {
  7050. uint8 buf[16];
  7051. nullpo_retv(pd);
  7052. WBUFW(buf,0) = 0x1a4;
  7053. WBUFB(buf,2) = type;
  7054. WBUFL(buf,3) = pd->bl.id;
  7055. WBUFL(buf,7) = param;
  7056. if (sd)
  7057. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7058. else
  7059. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7060. }
  7061. /// Pet's base data (ZC_PROPERTY_PET).
  7062. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7063. void clif_send_petstatus(struct map_session_data *sd)
  7064. {
  7065. int fd;
  7066. struct s_pet *pet;
  7067. nullpo_retv(sd);
  7068. nullpo_retv(sd->pd);
  7069. fd=sd->fd;
  7070. pet = &sd->pd->pet;
  7071. WFIFOHEAD(fd,packet_len(0x1a2));
  7072. WFIFOW(fd,0)=0x1a2;
  7073. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7074. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7075. WFIFOW(fd,27)=pet->level;
  7076. WFIFOW(fd,29)=pet->hungry;
  7077. WFIFOW(fd,31)=pet->intimate;
  7078. WFIFOW(fd,33)=pet->equip;
  7079. #if PACKETVER >= 20081126
  7080. WFIFOW(fd,35)=pet->class_;
  7081. #endif
  7082. WFIFOSET(fd,packet_len(0x1a2));
  7083. }
  7084. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7085. /// 01aa <id>.L <data>.L
  7086. /// data:
  7087. /// @see CZ_PET_ACT.
  7088. void clif_pet_emotion(struct pet_data *pd,int param)
  7089. {
  7090. unsigned char buf[16];
  7091. nullpo_retv(pd);
  7092. memset(buf,0,packet_len(0x1aa));
  7093. WBUFW(buf,0)=0x1aa;
  7094. WBUFL(buf,2)=pd->bl.id;
  7095. WBUFL(buf,6)=param;
  7096. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7097. }
  7098. /// Result of request to feed a pet (ZC_FEED_PET).
  7099. /// 01a3 <result>.B <name id>.W
  7100. /// result:
  7101. /// 0 = failure
  7102. /// 1 = success
  7103. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  7104. nullpo_retv( sd );
  7105. struct PACKET_ZC_FEED_PET p;
  7106. p.packetType = 0x1a3;
  7107. p.result = fail;
  7108. p.itemId = client_nameid( foodid );
  7109. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7110. }
  7111. /// Send pet auto feed info.
  7112. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  7113. #if PACKETVER >= 20141008
  7114. nullpo_retv(sd);
  7115. if (force || battle_config.pet_autofeed_always) {
  7116. // Always send ON or OFF
  7117. if (sd->pd && battle_config.feature_pet_autofeed) {
  7118. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7119. }
  7120. else {
  7121. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7122. }
  7123. }
  7124. else {
  7125. // Only send when enabled
  7126. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7127. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7128. }
  7129. }
  7130. #endif
  7131. }
  7132. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7133. /// 01cd { <skill id>.L }*7
  7134. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  7135. {
  7136. nullpo_retv(sd);
  7137. int fd = sd->fd;
  7138. #ifdef RENEWAL
  7139. uint16 autospell_skill[][2] = {
  7140. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7141. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7142. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7143. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7144. };
  7145. int count = 0;
  7146. WFIFOHEAD(fd, 2 * 6 + 4);
  7147. WFIFOW(fd, 0) = 0x442;
  7148. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7149. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7150. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7151. count++;
  7152. }
  7153. }
  7154. WFIFOW(fd, 2) = 8 + count * 2;
  7155. WFIFOL(fd, 4) = count;
  7156. WFIFOSET(fd, WFIFOW(fd, 2));
  7157. #else
  7158. WFIFOHEAD(fd,packet_len(0x1cd));
  7159. WFIFOW(fd, 0)=0x1cd;
  7160. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7161. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7162. else
  7163. WFIFOL(fd,2)= 0x00000000;
  7164. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7165. WFIFOL(fd,6)= MG_COLDBOLT;
  7166. else
  7167. WFIFOL(fd,6)= 0x00000000;
  7168. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7169. WFIFOL(fd,10)= MG_FIREBOLT;
  7170. else
  7171. WFIFOL(fd,10)= 0x00000000;
  7172. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7173. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7174. else
  7175. WFIFOL(fd,14)= 0x00000000;
  7176. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7177. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7178. else
  7179. WFIFOL(fd,18)= 0x00000000;
  7180. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7181. WFIFOL(fd,22)= MG_FIREBALL;
  7182. else
  7183. WFIFOL(fd,22)= 0x00000000;
  7184. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7185. WFIFOL(fd,26)= MG_FROSTDIVER;
  7186. else
  7187. WFIFOL(fd,26)= 0x00000000;
  7188. WFIFOSET(fd,packet_len(0x1cd));
  7189. #endif
  7190. sd->menuskill_id = SA_AUTOSPELL;
  7191. sd->menuskill_val = skill_lv;
  7192. }
  7193. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7194. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7195. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7196. {
  7197. unsigned char buf[56];
  7198. nullpo_retv(src);
  7199. memset(buf,0,packet_len(0x1cf));
  7200. WBUFW(buf,0) = 0x1cf;
  7201. WBUFL(buf,2) = src->id;
  7202. if( src->type == BL_MER )
  7203. {
  7204. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7205. if( md && md->master && md->devotion_flag )
  7206. WBUFL(buf,6) = md->master->bl.id;
  7207. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7208. }
  7209. else
  7210. {
  7211. int i;
  7212. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7213. if( sd == NULL )
  7214. return;
  7215. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7216. WBUFL(buf,6+4*i) = sd->devotion[i];
  7217. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7218. }
  7219. if( tsd )
  7220. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7221. else
  7222. clif_send(buf, packet_len(0x1cf), src, AREA);
  7223. }
  7224. /// Notifies the client of an object's spirits.
  7225. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7226. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7227. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7228. nullpo_retv( bl );
  7229. struct PACKET_ZC_SPIRITS p = {};
  7230. p.PacketType = HEADER_ZC_SPIRITS;
  7231. p.AID = bl->id;
  7232. switch( bl->type ){
  7233. case BL_PC:
  7234. p.num = ( (struct map_session_data*)bl )->spiritball;
  7235. break;
  7236. case BL_HOM:
  7237. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7238. break;
  7239. }
  7240. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7241. }
  7242. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7243. /// 01d2 <account id>.L <delay>.L
  7244. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7245. {
  7246. unsigned char buf[32];
  7247. nullpo_retv(bl);
  7248. WBUFW(buf,0)=0x1d2;
  7249. WBUFL(buf,2)=bl->id;
  7250. WBUFL(buf,6)=client_tick(wait);
  7251. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7252. }
  7253. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7254. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7255. /// flag:
  7256. /// 0 = inactive
  7257. /// 1 = active
  7258. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7259. {
  7260. unsigned char buf[32];
  7261. nullpo_retv(src);
  7262. WBUFW(buf,0)=0x1d1;
  7263. WBUFL(buf,2)=src->id;
  7264. WBUFL(buf,6)=dst_id;
  7265. WBUFL(buf,10)=active;
  7266. clif_send(buf,packet_len(0x1d1),src,AREA);
  7267. }
  7268. /// MVP effect (ZC_MVP).
  7269. /// 010c <account id>.L
  7270. void clif_mvp_effect(struct map_session_data *sd)
  7271. {
  7272. unsigned char buf[16];
  7273. nullpo_retv(sd);
  7274. WBUFW(buf,0)=0x10c;
  7275. WBUFL(buf,2)=sd->bl.id;
  7276. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7277. }
  7278. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7279. /// 010a <name id>.W
  7280. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7281. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7282. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7283. p.itemId = client_nameid( nameid );
  7284. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7285. }
  7286. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7287. /// 010b <exp>.L
  7288. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7289. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7290. if (battle_config.mvp_exp_reward_message) {
  7291. char e_msg[CHAT_SIZE_MAX];
  7292. sprintf(e_msg, msg_txt(sd, 717), exp);
  7293. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7294. }
  7295. #else
  7296. int fd;
  7297. nullpo_retv(sd);
  7298. fd = sd->fd;
  7299. WFIFOHEAD(fd, packet_len(0x10b));
  7300. WFIFOW(fd,0) = 0x10b;
  7301. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7302. WFIFOSET(fd, packet_len(0x10b));
  7303. #endif
  7304. }
  7305. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7306. /// 010d
  7307. ///
  7308. /// "You are the MVP, but cannot obtain the reward because
  7309. /// you are overweight."
  7310. void clif_mvp_noitem(struct map_session_data* sd)
  7311. {
  7312. int fd = sd->fd;
  7313. WFIFOHEAD(fd,packet_len(0x10d));
  7314. WFIFOW(fd,0) = 0x10d;
  7315. WFIFOSET(fd,packet_len(0x10d));
  7316. }
  7317. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7318. /// 0167 <result>.B
  7319. /// result:
  7320. /// 0 = "Guild has been created."
  7321. /// 1 = "You are already in a Guild."
  7322. /// 2 = "That Guild Name already exists."
  7323. /// 3 = "You need the neccessary item to create a Guild."
  7324. void clif_guild_created(struct map_session_data *sd,int flag)
  7325. {
  7326. int fd;
  7327. nullpo_retv(sd);
  7328. fd=sd->fd;
  7329. WFIFOHEAD(fd,packet_len(0x167));
  7330. WFIFOW(fd,0)=0x167;
  7331. WFIFOB(fd,2)=flag;
  7332. WFIFOSET(fd,packet_len(0x167));
  7333. }
  7334. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7335. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7336. /// mode:
  7337. /// &0x01 = allow invite
  7338. /// &0x10 = allow expel
  7339. void clif_guild_belonginfo( struct map_session_data& sd ){
  7340. if( sd.guild == nullptr ){
  7341. return;
  7342. }
  7343. struct guild& guild = *sd.guild;
  7344. int position = guild_getposition( &sd );
  7345. if( position < 0 ){
  7346. return;
  7347. }
  7348. struct PACKET_ZC_UPDATE_GDID p = {};
  7349. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7350. p.guildId = guild.guild_id;
  7351. p.emblemVersion = guild.emblem_id;
  7352. p.mode = guild.position[position].mode;
  7353. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7354. p.interSid = 0; // InterSID (unknown purpose)
  7355. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7356. #if PACKETVER_MAIN_NUM >= 20220216
  7357. p.masterGID = guild.member[0].char_id;
  7358. #endif
  7359. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7360. }
  7361. /// Guild member login notice.
  7362. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7363. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7364. /// status:
  7365. /// 0 = offline
  7366. /// 1 = online
  7367. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7368. {
  7369. unsigned char buf[64];
  7370. struct map_session_data* sd;
  7371. nullpo_retv(g);
  7372. WBUFW(buf, 0)=0x1f2;
  7373. WBUFL(buf, 2)=g->member[idx].account_id;
  7374. WBUFL(buf, 6)=g->member[idx].char_id;
  7375. WBUFL(buf,10)=flag;
  7376. if( ( sd = g->member[idx].sd ) != NULL )
  7377. {
  7378. WBUFW(buf,14) = sd->status.sex;
  7379. WBUFW(buf,16) = sd->status.hair;
  7380. WBUFW(buf,18) = sd->status.hair_color;
  7381. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7382. }
  7383. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7384. {
  7385. WBUFW(buf,14) = 0;
  7386. WBUFW(buf,16) = 0;
  7387. WBUFW(buf,18) = 0;
  7388. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7389. }
  7390. }
  7391. // Function `clif_guild_memberlogin_notice` sends info about
  7392. // logins and logouts of a guild member to the rest members.
  7393. // But at the 1st time (after a player login or map changing)
  7394. // the client won't show the message.
  7395. // So I suggest use this function for sending "first-time-info"
  7396. // to some player on entering the game or changing location.
  7397. // At next time the client would always show the message.
  7398. // The function sends all the statuses in the single packet
  7399. // to economize traffic. [LuzZza]
  7400. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7401. {
  7402. struct guild *g;
  7403. unsigned char buf[14*128];
  7404. int i, count=0, p_len;
  7405. nullpo_retv(sd);
  7406. p_len = packet_len(0x16d);
  7407. if(!(g = sd->guild))
  7408. return;
  7409. for(i=0; i<g->max_member; i++) {
  7410. if(g->member[i].account_id > 0 &&
  7411. g->member[i].account_id != sd->status.account_id) {
  7412. WBUFW(buf,count*p_len) = 0x16d;
  7413. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7414. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7415. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7416. count++;
  7417. }
  7418. }
  7419. clif_send(buf, p_len*count, &sd->bl, SELF);
  7420. }
  7421. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7422. /// 014e <menu flag>.L
  7423. /// menu flag:
  7424. /// 0x00 = Basic Info (always on)
  7425. /// &0x01 = Member manager
  7426. /// &0x02 = Positions
  7427. /// &0x04 = Skills
  7428. /// &0x10 = Expulsion list
  7429. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7430. /// &0x80 = Notice
  7431. void clif_guild_masterormember(struct map_session_data *sd)
  7432. {
  7433. int fd;
  7434. nullpo_retv(sd);
  7435. fd=sd->fd;
  7436. WFIFOHEAD(fd,packet_len(0x14e));
  7437. WFIFOW(fd,0) = 0x14e;
  7438. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7439. WFIFOSET(fd,packet_len(0x14e));
  7440. }
  7441. /// Guild basic information (Territories [Valaris])
  7442. /// 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)
  7443. /// 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)
  7444. /// 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)
  7445. void clif_guild_basicinfo( struct map_session_data& sd ){
  7446. if( sd.guild == nullptr ){
  7447. return;
  7448. }
  7449. struct guild& guild = *sd.guild;
  7450. struct PACKET_ZC_GUILD_INFO p = {};
  7451. p.PacketType = HEADER_ZC_GUILD_INFO;
  7452. p.GDID = guild.guild_id;
  7453. p.level = guild.guild_lv;
  7454. p.userNum = guild.connect_member;
  7455. p.maxUserNum = guild.max_member;
  7456. p.userAverageLevel = guild.average_lv;
  7457. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7458. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7459. p.point = 0; // Tax Points
  7460. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7461. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7462. p.emblemVersion = guild.emblem_id;
  7463. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7464. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( &guild ) ), sizeof( p.manageLand ) );
  7465. p.zeny = 0;
  7466. #if PACKETVER >= 20200902
  7467. p.masterGID = guild.member[0].char_id; // leader
  7468. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7469. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7470. p.masterGID = guild.member[0].char_id; // leader
  7471. #else
  7472. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7473. #endif
  7474. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7475. }
  7476. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7477. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7478. void clif_guild_allianceinfo(struct map_session_data *sd)
  7479. {
  7480. int fd,i,c;
  7481. struct guild *g;
  7482. nullpo_retv(sd);
  7483. if( (g = sd->guild) == NULL )
  7484. return;
  7485. fd = sd->fd;
  7486. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7487. WFIFOW(fd, 0)=0x14c;
  7488. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7489. struct guild_alliance *a=&g->alliance[i];
  7490. if(a->guild_id>0){
  7491. WFIFOL(fd,c*32+4)=a->opposition;
  7492. WFIFOL(fd,c*32+8)=a->guild_id;
  7493. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7494. c++;
  7495. }
  7496. }
  7497. WFIFOW(fd, 2)=c*32+4;
  7498. WFIFOSET(fd,WFIFOW(fd,2));
  7499. }
  7500. /// Guild member manager information
  7501. /// 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)
  7502. /// state:
  7503. /// 0 = offline
  7504. /// 1 = online
  7505. /// memo:
  7506. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7507. /// 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)
  7508. void clif_guild_memberlist( struct map_session_data& sd ){
  7509. if( sd.guild == nullptr ){
  7510. return;
  7511. }
  7512. struct guild& guild = *sd.guild;
  7513. struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer;
  7514. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7515. p->packetLength = sizeof( *p );
  7516. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7517. struct guild_member& member = guild.member[i];
  7518. if( member.account_id == 0 ){
  7519. continue;
  7520. }
  7521. struct GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7522. member_info.AID = member.account_id;
  7523. member_info.GID = member.char_id;
  7524. member_info.head = member.hair;
  7525. member_info.headPalette = member.hair_color;
  7526. member_info.sex = member.gender;
  7527. member_info.job = member.class_;
  7528. member_info.level = member.lv;
  7529. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7530. member_info.currentState = member.online;
  7531. member_info.positionID = member.position;
  7532. #if PACKETVER >= 20200902
  7533. member_info.lastLoginTime = member.last_login;
  7534. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7535. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7536. member_info.lastLoginTime = member.last_login;
  7537. #else
  7538. 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.
  7539. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7540. #endif
  7541. c++;
  7542. p->packetLength += sizeof( member_info );
  7543. }
  7544. clif_send( p, p->packetLength, &sd.bl, SELF );
  7545. }
  7546. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7547. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7548. void clif_guild_positionnamelist(struct map_session_data *sd)
  7549. {
  7550. int i,fd;
  7551. struct guild *g;
  7552. nullpo_retv(sd);
  7553. if( (g = sd->guild) == NULL )
  7554. return;
  7555. fd = sd->fd;
  7556. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7557. WFIFOW(fd, 0)=0x166;
  7558. for(i=0;i<MAX_GUILDPOSITION;i++){
  7559. WFIFOL(fd,i*28+4)=i;
  7560. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7561. }
  7562. WFIFOW(fd,2)=i*28+4;
  7563. WFIFOSET(fd,WFIFOW(fd,2));
  7564. }
  7565. /// Guild position information (ZC_POSITION_INFO).
  7566. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7567. /// mode:
  7568. /// &0x01 = allow invite
  7569. /// &0x10 = allow expel
  7570. /// ranking:
  7571. /// TODO
  7572. void clif_guild_positioninfolist(struct map_session_data *sd)
  7573. {
  7574. int i,fd;
  7575. struct guild *g;
  7576. nullpo_retv(sd);
  7577. if( (g = sd->guild) == NULL )
  7578. return;
  7579. fd = sd->fd;
  7580. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7581. WFIFOW(fd, 0)=0x160;
  7582. for(i=0;i<MAX_GUILDPOSITION;i++){
  7583. struct guild_position *p=&g->position[i];
  7584. WFIFOL(fd,i*16+ 4)=i;
  7585. WFIFOL(fd,i*16+ 8)=p->mode;
  7586. WFIFOL(fd,i*16+12)=i;
  7587. WFIFOL(fd,i*16+16)=p->exp_mode;
  7588. }
  7589. WFIFOW(fd, 2)=i*16+4;
  7590. WFIFOSET(fd,WFIFOW(fd,2));
  7591. }
  7592. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7593. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7594. /// mode:
  7595. /// &0x01 = allow invite
  7596. /// &0x10 = allow expel
  7597. /// ranking:
  7598. /// TODO
  7599. void clif_guild_positionchanged(struct guild *g,int idx)
  7600. {
  7601. // FIXME: This packet is intended to update the clients after a
  7602. // commit of position info changes, not sending one packet per
  7603. // position.
  7604. struct map_session_data *sd;
  7605. unsigned char buf[128];
  7606. nullpo_retv(g);
  7607. WBUFW(buf, 0)=0x174;
  7608. WBUFW(buf, 2)=44; // packet len
  7609. // GUILD_REG_POSITION_INFO{
  7610. WBUFL(buf, 4)=idx;
  7611. WBUFL(buf, 8)=g->position[idx].mode;
  7612. WBUFL(buf,12)=idx;
  7613. WBUFL(buf,16)=g->position[idx].exp_mode;
  7614. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7615. // }*
  7616. if( (sd=guild_getavailablesd(g))!=NULL )
  7617. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7618. }
  7619. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7620. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7621. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7622. {
  7623. // FIXME: This packet is intended to update the clients after a
  7624. // commit of member position assignment changes, not sending one
  7625. // packet per position.
  7626. struct map_session_data *sd;
  7627. unsigned char buf[64];
  7628. nullpo_retv(g);
  7629. WBUFW(buf, 0)=0x156;
  7630. WBUFW(buf, 2)=16; // packet len
  7631. // MEMBER_POSITION_INFO{
  7632. WBUFL(buf, 4)=g->member[idx].account_id;
  7633. WBUFL(buf, 8)=g->member[idx].char_id;
  7634. WBUFL(buf,12)=g->member[idx].position;
  7635. // }*
  7636. if( (sd=guild_getavailablesd(g))!=NULL )
  7637. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7638. }
  7639. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7640. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7641. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7642. {
  7643. int fd;
  7644. nullpo_retv(sd);
  7645. nullpo_retv(g);
  7646. fd = sd->fd;
  7647. if( g->emblem_len <= 0 )
  7648. return;
  7649. WFIFOHEAD(fd,g->emblem_len+12);
  7650. WFIFOW(fd,0)=0x152;
  7651. WFIFOW(fd,2)=g->emblem_len+12;
  7652. WFIFOL(fd,4)=g->guild_id;
  7653. WFIFOL(fd,8)=g->emblem_id;
  7654. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7655. WFIFOSET(fd,WFIFOW(fd,2));
  7656. }
  7657. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7658. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7659. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7660. void clif_guild_emblem_area(struct block_list* bl)
  7661. {
  7662. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7663. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7664. PACKET_ZC_CHANGE_GUILD p{};
  7665. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7666. p.guild_id = status_get_guild_id(bl);
  7667. p.emblem_id = status_get_emblem_id(bl);
  7668. #if PACKETVER < 20190724
  7669. p.aid = bl->id;
  7670. #else
  7671. p.unknown = 0;
  7672. #endif
  7673. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7674. }
  7675. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7676. /// 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 }*
  7677. void clif_guild_skillinfo(struct map_session_data* sd)
  7678. {
  7679. int fd;
  7680. struct guild* g;
  7681. int i,c;
  7682. nullpo_retv(sd);
  7683. if( (g = sd->guild) == NULL )
  7684. return;
  7685. fd = sd->fd;
  7686. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7687. WFIFOW(fd,0) = 0x0162;
  7688. WFIFOW(fd,4) = g->skill_point;
  7689. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7690. {
  7691. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7692. {
  7693. int id = g->skill[i].id;
  7694. int p = 6 + c*37;
  7695. WFIFOW(fd,p+0) = id;
  7696. WFIFOL(fd,p+2) = skill_get_inf(id);
  7697. WFIFOW(fd,p+6) = g->skill[i].lv;
  7698. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7699. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7700. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7701. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7702. c++;
  7703. }
  7704. }
  7705. WFIFOW(fd,2) = 6 + c*37;
  7706. WFIFOSET(fd,WFIFOW(fd,2));
  7707. }
  7708. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7709. /// 016f <subject>.60B <notice>.120B
  7710. void clif_guild_notice(struct map_session_data* sd)
  7711. {
  7712. struct guild* g;
  7713. nullpo_retv(sd);
  7714. nullpo_retv(g = sd->guild);
  7715. int fd = sd->fd;
  7716. if ( !session_isActive(fd) )
  7717. return;
  7718. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7719. return;
  7720. WFIFOHEAD(fd,packet_len(0x16f));
  7721. WFIFOW(fd,0) = 0x16f;
  7722. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7723. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7724. WFIFOSET(fd,packet_len(0x16f));
  7725. }
  7726. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7727. /// 016a <guild id>.L <guild name>.24B
  7728. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7729. {
  7730. int fd;
  7731. nullpo_retv(sd);
  7732. nullpo_retv(g);
  7733. fd=sd->fd;
  7734. WFIFOHEAD(fd,packet_len(0x16a));
  7735. WFIFOW(fd,0)=0x16a;
  7736. WFIFOL(fd,2)=g->guild_id;
  7737. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7738. WFIFOSET(fd,packet_len(0x16a));
  7739. }
  7740. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7741. /// 0169 <answer>.B
  7742. /// answer:
  7743. /// 0 = Already in guild.
  7744. /// 1 = Offer rejected.
  7745. /// 2 = Offer accepted.
  7746. /// 3 = Guild full.
  7747. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7748. {
  7749. int fd;
  7750. nullpo_retv(sd);
  7751. fd=sd->fd;
  7752. WFIFOHEAD(fd,packet_len(0x169));
  7753. WFIFOW(fd,0)=0x169;
  7754. WFIFOB(fd,2)=flag;
  7755. WFIFOSET(fd,packet_len(0x169));
  7756. }
  7757. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7758. /// 015a <char name>.24B <reason>.40B
  7759. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7760. {
  7761. unsigned char buf[128];
  7762. nullpo_retv(sd);
  7763. WBUFW(buf, 0)=0x15a;
  7764. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7765. memcpy(WBUFP(buf,26),mes,40);
  7766. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7767. }
  7768. /// Notifies clients of a guild of an expelled member.
  7769. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7770. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7771. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7772. {
  7773. unsigned char buf[128];
  7774. #if PACKETVER < 20100803
  7775. const unsigned short cmd = 0x15c;
  7776. #else
  7777. const unsigned short cmd = 0x839;
  7778. #endif
  7779. nullpo_retv(sd);
  7780. WBUFW(buf,0) = cmd;
  7781. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7782. safestrncpy(WBUFCP(buf,26), mes, 40);
  7783. #if PACKETVER < 20100803
  7784. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7785. #endif
  7786. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7787. }
  7788. /// Guild expulsion list (ZC_BAN_LIST).
  7789. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7790. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7791. void clif_guild_expulsionlist(struct map_session_data* sd)
  7792. {
  7793. #if PACKETVER < 20100803
  7794. const int offset = NAME_LENGTH*2+40;
  7795. #else
  7796. const int offset = NAME_LENGTH+40;
  7797. #endif
  7798. int fd, i, c = 0;
  7799. struct guild* g;
  7800. nullpo_retv(sd);
  7801. if( (g = sd->guild) == NULL )
  7802. return;
  7803. fd = sd->fd;
  7804. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7805. WFIFOW(fd,0) = 0x163;
  7806. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7807. {
  7808. struct guild_expulsion* e = &g->expulsion[i];
  7809. if( e->account_id > 0 )
  7810. {
  7811. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7812. #if PACKETVER < 20100803
  7813. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7814. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7815. #else
  7816. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7817. #endif
  7818. c++;
  7819. }
  7820. }
  7821. WFIFOW(fd,2) = 4 + c*offset;
  7822. WFIFOSET(fd,WFIFOW(fd,2));
  7823. }
  7824. /// Guild chat message (ZC_GUILD_CHAT).
  7825. /// 017f <packet len>.W <message>.?B
  7826. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7827. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7828. struct map_session_data *sd;
  7829. uint8 buf[256];
  7830. if( len == 0 )
  7831. {
  7832. return;
  7833. }
  7834. else if( len > sizeof(buf)-5 )
  7835. {
  7836. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7837. len = sizeof(buf)-5;
  7838. }
  7839. WBUFW(buf, 0) = 0x17f;
  7840. WBUFW(buf, 2) = len + 5;
  7841. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7842. if ((sd = guild_getavailablesd(g)) != NULL)
  7843. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7844. }
  7845. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7846. /// 0171 <inviter account id>.L <guild name>.24B
  7847. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7848. {
  7849. int fd;
  7850. nullpo_retv(sd);
  7851. fd=sd->fd;
  7852. WFIFOHEAD(fd,packet_len(0x171));
  7853. WFIFOW(fd,0)=0x171;
  7854. WFIFOL(fd,2)=account_id;
  7855. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7856. WFIFOSET(fd,packet_len(0x171));
  7857. }
  7858. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7859. /// 0173 <answer>.B
  7860. /// answer:
  7861. /// 0 = Already allied.
  7862. /// 1 = You rejected the offer.
  7863. /// 2 = You accepted the offer.
  7864. /// 3 = They have too any alliances.
  7865. /// 4 = You have too many alliances.
  7866. /// 5 = Alliances are disabled.
  7867. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7868. {
  7869. int fd;
  7870. nullpo_retv(sd);
  7871. fd=sd->fd;
  7872. WFIFOHEAD(fd,packet_len(0x173));
  7873. WFIFOW(fd,0)=0x173;
  7874. WFIFOL(fd,2)=flag;
  7875. WFIFOSET(fd,packet_len(0x173));
  7876. }
  7877. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7878. /// 0184 <other guild id>.L <relation>.L
  7879. /// relation:
  7880. /// 0 = Ally
  7881. /// 1 = Enemy
  7882. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7883. {
  7884. nullpo_retv(sd);
  7885. int fd = sd->fd;
  7886. if ( !session_isActive(fd) )
  7887. return;
  7888. WFIFOHEAD(fd,packet_len(0x184));
  7889. WFIFOW(fd,0)=0x184;
  7890. WFIFOL(fd,2)=guild_id;
  7891. WFIFOL(fd,6)=flag;
  7892. WFIFOSET(fd,packet_len(0x184));
  7893. }
  7894. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7895. /// 0181 <result>.B
  7896. /// result:
  7897. /// 0 = Antagonist has been set.
  7898. /// 1 = Guild has too many Antagonists.
  7899. /// 2 = Already set as an Antagonist.
  7900. /// 3 = Antagonists are disabled.
  7901. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7902. {
  7903. int fd;
  7904. nullpo_retv(sd);
  7905. fd=sd->fd;
  7906. WFIFOHEAD(fd,packet_len(0x181));
  7907. WFIFOW(fd,0)=0x181;
  7908. WFIFOB(fd,2)=flag;
  7909. WFIFOSET(fd,packet_len(0x181));
  7910. }
  7911. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7912. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7913. /*
  7914. void clif_guild_allianceadded(struct guild *g,int idx)
  7915. {
  7916. unsigned char buf[64];
  7917. WBUFW(buf,0)=0x185;
  7918. WBUFL(buf,2)=g->alliance[idx].opposition;
  7919. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7920. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7921. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7922. }
  7923. */
  7924. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7925. /// 015e <reason>.L
  7926. /// 0 = success
  7927. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7928. /// 2 = there are still members in the guild
  7929. void clif_guild_broken(struct map_session_data *sd,int flag)
  7930. {
  7931. int fd;
  7932. nullpo_retv(sd);
  7933. fd=sd->fd;
  7934. WFIFOHEAD(fd,packet_len(0x15e));
  7935. WFIFOW(fd,0)=0x15e;
  7936. WFIFOL(fd,2)=flag;
  7937. WFIFOSET(fd,packet_len(0x15e));
  7938. }
  7939. /// Displays emotion on an object (ZC_EMOTION).
  7940. /// 00c0 <id>.L <type>.B
  7941. /// type:
  7942. /// enum emotion_type
  7943. void clif_emotion(struct block_list *bl,int type)
  7944. {
  7945. unsigned char buf[8];
  7946. nullpo_retv(bl);
  7947. WBUFW(buf,0)=0xc0;
  7948. WBUFL(buf,2)=bl->id;
  7949. WBUFB(buf,6)=type;
  7950. clif_send(buf,packet_len(0xc0),bl,AREA);
  7951. }
  7952. /// Displays the contents of a talkiebox trap.
  7953. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7954. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7955. nullpo_retv( bl );
  7956. nullpo_retv( talkie );
  7957. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7958. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7959. p.aid = bl->id;
  7960. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7961. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7962. }
  7963. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7964. /// 01ea <id>.L
  7965. void clif_wedding_effect(struct block_list *bl)
  7966. {
  7967. unsigned char buf[6];
  7968. nullpo_retv(bl);
  7969. WBUFW(buf,0) = 0x1ea;
  7970. WBUFL(buf,2) = bl->id;
  7971. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7972. }
  7973. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7974. /// 01e6 <partner name>.24B
  7975. void clif_callpartner(struct map_session_data *sd)
  7976. {
  7977. unsigned char buf[26];
  7978. nullpo_retv(sd);
  7979. WBUFW(buf,0) = 0x1e6;
  7980. if( sd->status.partner_id ) {
  7981. const char *p = map_charid2nick(sd->status.partner_id);
  7982. struct map_session_data *p_sd = pc_get_partner(sd);
  7983. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7984. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7985. else
  7986. WBUFB(buf,2) = 0;
  7987. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7988. WBUFB(buf,2) = 0;
  7989. }
  7990. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7991. }
  7992. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7993. /// 01e4
  7994. /// This packet while still implemented by the client is no longer being officially used.
  7995. /*
  7996. void clif_marriage_process(struct map_session_data *sd)
  7997. {
  7998. int fd;
  7999. nullpo_retv(sd);
  8000. fd=sd->fd;
  8001. WFIFOHEAD(fd,packet_len(0x1e4));
  8002. WFIFOW(fd,0)=0x1e4;
  8003. WFIFOSET(fd,packet_len(0x1e4));
  8004. }
  8005. */
  8006. /// Notice of divorce (ZC_DIVORCE).
  8007. /// 0205 <partner name>.24B
  8008. void clif_divorced(struct map_session_data* sd, const char* name)
  8009. {
  8010. int fd;
  8011. nullpo_retv(sd);
  8012. fd=sd->fd;
  8013. WFIFOHEAD(fd,packet_len(0x205));
  8014. WFIFOW(fd,0)=0x205;
  8015. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8016. WFIFOSET(fd, packet_len(0x205));
  8017. }
  8018. /// Marriage proposal (ZC_REQ_COUPLE).
  8019. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8020. /// This packet while still implemented by the client is no longer being officially used.
  8021. /*
  8022. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  8023. {
  8024. nullpo_retv(sd);
  8025. WFIFOHEAD(fd,packet_len(0x1e2));
  8026. WFIFOW(fd,0) = 0x1e2;
  8027. WFIFOL(fd,2) = ssd->status.account_id;
  8028. WFIFOL(fd,6) = ssd->status.char_id;
  8029. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8030. WFIFOSET(fd, packet_len(0x1e2));
  8031. }
  8032. */
  8033. /*==========================================
  8034. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8035. *------------------------------------------*/
  8036. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8037. {
  8038. unsigned char buf[256];
  8039. if( len == 0 ) {
  8040. return;
  8041. } else if( len > sizeof(buf)-5 ) {
  8042. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8043. len = sizeof(buf)-5;
  8044. }
  8045. WBUFW(buf, 0) = 0x17f;
  8046. WBUFW(buf, 2) = len + 5;
  8047. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8048. clif_send(buf, WBUFW(buf,2), src, target);
  8049. }
  8050. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8051. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8052. /// 00cd <result>.B
  8053. /// result:
  8054. /// 0 = failure
  8055. /// 1 = success
  8056. void clif_GM_kickack(struct map_session_data *sd, int id)
  8057. {
  8058. int fd;
  8059. nullpo_retv(sd);
  8060. fd = sd->fd;
  8061. WFIFOHEAD(fd,packet_len(0xcd));
  8062. WFIFOW(fd,0) = 0xcd;
  8063. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8064. WFIFOSET(fd, packet_len(0xcd));
  8065. }
  8066. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  8067. {
  8068. nullpo_retv(tsd);
  8069. if (sd == NULL)
  8070. tsd->state.keepshop = true;
  8071. if (session_isActive(tsd->fd))
  8072. clif_authfail_fd(tsd->fd, 15);
  8073. else
  8074. map_quit(tsd);
  8075. if (sd)
  8076. clif_GM_kickack(sd, tsd->status.account_id);
  8077. }
  8078. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8079. /// 014a <result>.L
  8080. /// result:
  8081. /// 0 = "A manner point has been successfully aligned."
  8082. /// 1 = MP_FAILURE_EXHAUST
  8083. /// 2 = MP_FAILURE_ALREADY_GIVING
  8084. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8085. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8086. /// 5 = "You got a good point from %s."
  8087. void clif_manner_message(struct map_session_data* sd, uint32 type)
  8088. {
  8089. int fd;
  8090. nullpo_retv(sd);
  8091. fd = sd->fd;
  8092. WFIFOHEAD(fd,packet_len(0x14a));
  8093. WFIFOW(fd,0) = 0x14a;
  8094. WFIFOL(fd,2) = type;
  8095. WFIFOSET(fd, packet_len(0x14a));
  8096. }
  8097. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8098. /// 014b <type>.B <GM name>.24B
  8099. /// type:
  8100. /// 0 = positive (unmute)
  8101. /// 1 = negative (mute)
  8102. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  8103. {
  8104. int fd;
  8105. nullpo_retv(sd);
  8106. nullpo_retv(tsd);
  8107. fd = tsd->fd;
  8108. WFIFOHEAD(fd,packet_len(0x14b));
  8109. WFIFOW(fd,0) = 0x14b;
  8110. WFIFOB(fd,2) = type;
  8111. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8112. WFIFOSET(fd, packet_len(0x14b));
  8113. }
  8114. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8115. /// 00d1 <type>.B <result>.B
  8116. /// type:
  8117. /// 0 = /ex (deny)
  8118. /// 1 = /in (allow)
  8119. /// result:
  8120. /// 0 = success
  8121. /// 1 = failure
  8122. /// 2 = too many blocks
  8123. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  8124. {
  8125. int fd;
  8126. nullpo_retv(sd);
  8127. fd=sd->fd;
  8128. WFIFOHEAD(fd,packet_len(0xd1));
  8129. WFIFOW(fd,0)=0xd1;
  8130. WFIFOB(fd,2)=type;
  8131. WFIFOB(fd,3)=flag;
  8132. WFIFOSET(fd,packet_len(0xd1));
  8133. }
  8134. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8135. /// 00d2 <type>.B <result>.B
  8136. /// type:
  8137. /// 0 = /exall (deny)
  8138. /// 1 = /inall (allow)
  8139. /// result:
  8140. /// 0 = success
  8141. /// 1 = failure
  8142. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8143. {
  8144. int fd;
  8145. nullpo_retv(sd);
  8146. fd=sd->fd;
  8147. WFIFOHEAD(fd,packet_len(0xd2));
  8148. WFIFOW(fd,0)=0xd2;
  8149. WFIFOB(fd,2)=type;
  8150. WFIFOB(fd,3)=flag;
  8151. WFIFOSET(fd,packet_len(0xd2));
  8152. }
  8153. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8154. /// 07fe <bgm>.24B
  8155. void clif_playBGM( struct map_session_data& sd, const char* name ){
  8156. #if PACKETVER_MAIN_NUM >= 20220504
  8157. struct PACKET_ZC_PLAY_NPC_BGM* p = (struct PACKET_ZC_PLAY_NPC_BGM*)packet_buffer;
  8158. int16 length = (int16)( strlen( name ) + 1 );
  8159. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8160. p->PacketLength = sizeof( *p ) + length;
  8161. p->playType = 0; // TODO: implement, send loop for the time being
  8162. safestrncpy( p->bgm, name, length );
  8163. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8164. #elif PACKETVER >= 20091201
  8165. struct PACKET_ZC_PLAY_NPC_BGM p = {};
  8166. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8167. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8168. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8169. #endif
  8170. }
  8171. /// Plays/stops a wave sound (ZC_SOUND).
  8172. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8173. /// file name:
  8174. /// relative to data\wav
  8175. /// act:
  8176. /// 0 = play (once)
  8177. /// 1 = play (repeat, does not work)
  8178. /// 2 = stops all sound instances of file name (does not work)
  8179. /// term:
  8180. /// unknown purpose, only relevant to act = 1
  8181. /// npc id:
  8182. /// The accustic direction of the sound is determined by the
  8183. /// relative position of the NPC to the player (3D sound).
  8184. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8185. struct PACKET_ZC_SOUND p = {};
  8186. p.PacketType = HEADER_ZC_SOUND;
  8187. safestrncpy( p.name, name, sizeof( p.name ) );
  8188. p.act = type;
  8189. p.term = 0; // TODO: implement
  8190. p.AID = bl.id;
  8191. clif_send( &p, sizeof( p ), &bl, target );
  8192. }
  8193. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8194. /// 01f3 <id>.L <effect id>.L
  8195. /// effect id:
  8196. /// @see doc/effect_list.txt
  8197. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8198. {
  8199. unsigned char buf[24];
  8200. nullpo_retv(bl);
  8201. memset(buf, 0, packet_len(0x1f3));
  8202. WBUFW(buf,0) = 0x1f3;
  8203. WBUFL(buf,2) = bl->id;
  8204. WBUFL(buf,6) = type;
  8205. clif_send(buf, packet_len(0x1f3), bl, target);
  8206. if (disguised(bl)) {
  8207. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8208. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8209. }
  8210. }
  8211. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8212. {
  8213. WFIFOHEAD(fd,10);
  8214. WFIFOW(fd,0) = 0x1f3;
  8215. WFIFOL(fd,2) = bl->id;
  8216. WFIFOL(fd,6) = type;
  8217. WFIFOSET(fd,10);
  8218. }
  8219. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8220. /// 0284 <id>.L <effect id>.L <num data>.L
  8221. /// effect id:
  8222. /// @see doc/effect_list.txt
  8223. /// num data:
  8224. /// effect-dependent value
  8225. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8226. {
  8227. uint8 buf[14];
  8228. WBUFW(buf,0) = 0x284;
  8229. WBUFL(buf,2) = bl->id;
  8230. WBUFL(buf,6) = effect_id;
  8231. WBUFL(buf,10) = num;
  8232. clif_send(buf, packet_len(0x284), bl, target);
  8233. if( disguised(bl) )
  8234. {
  8235. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8236. clif_send(buf, packet_len(0x284), bl, SELF);
  8237. }
  8238. }
  8239. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8240. {
  8241. #if PACKETVER >= 20181002
  8242. nullpo_retv( bl_src );
  8243. nullpo_retv( bl_target );
  8244. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8245. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8246. p.aid = bl_src->id;
  8247. p.effectId = effect;
  8248. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8249. if( disguised(bl_src) )
  8250. {
  8251. p.aid = disguised_bl_id( bl_src->id );
  8252. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8253. }
  8254. #endif
  8255. }
  8256. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8257. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8258. 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) {
  8259. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8260. uint8 buf[CHAT_SIZE_MAX];
  8261. nullpo_retv(bl);
  8262. if (msg_len > sizeof(buf) - 12) {
  8263. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8264. msg_len = sizeof(buf) - 12;
  8265. }
  8266. if (rgb2bgr)
  8267. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8268. WBUFW(buf,0) = 0x2C1;
  8269. WBUFW(buf,2) = msg_len + 12;
  8270. WBUFL(buf,4) = bl->id;
  8271. WBUFL(buf,8) = color;
  8272. memcpy(WBUFCP(buf,12), msg, msg_len);
  8273. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8274. }
  8275. /**
  8276. * Notifies the client that the storage window is still open
  8277. *
  8278. * Should only be used in cases where the client closed the
  8279. * storage window without server's consent
  8280. */
  8281. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8282. // Notify the client that the storage is open
  8283. if( sd->state.storage_flag == 1 ) {
  8284. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8285. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8286. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8287. }
  8288. // Notify the client that the gstorage is open otherwise it will
  8289. // remain locked forever and nobody will be able to access it
  8290. if( sd->state.storage_flag == 2 ) {
  8291. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8292. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8293. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8294. else {
  8295. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8296. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8297. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8298. }
  8299. }
  8300. // Notify the client that the premium storage is open
  8301. if (sd->state.storage_flag == 3) {
  8302. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8303. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8304. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8305. }
  8306. }
  8307. // refresh the client's screen, getting rid of any effects
  8308. void clif_refresh(struct map_session_data *sd)
  8309. {
  8310. nullpo_retv(sd);
  8311. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8312. clif_inventorylist(sd);
  8313. clif_equipswitch_list(sd);
  8314. if(pc_iscarton(sd)) {
  8315. clif_cartlist(sd);
  8316. clif_updatestatus(sd,SP_CARTINFO);
  8317. }
  8318. clif_updatestatus(sd,SP_WEIGHT);
  8319. clif_updatestatus(sd,SP_MAXWEIGHT);
  8320. clif_updatestatus(sd,SP_STR);
  8321. clif_updatestatus(sd,SP_AGI);
  8322. clif_updatestatus(sd,SP_VIT);
  8323. clif_updatestatus(sd,SP_INT);
  8324. clif_updatestatus(sd,SP_DEX);
  8325. clif_updatestatus(sd,SP_LUK);
  8326. #ifdef RENEWAL
  8327. clif_updatestatus(sd,SP_POW);
  8328. clif_updatestatus(sd,SP_STA);
  8329. clif_updatestatus(sd,SP_WIS);
  8330. clif_updatestatus(sd,SP_SPL);
  8331. clif_updatestatus(sd,SP_CON);
  8332. clif_updatestatus(sd,SP_CRT);
  8333. #endif
  8334. if (sd->spiritball)
  8335. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8336. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8337. clif_millenniumshield_single(sd->fd, sd);
  8338. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8339. clif_spiritcharm_single(sd->fd, sd);
  8340. if (sd->soulball)
  8341. clif_soulball( sd, &sd->bl, SELF );
  8342. if (sd->servantball)
  8343. clif_servantball( *sd, &sd->bl, SELF );
  8344. if (sd->abyssball)
  8345. clif_abyssball( *sd, &sd->bl, SELF );
  8346. if (sd->vd.cloth_color)
  8347. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8348. if (sd->vd.body_style)
  8349. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8350. if(hom_is_active(sd->hd))
  8351. clif_send_homdata(sd,SP_ACK,0);
  8352. if( sd->md ) {
  8353. clif_mercenary_info(sd);
  8354. clif_mercenary_skillblock(sd);
  8355. }
  8356. if( sd->ed )
  8357. clif_elemental_info(sd);
  8358. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8359. clif_weather_check(sd);
  8360. if( sd->chatID )
  8361. chat_leavechat(sd,0);
  8362. if( sd->state.vending )
  8363. clif_openvending(sd, sd->bl.id, sd->vending);
  8364. if( pc_issit(sd) )
  8365. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8366. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8367. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8368. else
  8369. clif_changed_dir(&sd->bl, SELF);
  8370. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8371. //Issue #2143
  8372. //Cancel Trading State
  8373. if (sd->state.trading)
  8374. trade_tradecancel(sd);
  8375. //Cancel Buying/Selling State
  8376. if (sd->state.buyingstore)
  8377. buyingstore_close(sd);
  8378. mail_clear(sd);
  8379. clif_loadConfirm( sd );
  8380. if( disguised(&sd->bl) ) {/* refresh-da */
  8381. short disguise = sd->disguise;
  8382. pc_disguise(sd, 0);
  8383. pc_disguise(sd, disguise);
  8384. }
  8385. clif_refresh_storagewindow(sd);
  8386. }
  8387. /// Updates the object's (bl) name on client.
  8388. /// Used to update when a char leaves a party/guild. [Skotlex]
  8389. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8390. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8391. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8392. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8393. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8394. nullpo_retv( src );
  8395. nullpo_retv( bl );
  8396. switch( bl->type ){
  8397. case BL_PC: {
  8398. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8399. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8400. packet.gid = bl->id;
  8401. map_session_data *sd = (map_session_data *)bl;
  8402. //Requesting your own "shadow" name. [Skotlex]
  8403. if( src == bl && target == SELF && sd->disguise ){
  8404. packet.gid = -bl->id;
  8405. }
  8406. if( sd->fakename[0] ) {
  8407. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8408. clif_send( &packet, sizeof(packet), src, target );
  8409. return;
  8410. }
  8411. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8412. party_data *p = nullptr;
  8413. if( sd->status.party_id ){
  8414. p = party_search( sd->status.party_id );
  8415. }
  8416. // do not display party unless the player is also in a guild
  8417. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8418. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8419. }
  8420. if( sd->guild ){
  8421. int position;
  8422. // Will get the position of the guild the player is in
  8423. position = guild_getposition( sd );
  8424. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8425. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8426. }else if( sd->clan ){
  8427. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8428. }
  8429. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8430. packet.title_id = sd->status.title_id; // Title ID
  8431. #endif
  8432. clif_send(&packet, sizeof(packet), src, target);
  8433. }
  8434. break;
  8435. //[blackhole89]
  8436. case BL_HOM:
  8437. case BL_MER:
  8438. case BL_PET:
  8439. case BL_NPC:
  8440. case BL_ELEM: {
  8441. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8442. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8443. packet.gid = bl->id;
  8444. switch (bl->type) {
  8445. case BL_HOM:
  8446. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8447. break;
  8448. case BL_MER:
  8449. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8450. break;
  8451. case BL_PET:
  8452. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8453. break;
  8454. case BL_NPC:
  8455. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8456. break;
  8457. case BL_ELEM:
  8458. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8459. break;
  8460. }
  8461. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8462. unit_data *ud = unit_bl2ud(bl);
  8463. if (ud != nullptr) {
  8464. memcpy(packet.title, ud->title, NAME_LENGTH);
  8465. packet.groupId = ud->group_id;
  8466. }
  8467. #endif
  8468. clif_send(&packet, sizeof(packet), src, target);
  8469. }
  8470. break;
  8471. case BL_MOB: {
  8472. mob_data *md = (mob_data *)bl;
  8473. if( md->guardian_data && md->guardian_data->guild_id ){
  8474. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8475. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8476. packet.gid = bl->id;
  8477. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8478. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8479. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8480. clif_send(&packet, sizeof(packet), src, target);
  8481. }else if( battle_config.show_mob_info ){
  8482. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8483. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8484. packet.gid = bl->id;
  8485. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8486. char mobhp[50], *str_p = mobhp;
  8487. if( battle_config.show_mob_info&4 ){
  8488. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8489. }
  8490. if( battle_config.show_mob_info&1 ){
  8491. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8492. }
  8493. if( battle_config.show_mob_info&2 ){
  8494. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8495. }
  8496. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8497. if( str_p != mobhp ){
  8498. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8499. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8500. }
  8501. clif_send(&packet, sizeof(packet), src, target);
  8502. } else {
  8503. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8504. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8505. packet.gid = bl->id;
  8506. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8507. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8508. unit_data *ud = unit_bl2ud(bl);
  8509. if (ud != nullptr) {
  8510. memcpy(packet.title, ud->title, NAME_LENGTH);
  8511. packet.groupId = ud->group_id;
  8512. }
  8513. #endif
  8514. clif_send(&packet, sizeof(packet), src, target);
  8515. }
  8516. }
  8517. break;
  8518. case BL_CHAT:
  8519. case BL_SKILL:
  8520. // Newer clients request this, but do not need an answer
  8521. return;
  8522. default:
  8523. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8524. return;
  8525. }
  8526. }
  8527. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8528. /// 01ff <id>.L <x>.W <y>.W
  8529. ///
  8530. /// Visually moves(instant) a character to x,y. The char moves even
  8531. /// when the target cell isn't walkable. If the char is sitting it
  8532. /// stays that way.
  8533. void clif_slide(struct block_list *bl, int x, int y)
  8534. {
  8535. unsigned char buf[10];
  8536. nullpo_retv(bl);
  8537. WBUFW(buf, 0) = 0x01ff;
  8538. WBUFL(buf, 2) = bl->id;
  8539. WBUFW(buf, 6) = x;
  8540. WBUFW(buf, 8) = y;
  8541. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8542. if( disguised(bl) )
  8543. {
  8544. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8545. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8546. }
  8547. }
  8548. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8549. /// 008d <packet len>.W <id>.L <message>.?B
  8550. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8551. {
  8552. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8553. int len_mes = strlen(mes)+1; //Account for \0
  8554. if (len_mes > sizeof(buf)-8) {
  8555. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8556. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8557. }
  8558. // send message to others
  8559. if (flag == AREA) {
  8560. WBUFW(buf,0) = 0x8d;
  8561. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8562. WBUFL(buf,4) = bl->id;
  8563. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8564. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8565. }
  8566. // send back message to the speaker
  8567. if( bl->type == BL_PC ) {
  8568. WBUFW(buf,0) = 0x8e;
  8569. WBUFW(buf, 2) = len_mes + 4;
  8570. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8571. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8572. }
  8573. }
  8574. /*==========================
  8575. * Minimap fix [Kevin]
  8576. * Remove dot from minimap
  8577. *--------------------------*/
  8578. void clif_party_xy_remove(struct map_session_data* sd)
  8579. {
  8580. nullpo_retv(sd);
  8581. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8582. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8583. p.AID = sd->status.account_id;
  8584. p.xPos = -1;
  8585. p.yPos = -1;
  8586. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8587. }
  8588. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8589. /// 0215 <msg id>.L
  8590. /// msg id:
  8591. /// 0x15 = End all negative status (PA_GOSPEL)
  8592. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8593. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8594. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8595. /// 0x19 = All stats +20 (PA_GOSPEL)
  8596. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8597. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8598. /// 0x1e = DEF +25% (PA_GOSPEL)
  8599. /// 0x1f = ATK +100% (PA_GOSPEL)
  8600. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8601. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8602. /// ? = nothing
  8603. void clif_gospel_info(struct map_session_data *sd, int type)
  8604. {
  8605. int fd=sd->fd;
  8606. WFIFOHEAD(fd,packet_len(0x215));
  8607. WFIFOW(fd,0)=0x215;
  8608. WFIFOL(fd,2)=type;
  8609. WFIFOSET(fd, packet_len(0x215));
  8610. }
  8611. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8612. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8613. /// result:
  8614. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8615. /// star:
  8616. /// 0 = Place of the Sun
  8617. /// 1 = Place of the Moon
  8618. /// 2 = Place of the Stars
  8619. /// 1 = Star Gladiator %s's %s: <mapname>
  8620. /// star:
  8621. /// 0 = Place of the Sun
  8622. /// 1 = Place of the Moon
  8623. /// 2 = Place of the Stars
  8624. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8625. /// star:
  8626. /// 0 = Target of the Sun
  8627. /// 1 = Target of the Moon
  8628. /// 2 = Target of the Stars
  8629. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8630. /// star:
  8631. /// 0 = Monster of the Sun
  8632. /// 1 = Monster of the Moon
  8633. /// 2 = Monster of the Stars
  8634. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8635. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8636. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8637. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8638. /// 40 = Target HP : <monster_id used as HP>
  8639. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8640. {
  8641. int fd = sd->fd;
  8642. WFIFOHEAD(fd,packet_len(0x20e));
  8643. WFIFOW(fd,0) = 0x20e;
  8644. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8645. WFIFOL(fd,26) = monster_id;
  8646. WFIFOB(fd,30) = star;
  8647. WFIFOB(fd,31) = result;
  8648. WFIFOSET(fd,packet_len(0x20e));
  8649. }
  8650. /*==========================================
  8651. * Info about Star Glaldiator save map [Komurka]
  8652. * type: 1: Information, 0: Map registered
  8653. *------------------------------------------*/
  8654. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8655. {
  8656. char mapname[MAP_NAME_LENGTH_EXT];
  8657. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8658. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8659. }
  8660. /*==========================================
  8661. * Info about Star Glaldiator hate mob [Komurka]
  8662. * type: 1: Register mob, 0: Information.
  8663. *------------------------------------------*/
  8664. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8665. {
  8666. if( pcdb_checkid(class_) ) {
  8667. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8668. } else if( mobdb_checkid(class_) ) {
  8669. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8670. } else {
  8671. 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);
  8672. }
  8673. }
  8674. /*==========================================
  8675. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8676. *------------------------------------------*/
  8677. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8678. {
  8679. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8680. }
  8681. /*==========================================
  8682. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8683. *------------------------------------------*/
  8684. void clif_feel_hate_reset(struct map_session_data *sd)
  8685. {
  8686. clif_starskill(sd, "", 0, 0, 30);
  8687. }
  8688. /// Send out reply to configuration change
  8689. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8690. /// type: see enum e_config_type
  8691. /// value:
  8692. /// false = disabled
  8693. /// true = enabled
  8694. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8695. int fd;
  8696. nullpo_retv(sd);
  8697. fd = sd->fd;
  8698. WFIFOHEAD(fd, packet_len(0x2d9));
  8699. WFIFOW(fd, 0) = 0x2d9;
  8700. WFIFOL(fd, 2) = type;
  8701. WFIFOL(fd, 6) = enabled;
  8702. WFIFOSET(fd, packet_len(0x2d9));
  8703. }
  8704. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8705. /// 02da <open equip window>.B
  8706. /// open equip window:
  8707. /// 0 = disabled
  8708. /// 1 = enabled
  8709. void clif_equipcheckbox(struct map_session_data* sd)
  8710. {
  8711. int fd;
  8712. nullpo_retv(sd);
  8713. fd = sd->fd;
  8714. WFIFOHEAD(fd, packet_len(0x2da));
  8715. WFIFOW(fd, 0) = 0x2da;
  8716. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8717. WFIFOSET(fd, packet_len(0x2da));
  8718. }
  8719. /// Sends info about a player's equipped items.
  8720. /// 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)
  8721. /// 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)
  8722. /// 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)
  8723. /// 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)
  8724. /// 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)
  8725. /// 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)
  8726. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8727. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8728. nullpo_retv( sd );
  8729. nullpo_retv( tsd );
  8730. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8731. int equip = 0;
  8732. for( int i = 0; i < EQI_MAX; i++ ){
  8733. int k = tsd->equip_index[i];
  8734. if( k >= 0 ){
  8735. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8736. continue;
  8737. }
  8738. if( !tsd->inventory.u.items_inventory[k].equip ){
  8739. continue;
  8740. }
  8741. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8742. continue;
  8743. }
  8744. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8745. }
  8746. }
  8747. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8748. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8749. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8750. p->job = tsd->status.class_;
  8751. p->head = tsd->vd.hair_style;
  8752. p->accessory = tsd->vd.head_bottom;
  8753. p->accessory2 = tsd->vd.head_mid;
  8754. p->accessory3 = tsd->vd.head_top;
  8755. #if PACKETVER >= 20110111
  8756. p->robe = tsd->vd.robe;
  8757. #endif
  8758. p->headpalette = tsd->vd.hair_color;
  8759. p->bodypalette = tsd->vd.cloth_color;
  8760. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8761. p->body2 = tsd->vd.body_style;
  8762. #endif
  8763. p->sex = tsd->vd.sex;
  8764. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8765. #endif
  8766. }
  8767. /// Display msgstringtable.txt string (ZC_MSG).
  8768. /// 0291 <message>.W
  8769. void clif_msg(struct map_session_data* sd, unsigned short id)
  8770. {
  8771. int fd;
  8772. nullpo_retv(sd);
  8773. fd = sd->fd;
  8774. WFIFOHEAD(fd, packet_len(0x291));
  8775. WFIFOW(fd, 0) = 0x291;
  8776. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8777. WFIFOSET(fd, packet_len(0x291));
  8778. }
  8779. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8780. /// 0x7e2 <message>.W <value>.L
  8781. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8782. {
  8783. int fd = sd->fd;
  8784. WFIFOHEAD(fd, packet_len(0x7e2));
  8785. WFIFOW(fd,0) = 0x7e2;
  8786. WFIFOW(fd,2) = id;
  8787. WFIFOL(fd,4) = value;
  8788. WFIFOSET(fd, packet_len(0x7e2));
  8789. }
  8790. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8791. /// 07e6 <skill id>.W <msg id>.L
  8792. ///
  8793. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8794. /// "[SkillName] Message"
  8795. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8796. {
  8797. int fd = sd->fd;
  8798. WFIFOHEAD(fd, packet_len(0x7e6));
  8799. WFIFOW(fd,0) = 0x7e6;
  8800. WFIFOW(fd,2) = skill_id;
  8801. WFIFOL(fd,4) = msg_id;
  8802. WFIFOSET(fd, packet_len(0x7e6));
  8803. }
  8804. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8805. /// 09cd <msg id>.W <color>.L
  8806. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8807. nullpo_retv(sd);
  8808. int fd = sd->fd;
  8809. WFIFOHEAD(fd, packet_len(0x9cd));
  8810. WFIFOW(fd, 0) = 0x9cd;
  8811. WFIFOW(fd, 2) = msg_id;
  8812. WFIFOL(fd, 4) = color;
  8813. WFIFOSET(fd, packet_len(0x9cd));
  8814. }
  8815. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8816. /// Returns true if the packet was parsed successfully.
  8817. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8818. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8819. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8820. const char* seperator = " : ";
  8821. int fd;
  8822. struct s_packet_db* info;
  8823. uint16 packetLength, inputLength;
  8824. const char *input, *name, *message;
  8825. size_t nameLength, messageLength;
  8826. fd = sd->fd;
  8827. info = &packet_db[RFIFOW(fd,0)];
  8828. packetLength = RFIFOW(fd,info->pos[0]);
  8829. input = RFIFOCP(fd,info->pos[1]);
  8830. // basic structure check for the 4-byte header
  8831. if( packetLength < 4 ){
  8832. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8833. return false;
  8834. }else{
  8835. inputLength = packetLength - 4;
  8836. }
  8837. // process <name> part of the packet
  8838. if( whisperFormat ) {
  8839. // name has fixed width
  8840. if( inputLength < NAME_LENGTH + 1 ) {
  8841. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8842. return false;
  8843. }
  8844. name = input;
  8845. // validate name
  8846. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8847. // only restriction is that the name must be zero-terminated
  8848. if( name[nameLength] != '\0' ) {
  8849. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8850. return false;
  8851. }
  8852. message = input + NAME_LENGTH;
  8853. messageLength = inputLength - NAME_LENGTH;
  8854. }else{
  8855. // name and message are separated by ' : '
  8856. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8857. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8858. // check if there's enough data provided
  8859. if( inputLength < nameLength + seperatorLength + 1 ){
  8860. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8861. return false;
  8862. }
  8863. name = input;
  8864. // validate name
  8865. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8866. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8867. {
  8868. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8869. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8870. set_eof(sd->fd); // Just kick them out to correct it.
  8871. return false;
  8872. }
  8873. message = input + nameLength + seperatorLength;
  8874. messageLength = inputLength - nameLength - seperatorLength;
  8875. }
  8876. #if PACKETVER < 20151001
  8877. // the declared length must match real length
  8878. if( messageLength != strnlen(message, messageLength)+1 ) {
  8879. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8880. return false;
  8881. }
  8882. // verify <message> part of the packet
  8883. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8884. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8885. return false;
  8886. }
  8887. #else
  8888. // No zero termination anymore
  8889. messageLength += 1;
  8890. #endif
  8891. // messages mustn't be too long
  8892. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8893. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8894. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8895. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8896. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8897. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8898. return false;
  8899. }
  8900. // If it is not a whisper message, set the name to the fakename of the player
  8901. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8902. strcpy( out_name, sd->fakename );
  8903. }else{
  8904. safestrncpy( out_name, name, nameLength + 1 );
  8905. }
  8906. safestrncpy( out_message, message, messageLength );
  8907. if( whisperFormat ){
  8908. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8909. out_full_message[nameLength] = '\0';
  8910. }else{
  8911. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8912. }
  8913. if( is_atcommand( fd, sd, out_message, 1 ) )
  8914. return false;
  8915. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8916. return false; //no "chatting" while muted.
  8917. if( battle_config.min_chat_delay ) { //[Skotlex]
  8918. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8919. return false;
  8920. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8921. }
  8922. if (battle_config.idletime_option&IDLE_CHAT)
  8923. sd->idletime = last_tick;
  8924. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8925. sd->idletime_hom = last_tick;
  8926. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8927. sd->idletime_mer = last_tick;
  8928. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8929. return true;
  8930. }
  8931. /**
  8932. * Displays a message if the player enters a PK Zone (during pk_mode)
  8933. * @param sd: Player data
  8934. */
  8935. inline void clif_pk_mode_message(struct map_session_data * sd)
  8936. {
  8937. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8938. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8939. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8940. char output[CHAT_SIZE_MAX];
  8941. // 1504: You've entered a PK Zone (safe until level %d).
  8942. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8943. battle_config.pk_min_level);
  8944. clif_showscript(&sd->bl, output, SELF);
  8945. } else {
  8946. // 1503: You've entered a PK Zone.
  8947. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8948. }
  8949. }
  8950. return;
  8951. }
  8952. // ---------------------
  8953. // clif_parse_wanttoconnect
  8954. // ---------------------
  8955. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8956. // error codes:
  8957. // 0 - Success
  8958. // 1 - Unknown packet_ver
  8959. // 2 - Invalid account_id
  8960. // 3 - Invalid char_id
  8961. // 4 - Invalid login_id1 (reserved)
  8962. // 5 - Invalid client_tick (reserved)
  8963. // 6 - Invalid sex
  8964. // Only the first 'invalid' error that appears is used.
  8965. static int clif_parse_WantToConnection_sub(int fd)
  8966. {
  8967. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8968. unsigned short cmd;
  8969. //By default, start searching on the default one.
  8970. cmd = RFIFOW(fd, 0);
  8971. packet_len = RFIFOREST(fd);
  8972. // FIXME: If the packet is not received at once, this will FAIL.
  8973. // Figure out, when it happens, that only part of the packet is
  8974. // received, or fix the function to be able to deal with that
  8975. // case.
  8976. if( packet_len != packet_db[cmd].len )
  8977. return 1; /* wrong length */
  8978. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8979. return 2; /* invalid account_id */
  8980. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8981. return 3; /* invalid char_id */
  8982. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8983. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8984. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8985. return 6; /* invalid sex */
  8986. else
  8987. return 0;
  8988. }
  8989. /// Request to connect to map-server.
  8990. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8991. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8992. /// There are various variants of this packet, some of them have padding between fields.
  8993. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8994. {
  8995. struct block_list* bl;
  8996. struct auth_node* node;
  8997. int cmd, account_id, char_id, login_id1, sex, err;
  8998. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8999. if (sd) {
  9000. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9001. return;
  9002. }
  9003. cmd = RFIFOW(fd, 0);
  9004. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9005. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9006. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9007. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9008. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9009. err = clif_parse_WantToConnection_sub(fd);
  9010. if( err ){ // connection rejected
  9011. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9012. err == 1 ? "." :
  9013. err == 2 ? ", possibly for having an invalid account_id." :
  9014. err == 3 ? ", possibly for having an invalid char_id." :
  9015. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9016. err == 4 ? ", possibly for having an invalid login_id1." :
  9017. err == 5 ? ", possibly for having an invalid client_tick." :
  9018. */
  9019. err == 6 ? ", possibly for having an invalid sex." :
  9020. ". ERROR invalid error code"));
  9021. WFIFOHEAD(fd,packet_len(0x6a));
  9022. WFIFOW(fd,0) = 0x6a;
  9023. WFIFOB(fd,2) = err;
  9024. WFIFOSET(fd,packet_len(0x6a));
  9025. #ifdef DUMP_INVALID_PACKET
  9026. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9027. #endif
  9028. RFIFOSKIP(fd, RFIFOREST(fd));
  9029. set_eof(fd);
  9030. return;
  9031. }
  9032. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  9033. clif_authfail_fd(fd,1);// server closed
  9034. return;
  9035. }
  9036. //Check for double login.
  9037. bl = map_id2bl(account_id);
  9038. if(bl && bl->type != BL_PC) {
  9039. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9040. WFIFOHEAD(fd,packet_len(0x6a));
  9041. WFIFOW(fd,0) = 0x6a;
  9042. WFIFOB(fd,2) = 3; // Rejected by server
  9043. WFIFOSET(fd,packet_len(0x6a));
  9044. set_eof(fd);
  9045. return;
  9046. }
  9047. if (bl ||
  9048. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9049. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9050. {
  9051. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9052. return;
  9053. }
  9054. CREATE(sd, TBL_PC, 1);
  9055. sd->fd = fd;
  9056. #ifdef PACKET_OBFUSCATION
  9057. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9058. #endif
  9059. session[fd]->session_data = sd;
  9060. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9061. #if PACKETVER < 20070521
  9062. WFIFOHEAD(fd,4);
  9063. WFIFOL(fd,0) = sd->bl.id;
  9064. WFIFOSET(fd,4);
  9065. #else
  9066. WFIFOHEAD(fd,packet_len(0x283));
  9067. WFIFOW(fd,0) = 0x283;
  9068. WFIFOL(fd,2) = sd->bl.id;
  9069. WFIFOSET(fd,packet_len(0x283));
  9070. #endif
  9071. chrif_authreq(sd,false);
  9072. }
  9073. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9074. /// 007d
  9075. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  9076. {
  9077. bool guild_notice = false;
  9078. if(sd->bl.prev != NULL)
  9079. return;
  9080. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9081. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9082. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9083. sd->state.connect_new = 0;
  9084. return;
  9085. }
  9086. if (sd->state.rewarp) { //Rewarp player.
  9087. sd->state.rewarp = 0;
  9088. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9089. return;
  9090. }
  9091. sd->state.warping = 0;
  9092. // look
  9093. #if PACKETVER < 4
  9094. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9095. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9096. #else
  9097. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9098. #endif
  9099. pc_set_costume_view(sd);
  9100. if(sd->vd.cloth_color)
  9101. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9102. if(sd->vd.body_style)
  9103. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9104. // item
  9105. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9106. pc_checkitem(sd);
  9107. clif_equipswitch_list(sd);
  9108. // cart
  9109. if(pc_iscarton(sd)) {
  9110. clif_cartlist(sd);
  9111. clif_updatestatus(sd,SP_CARTINFO);
  9112. }
  9113. // weight
  9114. clif_updatestatus(sd,SP_WEIGHT);
  9115. clif_updatestatus(sd,SP_MAXWEIGHT);
  9116. // guild
  9117. // (needs to go before clif_spawn() to show guild emblems correctly)
  9118. if(sd->status.guild_id)
  9119. guild_send_memberinfoshort(sd,1);
  9120. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9121. if(battle_config.pc_invincible_time > 0) {
  9122. if(mapdata_flag_gvg(mapdata))
  9123. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9124. else
  9125. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9126. }
  9127. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9128. map_spawnmobs(sd->bl.m);
  9129. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9130. mapdata->users_pvp++;
  9131. }
  9132. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9133. // reset the callshop flag if the player changes map
  9134. sd->state.callshop = 0;
  9135. if(map_addblock(&sd->bl))
  9136. return;
  9137. clif_spawn(&sd->bl);
  9138. // Party
  9139. // (needs to go after clif_spawn() to show hp bars correctly)
  9140. if(sd->status.party_id) {
  9141. party_send_movemap(sd);
  9142. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9143. }
  9144. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9145. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9146. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9147. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9148. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9149. sd->pvp_rank = 0;
  9150. sd->pvp_lastusers = 0;
  9151. sd->pvp_point = 5;
  9152. sd->pvp_won = 0;
  9153. sd->pvp_lost = 0;
  9154. }
  9155. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9156. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9157. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9158. else if (mapdata->flag[MF_GVG_DUNGEON])
  9159. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9160. else if( mapdata_flag_gvg(mapdata) )
  9161. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9162. else
  9163. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9164. // info about nearby objects
  9165. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9166. 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);
  9167. // pet
  9168. if( sd->pd ) {
  9169. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9170. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9171. pet_return_egg( sd, sd->pd );
  9172. } else {
  9173. if(map_addblock(&sd->pd->bl))
  9174. return;
  9175. clif_spawn(&sd->pd->bl);
  9176. clif_send_petdata(sd,sd->pd,0,0);
  9177. clif_send_petstatus(sd);
  9178. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9179. }
  9180. }
  9181. //homunculus [blackhole89]
  9182. if( hom_is_active(sd->hd) ) {
  9183. if(map_addblock(&sd->hd->bl))
  9184. return;
  9185. clif_spawn(&sd->hd->bl);
  9186. clif_send_homdata(sd,SP_ACK,0);
  9187. clif_hominfo(sd,sd->hd,1);
  9188. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9189. clif_homskillinfoblock(sd);
  9190. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9191. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9192. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9193. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9194. }
  9195. if( sd->md ) {
  9196. if(map_addblock(&sd->md->bl))
  9197. return;
  9198. clif_spawn(&sd->md->bl);
  9199. clif_mercenary_info(sd);
  9200. clif_mercenary_skillblock(sd);
  9201. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9202. }
  9203. if( sd->ed ) {
  9204. if (map_addblock(&sd->ed->bl))
  9205. return;
  9206. clif_spawn(&sd->ed->bl);
  9207. clif_elemental_info(sd);
  9208. clif_elemental_updatestatus(sd,SP_HP);
  9209. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9210. clif_elemental_updatestatus(sd,SP_SP);
  9211. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9212. }
  9213. if(sd->state.connect_new) {
  9214. int lv;
  9215. guild_notice = true;
  9216. clif_skillinfoblock(sd);
  9217. clif_hotkeys_send(sd,0);
  9218. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9219. clif_hotkeys_send(sd,1);
  9220. #endif
  9221. clif_updatestatus(sd,SP_BASEEXP);
  9222. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9223. clif_updatestatus(sd,SP_JOBEXP);
  9224. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9225. clif_updatestatus(sd,SP_SKILLPOINT);
  9226. clif_initialstatus(sd);
  9227. if (sd->sc.option&OPTION_FALCON)
  9228. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9229. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9230. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9231. else if (sd->sc.option&OPTION_WUGRIDER)
  9232. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9233. else if (sd->sc.data[SC_ALL_RIDING])
  9234. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9235. if(sd->status.manner < 0)
  9236. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9237. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9238. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9239. if(sd->bl.m == sd->feel_map[0].m
  9240. || sd->bl.m == sd->feel_map[1].m
  9241. || sd->bl.m == sd->feel_map[2].m)
  9242. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9243. }
  9244. if(sd->pd && sd->pd->pet.intimate > 900)
  9245. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9246. if(hom_is_active(sd->hd))
  9247. hom_init_timers(sd->hd);
  9248. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9249. sd->state.night = 1;
  9250. clif_status_load(&sd->bl, EFST_SKE, 1);
  9251. }
  9252. // Notify everyone that this char logged in [Skotlex].
  9253. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9254. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9255. //Login Event
  9256. npc_script_event(sd, NPCE_LOGIN);
  9257. }
  9258. // Set facing direction before check below to update client
  9259. if (battle_config.spawn_direction)
  9260. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9261. } else {
  9262. //For some reason the client "loses" these on warp/map-change.
  9263. clif_updatestatus(sd,SP_STR);
  9264. clif_updatestatus(sd,SP_AGI);
  9265. clif_updatestatus(sd,SP_VIT);
  9266. clif_updatestatus(sd,SP_INT);
  9267. clif_updatestatus(sd,SP_DEX);
  9268. clif_updatestatus(sd,SP_LUK);
  9269. #ifdef RENEWAL
  9270. clif_updatestatus(sd,SP_POW);
  9271. clif_updatestatus(sd,SP_STA);
  9272. clif_updatestatus(sd,SP_WIS);
  9273. clif_updatestatus(sd,SP_SPL);
  9274. clif_updatestatus(sd,SP_CON);
  9275. clif_updatestatus(sd,SP_CRT);
  9276. #endif
  9277. // abort currently running script
  9278. sd->state.using_fake_npc = 0;
  9279. sd->state.menu_or_input = 0;
  9280. sd->npc_menu = 0;
  9281. if(sd->npc_id)
  9282. npc_event_dequeue(sd);
  9283. }
  9284. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9285. clif_partyinvitationstate( *sd );
  9286. #if PACKETVER >= 20070918
  9287. clif_equipcheckbox(sd);
  9288. #endif
  9289. clif_pet_autofeed_status(sd,false);
  9290. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9291. #if PACKETVER >= 20170920
  9292. if( battle_config.homunculus_autofeed_always ){
  9293. // Always send ON or OFF
  9294. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9295. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9296. }else{
  9297. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9298. }
  9299. }else{
  9300. // Only send when enabled
  9301. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9302. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9303. }
  9304. }
  9305. #endif
  9306. clif_reputation_list( *sd );
  9307. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9308. clif_guild_notice(sd); // Displays after VIP
  9309. guild_notice = false; // Do not display it twice
  9310. }
  9311. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9312. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9313. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9314. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9315. }
  9316. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9317. { //Display night.
  9318. if( !sd->state.night )
  9319. {
  9320. sd->state.night = 1;
  9321. clif_status_load(&sd->bl, EFST_SKE, 1);
  9322. }
  9323. }
  9324. else if( sd->state.night )
  9325. { //Clear night display.
  9326. sd->state.night = 0;
  9327. clif_status_load(&sd->bl, EFST_SKE, 0);
  9328. }
  9329. if( mapdata->flag[MF_BATTLEGROUND] )
  9330. {
  9331. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9332. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9333. clif_bg_updatescore_single(sd);
  9334. }
  9335. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9336. {
  9337. char output[128];
  9338. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9339. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9340. }
  9341. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9342. mapdata->hpmeter_visible++;
  9343. sd->state.hpmeter_visible = 1;
  9344. }
  9345. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9346. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9347. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9348. #ifdef VIP_ENABLE
  9349. if (!sd->state.connect_new &&
  9350. !sd->vip.disableshowrate &&
  9351. sd->state.pmap != sd->bl.m &&
  9352. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9353. )
  9354. {
  9355. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9356. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9357. }
  9358. #endif
  9359. // Instances do not need their own channels
  9360. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9361. channel_mjoin(sd); //join new map
  9362. clif_pk_mode_message(sd);
  9363. }
  9364. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9365. clif_guild_notice(sd); // Displays at end
  9366. }
  9367. mail_clear(sd);
  9368. /* Guild Aura Init */
  9369. if( sd->guild && sd->state.gmaster_flag ) {
  9370. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9371. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9372. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9373. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9374. }
  9375. if( sd->state.vending ) { /* show we have a vending */
  9376. clif_openvending(sd,sd->bl.id,sd->vending);
  9377. clif_showvendingboard( *sd );
  9378. }
  9379. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9380. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9381. npc_script_event(sd, NPCE_LOADMAP);
  9382. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9383. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9384. if (sd->sc.opt2) //Client loses these on warp.
  9385. clif_changeoption(&sd->bl);
  9386. 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)) {
  9387. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9388. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9389. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9390. }
  9391. clif_weather_check(sd);
  9392. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9393. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9394. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9395. else
  9396. sd->areanpc.clear();
  9397. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9398. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9399. pc_setdead(sd);
  9400. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9401. if(pc_isdead(sd))
  9402. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9403. else {
  9404. skill_usave_trigger(sd);
  9405. if (battle_config.spawn_direction)
  9406. clif_changed_dir(&sd->bl, SELF);
  9407. }
  9408. // Trigger skill effects if you appear standing on them
  9409. if(!battle_config.pc_invincible_time)
  9410. skill_unit_move(&sd->bl,gettick(),1);
  9411. pc_show_questinfo_reinit(sd);
  9412. pc_show_questinfo(sd);
  9413. #if PACKETVER >= 20150513
  9414. if( sd->mail.inbox.unread ){
  9415. clif_Mail_new(sd, 0, NULL, NULL);
  9416. }
  9417. #endif
  9418. sd->state.connect_new = 0;
  9419. sd->state.changemap = false;
  9420. }
  9421. /// Server's tick (ZC_NOTIFY_TIME).
  9422. /// 007f <time>.L
  9423. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9424. {
  9425. int fd = sd->fd;
  9426. WFIFOHEAD(fd,packet_len(0x7f));
  9427. WFIFOW(fd,0) = 0x7f;
  9428. WFIFOL(fd,2) = client_tick(time);
  9429. WFIFOSET(fd,packet_len(0x7f));
  9430. }
  9431. /// Request for server's tick.
  9432. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9433. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9434. /// There are various variants of this packet, some of them have padding between fields.
  9435. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9436. {
  9437. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9438. clif_notify_time(sd, gettick());
  9439. }
  9440. /// Sends hotkey bar.
  9441. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9442. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9443. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9444. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9445. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9446. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9447. nullpo_retv( sd );
  9448. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9449. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9450. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9451. if( tab == 0 ){
  9452. p.rotate = sd->status.hotkey_rowshift;
  9453. }else{
  9454. p.rotate = sd->status.hotkey_rowshift2;
  9455. }
  9456. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9457. p.tab = tab;
  9458. #endif
  9459. #endif
  9460. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9461. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9462. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9463. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9464. }
  9465. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9466. #endif
  9467. }
  9468. /// Request to update a position on the hotkey row bar
  9469. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9470. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9471. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9472. if( p->tab == 0 ){
  9473. sd->status.hotkey_rowshift = p->rowshift;
  9474. }else{
  9475. sd->status.hotkey_rowshift2 = p->rowshift;
  9476. }
  9477. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9478. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9479. sd->status.hotkey_rowshift = p->rowshift;
  9480. #endif
  9481. }
  9482. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9483. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9484. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9485. #ifdef HOTKEY_SAVING
  9486. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9487. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9488. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9489. if( idx >= MAX_HOTKEYS_DB ){
  9490. return;
  9491. }
  9492. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9493. sd->status.hotkeys[idx].id = p->hotkey.id;
  9494. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9495. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9496. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9497. const unsigned short idx = p->index;
  9498. if( idx >= MAX_HOTKEYS_DB ){
  9499. return;
  9500. }
  9501. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9502. sd->status.hotkeys[idx].id = p->hotkey.id;
  9503. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9504. #endif
  9505. #endif
  9506. }
  9507. /// Displays cast-like progress bar (ZC_PROGRESS).
  9508. /// 02f0 <color>.L <time>.L
  9509. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9510. {
  9511. int fd = sd->fd;
  9512. WFIFOHEAD(fd,packet_len(0x2f0));
  9513. WFIFOW(fd,0) = 0x2f0;
  9514. WFIFOL(fd,2) = color;
  9515. WFIFOL(fd,6) = second;
  9516. WFIFOSET(fd,packet_len(0x2f0));
  9517. }
  9518. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9519. /// 02f2
  9520. void clif_progressbar_abort(struct map_session_data * sd)
  9521. {
  9522. int fd = sd->fd;
  9523. WFIFOHEAD(fd,packet_len(0x2f2));
  9524. WFIFOW(fd,0) = 0x2f2;
  9525. WFIFOSET(fd,packet_len(0x2f2));
  9526. }
  9527. /// Notification from the client, that the progress bar has reached 100%.
  9528. /// 02f1 (CZ_PROGRESS)
  9529. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9530. // No progressbar active, ignore it
  9531. if( !sd->progressbar.npc_id ){
  9532. return;
  9533. }
  9534. int npc_id = sd->progressbar.npc_id;
  9535. bool closing = false;
  9536. // Check if the progress was canceled
  9537. if( gettick() < sd->progressbar.timeout && sd->st ){
  9538. closing = true;
  9539. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9540. // If a message window was open, offer a close button to the user
  9541. if( sd->st->mes_active ){
  9542. clif_scriptclose( sd, npc_id );
  9543. }
  9544. }
  9545. sd->progressbar.npc_id = 0;
  9546. sd->progressbar.timeout = 0;
  9547. sd->state.workinprogress = WIP_DISABLE_NONE;
  9548. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9549. sd->idletime = last_tick;
  9550. }
  9551. npc_scriptcont(sd, npc_id, closing);
  9552. }
  9553. /// Displays cast-like progress bar on a NPC
  9554. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9555. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9556. #if PACKETVER >= 20130821
  9557. unsigned char buf[14];
  9558. if( nd->progressbar.timeout > 0 ){
  9559. WBUFW(buf,0) = 0x9d1;
  9560. WBUFL(buf,2) = nd->bl.id;
  9561. WBUFL(buf,6) = nd->progressbar.color;
  9562. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9563. if( sd ){
  9564. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9565. }else{
  9566. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9567. }
  9568. }
  9569. #endif
  9570. }
  9571. /// Request to walk to a certain position on the current map.
  9572. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9573. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9574. /// There are various variants of this packet, some of them have padding between fields.
  9575. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9576. {
  9577. short x, y;
  9578. if (pc_isdead(sd)) {
  9579. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9580. return;
  9581. }
  9582. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9583. ; //You CAN walk on this OPT1 value.
  9584. else if (sd->progressbar.npc_id) {
  9585. clif_progressbar_abort(sd);
  9586. return; // First walk attempt cancels the progress bar
  9587. } else if (pc_cant_act(sd))
  9588. return;
  9589. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9590. return;
  9591. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9592. //A move command one cell west is only valid if the target cell is free
  9593. if(battle_config.official_cell_stack_limit > 0
  9594. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9595. return;
  9596. // Cloaking wall check is actually updated when you click to process next movement
  9597. // not when you move each cell. This is official behaviour.
  9598. if (sd->sc.data[SC_CLOAKING])
  9599. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9600. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9601. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9602. pc_delinvincibletimer(sd);
  9603. //Set last idle time... [Skotlex]
  9604. if (battle_config.idletime_option&IDLE_WALK)
  9605. sd->idletime = last_tick;
  9606. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9607. sd->idletime_hom = last_tick;
  9608. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9609. sd->idletime_mer = last_tick;
  9610. unit_walktoxy(&sd->bl, x, y, 4);
  9611. }
  9612. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9613. /// 018b <result>.W
  9614. /// result:
  9615. /// 0 = disconnect (quit)
  9616. /// 1 = cannot disconnect (wait 10 seconds)
  9617. /// ? = ignored
  9618. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9619. {
  9620. int fd = sd->fd;
  9621. WFIFOHEAD(fd,packet_len(0x18b));
  9622. WFIFOW(fd,0) = 0x18b;
  9623. WFIFOW(fd,2) = result;
  9624. WFIFOSET(fd,packet_len(0x18b));
  9625. }
  9626. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9627. /// 018a <type>.W
  9628. /// type:
  9629. /// 0 = quit
  9630. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9631. {
  9632. /* Rovert's prevent logout option fixed [Valaris] */
  9633. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9634. 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] &&
  9635. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9636. {
  9637. pc_damage_log_clear(sd,0);
  9638. clif_disconnect_ack(sd, 0);
  9639. flush_fifo( fd );
  9640. if( battle_config.drop_connection_on_quit ){
  9641. set_eof( fd );
  9642. }
  9643. } else {
  9644. clif_disconnect_ack(sd, 1);
  9645. }
  9646. }
  9647. /// Requesting unit's name.
  9648. /// 0094 <id>.L (CZ_REQNAME)
  9649. /// 0368 <id>.L (CZ_REQNAME2)
  9650. /// There are various variants of this packet, some of them have padding between fields.
  9651. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9652. {
  9653. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9654. struct block_list* bl;
  9655. //struct status_change *sc;
  9656. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9657. id = sd->bl.id;
  9658. bl = map_id2bl(id);
  9659. if( bl == NULL )
  9660. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9661. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9662. return; // Block namerequests past view range
  9663. // 'see people in GM hide' cheat detection
  9664. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9665. sc = status_get_sc(bl);
  9666. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9667. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9668. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9669. ) {
  9670. char gm_msg[256];
  9671. 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);
  9672. ShowWarning(gm_msg);
  9673. // information is sent to all online GMs
  9674. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9675. return;
  9676. }
  9677. */
  9678. clif_name(&sd->bl,bl,SELF);
  9679. }
  9680. /// Validates and processes global messages
  9681. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9682. /// There are various variants of this packet.
  9683. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9684. {
  9685. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9686. size_t length;
  9687. // validate packet and retrieve name and message
  9688. if( !clif_process_message(sd, false, name, message, output ) )
  9689. return;
  9690. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9691. channel_send(sd->gcbind,sd,message);
  9692. return;
  9693. }
  9694. // send message to others (using the send buffer for temp. storage)
  9695. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9696. length = strlen(output) + 1;
  9697. // send back message to the speaker
  9698. WFIFOHEAD(fd,4+length);
  9699. WFIFOW(fd,0) = 0x8e;
  9700. WFIFOW(fd,2) = (uint16)(4+length);
  9701. safestrncpy(WFIFOCP(fd,4), output, length );
  9702. WFIFOSET(fd, WFIFOW(fd,2));
  9703. #ifdef PCRE_SUPPORT
  9704. // trigger listening npcs
  9705. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9706. #endif
  9707. // Chat logging type 'O' / Global Chat
  9708. 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);
  9709. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9710. }
  9711. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9712. /// Request to warp to a map on given coordinates.
  9713. /// 0140 <map name>.16B <x>.W <y>.W
  9714. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9715. {
  9716. char command[MAP_NAME_LENGTH_EXT+25];
  9717. char* map_name;
  9718. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9719. map_name = RFIFOCP(fd,info->pos[0]);
  9720. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9721. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9722. RFIFOW(fd,info->pos[1]), //x
  9723. RFIFOW(fd,info->pos[2])); //y
  9724. is_atcommand(fd, sd, command, 1);
  9725. }
  9726. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9727. /// 009c <id>.L <head dir>.W <dir>.B
  9728. /// head dir:
  9729. /// 0 = straight
  9730. /// 1 = turned CW
  9731. /// 2 = turned CCW
  9732. /// dir:
  9733. /// 0 = north
  9734. /// 1 = northwest
  9735. /// 2 = west
  9736. /// 3 = southwest
  9737. /// 4 = south
  9738. /// 5 = southeast
  9739. /// 6 = east
  9740. /// 7 = northeast
  9741. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9742. {
  9743. unsigned char buf[64];
  9744. WBUFW(buf,0) = 0x9c;
  9745. WBUFL(buf,2) = bl->id;
  9746. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9747. WBUFB(buf,8) = unit_getdir(bl);
  9748. clif_send(buf, packet_len(0x9c), bl, target);
  9749. if (disguised(bl)) {
  9750. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9751. WBUFW(buf,6) = 0;
  9752. clif_send(buf, packet_len(0x9c), bl, SELF);
  9753. }
  9754. }
  9755. /// Request to change own body and head direction.
  9756. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9757. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9758. /// There are various variants of this packet, some of them have padding between fields.
  9759. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9760. {
  9761. unsigned char headdir, dir;
  9762. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9763. headdir = RFIFOB(fd,info->pos[0]);
  9764. dir = RFIFOB(fd,info->pos[1]);
  9765. pc_setdir(sd, dir, headdir);
  9766. clif_changed_dir(&sd->bl, AREA_WOS);
  9767. }
  9768. /// Request to show an emotion (CZ_REQ_EMOTION).
  9769. /// 00bf <type>.B
  9770. /// type:
  9771. /// @see enum emotion_type
  9772. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9773. {
  9774. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9775. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9776. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9777. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9778. return;
  9779. }
  9780. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9781. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9782. sd->emotionlasttime = time(NULL);
  9783. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9784. return;
  9785. }
  9786. sd->emotionlasttime = time(NULL);
  9787. if (battle_config.idletime_option&IDLE_EMOTION)
  9788. sd->idletime = last_tick;
  9789. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9790. sd->idletime_hom = last_tick;
  9791. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9792. sd->idletime_mer = last_tick;
  9793. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9794. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9795. return;
  9796. }
  9797. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9798. emoticon = rnd()%6+ET_DICE1;
  9799. }
  9800. clif_emotion(&sd->bl, emoticon);
  9801. } else
  9802. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9803. }
  9804. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9805. /// 00c2 <count>.L
  9806. void clif_user_count(struct map_session_data* sd, int count)
  9807. {
  9808. int fd = sd->fd;
  9809. WFIFOHEAD(fd,packet_len(0xc2));
  9810. WFIFOW(fd,0) = 0xc2;
  9811. WFIFOL(fd,2) = count;
  9812. WFIFOSET(fd,packet_len(0xc2));
  9813. }
  9814. /// /w /who (CZ_REQ_USER_COUNT).
  9815. /// Request to display amount of currently connected players.
  9816. /// 00c1
  9817. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9818. {
  9819. clif_user_count(sd, map_getusers());
  9820. }
  9821. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9822. {
  9823. if (pc_isdead(sd)) {
  9824. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9825. return;
  9826. }
  9827. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9828. if (action_type != 0x00 && action_type != 0x07) {
  9829. if (sd->sc.cant.interact)
  9830. return;
  9831. pc_stop_walking(sd, 1);
  9832. }
  9833. pc_stop_attack(sd);
  9834. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9835. target_id = sd->bl.id;
  9836. switch(action_type)
  9837. {
  9838. case 0x00: // once attack
  9839. case 0x07: // continuous attack
  9840. if( pc_cant_act(sd) )
  9841. return;
  9842. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9843. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9844. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9845. return;
  9846. }
  9847. }
  9848. pc_delinvincibletimer(sd);
  9849. if (battle_config.idletime_option&IDLE_ATTACK)
  9850. sd->idletime = last_tick;
  9851. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9852. sd->idletime_hom = last_tick;
  9853. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9854. sd->idletime_mer = last_tick;
  9855. unit_attack(&sd->bl, target_id, action_type != 0);
  9856. break;
  9857. case 0x02: // sitdown
  9858. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9859. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9860. break;
  9861. }
  9862. if(pc_issit(sd)) {
  9863. //Bugged client? Just refresh them.
  9864. clif_sitting(&sd->bl);
  9865. return;
  9866. }
  9867. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9868. break;
  9869. if (sd->sc.count && (
  9870. sd->sc.data[SC_DANCING] ||
  9871. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9872. )) //No sitting during these states either.
  9873. break;
  9874. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9875. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9876. break;
  9877. }
  9878. if (battle_config.idletime_option&IDLE_SIT)
  9879. sd->idletime = last_tick;
  9880. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9881. sd->idletime_hom = last_tick;
  9882. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9883. sd->idletime_mer = last_tick;
  9884. pc_setsit(sd);
  9885. skill_sit(sd, true);
  9886. clif_sitting(&sd->bl);
  9887. break;
  9888. case 0x03: // standup
  9889. if (!pc_issit(sd)) {
  9890. //Bugged client? Just refresh them.
  9891. clif_standing(&sd->bl);
  9892. return;
  9893. }
  9894. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9895. break;
  9896. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9897. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9898. break;
  9899. }
  9900. if (pc_setstand(sd, false)) {
  9901. if (battle_config.idletime_option&IDLE_SIT)
  9902. sd->idletime = last_tick;
  9903. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9904. sd->idletime_hom = last_tick;
  9905. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9906. sd->idletime_mer = last_tick;
  9907. skill_sit(sd, false);
  9908. clif_standing(&sd->bl);
  9909. }
  9910. break;
  9911. }
  9912. }
  9913. /// Request for an action.
  9914. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9915. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9916. /// action:
  9917. /// 0 = attack
  9918. /// 1 = pick up item
  9919. /// 2 = sit down
  9920. /// 3 = stand up
  9921. /// 7 = continous attack
  9922. /// 12 = (touch skill?)
  9923. /// There are various variants of this packet, some of them have padding between fields.
  9924. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9925. {
  9926. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9927. clif_parse_ActionRequest_sub(sd,
  9928. RFIFOB(fd,info->pos[1]),
  9929. RFIFOL(fd,info->pos[0]),
  9930. gettick()
  9931. );
  9932. }
  9933. /// Response to the death/system menu (CZ_RESTART).
  9934. /// 00b2 <type>.B
  9935. /// type:
  9936. /// 0 = restart (respawn)
  9937. /// 1 = char-select (disconnect)
  9938. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9939. {
  9940. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9941. case 0x00:
  9942. pc_respawn(sd,CLR_OUTSIGHT);
  9943. break;
  9944. case 0x01:
  9945. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9946. 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] &&
  9947. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9948. { //Send to char-server for character selection.
  9949. pc_damage_log_clear(sd,0);
  9950. chrif_charselectreq(sd, session[fd]->client_addr);
  9951. } else {
  9952. clif_disconnect_ack(sd, 1);
  9953. }
  9954. break;
  9955. }
  9956. }
  9957. /// Validates and processes whispered messages (CZ_WHISPER).
  9958. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9959. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9960. {
  9961. struct map_session_data* dstsd;
  9962. int i;
  9963. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9964. // validate packet and retrieve name and message
  9965. if( !clif_process_message( sd, true, target, message, output ) )
  9966. return;
  9967. // Chat logging type 'W' / Whisper
  9968. 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);
  9969. //-------------------------------------------------------//
  9970. // Lordalfa - Paperboy - To whisper NPC commands //
  9971. //-------------------------------------------------------//
  9972. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9973. {
  9974. char* str = target+4; //Skip the NPC: string part.
  9975. struct npc_data* npc;
  9976. if ((npc = npc_name2id(str))) {
  9977. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9978. char *split;
  9979. char event[EVENT_NAME_LENGTH];
  9980. str = message;
  9981. // skip codepage indicator, if detected
  9982. if( str[0] == '|' && strlen(str) >= 4 )
  9983. str += 3;
  9984. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9985. split = strchr(str,'#');
  9986. if( split == NULL ) { // use the remaining string
  9987. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9988. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9989. split_data[i][0] = '\0';
  9990. break;
  9991. }
  9992. *split = '\0';
  9993. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9994. str = split+1;
  9995. }
  9996. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9997. char variablename[CHAT_SIZE_MAX];
  9998. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9999. set_var_str( sd, variablename, split_data[i] );
  10000. }
  10001. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  10002. npc_event(sd,event,0); // Calls the NPC label
  10003. return;
  10004. }
  10005. } else if( target[0] == '#' ) {
  10006. struct Channel *channel = NULL;
  10007. char* chname = target;
  10008. channel = channel_name2channel(chname,sd,3);
  10009. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  10010. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  10011. channel_send(channel,sd,message);
  10012. }
  10013. else if( channel->pass[0] == '\0') { //no pass needed
  10014. if (channel_join(channel,sd)==0)
  10015. channel_send(channel,sd,message); //join success
  10016. }
  10017. else {
  10018. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  10019. }
  10020. return;
  10021. }
  10022. }
  10023. // searching destination character
  10024. dstsd = map_nick2sd(target,false);
  10025. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  10026. // player is not on this map-server
  10027. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  10028. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  10029. // and if we ask for 'Test', we must not contact 'test' player
  10030. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  10031. intif_wis_message(sd, target, message, strlen(message) + 1);
  10032. return;
  10033. }
  10034. // if player ignores everyone
  10035. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10036. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  10037. clif_wis_end(fd, 1); // 1: target character is not logged in
  10038. else
  10039. clif_wis_end(fd, 3); // 3: everyone ignored by target
  10040. return;
  10041. }
  10042. // if player is autotrading
  10043. if (dstsd->state.autotrade == 1){
  10044. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  10045. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  10046. return;
  10047. }
  10048. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10049. // if player ignores the source character
  10050. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  10051. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  10052. clif_wis_end(fd, 2); // 2: ignored by target
  10053. return;
  10054. }
  10055. }
  10056. // notify sender of success
  10057. clif_wis_end(fd, 0); // 0: success to send wisper
  10058. // Normal message
  10059. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10060. }
  10061. /// /b /nb (CZ_BROADCAST).
  10062. /// Request to broadcast a message on whole server.
  10063. /// 0099 <packet len>.W <text>.?B 00
  10064. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  10065. char command[CHAT_SIZE_MAX+11];
  10066. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10067. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10068. char* msg = RFIFOCP(fd,info->pos[1]);
  10069. // as the length varies depending on the command used, just block unreasonably long strings
  10070. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10071. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10072. is_atcommand(fd, sd, command, 1);
  10073. }
  10074. /// Request to pick up an item.
  10075. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10076. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10077. /// There are various variants of this packet, some of them have padding between fields.
  10078. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  10079. {
  10080. struct flooritem_data *fitem;
  10081. int map_object_id;
  10082. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10083. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10084. do {
  10085. if (pc_isdead(sd)) {
  10086. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10087. break;
  10088. }
  10089. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10090. break;
  10091. if (pc_cant_act(sd))
  10092. break;
  10093. if (!pc_takeitem(sd, fitem))
  10094. break;
  10095. return;
  10096. } while (0);
  10097. // Client REQUIRES a fail packet or you can no longer pick items.
  10098. clif_additem(sd,0,0,6);
  10099. }
  10100. /// Request to drop an item.
  10101. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10102. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10103. /// There are various variants of this packet, some of them have padding between fields.
  10104. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  10105. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10106. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10107. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10108. for(;;) {
  10109. if (pc_isdead(sd))
  10110. break;
  10111. if (pc_cant_act2(sd) || sd->npc_id)
  10112. break;
  10113. if (sd->sc.cant.drop)
  10114. break;
  10115. if (!pc_dropitem(sd, item_index, item_amount))
  10116. break;
  10117. if (battle_config.idletime_option&IDLE_DROPITEM)
  10118. sd->idletime = last_tick;
  10119. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10120. sd->idletime_hom = last_tick;
  10121. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10122. sd->idletime_mer = last_tick;
  10123. return;
  10124. }
  10125. //Because the client does not like being ignored.
  10126. clif_dropitem(sd, item_index,0);
  10127. }
  10128. /// Request to use an item.
  10129. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10130. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10131. /// There are various variants of this packet, some of them have padding between fields.
  10132. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  10133. {
  10134. int n;
  10135. if (pc_isdead(sd)) {
  10136. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10137. return;
  10138. }
  10139. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10140. clif_msg(sd, WORK_IN_PROGRESS);
  10141. return;
  10142. }
  10143. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10144. if (battle_config.idletime_option&IDLE_USEITEM)
  10145. sd->idletime = last_tick;
  10146. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10147. sd->idletime_hom = last_tick;
  10148. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10149. sd->idletime_mer = last_tick;
  10150. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10151. if(n <0 || n >= MAX_INVENTORY)
  10152. return;
  10153. if (!pc_useitem(sd,n))
  10154. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10155. }
  10156. /// Request to equip an item
  10157. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10158. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10159. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10160. {
  10161. int index;
  10162. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10163. if(pc_isdead(sd)) {
  10164. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10165. return;
  10166. }
  10167. index = RFIFOW(fd,info->pos[0])-2;
  10168. if (index < 0 || index >= MAX_INVENTORY)
  10169. return; //Out of bounds check.
  10170. if(sd->npc_id && !sd->npc_item_flag) {
  10171. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10172. return;
  10173. } else if (sd->state.storage_flag || sd->sc.opt1)
  10174. ; //You can equip/unequip stuff while storage is open/under status changes
  10175. else if (pc_cant_act2(sd))
  10176. return;
  10177. if(!sd->inventory.u.items_inventory[index].identify) {
  10178. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  10179. return;
  10180. }
  10181. if(!sd->inventory_data[index])
  10182. return;
  10183. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10184. pet_equipitem(sd,index);
  10185. return;
  10186. }
  10187. if (battle_config.idletime_option&IDLE_USEITEM)
  10188. sd->idletime = last_tick;
  10189. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10190. sd->idletime_hom = last_tick;
  10191. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10192. sd->idletime_mer = last_tick;
  10193. //Client doesn't send the position for ammo.
  10194. if(sd->inventory_data[index]->type == IT_AMMO)
  10195. pc_equipitem(sd,index,EQP_AMMO);
  10196. else {
  10197. int req_pos;
  10198. #if PACKETVER >= 20120925
  10199. req_pos = RFIFOL(fd,info->pos[1]);
  10200. #else
  10201. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10202. #endif
  10203. pc_equipitem(sd,index,req_pos);
  10204. }
  10205. }
  10206. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10207. /// 00ab <index>.W
  10208. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10209. {
  10210. int index;
  10211. if(pc_isdead(sd)) {
  10212. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10213. return;
  10214. }
  10215. if (sd->npc_id && !sd->npc_item_flag) {
  10216. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10217. return;
  10218. } else if (sd->state.storage_flag || sd->sc.opt1)
  10219. ; //You can equip/unequip stuff while storage is open/under status changes
  10220. else if (pc_cant_act2(sd))
  10221. return;
  10222. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10223. if (battle_config.idletime_option&IDLE_USEITEM)
  10224. sd->idletime = last_tick;
  10225. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10226. sd->idletime_hom = last_tick;
  10227. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10228. sd->idletime_mer = last_tick;
  10229. pc_unequipitem(sd,index,1);
  10230. }
  10231. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10232. /// 0090 <id>.L <type>.B
  10233. /// type:
  10234. /// 1 = click
  10235. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10236. {
  10237. struct block_list *bl;
  10238. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10239. if(pc_isdead(sd)) {
  10240. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10241. return;
  10242. }
  10243. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10244. #ifdef RENEWAL
  10245. clif_msg( sd, WORK_IN_PROGRESS );
  10246. #endif
  10247. return;
  10248. }
  10249. if( sd->state.mail_writing )
  10250. return;
  10251. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10252. //type = RFIFOB(fd,info->pos[1]);
  10253. if (!bl) return;
  10254. switch (bl->type) {
  10255. case BL_MOB:
  10256. case BL_PC:
  10257. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10258. break;
  10259. case BL_NPC:
  10260. #ifdef RENEWAL
  10261. 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
  10262. clif_msg(sd, WORK_IN_PROGRESS);
  10263. break;
  10264. }
  10265. #endif
  10266. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10267. struct npc_data* nd = (struct npc_data*)bl;
  10268. // Progressbar is running
  10269. if( nd->progressbar.timeout > 0 ){
  10270. return;
  10271. }
  10272. npc_click(sd,nd);
  10273. }
  10274. break;
  10275. }
  10276. }
  10277. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10278. /// 00c5 <id>.L <type>.B
  10279. /// type:
  10280. /// 0 = buy
  10281. /// 1 = sell
  10282. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10283. {
  10284. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10285. if (sd->state.trading)
  10286. return;
  10287. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10288. }
  10289. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10290. /// 00ca <result>.B
  10291. /// result:
  10292. /// 0 = "The deal has successfully completed."
  10293. /// 1 = "You do not have enough zeny."
  10294. /// 2 = "You are over your Weight Limit."
  10295. /// 3 = "Out of the maximum capacity, you have too many items."
  10296. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10297. /// 10 = "Props open-air store sales will be traded in RODEX"
  10298. /// 11 = "The exchange failed."
  10299. /// 12 = "The exchange was well done."
  10300. /// 13 = "The item is already sold and out of stock."
  10301. /// 14 = "There is not enough goods to exchange."
  10302. void clif_npc_buy_result( struct map_session_data* sd, e_purchase_result result ){
  10303. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10304. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10305. p.result = (uint8)result;
  10306. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10307. }
  10308. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10309. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10310. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10311. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10312. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10313. e_purchase_result result;
  10314. if( sd->state.trading || !sd->npc_shopid )
  10315. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10316. else{
  10317. std::vector<s_npc_buy_list> items = {};
  10318. items.reserve( n );
  10319. for( uint16 i = 0; i < n; i++ ){
  10320. s_npc_buy_list item = {};
  10321. item.nameid = p->items[i].itemId;
  10322. item.qty = p->items[i].amount;
  10323. items.push_back( item );
  10324. }
  10325. result = npc_buylist( sd, items );
  10326. }
  10327. sd->npc_shopid = 0; //Clear shop data.
  10328. clif_npc_buy_result(sd, result);
  10329. }
  10330. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10331. /// 00cb <result>.B
  10332. /// result:
  10333. /// 0 = "The deal has successfully completed."
  10334. /// 1 = "The deal has failed."
  10335. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10336. {
  10337. int fd = sd->fd;
  10338. WFIFOHEAD(fd,packet_len(0xcb));
  10339. WFIFOW(fd,0) = 0xcb;
  10340. WFIFOB(fd,2) = result;
  10341. WFIFOSET(fd,packet_len(0xcb));
  10342. }
  10343. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10344. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10345. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10346. {
  10347. int fail=0,n;
  10348. unsigned short *item_list;
  10349. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10350. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10351. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10352. if (sd->state.trading || !sd->npc_shopid)
  10353. fail = 1;
  10354. else
  10355. fail = npc_selllist(sd,n,item_list);
  10356. sd->npc_shopid = 0; //Clear shop data.
  10357. clif_npc_sell_result(sd, fail);
  10358. }
  10359. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10360. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10361. /// type:
  10362. /// 0 = private
  10363. /// 1 = public
  10364. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10365. {
  10366. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10367. int len = RFIFOW(fd,info->pos[0])-15;
  10368. int limit = RFIFOW(fd,info->pos[1]);
  10369. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10370. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10371. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10372. char s_password[CHATROOM_PASS_SIZE];
  10373. char s_title[CHATROOM_TITLE_SIZE];
  10374. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10375. return;
  10376. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10377. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10378. return;
  10379. }
  10380. if( npc_isnear(&sd->bl) ) {
  10381. // uncomment to send msg_txt.
  10382. //char output[150];
  10383. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10384. //clif_displaymessage(sd->fd, output);
  10385. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10386. return;
  10387. }
  10388. if( len <= 0 )
  10389. return; // invalid input
  10390. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10391. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10392. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10393. }
  10394. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10395. /// 00d9 <chat ID>.L <passwd>.8B
  10396. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10397. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10398. int chatid = RFIFOL(fd,info->pos[0]);
  10399. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10400. chat_joinchat(sd,chatid,password);
  10401. }
  10402. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10403. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10404. /// type:
  10405. /// 0 = private
  10406. /// 1 = public
  10407. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10408. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10409. int len = RFIFOW(fd,info->pos[0])-15;
  10410. int limit = RFIFOW(fd,info->pos[1]);
  10411. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10412. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10413. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10414. char s_password[CHATROOM_PASS_SIZE];
  10415. char s_title[CHATROOM_TITLE_SIZE];
  10416. if( len <= 0 )
  10417. return; // invalid input
  10418. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10419. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10420. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10421. }
  10422. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10423. /// 00e0 <role>.L <nick>.24B
  10424. /// role:
  10425. /// 0 = owner
  10426. /// 1 = normal
  10427. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10428. {
  10429. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10430. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10431. }
  10432. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10433. /// 00e2 <name>.24B
  10434. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10435. {
  10436. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10437. }
  10438. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10439. /// 00e3
  10440. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10441. {
  10442. chat_leavechat(sd,0);
  10443. }
  10444. //Handles notifying asker and rejecter of what has just ocurred.
  10445. //Type is used to determine the correct msg_txt to use:
  10446. //0:
  10447. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10448. {
  10449. const char* msg;
  10450. char output[256];
  10451. // Your request has been rejected by autoreject option.
  10452. msg = msg_txt(sd,392);
  10453. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10454. //Notice that a request was rejected.
  10455. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10456. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10457. }
  10458. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10459. /// 00e4 <account id>.L
  10460. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10461. {
  10462. struct map_session_data *t_sd;
  10463. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10464. if(!sd->chatID && pc_cant_act(sd))
  10465. return; //You can trade while in a chatroom.
  10466. if(t_sd){
  10467. // @noask [LuzZza]
  10468. if(t_sd->state.noask) {
  10469. clif_noask_sub(sd, t_sd, 0);
  10470. return;
  10471. }
  10472. if (t_sd->state.mail_writing) {
  10473. int old = sd->trade_partner;
  10474. // Fake trading
  10475. sd->trade_partner = t_sd->status.account_id;
  10476. clif_tradestart(sd, 5);
  10477. // Restore old state
  10478. sd->trade_partner = old;
  10479. return;
  10480. }
  10481. }
  10482. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10483. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10484. return;
  10485. }
  10486. trade_traderequest(sd,t_sd);
  10487. }
  10488. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10489. /// 00e6 <result>.B
  10490. /// result:
  10491. /// 3 = accepted
  10492. /// 4 = rejected
  10493. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10494. {
  10495. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10496. }
  10497. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10498. /// 00e8 <index>.W <amount>.L
  10499. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10500. {
  10501. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10502. short index = RFIFOW(fd,info->pos[0]);
  10503. int amount = RFIFOL(fd,info->pos[1]);
  10504. if( index == 0 )
  10505. trade_tradeaddzeny(sd, amount);
  10506. else
  10507. trade_tradeadditem(sd, index, (short)amount);
  10508. }
  10509. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10510. /// 00eb
  10511. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10512. {
  10513. trade_tradeok(sd);
  10514. }
  10515. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10516. /// 00ed
  10517. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10518. {
  10519. trade_tradecancel(sd);
  10520. }
  10521. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10522. /// 00ef
  10523. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10524. {
  10525. trade_tradecommit(sd);
  10526. }
  10527. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10528. /// 0118
  10529. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10530. {
  10531. pc_stop_attack(sd);
  10532. if (sd) sd->ud.state.attack_continue = 0;
  10533. }
  10534. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10535. /// 0126 <index>.W <amount>.L
  10536. void clif_parse_PutItemToCart( int fd, struct map_session_data *sd ){
  10537. if (pc_istrading(sd))
  10538. return;
  10539. if (!pc_iscarton(sd))
  10540. return;
  10541. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10542. return;
  10543. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10544. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10545. }
  10546. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10547. /// 0127 <index>.W <amount>.L
  10548. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10549. {
  10550. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10551. if (!pc_iscarton(sd))
  10552. return;
  10553. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10554. return;
  10555. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10556. }
  10557. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10558. /// 012a
  10559. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10560. {
  10561. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10562. #ifdef NEW_CARTS
  10563. && sd->sc.data[SC_PUSH_CART] )
  10564. pc_setcart(sd,0);
  10565. #else
  10566. )
  10567. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10568. #endif
  10569. else // priority to remove this option before we can clear cart
  10570. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10571. }
  10572. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10573. /// 097f <Length>.W <identity>.L <type>.B
  10574. void clif_SelectCart(struct map_session_data *sd) {
  10575. #if PACKETVER >= 20150826
  10576. int i = 0, carts = 3;
  10577. int fd = sd->fd;
  10578. WFIFOHEAD(fd,8 + carts);
  10579. WFIFOW(fd,0) = 0x97f;
  10580. WFIFOW(fd,2) = 8 + carts;
  10581. WFIFOL(fd,4) = sd->status.account_id;
  10582. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10583. for( i = 0; i < carts; i++ ) {
  10584. WFIFOB(fd,8 + i) = 10 + i;
  10585. }
  10586. WFIFOSET(fd,8 + carts);
  10587. #endif
  10588. }
  10589. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10590. /// 0980 <identity>.L <type>.B
  10591. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10592. #if PACKETVER >= 20150826
  10593. int type;
  10594. // Check identity
  10595. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10596. return;
  10597. type = (int)RFIFOB(fd,6);
  10598. // Check type
  10599. if( type < 10 || type > 12 )
  10600. return;
  10601. pc_setcart(sd, type);
  10602. #endif
  10603. }
  10604. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10605. /// 01af <num>.W
  10606. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10607. {// TODO: State tracking?
  10608. int type;
  10609. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10610. return;
  10611. #ifdef RENEWAL
  10612. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10613. clif_msg(sd, WORK_IN_PROGRESS);
  10614. return;
  10615. }
  10616. #endif
  10617. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10618. if(
  10619. #ifdef NEW_CARTS
  10620. #if PACKETVER >= 20191106
  10621. (type == 13 && sd->status.base_level > 100) ||
  10622. #endif
  10623. (type == 9 && sd->status.base_level > 130) ||
  10624. (type == 8 && sd->status.base_level > 120) ||
  10625. (type == 7 && sd->status.base_level > 110) ||
  10626. (type == 6 && sd->status.base_level > 100) ||
  10627. #endif
  10628. (type == 5 && sd->status.base_level > 90) ||
  10629. (type == 4 && sd->status.base_level > 80) ||
  10630. (type == 3 && sd->status.base_level > 65) ||
  10631. (type == 2 && sd->status.base_level > 40) ||
  10632. (type == 1))
  10633. pc_setcart(sd, type);
  10634. }
  10635. /// Request to increase status (CZ_STATUS_CHANGE).
  10636. /// 00bb <status id>.W <amount>.B
  10637. /// status id:
  10638. /// SP_STR ~ SP_LUK
  10639. /// amount:
  10640. /// Old clients always send 1 for this, even when using /str+ and the like.
  10641. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10642. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10643. {
  10644. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10645. if( increase_amount < 0 ) {
  10646. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10647. fd, increase_amount);
  10648. }
  10649. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10650. }
  10651. /// Request to increase trait status.
  10652. /// 0b24 <status id>.W <amount>.W
  10653. /// status id:
  10654. /// SP_POW ~ SP_CON
  10655. /// amount:
  10656. /// The amount to increase the trait status
  10657. void clif_parse_traitstatus_up( int fd, struct map_session_data *sd ){
  10658. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10659. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10660. if( p->amount < 0 ){
  10661. 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 );
  10662. return;
  10663. }
  10664. pc_traitstatusup( sd, p->type, p->amount );
  10665. #endif
  10666. }
  10667. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10668. /// 0112 <skill id>.W
  10669. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10670. {
  10671. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10672. }
  10673. 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)
  10674. {
  10675. int lv;
  10676. if( !hd )
  10677. return;
  10678. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10679. clif_emotion(&hd->bl, ET_THINK);
  10680. return;
  10681. }
  10682. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10683. target_id = hd->bl.id;
  10684. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10685. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10686. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10687. clif_emotion(&hd->bl, ET_THINK);
  10688. if (hd->master)
  10689. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10690. return;
  10691. }
  10692. lv = hom_checkskill(hd, skill_id);
  10693. if( skill_lv > lv )
  10694. skill_lv = lv;
  10695. if( skill_lv )
  10696. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10697. }
  10698. 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)
  10699. {
  10700. int lv;
  10701. if( !hd )
  10702. return;
  10703. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10704. clif_emotion(&hd->bl, ET_THINK);
  10705. return;
  10706. }
  10707. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10708. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10709. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10710. clif_emotion(&hd->bl, ET_THINK);
  10711. if (hd->master)
  10712. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10713. return;
  10714. }
  10715. #ifdef RENEWAL
  10716. if (hd->sc.data[SC_BASILICA_CELL])
  10717. #else
  10718. if (hd->sc.data[SC_BASILICA])
  10719. #endif
  10720. return;
  10721. lv = hom_checkskill(hd, skill_id);
  10722. if( skill_lv > lv )
  10723. skill_lv = lv;
  10724. if( skill_lv )
  10725. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10726. }
  10727. 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)
  10728. {
  10729. int lv;
  10730. if( !md )
  10731. return;
  10732. if( skill_isNotOk_mercenary(skill_id, md) )
  10733. return;
  10734. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10735. target_id = md->bl.id;
  10736. if( md->ud.skilltimer != INVALID_TIMER )
  10737. {
  10738. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10739. }
  10740. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10741. return;
  10742. lv = mercenary_checkskill(md, skill_id);
  10743. if( skill_lv > lv )
  10744. skill_lv = lv;
  10745. if( skill_lv )
  10746. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10747. }
  10748. 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)
  10749. {
  10750. int lv;
  10751. if( !md )
  10752. return;
  10753. if( skill_isNotOk_mercenary(skill_id, md) )
  10754. return;
  10755. if( md->ud.skilltimer != INVALID_TIMER )
  10756. return;
  10757. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10758. {
  10759. if (md->master)
  10760. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10761. return;
  10762. }
  10763. #ifdef RENEWAL
  10764. if (md->sc.data[SC_BASILICA_CELL])
  10765. #else
  10766. if (md->sc.data[SC_BASILICA])
  10767. #endif
  10768. return;
  10769. lv = mercenary_checkskill(md, skill_id);
  10770. if( skill_lv > lv )
  10771. skill_lv = lv;
  10772. if( skill_lv )
  10773. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10774. }
  10775. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10776. t_tick tick = gettick();
  10777. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10778. int inf = skill_get_inf(skill_id);
  10779. if (inf&INF_GROUND_SKILL || !inf)
  10780. return; //Using a ground/passive skill on a target? WRONG.
  10781. if (sd->state.block_action & PCBLOCK_SKILL) {
  10782. clif_msg(sd, WORK_IN_PROGRESS);
  10783. return;
  10784. }
  10785. if( SKILL_CHK_HOMUN(skill_id) ) {
  10786. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10787. return;
  10788. }
  10789. if( SKILL_CHK_MERC(skill_id) ) {
  10790. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10791. return;
  10792. }
  10793. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10794. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10795. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10796. sd->idletime = last_tick;
  10797. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10798. sd->idletime_hom = last_tick;
  10799. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10800. sd->idletime_mer = last_tick;
  10801. if( sd->npc_id ){
  10802. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10803. #ifdef RENEWAL
  10804. clif_msg( sd, WORK_IN_PROGRESS );
  10805. #endif
  10806. return;
  10807. }
  10808. }
  10809. if ((pc_cant_act2(sd) || sd->chatID) &&
  10810. skill_id != RK_REFRESH &&
  10811. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10812. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10813. return;
  10814. if( pc_issit(sd) )
  10815. return;
  10816. if( skill_isNotOk(skill_id, sd) )
  10817. return;
  10818. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10819. target_id = sd->bl.id; // never trust the client
  10820. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10821. target_id = sd->bl.id;
  10822. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10823. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10824. return;
  10825. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10826. if( sd->skillitem != skill_id ) {
  10827. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10828. return;
  10829. }
  10830. }
  10831. if( sd->sc.option&OPTION_COSTUME )
  10832. return;
  10833. #ifndef RENEWAL
  10834. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10835. return; // On basilica only caster can use Basilica again to stop it.
  10836. #endif
  10837. if( sd->menuskill_id ) {
  10838. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10839. clif_menuskill_clear(sd); //Cancel pet capture.
  10840. }else if( sd->menuskill_id == SG_FEEL ){
  10841. clif_menuskill_clear( sd ); // Cancel selection
  10842. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10843. return; //Can't use skills while a menu is open.
  10844. }
  10845. if( sd->skillitem == skill_id ) {
  10846. if( skill_lv != sd->skillitemlv )
  10847. skill_lv = sd->skillitemlv;
  10848. if( !(inf&INF_SELF_SKILL) )
  10849. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10850. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10851. return;
  10852. }
  10853. sd->skillitem = sd->skillitemlv = 0;
  10854. if( SKILL_CHK_GUILD(skill_id) ) {
  10855. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10856. skill_lv = guild_checkskill(sd->guild, skill_id);
  10857. else
  10858. skill_lv = 0;
  10859. } else {
  10860. if( skill_id != ALL_EQSWITCH ){
  10861. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10862. }
  10863. }
  10864. pc_delinvincibletimer(sd);
  10865. if( skill_lv )
  10866. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10867. }
  10868. /// Request to use a targeted skill.
  10869. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10870. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10871. /// There are various variants of this packet, some of them have padding between fields.
  10872. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10873. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10874. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10875. }
  10876. /*==========================================
  10877. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10878. *------------------------------------------*/
  10879. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10880. {
  10881. t_tick tick = gettick();
  10882. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10883. return; //Using a target skill on the ground? WRONG.
  10884. if (sd->state.block_action & PCBLOCK_SKILL) {
  10885. clif_msg(sd, WORK_IN_PROGRESS);
  10886. return;
  10887. }
  10888. if( SKILL_CHK_HOMUN(skill_id) ) {
  10889. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10890. return;
  10891. }
  10892. if( SKILL_CHK_MERC(skill_id) ) {
  10893. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10894. return;
  10895. }
  10896. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10897. #ifdef RENEWAL
  10898. clif_msg( sd, WORK_IN_PROGRESS );
  10899. #endif
  10900. return;
  10901. }
  10902. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10903. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10904. sd->idletime = last_tick;
  10905. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10906. sd->idletime_hom = last_tick;
  10907. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10908. sd->idletime_mer = last_tick;
  10909. if( skill_isNotOk(skill_id, sd) )
  10910. return;
  10911. if( skillmoreinfo != -1 ) {
  10912. if( pc_issit(sd) ) {
  10913. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10914. return;
  10915. }
  10916. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10917. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10918. }
  10919. if( sd->ud.skilltimer != INVALID_TIMER )
  10920. return;
  10921. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10922. if( sd->skillitem != skill_id ) {
  10923. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10924. return;
  10925. }
  10926. }
  10927. if( sd->sc.option&OPTION_COSTUME )
  10928. return;
  10929. #ifndef RENEWAL
  10930. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10931. return; // On basilica only caster can use Basilica again to stop it.
  10932. #endif
  10933. if( sd->menuskill_id ) {
  10934. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10935. clif_menuskill_clear(sd); //Cancel pet capture.
  10936. }else if( sd->menuskill_id == SG_FEEL ){
  10937. clif_menuskill_clear( sd ); // Cancel selection
  10938. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10939. return; //Can't use skills while a menu is open.
  10940. }
  10941. pc_delinvincibletimer(sd);
  10942. if( sd->skillitem == skill_id ) {
  10943. if( skill_lv != sd->skillitemlv )
  10944. skill_lv = sd->skillitemlv;
  10945. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10946. } else {
  10947. int lv;
  10948. sd->skillitem = sd->skillitemlv = 0;
  10949. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10950. if( skill_lv > lv )
  10951. skill_lv = lv;
  10952. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10953. }
  10954. }
  10955. }
  10956. /// Request to use a ground skill.
  10957. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10958. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10959. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10960. /// There are various variants of this packet, some of them have padding between fields.
  10961. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10962. {
  10963. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10964. if (pc_cant_act(sd))
  10965. return;
  10966. if (pc_issit(sd))
  10967. return;
  10968. clif_parse_UseSkillToPosSub(fd, sd,
  10969. RFIFOW(fd,info->pos[0]), //skill lv
  10970. RFIFOW(fd,info->pos[1]), //skill num
  10971. RFIFOW(fd,info->pos[2]), //pos x
  10972. RFIFOW(fd,info->pos[3]), //pos y
  10973. // TODO: find out what this is intended to do
  10974. //RFIFOB(fd, info->pos[4])
  10975. -1 //Skill more info.
  10976. );
  10977. }
  10978. /// Request to use a ground skill with text.
  10979. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10980. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10981. /// There are various variants of this packet, some of them have padding between fields.
  10982. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10983. {
  10984. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10985. if (pc_cant_act(sd))
  10986. return;
  10987. if (pc_issit(sd))
  10988. return;
  10989. clif_parse_UseSkillToPosSub(fd, sd,
  10990. RFIFOW(fd,info->pos[0]), //Skill lv
  10991. RFIFOW(fd,info->pos[1]), //Skill num
  10992. RFIFOW(fd,info->pos[2]), //pos x
  10993. RFIFOW(fd,info->pos[3]), //pos y
  10994. info->pos[4] //skill more info
  10995. );
  10996. }
  10997. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10998. /// 011b <skill id>.W <map name>.16B
  10999. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  11000. {
  11001. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11002. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11003. char map_name[MAP_NAME_LENGTH];
  11004. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11005. sd->state.workinprogress = WIP_DISABLE_NONE;
  11006. if(skill_id != sd->menuskill_id)
  11007. return;
  11008. //It is possible to use teleport with the storage window open bugreport:8027
  11009. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11010. clif_menuskill_clear(sd);
  11011. return;
  11012. }
  11013. pc_delinvincibletimer(sd);
  11014. skill_castend_map(sd,skill_id,map_name);
  11015. }
  11016. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11017. /// 011d
  11018. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  11019. {
  11020. if (!pc_isdead(sd))
  11021. pc_memo(sd,-1);
  11022. }
  11023. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11024. /// 018e <name id>.W { <material id>.W }*3
  11025. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  11026. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11027. switch( sd->menuskill_id ) {
  11028. case -1:
  11029. case AM_PHARMACY:
  11030. case RK_RUNEMASTERY:
  11031. case GC_RESEARCHNEWPOISON:
  11032. break;
  11033. default:
  11034. return;
  11035. }
  11036. if (pc_istrading(sd)) {
  11037. //Make it fail to avoid shop exploits where you sell something different than you see.
  11038. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11039. clif_menuskill_clear(sd);
  11040. return;
  11041. }
  11042. int produce_idx;
  11043. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11044. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11045. clif_menuskill_clear(sd);
  11046. }
  11047. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11048. /// 025b <mk type>.W <name id>.W
  11049. /// mk type:
  11050. /// 1 = cooking
  11051. /// 2 = arrow
  11052. /// 3 = elemental
  11053. /// 4 = GN_MIX_COOKING
  11054. /// 5 = GN_MAKEBOMB
  11055. /// 6 = GN_S_PHARMACY
  11056. /// 7 = MT_M_MACHINE - Unconfirmed
  11057. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11058. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  11059. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11060. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11061. short food_idx = -1;
  11062. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11063. return;
  11064. if (pc_istrading(sd)) {
  11065. //Make it fail to avoid shop exploits where you sell something different than you see.
  11066. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11067. clif_menuskill_clear(sd);
  11068. return;
  11069. }
  11070. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11071. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11072. clif_menuskill_clear(sd);
  11073. }
  11074. /// Answer to repair weapon item selection dialog
  11075. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11076. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11077. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  11078. // Hercules has wrong date -> use correct one here
  11079. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11080. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11081. #else
  11082. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11083. #endif
  11084. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11085. return;
  11086. if (pc_istrading(sd)) {
  11087. //Make it fail to avoid shop exploits where you sell something different than you see.
  11088. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11089. clif_menuskill_clear(sd);
  11090. return;
  11091. }
  11092. skill_repairweapon( sd, p->item.index );
  11093. clif_menuskill_clear(sd);
  11094. }
  11095. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11096. /// 0222 <index>.L
  11097. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  11098. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11099. return;
  11100. if (pc_istrading(sd)) {
  11101. //Make it fail to avoid shop exploits where you sell something different than you see.
  11102. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11103. clif_menuskill_clear(sd);
  11104. return;
  11105. }
  11106. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11107. clif_menuskill_clear(sd);
  11108. }
  11109. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11110. /// 00b8 <npc id>.L <choice>.B
  11111. /// choice:
  11112. /// 1~254 = menu item
  11113. /// 255 = cancel
  11114. /// NOTE: If there were more than 254 items in the list, choice
  11115. /// overflows to choice%256.
  11116. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  11117. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11118. int npc_id = RFIFOL(fd,info->pos[0]);
  11119. uint8 select = RFIFOB(fd,info->pos[1]);
  11120. #ifdef SECURE_NPCTIMEOUT
  11121. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11122. return;
  11123. #endif
  11124. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11125. TBL_NPC* nd = map_id2nd(npc_id);
  11126. 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);
  11127. clif_GM_kick(NULL,sd);
  11128. return;
  11129. }
  11130. sd->npc_menu = select;
  11131. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11132. sd->idletime = last_tick;
  11133. }
  11134. npc_scriptcont(sd,npc_id, false);
  11135. }
  11136. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11137. /// 00b9 <npc id>.L
  11138. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  11139. {
  11140. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11141. sd->idletime = last_tick;
  11142. }
  11143. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11144. }
  11145. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11146. /// 0143 <npc id>.L <value>.L
  11147. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  11148. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11149. int npcid = RFIFOL(fd,info->pos[0]);
  11150. int amount = (int)RFIFOL(fd,info->pos[1]);
  11151. sd->npc_amount = amount;
  11152. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11153. sd->idletime = last_tick;
  11154. }
  11155. npc_scriptcont(sd, npcid, false);
  11156. }
  11157. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11158. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11159. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  11160. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11161. int message_len = RFIFOW(fd,info->pos[0])-8;
  11162. int npcid = RFIFOL(fd,info->pos[1]);
  11163. const char* message = RFIFOCP(fd,info->pos[2]);
  11164. if( message_len <= 0 )
  11165. return; // invalid input
  11166. #if PACKETVER >= 20151001
  11167. message_len++;
  11168. #endif
  11169. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11170. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11171. sd->idletime = last_tick;
  11172. }
  11173. npc_scriptcont(sd, npcid, false);
  11174. }
  11175. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11176. /// 0146 <npc id>.L
  11177. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11178. {
  11179. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11180. return;
  11181. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11182. sd->idletime = last_tick;
  11183. }
  11184. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11185. }
  11186. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11187. /// 0178 <index>.W
  11188. /// index:
  11189. /// -1 = cancel
  11190. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11191. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11192. if (sd->menuskill_id != MC_IDENTIFY)
  11193. return;
  11194. // Ignore the request
  11195. // - Invalid item index
  11196. // - Invalid item ID or item doesn't exist
  11197. // - Item is already identified
  11198. if (idx < 0 || idx >= MAX_INVENTORY ||
  11199. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11200. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11201. sd->state.workinprogress = WIP_DISABLE_NONE;
  11202. clif_menuskill_clear(sd);
  11203. return;
  11204. }
  11205. skill_identify(sd, idx);
  11206. clif_menuskill_clear(sd);
  11207. }
  11208. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11209. /// 01ae <name id>.W
  11210. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11211. if (pc_istrading(sd)) {
  11212. //Make it fail to avoid shop exploits where you sell something different than you see.
  11213. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11214. clif_menuskill_clear(sd);
  11215. return;
  11216. }
  11217. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11218. switch (sd->menuskill_id) {
  11219. case AC_MAKINGARROW:
  11220. skill_arrow_create(sd,p->itemId);
  11221. break;
  11222. case SA_CREATECON:
  11223. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11224. break;
  11225. case GC_POISONINGWEAPON:
  11226. skill_poisoningweapon(sd,p->itemId);
  11227. break;
  11228. case NC_MAGICDECOY:
  11229. skill_magicdecoy(sd,p->itemId);
  11230. break;
  11231. }
  11232. clif_menuskill_clear(sd);
  11233. }
  11234. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11235. /// 01ce <skill id>.L
  11236. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11237. {
  11238. if (sd->menuskill_id != SA_AUTOSPELL)
  11239. return;
  11240. sd->state.workinprogress = WIP_DISABLE_NONE;
  11241. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11242. clif_menuskill_clear(sd);
  11243. }
  11244. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11245. /// 017a <card index>.W
  11246. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11247. {
  11248. if (sd->state.trading != 0)
  11249. return;
  11250. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11251. }
  11252. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11253. /// 017c <card index>.W <equip index>.W
  11254. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11255. {
  11256. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11257. if (sd->state.trading != 0)
  11258. return;
  11259. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11260. }
  11261. /// Request of character's name by char ID.
  11262. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11263. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11264. /// There are various variants of this packet, some of them have padding between fields.
  11265. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11266. {
  11267. int charid;
  11268. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11269. map_reqnickdb(sd, charid);
  11270. }
  11271. /// /resetskill /resetstate (CZ_RESET).
  11272. /// Request to reset stats or skills.
  11273. /// 0197 <type>.W
  11274. /// type:
  11275. /// 0 = state
  11276. /// 1 = skill
  11277. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11278. char cmd[15];
  11279. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11280. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11281. else
  11282. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11283. is_atcommand(fd, sd, cmd, 1);
  11284. }
  11285. /// /lb /nlb (CZ_LOCALBROADCAST).
  11286. /// Request to broadcast a message on current map.
  11287. /// 019c <packet len>.W <text>.?B
  11288. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11289. {
  11290. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11291. char command[CHAT_SIZE_MAX+16];
  11292. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11293. char* msg = RFIFOCP(fd,info->pos[1]);
  11294. // as the length varies depending on the command used, just block unreasonably long strings
  11295. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11296. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11297. is_atcommand(fd, sd, command, 1);
  11298. }
  11299. /// Request to move an item from inventory to storage.
  11300. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11301. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11302. /// There are various variants of this packet, some of them have padding between fields.
  11303. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11304. {
  11305. int item_index, item_amount;
  11306. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11307. if (pc_istrading(sd))
  11308. return;
  11309. item_index = RFIFOW(fd,info->pos[0])-2;
  11310. item_amount = RFIFOL(fd,info->pos[1]);
  11311. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11312. return;
  11313. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11314. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11315. return;
  11316. }
  11317. if (sd->state.storage_flag == 1)
  11318. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11319. else
  11320. if (sd->state.storage_flag == 2)
  11321. storage_guild_storageadd(sd, item_index, item_amount);
  11322. else if (sd->state.storage_flag == 3)
  11323. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11324. }
  11325. /// Request to move an item from storage to inventory.
  11326. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11327. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11328. /// There are various variants of this packet, some of them have padding between fields.
  11329. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11330. {
  11331. int item_index, item_amount;
  11332. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11333. item_index = RFIFOW(fd,info->pos[0])-1;
  11334. item_amount = RFIFOL(fd,info->pos[1]);
  11335. if (sd->state.storage_flag == 1)
  11336. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11337. else if(sd->state.storage_flag == 2)
  11338. storage_guild_storageget(sd, item_index, item_amount);
  11339. else if(sd->state.storage_flag == 3)
  11340. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11341. }
  11342. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11343. /// 0129 <index>.W <amount>.L
  11344. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11345. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11346. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11347. int amount = RFIFOL(fd,info->pos[1]);
  11348. if( sd->state.vending )
  11349. return;
  11350. if (!pc_iscarton(sd))
  11351. return;
  11352. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11353. return;
  11354. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11355. return;
  11356. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11357. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11358. return;
  11359. }
  11360. if (sd->state.storage_flag == 1)
  11361. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11362. else if (sd->state.storage_flag == 2)
  11363. storage_guild_storageaddfromcart(sd, idx, amount);
  11364. else if (sd->state.storage_flag == 3)
  11365. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11366. }
  11367. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11368. /// 0128 <index>.W <amount>.L
  11369. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11370. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11371. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11372. int amount = RFIFOL(fd,info->pos[1]);
  11373. if( sd->state.vending )
  11374. return;
  11375. if (!pc_iscarton(sd))
  11376. return;
  11377. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11378. return;
  11379. if (sd->state.storage_flag == 1)
  11380. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11381. else
  11382. if (sd->state.storage_flag == 2)
  11383. storage_guild_storagegettocart(sd, idx, amount);
  11384. else if (sd->state.storage_flag == 3)
  11385. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11386. }
  11387. /// Request to close storage (CZ_CLOSE_STORE).
  11388. /// 00f7
  11389. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11390. {
  11391. if( sd->state.storage_flag == 1 )
  11392. storage_storageclose(sd);
  11393. else
  11394. if( sd->state.storage_flag == 2 )
  11395. storage_guild_storageclose(sd);
  11396. else if( sd->state.storage_flag == 3 )
  11397. storage_premiumStorage_close(sd);
  11398. }
  11399. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11400. /// 023a <info>.W
  11401. /// info:
  11402. /// 0 = password has not been set yet
  11403. /// 1 = storage is password-protected
  11404. /// 8 = too many wrong passwords
  11405. /// ? = ignored
  11406. /// NOTE: This packet is only available on certain non-kRO clients.
  11407. void clif_storagepassword(struct map_session_data* sd, short info)
  11408. {
  11409. int fd = sd->fd;
  11410. WFIFOHEAD(fd,packet_len(0x23a));
  11411. WFIFOW(fd,0) = 0x23a;
  11412. WFIFOW(fd,2) = info;
  11413. WFIFOSET(fd,packet_len(0x23a));
  11414. }
  11415. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11416. /// 023b <type>.W <password>.16B <new password>.16B
  11417. /// type:
  11418. /// 2 = change password
  11419. /// 3 = check password
  11420. /// NOTE: This packet is only available on certain non-kRO clients.
  11421. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11422. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11423. // int type = RFIFOW(fd,info->pos[0]);
  11424. // char* password = RFIFOP(fd,info->pos[1]);
  11425. // char* new_password = RFIFOP(fd,info->pos[2]);
  11426. // storage_changepass(sd,password,new_password);
  11427. }
  11428. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11429. /// 023c <result>.W <error count>.W
  11430. /// result:
  11431. /// 4 = password change success
  11432. /// 5 = password change failure
  11433. /// 6 = password check success
  11434. /// 7 = password check failure
  11435. /// 8 = too many wrong passwords
  11436. /// ? = ignored
  11437. /// NOTE: This packet is only available on certain non-kRO clients.
  11438. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11439. {
  11440. int fd = sd->fd;
  11441. WFIFOHEAD(fd,packet_len(0x23c));
  11442. WFIFOW(fd,0) = 0x23c;
  11443. WFIFOW(fd,2) = result;
  11444. WFIFOW(fd,4) = error_count;
  11445. WFIFOSET(fd,packet_len(0x23c));
  11446. }
  11447. /// Party creation request
  11448. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11449. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11450. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11451. name[NAME_LENGTH-1] = '\0';
  11452. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11453. clif_displaymessage(fd, msg_txt(sd,227));
  11454. return;
  11455. }
  11456. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11457. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11458. return;
  11459. }
  11460. party_create(sd,name,0,0);
  11461. }
  11462. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11463. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11464. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11465. char* name = RFIFOCP(fd,info->pos[0]);
  11466. int item1 = RFIFOB(fd,info->pos[1]);
  11467. int item2 = RFIFOB(fd,info->pos[2]);
  11468. name[NAME_LENGTH-1] = '\0';
  11469. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11470. clif_displaymessage(fd, msg_txt(sd,227));
  11471. return;
  11472. }
  11473. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11474. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11475. return;
  11476. }
  11477. party_create(sd,name,item1,item2);
  11478. }
  11479. /// Party invitation request
  11480. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11481. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11482. {
  11483. struct map_session_data *t_sd;
  11484. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11485. clif_displaymessage(fd, msg_txt(sd,227));
  11486. return;
  11487. }
  11488. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11489. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11490. clif_noask_sub(sd, t_sd, 1);
  11491. return;
  11492. }
  11493. party_invite(sd, t_sd);
  11494. }
  11495. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11496. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11497. struct map_session_data *t_sd;
  11498. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11499. name[NAME_LENGTH-1] = '\0';
  11500. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11501. clif_displaymessage(fd, msg_txt(sd,227));
  11502. return;
  11503. }
  11504. t_sd = map_nick2sd(name,false);
  11505. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11506. clif_noask_sub(sd, t_sd, 1);
  11507. return;
  11508. }
  11509. party_invite(sd, t_sd);
  11510. }
  11511. /// Party invitation reply
  11512. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11513. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11514. /// flag:
  11515. /// 0 = reject
  11516. /// 1 = accept
  11517. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11518. {
  11519. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11520. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11521. RFIFOL(fd,info->pos[1]));
  11522. }
  11523. //(CZ_PARTY_JOIN_REQ_ACK)
  11524. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11525. {
  11526. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11527. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11528. RFIFOB(fd,info->pos[1]));
  11529. }
  11530. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11531. /// 0100
  11532. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11533. {
  11534. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11535. clif_displaymessage(fd, msg_txt(sd,227));
  11536. return;
  11537. }
  11538. party_leave(sd);
  11539. }
  11540. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11541. /// 0103 <account id>.L <char name>.24B
  11542. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11543. {
  11544. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11545. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11546. clif_displaymessage(fd, msg_txt(sd,227));
  11547. return;
  11548. }
  11549. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11550. RFIFOCP(fd,info->pos[1]));
  11551. }
  11552. /// Request to change party options.
  11553. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11554. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11555. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11556. {
  11557. struct party_data *p;
  11558. int i,expflag;
  11559. int cmd = RFIFOW(fd,0);
  11560. struct s_packet_db* info = &packet_db[cmd];
  11561. if( !sd->status.party_id )
  11562. return;
  11563. p = party_search(sd->status.party_id);
  11564. if( p == NULL )
  11565. return;
  11566. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11567. if( i == MAX_PARTY )
  11568. return; //Shouldn't happen
  11569. if( !p->party.member[i].leader )
  11570. return;
  11571. expflag = RFIFOL(fd,info->pos[0]);
  11572. if(cmd == 0x0102){ //Client can't change the item-field
  11573. party_changeoption(sd, expflag, p->party.item);
  11574. }
  11575. else {
  11576. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11577. party_changeoption(sd, expflag, itemflag);
  11578. }
  11579. }
  11580. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11581. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11582. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11583. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11584. // validate packet and retrieve name and message
  11585. if( !clif_process_message( sd, false, name, message, output ) )
  11586. return;
  11587. party_send_message(sd, output, strlen(output) + 1 );
  11588. }
  11589. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11590. /// 07da <account id>.L
  11591. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11592. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11593. }
  11594. /// Party Booking in KRO [Spiria]
  11595. ///
  11596. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11597. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11598. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11599. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11600. short level = RFIFOW(fd,info->pos[0]);
  11601. short mapid = RFIFOW(fd,info->pos[1]);
  11602. int idxpbj = info->pos[2];
  11603. short job[MAX_PARTY_BOOKING_JOBS];
  11604. int i;
  11605. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11606. job[i] = RFIFOB(fd,idxpbj+i*2);
  11607. party_booking_register(sd, level, mapid, job);
  11608. }
  11609. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11610. /// 0803 <result>.W
  11611. /// result:
  11612. /// 0 = success
  11613. /// 1 = failure
  11614. /// 2 = already registered
  11615. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11616. {
  11617. int fd = sd->fd;
  11618. WFIFOHEAD(fd,packet_len(0x803));
  11619. WFIFOW(fd,0) = 0x803;
  11620. WFIFOW(fd,2) = flag;
  11621. WFIFOSET(fd,packet_len(0x803));
  11622. }
  11623. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11624. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11625. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11626. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11627. short level = RFIFOW(fd,info->pos[0]);
  11628. short mapid = RFIFOW(fd,info->pos[1]);
  11629. short job = RFIFOW(fd,info->pos[2]);
  11630. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11631. short resultcount = RFIFOW(fd,info->pos[4]);
  11632. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11633. }
  11634. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11635. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11636. /// more results:
  11637. /// 0 = no
  11638. /// 1 = yes
  11639. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11640. {
  11641. int i, j;
  11642. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11643. struct party_booking_ad_info *pb_ad;
  11644. WFIFOHEAD(fd,size*count + 5);
  11645. WFIFOW(fd,0) = 0x805;
  11646. WFIFOW(fd,2) = size*count + 5;
  11647. WFIFOB(fd,4) = more_result;
  11648. for(i=0; i<count; i++)
  11649. {
  11650. pb_ad = results[i];
  11651. WFIFOL(fd,i*size+5) = pb_ad->index;
  11652. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11653. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11654. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11655. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11656. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11657. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11658. }
  11659. WFIFOSET(fd,WFIFOW(fd,2));
  11660. }
  11661. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11662. /// 0806
  11663. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11664. {
  11665. if(party_booking_delete(sd))
  11666. clif_PartyBookingDeleteAck(sd, 0);
  11667. }
  11668. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11669. /// 0807 <result>.W
  11670. /// result:
  11671. /// 0 = success
  11672. /// 1 = success (auto-removed expired ad)
  11673. /// 2 = failure
  11674. /// 3 = nothing registered
  11675. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11676. {
  11677. int fd = sd->fd;
  11678. WFIFOHEAD(fd,packet_len(0x807));
  11679. WFIFOW(fd,0) = 0x807;
  11680. WFIFOW(fd,2) = flag;
  11681. WFIFOSET(fd,packet_len(0x807));
  11682. }
  11683. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11684. /// 0808 { <job>.W }*6
  11685. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11686. {
  11687. short job[MAX_PARTY_BOOKING_JOBS];
  11688. int i;
  11689. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11690. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11691. job[i] = RFIFOW(fd,idxpbu+i*2);
  11692. party_booking_update(sd, job);
  11693. }
  11694. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11695. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11696. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11697. {
  11698. int i;
  11699. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11700. if(pb_ad == NULL) return;
  11701. WBUFW(buf,0) = 0x809;
  11702. WBUFL(buf,2) = pb_ad->index;
  11703. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11704. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11705. WBUFW(buf,34) = pb_ad->p_detail.level;
  11706. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11707. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11708. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11709. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11710. }
  11711. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11712. /// 080a <index>.L { <job>.W }*6
  11713. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11714. {
  11715. int i;
  11716. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11717. if(pb_ad == NULL) return;
  11718. WBUFW(buf,0) = 0x80a;
  11719. WBUFL(buf,2) = pb_ad->index;
  11720. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11721. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11722. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11723. }
  11724. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11725. /// 080b <index>.L
  11726. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11727. {
  11728. uint8 buf[6];
  11729. WBUFW(buf,0) = 0x80b;
  11730. WBUFL(buf,2) = index;
  11731. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11732. }
  11733. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11734. /// 012e
  11735. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11736. {
  11737. vending_closevending(sd);
  11738. }
  11739. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11740. /// 0130 <account id>.L
  11741. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11742. {
  11743. if( sd->npc_id ) {// using an NPC
  11744. return;
  11745. }
  11746. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11747. }
  11748. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11749. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11750. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11751. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11752. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11753. // whether it fails or not, the buy window is closed
  11754. sd->vended_id = 0;
  11755. }
  11756. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11757. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11758. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11759. #if PACKETVER >= 20100105
  11760. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11761. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11762. // whether it fails or not, the buy window is closed
  11763. sd->vended_id = 0;
  11764. #endif
  11765. }
  11766. /// Confirm or cancel the shop preparation window.
  11767. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11768. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11769. /// result:
  11770. /// 0 = canceled
  11771. /// 1 = open
  11772. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11773. int cmd = RFIFOW(fd,0);
  11774. struct s_packet_db* info = &packet_db[cmd];
  11775. short len = (short)RFIFOW(fd,info->pos[0]);
  11776. const char* message = RFIFOCP(fd,info->pos[1]);
  11777. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11778. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11779. len -= 84;
  11780. }
  11781. else { //(CZ_REQ_OPENSTORE2)
  11782. bool flag;
  11783. len -= 85;
  11784. flag = RFIFOB(fd,info->pos[2]) != 0;
  11785. if (!flag) {
  11786. sd->state.prevend = 0;
  11787. sd->state.workinprogress = WIP_DISABLE_NONE;
  11788. }
  11789. }
  11790. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11791. return;
  11792. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11793. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11794. return;
  11795. }
  11796. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11797. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11798. return;
  11799. }
  11800. if( message[0] == '\0' ) // invalid input
  11801. return;
  11802. vending_openvending(sd, message, data, len/8, NULL);
  11803. }
  11804. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11805. /// 0165 <char id>.L <guild name>.24B
  11806. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11807. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11808. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11809. name[NAME_LENGTH-1] = '\0';
  11810. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11811. clif_displaymessage(fd, msg_txt(sd,228));
  11812. return;
  11813. }
  11814. if(sd->clan){
  11815. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11816. return;
  11817. }
  11818. guild_create(sd, name);
  11819. }
  11820. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11821. /// 014d
  11822. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11823. {
  11824. clif_guild_masterormember(sd);
  11825. }
  11826. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11827. /// 014f <type>.L
  11828. /// type:
  11829. /// 0 = basic info
  11830. /// 1 = member manager
  11831. /// 2 = positions
  11832. /// 3 = skills
  11833. /// 4 = expulsion list
  11834. /// 5 = unknown (GM_ALLGUILDLIST)
  11835. /// 6 = notice
  11836. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11837. {
  11838. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11839. if( !sd->status.guild_id && !sd->bg_id )
  11840. return;
  11841. switch( type )
  11842. {
  11843. case 0: // Basic Information Guild, hostile alliance information
  11844. clif_guild_basicinfo( *sd );
  11845. clif_guild_allianceinfo(sd);
  11846. break;
  11847. case 1: // Members list, list job title
  11848. clif_guild_positionnamelist(sd);
  11849. clif_guild_memberlist( *sd );
  11850. break;
  11851. case 2: // List job title, title information list
  11852. clif_guild_positionnamelist(sd);
  11853. clif_guild_positioninfolist(sd);
  11854. break;
  11855. case 3: // Skill list
  11856. clif_guild_skillinfo(sd);
  11857. break;
  11858. case 4: // Expulsion list
  11859. clif_guild_expulsionlist(sd);
  11860. break;
  11861. default:
  11862. ShowError("clif: guild request info: unknown type %d\n", type);
  11863. break;
  11864. }
  11865. }
  11866. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11867. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11868. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11869. {
  11870. int i;
  11871. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11872. int len = RFIFOW(fd,info->pos[0]);
  11873. int idxgpos = info->pos[1];
  11874. if(!sd->state.gmaster_flag)
  11875. return;
  11876. for(i = idxgpos; i < len; i += 40 ){
  11877. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11878. }
  11879. }
  11880. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11881. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11882. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11883. {
  11884. int i;
  11885. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11886. int len = RFIFOW(fd,info->pos[0]);
  11887. int idxgpos = info->pos[1];
  11888. if(!sd->state.gmaster_flag)
  11889. return;
  11890. // Guild leadership change
  11891. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11892. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11893. clif_msg(sd, GUILD_MASTER_WOE);
  11894. return;
  11895. }
  11896. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11897. clif_msg(sd, GUILD_MASTER_DELAY);
  11898. return;
  11899. }
  11900. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11901. return;
  11902. }
  11903. for(i=idxgpos;i<len;i+=12){
  11904. int position = RFIFOL(fd,i+8);
  11905. if( position > 0 ){
  11906. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11907. }
  11908. }
  11909. }
  11910. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11911. /// 0151 <guild id>.L
  11912. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11913. {
  11914. struct guild* g;
  11915. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11916. if( (g = guild_search(guild_id)) != NULL )
  11917. clif_guild_emblem(sd,g);
  11918. }
  11919. /// Validates data of a guild emblem (compressed bitmap)
  11920. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11921. EMBVALIDATE_SUCCESS = 0,
  11922. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11923. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  11924. };
  11925. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11926. {
  11927. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11928. unsigned long buf_len = sizeof(buf);
  11929. int offset = 0;
  11930. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11931. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11932. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11933. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11934. ))
  11935. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11936. if(inter_config.emblem_transparency_limit != 100) {
  11937. int i, transcount = 1, tmp[3];
  11938. for(i = offset; i < buf_len-1; i++) {
  11939. int j = i%3;
  11940. tmp[j] = RBUFL(buf,i);
  11941. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11942. transcount++;
  11943. }
  11944. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  11945. return EMBVALIDATE_ERR_TRANSPARENCY;
  11946. }
  11947. return EMBVALIDATE_SUCCESS;
  11948. }
  11949. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11950. /// 0153 <packet len>.W <emblem data>.?B
  11951. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11952. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11953. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11954. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11955. int emb_val=0;
  11956. if( !emblem_len || !sd->state.gmaster_flag )
  11957. return;
  11958. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  11959. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11960. return;
  11961. }
  11962. emb_val = clif_validate_emblem(emblem, emblem_len);
  11963. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11964. 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);
  11965. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11966. return;
  11967. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11968. char output[128];
  11969. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  11970. 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"
  11971. return;
  11972. }
  11973. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11974. }
  11975. /// Request to update the guild emblem id (version, according to Gravity)
  11976. /// 0b46 <guild id>.L <version>.L
  11977. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  11978. nullpo_retv(sd);
  11979. #if PACKETVER >= 20190724
  11980. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11981. guild* g = sd->guild;
  11982. if (g == nullptr || g->guild_id != p->guild_id)
  11983. return;
  11984. if (!sd->state.gmaster_flag)
  11985. return;
  11986. if (!inter_config.emblem_woe_change && is_agit_start()) {
  11987. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11988. return;
  11989. }
  11990. guild_change_emblem_version(sd, p->version);
  11991. #endif
  11992. }
  11993. /// Guild notice update request (CZ_GUILD_NOTICE).
  11994. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11995. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11996. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11997. int guild_id = RFIFOL(fd,info->pos[0]);
  11998. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11999. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12000. if(!sd->state.gmaster_flag)
  12001. return;
  12002. // compensate for some client defects when using multilanguage mode
  12003. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12004. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12005. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12006. guild_change_notice(sd, guild_id, msg1, msg2);
  12007. }
  12008. // Helper function for guild invite functions
  12009. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  12010. {
  12011. if (t_sd == NULL) // not online or does not exist
  12012. return 1;
  12013. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12014. clif_displaymessage(fd, msg_txt(sd,228));
  12015. return 1;
  12016. }
  12017. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12018. clif_noask_sub(sd, t_sd, 2);
  12019. return 1;
  12020. }
  12021. // Players in a clan can not join a guild
  12022. if(t_sd && t_sd->clan){
  12023. return 1;
  12024. }
  12025. guild_invite(sd, t_sd);
  12026. return 0;
  12027. }
  12028. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12029. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12030. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  12031. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12032. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12033. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12034. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12035. if (clif_sub_guild_invite(fd, sd, t_sd))
  12036. return;
  12037. }
  12038. /// Guild invite request (/guildinvite)
  12039. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12040. void
  12041. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  12042. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12043. if (clif_sub_guild_invite(fd, sd, t_sd))
  12044. return;
  12045. }
  12046. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12047. /// 016b <guild id>.L <answer>.L
  12048. /// answer:
  12049. /// 0 = refuse
  12050. /// 1 = accept
  12051. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  12052. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12053. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12054. RFIFOL(fd,info->pos[1]));
  12055. }
  12056. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12057. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12058. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  12059. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12060. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12061. clif_displaymessage(fd, msg_txt(sd,228));
  12062. return;
  12063. }
  12064. if( sd->bg_id ) {
  12065. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12066. return;
  12067. }
  12068. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12069. RFIFOL(fd,info->pos[1]),
  12070. RFIFOL(fd,info->pos[2]),
  12071. RFIFOCP(fd,info->pos[3]));
  12072. }
  12073. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12074. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12075. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  12076. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12077. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12078. { // Guild locked.
  12079. clif_displaymessage(fd, msg_txt(sd,228));
  12080. return;
  12081. }
  12082. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12083. RFIFOL(fd,info->pos[1]),
  12084. RFIFOL(fd,info->pos[2]),
  12085. RFIFOCP(fd,info->pos[3]));
  12086. }
  12087. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12088. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12089. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  12090. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12091. // validate packet and retrieve name and message
  12092. if( !clif_process_message( sd, false, name, message, output ) )
  12093. return;
  12094. if( sd->bg_id )
  12095. bg_send_message(sd, output, strlen(output) );
  12096. else
  12097. guild_send_message(sd, output, strlen(output) );
  12098. }
  12099. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12100. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12101. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  12102. {
  12103. struct map_session_data *t_sd;
  12104. if(!sd->state.gmaster_flag)
  12105. return;
  12106. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12107. clif_displaymessage(fd, msg_txt(sd,228));
  12108. return;
  12109. }
  12110. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12111. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12112. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12113. // @noask [LuzZza]
  12114. if(t_sd && t_sd->state.noask) {
  12115. clif_noask_sub(sd, t_sd, 3);
  12116. return;
  12117. }
  12118. guild_reqalliance(sd,t_sd);
  12119. }
  12120. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12121. /// 0172 <inviter account id>.L <answer>.L
  12122. /// answer:
  12123. /// 0 = refuse
  12124. /// 1 = accept
  12125. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  12126. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12127. guild_reply_reqalliance(sd,
  12128. RFIFOL(fd,info->pos[0]),
  12129. RFIFOL(fd,info->pos[1]));
  12130. }
  12131. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12132. /// 0183 <opponent guild id>.L <relation>.L
  12133. /// relation:
  12134. /// 0 = Ally
  12135. /// 1 = Enemy
  12136. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  12137. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12138. if(!sd->state.gmaster_flag)
  12139. return;
  12140. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12141. clif_displaymessage(fd, msg_txt(sd,228));
  12142. return;
  12143. }
  12144. guild_delalliance(sd,
  12145. RFIFOL(fd,info->pos[0]),
  12146. RFIFOL(fd,info->pos[1]));
  12147. }
  12148. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12149. /// 0180 <account id>.L
  12150. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  12151. {
  12152. struct map_session_data *t_sd;
  12153. if(!sd->state.gmaster_flag)
  12154. return;
  12155. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12156. clif_displaymessage(fd, msg_txt(sd,228));
  12157. return;
  12158. }
  12159. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12160. // @noask [LuzZza]
  12161. if(t_sd && t_sd->state.noask) {
  12162. clif_noask_sub(sd, t_sd, 4);
  12163. return;
  12164. }
  12165. guild_opposition(sd,t_sd);
  12166. }
  12167. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12168. /// 015d <key>.40B
  12169. /// key:
  12170. /// now guild name; might have been (intended) email, since the
  12171. /// field name and size is same as the one in CH_DELETE_CHAR.
  12172. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  12173. {
  12174. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12175. clif_displaymessage(fd, msg_txt(sd,228));
  12176. return;
  12177. }
  12178. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12179. }
  12180. /// Pet
  12181. ///
  12182. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12183. /// 01a1 <type>.B
  12184. /// type:
  12185. /// 0 = pet information
  12186. /// 1 = feed
  12187. /// 2 = performance
  12188. /// 3 = return to egg
  12189. /// 4 = unequip accessory
  12190. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12191. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12192. }
  12193. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12194. /// 019f <id>.L
  12195. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12196. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12197. }
  12198. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12199. /// 01a7 <index>.W
  12200. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12201. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12202. return;
  12203. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12204. clif_menuskill_clear(sd);
  12205. }
  12206. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12207. /// 01a9 <data>.L
  12208. /// data:
  12209. /// is either emotion (@see enum emotion_type) or a compound value
  12210. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12211. /// entry (given in parentheses) in data\pettalktable.xml
  12212. /// act id:
  12213. /// 0 = feeding
  12214. /// 1 = hunting
  12215. /// 2 = danger
  12216. /// 3 = dead
  12217. /// 4 = normal (stand)
  12218. /// 5 = special performance (perfor_s)
  12219. /// 6 = level up (levelup)
  12220. /// 7 = performance 1 (perfor_1)
  12221. /// 8 = performance 2 (perfor_2)
  12222. /// 9 = performance 3 (perfor_3)
  12223. /// 10 = log-in greeting (connect)
  12224. /// hungry value:
  12225. /// 0 = very hungry (hungry)
  12226. /// 1 = hungry (bit_hungry)
  12227. /// 2 = satisfied (noting)
  12228. /// 3 = stuffed (full)
  12229. /// 4 = full (so_full)
  12230. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12231. {
  12232. if(sd->pd)
  12233. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12234. }
  12235. /// Request to change pet's name (CZ_RENAME_PET).
  12236. /// 01a5 <name>.24B
  12237. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12238. {
  12239. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12240. }
  12241. /// /kill (CZ_DISCONNECT_CHARACTER).
  12242. /// Request to disconnect a character.
  12243. /// 00cc <account id>.L
  12244. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12245. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12246. {
  12247. struct block_list *target;
  12248. int tid;
  12249. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12250. target = map_id2bl(tid);
  12251. if (!target) {
  12252. clif_GM_kickack(sd, 0);
  12253. return;
  12254. }
  12255. switch (target->type) {
  12256. case BL_PC:
  12257. {
  12258. char command[NAME_LENGTH+6];
  12259. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12260. is_atcommand(fd, sd, command, 1);
  12261. }
  12262. break;
  12263. /**
  12264. * This one does not invoke any atcommand, so we need to check for permissions.
  12265. */
  12266. case BL_MOB:
  12267. {
  12268. char command[100];
  12269. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12270. clif_GM_kickack(sd, 0);
  12271. return;
  12272. }
  12273. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12274. log_atcommand(sd, command);
  12275. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12276. }
  12277. break;
  12278. case BL_NPC:
  12279. {
  12280. struct npc_data* nd = (struct npc_data *)target;
  12281. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12282. npc_unload_duplicates(nd);
  12283. npc_unload(nd,true);
  12284. npc_read_event_script();
  12285. }
  12286. }
  12287. break;
  12288. default:
  12289. clif_GM_kickack(sd, 0);
  12290. }
  12291. }
  12292. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12293. /// Request to disconnect all characters.
  12294. /// 00ce
  12295. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12296. char cmd[15];
  12297. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12298. is_atcommand(fd, sd, cmd, 1);
  12299. }
  12300. /// /remove (CZ_REMOVE_AID).
  12301. /// Request to warp to a character with given login ID.
  12302. /// 01ba <account name>.24B
  12303. /// /shift (CZ_SHIFT).
  12304. /// Request to warp to a character with given name.
  12305. /// 01bb <char name>.24B
  12306. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12307. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12308. char *player_name;
  12309. char command[NAME_LENGTH+8];
  12310. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12311. player_name[NAME_LENGTH-1] = '\0';
  12312. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12313. is_atcommand(fd, sd, command, 1);
  12314. }
  12315. /// /remove (CZ_REMOVE_AID_SSO).
  12316. /// Request to warp to a character with given account ID.
  12317. /// 0843 <account id>.L
  12318. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12319. {
  12320. uint32 account_id;
  12321. struct map_session_data* pl_sd;
  12322. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12323. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12324. char command[NAME_LENGTH+8];
  12325. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12326. is_atcommand(fd, sd, command, 1);
  12327. }
  12328. }
  12329. /// /recall (CZ_RECALL).
  12330. /// Request to summon a player with given login ID to own position.
  12331. /// 01bc <account name>.24B
  12332. /// /summon (CZ_RECALL_GID).
  12333. /// Request to summon a player with given name to own position.
  12334. /// 01bd <char name>.24B
  12335. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12336. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12337. char *player_name;
  12338. char command [NAME_LENGTH+8];
  12339. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12340. player_name[NAME_LENGTH-1] = '\0';
  12341. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12342. is_atcommand(fd, sd, command, 1);
  12343. }
  12344. /// /recall (CZ_RECALL_SSO).
  12345. /// Request to summon a player with given account ID to own position.
  12346. /// 0842 <account id>.L
  12347. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12348. {
  12349. uint32 account_id;
  12350. struct map_session_data* pl_sd;
  12351. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12352. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12353. char command[NAME_LENGTH+8];
  12354. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12355. is_atcommand(fd, sd, command, 1);
  12356. }
  12357. }
  12358. /// /item /monster (CZ_ITEM_CREATE).
  12359. /// Request to execute GM commands.
  12360. /// Usage:
  12361. /// /item n - summon n monster or acquire n item/s
  12362. /// /item money - grants 2147483647 zenies
  12363. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12364. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12365. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12366. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12367. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12368. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12369. /// 013f <item/mob name>.24B
  12370. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12371. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12372. {
  12373. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12374. int mob_id = 0;
  12375. StringBuf command;
  12376. char *str;
  12377. //#if PACKETVER >= 20131218
  12378. // char str[100];
  12379. //#else
  12380. // char str[24];
  12381. //#endif
  12382. str = RFIFOCP(fd,info->pos[0]);
  12383. if (!str || str[0] == '\0')
  12384. return;
  12385. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12386. return;
  12387. trim(str);
  12388. // Zeny
  12389. if( strcmpi(str, "money") == 0 ) {
  12390. StringBuf_Init(&command);
  12391. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12392. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12393. StringBuf_Destroy(&command);
  12394. return;
  12395. }
  12396. std::shared_ptr<item_data> id = item_db.searchname( str );
  12397. // Item
  12398. if( id ){
  12399. StringBuf_Init(&command);
  12400. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12401. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12402. }else{
  12403. if (id->flag.guid)
  12404. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12405. else
  12406. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12407. }
  12408. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12409. StringBuf_Destroy(&command);
  12410. return;
  12411. }
  12412. // Monster
  12413. if ((mob_id = mobdb_searchname(str)) == 0)
  12414. mob_id = mobdb_checkid(atoi(str));
  12415. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12416. if( mob != nullptr ) {
  12417. StringBuf_Init(&command);
  12418. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12419. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12420. StringBuf_Destroy(&command);
  12421. return;
  12422. }
  12423. }
  12424. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12425. /// 019d <effect state>.L
  12426. /// effect state:
  12427. /// TODO: Any OPTION_* ?
  12428. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12429. char cmd[6];
  12430. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12431. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12432. is_atcommand(fd, sd, cmd, 1);
  12433. }
  12434. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12435. /// 0149 <account id>.L <type>.B <value>.W
  12436. /// type:
  12437. /// 0 = positive points
  12438. /// 1 = negative points
  12439. /// 2 = self mute (+10 minutes)
  12440. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12441. {
  12442. int id, type, value;
  12443. struct map_session_data *dstsd;
  12444. char command[NAME_LENGTH+15];
  12445. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12446. id = RFIFOL(fd,info->pos[0]);
  12447. type = RFIFOB(fd,info->pos[1]);
  12448. value = RFIFOW(fd,info->pos[2]);
  12449. if( type == 0 )
  12450. value = -value;
  12451. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12452. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12453. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12454. return;
  12455. dstsd = map_id2sd(id);
  12456. if( dstsd == NULL )
  12457. return;
  12458. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12459. is_atcommand(fd, sd, command, 1);
  12460. }
  12461. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12462. /// GM adjustment of a player's manner value by -60.
  12463. /// 0212 <char name>.24B
  12464. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12465. {
  12466. char command[NAME_LENGTH+15];
  12467. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12468. name[NAME_LENGTH-1] = '\0';
  12469. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12470. is_atcommand(fd, sd, command, 1);
  12471. }
  12472. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12473. /// 01e0 <account id>.L <account name>.24B
  12474. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12475. {
  12476. WFIFOHEAD(fd,packet_len(0x1e0));
  12477. WFIFOW(fd,0) = 0x1e0;
  12478. WFIFOL(fd,2) = account_id;
  12479. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12480. WFIFOSET(fd,packet_len(0x1e0));
  12481. }
  12482. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12483. /// 01df <account id>.L
  12484. //! TODO: Figure out how does this actually work
  12485. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12486. {
  12487. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12488. /*
  12489. char query[30];
  12490. safesnprintf(query,sizeof(query),"%d", account_id);
  12491. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12492. */
  12493. clif_account_name(fd, account_id, "");
  12494. }
  12495. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12496. /// GM single cell type change request.
  12497. /// 0198 <x>.W <y>.W <type>.W
  12498. /// type:
  12499. /// 0 = not walkable
  12500. /// 1 = walkable
  12501. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12502. {
  12503. int x,y,type;
  12504. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12505. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12506. return;
  12507. x = RFIFOW(fd,info->pos[0]);
  12508. y = RFIFOW(fd,info->pos[1]);
  12509. type = RFIFOW(fd,info->pos[2]);
  12510. map_setgatcell(sd->bl.m,x,y,type);
  12511. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12512. //FIXME: once players leave the map, the client 'forgets' this information.
  12513. }
  12514. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12515. /// Request to allow/deny whispers from a nick.
  12516. /// 00cf <nick>.24B <type>.B
  12517. /// type:
  12518. /// 0 = (/ex nick) deny speech from nick
  12519. /// 1 = (/in nick) allow speech from nick
  12520. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12521. {
  12522. char* nick;
  12523. uint8 type;
  12524. int i;
  12525. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12526. nick = RFIFOCP(fd,info->pos[0]);
  12527. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12528. type = RFIFOB(fd,info->pos[1]);
  12529. if( type == 0 ) { // Add name to ignore list (block)
  12530. if (strcmp(wisp_server_name, nick) == 0) {
  12531. clif_wisexin(sd, type, 1); // fail
  12532. return;
  12533. }
  12534. // try to find a free spot, while checking for duplicates at the same time
  12535. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12536. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12537. clif_wisexin(sd, type, 2); // too many blocks
  12538. return;
  12539. }
  12540. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12541. clif_wisexin(sd, type, 0); // Aegis reports success.
  12542. return;
  12543. }
  12544. //Insert in position i
  12545. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12546. } else { // Remove name from ignore list (unblock)
  12547. // find entry
  12548. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12549. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12550. clif_wisexin(sd, type, 1); // fail
  12551. return;
  12552. }
  12553. // move everything one place down to overwrite removed entry
  12554. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12555. // wipe last entry
  12556. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12557. }
  12558. clif_wisexin(sd, type, 0); // success
  12559. }
  12560. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12561. /// Request to allow/deny all whispers.
  12562. /// 00d0 <type>.B
  12563. /// type:
  12564. /// 0 = (/exall) deny all speech
  12565. /// 1 = (/inall) allow all speech
  12566. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12567. {
  12568. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12569. if( type == 0 ) {// Deny all
  12570. if( sd->state.ignoreAll ) {
  12571. flag = 1; // fail
  12572. } else {
  12573. sd->state.ignoreAll = 1;
  12574. flag = 0; // success
  12575. }
  12576. } else {//Unblock everyone
  12577. if( sd->state.ignoreAll ) {
  12578. sd->state.ignoreAll = 0;
  12579. flag = 0; // success
  12580. } else {
  12581. if (sd->ignore[0].name[0] != '\0')
  12582. { //Wipe the ignore list.
  12583. memset(sd->ignore, 0, sizeof(sd->ignore));
  12584. flag = 0; // success
  12585. } else {
  12586. flag = 1; // fail
  12587. }
  12588. }
  12589. }
  12590. clif_wisall(sd, type, flag);
  12591. }
  12592. /// Whisper ignore list (ZC_WHISPER_LIST).
  12593. /// 00d4 <packet len>.W { <char name>.24B }*
  12594. void clif_PMIgnoreList(struct map_session_data* sd)
  12595. {
  12596. int i, fd = sd->fd;
  12597. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12598. WFIFOW(fd,0) = 0xd4;
  12599. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12600. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12601. }
  12602. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12603. WFIFOSET(fd,WFIFOW(fd,2));
  12604. }
  12605. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12606. /// 00d3
  12607. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12608. {
  12609. clif_PMIgnoreList(sd);
  12610. }
  12611. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12612. /// 01e7
  12613. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12614. {
  12615. if (sd->state.doridori) return;
  12616. switch (sd->class_&MAPID_UPPERMASK) {
  12617. case MAPID_SOUL_LINKER:
  12618. case MAPID_STAR_GLADIATOR:
  12619. case MAPID_TAEKWON:
  12620. if (!sd->state.rest)
  12621. break;
  12622. case MAPID_SUPER_NOVICE:
  12623. case MAPID_SUPER_BABY:
  12624. case MAPID_SUPER_NOVICE_E:
  12625. case MAPID_SUPER_BABY_E:
  12626. sd->state.doridori=1;
  12627. break;
  12628. }
  12629. }
  12630. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12631. /// 01ed
  12632. /// Note: This packet is caused by 7 lines of any text, followed by
  12633. /// the prayer and an another line of any text. The prayer is
  12634. /// defined by lines 790~793 in data\msgstringtable.txt
  12635. /// "Dear angel, can you hear my voice?"
  12636. /// "I am" (space separated player name) "Super Novice~"
  12637. /// "Help me out~ Please~ T_T"
  12638. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12639. {
  12640. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12641. t_exp next = pc_nextbaseexp(sd);
  12642. if( next ) {
  12643. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12644. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12645. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12646. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12647. }
  12648. }
  12649. }
  12650. }
  12651. /// Friends List
  12652. ///
  12653. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12654. /// 0206 <account id>.L <char id>.L <state>.B
  12655. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12656. /// state:
  12657. /// 0 = online
  12658. /// 1 = offline
  12659. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12660. {
  12661. int i, fd = sd->fd;
  12662. //Seek friend.
  12663. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12664. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12665. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12666. return; //Not found
  12667. WFIFOHEAD(fd,packet_len(0x206));
  12668. WFIFOW(fd, 0) = 0x206;
  12669. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12670. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12671. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12672. #if PACKETVER >= 20180221
  12673. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12674. #endif
  12675. WFIFOSET(fd, packet_len(0x206));
  12676. }
  12677. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12678. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12679. {
  12680. uint32 account_id, char_id, online;
  12681. account_id = va_arg(ap, int);
  12682. char_id = va_arg(ap, int);
  12683. online = va_arg(ap, int);
  12684. clif_friendslist_toggle(sd, account_id, char_id, online);
  12685. return 0;
  12686. }
  12687. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12688. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12689. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12690. void clif_friendslist_send( struct map_session_data& sd ){
  12691. struct PACKET_ZC_FRIENDS_LIST* p = (struct PACKET_ZC_FRIENDS_LIST*)packet_buffer;
  12692. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12693. p->PacketLength = sizeof( *p );
  12694. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12695. struct PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12696. f.AID = sd.status.friends[i].account_id;
  12697. f.CID = sd.status.friends[i].char_id;
  12698. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12699. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12700. #endif
  12701. c++;
  12702. p->PacketLength += sizeof( f );
  12703. }
  12704. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12705. // Sending the online players
  12706. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12707. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12708. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12709. }
  12710. }
  12711. }
  12712. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12713. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12714. /// result:
  12715. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12716. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12717. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12718. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12719. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12720. {
  12721. int fd;
  12722. nullpo_retv(sd);
  12723. fd = sd->fd;
  12724. WFIFOHEAD(fd,packet_len(0x209));
  12725. WFIFOW(fd,0) = 0x209;
  12726. WFIFOW(fd,2) = type;
  12727. if (f_sd) {
  12728. WFIFOL(fd,4) = f_sd->status.account_id;
  12729. WFIFOL(fd,8) = f_sd->status.char_id;
  12730. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12731. }
  12732. WFIFOSET(fd, packet_len(0x209));
  12733. }
  12734. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12735. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12736. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12737. {
  12738. int fd = sd->fd;
  12739. WFIFOHEAD(fd,packet_len(0x207));
  12740. WFIFOW(fd,0) = 0x207;
  12741. WFIFOL(fd,2) = account_id;
  12742. WFIFOL(fd,6) = char_id;
  12743. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12744. WFIFOSET(fd,packet_len(0x207));
  12745. }
  12746. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12747. /// 0202 <name>.24B
  12748. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12749. {
  12750. struct map_session_data *f_sd;
  12751. int i;
  12752. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12753. // Friend doesn't exist (no player with this name)
  12754. if (f_sd == NULL) {
  12755. clif_displaymessage(fd, msg_txt(sd,3));
  12756. return;
  12757. }
  12758. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12759. return;
  12760. }
  12761. // ensure that the request player's friend list is not full
  12762. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12763. if( i == MAX_FRIENDS ){
  12764. clif_friendslist_reqack(sd, f_sd, 2);
  12765. return;
  12766. }
  12767. // @noask [LuzZza]
  12768. if(f_sd->state.noask) {
  12769. clif_noask_sub(sd, f_sd, 5);
  12770. return;
  12771. }
  12772. // Friend already exists
  12773. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12774. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12775. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12776. return;
  12777. }
  12778. }
  12779. f_sd->friend_req = sd->status.char_id;
  12780. sd->friend_req = f_sd->status.char_id;
  12781. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12782. }
  12783. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12784. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12785. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12786. /// reply:
  12787. /// 0 = rejected
  12788. /// 1 = accepted
  12789. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12790. {
  12791. struct map_session_data *f_sd;
  12792. uint32 account_id;
  12793. char reply;
  12794. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12795. account_id = RFIFOL(fd,info->pos[0]);
  12796. //char_id = RFIFOL(fd,info->pos[1]);
  12797. #if PACKETVER < 6
  12798. reply = RFIFOB(fd,info->pos[2]);
  12799. #else
  12800. reply = RFIFOL(fd,info->pos[2]);
  12801. #endif
  12802. if( sd->bl.id == account_id ) {// adding oneself as friend
  12803. return;
  12804. }
  12805. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12806. if (f_sd == NULL)
  12807. return;
  12808. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12809. clif_friendslist_reqack(f_sd, sd, 1);
  12810. else {
  12811. int i;
  12812. // Find an empty slot
  12813. for (i = 0; i < MAX_FRIENDS; i++)
  12814. if (f_sd->status.friends[i].char_id == 0)
  12815. break;
  12816. if (i == MAX_FRIENDS) {
  12817. clif_friendslist_reqack(f_sd, sd, 2);
  12818. return;
  12819. }
  12820. f_sd->status.friends[i].account_id = sd->status.account_id;
  12821. f_sd->status.friends[i].char_id = sd->status.char_id;
  12822. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12823. clif_friendslist_reqack(f_sd, sd, 0);
  12824. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12825. if (battle_config.friend_auto_add) {
  12826. // Also add f_sd to sd's friendlist.
  12827. for (i = 0; i < MAX_FRIENDS; i++) {
  12828. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12829. return; //No need to add anything.
  12830. if (sd->status.friends[i].char_id == 0)
  12831. break;
  12832. }
  12833. if (i == MAX_FRIENDS) {
  12834. clif_friendslist_reqack(sd, f_sd, 2);
  12835. return;
  12836. }
  12837. sd->status.friends[i].account_id = f_sd->status.account_id;
  12838. sd->status.friends[i].char_id = f_sd->status.char_id;
  12839. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12840. clif_friendslist_reqack(sd, f_sd, 0);
  12841. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12842. }
  12843. }
  12844. }
  12845. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12846. /// 0203 <account id>.L <char id>.L
  12847. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12848. {
  12849. struct map_session_data *f_sd = NULL;
  12850. uint32 account_id, char_id;
  12851. int i, j;
  12852. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12853. account_id = RFIFOL(fd,info->pos[0]);
  12854. char_id = RFIFOL(fd,info->pos[1]);
  12855. // Search friend
  12856. for (i = 0; i < MAX_FRIENDS &&
  12857. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12858. if (i == MAX_FRIENDS) {
  12859. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12860. return;
  12861. }
  12862. //remove from friend's list first
  12863. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12864. for (i = 0; i < MAX_FRIENDS &&
  12865. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12866. if (i != MAX_FRIENDS) {
  12867. // move all chars up
  12868. for(j = i + 1; j < MAX_FRIENDS; j++)
  12869. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12870. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12871. //should the guy be notified of some message? we should add it here if so
  12872. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12873. WFIFOW(f_sd->fd,0) = 0x20a;
  12874. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12875. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12876. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12877. }
  12878. } else { //friend not online -- ask char server to delete from his friendlist
  12879. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12880. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12881. return;
  12882. }
  12883. }
  12884. // We can now delete from original requester
  12885. for (i = 0; i < MAX_FRIENDS &&
  12886. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12887. // move all chars up
  12888. for(j = i + 1; j < MAX_FRIENDS; j++)
  12889. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12890. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12891. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12892. WFIFOHEAD(fd,packet_len(0x20a));
  12893. WFIFOW(fd,0) = 0x20a;
  12894. WFIFOL(fd,2) = account_id;
  12895. WFIFOL(fd,6) = char_id;
  12896. WFIFOSET(fd, packet_len(0x20a));
  12897. }
  12898. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12899. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12900. void clif_PVPInfo(struct map_session_data* sd)
  12901. {
  12902. int fd = sd->fd;
  12903. WFIFOHEAD(fd,packet_len(0x210));
  12904. WFIFOW(fd,0) = 0x210;
  12905. WFIFOL(fd,2) = sd->status.char_id;
  12906. WFIFOL(fd,6) = sd->status.account_id;
  12907. WFIFOL(fd,10) = sd->pvp_won; // times won
  12908. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12909. WFIFOL(fd,18) = sd->pvp_point;
  12910. WFIFOSET(fd, packet_len(0x210));
  12911. }
  12912. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12913. /// 020f <char id>.L <account id>.L
  12914. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12915. {
  12916. // TODO: Is there a way to use this on an another player (char/acc id)?
  12917. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12918. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12919. clif_PVPInfo(sd);
  12920. }
  12921. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12922. /// 0254 <which>.B
  12923. /// which: (unused atm for security purpose)
  12924. /// 0 = sun
  12925. /// 1 = moon
  12926. /// 2 = star
  12927. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12928. {
  12929. int i;
  12930. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12931. if (sd->menuskill_id != SG_FEEL)
  12932. return;
  12933. i = sd->menuskill_val-1;
  12934. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12935. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12936. sd->feel_map[i].m = sd->bl.m;
  12937. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12938. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12939. // clif_misceffect2(&sd->bl, 0x1b0);
  12940. // clif_misceffect2(&sd->bl, 0x21f);
  12941. clif_feel_info(sd, i, 0);
  12942. clif_menuskill_clear(sd);
  12943. }
  12944. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12945. /// 0253 <which>.B
  12946. /// which:
  12947. /// 0 = sun
  12948. /// 1 = moon
  12949. /// 2 = star
  12950. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12951. {
  12952. WFIFOHEAD(fd,packet_len(0x253));
  12953. WFIFOW(fd,0)=0x253;
  12954. WFIFOB(fd,2)=TOB(skill_lv-1);
  12955. WFIFOSET(fd, packet_len(0x253));
  12956. sd->menuskill_id = SG_FEEL;
  12957. sd->menuskill_val = skill_lv;
  12958. }
  12959. /// Request to change homunculus' name (CZ_RENAME_MER).
  12960. /// 0231 <name>.24B
  12961. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12962. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12963. }
  12964. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12965. /// 0234 <id>.L
  12966. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12967. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12968. struct block_list *bl = NULL;
  12969. struct unit_data *ud = NULL;
  12970. if( sd->md && sd->md->bl.id == id )
  12971. bl = &sd->md->bl;
  12972. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12973. bl = &sd->hd->bl; // Moving Homunculus
  12974. else
  12975. return;
  12976. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12977. ud = unit_bl2ud(bl);
  12978. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12979. }
  12980. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12981. /// 0232 <id>.L <position data>.3B
  12982. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12983. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12984. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12985. struct block_list *bl = NULL;
  12986. short x, y;
  12987. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12988. if( sd->md && sd->md->bl.id == id )
  12989. bl = &sd->md->bl; // Moving Mercenary
  12990. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12991. bl = &sd->hd->bl; // Moving Homunculus
  12992. else
  12993. return;
  12994. unit_walktoxy(bl, x, y, 4);
  12995. }
  12996. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12997. /// 0233 <id>.L <target id>.L <action>.B
  12998. /// action:
  12999. /// always 0
  13000. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  13001. {
  13002. struct block_list *bl = NULL;
  13003. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13004. int id = RFIFOL(fd,info->pos[0]);
  13005. int target_id = RFIFOL(fd,info->pos[1]);
  13006. int action_type = RFIFOB(fd,info->pos[2]);
  13007. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13008. bl = &sd->hd->bl;
  13009. else if( sd->md && sd->md->bl.id == id )
  13010. bl = &sd->md->bl;
  13011. else return;
  13012. unit_stop_attack(bl);
  13013. unit_attack(bl, target_id, action_type != 0);
  13014. }
  13015. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13016. /// 022d <type>.W <command>.B
  13017. /// type:
  13018. /// always 0
  13019. /// command:
  13020. /// 0 = homunculus information
  13021. /// 1 = feed
  13022. /// 2 = delete
  13023. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  13024. { //[orn]
  13025. int cmd = RFIFOW(fd,0);
  13026. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13027. if(!hom_is_active(sd->hd))
  13028. return;
  13029. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13030. }
  13031. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13032. /// 0292
  13033. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  13034. {
  13035. pc_revive_item(sd);
  13036. }
  13037. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13038. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13039. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13040. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13041. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13042. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13043. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13044. void clif_check(int fd, struct map_session_data* pl_sd)
  13045. {
  13046. WFIFOHEAD(fd,packet_len(0x214));
  13047. WFIFOW(fd, 0) = 0x214;
  13048. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13049. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13050. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13051. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13052. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13053. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13054. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13055. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13056. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13057. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13058. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13059. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13060. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13061. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13062. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13063. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13064. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13065. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13066. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13067. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13068. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13069. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13070. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13071. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13072. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13073. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13074. WFIFOSET(fd,packet_len(0x214));
  13075. }
  13076. /// /check (CZ_REQ_STATUS_GM).
  13077. /// Request character's status values.
  13078. /// 0213 <char name>.24B
  13079. void clif_parse_Check(int fd, struct map_session_data *sd)
  13080. {
  13081. char charname[NAME_LENGTH];
  13082. struct map_session_data* pl_sd;
  13083. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13084. return;
  13085. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13086. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13087. {
  13088. return;
  13089. }
  13090. clif_check(fd, pl_sd);
  13091. }
  13092. /// MAIL SYSTEM
  13093. /// By Zephyrus
  13094. ///
  13095. /// Notification about the result of adding an item to mail
  13096. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13097. /// result:
  13098. /// 0 = success
  13099. /// 1 = failure
  13100. /// 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)
  13101. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13102. /// result:
  13103. /// 0 = success
  13104. /// 1 = over weight
  13105. /// 2 = fatal error
  13106. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  13107. int fd = sd->fd;
  13108. #if PACKETVER < 20150513
  13109. WFIFOHEAD(fd,packet_len(0x255));
  13110. WFIFOW(fd,0) = 0x255;
  13111. WFIFOW(fd,2) = index;
  13112. WFIFOB(fd,4) = flag;
  13113. WFIFOSET(fd,packet_len(0x255));
  13114. #else
  13115. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13116. if( flag ){
  13117. memset( &p, 0, sizeof( p ) );
  13118. }else{
  13119. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13120. p.index = index;
  13121. p.count = amount;
  13122. p.itemId = client_nameid( item->nameid );
  13123. p.type = itemtype( item->nameid );
  13124. p.IsIdentified = item->identify ? 1 : 0;
  13125. p.IsDamaged = item->attribute ? 1 : 0;
  13126. p.refiningLevel = item->refine;
  13127. clif_addcards( &p.slot, item );
  13128. clif_add_random_options( p.optionData, item );
  13129. p.weight = 0;
  13130. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13131. if( sd->mail.item[i].nameid == 0 ){
  13132. continue;
  13133. }
  13134. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13135. }
  13136. p.favorite = item->favorite;
  13137. p.location = pc_equippoint( sd, server_index( index ) );
  13138. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13139. p.grade = item->enchantgrade;
  13140. #endif
  13141. }
  13142. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13143. p.result = flag;
  13144. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13145. #endif
  13146. }
  13147. /// Notification about the result of retrieving a mail attachment
  13148. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13149. /// result:
  13150. /// 0 = success
  13151. /// 1 = failure
  13152. /// 2 = too many items
  13153. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13154. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13155. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13156. #if PACKETVER < 20150513
  13157. int fd = sd->fd;
  13158. WFIFOHEAD(fd,packet_len(0x245));
  13159. WFIFOW(fd,0) = 0x245;
  13160. WFIFOB(fd,2) = result;
  13161. WFIFOSET(fd,packet_len(0x245));
  13162. #else
  13163. switch( type ){
  13164. case MAIL_ATT_ITEM:
  13165. case MAIL_ATT_ZENY:
  13166. break;
  13167. default:
  13168. return;
  13169. }
  13170. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13171. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13172. p.MailID = msg->id;
  13173. p.opentype = msg->type;
  13174. p.result = result;
  13175. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13176. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13177. #endif
  13178. }
  13179. /// Notification about the result of sending a mail
  13180. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13181. /// result:
  13182. /// 0 = success
  13183. /// 1 = recipinent does not exist
  13184. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13185. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13186. #if PACKETVER < 20150513
  13187. int fd = sd->fd;
  13188. WFIFOHEAD(fd,packet_len(0x249));
  13189. WFIFOW(fd,0) = 0x249;
  13190. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13191. WFIFOSET(fd,packet_len(0x249));
  13192. #else
  13193. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13194. p.PacketType = rodexwriteresult;
  13195. p.result = result;
  13196. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13197. #endif
  13198. }
  13199. /// Notification about the result of deleting a mail.
  13200. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13201. /// result:
  13202. /// 0 = success
  13203. /// 1 = failure
  13204. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13205. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13206. #if PACKETVER < 20150513
  13207. int fd = sd->fd;
  13208. WFIFOHEAD(fd, packet_len(0x257));
  13209. WFIFOW(fd,0) = 0x257;
  13210. WFIFOL(fd,2) = msg->id;
  13211. WFIFOW(fd,6) = !success;
  13212. WFIFOSET(fd, packet_len(0x257));
  13213. #else
  13214. // This is only a success notification
  13215. if( success ){
  13216. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13217. p.PacketType = rodexdelete;
  13218. p.opentype = msg->type;
  13219. p.MailID = msg->id;
  13220. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13221. }
  13222. #endif
  13223. }
  13224. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13225. /// 0274 <mail id>.L <result>.W
  13226. /// result:
  13227. /// 0 = success
  13228. /// 1 = failure
  13229. void clif_Mail_return(int fd, int mail_id, short fail)
  13230. {
  13231. WFIFOHEAD(fd,packet_len(0x274));
  13232. WFIFOW(fd,0) = 0x274;
  13233. WFIFOL(fd,2) = mail_id;
  13234. WFIFOW(fd,6) = fail;
  13235. WFIFOSET(fd,packet_len(0x274));
  13236. }
  13237. /// Notification about new mail.
  13238. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13239. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13240. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13241. #if PACKETVER < 20150513
  13242. int fd = sd->fd;
  13243. WFIFOHEAD(fd,packet_len(0x24a));
  13244. WFIFOW(fd,0) = 0x24a;
  13245. WFIFOL(fd,2) = mail_id;
  13246. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13247. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13248. WFIFOSET(fd,packet_len(0x24a));
  13249. #else
  13250. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13251. p.PacketType = rodexicon;
  13252. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13253. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13254. #endif
  13255. }
  13256. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13257. /// 0260 <type>.L
  13258. /// type:
  13259. /// 0 = open
  13260. /// 1 = close
  13261. void clif_Mail_window(int fd, int flag)
  13262. {
  13263. WFIFOHEAD(fd,packet_len(0x260));
  13264. WFIFOW(fd,0) = 0x260;
  13265. WFIFOL(fd,2) = flag;
  13266. WFIFOSET(fd,packet_len(0x260));
  13267. }
  13268. /// Lists mails stored in inbox.
  13269. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13270. /// read:
  13271. /// 0 = unread
  13272. /// 1 = read
  13273. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13274. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13275. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13276. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13277. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13278. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13279. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13280. #if PACKETVER < 20150513
  13281. int fd = sd->fd;
  13282. struct mail_data *md = &sd->mail.inbox;
  13283. struct mail_message *msg;
  13284. int len, i, j;
  13285. len = 8 + (73 * md->amount);
  13286. WFIFOHEAD(fd,len);
  13287. WFIFOW(fd,0) = 0x240;
  13288. WFIFOW(fd,2) = len;
  13289. WFIFOL(fd,4) = md->amount;
  13290. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13291. {
  13292. msg = &md->msg[i];
  13293. if (msg->id < 1)
  13294. continue;
  13295. WFIFOL(fd,8+73*j) = msg->id;
  13296. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13297. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13298. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13299. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13300. j++;
  13301. }
  13302. WFIFOSET(fd,len);
  13303. if( md->full ) {// TODO: is this official?
  13304. char output[100];
  13305. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13306. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13307. }
  13308. #else
  13309. int fd = sd->fd;
  13310. struct mail_data *md = &sd->mail.inbox;
  13311. struct mail_message *msg;
  13312. int i, j, k, offset, titleLength;
  13313. uint8 mailType, amount, remaining;
  13314. uint32 now = (uint32)time(NULL);
  13315. #if PACKETVER >= 20170419
  13316. int cmd = 0xac2;
  13317. #elif PACKETVER >= 20160601
  13318. int cmd = 0xa7d;
  13319. #else
  13320. int cmd = 0x9f0;
  13321. #endif
  13322. if( battle_config.mail_daily_count ){
  13323. mail_refresh_remaining_amount(sd);
  13324. }
  13325. #if PACKETVER >= 20170419
  13326. // Always send all
  13327. i = md->amount;
  13328. #else
  13329. // If a starting mail id was sent
  13330. if( mailID != 0 ){
  13331. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13332. // Unknown mail
  13333. if( i == md->amount ){
  13334. // Ignore the request for now
  13335. return; // TODO: Should we just show the first page instead?
  13336. }
  13337. // It was actually the oldest/first mail, there is no further page
  13338. if( i == 0 ){
  13339. return;
  13340. }
  13341. // We actually want the next/older mail
  13342. i -= 1;
  13343. }else{
  13344. i = md->amount;
  13345. }
  13346. #endif
  13347. // Count the remaining mails from the starting mail or the beginning
  13348. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13349. for( j = i, remaining = 0; j >= 0; j-- ){
  13350. msg = &md->msg[j];
  13351. if (msg->id < 1)
  13352. continue;
  13353. #if PACKETVER < 20170419
  13354. if (msg->type != type)
  13355. continue;
  13356. #endif
  13357. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13358. continue;
  13359. remaining++;
  13360. }
  13361. #if PACKETVER >= 20170419
  13362. // Always send all
  13363. amount = remaining;
  13364. #else
  13365. if( remaining > MAIL_PAGE_SIZE ){
  13366. amount = MAIL_PAGE_SIZE;
  13367. }else{
  13368. amount = remaining;
  13369. }
  13370. #endif
  13371. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13372. WFIFOW(fd, 0) = cmd;
  13373. #if PACKETVER >= 20170419
  13374. WFIFOB(fd, 4) = 1; // Unknown
  13375. offset = 5;
  13376. #else
  13377. WFIFOB(fd, 4) = type;
  13378. WFIFOB(fd, 5) = amount;
  13379. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13380. offset = 7;
  13381. #endif
  13382. for( amount = 0; i >= 0; i-- ){
  13383. msg = &md->msg[i];
  13384. if (msg->id < 1)
  13385. continue;
  13386. #if PACKETVER < 20170419
  13387. if (msg->type != type)
  13388. continue;
  13389. #endif
  13390. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13391. continue;
  13392. #if PACKETVER >= 20170419
  13393. WFIFOB(fd, offset) = msg->type;
  13394. offset += 1;
  13395. #endif
  13396. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13397. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13398. mailType = MAIL_TYPE_TEXT; // Normal letter
  13399. if( msg->zeny > 0 ){
  13400. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13401. }
  13402. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13403. if( msg->item[k].nameid > 0 ){
  13404. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13405. break;
  13406. }
  13407. }
  13408. #if PACKETVER >= 20170419
  13409. // If it came from an npc?
  13410. if( !msg->send_id ){
  13411. mailType |= MAIL_TYPE_NPC;
  13412. }
  13413. #endif
  13414. WFIFOB(fd, offset + 9) = mailType;
  13415. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13416. #if PACKETVER < 20170419
  13417. // How much time has passed since you received the mail
  13418. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13419. offset += 4;
  13420. #endif
  13421. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13422. if( msg->scheduled_deletion > 0 ){
  13423. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13424. }else{
  13425. // Fake the scheduled deletion to one year in the future
  13426. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13427. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13428. }
  13429. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13430. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13431. offset += 40 + titleLength;
  13432. }
  13433. WFIFOW(fd, 2) = (int16)offset;
  13434. WFIFOSET(fd, offset);
  13435. #endif
  13436. }
  13437. /// Mail inbox list request.
  13438. /// 023f (CZ_MAIL_GET_LIST)
  13439. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13440. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13441. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13442. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13443. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13444. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13445. if( mail_invalid_operation( sd ) ){
  13446. return;
  13447. }
  13448. #if PACKETVER < 20150513
  13449. struct mail_data* md = &sd->mail.inbox;
  13450. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13451. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13452. else
  13453. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13454. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13455. mail_removezeny(sd, false);
  13456. #else
  13457. int cmd = RFIFOW(fd, 0);
  13458. #if PACKETVER < 20170419
  13459. uint8 openType = RFIFOB(fd, 2);
  13460. uint64 mailId = RFIFOQ(fd, 3);
  13461. #else
  13462. uint8 openType;
  13463. uint64 mailId = RFIFOQ(fd, 2);
  13464. int i;
  13465. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13466. if( i == MAIL_MAX_INBOX ){
  13467. openType = MAIL_INBOX_NORMAL;
  13468. mailId = 0;
  13469. }else{
  13470. openType = sd->mail.inbox.msg[i].type;
  13471. mailId = 0;
  13472. }
  13473. #endif
  13474. switch( openType ){
  13475. case MAIL_INBOX_NORMAL:
  13476. case MAIL_INBOX_ACCOUNT:
  13477. case MAIL_INBOX_RETURNED:
  13478. break;
  13479. default:
  13480. // Unknown type: ignore request
  13481. return;
  13482. }
  13483. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13484. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13485. return;
  13486. }
  13487. // If it is not a next page request
  13488. if( cmd != 0x9ee ){
  13489. mailId = 0;
  13490. }
  13491. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13492. #endif
  13493. }
  13494. /// Opens a mail
  13495. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13496. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13497. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13498. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13499. /// { }*n
  13500. // TODO: Packet description => for repeated block
  13501. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13502. int i, fd = sd->fd;
  13503. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13504. if( i == MAIL_MAX_INBOX ) {
  13505. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13506. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13507. return;
  13508. } else {
  13509. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13510. struct item *item;
  13511. int msg_len = strlen(msg->body);
  13512. if( msg_len == 0 ) {
  13513. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13514. msg_len = strlen(msg->body);
  13515. }
  13516. #if PACKETVER < 20150513
  13517. item = &msg->item[0];
  13518. int len = 101 + msg_len;
  13519. WFIFOHEAD(fd,len);
  13520. WFIFOW(fd,0) = 0x242;
  13521. WFIFOW(fd,2) = len;
  13522. WFIFOL(fd,4) = msg->id;
  13523. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13524. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13525. WFIFOL(fd,72) = 0;
  13526. WFIFOL(fd,76) = msg->zeny;
  13527. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13528. if( item->nameid && data != nullptr ) {
  13529. WFIFOL(fd,80) = item->amount;
  13530. WFIFOW(fd,84) = client_nameid( item->nameid );
  13531. WFIFOW(fd,86) = itemtype( item->nameid );
  13532. WFIFOB(fd,88) = item->identify;
  13533. WFIFOB(fd,89) = item->attribute;
  13534. WFIFOB(fd,90) = item->refine;
  13535. WFIFOW(fd,91) = item->card[0];
  13536. WFIFOW(fd,93) = item->card[1];
  13537. WFIFOW(fd,95) = item->card[2];
  13538. WFIFOW(fd,97) = item->card[3];
  13539. } else // no item, set all to zero
  13540. memset(WFIFOP(fd,80), 0x00, 19);
  13541. WFIFOB(fd,99) = (unsigned char)msg_len;
  13542. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13543. WFIFOSET(fd,len);
  13544. #else
  13545. msg_len += 1; // Zero Termination
  13546. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13547. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13548. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13549. p->opentype = msg->type;
  13550. p->MailID = msg->id;
  13551. p->TextcontentsLength = msg_len;
  13552. p->zeny = msg->zeny;
  13553. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13554. p->PacketLength += p->TextcontentsLength;
  13555. p->ItemCnt = 0;
  13556. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13557. item = &msg->item[j];
  13558. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13559. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13560. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13561. mailitem->ITID = client_nameid( item->nameid );
  13562. mailitem->count = item->amount;
  13563. mailitem->type = itemtype( item->nameid );
  13564. mailitem->IsIdentified = item->identify ? 1 : 0;
  13565. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13566. mailitem->refiningLevel = item->refine;
  13567. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13568. mailitem->viewSprite = data->look;
  13569. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13570. clif_addcards( &mailitem->slot, item );
  13571. clif_add_random_options( mailitem->option_data, item );
  13572. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13573. mailitem->grade = item->enchantgrade;
  13574. #endif
  13575. p->PacketLength += sizeof( *mailitem );
  13576. p->ItemCnt++;
  13577. }
  13578. }
  13579. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13580. #endif
  13581. if (msg->status == MAIL_UNREAD) {
  13582. msg->status = MAIL_READ;
  13583. intif_Mail_read(mail_id);
  13584. clif_parse_Mail_refreshinbox(fd, sd);
  13585. sd->mail.inbox.unread--;
  13586. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13587. }
  13588. }
  13589. }
  13590. /// Request to open a mail.
  13591. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13592. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13593. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13594. #if PACKETVER < 20150513
  13595. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13596. #else
  13597. //uint8 openType = RFIFOB(fd, 2);
  13598. int mail_id = (int)RFIFOQ(fd, 3);
  13599. #endif
  13600. if( mail_id <= 0 )
  13601. return;
  13602. if( mail_invalid_operation(sd) )
  13603. return;
  13604. clif_Mail_read(sd, mail_id);
  13605. }
  13606. /// Allow a player to begin writing a mail
  13607. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13608. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13609. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13610. p.PacketType = rodexopenwrite;
  13611. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13612. p.result = success;
  13613. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13614. }
  13615. /// Request to start writing a mail
  13616. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13617. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13618. char name[NAME_LENGTH];
  13619. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13620. if( mail_invalid_operation( sd ) ){
  13621. return;
  13622. }
  13623. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13624. clif_send_Mail_beginwrite_ack(sd, name, false);
  13625. return;
  13626. }
  13627. mail_clear(sd);
  13628. sd->state.mail_writing = true;
  13629. clif_send_Mail_beginwrite_ack(sd, name,true);
  13630. }
  13631. /// Notification that the client cancelled writing a mail
  13632. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13633. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13634. sd->state.mail_writing = false;
  13635. }
  13636. /// Give the client information about the recipient, if available
  13637. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13638. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13639. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13640. #if PACKETVER >= 20141119
  13641. PACKET_ZC_CHECKNAME p = { 0 };
  13642. p.PacketType = HEADER_ZC_CHECKNAME;
  13643. p.CharId = char_id;
  13644. p.Class = class_;
  13645. p.BaseLevel = level;
  13646. #if PACKETVER >= 20160302
  13647. strncpy(p.Name, name, NAME_LENGTH);
  13648. #endif
  13649. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13650. #endif
  13651. }
  13652. /// Request information about the recipient
  13653. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13654. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13655. #if PACKETVER >= 20140423
  13656. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13657. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13658. #else
  13659. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13660. #endif
  13661. static char name[NAME_LENGTH];
  13662. if( mail_invalid_operation( sd ) ){
  13663. return;
  13664. }
  13665. safestrncpy(name, p->Name, NAME_LENGTH);
  13666. intif_mail_checkreceiver(sd, name);
  13667. #endif
  13668. }
  13669. /// Request to receive mail's attachment.
  13670. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13671. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13672. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13673. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13674. int i;
  13675. struct mail_message* msg;
  13676. #if PACKETVER < 20150513
  13677. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13678. int attachment = MAIL_ATT_ALL;
  13679. #else
  13680. uint16 packet_id = RFIFOW(fd, 0);
  13681. int mail_id = (int)RFIFOQ(fd, 2);
  13682. //int openType = RFIFOB(fd, 10);
  13683. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13684. #endif
  13685. if( !chrif_isconnected() )
  13686. return;
  13687. if( mail_id <= 0 )
  13688. return;
  13689. if( mail_invalid_operation(sd) )
  13690. return;
  13691. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13692. if( i == MAIL_MAX_INBOX )
  13693. return;
  13694. msg = &sd->mail.inbox.msg[i];
  13695. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13696. attachment &= ~MAIL_ATT_ZENY;
  13697. }
  13698. if( attachment&MAIL_ATT_ITEM ){
  13699. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13700. // No items were found
  13701. if( i == MAIL_MAX_ITEM ){
  13702. attachment &= ~MAIL_ATT_ITEM;
  13703. }
  13704. }
  13705. // Either no attachment requested at all or there are no zeny or items in the mail
  13706. if( attachment == MAIL_ATT_NONE ){
  13707. return;
  13708. }
  13709. if( attachment&MAIL_ATT_ZENY ){
  13710. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13711. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13712. return;
  13713. }else{
  13714. // Store the pending zeny (required for the "retrieve all" feature)
  13715. sd->mail.pending_zeny += msg->zeny;
  13716. // To make sure another request fails
  13717. msg->zeny = 0;
  13718. }
  13719. }
  13720. if( attachment&MAIL_ATT_ITEM ){
  13721. int slots = 0, totalweight = 0;
  13722. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13723. struct item* item = &msg->item[i];
  13724. if( item->nameid > 0 && item->amount > 0 ){
  13725. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13726. if(data == nullptr)
  13727. continue;
  13728. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13729. case CHKADDITEM_NEW:
  13730. slots += data->inventorySlotNeeded( item->amount );
  13731. break;
  13732. case CHKADDITEM_OVERAMOUNT:
  13733. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13734. return;
  13735. }
  13736. totalweight += data->weight * item->amount;
  13737. }
  13738. }
  13739. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13740. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13741. return;
  13742. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13743. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13744. return;
  13745. }
  13746. // To make sure another request fails
  13747. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13748. // Store the pending weight (required for the "retrieve all" feature)
  13749. sd->mail.pending_weight += totalweight;
  13750. // Store the pending slots (required for the "retrieve all" feature)
  13751. sd->mail.pending_slots += slots;
  13752. }
  13753. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13754. }
  13755. /// Request to delete a mail.
  13756. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13757. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13758. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13759. #if PACKETVER < 20150513
  13760. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13761. #else
  13762. //int openType = RFIFOB(fd, 2);
  13763. int mail_id = (int)RFIFOQ(fd, 3);
  13764. #endif
  13765. int i, j;
  13766. if( !chrif_isconnected() )
  13767. return;
  13768. if( mail_id <= 0 )
  13769. return;
  13770. if( mail_invalid_operation(sd) )
  13771. return;
  13772. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13773. if (i < MAIL_MAX_INBOX) {
  13774. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13775. // can't delete mail without removing zeny first
  13776. if( msg->zeny > 0 ){
  13777. clif_mail_delete(sd, msg, false);
  13778. return;
  13779. }
  13780. // can't delete mail without removing attachment(s) first
  13781. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13782. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13783. clif_mail_delete(sd, msg, false);
  13784. return;
  13785. }
  13786. }
  13787. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13788. sd->mail.inbox.unread--;
  13789. clif_Mail_new(sd,0,NULL,NULL);
  13790. }
  13791. }
  13792. }
  13793. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13794. /// 0273 <mail id>.L <receive name>.24B
  13795. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13796. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13797. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13798. //ShowDump( p, sizeof( p ) );
  13799. int mail_id = p->msgId;
  13800. // not supported for now
  13801. return;
  13802. #else
  13803. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13804. #endif
  13805. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13806. int i;
  13807. if( mail_id <= 0 )
  13808. return;
  13809. if( mail_invalid_operation(sd) )
  13810. return;
  13811. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13812. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13813. intif_Mail_return(sd->status.char_id, mail_id);
  13814. else
  13815. clif_Mail_return(sd->fd, mail_id, 1);
  13816. }
  13817. /// Request to add an item or Zeny to mail.
  13818. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13819. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13820. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13821. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13822. uint16 idx = RFIFOW(fd,info->pos[0]);
  13823. #if PACKETVER < 20150513
  13824. int amount = RFIFOL(fd,info->pos[1]);
  13825. #else
  13826. int amount = RFIFOW(fd,info->pos[1]);
  13827. #endif
  13828. unsigned char flag;
  13829. if( !chrif_isconnected() )
  13830. return;
  13831. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13832. return;
  13833. if (sd->inventory_data[server_index(idx)] == nullptr)
  13834. return;
  13835. if( mail_invalid_operation( sd ) ){
  13836. return;
  13837. }
  13838. flag = mail_setitem(sd, idx, amount);
  13839. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13840. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13841. }else{
  13842. clif_Mail_setattachment(sd,idx,amount,flag);
  13843. }
  13844. }
  13845. /// Remove an item from a mail
  13846. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13847. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13848. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13849. p.PacketType = rodexremoveitem;
  13850. p.result = success;
  13851. p.index = index;
  13852. p.cnt = amount;
  13853. int total = 0;
  13854. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13855. if( sd->mail.item[i].nameid == 0 ){
  13856. break;
  13857. }
  13858. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13859. }
  13860. p.weight = total;
  13861. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13862. }
  13863. /// Request to reset mail item and/or Zeny
  13864. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13865. /// type:
  13866. /// 0 = reset all
  13867. /// 1 = remove item
  13868. /// 2 = remove zeny
  13869. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13870. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13871. {
  13872. #if PACKETVER < 20150513
  13873. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13874. if (type == 0 || type == 1)
  13875. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13876. if (type == 0 || type == 2)
  13877. mail_removezeny(sd, false);
  13878. #else
  13879. uint16 index = RFIFOW(fd, 2);
  13880. uint16 count = RFIFOW(fd, 4);
  13881. mail_removeitem(sd,0,index,count);
  13882. #endif
  13883. }
  13884. /// Request to send mail
  13885. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13886. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13887. /// 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)
  13888. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13889. #if PACKETVER < 20150513
  13890. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13891. if( !chrif_isconnected() )
  13892. return;
  13893. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13894. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13895. return;
  13896. }
  13897. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13898. #else
  13899. uint16 length = RFIFOW(fd, 2);
  13900. if( length < 0x3e ){
  13901. ShowWarning("Too short...\n");
  13902. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13903. return;
  13904. }
  13905. if( mail_invalid_operation( sd ) ){
  13906. return;
  13907. }
  13908. // Forged request without a begin writing packet?
  13909. if( !sd->state.mail_writing ){
  13910. return; // Ignore it
  13911. }
  13912. char receiver[NAME_LENGTH];
  13913. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13914. // char sender[NAME_LENGTH];
  13915. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13916. uint64 zeny = RFIFOQ(fd, 52);
  13917. uint16 titleLength = RFIFOW(fd, 60);
  13918. uint16 textLength = RFIFOW(fd, 62);
  13919. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13920. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13921. char title[MAIL_TITLE_LENGTH];
  13922. char text[MAIL_BODY_LENGTH];
  13923. #if PACKETVER <= 20160330
  13924. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13925. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13926. #else
  13927. // 64 = <char id>.L
  13928. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13929. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13930. #endif
  13931. if( zeny > 0 ){
  13932. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13933. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13934. return;
  13935. }
  13936. }
  13937. mail_send(sd, receiver, title, text, realTextLength);
  13938. #endif
  13939. }
  13940. /// AUCTION SYSTEM
  13941. /// By Zephyrus
  13942. ///
  13943. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13944. /// 025f <type>.L
  13945. /// type:
  13946. /// 0 = open
  13947. /// 1 = close
  13948. void clif_Auction_openwindow(struct map_session_data *sd)
  13949. {
  13950. int fd = sd->fd;
  13951. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13952. return;
  13953. if( !battle_config.feature_auction )
  13954. return;
  13955. WFIFOHEAD(fd,packet_len(0x25f));
  13956. WFIFOW(fd,0) = 0x25f;
  13957. WFIFOL(fd,2) = 0;
  13958. WFIFOSET(fd,packet_len(0x25f));
  13959. }
  13960. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13961. /// 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 }*
  13962. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13963. {
  13964. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13965. struct auction_data auction;
  13966. WFIFOHEAD(fd,12 + (count * 83));
  13967. WFIFOW(fd,0) = 0x252;
  13968. WFIFOW(fd,2) = 12 + (count * 83);
  13969. WFIFOL(fd,4) = pages;
  13970. WFIFOL(fd,8) = count;
  13971. for( i = 0; i < count; i++ ) {
  13972. int k = 12 + (i * 83);
  13973. memcpy(&auction, RBUFP(buf,i * len), len);
  13974. WFIFOL(fd,k) = auction.auction_id;
  13975. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13976. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13977. WFIFOL(fd,30+k) = auction.type;
  13978. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13979. WFIFOB(fd,36+k) = auction.item.identify;
  13980. WFIFOB(fd,37+k) = auction.item.attribute;
  13981. WFIFOB(fd,38+k) = auction.item.refine;
  13982. WFIFOW(fd,39+k) = auction.item.card[0];
  13983. WFIFOW(fd,41+k) = auction.item.card[1];
  13984. WFIFOW(fd,43+k) = auction.item.card[2];
  13985. WFIFOW(fd,45+k) = auction.item.card[3];
  13986. WFIFOL(fd,47+k) = auction.price;
  13987. WFIFOL(fd,51+k) = auction.buynow;
  13988. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13989. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13990. }
  13991. WFIFOSET(fd,WFIFOW(fd,2));
  13992. }
  13993. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13994. /// 0256 <index>.W <result>.B
  13995. /// result:
  13996. /// 0 = success
  13997. /// 1 = failure
  13998. static void clif_Auction_setitem(int fd, int index, bool fail)
  13999. {
  14000. WFIFOHEAD(fd,packet_len(0x256));
  14001. WFIFOW(fd,0) = 0x256;
  14002. WFIFOW(fd,2) = index;
  14003. WFIFOB(fd,4) = fail;
  14004. WFIFOSET(fd,packet_len(0x256));
  14005. }
  14006. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  14007. /// 024b <type>.W
  14008. /// type:
  14009. /// 0 = create (any other action in auction window)
  14010. /// 1 = cancel (cancel pressed on register tab)
  14011. /// ? = junk, uninitialized value (ex. when switching between list filters)
  14012. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  14013. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14014. if( sd->auction.amount > 0 )
  14015. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  14016. sd->auction.amount = 0;
  14017. }
  14018. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  14019. /// 024c <index>.W <count>.L
  14020. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  14021. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14022. int idx = RFIFOW(fd,info->pos[0]) - 2;
  14023. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  14024. if( !battle_config.feature_auction )
  14025. return;
  14026. if( sd->auction.amount > 0 )
  14027. sd->auction.amount = 0;
  14028. if( idx < 0 || idx >= MAX_INVENTORY ) {
  14029. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  14030. return;
  14031. }
  14032. 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.
  14033. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  14034. return;
  14035. }
  14036. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  14037. 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) )
  14038. { // Consumable or pets are not allowed
  14039. clif_Auction_setitem(sd->fd, idx, true);
  14040. return;
  14041. }
  14042. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  14043. !sd->inventory.u.items_inventory[idx].identify ||
  14044. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  14045. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  14046. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  14047. clif_Auction_setitem(sd->fd, idx, true);
  14048. return;
  14049. }
  14050. sd->auction.index = idx;
  14051. sd->auction.amount = amount;
  14052. clif_Auction_setitem(fd, idx + 2, false);
  14053. }
  14054. /// Result from an auction action (ZC_AUCTION_RESULT).
  14055. /// 0250 <result>.B
  14056. /// result:
  14057. /// 0 = You have failed to bid into the auction
  14058. /// 1 = You have successfully bid in the auction
  14059. /// 2 = The auction has been canceled
  14060. /// 3 = An auction with at least one bidder cannot be canceled
  14061. /// 4 = You cannot register more than 5 items in an auction at a time
  14062. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14063. /// 6 = You have won the auction
  14064. /// 7 = You have failed to win the auction
  14065. /// 8 = You do not have enough Zeny
  14066. /// 9 = You cannot place more than 5 bids at a time
  14067. void clif_Auction_message(int fd, unsigned char flag)
  14068. {
  14069. WFIFOHEAD(fd,packet_len(0x250));
  14070. WFIFOW(fd,0) = 0x250;
  14071. WFIFOB(fd,2) = flag;
  14072. WFIFOSET(fd,packet_len(0x250));
  14073. }
  14074. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14075. /// 025e <result>.W
  14076. /// result:
  14077. /// 0 = You have ended the auction
  14078. /// 1 = You cannot end the auction
  14079. /// 2 = Auction ID is incorrect
  14080. void clif_Auction_close(int fd, unsigned char flag)
  14081. {
  14082. WFIFOHEAD(fd,packet_len(0x25e));
  14083. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14084. WFIFOW(fd,2) = flag;
  14085. WFIFOSET(fd,packet_len(0x25e));
  14086. }
  14087. /// Request to add an auction (CZ_AUCTION_ADD).
  14088. /// 024d <now money>.L <max money>.L <delete hour>.W
  14089. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  14090. {
  14091. struct auction_data auction;
  14092. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14093. if( !battle_config.feature_auction )
  14094. return;
  14095. auction.price = RFIFOL(fd,info->pos[0]);
  14096. auction.buynow = RFIFOL(fd,info->pos[1]);
  14097. auction.hours = RFIFOW(fd,info->pos[2]);
  14098. // Invalid Situations...
  14099. if( sd->auction.amount < 1 ) {
  14100. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14101. return;
  14102. }
  14103. if( auction.price >= auction.buynow ) {
  14104. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14105. return;
  14106. }
  14107. if( auction.hours < 1 || auction.hours > 48 ) {
  14108. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14109. return;
  14110. }
  14111. // Auction checks...
  14112. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14113. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14114. clif_Auction_message(fd, 2); // The auction has been canceled
  14115. return;
  14116. }
  14117. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14118. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14119. return;
  14120. }
  14121. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14122. auction.buynow = battle_config.auction_maximumprice;
  14123. if( auction.price >= auction.buynow )
  14124. auction.price = auction.buynow - 1;
  14125. }
  14126. auction.auction_id = 0;
  14127. auction.seller_id = sd->status.char_id;
  14128. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14129. auction.buyer_id = 0;
  14130. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14131. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14132. {
  14133. clif_Auction_message(fd, 2); // The auction has been canceled
  14134. return;
  14135. }
  14136. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14137. if( id == nullptr )
  14138. { // Just in case
  14139. clif_Auction_message(fd, 2); // The auction has been canceled
  14140. return;
  14141. }
  14142. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14143. auction.type = id->type;
  14144. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14145. auction.item.amount = 1;
  14146. auction.timestamp = 0;
  14147. if( !intif_Auction_register(&auction) )
  14148. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14149. else
  14150. {
  14151. int zeny = auction.hours*battle_config.auction_feeperhour;
  14152. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14153. sd->auction.amount = 0;
  14154. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  14155. }
  14156. }
  14157. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14158. /// 024e <auction id>.L
  14159. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  14160. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14161. intif_Auction_cancel(sd->status.char_id, auction_id);
  14162. }
  14163. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14164. /// 025d <auction id>.L
  14165. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  14166. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14167. intif_Auction_close(sd->status.char_id, auction_id);
  14168. }
  14169. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14170. /// 024f <auction id>.L <money>.L
  14171. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  14172. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14173. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14174. int bid = RFIFOL(fd,info->pos[1]);
  14175. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14176. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14177. return;
  14178. }
  14179. if( bid <= 0 )
  14180. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14181. else if( bid > sd->status.zeny )
  14182. clif_Auction_message(fd, 8); // You do not have enough zeny
  14183. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14184. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14185. else {
  14186. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14187. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14188. }
  14189. }
  14190. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14191. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14192. /// search type:
  14193. /// 0 = armor
  14194. /// 1 = weapon
  14195. /// 2 = card
  14196. /// 3 = misc
  14197. /// 4 = name search
  14198. /// 5 = auction id search
  14199. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  14200. char search_text[NAME_LENGTH];
  14201. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14202. short type = RFIFOW(fd,info->pos[0]);
  14203. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14204. int page = RFIFOW(fd,info->pos[3]);
  14205. if( !battle_config.feature_auction )
  14206. return;
  14207. clif_parse_Auction_cancelreg(fd, sd);
  14208. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14209. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14210. }
  14211. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14212. /// 025c <type>.W
  14213. /// type:
  14214. /// 0 = sell (own auctions)
  14215. /// 1 = buy (own bids)
  14216. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  14217. {
  14218. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14219. if( !battle_config.feature_auction )
  14220. return;
  14221. clif_parse_Auction_cancelreg(fd, sd);
  14222. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14223. }
  14224. /// CASH/POINT SHOP
  14225. ///
  14226. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  14227. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14228. nullpo_retv( sd );
  14229. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14230. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14231. p.cashPoints = sd->cashPoints;
  14232. p.kafraPoints = sd->kafraPoints;
  14233. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14234. p.tab = tab;
  14235. #endif
  14236. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14237. #endif
  14238. }
  14239. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  14240. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14241. nullpo_retv( sd );
  14242. int tab = 0;
  14243. #if PACKETVER >= 20191224
  14244. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14245. tab = p->tab;
  14246. #endif
  14247. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14248. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14249. return;
  14250. }
  14251. sd->state.cashshop_open = true;
  14252. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14253. clif_cashshop_open( sd, tab );
  14254. #endif
  14255. }
  14256. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14257. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14258. sd->state.cashshop_open = false;
  14259. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14260. // No need to do anything here
  14261. #endif
  14262. }
  14263. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14264. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14265. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14266. // [4144] packet exists only in 2011 and was dropped after
  14267. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14268. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14269. int j;
  14270. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14271. return;
  14272. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14273. WFIFOW(fd, 0) = 0x8c0;
  14274. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14275. WFIFOL(fd, 4) = tab;
  14276. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14277. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14278. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14279. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14280. }
  14281. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14282. #endif
  14283. }
  14284. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14285. void clif_cashshop_list( struct map_session_data* sd ){
  14286. nullpo_retv( sd );
  14287. int fd = sd->fd;
  14288. if( !session_isActive( fd ) ){
  14289. return;
  14290. }
  14291. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14292. // Skip empty tabs, the client only expects filled ones
  14293. if( cash_shop_items[tab].count == 0 ){
  14294. continue;
  14295. }
  14296. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14297. WFIFOHEAD( fd, len );
  14298. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14299. p->packetType = 0x8ca;
  14300. p->packetLength = len;
  14301. p->count = cash_shop_items[tab].count;
  14302. p->tabNum = tab;
  14303. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14304. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14305. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14306. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14307. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14308. if( id == nullptr ){
  14309. p->items[i].location = 0;
  14310. p->items[i].viewSprite = 0;
  14311. }else{
  14312. p->items[i].location = pc_equippoint_sub( sd, id );
  14313. p->items[i].viewSprite = id->look;
  14314. }
  14315. #endif
  14316. }
  14317. WFIFOSET( fd, len );
  14318. }
  14319. }
  14320. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14321. if( !sd->status.cashshop_sent ) {
  14322. clif_cashshop_list( sd );
  14323. #if PACKETVER_SUPPORTS_SALES
  14324. sale_notify_login(sd);
  14325. #endif
  14326. sd->status.cashshop_sent = true;
  14327. }
  14328. }
  14329. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14330. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14331. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14332. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14333. nullpo_retv( sd );
  14334. nullpo_retv( nd );
  14335. int fd = sd->fd;
  14336. if( !session_isActive( fd ) ){
  14337. return;
  14338. }
  14339. sd->npc_shopid = nd->bl.id;
  14340. int cost[2] = { 0, 0 };
  14341. npc_shop_currency_type( sd, nd, cost, true );
  14342. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14343. WFIFOHEAD( fd, len );
  14344. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14345. p->packetType = 0x287;
  14346. p->packetLength = len;
  14347. p->cashPoints = cost[0];
  14348. #if PACKETVER >= 20070711
  14349. p->kafraPoints = cost[1];
  14350. #endif
  14351. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14352. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14353. p->items[i].price = nd->u.shop.shop_item[i].value;
  14354. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14355. p->items[i].itemType = itemtype( id->nameid );
  14356. p->items[i].itemId = client_nameid( id->nameid );
  14357. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14358. p->items[i].location = pc_equippoint_sub( sd, id );
  14359. p->items[i].viewSprite = id->look;
  14360. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14361. #endif
  14362. }
  14363. WFIFOSET( fd, len );
  14364. }
  14365. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14366. /// 0289 <cash point>.L <error>.W
  14367. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14368. /// error:
  14369. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14370. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14371. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14372. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14373. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14374. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14375. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14376. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14377. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14378. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14379. {
  14380. int fd, cost[2] = { 0, 0 };
  14381. struct npc_data *nd;
  14382. nullpo_retv(sd);
  14383. fd = sd->fd;
  14384. nd = map_id2nd(sd->npc_shopid);
  14385. npc_shop_currency_type(sd, nd, cost, false);
  14386. WFIFOHEAD(fd, packet_len(0x289));
  14387. WFIFOW(fd,0) = 0x289;
  14388. WFIFOL(fd,2) = cost[0];
  14389. #if PACKETVER < 20070711
  14390. WFIFOW(fd,6) = TOW(error);
  14391. #else
  14392. WFIFOL(fd,6) = cost[1];
  14393. WFIFOW(fd,10) = TOW(error);
  14394. #endif
  14395. WFIFOSET(fd, packet_len(0x289));
  14396. }
  14397. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14398. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14399. nullpo_retv( sd );
  14400. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14401. packet.packetType = 0x849;
  14402. if( item_id != 0 ){
  14403. packet.itemId = client_nameid( item_id );
  14404. }else{
  14405. packet.itemId = 0;
  14406. }
  14407. packet.result = result;
  14408. packet.cashPoints = sd->cashPoints;
  14409. packet.kafraPoints = sd->kafraPoints;
  14410. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14411. #endif
  14412. }
  14413. /// Request to buy item(s) from cash shop.
  14414. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14415. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14416. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14417. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14418. nullpo_retv( sd );
  14419. if( sd->state.trading || !sd->npc_shopid ){
  14420. clif_cashshop_ack( sd, 1 );
  14421. return;
  14422. }
  14423. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14424. #if PACKETVER < 20070711
  14425. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14426. #elif PACKETVER < 20101116
  14427. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14428. #else
  14429. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14430. 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 ){
  14431. 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 );
  14432. return;
  14433. }
  14434. std::vector<s_npc_buy_list> item_list = {};
  14435. item_list.reserve( p->count );
  14436. for( int i = 0; i < p->count; i++ ){
  14437. s_npc_buy_list item = {};
  14438. item.nameid = p->items[i].itemId;
  14439. item.qty = p->items[i].amount;
  14440. item_list.push_back( item );
  14441. }
  14442. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14443. #endif
  14444. }
  14445. /// Request to buy item(s) from cash shop.
  14446. /// 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)
  14447. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14448. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14449. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14450. 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 ){
  14451. 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 );
  14452. return;
  14453. }
  14454. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14455. }
  14456. /// Adoption System
  14457. ///
  14458. /// Adoption message (ZC_BABYMSG).
  14459. /// 0216 <msg>.L
  14460. /// msg:
  14461. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14462. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14463. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14464. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14465. {
  14466. int fd = sd->fd;
  14467. WFIFOHEAD(fd,6);
  14468. WFIFOW(fd,0) = 0x216;
  14469. WFIFOL(fd,2) = type;
  14470. WFIFOSET(fd,6);
  14471. }
  14472. /// Adoption confirmation (ZC_REQ_BABY).
  14473. /// 01f6 <account id>.L <char id>.L <name>.B
  14474. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14475. {
  14476. int fd = sd->fd;
  14477. WFIFOHEAD(fd,34);
  14478. WFIFOW(fd,0) = 0x1f6;
  14479. WFIFOL(fd,2) = src->status.account_id;
  14480. WFIFOL(fd,6) = p_id;
  14481. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14482. WFIFOSET(fd,34);
  14483. }
  14484. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14485. /// 01f9 <account id>.L
  14486. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14487. {
  14488. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14489. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14490. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14491. {
  14492. tsd->adopt_invite = sd->status.account_id;
  14493. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14494. }
  14495. }
  14496. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14497. /// 01f7 <account id>.L <char id>.L <answer>.L
  14498. /// answer:
  14499. /// 0 = rejected
  14500. /// 1 = accepted
  14501. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14502. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14503. int p1_id = RFIFOL(fd,info->pos[0]);
  14504. int p2_id = RFIFOL(fd,info->pos[1]);
  14505. int result = RFIFOL(fd,info->pos[2]);
  14506. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14507. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14508. int pid = sd->adopt_invite;
  14509. sd->adopt_invite = 0;
  14510. if( p1_sd == NULL || p2_sd == NULL )
  14511. return; // Both players need to be online
  14512. if( pid != p1_sd->status.account_id )
  14513. return; // Incorrect values
  14514. if( result == 0 )
  14515. return; // Rejected
  14516. pc_adoption(p1_sd, p2_sd, sd);
  14517. }
  14518. /// Convex Mirror (ZC_BOSS_INFO).
  14519. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14520. /// infoType:
  14521. /// BOSS_INFO_NOT = No boss on this map.
  14522. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14523. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14524. /// BOSS_INFO_DEAD = Boss is dead.
  14525. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14526. {
  14527. int fd = sd->fd;
  14528. WFIFOHEAD(fd,70);
  14529. memset(WFIFOP(fd,0),0,70);
  14530. WFIFOW(fd,0) = 0x293;
  14531. switch (flag) {
  14532. case BOSS_INFO_NOT:
  14533. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14534. // No data required
  14535. break;
  14536. case BOSS_INFO_ALIVE:
  14537. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14538. // Update X/Y
  14539. WFIFOL(fd,3) = md->bl.x;
  14540. WFIFOL(fd,7) = md->bl.y;
  14541. break;
  14542. case BOSS_INFO_ALIVE_WITHMSG:
  14543. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14544. // Current X/Y
  14545. WFIFOL(fd,3) = md->bl.x;
  14546. WFIFOL(fd,7) = md->bl.y;
  14547. break;
  14548. case BOSS_INFO_DEAD:
  14549. {
  14550. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14551. unsigned int seconds;
  14552. int hours, minutes;
  14553. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14554. hours = seconds / (60 * 60);
  14555. seconds = seconds - (60 * 60 * hours);
  14556. minutes = seconds / 60;
  14557. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14558. // Add respawn info
  14559. WFIFOW(fd,11) = hours; // Hours
  14560. WFIFOW(fd,13) = minutes; // Minutes
  14561. }
  14562. break;
  14563. }
  14564. if (md != NULL)
  14565. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14566. WFIFOSET(fd,70);
  14567. }
  14568. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14569. /// 02d6 <account id>.L
  14570. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14571. {
  14572. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14573. struct map_session_data* tsd = map_id2sd(aid);
  14574. if (!tsd)
  14575. return;
  14576. if (sd->bl.m != tsd->bl.m)
  14577. return;
  14578. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14579. clif_viewequip_ack(sd, tsd);
  14580. else
  14581. clif_msg(sd, VIEW_EQUIP_FAIL);
  14582. }
  14583. /// Request to a configuration.
  14584. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14585. /// type: see enum e_config_type
  14586. /// flag:
  14587. /// false = disabled
  14588. /// true = enabled
  14589. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14590. int cmd = RFIFOW(fd,0);
  14591. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14592. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14593. switch( type ){
  14594. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14595. sd->status.show_equip = flag;
  14596. break;
  14597. case CONFIG_CALL:
  14598. sd->status.disable_call = flag;
  14599. break;
  14600. case CONFIG_PET_AUTOFEED:
  14601. // Player can not click this if he does not have a pet
  14602. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14603. return;
  14604. }
  14605. sd->pd->pet.autofeed = flag;
  14606. break;
  14607. case CONFIG_HOMUNCULUS_AUTOFEED:
  14608. // Player can not click this if he does not have a homunculus or it is vaporized
  14609. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14610. return;
  14611. }
  14612. sd->hd->homunculus.autofeed = flag;
  14613. break;
  14614. default:
  14615. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14616. return;
  14617. }
  14618. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14619. }
  14620. /// Request to change party invitation tick.
  14621. /// value:
  14622. /// 0 = disabled
  14623. /// 1 = enabled
  14624. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14625. {
  14626. bool flag = RFIFOB(fd,6) ? true : false;
  14627. sd->status.allow_party = flag;
  14628. clif_partytickack(sd, flag);
  14629. }
  14630. /// Questlog System [Kevin] [Inkfish]
  14631. ///
  14632. /**
  14633. * Safe check to init packet len & quest num for player.
  14634. * @param def_len
  14635. * @param info_len Length of each quest info.
  14636. * @param avail_quests Avail quests that player has.
  14637. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14638. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14639. **/
  14640. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14641. (*limit_out) = (0xFFFF - def_len) / info_len;
  14642. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14643. (*len_out) = ((*limit_out) * info_len) + def_len;
  14644. }
  14645. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14646. std::string race_name;
  14647. switch( objective->race ){
  14648. case RC_FORMLESS: race_name = "Formless"; break;
  14649. case RC_UNDEAD: race_name = "Undead"; break;
  14650. case RC_BRUTE: race_name = "Brute"; break;
  14651. case RC_PLANT: race_name = "Plant"; break;
  14652. case RC_INSECT: race_name = "Insect"; break;
  14653. case RC_FISH: race_name = "Fish"; break;
  14654. case RC_DEMON: race_name = "Demon"; break;
  14655. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14656. case RC_ANGEL: race_name = "Angel"; break;
  14657. case RC_DRAGON: race_name = "Dragon"; break;
  14658. default:
  14659. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14660. // Fallthrough
  14661. case RC_ALL: race_name = ""; break;
  14662. }
  14663. std::string size_name;
  14664. switch( objective->size ){
  14665. case SZ_SMALL: size_name = "Small"; break;
  14666. case SZ_MEDIUM: size_name = "Medium"; break;
  14667. case SZ_BIG: size_name = "Large"; break;
  14668. default:
  14669. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14670. // Fallthrough
  14671. case SZ_ALL: size_name = ""; break;
  14672. }
  14673. std::string ele_name;
  14674. switch( objective->element ){
  14675. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14676. case ELE_WATER: ele_name = "Water Element"; break;
  14677. case ELE_EARTH: ele_name = "Earth Element"; break;
  14678. case ELE_FIRE: ele_name = "Fire Element"; break;
  14679. case ELE_WIND: ele_name = "Wind Element"; break;
  14680. case ELE_POISON: ele_name = "Poison Element"; break;
  14681. case ELE_HOLY: ele_name = "Holy Element"; break;
  14682. case ELE_DARK: ele_name = "Shadow Element"; break;
  14683. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14684. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14685. default:
  14686. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14687. // Fallthrough
  14688. case ELE_ALL: ele_name = ""; break;
  14689. }
  14690. std::string str;
  14691. if( !objective->map_name.empty() ){
  14692. str += objective->map_name;
  14693. }
  14694. if( !race_name.empty() ){
  14695. if( !str.empty() ){
  14696. str += ", ";
  14697. }
  14698. str += race_name;
  14699. }
  14700. if( !size_name.empty() ){
  14701. if( !str.empty() ){
  14702. str += ", ";
  14703. }
  14704. str += size_name;
  14705. }
  14706. if( !ele_name.empty() ){
  14707. if( !str.empty() ){
  14708. str += ", ";
  14709. }
  14710. str += ele_name;
  14711. }
  14712. return str;
  14713. }
  14714. /// Sends list of all quest states
  14715. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14716. /// 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)
  14717. /// 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)
  14718. void clif_quest_send_list(struct map_session_data *sd)
  14719. {
  14720. nullpo_retv(sd);
  14721. int fd = sd->fd;
  14722. int i;
  14723. int offset = 8;
  14724. int limit = 0;
  14725. #if PACKETVER >= 20141022
  14726. #if PACKETVER >= 20150513
  14727. int size = 22 + NAME_LENGTH;
  14728. #else
  14729. int size = 10 + NAME_LENGTH;
  14730. #endif
  14731. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14732. WFIFOHEAD(fd,i);
  14733. #if PACKETVER >= 20150513
  14734. WFIFOW(fd, 0) = 0x9f8;
  14735. #else
  14736. WFIFOW(fd, 0) = 0x97a;
  14737. #endif
  14738. WFIFOL(fd, 4) = limit;
  14739. for (i = 0; i < limit; i++) {
  14740. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14741. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14742. offset += 4;
  14743. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14744. offset++;
  14745. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14746. offset += 4;
  14747. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14748. offset += 4;
  14749. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14750. offset += 2;
  14751. if (!qi->objectives.empty()) {
  14752. std::shared_ptr<s_mob_db> mob;
  14753. for (int j = 0; j < qi->objectives.size(); j++) {
  14754. mob = mob_db.find(qi->objectives[j]->mob_id);
  14755. e_race race = qi->objectives[j]->race;
  14756. e_size size = qi->objectives[j]->size;
  14757. e_element element = qi->objectives[j]->element;
  14758. #if PACKETVER >= 20150513
  14759. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14760. offset += 4;
  14761. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14762. offset += 4;
  14763. #endif
  14764. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14765. offset += 4;
  14766. #if PACKETVER >= 20150513
  14767. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14768. offset += 2;
  14769. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14770. offset += 2;
  14771. #endif
  14772. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14773. offset += 2;
  14774. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14775. offset += 2;
  14776. if (mob && qi->objectives[j]->mob_id > 0)
  14777. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14778. else
  14779. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14780. offset += NAME_LENGTH;
  14781. }
  14782. }
  14783. }
  14784. WFIFOW(fd, 2) = offset;
  14785. WFIFOSET(fd, offset);
  14786. #else
  14787. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14788. WFIFOHEAD(fd,i);
  14789. WFIFOW(fd, 0) = 0x2b1;
  14790. WFIFOL(fd, 4) = limit;
  14791. for (i = 0; i < limit; i++) {
  14792. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14793. offset += 4;
  14794. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14795. offset += 1;
  14796. }
  14797. WFIFOW(fd, 2) = offset;
  14798. WFIFOSET(fd, offset);
  14799. #endif
  14800. }
  14801. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14802. /// 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
  14803. void clif_quest_send_mission(struct map_session_data *sd)
  14804. {
  14805. nullpo_retv(sd);
  14806. int fd = sd->fd;
  14807. int limit = 0;
  14808. int len = sd->avail_quests*104+8;
  14809. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14810. WFIFOHEAD(fd, len);
  14811. WFIFOW(fd, 0) = 0x2b2;
  14812. WFIFOW(fd, 2) = len;
  14813. WFIFOL(fd, 4) = limit;
  14814. for (int i = 0; i < limit; i++) {
  14815. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14816. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14817. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14818. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14819. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14820. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14821. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14822. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14823. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14824. if (mob && qi->objectives[j]->mob_id > 0)
  14825. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14826. else
  14827. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14828. }
  14829. }
  14830. WFIFOSET(fd, len);
  14831. }
  14832. /// Notification about a new quest
  14833. /// 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)
  14834. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14835. /// 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)
  14836. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14837. {
  14838. nullpo_retv(sd);
  14839. nullpo_retv(qd);
  14840. int fd = sd->fd;
  14841. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14842. if (!qi)
  14843. return;
  14844. #if PACKETVER >= 20150513
  14845. int cmd = 0x9f9;
  14846. #else
  14847. int cmd = 0x2b3;
  14848. #endif
  14849. WFIFOHEAD(fd, packet_len(cmd));
  14850. WFIFOW(fd, 0) = cmd;
  14851. WFIFOL(fd, 2) = qd->quest_id;
  14852. WFIFOB(fd, 6) = qd->state;
  14853. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14854. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14855. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14856. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14857. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14858. e_race race = qi->objectives[i]->race;
  14859. e_size size = qi->objectives[i]->size;
  14860. e_element element = qi->objectives[i]->element;
  14861. #if PACKETVER >= 20150513
  14862. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14863. offset += 4;
  14864. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14865. offset += 4;
  14866. #endif
  14867. 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
  14868. offset += 4;
  14869. #if PACKETVER >= 20150513
  14870. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14871. offset += 2;
  14872. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14873. offset += 2;
  14874. #endif
  14875. WFIFOW(fd, offset) = qd->count[i];
  14876. offset += 2;
  14877. if (mob && qi->objectives[i]->mob_id > 0)
  14878. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14879. else
  14880. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14881. offset += NAME_LENGTH;
  14882. }
  14883. WFIFOSET(fd, packet_len(cmd));
  14884. #if PACKETVER >= 20150513
  14885. int len = 4 + qi->objectives.size() * 12;
  14886. WFIFOHEAD(fd, len);
  14887. WFIFOW(fd, 0) = 0x8fe;
  14888. WFIFOW(fd, 2) = len;
  14889. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14890. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14891. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14892. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14893. WFIFOW(fd, offset + 10) = qd->count[i];
  14894. }
  14895. WFIFOSET(fd, len);
  14896. #endif
  14897. }
  14898. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14899. /// 02b4 <quest id>.L
  14900. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14901. {
  14902. int fd = sd->fd;
  14903. WFIFOHEAD(fd, packet_len(0x2b4));
  14904. WFIFOW(fd, 0) = 0x2b4;
  14905. WFIFOL(fd, 2) = quest_id;
  14906. WFIFOSET(fd, packet_len(0x2b4));
  14907. }
  14908. /// Notification of an update to the hunting mission counter
  14909. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14910. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14911. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  14912. {
  14913. int fd = sd->fd;
  14914. int offset = 6;
  14915. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14916. int len = qi->objectives.size() * 12 + 6;
  14917. #if PACKETVER >= 20150513
  14918. int cmd = 0x9fa;
  14919. #else
  14920. int cmd = 0x2b5;
  14921. #endif
  14922. WFIFOHEAD(fd, len);
  14923. WFIFOW(fd, 0) = cmd;
  14924. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14925. for (int i = 0; i < qi->objectives.size(); i++) {
  14926. WFIFOL(fd, offset) = qd->quest_id;
  14927. offset += 4;
  14928. #if PACKETVER >= 20150513
  14929. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14930. offset += 4;
  14931. #else
  14932. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14933. offset += 4;
  14934. #endif
  14935. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14936. offset += 2;
  14937. WFIFOW(fd, offset) = qd->count[i];
  14938. offset += 2;
  14939. }
  14940. WFIFOW(fd, 2) = offset;
  14941. WFIFOSET(fd, offset);
  14942. }
  14943. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14944. /// 02b6 <quest id>.L <active>.B
  14945. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14946. {
  14947. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14948. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14949. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14950. }
  14951. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14952. /// 02b7 <quest id>.L <active>.B
  14953. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14954. {
  14955. int fd = sd->fd;
  14956. WFIFOHEAD(fd, packet_len(0x2b7));
  14957. WFIFOW(fd, 0) = 0x2b7;
  14958. WFIFOL(fd, 2) = quest_id;
  14959. WFIFOB(fd, 6) = active;
  14960. WFIFOSET(fd, packet_len(0x2b7));
  14961. }
  14962. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14963. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14964. /// effect:
  14965. /// 0 = none
  14966. /// 1 = exclamation mark icon
  14967. /// 2 = question mark icon
  14968. /// color:
  14969. /// 0 = yellow
  14970. /// 1 = orange
  14971. /// 2 = green
  14972. /// 3 = purple
  14973. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14974. {
  14975. #if PACKETVER >= 20090218
  14976. nullpo_retv(sd);
  14977. nullpo_retv(bl);
  14978. int fd = sd->fd;
  14979. WFIFOHEAD(fd, packet_len(0x446));
  14980. WFIFOW(fd, 0) = 0x446;
  14981. WFIFOL(fd, 2) = bl->id;
  14982. WFIFOW(fd, 6) = bl->x;
  14983. WFIFOW(fd, 8) = bl->y;
  14984. WFIFOW(fd, 10) = effect;
  14985. WFIFOW(fd, 12) = color;
  14986. WFIFOSET(fd, packet_len(0x446));
  14987. #endif
  14988. }
  14989. /// Mercenary System
  14990. ///
  14991. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14992. /// 02a2 <var id>.W <value>.L
  14993. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14994. {
  14995. s_mercenary_data *md;
  14996. struct status_data *status;
  14997. int fd;
  14998. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14999. return;
  15000. fd = sd->fd;
  15001. status = &md->battle_status;
  15002. WFIFOHEAD(fd,packet_len(0x2a2));
  15003. WFIFOW(fd,0) = 0x2a2;
  15004. WFIFOW(fd,2) = type;
  15005. switch( type ) {
  15006. case SP_ATK1:
  15007. {
  15008. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15009. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  15010. }
  15011. break;
  15012. case SP_MATK1:
  15013. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  15014. break;
  15015. case SP_HIT:
  15016. WFIFOL(fd,4) = status->hit;
  15017. break;
  15018. case SP_CRITICAL:
  15019. WFIFOL(fd,4) = status->cri/10;
  15020. break;
  15021. case SP_DEF1:
  15022. WFIFOL(fd,4) = status->def;
  15023. break;
  15024. case SP_MDEF1:
  15025. WFIFOL(fd,4) = status->mdef;
  15026. break;
  15027. case SP_MERCFLEE:
  15028. WFIFOL(fd,4) = status->flee;
  15029. break;
  15030. case SP_ASPD:
  15031. WFIFOL(fd,4) = status->amotion;
  15032. break;
  15033. case SP_HP:
  15034. WFIFOL(fd,4) = status->hp;
  15035. break;
  15036. case SP_MAXHP:
  15037. WFIFOL(fd,4) = status->max_hp;
  15038. break;
  15039. case SP_SP:
  15040. WFIFOL(fd,4) = status->sp;
  15041. break;
  15042. case SP_MAXSP:
  15043. WFIFOL(fd,4) = status->max_sp;
  15044. break;
  15045. case SP_MERCKILLS:
  15046. WFIFOL(fd,4) = md->mercenary.kill_count;
  15047. break;
  15048. case SP_MERCFAITH:
  15049. WFIFOL(fd,4) = mercenary_get_faith(md);
  15050. break;
  15051. }
  15052. WFIFOSET(fd,packet_len(0x2a2));
  15053. }
  15054. /// Mercenary base status data (ZC_MER_INIT).
  15055. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  15056. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  15057. /// <calls>.L <kills>.L <atk range>.W
  15058. void clif_mercenary_info(struct map_session_data *sd)
  15059. {
  15060. int fd;
  15061. s_mercenary_data *md;
  15062. struct status_data *status;
  15063. int atk;
  15064. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15065. return;
  15066. fd = sd->fd;
  15067. status = &md->battle_status;
  15068. WFIFOHEAD(fd,packet_len(0x29b));
  15069. WFIFOW(fd,0) = 0x29b;
  15070. WFIFOL(fd,2) = md->bl.id;
  15071. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15072. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15073. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15074. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15075. WFIFOW(fd,10) = status->hit;
  15076. WFIFOW(fd,12) = status->cri/10;
  15077. WFIFOW(fd,14) = status->def;
  15078. WFIFOW(fd,16) = status->mdef;
  15079. WFIFOW(fd,18) = status->flee;
  15080. WFIFOW(fd,20) = status->amotion;
  15081. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15082. WFIFOW(fd,46) = md->db->lv;
  15083. WFIFOL(fd,48) = status->hp;
  15084. WFIFOL(fd,52) = status->max_hp;
  15085. WFIFOL(fd,56) = status->sp;
  15086. WFIFOL(fd,60) = status->max_sp;
  15087. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15088. WFIFOW(fd,68) = mercenary_get_faith(md);
  15089. WFIFOL(fd,70) = mercenary_get_calls(md);
  15090. WFIFOL(fd,74) = md->mercenary.kill_count;
  15091. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15092. WFIFOSET(fd,packet_len(0x29b));
  15093. }
  15094. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15095. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15096. void clif_mercenary_skillblock(struct map_session_data *sd)
  15097. {
  15098. s_mercenary_data *md;
  15099. int fd, len = 4;
  15100. if( sd == NULL || (md = sd->md) == NULL )
  15101. return;
  15102. fd = sd->fd;
  15103. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15104. WFIFOW(fd,0) = 0x29d;
  15105. for (const auto &it : md->db->skill) {
  15106. uint16 id = it.first;
  15107. if (!SKILL_CHK_MERC(id))
  15108. continue;
  15109. uint16 lv = it.second;
  15110. WFIFOW(fd,len) = id;
  15111. WFIFOL(fd,len+2) = skill_get_inf(id);
  15112. WFIFOW(fd,len+6) = lv;
  15113. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15114. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15115. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15116. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15117. len += 37;
  15118. }
  15119. WFIFOW(fd,2) = len;
  15120. WFIFOSET(fd,len);
  15121. }
  15122. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15123. /// 029f <command>.B
  15124. /// 1 = mercenary information
  15125. /// 2 = delete
  15126. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  15127. {
  15128. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15129. if( sd->md == NULL )
  15130. return;
  15131. if( option == 2 ) mercenary_delete(sd->md, 2);
  15132. }
  15133. /// Mercenary Message
  15134. /// message:
  15135. /// 0 = Mercenary soldier's duty hour is over.
  15136. /// 1 = Your mercenary soldier has been killed.
  15137. /// 2 = Your mercenary soldier has been fired.
  15138. /// 3 = Your mercenary soldier has ran away.
  15139. void clif_mercenary_message(struct map_session_data* sd, int message){
  15140. clif_msg(sd, MERC_MSG_BASE + message);
  15141. }
  15142. /// Notification about the remaining time of a rental item.
  15143. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15144. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  15145. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15146. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15147. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15148. p.itemId = client_nameid( nameid );
  15149. p.seconds = seconds;
  15150. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15151. }
  15152. /// Deletes a rental item from client's inventory.
  15153. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15154. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  15155. // '<ItemName>' item has been deleted from the Inventory
  15156. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15157. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15158. p.index = client_index( index );
  15159. p.itemId = client_nameid( nameid );
  15160. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15161. }
  15162. /// Book Reading (ZC_READ_BOOK).
  15163. /// 0294 <book id>.L <page>.L
  15164. void clif_readbook(int fd, int book_id, int page)
  15165. {
  15166. WFIFOHEAD(fd,packet_len(0x294));
  15167. WFIFOW(fd,0) = 0x294;
  15168. WFIFOL(fd,2) = book_id;
  15169. WFIFOL(fd,6) = page;
  15170. WFIFOSET(fd,packet_len(0x294));
  15171. }
  15172. /// Battlegrounds
  15173. ///
  15174. /// Updates HP bar of a camp member.
  15175. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15176. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15177. void clif_bg_hp(struct map_session_data *sd) {
  15178. #if PACKETVER < 20140613
  15179. unsigned char buf[34];
  15180. const int cmd = 0x2e0;
  15181. #else
  15182. unsigned char buf[14];
  15183. const int cmd = 0xa0e;
  15184. #endif
  15185. nullpo_retv(sd);
  15186. WBUFW(buf,0) = cmd;
  15187. WBUFL(buf,2) = sd->status.account_id;
  15188. #if PACKETVER < 20140613
  15189. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15190. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15191. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15192. WBUFW(buf,32) = 100;
  15193. } else {
  15194. WBUFW(buf,30) = sd->battle_status.hp;
  15195. WBUFW(buf,32) = sd->battle_status.max_hp;
  15196. }
  15197. #else
  15198. if( sd->battle_status.max_hp > INT32_MAX ) {
  15199. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15200. WBUFL(buf,10) = 100;
  15201. } else {
  15202. WBUFL(buf,6) = sd->battle_status.hp;
  15203. WBUFL(buf,10) = sd->battle_status.max_hp;
  15204. }
  15205. #endif
  15206. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15207. }
  15208. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15209. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15210. void clif_bg_xy(struct map_session_data *sd)
  15211. {
  15212. unsigned char buf[36];
  15213. nullpo_retv(sd);
  15214. WBUFW(buf,0)=0x2df;
  15215. WBUFL(buf,2)=sd->status.account_id;
  15216. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15217. WBUFW(buf,30)=sd->status.class_;
  15218. WBUFW(buf,32)=sd->bl.x;
  15219. WBUFW(buf,34)=sd->bl.y;
  15220. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15221. }
  15222. void clif_bg_xy_remove(struct map_session_data *sd)
  15223. {
  15224. unsigned char buf[36];
  15225. nullpo_retv(sd);
  15226. WBUFW(buf,0)=0x2df;
  15227. WBUFL(buf,2)=sd->status.account_id;
  15228. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15229. WBUFW(buf,30)=0;
  15230. WBUFW(buf,32)=-1;
  15231. WBUFW(buf,34)=-1;
  15232. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15233. }
  15234. /// Notifies clients of a battleground message.
  15235. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15236. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15237. struct map_session_data *sd = bg_getavailablesd( bg );
  15238. if( sd == nullptr ){
  15239. return;
  15240. }
  15241. // limit length
  15242. len = min( len + 1, CHAT_SIZE_MAX );
  15243. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15244. WBUFW(buf,0) = 0x2dc;
  15245. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15246. WBUFL(buf,4) = src_id;
  15247. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15248. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15249. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15250. }
  15251. /// Validates and processes battlechat messages.
  15252. /// All messages that are sent after enabling battleground chat with /battlechat.
  15253. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15254. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  15255. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15256. if( !clif_process_message( sd, false, name, message, output ) )
  15257. return;
  15258. bg_send_message(sd, output, strlen(output) );
  15259. }
  15260. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15261. /// 02de <camp A points>.W <camp B points>.W
  15262. void clif_bg_updatescore(int16 m)
  15263. {
  15264. struct block_list bl;
  15265. unsigned char buf[6];
  15266. struct map_data *mapdata = map_getmapdata(m);
  15267. bl.id = 0;
  15268. bl.type = BL_NUL;
  15269. bl.m = m;
  15270. WBUFW(buf,0) = 0x2de;
  15271. WBUFW(buf,2) = mapdata->bgscore_lion;
  15272. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15273. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15274. }
  15275. void clif_bg_updatescore_single(struct map_session_data *sd)
  15276. {
  15277. int fd;
  15278. nullpo_retv(sd);
  15279. fd = sd->fd;
  15280. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15281. WFIFOHEAD(fd,packet_len(0x2de));
  15282. WFIFOW(fd,0) = 0x2de;
  15283. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15284. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15285. WFIFOSET(fd,packet_len(0x2de));
  15286. }
  15287. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15288. /// 02dd <account id>.L <name>.24B <camp>.W
  15289. void clif_sendbgemblem_area(struct map_session_data *sd)
  15290. {
  15291. unsigned char buf[33];
  15292. nullpo_retv(sd);
  15293. WBUFW(buf, 0) = 0x2dd;
  15294. WBUFL(buf,2) = sd->bl.id;
  15295. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15296. WBUFW(buf,30) = sd->bg_id;
  15297. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15298. }
  15299. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15300. {
  15301. nullpo_retv(sd);
  15302. WFIFOHEAD(fd,32);
  15303. WFIFOW(fd,0) = 0x2dd;
  15304. WFIFOL(fd,2) = sd->bl.id;
  15305. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15306. WFIFOW(fd,30) = sd->bg_id;
  15307. WFIFOSET(fd,packet_len(0x2dd));
  15308. }
  15309. /// Battlegrounds queue incoming apply request from client.
  15310. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15311. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15312. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15313. {
  15314. if (!battle_config.feature_bgqueue)
  15315. return;
  15316. nullpo_retv(sd);
  15317. short type = RFIFOW(fd,2);
  15318. char name[NAME_LENGTH];
  15319. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15320. if (sd->bg_queue_id > 0) {
  15321. //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);
  15322. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15323. return;
  15324. } else if (type == 1) // Solo
  15325. bg_queue_join_solo(name, sd);
  15326. else if (type == 2) // Party
  15327. bg_queue_join_party(name, sd);
  15328. else if (type == 4) // Guild
  15329. bg_queue_join_guild(name, sd);
  15330. else {
  15331. 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);
  15332. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15333. return;
  15334. }
  15335. }
  15336. /// Outgoing battlegrounds queue apply result.
  15337. /// Result types: @see e_bg_queue_apply_ack
  15338. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15339. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15340. {
  15341. nullpo_retv(sd);
  15342. int fd = sd->fd;
  15343. WFIFOHEAD(fd, packet_len(0x8d8));
  15344. WFIFOW(fd,0) = 0x8d8;
  15345. WFIFOB(fd,2) = result;
  15346. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15347. WFIFOSET(fd, packet_len(0x8d8));
  15348. }
  15349. /// Outgoing battlegrounds queue apply notification.
  15350. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15351. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15352. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15353. {
  15354. nullpo_retv(sd);
  15355. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15356. if (queue == nullptr) {
  15357. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15358. return;
  15359. }
  15360. int fd = sd->fd;
  15361. WFIFOHEAD(fd, packet_len(0x8d9));
  15362. WFIFOW(fd,0) = 0x8d9;
  15363. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15364. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15365. WFIFOSET(fd, packet_len(0x8d9));
  15366. }
  15367. /// Battlegrounds queue outgoing cancel result.
  15368. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15369. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15370. {
  15371. nullpo_retv(sd);
  15372. int fd = sd->fd;
  15373. WFIFOHEAD(fd, packet_len(0x8d8));
  15374. WFIFOW(fd,0) = 0x8db;
  15375. WFIFOB(fd,2) = success;
  15376. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15377. WFIFOSET(fd, packet_len(0x8d8));
  15378. }
  15379. /// Battlegrounds queue incoming cancel request from client.
  15380. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15381. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15382. {
  15383. if (!battle_config.feature_bgqueue)
  15384. return;
  15385. nullpo_retv(sd);
  15386. bool success;
  15387. if (sd->bg_queue_id > 0) {
  15388. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15389. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15390. 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.
  15391. else
  15392. success = bg_queue_leave(sd);
  15393. } else {
  15394. 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);
  15395. success = false;
  15396. }
  15397. char name[NAME_LENGTH];
  15398. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15399. clif_bg_queue_cancel_result(success, name, sd);
  15400. }
  15401. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15402. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15403. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15404. {
  15405. nullpo_retv(sd);
  15406. int fd = sd->fd;
  15407. WFIFOHEAD(fd, packet_len(0x8df));
  15408. WFIFOW(fd,0) = 0x8df;
  15409. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15410. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15411. WFIFOSET(fd, packet_len(0x8df));
  15412. }
  15413. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15414. /// Result types: 1(Accept), 2(Decline).
  15415. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15416. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15417. {
  15418. nullpo_retv(sd);
  15419. if(sd->bg_queue_id > 0) {
  15420. uint8 result = RFIFOB(fd, 2);
  15421. if(result == 1) { // Accept
  15422. bg_queue_on_accept_invite(sd);
  15423. } else if(result == 2) { // Decline
  15424. bg_queue_leave(sd);
  15425. clif_bg_queue_entry_init(sd);
  15426. }
  15427. }
  15428. }
  15429. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15430. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15431. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15432. {
  15433. nullpo_retv(sd);
  15434. int fd = sd->fd;
  15435. WFIFOHEAD(fd, packet_len(0x8e1));
  15436. WFIFOW(fd,0) = 0x8e1;
  15437. WFIFOB(fd,2) = result;
  15438. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15439. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15440. WFIFOSET(fd, packet_len(0x8e1));
  15441. }
  15442. /// Battlegrounds queue incoming queue number request from client.
  15443. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15444. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15445. {
  15446. nullpo_retv(sd);
  15447. char name[NAME_LENGTH];
  15448. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15449. clif_bg_queue_apply_notify(name, sd);
  15450. }
  15451. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15452. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15453. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15454. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15455. {
  15456. nullpo_retv(sd);
  15457. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15458. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15459. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15460. }
  15461. /// Custom Fonts (ZC_NOTIFY_FONT).
  15462. /// 02ef <account_id>.L <font id>.W
  15463. void clif_font(struct map_session_data *sd)
  15464. {
  15465. #if PACKETVER >= 20080102
  15466. unsigned char buf[8];
  15467. nullpo_retv(sd);
  15468. WBUFW(buf,0) = 0x2ef;
  15469. WBUFL(buf,2) = sd->bl.id;
  15470. WBUFW(buf,6) = sd->status.font;
  15471. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15472. #endif
  15473. }
  15474. /// Required to start the instancing information window on Client
  15475. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15476. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15477. void clif_instance_create(int instance_id, int num)
  15478. {
  15479. #if PACKETVER >= 20071128
  15480. struct map_session_data *sd = NULL;
  15481. enum send_target target = PARTY;
  15482. unsigned char buf[65];
  15483. instance_getsd(instance_id, sd, &target);
  15484. if (!sd)
  15485. return;
  15486. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15487. if (!db)
  15488. return;
  15489. WBUFW(buf,0) = 0x2cb;
  15490. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15491. WBUFW(buf,63) = num;
  15492. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15493. #endif
  15494. return;
  15495. }
  15496. /// To announce Instancing queue creation if no maps available
  15497. /// S 0x2cc <Standby Position>.W
  15498. void clif_instance_changewait(int instance_id, int num)
  15499. {
  15500. #if PACKETVER >= 20071128
  15501. struct map_session_data *sd = NULL;
  15502. enum send_target target = PARTY;
  15503. unsigned char buf[4];
  15504. instance_getsd(instance_id, sd, &target);
  15505. if (!sd)
  15506. return;
  15507. WBUFW(buf,0) = 0x2cc;
  15508. WBUFW(buf,2) = num;
  15509. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15510. #endif
  15511. return;
  15512. }
  15513. /// Notify the current status to members
  15514. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15515. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15516. {
  15517. #if PACKETVER >= 20071128
  15518. struct map_session_data *sd = NULL;
  15519. enum send_target target = PARTY;
  15520. unsigned char buf[71];
  15521. instance_getsd(instance_id, sd, &target);
  15522. if (!sd)
  15523. return;
  15524. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15525. if (!db)
  15526. return;
  15527. WBUFW(buf,0) = 0x2cd;
  15528. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15529. WBUFL(buf,63) = limit1;
  15530. WBUFL(buf,67) = limit2;
  15531. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15532. #endif
  15533. return;
  15534. }
  15535. /// Notify a status change to members
  15536. /// S 0x2ce <Message ID>.L
  15537. /// 0 = Notification (EnterLimitDate update?)
  15538. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15539. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15540. /// 3 = The Memorial Dungeon has been removed.
  15541. /// 4 = Create failure (removes the instance window)
  15542. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15543. {
  15544. #if PACKETVER >= 20071128
  15545. struct map_session_data *sd = NULL;
  15546. enum send_target target = PARTY;
  15547. unsigned char buf[10];
  15548. instance_getsd(instance_id, sd, &target);
  15549. if (!sd)
  15550. return;
  15551. WBUFW(buf,0) = 0x2ce;
  15552. WBUFL(buf,2) = type;
  15553. WBUFL(buf,6) = limit;
  15554. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15555. #endif
  15556. return;
  15557. }
  15558. /// Destroy an instance from the status window
  15559. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15560. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15561. {
  15562. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15563. return;
  15564. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15565. switch (p->command) {
  15566. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15567. instance_destroy_command(sd);
  15568. break;
  15569. }
  15570. }
  15571. void clif_instance_info( struct map_session_data& sd ){
  15572. if( sd.instance_id > 0 ){
  15573. instance_reqinfo( &sd, sd.instance_id );
  15574. }
  15575. if( sd.status.party_id > 0 ){
  15576. struct party_data* p = party_search( sd.status.party_id );
  15577. if( p != nullptr && p->instance_id > 0 ){
  15578. instance_reqinfo( &sd, p->instance_id );
  15579. }
  15580. }
  15581. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15582. instance_reqinfo( &sd, sd.guild->instance_id );
  15583. }
  15584. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15585. instance_reqinfo( &sd, sd.clan->instance_id );
  15586. }
  15587. }
  15588. /// Notifies clients about item picked up by a party member.
  15589. /// 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)
  15590. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15591. #if PACKETVER >= 20071002
  15592. nullpo_retv( sd );
  15593. nullpo_retv( item_data );
  15594. struct item_data* id = itemdb_search( item_data->nameid );
  15595. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15596. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15597. p.AID = sd->status.account_id;
  15598. p.itemId = client_nameid( item_data->nameid );
  15599. p.identified = item_data->identify;
  15600. p.damaged = item_data->attribute;
  15601. p.refine = item_data->refine;
  15602. clif_addcards( &p.slot, item_data );
  15603. p.location = id->equip; // equip location
  15604. p.itemType = itemtype( id->nameid ); // item type
  15605. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15606. p.grade = item_data->enchantgrade;
  15607. #endif
  15608. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15609. #endif
  15610. }
  15611. /** Display gained exp.
  15612. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15613. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15614. * amount: INT32_MIN ~ INT32_MAX
  15615. * var id:
  15616. * SP_BASEEXP, SP_JOBEXP
  15617. * exp type:
  15618. * 0 = normal exp gained/lost
  15619. * 1 = quest exp gained/lost
  15620. * @param sd Player
  15621. * @param exp EXP value gained/loss
  15622. * @param type SP_BASEEXP, SP_JOBEXP
  15623. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15624. * @param lost True:if losing EXP
  15625. */
  15626. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15627. {
  15628. int fd;
  15629. int offset;
  15630. #if PACKETVER >= 20170830
  15631. int cmd = 0xacc;
  15632. #else
  15633. int cmd = 0x7f6;
  15634. #endif
  15635. nullpo_retv(sd);
  15636. fd = sd->fd;
  15637. WFIFOHEAD(fd, packet_len(cmd));
  15638. WFIFOW(fd,0) = cmd;
  15639. WFIFOL(fd,2) = sd->bl.id;
  15640. #if PACKETVER >= 20170830
  15641. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15642. offset = 4;
  15643. #else
  15644. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15645. offset = 0;
  15646. #endif
  15647. WFIFOW(fd,10+offset) = type;
  15648. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15649. WFIFOSET(fd,packet_len(cmd));
  15650. }
  15651. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15652. /// type:
  15653. /// 0 = Displays 'value' for 5 seconds.
  15654. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15655. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15656. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15657. /// value:
  15658. /// 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).
  15659. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15660. {
  15661. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15662. WFIFOW(sd->fd,0) = 0x1b1;
  15663. WFIFOB(sd->fd,2) = type;
  15664. WFIFOL(sd->fd,3) = value;
  15665. WFIFOSET(sd->fd, packet_len(0x1b1));
  15666. }
  15667. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15668. /// 021d <state>.L
  15669. /// state:
  15670. /// 0 = Full effects
  15671. /// 1 = Reduced effects
  15672. ///
  15673. /// NOTE: The state is used on Aegis for sending skill unit packet
  15674. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15675. /// whenever possible. Due to the way the decision check is
  15676. /// constructed, this state tracking was rendered useless,
  15677. /// as the only skill unit, that is sent with 0x1c9 is
  15678. /// Graffiti.
  15679. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15680. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15681. sd->state.lesseffect = ( isLess != 0 );
  15682. }
  15683. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15684. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15685. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15686. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15687. int type = RFIFOL(fd,info->pos[1]);
  15688. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15689. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15690. if( sd->state.trading || sd->npc_shopid )
  15691. return;
  15692. if( flag == 0 || n == 0) {
  15693. clif_menuskill_clear(sd);
  15694. return; // Canceled by player.
  15695. }
  15696. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15697. clif_menuskill_clear(sd);
  15698. return; // Prevent hacking.
  15699. }
  15700. switch( type ) {
  15701. case 0: // Change Material
  15702. skill_changematerial(sd,n,item_list);
  15703. break;
  15704. case 1: // Level 1: Pure to Rough
  15705. case 2: // Level 2: Rough to Pure
  15706. skill_elementalanalysis(sd,n,type,item_list);
  15707. break;
  15708. }
  15709. clif_menuskill_clear(sd);
  15710. return;
  15711. }
  15712. /*==========================================
  15713. * Elemental System
  15714. *==========================================*/
  15715. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15716. s_elemental_data *ed;
  15717. struct status_data *status;
  15718. int fd;
  15719. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15720. return;
  15721. fd = sd->fd;
  15722. status = &ed->battle_status;
  15723. WFIFOHEAD(fd,8);
  15724. WFIFOW(fd,0) = 0x81e;
  15725. WFIFOW(fd,2) = type;
  15726. switch( type ) {
  15727. case SP_HP:
  15728. WFIFOL(fd,4) = status->hp;
  15729. break;
  15730. case SP_MAXHP:
  15731. WFIFOL(fd,4) = status->max_hp;
  15732. break;
  15733. case SP_SP:
  15734. WFIFOL(fd,4) = status->sp;
  15735. break;
  15736. case SP_MAXSP:
  15737. WFIFOL(fd,4) = status->max_sp;
  15738. break;
  15739. }
  15740. WFIFOSET(fd,8);
  15741. }
  15742. void clif_elemental_info(struct map_session_data *sd) {
  15743. int fd;
  15744. s_elemental_data *ed;
  15745. struct status_data *status;
  15746. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15747. return;
  15748. fd = sd->fd;
  15749. status = &ed->battle_status;
  15750. WFIFOHEAD(fd,22);
  15751. WFIFOW(fd, 0) = 0x81d;
  15752. WFIFOL(fd, 2) = ed->bl.id;
  15753. WFIFOL(fd, 6) = status->hp;
  15754. WFIFOL(fd,10) = status->max_hp;
  15755. WFIFOL(fd,14) = status->sp;
  15756. WFIFOL(fd,18) = status->max_sp;
  15757. WFIFOSET(fd,22);
  15758. }
  15759. /// Buying Store System
  15760. ///
  15761. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15762. /// 0810 <slots>.B
  15763. void clif_buyingstore_open(struct map_session_data* sd)
  15764. {
  15765. int fd = sd->fd;
  15766. WFIFOHEAD(fd,packet_len(0x810));
  15767. WFIFOW(fd,0) = 0x810;
  15768. WFIFOB(fd,2) = sd->buyingstore.slots;
  15769. WFIFOSET(fd,packet_len(0x810));
  15770. }
  15771. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15772. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15773. /// result:
  15774. /// 0 = cancel
  15775. /// 1 = open
  15776. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15777. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15778. // TODO: Make this check global for all variable length packets.
  15779. // minimum packet length
  15780. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15781. 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 );
  15782. return;
  15783. }
  15784. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15785. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15786. return;
  15787. }
  15788. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15789. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15790. return;
  15791. }
  15792. char storename[MESSAGE_SIZE];
  15793. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15794. // so that buyingstore_create knows, how many elements it has access to
  15795. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15796. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15797. 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 ) );
  15798. return;
  15799. }
  15800. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15801. }
  15802. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15803. /// 0812 <result>.W <total weight>.L
  15804. /// result:
  15805. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15806. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15807. /// 8 = "No sale (purchase) information available." (0x705)
  15808. /// ? = nothing
  15809. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15810. {
  15811. int fd = sd->fd;
  15812. WFIFOHEAD(fd,packet_len(0x812));
  15813. WFIFOW(fd,0) = 0x812;
  15814. WFIFOW(fd,2) = result;
  15815. WFIFOL(fd,4) = weight;
  15816. WFIFOSET(fd,packet_len(0x812));
  15817. }
  15818. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15819. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15820. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15821. nullpo_retv( sd );
  15822. int fd = sd->fd;
  15823. if( !session_isActive( fd ) ){
  15824. return;
  15825. }
  15826. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15827. WFIFOHEAD( fd, length );
  15828. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15829. p->packetType = 0x813;
  15830. p->packetLength = length;
  15831. p->AID = sd->bl.id;
  15832. p->zenyLimit = sd->buyingstore.zenylimit;
  15833. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15834. p->items[i].price = sd->buyingstore.items[i].price;
  15835. p->items[i].amount = sd->buyingstore.items[i].amount;
  15836. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15837. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15838. }
  15839. WFIFOSET( fd, p->packetLength );
  15840. }
  15841. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15842. /// 0814 <account id>.L <store name>.80B
  15843. void clif_buyingstore_entry( struct map_session_data& sd, struct block_list* tbl ){
  15844. #if PACKETVER >= 20100420
  15845. enum send_target target;
  15846. if( tbl == nullptr ){
  15847. tbl = &sd.bl;
  15848. target = AREA_WOS;
  15849. }else{
  15850. target = SELF;
  15851. }
  15852. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15853. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15854. p.makerAID = sd.status.account_id;
  15855. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15856. clif_send( &p, sizeof( p ), tbl, target );
  15857. #endif
  15858. }
  15859. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15860. /// 0815
  15861. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15862. {
  15863. buyingstore_close(sd);
  15864. }
  15865. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15866. /// 0816 <account id>.L
  15867. void clif_buyingstore_disappear_entry( struct map_session_data& sd, struct block_list* tbl ){
  15868. #if PACKETVER >= 20100309
  15869. enum send_target target;
  15870. if( tbl == nullptr ){
  15871. tbl = &sd.bl;
  15872. target = AREA_WOS;
  15873. }else{
  15874. target = SELF;
  15875. }
  15876. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15877. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15878. p.makerAID = sd.status.account_id;
  15879. clif_send( &p, sizeof( p ), tbl, target );
  15880. #endif
  15881. }
  15882. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15883. /// 0817 <account id>.L
  15884. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15885. {
  15886. uint32 account_id;
  15887. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15888. buyingstore_open(sd, account_id);
  15889. }
  15890. /// Sends buying store item list.
  15891. /// 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)
  15892. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15893. nullpo_retv( sd );
  15894. nullpo_retv( pl_sd );
  15895. int fd = sd->fd;
  15896. if( !session_isActive( fd ) ){
  15897. return;
  15898. }
  15899. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15900. WFIFOHEAD( fd, length );
  15901. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15902. p->packetType = 0x818;
  15903. p->packetLength = length;
  15904. p->AID = pl_sd->bl.id;
  15905. p->storeId = pl_sd->buyer_id;
  15906. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15907. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15908. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15909. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15910. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15911. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15912. }
  15913. WFIFOSET( fd, p->packetLength );
  15914. }
  15915. /// Request to sell items to a buying store.
  15916. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15917. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15918. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15919. // minimum packet length
  15920. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15921. 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 );
  15922. return;
  15923. }
  15924. // so that buyingstore_trade knows, how many elements it has access to
  15925. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15926. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15927. 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 ) );
  15928. return;
  15929. }
  15930. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15931. }
  15932. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15933. /// 081a <result>.W
  15934. /// result:
  15935. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15936. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15937. /// ? = nothing
  15938. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15939. {
  15940. int fd = sd->fd;
  15941. WFIFOHEAD(fd,packet_len(0x81a));
  15942. WFIFOW(fd,0) = 0x81a;
  15943. WFIFOW(fd,2) = result;
  15944. WFIFOSET(fd,packet_len(0x81a));
  15945. }
  15946. /// Updates the zeny limit and an item in the buying store item list.
  15947. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15948. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15949. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15950. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15951. p.packetType = buyingStoreUpdateItemType;
  15952. p.itemId = client_nameid( nameid );
  15953. p.amount = amount;
  15954. p.zenyLimit = sd->buyingstore.zenylimit;
  15955. #if PACKETVER >= 20141016
  15956. p.zeny = zeny;
  15957. p.charId = char_id; // GID
  15958. p.updateTime = (int)time(NULL);
  15959. #endif
  15960. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15961. }
  15962. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15963. /// 081c <index>.W <amount>.W <price>.L
  15964. /// message:
  15965. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15966. ///
  15967. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15968. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15969. {
  15970. int fd = sd->fd;
  15971. WFIFOHEAD(fd,packet_len(0x81c));
  15972. WFIFOW(fd,0) = 0x81c;
  15973. WFIFOW(fd,2) = client_index( index );
  15974. WFIFOW(fd,4) = amount;
  15975. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15976. WFIFOSET(fd,packet_len(0x81c));
  15977. }
  15978. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15979. /// 0824 <result>.W <name id>.W
  15980. /// result:
  15981. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15982. /// 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)
  15983. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15984. /// ? = nothing
  15985. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  15986. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15987. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15988. p.result = result;
  15989. p.itemId = client_nameid( nameid );
  15990. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15991. }
  15992. /// Search Store Info System
  15993. ///
  15994. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15995. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15996. /// type:
  15997. /// 0 = Vending
  15998. /// 1 = Buying Store
  15999. ///
  16000. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16001. /// amount of card slots. If the client does not know about the item it
  16002. /// cannot be searched.
  16003. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  16004. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16005. // minimum packet length
  16006. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16007. 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 );
  16008. return;
  16009. }
  16010. // check, if there is enough data for the claimed count of items
  16011. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16012. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16013. 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 ) );
  16014. return;
  16015. }
  16016. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16017. if( count < p->itemsCount + p->cardsCount ){
  16018. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16019. return;
  16020. }
  16021. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16022. }
  16023. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16024. /// 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 }*
  16025. /// is first page:
  16026. /// 0 = appends to existing results
  16027. /// 1 = clears previous results before displaying this result set
  16028. /// is next page:
  16029. /// 0 = no "next" label
  16030. /// 1 = "next" label to retrieve more results
  16031. void clif_search_store_info_ack( struct map_session_data* sd ){
  16032. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  16033. nullpo_retv( sd );
  16034. int fd = sd->fd;
  16035. if( !session_isActive( fd ) ){
  16036. return;
  16037. }
  16038. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16039. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16040. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16041. WFIFOHEAD( fd, len );
  16042. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16043. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16044. p->packetLength = len;
  16045. p->firstPage = !sd->searchstore.pages;
  16046. p->nextPage = searchstore_querynext( sd );
  16047. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16048. for( int i = 0; i < end - start; i++ ) {
  16049. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16050. p->items[i].storeId = ssitem->store_id;
  16051. p->items[i].AID = ssitem->account_id;
  16052. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16053. p->items[i].itemId = client_nameid( ssitem->nameid );
  16054. p->items[i].itemType = itemtype( ssitem->nameid );
  16055. p->items[i].price = ssitem->price;
  16056. p->items[i].amount = ssitem->amount;
  16057. p->items[i].refine = ssitem->refine;
  16058. // make-up an item for clif_addcards
  16059. struct item it = {};
  16060. for( int j = 0; j < MAX_SLOTS; j++ ){
  16061. it.card[j] = ssitem->card[j];
  16062. }
  16063. it.nameid = ssitem->nameid;
  16064. it.amount = ssitem->amount;
  16065. clif_addcards( &p->items[i].slot, &it );
  16066. #if PACKETVER >= 20150226
  16067. clif_add_random_options( p->items[i].option_data, &it );
  16068. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16069. p->items[i].grade = ssitem->enchantgrade;
  16070. #endif
  16071. #endif
  16072. }
  16073. WFIFOSET( fd, len );
  16074. #endif
  16075. }
  16076. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16077. /// 0837 <reason>.B
  16078. /// reason:
  16079. /// 0 = "No matching stores were found." (0x70b)
  16080. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16081. /// 2 = "You cannot search anymore." (0x706)
  16082. /// 3 = "You cannot search yet." (0x708)
  16083. /// 4 = "No sale (purchase) information available." (0x705)
  16084. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  16085. {
  16086. int fd = sd->fd;
  16087. WFIFOHEAD(fd,packet_len(0x837));
  16088. WFIFOW(fd,0) = 0x837;
  16089. WFIFOB(fd,2) = reason;
  16090. WFIFOSET(fd,packet_len(0x837));
  16091. }
  16092. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16093. /// 0838
  16094. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  16095. {
  16096. searchstore_next(sd);
  16097. }
  16098. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16099. /// 083a <type>.W <remaining uses>.B
  16100. /// type:
  16101. /// 0 = Search Stores
  16102. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16103. void clif_open_search_store_info(struct map_session_data* sd)
  16104. {
  16105. int fd = sd->fd;
  16106. WFIFOHEAD(fd,packet_len(0x83a));
  16107. WFIFOW(fd,0) = 0x83a;
  16108. WFIFOW(fd,2) = sd->searchstore.effect;
  16109. #if PACKETVER > 20100701
  16110. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16111. #endif
  16112. WFIFOSET(fd,packet_len(0x83a));
  16113. }
  16114. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16115. /// 083b
  16116. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  16117. {
  16118. searchstore_close(sd);
  16119. }
  16120. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16121. /// 083c <account id>.L <store id>.L <nameid>.W
  16122. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  16123. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16124. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16125. }
  16126. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16127. /// 083d <xPos>.W <yPos>.W
  16128. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  16129. {
  16130. int fd = sd->fd;
  16131. WFIFOHEAD(fd,packet_len(0x83d));
  16132. WFIFOW(fd,0) = 0x83d;
  16133. WFIFOW(fd,2) = x;
  16134. WFIFOW(fd,4) = y;
  16135. WFIFOSET(fd,packet_len(0x83d));
  16136. }
  16137. /// Parse function for packet debugging.
  16138. void clif_parse_debug(int fd,struct map_session_data *sd)
  16139. {
  16140. int cmd, packet_len;
  16141. // clif_parse ensures, that there is at least 2 bytes of data
  16142. cmd = RFIFOW(fd,0);
  16143. if( sd ) {
  16144. packet_len = packet_db[cmd].len;
  16145. if( packet_len == 0 )
  16146. {// unknown
  16147. packet_len = RFIFOREST(fd);
  16148. }
  16149. else if( packet_len == -1 )
  16150. {// variable length
  16151. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16152. }
  16153. 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);
  16154. }
  16155. else
  16156. {
  16157. packet_len = RFIFOREST(fd);
  16158. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16159. }
  16160. ShowDump(RFIFOP(fd,0), packet_len);
  16161. }
  16162. /*==========================================
  16163. * Server tells client to display a window similar to Magnifier (item) one
  16164. * Server populates the window with avilable elemental converter options according to player's inventory
  16165. *------------------------------------------*/
  16166. void clif_elementalconverter_list( struct map_session_data *sd ){
  16167. nullpo_retv( sd );
  16168. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16169. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16170. int count = 0;
  16171. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16172. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16173. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16174. count++;
  16175. }
  16176. }
  16177. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16178. clif_send( p, p->packetLength, &sd->bl, SELF );
  16179. if( count > 0 ){
  16180. sd->menuskill_id = SA_CREATECON;
  16181. sd->menuskill_val = count;
  16182. }
  16183. }
  16184. /**
  16185. * Rune Knight
  16186. **/
  16187. void clif_millenniumshield(struct block_list *bl, short shields) {
  16188. #if PACKETVER >= 20081217
  16189. unsigned char buf[10];
  16190. WBUFW(buf,0) = 0x440;
  16191. WBUFL(buf,2) = bl->id;
  16192. WBUFW(buf,6) = shields;
  16193. WBUFW(buf,8) = 0;
  16194. clif_send(buf,packet_len(0x440),bl,AREA);
  16195. #endif
  16196. }
  16197. /**
  16198. * Mechanic
  16199. **/
  16200. /*==========================================
  16201. * Magic Decoy Material List
  16202. *------------------------------------------*/
  16203. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  16204. nullpo_retv( sd );
  16205. int fd = sd->fd;
  16206. if( !session_isActive( fd ) ){
  16207. return;
  16208. }
  16209. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16210. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16211. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16212. int count = 0;
  16213. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16214. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16215. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16216. count++;
  16217. }
  16218. }
  16219. if( count > 0 ) {
  16220. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16221. WFIFOSET( fd, p->packetLength );
  16222. sd->menuskill_id = NC_MAGICDECOY;
  16223. sd->menuskill_val = skill_lv;
  16224. sd->sc.comet_x = x;
  16225. sd->sc.comet_y = y;
  16226. }else{
  16227. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16228. }
  16229. }
  16230. /*==========================================
  16231. * Guillotine Cross Poisons List
  16232. *------------------------------------------*/
  16233. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16234. nullpo_retv( sd );
  16235. int fd = sd->fd;
  16236. if( !session_isActive( fd ) ){
  16237. return;
  16238. }
  16239. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16240. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16241. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16242. int count = 0;
  16243. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16244. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16245. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16246. count++;
  16247. }
  16248. }
  16249. if( count > 0 ){
  16250. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16251. WFIFOSET( fd, p->packetLength );
  16252. sd->menuskill_id = GC_POISONINGWEAPON;
  16253. sd->menuskill_val = skill_lv;
  16254. }else{
  16255. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16256. }
  16257. }
  16258. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16259. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16260. int fd, i, c;
  16261. nullpo_ret(sd);
  16262. fd = sd->fd;
  16263. if( !session_isActive(fd) )
  16264. return 0;
  16265. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16266. return 0;
  16267. WFIFOHEAD(fd, 2 * 6 + 4);
  16268. WFIFOW(fd,0) = 0x442;
  16269. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16270. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16271. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16272. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16273. {
  16274. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16275. c++;
  16276. }
  16277. if( c > 0 ) {
  16278. WFIFOW(fd,2) = 8 + c * 2;
  16279. WFIFOL(fd,4) = c;
  16280. WFIFOSET(fd,WFIFOW(fd,2));
  16281. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16282. sd->menuskill_val = c;
  16283. } else {
  16284. status_change_end(&sd->bl,SC_STOP);
  16285. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16286. }
  16287. return 1;
  16288. }
  16289. /*===========================================
  16290. * Skill list for Four Elemental Analysis
  16291. * and Change Material skills.
  16292. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16293. *------------------------------------------*/
  16294. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16295. #if PACKETVER >= 20090922
  16296. int fd = sd->fd;
  16297. nullpo_ret(sd);
  16298. sd->menuskill_id = skill_id; // To prevent hacking.
  16299. sd->menuskill_val = skill_lv;
  16300. if( skill_id == GN_CHANGEMATERIAL )
  16301. skill_lv = 0; // Changematerial
  16302. WFIFOHEAD(fd, packet_len(0x7e3));
  16303. WFIFOW(fd,0) = 0x7e3;
  16304. WFIFOL(fd,2) = skill_lv;
  16305. WFIFOL(fd,4) = 0;
  16306. WFIFOSET(fd, packet_len(0x7e3));
  16307. #endif
  16308. return 1;
  16309. }
  16310. /*==========================================
  16311. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16312. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16313. * RFIFOL(fd,2) - type (currently not used)
  16314. *------------------------------------------*/
  16315. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16316. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16317. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16318. if (sd->menuskill_id == SA_AUTOSPELL) {
  16319. sd->state.workinprogress = WIP_DISABLE_NONE;
  16320. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16321. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16322. if (pc_istrading(sd)) {
  16323. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16324. clif_menuskill_clear(sd);
  16325. return;
  16326. }
  16327. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16328. } else
  16329. return;
  16330. clif_menuskill_clear(sd);
  16331. }
  16332. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16333. /// 08cf <id>.L <type>.W <num>.W
  16334. void clif_spiritcharm(struct map_session_data *sd) {
  16335. unsigned char buf[10];
  16336. nullpo_retv(sd);
  16337. WBUFW(buf,0) = 0x08cf;
  16338. WBUFL(buf,2) = sd->bl.id;
  16339. WBUFW(buf,6) = sd->spiritcharm_type;
  16340. WBUFW(buf,8) = sd->spiritcharm;
  16341. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16342. }
  16343. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16344. /// 0907 <index>.W
  16345. ///
  16346. /// R 0908 <index>.w <type>.b
  16347. /// type:
  16348. /// 0 = move item to personal tab
  16349. /// 1 = move item to normal tab
  16350. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16351. #if PACKETVER >= 20111122
  16352. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16353. int index = RFIFOW(fd,info->pos[0]) - 2;
  16354. int type = RFIFOB(fd, info->pos[1]);
  16355. /* can't move while dead. */
  16356. if(pc_isdead(sd)) {
  16357. return;
  16358. }
  16359. if (index < 0 || index >= MAX_INVENTORY)
  16360. return;
  16361. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16362. sd->inventory.u.items_inventory[index].favorite = 0;
  16363. else if( type == 0 )
  16364. sd->inventory.u.items_inventory[index].favorite = 1;
  16365. else
  16366. return;/* nothing to do. */
  16367. clif_favorite_item(sd, index);
  16368. #endif
  16369. }
  16370. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16371. /// 0900 <index>.W <favorite>.B
  16372. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16373. int fd = sd->fd;
  16374. WFIFOHEAD(fd,packet_len(0x908));
  16375. WFIFOW(fd,0) = 0x908;
  16376. WFIFOW(fd,2) = index+2;
  16377. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16378. WFIFOSET(fd,packet_len(0x908));
  16379. }
  16380. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16381. void clif_snap( struct block_list *bl, short x, short y ) {
  16382. unsigned char buf[10];
  16383. WBUFW(buf,0) = 0x8d2;
  16384. WBUFL(buf,2) = bl->id;
  16385. WBUFW(buf,6) = x;
  16386. WBUFW(buf,8) = y;
  16387. if( disguised(bl) )
  16388. {
  16389. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16390. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16391. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16392. } else
  16393. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16394. }
  16395. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16396. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16397. #if PACKETVER >= 20120404
  16398. WFIFOHEAD(fd,packet_len(0x977));
  16399. WFIFOW(fd,0) = 0x977;
  16400. WFIFOL(fd,2) = md->bl.id;
  16401. WFIFOL(fd,6) = md->status.hp;
  16402. WFIFOL(fd,10) = md->status.max_hp;
  16403. WFIFOSET(fd,packet_len(0x977));
  16404. #endif
  16405. }
  16406. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16407. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16408. return;
  16409. }
  16410. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16411. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16412. WFIFOW(sd->fd,0) = 0x2c9;
  16413. WFIFOB(sd->fd,2) = flag;
  16414. WFIFOSET(sd->fd, packet_len(0x2c9));
  16415. }
  16416. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16417. /// 0979 <world name>.24B <char name>.24B
  16418. void clif_ackworldinfo(struct map_session_data* sd) {
  16419. int fd;
  16420. nullpo_retv(sd);
  16421. fd = sd->fd;
  16422. WFIFOHEAD(fd,packet_len(0x979));
  16423. WFIFOW(fd,0)=0x979;
  16424. //AID -> world name ?
  16425. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16426. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16427. WFIFOSET(fd,packet_len(0x979));
  16428. }
  16429. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16430. /// 0978 <AID>.L
  16431. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16432. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16433. if(sd)
  16434. clif_ackworldinfo(sd);
  16435. }
  16436. static void clif_loadConfirm( struct map_session_data *sd ){
  16437. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16438. nullpo_retv( sd );
  16439. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16440. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16441. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16442. clif_instance_info( *sd );
  16443. #endif
  16444. }
  16445. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16446. /// 0447
  16447. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16448. clif_loadConfirm( sd );
  16449. }
  16450. /// req world info (CZ_CLIENT_VERSION)
  16451. /// 044A <version>.L
  16452. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16453. //if(sd)
  16454. ;
  16455. }
  16456. /// Ranking list
  16457. /// ranking pointlist { <name>.24B <point>.L }*10
  16458. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16459. struct fame_list* list;
  16460. int i, size = MAX_FAME_LIST;
  16461. switch(rankingtype) {
  16462. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16463. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16464. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16465. // PK currently unsupported
  16466. case RANK_KILLER: list = NULL; size = 0; break;
  16467. default:
  16468. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16469. return;
  16470. }
  16471. //Packet size limits this list to 10 elements. [Skotlex]
  16472. for (i = 0; i < min(10,size); i++) {
  16473. if (list[i].id > 0) {
  16474. const char* name;
  16475. if (strcmp(list[i].name, "-") == 0 &&
  16476. (name = map_charid2nick(list[i].id)) != NULL)
  16477. {
  16478. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16479. } else {
  16480. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16481. }
  16482. } else {
  16483. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16484. }
  16485. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16486. }
  16487. for(;i < 10; i++) { //In case the MAX is less than 10.
  16488. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16489. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16490. }
  16491. }
  16492. /// Request for the blacksmith ranklist.
  16493. /// /blacksmith command sends this packet to the server.
  16494. /// 0217 (CZ_BLACKSMITH_RANK)
  16495. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16496. clif_ranklist(sd,RANK_BLACKSMITH);
  16497. }
  16498. /// Request for the alchemist ranklist.
  16499. /// /alchemist command sends this packet to the server.
  16500. /// 0218 (CZ_ALCHEMIST_RANK)
  16501. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16502. clif_ranklist(sd,RANK_ALCHEMIST);
  16503. }
  16504. /// Request for the taekwon ranklist.
  16505. /// /taekwon command sends this packet to the server.
  16506. /// 0225 (CZ_TAEKWON_RANK)
  16507. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16508. clif_ranklist(sd,RANK_TAEKWON);
  16509. }
  16510. /// Request for the killer ranklist.
  16511. /// /pk command sends this packet to the server.
  16512. /// 0237 (CZ_KILLER_RANK)
  16513. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16514. clif_ranklist(sd,RANK_KILLER);
  16515. }
  16516. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16517. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16518. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16519. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16520. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16521. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16522. enum e_rank rank;
  16523. #if PACKETVER < 20130710
  16524. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16525. short cmd;
  16526. switch( rankingType ){
  16527. case RANK_BLACKSMITH: cmd = 0x219; break;
  16528. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16529. case RANK_TAEKWON: cmd = 0x226; break;
  16530. case RANK_KILLER: cmd = 0x238; break;
  16531. default:
  16532. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16533. return;
  16534. }
  16535. // Can be safely casted here, since we validated it before
  16536. rank = (enum e_rank)rankingType;
  16537. WBUFW(buf,0) = cmd;
  16538. clif_sub_ranklist(buf,2,sd,rank);
  16539. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16540. #else
  16541. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16542. int mypoint = 0;
  16543. switch( rankingType ){
  16544. case RANK_BLACKSMITH:
  16545. case RANK_ALCHEMIST:
  16546. case RANK_TAEKWON:
  16547. case RANK_KILLER:
  16548. break;
  16549. default:
  16550. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16551. return;
  16552. }
  16553. // Can be safely casted here, since we validated it before
  16554. rank = (enum e_rank)rankingType;
  16555. WBUFW(buf,0) = 0x97d;
  16556. WBUFW(buf,2) = rank;
  16557. clif_sub_ranklist(buf,4,sd,rank);
  16558. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16559. case MAPID_BLACKSMITH:
  16560. case MAPID_ALCHEMIST:
  16561. case MAPID_TAEKWON:
  16562. mypoint = sd->status.fame;
  16563. }
  16564. WBUFL(buf,284) = mypoint; //mypoint
  16565. clif_send(buf, 288, &sd->bl, SELF);
  16566. #endif
  16567. }
  16568. /*
  16569. * 097c <type> (CZ_REQ_RANKING)
  16570. * type
  16571. * 0: /blacksmith
  16572. * 1: /alchemist
  16573. * 2: /taekwon
  16574. * 3: /pk
  16575. * */
  16576. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16577. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16578. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16579. clif_ranklist(sd,rankingtype);
  16580. }
  16581. /// Updates the fame rank points for the given ranking.
  16582. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16583. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16584. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16585. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16586. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16587. int fd = sd.fd;
  16588. #if PACKETVER < 20130710
  16589. short cmd;
  16590. switch(rankingtype){
  16591. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16592. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16593. case RANK_TAEKWON: cmd = 0x224; break;
  16594. default:
  16595. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16596. return;
  16597. }
  16598. WFIFOHEAD(fd,packet_len(cmd));
  16599. WFIFOW(fd,0) = cmd;
  16600. WFIFOL(fd,2) = point;
  16601. WFIFOL(fd,6) = sd.status.fame;
  16602. WFIFOSET(fd, packet_len(cmd));
  16603. #else
  16604. WFIFOHEAD(fd,packet_len(0x97e));
  16605. WFIFOW(fd,0) = 0x97e;
  16606. WFIFOW(fd,2) = rankingtype;
  16607. WFIFOL(fd,4) = point;
  16608. WFIFOL(fd,8) = sd.status.fame;
  16609. WFIFOSET(fd,packet_len(0x97e));
  16610. #endif
  16611. }
  16612. /**
  16613. * Transmit personal information to player. (rates)
  16614. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16615. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16616. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16617. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16618. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16619. * FIXME!
  16620. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16621. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16622. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16623. */
  16624. #ifdef VIP_ENABLE
  16625. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16626. if (sd) {
  16627. struct s_packet_db* info;
  16628. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16629. int cmd = 0, fd, i = 0;
  16630. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16631. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16632. /**
  16633. * EXP
  16634. */
  16635. //0:PCRoom
  16636. details_bexp[PINFO_BASIC] = map_getmapflag(sd->bl.m, MF_BEXP);
  16637. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16638. details_bexp[PINFO_BASIC] = 0;
  16639. else {
  16640. if (details_bexp[PINFO_BASIC] < 100) {
  16641. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16642. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16643. } else
  16644. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16645. }
  16646. //1:Premium
  16647. if (pc_isvip(sd)) {
  16648. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16649. if (details_bexp[PINFO_PREMIUM] < 0)
  16650. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16651. } else
  16652. details_bexp[PINFO_PREMIUM] = 0;
  16653. //2:Server
  16654. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16655. if (details_bexp[PINFO_SERVER] == 100)
  16656. details_bexp[PINFO_SERVER] = 0;
  16657. else {
  16658. if (details_bexp[PINFO_SERVER] < 100) {
  16659. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16660. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16661. } else
  16662. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16663. }
  16664. //3:TPLUS
  16665. details_bexp[PINFO_CAFE] = 0;
  16666. /**
  16667. * Drop rate
  16668. */
  16669. //0:PCRoom
  16670. details_drop[PINFO_BASIC] = 0;
  16671. //1:Premium
  16672. if (pc_isvip(sd)) {
  16673. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16674. if (details_drop[PINFO_PREMIUM] < 0)
  16675. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16676. } else
  16677. details_drop[PINFO_PREMIUM] = 0;
  16678. //2:Server
  16679. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16680. if (details_drop[PINFO_SERVER] == 100)
  16681. details_drop[PINFO_SERVER] = 0;
  16682. else {
  16683. if (details_drop[PINFO_SERVER] < 100) {
  16684. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16685. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16686. } else
  16687. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16688. }
  16689. //3:TPLUS
  16690. details_drop[PINFO_CAFE] = 0;
  16691. /**
  16692. * Penalty rate
  16693. */
  16694. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16695. //0:PCRoom
  16696. details_penalty[PINFO_BASIC] = 0;
  16697. //1:Premium
  16698. if (pc_isvip(sd)) {
  16699. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16700. if (details_penalty[PINFO_PREMIUM] == 100)
  16701. details_penalty[PINFO_PREMIUM] = 0;
  16702. else {
  16703. if (details_penalty[PINFO_PREMIUM] < 100) {
  16704. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16705. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16706. } else
  16707. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16708. }
  16709. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16710. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16711. } else
  16712. details_penalty[PINFO_PREMIUM] = 0;
  16713. //2:Server
  16714. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16715. if (details_penalty[PINFO_SERVER] == 100)
  16716. details_penalty[PINFO_SERVER] = 0;
  16717. else {
  16718. if (details_penalty[PINFO_SERVER] < 100) {
  16719. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16720. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16721. } else
  16722. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16723. }
  16724. //3:TPLUS
  16725. details_penalty[PINFO_CAFE] = 0;
  16726. cmd = packet_db_ack[cmdtype];
  16727. info = &packet_db[cmd];
  16728. len = info->len; //this is the base len without details
  16729. if(!len) return; //version as packet disable
  16730. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16731. szdetails = 7;
  16732. factor = 1;
  16733. }
  16734. else if (cmd == 0x097b) {
  16735. tot_baseexp *= factor;
  16736. tot_drop *= factor;
  16737. tot_penalty *= factor;
  16738. }
  16739. fd = sd->fd;
  16740. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16741. WFIFOW(fd,0) = cmd;
  16742. for (i = 0; i < maxinfotype; i++) {
  16743. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16744. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16745. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16746. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16747. tot_baseexp += details_bexp[i]*factor;
  16748. tot_drop += details_drop[i]*factor;
  16749. tot_penalty += details_penalty[i]*factor;
  16750. len += szdetails;
  16751. }
  16752. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16753. if (cmd == 0x08cb) { //0x08cb version
  16754. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16755. WFIFOW(fd,info->pos[2]) = tot_penalty;
  16756. WFIFOW(fd,info->pos[3]) = tot_drop;
  16757. }
  16758. else { //2013-08-07aRagexe uses 0x097b
  16759. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16760. WFIFOL(fd,info->pos[2]) = tot_penalty;
  16761. WFIFOL(fd,info->pos[3]) = tot_drop;
  16762. }
  16763. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16764. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16765. WFIFOSET(fd,len);
  16766. }
  16767. }
  16768. #endif
  16769. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16770. char cmd[30];
  16771. int t_aid = RFIFOL(fd,2);
  16772. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16773. is_atcommand(fd, sd, cmd, 1);
  16774. }
  16775. /**
  16776. * Marks Crimson Marker target on mini-map to the caster
  16777. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16778. * @param fd
  16779. * @param bl Crimson Marker target
  16780. **/
  16781. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16782. struct s_packet_db* info;
  16783. int cmd = 0;
  16784. int16 len;
  16785. unsigned char buf[11];
  16786. nullpo_retv(sd);
  16787. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16788. if (!cmd)
  16789. cmd = 0x09C1; //default
  16790. info = &packet_db[cmd];
  16791. if (!(len = info->len))
  16792. return;
  16793. WBUFW(buf, 0) = cmd;
  16794. WBUFL(buf, info->pos[0]) = bl->id;
  16795. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16796. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16797. clif_send(buf, len, &sd->bl, SELF);
  16798. }
  16799. /**
  16800. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16801. **/
  16802. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16803. struct s_packet_db *info = NULL;
  16804. int cmd = 0;
  16805. nullpo_retv(sd);
  16806. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16807. info = &packet_db[cmd];
  16808. if (!cmd || !info->len)
  16809. return;
  16810. WFIFOHEAD(sd->fd, info->len);
  16811. WFIFOW(sd->fd, 0) = cmd;
  16812. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16813. WFIFOSET(sd->fd, info->len);
  16814. }
  16815. /**
  16816. * [Ind/Hercules]
  16817. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16818. **/
  16819. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16820. char buf[256];
  16821. size_t len;
  16822. nullpo_retv(bl);
  16823. if(!message)
  16824. return;
  16825. len = strlen(message)+1;
  16826. if( len > sizeof(buf)-8 ) {
  16827. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16828. len = sizeof(buf)-8;
  16829. }
  16830. WBUFW(buf,0) = 0x8b3;
  16831. WBUFW(buf,2) = (uint16)(len+8);
  16832. WBUFL(buf,4) = bl->id;
  16833. safestrncpy(WBUFCP(buf,8), message, len);
  16834. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16835. }
  16836. /**
  16837. * [Ind/Hercules]
  16838. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16839. **/
  16840. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16841. unsigned char buf[10];
  16842. nullpo_retv(sd);
  16843. WBUFW(buf,0) = 0x7fc;
  16844. WBUFL(buf,2) = prev_leader_aid;
  16845. WBUFL(buf,6) = new_leader_aid;
  16846. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16847. }
  16848. /**
  16849. * Sends a clan message to a player
  16850. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16851. **/
  16852. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16853. #if PACKETVER >= 20131223
  16854. struct map_session_data *sd;
  16855. uint8 buf[256];
  16856. if( len == 0 ){
  16857. return;
  16858. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16859. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16860. len = sizeof(buf)-5-NAME_LENGTH;
  16861. }
  16862. WBUFW(buf, 0) = 0x98e;
  16863. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16864. // 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
  16865. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16866. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16867. if((sd = clan_getavailablesd(clan)) != NULL)
  16868. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16869. #endif
  16870. }
  16871. /**
  16872. * Parses a clan message from a player.
  16873. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16874. **/
  16875. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16876. #if PACKETVER >= 20131223
  16877. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16878. // validate packet and retrieve name and message
  16879. if( !clif_process_message(sd, false, name, message, output ) )
  16880. return;
  16881. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16882. #endif
  16883. }
  16884. /**
  16885. * Sends the basic clan informations to the client.
  16886. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16887. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16888. **/
  16889. void clif_clan_basicinfo( struct map_session_data *sd ){
  16890. #if PACKETVER >= 20131223
  16891. int fd, offset, length, i, flag;
  16892. struct clan* clan;
  16893. char mapname[MAP_NAME_LENGTH_EXT];
  16894. nullpo_retv( sd );
  16895. nullpo_retv( clan = sd->clan );
  16896. // Check if the player has a valid session and is not autotrading
  16897. if( !clif_session_isValid( sd ) ){
  16898. return;
  16899. }
  16900. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16901. fd = sd->fd;
  16902. WFIFOHEAD(fd,length);
  16903. memset( WFIFOP(fd, 0), 0, length );
  16904. WFIFOW( fd, 0 ) = 0x98a;
  16905. WFIFOL( fd, 4 ) = clan->id;
  16906. offset = 8;
  16907. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16908. offset += NAME_LENGTH;
  16909. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16910. offset += NAME_LENGTH;
  16911. mapindex_getmapname_ext( clan->map, mapname );
  16912. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16913. offset += MAP_NAME_LENGTH_EXT;
  16914. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16915. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16916. for( flag = 0; flag < 2; flag++ ){
  16917. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16918. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16919. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16920. offset += NAME_LENGTH;
  16921. }
  16922. }
  16923. }
  16924. WFIFOW( fd, 2 ) = offset;
  16925. WFIFOSET(fd,offset);
  16926. #endif
  16927. }
  16928. /**
  16929. * Updates the online and maximum player count of a clan.
  16930. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16931. **/
  16932. void clif_clan_onlinecount( struct clan* clan ){
  16933. #if PACKETVER >= 20131223
  16934. uint8 buf[6];
  16935. struct map_session_data *sd;
  16936. WBUFW(buf,0) = 0x988;
  16937. WBUFW(buf,2) = clan->connect_member;
  16938. WBUFW(buf,4) = clan->max_member;
  16939. if((sd = clan_getavailablesd(clan)) != NULL)
  16940. clif_send(buf, 6, &sd->bl, CLAN);
  16941. #endif
  16942. }
  16943. /**
  16944. * Notifies the client that the player has left his clan.
  16945. * 0989 (ZC_ACK_CLAN_LEAVE)
  16946. **/
  16947. void clif_clan_leave( struct map_session_data* sd ){
  16948. #if PACKETVER >= 20131223
  16949. int fd;
  16950. nullpo_retv( sd );
  16951. if( !clif_session_isValid( sd ) ){
  16952. return;
  16953. }
  16954. fd = sd->fd;
  16955. WFIFOHEAD(fd,2);
  16956. WFIFOW(fd,0) = 0x989;
  16957. WFIFOSET(fd,2);
  16958. #endif
  16959. }
  16960. /**
  16961. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16962. * 0A2F <result>.B <title_id>.L
  16963. */
  16964. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16965. {
  16966. #if PACKETVER >= 20150513
  16967. int fd;
  16968. nullpo_retv(sd);
  16969. if (!clif_session_isValid(sd))
  16970. return;
  16971. fd = sd->fd;
  16972. WFIFOHEAD(fd, packet_len(0xa2f));
  16973. WFIFOW(fd, 0) = 0xa2f;
  16974. WFIFOB(fd, 2) = result;
  16975. WFIFOL(fd, 3) = title_id;
  16976. WFIFOSET(fd, packet_len(0xa2f));
  16977. #endif
  16978. }
  16979. /**
  16980. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16981. * 0A2E <title_id>.L
  16982. */
  16983. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16984. {
  16985. int title_id;
  16986. nullpo_retv(sd);
  16987. title_id = RFIFOL(fd, 2);
  16988. if( title_id == sd->status.title_id ){
  16989. // It is exactly the same as the old one
  16990. return;
  16991. }else if( title_id <= 0 ){
  16992. sd->status.title_id = 0;
  16993. }else{
  16994. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16995. clif_change_title_ack(sd, 1, title_id);
  16996. return;
  16997. }
  16998. sd->status.title_id = title_id;
  16999. }
  17000. clif_name_area(&sd->bl);
  17001. clif_change_title_ack(sd, 0, title_id);
  17002. }
  17003. #ifdef DUMP_UNKNOWN_PACKET
  17004. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17005. {
  17006. const char* packet_txt = "save/packet.txt";
  17007. FILE* fp;
  17008. time_t time_server;
  17009. struct tm *datetime;
  17010. char datestr[512];
  17011. time(&time_server); // get time in seconds since 1/1/1970
  17012. datetime = localtime(&time_server); // convert seconds in structure
  17013. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17014. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17015. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17016. if( sd ) {
  17017. 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);
  17018. } else {
  17019. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17020. }
  17021. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17022. fprintf(fp, "\n");
  17023. fclose(fp);
  17024. } else {
  17025. ShowError("Failed to write '%s'.\n", packet_txt);
  17026. // Dump on console instead
  17027. if( sd ) {
  17028. 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);
  17029. } else {
  17030. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17031. }
  17032. ShowDump(RFIFOP(fd,0), packet_len);
  17033. }
  17034. }
  17035. #endif
  17036. /// Roulette System
  17037. /// Author: Yommy
  17038. /// Opens the roulette window
  17039. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17040. void clif_roulette_open( struct map_session_data* sd ){
  17041. nullpo_retv( sd );
  17042. struct packet_roulette_open_ack p;
  17043. p.PacketType = 0xa1a;
  17044. p.Result = 0; // result
  17045. p.Serial = 0; // serial
  17046. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17047. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17048. p.AdditionItemID = -1; //! TODO: Display bonus item
  17049. p.GoldPoint = sd->roulette_point.gold;
  17050. p.SilverPoint = sd->roulette_point.silver;
  17051. p.BronzePoint = sd->roulette_point.bronze;
  17052. sd->state.roulette_open = true;
  17053. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17054. }
  17055. /// Request to open the roulette window
  17056. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17057. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  17058. nullpo_retv(sd);
  17059. if (!battle_config.feature_roulette) {
  17060. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17061. return;
  17062. }
  17063. clif_roulette_open(sd);
  17064. }
  17065. /// Sends the info about the available roulette rewards to the client
  17066. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17067. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17068. void clif_roulette_info( struct map_session_data* sd ){
  17069. nullpo_retv(sd);
  17070. struct packet_roulette_info_ack p;
  17071. p.PacketType = rouletteinfoackType;
  17072. p.PacketLength = sizeof(p);
  17073. p.RouletteSerial = 1;
  17074. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17075. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17076. p.ItemInfo[count].Row = i;
  17077. p.ItemInfo[count].Position = j;
  17078. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17079. p.ItemInfo[count].Count = rd.qty[i][j];
  17080. #if PACKETVER >= 20180511
  17081. p.ItemInfo[count].unused = 0;
  17082. #endif
  17083. count++;
  17084. }
  17085. }
  17086. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17087. }
  17088. /// Request the roulette reward data
  17089. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17090. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  17091. nullpo_retv(sd);
  17092. if (!battle_config.feature_roulette) {
  17093. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17094. return;
  17095. }
  17096. clif_roulette_info(sd);
  17097. }
  17098. /// Notification of the client that the roulette window was closed
  17099. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17100. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  17101. nullpo_retv(sd);
  17102. if (!battle_config.feature_roulette) {
  17103. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17104. return;
  17105. }
  17106. sd->state.roulette_open = false;
  17107. }
  17108. /// Response to a item reward request
  17109. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17110. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17111. #if PACKETVER >= 20141016
  17112. nullpo_retv(sd);
  17113. struct packet_roulette_itemrecv_ack p;
  17114. p.PacketType = roulettercvitemackType;
  17115. p.Result = type;
  17116. p.AdditionItemID = 0; //! TODO: Additional item
  17117. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17118. #endif
  17119. }
  17120. /**
  17121. * Claim roulette reward
  17122. * @param sd Player
  17123. * @return 0:Success
  17124. **/
  17125. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  17126. struct item it;
  17127. uint8 res = 1;
  17128. nullpo_retr(1, sd);
  17129. if (sd->roulette.prizeIdx < 0)
  17130. return RECV_ITEM_FAILED;
  17131. memset(&it, 0, sizeof(it));
  17132. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17133. it.identify = 1;
  17134. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  17135. ; // onSuccess
  17136. }
  17137. sd->roulette.claimPrize = false;
  17138. sd->roulette.prizeStage = 0;
  17139. sd->roulette.prizeIdx = -1;
  17140. sd->roulette.stage = 0;
  17141. return res;
  17142. }
  17143. /// Update Roulette window with current stats
  17144. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17145. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17146. nullpo_retv( sd );
  17147. struct packet_roulette_generate_ack p;
  17148. p.PacketType = roulettgenerateackType;
  17149. p.Result = result;
  17150. p.Step = stage;
  17151. p.Idx = prizeIdx;
  17152. p.AdditionItemID = bonusItemID;
  17153. p.RemainGold = sd->roulette_point.gold;
  17154. p.RemainSilver = sd->roulette_point.silver;
  17155. p.RemainBronze = sd->roulette_point.bronze;
  17156. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17157. }
  17158. /// Request to start the roulette
  17159. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17160. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  17161. enum GENERATE_ROULETTE_ACK result;
  17162. nullpo_retv(sd);
  17163. if (!battle_config.feature_roulette) {
  17164. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17165. return;
  17166. }
  17167. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17168. return;
  17169. }
  17170. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17171. sd->roulette.stage = 0;
  17172. sd->roulette.claimPrize = false;
  17173. sd->roulette.prizeStage = 0;
  17174. sd->roulette.prizeIdx = -1;
  17175. }
  17176. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17177. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17178. }else{
  17179. if (!sd->roulette.stage) {
  17180. if (sd->roulette_point.bronze > 0) {
  17181. sd->roulette_point.bronze -= 1;
  17182. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17183. } else if (sd->roulette_point.silver > 9) {
  17184. sd->roulette_point.silver -= 10;
  17185. sd->roulette.stage = 2;
  17186. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17187. } else if (sd->roulette_point.gold > 9) {
  17188. sd->roulette_point.gold -= 10;
  17189. sd->roulette.stage = 4;
  17190. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17191. }
  17192. }
  17193. sd->roulette.prizeStage = sd->roulette.stage;
  17194. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17195. sd->roulette.claimPrize = true;
  17196. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17197. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17198. result = GENERATE_ROULETTE_LOSING;
  17199. sd->roulette.stage = 0;
  17200. }else{
  17201. result = GENERATE_ROULETTE_SUCCESS;
  17202. sd->roulette.stage++;
  17203. }
  17204. }
  17205. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17206. }
  17207. /// Request to claim a prize
  17208. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17209. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17210. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17211. nullpo_retv(sd);
  17212. if (!battle_config.feature_roulette) {
  17213. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17214. return;
  17215. }
  17216. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17217. return;
  17218. }
  17219. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17220. switch (clif_roulette_getitem(sd)) {
  17221. case ADDITEM_SUCCESS:
  17222. type = RECV_ITEM_SUCCESS;
  17223. break;
  17224. case ADDITEM_INVALID:
  17225. case ADDITEM_OVERITEM:
  17226. case ADDITEM_OVERAMOUNT:
  17227. type = RECV_ITEM_OVERCOUNT;
  17228. break;
  17229. case ADDITEM_OVERWEIGHT:
  17230. type = RECV_ITEM_OVERWEIGHT;
  17231. break;
  17232. case ADDITEM_STACKLIMIT:
  17233. default:
  17234. type = RECV_ITEM_FAILED;
  17235. break;
  17236. }
  17237. }
  17238. clif_roulette_recvitem_ack(sd,type);
  17239. }
  17240. /// MERGE ITEM
  17241. /**
  17242. * Acknowledge the client about item merger result
  17243. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17244. * @param fd
  17245. * @param sd
  17246. **/
  17247. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  17248. unsigned char buf[9];
  17249. struct s_packet_db *info = NULL;
  17250. short cmd = 0;
  17251. nullpo_retv(sd);
  17252. if (!clif_session_isValid(sd))
  17253. return;
  17254. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  17255. return;
  17256. if (!(info = &packet_db[cmd]) || info->len == 0)
  17257. return;
  17258. WBUFW(buf, 0) = cmd;
  17259. WBUFW(buf, info->pos[0]) = index;
  17260. WBUFW(buf, info->pos[1]) = count;
  17261. WBUFB(buf, info->pos[2]) = type;
  17262. clif_send(buf, info->len, &sd->bl, SELF);
  17263. }
  17264. /**
  17265. * Check if item has the pair to be merged
  17266. * @param sd
  17267. * @param it Item
  17268. * @return True if has pair, False if not
  17269. **/
  17270. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17271. struct item *it_;
  17272. unsigned short i;
  17273. nullpo_retr(false, sd);
  17274. 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);
  17275. if (i < MAX_INVENTORY)
  17276. return true;
  17277. return false;
  17278. }
  17279. /**
  17280. * Check if item can be merged
  17281. * @param id Item Data
  17282. * @param it Item
  17283. * @return True if can be merged, False if not
  17284. **/
  17285. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17286. if (!id || !it)
  17287. return false;
  17288. if (id->type == IT_CASH)
  17289. return false;
  17290. if (!itemdb_isstackable2(id))
  17291. return false;
  17292. if (itemdb_isspecial(it->card[0]))
  17293. return false;
  17294. if (!it->unique_id)
  17295. return false;
  17296. return true;
  17297. }
  17298. /**
  17299. * Open available item to be merged.
  17300. * Only show 1 item in 1 process.
  17301. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17302. * @param sd
  17303. **/
  17304. void clif_merge_item_open(struct map_session_data *sd) {
  17305. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  17306. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  17307. int len = 0;
  17308. struct s_packet_db *info = NULL;
  17309. struct item *it;
  17310. nullpo_retv(sd);
  17311. if (!clif_session_isValid(sd))
  17312. return;
  17313. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  17314. return;
  17315. if (!(info = &packet_db[cmd]) || info->len == 0)
  17316. return;
  17317. // Get entries
  17318. for (i = 0; i < MAX_INVENTORY; i++) {
  17319. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  17320. continue;
  17321. if (clif_merge_item_has_pair(sd, it))
  17322. indexes[n++] = i;
  17323. }
  17324. if (n < 2) { // No item need to be merged
  17325. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17326. return;
  17327. }
  17328. WBUFW(buf, 0) = cmd;
  17329. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  17330. for (i = 0; i < n; i++) {
  17331. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  17332. }
  17333. clif_send(buf, len, &sd->bl, SELF);
  17334. }
  17335. /**
  17336. * Process item merger
  17337. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17338. * @param fd
  17339. * @param sd
  17340. **/
  17341. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17342. struct s_packet_db *info = NULL;
  17343. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17344. unsigned int count = 0;
  17345. struct item_data *id = NULL;
  17346. nullpo_retv(sd);
  17347. if (!clif_session_isValid(sd))
  17348. return;
  17349. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17350. return;
  17351. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17352. if (n < 2) { // No item need to be merged
  17353. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17354. return;
  17355. }
  17356. for (i = 0, j = 0; i < n; i++) {
  17357. uint16 idx = server_index( RFIFOW( fd, info->pos[1] + i * 2 ) );
  17358. if( idx >= MAX_INVENTORY ){
  17359. return;
  17360. }
  17361. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17362. continue;
  17363. indexes[j] = idx;
  17364. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17365. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17366. return;
  17367. }
  17368. count += sd->inventory.u.items_inventory[idx].amount;
  17369. j++;
  17370. }
  17371. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17372. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17373. return;
  17374. }
  17375. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17376. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17377. return;
  17378. }
  17379. // Merrrrge!!!!
  17380. for (i = 1; i < n; i++) {
  17381. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17382. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17383. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17384. sd->inventory_data[idx] = NULL;
  17385. clif_delitem(sd, idx, amt, 0);
  17386. }
  17387. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17388. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17389. }
  17390. /**
  17391. * Cancel item merge
  17392. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17393. * @param fd
  17394. * @param sd
  17395. **/
  17396. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17397. return; // Nothing todo yet
  17398. }
  17399. static std::string clif_hide_name(const char* original_name)
  17400. {
  17401. std::string censored(original_name);
  17402. int hide = min(battle_config.broadcast_hide_name, censored.length() - 1);
  17403. censored.replace(censored.length() - hide, hide, hide, '*');
  17404. return censored;
  17405. }
  17406. /**
  17407. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17408. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17409. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17410. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17411. **/
  17412. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17413. char name[NAME_LENGTH];
  17414. if( battle_config.broadcast_hide_name ){
  17415. std::string dispname = clif_hide_name(char_name);
  17416. safestrncpy(name, dispname.c_str(), sizeof(name));
  17417. }else{
  17418. safestrncpy( name, char_name, sizeof( name ) );
  17419. }
  17420. switch( type ){
  17421. case ITEMOBTAIN_TYPE_BOXITEM:
  17422. #if PACKETVER >= 20091201
  17423. {
  17424. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17425. p.PacketType = package_item_announceType;
  17426. p.PacketLength = sizeof( p );
  17427. p.type = type;
  17428. p.ItemID = client_nameid( nameid );
  17429. p.len = NAME_LENGTH;
  17430. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17431. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17432. p.BoxItemID = client_nameid( container );
  17433. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17434. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17435. p.refineLevel = 0; // TODO: implement
  17436. #endif
  17437. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17438. }
  17439. #endif
  17440. break;
  17441. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17442. case ITEMOBTAIN_TYPE_NPC:
  17443. {
  17444. struct packet_item_drop_announce p;
  17445. p.PacketType = item_drop_announceType;
  17446. p.type = type;
  17447. p.ItemID = client_nameid( nameid );
  17448. p.len = NAME_LENGTH;
  17449. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17450. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17451. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17452. p.monsterNameLen = NAME_LENGTH;
  17453. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17454. }else{
  17455. p.monsterNameLen = 0;
  17456. p.monsterName[0] = '\0';
  17457. }
  17458. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17459. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17460. #else
  17461. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17462. #endif
  17463. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17464. }
  17465. break;
  17466. }
  17467. }
  17468. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17469. /// 0A02 <view>.W
  17470. /// Value <flag> has the following effects:
  17471. /// 1: Open a Dress Room window.
  17472. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17473. #if PACKETVER >= 20150513
  17474. int fd = sd->fd;
  17475. nullpo_retv(sd);
  17476. WFIFOHEAD(fd, packet_len(0xa02));
  17477. WFIFOW(fd,0) = 0xa02;
  17478. WFIFOW(fd,2) = flag;
  17479. WFIFOSET(fd, packet_len(0xa02));
  17480. #endif
  17481. }
  17482. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17483. /// 0A35 <result>.W
  17484. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17485. #if PACKETVER >= 20150513
  17486. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17487. // Ignore the request
  17488. // - Invalid item index
  17489. // - Invalid item ID or item doesn't exist
  17490. // - Item is already identified
  17491. if (idx < 0 || idx >= MAX_INVENTORY ||
  17492. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17493. sd->inventory.u.items_inventory[idx].identify)
  17494. return;
  17495. // Ignore the request - No magnifiers in inventory
  17496. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17497. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17498. return;
  17499. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17500. return;
  17501. skill_identify(sd, idx);
  17502. #endif
  17503. }
  17504. /// Starts navigation to the given target on client side
  17505. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17506. #if PACKETVER >= 20111010
  17507. int fd = sd->fd;
  17508. WFIFOHEAD(fd,27);
  17509. WFIFOW(fd,0) = 0x08e2;
  17510. // How detailed will our navigation be?
  17511. if( mob_id > 0 ){
  17512. x = 0;
  17513. y = 0;
  17514. WFIFOB(fd,2) = 3; // monster with destination field
  17515. }else if( x > 0 && y > 0 ){
  17516. WFIFOB(fd,2) = 0; // with coordinates
  17517. }else{
  17518. x = 0;
  17519. y = 0;
  17520. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17521. }
  17522. // Which services can be used for transportation?
  17523. WFIFOB(fd,3) = flag;
  17524. // If this flag is set, the navigation window will not be opened up
  17525. WFIFOB(fd,4) = hideWindow;
  17526. // Target map
  17527. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17528. // Target x
  17529. WFIFOW(fd,21) = x;
  17530. // Target y
  17531. WFIFOW(fd,23) = y;
  17532. // Target monster ID
  17533. WFIFOW(fd,25) = mob_id;
  17534. WFIFOSET(fd,27);
  17535. #endif
  17536. }
  17537. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17538. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17539. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17540. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17541. struct map_session_data *tsd;
  17542. struct block_list* tbl;
  17543. if( target == SELF ){
  17544. tsd = BL_CAST(BL_PC,bl);
  17545. tbl = &sd->bl;
  17546. }else{
  17547. tsd = sd;
  17548. tbl = bl;
  17549. }
  17550. nullpo_retv( tsd );
  17551. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17552. return;
  17553. }
  17554. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17555. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17556. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17557. p->aid = tsd->bl.id;
  17558. p->status = 1;
  17559. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17560. p->effects[i] = tsd->hatEffects[i];
  17561. }
  17562. clif_send( p, p->packetLength, tbl, target );
  17563. #endif
  17564. }
  17565. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17566. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17567. nullpo_retv( sd );
  17568. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17569. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17570. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17571. p->aid = sd->bl.id;
  17572. p->status = enable;
  17573. p->effects[0] = effectId;
  17574. clif_send( p, p->packetLength, &sd->bl, AREA );
  17575. #endif
  17576. }
  17577. /// Notify the client that a sale has started
  17578. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17579. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17580. #if PACKETVER_SUPPORTS_SALES
  17581. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17582. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17583. p.itemId = client_nameid( sale_item->nameid );
  17584. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17585. clif_send( &p, sizeof( p ), bl, target );
  17586. #endif
  17587. }
  17588. /// Notify the client that a sale has ended
  17589. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17590. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17591. #if PACKETVER_SUPPORTS_SALES
  17592. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17593. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17594. p.itemId = client_nameid( sale_item->nameid );
  17595. clif_send( &p, sizeof( p ), bl, target );
  17596. #endif
  17597. }
  17598. /// Update the remaining amount of a sale item.
  17599. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17600. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17601. #if PACKETVER_SUPPORTS_SALES
  17602. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17603. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17604. p.itemId = client_nameid( sale_item->nameid );
  17605. p.amount = sale_item->amount;
  17606. clif_send( &p, sizeof( p ), bl, target );
  17607. #endif
  17608. }
  17609. /// The client requested a refresh of the current remaining count of a sale item
  17610. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17611. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17612. #if PACKETVER_SUPPORTS_SALES
  17613. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17614. struct sale_item_data* sale;
  17615. if( p->AID != sd->status.account_id ){
  17616. return;
  17617. }
  17618. sale = sale_find_item( p->itemId, true );
  17619. if( sale == NULL ){
  17620. return;
  17621. }
  17622. clif_sale_amount(sale, &sd->bl, SELF);
  17623. #endif
  17624. }
  17625. /// Opens the sale administration window on the client
  17626. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17627. void clif_sale_open( struct map_session_data* sd ){
  17628. #if PACKETVER_SUPPORTS_SALES
  17629. nullpo_retv(sd);
  17630. if( sd->state.sale_open ){
  17631. return;
  17632. }
  17633. sd->state.sale_open = true;
  17634. int fd = sd->fd;
  17635. WFIFOHEAD(fd, 2);
  17636. WFIFOW(fd, 0) = 0x9b5;
  17637. WFIFOSET(fd, 2);
  17638. #endif
  17639. }
  17640. /// Client request to open the sale administration window.
  17641. /// This is sent by /limitedsale
  17642. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17643. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17644. #if PACKETVER_SUPPORTS_SALES
  17645. nullpo_retv(sd);
  17646. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17647. return;
  17648. }
  17649. char command[CHAT_SIZE_MAX];
  17650. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17651. is_atcommand(fd, sd, command, 1);
  17652. #endif
  17653. }
  17654. /// Closes the sale administration window on the client.
  17655. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17656. void clif_sale_close(struct map_session_data* sd) {
  17657. #if PACKETVER_SUPPORTS_SALES
  17658. nullpo_retv(sd);
  17659. if( !sd->state.sale_open ){
  17660. return;
  17661. }
  17662. sd->state.sale_open = false;
  17663. int fd = sd->fd;
  17664. WFIFOHEAD(fd, 2);
  17665. WFIFOW(fd, 0) = 0x9bd;
  17666. WFIFOSET(fd, 2);
  17667. #endif
  17668. }
  17669. /// Client request to close the sale administration window.
  17670. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17671. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17672. #if PACKETVER_SUPPORTS_SALES
  17673. nullpo_retv(sd);
  17674. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17675. return;
  17676. }
  17677. clif_sale_close(sd);
  17678. #endif
  17679. }
  17680. /// Reply to a item search request for item sale administration.
  17681. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17682. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17683. #if PACKETVER_SUPPORTS_SALES
  17684. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17685. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17686. if( item != NULL ){
  17687. p.result = 0;
  17688. p.itemId = client_nameid( item->nameid );
  17689. p.price = item->price;
  17690. }else{
  17691. p.result = 1;
  17692. p.itemId = 0;
  17693. p.price = 0;
  17694. }
  17695. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17696. #endif
  17697. }
  17698. /// Search request for an item sale administration.
  17699. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17700. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17701. #if PACKETVER_SUPPORTS_SALES
  17702. char item_name[ITEM_NAME_LENGTH];
  17703. nullpo_retv(sd);
  17704. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17705. return;
  17706. }
  17707. if( !sd->state.sale_open ){
  17708. return;
  17709. }
  17710. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17711. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17712. if( id ){
  17713. int i;
  17714. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17715. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17716. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17717. return;
  17718. }
  17719. }
  17720. }
  17721. // not found
  17722. clif_sale_search_reply( sd, NULL );
  17723. #endif
  17724. }
  17725. /// Reply if an item was successfully put on sale or not.
  17726. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17727. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17728. #if PACKETVER_SUPPORTS_SALES
  17729. int fd = sd->fd;
  17730. WFIFOHEAD(fd, 4);
  17731. WFIFOW(fd, 0) = 0x9af;
  17732. WFIFOW(fd, 2) = (uint16)result;
  17733. WFIFOSET(fd, 4);
  17734. #endif
  17735. }
  17736. /// A client request to put an item on sale.
  17737. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17738. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17739. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17740. #if PACKETVER_SUPPORTS_SALES
  17741. nullpo_retv( sd );
  17742. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17743. if( p->AID != sd->status.account_id ){
  17744. return;
  17745. }
  17746. if( !sd->state.sale_open ){
  17747. return;
  17748. }
  17749. time_t endTime = p->startTime + p->hours * 60 * 60;
  17750. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17751. #endif
  17752. }
  17753. /// Reply to an item removal from sale.
  17754. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17755. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17756. #if PACKETVER_SUPPORTS_SALES
  17757. int fd = sd->fd;
  17758. WFIFOHEAD(fd, 4);
  17759. WFIFOW(fd, 0) = 0x9b1;
  17760. WFIFOW(fd, 2) = failed;
  17761. WFIFOSET(fd, 4);
  17762. #endif
  17763. }
  17764. /// Request to remove an item from sale.
  17765. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17766. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17767. #if PACKETVER_SUPPORTS_SALES
  17768. nullpo_retv( sd );
  17769. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17770. if( p->AID != sd->status.account_id ){
  17771. return;
  17772. }
  17773. if( !sd->state.sale_open ){
  17774. return;
  17775. }
  17776. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17777. #endif
  17778. }
  17779. /// Achievement System
  17780. /// Author: Luxuri, Aleos
  17781. /**
  17782. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17783. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17784. */
  17785. void clif_achievement_list_all(struct map_session_data *sd)
  17786. {
  17787. nullpo_retv(sd);
  17788. if (!battle_config.feature_achievement) {
  17789. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17790. return;
  17791. }
  17792. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17793. if (count == 0)
  17794. return;
  17795. int len = (50 * count) + 22;
  17796. int fd = sd->fd;
  17797. int *info = achievement_level(sd, true);
  17798. WFIFOHEAD(fd,len);
  17799. WFIFOW(fd, 0) = 0xa23;
  17800. WFIFOW(fd, 2) = len;
  17801. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17802. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17803. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17804. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17805. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17806. for (int i = 0; i < count; i++) {
  17807. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17808. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17809. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17810. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17811. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17812. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17813. }
  17814. WFIFOSET(fd, len);
  17815. }
  17816. /**
  17817. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17818. * 0a24 <ACHPoint>.L
  17819. */
  17820. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17821. {
  17822. nullpo_retv(sd);
  17823. if (!battle_config.feature_achievement) {
  17824. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17825. return;
  17826. }
  17827. int fd = sd->fd;
  17828. int *info = achievement_level(sd, true);
  17829. WFIFOHEAD(fd, packet_len(0xa24));
  17830. WFIFOW(fd, 0) = 0xa24;
  17831. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17832. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17833. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17834. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17835. if (ach) {
  17836. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17837. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17838. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17839. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17840. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17841. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17842. } else
  17843. memset(WFIFOP(fd, 16), 0, 40);
  17844. WFIFOSET(fd, packet_len(0xa24));
  17845. }
  17846. /**
  17847. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17848. * 0a25 <achievementID>.L
  17849. */
  17850. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17851. {
  17852. nullpo_retv(sd);
  17853. if( sd->achievement_data.save )
  17854. intif_achievement_save(sd);
  17855. achievement_check_reward(sd, RFIFOL(fd,2));
  17856. }
  17857. /**
  17858. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17859. * 0a26 <result>.W <achievementID>.L
  17860. */
  17861. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17862. {
  17863. WFIFOHEAD(fd, packet_len(0xa26));
  17864. WFIFOW(fd, 0) = 0xa26;
  17865. WFIFOB(fd, 2) = result;
  17866. WFIFOL(fd, 3) = achievement_id;
  17867. WFIFOSET(fd, packet_len(0xa26));
  17868. }
  17869. /// Process the pet evolution request
  17870. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17871. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17872. #if PACKETVER >= 20141008
  17873. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17874. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17875. if (!pet) {
  17876. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17877. return;
  17878. }
  17879. pet_evolution(sd, pet->class_);
  17880. #endif
  17881. }
  17882. /// Sends the result of the evolution to the client.
  17883. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17884. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17885. #if PACKETVER >= 20141008
  17886. int fd = sd->fd;
  17887. WFIFOHEAD(fd, packet_len(0x9fc));
  17888. WFIFOW(fd, 0) = 0x9fc;
  17889. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17890. WFIFOSET(fd, packet_len(0x9fc));
  17891. #endif
  17892. }
  17893. /*
  17894. * This packet is sent by /changedress or /nocosplay
  17895. *
  17896. * 0ae8
  17897. */
  17898. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17899. #if PACKETVER >= 20180103
  17900. char command[CHAT_SIZE_MAX];
  17901. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17902. is_atcommand( fd, sd, command, 1 );
  17903. #endif
  17904. }
  17905. /// Opens an UI window of the given type and initializes it with the given data
  17906. /// 0AE2 <type>.B <data>.L
  17907. void clif_ui_open( struct map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  17908. #if PACKETVER >= 20151202
  17909. // If the UI requires state tracking
  17910. switch( ui_type ){
  17911. case OUT_UI_STYLIST:
  17912. sd.state.stylist_open = true;
  17913. break;
  17914. case OUT_UI_ENCHANTGRADE:
  17915. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  17916. sd.state.enchantgrade_open = true;
  17917. break;
  17918. #else
  17919. return;
  17920. #endif
  17921. }
  17922. struct PACKET_ZC_UI_OPEN p = {};
  17923. p.PacketType = HEADER_ZC_UI_OPEN;
  17924. p.UIType = ui_type;
  17925. #if PACKETVER >= 20171122
  17926. p.data = data;
  17927. #endif
  17928. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17929. #endif
  17930. }
  17931. /// Request to open an UI window of the given type
  17932. /// 0A68 <type>.B
  17933. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17934. switch( RFIFOB(fd,2) ){
  17935. case IN_UI_ATTENDANCE:
  17936. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17937. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17938. }else if( pc_attendance_enabled() ){
  17939. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17940. }else{
  17941. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17942. }
  17943. break;
  17944. #if PACKETVER >= 20160316
  17945. case IN_UI_MACRO_REGISTER:
  17946. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  17947. break;
  17948. case IN_UI_MACRO_DETECTOR:
  17949. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  17950. break;
  17951. #endif
  17952. }
  17953. }
  17954. /// Response for attedance request
  17955. /// 0AF0 <unknown>.L <data>.L
  17956. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17957. nullpo_retv(sd);
  17958. int fd = sd->fd;
  17959. WFIFOHEAD(fd,packet_len(0xAF0));
  17960. WFIFOW(fd,0) = 0xAF0;
  17961. WFIFOL(fd,2) = 0;
  17962. WFIFOL(fd,6) = data;
  17963. WFIFOSET(fd,packet_len(0xAF0));
  17964. }
  17965. /// Request from the client to retrieve today's attendance reward
  17966. /// 0AEF
  17967. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17968. pc_attendance_claim_reward(sd);
  17969. }
  17970. /// Send out the percentage of weight that causes it to be displayed in red.
  17971. /// 0ADE <percentage>.L
  17972. void clif_weight_limit( struct map_session_data* sd ){
  17973. #if PACKETVER >= 20171025
  17974. nullpo_retv(sd);
  17975. int fd = sd->fd;
  17976. WFIFOHEAD(fd, packet_len(0xADE));
  17977. WFIFOW(fd, 0) = 0xADE;
  17978. #ifdef RENEWAL
  17979. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17980. #else
  17981. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17982. #endif
  17983. WFIFOSET(fd, packet_len(0xADE));
  17984. #endif
  17985. }
  17986. enum e_private_airship_response : uint32{
  17987. PRIVATEAIRSHIP_OK,
  17988. PRIVATEAIRSHIP_RETRY,
  17989. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17990. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17991. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17992. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17993. };
  17994. /// Send out the response to a private airship request
  17995. /// 0A4A <response>.L
  17996. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17997. #if PACKETVER >= 20180321
  17998. nullpo_retv( sd );
  17999. int fd = sd->fd;
  18000. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18001. WFIFOW( fd, 0 ) = 0xA4A;
  18002. WFIFOL( fd, 2 ) = response;
  18003. WFIFOSET( fd, packet_len( 0xA4A ) );
  18004. #endif
  18005. }
  18006. /// Parses a request for a private airship
  18007. /// 0A49 <mapname>.16B <itemid>.W
  18008. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  18009. #if PACKETVER >= 20180321
  18010. // Check if the feature is enabled
  18011. if( !battle_config.feature_privateairship ){
  18012. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18013. return;
  18014. }
  18015. // Check if the player is allowed to warp from the source map
  18016. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18017. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18018. return;
  18019. }
  18020. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18021. char mapname[MAP_NAME_LENGTH_EXT];
  18022. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18023. int16 mapindex = mapindex_name2id( mapname );
  18024. // Check if we know the mapname
  18025. if( mapindex < 0 ){
  18026. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18027. return;
  18028. }
  18029. int16 mapid = map_mapindex2mapid( mapindex );
  18030. // Check if the map is available on this server
  18031. if( mapid < 0 ){
  18032. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18033. return;
  18034. }
  18035. // Check if the player tried to warp to the map he is on
  18036. if( sd->bl.m == mapid ){
  18037. // This is blocked by the client, but just to be sure
  18038. return;
  18039. }
  18040. // This can only be a hack, so we prevent it
  18041. if( map_getmapdata( mapid )->instance_id ){
  18042. // Ignore requests to warp directly into a running instance
  18043. return;
  18044. }
  18045. // Check if the player is allowed to warp to the target map
  18046. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18047. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18048. return;
  18049. }
  18050. t_itemid item_id = p->ItemID;
  18051. // Check if the item sent by the client is known to us
  18052. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18053. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18054. return;
  18055. }
  18056. int idx = pc_search_inventory( sd, item_id );
  18057. // Check if the player has the item at all
  18058. if( idx < 0 ){
  18059. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18060. return;
  18061. }
  18062. // Delete the chosen item
  18063. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18064. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18065. return;
  18066. }
  18067. // Warp the player to a random spot on the destination map
  18068. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18069. #endif
  18070. }
  18071. /// Sends out the usage history of the guild storage
  18072. /// 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
  18073. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18074. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18075. #if PACKETVER >= 20140205
  18076. nullpo_retv( sd );
  18077. int fd = sd->fd;
  18078. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18079. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18080. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18081. }else{
  18082. log.clear();
  18083. }
  18084. WFIFOHEAD( fd, size );
  18085. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18086. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18087. p->PacketLength = size;
  18088. p->result = result;
  18089. p->amount = (uint16)log.size();
  18090. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18091. for( int i = 0; i < log.size(); i++ ){
  18092. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18093. struct guild_log_entry& entry = log[i];
  18094. item->id = entry.id;
  18095. item->itemId = client_nameid( entry.item.nameid );
  18096. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18097. item->action = entry.amount > 0; // action = true(put), false(get)
  18098. item->refine = entry.item.refine;
  18099. item->uniqueId = entry.item.unique_id;
  18100. item->IsIdentified = entry.item.identify;
  18101. item->itemType = itemtype( entry.item.nameid );
  18102. clif_addcards( &item->slot, &entry.item );
  18103. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18104. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18105. item->attribute = entry.item.attribute;
  18106. }
  18107. }
  18108. WFIFOSET( fd, p->PacketLength );
  18109. #endif
  18110. }
  18111. /// Activates the client camera info or updates the client camera with the given values.
  18112. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18113. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18114. #if PACKETVER >= 20160525
  18115. int fd = sd->fd;
  18116. WFIFOHEAD(fd, packet_len(0xa78));
  18117. WFIFOW(fd, 0) = 0xa78;
  18118. WFIFOB(fd, 2) = show;
  18119. WFIFOF(fd, 3) = range;
  18120. WFIFOF(fd, 7) = rotation;
  18121. WFIFOF(fd, 11) = latitude;
  18122. WFIFOSET(fd, packet_len(0xa78));
  18123. #endif
  18124. }
  18125. /// Activates or deactives the client camera info or updates the camera settings.
  18126. /// This packet is triggered by /viewpointvalue or /setcamera
  18127. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18128. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  18129. char command[CHAT_SIZE_MAX];
  18130. // /viewpointvalue
  18131. if( RFIFOB( fd, 2 ) == 1 ){
  18132. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18133. // /setcamera
  18134. }else{
  18135. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18136. }
  18137. is_atcommand( fd, sd, command, 1 );
  18138. }
  18139. /// Send the full list of items in the equip switch window
  18140. /// 0a9b <length>.W { <index>.W <position>.L }*
  18141. void clif_equipswitch_list( struct map_session_data* sd ){
  18142. #if PACKETVER >= 20170208
  18143. int fd = sd->fd;
  18144. int offset, i, position;
  18145. WFIFOW(fd, 0) = 0xa9b;
  18146. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18147. short index = sd->equip_switch_index[i];
  18148. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18149. WFIFOW(fd, offset) = index + 2;
  18150. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18151. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18152. offset += 6;
  18153. }
  18154. }
  18155. WFIFOW(fd, 2) = offset;
  18156. WFIFOSET(fd, offset);
  18157. #endif
  18158. }
  18159. /// Acknowledgement for removing an equip to the equip switch window
  18160. /// 0a9a <index>.W <position.>.L <failure>.W
  18161. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18162. #if PACKETVER >= 20170208
  18163. int fd = sd->fd;
  18164. WFIFOHEAD(fd, packet_len(0xa9a));
  18165. WFIFOW(fd, 0) = 0xa9a;
  18166. WFIFOW(fd, 2) = index + 2;
  18167. WFIFOL(fd, 4) = pos;
  18168. WFIFOW(fd, 8) = failed;
  18169. WFIFOSET(fd, packet_len(0xa9a));
  18170. #endif
  18171. }
  18172. /// Request to remove an equip from the equip switch window
  18173. /// 0a99 <index>.W <position>.L <= 20170502
  18174. /// 0a99 <index>.W
  18175. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  18176. #if PACKETVER >= 20170208
  18177. uint16 index = RFIFOW(fd, 2) - 2;
  18178. bool removed = false;
  18179. if( !battle_config.feature_equipswitch ){
  18180. return;
  18181. }
  18182. // Check if the index is valid
  18183. if( index >= MAX_INVENTORY ){
  18184. return;
  18185. }
  18186. pc_equipswitch_remove( sd, index );
  18187. #endif
  18188. }
  18189. /// Acknowledgement for adding an equip to the equip switch window
  18190. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18191. /// 0a98 <index>.W <position.>.L <flag>.W
  18192. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18193. #if PACKETVER >= 20170208
  18194. int fd = sd->fd;
  18195. WFIFOHEAD(fd, packet_len(0xa98));
  18196. WFIFOW(fd, 0) = 0xa98;
  18197. WFIFOW(fd, 2) = index + 2;
  18198. WFIFOL(fd, 4) = pos;
  18199. #if PACKETVER <= 20170502
  18200. WFIFOL(fd, 8) = flag;
  18201. #else
  18202. WFIFOW(fd, 8) = flag;
  18203. #endif
  18204. WFIFOSET(fd,packet_len(0xa98));
  18205. #endif
  18206. }
  18207. /// Request to add an equip to the equip switch window
  18208. /// 0a97 <index>.W <position>.L
  18209. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  18210. #if PACKETVER >= 20170208
  18211. uint16 index = RFIFOW(fd, 2) - 2;
  18212. uint32 position = RFIFOL(fd, 4);
  18213. if( !battle_config.feature_equipswitch ){
  18214. return;
  18215. }
  18216. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18217. return;
  18218. }
  18219. if( sd->state.trading || sd->npc_shopid ){
  18220. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18221. return;
  18222. }
  18223. if( sd->inventory_data[index]->type == IT_AMMO ){
  18224. position = EQP_AMMO;
  18225. }
  18226. pc_equipitem( sd, index, position, true );
  18227. #endif
  18228. }
  18229. /// Acknowledgement packet for the full equip switch
  18230. /// 0a9d <failed>.W
  18231. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  18232. #if PACKETVER >= 20170208
  18233. int fd = sd->fd;
  18234. WFIFOHEAD(fd, packet_len(0xa9d));
  18235. WFIFOW(fd, 0) = 0xa9d;
  18236. WFIFOW(fd, 2) = failed;
  18237. WFIFOSET(fd, packet_len(0xa9d));
  18238. #endif
  18239. }
  18240. /// Request to do a full equip switch
  18241. /// 0a9c
  18242. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18243. #if PACKETVER >= 20170208
  18244. int i;
  18245. t_tick tick = gettick();
  18246. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18247. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18248. // Client will not let you send a request
  18249. return;
  18250. }
  18251. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18252. if( !battle_config.feature_equipswitch ){
  18253. return;
  18254. }
  18255. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18256. if( i == EQI_MAX ){
  18257. // client will show: "There is no item to replace." and should not even come here
  18258. clif_equipswitch_reply( sd, false );
  18259. return;
  18260. }
  18261. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18262. return;
  18263. }
  18264. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18265. #endif
  18266. }
  18267. /// Request to do a single equip switch
  18268. /// 0ace <index>.W
  18269. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18270. #if PACKETVER >= 20170502
  18271. uint16 index = RFIFOW(fd, 2) - 2;
  18272. if( !battle_config.feature_equipswitch ){
  18273. return;
  18274. }
  18275. // Check if the index is valid
  18276. if( index >= MAX_INVENTORY ){
  18277. return;
  18278. }
  18279. // Check if the item exists
  18280. if (sd->inventory_data[index] == nullptr)
  18281. return;
  18282. // Check if the item was already added to equip switch
  18283. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18284. if( sd->npc_id ){
  18285. #ifdef RENEWAL
  18286. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18287. clif_msg( sd, WORK_IN_PROGRESS );
  18288. return;
  18289. }
  18290. #endif
  18291. if( !sd->npc_item_flag ){
  18292. return;
  18293. }
  18294. }
  18295. pc_equipswitch( sd, index );
  18296. return;
  18297. }
  18298. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18299. #endif
  18300. }
  18301. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18302. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18303. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18304. // Only rolling cutter is supported for now
  18305. if( p->skillId != GC_ROLLINGCUTTER ){
  18306. return;
  18307. }
  18308. // Already running - cant happen on officials, since only one skill is supported
  18309. if( sd->skill_keep_using.skill_id != 0 ){
  18310. return;
  18311. }
  18312. sd->skill_keep_using.tid = INVALID_TIMER;
  18313. sd->skill_keep_using.skill_id = p->skillId;
  18314. sd->skill_keep_using.level = p->skillLv;
  18315. sd->skill_keep_using.target = p->targetId;
  18316. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18317. #endif
  18318. }
  18319. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18320. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18321. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18322. // Not running
  18323. if( sd->skill_keep_using.skill_id == 0 ){
  18324. return;
  18325. }
  18326. #if 0
  18327. // Hack
  18328. if( p->skillId != sd->skill_keep_using.skill_id ){
  18329. return;
  18330. }
  18331. #endif
  18332. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18333. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18334. sd->skill_keep_using.tid = INVALID_TIMER;
  18335. }
  18336. sd->skill_keep_using.skill_id = 0;
  18337. sd->skill_keep_using.level = 0;
  18338. sd->skill_keep_using.target = 0;
  18339. #endif
  18340. }
  18341. void clif_ping( struct map_session_data* sd ){
  18342. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18343. nullpo_retv( sd );
  18344. int fd = sd->fd;
  18345. if( !session_isActive( fd ) ){
  18346. return;
  18347. }
  18348. struct PACKET_ZC_PING_LIVE p = {};
  18349. p.packetType = HEADER_ZC_PING_LIVE;
  18350. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18351. #endif
  18352. }
  18353. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18354. nullpo_ret( sd );
  18355. int fd = sd->fd;
  18356. if( !session_isActive( fd ) ){
  18357. return 0;
  18358. }
  18359. t_tick tick = va_arg( ap, t_tick );
  18360. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18361. clif_ping( sd );
  18362. }
  18363. return 0;
  18364. }
  18365. TIMER_FUNC( clif_ping_timer ){
  18366. map_foreachpc( clif_ping_timer_sub, gettick() );
  18367. return 0;
  18368. }
  18369. /**
  18370. * Opens the refine UI on the designated client.
  18371. * 0aa0
  18372. */
  18373. void clif_refineui_open( struct map_session_data* sd ){
  18374. #if PACKETVER >= 20161012
  18375. nullpo_retv( sd );
  18376. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18377. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18378. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18379. sd->state.refineui_open = true;
  18380. #endif
  18381. }
  18382. /**
  18383. * Parses cancel/close of the refine UI on client side.
  18384. * 0aa4
  18385. */
  18386. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18387. #if PACKETVER >= 20161012
  18388. sd->state.refineui_open = false;
  18389. #endif
  18390. }
  18391. /**
  18392. * Adds the selected item into the refine UI and sends the possible materials
  18393. * to the client.
  18394. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18395. */
  18396. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18397. #if PACKETVER >= 20161012
  18398. int fd = sd->fd;
  18399. // Get the item db reference
  18400. struct item_data* id = sd->inventory_data[index];
  18401. // No item data was found
  18402. if( id == NULL ){
  18403. return;
  18404. }
  18405. // Check the inventory
  18406. struct item* item = &sd->inventory.u.items_inventory[index];
  18407. // No item was found at the given index
  18408. if( item == NULL ){
  18409. return;
  18410. }
  18411. // Check if the item is identified
  18412. if( !item->identify ){
  18413. return;
  18414. }
  18415. // Check if the item is broken
  18416. if( item->attribute ){
  18417. return;
  18418. }
  18419. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18420. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18421. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18422. p->itemIndex = client_index( index );
  18423. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18424. // No possibilities were found
  18425. if( info == nullptr ){
  18426. p->blacksmithBlessing = 0;
  18427. }else{
  18428. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18429. uint16 count = 0;
  18430. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18431. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18432. if( cost != nullptr ){
  18433. p->req[count].itemId = client_nameid( cost->nameid );
  18434. p->req[count].chance = (uint8)( cost->chance / 100 );
  18435. p->req[count].zeny = cost->zeny;
  18436. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18437. count++;
  18438. }
  18439. }
  18440. }
  18441. clif_send( p, p->packetLength, &sd->bl, SELF );
  18442. #endif
  18443. }
  18444. /**
  18445. * Client request to add an item to the refine UI.
  18446. * 0aa1 <index>.W
  18447. */
  18448. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18449. #if PACKETVER >= 20161012
  18450. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18451. uint16 index = server_index( p->index );
  18452. // Check if the refine UI is open
  18453. if( !sd->state.refineui_open ){
  18454. return;
  18455. }
  18456. // Check if the index is valid
  18457. if( index >= MAX_INVENTORY ){
  18458. return;
  18459. }
  18460. // Send out the requirements for the refine process
  18461. clif_refineui_info( sd, index );
  18462. #endif
  18463. }
  18464. /**
  18465. * Client requests to try to refine an item.
  18466. * 0aa3 <index>.W <material>.W <catalyst>.B
  18467. */
  18468. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18469. #if PACKETVER >= 20161012
  18470. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18471. uint16 index = server_index( p->index );
  18472. t_itemid material = p->itemId;
  18473. int16 j;
  18474. // Check if the refine UI is open
  18475. if( !sd->state.refineui_open ){
  18476. return;
  18477. }
  18478. // Check if the index is valid
  18479. if( index >= MAX_INVENTORY ){
  18480. return;
  18481. }
  18482. // Get the item db reference
  18483. struct item_data* id = sd->inventory_data[index];
  18484. // No item data was found
  18485. if( id == NULL ){
  18486. return;
  18487. }
  18488. // Check the inventory
  18489. struct item* item = &sd->inventory.u.items_inventory[index];
  18490. // No item was found at the given index
  18491. if( item == NULL ){
  18492. return;
  18493. }
  18494. // Check if the item is identified
  18495. if( !item->identify ){
  18496. return;
  18497. }
  18498. // Check if the item is broken
  18499. if( item->attribute ){
  18500. return;
  18501. }
  18502. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18503. // No refine possible
  18504. if( info == nullptr ){
  18505. return;
  18506. }
  18507. // No possibilities were found
  18508. if( info->costs.empty() ){
  18509. return;
  18510. }
  18511. // Check if the player has the selected material
  18512. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18513. return;
  18514. }
  18515. int16 blacksmith_index = -1;
  18516. uint16 blacksmith_amount = 0;
  18517. // Check if the player has enough blacksmith blessings
  18518. if( p->blacksmithBlessing != 0 ){
  18519. blacksmith_amount = info->blessing_amount;
  18520. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18521. if( blacksmith_amount == 0 ){
  18522. return;
  18523. }
  18524. // Check if the player has blacksmith blessings
  18525. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18526. return;
  18527. }
  18528. // Check if the player has enough blacksmith blessings
  18529. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18530. return;
  18531. }
  18532. }
  18533. std::shared_ptr<s_refine_cost> cost = nullptr;
  18534. for( const auto& pair : info->costs ){
  18535. if( pair.second->nameid == material ){
  18536. cost = pair.second;
  18537. break;
  18538. }
  18539. }
  18540. // The material was not in the list of possible materials
  18541. if( cost == nullptr ){
  18542. return;
  18543. }
  18544. // Try to pay for the refine
  18545. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18546. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18547. return;
  18548. }
  18549. // Delete the required material
  18550. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18551. return;
  18552. }
  18553. // Delete the required blacksmith blessings
  18554. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18555. return;
  18556. }
  18557. // Try to refine the item
  18558. if( cost->chance >= ( rnd() % 10000 ) ){
  18559. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18560. // Success
  18561. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18562. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18563. clif_misceffect( &sd->bl, 3 );
  18564. clif_refine( fd, 0, index, item->refine );
  18565. if (info->broadcast_success) {
  18566. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18567. }
  18568. if( id->type == IT_WEAPON ){
  18569. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18570. }
  18571. clif_refineui_info( sd, index );
  18572. }else{
  18573. // Failure
  18574. if (info->broadcast_failure) {
  18575. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18576. }
  18577. // Blacksmith blessings were used to prevent breaking and downgrading
  18578. if( blacksmith_amount > 0 ){
  18579. clif_refine( fd, 3, index, item->refine );
  18580. clif_refineui_info( sd, index );
  18581. // Delete the item if it is breakable
  18582. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18583. clif_refine( fd, 1, index, item->refine );
  18584. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18585. // Downgrade the item if necessary
  18586. }else if( cost->downgrade_amount > 0 ){
  18587. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18588. clif_refine( fd, 2, index, item->refine );
  18589. clif_refineui_info(sd, index);
  18590. // Only show failure, but dont do anything
  18591. }else{
  18592. clif_refine( fd, 3, index, item->refine );
  18593. clif_refineui_info( sd, index );
  18594. }
  18595. clif_misceffect( &sd->bl, 2 );
  18596. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18597. }
  18598. #endif
  18599. }
  18600. void clif_unequipall_reply( struct map_session_data* sd, bool failed ){
  18601. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18602. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18603. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18604. p.result = failed;
  18605. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18606. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18607. }
  18608. void clif_parse_unequipall( int fd, struct map_session_data* sd ){
  18609. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18610. if( pc_cant_act( sd ) ){
  18611. clif_unequipall_reply( sd, true );
  18612. return;
  18613. }
  18614. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18615. if( sd->equip_index[i] >= 0 ){
  18616. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18617. }
  18618. }
  18619. clif_unequipall_reply( sd, false );
  18620. #endif
  18621. }
  18622. void clif_stylist_response( struct map_session_data* sd, bool failed ){
  18623. #if PACKETVER >= 20151104
  18624. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18625. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18626. p.flag = failed;
  18627. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18628. if( !failed ){
  18629. sd->state.stylist_open = false;
  18630. }
  18631. #endif
  18632. }
  18633. bool clif_parse_stylist_buy_sub( struct map_session_data* sd, _look look, int16 index ){
  18634. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18635. if( list == nullptr ){
  18636. return false;
  18637. }
  18638. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18639. if( entry == nullptr ){
  18640. return false;
  18641. }
  18642. std::shared_ptr<s_stylist_costs> costs;
  18643. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18644. costs = entry->doram;
  18645. }else{
  18646. costs = entry->human;
  18647. }
  18648. if( costs == nullptr ){
  18649. return false;
  18650. }
  18651. if( sd->status.zeny < costs->price ){
  18652. return false;
  18653. }
  18654. int16 inventoryIndex = -1;
  18655. if( costs->requiredItem != 0 ){
  18656. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18657. if( inventoryIndex < 0 ){
  18658. // No other option
  18659. if( costs->requiredItemBox == 0 ){
  18660. return false;
  18661. }
  18662. // Check if the box that contains the item is in the inventory
  18663. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18664. // The box containing the item also does not exist
  18665. if( inventoryIndex < 0 ){
  18666. return false;
  18667. }
  18668. }
  18669. }else if( costs->requiredItemBox != 0 ){
  18670. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18671. if( inventoryIndex < 0 ){
  18672. return false;
  18673. }
  18674. }
  18675. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18676. return false;
  18677. }
  18678. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18679. return false;
  18680. }
  18681. switch( look ){
  18682. case LOOK_HAIR:
  18683. case LOOK_HAIR_COLOR:
  18684. case LOOK_CLOTHES_COLOR:
  18685. case LOOK_BODY2:
  18686. pc_changelook( sd, look, entry->value );
  18687. break;
  18688. case LOOK_HEAD_BOTTOM:
  18689. case LOOK_HEAD_MID:
  18690. case LOOK_HEAD_TOP: {
  18691. struct mail_message msg = {};
  18692. msg.dest_id = sd->status.char_id;
  18693. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18694. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18695. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18696. msg.item[0].nameid = entry->value;
  18697. msg.item[0].identify = 1;
  18698. msg.item[0].amount = 1;
  18699. msg.status = MAIL_NEW;
  18700. msg.type = MAIL_INBOX_NORMAL;
  18701. msg.timestamp = time( nullptr );
  18702. intif_Mail_send( 0, &msg );
  18703. } break;
  18704. }
  18705. return true;
  18706. }
  18707. void clif_parse_stylist_buy( int fd, struct map_session_data* sd ){
  18708. #if PACKETVER >= 20151104
  18709. #if PACKETVER >= 20180516
  18710. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18711. #else
  18712. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18713. #endif
  18714. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18715. clif_stylist_response( sd, true );
  18716. return;
  18717. }
  18718. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18719. clif_stylist_response( sd, true );
  18720. return;
  18721. }
  18722. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18723. clif_stylist_response( sd, true );
  18724. return;
  18725. }
  18726. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18727. clif_stylist_response( sd, true );
  18728. return;
  18729. }
  18730. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18731. clif_stylist_response( sd, true );
  18732. return;
  18733. }
  18734. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18735. clif_stylist_response( sd, true );
  18736. return;
  18737. }
  18738. #if PACKETVER >= 20180516
  18739. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18740. clif_stylist_response( sd, true );
  18741. return;
  18742. }
  18743. #endif
  18744. clif_stylist_response( sd, false );
  18745. #endif
  18746. }
  18747. void clif_parse_stylist_close( int fd, struct map_session_data* sd ){
  18748. #if PACKETVER >= 20151104
  18749. sd->state.stylist_open = false;
  18750. #endif
  18751. }
  18752. void clif_inventory_expansion_info( struct map_session_data* sd ){
  18753. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18754. nullpo_retv( sd );
  18755. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18756. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18757. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18758. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18759. #endif
  18760. }
  18761. enum class e_inventory_expansion_response : uint8{
  18762. ASK_CONFIRMATION = 0,
  18763. FAILED,
  18764. BUSY,
  18765. MISSING_ITEM,
  18766. MAXIMUM_REACHED
  18767. };
  18768. void clif_inventory_expansion_response( struct map_session_data* sd, e_inventory_expansion_response response ){
  18769. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18770. nullpo_retv( sd );
  18771. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18772. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18773. p.result = (uint8)response;
  18774. p.itemId = sd->state.inventory_expansion_confirmation;
  18775. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18776. #endif
  18777. }
  18778. void clif_parse_inventory_expansion_request( int fd, struct map_session_data* sd ){
  18779. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18780. // Check if player is dead or busy with other stuff
  18781. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18782. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18783. return;
  18784. }
  18785. // Check if the player already reached the maximum
  18786. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18787. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18788. return;
  18789. }
  18790. static std::map<t_itemid, uint16> items = {
  18791. // The order of entries in this list defines which will be used first
  18792. // This order and the usable items are hardcoded into the client
  18793. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18794. { ITEMID_INVENTORY_EX_EVT, 10 },
  18795. { ITEMID_INVENTORY_EX_DIS, 10 },
  18796. { ITEMID_INVENTORY_EX, 10 },
  18797. };
  18798. int16 index = -1;
  18799. bool found_over_limit = false;
  18800. for( const auto& entry : items ){
  18801. // Check if the player has the required item
  18802. index = pc_search_inventory( sd, entry.first );
  18803. // Found an item
  18804. if( index >= 0 ){
  18805. // Check if the player would exceed the maximum
  18806. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18807. found_over_limit = true;
  18808. }else{
  18809. found_over_limit = false;
  18810. sd->state.inventory_expansion_confirmation = entry.first;
  18811. sd->state.inventory_expansion_amount = entry.second;
  18812. break;
  18813. }
  18814. }
  18815. }
  18816. // Check if an item was found
  18817. if( sd->state.inventory_expansion_confirmation == 0 ){
  18818. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18819. return;
  18820. }
  18821. // Check if an item would have been found, but the player would exceed the maximum
  18822. if( found_over_limit ){
  18823. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18824. return;
  18825. }
  18826. // The player met all requirements => ask him for confirmation
  18827. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18828. #endif
  18829. }
  18830. enum class e_inventory_expansion_result : uint8{
  18831. SUCCESS = 0,
  18832. FAILED,
  18833. BUSY,
  18834. MISSING_ITEM,
  18835. MAXIMUM_REACHED
  18836. };
  18837. void clif_inventory_expansion_result( struct map_session_data* sd, e_inventory_expansion_result result ){
  18838. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18839. nullpo_retv( sd );
  18840. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18841. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18842. p.result = (uint8)result;
  18843. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18844. // Reset the state tracking
  18845. sd->state.inventory_expansion_confirmation = 0;
  18846. sd->state.inventory_expansion_amount = 0;
  18847. #endif
  18848. }
  18849. void clif_parse_inventory_expansion_confirm( int fd, struct map_session_data* sd ){
  18850. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18851. if( sd->state.inventory_expansion_confirmation == 0 ){
  18852. return;
  18853. }
  18854. // Check if player is dead
  18855. if( pc_isdead( sd ) ){
  18856. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18857. return;
  18858. }
  18859. // Check if the player already reached the maximum
  18860. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18861. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18862. return;
  18863. }
  18864. // Check if the player has the required item
  18865. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18866. // The player did not have the item anymore
  18867. if( index < 0 ){
  18868. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18869. return;
  18870. }
  18871. // Check if the player would exceed the maximum
  18872. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18873. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18874. return;
  18875. }
  18876. // Delete the required item
  18877. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18878. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18879. return;
  18880. }
  18881. // Increase the slots
  18882. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18883. // Save player data (slots) and inventory data (removed item)
  18884. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18885. // Inform the player of success
  18886. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18887. clif_inventory_expansion_info( sd );
  18888. #endif
  18889. }
  18890. void clif_parse_inventory_expansion_reject( int fd, struct map_session_data* sd ){
  18891. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18892. sd->state.inventory_expansion_confirmation = 0;
  18893. sd->state.inventory_expansion_amount = 0;
  18894. #endif
  18895. }
  18896. void clif_barter_open( struct map_session_data& sd, struct npc_data& nd ){
  18897. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18898. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18899. return;
  18900. }
  18901. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18902. if( barter == nullptr ){
  18903. return;
  18904. }
  18905. sd.state.barter_open = true;
  18906. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18907. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18908. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  18909. int16 count = 0;
  18910. for( const auto& itemPair : barter->items ){
  18911. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  18912. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18913. item->nameid = client_nameid( id->nameid );
  18914. item->type = itemtype( id->nameid );
  18915. if( itemPair.second->stockLimited ){
  18916. item->amount = itemPair.second->stock;
  18917. }else{
  18918. item->amount = -1;
  18919. }
  18920. item->weight = id->weight;
  18921. item->index = itemPair.second->index;
  18922. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18923. item->viewSprite = id->look;
  18924. item->location = pc_equippoint_sub( &sd, id.get() );
  18925. #endif
  18926. // Use a loop if someone did not start with index 0
  18927. for( const auto& requirementPair : itemPair.second->requirements ){
  18928. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18929. item->currencyNameid = client_nameid( requirement->nameid );
  18930. item->currencyAmount = requirement->amount;
  18931. // It is a normal barter, cancel after first entry
  18932. break;
  18933. }
  18934. p->packetLength += (int16)( sizeof( *item ) );
  18935. count++;
  18936. }
  18937. clif_send( p, p->packetLength, &sd.bl, SELF );
  18938. #endif
  18939. }
  18940. void clif_parse_barter_close( int fd, struct map_session_data* sd ){
  18941. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18942. if( sd->state.barter_open ){
  18943. sd->npc_shopid = 0;
  18944. sd->state.barter_open = false;
  18945. }
  18946. #endif
  18947. }
  18948. void clif_parse_barter_buy( int fd, struct map_session_data* sd ){
  18949. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18950. // No shop open
  18951. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  18952. return;
  18953. }
  18954. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18955. // Unknown shop
  18956. if( nd == nullptr ){
  18957. return;
  18958. }
  18959. // Not a barter
  18960. if( nd->subtype != NPCTYPE_BARTER ){
  18961. return;
  18962. }
  18963. // It is an extended barter
  18964. if( nd->u.barter.extended ){
  18965. return;
  18966. }
  18967. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  18968. if( barter == nullptr ){
  18969. return;
  18970. }
  18971. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  18972. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  18973. // Empty purchase list
  18974. if( entries == 0 ){
  18975. return;
  18976. }
  18977. std::vector<s_barter_purchase> purchases;
  18978. purchases.reserve( entries );
  18979. // Make sure each shop index and target item id is only used once
  18980. for( int i = 0; i < entries; i++ ){
  18981. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  18982. // Invalid shop index
  18983. if( item == nullptr ){
  18984. return;
  18985. }
  18986. for( int j = i + 1; j < entries; j++ ){
  18987. // Same shop index
  18988. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  18989. return;
  18990. }
  18991. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  18992. // Invalid shop index
  18993. if( item2 == nullptr ){
  18994. return;
  18995. }
  18996. // Same target item id
  18997. if( item->nameid == item2->nameid ){
  18998. return;
  18999. }
  19000. }
  19001. s_barter_purchase purchase = {};
  19002. purchase.item = item;
  19003. purchase.amount = p->list[i].amount;
  19004. purchases.push_back( purchase );
  19005. }
  19006. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19007. #endif
  19008. }
  19009. void clif_barter_extended_open( struct map_session_data& sd, struct npc_data& nd ){
  19010. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19011. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19012. return;
  19013. }
  19014. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19015. if( barter == nullptr ){
  19016. return;
  19017. }
  19018. sd.state.barter_extended_open = true;
  19019. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19020. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19021. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  19022. p->items_count = 0;
  19023. for( const auto& itemPair : barter->items ){
  19024. // Needs dynamic calculation, because of variable currencies
  19025. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  19026. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19027. item->nameid = client_nameid( id->nameid );
  19028. item->type = itemtype( id->nameid );
  19029. if( itemPair.second->stockLimited ){
  19030. item->amount = itemPair.second->stock;
  19031. }else{
  19032. item->amount = -1;
  19033. }
  19034. item->weight = id->weight;
  19035. item->index = itemPair.second->index;
  19036. item->zeny = itemPair.second->price;
  19037. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19038. item->viewSprite = id->look;
  19039. item->location = pc_equippoint_sub( &sd, id.get() );
  19040. #endif
  19041. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19042. p->items_count++;
  19043. item->currency_count = 0;
  19044. for( const auto& requirementPair : itemPair.second->requirements ){
  19045. // Needs dynamic calculation, because of variable currencies
  19046. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19047. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19048. req->nameid = requirement->nameid;
  19049. if( requirement->refine >= 0 ){
  19050. req->refine_level = requirement->refine;
  19051. }else{
  19052. req->refine_level = 0;
  19053. }
  19054. req->amount = requirement->amount;
  19055. req->type = itemtype( requirement->nameid );
  19056. p->packetLength += (int16)( sizeof( *req ) );
  19057. item->currency_count++;
  19058. }
  19059. }
  19060. clif_send( p, p->packetLength, &sd.bl, SELF );
  19061. #endif
  19062. }
  19063. void clif_parse_barter_extended_close( int fd, struct map_session_data* sd ){
  19064. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19065. if( sd->state.barter_extended_open ){
  19066. sd->npc_shopid = 0;
  19067. sd->state.barter_extended_open = false;
  19068. }
  19069. #endif
  19070. }
  19071. void clif_parse_barter_extended_buy( int fd, struct map_session_data* sd ){
  19072. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19073. // No shop open
  19074. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19075. return;
  19076. }
  19077. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19078. // Unknown shop
  19079. if( nd == nullptr ){
  19080. return;
  19081. }
  19082. // Not a barter
  19083. if( nd->subtype != NPCTYPE_BARTER ){
  19084. return;
  19085. }
  19086. // Not an extended barter
  19087. if( !nd->u.barter.extended ){
  19088. return;
  19089. }
  19090. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19091. if( barter == nullptr ){
  19092. return;
  19093. }
  19094. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19095. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19096. // Empty purchase list
  19097. if( entries == 0 ){
  19098. return;
  19099. }
  19100. std::vector<s_barter_purchase> purchases;
  19101. purchases.reserve( entries );
  19102. // Make sure each shop index and target item id is only used once
  19103. for( int i = 0; i < entries; i++ ){
  19104. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19105. // Invalid shop index
  19106. if( item == nullptr ){
  19107. return;
  19108. }
  19109. for( int j = i + 1; j < entries; j++ ){
  19110. // Same shop index
  19111. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19112. return;
  19113. }
  19114. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19115. // Invalid shop index
  19116. if( item2 == nullptr ){
  19117. return;
  19118. }
  19119. // Same target item id
  19120. if( item->nameid == item2->nameid ){
  19121. return;
  19122. }
  19123. }
  19124. s_barter_purchase purchase = {};
  19125. purchase.item = item;
  19126. purchase.amount = p->list[i].amount;
  19127. purchases.push_back( purchase );
  19128. }
  19129. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19130. #endif
  19131. }
  19132. void clif_summon_init(struct mob_data& md) {
  19133. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19134. struct block_list* master_bl = battle_get_master(&md.bl);
  19135. if( master_bl == nullptr ){
  19136. return;
  19137. }
  19138. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19139. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19140. p.summonAID = md.bl.id;
  19141. p.CurrentHP = md.status.hp;
  19142. p.MaxHP = md.status.max_hp;
  19143. clif_send( &p, sizeof( p ), master_bl, SELF );
  19144. #endif
  19145. }
  19146. void clif_summon_hp_bar(struct mob_data& md) {
  19147. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19148. struct block_list* master_bl = battle_get_master(&md.bl);
  19149. if( master_bl == nullptr ){
  19150. return;
  19151. }
  19152. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19153. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19154. p.summonAID = md.bl.id;
  19155. p.VarId = SP_HP; // HP parameter
  19156. p.Value = md.status.hp;
  19157. clif_send( &p, sizeof( p ), master_bl, SELF );
  19158. #endif
  19159. }
  19160. void clif_laphine_synthesis_open( struct map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19161. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19162. nullpo_retv( sd );
  19163. sd->state.laphine_synthesis = synthesis->item_id;
  19164. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19165. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19166. p.itemId = client_nameid( synthesis->item_id );
  19167. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19168. #endif
  19169. }
  19170. void clif_parse_laphine_synthesis_close( int fd, struct map_session_data* sd ){
  19171. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19172. sd->state.laphine_synthesis = 0;
  19173. #endif
  19174. }
  19175. enum e_laphine_synthesis_result : int16{
  19176. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19177. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19178. LAPHINE_SYNTHESIS_ITEM = 7
  19179. };
  19180. void clif_laphine_synthesis_result( struct map_session_data* sd, enum e_laphine_synthesis_result result ){
  19181. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19182. nullpo_retv( sd );
  19183. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19184. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19185. p.result = result;
  19186. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19187. #endif
  19188. }
  19189. void clif_parse_laphine_synthesis( int fd, struct map_session_data* sd ){
  19190. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19191. if( sd->state.laphine_synthesis == 0 ){
  19192. return;
  19193. }
  19194. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19195. if( sd->state.laphine_synthesis != p->itemId ){
  19196. return;
  19197. }
  19198. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19199. if( synthesis == nullptr ){
  19200. return;
  19201. }
  19202. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19203. // Player sent more or less than actually required
  19204. if( count != synthesis->requiredRequirements ){
  19205. return;
  19206. }
  19207. // Check for duplicates
  19208. for( size_t i = 0; i < count; i++ ){
  19209. for( size_t j = i + 1; j < count; j++ ){
  19210. if( p->items[i].index == p->items[j].index ){
  19211. return;
  19212. }
  19213. }
  19214. }
  19215. for( size_t i = 0; i < count; i++ ){
  19216. int16 index = server_index( p->items[i].index );
  19217. if( index >= MAX_INVENTORY ){
  19218. return;
  19219. }
  19220. if( sd->inventory_data[i] == nullptr ){
  19221. return;
  19222. }
  19223. struct item* item = &sd->inventory.u.items_inventory[index];
  19224. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19225. if( requirement == nullptr ){
  19226. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19227. return;
  19228. }
  19229. if( p->items[i].count != requirement->amount ){
  19230. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19231. return;
  19232. }
  19233. if( item->amount < requirement->amount ){
  19234. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19235. return;
  19236. }
  19237. if( item->refine < synthesis->minimumRefine ){
  19238. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19239. return;
  19240. }
  19241. if( item->refine > synthesis->maximumRefine ){
  19242. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19243. return;
  19244. }
  19245. if( item->equip != 0 ){
  19246. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19247. return;
  19248. }
  19249. if( item->equipSwitch != 0 ){
  19250. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19251. return;
  19252. }
  19253. }
  19254. // If triggered from item
  19255. if( sd->itemid == sd->state.laphine_synthesis ){
  19256. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19257. if( index < 0 ){
  19258. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19259. return;
  19260. }
  19261. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19262. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19263. return;
  19264. }
  19265. }
  19266. }
  19267. for( size_t i = 0; i < count; i++ ){
  19268. int16 index = server_index( p->items[i].index );
  19269. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19270. return;
  19271. }
  19272. }
  19273. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19274. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19275. #endif
  19276. }
  19277. void clif_laphine_upgrade_open( struct map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19278. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19279. nullpo_retv( sd );
  19280. sd->state.laphine_upgrade = upgrade->item_id;
  19281. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19282. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19283. p.itemId = client_nameid( upgrade->item_id );
  19284. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19285. #endif
  19286. }
  19287. void clif_parse_laphine_upgrade_close( int fd, struct map_session_data* sd ){
  19288. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19289. sd->state.laphine_upgrade = 0;
  19290. #endif
  19291. }
  19292. void clif_laphine_upgrade_result( struct map_session_data *sd, bool failed ){
  19293. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19294. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19295. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19296. p.result = failed;
  19297. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19298. #endif
  19299. }
  19300. static void clif_item_preview( struct map_session_data *sd, int16 index ){
  19301. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19302. nullpo_retv( sd );
  19303. struct item* item = &sd->inventory.u.items_inventory[index];
  19304. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19305. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19306. p.index = client_index( index );
  19307. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19308. p.isDamaged = item->attribute != 0;
  19309. #endif
  19310. p.refiningLevel = item->refine;
  19311. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19312. p.grade = item->enchantgrade;
  19313. #endif
  19314. clif_addcards( &p.slot, item );
  19315. clif_add_random_options( p.option_data, item );
  19316. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19317. #endif
  19318. }
  19319. void clif_parse_laphine_upgrade( int fd, struct map_session_data* sd ){
  19320. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19321. if( sd->state.laphine_upgrade == 0 ){
  19322. return;
  19323. }
  19324. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19325. if( sd->state.laphine_upgrade != p->itemId ){
  19326. return;
  19327. }
  19328. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19329. if( upgrade == nullptr ){
  19330. return;
  19331. }
  19332. uint16 index = server_index( p->index );
  19333. if( index >= MAX_INVENTORY ){
  19334. return;
  19335. }
  19336. if( sd->inventory_data[index] == nullptr ){
  19337. return;
  19338. }
  19339. struct item* item = &sd->inventory.u.items_inventory[index];
  19340. // Not a valid target item
  19341. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19342. clif_laphine_upgrade_result( sd, true );
  19343. return;
  19344. }
  19345. // If target item is not identified
  19346. if( item->identify == 0 ){
  19347. clif_laphine_upgrade_result( sd, true );
  19348. return;
  19349. }
  19350. // If target item is equipped
  19351. if( item->equip != 0 ){
  19352. clif_laphine_upgrade_result( sd, true );
  19353. return;
  19354. }
  19355. // If target item is in equipswitch
  19356. if( item->equipSwitch != 0 ){
  19357. clif_laphine_upgrade_result( sd, true );
  19358. return;
  19359. }
  19360. // Check minimum refine requirement
  19361. if( item->refine < upgrade->minimumRefine ){
  19362. clif_laphine_upgrade_result( sd, true );
  19363. return;
  19364. }
  19365. // Check maximum refine requirement
  19366. if( item->refine > upgrade->maximumRefine ){
  19367. clif_laphine_upgrade_result( sd, true );
  19368. return;
  19369. }
  19370. // If no cards are allowed
  19371. if( !upgrade->cardsAllowed ){
  19372. for( int i = 0; i < MAX_SLOTS; i++ ){
  19373. if( item->card[i] != 0 ){
  19374. clif_laphine_upgrade_result( sd, true );
  19375. return;
  19376. }
  19377. }
  19378. }
  19379. // If random options are required
  19380. if( upgrade->requiredRandomOptions > 0 ){
  19381. int i;
  19382. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19383. if( item->option[i].id != 0 ){
  19384. break;
  19385. }
  19386. }
  19387. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19388. clif_laphine_upgrade_result( sd, true );
  19389. return;
  19390. }
  19391. }
  19392. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19393. if( index2 < 0 ){
  19394. clif_laphine_upgrade_result( sd, true );
  19395. return;
  19396. }
  19397. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19398. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19399. return;
  19400. }
  19401. }
  19402. // Log removal of item
  19403. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19404. // Visually remove it from the client
  19405. clif_delitem( sd, index, 1, 0 );
  19406. // Apply the random options
  19407. if( upgrade->randomOptionGroup != nullptr ){
  19408. upgrade->randomOptionGroup->apply( *item );
  19409. }
  19410. // Change the refine rate if needed
  19411. if( upgrade->resultRefine > 0 ){
  19412. // Absolute refine level change
  19413. item->refine = max( item->refine, upgrade->resultRefine );
  19414. }else if( upgrade->resultRefineMaximum > 0 ){
  19415. // If a minimum is specified it can also downgrade
  19416. if( upgrade->resultRefineMinimum ){
  19417. item->refine = rnd_value( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum );
  19418. }else{
  19419. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19420. item->refine = rnd_value( item->refine, upgrade->resultRefineMaximum );
  19421. }
  19422. }else if( upgrade->resultRefineMinimum > 0 ){
  19423. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19424. item->refine = rnd_value( upgrade->resultRefineMinimum, MAX_REFINE );
  19425. }
  19426. // Log retrieving the item again -> with the new options
  19427. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19428. // Make it visible for the client again
  19429. clif_additem( sd, index, 1, 0 );
  19430. // Open a preview of the item
  19431. clif_item_preview( sd, index );
  19432. // Tell the client we are done
  19433. clif_laphine_upgrade_result( sd, false );
  19434. #endif
  19435. }
  19436. void clif_enchantgrade_add( struct map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19437. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19438. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19439. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19440. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19441. if( index < UINT16_MAX ){
  19442. p->index = client_index( index );
  19443. if( sd.inventory.u.items_inventory[index].refine >= gradeLevel->refine ){
  19444. p->success_chance = gradeLevel->chance / 100;
  19445. }else{
  19446. p->success_chance = 0;
  19447. }
  19448. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19449. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19450. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19451. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19452. // Not displayed by client
  19453. p->protect_itemid = 0;
  19454. p->protect_amount = 0;
  19455. int i = 0;
  19456. for( const auto& pair : gradeLevel->options ){
  19457. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19458. p->material_info[i].nameid = client_nameid( option->item );
  19459. p->material_info[i].amount = option->amount;
  19460. p->material_info[i].price = option->zeny;
  19461. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19462. p->material_info[i].breakable = option->breaking_rate > 0;
  19463. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19464. i++;
  19465. }
  19466. }else{
  19467. p->index = -1;
  19468. p->success_chance = 0;
  19469. p->blessing_info.id = 0;
  19470. p->blessing_info.amount = 0;
  19471. p->blessing_info.max_blessing = 0;
  19472. p->blessing_info.bonus = 0;
  19473. p->protect_itemid = 0;
  19474. p->protect_amount = 0;
  19475. }
  19476. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19477. #endif
  19478. }
  19479. void clif_parse_enchantgrade_add( int fd, struct map_session_data* sd ){
  19480. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19481. nullpo_retv( sd );
  19482. if( !sd->state.enchantgrade_open ){
  19483. return;
  19484. }
  19485. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19486. uint16 index = server_index( p->index );
  19487. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19488. return;
  19489. }
  19490. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19491. // Unsupported item type - no answer, because client should have actually prevented this request
  19492. if( enchantgrade == nullptr ){
  19493. return;
  19494. }
  19495. // Item can't be enhanced
  19496. if( !sd->inventory_data[index]->flag.gradable ){
  19497. return;
  19498. }
  19499. uint16 level = 0;
  19500. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19501. level = sd->inventory_data[index]->weapon_level;
  19502. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19503. level = sd->inventory_data[index]->armor_level;
  19504. }
  19505. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19506. // Cannot upgrade this weapon or armor level
  19507. if( enchantgradelevels == enchantgrade->levels.end() ){
  19508. clif_enchantgrade_add( *sd );
  19509. return;
  19510. }
  19511. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19512. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19513. if( enchantgradelevel == nullptr ){
  19514. return;
  19515. }
  19516. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19517. #endif
  19518. }
  19519. /// <summary>
  19520. /// Sends the result for trying to enchant an item
  19521. /// </summary>
  19522. /// <param name="sd">The player session</param>
  19523. /// <param name="index">The target item</param>
  19524. /// <param name="result">
  19525. /// 0= The grade has been successfully upgraded.
  19526. /// 1= Refinement failed.
  19527. /// 2= The refine level has decreased.
  19528. /// 3= Equipment destroyed.
  19529. /// 4= The equipment is protected.
  19530. /// </param>
  19531. void clif_enchantgrade_result( struct map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19532. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19533. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19534. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19535. p.index = client_index( index );
  19536. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19537. p.result = result;
  19538. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19539. #endif
  19540. }
  19541. void clif_enchantgrade_announce( struct map_session_data& sd, struct item& item, bool success ){
  19542. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19543. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19544. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19545. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19546. p.itemId = client_nameid( item.nameid );
  19547. p.grade = item.enchantgrade;
  19548. p.status = success;
  19549. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19550. #endif
  19551. }
  19552. void clif_parse_enchantgrade_start( int fd, struct map_session_data* sd ){
  19553. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19554. nullpo_retv( sd );
  19555. if( !sd->state.enchantgrade_open ){
  19556. return;
  19557. }
  19558. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19559. uint16 index = server_index( p->index );
  19560. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19561. return;
  19562. }
  19563. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19564. // Unsupported item type - no answer
  19565. if( enchantgrade == nullptr ){
  19566. return;
  19567. }
  19568. uint16 level = 0;
  19569. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19570. level = sd->inventory_data[index]->weapon_level;
  19571. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19572. level = sd->inventory_data[index]->armor_level;
  19573. }
  19574. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19575. // Cannot upgrade this weapon or armor level - no answer
  19576. if( enchantgradelevels == enchantgrade->levels.end() ){
  19577. return;
  19578. }
  19579. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19580. // Cannot increase enchantgrade any further - no answer
  19581. if( enchantgradelevel == nullptr ){
  19582. return;
  19583. }
  19584. // Not refined enough
  19585. if( sd->inventory.u.items_inventory[index].refine < enchantgradelevel->refine ){
  19586. return;
  19587. }
  19588. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19589. // Unknown option id - no answer
  19590. if( option == nullptr ){
  19591. return;
  19592. }
  19593. // Not enough zeny
  19594. if( sd->status.zeny < option->zeny ){
  19595. return;
  19596. }
  19597. uint16 totalChance = enchantgradelevel->chance;
  19598. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19599. std::unordered_map<uint16, uint16> requiredItems;
  19600. if( p->blessing_flag ){
  19601. // If the catalysator item is the same as the option item build the sum of amounts
  19602. if( enchantgradelevel->catalyst.item == option->item ){
  19603. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19604. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19605. if( index < 0 ){
  19606. return;
  19607. }
  19608. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19609. return;
  19610. }
  19611. requiredItems[index] = amount;
  19612. }else{
  19613. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19614. // Check catalysator item
  19615. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19616. if( index < 0 ){
  19617. return;
  19618. }
  19619. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19620. return;
  19621. }
  19622. requiredItems[index] = amount;
  19623. // Check option item
  19624. index = pc_search_inventory( sd, option->item );
  19625. if( index < 0 ){
  19626. return;
  19627. }
  19628. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19629. return;
  19630. }
  19631. requiredItems[index] = option->amount;
  19632. }
  19633. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19634. }else{
  19635. // Check option item
  19636. int16 index = pc_search_inventory( sd, option->item );
  19637. if( index < 0 ){
  19638. return;
  19639. }
  19640. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19641. return;
  19642. }
  19643. requiredItems[index] = option->amount;
  19644. }
  19645. // All items should be there, start deleting
  19646. for( const auto& pair : requiredItems ){
  19647. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19648. return;
  19649. }
  19650. }
  19651. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE, nullptr ) > 0 ){
  19652. return;
  19653. }
  19654. if( rnd()%10000 < totalChance ){
  19655. // Log removal of item
  19656. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19657. // Increase enchantgrade
  19658. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19659. // On successful enchantgrade increase the refine is reset
  19660. sd->inventory.u.items_inventory[index].refine = 0;
  19661. // Log retrieving the item again -> with the new refine and enchantgrade
  19662. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19663. // Show success
  19664. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19665. // Check if it has to be announced
  19666. if( enchantgradelevel->announce ){
  19667. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19668. }
  19669. }else{
  19670. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19671. if( enchantgradelevel->announce ){
  19672. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19673. }
  19674. // Delete the item if it is breakable
  19675. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19676. // Delete the item
  19677. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19678. // Show failure
  19679. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19680. // Downgrade the item if necessary
  19681. }else if( option->downgrade_amount > 0 ){
  19682. // Log removal of item
  19683. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19684. // Decrease refine level
  19685. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19686. // Log retrieving the item again -> with the new refine
  19687. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19688. // Show downgrade
  19689. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19690. // Only show failure, but dont do anything
  19691. }else{
  19692. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19693. }
  19694. }
  19695. #endif
  19696. }
  19697. void clif_parse_enchantgrade_close( int fd, struct map_session_data* sd ){
  19698. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19699. nullpo_retv( sd );
  19700. sd->state.enchantgrade_open = false;
  19701. #endif
  19702. }
  19703. void clif_reputation_type( struct map_session_data& sd, int64 type, int64 points ){
  19704. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19705. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19706. p->packetType = HEADER_ZC_REPUTE_INFO;
  19707. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19708. p->success = true;
  19709. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19710. entry->type = type;
  19711. entry->points = points;
  19712. clif_send( p, p->packetLength, &sd.bl, SELF );
  19713. #endif
  19714. }
  19715. void clif_reputation_list( struct map_session_data& sd ){
  19716. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19717. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19718. p->packetType = HEADER_ZC_REPUTE_INFO;
  19719. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19720. p->success = true;
  19721. size_t index = 0;
  19722. for( const auto& entry : reputation_db ){
  19723. std::shared_ptr<s_reputation> reputation = entry.second;
  19724. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19725. list_entry->type = reputation->id;
  19726. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19727. p->packetLength += sizeof( *list_entry );
  19728. index++;
  19729. }
  19730. clif_send( p, p->packetLength, &sd.bl, SELF );
  19731. #endif
  19732. }
  19733. void clif_item_reform_open( struct map_session_data& sd, t_itemid item ){
  19734. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19735. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19736. p.packetType = HEADER_ZC_OPEN_REFORM_UI;
  19737. p.itemId = item;
  19738. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19739. sd.state.item_reform = item;
  19740. #endif
  19741. }
  19742. void clif_parse_item_reform_close( int fd, struct map_session_data* sd ){
  19743. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19744. sd->state.item_reform = 0;
  19745. #endif
  19746. }
  19747. void clif_item_reform_result( struct map_session_data& sd, uint16 index, uint8 result ){
  19748. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19749. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19750. p.packetType = HEADER_ZC_ITEM_REFORM_ACK;
  19751. p.index = client_index( index );
  19752. p.result = result;
  19753. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19754. if( result == 0 ){
  19755. // Client closes the window on success
  19756. sd.state.item_reform = 0;
  19757. }
  19758. #endif
  19759. }
  19760. void clif_parse_item_reform_start( int fd, struct map_session_data* sd ){
  19761. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19762. // Not opened
  19763. if( sd->state.item_reform == 0 ){
  19764. return;
  19765. }
  19766. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19767. // Item mismatch
  19768. if( p->itemId != sd->state.item_reform ){
  19769. return;
  19770. }
  19771. uint16 index = server_index( p->index );
  19772. if( index >= MAX_INVENTORY ){
  19773. return;
  19774. }
  19775. if( sd->inventory_data[index] == nullptr ){
  19776. return;
  19777. }
  19778. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19779. if( reform == nullptr ){
  19780. return;
  19781. }
  19782. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19783. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19784. if( base == nullptr ){
  19785. return;
  19786. }
  19787. // If target item is not identified
  19788. if( selected_item.identify == 0 ){
  19789. return;
  19790. }
  19791. // If target item is equipped
  19792. if( selected_item.equip != 0 ){
  19793. return;
  19794. }
  19795. // Check minimum refine requirement
  19796. if( selected_item.refine < base->minimumRefine ){
  19797. return;
  19798. }
  19799. // Check maximum refine requirement
  19800. if( selected_item.refine > base->maximumRefine ){
  19801. return;
  19802. }
  19803. // If no cards are allowed
  19804. if( !base->cardsAllowed ){
  19805. for( int i = 0; i < MAX_SLOTS; i++ ){
  19806. if( selected_item.card[i] != 0 ){
  19807. return;
  19808. }
  19809. }
  19810. }
  19811. // If random options are required
  19812. if( base->requiredRandomOptions > 0 ){
  19813. int i;
  19814. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19815. if( selected_item.option[i].id != 0 ){
  19816. break;
  19817. }
  19818. }
  19819. if( ( i + 1 ) < base->requiredRandomOptions ){
  19820. return;
  19821. }
  19822. }
  19823. std::unordered_map<uint16, uint16> materials;
  19824. // Check if all materials exist
  19825. for( const auto& material : base->materials ){
  19826. int16 material_index = pc_search_inventory( sd, material.first );
  19827. if( material_index < 0 ){
  19828. return;
  19829. }
  19830. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19831. return;
  19832. }
  19833. materials[material_index] = material.second;
  19834. }
  19835. // Remove the material
  19836. for( const auto& material : materials ){
  19837. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19838. return;
  19839. }
  19840. }
  19841. // If triggered from item
  19842. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19843. return;
  19844. }
  19845. // Log removal of item
  19846. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19847. // Visually remove it from the client
  19848. clif_delitem( sd, index, 1, 0 );
  19849. // Apply the random options
  19850. if( base->randomOptionGroup != nullptr ){
  19851. base->randomOptionGroup->apply( selected_item );
  19852. }
  19853. // Change the refine rate if needed
  19854. if( base->refineChange != 0 ){
  19855. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19856. }
  19857. // Remove all cards and socket enchants
  19858. if( base->clearSlots ){
  19859. for( int i = 0; i < MAX_SLOTS; i++ ){
  19860. selected_item.card[i] = 0;
  19861. }
  19862. }
  19863. // Remove the current enchantgrade
  19864. if( base->removeEnchantgrade ){
  19865. selected_item.enchantgrade = 0;
  19866. }
  19867. // Finally change the item id
  19868. selected_item.nameid = base->resultItemId;
  19869. // Link inventory data cache to the new item
  19870. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19871. // Log retrieving the item again -> with the new options
  19872. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19873. // Make it visible for the client again
  19874. clif_additem( sd, index, 1, 0 );
  19875. clif_item_reform_result( *sd, index, 0 );
  19876. #endif
  19877. }
  19878. void clif_enchantwindow_open( struct map_session_data& sd, uint64 clientLuaIndex ){
  19879. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19880. // Hardcoded clientside check
  19881. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19882. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  19883. sd.state.item_enchant_index = 0;
  19884. return;
  19885. }
  19886. struct PACKET_ZC_UI_OPEN_V3 p = {};
  19887. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19888. p.type = OUT_UI_ENCHANT;
  19889. p.data = clientLuaIndex;
  19890. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19891. sd.state.item_enchant_index = clientLuaIndex;
  19892. #endif
  19893. }
  19894. void clif_enchantwindow_result( struct map_session_data& sd, bool success, t_itemid enchant = 0 ){
  19895. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19896. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  19897. p.packetType = HEADER_ZC_RESPONSE_ENCHANT;
  19898. if( success ){
  19899. p.messageId = C_ENCHANT_SUCCESS;
  19900. }else{
  19901. p.messageId = C_ENCHANT_FAILURE;
  19902. }
  19903. p.enchantItemId = enchant;
  19904. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19905. sd.state.item_enchant_index = 0;
  19906. #endif
  19907. }
  19908. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  19909. if( selected_item.equip != 0 ){
  19910. return false;
  19911. }
  19912. if( selected_item.equipSwitch != 0 ){
  19913. return false;
  19914. }
  19915. if( selected_item.attribute != 0 ){
  19916. return false;
  19917. }
  19918. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  19919. return false;
  19920. }
  19921. if( selected_item.refine < enchant->minimumRefine ){
  19922. return false;
  19923. }
  19924. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  19925. return false;
  19926. }
  19927. if( !enchant->allowRandomOptions ){
  19928. for( const s_item_randomoption& option : selected_item.option ){
  19929. if( option.id != 0 ){
  19930. return false;
  19931. }
  19932. }
  19933. }
  19934. return true;
  19935. }
  19936. void clif_parse_enchantwindow_general( int fd, struct map_session_data* sd ){
  19937. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19938. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  19939. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19940. return;
  19941. }
  19942. uint16 index = server_index( p->index );
  19943. if( index >= MAX_INVENTORY ){
  19944. return;
  19945. }
  19946. if( sd->inventory_data[index] == nullptr ){
  19947. return;
  19948. }
  19949. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19950. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  19951. if( enchant == nullptr ){
  19952. return;
  19953. }
  19954. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19955. return;
  19956. }
  19957. uint16 slot = MAX_SLOTS;
  19958. for( uint16 nextSlot : enchant->order ){
  19959. if( selected_item.card[nextSlot] == 0 ){
  19960. slot = nextSlot;
  19961. break;
  19962. }
  19963. }
  19964. if( slot == MAX_SLOTS ){
  19965. return;
  19966. }
  19967. if( slot < sd->inventory_data[index]->slots ){
  19968. return;
  19969. }
  19970. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19971. if( enchant_slot == nullptr ){
  19972. return;
  19973. }
  19974. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  19975. if( enchants_for_enchantgrade == nullptr ){
  19976. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  19977. clif_enchantwindow_result( *sd, false );
  19978. return;
  19979. }
  19980. if( sd->status.zeny < enchant_slot->normal.zeny ){
  19981. return;
  19982. }
  19983. std::unordered_map<uint16, uint16> materials;
  19984. for( const auto& entry : enchant_slot->normal.materials ){
  19985. int16 idx = pc_search_inventory( sd, entry.first );
  19986. if( idx < 0 ){
  19987. return;
  19988. }
  19989. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19990. return;
  19991. }
  19992. materials[idx] = entry.second;
  19993. }
  19994. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  19995. return;
  19996. }
  19997. for( const auto& entry : materials ){
  19998. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  19999. return;
  20000. }
  20001. }
  20002. uint32 chance = enchant_slot->normal.chance;
  20003. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  20004. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  20005. }
  20006. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20007. clif_enchantwindow_result( *sd, false );
  20008. return;
  20009. }
  20010. // Log removal of item
  20011. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20012. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  20013. bool enchanted = false;
  20014. for( int i = 0; i < maximum; i++ ){
  20015. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20016. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  20017. selected_item.card[slot] = normal_enchant->item_id;
  20018. enchanted = true;
  20019. break;
  20020. }
  20021. }
  20022. if( !enchanted ){
  20023. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20024. selected_item.card[slot] = normal_enchant->item_id;
  20025. }
  20026. // Log retrieving the item again -> with the new enchant
  20027. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20028. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20029. #endif
  20030. }
  20031. void clif_parse_enchantwindow_perfect( int fd, struct map_session_data* sd ){
  20032. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20033. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  20034. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20035. return;
  20036. }
  20037. uint16 index = server_index( p->index );
  20038. if( index >= MAX_INVENTORY ){
  20039. return;
  20040. }
  20041. if( sd->inventory_data[index] == nullptr ){
  20042. return;
  20043. }
  20044. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20045. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20046. if( enchant == nullptr ){
  20047. return;
  20048. }
  20049. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20050. return;
  20051. }
  20052. uint16 slot = MAX_SLOTS;
  20053. for( uint16 nextSlot : enchant->order ){
  20054. if( selected_item.card[nextSlot] == 0 ){
  20055. slot = nextSlot;
  20056. break;
  20057. }
  20058. }
  20059. if( slot == MAX_SLOTS ){
  20060. return;
  20061. }
  20062. if( slot < sd->inventory_data[index]->slots ){
  20063. return;
  20064. }
  20065. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20066. if( enchant_slot == nullptr ){
  20067. return;
  20068. }
  20069. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->itemId );
  20070. if( perfect_enchant == nullptr ){
  20071. return;
  20072. }
  20073. if( sd->status.zeny < perfect_enchant->zeny ){
  20074. return;
  20075. }
  20076. std::unordered_map<uint16, uint16> materials;
  20077. for( const auto& entry : perfect_enchant->materials ){
  20078. int16 idx = pc_search_inventory( sd, entry.first );
  20079. if( idx < 0 ){
  20080. return;
  20081. }
  20082. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20083. return;
  20084. }
  20085. materials[idx] = entry.second;
  20086. }
  20087. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20088. return;
  20089. }
  20090. for( const auto& entry : materials ){
  20091. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20092. return;
  20093. }
  20094. }
  20095. // Log removal of item
  20096. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20097. selected_item.card[slot] = perfect_enchant->item_id;
  20098. // Log retrieving the item again -> with the new enchant
  20099. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20100. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20101. #endif
  20102. }
  20103. void clif_parse_enchantwindow_upgrade( int fd, struct map_session_data* sd ){
  20104. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20105. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20106. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20107. return;
  20108. }
  20109. uint16 index = server_index( p->index );
  20110. if( index >= MAX_INVENTORY ){
  20111. return;
  20112. }
  20113. if( sd->inventory_data[index] == nullptr ){
  20114. return;
  20115. }
  20116. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20117. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20118. if( enchant == nullptr ){
  20119. return;
  20120. }
  20121. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20122. return;
  20123. }
  20124. uint16 slot = p->slot;
  20125. if( slot >= MAX_SLOTS ){
  20126. return;
  20127. }
  20128. if( slot < sd->inventory_data[index]->slots ){
  20129. return;
  20130. }
  20131. if( selected_item.card[slot] == 0 ){
  20132. return;
  20133. }
  20134. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20135. if( enchant_slot == nullptr ){
  20136. return;
  20137. }
  20138. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20139. if( upgrade == nullptr ){
  20140. return;
  20141. }
  20142. if( sd->status.zeny < upgrade->zeny ){
  20143. return;
  20144. }
  20145. std::unordered_map<uint16, uint16> materials;
  20146. for( const auto& entry : upgrade->materials ){
  20147. int16 idx = pc_search_inventory( sd, entry.first );
  20148. if( idx < 0 ){
  20149. return;
  20150. }
  20151. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20152. return;
  20153. }
  20154. materials[idx] = entry.second;
  20155. }
  20156. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20157. return;
  20158. }
  20159. for( const auto& entry : materials ){
  20160. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20161. return;
  20162. }
  20163. }
  20164. // Log removal of item
  20165. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20166. selected_item.card[slot] = upgrade->upgrade_item_id;
  20167. // Log retrieving the item again -> with the new enchant
  20168. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20169. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20170. #endif
  20171. }
  20172. void clif_parse_enchantwindow_reset( int fd, struct map_session_data* sd ){
  20173. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20174. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20175. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  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. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20186. if( selected_item.equip != 0 ){
  20187. return;
  20188. }
  20189. if( selected_item.equipSwitch != 0 ){
  20190. return;
  20191. }
  20192. if( selected_item.attribute != 0 ){
  20193. return;
  20194. }
  20195. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20196. if( enchant == nullptr ){
  20197. return;
  20198. }
  20199. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20200. return;
  20201. }
  20202. if( selected_item.refine < enchant->minimumRefine ){
  20203. return;
  20204. }
  20205. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20206. return;
  20207. }
  20208. bool is_enchanted = false;
  20209. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20210. if( selected_item.card[i] != 0 ){
  20211. is_enchanted = true;
  20212. break;
  20213. }
  20214. }
  20215. if( !is_enchanted ){
  20216. return;
  20217. }
  20218. if( sd->status.zeny < enchant->reset.zeny ){
  20219. return;
  20220. }
  20221. std::unordered_map<uint16, uint16> materials;
  20222. for( const auto& entry : enchant->reset.materials ){
  20223. int16 idx = pc_search_inventory( sd, entry.first );
  20224. if( idx < 0 ){
  20225. return;
  20226. }
  20227. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20228. return;
  20229. }
  20230. materials[idx] = entry.second;
  20231. }
  20232. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20233. return;
  20234. }
  20235. for( const auto& entry : materials ){
  20236. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20237. return;
  20238. }
  20239. }
  20240. uint32 chance = enchant->reset.chance;
  20241. if( chance == 0 ){
  20242. return;
  20243. }
  20244. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20245. clif_enchantwindow_result( *sd, false );
  20246. return;
  20247. }
  20248. // Log removal of item
  20249. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20250. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20251. selected_item.card[i] = 0;
  20252. }
  20253. // Log retrieving the item again -> with the new enchant
  20254. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20255. clif_enchantwindow_result( *sd, true );
  20256. #endif
  20257. }
  20258. void clif_parse_enchantwindow_close( int fd, struct map_session_data* sd ){
  20259. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20260. sd->state.item_enchant_index = 0;
  20261. #endif
  20262. }
  20263. void clif_parse_itempackage_select( int fd, struct map_session_data* sd ){
  20264. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20265. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20266. if( p->AID != sd->status.account_id ){
  20267. return;
  20268. }
  20269. uint16 index = server_index( p->index );
  20270. if( index >= MAX_INVENTORY ){
  20271. return;
  20272. }
  20273. if( sd->inventory_data[index] == nullptr ){
  20274. return;
  20275. }
  20276. if( sd->inventory_data[index]->nameid != p->itemID ){
  20277. return;
  20278. }
  20279. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20280. return;
  20281. }
  20282. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20283. if( package == nullptr ){
  20284. return;
  20285. }
  20286. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20287. if( group == nullptr ){
  20288. return;
  20289. }
  20290. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20291. return;
  20292. }
  20293. for( const auto& entry : group->items ){
  20294. struct item item = {};
  20295. item.nameid = entry.second->item_id;
  20296. item.identify = 1;
  20297. item.refine = (char)entry.second->refine;
  20298. if( entry.second->rentalhours ){
  20299. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20300. }
  20301. // Check if it is a pet egg
  20302. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20303. if( pet != nullptr ){
  20304. for( int i = 0; i < entry.second->amount; i++ ){
  20305. pet_create_egg( sd, item.nameid );
  20306. }
  20307. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20308. for( int i = 0; i < entry.second->amount; i++ ){
  20309. // New random options on each iteration
  20310. if( entry.second->randomOptionGroup != nullptr ){
  20311. entry.second->randomOptionGroup->apply( item );
  20312. }
  20313. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20314. }
  20315. }else{
  20316. if( entry.second->randomOptionGroup != nullptr ){
  20317. entry.second->randomOptionGroup->apply( item );
  20318. }
  20319. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20320. }
  20321. }
  20322. #endif
  20323. }
  20324. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20325. {
  20326. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20327. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20328. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20329. p.itemId = itemId;
  20330. p.refine_level = level;
  20331. p.status = (int8)success;
  20332. if (battle_config.broadcast_hide_name) {
  20333. std::string dispname = clif_hide_name(sd.status.name);
  20334. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20335. }
  20336. else {
  20337. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20338. }
  20339. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20340. #endif
  20341. }
  20342. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20343. #if PACKETVER >= 20160316
  20344. nullpo_retv(sd);
  20345. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20346. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20347. return;
  20348. }
  20349. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20350. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20351. #endif
  20352. }
  20353. void clif_captcha_upload_request(map_session_data &sd) {
  20354. #if PACKETVER >= 20160330
  20355. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20356. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20357. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20358. if (sd.captcha_upload.cd != nullptr) {
  20359. p.captchaFlag = 0;
  20360. } else {
  20361. p.captchaFlag = 1;
  20362. }
  20363. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20364. #endif
  20365. }
  20366. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20367. #if PACKETVER >= 20160316
  20368. nullpo_retv(sd);
  20369. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20370. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20371. return;
  20372. }
  20373. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20374. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20375. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20376. return;
  20377. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20378. return;
  20379. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20380. #endif
  20381. }
  20382. void clif_captcha_upload_end(map_session_data &sd) {
  20383. #if PACKETVER >= 20160330
  20384. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20385. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20386. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20387. #endif
  20388. }
  20389. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20390. #if PACKETVER >= 20160323
  20391. nullpo_retv(sd);
  20392. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20393. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20394. return;
  20395. }
  20396. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20397. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20398. #endif
  20399. }
  20400. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20401. #if PACKETVER >= 20160330
  20402. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20403. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20404. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20405. if (cd == nullptr) {
  20406. p.captchaFlag = 1;
  20407. p.imageSize = 0;
  20408. } else {
  20409. p.captchaFlag = 0;
  20410. p.imageSize = cd->image_size;
  20411. }
  20412. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20413. if (cd != nullptr) {
  20414. for (uint16 offset = 0; offset < cd->image_size;) {
  20415. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20416. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20417. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20418. p2->PacketLength = (int16)(sizeof(PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20419. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20420. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20421. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20422. offset += chunk_size;
  20423. }
  20424. }
  20425. #endif
  20426. }
  20427. void clif_macro_detector_request(map_session_data &sd) {
  20428. #if PACKETVER >= 20160330
  20429. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20430. if (cd == nullptr) {
  20431. return;
  20432. }
  20433. // Send preview initialization request to the client.
  20434. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20435. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20436. p.imageSize = cd->image_size;
  20437. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20438. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20439. for (uint16 offset = 0; offset < cd->image_size;) {
  20440. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20441. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20442. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20443. p2->PacketLength = (int16)(sizeof(PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20444. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20445. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20446. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20447. offset += chunk_size;
  20448. }
  20449. #endif
  20450. }
  20451. void clif_macro_detector_request_show(map_session_data &sd) {
  20452. #if PACKETVER >= 20160330
  20453. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20454. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20455. p.retryCount = sd.macro_detect.retry;
  20456. p.timeout = battle_config.macro_detection_timeout;
  20457. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20458. #endif
  20459. }
  20460. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20461. #if PACKETVER >= 20160316
  20462. nullpo_retv(sd);
  20463. if (sd->macro_detect.retry != 0) {
  20464. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20465. clif_macro_detector_request_show(*sd);
  20466. }
  20467. #endif
  20468. }
  20469. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20470. #if PACKETVER >= 20160316
  20471. nullpo_retv(sd);
  20472. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20473. pc_macro_detector_process_answer(*sd, p->answer);
  20474. #endif
  20475. }
  20476. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20477. #if PACKETVER >= 20160330
  20478. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20479. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20480. p.status = stype;
  20481. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20482. #endif
  20483. }
  20484. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20485. #if PACKETVER >= 20160330
  20486. nullpo_retv(sd);
  20487. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20488. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20489. return;
  20490. }
  20491. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20492. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20493. #endif
  20494. }
  20495. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20496. #if PACKETVER >= 20160330
  20497. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *p = (PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *)packet_buffer;
  20498. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20499. p->PacketLength = static_cast<int16>(sizeof(PACKET_ZC_ACK_PLAYER_AID_IN_RANGE) + sizeof(uint32) * aid_list.size());
  20500. for (size_t i = 0; i < aid_list.size(); i++)
  20501. p->AID[i] = aid_list[static_cast<int32>(i)];
  20502. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20503. #endif
  20504. }
  20505. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20506. #if PACKETVER >= 20160316
  20507. nullpo_retv(sd);
  20508. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20509. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20510. return;
  20511. }
  20512. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20513. map_session_data *tsd = map_id2sd(p->AID);
  20514. if (tsd == nullptr) {
  20515. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20516. return;
  20517. }
  20518. if (tsd->macro_detect.retry != 0) {
  20519. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20520. return;
  20521. }
  20522. if (captcha_db.empty()) {
  20523. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20524. return;
  20525. }
  20526. pc_macro_reporter_process(*sd, *tsd);
  20527. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20528. #endif
  20529. }
  20530. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20531. #if PACKETVER >= 20160330
  20532. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20533. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20534. p.status = stype;
  20535. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20536. #endif
  20537. }
  20538. /*==========================================
  20539. * Main client packet processing function
  20540. *------------------------------------------*/
  20541. static int clif_parse(int fd)
  20542. {
  20543. int cmd, packet_len;
  20544. TBL_PC* sd;
  20545. int pnum;
  20546. #ifdef PACKET_OBFUSCATION
  20547. int cmd2;
  20548. #endif
  20549. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20550. // Note: "click masters" can do 80+ clicks in 10 seconds
  20551. 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]
  20552. { // begin main client packet processing loop
  20553. sd = (TBL_PC *)session[fd]->session_data;
  20554. if (session[fd]->flag.eof) {
  20555. if (sd) {
  20556. if (sd->state.autotrade) {
  20557. //Disassociate character from the socket connection.
  20558. session[fd]->session_data = NULL;
  20559. sd->fd = 0;
  20560. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20561. } else
  20562. if (sd->state.active) {
  20563. // Player logout display [Valaris]
  20564. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20565. clif_quitsave(fd, sd);
  20566. } else {
  20567. //Unusual logout (during log on/off/map-changer procedure)
  20568. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20569. map_quit(sd);
  20570. }
  20571. } else {
  20572. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20573. }
  20574. do_close(fd);
  20575. return 0;
  20576. }
  20577. if (RFIFOREST(fd) < 2)
  20578. return 0;
  20579. cmd = RFIFOW(fd, 0);
  20580. #ifdef PACKET_OBFUSCATION
  20581. // Check if it is a player that tries to connect to the map server.
  20582. if( sd ){
  20583. // Decrypt the current packet ID with the last key stored in the session.
  20584. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20585. }else{
  20586. // Store the original value for checking
  20587. cmd2 = cmd;
  20588. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20589. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20590. }
  20591. #endif
  20592. // filter out invalid / unsupported packets
  20593. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20594. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20595. #ifdef DUMP_INVALID_PACKET
  20596. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20597. #endif
  20598. #ifdef PACKET_OBFUSCATION_WARN
  20599. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20600. if( !sd ){
  20601. #ifdef PACKET_OBFUSCATION
  20602. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20603. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20604. }
  20605. #else
  20606. // Try to use the initial keys for the decryption of the packet ID.
  20607. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20608. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20609. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20610. }
  20611. #endif
  20612. }
  20613. #endif
  20614. set_eof(fd);
  20615. return 0;
  20616. }
  20617. // determine real packet length
  20618. packet_len = packet_db[cmd].len;
  20619. if (packet_len == -1) { // variable-length packet
  20620. if (RFIFOREST(fd) < 4)
  20621. return 0;
  20622. packet_len = RFIFOW(fd,2);
  20623. if (packet_len < 4 || packet_len > 32768) {
  20624. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20625. #ifdef DUMP_INVALID_PACKET
  20626. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20627. #endif
  20628. set_eof(fd);
  20629. return 0;
  20630. }
  20631. }
  20632. if ((int)RFIFOREST(fd) < packet_len){
  20633. 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 );
  20634. #ifdef DUMP_INVALID_PACKET
  20635. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20636. #endif
  20637. set_eof( fd );
  20638. return 0; // not enough data received to form the packet
  20639. }
  20640. #ifdef PACKET_OBFUSCATION
  20641. RFIFOW(fd, 0) = cmd;
  20642. if (sd)
  20643. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20644. #endif
  20645. if( packet_db[cmd].func == clif_parse_debug )
  20646. packet_db[cmd].func(fd, sd);
  20647. else if( packet_db[cmd].func != NULL ) {
  20648. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20649. ; //Only valid packet when there is no session
  20650. else
  20651. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20652. ; //Only valid packet when player is not on a map
  20653. else
  20654. packet_db[cmd].func(fd, sd);
  20655. }
  20656. #ifdef DUMP_UNKNOWN_PACKET
  20657. else DumpUnknown(fd,sd,cmd,packet_len);
  20658. #endif
  20659. RFIFOSKIP(fd, packet_len);
  20660. }; // main loop end
  20661. return 0;
  20662. }
  20663. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  20664. va_list argp;
  20665. int i;
  20666. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20667. return;
  20668. packet_db[cmd].len = length;
  20669. packet_db[cmd].func = func;
  20670. va_start(argp, func);
  20671. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20672. int offset = va_arg(argp, int);
  20673. if( offset == 0 ){
  20674. break;
  20675. }
  20676. packet_db[cmd].pos[i] = offset;
  20677. }
  20678. if( i == MAX_PACKET_POS ){
  20679. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20680. }
  20681. va_end(argp);
  20682. }
  20683. /*==========================================
  20684. * Reads packets and setups its array reference
  20685. *------------------------------------------*/
  20686. void packetdb_readdb(){
  20687. memset(packet_db,0,sizeof(packet_db));
  20688. memset(packet_db_ack,0,sizeof(packet_db_ack));
  20689. #include "clif_packetdb.hpp"
  20690. #include "clif_shuffle.hpp"
  20691. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20692. #ifdef PACKET_OBFUSCATION
  20693. 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]);
  20694. #else
  20695. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20696. #endif
  20697. }
  20698. /*==========================================
  20699. *
  20700. *------------------------------------------*/
  20701. void do_init_clif(void) {
  20702. const char* colors[COLOR_MAX] = {
  20703. "0x00FF00",
  20704. "0xFF0000",
  20705. "0xFFFFFF",
  20706. "0xFFFF00",
  20707. "0x00FFFF",
  20708. "0xB5FFB5",
  20709. };
  20710. int i;
  20711. /**
  20712. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20713. **/
  20714. for(i = 0; i < COLOR_MAX; i++) {
  20715. color_table[i] = strtoul(colors[i],NULL,0);
  20716. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  20717. }
  20718. packetdb_readdb();
  20719. set_defaultparse(clif_parse);
  20720. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20721. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20722. exit(EXIT_FAILURE);
  20723. }
  20724. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20725. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20726. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20727. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20728. if( battle_config.ping_timer_interval > 0 ){
  20729. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20730. }
  20731. #endif
  20732. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20733. }
  20734. void do_final_clif(void) {
  20735. ers_destroy(delay_clearunit_ers);
  20736. }