clif.cpp 713 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933
  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.GID = sd.bl.id;
  1345. p.amount = 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.GID = sd.bl.id;
  1355. p.amount = 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, int npcid, const char *mes)
  2098. {
  2099. int fd = sd->fd;
  2100. int slen = strlen(mes) + 9;
  2101. WFIFOHEAD(fd, slen);
  2102. WFIFOW(fd,0)=0xb4;
  2103. WFIFOW(fd,2)=slen;
  2104. WFIFOL(fd,4)=npcid;
  2105. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2106. WFIFOSET(fd,WFIFOW(fd,2));
  2107. }
  2108. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2109. /// 00b5 <npc id>.L
  2110. /// Client behavior (dialog window):
  2111. /// - disable mouse targeting
  2112. /// - open the dialog window
  2113. /// - add 'next' button
  2114. /// When 'next' is pressed:
  2115. /// - 00B9 <npcid of dialog window>.L
  2116. /// - set to clear on next mes
  2117. /// - remove 'next' button
  2118. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2119. {
  2120. int fd;
  2121. nullpo_retv(sd);
  2122. fd=sd->fd;
  2123. WFIFOHEAD(fd, packet_len(0xb5));
  2124. WFIFOW(fd,0)=0xb5;
  2125. WFIFOL(fd,2)=npcid;
  2126. WFIFOSET(fd,packet_len(0xb5));
  2127. }
  2128. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2129. /// 00b6 <npc id>.L
  2130. /// Client behavior:
  2131. /// - if dialog window is open:
  2132. /// - remove 'next' button
  2133. /// - add 'close' button
  2134. /// - else:
  2135. /// - enable mouse targeting
  2136. /// - close the dialog window
  2137. /// - close the menu window
  2138. /// When 'close' is pressed:
  2139. /// - enable mouse targeting
  2140. /// - close the dialog window
  2141. /// - close the menu window
  2142. /// - 0146 <npcid of dialog window>.L
  2143. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2144. {
  2145. int fd;
  2146. nullpo_retv(sd);
  2147. fd=sd->fd;
  2148. WFIFOHEAD(fd, packet_len(0xb6));
  2149. WFIFOW(fd,0)=0xb6;
  2150. WFIFOL(fd,2)=npcid;
  2151. WFIFOSET(fd,packet_len(0xb6));
  2152. }
  2153. /**
  2154. * Close script when player is idle
  2155. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2156. * @author [Ind/Hercules]
  2157. * @param sd : player pointer
  2158. * @param npcid : npc gid to close
  2159. */
  2160. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2161. {
  2162. struct s_packet_db* info;
  2163. int16 len;
  2164. int cmd = 0;
  2165. int fd;
  2166. nullpo_retv(sd);
  2167. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2168. if(!cmd) cmd = 0x8d6; //default
  2169. info = &packet_db[cmd];
  2170. len = info->len;
  2171. fd = sd->fd;
  2172. WFIFOHEAD(fd, len);
  2173. WFIFOW(fd,0)=0x8d6;
  2174. WFIFOL(fd,info->pos[0])=npcid;
  2175. WFIFOSET(fd,len);
  2176. }
  2177. /*==========================================
  2178. *
  2179. *------------------------------------------*/
  2180. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2181. unsigned char *buf;
  2182. int fd = sd->fd;
  2183. sd->state.using_fake_npc = 1;
  2184. WFIFOHEAD(fd, packet_len(0x78));
  2185. buf = WFIFOP(fd,0);
  2186. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2187. WBUFW(buf,0)=0x78;
  2188. #if PACKETVER >= 20071106
  2189. WBUFB(buf,2) = 0; // object type
  2190. buf = WFIFOP(fd,1);
  2191. #endif
  2192. WBUFL(buf,2)=npcid;
  2193. WBUFW(buf,14)=111;
  2194. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2195. WBUFB(buf,49)=5;
  2196. WBUFB(buf,50)=5;
  2197. WFIFOSET(fd, packet_len(0x78));
  2198. }
  2199. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2200. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2201. /// Client behavior:
  2202. /// - disable mouse targeting
  2203. /// - close the menu window
  2204. /// - open the menu window
  2205. /// - add options to the menu (separated in the text by ":")
  2206. /// - set npcid of menu window
  2207. /// - if dialog window is open:
  2208. /// - remove 'next' button
  2209. /// When 'ok' is pressed:
  2210. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2211. /// - close the menu window
  2212. /// When 'cancel' is pressed:
  2213. /// - 00B8 <npcid of menu window>.L <-1>.B
  2214. /// - enable mouse targeting
  2215. /// - close a bunch of windows...
  2216. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2217. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2218. /// TODO investigate behavior of other windows [FlavioJS]
  2219. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2220. {
  2221. int fd = sd->fd;
  2222. int slen = strlen(mes) + 9;
  2223. struct block_list *bl = NULL;
  2224. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2225. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2226. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2227. clif_sendfakenpc(sd, npcid);
  2228. WFIFOHEAD(fd, slen);
  2229. WFIFOW(fd,0)=0xb7;
  2230. WFIFOW(fd,2)=slen;
  2231. WFIFOL(fd,4)=npcid;
  2232. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2233. WFIFOSET(fd,WFIFOW(fd,2));
  2234. }
  2235. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2236. /// 0142 <npc id>.L
  2237. /// Client behavior (inputnum window):
  2238. /// - if npcid exists in the client:
  2239. /// - open the inputnum window
  2240. /// - set npcid of inputnum window
  2241. /// When 'ok' is pressed:
  2242. /// - if inputnum window has text:
  2243. /// - if npcid exists in the client:
  2244. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2245. /// - close inputnum window
  2246. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2247. {
  2248. int fd;
  2249. struct block_list *bl = NULL;
  2250. nullpo_retv(sd);
  2251. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2252. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2253. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2254. clif_sendfakenpc(sd, npcid);
  2255. fd=sd->fd;
  2256. WFIFOHEAD(fd, packet_len(0x142));
  2257. WFIFOW(fd,0)=0x142;
  2258. WFIFOL(fd,2)=npcid;
  2259. WFIFOSET(fd,packet_len(0x142));
  2260. }
  2261. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2262. /// 01d4 <npc id>.L
  2263. /// Client behavior (inputstr window):
  2264. /// - if npcid is 0 or npcid exists in the client:
  2265. /// - open the inputstr window
  2266. /// - set npcid of inputstr window
  2267. /// When 'ok' is pressed:
  2268. /// - if inputstr window has text and isn't an insult(manner.txt):
  2269. /// - if npcid is 0 or npcid exists in the client:
  2270. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2271. /// - close inputstr window
  2272. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2273. {
  2274. int fd;
  2275. struct block_list *bl = NULL;
  2276. nullpo_retv(sd);
  2277. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2278. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2279. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2280. clif_sendfakenpc(sd, npcid);
  2281. fd=sd->fd;
  2282. WFIFOHEAD(fd, packet_len(0x1d4));
  2283. WFIFOW(fd,0)=0x1d4;
  2284. WFIFOL(fd,2)=npcid;
  2285. WFIFOSET(fd,packet_len(0x1d4));
  2286. }
  2287. /// Marks a position on client's minimap (ZC_COMPASS).
  2288. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2289. /// npc id:
  2290. /// is ignored in the client
  2291. /// type:
  2292. /// 0 = display mark for 15 seconds
  2293. /// 1 = display mark until dead or teleported
  2294. /// 2 = remove mark
  2295. /// color:
  2296. /// 0x00RRGGBB
  2297. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2298. {
  2299. int fd;
  2300. nullpo_retv(sd);
  2301. fd=sd->fd;
  2302. WFIFOHEAD(fd, packet_len(0x144));
  2303. WFIFOW(fd,0)=0x144;
  2304. WFIFOL(fd,2)=npc_id;
  2305. WFIFOL(fd,6)=type;
  2306. WFIFOL(fd,10)=x;
  2307. WFIFOL(fd,14)=y;
  2308. WFIFOB(fd,18)=id;
  2309. WFIFOL(fd,19)=color;
  2310. WFIFOSET(fd,packet_len(0x144));
  2311. }
  2312. /// Displays an illustration image.
  2313. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2314. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2315. /// type:
  2316. /// 0 = bottom left corner
  2317. /// 1 = bottom middle
  2318. /// 2 = bottom right corner
  2319. /// 3 = middle of screen, inside a movable window
  2320. /// 4 = middle of screen, movable with a close button, chrome-less
  2321. /// 255 = clear all displayed cutins
  2322. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2323. {
  2324. int fd;
  2325. nullpo_retv(sd);
  2326. fd=sd->fd;
  2327. WFIFOHEAD(fd, packet_len(0x1b3));
  2328. WFIFOW(fd,0)=0x1b3;
  2329. strncpy(WFIFOCP(fd,2),image,64);
  2330. WFIFOB(fd,66)=type;
  2331. WFIFOSET(fd,packet_len(0x1b3));
  2332. }
  2333. /*==========================================
  2334. * Fills in card data from the given item and into the buffer. [Skotlex]
  2335. *------------------------------------------*/
  2336. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2337. nullpo_retv( buf );
  2338. // Blank data
  2339. if( item == nullptr ){
  2340. buf->card[0] = 0;
  2341. buf->card[1] = 0;
  2342. buf->card[2] = 0;
  2343. buf->card[3] = 0;
  2344. return;
  2345. }
  2346. // Pet eggs
  2347. if( item->card[0] == CARD0_PET ){
  2348. buf->card[0] = 0;
  2349. buf->card[1] = 0;
  2350. // Pet intimacy
  2351. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2352. buf->card[2] = item->card[3] >> 1;
  2353. // Pet renamed flag
  2354. buf->card[3] = item->card[3] & 1;
  2355. return;
  2356. }
  2357. // Forged/created items
  2358. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2359. buf->card[0] = item->card[0];
  2360. buf->card[1] = item->card[1];
  2361. buf->card[2] = item->card[2];
  2362. buf->card[3] = item->card[3];
  2363. return;
  2364. }
  2365. int i = 0, j;
  2366. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2367. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2368. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2369. }
  2370. // Normal items.
  2371. for( int k = 0; k < 4; k++, i++ ){
  2372. if( item->card[i] > 0 ){
  2373. buf->card[k] = client_nameid( item->card[i] );
  2374. }else{
  2375. buf->card[k] = 0;
  2376. }
  2377. }
  2378. }
  2379. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2380. /// A maximum of 5 random options can be supported.
  2381. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2382. nullpo_retr( 0, it );
  2383. uint8 count = 0;
  2384. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2385. if( it->option[i].id ){
  2386. buf[i].index = it->option[i].id; // OptIndex
  2387. buf[i].value = it->option[i].value; // Value
  2388. buf[i].param = it->option[i].param; // Param1
  2389. count++;
  2390. }else{
  2391. buf[i].index = 0;
  2392. buf[i].value = 0;
  2393. buf[i].param = 0;
  2394. }
  2395. }
  2396. #if MAX_ITEM_RDM_OPT < 5
  2397. for( ; i < 5; i++ ){
  2398. buf[i].index = 0; // OptIndex
  2399. buf[i].value = 0; // Value
  2400. buf[i].param = 0; // Param1
  2401. }
  2402. #endif
  2403. return count;
  2404. }
  2405. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2406. /// 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)
  2407. /// 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)
  2408. /// 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)
  2409. /// 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)
  2410. /// 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)
  2411. /// 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)
  2412. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2413. nullpo_retv( sd );
  2414. int fd = sd->fd;
  2415. if( !session_isActive( fd ) ){
  2416. return;
  2417. }
  2418. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2419. if( fail ){
  2420. p = {};
  2421. }else{
  2422. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2423. return;
  2424. }
  2425. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2426. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2427. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2428. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2429. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2430. p.location = pc_equippoint(sd,n);
  2431. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2432. #if PACKETVER >= 20061218
  2433. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2434. #if PACKETVER >= 20071002
  2435. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2436. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2437. */
  2438. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2439. #if PACKETVER >= 20150226
  2440. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2441. #if PACKETVER >= 20160921
  2442. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2443. p.look = sd->inventory_data[n]->look;
  2444. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2445. p.enchantgrade = sd->inventory.u.items_inventory[n].enchantgrade;
  2446. #endif
  2447. #endif
  2448. #endif
  2449. #endif
  2450. #endif
  2451. }
  2452. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2453. p.Index = client_index( n );
  2454. p.count = amount;
  2455. p.result = fail;
  2456. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2457. }
  2458. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2459. /// 00af <index>.W <amount>.W
  2460. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2461. {
  2462. int fd;
  2463. nullpo_retv(sd);
  2464. fd=sd->fd;
  2465. WFIFOHEAD(fd, packet_len(0xaf));
  2466. WFIFOW(fd,0)=0xaf;
  2467. WFIFOW(fd,2)=n+2;
  2468. WFIFOW(fd,4)=amount;
  2469. WFIFOSET(fd,packet_len(0xaf));
  2470. }
  2471. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2472. /// 07fa <delete type>.W <index>.W <amount>.W
  2473. /// delete type:
  2474. /// 0 = Normal
  2475. /// 1 = Item used for a skill
  2476. /// 2 = Refine failed
  2477. /// 3 = Material changed
  2478. /// 4 = Moved to storage
  2479. /// 5 = Moved to cart
  2480. /// 6 = Item sold
  2481. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2482. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2483. {
  2484. #if PACKETVER < 20091117
  2485. clif_dropitem(sd,n,amount);
  2486. #else
  2487. int fd;
  2488. nullpo_retv(sd);
  2489. fd=sd->fd;
  2490. WFIFOHEAD(fd, packet_len(0x7fa));
  2491. WFIFOW(fd,0)=0x7fa;
  2492. WFIFOW(fd,2)=reason;
  2493. WFIFOW(fd,4)=n+2;
  2494. WFIFOW(fd,6)=amount;
  2495. WFIFOSET(fd,packet_len(0x7fa));
  2496. #endif
  2497. }
  2498. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2499. nullpo_retv( p );
  2500. nullpo_retv( it );
  2501. nullpo_retv( id );
  2502. p->index = idx;
  2503. p->ITID = client_nameid( it->nameid );
  2504. p->type = itemtype( it->nameid );
  2505. #if PACKETVER < 20120925
  2506. p->IsIdentified = it->identify ? 1 : 0;
  2507. #endif
  2508. p->location = eqp_pos;
  2509. p->WearState = it->equip;
  2510. #if PACKETVER < 20120925
  2511. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2512. #endif
  2513. p->RefiningLevel = it->refine;
  2514. clif_addcards( &p->slot, it );
  2515. #if PACKETVER >= 20071002
  2516. p->HireExpireDate = it->expire_time;
  2517. #endif
  2518. #if PACKETVER >= 20080102
  2519. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2520. #endif
  2521. #if PACKETVER >= 20100629
  2522. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2523. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2524. #endif
  2525. #if PACKETVER >= 20120925
  2526. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2527. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2528. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2529. p->Flag.SpareBits = 0;
  2530. #endif
  2531. #if PACKETVER >= 20150226
  2532. p->option_count = clif_add_random_options( p->option_data, it );
  2533. #endif
  2534. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2535. p->enchantgrade = it->enchantgrade;
  2536. #endif
  2537. }
  2538. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2539. nullpo_retv(p);
  2540. nullpo_retv(i);
  2541. nullpo_retv(id);
  2542. p->index = idx;
  2543. p->ITID = client_nameid( i->nameid );
  2544. p->type = itemtype( i->nameid );
  2545. #if PACKETVER < 20120925
  2546. p->IsIdentified = i->identify ? 1 : 0;
  2547. #endif
  2548. p->count = i->amount;
  2549. p->WearState = id->equip;
  2550. #if PACKETVER >= 5
  2551. clif_addcards( &p->slot, i );
  2552. #endif
  2553. #if PACKETVER >= 20080102
  2554. p->HireExpireDate = i->expire_time;
  2555. #endif
  2556. #if PACKETVER >= 20120925
  2557. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2558. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2559. p->Flag.SpareBits = 0;
  2560. #endif
  2561. }
  2562. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2563. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2564. nullpo_retv(sd);
  2565. nullpo_retv(name);
  2566. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2567. memset(buf, 0, sizeof(buf));
  2568. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2569. p->packetType = HEADER_ZC_INVENTORY_START;
  2570. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2571. p->invType = type;
  2572. #endif
  2573. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2574. int strLen = (int)safestrnlen(name, 24) + 1;
  2575. if (strLen > 24)
  2576. strLen = 24;
  2577. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2578. p->packetLength = len;
  2579. safestrncpy(p->name, name, strLen);
  2580. #else
  2581. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2582. safestrncpy(p->name, name, NAME_LENGTH);
  2583. #endif
  2584. clif_send( p, len, &sd->bl, SELF );
  2585. #endif
  2586. }
  2587. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2588. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2589. nullpo_retv(sd);
  2590. struct PACKET_ZC_INVENTORY_END p;
  2591. p.packetType = HEADER_ZC_INVENTORY_END;
  2592. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2593. p.invType = type;
  2594. #endif
  2595. p.flag = 0;
  2596. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2597. #endif
  2598. }
  2599. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2600. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2601. void clif_inventorylist( struct map_session_data *sd ){
  2602. nullpo_retv( sd );
  2603. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2604. e_inventory_type type = INVTYPE_INVENTORY;
  2605. clif_inventoryStart( sd, type, "" );
  2606. #endif
  2607. static struct packet_itemlist_normal itemlist_normal;
  2608. static struct packet_itemlist_equip itemlist_equip;
  2609. int equip = 0;
  2610. int normal = 0;
  2611. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2612. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2613. continue;
  2614. }
  2615. // Non-stackable (Equippable)
  2616. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2617. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2618. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2619. itemlist_equip.PacketType = inventorylistequipType;
  2620. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2621. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2622. itemlist_equip.invType = type;
  2623. #endif
  2624. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2625. equip = 0;
  2626. }
  2627. // Stackable (Normal)
  2628. }else{
  2629. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2630. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2631. itemlist_normal.PacketType = inventorylistnormalType;
  2632. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2633. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2634. itemlist_normal.invType = type;
  2635. #endif
  2636. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2637. normal = 0;
  2638. }
  2639. }
  2640. }
  2641. if( normal ){
  2642. itemlist_normal.PacketType = inventorylistnormalType;
  2643. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2644. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2645. itemlist_normal.invType = type;
  2646. #endif
  2647. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2648. }
  2649. if( sd->equip_index[EQI_AMMO] >= 0 )
  2650. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2651. if( equip ) {
  2652. itemlist_equip.PacketType = inventorylistequipType;
  2653. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2654. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2655. itemlist_equip.invType = type;
  2656. #endif
  2657. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2658. }
  2659. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2660. clif_inventoryEnd( sd, type );
  2661. #endif
  2662. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2663. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2664. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2665. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2666. continue;
  2667. if ( sd->inventory.u.items_inventory[i].favorite )
  2668. clif_favorite_item(sd, i);
  2669. }
  2670. #endif
  2671. }
  2672. //Required when items break/get-repaired. Only sends equippable item list.
  2673. void clif_equiplist( struct map_session_data *sd ){
  2674. // TODO: implement again => only send equip part
  2675. clif_inventorylist( sd );
  2676. }
  2677. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2678. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2679. e_inventory_type type = INVTYPE_STORAGE;
  2680. clif_inventoryStart( sd, type, storename );
  2681. #endif
  2682. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2683. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2684. int equip = 0;
  2685. int normal = 0;
  2686. for( int i = 0; i < items_length; i++ ){
  2687. if( items[i].nameid == 0 ){
  2688. continue;
  2689. }
  2690. struct item_data* id = itemdb_search( items[i].nameid );
  2691. // Non-stackable (Equippable)
  2692. if( !itemdb_isstackable2( id ) ){
  2693. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2694. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2695. storage_itemlist_equip.PacketType = storageListEquipType;
  2696. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2697. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2698. storage_itemlist_equip.invType = type;
  2699. #elif PACKETVER >= 20120925
  2700. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2701. #endif
  2702. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2703. equip = 0;
  2704. }
  2705. // Stackable (Normal)
  2706. }else{
  2707. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2708. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2709. storage_itemlist_normal.PacketType = storageListNormalType;
  2710. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2711. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2712. storage_itemlist_normal.invType = type;
  2713. #elif PACKETVER >= 20120925
  2714. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2715. #endif
  2716. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2717. normal = 0;
  2718. }
  2719. }
  2720. }
  2721. if( normal ){
  2722. storage_itemlist_normal.PacketType = storageListNormalType;
  2723. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2724. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2725. storage_itemlist_normal.invType = type;
  2726. #elif PACKETVER >= 20120925
  2727. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2728. #endif
  2729. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2730. }
  2731. if( equip ) {
  2732. storage_itemlist_equip.PacketType = storageListEquipType;
  2733. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2734. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2735. storage_itemlist_equip.invType = type;
  2736. #elif PACKETVER >= 20120925
  2737. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2738. #endif
  2739. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2740. }
  2741. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2742. clif_inventoryEnd( sd, type );
  2743. #endif
  2744. }
  2745. void clif_cartlist( struct map_session_data *sd ){
  2746. nullpo_retv( sd );
  2747. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2748. e_inventory_type type = INVTYPE_CART;
  2749. clif_inventoryStart( sd, type, "" );
  2750. #endif
  2751. static struct packet_itemlist_normal itemlist_normal;
  2752. static struct packet_itemlist_equip itemlist_equip;
  2753. int normal = 0;
  2754. int equip = 0;
  2755. for( int i = 0; i < MAX_CART; i++ ){
  2756. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2757. continue;
  2758. }
  2759. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2760. // Non-stackable (Equippable)
  2761. if( !itemdb_isstackable2(id) ){
  2762. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2763. // Stackable (Normal)
  2764. }else{
  2765. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2766. }
  2767. }
  2768. if( normal ){
  2769. itemlist_normal.PacketType = cartlistnormalType;
  2770. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2771. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2772. itemlist_normal.invType = type;
  2773. #endif
  2774. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2775. }
  2776. if( equip ){
  2777. itemlist_equip.PacketType = cartlistequipType;
  2778. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2779. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2780. itemlist_equip.invType = type;
  2781. #endif
  2782. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2783. }
  2784. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2785. clif_inventoryEnd( sd, type );
  2786. #endif
  2787. }
  2788. /// Removes cart (ZC_CARTOFF).
  2789. /// 012b
  2790. /// Client behaviour:
  2791. /// Closes the cart storage and removes all it's items from memory.
  2792. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2793. void clif_clearcart(int fd)
  2794. {
  2795. WFIFOHEAD(fd, packet_len(0x12b));
  2796. WFIFOW(fd,0) = 0x12b;
  2797. WFIFOSET(fd, packet_len(0x12b));
  2798. }
  2799. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2800. /// 01eb <account id>.L <x>.W <y>.W
  2801. void clif_guild_xy(struct map_session_data *sd)
  2802. {
  2803. unsigned char buf[10];
  2804. nullpo_retv(sd);
  2805. WBUFW(buf,0)=0x1eb;
  2806. WBUFL(buf,2)=sd->status.account_id;
  2807. WBUFW(buf,6)=sd->bl.x;
  2808. WBUFW(buf,8)=sd->bl.y;
  2809. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2810. }
  2811. /*==========================================
  2812. * Sends x/y dot to a single fd. [Skotlex]
  2813. *------------------------------------------*/
  2814. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2815. {
  2816. if( sd->bg_id )
  2817. return;
  2818. WFIFOHEAD(fd,packet_len(0x1eb));
  2819. WFIFOW(fd,0)=0x1eb;
  2820. WFIFOL(fd,2)=sd->status.account_id;
  2821. WFIFOW(fd,6)=sd->bl.x;
  2822. WFIFOW(fd,8)=sd->bl.y;
  2823. WFIFOSET(fd,packet_len(0x1eb));
  2824. }
  2825. // Guild XY locators [Valaris]
  2826. void clif_guild_xy_remove(struct map_session_data *sd)
  2827. {
  2828. unsigned char buf[10];
  2829. nullpo_retv(sd);
  2830. WBUFW(buf,0)=0x1eb;
  2831. WBUFL(buf,2)=sd->status.account_id;
  2832. WBUFW(buf,6)=-1;
  2833. WBUFW(buf,8)=-1;
  2834. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2835. }
  2836. /*==========================================
  2837. *
  2838. *------------------------------------------*/
  2839. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2840. {
  2841. struct map_session_data *sd, *tsd;
  2842. #if PACKETVER < 20100126
  2843. const int cmd = 0x106;
  2844. #else
  2845. const int cmd = 0x80e;
  2846. #endif
  2847. sd = va_arg(ap, struct map_session_data *);
  2848. tsd = (TBL_PC *)bl;
  2849. nullpo_ret(sd);
  2850. nullpo_ret(tsd);
  2851. if( !session_isActive(tsd->fd) || tsd == sd )
  2852. return 0;
  2853. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2854. return 0;
  2855. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2856. WFIFOW(tsd->fd,0) = cmd;
  2857. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2858. #if PACKETVER < 20100126
  2859. if( sd->battle_status.max_hp > INT16_MAX )
  2860. { //To correctly display the %hp bar. [Skotlex]
  2861. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2862. WFIFOW(tsd->fd,8) = 100;
  2863. } else {
  2864. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2865. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2866. }
  2867. #else
  2868. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2869. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2870. #endif
  2871. WFIFOSET(tsd->fd,packet_len(cmd));
  2872. return 0;
  2873. }
  2874. /*==========================================
  2875. * Server tells all players that are allowed to view HP bars
  2876. * and are nearby 'sd' that 'sd' hp bar was updated.
  2877. *------------------------------------------*/
  2878. static int clif_hpmeter(struct map_session_data *sd)
  2879. {
  2880. nullpo_ret(sd);
  2881. 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);
  2882. return 0;
  2883. }
  2884. /**
  2885. * Send HP bar update to others.
  2886. * @param sd: Player invoking update
  2887. */
  2888. void clif_update_hp(map_session_data &sd) {
  2889. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2890. clif_hpmeter(&sd);
  2891. if (!battle_config.party_hp_mode && sd.status.party_id)
  2892. clif_party_hp(&sd);
  2893. if (sd.bg_id)
  2894. clif_bg_hp(&sd);
  2895. }
  2896. /// Notifies client of a character parameter change.
  2897. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2898. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2899. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2900. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2901. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2902. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2903. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2904. /// TODO: Extract individual packets.
  2905. /// FIXME: Packet lengths from packet_len(cmd)
  2906. void clif_updatestatus(struct map_session_data *sd,int type)
  2907. {
  2908. int fd,len=8;
  2909. nullpo_retv(sd);
  2910. fd=sd->fd;
  2911. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2912. return;
  2913. WFIFOHEAD(fd, 14);
  2914. WFIFOW(fd,0)=0xb0;
  2915. WFIFOW(fd,2)=type;
  2916. switch(type){
  2917. // 00b0
  2918. case SP_WEIGHT:
  2919. pc_updateweightstatus(sd);
  2920. WFIFOHEAD(fd,14);
  2921. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2922. WFIFOW(fd,2)=type;
  2923. WFIFOL(fd,4)=sd->weight;
  2924. break;
  2925. case SP_MAXWEIGHT:
  2926. WFIFOL(fd,4)=sd->max_weight;
  2927. break;
  2928. case SP_SPEED:
  2929. WFIFOL(fd,4)=sd->battle_status.speed;
  2930. break;
  2931. case SP_BASELEVEL:
  2932. WFIFOL(fd,4)=sd->status.base_level;
  2933. break;
  2934. case SP_JOBLEVEL:
  2935. WFIFOL(fd,4)=sd->status.job_level;
  2936. break;
  2937. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2938. WFIFOL(fd,4)=sd->status.karma;
  2939. break;
  2940. case SP_MANNER:
  2941. WFIFOL(fd,4)=sd->status.manner;
  2942. break;
  2943. case SP_STATUSPOINT:
  2944. WFIFOL(fd,4)=sd->status.status_point;
  2945. break;
  2946. case SP_SKILLPOINT:
  2947. WFIFOL(fd,4)=sd->status.skill_point;
  2948. break;
  2949. case SP_HIT:
  2950. WFIFOL(fd,4)=sd->battle_status.hit;
  2951. break;
  2952. case SP_FLEE1:
  2953. WFIFOL(fd,4)=sd->battle_status.flee;
  2954. break;
  2955. case SP_FLEE2:
  2956. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2957. break;
  2958. case SP_MAXHP:
  2959. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2960. break;
  2961. case SP_MAXSP:
  2962. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2963. break;
  2964. case SP_HP:
  2965. // On officials the HP never go below 1, even if you die [Lemongrass]
  2966. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2967. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2968. break;
  2969. case SP_SP:
  2970. WFIFOL(fd,4)=sd->battle_status.sp;
  2971. break;
  2972. case SP_ASPD:
  2973. WFIFOL(fd,4)=sd->battle_status.amotion;
  2974. break;
  2975. case SP_ATK1:
  2976. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2977. break;
  2978. case SP_DEF1:
  2979. WFIFOL(fd,4)=pc_leftside_def(sd);
  2980. break;
  2981. case SP_MDEF1:
  2982. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2983. break;
  2984. case SP_ATK2:
  2985. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2986. break;
  2987. case SP_DEF2:
  2988. WFIFOL(fd,4)=pc_rightside_def(sd);
  2989. break;
  2990. case SP_MDEF2: {
  2991. //negative check (in case you have something like Berserk active)
  2992. int mdef2 = pc_rightside_mdef(sd);
  2993. WFIFOL(fd,4)=
  2994. #ifndef RENEWAL
  2995. ( mdef2 < 0 ) ? 0 :
  2996. #endif
  2997. mdef2;
  2998. }
  2999. break;
  3000. case SP_CRITICAL:
  3001. WFIFOL(fd,4)=sd->battle_status.cri/10;
  3002. break;
  3003. case SP_MATK1:
  3004. WFIFOL(fd,4)=pc_rightside_matk(sd);
  3005. break;
  3006. case SP_MATK2:
  3007. WFIFOL(fd,4)=pc_leftside_matk(sd);
  3008. break;
  3009. case SP_ZENY:
  3010. WFIFOW(fd,0)=0xb1;
  3011. WFIFOL(fd,4)=sd->status.zeny;
  3012. break;
  3013. #if PACKETVER >= 20170830
  3014. case SP_BASEEXP:
  3015. WFIFOW(fd,0)=0xacb;
  3016. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  3017. len = packet_len(0xacb);
  3018. break;
  3019. case SP_JOBEXP:
  3020. WFIFOW(fd,0)=0xacb;
  3021. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  3022. len = packet_len(0xacb);
  3023. break;
  3024. case SP_NEXTBASEEXP:
  3025. WFIFOW(fd,0)=0xacb;
  3026. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  3027. len = packet_len(0xacb);
  3028. break;
  3029. case SP_NEXTJOBEXP:
  3030. WFIFOW(fd,0)=0xacb;
  3031. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3032. len = packet_len(0xacb);
  3033. break;
  3034. #else
  3035. case SP_BASEEXP:
  3036. WFIFOW(fd,0)=0xb1;
  3037. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3038. break;
  3039. case SP_JOBEXP:
  3040. WFIFOW(fd,0)=0xb1;
  3041. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3042. break;
  3043. case SP_NEXTBASEEXP:
  3044. WFIFOW(fd,0)=0xb1;
  3045. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3046. break;
  3047. case SP_NEXTJOBEXP:
  3048. WFIFOW(fd,0)=0xb1;
  3049. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3050. break;
  3051. #endif
  3052. /**
  3053. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3054. **/
  3055. case SP_USTR:
  3056. case SP_UAGI:
  3057. case SP_UVIT:
  3058. case SP_UINT:
  3059. case SP_UDEX:
  3060. case SP_ULUK:
  3061. WFIFOW(fd,0)=0xbe;
  3062. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3063. len=5;
  3064. break;
  3065. /**
  3066. * Tells the client how far it is allowed to attack (weapon range)
  3067. **/
  3068. case SP_ATTACKRANGE:
  3069. WFIFOW(fd,0)=0x13a;
  3070. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3071. len=4;
  3072. break;
  3073. case SP_STR:
  3074. WFIFOW(fd,0)=0x141;
  3075. WFIFOL(fd,2)=type;
  3076. WFIFOL(fd,6)=sd->status.str;
  3077. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3078. len=14;
  3079. break;
  3080. case SP_AGI:
  3081. WFIFOW(fd,0)=0x141;
  3082. WFIFOL(fd,2)=type;
  3083. WFIFOL(fd,6)=sd->status.agi;
  3084. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3085. len=14;
  3086. break;
  3087. case SP_VIT:
  3088. WFIFOW(fd,0)=0x141;
  3089. WFIFOL(fd,2)=type;
  3090. WFIFOL(fd,6)=sd->status.vit;
  3091. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3092. len=14;
  3093. break;
  3094. case SP_INT:
  3095. WFIFOW(fd,0)=0x141;
  3096. WFIFOL(fd,2)=type;
  3097. WFIFOL(fd,6)=sd->status.int_;
  3098. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3099. len=14;
  3100. break;
  3101. case SP_DEX:
  3102. WFIFOW(fd,0)=0x141;
  3103. WFIFOL(fd,2)=type;
  3104. WFIFOL(fd,6)=sd->status.dex;
  3105. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3106. len=14;
  3107. break;
  3108. case SP_LUK:
  3109. WFIFOW(fd,0)=0x141;
  3110. WFIFOL(fd,2)=type;
  3111. WFIFOL(fd,6)=sd->status.luk;
  3112. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3113. len=14;
  3114. break;
  3115. case SP_CARTINFO:
  3116. WFIFOW(fd,0)=0x121;
  3117. WFIFOW(fd,2)=sd->cart_num;
  3118. WFIFOW(fd,4)=MAX_CART;
  3119. WFIFOL(fd,6)=sd->cart_weight;
  3120. WFIFOL(fd,10)=sd->cart_weight_max;
  3121. len=14;
  3122. break;
  3123. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3124. case SP_AP:
  3125. WFIFOL(fd, 4) = sd->battle_status.ap;
  3126. break;
  3127. case SP_TRAITPOINT:
  3128. WFIFOL(fd, 4) = sd->status.trait_point;
  3129. break;
  3130. case SP_MAXAP:
  3131. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3132. break;
  3133. case SP_POW:
  3134. WFIFOW(fd, 0) = 0x141;
  3135. WFIFOL(fd, 2) = type;
  3136. WFIFOL(fd, 6) = sd->status.pow;
  3137. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3138. len = 14;
  3139. break;
  3140. case SP_STA:
  3141. WFIFOW(fd, 0) = 0x141;
  3142. WFIFOL(fd, 2) = type;
  3143. WFIFOL(fd, 6) = sd->status.sta;
  3144. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3145. len = 14;
  3146. break;
  3147. case SP_WIS:
  3148. WFIFOW(fd, 0) = 0x141;
  3149. WFIFOL(fd, 2) = type;
  3150. WFIFOL(fd, 6) = sd->status.wis;
  3151. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3152. len = 14;
  3153. break;
  3154. case SP_SPL:
  3155. WFIFOW(fd, 0) = 0x141;
  3156. WFIFOL(fd, 2) = type;
  3157. WFIFOL(fd, 6) = sd->status.spl;
  3158. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3159. len = 14;
  3160. break;
  3161. case SP_CON:
  3162. WFIFOW(fd, 0) = 0x141;
  3163. WFIFOL(fd, 2) = type;
  3164. WFIFOL(fd, 6) = sd->status.con;
  3165. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3166. len = 14;
  3167. break;
  3168. case SP_CRT:
  3169. WFIFOW(fd, 0) = 0x141;
  3170. WFIFOL(fd, 2) = type;
  3171. WFIFOL(fd, 6) = sd->status.crt;
  3172. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3173. len = 14;
  3174. break;
  3175. case SP_UPOW:
  3176. case SP_USTA:
  3177. case SP_UWIS:
  3178. case SP_USPL:
  3179. case SP_UCON:
  3180. case SP_UCRT:
  3181. WFIFOW(fd, 0) = 0xbe;
  3182. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3183. len = 5;
  3184. break;
  3185. case SP_PATK:
  3186. WFIFOL(fd, 4) = sd->battle_status.patk;
  3187. break;
  3188. case SP_SMATK:
  3189. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3190. break;
  3191. case SP_RES:
  3192. WFIFOL(fd, 4) = sd->battle_status.res;
  3193. break;
  3194. case SP_MRES:
  3195. WFIFOL(fd, 4) = sd->battle_status.mres;
  3196. break;
  3197. case SP_HPLUS:
  3198. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3199. break;
  3200. case SP_CRATE:
  3201. WFIFOL(fd, 4) = sd->battle_status.crate;
  3202. break;
  3203. #else
  3204. case SP_AP:
  3205. case SP_TRAITPOINT:
  3206. case SP_MAXAP:
  3207. case SP_POW:
  3208. case SP_STA:
  3209. case SP_WIS:
  3210. case SP_SPL:
  3211. case SP_CON:
  3212. case SP_CRT:
  3213. case SP_UPOW:
  3214. case SP_USTA:
  3215. case SP_UWIS:
  3216. case SP_USPL:
  3217. case SP_UCON:
  3218. case SP_UCRT:
  3219. case SP_PATK:
  3220. case SP_SMATK:
  3221. case SP_RES:
  3222. case SP_MRES:
  3223. case SP_HPLUS:
  3224. case SP_CRATE:
  3225. // 4th job status are not supported by older clients
  3226. return;
  3227. #endif
  3228. default:
  3229. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3230. return;
  3231. }
  3232. WFIFOSET(fd,len);
  3233. // Additional update packets that should be sent right after
  3234. switch( type ){
  3235. case SP_BASELEVEL:
  3236. if( sd->status.party_id ){
  3237. struct party_data* p;
  3238. int i;
  3239. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3240. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3241. if( i < MAX_PARTY ){
  3242. p->party.member[i].lv = sd->status.base_level;
  3243. clif_party_job_and_level(sd);
  3244. }
  3245. }
  3246. }
  3247. break;
  3248. case SP_HP:
  3249. clif_update_hp(*sd);
  3250. break;
  3251. }
  3252. }
  3253. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3254. /// 01ab <account id>.L <var id>.W <value>.L
  3255. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3256. {
  3257. unsigned char buf[12];
  3258. nullpo_retv(sd);
  3259. WBUFW(buf,0)=0x1ab;
  3260. WBUFL(buf,2)=sd->bl.id;
  3261. WBUFW(buf,6)=type;
  3262. switch(type)
  3263. {
  3264. case SP_MANNER:
  3265. WBUFL(buf,8)=val;
  3266. break;
  3267. default:
  3268. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3269. return;
  3270. }
  3271. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3272. }
  3273. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3274. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3275. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3276. struct PACKET_ZC_SPRITE_CHANGE p;
  3277. p.packetType = sendLookType;
  3278. p.AID = id;
  3279. p.type = type;
  3280. p.val = val;
  3281. #if PACKETVER >= 4
  3282. p.val2 = val2;
  3283. #endif
  3284. clif_send( &p, sizeof( p ), bl, target );
  3285. }
  3286. /// Updates sprite/style properties of an object.
  3287. void clif_changelook(struct block_list *bl, int type, int val) {
  3288. struct map_session_data* sd;
  3289. struct status_change* sc;
  3290. struct view_data* vd;
  3291. enum send_target target = AREA;
  3292. int val2 = 0;
  3293. nullpo_retv(bl);
  3294. sd = BL_CAST(BL_PC, bl);
  3295. sc = status_get_sc(bl);
  3296. vd = status_get_viewdata(bl);
  3297. if( vd ) //temp hack to let Warp Portal change appearance
  3298. switch(type) {
  3299. case LOOK_WEAPON:
  3300. if (sd) {
  3301. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3302. val = vd->weapon;
  3303. }
  3304. else
  3305. vd->weapon = val;
  3306. break;
  3307. case LOOK_SHIELD:
  3308. if (sd) {
  3309. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3310. val = vd->shield;
  3311. }
  3312. else
  3313. vd->shield = val;
  3314. break;
  3315. case LOOK_BASE:
  3316. if (!sd)
  3317. break;
  3318. if ( val == JT_INVISIBLE )
  3319. return;
  3320. if (sd->sc.option&OPTION_COSTUME)
  3321. vd->weapon = vd->shield = 0;
  3322. if (!vd->cloth_color)
  3323. break;
  3324. if (sd) {
  3325. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3326. vd->cloth_color = 0;
  3327. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3328. vd->cloth_color = 0;
  3329. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3330. vd->cloth_color = 0;
  3331. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3332. vd->cloth_color = 0;
  3333. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3334. vd->cloth_color = 0;
  3335. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3336. vd->body_style = 0;
  3337. }
  3338. break;
  3339. case LOOK_HAIR:
  3340. vd->hair_style = val;
  3341. break;
  3342. case LOOK_HEAD_BOTTOM:
  3343. vd->head_bottom = val;
  3344. break;
  3345. case LOOK_HEAD_TOP:
  3346. vd->head_top = val;
  3347. break;
  3348. case LOOK_HEAD_MID:
  3349. vd->head_mid = val;
  3350. break;
  3351. case LOOK_HAIR_COLOR:
  3352. vd->hair_color = val;
  3353. break;
  3354. case LOOK_CLOTHES_COLOR:
  3355. if (val && sd) {
  3356. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3357. val = 0;
  3358. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3359. val = 0;
  3360. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3361. val = 0;
  3362. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3363. val = 0;
  3364. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3365. val = 0;
  3366. }
  3367. vd->cloth_color = val;
  3368. break;
  3369. case LOOK_SHOES:
  3370. #if PACKETVER > 3
  3371. if (sd) {
  3372. int n;
  3373. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3374. if(sd->inventory_data[n]->view_id > 0)
  3375. val = sd->inventory_data[n]->view_id;
  3376. else
  3377. val = sd->inventory.u.items_inventory[n].nameid;
  3378. } else
  3379. val = 0;
  3380. }
  3381. #endif
  3382. //Shoes? No packet uses this....
  3383. break;
  3384. case LOOK_BODY:
  3385. // unknown purpose
  3386. break;
  3387. case LOOK_ROBE:
  3388. #if PACKETVER < 20110111
  3389. return;
  3390. #else
  3391. vd->robe = val;
  3392. #endif
  3393. break;
  3394. case LOOK_BODY2:
  3395. #if PACKETVER < 20150513
  3396. return;
  3397. #else
  3398. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3399. val = 0;
  3400. vd->body_style = val;
  3401. #endif
  3402. break;
  3403. }
  3404. // prevent leaking the presence of GM-hidden objects
  3405. if( sc && sc->option&OPTION_INVISIBLE )
  3406. target = SELF;
  3407. #if PACKETVER < 4
  3408. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3409. #else
  3410. if (bl->type != BL_NPC) {
  3411. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3412. type = LOOK_WEAPON;
  3413. val = (vd ? vd->weapon : 0);
  3414. val2 = (vd ? vd->shield : 0);
  3415. }
  3416. if (disguised(bl)) {
  3417. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3418. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3419. } else
  3420. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3421. } else
  3422. unit_refresh(bl);
  3423. #endif
  3424. }
  3425. //Sends a change-base-look packet required for traps as they are triggered.
  3426. void clif_changetraplook(struct block_list *bl,int val) {
  3427. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3428. }
  3429. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3430. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3431. clif_sprite_change(bl, id, type, val, 0, target);
  3432. }
  3433. /// Character status (ZC_STATUS).
  3434. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3435. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3436. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3437. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3438. void clif_initialstatus(struct map_session_data *sd) {
  3439. int fd, mdef2;
  3440. unsigned char *buf;
  3441. nullpo_retv(sd);
  3442. fd=sd->fd;
  3443. WFIFOHEAD(fd, packet_len(0xbd));
  3444. buf = WFIFOP(fd,0);
  3445. WBUFW(buf,0) = 0xbd;
  3446. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3447. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3448. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3449. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3450. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3451. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3452. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3453. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3454. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3455. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3456. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3457. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3458. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3459. WBUFW(buf,16) = pc_leftside_atk(sd);
  3460. WBUFW(buf,18) = pc_rightside_atk(sd);
  3461. WBUFW(buf,20) = pc_rightside_matk(sd);
  3462. WBUFW(buf,22) = pc_leftside_matk(sd);
  3463. WBUFW(buf,24) = pc_leftside_def(sd);
  3464. WBUFW(buf,26) = pc_rightside_def(sd);
  3465. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3466. mdef2 = pc_rightside_mdef(sd);
  3467. WBUFW(buf,30) =
  3468. #ifndef RENEWAL
  3469. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3470. #endif
  3471. mdef2;
  3472. WBUFW(buf,32) = sd->battle_status.hit;
  3473. WBUFW(buf,34) = sd->battle_status.flee;
  3474. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3475. WBUFW(buf,38) = sd->battle_status.cri/10;
  3476. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3477. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3478. WFIFOSET(fd, packet_len(0xbd));
  3479. clif_updatestatus(sd, SP_STR);
  3480. clif_updatestatus(sd, SP_AGI);
  3481. clif_updatestatus(sd, SP_VIT);
  3482. clif_updatestatus(sd, SP_INT);
  3483. clif_updatestatus(sd, SP_DEX);
  3484. clif_updatestatus(sd, SP_LUK);
  3485. clif_updatestatus(sd, SP_ATTACKRANGE);
  3486. clif_updatestatus(sd, SP_ASPD);
  3487. #ifdef RENEWAL
  3488. clif_updatestatus(sd, SP_POW);
  3489. clif_updatestatus(sd, SP_STA);
  3490. clif_updatestatus(sd, SP_WIS);
  3491. clif_updatestatus(sd, SP_SPL);
  3492. clif_updatestatus(sd, SP_CON);
  3493. clif_updatestatus(sd, SP_CRT);
  3494. clif_updatestatus(sd, SP_PATK);
  3495. clif_updatestatus(sd, SP_SMATK);
  3496. clif_updatestatus(sd, SP_RES);
  3497. clif_updatestatus(sd, SP_MRES);
  3498. clif_updatestatus(sd, SP_HPLUS);
  3499. clif_updatestatus(sd, SP_CRATE);
  3500. clif_updatestatus(sd, SP_TRAITPOINT);
  3501. clif_updatestatus(sd, SP_AP);
  3502. clif_updatestatus(sd, SP_MAXAP);
  3503. clif_updatestatus(sd, SP_UPOW);
  3504. clif_updatestatus(sd, SP_USTA);
  3505. clif_updatestatus(sd, SP_UWIS);
  3506. clif_updatestatus(sd, SP_USPL);
  3507. clif_updatestatus(sd, SP_UCON);
  3508. clif_updatestatus(sd, SP_UCRT);
  3509. #endif
  3510. }
  3511. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3512. /// 013c <index>.W
  3513. void clif_arrowequip(struct map_session_data *sd,int val) {
  3514. int fd;
  3515. nullpo_retv(sd);
  3516. #if PACKETVER >= 20121128
  3517. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3518. #endif
  3519. fd=sd->fd;
  3520. WFIFOHEAD(fd, packet_len(0x013c));
  3521. WFIFOW(fd,0) = 0x013c;
  3522. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3523. WFIFOSET(fd, packet_len(0x013c));
  3524. }
  3525. /// Ammunition action message (ZC_ACTION_FAILURE).
  3526. /// 013b <type>.W
  3527. /// type:
  3528. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3529. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3530. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3531. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3532. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3533. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3534. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3535. int fd;
  3536. nullpo_retv(sd);
  3537. fd=sd->fd;
  3538. WFIFOHEAD(fd, packet_len(0x013b));
  3539. WFIFOW(fd,0) = 0x013b;
  3540. WFIFOW(fd,2) = type;
  3541. WFIFOSET(fd, packet_len(0x013b));
  3542. }
  3543. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3544. /// 01ad <packet len>.W { <name id>.W }*
  3545. void clif_arrow_create_list( struct map_session_data *sd ){
  3546. nullpo_retv( sd );
  3547. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3548. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3549. int count = 0;
  3550. for (const auto &it : skill_arrow_db) {
  3551. t_itemid nameid = it.second->nameid;
  3552. if( !item_db.exists( nameid ) ){
  3553. continue;
  3554. }
  3555. int index = pc_search_inventory( sd, nameid );
  3556. if( index < 0 ){
  3557. continue;
  3558. }
  3559. if( sd->inventory.u.items_inventory[index].equip ){
  3560. continue;
  3561. }
  3562. if( !sd->inventory.u.items_inventory[index].identify ){
  3563. continue;
  3564. }
  3565. p->items[count].itemId = client_nameid( nameid );
  3566. count++;
  3567. }
  3568. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3569. clif_send( p, p->packetLength, &sd->bl, SELF );
  3570. if( count > 0 ){
  3571. sd->menuskill_id = AC_MAKINGARROW;
  3572. sd->menuskill_val = count;
  3573. }
  3574. }
  3575. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3576. /// 00bc <status id>.W <result>.B <value>.B
  3577. /// status id:
  3578. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3579. /// result:
  3580. /// 0 = failure
  3581. /// 1 = success
  3582. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3583. int fd;
  3584. nullpo_retv(sd);
  3585. fd=sd->fd;
  3586. WFIFOHEAD(fd, packet_len(0xbc));
  3587. WFIFOW(fd,0) = 0xbc;
  3588. WFIFOW(fd,2) = type;
  3589. WFIFOB(fd,4) = ok;
  3590. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3591. WFIFOSET(fd, packet_len(0xbc));
  3592. }
  3593. /// Notifies the client about the result of a request to equip an item.
  3594. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3595. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3596. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3597. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3598. /// @ok: //inversed forv2 v5
  3599. /// 0 = failure
  3600. /// 1 = success
  3601. /// 2 = failure due to low level
  3602. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3603. {
  3604. int fd = 0, cmd = 0, look = 0;
  3605. struct s_packet_db *info = NULL;
  3606. nullpo_retv(sd);
  3607. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3608. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3609. return;
  3610. fd = sd->fd;
  3611. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3612. look = sd->inventory_data[n]->look;
  3613. WFIFOHEAD(fd, info->len);
  3614. WFIFOW(fd, 0) = cmd;
  3615. WFIFOW(fd, info->pos[0]) = n+2;
  3616. switch (cmd) {
  3617. case 0xaa:
  3618. WFIFOW(fd, info->pos[1]) = pos;
  3619. #if PACKETVER < 20100629
  3620. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3621. #else
  3622. WFIFOL(fd, info->pos[2]) = look;
  3623. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3624. #endif
  3625. break;
  3626. case 0x8d0:
  3627. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3628. flag = 1;
  3629. case 0x999:
  3630. if (cmd == 0x999)
  3631. WFIFOL(fd, info->pos[1]) = pos;
  3632. else
  3633. WFIFOW(fd, info->pos[1]) = pos;
  3634. WFIFOL(fd, info->pos[2]) = look;
  3635. WFIFOW(fd, info->pos[3]) = flag;
  3636. break;
  3637. }
  3638. WFIFOSET(fd, info->len);
  3639. }
  3640. /// Notifies the client about the result of a request to take off an item.
  3641. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3642. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3643. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3644. /// @ok : //inversed for v2 v5
  3645. /// 0 = failure
  3646. /// 1 = success
  3647. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3648. {
  3649. int fd, header, offs = 0;
  3650. #if PACKETVER >= 20130000
  3651. header = 0x99a;
  3652. ok = ok ? 0 : 1;
  3653. #elif PACKETVER >= 20110824
  3654. header = 0x8d1;
  3655. ok = ok ? 0 : 1;
  3656. #else
  3657. header = 0xac;
  3658. #endif
  3659. nullpo_retv(sd);
  3660. fd=sd->fd;
  3661. WFIFOHEAD(fd, packet_len(header));
  3662. WFIFOW(fd,offs+0) = header;
  3663. WFIFOW(fd,offs+2) = n+2;
  3664. #if PACKETVER >= 20130000
  3665. WFIFOL(fd,offs+4) = pos;
  3666. offs += 2;
  3667. #else
  3668. WFIFOW(fd,offs+4) = pos;
  3669. #endif
  3670. WFIFOB(fd,offs+6) = ok;
  3671. WFIFOSET(fd, packet_len(header));
  3672. }
  3673. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3674. /// 019b <id>.L <effect id>.L
  3675. /// effect id:
  3676. /// 0 = base level up
  3677. /// 1 = job level up
  3678. /// 2 = refine failure
  3679. /// 3 = refine success
  3680. /// 4 = game over
  3681. /// 5 = pharmacy success
  3682. /// 6 = pharmacy failure
  3683. /// 7 = base level up (super novice)
  3684. /// 8 = job level up (super novice)
  3685. /// 9 = base level up (taekwon)
  3686. void clif_misceffect(struct block_list* bl,int type)
  3687. {
  3688. unsigned char buf[32];
  3689. nullpo_retv(bl);
  3690. WBUFW(buf,0) = 0x19b;
  3691. WBUFL(buf,2) = bl->id;
  3692. WBUFL(buf,6) = type;
  3693. clif_send(buf,packet_len(0x19b),bl,AREA);
  3694. }
  3695. /// Notifies clients in the area of a state change.
  3696. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3697. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3698. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3699. nullpo_retv( bl );
  3700. struct status_change* sc = status_get_sc( bl );
  3701. //How can an option change if there's no sc?
  3702. if( sc == nullptr ){
  3703. return;
  3704. }
  3705. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3706. struct PACKET_ZC_STATE_CHANGE p;
  3707. p.packetType = HEADER_ZC_STATE_CHANGE;
  3708. p.AID = bl->id;
  3709. p.bodyState = sc->opt1;
  3710. p.healthState = sc->opt2;
  3711. p.effectState = sc->option;
  3712. p.isPKModeON = sd ? sd->status.karma : false;
  3713. if( target == nullptr ){
  3714. if( disguised( bl ) ){
  3715. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3716. p.AID = disguised_bl_id( p.AID );
  3717. clif_send( &p, sizeof( p ), bl, SELF );
  3718. p.AID = disguised_bl_id( p.AID );
  3719. p.effectState = OPTION_INVISIBLE;
  3720. clif_send( &p, sizeof( p ), bl, SELF );
  3721. }else{
  3722. clif_send( &p, sizeof( p ), bl, AREA );
  3723. }
  3724. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3725. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3726. if( sc->data[SC_PROVOKE] ){
  3727. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3728. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3729. }
  3730. }else{
  3731. if( disguised( bl ) ){
  3732. p.AID = disguised_bl_id( p.AID );
  3733. clif_send( &p, sizeof( p ), target, SELF );
  3734. p.AID = disguised_bl_id( p.AID );
  3735. p.effectState = OPTION_INVISIBLE;
  3736. clif_send( &p, sizeof( p ), target, SELF );
  3737. }else{
  3738. clif_send( &p, sizeof( p ), target, SELF );
  3739. }
  3740. }
  3741. }
  3742. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3743. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3744. void clif_changeoption2(struct block_list* bl)
  3745. {
  3746. unsigned char buf[20];
  3747. struct status_change *sc;
  3748. sc = status_get_sc(bl);
  3749. if (!sc) return; //How can an option change if there's no sc?
  3750. WBUFW(buf,0) = 0x28a;
  3751. WBUFL(buf,2) = bl->id;
  3752. WBUFL(buf,6) = sc->option;
  3753. WBUFL(buf,10) = clif_setlevel(bl);
  3754. WBUFL(buf,14) = sc->opt3;
  3755. if(disguised(bl)) {
  3756. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3757. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3758. clif_send(buf,packet_len(0x28a),bl,SELF);
  3759. WBUFL(buf,2) = bl->id;
  3760. WBUFL(buf,6) = OPTION_INVISIBLE;
  3761. clif_send(buf,packet_len(0x28a),bl,SELF);
  3762. } else
  3763. clif_send(buf,packet_len(0x28a),bl,AREA);
  3764. }
  3765. /// Notifies the client about the result of an item use request.
  3766. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3767. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3768. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3769. nullpo_retv( sd );
  3770. int fd = sd->fd;
  3771. if( !session_isActive( fd ) ){
  3772. return;
  3773. }
  3774. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3775. return;
  3776. }
  3777. struct PACKET_ZC_USE_ITEM_ACK p;
  3778. p.packetType = useItemAckType;
  3779. p.index = index + 2;
  3780. #if PACKETVER > 3
  3781. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3782. p.AID = sd->bl.id;
  3783. #endif
  3784. p.amount = amount;
  3785. p.result = ok;
  3786. if( !ok ){
  3787. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3788. }else{
  3789. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3790. }
  3791. }
  3792. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3793. /// 00d6 <flag>.B
  3794. /// flag:
  3795. /// 0 = Room has been successfully created (opens chat room)
  3796. /// 1 = Room limit exceeded
  3797. /// 2 = Same room already exists
  3798. void clif_createchat(struct map_session_data* sd, int flag)
  3799. {
  3800. int fd;
  3801. nullpo_retv(sd);
  3802. fd = sd->fd;
  3803. WFIFOHEAD(fd,packet_len(0xd6));
  3804. WFIFOW(fd,0) = 0xd6;
  3805. WFIFOB(fd,2) = flag;
  3806. WFIFOSET(fd,packet_len(0xd6));
  3807. }
  3808. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3809. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3810. /// type:
  3811. /// 0 = private (password protected)
  3812. /// 1 = public
  3813. /// 2 = arena (npc waiting room)
  3814. /// 3 = PK zone (non-clickable)
  3815. void clif_dispchat(struct chat_data* cd, int fd)
  3816. {
  3817. unsigned char buf[128];
  3818. uint8 type;
  3819. if( cd == NULL || cd->owner == NULL )
  3820. return;
  3821. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3822. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3823. : 1;
  3824. WBUFW(buf, 0) = 0xd7;
  3825. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3826. WBUFL(buf, 4) = cd->owner->id;
  3827. WBUFL(buf, 8) = cd->bl.id;
  3828. WBUFW(buf,12) = cd->limit;
  3829. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3830. WBUFB(buf,16) = type;
  3831. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3832. if( session_isActive(fd) ) {
  3833. WFIFOHEAD(fd,WBUFW(buf,2));
  3834. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3835. WFIFOSET(fd,WBUFW(buf,2));
  3836. } else {
  3837. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3838. }
  3839. }
  3840. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3841. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3842. /// type:
  3843. /// 0 = private (password protected)
  3844. /// 1 = public
  3845. /// 2 = arena (npc waiting room)
  3846. /// 3 = PK zone (non-clickable)
  3847. void clif_changechatstatus(struct chat_data* cd)
  3848. {
  3849. unsigned char buf[128];
  3850. uint8 type;
  3851. if( cd == NULL || cd->usersd[0] == NULL )
  3852. return;
  3853. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3854. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3855. : 1;
  3856. WBUFW(buf, 0) = 0xdf;
  3857. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3858. WBUFL(buf, 4) = cd->owner->id;
  3859. WBUFL(buf, 8) = cd->bl.id;
  3860. WBUFW(buf,12) = cd->limit;
  3861. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3862. WBUFB(buf,16) = type;
  3863. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3864. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3865. }
  3866. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3867. /// 00d8 <chat id>.L
  3868. void clif_clearchat(struct chat_data *cd,int fd)
  3869. {
  3870. unsigned char buf[32];
  3871. nullpo_retv(cd);
  3872. WBUFW(buf,0) = 0xd8;
  3873. WBUFL(buf,2) = cd->bl.id;
  3874. if( session_isActive(fd) ) {
  3875. WFIFOHEAD(fd,packet_len(0xd8));
  3876. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3877. WFIFOSET(fd,packet_len(0xd8));
  3878. } else {
  3879. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3880. }
  3881. }
  3882. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3883. /// 00da <result>.B
  3884. /// result:
  3885. /// 0 = room full
  3886. /// 1 = wrong password
  3887. /// 2 = kicked
  3888. /// 3 = success (no message)
  3889. /// 4 = no enough zeny
  3890. /// 5 = too low level
  3891. /// 6 = too high level
  3892. /// 7 = unsuitable job class
  3893. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3894. {
  3895. int fd;
  3896. nullpo_retv(sd);
  3897. fd = sd->fd;
  3898. WFIFOHEAD(fd,packet_len(0xda));
  3899. WFIFOW(fd,0) = 0xda;
  3900. WFIFOB(fd,2) = flag;
  3901. WFIFOSET(fd,packet_len(0xda));
  3902. }
  3903. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3904. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3905. /// role:
  3906. /// 0 = owner (menu)
  3907. /// 1 = normal
  3908. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3909. {
  3910. int fd;
  3911. int i,t;
  3912. nullpo_retv(sd);
  3913. nullpo_retv(cd);
  3914. fd = sd->fd;
  3915. if (!session_isActive(fd))
  3916. return;
  3917. t = (int)(cd->owner->type == BL_NPC);
  3918. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3919. WFIFOW(fd, 0) = 0xdb;
  3920. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3921. WFIFOL(fd, 4) = cd->bl.id;
  3922. if(cd->owner->type == BL_NPC){
  3923. WFIFOL(fd, 30) = 1;
  3924. WFIFOL(fd, 8) = 0;
  3925. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3926. for (i = 0; i < cd->users; i++) {
  3927. WFIFOL(fd, 8+(i+1)*28) = 1;
  3928. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3929. }
  3930. }else{
  3931. for (i = 0; i < cd->users; i++) {
  3932. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3933. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3934. }
  3935. }
  3936. WFIFOSET(fd, WFIFOW(fd, 2));
  3937. }
  3938. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3939. /// 00dc <users>.W <name>.24B
  3940. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3941. {
  3942. unsigned char buf[29];
  3943. nullpo_retv(sd);
  3944. nullpo_retv(cd);
  3945. WBUFW(buf, 0) = 0xdc;
  3946. WBUFW(buf, 2) = cd->users;
  3947. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3948. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3949. }
  3950. /// Announce the new owner (ZC_ROLE_CHANGE).
  3951. /// 00e1 <role>.L <nick>.24B
  3952. /// role:
  3953. /// 0 = owner (menu)
  3954. /// 1 = normal
  3955. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3956. {
  3957. unsigned char buf[64];
  3958. nullpo_retv(sd);
  3959. nullpo_retv(cd);
  3960. WBUFW(buf, 0) = 0xe1;
  3961. WBUFL(buf, 2) = 1;
  3962. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3963. WBUFW(buf,30) = 0xe1;
  3964. WBUFL(buf,32) = 0;
  3965. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3966. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3967. }
  3968. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3969. /// 00dd <users>.W <nick>.24B <flag>.B
  3970. /// flag:
  3971. /// 0 = left
  3972. /// 1 = kicked
  3973. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3974. {
  3975. unsigned char buf[32];
  3976. nullpo_retv(sd);
  3977. nullpo_retv(cd);
  3978. WBUFW(buf, 0) = 0xdd;
  3979. WBUFW(buf, 2) = cd->users-1;
  3980. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3981. WBUFB(buf,28) = flag;
  3982. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3983. }
  3984. /// Opens a trade request window from char 'name'.
  3985. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3986. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3987. void clif_traderequest(struct map_session_data* sd, const char* name)
  3988. {
  3989. int fd = sd->fd;
  3990. #if PACKETVER < 6
  3991. WFIFOHEAD(fd,packet_len(0xe5));
  3992. WFIFOW(fd,0) = 0xe5;
  3993. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3994. WFIFOSET(fd,packet_len(0xe5));
  3995. #else
  3996. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3997. if( !tsd ) return;
  3998. WFIFOHEAD(fd,packet_len(0x1f4));
  3999. WFIFOW(fd,0) = 0x1f4;
  4000. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  4001. WFIFOL(fd,26) = tsd->status.char_id;
  4002. WFIFOW(fd,30) = tsd->status.base_level;
  4003. WFIFOSET(fd,packet_len(0x1f4));
  4004. #endif
  4005. }
  4006. /// Reply to a trade-request.
  4007. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  4008. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  4009. /// result:
  4010. /// 0 = Char is too far
  4011. /// 1 = Character does not exist
  4012. /// 2 = Trade failed
  4013. /// 3 = Accept
  4014. /// 4 = Cancel
  4015. /// 5 = Busy
  4016. void clif_tradestart(struct map_session_data* sd, uint8 type)
  4017. {
  4018. int fd = sd->fd;
  4019. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  4020. if( PACKETVER < 6 || !tsd ) {
  4021. WFIFOHEAD(fd,packet_len(0xe7));
  4022. WFIFOW(fd,0) = 0xe7;
  4023. WFIFOB(fd,2) = type;
  4024. WFIFOSET(fd,packet_len(0xe7));
  4025. } else {
  4026. WFIFOHEAD(fd,packet_len(0x1f5));
  4027. WFIFOW(fd,0) = 0x1f5;
  4028. WFIFOB(fd,2) = type;
  4029. WFIFOL(fd,3) = tsd->status.char_id;
  4030. WFIFOW(fd,7) = tsd->status.base_level;
  4031. WFIFOSET(fd,packet_len(0x1f5));
  4032. }
  4033. }
  4034. /// Notifies the client about an item from other player in current trade.
  4035. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4036. /// 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)
  4037. /// 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)
  4038. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  4039. nullpo_retv( sd );
  4040. nullpo_retv( tsd );
  4041. int fd = tsd->fd;
  4042. if( !session_isActive( fd ) ){
  4043. return;
  4044. }
  4045. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4046. if( index ){
  4047. index = server_index( index );
  4048. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4049. return;
  4050. }
  4051. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4052. #if PACKETVER >= 20100223
  4053. p.itemType = sd->inventory_data[index]->type;
  4054. #endif
  4055. p.identified = sd->inventory.u.items_inventory[index].identify;
  4056. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4057. p.refine = sd->inventory.u.items_inventory[index].refine;
  4058. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4059. #if PACKETVER >= 20150226
  4060. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  4061. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4062. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4063. p.look = sd->inventory_data[index]->look;
  4064. p.enchantgrade = sd->inventory.u.items_inventory[index].enchantgrade;
  4065. #endif
  4066. #endif
  4067. }else{
  4068. p = {};
  4069. }
  4070. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4071. p.amount = amount;
  4072. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4073. }
  4074. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4075. /// 00ea <index>.W <result>.B
  4076. /// result:
  4077. /// 0 = success
  4078. /// 1 = overweight
  4079. /// 2 = trade canceled
  4080. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  4081. {
  4082. int fd;
  4083. nullpo_retv(sd);
  4084. fd = sd->fd;
  4085. WFIFOHEAD(fd,packet_len(0xea));
  4086. WFIFOW(fd,0) = 0xea;
  4087. WFIFOW(fd,2) = index;
  4088. WFIFOB(fd,4) = fail;
  4089. WFIFOSET(fd,packet_len(0xea));
  4090. }
  4091. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4092. /// 00ec <who>.B
  4093. /// who:
  4094. /// 0 = self
  4095. /// 1 = other player
  4096. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  4097. {
  4098. int fd;
  4099. nullpo_retv(sd);
  4100. fd = sd->fd;
  4101. WFIFOHEAD(fd,packet_len(0xec));
  4102. WFIFOW(fd,0) = 0xec;
  4103. WFIFOB(fd,2) = fail;
  4104. WFIFOSET(fd,packet_len(0xec));
  4105. }
  4106. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4107. /// 00ee
  4108. void clif_tradecancelled(struct map_session_data* sd)
  4109. {
  4110. int fd;
  4111. nullpo_retv(sd);
  4112. fd = sd->fd;
  4113. WFIFOHEAD(fd,packet_len(0xee));
  4114. WFIFOW(fd,0) = 0xee;
  4115. WFIFOSET(fd,packet_len(0xee));
  4116. }
  4117. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4118. /// 00f0 <result>.B
  4119. /// result:
  4120. /// 0 = success
  4121. /// 1 = failure
  4122. void clif_tradecompleted(struct map_session_data* sd, int fail)
  4123. {
  4124. int fd;
  4125. nullpo_retv(sd);
  4126. fd = sd->fd;
  4127. WFIFOHEAD(fd,packet_len(0xf0));
  4128. WFIFOW(fd,0) = 0xf0;
  4129. WFIFOB(fd,2) = fail;
  4130. WFIFOSET(fd,packet_len(0xf0));
  4131. }
  4132. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4133. /// 00f1
  4134. /// NOTE: Unknown purpose. Items are not removed until the window is
  4135. /// refreshed (ex. by putting another item in there).
  4136. void clif_tradeundo(struct map_session_data* sd)
  4137. {
  4138. int fd = sd->fd;
  4139. WFIFOHEAD(fd,packet_len(0xf1));
  4140. WFIFOW(fd,0) = 0xf1;
  4141. WFIFOSET(fd,packet_len(0xf1));
  4142. }
  4143. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4144. /// 00f2 <current count>.W <max count>.W
  4145. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  4146. {
  4147. int fd;
  4148. nullpo_retv(sd);
  4149. fd=sd->fd;
  4150. WFIFOHEAD(fd,packet_len(0xf2));
  4151. WFIFOW(fd,0) = 0xf2;
  4152. WFIFOW(fd,2) = amount;
  4153. WFIFOW(fd,4) = max_amount;
  4154. WFIFOSET(fd,packet_len(0xf2));
  4155. }
  4156. /// Notifies the client of an item being added to the storage.
  4157. /// 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)
  4158. /// 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)
  4159. /// 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)
  4160. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  4161. nullpo_retv( sd );
  4162. nullpo_retv( i );
  4163. int fd = sd->fd;
  4164. if( !session_isActive( fd ) ){
  4165. return;
  4166. }
  4167. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4168. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4169. p.index = client_storage_index( index ); // index
  4170. p.amount = amount; // amount
  4171. p.itemId = client_nameid( i->nameid ); // id
  4172. #if PACKETVER >= 5
  4173. p.itemType = itemtype( i->nameid ); //type
  4174. #endif
  4175. p.identified = i->identify; //identify flag
  4176. p.damaged = i->attribute; // attribute
  4177. p.refine = i->refine; //refine
  4178. clif_addcards( &p.slot, i );
  4179. #if PACKETVER >= 20150226
  4180. clif_add_random_options( p.option_data, i );
  4181. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4182. p.enchantgrade = i->enchantgrade;
  4183. #endif
  4184. #endif
  4185. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4186. }
  4187. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4188. /// 00f6 <index>.W <amount>.L
  4189. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4190. {
  4191. int fd;
  4192. nullpo_retv(sd);
  4193. fd=sd->fd;
  4194. WFIFOHEAD(fd,packet_len(0xf6));
  4195. WFIFOW(fd,0)=0xf6; // Storage item removed
  4196. WFIFOW(fd,2)=client_storage_index(index);
  4197. WFIFOL(fd,4)=amount;
  4198. WFIFOSET(fd,packet_len(0xf6));
  4199. }
  4200. /// Closes storage (ZC_CLOSE_STORE).
  4201. /// 00f8
  4202. void clif_storageclose(struct map_session_data* sd)
  4203. {
  4204. int fd;
  4205. nullpo_retv(sd);
  4206. fd=sd->fd;
  4207. WFIFOHEAD(fd,packet_len(0xf8));
  4208. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4209. WFIFOSET(fd,packet_len(0xf8));
  4210. }
  4211. /// Notifies clients in an area of a player's souls.
  4212. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4213. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4214. /// 0b73 <id>.L <amount>.W
  4215. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4216. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4217. struct PACKET_ZC_UNCONFIRMED_SPIRITS3 p = {};
  4218. p.packetType = HEADER_ZC_UNCONFIRMED_SPIRITS3;
  4219. #else
  4220. struct PACKET_ZC_SPIRITS p = {};
  4221. p.packetType = HEADER_ZC_SPIRITS;
  4222. #endif
  4223. p.GID = sd->bl.id;
  4224. p.amount = sd->soulball;
  4225. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4226. }
  4227. /*==========================================
  4228. * Server tells 'sd' player client the abouts of 'dstsd' player
  4229. *------------------------------------------*/
  4230. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4231. {
  4232. struct block_list *d_bl;
  4233. int i;
  4234. if( dstsd->chatID ) {
  4235. struct chat_data *cd = NULL;
  4236. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4237. clif_dispchat(cd,sd->fd);
  4238. } else if( dstsd->state.vending )
  4239. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4240. else if( dstsd->state.buyingstore )
  4241. clif_buyingstore_entry_single(sd, dstsd);
  4242. if(dstsd->spiritball > 0)
  4243. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4244. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4245. clif_millenniumshield_single(sd->fd, dstsd);
  4246. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4247. clif_spiritcharm_single(sd->fd, dstsd);
  4248. if (dstsd->soulball > 0)
  4249. clif_soulball( dstsd, &sd->bl, SELF );
  4250. if (dstsd->servantball > 0)
  4251. clif_servantball( *dstsd, &sd->bl, SELF );
  4252. if (dstsd->abyssball > 0)
  4253. clif_abyssball( *dstsd, &sd->bl, SELF );
  4254. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4255. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4256. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4257. )
  4258. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4259. // display link (sd - dstsd) to sd
  4260. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4261. if( i < MAX_DEVOTION )
  4262. clif_devotion(&sd->bl, sd);
  4263. // display links (dstsd - devotees) to sd
  4264. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4265. if( i < MAX_DEVOTION )
  4266. clif_devotion(&dstsd->bl, sd);
  4267. // display link (dstsd - crusader) to sd
  4268. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4269. clif_devotion(d_bl, sd);
  4270. }
  4271. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4272. struct unit_data *ud;
  4273. struct view_data *vd;
  4274. bool option = false;
  4275. unsigned int option_val = 0;
  4276. vd = status_get_viewdata(bl);
  4277. if (!vd || vd->class_ == JT_INVISIBLE)
  4278. return;
  4279. // Hide NPC from Maya Purple card
  4280. if (clif_npc_mayapurple(bl))
  4281. return;
  4282. ud = unit_bl2ud(bl);
  4283. if( ud && ud->walktimer != INVALID_TIMER ){
  4284. clif_set_unit_walking( bl, sd, ud, SELF );
  4285. }else{
  4286. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4287. }
  4288. if (vd->cloth_color)
  4289. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4290. if (vd->body_style)
  4291. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4292. switch (bl->type)
  4293. {
  4294. case BL_PC:
  4295. {
  4296. TBL_PC* tsd = (TBL_PC*)bl;
  4297. clif_getareachar_pc(sd, tsd);
  4298. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4299. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4300. else if(tsd->state.size==SZ_MEDIUM)
  4301. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4302. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4303. clif_sendbgemblem_single(sd->fd,tsd);
  4304. if ( tsd->status.robe )
  4305. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4306. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4307. clif_hat_effects(sd,bl,SELF);
  4308. }
  4309. break;
  4310. case BL_MER: // Devotion Effects
  4311. if( ((TBL_MER*)bl)->devotion_flag )
  4312. clif_devotion(bl, sd);
  4313. break;
  4314. case BL_NPC:
  4315. {
  4316. TBL_NPC* nd = (TBL_NPC*)bl;
  4317. if( nd->chat_id )
  4318. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4319. if( nd->size == SZ_BIG )
  4320. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4321. else if( nd->size == SZ_MEDIUM )
  4322. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4323. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4324. clif_progressbar_npc(nd, sd);
  4325. }
  4326. break;
  4327. case BL_MOB:
  4328. {
  4329. TBL_MOB* md = (TBL_MOB*)bl;
  4330. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4331. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4332. else if(md->special_state.size==SZ_MEDIUM)
  4333. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4334. #if PACKETVER >= 20120404
  4335. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4336. int i;
  4337. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4338. if( md->dmglog[i].id == sd->status.char_id )
  4339. clif_monster_hp_bar(md, sd->fd);
  4340. }
  4341. #endif
  4342. }
  4343. break;
  4344. case BL_PET:
  4345. if (vd->head_bottom)
  4346. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4347. break;
  4348. }
  4349. }
  4350. //Modifies the type of damage according to status changes [Skotlex]
  4351. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4352. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4353. {
  4354. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4355. }
  4356. /*==========================================
  4357. * Estimates walk delay based on the damage criteria. [Skotlex]
  4358. *------------------------------------------*/
  4359. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4360. {
  4361. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4362. return 0;
  4363. if (bl->type == BL_PC) {
  4364. if (battle_config.pc_walk_delay_rate != 100)
  4365. delay = delay*battle_config.pc_walk_delay_rate/100;
  4366. } else
  4367. if (battle_config.walk_delay_rate != 100)
  4368. delay = delay*battle_config.walk_delay_rate/100;
  4369. if (div_ > 1) //Multi-hit skills mean higher delays.
  4370. delay += battle_config.multihit_delay*(div_-1);
  4371. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4372. }
  4373. /*========================================== [Playtester]
  4374. * Returns hallucination damage the client displays
  4375. *------------------------------------------*/
  4376. static int clif_hallucination_damage()
  4377. {
  4378. int digit = rnd() % 5 + 1;
  4379. switch (digit)
  4380. {
  4381. case 1:
  4382. return (rnd() % 10);
  4383. case 2:
  4384. return (rnd() % 100);
  4385. case 3:
  4386. return (rnd() % 1000);
  4387. case 4:
  4388. return (rnd() % 10000);
  4389. }
  4390. return (rnd() % 32767);
  4391. }
  4392. /// Sends a 'damage' packet (src performs action on dst)
  4393. /// 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)
  4394. /// 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)
  4395. /// 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)
  4396. /// type:
  4397. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4398. /// 1 = pick up item
  4399. /// 2 = sit down
  4400. /// 3 = stand up
  4401. /// 4 = damage (endure)
  4402. /// 5 = (splash?)
  4403. /// 6 = (skill?)
  4404. /// 7 = (repeat damage?)
  4405. /// 8 = multi-hit damage
  4406. /// 9 = multi-hit damage (endure)
  4407. /// 10 = critical hit
  4408. /// 11 = lucky dodge
  4409. /// 12 = (touch skill?)
  4410. /// 13 = multi-hit critical
  4411. 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)
  4412. {
  4413. unsigned char buf[34];
  4414. struct status_change *sc;
  4415. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4416. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4417. #if PACKETVER < 20071113
  4418. const int cmd = 0x8a;
  4419. int offset = 0;
  4420. #elif PACKETVER < 20131223
  4421. const int cmd = 0x2e1;
  4422. int offset = 2;
  4423. #else
  4424. const int cmd = 0x8c8;
  4425. int offset = 3;
  4426. #endif
  4427. nullpo_ret(src);
  4428. nullpo_ret(dst);
  4429. if (type != DMG_MULTI_HIT_CRITICAL)
  4430. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4431. sc = status_get_sc(dst);
  4432. if(sc && sc->count) {
  4433. if(sc->data[SC_HALLUCINATION]) {
  4434. damage = clif_hallucination_damage();
  4435. if(damage2) damage2 = clif_hallucination_damage();
  4436. }
  4437. }
  4438. WBUFW(buf,0) = cmd;
  4439. WBUFL(buf,2) = src->id;
  4440. WBUFL(buf,6) = dst->id;
  4441. WBUFL(buf,10) = client_tick(tick);
  4442. WBUFL(buf,14) = sdelay;
  4443. WBUFL(buf,18) = ddelay;
  4444. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4445. #if PACKETVER < 20071113
  4446. WBUFW(buf,22) = damage ? div : 0;
  4447. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4448. #else
  4449. WBUFL(buf, 22) = damage ? div : 0;
  4450. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4451. #endif
  4452. } else {
  4453. #if PACKETVER < 20071113
  4454. WBUFW(buf,22) = min(damage, INT16_MAX);
  4455. WBUFW(buf,27+offset) = damage2;
  4456. #else
  4457. WBUFL(buf,22) = damage;
  4458. WBUFL(buf,27+offset) = damage2;
  4459. #endif
  4460. }
  4461. #if PACKETVER >= 20131223
  4462. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4463. #endif
  4464. WBUFW(buf,24+offset) = div;
  4465. WBUFB(buf,26+offset) = type;
  4466. if(disguised(dst)) {
  4467. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4468. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4469. clif_send(buf, packet_len(cmd), dst, SELF);
  4470. } else
  4471. clif_send(buf, packet_len(cmd), dst, AREA);
  4472. if(disguised(src)) {
  4473. WBUFL(buf,2) = disguised_bl_id( src->id );
  4474. if (disguised(dst))
  4475. WBUFL(buf,6) = dst->id;
  4476. #if PACKETVER < 20071113
  4477. if(damage > 0) WBUFW(buf,22) = -1;
  4478. if(damage2 > 0) WBUFW(buf,27) = -1;
  4479. #else
  4480. if(damage > 0) WBUFL(buf,22) = -1;
  4481. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4482. #endif
  4483. clif_send(buf,packet_len(cmd),src,SELF);
  4484. }
  4485. if(src == dst) {
  4486. unit_setdir(src, unit_getdir(src));
  4487. }
  4488. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4489. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4490. //Return adjusted can't walk delay for further processing.
  4491. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4492. }
  4493. /*==========================================
  4494. * src picks up dst
  4495. *------------------------------------------*/
  4496. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4497. {
  4498. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4499. unsigned char buf[32];
  4500. nullpo_retv(src);
  4501. nullpo_retv(dst);
  4502. WBUFW(buf, 0) = 0x8a;
  4503. WBUFL(buf, 2) = src->id;
  4504. WBUFL(buf, 6) = dst->id;
  4505. WBUFB(buf,26) = 1;
  4506. clif_send(buf, packet_len(0x8a), src, AREA);
  4507. }
  4508. /*==========================================
  4509. * inform clients in area that `bl` is sitting
  4510. *------------------------------------------*/
  4511. void clif_sitting(struct block_list* bl)
  4512. {
  4513. unsigned char buf[32];
  4514. nullpo_retv(bl);
  4515. WBUFW(buf, 0) = 0x8a;
  4516. WBUFL(buf, 2) = bl->id;
  4517. WBUFB(buf,26) = 2;
  4518. clif_send(buf, packet_len(0x8a), bl, AREA);
  4519. if(disguised(bl)) {
  4520. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4521. clif_send(buf, packet_len(0x8a), bl, SELF);
  4522. }
  4523. }
  4524. /*==========================================
  4525. * inform clients in area that `bl` is standing
  4526. *------------------------------------------*/
  4527. void clif_standing(struct block_list* bl)
  4528. {
  4529. unsigned char buf[32];
  4530. nullpo_retv(bl);
  4531. WBUFW(buf, 0) = 0x8a;
  4532. WBUFL(buf, 2) = bl->id;
  4533. WBUFB(buf,26) = 3;
  4534. clif_send(buf, packet_len(0x8a), bl, AREA);
  4535. if(disguised(bl)) {
  4536. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4537. clif_send(buf, packet_len(0x8a), bl, SELF);
  4538. }
  4539. }
  4540. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4541. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4542. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4543. {
  4544. unsigned char buf[32];
  4545. WBUFW(buf,0) = 0x192;
  4546. WBUFW(buf,2) = x;
  4547. WBUFW(buf,4) = y;
  4548. WBUFW(buf,6) = type;
  4549. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4550. if( session_isActive(fd) )
  4551. {
  4552. WFIFOHEAD(fd,packet_len(0x192));
  4553. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4554. WFIFOSET(fd,packet_len(0x192));
  4555. }
  4556. else
  4557. {
  4558. struct block_list dummy_bl;
  4559. dummy_bl.type = BL_NUL;
  4560. dummy_bl.x = x;
  4561. dummy_bl.y = y;
  4562. dummy_bl.m = m;
  4563. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4564. }
  4565. }
  4566. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4567. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4568. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4569. nullpo_retv( sd );
  4570. nullpo_retv( fitem );
  4571. struct PACKET_ZC_ITEM_ENTRY p;
  4572. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4573. p.AID = fitem->bl.id;
  4574. p.itemId = client_nameid( fitem->item.nameid );
  4575. p.identify = fitem->item.identify;
  4576. p.x = fitem->bl.x;
  4577. p.y = fitem->bl.y;
  4578. p.amount = fitem->item.amount;
  4579. p.subX = fitem->subx;
  4580. p.subY = fitem->suby;
  4581. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4582. }
  4583. /// Notifes client about Graffiti
  4584. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4585. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4586. unsigned char buf[128];
  4587. nullpo_retv(bl);
  4588. nullpo_retv(unit);
  4589. WBUFW(buf, 0) = 0x1c9;
  4590. WBUFL(buf, 2) = unit->bl.id;
  4591. WBUFL(buf, 6) = unit->group->src_id;
  4592. WBUFW(buf,10) = unit->bl.x;
  4593. WBUFW(buf,12) = unit->bl.y;
  4594. WBUFB(buf,14) = unit->group->unit_id;
  4595. WBUFB(buf,15) = 1;
  4596. WBUFB(buf,16) = 1;
  4597. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4598. clif_send(buf,packet_len(0x1c9),bl,target);
  4599. }
  4600. /// Notifies the client of a skill unit.
  4601. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4602. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4603. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4604. /// 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)
  4605. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4606. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4607. unsigned char buf[128];
  4608. nullpo_retv(bl);
  4609. nullpo_retv(unit);
  4610. if (bl->type == BL_PC)
  4611. fd = ((TBL_PC*)bl)->fd;
  4612. if (unit->group->state.guildaura)
  4613. return;
  4614. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4615. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4616. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4617. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4618. else
  4619. unit_id = unit->group->unit_id;
  4620. if (!visible)
  4621. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4622. #if PACKETVER >= 3
  4623. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4624. clif_graffiti(bl, unit, target);
  4625. return;
  4626. }
  4627. #endif
  4628. #if PACKETVER <= 20120702
  4629. header = 0x011f;
  4630. //#if PACKETVER < 20110718
  4631. // header = 0x011f;
  4632. //#elif PACKETVER < 20121212
  4633. // header = 0x08c7;
  4634. #elif PACKETVER < 20130731
  4635. header = 0x099f;
  4636. #else
  4637. header = 0x09ca;
  4638. #endif
  4639. len = packet_len(header);
  4640. WBUFW(buf,pos) = header;
  4641. if (header != 0x011f) {
  4642. WBUFW(buf, pos+2) = len;
  4643. pos += 2;
  4644. }
  4645. WBUFL(buf,pos+2) = unit->bl.id;
  4646. WBUFL(buf,pos+6) = unit->group->src_id;
  4647. WBUFW(buf,pos+10) = unit->bl.x;
  4648. WBUFW(buf,pos+12) = unit->bl.y;
  4649. switch (header) {
  4650. case 0x011f:
  4651. WBUFB(buf,pos+14) = unit_id;
  4652. WBUFB(buf,pos+15) = visible;
  4653. break;
  4654. case 0x08c7:
  4655. WBUFB(buf,pos+14) = unit_id;
  4656. WBUFW(buf,pos+15) = unit->range;
  4657. WBUFB(buf,pos+17) = visible;
  4658. break;
  4659. case 0x099f:
  4660. WBUFL(buf,pos+14) = unit_id;
  4661. WBUFW(buf,pos+18) = unit->range;
  4662. WBUFB(buf,pos+20) = visible;
  4663. break;
  4664. case 0x09ca:
  4665. WBUFL(buf,pos+14) = unit_id;
  4666. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4667. WBUFB(buf,pos+19) = visible;
  4668. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4669. break;
  4670. }
  4671. clif_send(buf, len, bl, target);
  4672. if (unit->group->skill_id == WZ_ICEWALL)
  4673. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4674. }
  4675. /// 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)
  4676. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4677. unsigned char buf[128];
  4678. nullpo_retv(bl);
  4679. WBUFW(buf, 0) = 0x09ca;
  4680. WBUFW(buf, 2) = packet_len(0x09ca);
  4681. WBUFL(buf, 4) = 1000;
  4682. WBUFL(buf, 8) = 2000;
  4683. WBUFW(buf, 12) = x;
  4684. WBUFW(buf, 14) = y;
  4685. WBUFL(buf, 16) = unit_id;
  4686. WBUFB(buf, 20) = (unsigned char)range;
  4687. WBUFB(buf, 21) = 1;
  4688. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4689. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4690. }
  4691. /*==========================================
  4692. * Server tells client to remove unit of id 'unit->bl.id'
  4693. *------------------------------------------*/
  4694. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4695. {
  4696. nullpo_retv(unit);
  4697. WFIFOHEAD(fd,packet_len(0x120));
  4698. WFIFOW(fd, 0)=0x120;
  4699. WFIFOL(fd, 2)=unit->bl.id;
  4700. WFIFOSET(fd,packet_len(0x120));
  4701. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4702. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4703. }
  4704. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4705. /// 0120 <id>.L
  4706. void clif_skill_delunit(struct skill_unit *unit)
  4707. {
  4708. unsigned char buf[16];
  4709. nullpo_retv(unit);
  4710. WBUFW(buf, 0)=0x120;
  4711. WBUFL(buf, 2)=unit->bl.id;
  4712. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4713. }
  4714. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4715. /// 01ac <id>.L
  4716. /// Only affects units with class [139,153] client-side.
  4717. void clif_skillunit_update(struct block_list* bl)
  4718. {
  4719. unsigned char buf[6];
  4720. nullpo_retv(bl);
  4721. WBUFW(buf,0) = 0x1ac;
  4722. WBUFL(buf,2) = bl->id;
  4723. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4724. }
  4725. /*==========================================
  4726. *
  4727. *------------------------------------------*/
  4728. static int clif_getareachar(struct block_list* bl,va_list ap)
  4729. {
  4730. struct map_session_data *sd;
  4731. nullpo_ret(bl);
  4732. sd=va_arg(ap,struct map_session_data*);
  4733. if (!clif_session_isValid(sd))
  4734. return 0;
  4735. switch(bl->type){
  4736. case BL_ITEM:
  4737. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4738. break;
  4739. case BL_SKILL:
  4740. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4741. break;
  4742. default:
  4743. if(&sd->bl == bl)
  4744. break;
  4745. clif_getareachar_unit(sd,bl);
  4746. break;
  4747. }
  4748. return 0;
  4749. }
  4750. /*==========================================
  4751. * tbl has gone out of view-size of bl
  4752. *------------------------------------------*/
  4753. int clif_outsight(struct block_list *bl,va_list ap)
  4754. {
  4755. struct block_list *tbl;
  4756. struct view_data *vd;
  4757. TBL_PC *sd, *tsd;
  4758. tbl=va_arg(ap,struct block_list*);
  4759. if(bl == tbl) return 0;
  4760. sd = BL_CAST(BL_PC, bl);
  4761. tsd = BL_CAST(BL_PC, tbl);
  4762. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4763. nullpo_ret(bl);
  4764. switch(bl->type){
  4765. case BL_PC:
  4766. if(sd->vd.class_ != JT_INVISIBLE)
  4767. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4768. if(sd->chatID){
  4769. struct chat_data *cd;
  4770. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4771. if(cd->usersd[0]==sd)
  4772. clif_dispchat(cd,tsd->fd);
  4773. }
  4774. if(sd->state.vending)
  4775. clif_closevendingboard(bl,tsd->fd);
  4776. if(sd->state.buyingstore)
  4777. clif_buyingstore_disappear_entry_single(tsd, sd);
  4778. break;
  4779. case BL_ITEM:
  4780. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4781. break;
  4782. case BL_SKILL:
  4783. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4784. break;
  4785. case BL_NPC:
  4786. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4787. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4788. break;
  4789. default:
  4790. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4791. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4792. break;
  4793. }
  4794. }
  4795. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4796. nullpo_ret(tbl);
  4797. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4798. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4799. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4800. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4801. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4802. }
  4803. return 0;
  4804. }
  4805. /*==========================================
  4806. * tbl has come into view of bl
  4807. *------------------------------------------*/
  4808. int clif_insight(struct block_list *bl,va_list ap)
  4809. {
  4810. struct block_list *tbl;
  4811. TBL_PC *sd, *tsd;
  4812. tbl=va_arg(ap,struct block_list*);
  4813. if (bl == tbl) return 0;
  4814. sd = BL_CAST(BL_PC, bl);
  4815. tsd = BL_CAST(BL_PC, tbl);
  4816. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4817. switch(bl->type){
  4818. case BL_ITEM:
  4819. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4820. break;
  4821. case BL_SKILL:
  4822. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4823. break;
  4824. default:
  4825. clif_getareachar_unit(tsd,bl);
  4826. break;
  4827. }
  4828. }
  4829. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4830. clif_getareachar_unit(sd,tbl);
  4831. }
  4832. return 0;
  4833. }
  4834. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4835. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4836. void clif_skillinfoblock(struct map_session_data *sd)
  4837. {
  4838. int fd;
  4839. int i,len,id;
  4840. nullpo_retv(sd);
  4841. fd = sd->fd;
  4842. if (!session_isActive(fd))
  4843. return;
  4844. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4845. WFIFOW(fd,0) = 0x10f;
  4846. bool haveCallPartnerSkill = false;
  4847. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4848. {
  4849. if( (id = sd->status.skill[i].id) != 0 )
  4850. {
  4851. // workaround for bugreport:5348
  4852. if (len + 37 > 8192)
  4853. break;
  4854. // skip WE_CALLPARTNER and send it in special way
  4855. if (id == WE_CALLPARTNER) {
  4856. haveCallPartnerSkill = true;
  4857. continue;
  4858. }
  4859. WFIFOW(fd,len) = id;
  4860. WFIFOL(fd,len+2) = skill_get_inf(id);
  4861. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4862. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4863. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4864. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4865. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4866. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4867. else
  4868. WFIFOB(fd,len+36) = 0;
  4869. len += 37;
  4870. }
  4871. }
  4872. WFIFOW(fd,2)=len;
  4873. WFIFOSET(fd,len);
  4874. // adoption fix
  4875. if (haveCallPartnerSkill) {
  4876. clif_addskill(sd, WE_CALLPARTNER);
  4877. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4878. }
  4879. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4880. for ( ; i < MAX_SKILL; i++)
  4881. {
  4882. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4883. {
  4884. clif_addskill(sd, id);
  4885. clif_skillinfo(sd, id, 0);
  4886. }
  4887. }
  4888. }
  4889. /**
  4890. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4891. **/
  4892. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4893. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4894. void clif_addskill(struct map_session_data *sd, int skill_id)
  4895. {
  4896. nullpo_retv(sd);
  4897. int fd = sd->fd;
  4898. uint16 idx = skill_get_index(skill_id);
  4899. if (!session_isActive(fd) || !idx)
  4900. return;
  4901. if( sd->status.skill[idx].id <= 0 )
  4902. return;
  4903. WFIFOHEAD(fd, packet_len(0x111));
  4904. WFIFOW(fd,0) = 0x111;
  4905. WFIFOW(fd,2) = skill_id;
  4906. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4907. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4908. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4909. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4910. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4911. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4912. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4913. else
  4914. WFIFOB(fd,38) = 0;
  4915. WFIFOSET(fd,packet_len(0x111));
  4916. }
  4917. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4918. /// 0441 <skill id>.W
  4919. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4920. {
  4921. #if PACKETVER >= 20081217
  4922. nullpo_retv(sd);
  4923. int fd = sd->fd;
  4924. uint16 idx = skill_get_index(skill_id);
  4925. if (!session_isActive(fd) || !idx)
  4926. return;
  4927. WFIFOHEAD(fd,packet_len(0x441));
  4928. WFIFOW(fd,0) = 0x441;
  4929. WFIFOW(fd,2) = skill_id;
  4930. WFIFOSET(fd,packet_len(0x441));
  4931. #endif
  4932. clif_skillinfoblock(sd);
  4933. }
  4934. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4935. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4936. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4937. nullpo_retv(sd);
  4938. int fd = sd->fd;
  4939. uint16 idx = skill_get_index(skill_id);
  4940. if (!session_isActive(fd) || !idx)
  4941. return;
  4942. WFIFOHEAD(fd, packet_len(0x10e));
  4943. WFIFOW(fd, 0) = 0x10e;
  4944. WFIFOW(fd, 2) = skill_id;
  4945. WFIFOW(fd, 4) = lv;
  4946. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4947. WFIFOW(fd, 8) = range;
  4948. WFIFOB(fd, 10) = upgradable;
  4949. WFIFOSET(fd, packet_len(0x10e));
  4950. }
  4951. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4952. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4953. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4954. {
  4955. nullpo_retv(sd);
  4956. const int fd = sd->fd;
  4957. uint16 idx = skill_get_index(skill_id);
  4958. if (!session_isActive(fd) || !idx)
  4959. return;
  4960. WFIFOHEAD(fd,packet_len(0x7e1));
  4961. WFIFOW(fd,0) = 0x7e1;
  4962. WFIFOW(fd,2) = skill_id;
  4963. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4964. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4965. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4966. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4967. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4968. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4969. else
  4970. WFIFOB(fd,14) = 0;
  4971. WFIFOSET(fd,packet_len(0x7e1));
  4972. }
  4973. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4974. #if PACKETVER >= 20151223
  4975. if( !battle_config.show_skill_scale ){
  4976. return;
  4977. }
  4978. struct PACKET_ZC_SKILL_SCALE p;
  4979. p.PacketType = skillscale;
  4980. p.AID = src_id;
  4981. p.skill_id = skill_id;
  4982. p.skill_lv = skill_lv;
  4983. p.x = x;
  4984. p.y = y;
  4985. p.casttime = casttime;
  4986. if( disguised( bl ) ){
  4987. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4988. p.AID = disguised_bl_id( bl->id );
  4989. clif_send( &p, sizeof( p ), bl, SELF );
  4990. }else{
  4991. clif_send( &p, sizeof( p ), bl, AREA );
  4992. }
  4993. #endif
  4994. }
  4995. /// Notifies clients in area, that an object is about to use a skill.
  4996. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4997. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4998. /// property:
  4999. /// 0 = Yellow cast aura
  5000. /// 1 = Water elemental cast aura
  5001. /// 2 = Earth elemental cast aura
  5002. /// 3 = Fire elemental cast aura
  5003. /// 4 = Wind elemental cast aura
  5004. /// 5 = Poison elemental cast aura
  5005. /// 6 = Holy elemental cast aura
  5006. /// ? = like 0
  5007. /// is disposable:
  5008. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  5009. /// 1 = no text
  5010. 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)
  5011. {
  5012. #if PACKETVER < 20091124
  5013. const int cmd = 0x13e;
  5014. #else
  5015. const int cmd = 0x7fb;
  5016. #endif
  5017. unsigned char buf[32];
  5018. WBUFW(buf,0) = cmd;
  5019. WBUFL(buf,2) = src_id;
  5020. WBUFL(buf,6) = dst_id;
  5021. WBUFW(buf,10) = dst_x;
  5022. WBUFW(buf,12) = dst_y;
  5023. WBUFW(buf,14) = skill_id;
  5024. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5025. WBUFL(buf,20) = casttime;
  5026. #if PACKETVER >= 20091124
  5027. WBUFB(buf,24) = 0; // isDisposable
  5028. #endif
  5029. if (disguised(bl)) {
  5030. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5031. WBUFL(buf,2) = disguised_bl_id( src_id );
  5032. clif_send(buf,packet_len(cmd), bl, SELF);
  5033. } else
  5034. clif_send(buf,packet_len(cmd), bl, AREA);
  5035. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5036. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5037. }
  5038. }
  5039. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5040. /// 01b9 <id>.L
  5041. void clif_skillcastcancel(struct block_list* bl)
  5042. {
  5043. unsigned char buf[16];
  5044. nullpo_retv(bl);
  5045. WBUFW(buf,0) = 0x1b9;
  5046. WBUFL(buf,2) = bl->id;
  5047. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5048. }
  5049. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5050. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5051. /// num (only used when skill id = NV_BASIC and cause = 0):
  5052. /// 0 = "skill failed" MsgStringTable[159]
  5053. /// 1 = "no emotions" MsgStringTable[160]
  5054. /// 2 = "no sit" MsgStringTable[161]
  5055. /// 3 = "no chat" MsgStringTable[162]
  5056. /// 4 = "no party" MsgStringTable[163]
  5057. /// 5 = "no shout" MsgStringTable[164]
  5058. /// 6 = "no PKing" MsgStringTable[165]
  5059. /// 7 = "no alligning" MsgStringTable[383]
  5060. /// ? = ignored
  5061. /// cause:
  5062. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5063. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5064. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5065. /// "skill failed" MsgStringTable[204] (otherwise)
  5066. /// ... = @see enum useskill_fail_cause
  5067. /// ? = ignored
  5068. ///
  5069. /// if(result!=0) doesn't display any of the previous messages
  5070. /// Note: when this packet is received an unknown flag is always set to 0,
  5071. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5072. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5073. nullpo_retv( sd );
  5074. int fd = sd->fd;
  5075. if( !session_isActive( fd ) ){
  5076. return;
  5077. }
  5078. if(battle_config.display_skill_fail&1)
  5079. return; //Disable all skill failed messages
  5080. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5081. return; //Disable delay failed messages
  5082. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5083. return;
  5084. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5085. return;
  5086. struct PACKET_ZC_ACK_TOUSESKILL p;
  5087. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5088. p.skillId = skill_id;
  5089. p.btype = btype;
  5090. p.itemId = itemId;
  5091. p.flag = 0; // 0 - failed
  5092. p.cause = cause;
  5093. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5094. }
  5095. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5096. /// 043d <skill ID>.W <tick>.L
  5097. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  5098. {
  5099. #if PACKETVER>=20081112
  5100. int fd;
  5101. nullpo_retv(sd);
  5102. fd=sd->fd;
  5103. WFIFOHEAD(fd,packet_len(0x43d));
  5104. WFIFOW(fd,0) = 0x43d;
  5105. WFIFOW(fd,2) = skill_id;
  5106. WFIFOL(fd,4) = client_tick(tick);
  5107. WFIFOSET(fd,packet_len(0x43d));
  5108. #endif
  5109. }
  5110. /// Skill attack effect and damage.
  5111. /// 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)
  5112. /// 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)
  5113. 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)
  5114. {
  5115. unsigned char buf[64];
  5116. struct status_change *sc;
  5117. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5118. nullpo_ret(src);
  5119. nullpo_ret(dst);
  5120. type = clif_calc_delay(type,div,damage,ddelay);
  5121. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5122. if(sc->data[SC_HALLUCINATION] && damage)
  5123. damage = clif_hallucination_damage();
  5124. }
  5125. #if PACKETVER < 3
  5126. WBUFW(buf,0)=0x114;
  5127. WBUFW(buf,2)=skill_id;
  5128. WBUFL(buf,4)=src->id;
  5129. WBUFL(buf,8)=dst->id;
  5130. WBUFL(buf,12)=client_tick(tick);
  5131. WBUFL(buf,16)=sdelay;
  5132. WBUFL(buf,20)=ddelay;
  5133. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5134. WBUFW(buf,24)=damage?div:0;
  5135. } else {
  5136. WBUFW(buf,24)=damage;
  5137. }
  5138. WBUFW(buf,26)=skill_lv;
  5139. WBUFW(buf,28)=div;
  5140. WBUFB(buf,30)=type;
  5141. if (disguised(dst)) {
  5142. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5143. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5144. clif_send(buf,packet_len(0x114),dst,SELF);
  5145. } else
  5146. clif_send(buf,packet_len(0x114),dst,AREA);
  5147. if(disguised(src)) {
  5148. WBUFL(buf,4)=disguised_bl_id(src->id);
  5149. if (disguised(dst))
  5150. WBUFL(buf,8)=dst->id;
  5151. if(damage > 0)
  5152. WBUFW(buf,24)=-1;
  5153. clif_send(buf,packet_len(0x114),src,SELF);
  5154. }
  5155. #else
  5156. WBUFW(buf,0)=0x1de;
  5157. WBUFW(buf,2)=skill_id;
  5158. WBUFL(buf,4)=src->id;
  5159. WBUFL(buf,8)=dst->id;
  5160. WBUFL(buf,12)=client_tick(tick);
  5161. WBUFL(buf,16)=sdelay;
  5162. WBUFL(buf,20)=ddelay;
  5163. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5164. WBUFL(buf,24)=damage?div:0;
  5165. } else {
  5166. WBUFL(buf,24)=damage;
  5167. }
  5168. WBUFW(buf,28)=skill_lv;
  5169. WBUFW(buf,30)=div;
  5170. // For some reason, late 2013 and newer clients have
  5171. // a issue that causes players and monsters to endure
  5172. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5173. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5174. #if PACKETVER < 20131223
  5175. WBUFB(buf,32)=type;
  5176. #else
  5177. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5178. #endif
  5179. if (disguised(dst)) {
  5180. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5181. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5182. clif_send(buf,packet_len(0x1de),dst,SELF);
  5183. } else
  5184. clif_send(buf,packet_len(0x1de),dst,AREA);
  5185. if(disguised(src)) {
  5186. WBUFL(buf,4)=disguised_bl_id(src->id);
  5187. if (disguised(dst))
  5188. WBUFL(buf,8)=dst->id;
  5189. if(damage > 0)
  5190. WBUFL(buf,24)=-1;
  5191. clif_send(buf,packet_len(0x1de),src,SELF);
  5192. }
  5193. #endif
  5194. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5195. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5196. }
  5197. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5198. /// 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
  5199. /*
  5200. 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)
  5201. {
  5202. unsigned char buf[64];
  5203. struct status_change *sc;
  5204. nullpo_ret(src);
  5205. nullpo_ret(dst);
  5206. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5207. type = clif_calc_delay(type,div,damage,ddelay);
  5208. sc = status_get_sc(dst);
  5209. if(sc && sc->count) {
  5210. if(sc->data[SC_HALLUCINATION] && damage)
  5211. damage = clif_hallucination_damage();
  5212. }
  5213. WBUFW(buf,0)=0x115;
  5214. WBUFW(buf,2)=skill_id;
  5215. WBUFL(buf,4)=src->id;
  5216. WBUFL(buf,8)=dst->id;
  5217. WBUFL(buf,12)=client_tick(tick);
  5218. WBUFL(buf,16)=sdelay;
  5219. WBUFL(buf,20)=ddelay;
  5220. WBUFW(buf,24)=dst->x;
  5221. WBUFW(buf,26)=dst->y;
  5222. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5223. WBUFW(buf,28)=damage?div:0;
  5224. } else {
  5225. WBUFW(buf,28)=damage;
  5226. }
  5227. WBUFW(buf,30)=skill_lv;
  5228. WBUFW(buf,32)=div;
  5229. WBUFB(buf,34)=type;
  5230. clif_send(buf,packet_len(0x115),src,AREA);
  5231. if(disguised(src)) {
  5232. WBUFL(buf,4)=disguised_bl_id(src->id);
  5233. if(damage > 0)
  5234. WBUFW(buf,28)=-1;
  5235. clif_send(buf,packet_len(0x115),src,SELF);
  5236. }
  5237. if (disguised(dst)) {
  5238. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5239. if (disguised(src))
  5240. WBUFL(buf,4)=src->id;
  5241. else if(damage > 0)
  5242. WBUFW(buf,28)=-1;
  5243. clif_send(buf,packet_len(0x115),dst,SELF);
  5244. }
  5245. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5246. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5247. }
  5248. */
  5249. /// Non-damaging skill effect
  5250. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5251. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5252. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5253. {
  5254. unsigned char buf[17];
  5255. #if PACKETVER < 20130731
  5256. const int cmd = 0x11a;
  5257. #else
  5258. const int cmd = 0x9cb;
  5259. #endif
  5260. int offset = 0;
  5261. bool success = ( tick != 0 );
  5262. nullpo_ret(dst);
  5263. WBUFW(buf,0) = cmd;
  5264. WBUFW(buf,2) = skill_id;
  5265. #if PACKETVER < 20130731
  5266. WBUFW(buf,4) = min(heal, INT16_MAX);
  5267. #else
  5268. WBUFL(buf,4) = min(heal, INT32_MAX);
  5269. offset += 2;
  5270. #endif
  5271. WBUFL(buf,6+offset) = dst->id;
  5272. WBUFL(buf,10+offset) = src ? src->id : 0;
  5273. WBUFB(buf,14+offset) = success;
  5274. if (disguised(dst)) {
  5275. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5276. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5277. clif_send(buf, packet_len(cmd), dst, SELF);
  5278. } else
  5279. clif_send(buf, packet_len(cmd), dst, AREA);
  5280. if(src && disguised(src)) {
  5281. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5282. if (disguised(dst))
  5283. WBUFL(buf,6+offset) = dst->id;
  5284. clif_send(buf, packet_len(cmd), src, SELF);
  5285. }
  5286. return success;
  5287. }
  5288. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5289. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5290. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5291. {
  5292. unsigned char buf[32];
  5293. nullpo_retv(src);
  5294. WBUFW(buf,0)=0x117;
  5295. WBUFW(buf,2)=skill_id;
  5296. WBUFL(buf,4)=src->id;
  5297. WBUFW(buf,8)=val;
  5298. WBUFW(buf,10)=x;
  5299. WBUFW(buf,12)=y;
  5300. WBUFL(buf,14)=client_tick(tick);
  5301. if(disguised(src)) {
  5302. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5303. WBUFL(buf,4)=disguised_bl_id(src->id);
  5304. clif_send(buf,packet_len(0x117),src,SELF);
  5305. } else
  5306. clif_send(buf,packet_len(0x117),src,AREA);
  5307. }
  5308. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5309. /// 011c <skill id>.W { <map name>.16B }*4
  5310. 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)
  5311. {
  5312. int fd;
  5313. nullpo_retv(sd);
  5314. fd = sd->fd;
  5315. WFIFOHEAD(fd,packet_len(0x11c));
  5316. WFIFOW(fd,0) = 0x11c;
  5317. WFIFOW(fd,2) = skill_id;
  5318. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5319. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5320. else // normal map name
  5321. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5322. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5323. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5324. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5325. WFIFOSET(fd,packet_len(0x11c));
  5326. sd->menuskill_id = skill_id;
  5327. if (skill_id == AL_WARP) {
  5328. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5329. sd->state.workinprogress = WIP_DISABLE_ALL;
  5330. } else
  5331. sd->menuskill_val = skill_lv;
  5332. }
  5333. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5334. /// 011e <type>.B
  5335. /// type:
  5336. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5337. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5338. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5339. ///
  5340. /// @param sd Who receives the message
  5341. /// @param type What message
  5342. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5343. {
  5344. int fd;
  5345. nullpo_retv(sd);
  5346. fd=sd->fd;
  5347. WFIFOHEAD(fd,packet_len(0x11e));
  5348. WFIFOW(fd,0)=0x11e;
  5349. WFIFOB(fd,2)=type;
  5350. WFIFOSET(fd,packet_len(0x11e));
  5351. }
  5352. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5353. /// 0189 <type>.W
  5354. /// type:
  5355. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5356. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5357. ///
  5358. /// @param sd Who receives the message
  5359. /// @param type What message
  5360. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5361. {
  5362. int fd;
  5363. nullpo_retv(sd);
  5364. fd=sd->fd;
  5365. WFIFOHEAD(fd,packet_len(0x189));
  5366. WFIFOW(fd,0)=0x189;
  5367. WFIFOW(fd,2)=type;
  5368. WFIFOSET(fd,packet_len(0x189));
  5369. }
  5370. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5371. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5372. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5373. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5374. {
  5375. struct status_data *status;
  5376. unsigned char buf[64];
  5377. int i, fix;
  5378. nullpo_retv(sd);
  5379. nullpo_retv(dst);
  5380. if( dst->type != BL_MOB )
  5381. return;
  5382. status = status_get_status_data(dst);
  5383. WBUFW(buf, 0)=0x18c;
  5384. WBUFW(buf, 2)=status_get_class(dst);
  5385. WBUFW(buf, 4)=status_get_lv(dst);
  5386. WBUFW(buf, 6)=status->size;
  5387. WBUFL(buf, 8)=status->hp;
  5388. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5389. +(battle_config.estimation_type&2?status->def2:0);
  5390. WBUFW(buf,14)=status->race;
  5391. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5392. +(battle_config.estimation_type&2?status->mdef2:0);
  5393. WBUFW(buf,18)= status->def_ele;
  5394. for(i=0;i<9;i++)
  5395. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5396. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5397. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5398. }
  5399. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5400. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5401. /// material id:
  5402. /// unused by the client
  5403. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5404. nullpo_retv(sd);
  5405. int fd = sd->fd;
  5406. if( !session_isActive( fd ) ){
  5407. return;
  5408. }
  5409. if (sd->menuskill_id == skill_id)
  5410. return; //Avoid resending the menu twice or more times...
  5411. if (skill_id == GC_CREATENEWPOISON)
  5412. skill_id = GC_RESEARCHNEWPOISON;
  5413. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5414. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5415. p->packetType = 0x18d;
  5416. int count = 0;
  5417. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5418. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5419. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5420. )
  5421. {
  5422. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5423. p->items[count].material[0] = 0;
  5424. p->items[count].material[1] = 0;
  5425. p->items[count].material[2] = 0;
  5426. count++;
  5427. }
  5428. }
  5429. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5430. WFIFOSET( fd, p->packetLength );
  5431. if( count > 0 ){
  5432. sd->menuskill_id = skill_id;
  5433. sd->menuskill_val = trigger;
  5434. return;
  5435. }
  5436. }
  5437. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5438. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5439. /// mk type:
  5440. /// 1 = cooking
  5441. /// 2 = arrow
  5442. /// 3 = elemental
  5443. /// 4 = GN_MIX_COOKING
  5444. /// 5 = GN_MAKEBOMB
  5445. /// 6 = GN_S_PHARMACY
  5446. /// 7 = MT_M_MACHINE - Unconfirmed
  5447. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5448. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5449. nullpo_retv( sd );
  5450. // Avoid resending the menu twice or more times...
  5451. if( sd->menuskill_id == skill_id ){
  5452. return;
  5453. }
  5454. int fd = sd->fd;
  5455. if( !session_isActive( fd ) ){
  5456. return;
  5457. }
  5458. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5459. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5460. p->packetType = 0x25a;
  5461. p->makeItem = list_type; // list type
  5462. int count = 0;
  5463. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5464. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5465. continue;
  5466. }
  5467. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5468. count++;
  5469. }
  5470. if( count > 0 || skill_id == AM_PHARMACY ){
  5471. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5472. WFIFOSET( fd, p->packetLength );
  5473. sd->menuskill_id = skill_id;
  5474. sd->menuskill_val = trigger;
  5475. sd->menuskill_val2 = qty; // amount.
  5476. }else{
  5477. clif_menuskill_clear(sd);
  5478. #if PACKETVER >= 20090922
  5479. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5480. #else
  5481. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5482. WFIFOSET( fd, p->packetLength );
  5483. #endif
  5484. }
  5485. }
  5486. /// Notifies clients of a status change.
  5487. /// 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)]
  5488. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5489. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5490. /// @param bl Sends packet to clients around this object
  5491. /// @param id ID of object that has this effect
  5492. /// @param type Status icon see enum efst_type
  5493. /// @param flag 1:Active, 0:Deactive
  5494. /// @param tick Duration in ms
  5495. /// @param val1
  5496. /// @param val2
  5497. /// @param val3
  5498. 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)
  5499. {
  5500. unsigned char buf[32];
  5501. if (type == EFST_BLANK) //It shows nothing on the client...
  5502. return;
  5503. if (type == EFST_POSTDELAY && tick == 0)
  5504. return;
  5505. nullpo_retv(bl);
  5506. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5507. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5508. tick = 200;
  5509. #if PACKETVER >= 20120618
  5510. if (flag && battle_config.display_status_timers)
  5511. WBUFW(buf,0) = 0x983;
  5512. else
  5513. #elif PACKETVER >= 20090121
  5514. if (flag && battle_config.display_status_timers)
  5515. WBUFW(buf,0) = 0x43f;
  5516. else
  5517. #endif
  5518. WBUFW(buf,0) = 0x196;
  5519. WBUFW(buf,2) = type;
  5520. WBUFL(buf,4) = id;
  5521. WBUFB(buf,8) = flag;
  5522. #if PACKETVER >= 20120618
  5523. if (flag && battle_config.display_status_timers) {
  5524. if (tick <= 0)
  5525. tick = 9999; // this is indeed what official servers do
  5526. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5527. WBUFL(buf,13) = client_tick(tick);
  5528. WBUFL(buf,17) = val1;
  5529. WBUFL(buf,21) = val2;
  5530. WBUFL(buf,25) = val3;
  5531. }
  5532. #elif PACKETVER >= 20090121
  5533. if (flag && battle_config.display_status_timers) {
  5534. if (tick <= 0)
  5535. tick = 9999; // this is indeed what official servers do
  5536. WBUFL(buf,9) = client_tick(tick);
  5537. WBUFL(buf,13) = val1;
  5538. WBUFL(buf,17) = val2;
  5539. WBUFL(buf,21) = val3;
  5540. }
  5541. #endif
  5542. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5543. }
  5544. /* Sends status effect to clients around the bl
  5545. * @param bl Object that has the effect
  5546. * @param type Status icon see enum efst_type
  5547. * @param flag 1:Active, 0:Deactive
  5548. * @param tick Duration in ms
  5549. * @param val1
  5550. * @param val2
  5551. * @param val3
  5552. */
  5553. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5554. struct map_session_data *sd = NULL;
  5555. if (type == EFST_BLANK) //It shows nothing on the client...
  5556. return;
  5557. if (type == EFST_POSTDELAY && tick == 0)
  5558. return;
  5559. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5560. return;
  5561. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5562. // Older clients display normal riding icon.
  5563. if (type == EFST_MADOGEAR)
  5564. type = EFST_RIDING;
  5565. #endif
  5566. nullpo_retv(bl);
  5567. sd = BL_CAST(BL_PC, bl);
  5568. if (!(status_efst_get_bl_type((efst_type)type)&bl->type)) // only send status changes that actually matter to the client
  5569. return;
  5570. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5571. }
  5572. /**
  5573. * Send any active EFST to those around.
  5574. * @param tbl: Unit to send the packet to
  5575. * @param bl: Objects walking into view
  5576. * @param target: Client send type
  5577. */
  5578. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5579. unsigned char i;
  5580. struct sc_display_entry **sc_display;
  5581. unsigned char sc_display_count;
  5582. bool spheres_sent;
  5583. nullpo_retv(bl);
  5584. switch( bl->type ){
  5585. case BL_PC: {
  5586. struct map_session_data* sd = (struct map_session_data*)bl;
  5587. sc_display = sd->sc_display;
  5588. sc_display_count = sd->sc_display_count;
  5589. spheres_sent = !sd->state.connect_new;
  5590. }
  5591. break;
  5592. case BL_NPC: {
  5593. struct npc_data* nd = (struct npc_data*)bl;
  5594. sc_display = nd->sc_display;
  5595. sc_display_count = nd->sc_display_count;
  5596. spheres_sent = true;
  5597. }
  5598. break;
  5599. default:
  5600. return;
  5601. }
  5602. for (i = 0; i < sc_display_count; i++) {
  5603. enum sc_type type = sc_display[i]->type;
  5604. struct status_change *sc = status_get_sc(bl);
  5605. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5606. t_tick tick = 0;
  5607. if (td)
  5608. tick = DIFF_TICK(td->tick, gettick());
  5609. // Status changes that need special handling
  5610. switch( type ){
  5611. case SC_SPHERE_1:
  5612. case SC_SPHERE_2:
  5613. case SC_SPHERE_3:
  5614. case SC_SPHERE_4:
  5615. case SC_SPHERE_5:
  5616. if( spheres_sent ){
  5617. target = AREA_WOS;
  5618. }
  5619. break;
  5620. case SC_HELLS_PLANT:
  5621. if( sc && sc->data[type] ){
  5622. tick = sc->data[type]->val4;
  5623. }
  5624. break;
  5625. }
  5626. #if PACKETVER > 20120418
  5627. 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);
  5628. #else
  5629. 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);
  5630. #endif
  5631. }
  5632. }
  5633. /// Notifies the client when a player enters the screen with an active EFST.
  5634. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5635. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5636. 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) {
  5637. #if PACKETVER >= 20111108
  5638. unsigned char buf[32];
  5639. #if PACKETVER >= 20120618
  5640. const int cmd = 0x984;
  5641. #elif PACKETVER >= 20111108
  5642. const int cmd = 0x8ff;
  5643. #endif
  5644. int offset = 0;
  5645. if (type == EFST_BLANK)
  5646. return;
  5647. nullpo_retv(bl);
  5648. if (tick <= 0)
  5649. tick = 9999;
  5650. WBUFW(buf,offset + 0) = cmd;
  5651. WBUFL(buf,offset + 2) = tid;
  5652. WBUFW(buf,offset + 6) = type;
  5653. #if PACKETVER >= 20111108
  5654. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5655. #if PACKETVER >= 20120618
  5656. WBUFL(buf,offset + 12) = client_tick(tick);
  5657. offset += 4;
  5658. #endif
  5659. WBUFL(buf,offset + 12) = val1;
  5660. WBUFL(buf,offset + 16) = val2;
  5661. WBUFL(buf,offset + 20) = val3;
  5662. #endif
  5663. clif_send(buf,packet_len(cmd),bl,target);
  5664. #endif
  5665. }
  5666. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5667. /// 008e <packet len>.W <message>.?B
  5668. void clif_displaymessage(const int fd, const char* mes)
  5669. {
  5670. nullpo_retv(mes);
  5671. if( session_isActive( fd ) ){
  5672. char *message, *line;
  5673. message = aStrdup(mes);
  5674. line = strtok(message, "\n");
  5675. while(line != NULL) {
  5676. #if PACKETVER == 20141022
  5677. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5678. /** so we redirect to ZC_NPC_CHAT **/
  5679. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5680. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5681. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5682. if (len > 0) {
  5683. WFIFOHEAD(fd, 13 + len);
  5684. WFIFOW(fd, 0) = 0x2C1;
  5685. WFIFOW(fd, 2) = 13 + len;
  5686. WFIFOL(fd, 4) = 0;
  5687. WFIFOL(fd, 8) = color;
  5688. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5689. WFIFOSET(fd, WFIFOW(fd, 2));
  5690. }
  5691. #else
  5692. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5693. int len = strnlen(line, CHAT_SIZE_MAX);
  5694. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5695. WFIFOHEAD(fd, 5 + len);
  5696. WFIFOW(fd,0) = 0x8e;
  5697. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5698. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5699. WFIFOSET(fd, 5 + len);
  5700. }
  5701. #endif
  5702. line = strtok(NULL, "\n");
  5703. }
  5704. aFree(message);
  5705. }
  5706. }
  5707. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5708. /// 009a <packet len>.W <message>.?B
  5709. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5710. {
  5711. nullpo_retv(mes);
  5712. if (len < 2)
  5713. return;
  5714. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5715. p->packetType = HEADER_ZC_BROADCAST;
  5716. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5717. if( ( type&BC_BLUE ) != 0 ){
  5718. const char* color = "blue";
  5719. int16 length = (int16)strlen( color );
  5720. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5721. strcpy( p->message, color );
  5722. strncpy( &p->message[length], mes, len );
  5723. p->PacketLength += length;
  5724. }else if( ( type&BC_WOE ) != 0 ){
  5725. const char* color = "ssss";
  5726. int16 length = (int16)strlen( color );
  5727. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5728. strcpy( p->message, color );
  5729. strncpy( &p->message[length], mes, len );
  5730. p->PacketLength += length;
  5731. }else{
  5732. strncpy( p->message, mes, len );
  5733. }
  5734. clif_send( p, p->PacketLength, bl, target );
  5735. }
  5736. /*==========================================
  5737. * Displays a message on a 'bl' to all it's nearby clients
  5738. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5739. *------------------------------------------*/
  5740. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5741. nullpo_retv(bl);
  5742. nullpo_retv(message);
  5743. int16 len = (int16)( strlen( message ) + 1 );
  5744. if( len > CHAT_SIZE_MAX ) {
  5745. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5746. len = CHAT_SIZE_MAX;
  5747. }
  5748. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5749. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5750. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5751. p->GID = bl->id;
  5752. safestrncpy( p->Message, message, len );
  5753. clif_send( p, p->PacketLength, bl, target );
  5754. }
  5755. /// Send broadcast message with font formatting.
  5756. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5757. 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)
  5758. {
  5759. nullpo_retv(mes);
  5760. if (len < 2)
  5761. return;
  5762. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5763. p->packetType = HEADER_ZC_BROADCAST2;
  5764. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5765. p->fontColor = fontColor;
  5766. p->fontType = fontType;
  5767. p->fontSize = fontSize;
  5768. p->fontAlign = fontAlign;
  5769. p->fontY = fontY;
  5770. strncpy( p->message, mes, len );
  5771. clif_send( p, p->PacketLength, bl, target );
  5772. }
  5773. /*
  5774. * Display *msg to all *users in channel
  5775. */
  5776. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5777. DBIterator *iter;
  5778. struct map_session_data *user;
  5779. unsigned short msg_len = 0, len = 0;
  5780. unsigned char buf[CHAT_SIZE_MAX];
  5781. if (!channel || !msg)
  5782. return;
  5783. msg_len = (unsigned short)(strlen(msg) + 1);
  5784. if( msg_len > sizeof(buf)-12 ) {
  5785. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5786. msg_len = sizeof(buf)-12;
  5787. }
  5788. WBUFW(buf,0) = 0x2C1;
  5789. WBUFW(buf,2) = (len = msg_len + 12);
  5790. WBUFL(buf,4) = 0;
  5791. WBUFL(buf,8) = color;
  5792. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5793. iter = db_iterator(channel->users);
  5794. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5795. clif_send(buf, len, &user->bl, SELF);
  5796. }
  5797. dbi_destroy(iter);
  5798. }
  5799. /// Displays heal effect.
  5800. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5801. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5802. /// var id:
  5803. /// 5 = HP (SP_HP)
  5804. /// 7 = SP (SP_SP)
  5805. /// ? = ignored
  5806. void clif_heal(int fd,int type,int val) {
  5807. #if PACKETVER < 20141022
  5808. const int cmd = 0x13d;
  5809. #else
  5810. const int cmd = 0xa27;
  5811. #endif
  5812. WFIFOHEAD(fd, packet_len(cmd));
  5813. WFIFOW(fd,0) = cmd;
  5814. WFIFOW(fd,2) = type;
  5815. #if PACKETVER < 20141022
  5816. WFIFOW(fd,4) = min(val, INT16_MAX);
  5817. #else
  5818. WFIFOL(fd,4) = min(val, INT32_MAX);
  5819. #endif
  5820. WFIFOSET(fd, packet_len(cmd));
  5821. }
  5822. /// Displays resurrection effect (ZC_RESURRECTION).
  5823. /// 0148 <id>.L <type>.W
  5824. /// type:
  5825. /// ignored
  5826. void clif_resurrection(struct block_list *bl,int type)
  5827. {
  5828. unsigned char buf[16];
  5829. nullpo_retv(bl);
  5830. WBUFW(buf,0)=0x148;
  5831. WBUFL(buf,2)=bl->id;
  5832. WBUFW(buf,6)=0;
  5833. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5834. if (disguised(bl))
  5835. clif_spawn(bl);
  5836. }
  5837. /// Sets the map property
  5838. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5839. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5840. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5841. {
  5842. #if PACKETVER >= 20121010
  5843. short cmd = 0x99b;
  5844. unsigned char buf[8];
  5845. #else
  5846. short cmd = 0x199;
  5847. unsigned char buf[4];
  5848. #endif
  5849. WBUFW(buf,0)=cmd;
  5850. WBUFW(buf,2)=property;
  5851. #if PACKETVER >= 20121010
  5852. struct map_data *mapdata = map_getmapdata(bl->m);
  5853. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  5854. WBUFL(buf,4) = ((mapdata->flag[MF_PVP] || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5855. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5856. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5857. ((mapdata->flag[MF_FORCEMINEFFECT] || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5858. ((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
  5859. ((mapdata->flag[MF_PVP])<<5)| // COUNT_PK - Show the PvP counter
  5860. ((mapdata->flag[MF_PARTYLOCK])<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5861. ((mapdata->flag[MF_BATTLEGROUND])<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5862. ((mapdata->flag[MF_NOCOSTUME])<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5863. ((!mapdata->flag[MF_NOUSECART])<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5864. ((!mapdata->flag[MF_NOSUNMOONSTARMIRACLE])<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5865. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5866. #endif
  5867. clif_send(buf,packet_len(cmd),bl,t);
  5868. }
  5869. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5870. /// 01d6 <type>.W
  5871. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5872. {
  5873. int fd;
  5874. nullpo_retv(sd);
  5875. fd=sd->fd;
  5876. WFIFOHEAD(fd,packet_len(0x1D6));
  5877. WFIFOW(fd,0)=0x1D6;
  5878. WFIFOW(fd,2)=type;
  5879. WFIFOSET(fd,packet_len(0x1D6));
  5880. }
  5881. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5882. /// 019a <id>.L <ranking>.L <total>.L
  5883. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5884. {
  5885. if(type == 2) {
  5886. int fd = sd->fd;
  5887. WFIFOHEAD(fd,packet_len(0x19a));
  5888. WFIFOW(fd,0) = 0x19a;
  5889. WFIFOL(fd,2) = sd->bl.id;
  5890. WFIFOL(fd,6) = pvprank;
  5891. WFIFOL(fd,10) = pvpnum;
  5892. WFIFOSET(fd,packet_len(0x19a));
  5893. } else {
  5894. unsigned char buf[32];
  5895. WBUFW(buf,0) = 0x19a;
  5896. WBUFL(buf,2) = sd->bl.id;
  5897. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5898. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5899. else
  5900. WBUFL(buf,6) = pvprank;
  5901. WBUFL(buf,10) = pvpnum;
  5902. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5903. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5904. else if(!type)
  5905. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5906. else
  5907. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5908. }
  5909. }
  5910. /*==========================================
  5911. *
  5912. *------------------------------------------*/
  5913. void clif_map_property_mapall(int map_idx, enum map_property property)
  5914. {
  5915. struct block_list bl;
  5916. bl.id = 0;
  5917. bl.type = BL_NUL;
  5918. bl.m = map_idx;
  5919. clif_map_property( &bl, property, ALL_SAMEMAP );
  5920. }
  5921. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5922. /// 0188 <result>.W <index>.W <refine>.W
  5923. /// result:
  5924. /// 0 = success
  5925. /// 1 = failure
  5926. /// 2 = downgrade
  5927. void clif_refine(int fd, int fail, int index, int val)
  5928. {
  5929. WFIFOHEAD(fd,packet_len(0x188));
  5930. WFIFOW(fd,0)=0x188;
  5931. WFIFOW(fd,2)=fail;
  5932. WFIFOW(fd,4)=index+2;
  5933. WFIFOW(fd,6)=val;
  5934. WFIFOSET(fd,packet_len(0x188));
  5935. }
  5936. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5937. /// 0223 <result>.L <nameid>.W
  5938. /// result:
  5939. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5940. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5941. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5942. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5943. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5944. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5945. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5946. p.result = result;
  5947. p.itemId = client_nameid( item_id );
  5948. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5949. }
  5950. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5951. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5952. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5953. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5954. int fd;
  5955. nullpo_retv(sd);
  5956. fd = sd->fd;
  5957. #if PACKETVER < 20091104
  5958. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5959. WFIFOW(fd,0) = 0x97;
  5960. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5961. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5962. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5963. WFIFOSET(fd,WFIFOW(fd,2));
  5964. #else
  5965. struct map_session_data *ssd = map_nick2sd(nick,false);
  5966. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5967. WFIFOW(fd,0) = 0x97;
  5968. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5969. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5970. // If it is not a message from the server or a player from another map-server
  5971. if( ssd ){
  5972. gmlvl = pc_get_group_level(ssd);
  5973. }
  5974. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5975. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5976. WFIFOSET(fd,WFIFOW(fd,2));
  5977. #endif
  5978. }
  5979. /// Inform the player about the result of his whisper action
  5980. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5981. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5982. /// result:
  5983. /// 0 = success to send wisper
  5984. /// 1 = target character is not loged in
  5985. /// 2 = ignored by target
  5986. /// 3 = everyone ignored by target
  5987. void clif_wis_end(int fd, int result)
  5988. {
  5989. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5990. #if PACKETVER < 20131223
  5991. const int cmd = 0x98;
  5992. #else
  5993. const int cmd = 0x9df;
  5994. #endif
  5995. if (!sd)
  5996. return;
  5997. WFIFOHEAD(fd,packet_len(cmd));
  5998. WFIFOW(fd,0) = cmd;
  5999. WFIFOB(fd,2) = (char)result;
  6000. #if PACKETVER >= 20131223
  6001. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  6002. #endif
  6003. WFIFOSET(fd,packet_len(cmd));
  6004. }
  6005. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  6006. /// 0194 <char id>.L <name>.24B
  6007. /// 0af7 <flag>.W <char id>.L <name>.24B
  6008. void clif_solved_charname(int fd, int charid, const char* name)
  6009. {
  6010. #if PACKETVER >= 20180221
  6011. WFIFOHEAD(fd,packet_len(0xaf7));
  6012. WFIFOW(fd,0) = 0xaf7;
  6013. WFIFOW(fd,2) = name[0] ? 3 : 2;
  6014. WFIFOL(fd,4) = charid;
  6015. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  6016. WFIFOSET(fd,packet_len(0x0af7));
  6017. #else
  6018. WFIFOHEAD(fd,packet_len(0x194));
  6019. WFIFOW(fd,0)=0x194;
  6020. WFIFOL(fd,2)=charid;
  6021. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  6022. WFIFOSET(fd,packet_len(0x194));
  6023. #endif
  6024. }
  6025. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  6026. /// 017b <packet len>.W { <name id>.W }*
  6027. void clif_use_card(struct map_session_data *sd,int idx)
  6028. {
  6029. int i,c,ep;
  6030. int fd=sd->fd;
  6031. nullpo_retv(sd);
  6032. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6033. return;
  6034. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6035. return; //Avoid parsing invalid item indexes (no card/no item)
  6036. ep=sd->inventory_data[idx]->equip;
  6037. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6038. WFIFOW(fd,0)=0x17b;
  6039. for(i=c=0;i<MAX_INVENTORY;i++){
  6040. int j;
  6041. if(sd->inventory_data[i] == NULL)
  6042. continue;
  6043. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6044. continue;
  6045. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6046. continue;
  6047. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6048. continue;
  6049. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6050. continue;
  6051. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6052. continue;
  6053. 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.
  6054. continue;
  6055. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6056. if( j == sd->inventory_data[i]->slots ) // No room
  6057. continue;
  6058. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6059. continue;
  6060. WFIFOW(fd,4+c*2)=i+2;
  6061. c++;
  6062. }
  6063. if( !c ) return; // no item is available for card insertion
  6064. WFIFOW(fd,2)=4+c*2;
  6065. WFIFOSET(fd,WFIFOW(fd,2));
  6066. }
  6067. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6068. /// 017d <equip index>.W <card index>.W <result>.B
  6069. /// result:
  6070. /// 0 = success
  6071. /// 1 = failure
  6072. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  6073. {
  6074. int fd;
  6075. nullpo_retv(sd);
  6076. fd=sd->fd;
  6077. WFIFOHEAD(fd,packet_len(0x17d));
  6078. WFIFOW(fd,0)=0x17d;
  6079. WFIFOW(fd,2)=idx_equip+2;
  6080. WFIFOW(fd,4)=idx_card+2;
  6081. WFIFOB(fd,6)=flag;
  6082. WFIFOSET(fd,packet_len(0x17d));
  6083. }
  6084. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6085. /// 0177 <packet len>.W { <index>.W }*
  6086. void clif_item_identify_list(struct map_session_data *sd)
  6087. {
  6088. int i,c;
  6089. int fd;
  6090. nullpo_retv(sd);
  6091. fd=sd->fd;
  6092. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6093. WFIFOW(fd,0)=0x177;
  6094. for(i=c=0;i<MAX_INVENTORY;i++){
  6095. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6096. WFIFOW(fd,c*2+4)=client_index(i);
  6097. c++;
  6098. }
  6099. }
  6100. if(c > 0) {
  6101. WFIFOW(fd,2)=c*2+4;
  6102. WFIFOSET(fd,WFIFOW(fd,2));
  6103. sd->menuskill_id = MC_IDENTIFY;
  6104. sd->menuskill_val = c;
  6105. sd->state.workinprogress = WIP_DISABLE_ALL;
  6106. }
  6107. }
  6108. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6109. /// 0179 <index>.W <result>.B
  6110. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  6111. {
  6112. int fd;
  6113. nullpo_retv(sd);
  6114. fd=sd->fd;
  6115. WFIFOHEAD(fd,packet_len(0x179));
  6116. WFIFOW(fd, 0)=0x179;
  6117. WFIFOW(fd, 2)=idx+2;
  6118. WFIFOB(fd, 4)=flag;
  6119. WFIFOSET(fd,packet_len(0x179));
  6120. }
  6121. /// Presents a list of items that can be repaired.
  6122. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6123. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  6124. nullpo_retv( sd );
  6125. nullpo_retv( dstsd );
  6126. int fd = sd->fd;
  6127. if( !session_isActive( fd ) ){
  6128. return;
  6129. }
  6130. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6131. // Preallocate the maximum size
  6132. WFIFOHEAD( fd, len );
  6133. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6134. int c = 0;
  6135. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6136. 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)){
  6137. p->items[c].index = i;
  6138. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6139. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6140. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6141. c++;
  6142. }
  6143. }
  6144. if( c > 0 ){
  6145. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6146. // Recalculate real length
  6147. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6148. p->packetLength = len;
  6149. WFIFOSET( fd, len );
  6150. sd->menuskill_id = BS_REPAIRWEAPON;
  6151. sd->menuskill_val = dstsd->bl.id;
  6152. sd->menuskill_val2 = lv;
  6153. }else{
  6154. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6155. }
  6156. }
  6157. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6158. /// 01fe <index>.W <result>.B
  6159. /// index:
  6160. /// ignored (inventory index)
  6161. /// result:
  6162. /// 0 = Item repair success.
  6163. /// 1 = Item repair failure.
  6164. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  6165. {
  6166. int fd;
  6167. nullpo_retv(sd);
  6168. fd = sd->fd;
  6169. WFIFOHEAD(fd,packet_len(0x1fe));
  6170. WFIFOW(fd, 0)=0x1fe;
  6171. WFIFOW(fd, 2)=idx+2;
  6172. WFIFOB(fd, 4)=flag;
  6173. WFIFOSET(fd,packet_len(0x1fe));
  6174. }
  6175. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6176. /// 02bb <equip location>.W <account id>.L
  6177. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  6178. {
  6179. int fd = sd->fd;
  6180. WFIFOHEAD(fd,packet_len(0x2bb));
  6181. WFIFOW(fd,0) = 0x2bb;
  6182. WFIFOW(fd,2) = position;
  6183. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6184. WFIFOSET(fd,packet_len(0x2bb));
  6185. }
  6186. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6187. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6188. void clif_item_refine_list( struct map_session_data *sd ){
  6189. nullpo_retv( sd );
  6190. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6191. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6192. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6193. int refine_item[MAX_WEAPON_LEVEL];
  6194. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6195. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6196. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6197. #ifdef RENEWAL
  6198. refine_item[4] = -1;
  6199. #endif
  6200. int count = 0;
  6201. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6202. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6203. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6204. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6205. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6206. p->items[count].index = client_index( i );
  6207. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6208. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6209. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6210. count++;
  6211. }
  6212. }
  6213. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6214. clif_send( p, p->packetLength, &sd->bl, SELF );
  6215. if( count > 0 ){
  6216. sd->menuskill_id = WS_WEAPONREFINE;
  6217. sd->menuskill_val = skill_lv;
  6218. }
  6219. }
  6220. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6221. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6222. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6223. nullpo_retv( sd );
  6224. struct PACKET_ZC_AUTORUN_SKILL p;
  6225. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6226. p.skill_id = skill_id;
  6227. p.skill_type = skill_get_inf( skill_id );
  6228. p.skill_lv = skill_lv;
  6229. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6230. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6231. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6232. p.up_flag = false;
  6233. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6234. }
  6235. /// Adds an item to character's cart.
  6236. /// 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)
  6237. /// 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)
  6238. /// 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)
  6239. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6240. nullpo_retv( sd );
  6241. int fd = sd->fd;
  6242. if( !session_isActive( fd ) ){
  6243. return;
  6244. }
  6245. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6246. return;
  6247. }
  6248. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6249. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6250. p.index = client_index( n );
  6251. p.amount = amount;
  6252. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6253. #if PACKETVER >= 5
  6254. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6255. #endif
  6256. p.identified = sd->cart.u.items_cart[n].identify;
  6257. p.damaged = sd->cart.u.items_cart[n].attribute;
  6258. p.refine = sd->cart.u.items_cart[n].refine;
  6259. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6260. #if PACKETVER >= 20150226
  6261. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6262. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6263. p.enchantgrade = sd->cart.u.items_cart[n].enchantgrade;
  6264. #endif
  6265. #endif
  6266. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6267. }
  6268. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6269. /* Acknowledge an item have been added to cart
  6270. * 012c <result>B
  6271. * result :
  6272. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6273. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6274. */
  6275. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6276. {
  6277. int fd;
  6278. unsigned char *buf;
  6279. nullpo_retv(sd);
  6280. fd = sd->fd;
  6281. buf = WFIFOP(fd,0);
  6282. WBUFW(buf,0) = 0x12c;
  6283. WBUFB(buf,2) = flag;
  6284. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6285. }
  6286. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6287. void clif_bank_open(struct map_session_data *sd){
  6288. int fd;
  6289. nullpo_retv(sd);
  6290. fd = sd->fd;
  6291. WFIFOHEAD(fd,4);
  6292. WFIFOW(fd,0) = 0x09b7;
  6293. WFIFOW(fd,2) = 0;
  6294. WFIFOSET(fd,4);
  6295. }
  6296. /*
  6297. * Request to Open the banking system
  6298. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6299. */
  6300. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6301. //TODO check if preventing trade or stuff like that
  6302. //also mark something in case char ain't available for saving, should we check now ?
  6303. nullpo_retv(sd);
  6304. if( !battle_config.feature_banking ) {
  6305. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6306. return;
  6307. }
  6308. else {
  6309. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6310. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6311. if(sd->status.account_id == aid){
  6312. sd->state.banking = 1;
  6313. //request save ?
  6314. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6315. //on succes open bank ?
  6316. clif_bank_open(sd);
  6317. }
  6318. }
  6319. }
  6320. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6321. void clif_bank_close(struct map_session_data *sd){
  6322. int fd;
  6323. nullpo_retv(sd);
  6324. fd = sd->fd;
  6325. WFIFOHEAD(fd,4);
  6326. WFIFOW(fd,0) = 0x09B9;
  6327. WFIFOW(fd,2) = 0;
  6328. WFIFOSET(fd,4);
  6329. }
  6330. /*
  6331. * Request to close the banking system
  6332. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6333. */
  6334. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6335. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6336. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6337. nullpo_retv(sd);
  6338. if( !battle_config.feature_banking ) {
  6339. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6340. //still allow to go trough to not stuck player if we have disable it while they was in
  6341. }
  6342. if(sd->status.account_id == aid){
  6343. sd->state.banking = 0;
  6344. clif_bank_close(sd);
  6345. }
  6346. }
  6347. /*
  6348. * Display how much we got in bank (I suppose)
  6349. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6350. */
  6351. void clif_Bank_Check(struct map_session_data* sd) {
  6352. unsigned char buf[13];
  6353. struct s_packet_db* info;
  6354. int16 len;
  6355. int cmd = 0;
  6356. nullpo_retv(sd);
  6357. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6358. if(!cmd) cmd = 0x09A6; //default
  6359. info = &packet_db[cmd];
  6360. len = info->len;
  6361. if(!len) return; //version as packet disable
  6362. // sd->state.banking = 1; //mark opening and closing
  6363. WBUFW(buf,0) = cmd;
  6364. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6365. WBUFW(buf,info->pos[1]) = 0; //reason
  6366. clif_send(buf,len,&sd->bl,SELF);
  6367. }
  6368. /*
  6369. * Requesting the data in bank
  6370. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6371. */
  6372. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6373. nullpo_retv(sd);
  6374. if( !battle_config.feature_banking ) {
  6375. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6376. return;
  6377. }
  6378. else {
  6379. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6380. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6381. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6382. clif_Bank_Check(sd);
  6383. }
  6384. }
  6385. /*
  6386. * Acknowledge of deposit some money in bank
  6387. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6388. */
  6389. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6390. unsigned char buf[17];
  6391. struct s_packet_db* info;
  6392. int16 len;
  6393. int cmd =0;
  6394. nullpo_retv(sd);
  6395. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6396. if(!cmd) cmd = 0x09A8;
  6397. info = &packet_db[cmd];
  6398. len = info->len;
  6399. if(!len) return; //version as packet disable
  6400. WBUFW(buf,0) = cmd;
  6401. WBUFW(buf,info->pos[0]) = (short)reason;
  6402. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6403. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6404. clif_send(buf,len,&sd->bl,SELF);
  6405. }
  6406. /*
  6407. * Request saving some money in bank
  6408. * @author : original [Yommy/Hercules]
  6409. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6410. */
  6411. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6412. nullpo_retv(sd);
  6413. if( !battle_config.feature_banking ) {
  6414. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6415. return;
  6416. }
  6417. else {
  6418. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6419. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6420. int money = RFIFOL(fd,info->pos[1]);
  6421. if(sd->status.account_id == aid){
  6422. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6423. clif_bank_deposit(sd,reason);
  6424. }
  6425. }
  6426. }
  6427. /*
  6428. * Acknowledge of withdrawing some money from bank
  6429. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6430. */
  6431. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6432. unsigned char buf[17];
  6433. struct s_packet_db* info;
  6434. int16 len;
  6435. int cmd;
  6436. nullpo_retv(sd);
  6437. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6438. if(!cmd) cmd = 0x09AA;
  6439. info = &packet_db[cmd];
  6440. len = info->len;
  6441. if(!len) return; //version as packet disable
  6442. WBUFW(buf,0) = cmd;
  6443. WBUFW(buf,info->pos[0]) = (short)reason;
  6444. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6445. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6446. clif_send(buf,len,&sd->bl,SELF);
  6447. }
  6448. /*
  6449. * Request Withdrawing some money from bank
  6450. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6451. */
  6452. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6453. nullpo_retv(sd);
  6454. if( !battle_config.feature_banking ) {
  6455. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6456. return;
  6457. }
  6458. else {
  6459. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6460. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6461. int money = RFIFOL(fd,info->pos[1]);
  6462. if(sd->status.account_id == aid){
  6463. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6464. clif_bank_withdraw(sd,reason);
  6465. }
  6466. }
  6467. }
  6468. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6469. /// 0125 <index>.W <amount>.L
  6470. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6471. {
  6472. int fd;
  6473. nullpo_retv(sd);
  6474. fd=sd->fd;
  6475. WFIFOHEAD(fd,packet_len(0x125));
  6476. WFIFOW(fd,0)=0x125;
  6477. WFIFOW(fd,2)=n+2;
  6478. WFIFOL(fd,4)=amount;
  6479. WFIFOSET(fd,packet_len(0x125));
  6480. }
  6481. /// Opens the shop creation menu (ZC_OPENSTORE).
  6482. /// 012d <num>.W
  6483. /// num:
  6484. /// number of allowed item slots
  6485. void clif_openvendingreq(struct map_session_data* sd, int num)
  6486. {
  6487. int fd;
  6488. nullpo_retv(sd);
  6489. fd = sd->fd;
  6490. WFIFOHEAD(fd,packet_len(0x12d));
  6491. WFIFOW(fd,0) = 0x12d;
  6492. WFIFOW(fd,2) = num;
  6493. WFIFOSET(fd,packet_len(0x12d));
  6494. }
  6495. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6496. /// 0131 <owner id>.L <message>.80B
  6497. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6498. {
  6499. unsigned char buf[128];
  6500. nullpo_retv(bl);
  6501. WBUFW(buf,0) = 0x131;
  6502. WBUFL(buf,2) = bl->id;
  6503. safestrncpy(WBUFCP(buf,6), message, 80);
  6504. if( session_isActive(fd) ) {
  6505. WFIFOHEAD(fd,packet_len(0x131));
  6506. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6507. WFIFOSET(fd,packet_len(0x131));
  6508. } else {
  6509. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6510. }
  6511. }
  6512. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6513. /// 0132 <owner id>.L
  6514. void clif_closevendingboard(struct block_list* bl, int fd)
  6515. {
  6516. unsigned char buf[16];
  6517. nullpo_retv(bl);
  6518. WBUFW(buf,0) = 0x132;
  6519. WBUFL(buf,2) = bl->id;
  6520. if( session_isActive(fd) ) {
  6521. WFIFOHEAD(fd,packet_len(0x132));
  6522. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6523. WFIFOSET(fd,packet_len(0x132));
  6524. } else {
  6525. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6526. }
  6527. }
  6528. /// Sends a list of items in a shop.
  6529. /// 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)
  6530. /// 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)
  6531. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6532. nullpo_retv( sd );
  6533. nullpo_retv( vsd );
  6534. nullpo_retv( vsd->vending );
  6535. int fd = sd->fd;
  6536. if( !session_isActive( fd ) ){
  6537. return;
  6538. }
  6539. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6540. WFIFOHEAD( fd, len );
  6541. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6542. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6543. p->packetLength = len;
  6544. p->AID = vsd->status.account_id;
  6545. #if PACKETVER >= 20100105
  6546. p->venderId = vsd->vender_id;
  6547. #endif
  6548. for( int i = 0; i < vsd->vend_num; i++ ){
  6549. int index = vsd->vending[i].index;
  6550. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6551. p->items[i].price = vsd->vending[i].value;
  6552. p->items[i].amount = vsd->vending[i].amount;
  6553. p->items[i].index = client_index( index );
  6554. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6555. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6556. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6557. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6558. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6559. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6560. #if PACKETVER >= 20150226
  6561. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6562. #if PACKETVER >= 20160921
  6563. p->items[i].location = pc_equippoint_sub( sd, data );
  6564. p->items[i].viewSprite = data->look;
  6565. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6566. p->items[i].enchantgrade = vsd->cart.u.items_cart[index].enchantgrade;
  6567. #endif
  6568. #endif
  6569. #endif
  6570. }
  6571. WFIFOSET( fd, len );
  6572. }
  6573. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6574. /// 0135 <index>.W <amount>.W <result>.B
  6575. /// result:
  6576. /// 0 = success
  6577. /// 1 = not enough zeny
  6578. /// 2 = overweight
  6579. /// 4 = out of stock
  6580. /// 5 = "cannot use an npc shop while in a trade"
  6581. /// 6 = Because the store information was incorrect the item was not purchased.
  6582. /// 7 = No sales information.
  6583. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6584. {
  6585. int fd;
  6586. nullpo_retv(sd);
  6587. fd = sd->fd;
  6588. WFIFOHEAD(fd,packet_len(0x135));
  6589. WFIFOW(fd,0) = 0x135;
  6590. WFIFOW(fd,2) = index+2;
  6591. WFIFOW(fd,4) = amount;
  6592. WFIFOB(fd,6) = fail;
  6593. WFIFOSET(fd,packet_len(0x135));
  6594. }
  6595. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6596. /// 0a28 <Result>.B
  6597. /// result:
  6598. /// 0 = Successed
  6599. /// 1 = Failed
  6600. void clif_openvending_ack(struct map_session_data* sd, int result)
  6601. {
  6602. int fd;
  6603. nullpo_retv(sd);
  6604. fd = sd->fd;
  6605. WFIFOHEAD(fd, 3);
  6606. WFIFOW(fd,0) = 0xa28;
  6607. WFIFOB(fd,2) = result;
  6608. WFIFOSET(fd, 3);
  6609. }
  6610. /// Shop creation success.
  6611. /// 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)
  6612. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6613. nullpo_retv( sd );
  6614. nullpo_retv( vending );
  6615. int fd = sd->fd;
  6616. if( !session_isActive( fd ) ){
  6617. return;
  6618. }
  6619. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6620. WFIFOHEAD( fd, len );
  6621. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6622. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6623. p->packetLength = len;
  6624. p->AID = id;
  6625. for( int i = 0; i < sd->vend_num; i++ ) {
  6626. int index = vending[i].index;
  6627. p->items[i].price = vending[i].value;
  6628. p->items[i].index = client_index( index );
  6629. p->items[i].amount = vending[i].amount;
  6630. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6631. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6632. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6633. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6634. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6635. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6636. #if PACKETVER >= 20150226
  6637. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6638. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6639. p->items[i].enchantgrade = sd->cart.u.items_cart[index].enchantgrade;
  6640. #endif
  6641. #endif
  6642. }
  6643. WFIFOSET( fd, len );
  6644. #if PACKETVER >= 20141022
  6645. /// 0 = Successed
  6646. /// 1 = Failed
  6647. clif_openvending_ack( sd, 0 );
  6648. #endif
  6649. }
  6650. /// Inform merchant that someone has bought an item.
  6651. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6652. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6653. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6654. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6655. const int cmd = 0x137;
  6656. #else
  6657. const int cmd = 0x9e5;
  6658. #endif
  6659. int fd = sd->fd;
  6660. nullpo_retv(sd);
  6661. WFIFOHEAD(fd,packet_len(cmd));
  6662. WFIFOW(fd,0) = cmd;
  6663. WFIFOW(fd,2) = index+2;
  6664. WFIFOW(fd,4) = amount;
  6665. #if PACKETVER >= 20141016
  6666. WFIFOL(fd,6) = char_id; // GID
  6667. WFIFOL(fd,10) = (int)time(NULL); // Date
  6668. WFIFOL(fd,14) = zeny; // zeny
  6669. #endif
  6670. WFIFOSET(fd,packet_len(cmd));
  6671. }
  6672. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6673. /// 00fa <result>.B
  6674. /// result:
  6675. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6676. /// 1 = MsgStringTable[78]="party name already exists"
  6677. /// 2 = MsgStringTable[79]="already in a party"
  6678. /// 3 = cannot organize parties on this map
  6679. /// ? = nothing
  6680. void clif_party_created(struct map_session_data *sd,int result)
  6681. {
  6682. int fd;
  6683. nullpo_retv(sd);
  6684. fd=sd->fd;
  6685. WFIFOHEAD(fd,packet_len(0xfa));
  6686. WFIFOW(fd,0)=0xfa;
  6687. WFIFOB(fd,2)=result;
  6688. WFIFOSET(fd,packet_len(0xfa));
  6689. }
  6690. /// Adds new member to a party.
  6691. /// 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)
  6692. /// 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)
  6693. /// 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)
  6694. /// role:
  6695. /// 0 = leader
  6696. /// 1 = normal
  6697. /// state:
  6698. /// 0 = connected
  6699. /// 1 = disconnected
  6700. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6701. {
  6702. int i;
  6703. #if PACKETVER < 20170502
  6704. unsigned char buf[81];
  6705. int cmd = 0x1e9;
  6706. int offset = 0;
  6707. #else
  6708. unsigned char buf[85];
  6709. int cmd = 0xa43;
  6710. int offset = 4;
  6711. #endif
  6712. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6713. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6714. } else {
  6715. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6716. }
  6717. if (i >= MAX_PARTY) return; //Should never happen...
  6718. sd = p->data[i].sd;
  6719. WBUFW(buf, 0) = cmd;
  6720. WBUFL(buf, 2) = sd->status.account_id;
  6721. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6722. #if PACKETVER >= 20170502
  6723. WBUFW(buf,10) = sd->status.class_;
  6724. WBUFW(buf,12) = sd->status.base_level;
  6725. #endif
  6726. WBUFW(buf,offset+10) = sd->bl.x;
  6727. WBUFW(buf,offset+12) = sd->bl.y;
  6728. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6729. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6730. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6731. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6732. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6733. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6734. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6735. }
  6736. /// Sends party information (ZC_GROUP_LIST).
  6737. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6738. /// role:
  6739. /// 0 = leader
  6740. /// 1 = normal
  6741. /// state:
  6742. /// 0 = connected
  6743. /// 1 = disconnected
  6744. /// 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
  6745. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6746. {
  6747. struct map_session_data* party_sd = NULL;
  6748. int i, c;
  6749. #if PACKETVER < 20170502
  6750. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6751. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6752. int cmd = 0xfb;
  6753. #else
  6754. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6755. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6756. int cmd = 0xa44;
  6757. #endif
  6758. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6759. nullpo_retv(p);
  6760. WBUFW(buf,0) = cmd;
  6761. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6762. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6763. {
  6764. struct party_member* m = &p->party.member[i];
  6765. if(!m->account_id) continue;
  6766. if(party_sd == NULL) party_sd = p->data[i].sd;
  6767. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6768. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6769. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6770. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6771. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6772. #if PACKETVER >= 20170502
  6773. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6774. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6775. #endif
  6776. c++;
  6777. }
  6778. #if PACKETVER < 20170502
  6779. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6780. #else
  6781. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6782. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6783. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6784. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6785. #endif
  6786. if(sd) { // send only to self
  6787. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6788. } else if (party_sd) { // send to whole party
  6789. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6790. }
  6791. }
  6792. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6793. /// 02c9 <flag>.B
  6794. /// flag:
  6795. /// 0 = allow party invites
  6796. /// 1 = auto-deny party invites
  6797. void clif_partyinvitationstate(struct map_session_data* sd)
  6798. {
  6799. int fd;
  6800. nullpo_retv(sd);
  6801. fd = sd->fd;
  6802. WFIFOHEAD(fd, packet_len(0x2c9));
  6803. WFIFOW(fd, 0) = 0x2c9;
  6804. WFIFOB(fd, 2) = 0; // not implemented
  6805. WFIFOSET(fd, packet_len(0x2c9));
  6806. }
  6807. /// Party invitation request.
  6808. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6809. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6810. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6811. {
  6812. #if PACKETVER < 20070821
  6813. const int cmd = 0xfe;
  6814. #else
  6815. const int cmd = 0x2c6;
  6816. #endif
  6817. int fd;
  6818. struct party_data *p;
  6819. nullpo_retv(sd);
  6820. nullpo_retv(tsd);
  6821. fd=tsd->fd;
  6822. if( (p=party_search(sd->status.party_id))==NULL )
  6823. return;
  6824. WFIFOHEAD(fd,packet_len(cmd));
  6825. WFIFOW(fd,0)=cmd;
  6826. WFIFOL(fd,2)=sd->status.party_id;
  6827. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6828. WFIFOSET(fd,packet_len(cmd));
  6829. }
  6830. /// Party invite result.
  6831. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6832. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6833. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6834. {
  6835. int fd;
  6836. nullpo_retv(sd);
  6837. fd=sd->fd;
  6838. #if PACKETVER < 20070904
  6839. if( reply == PARTY_REPLY_OFFLINE ) {
  6840. clif_displaymessage(fd, msg_txt(sd,3));
  6841. return;
  6842. }
  6843. #endif
  6844. #if PACKETVER < 20070821
  6845. WFIFOHEAD(fd,packet_len(0xfd));
  6846. WFIFOW(fd,0) = 0xfd;
  6847. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6848. WFIFOB(fd,26) = reply;
  6849. WFIFOSET(fd,packet_len(0xfd));
  6850. #else
  6851. WFIFOHEAD(fd,packet_len(0x2c5));
  6852. WFIFOW(fd,0) = 0x2c5;
  6853. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6854. WFIFOL(fd,26) = reply;
  6855. WFIFOSET(fd,packet_len(0x2c5));
  6856. #endif
  6857. }
  6858. /// Updates party settings.
  6859. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6860. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6861. /// exp option:
  6862. /// 0 = exp sharing disabled
  6863. /// 1 = exp sharing enabled
  6864. /// 2 = cannot change exp sharing
  6865. ///
  6866. /// flag:
  6867. /// 0 = send to party
  6868. /// 1 = send to sd
  6869. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6870. {
  6871. unsigned char buf[16];
  6872. #if PACKETVER < 20090603
  6873. const int cmd = 0x101;
  6874. #else
  6875. const int cmd = 0x7d8;
  6876. #endif
  6877. nullpo_retv(p);
  6878. if(!sd && flag==0){
  6879. int i;
  6880. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6881. if (i < MAX_PARTY)
  6882. sd = p->data[i].sd;
  6883. }
  6884. if(!sd) return;
  6885. WBUFW(buf,0)=cmd;
  6886. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6887. #if PACKETVER >= 20090603
  6888. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6889. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6890. #endif
  6891. if(flag==0)
  6892. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6893. else
  6894. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6895. }
  6896. /**
  6897. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6898. * @param sd Send the notification for this player
  6899. * @param account_id Account ID of kicked member
  6900. * @param name Name of kicked member
  6901. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6902. * @param target Send target
  6903. **/
  6904. 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) {
  6905. unsigned char buf[2+4+NAME_LENGTH+1];
  6906. if (!sd)
  6907. return;
  6908. WBUFW(buf,0) = 0x0105;
  6909. WBUFL(buf,2) = account_id;
  6910. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6911. WBUFB(buf,6+NAME_LENGTH) = result;
  6912. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6913. }
  6914. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6915. /// 0109 <packet len>.W <account id>.L <message>.?B
  6916. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6917. {
  6918. struct map_session_data *sd;
  6919. int i;
  6920. nullpo_retv(p);
  6921. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6922. if(i < MAX_PARTY){
  6923. unsigned char buf[1024];
  6924. if( len > sizeof(buf)-8 )
  6925. {
  6926. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6927. len = sizeof(buf)-8;
  6928. }
  6929. sd = p->data[i].sd;
  6930. WBUFW(buf,0)=0x109;
  6931. WBUFW(buf,2)=len+8;
  6932. WBUFL(buf,4)=account_id;
  6933. safestrncpy(WBUFCP(buf,8), mes, len);
  6934. clif_send(buf,len+8,&sd->bl,PARTY);
  6935. }
  6936. }
  6937. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6938. /// 0107 <account id>.L <x>.W <y>.W
  6939. void clif_party_xy(struct map_session_data *sd)
  6940. {
  6941. unsigned char buf[16];
  6942. nullpo_retv(sd);
  6943. WBUFW(buf,0)=0x107;
  6944. WBUFL(buf,2)=sd->status.account_id;
  6945. WBUFW(buf,6)=sd->bl.x;
  6946. WBUFW(buf,8)=sd->bl.y;
  6947. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6948. }
  6949. /*==========================================
  6950. * Sends x/y dot to a single fd. [Skotlex]
  6951. *------------------------------------------*/
  6952. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6953. {
  6954. WFIFOHEAD(fd,packet_len(0x107));
  6955. WFIFOW(fd,0)=0x107;
  6956. WFIFOL(fd,2)=sd->status.account_id;
  6957. WFIFOW(fd,6)=sd->bl.x;
  6958. WFIFOW(fd,8)=sd->bl.y;
  6959. WFIFOSET(fd,packet_len(0x107));
  6960. }
  6961. /// Updates HP bar of a party member.
  6962. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6963. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6964. void clif_party_hp(struct map_session_data *sd)
  6965. {
  6966. unsigned char buf[16];
  6967. #if PACKETVER < 20100126
  6968. const int cmd = 0x106;
  6969. #else
  6970. const int cmd = 0x80e;
  6971. #endif
  6972. nullpo_retv(sd);
  6973. WBUFW(buf,0)=cmd;
  6974. WBUFL(buf,2)=sd->status.account_id;
  6975. #if PACKETVER < 20100126
  6976. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6977. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6978. WBUFW(buf,8) = 100;
  6979. } else {
  6980. WBUFW(buf,6) = sd->battle_status.hp;
  6981. WBUFW(buf,8) = sd->battle_status.max_hp;
  6982. }
  6983. #else
  6984. WBUFL(buf,6) = sd->battle_status.hp;
  6985. WBUFL(buf,10) = sd->battle_status.max_hp;
  6986. #endif
  6987. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6988. }
  6989. /// Notifies the party members of a character's death or revival.
  6990. /// 0AB2 <GID>.L <dead>.B
  6991. void clif_party_dead( struct map_session_data *sd ){
  6992. #if PACKETVER >= 20170502
  6993. unsigned char buf[7];
  6994. nullpo_retv(sd);
  6995. WBUFW(buf, 0) = 0xab2;
  6996. WBUFL(buf, 2) = sd->status.account_id;
  6997. WBUFB(buf, 6) = pc_isdead(sd);
  6998. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6999. #endif
  7000. }
  7001. /// Updates the job and level of a party member
  7002. /// 0abd <account id>.L <job>.W <level>.W
  7003. void clif_party_job_and_level(struct map_session_data *sd){
  7004. #if PACKETVER >= 20170502
  7005. unsigned char buf[10];
  7006. nullpo_retv(sd);
  7007. WBUFW(buf, 0) = 0xabd;
  7008. WBUFL(buf, 2) = sd->status.account_id;
  7009. WBUFW(buf, 6) = sd->status.class_;
  7010. WBUFW(buf, 8) = sd->status.base_level;
  7011. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  7012. #endif
  7013. }
  7014. /*==========================================
  7015. * Sends HP bar to a single fd. [Skotlex]
  7016. *------------------------------------------*/
  7017. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  7018. {
  7019. #if PACKETVER < 20100126
  7020. const int cmd = 0x106;
  7021. #else
  7022. const int cmd = 0x80e;
  7023. #endif
  7024. WFIFOHEAD(fd,packet_len(cmd));
  7025. WFIFOW(fd,0) = cmd;
  7026. WFIFOL(fd,2) = id;
  7027. #if PACKETVER < 20100126
  7028. if( maxhp > INT16_MAX )
  7029. {// To correctly display the %hp bar. [Skotlex]
  7030. WFIFOW(fd,6) = hp/(maxhp/100);
  7031. WFIFOW(fd,8) = 100;
  7032. } else {
  7033. WFIFOW(fd,6) = hp;
  7034. WFIFOW(fd,8) = maxhp;
  7035. }
  7036. #else
  7037. WFIFOL(fd,6) = hp;
  7038. WFIFOL(fd,10) = maxhp;
  7039. #endif
  7040. WFIFOSET(fd, packet_len(cmd));
  7041. }
  7042. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  7043. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  7044. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  7045. {
  7046. int fd;
  7047. nullpo_retv(sd);
  7048. nullpo_retv(bl);
  7049. fd=sd->fd;
  7050. WFIFOHEAD(fd,packet_len(0x139));
  7051. WFIFOW(fd, 0)=0x139;
  7052. WFIFOL(fd, 2)=bl->id;
  7053. WFIFOW(fd, 6)=bl->x;
  7054. WFIFOW(fd, 8)=bl->y;
  7055. WFIFOW(fd,10)=sd->bl.x;
  7056. WFIFOW(fd,12)=sd->bl.y;
  7057. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  7058. WFIFOSET(fd,packet_len(0x139));
  7059. }
  7060. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  7061. /// 018f <result>.W <name id>.W
  7062. /// result:
  7063. /// 0 = success
  7064. /// 1 = failure
  7065. /// 2 = success (alchemist)
  7066. /// 3 = failure (alchemist)
  7067. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  7068. nullpo_retv( sd );
  7069. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  7070. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  7071. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  7072. p.result = flag;
  7073. p.itemId = client_nameid( nameid );
  7074. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7075. }
  7076. /// Initiates the pet taming process (ZC_START_CAPTURE).
  7077. /// 019e
  7078. void clif_catch_process(struct map_session_data *sd)
  7079. {
  7080. int fd;
  7081. nullpo_retv(sd);
  7082. fd=sd->fd;
  7083. WFIFOHEAD(fd,packet_len(0x19e));
  7084. WFIFOW(fd,0)=0x19e;
  7085. WFIFOSET(fd,packet_len(0x19e));
  7086. }
  7087. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  7088. /// 01a0 <result>.B
  7089. /// 0 = failure
  7090. /// 1 = success
  7091. void clif_pet_roulette(struct map_session_data *sd,int data)
  7092. {
  7093. int fd;
  7094. nullpo_retv(sd);
  7095. fd=sd->fd;
  7096. WFIFOHEAD(fd,packet_len(0x1a0));
  7097. WFIFOW(fd,0)=0x1a0;
  7098. WFIFOB(fd,2)=data;
  7099. WFIFOSET(fd,packet_len(0x1a0));
  7100. }
  7101. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7102. /// 01a6 <packet len>.W { <index>.W }*
  7103. void clif_sendegg(struct map_session_data *sd)
  7104. {
  7105. int i,n=0,fd;
  7106. nullpo_retv(sd);
  7107. fd=sd->fd;
  7108. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7109. clif_displaymessage(fd, msg_txt(sd,666));
  7110. return;
  7111. }
  7112. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7113. WFIFOW(fd,0)=0x1a6;
  7114. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7115. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7116. sd->inventory_data[i]->type != IT_PETEGG ||
  7117. sd->inventory.u.items_inventory[i].amount <= 0)
  7118. continue;
  7119. WFIFOW(fd,n*2+4)=client_index(i);
  7120. n++;
  7121. }
  7122. WFIFOW(fd,2)=4+n*2;
  7123. WFIFOSET(fd,WFIFOW(fd,2));
  7124. sd->menuskill_id = SA_TAMINGMONSTER;
  7125. sd->menuskill_val = -1;
  7126. }
  7127. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7128. /// 01a4 <type>.B <id>.L <data>.L
  7129. /// type:
  7130. /// 0 = pre-init (data = 0)
  7131. /// 1 = intimacy (data = 0~4)
  7132. /// 2 = hunger (data = 0~4)
  7133. /// 3 = accessory
  7134. /// 4 = performance (data = 1~3: normal, 4: special)
  7135. /// 5 = hairstyle
  7136. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7137. ///
  7138. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7139. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  7140. {
  7141. uint8 buf[16];
  7142. nullpo_retv(pd);
  7143. WBUFW(buf,0) = 0x1a4;
  7144. WBUFB(buf,2) = type;
  7145. WBUFL(buf,3) = pd->bl.id;
  7146. WBUFL(buf,7) = param;
  7147. if (sd)
  7148. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7149. else
  7150. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7151. }
  7152. /// Pet's base data (ZC_PROPERTY_PET).
  7153. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7154. void clif_send_petstatus(struct map_session_data *sd)
  7155. {
  7156. int fd;
  7157. struct s_pet *pet;
  7158. nullpo_retv(sd);
  7159. nullpo_retv(sd->pd);
  7160. fd=sd->fd;
  7161. pet = &sd->pd->pet;
  7162. WFIFOHEAD(fd,packet_len(0x1a2));
  7163. WFIFOW(fd,0)=0x1a2;
  7164. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7165. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7166. WFIFOW(fd,27)=pet->level;
  7167. WFIFOW(fd,29)=pet->hungry;
  7168. WFIFOW(fd,31)=pet->intimate;
  7169. WFIFOW(fd,33)=pet->equip;
  7170. #if PACKETVER >= 20081126
  7171. WFIFOW(fd,35)=pet->class_;
  7172. #endif
  7173. WFIFOSET(fd,packet_len(0x1a2));
  7174. }
  7175. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7176. /// 01aa <id>.L <data>.L
  7177. /// data:
  7178. /// @see CZ_PET_ACT.
  7179. void clif_pet_emotion(struct pet_data *pd,int param)
  7180. {
  7181. unsigned char buf[16];
  7182. nullpo_retv(pd);
  7183. memset(buf,0,packet_len(0x1aa));
  7184. WBUFW(buf,0)=0x1aa;
  7185. WBUFL(buf,2)=pd->bl.id;
  7186. WBUFL(buf,6)=param;
  7187. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7188. }
  7189. /// Result of request to feed a pet (ZC_FEED_PET).
  7190. /// 01a3 <result>.B <name id>.W
  7191. /// result:
  7192. /// 0 = failure
  7193. /// 1 = success
  7194. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  7195. nullpo_retv( sd );
  7196. struct PACKET_ZC_FEED_PET p;
  7197. p.packetType = 0x1a3;
  7198. p.result = fail;
  7199. p.itemId = client_nameid( foodid );
  7200. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7201. }
  7202. /// Send pet auto feed info.
  7203. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  7204. #if PACKETVER >= 20141008
  7205. nullpo_retv(sd);
  7206. if (force || battle_config.pet_autofeed_always) {
  7207. // Always send ON or OFF
  7208. if (sd->pd && battle_config.feature_pet_autofeed) {
  7209. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7210. }
  7211. else {
  7212. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7213. }
  7214. }
  7215. else {
  7216. // Only send when enabled
  7217. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7218. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7219. }
  7220. }
  7221. #endif
  7222. }
  7223. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7224. /// 01cd { <skill id>.L }*7
  7225. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  7226. {
  7227. nullpo_retv(sd);
  7228. int fd = sd->fd;
  7229. #ifdef RENEWAL
  7230. uint16 autospell_skill[][2] = {
  7231. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7232. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7233. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7234. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7235. };
  7236. int count = 0;
  7237. WFIFOHEAD(fd, 2 * 6 + 4);
  7238. WFIFOW(fd, 0) = 0x442;
  7239. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7240. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7241. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7242. count++;
  7243. }
  7244. }
  7245. WFIFOW(fd, 2) = 8 + count * 2;
  7246. WFIFOL(fd, 4) = count;
  7247. WFIFOSET(fd, WFIFOW(fd, 2));
  7248. #else
  7249. WFIFOHEAD(fd,packet_len(0x1cd));
  7250. WFIFOW(fd, 0)=0x1cd;
  7251. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7252. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7253. else
  7254. WFIFOL(fd,2)= 0x00000000;
  7255. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7256. WFIFOL(fd,6)= MG_COLDBOLT;
  7257. else
  7258. WFIFOL(fd,6)= 0x00000000;
  7259. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7260. WFIFOL(fd,10)= MG_FIREBOLT;
  7261. else
  7262. WFIFOL(fd,10)= 0x00000000;
  7263. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7264. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7265. else
  7266. WFIFOL(fd,14)= 0x00000000;
  7267. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7268. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7269. else
  7270. WFIFOL(fd,18)= 0x00000000;
  7271. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7272. WFIFOL(fd,22)= MG_FIREBALL;
  7273. else
  7274. WFIFOL(fd,22)= 0x00000000;
  7275. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7276. WFIFOL(fd,26)= MG_FROSTDIVER;
  7277. else
  7278. WFIFOL(fd,26)= 0x00000000;
  7279. WFIFOSET(fd,packet_len(0x1cd));
  7280. #endif
  7281. sd->menuskill_id = SA_AUTOSPELL;
  7282. sd->menuskill_val = skill_lv;
  7283. }
  7284. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7285. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7286. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7287. {
  7288. unsigned char buf[56];
  7289. nullpo_retv(src);
  7290. memset(buf,0,packet_len(0x1cf));
  7291. WBUFW(buf,0) = 0x1cf;
  7292. WBUFL(buf,2) = src->id;
  7293. if( src->type == BL_MER )
  7294. {
  7295. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7296. if( md && md->master && md->devotion_flag )
  7297. WBUFL(buf,6) = md->master->bl.id;
  7298. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7299. }
  7300. else
  7301. {
  7302. int i;
  7303. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7304. if( sd == NULL )
  7305. return;
  7306. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7307. WBUFL(buf,6+4*i) = sd->devotion[i];
  7308. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7309. }
  7310. if( tsd )
  7311. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7312. else
  7313. clif_send(buf, packet_len(0x1cf), src, AREA);
  7314. }
  7315. /// Notifies the client of an object's spirits.
  7316. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7317. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7318. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7319. nullpo_retv( bl );
  7320. struct PACKET_ZC_SPIRITS p = {};
  7321. p.packetType = HEADER_ZC_SPIRITS;
  7322. p.GID = bl->id;
  7323. switch( bl->type ){
  7324. case BL_PC:
  7325. p.amount = ( (struct map_session_data*)bl )->spiritball;
  7326. break;
  7327. case BL_HOM:
  7328. p.amount = ( (struct homun_data*)bl )->homunculus.spiritball;
  7329. break;
  7330. }
  7331. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7332. }
  7333. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7334. /// 01d2 <account id>.L <delay>.L
  7335. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7336. {
  7337. unsigned char buf[32];
  7338. nullpo_retv(bl);
  7339. WBUFW(buf,0)=0x1d2;
  7340. WBUFL(buf,2)=bl->id;
  7341. WBUFL(buf,6)=client_tick(wait);
  7342. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7343. }
  7344. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7345. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7346. /// flag:
  7347. /// 0 = inactive
  7348. /// 1 = active
  7349. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7350. {
  7351. unsigned char buf[32];
  7352. nullpo_retv(src);
  7353. WBUFW(buf,0)=0x1d1;
  7354. WBUFL(buf,2)=src->id;
  7355. WBUFL(buf,6)=dst_id;
  7356. WBUFL(buf,10)=active;
  7357. clif_send(buf,packet_len(0x1d1),src,AREA);
  7358. }
  7359. /// MVP effect (ZC_MVP).
  7360. /// 010c <account id>.L
  7361. void clif_mvp_effect(struct map_session_data *sd)
  7362. {
  7363. unsigned char buf[16];
  7364. nullpo_retv(sd);
  7365. WBUFW(buf,0)=0x10c;
  7366. WBUFL(buf,2)=sd->bl.id;
  7367. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7368. }
  7369. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7370. /// 010a <name id>.W
  7371. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7372. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7373. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7374. p.itemId = client_nameid( nameid );
  7375. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7376. }
  7377. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7378. /// 010b <exp>.L
  7379. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7380. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7381. if (battle_config.mvp_exp_reward_message) {
  7382. char e_msg[CHAT_SIZE_MAX];
  7383. sprintf(e_msg, msg_txt(sd, 717), exp);
  7384. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7385. }
  7386. #else
  7387. int fd;
  7388. nullpo_retv(sd);
  7389. fd = sd->fd;
  7390. WFIFOHEAD(fd, packet_len(0x10b));
  7391. WFIFOW(fd,0) = 0x10b;
  7392. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7393. WFIFOSET(fd, packet_len(0x10b));
  7394. #endif
  7395. }
  7396. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7397. /// 010d
  7398. ///
  7399. /// "You are the MVP, but cannot obtain the reward because
  7400. /// you are overweight."
  7401. void clif_mvp_noitem(struct map_session_data* sd)
  7402. {
  7403. int fd = sd->fd;
  7404. WFIFOHEAD(fd,packet_len(0x10d));
  7405. WFIFOW(fd,0) = 0x10d;
  7406. WFIFOSET(fd,packet_len(0x10d));
  7407. }
  7408. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7409. /// 0167 <result>.B
  7410. /// result:
  7411. /// 0 = "Guild has been created."
  7412. /// 1 = "You are already in a Guild."
  7413. /// 2 = "That Guild Name already exists."
  7414. /// 3 = "You need the neccessary item to create a Guild."
  7415. void clif_guild_created(struct map_session_data *sd,int flag)
  7416. {
  7417. int fd;
  7418. nullpo_retv(sd);
  7419. fd=sd->fd;
  7420. WFIFOHEAD(fd,packet_len(0x167));
  7421. WFIFOW(fd,0)=0x167;
  7422. WFIFOB(fd,2)=flag;
  7423. WFIFOSET(fd,packet_len(0x167));
  7424. }
  7425. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7426. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7427. /// mode:
  7428. /// &0x01 = allow invite
  7429. /// &0x10 = allow expel
  7430. void clif_guild_belonginfo(struct map_session_data *sd)
  7431. {
  7432. int ps,fd;
  7433. struct guild* g;
  7434. nullpo_retv(sd);
  7435. nullpo_retv(g = sd->guild);
  7436. fd=sd->fd;
  7437. ps=guild_getposition(sd);
  7438. WFIFOHEAD(fd,packet_len(0x16c));
  7439. WFIFOW(fd,0)=0x16c;
  7440. WFIFOL(fd,2)=g->guild_id;
  7441. WFIFOL(fd,6)=g->emblem_id;
  7442. WFIFOL(fd,10)=g->position[ps].mode;
  7443. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7444. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7445. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7446. WFIFOSET(fd,packet_len(0x16c));
  7447. }
  7448. /// Guild member login notice.
  7449. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7450. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7451. /// status:
  7452. /// 0 = offline
  7453. /// 1 = online
  7454. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7455. {
  7456. unsigned char buf[64];
  7457. struct map_session_data* sd;
  7458. nullpo_retv(g);
  7459. WBUFW(buf, 0)=0x1f2;
  7460. WBUFL(buf, 2)=g->member[idx].account_id;
  7461. WBUFL(buf, 6)=g->member[idx].char_id;
  7462. WBUFL(buf,10)=flag;
  7463. if( ( sd = g->member[idx].sd ) != NULL )
  7464. {
  7465. WBUFW(buf,14) = sd->status.sex;
  7466. WBUFW(buf,16) = sd->status.hair;
  7467. WBUFW(buf,18) = sd->status.hair_color;
  7468. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7469. }
  7470. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7471. {
  7472. WBUFW(buf,14) = 0;
  7473. WBUFW(buf,16) = 0;
  7474. WBUFW(buf,18) = 0;
  7475. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7476. }
  7477. }
  7478. // Function `clif_guild_memberlogin_notice` sends info about
  7479. // logins and logouts of a guild member to the rest members.
  7480. // But at the 1st time (after a player login or map changing)
  7481. // the client won't show the message.
  7482. // So I suggest use this function for sending "first-time-info"
  7483. // to some player on entering the game or changing location.
  7484. // At next time the client would always show the message.
  7485. // The function sends all the statuses in the single packet
  7486. // to economize traffic. [LuzZza]
  7487. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7488. {
  7489. struct guild *g;
  7490. unsigned char buf[14*128];
  7491. int i, count=0, p_len;
  7492. nullpo_retv(sd);
  7493. p_len = packet_len(0x16d);
  7494. if(!(g = sd->guild))
  7495. return;
  7496. for(i=0; i<g->max_member; i++) {
  7497. if(g->member[i].account_id > 0 &&
  7498. g->member[i].account_id != sd->status.account_id) {
  7499. WBUFW(buf,count*p_len) = 0x16d;
  7500. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7501. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7502. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7503. count++;
  7504. }
  7505. }
  7506. clif_send(buf, p_len*count, &sd->bl, SELF);
  7507. }
  7508. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7509. /// 014e <menu flag>.L
  7510. /// menu flag:
  7511. /// 0x00 = Basic Info (always on)
  7512. /// &0x01 = Member manager
  7513. /// &0x02 = Positions
  7514. /// &0x04 = Skills
  7515. /// &0x10 = Expulsion list
  7516. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7517. /// &0x80 = Notice
  7518. void clif_guild_masterormember(struct map_session_data *sd)
  7519. {
  7520. int fd;
  7521. nullpo_retv(sd);
  7522. fd=sd->fd;
  7523. WFIFOHEAD(fd,packet_len(0x14e));
  7524. WFIFOW(fd,0) = 0x14e;
  7525. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7526. WFIFOSET(fd,packet_len(0x14e));
  7527. }
  7528. /// Guild basic information (Territories [Valaris])
  7529. /// 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)
  7530. /// 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)
  7531. /// 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)
  7532. void clif_guild_basicinfo(struct map_session_data *sd) {
  7533. int fd;
  7534. struct guild *g;
  7535. #if PACKETVER < 20160622
  7536. int cmd = 0x1b6;
  7537. int offset = NAME_LENGTH;
  7538. #else
  7539. int cmd = 0xa84;
  7540. int offset = 0;
  7541. #endif
  7542. nullpo_retv(sd);
  7543. fd = sd->fd;
  7544. if( (g = sd->guild) == NULL )
  7545. return;
  7546. WFIFOHEAD(fd,packet_len(cmd));
  7547. WFIFOW(fd, 0)=cmd;
  7548. WFIFOL(fd, 2)=g->guild_id;
  7549. WFIFOL(fd, 6)=g->guild_lv;
  7550. WFIFOL(fd,10)=g->connect_member;
  7551. WFIFOL(fd,14)=g->max_member;
  7552. WFIFOL(fd,18)=g->average_lv;
  7553. WFIFOL(fd,22)=(uint32)cap_value(g->exp, 0, MAX_GUILD_EXP);
  7554. WFIFOL(fd,26)=(uint32)cap_value(g->next_exp, 0, MAX_GUILD_EXP);
  7555. WFIFOL(fd,30)=0; // Tax Points
  7556. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7557. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7558. WFIFOL(fd,42)=g->emblem_id;
  7559. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7560. #if PACKETVER < 20160622
  7561. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7562. #endif
  7563. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7564. WFIFOL(fd,70+offset+16) = 0; // zeny
  7565. #if PACKETVER >= 20160622
  7566. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7567. #endif
  7568. WFIFOSET(fd,packet_len(cmd));
  7569. }
  7570. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7571. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7572. void clif_guild_allianceinfo(struct map_session_data *sd)
  7573. {
  7574. int fd,i,c;
  7575. struct guild *g;
  7576. nullpo_retv(sd);
  7577. if( (g = sd->guild) == NULL )
  7578. return;
  7579. fd = sd->fd;
  7580. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7581. WFIFOW(fd, 0)=0x14c;
  7582. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7583. struct guild_alliance *a=&g->alliance[i];
  7584. if(a->guild_id>0){
  7585. WFIFOL(fd,c*32+4)=a->opposition;
  7586. WFIFOL(fd,c*32+8)=a->guild_id;
  7587. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7588. c++;
  7589. }
  7590. }
  7591. WFIFOW(fd, 2)=c*32+4;
  7592. WFIFOSET(fd,WFIFOW(fd,2));
  7593. }
  7594. /// Guild member manager information
  7595. /// 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)
  7596. /// state:
  7597. /// 0 = offline
  7598. /// 1 = online
  7599. /// memo:
  7600. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7601. /// 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)
  7602. void clif_guild_memberlist(struct map_session_data *sd)
  7603. {
  7604. int fd;
  7605. int i,c;
  7606. struct guild *g;
  7607. #if PACKETVER < 20161026
  7608. int cmd = 0x154;
  7609. int size = 104;
  7610. #else
  7611. int cmd = 0xaa5;
  7612. int size = 34;
  7613. #endif
  7614. nullpo_retv(sd);
  7615. if( !session_isActive(fd = sd->fd) )
  7616. return;
  7617. if( (g = sd->guild) == NULL )
  7618. return;
  7619. WFIFOHEAD(fd, g->max_member * size + 4);
  7620. WFIFOW(fd, 0)=cmd;
  7621. for(i=0,c=0;i<g->max_member;i++){
  7622. struct guild_member *m=&g->member[i];
  7623. if(m->account_id==0)
  7624. continue;
  7625. WFIFOL(fd,c*size+ 4)=m->account_id;
  7626. WFIFOL(fd,c*size+ 8)=m->char_id;
  7627. WFIFOW(fd,c*size+12)=m->hair;
  7628. WFIFOW(fd,c*size+14)=m->hair_color;
  7629. WFIFOW(fd,c*size+16)=m->gender;
  7630. WFIFOW(fd,c*size+18)=m->class_;
  7631. WFIFOW(fd,c*size+20)=m->lv;
  7632. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7633. WFIFOL(fd,c*size+26)=m->online;
  7634. WFIFOL(fd,c*size+30)=m->position;
  7635. #if PACKETVER < 20161026
  7636. memset(WFIFOP(fd,c*size+34),0,50); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
  7637. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7638. #else
  7639. WFIFOL(fd,c*size+34)=m->last_login;
  7640. #endif
  7641. c++;
  7642. }
  7643. WFIFOW(fd, 2)=c*size+4;
  7644. WFIFOSET(fd,WFIFOW(fd,2));
  7645. }
  7646. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7647. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7648. void clif_guild_positionnamelist(struct map_session_data *sd)
  7649. {
  7650. int i,fd;
  7651. struct guild *g;
  7652. nullpo_retv(sd);
  7653. if( (g = sd->guild) == NULL )
  7654. return;
  7655. fd = sd->fd;
  7656. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7657. WFIFOW(fd, 0)=0x166;
  7658. for(i=0;i<MAX_GUILDPOSITION;i++){
  7659. WFIFOL(fd,i*28+4)=i;
  7660. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7661. }
  7662. WFIFOW(fd,2)=i*28+4;
  7663. WFIFOSET(fd,WFIFOW(fd,2));
  7664. }
  7665. /// Guild position information (ZC_POSITION_INFO).
  7666. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7667. /// mode:
  7668. /// &0x01 = allow invite
  7669. /// &0x10 = allow expel
  7670. /// ranking:
  7671. /// TODO
  7672. void clif_guild_positioninfolist(struct map_session_data *sd)
  7673. {
  7674. int i,fd;
  7675. struct guild *g;
  7676. nullpo_retv(sd);
  7677. if( (g = sd->guild) == NULL )
  7678. return;
  7679. fd = sd->fd;
  7680. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7681. WFIFOW(fd, 0)=0x160;
  7682. for(i=0;i<MAX_GUILDPOSITION;i++){
  7683. struct guild_position *p=&g->position[i];
  7684. WFIFOL(fd,i*16+ 4)=i;
  7685. WFIFOL(fd,i*16+ 8)=p->mode;
  7686. WFIFOL(fd,i*16+12)=i;
  7687. WFIFOL(fd,i*16+16)=p->exp_mode;
  7688. }
  7689. WFIFOW(fd, 2)=i*16+4;
  7690. WFIFOSET(fd,WFIFOW(fd,2));
  7691. }
  7692. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7693. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7694. /// mode:
  7695. /// &0x01 = allow invite
  7696. /// &0x10 = allow expel
  7697. /// ranking:
  7698. /// TODO
  7699. void clif_guild_positionchanged(struct guild *g,int idx)
  7700. {
  7701. // FIXME: This packet is intended to update the clients after a
  7702. // commit of position info changes, not sending one packet per
  7703. // position.
  7704. struct map_session_data *sd;
  7705. unsigned char buf[128];
  7706. nullpo_retv(g);
  7707. WBUFW(buf, 0)=0x174;
  7708. WBUFW(buf, 2)=44; // packet len
  7709. // GUILD_REG_POSITION_INFO{
  7710. WBUFL(buf, 4)=idx;
  7711. WBUFL(buf, 8)=g->position[idx].mode;
  7712. WBUFL(buf,12)=idx;
  7713. WBUFL(buf,16)=g->position[idx].exp_mode;
  7714. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7715. // }*
  7716. if( (sd=guild_getavailablesd(g))!=NULL )
  7717. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7718. }
  7719. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7720. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7721. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7722. {
  7723. // FIXME: This packet is intended to update the clients after a
  7724. // commit of member position assignment changes, not sending one
  7725. // packet per position.
  7726. struct map_session_data *sd;
  7727. unsigned char buf[64];
  7728. nullpo_retv(g);
  7729. WBUFW(buf, 0)=0x156;
  7730. WBUFW(buf, 2)=16; // packet len
  7731. // MEMBER_POSITION_INFO{
  7732. WBUFL(buf, 4)=g->member[idx].account_id;
  7733. WBUFL(buf, 8)=g->member[idx].char_id;
  7734. WBUFL(buf,12)=g->member[idx].position;
  7735. // }*
  7736. if( (sd=guild_getavailablesd(g))!=NULL )
  7737. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7738. }
  7739. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7740. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7741. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7742. {
  7743. int fd;
  7744. nullpo_retv(sd);
  7745. nullpo_retv(g);
  7746. fd = sd->fd;
  7747. if( g->emblem_len <= 0 )
  7748. return;
  7749. WFIFOHEAD(fd,g->emblem_len+12);
  7750. WFIFOW(fd,0)=0x152;
  7751. WFIFOW(fd,2)=g->emblem_len+12;
  7752. WFIFOL(fd,4)=g->guild_id;
  7753. WFIFOL(fd,8)=g->emblem_id;
  7754. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7755. WFIFOSET(fd,WFIFOW(fd,2));
  7756. }
  7757. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7758. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7759. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7760. void clif_guild_emblem_area(struct block_list* bl)
  7761. {
  7762. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7763. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7764. PACKET_ZC_CHANGE_GUILD p{};
  7765. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7766. p.guild_id = status_get_guild_id(bl);
  7767. p.emblem_id = status_get_emblem_id(bl);
  7768. #if PACKETVER < 20190724
  7769. p.aid = bl->id;
  7770. #else
  7771. p.unknown = 0;
  7772. #endif
  7773. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7774. }
  7775. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7776. /// 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 }*
  7777. void clif_guild_skillinfo(struct map_session_data* sd)
  7778. {
  7779. int fd;
  7780. struct guild* g;
  7781. int i,c;
  7782. nullpo_retv(sd);
  7783. if( (g = sd->guild) == NULL )
  7784. return;
  7785. fd = sd->fd;
  7786. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7787. WFIFOW(fd,0) = 0x0162;
  7788. WFIFOW(fd,4) = g->skill_point;
  7789. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7790. {
  7791. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7792. {
  7793. int id = g->skill[i].id;
  7794. int p = 6 + c*37;
  7795. WFIFOW(fd,p+0) = id;
  7796. WFIFOL(fd,p+2) = skill_get_inf(id);
  7797. WFIFOW(fd,p+6) = g->skill[i].lv;
  7798. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7799. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7800. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7801. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7802. c++;
  7803. }
  7804. }
  7805. WFIFOW(fd,2) = 6 + c*37;
  7806. WFIFOSET(fd,WFIFOW(fd,2));
  7807. }
  7808. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7809. /// 016f <subject>.60B <notice>.120B
  7810. void clif_guild_notice(struct map_session_data* sd)
  7811. {
  7812. struct guild* g;
  7813. nullpo_retv(sd);
  7814. nullpo_retv(g = sd->guild);
  7815. int fd = sd->fd;
  7816. if ( !session_isActive(fd) )
  7817. return;
  7818. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7819. return;
  7820. WFIFOHEAD(fd,packet_len(0x16f));
  7821. WFIFOW(fd,0) = 0x16f;
  7822. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7823. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7824. WFIFOSET(fd,packet_len(0x16f));
  7825. }
  7826. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7827. /// 016a <guild id>.L <guild name>.24B
  7828. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7829. {
  7830. int fd;
  7831. nullpo_retv(sd);
  7832. nullpo_retv(g);
  7833. fd=sd->fd;
  7834. WFIFOHEAD(fd,packet_len(0x16a));
  7835. WFIFOW(fd,0)=0x16a;
  7836. WFIFOL(fd,2)=g->guild_id;
  7837. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7838. WFIFOSET(fd,packet_len(0x16a));
  7839. }
  7840. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7841. /// 0169 <answer>.B
  7842. /// answer:
  7843. /// 0 = Already in guild.
  7844. /// 1 = Offer rejected.
  7845. /// 2 = Offer accepted.
  7846. /// 3 = Guild full.
  7847. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7848. {
  7849. int fd;
  7850. nullpo_retv(sd);
  7851. fd=sd->fd;
  7852. WFIFOHEAD(fd,packet_len(0x169));
  7853. WFIFOW(fd,0)=0x169;
  7854. WFIFOB(fd,2)=flag;
  7855. WFIFOSET(fd,packet_len(0x169));
  7856. }
  7857. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7858. /// 015a <char name>.24B <reason>.40B
  7859. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7860. {
  7861. unsigned char buf[128];
  7862. nullpo_retv(sd);
  7863. WBUFW(buf, 0)=0x15a;
  7864. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7865. memcpy(WBUFP(buf,26),mes,40);
  7866. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7867. }
  7868. /// Notifies clients of a guild of an expelled member.
  7869. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7870. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7871. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7872. {
  7873. unsigned char buf[128];
  7874. #if PACKETVER < 20100803
  7875. const unsigned short cmd = 0x15c;
  7876. #else
  7877. const unsigned short cmd = 0x839;
  7878. #endif
  7879. nullpo_retv(sd);
  7880. WBUFW(buf,0) = cmd;
  7881. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7882. safestrncpy(WBUFCP(buf,26), mes, 40);
  7883. #if PACKETVER < 20100803
  7884. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7885. #endif
  7886. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7887. }
  7888. /// Guild expulsion list (ZC_BAN_LIST).
  7889. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7890. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7891. void clif_guild_expulsionlist(struct map_session_data* sd)
  7892. {
  7893. #if PACKETVER < 20100803
  7894. const int offset = NAME_LENGTH*2+40;
  7895. #else
  7896. const int offset = NAME_LENGTH+40;
  7897. #endif
  7898. int fd, i, c = 0;
  7899. struct guild* g;
  7900. nullpo_retv(sd);
  7901. if( (g = sd->guild) == NULL )
  7902. return;
  7903. fd = sd->fd;
  7904. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7905. WFIFOW(fd,0) = 0x163;
  7906. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7907. {
  7908. struct guild_expulsion* e = &g->expulsion[i];
  7909. if( e->account_id > 0 )
  7910. {
  7911. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7912. #if PACKETVER < 20100803
  7913. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7914. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7915. #else
  7916. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7917. #endif
  7918. c++;
  7919. }
  7920. }
  7921. WFIFOW(fd,2) = 4 + c*offset;
  7922. WFIFOSET(fd,WFIFOW(fd,2));
  7923. }
  7924. /// Guild chat message (ZC_GUILD_CHAT).
  7925. /// 017f <packet len>.W <message>.?B
  7926. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7927. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7928. struct map_session_data *sd;
  7929. uint8 buf[256];
  7930. if( len == 0 )
  7931. {
  7932. return;
  7933. }
  7934. else if( len > sizeof(buf)-5 )
  7935. {
  7936. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7937. len = sizeof(buf)-5;
  7938. }
  7939. WBUFW(buf, 0) = 0x17f;
  7940. WBUFW(buf, 2) = len + 5;
  7941. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7942. if ((sd = guild_getavailablesd(g)) != NULL)
  7943. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7944. }
  7945. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7946. /// 0171 <inviter account id>.L <guild name>.24B
  7947. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7948. {
  7949. int fd;
  7950. nullpo_retv(sd);
  7951. fd=sd->fd;
  7952. WFIFOHEAD(fd,packet_len(0x171));
  7953. WFIFOW(fd,0)=0x171;
  7954. WFIFOL(fd,2)=account_id;
  7955. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7956. WFIFOSET(fd,packet_len(0x171));
  7957. }
  7958. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7959. /// 0173 <answer>.B
  7960. /// answer:
  7961. /// 0 = Already allied.
  7962. /// 1 = You rejected the offer.
  7963. /// 2 = You accepted the offer.
  7964. /// 3 = They have too any alliances.
  7965. /// 4 = You have too many alliances.
  7966. /// 5 = Alliances are disabled.
  7967. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7968. {
  7969. int fd;
  7970. nullpo_retv(sd);
  7971. fd=sd->fd;
  7972. WFIFOHEAD(fd,packet_len(0x173));
  7973. WFIFOW(fd,0)=0x173;
  7974. WFIFOL(fd,2)=flag;
  7975. WFIFOSET(fd,packet_len(0x173));
  7976. }
  7977. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7978. /// 0184 <other guild id>.L <relation>.L
  7979. /// relation:
  7980. /// 0 = Ally
  7981. /// 1 = Enemy
  7982. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7983. {
  7984. nullpo_retv(sd);
  7985. int fd = sd->fd;
  7986. if ( !session_isActive(fd) )
  7987. return;
  7988. WFIFOHEAD(fd,packet_len(0x184));
  7989. WFIFOW(fd,0)=0x184;
  7990. WFIFOL(fd,2)=guild_id;
  7991. WFIFOL(fd,6)=flag;
  7992. WFIFOSET(fd,packet_len(0x184));
  7993. }
  7994. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7995. /// 0181 <result>.B
  7996. /// result:
  7997. /// 0 = Antagonist has been set.
  7998. /// 1 = Guild has too many Antagonists.
  7999. /// 2 = Already set as an Antagonist.
  8000. /// 3 = Antagonists are disabled.
  8001. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  8002. {
  8003. int fd;
  8004. nullpo_retv(sd);
  8005. fd=sd->fd;
  8006. WFIFOHEAD(fd,packet_len(0x181));
  8007. WFIFOW(fd,0)=0x181;
  8008. WFIFOB(fd,2)=flag;
  8009. WFIFOSET(fd,packet_len(0x181));
  8010. }
  8011. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  8012. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  8013. /*
  8014. void clif_guild_allianceadded(struct guild *g,int idx)
  8015. {
  8016. unsigned char buf[64];
  8017. WBUFW(buf,0)=0x185;
  8018. WBUFL(buf,2)=g->alliance[idx].opposition;
  8019. WBUFL(buf,6)=g->alliance[idx].guild_id;
  8020. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  8021. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  8022. }
  8023. */
  8024. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  8025. /// 015e <reason>.L
  8026. /// 0 = success
  8027. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  8028. /// 2 = there are still members in the guild
  8029. void clif_guild_broken(struct map_session_data *sd,int flag)
  8030. {
  8031. int fd;
  8032. nullpo_retv(sd);
  8033. fd=sd->fd;
  8034. WFIFOHEAD(fd,packet_len(0x15e));
  8035. WFIFOW(fd,0)=0x15e;
  8036. WFIFOL(fd,2)=flag;
  8037. WFIFOSET(fd,packet_len(0x15e));
  8038. }
  8039. /// Displays emotion on an object (ZC_EMOTION).
  8040. /// 00c0 <id>.L <type>.B
  8041. /// type:
  8042. /// enum emotion_type
  8043. void clif_emotion(struct block_list *bl,int type)
  8044. {
  8045. unsigned char buf[8];
  8046. nullpo_retv(bl);
  8047. WBUFW(buf,0)=0xc0;
  8048. WBUFL(buf,2)=bl->id;
  8049. WBUFB(buf,6)=type;
  8050. clif_send(buf,packet_len(0xc0),bl,AREA);
  8051. }
  8052. /// Displays the contents of a talkiebox trap.
  8053. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  8054. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  8055. nullpo_retv( bl );
  8056. nullpo_retv( talkie );
  8057. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  8058. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  8059. p.aid = bl->id;
  8060. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  8061. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  8062. }
  8063. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  8064. /// 01ea <id>.L
  8065. void clif_wedding_effect(struct block_list *bl)
  8066. {
  8067. unsigned char buf[6];
  8068. nullpo_retv(bl);
  8069. WBUFW(buf,0) = 0x1ea;
  8070. WBUFL(buf,2) = bl->id;
  8071. clif_send(buf, packet_len(0x1ea), bl, AREA);
  8072. }
  8073. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  8074. /// 01e6 <partner name>.24B
  8075. void clif_callpartner(struct map_session_data *sd)
  8076. {
  8077. unsigned char buf[26];
  8078. nullpo_retv(sd);
  8079. WBUFW(buf,0) = 0x1e6;
  8080. if( sd->status.partner_id ) {
  8081. const char *p = map_charid2nick(sd->status.partner_id);
  8082. struct map_session_data *p_sd = pc_get_partner(sd);
  8083. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  8084. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  8085. else
  8086. WBUFB(buf,2) = 0;
  8087. } else {// Send zero-length name if no partner, to initialize the client buffer.
  8088. WBUFB(buf,2) = 0;
  8089. }
  8090. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  8091. }
  8092. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  8093. /// 01e4
  8094. /// This packet while still implemented by the client is no longer being officially used.
  8095. /*
  8096. void clif_marriage_process(struct map_session_data *sd)
  8097. {
  8098. int fd;
  8099. nullpo_retv(sd);
  8100. fd=sd->fd;
  8101. WFIFOHEAD(fd,packet_len(0x1e4));
  8102. WFIFOW(fd,0)=0x1e4;
  8103. WFIFOSET(fd,packet_len(0x1e4));
  8104. }
  8105. */
  8106. /// Notice of divorce (ZC_DIVORCE).
  8107. /// 0205 <partner name>.24B
  8108. void clif_divorced(struct map_session_data* sd, const char* name)
  8109. {
  8110. int fd;
  8111. nullpo_retv(sd);
  8112. fd=sd->fd;
  8113. WFIFOHEAD(fd,packet_len(0x205));
  8114. WFIFOW(fd,0)=0x205;
  8115. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8116. WFIFOSET(fd, packet_len(0x205));
  8117. }
  8118. /// Marriage proposal (ZC_REQ_COUPLE).
  8119. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8120. /// This packet while still implemented by the client is no longer being officially used.
  8121. /*
  8122. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  8123. {
  8124. nullpo_retv(sd);
  8125. WFIFOHEAD(fd,packet_len(0x1e2));
  8126. WFIFOW(fd,0) = 0x1e2;
  8127. WFIFOL(fd,2) = ssd->status.account_id;
  8128. WFIFOL(fd,6) = ssd->status.char_id;
  8129. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8130. WFIFOSET(fd, packet_len(0x1e2));
  8131. }
  8132. */
  8133. /*==========================================
  8134. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8135. *------------------------------------------*/
  8136. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8137. {
  8138. unsigned char buf[256];
  8139. if( len == 0 ) {
  8140. return;
  8141. } else if( len > sizeof(buf)-5 ) {
  8142. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8143. len = sizeof(buf)-5;
  8144. }
  8145. WBUFW(buf, 0) = 0x17f;
  8146. WBUFW(buf, 2) = len + 5;
  8147. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8148. clif_send(buf, WBUFW(buf,2), src, target);
  8149. }
  8150. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8151. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8152. /// 00cd <result>.B
  8153. /// result:
  8154. /// 0 = failure
  8155. /// 1 = success
  8156. void clif_GM_kickack(struct map_session_data *sd, int id)
  8157. {
  8158. int fd;
  8159. nullpo_retv(sd);
  8160. fd = sd->fd;
  8161. WFIFOHEAD(fd,packet_len(0xcd));
  8162. WFIFOW(fd,0) = 0xcd;
  8163. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8164. WFIFOSET(fd, packet_len(0xcd));
  8165. }
  8166. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  8167. {
  8168. nullpo_retv(tsd);
  8169. if (sd == NULL)
  8170. tsd->state.keepshop = true;
  8171. if (session_isActive(tsd->fd))
  8172. clif_authfail_fd(tsd->fd, 15);
  8173. else
  8174. map_quit(tsd);
  8175. if (sd)
  8176. clif_GM_kickack(sd, tsd->status.account_id);
  8177. }
  8178. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8179. /// 014a <result>.L
  8180. /// result:
  8181. /// 0 = "A manner point has been successfully aligned."
  8182. /// 1 = MP_FAILURE_EXHAUST
  8183. /// 2 = MP_FAILURE_ALREADY_GIVING
  8184. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8185. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8186. /// 5 = "You got a good point from %s."
  8187. void clif_manner_message(struct map_session_data* sd, uint32 type)
  8188. {
  8189. int fd;
  8190. nullpo_retv(sd);
  8191. fd = sd->fd;
  8192. WFIFOHEAD(fd,packet_len(0x14a));
  8193. WFIFOW(fd,0) = 0x14a;
  8194. WFIFOL(fd,2) = type;
  8195. WFIFOSET(fd, packet_len(0x14a));
  8196. }
  8197. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8198. /// 014b <type>.B <GM name>.24B
  8199. /// type:
  8200. /// 0 = positive (unmute)
  8201. /// 1 = negative (mute)
  8202. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  8203. {
  8204. int fd;
  8205. nullpo_retv(sd);
  8206. nullpo_retv(tsd);
  8207. fd = tsd->fd;
  8208. WFIFOHEAD(fd,packet_len(0x14b));
  8209. WFIFOW(fd,0) = 0x14b;
  8210. WFIFOB(fd,2) = type;
  8211. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8212. WFIFOSET(fd, packet_len(0x14b));
  8213. }
  8214. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8215. /// 00d1 <type>.B <result>.B
  8216. /// type:
  8217. /// 0 = /ex (deny)
  8218. /// 1 = /in (allow)
  8219. /// result:
  8220. /// 0 = success
  8221. /// 1 = failure
  8222. /// 2 = too many blocks
  8223. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  8224. {
  8225. int fd;
  8226. nullpo_retv(sd);
  8227. fd=sd->fd;
  8228. WFIFOHEAD(fd,packet_len(0xd1));
  8229. WFIFOW(fd,0)=0xd1;
  8230. WFIFOB(fd,2)=type;
  8231. WFIFOB(fd,3)=flag;
  8232. WFIFOSET(fd,packet_len(0xd1));
  8233. }
  8234. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8235. /// 00d2 <type>.B <result>.B
  8236. /// type:
  8237. /// 0 = /exall (deny)
  8238. /// 1 = /inall (allow)
  8239. /// result:
  8240. /// 0 = success
  8241. /// 1 = failure
  8242. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8243. {
  8244. int fd;
  8245. nullpo_retv(sd);
  8246. fd=sd->fd;
  8247. WFIFOHEAD(fd,packet_len(0xd2));
  8248. WFIFOW(fd,0)=0xd2;
  8249. WFIFOB(fd,2)=type;
  8250. WFIFOB(fd,3)=flag;
  8251. WFIFOSET(fd,packet_len(0xd2));
  8252. }
  8253. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8254. /// 07fe <bgm>.24B
  8255. void clif_playBGM(struct map_session_data* sd, const char* name)
  8256. {
  8257. int fd;
  8258. nullpo_retv(sd);
  8259. fd = sd->fd;
  8260. WFIFOHEAD(fd,packet_len(0x7fe));
  8261. WFIFOW(fd,0) = 0x7fe;
  8262. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8263. WFIFOSET(fd,packet_len(0x7fe));
  8264. }
  8265. /// Plays/stops a wave sound (ZC_SOUND).
  8266. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8267. /// file name:
  8268. /// relative to data\wav
  8269. /// act:
  8270. /// 0 = play (once)
  8271. /// 1 = play (repeat, does not work)
  8272. /// 2 = stops all sound instances of file name (does not work)
  8273. /// term:
  8274. /// unknown purpose, only relevant to act = 1
  8275. /// npc id:
  8276. /// The accustic direction of the sound is determined by the
  8277. /// relative position of the NPC to the player (3D sound).
  8278. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8279. {
  8280. int fd;
  8281. nullpo_retv(sd);
  8282. nullpo_retv(bl);
  8283. fd = sd->fd;
  8284. WFIFOHEAD(fd,packet_len(0x1d3));
  8285. WFIFOW(fd,0) = 0x1d3;
  8286. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8287. WFIFOB(fd,26) = type;
  8288. WFIFOL(fd,27) = 0;
  8289. WFIFOL(fd,31) = bl->id;
  8290. WFIFOSET(fd,packet_len(0x1d3));
  8291. }
  8292. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8293. {
  8294. unsigned char buf[40];
  8295. nullpo_retv(bl);
  8296. WBUFW(buf,0) = 0x1d3;
  8297. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8298. WBUFB(buf,26) = type;
  8299. WBUFL(buf,27) = 0;
  8300. WBUFL(buf,31) = bl->id;
  8301. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8302. }
  8303. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8304. /// 01f3 <id>.L <effect id>.L
  8305. /// effect id:
  8306. /// @see doc/effect_list.txt
  8307. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8308. {
  8309. unsigned char buf[24];
  8310. nullpo_retv(bl);
  8311. memset(buf, 0, packet_len(0x1f3));
  8312. WBUFW(buf,0) = 0x1f3;
  8313. WBUFL(buf,2) = bl->id;
  8314. WBUFL(buf,6) = type;
  8315. clif_send(buf, packet_len(0x1f3), bl, target);
  8316. if (disguised(bl)) {
  8317. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8318. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8319. }
  8320. }
  8321. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8322. {
  8323. WFIFOHEAD(fd,10);
  8324. WFIFOW(fd,0) = 0x1f3;
  8325. WFIFOL(fd,2) = bl->id;
  8326. WFIFOL(fd,6) = type;
  8327. WFIFOSET(fd,10);
  8328. }
  8329. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8330. /// 0284 <id>.L <effect id>.L <num data>.L
  8331. /// effect id:
  8332. /// @see doc/effect_list.txt
  8333. /// num data:
  8334. /// effect-dependent value
  8335. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8336. {
  8337. uint8 buf[14];
  8338. WBUFW(buf,0) = 0x284;
  8339. WBUFL(buf,2) = bl->id;
  8340. WBUFL(buf,6) = effect_id;
  8341. WBUFL(buf,10) = num;
  8342. clif_send(buf, packet_len(0x284), bl, target);
  8343. if( disguised(bl) )
  8344. {
  8345. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8346. clif_send(buf, packet_len(0x284), bl, SELF);
  8347. }
  8348. }
  8349. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8350. {
  8351. #if PACKETVER >= 20181002
  8352. nullpo_retv( bl_src );
  8353. nullpo_retv( bl_target );
  8354. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8355. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8356. p.aid = bl_src->id;
  8357. p.effectId = effect;
  8358. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8359. if( disguised(bl_src) )
  8360. {
  8361. p.aid = disguised_bl_id( bl_src->id );
  8362. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8363. }
  8364. #endif
  8365. }
  8366. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8367. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8368. 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) {
  8369. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8370. uint8 buf[CHAT_SIZE_MAX];
  8371. nullpo_retv(bl);
  8372. if (msg_len > sizeof(buf) - 12) {
  8373. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8374. msg_len = sizeof(buf) - 12;
  8375. }
  8376. if (rgb2bgr)
  8377. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8378. WBUFW(buf,0) = 0x2C1;
  8379. WBUFW(buf,2) = msg_len + 12;
  8380. WBUFL(buf,4) = bl->id;
  8381. WBUFL(buf,8) = color;
  8382. memcpy(WBUFCP(buf,12), msg, msg_len);
  8383. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8384. }
  8385. /**
  8386. * Notifies the client that the storage window is still open
  8387. *
  8388. * Should only be used in cases where the client closed the
  8389. * storage window without server's consent
  8390. */
  8391. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8392. // Notify the client that the storage is open
  8393. if( sd->state.storage_flag == 1 ) {
  8394. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8395. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8396. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8397. }
  8398. // Notify the client that the gstorage is open otherwise it will
  8399. // remain locked forever and nobody will be able to access it
  8400. if( sd->state.storage_flag == 2 ) {
  8401. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8402. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8403. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8404. else {
  8405. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8406. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8407. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8408. }
  8409. }
  8410. // Notify the client that the premium storage is open
  8411. if (sd->state.storage_flag == 3) {
  8412. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8413. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8414. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8415. }
  8416. }
  8417. // refresh the client's screen, getting rid of any effects
  8418. void clif_refresh(struct map_session_data *sd)
  8419. {
  8420. nullpo_retv(sd);
  8421. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8422. clif_inventorylist(sd);
  8423. clif_equipswitch_list(sd);
  8424. if(pc_iscarton(sd)) {
  8425. clif_cartlist(sd);
  8426. clif_updatestatus(sd,SP_CARTINFO);
  8427. }
  8428. clif_updatestatus(sd,SP_WEIGHT);
  8429. clif_updatestatus(sd,SP_MAXWEIGHT);
  8430. clif_updatestatus(sd,SP_STR);
  8431. clif_updatestatus(sd,SP_AGI);
  8432. clif_updatestatus(sd,SP_VIT);
  8433. clif_updatestatus(sd,SP_INT);
  8434. clif_updatestatus(sd,SP_DEX);
  8435. clif_updatestatus(sd,SP_LUK);
  8436. #ifdef RENEWAL
  8437. clif_updatestatus(sd,SP_POW);
  8438. clif_updatestatus(sd,SP_STA);
  8439. clif_updatestatus(sd,SP_WIS);
  8440. clif_updatestatus(sd,SP_SPL);
  8441. clif_updatestatus(sd,SP_CON);
  8442. clif_updatestatus(sd,SP_CRT);
  8443. #endif
  8444. if (sd->spiritball)
  8445. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8446. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8447. clif_millenniumshield_single(sd->fd, sd);
  8448. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8449. clif_spiritcharm_single(sd->fd, sd);
  8450. if (sd->soulball)
  8451. clif_soulball( sd, &sd->bl, SELF );
  8452. if (sd->servantball)
  8453. clif_servantball( *sd, &sd->bl, SELF );
  8454. if (sd->abyssball)
  8455. clif_abyssball( *sd, &sd->bl, SELF );
  8456. if (sd->vd.cloth_color)
  8457. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8458. if (sd->vd.body_style)
  8459. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8460. if(hom_is_active(sd->hd))
  8461. clif_send_homdata(sd,SP_ACK,0);
  8462. if( sd->md ) {
  8463. clif_mercenary_info(sd);
  8464. clif_mercenary_skillblock(sd);
  8465. }
  8466. if( sd->ed )
  8467. clif_elemental_info(sd);
  8468. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8469. clif_weather_check(sd);
  8470. if( sd->chatID )
  8471. chat_leavechat(sd,0);
  8472. if( sd->state.vending )
  8473. clif_openvending(sd, sd->bl.id, sd->vending);
  8474. if( pc_issit(sd) )
  8475. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8476. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8477. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8478. else
  8479. clif_changed_dir(&sd->bl, SELF);
  8480. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8481. //Issue #2143
  8482. //Cancel Trading State
  8483. if (sd->state.trading)
  8484. trade_tradecancel(sd);
  8485. //Cancel Buying/Selling State
  8486. if (sd->state.buyingstore)
  8487. buyingstore_close(sd);
  8488. mail_clear(sd);
  8489. clif_loadConfirm( sd );
  8490. if( disguised(&sd->bl) ) {/* refresh-da */
  8491. short disguise = sd->disguise;
  8492. pc_disguise(sd, 0);
  8493. pc_disguise(sd, disguise);
  8494. }
  8495. clif_refresh_storagewindow(sd);
  8496. }
  8497. /// Updates the object's (bl) name on client.
  8498. /// Used to update when a char leaves a party/guild. [Skotlex]
  8499. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8500. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8501. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8502. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8503. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8504. nullpo_retv( src );
  8505. nullpo_retv( bl );
  8506. switch( bl->type ){
  8507. case BL_PC: {
  8508. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8509. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8510. packet.gid = bl->id;
  8511. map_session_data *sd = (map_session_data *)bl;
  8512. //Requesting your own "shadow" name. [Skotlex]
  8513. if( src == bl && target == SELF && sd->disguise ){
  8514. packet.gid = -bl->id;
  8515. }
  8516. if( sd->fakename[0] ) {
  8517. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8518. clif_send( &packet, sizeof(packet), src, target );
  8519. return;
  8520. }
  8521. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8522. party_data *p = nullptr;
  8523. if( sd->status.party_id ){
  8524. p = party_search( sd->status.party_id );
  8525. }
  8526. // do not display party unless the player is also in a guild
  8527. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8528. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8529. }
  8530. if( sd->guild ){
  8531. int position;
  8532. // Will get the position of the guild the player is in
  8533. position = guild_getposition( sd );
  8534. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8535. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8536. }else if( sd->clan ){
  8537. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8538. }
  8539. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8540. packet.title_id = sd->status.title_id; // Title ID
  8541. #endif
  8542. clif_send(&packet, sizeof(packet), src, target);
  8543. }
  8544. break;
  8545. //[blackhole89]
  8546. case BL_HOM:
  8547. case BL_MER:
  8548. case BL_PET:
  8549. case BL_NPC:
  8550. case BL_ELEM: {
  8551. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8552. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8553. packet.gid = bl->id;
  8554. switch (bl->type) {
  8555. case BL_HOM:
  8556. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8557. break;
  8558. case BL_MER:
  8559. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8560. break;
  8561. case BL_PET:
  8562. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8563. break;
  8564. case BL_NPC:
  8565. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8566. break;
  8567. case BL_ELEM:
  8568. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8569. break;
  8570. }
  8571. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8572. unit_data *ud = unit_bl2ud(bl);
  8573. if (ud != nullptr) {
  8574. memcpy(packet.title, ud->title, NAME_LENGTH);
  8575. packet.groupId = ud->group_id;
  8576. }
  8577. #endif
  8578. clif_send(&packet, sizeof(packet), src, target);
  8579. }
  8580. break;
  8581. case BL_MOB: {
  8582. mob_data *md = (mob_data *)bl;
  8583. if( md->guardian_data && md->guardian_data->guild_id ){
  8584. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8585. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8586. packet.gid = bl->id;
  8587. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8588. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8589. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8590. clif_send(&packet, sizeof(packet), src, target);
  8591. }else if( battle_config.show_mob_info ){
  8592. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8593. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8594. packet.gid = bl->id;
  8595. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8596. char mobhp[50], *str_p = mobhp;
  8597. if( battle_config.show_mob_info&4 ){
  8598. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8599. }
  8600. if( battle_config.show_mob_info&1 ){
  8601. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8602. }
  8603. if( battle_config.show_mob_info&2 ){
  8604. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8605. }
  8606. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8607. if( str_p != mobhp ){
  8608. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8609. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8610. }
  8611. clif_send(&packet, sizeof(packet), src, target);
  8612. } else {
  8613. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8614. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8615. packet.gid = bl->id;
  8616. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8617. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8618. unit_data *ud = unit_bl2ud(bl);
  8619. if (ud != nullptr) {
  8620. memcpy(packet.title, ud->title, NAME_LENGTH);
  8621. packet.groupId = ud->group_id;
  8622. }
  8623. #endif
  8624. clif_send(&packet, sizeof(packet), src, target);
  8625. }
  8626. }
  8627. break;
  8628. case BL_CHAT:
  8629. case BL_SKILL:
  8630. // Newer clients request this, but do not need an answer
  8631. return;
  8632. default:
  8633. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8634. return;
  8635. }
  8636. }
  8637. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8638. /// 01ff <id>.L <x>.W <y>.W
  8639. ///
  8640. /// Visually moves(instant) a character to x,y. The char moves even
  8641. /// when the target cell isn't walkable. If the char is sitting it
  8642. /// stays that way.
  8643. void clif_slide(struct block_list *bl, int x, int y)
  8644. {
  8645. unsigned char buf[10];
  8646. nullpo_retv(bl);
  8647. WBUFW(buf, 0) = 0x01ff;
  8648. WBUFL(buf, 2) = bl->id;
  8649. WBUFW(buf, 6) = x;
  8650. WBUFW(buf, 8) = y;
  8651. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8652. if( disguised(bl) )
  8653. {
  8654. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8655. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8656. }
  8657. }
  8658. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8659. /// 008d <packet len>.W <id>.L <message>.?B
  8660. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8661. {
  8662. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8663. int len_mes = strlen(mes)+1; //Account for \0
  8664. if (len_mes > sizeof(buf)-8) {
  8665. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8666. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8667. }
  8668. // send message to others
  8669. if (flag == AREA) {
  8670. WBUFW(buf,0) = 0x8d;
  8671. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8672. WBUFL(buf,4) = bl->id;
  8673. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8674. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8675. }
  8676. // send back message to the speaker
  8677. if( bl->type == BL_PC ) {
  8678. WBUFW(buf,0) = 0x8e;
  8679. WBUFW(buf, 2) = len_mes + 4;
  8680. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8681. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8682. }
  8683. }
  8684. /*==========================
  8685. * Minimap fix [Kevin]
  8686. * Remove dot from minimap
  8687. *--------------------------*/
  8688. void clif_party_xy_remove(struct map_session_data *sd)
  8689. {
  8690. unsigned char buf[16];
  8691. nullpo_retv(sd);
  8692. WBUFW(buf,0)=0x107;
  8693. WBUFL(buf,2)=sd->status.account_id;
  8694. WBUFW(buf,6)=-1;
  8695. WBUFW(buf,8)=-1;
  8696. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8697. }
  8698. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8699. /// 0215 <msg id>.L
  8700. /// msg id:
  8701. /// 0x15 = End all negative status (PA_GOSPEL)
  8702. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8703. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8704. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8705. /// 0x19 = All stats +20 (PA_GOSPEL)
  8706. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8707. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8708. /// 0x1e = DEF +25% (PA_GOSPEL)
  8709. /// 0x1f = ATK +100% (PA_GOSPEL)
  8710. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8711. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8712. /// ? = nothing
  8713. void clif_gospel_info(struct map_session_data *sd, int type)
  8714. {
  8715. int fd=sd->fd;
  8716. WFIFOHEAD(fd,packet_len(0x215));
  8717. WFIFOW(fd,0)=0x215;
  8718. WFIFOL(fd,2)=type;
  8719. WFIFOSET(fd, packet_len(0x215));
  8720. }
  8721. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8722. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8723. /// result:
  8724. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8725. /// star:
  8726. /// 0 = Place of the Sun
  8727. /// 1 = Place of the Moon
  8728. /// 2 = Place of the Stars
  8729. /// 1 = Star Gladiator %s's %s: <mapname>
  8730. /// star:
  8731. /// 0 = Place of the Sun
  8732. /// 1 = Place of the Moon
  8733. /// 2 = Place of the Stars
  8734. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8735. /// star:
  8736. /// 0 = Target of the Sun
  8737. /// 1 = Target of the Moon
  8738. /// 2 = Target of the Stars
  8739. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8740. /// star:
  8741. /// 0 = Monster of the Sun
  8742. /// 1 = Monster of the Moon
  8743. /// 2 = Monster of the Stars
  8744. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8745. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8746. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8747. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8748. /// 40 = Target HP : <monster_id used as HP>
  8749. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8750. {
  8751. int fd = sd->fd;
  8752. WFIFOHEAD(fd,packet_len(0x20e));
  8753. WFIFOW(fd,0) = 0x20e;
  8754. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8755. WFIFOL(fd,26) = monster_id;
  8756. WFIFOB(fd,30) = star;
  8757. WFIFOB(fd,31) = result;
  8758. WFIFOSET(fd,packet_len(0x20e));
  8759. }
  8760. /*==========================================
  8761. * Info about Star Glaldiator save map [Komurka]
  8762. * type: 1: Information, 0: Map registered
  8763. *------------------------------------------*/
  8764. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8765. {
  8766. char mapname[MAP_NAME_LENGTH_EXT];
  8767. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8768. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8769. }
  8770. /*==========================================
  8771. * Info about Star Glaldiator hate mob [Komurka]
  8772. * type: 1: Register mob, 0: Information.
  8773. *------------------------------------------*/
  8774. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8775. {
  8776. if( pcdb_checkid(class_) ) {
  8777. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8778. } else if( mobdb_checkid(class_) ) {
  8779. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8780. } else {
  8781. 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);
  8782. }
  8783. }
  8784. /*==========================================
  8785. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8786. *------------------------------------------*/
  8787. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8788. {
  8789. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8790. }
  8791. /*==========================================
  8792. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8793. *------------------------------------------*/
  8794. void clif_feel_hate_reset(struct map_session_data *sd)
  8795. {
  8796. clif_starskill(sd, "", 0, 0, 30);
  8797. }
  8798. /// Send out reply to configuration change
  8799. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8800. /// type: see enum e_config_type
  8801. /// value:
  8802. /// false = disabled
  8803. /// true = enabled
  8804. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8805. int fd;
  8806. nullpo_retv(sd);
  8807. fd = sd->fd;
  8808. WFIFOHEAD(fd, packet_len(0x2d9));
  8809. WFIFOW(fd, 0) = 0x2d9;
  8810. WFIFOL(fd, 2) = type;
  8811. WFIFOL(fd, 6) = enabled;
  8812. WFIFOSET(fd, packet_len(0x2d9));
  8813. }
  8814. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8815. /// 02da <open equip window>.B
  8816. /// open equip window:
  8817. /// 0 = disabled
  8818. /// 1 = enabled
  8819. void clif_equipcheckbox(struct map_session_data* sd)
  8820. {
  8821. int fd;
  8822. nullpo_retv(sd);
  8823. fd = sd->fd;
  8824. WFIFOHEAD(fd, packet_len(0x2da));
  8825. WFIFOW(fd, 0) = 0x2da;
  8826. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8827. WFIFOSET(fd, packet_len(0x2da));
  8828. }
  8829. /// Sends info about a player's equipped items.
  8830. /// 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)
  8831. /// 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)
  8832. /// 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)
  8833. /// 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)
  8834. /// 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)
  8835. /// 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)
  8836. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8837. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8838. nullpo_retv( sd );
  8839. nullpo_retv( tsd );
  8840. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8841. int equip = 0;
  8842. for( int i = 0; i < EQI_MAX; i++ ){
  8843. int k = tsd->equip_index[i];
  8844. if( k >= 0 ){
  8845. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8846. continue;
  8847. }
  8848. if( !tsd->inventory.u.items_inventory[k].equip ){
  8849. continue;
  8850. }
  8851. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8852. continue;
  8853. }
  8854. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8855. }
  8856. }
  8857. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8858. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8859. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8860. p->job = tsd->status.class_;
  8861. p->head = tsd->vd.hair_style;
  8862. p->accessory = tsd->vd.head_bottom;
  8863. p->accessory2 = tsd->vd.head_mid;
  8864. p->accessory3 = tsd->vd.head_top;
  8865. #if PACKETVER >= 20110111
  8866. p->robe = tsd->vd.robe;
  8867. #endif
  8868. p->headpalette = tsd->vd.hair_color;
  8869. p->bodypalette = tsd->vd.cloth_color;
  8870. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8871. p->body2 = tsd->vd.body_style;
  8872. #endif
  8873. p->sex = tsd->vd.sex;
  8874. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8875. #endif
  8876. }
  8877. /// Display msgstringtable.txt string (ZC_MSG).
  8878. /// 0291 <message>.W
  8879. void clif_msg(struct map_session_data* sd, unsigned short id)
  8880. {
  8881. int fd;
  8882. nullpo_retv(sd);
  8883. fd = sd->fd;
  8884. WFIFOHEAD(fd, packet_len(0x291));
  8885. WFIFOW(fd, 0) = 0x291;
  8886. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8887. WFIFOSET(fd, packet_len(0x291));
  8888. }
  8889. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8890. /// 0x7e2 <message>.W <value>.L
  8891. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8892. {
  8893. int fd = sd->fd;
  8894. WFIFOHEAD(fd, packet_len(0x7e2));
  8895. WFIFOW(fd,0) = 0x7e2;
  8896. WFIFOW(fd,2) = id;
  8897. WFIFOL(fd,4) = value;
  8898. WFIFOSET(fd, packet_len(0x7e2));
  8899. }
  8900. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8901. /// 07e6 <skill id>.W <msg id>.L
  8902. ///
  8903. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8904. /// "[SkillName] Message"
  8905. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8906. {
  8907. int fd = sd->fd;
  8908. WFIFOHEAD(fd, packet_len(0x7e6));
  8909. WFIFOW(fd,0) = 0x7e6;
  8910. WFIFOW(fd,2) = skill_id;
  8911. WFIFOL(fd,4) = msg_id;
  8912. WFIFOSET(fd, packet_len(0x7e6));
  8913. }
  8914. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8915. /// 09cd <msg id>.W <color>.L
  8916. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8917. nullpo_retv(sd);
  8918. int fd = sd->fd;
  8919. WFIFOHEAD(fd, packet_len(0x9cd));
  8920. WFIFOW(fd, 0) = 0x9cd;
  8921. WFIFOW(fd, 2) = msg_id;
  8922. WFIFOL(fd, 4) = color;
  8923. WFIFOSET(fd, packet_len(0x9cd));
  8924. }
  8925. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8926. /// Returns true if the packet was parsed successfully.
  8927. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8928. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8929. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8930. const char* seperator = " : ";
  8931. int fd;
  8932. struct s_packet_db* info;
  8933. uint16 packetLength, inputLength;
  8934. const char *input, *name, *message;
  8935. size_t nameLength, messageLength;
  8936. fd = sd->fd;
  8937. info = &packet_db[RFIFOW(fd,0)];
  8938. packetLength = RFIFOW(fd,info->pos[0]);
  8939. input = RFIFOCP(fd,info->pos[1]);
  8940. // basic structure check for the 4-byte header
  8941. if( packetLength < 4 ){
  8942. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8943. return false;
  8944. }else{
  8945. inputLength = packetLength - 4;
  8946. }
  8947. // process <name> part of the packet
  8948. if( whisperFormat ) {
  8949. // name has fixed width
  8950. if( inputLength < NAME_LENGTH + 1 ) {
  8951. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8952. return false;
  8953. }
  8954. name = input;
  8955. // validate name
  8956. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8957. // only restriction is that the name must be zero-terminated
  8958. if( name[nameLength] != '\0' ) {
  8959. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8960. return false;
  8961. }
  8962. message = input + NAME_LENGTH;
  8963. messageLength = inputLength - NAME_LENGTH;
  8964. }else{
  8965. // name and message are separated by ' : '
  8966. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8967. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8968. // check if there's enough data provided
  8969. if( inputLength < nameLength + seperatorLength + 1 ){
  8970. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8971. return false;
  8972. }
  8973. name = input;
  8974. // validate name
  8975. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8976. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8977. {
  8978. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8979. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8980. set_eof(sd->fd); // Just kick them out to correct it.
  8981. return false;
  8982. }
  8983. message = input + nameLength + seperatorLength;
  8984. messageLength = inputLength - nameLength - seperatorLength;
  8985. }
  8986. #if PACKETVER < 20151001
  8987. // the declared length must match real length
  8988. if( messageLength != strnlen(message, messageLength)+1 ) {
  8989. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8990. return false;
  8991. }
  8992. // verify <message> part of the packet
  8993. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8994. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8995. return false;
  8996. }
  8997. #else
  8998. // No zero termination anymore
  8999. messageLength += 1;
  9000. #endif
  9001. // messages mustn't be too long
  9002. if( messageLength > CHAT_SIZE_MAX-1 ) {
  9003. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  9004. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  9005. // Neither the official client nor server place any restriction on the length of the data in the packet,
  9006. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  9007. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  9008. return false;
  9009. }
  9010. // If it is not a whisper message, set the name to the fakename of the player
  9011. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  9012. strcpy( out_name, sd->fakename );
  9013. }else{
  9014. safestrncpy( out_name, name, nameLength + 1 );
  9015. }
  9016. safestrncpy( out_message, message, messageLength );
  9017. if( whisperFormat ){
  9018. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  9019. out_full_message[nameLength] = '\0';
  9020. }else{
  9021. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  9022. }
  9023. if( is_atcommand( fd, sd, out_message, 1 ) )
  9024. return false;
  9025. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  9026. return false; //no "chatting" while muted.
  9027. if( battle_config.min_chat_delay ) { //[Skotlex]
  9028. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9029. return false;
  9030. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9031. }
  9032. if (battle_config.idletime_option&IDLE_CHAT)
  9033. sd->idletime = last_tick;
  9034. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  9035. sd->idletime_hom = last_tick;
  9036. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  9037. sd->idletime_mer = last_tick;
  9038. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  9039. return true;
  9040. }
  9041. /**
  9042. * Displays a message if the player enters a PK Zone (during pk_mode)
  9043. * @param sd: Player data
  9044. */
  9045. inline void clif_pk_mode_message(struct map_session_data * sd)
  9046. {
  9047. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  9048. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  9049. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  9050. char output[CHAT_SIZE_MAX];
  9051. // 1504: You've entered a PK Zone (safe until level %d).
  9052. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  9053. battle_config.pk_min_level);
  9054. clif_showscript(&sd->bl, output, SELF);
  9055. } else {
  9056. // 1503: You've entered a PK Zone.
  9057. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  9058. }
  9059. }
  9060. return;
  9061. }
  9062. // ---------------------
  9063. // clif_parse_wanttoconnect
  9064. // ---------------------
  9065. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  9066. // error codes:
  9067. // 0 - Success
  9068. // 1 - Unknown packet_ver
  9069. // 2 - Invalid account_id
  9070. // 3 - Invalid char_id
  9071. // 4 - Invalid login_id1 (reserved)
  9072. // 5 - Invalid client_tick (reserved)
  9073. // 6 - Invalid sex
  9074. // Only the first 'invalid' error that appears is used.
  9075. static int clif_parse_WantToConnection_sub(int fd)
  9076. {
  9077. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  9078. unsigned short cmd;
  9079. //By default, start searching on the default one.
  9080. cmd = RFIFOW(fd, 0);
  9081. packet_len = RFIFOREST(fd);
  9082. // FIXME: If the packet is not received at once, this will FAIL.
  9083. // Figure out, when it happens, that only part of the packet is
  9084. // received, or fix the function to be able to deal with that
  9085. // case.
  9086. if( packet_len != packet_db[cmd].len )
  9087. return 1; /* wrong length */
  9088. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  9089. return 2; /* invalid account_id */
  9090. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  9091. return 3; /* invalid char_id */
  9092. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  9093. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  9094. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  9095. return 6; /* invalid sex */
  9096. else
  9097. return 0;
  9098. }
  9099. /// Request to connect to map-server.
  9100. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  9101. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  9102. /// There are various variants of this packet, some of them have padding between fields.
  9103. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  9104. {
  9105. struct block_list* bl;
  9106. struct auth_node* node;
  9107. int cmd, account_id, char_id, login_id1, sex, err;
  9108. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  9109. if (sd) {
  9110. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9111. return;
  9112. }
  9113. cmd = RFIFOW(fd, 0);
  9114. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9115. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9116. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9117. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9118. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9119. err = clif_parse_WantToConnection_sub(fd);
  9120. if( err ){ // connection rejected
  9121. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9122. err == 1 ? "." :
  9123. err == 2 ? ", possibly for having an invalid account_id." :
  9124. err == 3 ? ", possibly for having an invalid char_id." :
  9125. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9126. err == 4 ? ", possibly for having an invalid login_id1." :
  9127. err == 5 ? ", possibly for having an invalid client_tick." :
  9128. */
  9129. err == 6 ? ", possibly for having an invalid sex." :
  9130. ". ERROR invalid error code"));
  9131. WFIFOHEAD(fd,packet_len(0x6a));
  9132. WFIFOW(fd,0) = 0x6a;
  9133. WFIFOB(fd,2) = err;
  9134. WFIFOSET(fd,packet_len(0x6a));
  9135. #ifdef DUMP_INVALID_PACKET
  9136. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9137. #endif
  9138. RFIFOSKIP(fd, RFIFOREST(fd));
  9139. set_eof(fd);
  9140. return;
  9141. }
  9142. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  9143. clif_authfail_fd(fd,1);// server closed
  9144. return;
  9145. }
  9146. //Check for double login.
  9147. bl = map_id2bl(account_id);
  9148. if(bl && bl->type != BL_PC) {
  9149. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9150. WFIFOHEAD(fd,packet_len(0x6a));
  9151. WFIFOW(fd,0) = 0x6a;
  9152. WFIFOB(fd,2) = 3; // Rejected by server
  9153. WFIFOSET(fd,packet_len(0x6a));
  9154. set_eof(fd);
  9155. return;
  9156. }
  9157. if (bl ||
  9158. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9159. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9160. {
  9161. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9162. return;
  9163. }
  9164. CREATE(sd, TBL_PC, 1);
  9165. sd->fd = fd;
  9166. #ifdef PACKET_OBFUSCATION
  9167. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9168. #endif
  9169. session[fd]->session_data = sd;
  9170. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9171. #if PACKETVER < 20070521
  9172. WFIFOHEAD(fd,4);
  9173. WFIFOL(fd,0) = sd->bl.id;
  9174. WFIFOSET(fd,4);
  9175. #else
  9176. WFIFOHEAD(fd,packet_len(0x283));
  9177. WFIFOW(fd,0) = 0x283;
  9178. WFIFOL(fd,2) = sd->bl.id;
  9179. WFIFOSET(fd,packet_len(0x283));
  9180. #endif
  9181. chrif_authreq(sd,false);
  9182. }
  9183. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9184. /// 007d
  9185. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  9186. {
  9187. bool guild_notice = false;
  9188. if(sd->bl.prev != NULL)
  9189. return;
  9190. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9191. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9192. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9193. sd->state.connect_new = 0;
  9194. return;
  9195. }
  9196. if (sd->state.rewarp) { //Rewarp player.
  9197. sd->state.rewarp = 0;
  9198. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9199. return;
  9200. }
  9201. sd->state.warping = 0;
  9202. // look
  9203. #if PACKETVER < 4
  9204. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9205. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9206. #else
  9207. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9208. #endif
  9209. pc_set_costume_view(sd);
  9210. if(sd->vd.cloth_color)
  9211. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9212. if(sd->vd.body_style)
  9213. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9214. // item
  9215. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9216. pc_checkitem(sd);
  9217. clif_equipswitch_list(sd);
  9218. // cart
  9219. if(pc_iscarton(sd)) {
  9220. clif_cartlist(sd);
  9221. clif_updatestatus(sd,SP_CARTINFO);
  9222. }
  9223. // weight
  9224. clif_updatestatus(sd,SP_WEIGHT);
  9225. clif_updatestatus(sd,SP_MAXWEIGHT);
  9226. // guild
  9227. // (needs to go before clif_spawn() to show guild emblems correctly)
  9228. if(sd->status.guild_id)
  9229. guild_send_memberinfoshort(sd,1);
  9230. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9231. if(battle_config.pc_invincible_time > 0) {
  9232. if(mapdata_flag_gvg(mapdata))
  9233. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9234. else
  9235. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9236. }
  9237. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9238. map_spawnmobs(sd->bl.m);
  9239. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9240. mapdata->users_pvp++;
  9241. }
  9242. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9243. // reset the callshop flag if the player changes map
  9244. sd->state.callshop = 0;
  9245. if(map_addblock(&sd->bl))
  9246. return;
  9247. clif_spawn(&sd->bl);
  9248. // Party
  9249. // (needs to go after clif_spawn() to show hp bars correctly)
  9250. if(sd->status.party_id) {
  9251. party_send_movemap(sd);
  9252. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  9253. }
  9254. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9255. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9256. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9257. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9258. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9259. sd->pvp_rank = 0;
  9260. sd->pvp_lastusers = 0;
  9261. sd->pvp_point = 5;
  9262. sd->pvp_won = 0;
  9263. sd->pvp_lost = 0;
  9264. }
  9265. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9266. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9267. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9268. else if (mapdata->flag[MF_GVG_DUNGEON])
  9269. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9270. else if( mapdata_flag_gvg(mapdata) )
  9271. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9272. else
  9273. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9274. // info about nearby objects
  9275. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9276. 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);
  9277. // pet
  9278. if( sd->pd ) {
  9279. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9280. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9281. pet_return_egg( sd, sd->pd );
  9282. } else {
  9283. if(map_addblock(&sd->pd->bl))
  9284. return;
  9285. clif_spawn(&sd->pd->bl);
  9286. clif_send_petdata(sd,sd->pd,0,0);
  9287. clif_send_petstatus(sd);
  9288. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9289. }
  9290. }
  9291. //homunculus [blackhole89]
  9292. if( hom_is_active(sd->hd) ) {
  9293. if(map_addblock(&sd->hd->bl))
  9294. return;
  9295. clif_spawn(&sd->hd->bl);
  9296. clif_send_homdata(sd,SP_ACK,0);
  9297. clif_hominfo(sd,sd->hd,1);
  9298. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9299. clif_homskillinfoblock(sd);
  9300. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9301. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9302. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9303. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9304. }
  9305. if( sd->md ) {
  9306. if(map_addblock(&sd->md->bl))
  9307. return;
  9308. clif_spawn(&sd->md->bl);
  9309. clif_mercenary_info(sd);
  9310. clif_mercenary_skillblock(sd);
  9311. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9312. }
  9313. if( sd->ed ) {
  9314. if (map_addblock(&sd->ed->bl))
  9315. return;
  9316. clif_spawn(&sd->ed->bl);
  9317. clif_elemental_info(sd);
  9318. clif_elemental_updatestatus(sd,SP_HP);
  9319. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9320. clif_elemental_updatestatus(sd,SP_SP);
  9321. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9322. }
  9323. if(sd->state.connect_new) {
  9324. int lv;
  9325. guild_notice = true;
  9326. clif_skillinfoblock(sd);
  9327. clif_hotkeys_send(sd,0);
  9328. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9329. clif_hotkeys_send(sd,1);
  9330. #endif
  9331. clif_updatestatus(sd,SP_BASEEXP);
  9332. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9333. clif_updatestatus(sd,SP_JOBEXP);
  9334. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9335. clif_updatestatus(sd,SP_SKILLPOINT);
  9336. clif_initialstatus(sd);
  9337. if (sd->sc.option&OPTION_FALCON)
  9338. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9339. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9340. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9341. else if (sd->sc.option&OPTION_WUGRIDER)
  9342. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9343. else if (sd->sc.data[SC_ALL_RIDING])
  9344. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9345. if(sd->status.manner < 0)
  9346. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9347. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9348. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9349. if(sd->bl.m == sd->feel_map[0].m
  9350. || sd->bl.m == sd->feel_map[1].m
  9351. || sd->bl.m == sd->feel_map[2].m)
  9352. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9353. }
  9354. if(sd->pd && sd->pd->pet.intimate > 900)
  9355. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9356. if(hom_is_active(sd->hd))
  9357. hom_init_timers(sd->hd);
  9358. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9359. sd->state.night = 1;
  9360. clif_status_load(&sd->bl, EFST_SKE, 1);
  9361. }
  9362. // Notify everyone that this char logged in [Skotlex].
  9363. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9364. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9365. //Login Event
  9366. npc_script_event(sd, NPCE_LOGIN);
  9367. }
  9368. // Set facing direction before check below to update client
  9369. if (battle_config.spawn_direction)
  9370. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9371. } else {
  9372. //For some reason the client "loses" these on warp/map-change.
  9373. clif_updatestatus(sd,SP_STR);
  9374. clif_updatestatus(sd,SP_AGI);
  9375. clif_updatestatus(sd,SP_VIT);
  9376. clif_updatestatus(sd,SP_INT);
  9377. clif_updatestatus(sd,SP_DEX);
  9378. clif_updatestatus(sd,SP_LUK);
  9379. #ifdef RENEWAL
  9380. clif_updatestatus(sd,SP_POW);
  9381. clif_updatestatus(sd,SP_STA);
  9382. clif_updatestatus(sd,SP_WIS);
  9383. clif_updatestatus(sd,SP_SPL);
  9384. clif_updatestatus(sd,SP_CON);
  9385. clif_updatestatus(sd,SP_CRT);
  9386. #endif
  9387. // abort currently running script
  9388. sd->state.using_fake_npc = 0;
  9389. sd->state.menu_or_input = 0;
  9390. sd->npc_menu = 0;
  9391. if(sd->npc_id)
  9392. npc_event_dequeue(sd);
  9393. }
  9394. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9395. #if PACKETVER >= 20070918
  9396. clif_partyinvitationstate(sd);
  9397. clif_equipcheckbox(sd);
  9398. #endif
  9399. clif_pet_autofeed_status(sd,false);
  9400. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9401. #if PACKETVER >= 20170920
  9402. if( battle_config.homunculus_autofeed_always ){
  9403. // Always send ON or OFF
  9404. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9405. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9406. }else{
  9407. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9408. }
  9409. }else{
  9410. // Only send when enabled
  9411. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9412. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9413. }
  9414. }
  9415. #endif
  9416. clif_reputation_list( *sd );
  9417. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9418. clif_guild_notice(sd); // Displays after VIP
  9419. guild_notice = false; // Do not display it twice
  9420. }
  9421. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9422. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9423. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9424. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9425. }
  9426. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9427. { //Display night.
  9428. if( !sd->state.night )
  9429. {
  9430. sd->state.night = 1;
  9431. clif_status_load(&sd->bl, EFST_SKE, 1);
  9432. }
  9433. }
  9434. else if( sd->state.night )
  9435. { //Clear night display.
  9436. sd->state.night = 0;
  9437. clif_status_load(&sd->bl, EFST_SKE, 0);
  9438. }
  9439. if( mapdata->flag[MF_BATTLEGROUND] )
  9440. {
  9441. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9442. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9443. clif_bg_updatescore_single(sd);
  9444. }
  9445. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9446. {
  9447. char output[128];
  9448. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9449. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9450. }
  9451. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9452. mapdata->hpmeter_visible++;
  9453. sd->state.hpmeter_visible = 1;
  9454. }
  9455. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9456. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9457. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9458. #ifdef VIP_ENABLE
  9459. if (!sd->state.connect_new &&
  9460. !sd->vip.disableshowrate &&
  9461. sd->state.pmap != sd->bl.m &&
  9462. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9463. )
  9464. {
  9465. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9466. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9467. }
  9468. #endif
  9469. // Instances do not need their own channels
  9470. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9471. channel_mjoin(sd); //join new map
  9472. clif_pk_mode_message(sd);
  9473. }
  9474. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9475. clif_guild_notice(sd); // Displays at end
  9476. }
  9477. mail_clear(sd);
  9478. /* Guild Aura Init */
  9479. if( sd->guild && sd->state.gmaster_flag ) {
  9480. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9481. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9482. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9483. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9484. }
  9485. if( sd->state.vending ) { /* show we have a vending */
  9486. clif_openvending(sd,sd->bl.id,sd->vending);
  9487. clif_showvendingboard(&sd->bl,sd->message,0);
  9488. }
  9489. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9490. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9491. npc_script_event(sd, NPCE_LOADMAP);
  9492. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9493. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9494. if (sd->sc.opt2) //Client loses these on warp.
  9495. clif_changeoption(&sd->bl);
  9496. 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)) {
  9497. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9498. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9499. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9500. }
  9501. clif_weather_check(sd);
  9502. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9503. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9504. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9505. else
  9506. sd->areanpc.clear();
  9507. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9508. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9509. pc_setdead(sd);
  9510. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9511. if(pc_isdead(sd))
  9512. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9513. else {
  9514. skill_usave_trigger(sd);
  9515. if (battle_config.spawn_direction)
  9516. clif_changed_dir(&sd->bl, SELF);
  9517. }
  9518. // Trigger skill effects if you appear standing on them
  9519. if(!battle_config.pc_invincible_time)
  9520. skill_unit_move(&sd->bl,gettick(),1);
  9521. pc_show_questinfo_reinit(sd);
  9522. pc_show_questinfo(sd);
  9523. #if PACKETVER >= 20150513
  9524. if( sd->mail.inbox.unread ){
  9525. clif_Mail_new(sd, 0, NULL, NULL);
  9526. }
  9527. #endif
  9528. sd->state.connect_new = 0;
  9529. sd->state.changemap = false;
  9530. }
  9531. /// Server's tick (ZC_NOTIFY_TIME).
  9532. /// 007f <time>.L
  9533. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9534. {
  9535. int fd = sd->fd;
  9536. WFIFOHEAD(fd,packet_len(0x7f));
  9537. WFIFOW(fd,0) = 0x7f;
  9538. WFIFOL(fd,2) = client_tick(time);
  9539. WFIFOSET(fd,packet_len(0x7f));
  9540. }
  9541. /// Request for server's tick.
  9542. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9543. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9544. /// There are various variants of this packet, some of them have padding between fields.
  9545. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9546. {
  9547. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9548. clif_notify_time(sd, gettick());
  9549. }
  9550. /// Sends hotkey bar.
  9551. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9552. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9553. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9554. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9555. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9556. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9557. nullpo_retv( sd );
  9558. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9559. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9560. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9561. if( tab == 0 ){
  9562. p.rotate = sd->status.hotkey_rowshift;
  9563. }else{
  9564. p.rotate = sd->status.hotkey_rowshift2;
  9565. }
  9566. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9567. p.tab = tab;
  9568. #endif
  9569. #endif
  9570. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9571. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9572. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9573. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9574. }
  9575. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9576. #endif
  9577. }
  9578. /// Request to update a position on the hotkey row bar
  9579. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9580. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9581. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9582. if( p->tab == 0 ){
  9583. sd->status.hotkey_rowshift = p->rowshift;
  9584. }else{
  9585. sd->status.hotkey_rowshift2 = p->rowshift;
  9586. }
  9587. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9588. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9589. sd->status.hotkey_rowshift = p->rowshift;
  9590. #endif
  9591. }
  9592. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9593. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9594. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9595. #ifdef HOTKEY_SAVING
  9596. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9597. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9598. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9599. if( idx >= MAX_HOTKEYS_DB ){
  9600. return;
  9601. }
  9602. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9603. sd->status.hotkeys[idx].id = p->hotkey.id;
  9604. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9605. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9606. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9607. const unsigned short idx = p->index;
  9608. if( idx >= MAX_HOTKEYS_DB ){
  9609. return;
  9610. }
  9611. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9612. sd->status.hotkeys[idx].id = p->hotkey.id;
  9613. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9614. #endif
  9615. #endif
  9616. }
  9617. /// Displays cast-like progress bar (ZC_PROGRESS).
  9618. /// 02f0 <color>.L <time>.L
  9619. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9620. {
  9621. int fd = sd->fd;
  9622. WFIFOHEAD(fd,packet_len(0x2f0));
  9623. WFIFOW(fd,0) = 0x2f0;
  9624. WFIFOL(fd,2) = color;
  9625. WFIFOL(fd,6) = second;
  9626. WFIFOSET(fd,packet_len(0x2f0));
  9627. }
  9628. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9629. /// 02f2
  9630. void clif_progressbar_abort(struct map_session_data * sd)
  9631. {
  9632. int fd = sd->fd;
  9633. WFIFOHEAD(fd,packet_len(0x2f2));
  9634. WFIFOW(fd,0) = 0x2f2;
  9635. WFIFOSET(fd,packet_len(0x2f2));
  9636. }
  9637. /// Notification from the client, that the progress bar has reached 100%.
  9638. /// 02f1 (CZ_PROGRESS)
  9639. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9640. // No progressbar active, ignore it
  9641. if( !sd->progressbar.npc_id ){
  9642. return;
  9643. }
  9644. int npc_id = sd->progressbar.npc_id;
  9645. bool closing = false;
  9646. // Check if the progress was canceled
  9647. if( gettick() < sd->progressbar.timeout && sd->st ){
  9648. closing = true;
  9649. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9650. // If a message window was open, offer a close button to the user
  9651. if( sd->st->mes_active ){
  9652. clif_scriptclose( sd, npc_id );
  9653. }
  9654. }
  9655. sd->progressbar.npc_id = 0;
  9656. sd->progressbar.timeout = 0;
  9657. sd->state.workinprogress = WIP_DISABLE_NONE;
  9658. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9659. sd->idletime = last_tick;
  9660. }
  9661. npc_scriptcont(sd, npc_id, closing);
  9662. }
  9663. /// Displays cast-like progress bar on a NPC
  9664. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9665. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9666. #if PACKETVER >= 20130821
  9667. unsigned char buf[14];
  9668. if( nd->progressbar.timeout > 0 ){
  9669. WBUFW(buf,0) = 0x9d1;
  9670. WBUFL(buf,2) = nd->bl.id;
  9671. WBUFL(buf,6) = nd->progressbar.color;
  9672. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9673. if( sd ){
  9674. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9675. }else{
  9676. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9677. }
  9678. }
  9679. #endif
  9680. }
  9681. /// Request to walk to a certain position on the current map.
  9682. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9683. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9684. /// There are various variants of this packet, some of them have padding between fields.
  9685. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9686. {
  9687. short x, y;
  9688. if (pc_isdead(sd)) {
  9689. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9690. return;
  9691. }
  9692. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9693. ; //You CAN walk on this OPT1 value.
  9694. else if (sd->progressbar.npc_id) {
  9695. clif_progressbar_abort(sd);
  9696. return; // First walk attempt cancels the progress bar
  9697. } else if (pc_cant_act(sd))
  9698. return;
  9699. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9700. return;
  9701. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9702. //A move command one cell west is only valid if the target cell is free
  9703. if(battle_config.official_cell_stack_limit > 0
  9704. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9705. return;
  9706. // Cloaking wall check is actually updated when you click to process next movement
  9707. // not when you move each cell. This is official behaviour.
  9708. if (sd->sc.data[SC_CLOAKING])
  9709. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9710. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9711. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9712. pc_delinvincibletimer(sd);
  9713. //Set last idle time... [Skotlex]
  9714. if (battle_config.idletime_option&IDLE_WALK)
  9715. sd->idletime = last_tick;
  9716. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9717. sd->idletime_hom = last_tick;
  9718. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9719. sd->idletime_mer = last_tick;
  9720. unit_walktoxy(&sd->bl, x, y, 4);
  9721. }
  9722. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9723. /// 018b <result>.W
  9724. /// result:
  9725. /// 0 = disconnect (quit)
  9726. /// 1 = cannot disconnect (wait 10 seconds)
  9727. /// ? = ignored
  9728. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9729. {
  9730. int fd = sd->fd;
  9731. WFIFOHEAD(fd,packet_len(0x18b));
  9732. WFIFOW(fd,0) = 0x18b;
  9733. WFIFOW(fd,2) = result;
  9734. WFIFOSET(fd,packet_len(0x18b));
  9735. }
  9736. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9737. /// 018a <type>.W
  9738. /// type:
  9739. /// 0 = quit
  9740. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9741. {
  9742. /* Rovert's prevent logout option fixed [Valaris] */
  9743. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9744. 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] &&
  9745. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9746. {
  9747. pc_damage_log_clear(sd,0);
  9748. clif_disconnect_ack(sd, 0);
  9749. flush_fifo( fd );
  9750. if( battle_config.drop_connection_on_quit ){
  9751. set_eof( fd );
  9752. }
  9753. } else {
  9754. clif_disconnect_ack(sd, 1);
  9755. }
  9756. }
  9757. /// Requesting unit's name.
  9758. /// 0094 <id>.L (CZ_REQNAME)
  9759. /// 0368 <id>.L (CZ_REQNAME2)
  9760. /// There are various variants of this packet, some of them have padding between fields.
  9761. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9762. {
  9763. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9764. struct block_list* bl;
  9765. //struct status_change *sc;
  9766. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9767. id = sd->bl.id;
  9768. bl = map_id2bl(id);
  9769. if( bl == NULL )
  9770. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9771. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9772. return; // Block namerequests past view range
  9773. // 'see people in GM hide' cheat detection
  9774. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9775. sc = status_get_sc(bl);
  9776. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9777. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9778. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9779. ) {
  9780. char gm_msg[256];
  9781. 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);
  9782. ShowWarning(gm_msg);
  9783. // information is sent to all online GMs
  9784. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9785. return;
  9786. }
  9787. */
  9788. clif_name(&sd->bl,bl,SELF);
  9789. }
  9790. /// Validates and processes global messages
  9791. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9792. /// There are various variants of this packet.
  9793. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9794. {
  9795. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9796. size_t length;
  9797. // validate packet and retrieve name and message
  9798. if( !clif_process_message(sd, false, name, message, output ) )
  9799. return;
  9800. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9801. channel_send(sd->gcbind,sd,message);
  9802. return;
  9803. }
  9804. // send message to others (using the send buffer for temp. storage)
  9805. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9806. length = strlen(output) + 1;
  9807. // send back message to the speaker
  9808. WFIFOHEAD(fd,4+length);
  9809. WFIFOW(fd,0) = 0x8e;
  9810. WFIFOW(fd,2) = (uint16)(4+length);
  9811. safestrncpy(WFIFOCP(fd,4), output, length );
  9812. WFIFOSET(fd, WFIFOW(fd,2));
  9813. #ifdef PCRE_SUPPORT
  9814. // trigger listening npcs
  9815. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9816. #endif
  9817. // Chat logging type 'O' / Global Chat
  9818. 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);
  9819. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9820. }
  9821. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9822. /// Request to warp to a map on given coordinates.
  9823. /// 0140 <map name>.16B <x>.W <y>.W
  9824. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9825. {
  9826. char command[MAP_NAME_LENGTH_EXT+25];
  9827. char* map_name;
  9828. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9829. map_name = RFIFOCP(fd,info->pos[0]);
  9830. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9831. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9832. RFIFOW(fd,info->pos[1]), //x
  9833. RFIFOW(fd,info->pos[2])); //y
  9834. is_atcommand(fd, sd, command, 1);
  9835. }
  9836. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9837. /// 009c <id>.L <head dir>.W <dir>.B
  9838. /// head dir:
  9839. /// 0 = straight
  9840. /// 1 = turned CW
  9841. /// 2 = turned CCW
  9842. /// dir:
  9843. /// 0 = north
  9844. /// 1 = northwest
  9845. /// 2 = west
  9846. /// 3 = southwest
  9847. /// 4 = south
  9848. /// 5 = southeast
  9849. /// 6 = east
  9850. /// 7 = northeast
  9851. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9852. {
  9853. unsigned char buf[64];
  9854. WBUFW(buf,0) = 0x9c;
  9855. WBUFL(buf,2) = bl->id;
  9856. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9857. WBUFB(buf,8) = unit_getdir(bl);
  9858. clif_send(buf, packet_len(0x9c), bl, target);
  9859. if (disguised(bl)) {
  9860. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9861. WBUFW(buf,6) = 0;
  9862. clif_send(buf, packet_len(0x9c), bl, SELF);
  9863. }
  9864. }
  9865. /// Request to change own body and head direction.
  9866. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9867. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9868. /// There are various variants of this packet, some of them have padding between fields.
  9869. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9870. {
  9871. unsigned char headdir, dir;
  9872. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9873. headdir = RFIFOB(fd,info->pos[0]);
  9874. dir = RFIFOB(fd,info->pos[1]);
  9875. pc_setdir(sd, dir, headdir);
  9876. clif_changed_dir(&sd->bl, AREA_WOS);
  9877. }
  9878. /// Request to show an emotion (CZ_REQ_EMOTION).
  9879. /// 00bf <type>.B
  9880. /// type:
  9881. /// @see enum emotion_type
  9882. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9883. {
  9884. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9885. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9886. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9887. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9888. return;
  9889. }
  9890. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9891. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9892. sd->emotionlasttime = time(NULL);
  9893. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9894. return;
  9895. }
  9896. sd->emotionlasttime = time(NULL);
  9897. if (battle_config.idletime_option&IDLE_EMOTION)
  9898. sd->idletime = last_tick;
  9899. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9900. sd->idletime_hom = last_tick;
  9901. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9902. sd->idletime_mer = last_tick;
  9903. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9904. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9905. return;
  9906. }
  9907. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9908. emoticon = rnd()%6+ET_DICE1;
  9909. }
  9910. clif_emotion(&sd->bl, emoticon);
  9911. } else
  9912. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9913. }
  9914. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9915. /// 00c2 <count>.L
  9916. void clif_user_count(struct map_session_data* sd, int count)
  9917. {
  9918. int fd = sd->fd;
  9919. WFIFOHEAD(fd,packet_len(0xc2));
  9920. WFIFOW(fd,0) = 0xc2;
  9921. WFIFOL(fd,2) = count;
  9922. WFIFOSET(fd,packet_len(0xc2));
  9923. }
  9924. /// /w /who (CZ_REQ_USER_COUNT).
  9925. /// Request to display amount of currently connected players.
  9926. /// 00c1
  9927. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9928. {
  9929. clif_user_count(sd, map_getusers());
  9930. }
  9931. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9932. {
  9933. if (pc_isdead(sd)) {
  9934. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9935. return;
  9936. }
  9937. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9938. if (action_type != 0x00 && action_type != 0x07) {
  9939. if (sd->sc.cant.interact)
  9940. return;
  9941. pc_stop_walking(sd, 1);
  9942. }
  9943. pc_stop_attack(sd);
  9944. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9945. target_id = sd->bl.id;
  9946. switch(action_type)
  9947. {
  9948. case 0x00: // once attack
  9949. case 0x07: // continuous attack
  9950. if( pc_cant_act(sd) )
  9951. return;
  9952. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9953. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9954. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9955. return;
  9956. }
  9957. }
  9958. pc_delinvincibletimer(sd);
  9959. if (battle_config.idletime_option&IDLE_ATTACK)
  9960. sd->idletime = last_tick;
  9961. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9962. sd->idletime_hom = last_tick;
  9963. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9964. sd->idletime_mer = last_tick;
  9965. unit_attack(&sd->bl, target_id, action_type != 0);
  9966. break;
  9967. case 0x02: // sitdown
  9968. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9969. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9970. break;
  9971. }
  9972. if(pc_issit(sd)) {
  9973. //Bugged client? Just refresh them.
  9974. clif_sitting(&sd->bl);
  9975. return;
  9976. }
  9977. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9978. break;
  9979. if (sd->sc.count && (
  9980. sd->sc.data[SC_DANCING] ||
  9981. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9982. )) //No sitting during these states either.
  9983. break;
  9984. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9985. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9986. break;
  9987. }
  9988. if (battle_config.idletime_option&IDLE_SIT)
  9989. sd->idletime = last_tick;
  9990. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9991. sd->idletime_hom = last_tick;
  9992. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9993. sd->idletime_mer = last_tick;
  9994. pc_setsit(sd);
  9995. skill_sit(sd, true);
  9996. clif_sitting(&sd->bl);
  9997. break;
  9998. case 0x03: // standup
  9999. if (!pc_issit(sd)) {
  10000. //Bugged client? Just refresh them.
  10001. clif_standing(&sd->bl);
  10002. return;
  10003. }
  10004. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  10005. break;
  10006. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  10007. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  10008. break;
  10009. }
  10010. if (pc_setstand(sd, false)) {
  10011. if (battle_config.idletime_option&IDLE_SIT)
  10012. sd->idletime = last_tick;
  10013. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  10014. sd->idletime_hom = last_tick;
  10015. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  10016. sd->idletime_mer = last_tick;
  10017. skill_sit(sd, false);
  10018. clif_standing(&sd->bl);
  10019. }
  10020. break;
  10021. }
  10022. }
  10023. /// Request for an action.
  10024. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  10025. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  10026. /// action:
  10027. /// 0 = attack
  10028. /// 1 = pick up item
  10029. /// 2 = sit down
  10030. /// 3 = stand up
  10031. /// 7 = continous attack
  10032. /// 12 = (touch skill?)
  10033. /// There are various variants of this packet, some of them have padding between fields.
  10034. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  10035. {
  10036. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10037. clif_parse_ActionRequest_sub(sd,
  10038. RFIFOB(fd,info->pos[1]),
  10039. RFIFOL(fd,info->pos[0]),
  10040. gettick()
  10041. );
  10042. }
  10043. /// Response to the death/system menu (CZ_RESTART).
  10044. /// 00b2 <type>.B
  10045. /// type:
  10046. /// 0 = restart (respawn)
  10047. /// 1 = char-select (disconnect)
  10048. void clif_parse_Restart(int fd, struct map_session_data *sd)
  10049. {
  10050. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  10051. case 0x00:
  10052. pc_respawn(sd,CLR_OUTSIGHT);
  10053. break;
  10054. case 0x01:
  10055. /* Rovert's Prevent logout option - Fixed [Valaris] */
  10056. 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] &&
  10057. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  10058. { //Send to char-server for character selection.
  10059. pc_damage_log_clear(sd,0);
  10060. chrif_charselectreq(sd, session[fd]->client_addr);
  10061. } else {
  10062. clif_disconnect_ack(sd, 1);
  10063. }
  10064. break;
  10065. }
  10066. }
  10067. /// Validates and processes whispered messages (CZ_WHISPER).
  10068. /// 0096 <packet len>.W <nick>.24B <message>.?B
  10069. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  10070. {
  10071. struct map_session_data* dstsd;
  10072. int i;
  10073. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10074. // validate packet and retrieve name and message
  10075. if( !clif_process_message( sd, true, target, message, output ) )
  10076. return;
  10077. // Chat logging type 'W' / Whisper
  10078. 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);
  10079. //-------------------------------------------------------//
  10080. // Lordalfa - Paperboy - To whisper NPC commands //
  10081. //-------------------------------------------------------//
  10082. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  10083. {
  10084. char* str = target+4; //Skip the NPC: string part.
  10085. struct npc_data* npc;
  10086. if ((npc = npc_name2id(str))) {
  10087. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  10088. char *split;
  10089. char event[EVENT_NAME_LENGTH];
  10090. str = message;
  10091. // skip codepage indicator, if detected
  10092. if( str[0] == '|' && strlen(str) >= 4 )
  10093. str += 3;
  10094. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  10095. split = strchr(str,'#');
  10096. if( split == NULL ) { // use the remaining string
  10097. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10098. for( ++i; i < NUM_WHISPER_VAR; ++i )
  10099. split_data[i][0] = '\0';
  10100. break;
  10101. }
  10102. *split = '\0';
  10103. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10104. str = split+1;
  10105. }
  10106. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  10107. char variablename[CHAT_SIZE_MAX];
  10108. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  10109. set_var_str( sd, variablename, split_data[i] );
  10110. }
  10111. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  10112. npc_event(sd,event,0); // Calls the NPC label
  10113. return;
  10114. }
  10115. } else if( target[0] == '#' ) {
  10116. struct Channel *channel = NULL;
  10117. char* chname = target;
  10118. channel = channel_name2channel(chname,sd,3);
  10119. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  10120. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  10121. channel_send(channel,sd,message);
  10122. }
  10123. else if( channel->pass[0] == '\0') { //no pass needed
  10124. if (channel_join(channel,sd)==0)
  10125. channel_send(channel,sd,message); //join success
  10126. }
  10127. else {
  10128. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  10129. }
  10130. return;
  10131. }
  10132. }
  10133. // searching destination character
  10134. dstsd = map_nick2sd(target,false);
  10135. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  10136. // player is not on this map-server
  10137. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  10138. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  10139. // and if we ask for 'Test', we must not contact 'test' player
  10140. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  10141. intif_wis_message(sd, target, message, strlen(message) + 1);
  10142. return;
  10143. }
  10144. // if player ignores everyone
  10145. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10146. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  10147. clif_wis_end(fd, 1); // 1: target character is not logged in
  10148. else
  10149. clif_wis_end(fd, 3); // 3: everyone ignored by target
  10150. return;
  10151. }
  10152. // if player is autotrading
  10153. if (dstsd->state.autotrade == 1){
  10154. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  10155. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  10156. return;
  10157. }
  10158. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10159. // if player ignores the source character
  10160. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  10161. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  10162. clif_wis_end(fd, 2); // 2: ignored by target
  10163. return;
  10164. }
  10165. }
  10166. // notify sender of success
  10167. clif_wis_end(fd, 0); // 0: success to send wisper
  10168. // Normal message
  10169. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10170. }
  10171. /// /b /nb (CZ_BROADCAST).
  10172. /// Request to broadcast a message on whole server.
  10173. /// 0099 <packet len>.W <text>.?B 00
  10174. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  10175. char command[CHAT_SIZE_MAX+11];
  10176. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10177. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10178. char* msg = RFIFOCP(fd,info->pos[1]);
  10179. // as the length varies depending on the command used, just block unreasonably long strings
  10180. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10181. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10182. is_atcommand(fd, sd, command, 1);
  10183. }
  10184. /// Request to pick up an item.
  10185. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10186. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10187. /// There are various variants of this packet, some of them have padding between fields.
  10188. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  10189. {
  10190. struct flooritem_data *fitem;
  10191. int map_object_id;
  10192. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10193. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10194. do {
  10195. if (pc_isdead(sd)) {
  10196. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10197. break;
  10198. }
  10199. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10200. break;
  10201. if (pc_cant_act(sd))
  10202. break;
  10203. if (!pc_takeitem(sd, fitem))
  10204. break;
  10205. return;
  10206. } while (0);
  10207. // Client REQUIRES a fail packet or you can no longer pick items.
  10208. clif_additem(sd,0,0,6);
  10209. }
  10210. /// Request to drop an item.
  10211. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10212. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10213. /// There are various variants of this packet, some of them have padding between fields.
  10214. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  10215. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10216. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10217. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10218. for(;;) {
  10219. if (pc_isdead(sd))
  10220. break;
  10221. if (pc_cant_act2(sd) || sd->npc_id)
  10222. break;
  10223. if (sd->sc.cant.drop)
  10224. break;
  10225. if (!pc_dropitem(sd, item_index, item_amount))
  10226. break;
  10227. if (battle_config.idletime_option&IDLE_DROPITEM)
  10228. sd->idletime = last_tick;
  10229. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10230. sd->idletime_hom = last_tick;
  10231. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10232. sd->idletime_mer = last_tick;
  10233. return;
  10234. }
  10235. //Because the client does not like being ignored.
  10236. clif_dropitem(sd, item_index,0);
  10237. }
  10238. /// Request to use an item.
  10239. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10240. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10241. /// There are various variants of this packet, some of them have padding between fields.
  10242. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  10243. {
  10244. int n;
  10245. if (pc_isdead(sd)) {
  10246. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10247. return;
  10248. }
  10249. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10250. clif_msg(sd, WORK_IN_PROGRESS);
  10251. return;
  10252. }
  10253. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10254. if (battle_config.idletime_option&IDLE_USEITEM)
  10255. sd->idletime = last_tick;
  10256. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10257. sd->idletime_hom = last_tick;
  10258. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10259. sd->idletime_mer = last_tick;
  10260. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10261. if(n <0 || n >= MAX_INVENTORY)
  10262. return;
  10263. if (!pc_useitem(sd,n))
  10264. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10265. }
  10266. /// Request to equip an item
  10267. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10268. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10269. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10270. {
  10271. int index;
  10272. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10273. if(pc_isdead(sd)) {
  10274. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10275. return;
  10276. }
  10277. index = RFIFOW(fd,info->pos[0])-2;
  10278. if (index < 0 || index >= MAX_INVENTORY)
  10279. return; //Out of bounds check.
  10280. if(sd->npc_id && !sd->npc_item_flag) {
  10281. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10282. return;
  10283. } else if (sd->state.storage_flag || sd->sc.opt1)
  10284. ; //You can equip/unequip stuff while storage is open/under status changes
  10285. else if (pc_cant_act2(sd))
  10286. return;
  10287. if(!sd->inventory.u.items_inventory[index].identify) {
  10288. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  10289. return;
  10290. }
  10291. if(!sd->inventory_data[index])
  10292. return;
  10293. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10294. pet_equipitem(sd,index);
  10295. return;
  10296. }
  10297. if (battle_config.idletime_option&IDLE_USEITEM)
  10298. sd->idletime = last_tick;
  10299. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10300. sd->idletime_hom = last_tick;
  10301. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10302. sd->idletime_mer = last_tick;
  10303. //Client doesn't send the position for ammo.
  10304. if(sd->inventory_data[index]->type == IT_AMMO)
  10305. pc_equipitem(sd,index,EQP_AMMO);
  10306. else {
  10307. int req_pos;
  10308. #if PACKETVER >= 20120925
  10309. req_pos = RFIFOL(fd,info->pos[1]);
  10310. #else
  10311. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10312. #endif
  10313. pc_equipitem(sd,index,req_pos);
  10314. }
  10315. }
  10316. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10317. /// 00ab <index>.W
  10318. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10319. {
  10320. int index;
  10321. if(pc_isdead(sd)) {
  10322. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10323. return;
  10324. }
  10325. if (sd->npc_id && !sd->npc_item_flag) {
  10326. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10327. return;
  10328. } else if (sd->state.storage_flag || sd->sc.opt1)
  10329. ; //You can equip/unequip stuff while storage is open/under status changes
  10330. else if (pc_cant_act2(sd))
  10331. return;
  10332. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10333. if (battle_config.idletime_option&IDLE_USEITEM)
  10334. sd->idletime = last_tick;
  10335. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10336. sd->idletime_hom = last_tick;
  10337. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10338. sd->idletime_mer = last_tick;
  10339. pc_unequipitem(sd,index,1);
  10340. }
  10341. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10342. /// 0090 <id>.L <type>.B
  10343. /// type:
  10344. /// 1 = click
  10345. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10346. {
  10347. struct block_list *bl;
  10348. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10349. if(pc_isdead(sd)) {
  10350. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10351. return;
  10352. }
  10353. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10354. #ifdef RENEWAL
  10355. clif_msg( sd, WORK_IN_PROGRESS );
  10356. #endif
  10357. return;
  10358. }
  10359. if( sd->state.mail_writing )
  10360. return;
  10361. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10362. //type = RFIFOB(fd,info->pos[1]);
  10363. if (!bl) return;
  10364. switch (bl->type) {
  10365. case BL_MOB:
  10366. case BL_PC:
  10367. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10368. break;
  10369. case BL_NPC:
  10370. #ifdef RENEWAL
  10371. 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
  10372. clif_msg(sd, WORK_IN_PROGRESS);
  10373. break;
  10374. }
  10375. #endif
  10376. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10377. struct npc_data* nd = (struct npc_data*)bl;
  10378. // Progressbar is running
  10379. if( nd->progressbar.timeout > 0 ){
  10380. return;
  10381. }
  10382. npc_click(sd,nd);
  10383. }
  10384. break;
  10385. }
  10386. }
  10387. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10388. /// 00c5 <id>.L <type>.B
  10389. /// type:
  10390. /// 0 = buy
  10391. /// 1 = sell
  10392. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10393. {
  10394. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10395. if (sd->state.trading)
  10396. return;
  10397. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10398. }
  10399. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10400. /// 00ca <result>.B
  10401. /// result:
  10402. /// 0 = "The deal has successfully completed."
  10403. /// 1 = "You do not have enough zeny."
  10404. /// 2 = "You are over your Weight Limit."
  10405. /// 3 = "Out of the maximum capacity, you have too many items."
  10406. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10407. /// 10 = "Props open-air store sales will be traded in RODEX"
  10408. /// 11 = "The exchange failed."
  10409. /// 12 = "The exchange was well done."
  10410. /// 13 = "The item is already sold and out of stock."
  10411. /// 14 = "There is not enough goods to exchange."
  10412. void clif_npc_buy_result( struct map_session_data* sd, e_purchase_result result ){
  10413. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10414. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10415. p.result = (uint8)result;
  10416. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10417. }
  10418. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10419. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10420. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10421. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10422. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10423. e_purchase_result result;
  10424. if( sd->state.trading || !sd->npc_shopid )
  10425. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10426. else{
  10427. std::vector<s_npc_buy_list> items = {};
  10428. items.reserve( n );
  10429. for( uint16 i = 0; i < n; i++ ){
  10430. s_npc_buy_list item = {};
  10431. item.nameid = p->items[i].itemId;
  10432. item.qty = p->items[i].amount;
  10433. items.push_back( item );
  10434. }
  10435. result = npc_buylist( sd, items );
  10436. }
  10437. sd->npc_shopid = 0; //Clear shop data.
  10438. clif_npc_buy_result(sd, result);
  10439. }
  10440. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10441. /// 00cb <result>.B
  10442. /// result:
  10443. /// 0 = "The deal has successfully completed."
  10444. /// 1 = "The deal has failed."
  10445. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10446. {
  10447. int fd = sd->fd;
  10448. WFIFOHEAD(fd,packet_len(0xcb));
  10449. WFIFOW(fd,0) = 0xcb;
  10450. WFIFOB(fd,2) = result;
  10451. WFIFOSET(fd,packet_len(0xcb));
  10452. }
  10453. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10454. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10455. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10456. {
  10457. int fail=0,n;
  10458. unsigned short *item_list;
  10459. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10460. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10461. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10462. if (sd->state.trading || !sd->npc_shopid)
  10463. fail = 1;
  10464. else
  10465. fail = npc_selllist(sd,n,item_list);
  10466. sd->npc_shopid = 0; //Clear shop data.
  10467. clif_npc_sell_result(sd, fail);
  10468. }
  10469. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10470. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10471. /// type:
  10472. /// 0 = private
  10473. /// 1 = public
  10474. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10475. {
  10476. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10477. int len = RFIFOW(fd,info->pos[0])-15;
  10478. int limit = RFIFOW(fd,info->pos[1]);
  10479. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10480. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10481. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10482. char s_password[CHATROOM_PASS_SIZE];
  10483. char s_title[CHATROOM_TITLE_SIZE];
  10484. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10485. return;
  10486. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10487. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10488. return;
  10489. }
  10490. if( npc_isnear(&sd->bl) ) {
  10491. // uncomment to send msg_txt.
  10492. //char output[150];
  10493. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10494. //clif_displaymessage(sd->fd, output);
  10495. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10496. return;
  10497. }
  10498. if( len <= 0 )
  10499. return; // invalid input
  10500. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10501. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10502. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10503. }
  10504. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10505. /// 00d9 <chat ID>.L <passwd>.8B
  10506. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10507. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10508. int chatid = RFIFOL(fd,info->pos[0]);
  10509. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10510. chat_joinchat(sd,chatid,password);
  10511. }
  10512. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10513. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10514. /// type:
  10515. /// 0 = private
  10516. /// 1 = public
  10517. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10518. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10519. int len = RFIFOW(fd,info->pos[0])-15;
  10520. int limit = RFIFOW(fd,info->pos[1]);
  10521. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10522. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10523. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10524. char s_password[CHATROOM_PASS_SIZE];
  10525. char s_title[CHATROOM_TITLE_SIZE];
  10526. if( len <= 0 )
  10527. return; // invalid input
  10528. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10529. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10530. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10531. }
  10532. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10533. /// 00e0 <role>.L <nick>.24B
  10534. /// role:
  10535. /// 0 = owner
  10536. /// 1 = normal
  10537. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10538. {
  10539. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10540. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10541. }
  10542. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10543. /// 00e2 <name>.24B
  10544. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10545. {
  10546. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10547. }
  10548. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10549. /// 00e3
  10550. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10551. {
  10552. chat_leavechat(sd,0);
  10553. }
  10554. //Handles notifying asker and rejecter of what has just ocurred.
  10555. //Type is used to determine the correct msg_txt to use:
  10556. //0:
  10557. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10558. {
  10559. const char* msg;
  10560. char output[256];
  10561. // Your request has been rejected by autoreject option.
  10562. msg = msg_txt(sd,392);
  10563. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10564. //Notice that a request was rejected.
  10565. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10566. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10567. }
  10568. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10569. /// 00e4 <account id>.L
  10570. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10571. {
  10572. struct map_session_data *t_sd;
  10573. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10574. if(!sd->chatID && pc_cant_act(sd))
  10575. return; //You can trade while in a chatroom.
  10576. if(t_sd){
  10577. // @noask [LuzZza]
  10578. if(t_sd->state.noask) {
  10579. clif_noask_sub(sd, t_sd, 0);
  10580. return;
  10581. }
  10582. if (t_sd->state.mail_writing) {
  10583. int old = sd->trade_partner;
  10584. // Fake trading
  10585. sd->trade_partner = t_sd->status.account_id;
  10586. clif_tradestart(sd, 5);
  10587. // Restore old state
  10588. sd->trade_partner = old;
  10589. return;
  10590. }
  10591. }
  10592. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10593. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10594. return;
  10595. }
  10596. trade_traderequest(sd,t_sd);
  10597. }
  10598. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10599. /// 00e6 <result>.B
  10600. /// result:
  10601. /// 3 = accepted
  10602. /// 4 = rejected
  10603. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10604. {
  10605. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10606. }
  10607. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10608. /// 00e8 <index>.W <amount>.L
  10609. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10610. {
  10611. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10612. short index = RFIFOW(fd,info->pos[0]);
  10613. int amount = RFIFOL(fd,info->pos[1]);
  10614. if( index == 0 )
  10615. trade_tradeaddzeny(sd, amount);
  10616. else
  10617. trade_tradeadditem(sd, index, (short)amount);
  10618. }
  10619. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10620. /// 00eb
  10621. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10622. {
  10623. trade_tradeok(sd);
  10624. }
  10625. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10626. /// 00ed
  10627. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10628. {
  10629. trade_tradecancel(sd);
  10630. }
  10631. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10632. /// 00ef
  10633. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10634. {
  10635. trade_tradecommit(sd);
  10636. }
  10637. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10638. /// 0118
  10639. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10640. {
  10641. pc_stop_attack(sd);
  10642. if (sd) sd->ud.state.attack_continue = 0;
  10643. }
  10644. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10645. /// 0126 <index>.W <amount>.L
  10646. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10647. {
  10648. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10649. if (pc_istrading(sd))
  10650. return;
  10651. if (!pc_iscarton(sd))
  10652. return;
  10653. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10654. return;
  10655. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10656. }
  10657. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10658. /// 0127 <index>.W <amount>.L
  10659. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10660. {
  10661. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10662. if (!pc_iscarton(sd))
  10663. return;
  10664. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10665. return;
  10666. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10667. }
  10668. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10669. /// 012a
  10670. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10671. {
  10672. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10673. #ifdef NEW_CARTS
  10674. && sd->sc.data[SC_PUSH_CART] )
  10675. pc_setcart(sd,0);
  10676. #else
  10677. )
  10678. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10679. #endif
  10680. else // priority to remove this option before we can clear cart
  10681. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10682. }
  10683. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10684. /// 097f <Length>.W <identity>.L <type>.B
  10685. void clif_SelectCart(struct map_session_data *sd) {
  10686. #if PACKETVER >= 20150826
  10687. int i = 0, carts = 3;
  10688. int fd = sd->fd;
  10689. WFIFOHEAD(fd,8 + carts);
  10690. WFIFOW(fd,0) = 0x97f;
  10691. WFIFOW(fd,2) = 8 + carts;
  10692. WFIFOL(fd,4) = sd->status.account_id;
  10693. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10694. for( i = 0; i < carts; i++ ) {
  10695. WFIFOB(fd,8 + i) = 10 + i;
  10696. }
  10697. WFIFOSET(fd,8 + carts);
  10698. #endif
  10699. }
  10700. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10701. /// 0980 <identity>.L <type>.B
  10702. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10703. #if PACKETVER >= 20150826
  10704. int type;
  10705. // Check identity
  10706. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10707. return;
  10708. type = (int)RFIFOB(fd,6);
  10709. // Check type
  10710. if( type < 10 || type > 12 )
  10711. return;
  10712. pc_setcart(sd, type);
  10713. #endif
  10714. }
  10715. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10716. /// 01af <num>.W
  10717. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10718. {// TODO: State tracking?
  10719. int type;
  10720. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10721. return;
  10722. #ifdef RENEWAL
  10723. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10724. clif_msg(sd, WORK_IN_PROGRESS);
  10725. return;
  10726. }
  10727. #endif
  10728. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10729. if(
  10730. #ifdef NEW_CARTS
  10731. #if PACKETVER >= 20191106
  10732. (type == 13 && sd->status.base_level > 100) ||
  10733. #endif
  10734. (type == 9 && sd->status.base_level > 130) ||
  10735. (type == 8 && sd->status.base_level > 120) ||
  10736. (type == 7 && sd->status.base_level > 110) ||
  10737. (type == 6 && sd->status.base_level > 100) ||
  10738. #endif
  10739. (type == 5 && sd->status.base_level > 90) ||
  10740. (type == 4 && sd->status.base_level > 80) ||
  10741. (type == 3 && sd->status.base_level > 65) ||
  10742. (type == 2 && sd->status.base_level > 40) ||
  10743. (type == 1))
  10744. pc_setcart(sd, type);
  10745. }
  10746. /// Request to increase status (CZ_STATUS_CHANGE).
  10747. /// 00bb <status id>.W <amount>.B
  10748. /// status id:
  10749. /// SP_STR ~ SP_LUK
  10750. /// amount:
  10751. /// Old clients always send 1 for this, even when using /str+ and the like.
  10752. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10753. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10754. {
  10755. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10756. if( increase_amount < 0 ) {
  10757. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10758. fd, increase_amount);
  10759. }
  10760. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10761. }
  10762. /// Request to increase trait status.
  10763. /// 0b24 <status id>.W <amount>.W
  10764. /// status id:
  10765. /// SP_POW ~ SP_CON
  10766. /// amount:
  10767. /// The amount to increase the trait status
  10768. void clif_parse_traitstatus_up( int fd, struct map_session_data *sd ){
  10769. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10770. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10771. if( p->amount < 0 ){
  10772. 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 );
  10773. return;
  10774. }
  10775. pc_traitstatusup( sd, p->type, p->amount );
  10776. #endif
  10777. }
  10778. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10779. /// 0112 <skill id>.W
  10780. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10781. {
  10782. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10783. }
  10784. 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)
  10785. {
  10786. int lv;
  10787. if( !hd )
  10788. return;
  10789. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10790. clif_emotion(&hd->bl, ET_THINK);
  10791. return;
  10792. }
  10793. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10794. target_id = hd->bl.id;
  10795. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10796. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10797. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10798. clif_emotion(&hd->bl, ET_THINK);
  10799. if (hd->master)
  10800. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10801. return;
  10802. }
  10803. lv = hom_checkskill(hd, skill_id);
  10804. if( skill_lv > lv )
  10805. skill_lv = lv;
  10806. if( skill_lv )
  10807. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10808. }
  10809. 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)
  10810. {
  10811. int lv;
  10812. if( !hd )
  10813. return;
  10814. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10815. clif_emotion(&hd->bl, ET_THINK);
  10816. return;
  10817. }
  10818. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10819. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10820. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10821. clif_emotion(&hd->bl, ET_THINK);
  10822. if (hd->master)
  10823. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10824. return;
  10825. }
  10826. #ifdef RENEWAL
  10827. if (hd->sc.data[SC_BASILICA_CELL])
  10828. #else
  10829. if (hd->sc.data[SC_BASILICA])
  10830. #endif
  10831. return;
  10832. lv = hom_checkskill(hd, skill_id);
  10833. if( skill_lv > lv )
  10834. skill_lv = lv;
  10835. if( skill_lv )
  10836. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10837. }
  10838. 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)
  10839. {
  10840. int lv;
  10841. if( !md )
  10842. return;
  10843. if( skill_isNotOk_mercenary(skill_id, md) )
  10844. return;
  10845. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10846. target_id = md->bl.id;
  10847. if( md->ud.skilltimer != INVALID_TIMER )
  10848. {
  10849. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10850. }
  10851. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10852. return;
  10853. lv = mercenary_checkskill(md, skill_id);
  10854. if( skill_lv > lv )
  10855. skill_lv = lv;
  10856. if( skill_lv )
  10857. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10858. }
  10859. 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)
  10860. {
  10861. int lv;
  10862. if( !md )
  10863. return;
  10864. if( skill_isNotOk_mercenary(skill_id, md) )
  10865. return;
  10866. if( md->ud.skilltimer != INVALID_TIMER )
  10867. return;
  10868. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10869. {
  10870. if (md->master)
  10871. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10872. return;
  10873. }
  10874. #ifdef RENEWAL
  10875. if (md->sc.data[SC_BASILICA_CELL])
  10876. #else
  10877. if (md->sc.data[SC_BASILICA])
  10878. #endif
  10879. return;
  10880. lv = mercenary_checkskill(md, skill_id);
  10881. if( skill_lv > lv )
  10882. skill_lv = lv;
  10883. if( skill_lv )
  10884. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10885. }
  10886. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10887. t_tick tick = gettick();
  10888. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10889. int inf = skill_get_inf(skill_id);
  10890. if (inf&INF_GROUND_SKILL || !inf)
  10891. return; //Using a ground/passive skill on a target? WRONG.
  10892. if (sd->state.block_action & PCBLOCK_SKILL) {
  10893. clif_msg(sd, WORK_IN_PROGRESS);
  10894. return;
  10895. }
  10896. if( SKILL_CHK_HOMUN(skill_id) ) {
  10897. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10898. return;
  10899. }
  10900. if( SKILL_CHK_MERC(skill_id) ) {
  10901. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10902. return;
  10903. }
  10904. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10905. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10906. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10907. sd->idletime = last_tick;
  10908. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10909. sd->idletime_hom = last_tick;
  10910. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10911. sd->idletime_mer = last_tick;
  10912. if( sd->npc_id ){
  10913. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10914. #ifdef RENEWAL
  10915. clif_msg( sd, WORK_IN_PROGRESS );
  10916. #endif
  10917. return;
  10918. }
  10919. }
  10920. if ((pc_cant_act2(sd) || sd->chatID) &&
  10921. skill_id != RK_REFRESH &&
  10922. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10923. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10924. return;
  10925. if( pc_issit(sd) )
  10926. return;
  10927. if( skill_isNotOk(skill_id, sd) )
  10928. return;
  10929. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10930. target_id = sd->bl.id; // never trust the client
  10931. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10932. target_id = sd->bl.id;
  10933. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10934. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10935. return;
  10936. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10937. if( sd->skillitem != skill_id ) {
  10938. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10939. return;
  10940. }
  10941. }
  10942. if( sd->sc.option&OPTION_COSTUME )
  10943. return;
  10944. #ifndef RENEWAL
  10945. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10946. return; // On basilica only caster can use Basilica again to stop it.
  10947. #endif
  10948. if( sd->menuskill_id ) {
  10949. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10950. clif_menuskill_clear(sd); //Cancel pet capture.
  10951. }else if( sd->menuskill_id == SG_FEEL ){
  10952. clif_menuskill_clear( sd ); // Cancel selection
  10953. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10954. return; //Can't use skills while a menu is open.
  10955. }
  10956. if( sd->skillitem == skill_id ) {
  10957. if( skill_lv != sd->skillitemlv )
  10958. skill_lv = sd->skillitemlv;
  10959. if( !(inf&INF_SELF_SKILL) )
  10960. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10961. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10962. return;
  10963. }
  10964. sd->skillitem = sd->skillitemlv = 0;
  10965. if( SKILL_CHK_GUILD(skill_id) ) {
  10966. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10967. skill_lv = guild_checkskill(sd->guild, skill_id);
  10968. else
  10969. skill_lv = 0;
  10970. } else {
  10971. if( skill_id != ALL_EQSWITCH ){
  10972. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10973. }
  10974. }
  10975. pc_delinvincibletimer(sd);
  10976. if( skill_lv )
  10977. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10978. }
  10979. /// Request to use a targeted skill.
  10980. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10981. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10982. /// There are various variants of this packet, some of them have padding between fields.
  10983. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10984. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10985. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10986. }
  10987. /*==========================================
  10988. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10989. *------------------------------------------*/
  10990. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10991. {
  10992. t_tick tick = gettick();
  10993. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10994. return; //Using a target skill on the ground? WRONG.
  10995. if (sd->state.block_action & PCBLOCK_SKILL) {
  10996. clif_msg(sd, WORK_IN_PROGRESS);
  10997. return;
  10998. }
  10999. if( SKILL_CHK_HOMUN(skill_id) ) {
  11000. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  11001. return;
  11002. }
  11003. if( SKILL_CHK_MERC(skill_id) ) {
  11004. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  11005. return;
  11006. }
  11007. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  11008. #ifdef RENEWAL
  11009. clif_msg( sd, WORK_IN_PROGRESS );
  11010. #endif
  11011. return;
  11012. }
  11013. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  11014. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  11015. sd->idletime = last_tick;
  11016. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  11017. sd->idletime_hom = last_tick;
  11018. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  11019. sd->idletime_mer = last_tick;
  11020. if( skill_isNotOk(skill_id, sd) )
  11021. return;
  11022. if( skillmoreinfo != -1 ) {
  11023. if( pc_issit(sd) ) {
  11024. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  11025. return;
  11026. }
  11027. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  11028. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  11029. }
  11030. if( sd->ud.skilltimer != INVALID_TIMER )
  11031. return;
  11032. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  11033. if( sd->skillitem != skill_id ) {
  11034. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  11035. return;
  11036. }
  11037. }
  11038. if( sd->sc.option&OPTION_COSTUME )
  11039. return;
  11040. #ifndef RENEWAL
  11041. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  11042. return; // On basilica only caster can use Basilica again to stop it.
  11043. #endif
  11044. if( sd->menuskill_id ) {
  11045. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  11046. clif_menuskill_clear(sd); //Cancel pet capture.
  11047. }else if( sd->menuskill_id == SG_FEEL ){
  11048. clif_menuskill_clear( sd ); // Cancel selection
  11049. } else if( sd->menuskill_id != SA_AUTOSPELL )
  11050. return; //Can't use skills while a menu is open.
  11051. }
  11052. pc_delinvincibletimer(sd);
  11053. if( sd->skillitem == skill_id ) {
  11054. if( skill_lv != sd->skillitemlv )
  11055. skill_lv = sd->skillitemlv;
  11056. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  11057. } else {
  11058. int lv;
  11059. sd->skillitem = sd->skillitemlv = 0;
  11060. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  11061. if( skill_lv > lv )
  11062. skill_lv = lv;
  11063. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  11064. }
  11065. }
  11066. }
  11067. /// Request to use a ground skill.
  11068. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  11069. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  11070. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  11071. /// There are various variants of this packet, some of them have padding between fields.
  11072. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  11073. {
  11074. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11075. if (pc_cant_act(sd))
  11076. return;
  11077. if (pc_issit(sd))
  11078. return;
  11079. clif_parse_UseSkillToPosSub(fd, sd,
  11080. RFIFOW(fd,info->pos[0]), //skill lv
  11081. RFIFOW(fd,info->pos[1]), //skill num
  11082. RFIFOW(fd,info->pos[2]), //pos x
  11083. RFIFOW(fd,info->pos[3]), //pos y
  11084. // TODO: find out what this is intended to do
  11085. //RFIFOB(fd, info->pos[4])
  11086. -1 //Skill more info.
  11087. );
  11088. }
  11089. /// Request to use a ground skill with text.
  11090. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  11091. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  11092. /// There are various variants of this packet, some of them have padding between fields.
  11093. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  11094. {
  11095. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11096. if (pc_cant_act(sd))
  11097. return;
  11098. if (pc_issit(sd))
  11099. return;
  11100. clif_parse_UseSkillToPosSub(fd, sd,
  11101. RFIFOW(fd,info->pos[0]), //Skill lv
  11102. RFIFOW(fd,info->pos[1]), //Skill num
  11103. RFIFOW(fd,info->pos[2]), //pos x
  11104. RFIFOW(fd,info->pos[3]), //pos y
  11105. info->pos[4] //skill more info
  11106. );
  11107. }
  11108. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  11109. /// 011b <skill id>.W <map name>.16B
  11110. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  11111. {
  11112. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11113. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11114. char map_name[MAP_NAME_LENGTH];
  11115. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11116. sd->state.workinprogress = WIP_DISABLE_NONE;
  11117. if(skill_id != sd->menuskill_id)
  11118. return;
  11119. //It is possible to use teleport with the storage window open bugreport:8027
  11120. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11121. clif_menuskill_clear(sd);
  11122. return;
  11123. }
  11124. pc_delinvincibletimer(sd);
  11125. skill_castend_map(sd,skill_id,map_name);
  11126. }
  11127. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11128. /// 011d
  11129. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  11130. {
  11131. if (!pc_isdead(sd))
  11132. pc_memo(sd,-1);
  11133. }
  11134. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11135. /// 018e <name id>.W { <material id>.W }*3
  11136. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  11137. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11138. switch( sd->menuskill_id ) {
  11139. case -1:
  11140. case AM_PHARMACY:
  11141. case RK_RUNEMASTERY:
  11142. case GC_RESEARCHNEWPOISON:
  11143. break;
  11144. default:
  11145. return;
  11146. }
  11147. if (pc_istrading(sd)) {
  11148. //Make it fail to avoid shop exploits where you sell something different than you see.
  11149. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11150. clif_menuskill_clear(sd);
  11151. return;
  11152. }
  11153. int produce_idx;
  11154. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11155. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11156. clif_menuskill_clear(sd);
  11157. }
  11158. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11159. /// 025b <mk type>.W <name id>.W
  11160. /// mk type:
  11161. /// 1 = cooking
  11162. /// 2 = arrow
  11163. /// 3 = elemental
  11164. /// 4 = GN_MIX_COOKING
  11165. /// 5 = GN_MAKEBOMB
  11166. /// 6 = GN_S_PHARMACY
  11167. /// 7 = MT_M_MACHINE - Unconfirmed
  11168. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11169. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  11170. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11171. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11172. short food_idx = -1;
  11173. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11174. return;
  11175. if (pc_istrading(sd)) {
  11176. //Make it fail to avoid shop exploits where you sell something different than you see.
  11177. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11178. clif_menuskill_clear(sd);
  11179. return;
  11180. }
  11181. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11182. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11183. clif_menuskill_clear(sd);
  11184. }
  11185. /// Answer to repair weapon item selection dialog
  11186. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11187. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11188. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  11189. // Hercules has wrong date -> use correct one here
  11190. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11191. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11192. #else
  11193. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11194. #endif
  11195. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11196. return;
  11197. if (pc_istrading(sd)) {
  11198. //Make it fail to avoid shop exploits where you sell something different than you see.
  11199. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11200. clif_menuskill_clear(sd);
  11201. return;
  11202. }
  11203. skill_repairweapon( sd, p->item.index );
  11204. clif_menuskill_clear(sd);
  11205. }
  11206. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11207. /// 0222 <index>.L
  11208. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  11209. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11210. return;
  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. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11218. clif_menuskill_clear(sd);
  11219. }
  11220. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11221. /// 00b8 <npc id>.L <choice>.B
  11222. /// choice:
  11223. /// 1~254 = menu item
  11224. /// 255 = cancel
  11225. /// NOTE: If there were more than 254 items in the list, choice
  11226. /// overflows to choice%256.
  11227. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  11228. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11229. int npc_id = RFIFOL(fd,info->pos[0]);
  11230. uint8 select = RFIFOB(fd,info->pos[1]);
  11231. #ifdef SECURE_NPCTIMEOUT
  11232. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11233. return;
  11234. #endif
  11235. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11236. TBL_NPC* nd = map_id2nd(npc_id);
  11237. 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);
  11238. clif_GM_kick(NULL,sd);
  11239. return;
  11240. }
  11241. sd->npc_menu = select;
  11242. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11243. sd->idletime = last_tick;
  11244. }
  11245. npc_scriptcont(sd,npc_id, false);
  11246. }
  11247. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11248. /// 00b9 <npc id>.L
  11249. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  11250. {
  11251. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11252. sd->idletime = last_tick;
  11253. }
  11254. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11255. }
  11256. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11257. /// 0143 <npc id>.L <value>.L
  11258. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  11259. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11260. int npcid = RFIFOL(fd,info->pos[0]);
  11261. int amount = (int)RFIFOL(fd,info->pos[1]);
  11262. sd->npc_amount = amount;
  11263. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11264. sd->idletime = last_tick;
  11265. }
  11266. npc_scriptcont(sd, npcid, false);
  11267. }
  11268. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11269. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11270. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  11271. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11272. int message_len = RFIFOW(fd,info->pos[0])-8;
  11273. int npcid = RFIFOL(fd,info->pos[1]);
  11274. const char* message = RFIFOCP(fd,info->pos[2]);
  11275. if( message_len <= 0 )
  11276. return; // invalid input
  11277. #if PACKETVER >= 20151001
  11278. message_len++;
  11279. #endif
  11280. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11281. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11282. sd->idletime = last_tick;
  11283. }
  11284. npc_scriptcont(sd, npcid, false);
  11285. }
  11286. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11287. /// 0146 <npc id>.L
  11288. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11289. {
  11290. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11291. return;
  11292. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11293. sd->idletime = last_tick;
  11294. }
  11295. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11296. }
  11297. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11298. /// 0178 <index>.W
  11299. /// index:
  11300. /// -1 = cancel
  11301. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11302. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11303. if (sd->menuskill_id != MC_IDENTIFY)
  11304. return;
  11305. // Ignore the request
  11306. // - Invalid item index
  11307. // - Invalid item ID or item doesn't exist
  11308. // - Item is already identified
  11309. if (idx < 0 || idx >= MAX_INVENTORY ||
  11310. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11311. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11312. sd->state.workinprogress = WIP_DISABLE_NONE;
  11313. clif_menuskill_clear(sd);
  11314. return;
  11315. }
  11316. skill_identify(sd, idx);
  11317. clif_menuskill_clear(sd);
  11318. }
  11319. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11320. /// 01ae <name id>.W
  11321. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11322. if (pc_istrading(sd)) {
  11323. //Make it fail to avoid shop exploits where you sell something different than you see.
  11324. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11325. clif_menuskill_clear(sd);
  11326. return;
  11327. }
  11328. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11329. switch (sd->menuskill_id) {
  11330. case AC_MAKINGARROW:
  11331. skill_arrow_create(sd,p->itemId);
  11332. break;
  11333. case SA_CREATECON:
  11334. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11335. break;
  11336. case GC_POISONINGWEAPON:
  11337. skill_poisoningweapon(sd,p->itemId);
  11338. break;
  11339. case NC_MAGICDECOY:
  11340. skill_magicdecoy(sd,p->itemId);
  11341. break;
  11342. }
  11343. clif_menuskill_clear(sd);
  11344. }
  11345. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11346. /// 01ce <skill id>.L
  11347. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11348. {
  11349. if (sd->menuskill_id != SA_AUTOSPELL)
  11350. return;
  11351. sd->state.workinprogress = WIP_DISABLE_NONE;
  11352. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11353. clif_menuskill_clear(sd);
  11354. }
  11355. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11356. /// 017a <card index>.W
  11357. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11358. {
  11359. if (sd->state.trading != 0)
  11360. return;
  11361. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11362. }
  11363. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11364. /// 017c <card index>.W <equip index>.W
  11365. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11366. {
  11367. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11368. if (sd->state.trading != 0)
  11369. return;
  11370. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11371. }
  11372. /// Request of character's name by char ID.
  11373. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11374. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11375. /// There are various variants of this packet, some of them have padding between fields.
  11376. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11377. {
  11378. int charid;
  11379. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11380. map_reqnickdb(sd, charid);
  11381. }
  11382. /// /resetskill /resetstate (CZ_RESET).
  11383. /// Request to reset stats or skills.
  11384. /// 0197 <type>.W
  11385. /// type:
  11386. /// 0 = state
  11387. /// 1 = skill
  11388. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11389. char cmd[15];
  11390. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11391. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11392. else
  11393. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11394. is_atcommand(fd, sd, cmd, 1);
  11395. }
  11396. /// /lb /nlb (CZ_LOCALBROADCAST).
  11397. /// Request to broadcast a message on current map.
  11398. /// 019c <packet len>.W <text>.?B
  11399. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11400. {
  11401. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11402. char command[CHAT_SIZE_MAX+16];
  11403. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11404. char* msg = RFIFOCP(fd,info->pos[1]);
  11405. // as the length varies depending on the command used, just block unreasonably long strings
  11406. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11407. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11408. is_atcommand(fd, sd, command, 1);
  11409. }
  11410. /// Request to move an item from inventory to storage.
  11411. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11412. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11413. /// There are various variants of this packet, some of them have padding between fields.
  11414. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11415. {
  11416. int item_index, item_amount;
  11417. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11418. if (pc_istrading(sd))
  11419. return;
  11420. item_index = RFIFOW(fd,info->pos[0])-2;
  11421. item_amount = RFIFOL(fd,info->pos[1]);
  11422. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11423. return;
  11424. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11425. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11426. return;
  11427. }
  11428. if (sd->state.storage_flag == 1)
  11429. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11430. else
  11431. if (sd->state.storage_flag == 2)
  11432. storage_guild_storageadd(sd, item_index, item_amount);
  11433. else if (sd->state.storage_flag == 3)
  11434. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11435. }
  11436. /// Request to move an item from storage to inventory.
  11437. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11438. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11439. /// There are various variants of this packet, some of them have padding between fields.
  11440. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11441. {
  11442. int item_index, item_amount;
  11443. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11444. item_index = RFIFOW(fd,info->pos[0])-1;
  11445. item_amount = RFIFOL(fd,info->pos[1]);
  11446. if (sd->state.storage_flag == 1)
  11447. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11448. else if(sd->state.storage_flag == 2)
  11449. storage_guild_storageget(sd, item_index, item_amount);
  11450. else if(sd->state.storage_flag == 3)
  11451. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11452. }
  11453. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11454. /// 0129 <index>.W <amount>.L
  11455. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11456. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11457. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11458. int amount = RFIFOL(fd,info->pos[1]);
  11459. if( sd->state.vending )
  11460. return;
  11461. if (!pc_iscarton(sd))
  11462. return;
  11463. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11464. return;
  11465. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11466. return;
  11467. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11468. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11469. return;
  11470. }
  11471. if (sd->state.storage_flag == 1)
  11472. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11473. else if (sd->state.storage_flag == 2)
  11474. storage_guild_storageaddfromcart(sd, idx, amount);
  11475. else if (sd->state.storage_flag == 3)
  11476. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11477. }
  11478. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11479. /// 0128 <index>.W <amount>.L
  11480. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11481. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11482. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11483. int amount = RFIFOL(fd,info->pos[1]);
  11484. if( sd->state.vending )
  11485. return;
  11486. if (!pc_iscarton(sd))
  11487. return;
  11488. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11489. return;
  11490. if (sd->state.storage_flag == 1)
  11491. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11492. else
  11493. if (sd->state.storage_flag == 2)
  11494. storage_guild_storagegettocart(sd, idx, amount);
  11495. else if (sd->state.storage_flag == 3)
  11496. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11497. }
  11498. /// Request to close storage (CZ_CLOSE_STORE).
  11499. /// 00f7
  11500. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11501. {
  11502. if( sd->state.storage_flag == 1 )
  11503. storage_storageclose(sd);
  11504. else
  11505. if( sd->state.storage_flag == 2 )
  11506. storage_guild_storageclose(sd);
  11507. else if( sd->state.storage_flag == 3 )
  11508. storage_premiumStorage_close(sd);
  11509. }
  11510. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11511. /// 023a <info>.W
  11512. /// info:
  11513. /// 0 = password has not been set yet
  11514. /// 1 = storage is password-protected
  11515. /// 8 = too many wrong passwords
  11516. /// ? = ignored
  11517. /// NOTE: This packet is only available on certain non-kRO clients.
  11518. void clif_storagepassword(struct map_session_data* sd, short info)
  11519. {
  11520. int fd = sd->fd;
  11521. WFIFOHEAD(fd,packet_len(0x23a));
  11522. WFIFOW(fd,0) = 0x23a;
  11523. WFIFOW(fd,2) = info;
  11524. WFIFOSET(fd,packet_len(0x23a));
  11525. }
  11526. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11527. /// 023b <type>.W <password>.16B <new password>.16B
  11528. /// type:
  11529. /// 2 = change password
  11530. /// 3 = check password
  11531. /// NOTE: This packet is only available on certain non-kRO clients.
  11532. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11533. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11534. // int type = RFIFOW(fd,info->pos[0]);
  11535. // char* password = RFIFOP(fd,info->pos[1]);
  11536. // char* new_password = RFIFOP(fd,info->pos[2]);
  11537. // storage_changepass(sd,password,new_password);
  11538. }
  11539. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11540. /// 023c <result>.W <error count>.W
  11541. /// result:
  11542. /// 4 = password change success
  11543. /// 5 = password change failure
  11544. /// 6 = password check success
  11545. /// 7 = password check failure
  11546. /// 8 = too many wrong passwords
  11547. /// ? = ignored
  11548. /// NOTE: This packet is only available on certain non-kRO clients.
  11549. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11550. {
  11551. int fd = sd->fd;
  11552. WFIFOHEAD(fd,packet_len(0x23c));
  11553. WFIFOW(fd,0) = 0x23c;
  11554. WFIFOW(fd,2) = result;
  11555. WFIFOW(fd,4) = error_count;
  11556. WFIFOSET(fd,packet_len(0x23c));
  11557. }
  11558. /// Party creation request
  11559. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11560. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11561. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11562. name[NAME_LENGTH-1] = '\0';
  11563. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11564. clif_displaymessage(fd, msg_txt(sd,227));
  11565. return;
  11566. }
  11567. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11568. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11569. return;
  11570. }
  11571. party_create(sd,name,0,0);
  11572. }
  11573. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11574. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11575. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11576. char* name = RFIFOCP(fd,info->pos[0]);
  11577. int item1 = RFIFOB(fd,info->pos[1]);
  11578. int item2 = RFIFOB(fd,info->pos[2]);
  11579. name[NAME_LENGTH-1] = '\0';
  11580. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11581. clif_displaymessage(fd, msg_txt(sd,227));
  11582. return;
  11583. }
  11584. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11585. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11586. return;
  11587. }
  11588. party_create(sd,name,item1,item2);
  11589. }
  11590. /// Party invitation request
  11591. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11592. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11593. {
  11594. struct map_session_data *t_sd;
  11595. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11596. clif_displaymessage(fd, msg_txt(sd,227));
  11597. return;
  11598. }
  11599. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11600. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11601. clif_noask_sub(sd, t_sd, 1);
  11602. return;
  11603. }
  11604. party_invite(sd, t_sd);
  11605. }
  11606. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11607. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11608. struct map_session_data *t_sd;
  11609. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11610. name[NAME_LENGTH-1] = '\0';
  11611. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11612. clif_displaymessage(fd, msg_txt(sd,227));
  11613. return;
  11614. }
  11615. t_sd = map_nick2sd(name,false);
  11616. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11617. clif_noask_sub(sd, t_sd, 1);
  11618. return;
  11619. }
  11620. party_invite(sd, t_sd);
  11621. }
  11622. /// Party invitation reply
  11623. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11624. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11625. /// flag:
  11626. /// 0 = reject
  11627. /// 1 = accept
  11628. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11629. {
  11630. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11631. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11632. RFIFOL(fd,info->pos[1]));
  11633. }
  11634. //(CZ_PARTY_JOIN_REQ_ACK)
  11635. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11636. {
  11637. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11638. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11639. RFIFOB(fd,info->pos[1]));
  11640. }
  11641. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11642. /// 0100
  11643. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11644. {
  11645. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11646. clif_displaymessage(fd, msg_txt(sd,227));
  11647. return;
  11648. }
  11649. party_leave(sd);
  11650. }
  11651. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11652. /// 0103 <account id>.L <char name>.24B
  11653. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11654. {
  11655. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11656. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11657. clif_displaymessage(fd, msg_txt(sd,227));
  11658. return;
  11659. }
  11660. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11661. RFIFOCP(fd,info->pos[1]));
  11662. }
  11663. /// Request to change party options.
  11664. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11665. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11666. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11667. {
  11668. struct party_data *p;
  11669. int i,expflag;
  11670. int cmd = RFIFOW(fd,0);
  11671. struct s_packet_db* info = &packet_db[cmd];
  11672. if( !sd->status.party_id )
  11673. return;
  11674. p = party_search(sd->status.party_id);
  11675. if( p == NULL )
  11676. return;
  11677. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11678. if( i == MAX_PARTY )
  11679. return; //Shouldn't happen
  11680. if( !p->party.member[i].leader )
  11681. return;
  11682. expflag = RFIFOL(fd,info->pos[0]);
  11683. if(cmd == 0x0102){ //Client can't change the item-field
  11684. party_changeoption(sd, expflag, p->party.item);
  11685. }
  11686. else {
  11687. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11688. party_changeoption(sd, expflag, itemflag);
  11689. }
  11690. }
  11691. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11692. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11693. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11694. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11695. // validate packet and retrieve name and message
  11696. if( !clif_process_message( sd, false, name, message, output ) )
  11697. return;
  11698. party_send_message(sd, output, strlen(output) + 1 );
  11699. }
  11700. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11701. /// 07da <account id>.L
  11702. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11703. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11704. }
  11705. /// Party Booking in KRO [Spiria]
  11706. ///
  11707. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11708. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11709. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11710. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11711. short level = RFIFOW(fd,info->pos[0]);
  11712. short mapid = RFIFOW(fd,info->pos[1]);
  11713. int idxpbj = info->pos[2];
  11714. short job[MAX_PARTY_BOOKING_JOBS];
  11715. int i;
  11716. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11717. job[i] = RFIFOB(fd,idxpbj+i*2);
  11718. party_booking_register(sd, level, mapid, job);
  11719. }
  11720. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11721. /// 0803 <result>.W
  11722. /// result:
  11723. /// 0 = success
  11724. /// 1 = failure
  11725. /// 2 = already registered
  11726. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11727. {
  11728. int fd = sd->fd;
  11729. WFIFOHEAD(fd,packet_len(0x803));
  11730. WFIFOW(fd,0) = 0x803;
  11731. WFIFOW(fd,2) = flag;
  11732. WFIFOSET(fd,packet_len(0x803));
  11733. }
  11734. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11735. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11736. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11737. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11738. short level = RFIFOW(fd,info->pos[0]);
  11739. short mapid = RFIFOW(fd,info->pos[1]);
  11740. short job = RFIFOW(fd,info->pos[2]);
  11741. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11742. short resultcount = RFIFOW(fd,info->pos[4]);
  11743. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11744. }
  11745. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11746. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11747. /// more results:
  11748. /// 0 = no
  11749. /// 1 = yes
  11750. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11751. {
  11752. int i, j;
  11753. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11754. struct party_booking_ad_info *pb_ad;
  11755. WFIFOHEAD(fd,size*count + 5);
  11756. WFIFOW(fd,0) = 0x805;
  11757. WFIFOW(fd,2) = size*count + 5;
  11758. WFIFOB(fd,4) = more_result;
  11759. for(i=0; i<count; i++)
  11760. {
  11761. pb_ad = results[i];
  11762. WFIFOL(fd,i*size+5) = pb_ad->index;
  11763. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11764. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11765. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11766. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11767. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11768. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11769. }
  11770. WFIFOSET(fd,WFIFOW(fd,2));
  11771. }
  11772. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11773. /// 0806
  11774. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11775. {
  11776. if(party_booking_delete(sd))
  11777. clif_PartyBookingDeleteAck(sd, 0);
  11778. }
  11779. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11780. /// 0807 <result>.W
  11781. /// result:
  11782. /// 0 = success
  11783. /// 1 = success (auto-removed expired ad)
  11784. /// 2 = failure
  11785. /// 3 = nothing registered
  11786. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11787. {
  11788. int fd = sd->fd;
  11789. WFIFOHEAD(fd,packet_len(0x807));
  11790. WFIFOW(fd,0) = 0x807;
  11791. WFIFOW(fd,2) = flag;
  11792. WFIFOSET(fd,packet_len(0x807));
  11793. }
  11794. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11795. /// 0808 { <job>.W }*6
  11796. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11797. {
  11798. short job[MAX_PARTY_BOOKING_JOBS];
  11799. int i;
  11800. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11801. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11802. job[i] = RFIFOW(fd,idxpbu+i*2);
  11803. party_booking_update(sd, job);
  11804. }
  11805. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11806. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11807. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11808. {
  11809. int i;
  11810. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11811. if(pb_ad == NULL) return;
  11812. WBUFW(buf,0) = 0x809;
  11813. WBUFL(buf,2) = pb_ad->index;
  11814. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11815. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11816. WBUFW(buf,34) = pb_ad->p_detail.level;
  11817. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11818. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11819. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11820. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11821. }
  11822. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11823. /// 080a <index>.L { <job>.W }*6
  11824. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11825. {
  11826. int i;
  11827. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11828. if(pb_ad == NULL) return;
  11829. WBUFW(buf,0) = 0x80a;
  11830. WBUFL(buf,2) = pb_ad->index;
  11831. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11832. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11833. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11834. }
  11835. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11836. /// 080b <index>.L
  11837. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11838. {
  11839. uint8 buf[6];
  11840. WBUFW(buf,0) = 0x80b;
  11841. WBUFL(buf,2) = index;
  11842. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11843. }
  11844. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11845. /// 012e
  11846. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11847. {
  11848. vending_closevending(sd);
  11849. }
  11850. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11851. /// 0130 <account id>.L
  11852. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11853. {
  11854. if( sd->npc_id ) {// using an NPC
  11855. return;
  11856. }
  11857. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11858. }
  11859. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11860. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11861. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11862. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11863. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11864. int id = (int)RFIFOL(fd,info->pos[1]);
  11865. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11866. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11867. // whether it fails or not, the buy window is closed
  11868. sd->vended_id = 0;
  11869. }
  11870. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11871. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11872. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11873. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11874. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11875. int aid = (int)RFIFOL(fd,info->pos[1]);
  11876. int uid = (int)RFIFOL(fd,info->pos[2]);
  11877. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11878. vending_purchasereq(sd, aid, uid, data, len/4);
  11879. // whether it fails or not, the buy window is closed
  11880. sd->vended_id = 0;
  11881. }
  11882. /// Confirm or cancel the shop preparation window.
  11883. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11884. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11885. /// result:
  11886. /// 0 = canceled
  11887. /// 1 = open
  11888. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11889. int cmd = RFIFOW(fd,0);
  11890. struct s_packet_db* info = &packet_db[cmd];
  11891. short len = (short)RFIFOW(fd,info->pos[0]);
  11892. const char* message = RFIFOCP(fd,info->pos[1]);
  11893. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11894. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11895. len -= 84;
  11896. }
  11897. else { //(CZ_REQ_OPENSTORE2)
  11898. bool flag;
  11899. len -= 85;
  11900. flag = RFIFOB(fd,info->pos[2]) != 0;
  11901. if (!flag) {
  11902. sd->state.prevend = 0;
  11903. sd->state.workinprogress = WIP_DISABLE_NONE;
  11904. }
  11905. }
  11906. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11907. return;
  11908. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11909. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11910. return;
  11911. }
  11912. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11913. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11914. return;
  11915. }
  11916. if( message[0] == '\0' ) // invalid input
  11917. return;
  11918. vending_openvending(sd, message, data, len/8, NULL);
  11919. }
  11920. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11921. /// 0165 <char id>.L <guild name>.24B
  11922. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11923. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11924. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11925. name[NAME_LENGTH-1] = '\0';
  11926. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11927. clif_displaymessage(fd, msg_txt(sd,228));
  11928. return;
  11929. }
  11930. if(sd->clan){
  11931. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11932. return;
  11933. }
  11934. guild_create(sd, name);
  11935. }
  11936. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11937. /// 014d
  11938. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11939. {
  11940. clif_guild_masterormember(sd);
  11941. }
  11942. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11943. /// 014f <type>.L
  11944. /// type:
  11945. /// 0 = basic info
  11946. /// 1 = member manager
  11947. /// 2 = positions
  11948. /// 3 = skills
  11949. /// 4 = expulsion list
  11950. /// 5 = unknown (GM_ALLGUILDLIST)
  11951. /// 6 = notice
  11952. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11953. {
  11954. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11955. if( !sd->status.guild_id && !sd->bg_id )
  11956. return;
  11957. switch( type )
  11958. {
  11959. case 0: // Basic Information Guild, hostile alliance information
  11960. clif_guild_basicinfo(sd);
  11961. clif_guild_allianceinfo(sd);
  11962. break;
  11963. case 1: // Members list, list job title
  11964. clif_guild_positionnamelist(sd);
  11965. clif_guild_memberlist(sd);
  11966. break;
  11967. case 2: // List job title, title information list
  11968. clif_guild_positionnamelist(sd);
  11969. clif_guild_positioninfolist(sd);
  11970. break;
  11971. case 3: // Skill list
  11972. clif_guild_skillinfo(sd);
  11973. break;
  11974. case 4: // Expulsion list
  11975. clif_guild_expulsionlist(sd);
  11976. break;
  11977. default:
  11978. ShowError("clif: guild request info: unknown type %d\n", type);
  11979. break;
  11980. }
  11981. }
  11982. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11983. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11984. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11985. {
  11986. int i;
  11987. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11988. int len = RFIFOW(fd,info->pos[0]);
  11989. int idxgpos = info->pos[1];
  11990. if(!sd->state.gmaster_flag)
  11991. return;
  11992. for(i = idxgpos; i < len; i += 40 ){
  11993. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11994. }
  11995. }
  11996. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11997. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11998. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11999. {
  12000. int i;
  12001. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12002. int len = RFIFOW(fd,info->pos[0]);
  12003. int idxgpos = info->pos[1];
  12004. if(!sd->state.gmaster_flag)
  12005. return;
  12006. // Guild leadership change
  12007. if( len == 16 && RFIFOL(fd,12) == 0 ){
  12008. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  12009. clif_msg(sd, GUILD_MASTER_WOE);
  12010. return;
  12011. }
  12012. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  12013. clif_msg(sd, GUILD_MASTER_DELAY);
  12014. return;
  12015. }
  12016. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  12017. return;
  12018. }
  12019. for(i=idxgpos;i<len;i+=12){
  12020. int position = RFIFOL(fd,i+8);
  12021. if( position > 0 ){
  12022. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  12023. }
  12024. }
  12025. }
  12026. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  12027. /// 0151 <guild id>.L
  12028. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  12029. {
  12030. struct guild* g;
  12031. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12032. if( (g = guild_search(guild_id)) != NULL )
  12033. clif_guild_emblem(sd,g);
  12034. }
  12035. /// Validates data of a guild emblem (compressed bitmap)
  12036. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  12037. EMBVALIDATE_SUCCESS = 0,
  12038. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  12039. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  12040. };
  12041. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  12042. {
  12043. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  12044. unsigned long buf_len = sizeof(buf);
  12045. int offset = 0;
  12046. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  12047. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  12048. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  12049. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  12050. ))
  12051. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  12052. if(inter_config.emblem_transparency_limit != 100) {
  12053. int i, transcount = 1, tmp[3];
  12054. for(i = offset; i < buf_len-1; i++) {
  12055. int j = i%3;
  12056. tmp[j] = RBUFL(buf,i);
  12057. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  12058. transcount++;
  12059. }
  12060. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  12061. return EMBVALIDATE_ERR_TRANSPARENCY;
  12062. }
  12063. return EMBVALIDATE_SUCCESS;
  12064. }
  12065. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  12066. /// 0153 <packet len>.W <emblem data>.?B
  12067. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  12068. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12069. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  12070. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  12071. int emb_val=0;
  12072. if( !emblem_len || !sd->state.gmaster_flag )
  12073. return;
  12074. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  12075. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  12076. return;
  12077. }
  12078. emb_val = clif_validate_emblem(emblem, emblem_len);
  12079. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  12080. 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);
  12081. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  12082. return;
  12083. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  12084. char output[128];
  12085. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  12086. 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"
  12087. return;
  12088. }
  12089. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  12090. }
  12091. /// Request to update the guild emblem id (version, according to Gravity)
  12092. /// 0b46 <guild id>.L <version>.L
  12093. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  12094. nullpo_retv(sd);
  12095. #if PACKETVER >= 20190724
  12096. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  12097. guild* g = sd->guild;
  12098. if (g == nullptr || g->guild_id != p->guild_id)
  12099. return;
  12100. if (!sd->state.gmaster_flag)
  12101. return;
  12102. if (!inter_config.emblem_woe_change && is_agit_start()) {
  12103. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  12104. return;
  12105. }
  12106. guild_change_emblem_version(sd, p->version);
  12107. #endif
  12108. }
  12109. /// Guild notice update request (CZ_GUILD_NOTICE).
  12110. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  12111. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  12112. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12113. int guild_id = RFIFOL(fd,info->pos[0]);
  12114. char* msg1 = RFIFOCP(fd,info->pos[1]);
  12115. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12116. if(!sd->state.gmaster_flag)
  12117. return;
  12118. // compensate for some client defects when using multilanguage mode
  12119. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12120. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12121. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12122. guild_change_notice(sd, guild_id, msg1, msg2);
  12123. }
  12124. // Helper function for guild invite functions
  12125. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  12126. {
  12127. if (t_sd == NULL) // not online or does not exist
  12128. return 1;
  12129. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12130. clif_displaymessage(fd, msg_txt(sd,228));
  12131. return 1;
  12132. }
  12133. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12134. clif_noask_sub(sd, t_sd, 2);
  12135. return 1;
  12136. }
  12137. // Players in a clan can not join a guild
  12138. if(t_sd && t_sd->clan){
  12139. return 1;
  12140. }
  12141. guild_invite(sd, t_sd);
  12142. return 0;
  12143. }
  12144. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12145. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12146. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  12147. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12148. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12149. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12150. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12151. if (clif_sub_guild_invite(fd, sd, t_sd))
  12152. return;
  12153. }
  12154. /// Guild invite request (/guildinvite)
  12155. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12156. void
  12157. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  12158. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12159. if (clif_sub_guild_invite(fd, sd, t_sd))
  12160. return;
  12161. }
  12162. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12163. /// 016b <guild id>.L <answer>.L
  12164. /// answer:
  12165. /// 0 = refuse
  12166. /// 1 = accept
  12167. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  12168. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12169. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12170. RFIFOL(fd,info->pos[1]));
  12171. }
  12172. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12173. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12174. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  12175. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12176. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12177. clif_displaymessage(fd, msg_txt(sd,228));
  12178. return;
  12179. }
  12180. if( sd->bg_id ) {
  12181. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12182. return;
  12183. }
  12184. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12185. RFIFOL(fd,info->pos[1]),
  12186. RFIFOL(fd,info->pos[2]),
  12187. RFIFOCP(fd,info->pos[3]));
  12188. }
  12189. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12190. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12191. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  12192. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12193. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12194. { // Guild locked.
  12195. clif_displaymessage(fd, msg_txt(sd,228));
  12196. return;
  12197. }
  12198. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12199. RFIFOL(fd,info->pos[1]),
  12200. RFIFOL(fd,info->pos[2]),
  12201. RFIFOCP(fd,info->pos[3]));
  12202. }
  12203. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12204. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12205. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  12206. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12207. // validate packet and retrieve name and message
  12208. if( !clif_process_message( sd, false, name, message, output ) )
  12209. return;
  12210. if( sd->bg_id )
  12211. bg_send_message(sd, output, strlen(output) );
  12212. else
  12213. guild_send_message(sd, output, strlen(output) );
  12214. }
  12215. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12216. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12217. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  12218. {
  12219. struct map_session_data *t_sd;
  12220. if(!sd->state.gmaster_flag)
  12221. return;
  12222. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12223. clif_displaymessage(fd, msg_txt(sd,228));
  12224. return;
  12225. }
  12226. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12227. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12228. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12229. // @noask [LuzZza]
  12230. if(t_sd && t_sd->state.noask) {
  12231. clif_noask_sub(sd, t_sd, 3);
  12232. return;
  12233. }
  12234. guild_reqalliance(sd,t_sd);
  12235. }
  12236. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12237. /// 0172 <inviter account id>.L <answer>.L
  12238. /// answer:
  12239. /// 0 = refuse
  12240. /// 1 = accept
  12241. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  12242. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12243. guild_reply_reqalliance(sd,
  12244. RFIFOL(fd,info->pos[0]),
  12245. RFIFOL(fd,info->pos[1]));
  12246. }
  12247. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12248. /// 0183 <opponent guild id>.L <relation>.L
  12249. /// relation:
  12250. /// 0 = Ally
  12251. /// 1 = Enemy
  12252. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  12253. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12254. if(!sd->state.gmaster_flag)
  12255. return;
  12256. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12257. clif_displaymessage(fd, msg_txt(sd,228));
  12258. return;
  12259. }
  12260. guild_delalliance(sd,
  12261. RFIFOL(fd,info->pos[0]),
  12262. RFIFOL(fd,info->pos[1]));
  12263. }
  12264. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12265. /// 0180 <account id>.L
  12266. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  12267. {
  12268. struct map_session_data *t_sd;
  12269. if(!sd->state.gmaster_flag)
  12270. return;
  12271. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12272. clif_displaymessage(fd, msg_txt(sd,228));
  12273. return;
  12274. }
  12275. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12276. // @noask [LuzZza]
  12277. if(t_sd && t_sd->state.noask) {
  12278. clif_noask_sub(sd, t_sd, 4);
  12279. return;
  12280. }
  12281. guild_opposition(sd,t_sd);
  12282. }
  12283. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12284. /// 015d <key>.40B
  12285. /// key:
  12286. /// now guild name; might have been (intended) email, since the
  12287. /// field name and size is same as the one in CH_DELETE_CHAR.
  12288. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  12289. {
  12290. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12291. clif_displaymessage(fd, msg_txt(sd,228));
  12292. return;
  12293. }
  12294. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12295. }
  12296. /// Pet
  12297. ///
  12298. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12299. /// 01a1 <type>.B
  12300. /// type:
  12301. /// 0 = pet information
  12302. /// 1 = feed
  12303. /// 2 = performance
  12304. /// 3 = return to egg
  12305. /// 4 = unequip accessory
  12306. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12307. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12308. }
  12309. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12310. /// 019f <id>.L
  12311. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12312. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12313. }
  12314. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12315. /// 01a7 <index>.W
  12316. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12317. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12318. return;
  12319. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12320. clif_menuskill_clear(sd);
  12321. }
  12322. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12323. /// 01a9 <data>.L
  12324. /// data:
  12325. /// is either emotion (@see enum emotion_type) or a compound value
  12326. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12327. /// entry (given in parentheses) in data\pettalktable.xml
  12328. /// act id:
  12329. /// 0 = feeding
  12330. /// 1 = hunting
  12331. /// 2 = danger
  12332. /// 3 = dead
  12333. /// 4 = normal (stand)
  12334. /// 5 = special performance (perfor_s)
  12335. /// 6 = level up (levelup)
  12336. /// 7 = performance 1 (perfor_1)
  12337. /// 8 = performance 2 (perfor_2)
  12338. /// 9 = performance 3 (perfor_3)
  12339. /// 10 = log-in greeting (connect)
  12340. /// hungry value:
  12341. /// 0 = very hungry (hungry)
  12342. /// 1 = hungry (bit_hungry)
  12343. /// 2 = satisfied (noting)
  12344. /// 3 = stuffed (full)
  12345. /// 4 = full (so_full)
  12346. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12347. {
  12348. if(sd->pd)
  12349. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12350. }
  12351. /// Request to change pet's name (CZ_RENAME_PET).
  12352. /// 01a5 <name>.24B
  12353. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12354. {
  12355. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12356. }
  12357. /// /kill (CZ_DISCONNECT_CHARACTER).
  12358. /// Request to disconnect a character.
  12359. /// 00cc <account id>.L
  12360. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12361. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12362. {
  12363. struct block_list *target;
  12364. int tid;
  12365. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12366. target = map_id2bl(tid);
  12367. if (!target) {
  12368. clif_GM_kickack(sd, 0);
  12369. return;
  12370. }
  12371. switch (target->type) {
  12372. case BL_PC:
  12373. {
  12374. char command[NAME_LENGTH+6];
  12375. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12376. is_atcommand(fd, sd, command, 1);
  12377. }
  12378. break;
  12379. /**
  12380. * This one does not invoke any atcommand, so we need to check for permissions.
  12381. */
  12382. case BL_MOB:
  12383. {
  12384. char command[100];
  12385. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12386. clif_GM_kickack(sd, 0);
  12387. return;
  12388. }
  12389. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12390. log_atcommand(sd, command);
  12391. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12392. }
  12393. break;
  12394. case BL_NPC:
  12395. {
  12396. struct npc_data* nd = (struct npc_data *)target;
  12397. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12398. npc_unload_duplicates(nd);
  12399. npc_unload(nd,true);
  12400. npc_read_event_script();
  12401. }
  12402. }
  12403. break;
  12404. default:
  12405. clif_GM_kickack(sd, 0);
  12406. }
  12407. }
  12408. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12409. /// Request to disconnect all characters.
  12410. /// 00ce
  12411. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12412. char cmd[15];
  12413. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12414. is_atcommand(fd, sd, cmd, 1);
  12415. }
  12416. /// /remove (CZ_REMOVE_AID).
  12417. /// Request to warp to a character with given login ID.
  12418. /// 01ba <account name>.24B
  12419. /// /shift (CZ_SHIFT).
  12420. /// Request to warp to a character with given name.
  12421. /// 01bb <char name>.24B
  12422. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12423. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12424. char *player_name;
  12425. char command[NAME_LENGTH+8];
  12426. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12427. player_name[NAME_LENGTH-1] = '\0';
  12428. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12429. is_atcommand(fd, sd, command, 1);
  12430. }
  12431. /// /remove (CZ_REMOVE_AID_SSO).
  12432. /// Request to warp to a character with given account ID.
  12433. /// 0843 <account id>.L
  12434. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12435. {
  12436. uint32 account_id;
  12437. struct map_session_data* pl_sd;
  12438. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12439. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12440. char command[NAME_LENGTH+8];
  12441. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12442. is_atcommand(fd, sd, command, 1);
  12443. }
  12444. }
  12445. /// /recall (CZ_RECALL).
  12446. /// Request to summon a player with given login ID to own position.
  12447. /// 01bc <account name>.24B
  12448. /// /summon (CZ_RECALL_GID).
  12449. /// Request to summon a player with given name to own position.
  12450. /// 01bd <char name>.24B
  12451. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12452. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12453. char *player_name;
  12454. char command [NAME_LENGTH+8];
  12455. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12456. player_name[NAME_LENGTH-1] = '\0';
  12457. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12458. is_atcommand(fd, sd, command, 1);
  12459. }
  12460. /// /recall (CZ_RECALL_SSO).
  12461. /// Request to summon a player with given account ID to own position.
  12462. /// 0842 <account id>.L
  12463. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12464. {
  12465. uint32 account_id;
  12466. struct map_session_data* pl_sd;
  12467. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12468. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12469. char command[NAME_LENGTH+8];
  12470. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12471. is_atcommand(fd, sd, command, 1);
  12472. }
  12473. }
  12474. /// /item /monster (CZ_ITEM_CREATE).
  12475. /// Request to execute GM commands.
  12476. /// Usage:
  12477. /// /item n - summon n monster or acquire n item/s
  12478. /// /item money - grants 2147483647 zenies
  12479. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12480. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12481. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12482. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12483. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12484. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12485. /// 013f <item/mob name>.24B
  12486. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12487. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12488. {
  12489. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12490. int mob_id = 0;
  12491. StringBuf command;
  12492. char *str;
  12493. //#if PACKETVER >= 20131218
  12494. // char str[100];
  12495. //#else
  12496. // char str[24];
  12497. //#endif
  12498. str = RFIFOCP(fd,info->pos[0]);
  12499. if (!str || str[0] == '\0')
  12500. return;
  12501. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12502. return;
  12503. trim(str);
  12504. // Zeny
  12505. if( strcmpi(str, "money") == 0 ) {
  12506. StringBuf_Init(&command);
  12507. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12508. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12509. StringBuf_Destroy(&command);
  12510. return;
  12511. }
  12512. std::shared_ptr<item_data> id = item_db.searchname( str );
  12513. // Item
  12514. if( id ){
  12515. StringBuf_Init(&command);
  12516. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12517. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12518. }else{
  12519. if (id->flag.guid)
  12520. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12521. else
  12522. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12523. }
  12524. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12525. StringBuf_Destroy(&command);
  12526. return;
  12527. }
  12528. // Monster
  12529. if ((mob_id = mobdb_searchname(str)) == 0)
  12530. mob_id = mobdb_checkid(atoi(str));
  12531. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12532. if( mob != nullptr ) {
  12533. StringBuf_Init(&command);
  12534. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12535. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12536. StringBuf_Destroy(&command);
  12537. return;
  12538. }
  12539. }
  12540. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12541. /// 019d <effect state>.L
  12542. /// effect state:
  12543. /// TODO: Any OPTION_* ?
  12544. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12545. char cmd[6];
  12546. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12547. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12548. is_atcommand(fd, sd, cmd, 1);
  12549. }
  12550. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12551. /// 0149 <account id>.L <type>.B <value>.W
  12552. /// type:
  12553. /// 0 = positive points
  12554. /// 1 = negative points
  12555. /// 2 = self mute (+10 minutes)
  12556. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12557. {
  12558. int id, type, value;
  12559. struct map_session_data *dstsd;
  12560. char command[NAME_LENGTH+15];
  12561. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12562. id = RFIFOL(fd,info->pos[0]);
  12563. type = RFIFOB(fd,info->pos[1]);
  12564. value = RFIFOW(fd,info->pos[2]);
  12565. if( type == 0 )
  12566. value = -value;
  12567. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12568. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12569. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12570. return;
  12571. dstsd = map_id2sd(id);
  12572. if( dstsd == NULL )
  12573. return;
  12574. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12575. is_atcommand(fd, sd, command, 1);
  12576. }
  12577. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12578. /// GM adjustment of a player's manner value by -60.
  12579. /// 0212 <char name>.24B
  12580. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12581. {
  12582. char command[NAME_LENGTH+15];
  12583. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12584. name[NAME_LENGTH-1] = '\0';
  12585. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12586. is_atcommand(fd, sd, command, 1);
  12587. }
  12588. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12589. /// 01e0 <account id>.L <account name>.24B
  12590. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12591. {
  12592. WFIFOHEAD(fd,packet_len(0x1e0));
  12593. WFIFOW(fd,0) = 0x1e0;
  12594. WFIFOL(fd,2) = account_id;
  12595. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12596. WFIFOSET(fd,packet_len(0x1e0));
  12597. }
  12598. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12599. /// 01df <account id>.L
  12600. //! TODO: Figure out how does this actually work
  12601. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12602. {
  12603. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12604. /*
  12605. char query[30];
  12606. safesnprintf(query,sizeof(query),"%d", account_id);
  12607. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12608. */
  12609. clif_account_name(fd, account_id, "");
  12610. }
  12611. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12612. /// GM single cell type change request.
  12613. /// 0198 <x>.W <y>.W <type>.W
  12614. /// type:
  12615. /// 0 = not walkable
  12616. /// 1 = walkable
  12617. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12618. {
  12619. int x,y,type;
  12620. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12621. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12622. return;
  12623. x = RFIFOW(fd,info->pos[0]);
  12624. y = RFIFOW(fd,info->pos[1]);
  12625. type = RFIFOW(fd,info->pos[2]);
  12626. map_setgatcell(sd->bl.m,x,y,type);
  12627. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12628. //FIXME: once players leave the map, the client 'forgets' this information.
  12629. }
  12630. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12631. /// Request to allow/deny whispers from a nick.
  12632. /// 00cf <nick>.24B <type>.B
  12633. /// type:
  12634. /// 0 = (/ex nick) deny speech from nick
  12635. /// 1 = (/in nick) allow speech from nick
  12636. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12637. {
  12638. char* nick;
  12639. uint8 type;
  12640. int i;
  12641. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12642. nick = RFIFOCP(fd,info->pos[0]);
  12643. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12644. type = RFIFOB(fd,info->pos[1]);
  12645. if( type == 0 ) { // Add name to ignore list (block)
  12646. if (strcmp(wisp_server_name, nick) == 0) {
  12647. clif_wisexin(sd, type, 1); // fail
  12648. return;
  12649. }
  12650. // try to find a free spot, while checking for duplicates at the same time
  12651. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12652. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12653. clif_wisexin(sd, type, 2); // too many blocks
  12654. return;
  12655. }
  12656. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12657. clif_wisexin(sd, type, 0); // Aegis reports success.
  12658. return;
  12659. }
  12660. //Insert in position i
  12661. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12662. } else { // Remove name from ignore list (unblock)
  12663. // find entry
  12664. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12665. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12666. clif_wisexin(sd, type, 1); // fail
  12667. return;
  12668. }
  12669. // move everything one place down to overwrite removed entry
  12670. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12671. // wipe last entry
  12672. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12673. }
  12674. clif_wisexin(sd, type, 0); // success
  12675. }
  12676. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12677. /// Request to allow/deny all whispers.
  12678. /// 00d0 <type>.B
  12679. /// type:
  12680. /// 0 = (/exall) deny all speech
  12681. /// 1 = (/inall) allow all speech
  12682. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12683. {
  12684. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12685. if( type == 0 ) {// Deny all
  12686. if( sd->state.ignoreAll ) {
  12687. flag = 1; // fail
  12688. } else {
  12689. sd->state.ignoreAll = 1;
  12690. flag = 0; // success
  12691. }
  12692. } else {//Unblock everyone
  12693. if( sd->state.ignoreAll ) {
  12694. sd->state.ignoreAll = 0;
  12695. flag = 0; // success
  12696. } else {
  12697. if (sd->ignore[0].name[0] != '\0')
  12698. { //Wipe the ignore list.
  12699. memset(sd->ignore, 0, sizeof(sd->ignore));
  12700. flag = 0; // success
  12701. } else {
  12702. flag = 1; // fail
  12703. }
  12704. }
  12705. }
  12706. clif_wisall(sd, type, flag);
  12707. }
  12708. /// Whisper ignore list (ZC_WHISPER_LIST).
  12709. /// 00d4 <packet len>.W { <char name>.24B }*
  12710. void clif_PMIgnoreList(struct map_session_data* sd)
  12711. {
  12712. int i, fd = sd->fd;
  12713. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12714. WFIFOW(fd,0) = 0xd4;
  12715. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12716. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12717. }
  12718. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12719. WFIFOSET(fd,WFIFOW(fd,2));
  12720. }
  12721. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12722. /// 00d3
  12723. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12724. {
  12725. clif_PMIgnoreList(sd);
  12726. }
  12727. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12728. /// 01e7
  12729. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12730. {
  12731. if (sd->state.doridori) return;
  12732. switch (sd->class_&MAPID_UPPERMASK) {
  12733. case MAPID_SOUL_LINKER:
  12734. case MAPID_STAR_GLADIATOR:
  12735. case MAPID_TAEKWON:
  12736. if (!sd->state.rest)
  12737. break;
  12738. case MAPID_SUPER_NOVICE:
  12739. case MAPID_SUPER_BABY:
  12740. case MAPID_SUPER_NOVICE_E:
  12741. case MAPID_SUPER_BABY_E:
  12742. sd->state.doridori=1;
  12743. break;
  12744. }
  12745. }
  12746. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12747. /// 01ed
  12748. /// Note: This packet is caused by 7 lines of any text, followed by
  12749. /// the prayer and an another line of any text. The prayer is
  12750. /// defined by lines 790~793 in data\msgstringtable.txt
  12751. /// "Dear angel, can you hear my voice?"
  12752. /// "I am" (space separated player name) "Super Novice~"
  12753. /// "Help me out~ Please~ T_T"
  12754. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12755. {
  12756. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12757. t_exp next = pc_nextbaseexp(sd);
  12758. if( next ) {
  12759. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12760. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12761. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12762. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12763. }
  12764. }
  12765. }
  12766. }
  12767. /// Friends List
  12768. ///
  12769. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12770. /// 0206 <account id>.L <char id>.L <state>.B
  12771. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12772. /// state:
  12773. /// 0 = online
  12774. /// 1 = offline
  12775. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12776. {
  12777. int i, fd = sd->fd;
  12778. //Seek friend.
  12779. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12780. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12781. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12782. return; //Not found
  12783. WFIFOHEAD(fd,packet_len(0x206));
  12784. WFIFOW(fd, 0) = 0x206;
  12785. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12786. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12787. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12788. #if PACKETVER >= 20180221
  12789. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12790. #endif
  12791. WFIFOSET(fd, packet_len(0x206));
  12792. }
  12793. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12794. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12795. {
  12796. uint32 account_id, char_id, online;
  12797. account_id = va_arg(ap, int);
  12798. char_id = va_arg(ap, int);
  12799. online = va_arg(ap, int);
  12800. clif_friendslist_toggle(sd, account_id, char_id, online);
  12801. return 0;
  12802. }
  12803. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12804. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12805. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12806. void clif_friendslist_send(struct map_session_data *sd)
  12807. {
  12808. int i = 0, n, fd = sd->fd;
  12809. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12810. const int size = 8 + NAME_LENGTH;
  12811. #else
  12812. const int size = 8;
  12813. #endif
  12814. // Send friends list
  12815. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12816. WFIFOW(fd, 0) = 0x201;
  12817. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12818. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12819. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12820. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12821. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12822. #endif
  12823. }
  12824. if (i) {
  12825. WFIFOW(fd,2) = 4 + size * i;
  12826. WFIFOSET(fd, WFIFOW(fd,2));
  12827. }
  12828. for (n = 0; n < i; n++) { //Sending the online players
  12829. if (map_charid2sd(sd->status.friends[n].char_id))
  12830. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12831. }
  12832. }
  12833. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12834. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12835. /// result:
  12836. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12837. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12838. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12839. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12840. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12841. {
  12842. int fd;
  12843. nullpo_retv(sd);
  12844. fd = sd->fd;
  12845. WFIFOHEAD(fd,packet_len(0x209));
  12846. WFIFOW(fd,0) = 0x209;
  12847. WFIFOW(fd,2) = type;
  12848. if (f_sd) {
  12849. WFIFOL(fd,4) = f_sd->status.account_id;
  12850. WFIFOL(fd,8) = f_sd->status.char_id;
  12851. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12852. }
  12853. WFIFOSET(fd, packet_len(0x209));
  12854. }
  12855. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12856. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12857. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12858. {
  12859. int fd = sd->fd;
  12860. WFIFOHEAD(fd,packet_len(0x207));
  12861. WFIFOW(fd,0) = 0x207;
  12862. WFIFOL(fd,2) = account_id;
  12863. WFIFOL(fd,6) = char_id;
  12864. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12865. WFIFOSET(fd,packet_len(0x207));
  12866. }
  12867. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12868. /// 0202 <name>.24B
  12869. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12870. {
  12871. struct map_session_data *f_sd;
  12872. int i;
  12873. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12874. // Friend doesn't exist (no player with this name)
  12875. if (f_sd == NULL) {
  12876. clif_displaymessage(fd, msg_txt(sd,3));
  12877. return;
  12878. }
  12879. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12880. return;
  12881. }
  12882. // ensure that the request player's friend list is not full
  12883. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12884. if( i == MAX_FRIENDS ){
  12885. clif_friendslist_reqack(sd, f_sd, 2);
  12886. return;
  12887. }
  12888. // @noask [LuzZza]
  12889. if(f_sd->state.noask) {
  12890. clif_noask_sub(sd, f_sd, 5);
  12891. return;
  12892. }
  12893. // Friend already exists
  12894. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12895. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12896. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12897. return;
  12898. }
  12899. }
  12900. f_sd->friend_req = sd->status.char_id;
  12901. sd->friend_req = f_sd->status.char_id;
  12902. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12903. }
  12904. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12905. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12906. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12907. /// reply:
  12908. /// 0 = rejected
  12909. /// 1 = accepted
  12910. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12911. {
  12912. struct map_session_data *f_sd;
  12913. uint32 account_id;
  12914. char reply;
  12915. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12916. account_id = RFIFOL(fd,info->pos[0]);
  12917. //char_id = RFIFOL(fd,info->pos[1]);
  12918. #if PACKETVER < 6
  12919. reply = RFIFOB(fd,info->pos[2]);
  12920. #else
  12921. reply = RFIFOL(fd,info->pos[2]);
  12922. #endif
  12923. if( sd->bl.id == account_id ) {// adding oneself as friend
  12924. return;
  12925. }
  12926. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12927. if (f_sd == NULL)
  12928. return;
  12929. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12930. clif_friendslist_reqack(f_sd, sd, 1);
  12931. else {
  12932. int i;
  12933. // Find an empty slot
  12934. for (i = 0; i < MAX_FRIENDS; i++)
  12935. if (f_sd->status.friends[i].char_id == 0)
  12936. break;
  12937. if (i == MAX_FRIENDS) {
  12938. clif_friendslist_reqack(f_sd, sd, 2);
  12939. return;
  12940. }
  12941. f_sd->status.friends[i].account_id = sd->status.account_id;
  12942. f_sd->status.friends[i].char_id = sd->status.char_id;
  12943. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12944. clif_friendslist_reqack(f_sd, sd, 0);
  12945. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12946. if (battle_config.friend_auto_add) {
  12947. // Also add f_sd to sd's friendlist.
  12948. for (i = 0; i < MAX_FRIENDS; i++) {
  12949. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12950. return; //No need to add anything.
  12951. if (sd->status.friends[i].char_id == 0)
  12952. break;
  12953. }
  12954. if (i == MAX_FRIENDS) {
  12955. clif_friendslist_reqack(sd, f_sd, 2);
  12956. return;
  12957. }
  12958. sd->status.friends[i].account_id = f_sd->status.account_id;
  12959. sd->status.friends[i].char_id = f_sd->status.char_id;
  12960. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12961. clif_friendslist_reqack(sd, f_sd, 0);
  12962. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12963. }
  12964. }
  12965. }
  12966. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12967. /// 0203 <account id>.L <char id>.L
  12968. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12969. {
  12970. struct map_session_data *f_sd = NULL;
  12971. uint32 account_id, char_id;
  12972. int i, j;
  12973. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12974. account_id = RFIFOL(fd,info->pos[0]);
  12975. char_id = RFIFOL(fd,info->pos[1]);
  12976. // Search friend
  12977. for (i = 0; i < MAX_FRIENDS &&
  12978. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12979. if (i == MAX_FRIENDS) {
  12980. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12981. return;
  12982. }
  12983. //remove from friend's list first
  12984. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12985. for (i = 0; i < MAX_FRIENDS &&
  12986. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12987. if (i != MAX_FRIENDS) {
  12988. // move all chars up
  12989. for(j = i + 1; j < MAX_FRIENDS; j++)
  12990. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12991. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12992. //should the guy be notified of some message? we should add it here if so
  12993. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12994. WFIFOW(f_sd->fd,0) = 0x20a;
  12995. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12996. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12997. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12998. }
  12999. } else { //friend not online -- ask char server to delete from his friendlist
  13000. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  13001. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  13002. return;
  13003. }
  13004. }
  13005. // We can now delete from original requester
  13006. for (i = 0; i < MAX_FRIENDS &&
  13007. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  13008. // move all chars up
  13009. for(j = i + 1; j < MAX_FRIENDS; j++)
  13010. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  13011. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  13012. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  13013. WFIFOHEAD(fd,packet_len(0x20a));
  13014. WFIFOW(fd,0) = 0x20a;
  13015. WFIFOL(fd,2) = account_id;
  13016. WFIFOL(fd,6) = char_id;
  13017. WFIFOSET(fd, packet_len(0x20a));
  13018. }
  13019. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  13020. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  13021. void clif_PVPInfo(struct map_session_data* sd)
  13022. {
  13023. int fd = sd->fd;
  13024. WFIFOHEAD(fd,packet_len(0x210));
  13025. WFIFOW(fd,0) = 0x210;
  13026. WFIFOL(fd,2) = sd->status.char_id;
  13027. WFIFOL(fd,6) = sd->status.account_id;
  13028. WFIFOL(fd,10) = sd->pvp_won; // times won
  13029. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  13030. WFIFOL(fd,18) = sd->pvp_point;
  13031. WFIFOSET(fd, packet_len(0x210));
  13032. }
  13033. /// /pvpinfo (CZ_REQ_PVPPOINT).
  13034. /// 020f <char id>.L <account id>.L
  13035. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  13036. {
  13037. // TODO: Is there a way to use this on an another player (char/acc id)?
  13038. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13039. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13040. clif_PVPInfo(sd);
  13041. }
  13042. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  13043. /// 0254 <which>.B
  13044. /// which: (unused atm for security purpose)
  13045. /// 0 = sun
  13046. /// 1 = moon
  13047. /// 2 = star
  13048. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  13049. {
  13050. int i;
  13051. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13052. if (sd->menuskill_id != SG_FEEL)
  13053. return;
  13054. i = sd->menuskill_val-1;
  13055. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  13056. sd->feel_map[i].index = map_id2index(sd->bl.m);
  13057. sd->feel_map[i].m = sd->bl.m;
  13058. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  13059. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  13060. // clif_misceffect2(&sd->bl, 0x1b0);
  13061. // clif_misceffect2(&sd->bl, 0x21f);
  13062. clif_feel_info(sd, i, 0);
  13063. clif_menuskill_clear(sd);
  13064. }
  13065. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  13066. /// 0253 <which>.B
  13067. /// which:
  13068. /// 0 = sun
  13069. /// 1 = moon
  13070. /// 2 = star
  13071. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  13072. {
  13073. WFIFOHEAD(fd,packet_len(0x253));
  13074. WFIFOW(fd,0)=0x253;
  13075. WFIFOB(fd,2)=TOB(skill_lv-1);
  13076. WFIFOSET(fd, packet_len(0x253));
  13077. sd->menuskill_id = SG_FEEL;
  13078. sd->menuskill_val = skill_lv;
  13079. }
  13080. /// Request to change homunculus' name (CZ_RENAME_MER).
  13081. /// 0231 <name>.24B
  13082. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  13083. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13084. }
  13085. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  13086. /// 0234 <id>.L
  13087. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  13088. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  13089. struct block_list *bl = NULL;
  13090. struct unit_data *ud = NULL;
  13091. if( sd->md && sd->md->bl.id == id )
  13092. bl = &sd->md->bl;
  13093. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13094. bl = &sd->hd->bl; // Moving Homunculus
  13095. else
  13096. return;
  13097. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  13098. ud = unit_bl2ud(bl);
  13099. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  13100. }
  13101. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  13102. /// 0232 <id>.L <position data>.3B
  13103. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  13104. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13105. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  13106. struct block_list *bl = NULL;
  13107. short x, y;
  13108. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  13109. if( sd->md && sd->md->bl.id == id )
  13110. bl = &sd->md->bl; // Moving Mercenary
  13111. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13112. bl = &sd->hd->bl; // Moving Homunculus
  13113. else
  13114. return;
  13115. unit_walktoxy(bl, x, y, 4);
  13116. }
  13117. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  13118. /// 0233 <id>.L <target id>.L <action>.B
  13119. /// action:
  13120. /// always 0
  13121. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  13122. {
  13123. struct block_list *bl = NULL;
  13124. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13125. int id = RFIFOL(fd,info->pos[0]);
  13126. int target_id = RFIFOL(fd,info->pos[1]);
  13127. int action_type = RFIFOB(fd,info->pos[2]);
  13128. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13129. bl = &sd->hd->bl;
  13130. else if( sd->md && sd->md->bl.id == id )
  13131. bl = &sd->md->bl;
  13132. else return;
  13133. unit_stop_attack(bl);
  13134. unit_attack(bl, target_id, action_type != 0);
  13135. }
  13136. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13137. /// 022d <type>.W <command>.B
  13138. /// type:
  13139. /// always 0
  13140. /// command:
  13141. /// 0 = homunculus information
  13142. /// 1 = feed
  13143. /// 2 = delete
  13144. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  13145. { //[orn]
  13146. int cmd = RFIFOW(fd,0);
  13147. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13148. if(!hom_is_active(sd->hd))
  13149. return;
  13150. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13151. }
  13152. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13153. /// 0292
  13154. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  13155. {
  13156. pc_revive_item(sd);
  13157. }
  13158. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13159. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13160. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13161. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13162. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13163. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13164. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13165. void clif_check(int fd, struct map_session_data* pl_sd)
  13166. {
  13167. WFIFOHEAD(fd,packet_len(0x214));
  13168. WFIFOW(fd, 0) = 0x214;
  13169. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13170. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13171. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13172. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13173. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13174. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13175. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13176. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13177. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13178. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13179. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13180. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13181. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13182. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13183. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13184. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13185. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13186. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13187. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13188. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13189. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13190. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13191. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13192. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13193. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13194. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13195. WFIFOSET(fd,packet_len(0x214));
  13196. }
  13197. /// /check (CZ_REQ_STATUS_GM).
  13198. /// Request character's status values.
  13199. /// 0213 <char name>.24B
  13200. void clif_parse_Check(int fd, struct map_session_data *sd)
  13201. {
  13202. char charname[NAME_LENGTH];
  13203. struct map_session_data* pl_sd;
  13204. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13205. return;
  13206. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13207. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13208. {
  13209. return;
  13210. }
  13211. clif_check(fd, pl_sd);
  13212. }
  13213. /// MAIL SYSTEM
  13214. /// By Zephyrus
  13215. ///
  13216. /// Notification about the result of adding an item to mail
  13217. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13218. /// result:
  13219. /// 0 = success
  13220. /// 1 = failure
  13221. /// 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)
  13222. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13223. /// result:
  13224. /// 0 = success
  13225. /// 1 = over weight
  13226. /// 2 = fatal error
  13227. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  13228. int fd = sd->fd;
  13229. #if PACKETVER < 20150513
  13230. WFIFOHEAD(fd,packet_len(0x255));
  13231. WFIFOW(fd,0) = 0x255;
  13232. WFIFOW(fd,2) = index;
  13233. WFIFOB(fd,4) = flag;
  13234. WFIFOSET(fd,packet_len(0x255));
  13235. #else
  13236. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13237. if( flag ){
  13238. memset( &p, 0, sizeof( p ) );
  13239. }else{
  13240. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13241. p.index = index;
  13242. p.count = amount;
  13243. p.itemId = client_nameid( item->nameid );
  13244. p.type = itemtype( item->nameid );
  13245. p.IsIdentified = item->identify ? 1 : 0;
  13246. p.IsDamaged = item->attribute ? 1 : 0;
  13247. p.refiningLevel = item->refine;
  13248. clif_addcards( &p.slot, item );
  13249. clif_add_random_options( p.optionData, item );
  13250. p.weight = 0;
  13251. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13252. if( sd->mail.item[i].nameid == 0 ){
  13253. continue;
  13254. }
  13255. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13256. }
  13257. p.favorite = item->favorite;
  13258. p.location = pc_equippoint( sd, server_index( index ) );
  13259. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13260. p.enchantgrade = item->enchantgrade;
  13261. #endif
  13262. }
  13263. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13264. p.result = flag;
  13265. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13266. #endif
  13267. }
  13268. /// Notification about the result of retrieving a mail attachment
  13269. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13270. /// result:
  13271. /// 0 = success
  13272. /// 1 = failure
  13273. /// 2 = too many items
  13274. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13275. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13276. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13277. #if PACKETVER < 20150513
  13278. int fd = sd->fd;
  13279. WFIFOHEAD(fd,packet_len(0x245));
  13280. WFIFOW(fd,0) = 0x245;
  13281. WFIFOB(fd,2) = result;
  13282. WFIFOSET(fd,packet_len(0x245));
  13283. #else
  13284. switch( type ){
  13285. case MAIL_ATT_ITEM:
  13286. case MAIL_ATT_ZENY:
  13287. break;
  13288. default:
  13289. return;
  13290. }
  13291. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13292. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13293. p.MailID = msg->id;
  13294. p.opentype = msg->type;
  13295. p.result = result;
  13296. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13297. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13298. #endif
  13299. }
  13300. /// Notification about the result of sending a mail
  13301. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13302. /// result:
  13303. /// 0 = success
  13304. /// 1 = recipinent does not exist
  13305. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13306. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13307. #if PACKETVER < 20150513
  13308. int fd = sd->fd;
  13309. WFIFOHEAD(fd,packet_len(0x249));
  13310. WFIFOW(fd,0) = 0x249;
  13311. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13312. WFIFOSET(fd,packet_len(0x249));
  13313. #else
  13314. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13315. p.PacketType = rodexwriteresult;
  13316. p.result = result;
  13317. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13318. #endif
  13319. }
  13320. /// Notification about the result of deleting a mail.
  13321. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13322. /// result:
  13323. /// 0 = success
  13324. /// 1 = failure
  13325. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13326. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13327. #if PACKETVER < 20150513
  13328. int fd = sd->fd;
  13329. WFIFOHEAD(fd, packet_len(0x257));
  13330. WFIFOW(fd,0) = 0x257;
  13331. WFIFOL(fd,2) = msg->id;
  13332. WFIFOW(fd,6) = !success;
  13333. WFIFOSET(fd, packet_len(0x257));
  13334. #else
  13335. // This is only a success notification
  13336. if( success ){
  13337. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13338. p.PacketType = rodexdelete;
  13339. p.opentype = msg->type;
  13340. p.MailID = msg->id;
  13341. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13342. }
  13343. #endif
  13344. }
  13345. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13346. /// 0274 <mail id>.L <result>.W
  13347. /// result:
  13348. /// 0 = success
  13349. /// 1 = failure
  13350. void clif_Mail_return(int fd, int mail_id, short fail)
  13351. {
  13352. WFIFOHEAD(fd,packet_len(0x274));
  13353. WFIFOW(fd,0) = 0x274;
  13354. WFIFOL(fd,2) = mail_id;
  13355. WFIFOW(fd,6) = fail;
  13356. WFIFOSET(fd,packet_len(0x274));
  13357. }
  13358. /// Notification about new mail.
  13359. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13360. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13361. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13362. #if PACKETVER < 20150513
  13363. int fd = sd->fd;
  13364. WFIFOHEAD(fd,packet_len(0x24a));
  13365. WFIFOW(fd,0) = 0x24a;
  13366. WFIFOL(fd,2) = mail_id;
  13367. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13368. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13369. WFIFOSET(fd,packet_len(0x24a));
  13370. #else
  13371. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13372. p.PacketType = rodexicon;
  13373. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13374. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13375. #endif
  13376. }
  13377. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13378. /// 0260 <type>.L
  13379. /// type:
  13380. /// 0 = open
  13381. /// 1 = close
  13382. void clif_Mail_window(int fd, int flag)
  13383. {
  13384. WFIFOHEAD(fd,packet_len(0x260));
  13385. WFIFOW(fd,0) = 0x260;
  13386. WFIFOL(fd,2) = flag;
  13387. WFIFOSET(fd,packet_len(0x260));
  13388. }
  13389. /// Lists mails stored in inbox.
  13390. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13391. /// read:
  13392. /// 0 = unread
  13393. /// 1 = read
  13394. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13395. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13396. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13397. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13398. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13399. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13400. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13401. #if PACKETVER < 20150513
  13402. int fd = sd->fd;
  13403. struct mail_data *md = &sd->mail.inbox;
  13404. struct mail_message *msg;
  13405. int len, i, j;
  13406. len = 8 + (73 * md->amount);
  13407. WFIFOHEAD(fd,len);
  13408. WFIFOW(fd,0) = 0x240;
  13409. WFIFOW(fd,2) = len;
  13410. WFIFOL(fd,4) = md->amount;
  13411. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13412. {
  13413. msg = &md->msg[i];
  13414. if (msg->id < 1)
  13415. continue;
  13416. WFIFOL(fd,8+73*j) = msg->id;
  13417. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13418. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13419. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13420. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13421. j++;
  13422. }
  13423. WFIFOSET(fd,len);
  13424. if( md->full ) {// TODO: is this official?
  13425. char output[100];
  13426. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13427. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13428. }
  13429. #else
  13430. int fd = sd->fd;
  13431. struct mail_data *md = &sd->mail.inbox;
  13432. struct mail_message *msg;
  13433. int i, j, k, offset, titleLength;
  13434. uint8 mailType, amount, remaining;
  13435. uint32 now = (uint32)time(NULL);
  13436. #if PACKETVER >= 20170419
  13437. int cmd = 0xac2;
  13438. #elif PACKETVER >= 20160601
  13439. int cmd = 0xa7d;
  13440. #else
  13441. int cmd = 0x9f0;
  13442. #endif
  13443. if( battle_config.mail_daily_count ){
  13444. mail_refresh_remaining_amount(sd);
  13445. }
  13446. #if PACKETVER >= 20170419
  13447. // Always send all
  13448. i = md->amount;
  13449. #else
  13450. // If a starting mail id was sent
  13451. if( mailID != 0 ){
  13452. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13453. // Unknown mail
  13454. if( i == md->amount ){
  13455. // Ignore the request for now
  13456. return; // TODO: Should we just show the first page instead?
  13457. }
  13458. // It was actually the oldest/first mail, there is no further page
  13459. if( i == 0 ){
  13460. return;
  13461. }
  13462. // We actually want the next/older mail
  13463. i -= 1;
  13464. }else{
  13465. i = md->amount;
  13466. }
  13467. #endif
  13468. // Count the remaining mails from the starting mail or the beginning
  13469. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13470. for( j = i, remaining = 0; j >= 0; j-- ){
  13471. msg = &md->msg[j];
  13472. if (msg->id < 1)
  13473. continue;
  13474. #if PACKETVER < 20170419
  13475. if (msg->type != type)
  13476. continue;
  13477. #endif
  13478. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13479. continue;
  13480. remaining++;
  13481. }
  13482. #if PACKETVER >= 20170419
  13483. // Always send all
  13484. amount = remaining;
  13485. #else
  13486. if( remaining > MAIL_PAGE_SIZE ){
  13487. amount = MAIL_PAGE_SIZE;
  13488. }else{
  13489. amount = remaining;
  13490. }
  13491. #endif
  13492. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13493. WFIFOW(fd, 0) = cmd;
  13494. #if PACKETVER >= 20170419
  13495. WFIFOB(fd, 4) = 1; // Unknown
  13496. offset = 5;
  13497. #else
  13498. WFIFOB(fd, 4) = type;
  13499. WFIFOB(fd, 5) = amount;
  13500. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13501. offset = 7;
  13502. #endif
  13503. for( amount = 0; i >= 0; i-- ){
  13504. msg = &md->msg[i];
  13505. if (msg->id < 1)
  13506. continue;
  13507. #if PACKETVER < 20170419
  13508. if (msg->type != type)
  13509. continue;
  13510. #endif
  13511. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13512. continue;
  13513. #if PACKETVER >= 20170419
  13514. WFIFOB(fd, offset) = msg->type;
  13515. offset += 1;
  13516. #endif
  13517. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13518. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13519. mailType = MAIL_TYPE_TEXT; // Normal letter
  13520. if( msg->zeny > 0 ){
  13521. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13522. }
  13523. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13524. if( msg->item[k].nameid > 0 ){
  13525. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13526. break;
  13527. }
  13528. }
  13529. #if PACKETVER >= 20170419
  13530. // If it came from an npc?
  13531. if( !msg->send_id ){
  13532. mailType |= MAIL_TYPE_NPC;
  13533. }
  13534. #endif
  13535. WFIFOB(fd, offset + 9) = mailType;
  13536. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13537. #if PACKETVER < 20170419
  13538. // How much time has passed since you received the mail
  13539. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13540. offset += 4;
  13541. #endif
  13542. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13543. if( msg->scheduled_deletion > 0 ){
  13544. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13545. }else{
  13546. // Fake the scheduled deletion to one year in the future
  13547. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13548. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13549. }
  13550. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13551. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13552. offset += 40 + titleLength;
  13553. }
  13554. WFIFOW(fd, 2) = (int16)offset;
  13555. WFIFOSET(fd, offset);
  13556. #endif
  13557. }
  13558. /// Mail inbox list request.
  13559. /// 023f (CZ_MAIL_GET_LIST)
  13560. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13561. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13562. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13563. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13564. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13565. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13566. if( mail_invalid_operation( sd ) ){
  13567. return;
  13568. }
  13569. #if PACKETVER < 20150513
  13570. struct mail_data* md = &sd->mail.inbox;
  13571. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13572. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13573. else
  13574. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13575. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13576. mail_removezeny(sd, false);
  13577. #else
  13578. int cmd = RFIFOW(fd, 0);
  13579. #if PACKETVER < 20170419
  13580. uint8 openType = RFIFOB(fd, 2);
  13581. uint64 mailId = RFIFOQ(fd, 3);
  13582. #else
  13583. uint8 openType;
  13584. uint64 mailId = RFIFOQ(fd, 2);
  13585. int i;
  13586. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13587. if( i == MAIL_MAX_INBOX ){
  13588. openType = MAIL_INBOX_NORMAL;
  13589. mailId = 0;
  13590. }else{
  13591. openType = sd->mail.inbox.msg[i].type;
  13592. mailId = 0;
  13593. }
  13594. #endif
  13595. switch( openType ){
  13596. case MAIL_INBOX_NORMAL:
  13597. case MAIL_INBOX_ACCOUNT:
  13598. case MAIL_INBOX_RETURNED:
  13599. break;
  13600. default:
  13601. // Unknown type: ignore request
  13602. return;
  13603. }
  13604. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13605. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13606. return;
  13607. }
  13608. // If it is not a next page request
  13609. if( cmd != 0x9ee ){
  13610. mailId = 0;
  13611. }
  13612. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13613. #endif
  13614. }
  13615. /// Opens a mail
  13616. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13617. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13618. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13619. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13620. /// { }*n
  13621. // TODO: Packet description => for repeated block
  13622. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13623. int i, fd = sd->fd;
  13624. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13625. if( i == MAIL_MAX_INBOX ) {
  13626. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13627. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13628. return;
  13629. } else {
  13630. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13631. struct item *item;
  13632. int msg_len = strlen(msg->body);
  13633. if( msg_len == 0 ) {
  13634. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13635. msg_len = strlen(msg->body);
  13636. }
  13637. #if PACKETVER < 20150513
  13638. item = &msg->item[0];
  13639. int len = 101 + msg_len;
  13640. WFIFOHEAD(fd,len);
  13641. WFIFOW(fd,0) = 0x242;
  13642. WFIFOW(fd,2) = len;
  13643. WFIFOL(fd,4) = msg->id;
  13644. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13645. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13646. WFIFOL(fd,72) = 0;
  13647. WFIFOL(fd,76) = msg->zeny;
  13648. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13649. if( item->nameid && data != nullptr ) {
  13650. WFIFOL(fd,80) = item->amount;
  13651. WFIFOW(fd,84) = client_nameid( item->nameid );
  13652. WFIFOW(fd,86) = itemtype( item->nameid );
  13653. WFIFOB(fd,88) = item->identify;
  13654. WFIFOB(fd,89) = item->attribute;
  13655. WFIFOB(fd,90) = item->refine;
  13656. WFIFOW(fd,91) = item->card[0];
  13657. WFIFOW(fd,93) = item->card[1];
  13658. WFIFOW(fd,95) = item->card[2];
  13659. WFIFOW(fd,97) = item->card[3];
  13660. } else // no item, set all to zero
  13661. memset(WFIFOP(fd,80), 0x00, 19);
  13662. WFIFOB(fd,99) = (unsigned char)msg_len;
  13663. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13664. WFIFOSET(fd,len);
  13665. #else
  13666. msg_len += 1; // Zero Termination
  13667. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13668. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13669. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13670. p->opentype = msg->type;
  13671. p->MailID = msg->id;
  13672. p->TextcontentsLength = msg_len;
  13673. p->zeny = msg->zeny;
  13674. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13675. p->PacketLength += p->TextcontentsLength;
  13676. p->ItemCnt = 0;
  13677. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13678. item = &msg->item[j];
  13679. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13680. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13681. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13682. mailitem->ITID = client_nameid( item->nameid );
  13683. mailitem->count = item->amount;
  13684. mailitem->type = itemtype( item->nameid );
  13685. mailitem->IsIdentified = item->identify ? 1 : 0;
  13686. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13687. mailitem->refiningLevel = item->refine;
  13688. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13689. mailitem->viewSprite = data->look;
  13690. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13691. clif_addcards( &mailitem->slot, item );
  13692. clif_add_random_options( mailitem->option_data, item );
  13693. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13694. mailitem->enchantgrade = item->enchantgrade;
  13695. #endif
  13696. p->PacketLength += sizeof( *mailitem );
  13697. p->ItemCnt++;
  13698. }
  13699. }
  13700. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13701. #endif
  13702. if (msg->status == MAIL_UNREAD) {
  13703. msg->status = MAIL_READ;
  13704. intif_Mail_read(mail_id);
  13705. clif_parse_Mail_refreshinbox(fd, sd);
  13706. sd->mail.inbox.unread--;
  13707. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13708. }
  13709. }
  13710. }
  13711. /// Request to open a mail.
  13712. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13713. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13714. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13715. #if PACKETVER < 20150513
  13716. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13717. #else
  13718. //uint8 openType = RFIFOB(fd, 2);
  13719. int mail_id = (int)RFIFOQ(fd, 3);
  13720. #endif
  13721. if( mail_id <= 0 )
  13722. return;
  13723. if( mail_invalid_operation(sd) )
  13724. return;
  13725. clif_Mail_read(sd, mail_id);
  13726. }
  13727. /// Allow a player to begin writing a mail
  13728. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13729. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13730. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13731. p.PacketType = rodexopenwrite;
  13732. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13733. p.result = success;
  13734. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13735. }
  13736. /// Request to start writing a mail
  13737. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13738. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13739. char name[NAME_LENGTH];
  13740. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13741. if( mail_invalid_operation( sd ) ){
  13742. return;
  13743. }
  13744. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13745. clif_send_Mail_beginwrite_ack(sd, name, false);
  13746. return;
  13747. }
  13748. mail_clear(sd);
  13749. sd->state.mail_writing = true;
  13750. clif_send_Mail_beginwrite_ack(sd, name,true);
  13751. }
  13752. /// Notification that the client cancelled writing a mail
  13753. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13754. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13755. sd->state.mail_writing = false;
  13756. }
  13757. /// Give the client information about the recipient, if available
  13758. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13759. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13760. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13761. #if PACKETVER >= 20141119
  13762. PACKET_ZC_CHECKNAME p = { 0 };
  13763. p.PacketType = HEADER_ZC_CHECKNAME;
  13764. p.CharId = char_id;
  13765. p.Class = class_;
  13766. p.BaseLevel = level;
  13767. #if PACKETVER >= 20160302
  13768. strncpy(p.Name, name, NAME_LENGTH);
  13769. #endif
  13770. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13771. #endif
  13772. }
  13773. /// Request information about the recipient
  13774. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13775. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13776. #if PACKETVER >= 20140423
  13777. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13778. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13779. #else
  13780. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13781. #endif
  13782. static char name[NAME_LENGTH];
  13783. if( mail_invalid_operation( sd ) ){
  13784. return;
  13785. }
  13786. safestrncpy(name, p->Name, NAME_LENGTH);
  13787. intif_mail_checkreceiver(sd, name);
  13788. #endif
  13789. }
  13790. /// Request to receive mail's attachment.
  13791. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13792. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13793. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13794. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13795. int i;
  13796. struct mail_message* msg;
  13797. #if PACKETVER < 20150513
  13798. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13799. int attachment = MAIL_ATT_ALL;
  13800. #else
  13801. uint16 packet_id = RFIFOW(fd, 0);
  13802. int mail_id = (int)RFIFOQ(fd, 2);
  13803. //int openType = RFIFOB(fd, 10);
  13804. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13805. #endif
  13806. if( !chrif_isconnected() )
  13807. return;
  13808. if( mail_id <= 0 )
  13809. return;
  13810. if( mail_invalid_operation(sd) )
  13811. return;
  13812. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13813. if( i == MAIL_MAX_INBOX )
  13814. return;
  13815. msg = &sd->mail.inbox.msg[i];
  13816. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13817. attachment &= ~MAIL_ATT_ZENY;
  13818. }
  13819. if( attachment&MAIL_ATT_ITEM ){
  13820. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13821. // No items were found
  13822. if( i == MAIL_MAX_ITEM ){
  13823. attachment &= ~MAIL_ATT_ITEM;
  13824. }
  13825. }
  13826. // Either no attachment requested at all or there are no zeny or items in the mail
  13827. if( attachment == MAIL_ATT_NONE ){
  13828. return;
  13829. }
  13830. if( attachment&MAIL_ATT_ZENY ){
  13831. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13832. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13833. return;
  13834. }else{
  13835. // Store the pending zeny (required for the "retrieve all" feature)
  13836. sd->mail.pending_zeny += msg->zeny;
  13837. // To make sure another request fails
  13838. msg->zeny = 0;
  13839. }
  13840. }
  13841. if( attachment&MAIL_ATT_ITEM ){
  13842. int slots = 0, totalweight = 0;
  13843. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13844. struct item* item = &msg->item[i];
  13845. if( item->nameid > 0 && item->amount > 0 ){
  13846. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13847. if(data == nullptr)
  13848. continue;
  13849. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13850. case CHKADDITEM_NEW:
  13851. slots += data->inventorySlotNeeded( item->amount );
  13852. break;
  13853. case CHKADDITEM_OVERAMOUNT:
  13854. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13855. return;
  13856. }
  13857. totalweight += data->weight * item->amount;
  13858. }
  13859. }
  13860. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13861. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13862. return;
  13863. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13864. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13865. return;
  13866. }
  13867. // To make sure another request fails
  13868. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13869. // Store the pending weight (required for the "retrieve all" feature)
  13870. sd->mail.pending_weight += totalweight;
  13871. // Store the pending slots (required for the "retrieve all" feature)
  13872. sd->mail.pending_slots += slots;
  13873. }
  13874. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13875. }
  13876. /// Request to delete a mail.
  13877. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13878. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13879. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13880. #if PACKETVER < 20150513
  13881. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13882. #else
  13883. //int openType = RFIFOB(fd, 2);
  13884. int mail_id = (int)RFIFOQ(fd, 3);
  13885. #endif
  13886. int i, j;
  13887. if( !chrif_isconnected() )
  13888. return;
  13889. if( mail_id <= 0 )
  13890. return;
  13891. if( mail_invalid_operation(sd) )
  13892. return;
  13893. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13894. if (i < MAIL_MAX_INBOX) {
  13895. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13896. // can't delete mail without removing zeny first
  13897. if( msg->zeny > 0 ){
  13898. clif_mail_delete(sd, msg, false);
  13899. return;
  13900. }
  13901. // can't delete mail without removing attachment(s) first
  13902. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13903. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13904. clif_mail_delete(sd, msg, false);
  13905. return;
  13906. }
  13907. }
  13908. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13909. sd->mail.inbox.unread--;
  13910. clif_Mail_new(sd,0,NULL,NULL);
  13911. }
  13912. }
  13913. }
  13914. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13915. /// 0273 <mail id>.L <receive name>.24B
  13916. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13917. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13918. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13919. //ShowDump( p, sizeof( p ) );
  13920. int mail_id = p->msgId;
  13921. // not supported for now
  13922. return;
  13923. #else
  13924. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13925. #endif
  13926. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13927. int i;
  13928. if( mail_id <= 0 )
  13929. return;
  13930. if( mail_invalid_operation(sd) )
  13931. return;
  13932. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13933. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13934. intif_Mail_return(sd->status.char_id, mail_id);
  13935. else
  13936. clif_Mail_return(sd->fd, mail_id, 1);
  13937. }
  13938. /// Request to add an item or Zeny to mail.
  13939. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13940. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13941. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13942. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13943. uint16 idx = RFIFOW(fd,info->pos[0]);
  13944. #if PACKETVER < 20150513
  13945. int amount = RFIFOL(fd,info->pos[1]);
  13946. #else
  13947. int amount = RFIFOW(fd,info->pos[1]);
  13948. #endif
  13949. unsigned char flag;
  13950. if( !chrif_isconnected() )
  13951. return;
  13952. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13953. return;
  13954. if (sd->inventory_data[server_index(idx)] == nullptr)
  13955. return;
  13956. if( mail_invalid_operation( sd ) ){
  13957. return;
  13958. }
  13959. flag = mail_setitem(sd, idx, amount);
  13960. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13961. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13962. }else{
  13963. clif_Mail_setattachment(sd,idx,amount,flag);
  13964. }
  13965. }
  13966. /// Remove an item from a mail
  13967. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13968. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13969. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13970. p.PacketType = rodexremoveitem;
  13971. p.result = success;
  13972. p.index = index;
  13973. p.cnt = amount;
  13974. int total = 0;
  13975. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13976. if( sd->mail.item[i].nameid == 0 ){
  13977. break;
  13978. }
  13979. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13980. }
  13981. p.weight = total;
  13982. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13983. }
  13984. /// Request to reset mail item and/or Zeny
  13985. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13986. /// type:
  13987. /// 0 = reset all
  13988. /// 1 = remove item
  13989. /// 2 = remove zeny
  13990. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13991. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13992. {
  13993. #if PACKETVER < 20150513
  13994. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13995. if (type == 0 || type == 1)
  13996. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13997. if (type == 0 || type == 2)
  13998. mail_removezeny(sd, false);
  13999. #else
  14000. uint16 index = RFIFOW(fd, 2);
  14001. uint16 count = RFIFOW(fd, 4);
  14002. mail_removeitem(sd,0,index,count);
  14003. #endif
  14004. }
  14005. /// Request to send mail
  14006. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  14007. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  14008. /// 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)
  14009. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  14010. #if PACKETVER < 20150513
  14011. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14012. if( !chrif_isconnected() )
  14013. return;
  14014. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  14015. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  14016. return;
  14017. }
  14018. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  14019. #else
  14020. uint16 length = RFIFOW(fd, 2);
  14021. if( length < 0x3e ){
  14022. ShowWarning("Too short...\n");
  14023. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  14024. return;
  14025. }
  14026. if( mail_invalid_operation( sd ) ){
  14027. return;
  14028. }
  14029. // Forged request without a begin writing packet?
  14030. if( !sd->state.mail_writing ){
  14031. return; // Ignore it
  14032. }
  14033. char receiver[NAME_LENGTH];
  14034. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  14035. // char sender[NAME_LENGTH];
  14036. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  14037. uint64 zeny = RFIFOQ(fd, 52);
  14038. uint16 titleLength = RFIFOW(fd, 60);
  14039. uint16 textLength = RFIFOW(fd, 62);
  14040. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  14041. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  14042. char title[MAIL_TITLE_LENGTH];
  14043. char text[MAIL_BODY_LENGTH];
  14044. #if PACKETVER <= 20160330
  14045. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  14046. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  14047. #else
  14048. // 64 = <char id>.L
  14049. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  14050. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  14051. #endif
  14052. if( zeny > 0 ){
  14053. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  14054. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  14055. return;
  14056. }
  14057. }
  14058. mail_send(sd, receiver, title, text, realTextLength);
  14059. #endif
  14060. }
  14061. /// AUCTION SYSTEM
  14062. /// By Zephyrus
  14063. ///
  14064. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  14065. /// 025f <type>.L
  14066. /// type:
  14067. /// 0 = open
  14068. /// 1 = close
  14069. void clif_Auction_openwindow(struct map_session_data *sd)
  14070. {
  14071. int fd = sd->fd;
  14072. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  14073. return;
  14074. if( !battle_config.feature_auction )
  14075. return;
  14076. WFIFOHEAD(fd,packet_len(0x25f));
  14077. WFIFOW(fd,0) = 0x25f;
  14078. WFIFOL(fd,2) = 0;
  14079. WFIFOSET(fd,packet_len(0x25f));
  14080. }
  14081. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  14082. /// 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 }*
  14083. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  14084. {
  14085. int i, fd = sd->fd, len = sizeof(struct auction_data);
  14086. struct auction_data auction;
  14087. WFIFOHEAD(fd,12 + (count * 83));
  14088. WFIFOW(fd,0) = 0x252;
  14089. WFIFOW(fd,2) = 12 + (count * 83);
  14090. WFIFOL(fd,4) = pages;
  14091. WFIFOL(fd,8) = count;
  14092. for( i = 0; i < count; i++ ) {
  14093. int k = 12 + (i * 83);
  14094. memcpy(&auction, RBUFP(buf,i * len), len);
  14095. WFIFOL(fd,k) = auction.auction_id;
  14096. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  14097. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  14098. WFIFOL(fd,30+k) = auction.type;
  14099. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  14100. WFIFOB(fd,36+k) = auction.item.identify;
  14101. WFIFOB(fd,37+k) = auction.item.attribute;
  14102. WFIFOB(fd,38+k) = auction.item.refine;
  14103. WFIFOW(fd,39+k) = auction.item.card[0];
  14104. WFIFOW(fd,41+k) = auction.item.card[1];
  14105. WFIFOW(fd,43+k) = auction.item.card[2];
  14106. WFIFOW(fd,45+k) = auction.item.card[3];
  14107. WFIFOL(fd,47+k) = auction.price;
  14108. WFIFOL(fd,51+k) = auction.buynow;
  14109. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  14110. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  14111. }
  14112. WFIFOSET(fd,WFIFOW(fd,2));
  14113. }
  14114. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  14115. /// 0256 <index>.W <result>.B
  14116. /// result:
  14117. /// 0 = success
  14118. /// 1 = failure
  14119. static void clif_Auction_setitem(int fd, int index, bool fail)
  14120. {
  14121. WFIFOHEAD(fd,packet_len(0x256));
  14122. WFIFOW(fd,0) = 0x256;
  14123. WFIFOW(fd,2) = index;
  14124. WFIFOB(fd,4) = fail;
  14125. WFIFOSET(fd,packet_len(0x256));
  14126. }
  14127. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  14128. /// 024b <type>.W
  14129. /// type:
  14130. /// 0 = create (any other action in auction window)
  14131. /// 1 = cancel (cancel pressed on register tab)
  14132. /// ? = junk, uninitialized value (ex. when switching between list filters)
  14133. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  14134. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14135. if( sd->auction.amount > 0 )
  14136. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  14137. sd->auction.amount = 0;
  14138. }
  14139. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  14140. /// 024c <index>.W <count>.L
  14141. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  14142. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14143. int idx = RFIFOW(fd,info->pos[0]) - 2;
  14144. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  14145. if( !battle_config.feature_auction )
  14146. return;
  14147. if( sd->auction.amount > 0 )
  14148. sd->auction.amount = 0;
  14149. if( idx < 0 || idx >= MAX_INVENTORY ) {
  14150. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  14151. return;
  14152. }
  14153. 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.
  14154. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  14155. return;
  14156. }
  14157. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  14158. 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) )
  14159. { // Consumable or pets are not allowed
  14160. clif_Auction_setitem(sd->fd, idx, true);
  14161. return;
  14162. }
  14163. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  14164. !sd->inventory.u.items_inventory[idx].identify ||
  14165. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  14166. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  14167. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  14168. clif_Auction_setitem(sd->fd, idx, true);
  14169. return;
  14170. }
  14171. sd->auction.index = idx;
  14172. sd->auction.amount = amount;
  14173. clif_Auction_setitem(fd, idx + 2, false);
  14174. }
  14175. /// Result from an auction action (ZC_AUCTION_RESULT).
  14176. /// 0250 <result>.B
  14177. /// result:
  14178. /// 0 = You have failed to bid into the auction
  14179. /// 1 = You have successfully bid in the auction
  14180. /// 2 = The auction has been canceled
  14181. /// 3 = An auction with at least one bidder cannot be canceled
  14182. /// 4 = You cannot register more than 5 items in an auction at a time
  14183. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14184. /// 6 = You have won the auction
  14185. /// 7 = You have failed to win the auction
  14186. /// 8 = You do not have enough Zeny
  14187. /// 9 = You cannot place more than 5 bids at a time
  14188. void clif_Auction_message(int fd, unsigned char flag)
  14189. {
  14190. WFIFOHEAD(fd,packet_len(0x250));
  14191. WFIFOW(fd,0) = 0x250;
  14192. WFIFOB(fd,2) = flag;
  14193. WFIFOSET(fd,packet_len(0x250));
  14194. }
  14195. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14196. /// 025e <result>.W
  14197. /// result:
  14198. /// 0 = You have ended the auction
  14199. /// 1 = You cannot end the auction
  14200. /// 2 = Auction ID is incorrect
  14201. void clif_Auction_close(int fd, unsigned char flag)
  14202. {
  14203. WFIFOHEAD(fd,packet_len(0x25e));
  14204. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14205. WFIFOW(fd,2) = flag;
  14206. WFIFOSET(fd,packet_len(0x25e));
  14207. }
  14208. /// Request to add an auction (CZ_AUCTION_ADD).
  14209. /// 024d <now money>.L <max money>.L <delete hour>.W
  14210. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  14211. {
  14212. struct auction_data auction;
  14213. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14214. if( !battle_config.feature_auction )
  14215. return;
  14216. auction.price = RFIFOL(fd,info->pos[0]);
  14217. auction.buynow = RFIFOL(fd,info->pos[1]);
  14218. auction.hours = RFIFOW(fd,info->pos[2]);
  14219. // Invalid Situations...
  14220. if( sd->auction.amount < 1 ) {
  14221. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14222. return;
  14223. }
  14224. if( auction.price >= auction.buynow ) {
  14225. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14226. return;
  14227. }
  14228. if( auction.hours < 1 || auction.hours > 48 ) {
  14229. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14230. return;
  14231. }
  14232. // Auction checks...
  14233. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14234. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14235. clif_Auction_message(fd, 2); // The auction has been canceled
  14236. return;
  14237. }
  14238. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14239. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14240. return;
  14241. }
  14242. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14243. auction.buynow = battle_config.auction_maximumprice;
  14244. if( auction.price >= auction.buynow )
  14245. auction.price = auction.buynow - 1;
  14246. }
  14247. auction.auction_id = 0;
  14248. auction.seller_id = sd->status.char_id;
  14249. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14250. auction.buyer_id = 0;
  14251. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14252. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14253. {
  14254. clif_Auction_message(fd, 2); // The auction has been canceled
  14255. return;
  14256. }
  14257. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14258. if( id == nullptr )
  14259. { // Just in case
  14260. clif_Auction_message(fd, 2); // The auction has been canceled
  14261. return;
  14262. }
  14263. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14264. auction.type = id->type;
  14265. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14266. auction.item.amount = 1;
  14267. auction.timestamp = 0;
  14268. if( !intif_Auction_register(&auction) )
  14269. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14270. else
  14271. {
  14272. int zeny = auction.hours*battle_config.auction_feeperhour;
  14273. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14274. sd->auction.amount = 0;
  14275. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  14276. }
  14277. }
  14278. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14279. /// 024e <auction id>.L
  14280. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  14281. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14282. intif_Auction_cancel(sd->status.char_id, auction_id);
  14283. }
  14284. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14285. /// 025d <auction id>.L
  14286. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  14287. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14288. intif_Auction_close(sd->status.char_id, auction_id);
  14289. }
  14290. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14291. /// 024f <auction id>.L <money>.L
  14292. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  14293. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14294. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14295. int bid = RFIFOL(fd,info->pos[1]);
  14296. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14297. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14298. return;
  14299. }
  14300. if( bid <= 0 )
  14301. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14302. else if( bid > sd->status.zeny )
  14303. clif_Auction_message(fd, 8); // You do not have enough zeny
  14304. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14305. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14306. else {
  14307. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14308. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14309. }
  14310. }
  14311. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14312. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14313. /// search type:
  14314. /// 0 = armor
  14315. /// 1 = weapon
  14316. /// 2 = card
  14317. /// 3 = misc
  14318. /// 4 = name search
  14319. /// 5 = auction id search
  14320. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  14321. char search_text[NAME_LENGTH];
  14322. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14323. short type = RFIFOW(fd,info->pos[0]);
  14324. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14325. int page = RFIFOW(fd,info->pos[3]);
  14326. if( !battle_config.feature_auction )
  14327. return;
  14328. clif_parse_Auction_cancelreg(fd, sd);
  14329. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14330. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14331. }
  14332. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14333. /// 025c <type>.W
  14334. /// type:
  14335. /// 0 = sell (own auctions)
  14336. /// 1 = buy (own bids)
  14337. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  14338. {
  14339. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14340. if( !battle_config.feature_auction )
  14341. return;
  14342. clif_parse_Auction_cancelreg(fd, sd);
  14343. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14344. }
  14345. /// CASH/POINT SHOP
  14346. ///
  14347. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  14348. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14349. nullpo_retv( sd );
  14350. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14351. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14352. p.cashPoints = sd->cashPoints;
  14353. p.kafraPoints = sd->kafraPoints;
  14354. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14355. p.tab = tab;
  14356. #endif
  14357. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14358. #endif
  14359. }
  14360. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  14361. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14362. nullpo_retv( sd );
  14363. int tab = 0;
  14364. #if PACKETVER >= 20191224
  14365. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14366. tab = p->tab;
  14367. #endif
  14368. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14369. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14370. return;
  14371. }
  14372. sd->state.cashshop_open = true;
  14373. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14374. clif_cashshop_open( sd, tab );
  14375. #endif
  14376. }
  14377. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14378. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14379. sd->state.cashshop_open = false;
  14380. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14381. // No need to do anything here
  14382. #endif
  14383. }
  14384. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14385. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14386. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14387. // [4144] packet exists only in 2011 and was dropped after
  14388. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14389. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14390. int j;
  14391. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14392. return;
  14393. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14394. WFIFOW(fd, 0) = 0x8c0;
  14395. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14396. WFIFOL(fd, 4) = tab;
  14397. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14398. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14399. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14400. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14401. }
  14402. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14403. #endif
  14404. }
  14405. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14406. void clif_cashshop_list( struct map_session_data* sd ){
  14407. nullpo_retv( sd );
  14408. int fd = sd->fd;
  14409. if( !session_isActive( fd ) ){
  14410. return;
  14411. }
  14412. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14413. // Skip empty tabs, the client only expects filled ones
  14414. if( cash_shop_items[tab].count == 0 ){
  14415. continue;
  14416. }
  14417. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14418. WFIFOHEAD( fd, len );
  14419. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14420. p->packetType = 0x8ca;
  14421. p->packetLength = len;
  14422. p->count = cash_shop_items[tab].count;
  14423. p->tabNum = tab;
  14424. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14425. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14426. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14427. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14428. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14429. if( id == nullptr ){
  14430. p->items[i].location = 0;
  14431. p->items[i].viewSprite = 0;
  14432. }else{
  14433. p->items[i].location = pc_equippoint_sub( sd, id );
  14434. p->items[i].viewSprite = id->look;
  14435. }
  14436. #endif
  14437. }
  14438. WFIFOSET( fd, len );
  14439. }
  14440. }
  14441. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14442. if( !sd->status.cashshop_sent ) {
  14443. clif_cashshop_list( sd );
  14444. #if PACKETVER_SUPPORTS_SALES
  14445. sale_notify_login(sd);
  14446. #endif
  14447. sd->status.cashshop_sent = true;
  14448. }
  14449. }
  14450. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14451. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14452. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14453. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14454. nullpo_retv( sd );
  14455. nullpo_retv( nd );
  14456. int fd = sd->fd;
  14457. if( !session_isActive( fd ) ){
  14458. return;
  14459. }
  14460. sd->npc_shopid = nd->bl.id;
  14461. int cost[2] = { 0, 0 };
  14462. npc_shop_currency_type( sd, nd, cost, true );
  14463. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14464. WFIFOHEAD( fd, len );
  14465. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14466. p->packetType = 0x287;
  14467. p->packetLength = len;
  14468. p->cashPoints = cost[0];
  14469. #if PACKETVER >= 20070711
  14470. p->kafraPoints = cost[1];
  14471. #endif
  14472. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14473. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14474. p->items[i].price = nd->u.shop.shop_item[i].value;
  14475. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14476. p->items[i].itemType = itemtype( id->nameid );
  14477. p->items[i].itemId = client_nameid( id->nameid );
  14478. }
  14479. WFIFOSET( fd, len );
  14480. }
  14481. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14482. /// 0289 <cash point>.L <error>.W
  14483. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14484. /// error:
  14485. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14486. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14487. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14488. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14489. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14490. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14491. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14492. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14493. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14494. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14495. {
  14496. int fd, cost[2] = { 0, 0 };
  14497. struct npc_data *nd;
  14498. nullpo_retv(sd);
  14499. fd = sd->fd;
  14500. nd = map_id2nd(sd->npc_shopid);
  14501. npc_shop_currency_type(sd, nd, cost, false);
  14502. WFIFOHEAD(fd, packet_len(0x289));
  14503. WFIFOW(fd,0) = 0x289;
  14504. WFIFOL(fd,2) = cost[0];
  14505. #if PACKETVER < 20070711
  14506. WFIFOW(fd,6) = TOW(error);
  14507. #else
  14508. WFIFOL(fd,6) = cost[1];
  14509. WFIFOW(fd,10) = TOW(error);
  14510. #endif
  14511. WFIFOSET(fd, packet_len(0x289));
  14512. }
  14513. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14514. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14515. nullpo_retv( sd );
  14516. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14517. packet.packetType = 0x849;
  14518. if( item_id != 0 ){
  14519. packet.itemId = client_nameid( item_id );
  14520. }else{
  14521. packet.itemId = 0;
  14522. }
  14523. packet.result = result;
  14524. packet.cashPoints = sd->cashPoints;
  14525. packet.kafraPoints = sd->kafraPoints;
  14526. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14527. #endif
  14528. }
  14529. /// Request to buy item(s) from cash shop.
  14530. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14531. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14532. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14533. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14534. nullpo_retv( sd );
  14535. if( sd->state.trading || !sd->npc_shopid ){
  14536. clif_cashshop_ack( sd, 1 );
  14537. return;
  14538. }
  14539. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14540. #if PACKETVER < 20070711
  14541. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14542. #elif PACKETVER < 20101116
  14543. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14544. #else
  14545. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14546. 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 ){
  14547. 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 );
  14548. return;
  14549. }
  14550. std::vector<s_npc_buy_list> item_list = {};
  14551. item_list.reserve( p->count );
  14552. for( int i = 0; i < p->count; i++ ){
  14553. s_npc_buy_list item = {};
  14554. item.nameid = p->items[i].itemId;
  14555. item.qty = p->items[i].amount;
  14556. item_list.push_back( item );
  14557. }
  14558. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14559. #endif
  14560. }
  14561. /// Request to buy item(s) from cash shop.
  14562. /// 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)
  14563. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14564. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14565. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14566. 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 ){
  14567. 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 );
  14568. return;
  14569. }
  14570. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14571. }
  14572. /// Adoption System
  14573. ///
  14574. /// Adoption message (ZC_BABYMSG).
  14575. /// 0216 <msg>.L
  14576. /// msg:
  14577. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14578. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14579. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14580. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14581. {
  14582. int fd = sd->fd;
  14583. WFIFOHEAD(fd,6);
  14584. WFIFOW(fd,0) = 0x216;
  14585. WFIFOL(fd,2) = type;
  14586. WFIFOSET(fd,6);
  14587. }
  14588. /// Adoption confirmation (ZC_REQ_BABY).
  14589. /// 01f6 <account id>.L <char id>.L <name>.B
  14590. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14591. {
  14592. int fd = sd->fd;
  14593. WFIFOHEAD(fd,34);
  14594. WFIFOW(fd,0) = 0x1f6;
  14595. WFIFOL(fd,2) = src->status.account_id;
  14596. WFIFOL(fd,6) = p_id;
  14597. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14598. WFIFOSET(fd,34);
  14599. }
  14600. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14601. /// 01f9 <account id>.L
  14602. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14603. {
  14604. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14605. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14606. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14607. {
  14608. tsd->adopt_invite = sd->status.account_id;
  14609. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14610. }
  14611. }
  14612. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14613. /// 01f7 <account id>.L <char id>.L <answer>.L
  14614. /// answer:
  14615. /// 0 = rejected
  14616. /// 1 = accepted
  14617. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14618. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14619. int p1_id = RFIFOL(fd,info->pos[0]);
  14620. int p2_id = RFIFOL(fd,info->pos[1]);
  14621. int result = RFIFOL(fd,info->pos[2]);
  14622. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14623. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14624. int pid = sd->adopt_invite;
  14625. sd->adopt_invite = 0;
  14626. if( p1_sd == NULL || p2_sd == NULL )
  14627. return; // Both players need to be online
  14628. if( pid != p1_sd->status.account_id )
  14629. return; // Incorrect values
  14630. if( result == 0 )
  14631. return; // Rejected
  14632. pc_adoption(p1_sd, p2_sd, sd);
  14633. }
  14634. /// Convex Mirror (ZC_BOSS_INFO).
  14635. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14636. /// infoType:
  14637. /// BOSS_INFO_NOT = No boss on this map.
  14638. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14639. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14640. /// BOSS_INFO_DEAD = Boss is dead.
  14641. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14642. {
  14643. int fd = sd->fd;
  14644. WFIFOHEAD(fd,70);
  14645. memset(WFIFOP(fd,0),0,70);
  14646. WFIFOW(fd,0) = 0x293;
  14647. switch (flag) {
  14648. case BOSS_INFO_NOT:
  14649. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14650. // No data required
  14651. break;
  14652. case BOSS_INFO_ALIVE:
  14653. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14654. // Update X/Y
  14655. WFIFOL(fd,3) = md->bl.x;
  14656. WFIFOL(fd,7) = md->bl.y;
  14657. break;
  14658. case BOSS_INFO_ALIVE_WITHMSG:
  14659. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14660. // Current X/Y
  14661. WFIFOL(fd,3) = md->bl.x;
  14662. WFIFOL(fd,7) = md->bl.y;
  14663. break;
  14664. case BOSS_INFO_DEAD:
  14665. {
  14666. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14667. unsigned int seconds;
  14668. int hours, minutes;
  14669. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14670. hours = seconds / (60 * 60);
  14671. seconds = seconds - (60 * 60 * hours);
  14672. minutes = seconds / 60;
  14673. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14674. // Add respawn info
  14675. WFIFOW(fd,11) = hours; // Hours
  14676. WFIFOW(fd,13) = minutes; // Minutes
  14677. }
  14678. break;
  14679. }
  14680. if (md != NULL)
  14681. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14682. WFIFOSET(fd,70);
  14683. }
  14684. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14685. /// 02d6 <account id>.L
  14686. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14687. {
  14688. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14689. struct map_session_data* tsd = map_id2sd(aid);
  14690. if (!tsd)
  14691. return;
  14692. if (sd->bl.m != tsd->bl.m)
  14693. return;
  14694. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14695. clif_viewequip_ack(sd, tsd);
  14696. else
  14697. clif_msg(sd, VIEW_EQUIP_FAIL);
  14698. }
  14699. /// Request to a configuration.
  14700. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14701. /// type: see enum e_config_type
  14702. /// flag:
  14703. /// false = disabled
  14704. /// true = enabled
  14705. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14706. int cmd = RFIFOW(fd,0);
  14707. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14708. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14709. switch( type ){
  14710. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14711. sd->status.show_equip = flag;
  14712. break;
  14713. case CONFIG_CALL:
  14714. sd->status.disable_call = flag;
  14715. break;
  14716. case CONFIG_PET_AUTOFEED:
  14717. // Player can not click this if he does not have a pet
  14718. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14719. return;
  14720. }
  14721. sd->pd->pet.autofeed = flag;
  14722. break;
  14723. case CONFIG_HOMUNCULUS_AUTOFEED:
  14724. // Player can not click this if he does not have a homunculus or it is vaporized
  14725. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14726. return;
  14727. }
  14728. sd->hd->homunculus.autofeed = flag;
  14729. break;
  14730. default:
  14731. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14732. return;
  14733. }
  14734. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14735. }
  14736. /// Request to change party invitation tick.
  14737. /// value:
  14738. /// 0 = disabled
  14739. /// 1 = enabled
  14740. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14741. {
  14742. bool flag = RFIFOB(fd,6) ? true : false;
  14743. sd->status.allow_party = flag;
  14744. clif_partytickack(sd, flag);
  14745. }
  14746. /// Questlog System [Kevin] [Inkfish]
  14747. ///
  14748. /**
  14749. * Safe check to init packet len & quest num for player.
  14750. * @param def_len
  14751. * @param info_len Length of each quest info.
  14752. * @param avail_quests Avail quests that player has.
  14753. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14754. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14755. **/
  14756. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14757. (*limit_out) = (0xFFFF - def_len) / info_len;
  14758. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14759. (*len_out) = ((*limit_out) * info_len) + def_len;
  14760. }
  14761. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14762. std::string race_name;
  14763. switch( objective->race ){
  14764. case RC_FORMLESS: race_name = "Formless"; break;
  14765. case RC_UNDEAD: race_name = "Undead"; break;
  14766. case RC_BRUTE: race_name = "Brute"; break;
  14767. case RC_PLANT: race_name = "Plant"; break;
  14768. case RC_INSECT: race_name = "Insect"; break;
  14769. case RC_FISH: race_name = "Fish"; break;
  14770. case RC_DEMON: race_name = "Demon"; break;
  14771. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14772. case RC_ANGEL: race_name = "Angel"; break;
  14773. case RC_DRAGON: race_name = "Dragon"; break;
  14774. default:
  14775. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14776. // Fallthrough
  14777. case RC_ALL: race_name = ""; break;
  14778. }
  14779. std::string size_name;
  14780. switch( objective->size ){
  14781. case SZ_SMALL: size_name = "Small"; break;
  14782. case SZ_MEDIUM: size_name = "Medium"; break;
  14783. case SZ_BIG: size_name = "Large"; break;
  14784. default:
  14785. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14786. // Fallthrough
  14787. case SZ_ALL: size_name = ""; break;
  14788. }
  14789. std::string ele_name;
  14790. switch( objective->element ){
  14791. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14792. case ELE_WATER: ele_name = "Water Element"; break;
  14793. case ELE_EARTH: ele_name = "Earth Element"; break;
  14794. case ELE_FIRE: ele_name = "Fire Element"; break;
  14795. case ELE_WIND: ele_name = "Wind Element"; break;
  14796. case ELE_POISON: ele_name = "Poison Element"; break;
  14797. case ELE_HOLY: ele_name = "Holy Element"; break;
  14798. case ELE_DARK: ele_name = "Shadow Element"; break;
  14799. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14800. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14801. default:
  14802. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14803. // Fallthrough
  14804. case ELE_ALL: ele_name = ""; break;
  14805. }
  14806. std::string str;
  14807. if( !objective->map_name.empty() ){
  14808. str += objective->map_name;
  14809. }
  14810. if( !race_name.empty() ){
  14811. if( !str.empty() ){
  14812. str += ", ";
  14813. }
  14814. str += race_name;
  14815. }
  14816. if( !size_name.empty() ){
  14817. if( !str.empty() ){
  14818. str += ", ";
  14819. }
  14820. str += size_name;
  14821. }
  14822. if( !ele_name.empty() ){
  14823. if( !str.empty() ){
  14824. str += ", ";
  14825. }
  14826. str += ele_name;
  14827. }
  14828. return str;
  14829. }
  14830. /// Sends list of all quest states
  14831. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14832. /// 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)
  14833. /// 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)
  14834. void clif_quest_send_list(struct map_session_data *sd)
  14835. {
  14836. nullpo_retv(sd);
  14837. int fd = sd->fd;
  14838. int i;
  14839. int offset = 8;
  14840. int limit = 0;
  14841. #if PACKETVER >= 20141022
  14842. #if PACKETVER >= 20150513
  14843. int size = 22 + NAME_LENGTH;
  14844. #else
  14845. int size = 10 + NAME_LENGTH;
  14846. #endif
  14847. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14848. WFIFOHEAD(fd,i);
  14849. #if PACKETVER >= 20150513
  14850. WFIFOW(fd, 0) = 0x9f8;
  14851. #else
  14852. WFIFOW(fd, 0) = 0x97a;
  14853. #endif
  14854. WFIFOL(fd, 4) = limit;
  14855. for (i = 0; i < limit; i++) {
  14856. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14857. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14858. offset += 4;
  14859. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14860. offset++;
  14861. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14862. offset += 4;
  14863. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14864. offset += 4;
  14865. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14866. offset += 2;
  14867. if (!qi->objectives.empty()) {
  14868. std::shared_ptr<s_mob_db> mob;
  14869. for (int j = 0; j < qi->objectives.size(); j++) {
  14870. mob = mob_db.find(qi->objectives[j]->mob_id);
  14871. e_race race = qi->objectives[j]->race;
  14872. e_size size = qi->objectives[j]->size;
  14873. e_element element = qi->objectives[j]->element;
  14874. #if PACKETVER >= 20150513
  14875. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14876. offset += 4;
  14877. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14878. offset += 4;
  14879. #endif
  14880. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14881. offset += 4;
  14882. #if PACKETVER >= 20150513
  14883. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14884. offset += 2;
  14885. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14886. offset += 2;
  14887. #endif
  14888. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14889. offset += 2;
  14890. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14891. offset += 2;
  14892. if (mob && qi->objectives[j]->mob_id > 0)
  14893. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14894. else
  14895. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14896. offset += NAME_LENGTH;
  14897. }
  14898. }
  14899. }
  14900. WFIFOW(fd, 2) = offset;
  14901. WFIFOSET(fd, offset);
  14902. #else
  14903. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14904. WFIFOHEAD(fd,i);
  14905. WFIFOW(fd, 0) = 0x2b1;
  14906. WFIFOL(fd, 4) = limit;
  14907. for (i = 0; i < limit; i++) {
  14908. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14909. offset += 4;
  14910. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14911. offset += 1;
  14912. }
  14913. WFIFOW(fd, 2) = offset;
  14914. WFIFOSET(fd, offset);
  14915. #endif
  14916. }
  14917. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14918. /// 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
  14919. void clif_quest_send_mission(struct map_session_data *sd)
  14920. {
  14921. nullpo_retv(sd);
  14922. int fd = sd->fd;
  14923. int limit = 0;
  14924. int len = sd->avail_quests*104+8;
  14925. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14926. WFIFOHEAD(fd, len);
  14927. WFIFOW(fd, 0) = 0x2b2;
  14928. WFIFOW(fd, 2) = len;
  14929. WFIFOL(fd, 4) = limit;
  14930. for (int i = 0; i < limit; i++) {
  14931. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14932. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14933. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14934. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14935. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14936. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14937. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14938. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14939. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14940. if (mob && qi->objectives[j]->mob_id > 0)
  14941. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14942. else
  14943. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14944. }
  14945. }
  14946. WFIFOSET(fd, len);
  14947. }
  14948. /// Notification about a new quest
  14949. /// 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)
  14950. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14951. /// 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)
  14952. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14953. {
  14954. nullpo_retv(sd);
  14955. nullpo_retv(qd);
  14956. int fd = sd->fd;
  14957. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14958. if (!qi)
  14959. return;
  14960. #if PACKETVER >= 20150513
  14961. int cmd = 0x9f9;
  14962. #else
  14963. int cmd = 0x2b3;
  14964. #endif
  14965. WFIFOHEAD(fd, packet_len(cmd));
  14966. WFIFOW(fd, 0) = cmd;
  14967. WFIFOL(fd, 2) = qd->quest_id;
  14968. WFIFOB(fd, 6) = qd->state;
  14969. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14970. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14971. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14972. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14973. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14974. e_race race = qi->objectives[i]->race;
  14975. e_size size = qi->objectives[i]->size;
  14976. e_element element = qi->objectives[i]->element;
  14977. #if PACKETVER >= 20150513
  14978. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14979. offset += 4;
  14980. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14981. offset += 4;
  14982. #endif
  14983. 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
  14984. offset += 4;
  14985. #if PACKETVER >= 20150513
  14986. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14987. offset += 2;
  14988. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14989. offset += 2;
  14990. #endif
  14991. WFIFOW(fd, offset) = qd->count[i];
  14992. offset += 2;
  14993. if (mob && qi->objectives[i]->mob_id > 0)
  14994. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14995. else
  14996. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14997. offset += NAME_LENGTH;
  14998. }
  14999. WFIFOSET(fd, packet_len(cmd));
  15000. #if PACKETVER >= 20150513
  15001. int len = 4 + qi->objectives.size() * 12;
  15002. WFIFOHEAD(fd, len);
  15003. WFIFOW(fd, 0) = 0x8fe;
  15004. WFIFOW(fd, 2) = len;
  15005. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  15006. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15007. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  15008. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  15009. WFIFOW(fd, offset + 10) = qd->count[i];
  15010. }
  15011. WFIFOSET(fd, len);
  15012. #endif
  15013. }
  15014. /// Notification about a quest being removed (ZC_DEL_QUEST).
  15015. /// 02b4 <quest id>.L
  15016. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  15017. {
  15018. int fd = sd->fd;
  15019. WFIFOHEAD(fd, packet_len(0x2b4));
  15020. WFIFOW(fd, 0) = 0x2b4;
  15021. WFIFOL(fd, 2) = quest_id;
  15022. WFIFOSET(fd, packet_len(0x2b4));
  15023. }
  15024. /// Notification of an update to the hunting mission counter
  15025. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  15026. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  15027. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  15028. {
  15029. int fd = sd->fd;
  15030. int offset = 6;
  15031. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  15032. int len = qi->objectives.size() * 12 + 6;
  15033. #if PACKETVER >= 20150513
  15034. int cmd = 0x9fa;
  15035. #else
  15036. int cmd = 0x2b5;
  15037. #endif
  15038. WFIFOHEAD(fd, len);
  15039. WFIFOW(fd, 0) = cmd;
  15040. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  15041. for (int i = 0; i < qi->objectives.size(); i++) {
  15042. WFIFOL(fd, offset) = qd->quest_id;
  15043. offset += 4;
  15044. #if PACKETVER >= 20150513
  15045. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15046. offset += 4;
  15047. #else
  15048. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  15049. offset += 4;
  15050. #endif
  15051. WFIFOW(fd, offset) = qi->objectives[i]->count;
  15052. offset += 2;
  15053. WFIFOW(fd, offset) = qd->count[i];
  15054. offset += 2;
  15055. }
  15056. WFIFOW(fd, 2) = offset;
  15057. WFIFOSET(fd, offset);
  15058. }
  15059. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  15060. /// 02b6 <quest id>.L <active>.B
  15061. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  15062. {
  15063. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15064. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  15065. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  15066. }
  15067. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  15068. /// 02b7 <quest id>.L <active>.B
  15069. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  15070. {
  15071. int fd = sd->fd;
  15072. WFIFOHEAD(fd, packet_len(0x2b7));
  15073. WFIFOW(fd, 0) = 0x2b7;
  15074. WFIFOL(fd, 2) = quest_id;
  15075. WFIFOB(fd, 6) = active;
  15076. WFIFOSET(fd, packet_len(0x2b7));
  15077. }
  15078. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  15079. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  15080. /// effect:
  15081. /// 0 = none
  15082. /// 1 = exclamation mark icon
  15083. /// 2 = question mark icon
  15084. /// color:
  15085. /// 0 = yellow
  15086. /// 1 = orange
  15087. /// 2 = green
  15088. /// 3 = purple
  15089. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  15090. {
  15091. #if PACKETVER >= 20090218
  15092. nullpo_retv(sd);
  15093. nullpo_retv(bl);
  15094. int fd = sd->fd;
  15095. WFIFOHEAD(fd, packet_len(0x446));
  15096. WFIFOW(fd, 0) = 0x446;
  15097. WFIFOL(fd, 2) = bl->id;
  15098. WFIFOW(fd, 6) = bl->x;
  15099. WFIFOW(fd, 8) = bl->y;
  15100. WFIFOW(fd, 10) = effect;
  15101. WFIFOW(fd, 12) = color;
  15102. WFIFOSET(fd, packet_len(0x446));
  15103. #endif
  15104. }
  15105. /// Mercenary System
  15106. ///
  15107. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  15108. /// 02a2 <var id>.W <value>.L
  15109. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  15110. {
  15111. s_mercenary_data *md;
  15112. struct status_data *status;
  15113. int fd;
  15114. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15115. return;
  15116. fd = sd->fd;
  15117. status = &md->battle_status;
  15118. WFIFOHEAD(fd,packet_len(0x2a2));
  15119. WFIFOW(fd,0) = 0x2a2;
  15120. WFIFOW(fd,2) = type;
  15121. switch( type ) {
  15122. case SP_ATK1:
  15123. {
  15124. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15125. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  15126. }
  15127. break;
  15128. case SP_MATK1:
  15129. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  15130. break;
  15131. case SP_HIT:
  15132. WFIFOL(fd,4) = status->hit;
  15133. break;
  15134. case SP_CRITICAL:
  15135. WFIFOL(fd,4) = status->cri/10;
  15136. break;
  15137. case SP_DEF1:
  15138. WFIFOL(fd,4) = status->def;
  15139. break;
  15140. case SP_MDEF1:
  15141. WFIFOL(fd,4) = status->mdef;
  15142. break;
  15143. case SP_MERCFLEE:
  15144. WFIFOL(fd,4) = status->flee;
  15145. break;
  15146. case SP_ASPD:
  15147. WFIFOL(fd,4) = status->amotion;
  15148. break;
  15149. case SP_HP:
  15150. WFIFOL(fd,4) = status->hp;
  15151. break;
  15152. case SP_MAXHP:
  15153. WFIFOL(fd,4) = status->max_hp;
  15154. break;
  15155. case SP_SP:
  15156. WFIFOL(fd,4) = status->sp;
  15157. break;
  15158. case SP_MAXSP:
  15159. WFIFOL(fd,4) = status->max_sp;
  15160. break;
  15161. case SP_MERCKILLS:
  15162. WFIFOL(fd,4) = md->mercenary.kill_count;
  15163. break;
  15164. case SP_MERCFAITH:
  15165. WFIFOL(fd,4) = mercenary_get_faith(md);
  15166. break;
  15167. }
  15168. WFIFOSET(fd,packet_len(0x2a2));
  15169. }
  15170. /// Mercenary base status data (ZC_MER_INIT).
  15171. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  15172. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  15173. /// <calls>.L <kills>.L <atk range>.W
  15174. void clif_mercenary_info(struct map_session_data *sd)
  15175. {
  15176. int fd;
  15177. s_mercenary_data *md;
  15178. struct status_data *status;
  15179. int atk;
  15180. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15181. return;
  15182. fd = sd->fd;
  15183. status = &md->battle_status;
  15184. WFIFOHEAD(fd,packet_len(0x29b));
  15185. WFIFOW(fd,0) = 0x29b;
  15186. WFIFOL(fd,2) = md->bl.id;
  15187. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15188. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15189. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15190. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15191. WFIFOW(fd,10) = status->hit;
  15192. WFIFOW(fd,12) = status->cri/10;
  15193. WFIFOW(fd,14) = status->def;
  15194. WFIFOW(fd,16) = status->mdef;
  15195. WFIFOW(fd,18) = status->flee;
  15196. WFIFOW(fd,20) = status->amotion;
  15197. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15198. WFIFOW(fd,46) = md->db->lv;
  15199. WFIFOL(fd,48) = status->hp;
  15200. WFIFOL(fd,52) = status->max_hp;
  15201. WFIFOL(fd,56) = status->sp;
  15202. WFIFOL(fd,60) = status->max_sp;
  15203. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15204. WFIFOW(fd,68) = mercenary_get_faith(md);
  15205. WFIFOL(fd,70) = mercenary_get_calls(md);
  15206. WFIFOL(fd,74) = md->mercenary.kill_count;
  15207. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15208. WFIFOSET(fd,packet_len(0x29b));
  15209. }
  15210. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15211. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15212. void clif_mercenary_skillblock(struct map_session_data *sd)
  15213. {
  15214. s_mercenary_data *md;
  15215. int fd, len = 4;
  15216. if( sd == NULL || (md = sd->md) == NULL )
  15217. return;
  15218. fd = sd->fd;
  15219. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15220. WFIFOW(fd,0) = 0x29d;
  15221. for (const auto &it : md->db->skill) {
  15222. uint16 id = it.first;
  15223. if (!SKILL_CHK_MERC(id))
  15224. continue;
  15225. uint16 lv = it.second;
  15226. WFIFOW(fd,len) = id;
  15227. WFIFOL(fd,len+2) = skill_get_inf(id);
  15228. WFIFOW(fd,len+6) = lv;
  15229. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15230. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15231. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15232. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15233. len += 37;
  15234. }
  15235. WFIFOW(fd,2) = len;
  15236. WFIFOSET(fd,len);
  15237. }
  15238. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15239. /// 029f <command>.B
  15240. /// 1 = mercenary information
  15241. /// 2 = delete
  15242. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  15243. {
  15244. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15245. if( sd->md == NULL )
  15246. return;
  15247. if( option == 2 ) mercenary_delete(sd->md, 2);
  15248. }
  15249. /// Mercenary Message
  15250. /// message:
  15251. /// 0 = Mercenary soldier's duty hour is over.
  15252. /// 1 = Your mercenary soldier has been killed.
  15253. /// 2 = Your mercenary soldier has been fired.
  15254. /// 3 = Your mercenary soldier has ran away.
  15255. void clif_mercenary_message(struct map_session_data* sd, int message){
  15256. clif_msg(sd, MERC_MSG_BASE + message);
  15257. }
  15258. /// Notification about the remaining time of a rental item.
  15259. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15260. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  15261. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15262. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15263. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15264. p.itemId = client_nameid( nameid );
  15265. p.seconds = seconds;
  15266. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15267. }
  15268. /// Deletes a rental item from client's inventory.
  15269. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15270. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  15271. // '<ItemName>' item has been deleted from the Inventory
  15272. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15273. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15274. p.index = client_index( index );
  15275. p.itemId = client_nameid( nameid );
  15276. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15277. }
  15278. /// Book Reading (ZC_READ_BOOK).
  15279. /// 0294 <book id>.L <page>.L
  15280. void clif_readbook(int fd, int book_id, int page)
  15281. {
  15282. WFIFOHEAD(fd,packet_len(0x294));
  15283. WFIFOW(fd,0) = 0x294;
  15284. WFIFOL(fd,2) = book_id;
  15285. WFIFOL(fd,6) = page;
  15286. WFIFOSET(fd,packet_len(0x294));
  15287. }
  15288. /// Battlegrounds
  15289. ///
  15290. /// Updates HP bar of a camp member.
  15291. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15292. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15293. void clif_bg_hp(struct map_session_data *sd) {
  15294. #if PACKETVER < 20140613
  15295. unsigned char buf[34];
  15296. const int cmd = 0x2e0;
  15297. #else
  15298. unsigned char buf[14];
  15299. const int cmd = 0xa0e;
  15300. #endif
  15301. nullpo_retv(sd);
  15302. WBUFW(buf,0) = cmd;
  15303. WBUFL(buf,2) = sd->status.account_id;
  15304. #if PACKETVER < 20140613
  15305. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15306. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15307. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15308. WBUFW(buf,32) = 100;
  15309. } else {
  15310. WBUFW(buf,30) = sd->battle_status.hp;
  15311. WBUFW(buf,32) = sd->battle_status.max_hp;
  15312. }
  15313. #else
  15314. if( sd->battle_status.max_hp > INT32_MAX ) {
  15315. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15316. WBUFL(buf,10) = 100;
  15317. } else {
  15318. WBUFL(buf,6) = sd->battle_status.hp;
  15319. WBUFL(buf,10) = sd->battle_status.max_hp;
  15320. }
  15321. #endif
  15322. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15323. }
  15324. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15325. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15326. void clif_bg_xy(struct map_session_data *sd)
  15327. {
  15328. unsigned char buf[36];
  15329. nullpo_retv(sd);
  15330. WBUFW(buf,0)=0x2df;
  15331. WBUFL(buf,2)=sd->status.account_id;
  15332. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15333. WBUFW(buf,30)=sd->status.class_;
  15334. WBUFW(buf,32)=sd->bl.x;
  15335. WBUFW(buf,34)=sd->bl.y;
  15336. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15337. }
  15338. void clif_bg_xy_remove(struct map_session_data *sd)
  15339. {
  15340. unsigned char buf[36];
  15341. nullpo_retv(sd);
  15342. WBUFW(buf,0)=0x2df;
  15343. WBUFL(buf,2)=sd->status.account_id;
  15344. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15345. WBUFW(buf,30)=0;
  15346. WBUFW(buf,32)=-1;
  15347. WBUFW(buf,34)=-1;
  15348. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15349. }
  15350. /// Notifies clients of a battleground message.
  15351. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15352. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15353. struct map_session_data *sd = bg_getavailablesd( bg );
  15354. if( sd == nullptr ){
  15355. return;
  15356. }
  15357. // limit length
  15358. len = min( len + 1, CHAT_SIZE_MAX );
  15359. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15360. WBUFW(buf,0) = 0x2dc;
  15361. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15362. WBUFL(buf,4) = src_id;
  15363. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15364. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15365. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15366. }
  15367. /// Validates and processes battlechat messages.
  15368. /// All messages that are sent after enabling battleground chat with /battlechat.
  15369. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15370. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  15371. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15372. if( !clif_process_message( sd, false, name, message, output ) )
  15373. return;
  15374. bg_send_message(sd, output, strlen(output) );
  15375. }
  15376. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15377. /// 02de <camp A points>.W <camp B points>.W
  15378. void clif_bg_updatescore(int16 m)
  15379. {
  15380. struct block_list bl;
  15381. unsigned char buf[6];
  15382. struct map_data *mapdata = map_getmapdata(m);
  15383. bl.id = 0;
  15384. bl.type = BL_NUL;
  15385. bl.m = m;
  15386. WBUFW(buf,0) = 0x2de;
  15387. WBUFW(buf,2) = mapdata->bgscore_lion;
  15388. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15389. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15390. }
  15391. void clif_bg_updatescore_single(struct map_session_data *sd)
  15392. {
  15393. int fd;
  15394. nullpo_retv(sd);
  15395. fd = sd->fd;
  15396. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15397. WFIFOHEAD(fd,packet_len(0x2de));
  15398. WFIFOW(fd,0) = 0x2de;
  15399. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15400. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15401. WFIFOSET(fd,packet_len(0x2de));
  15402. }
  15403. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15404. /// 02dd <account id>.L <name>.24B <camp>.W
  15405. void clif_sendbgemblem_area(struct map_session_data *sd)
  15406. {
  15407. unsigned char buf[33];
  15408. nullpo_retv(sd);
  15409. WBUFW(buf, 0) = 0x2dd;
  15410. WBUFL(buf,2) = sd->bl.id;
  15411. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15412. WBUFW(buf,30) = sd->bg_id;
  15413. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15414. }
  15415. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15416. {
  15417. nullpo_retv(sd);
  15418. WFIFOHEAD(fd,32);
  15419. WFIFOW(fd,0) = 0x2dd;
  15420. WFIFOL(fd,2) = sd->bl.id;
  15421. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15422. WFIFOW(fd,30) = sd->bg_id;
  15423. WFIFOSET(fd,packet_len(0x2dd));
  15424. }
  15425. /// Battlegrounds queue incoming apply request from client.
  15426. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15427. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15428. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15429. {
  15430. if (!battle_config.feature_bgqueue)
  15431. return;
  15432. nullpo_retv(sd);
  15433. short type = RFIFOW(fd,2);
  15434. char name[NAME_LENGTH];
  15435. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15436. if (sd->bg_queue_id > 0) {
  15437. //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);
  15438. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15439. return;
  15440. } else if (type == 1) // Solo
  15441. bg_queue_join_solo(name, sd);
  15442. else if (type == 2) // Party
  15443. bg_queue_join_party(name, sd);
  15444. else if (type == 4) // Guild
  15445. bg_queue_join_guild(name, sd);
  15446. else {
  15447. 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);
  15448. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15449. return;
  15450. }
  15451. }
  15452. /// Outgoing battlegrounds queue apply result.
  15453. /// Result types: @see e_bg_queue_apply_ack
  15454. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15455. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15456. {
  15457. nullpo_retv(sd);
  15458. int fd = sd->fd;
  15459. WFIFOHEAD(fd, packet_len(0x8d8));
  15460. WFIFOW(fd,0) = 0x8d8;
  15461. WFIFOB(fd,2) = result;
  15462. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15463. WFIFOSET(fd, packet_len(0x8d8));
  15464. }
  15465. /// Outgoing battlegrounds queue apply notification.
  15466. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15467. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15468. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15469. {
  15470. nullpo_retv(sd);
  15471. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15472. if (queue == nullptr) {
  15473. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15474. return;
  15475. }
  15476. int fd = sd->fd;
  15477. WFIFOHEAD(fd, packet_len(0x8d9));
  15478. WFIFOW(fd,0) = 0x8d9;
  15479. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15480. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15481. WFIFOSET(fd, packet_len(0x8d9));
  15482. }
  15483. /// Battlegrounds queue outgoing cancel result.
  15484. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15485. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15486. {
  15487. nullpo_retv(sd);
  15488. int fd = sd->fd;
  15489. WFIFOHEAD(fd, packet_len(0x8d8));
  15490. WFIFOW(fd,0) = 0x8db;
  15491. WFIFOB(fd,2) = success;
  15492. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15493. WFIFOSET(fd, packet_len(0x8d8));
  15494. }
  15495. /// Battlegrounds queue incoming cancel request from client.
  15496. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15497. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15498. {
  15499. if (!battle_config.feature_bgqueue)
  15500. return;
  15501. nullpo_retv(sd);
  15502. bool success;
  15503. if (sd->bg_queue_id > 0) {
  15504. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15505. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15506. 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.
  15507. else
  15508. success = bg_queue_leave(sd);
  15509. } else {
  15510. 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);
  15511. success = false;
  15512. }
  15513. char name[NAME_LENGTH];
  15514. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15515. clif_bg_queue_cancel_result(success, name, sd);
  15516. }
  15517. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15518. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15519. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15520. {
  15521. nullpo_retv(sd);
  15522. int fd = sd->fd;
  15523. WFIFOHEAD(fd, packet_len(0x8df));
  15524. WFIFOW(fd,0) = 0x8df;
  15525. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15526. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15527. WFIFOSET(fd, packet_len(0x8df));
  15528. }
  15529. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15530. /// Result types: 1(Accept), 2(Decline).
  15531. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15532. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15533. {
  15534. nullpo_retv(sd);
  15535. if(sd->bg_queue_id > 0) {
  15536. uint8 result = RFIFOB(fd, 2);
  15537. if(result == 1) { // Accept
  15538. bg_queue_on_accept_invite(sd);
  15539. } else if(result == 2) { // Decline
  15540. bg_queue_leave(sd);
  15541. clif_bg_queue_entry_init(sd);
  15542. }
  15543. }
  15544. }
  15545. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15546. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15547. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15548. {
  15549. nullpo_retv(sd);
  15550. int fd = sd->fd;
  15551. WFIFOHEAD(fd, packet_len(0x8e1));
  15552. WFIFOW(fd,0) = 0x8e1;
  15553. WFIFOB(fd,2) = result;
  15554. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15555. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15556. WFIFOSET(fd, packet_len(0x8e1));
  15557. }
  15558. /// Battlegrounds queue incoming queue number request from client.
  15559. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15560. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15561. {
  15562. nullpo_retv(sd);
  15563. char name[NAME_LENGTH];
  15564. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15565. clif_bg_queue_apply_notify(name, sd);
  15566. }
  15567. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15568. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15569. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15570. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15571. {
  15572. nullpo_retv(sd);
  15573. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15574. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15575. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15576. }
  15577. /// Custom Fonts (ZC_NOTIFY_FONT).
  15578. /// 02ef <account_id>.L <font id>.W
  15579. void clif_font(struct map_session_data *sd)
  15580. {
  15581. #if PACKETVER >= 20080102
  15582. unsigned char buf[8];
  15583. nullpo_retv(sd);
  15584. WBUFW(buf,0) = 0x2ef;
  15585. WBUFL(buf,2) = sd->bl.id;
  15586. WBUFW(buf,6) = sd->status.font;
  15587. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15588. #endif
  15589. }
  15590. /// Required to start the instancing information window on Client
  15591. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15592. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15593. void clif_instance_create(int instance_id, int num)
  15594. {
  15595. #if PACKETVER >= 20071128
  15596. struct map_session_data *sd = NULL;
  15597. enum send_target target = PARTY;
  15598. unsigned char buf[65];
  15599. instance_getsd(instance_id, sd, &target);
  15600. if (!sd)
  15601. return;
  15602. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15603. if (!db)
  15604. return;
  15605. WBUFW(buf,0) = 0x2cb;
  15606. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15607. WBUFW(buf,63) = num;
  15608. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15609. #endif
  15610. return;
  15611. }
  15612. /// To announce Instancing queue creation if no maps available
  15613. /// S 0x2cc <Standby Position>.W
  15614. void clif_instance_changewait(int instance_id, int num)
  15615. {
  15616. #if PACKETVER >= 20071128
  15617. struct map_session_data *sd = NULL;
  15618. enum send_target target = PARTY;
  15619. unsigned char buf[4];
  15620. instance_getsd(instance_id, sd, &target);
  15621. if (!sd)
  15622. return;
  15623. WBUFW(buf,0) = 0x2cc;
  15624. WBUFW(buf,2) = num;
  15625. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15626. #endif
  15627. return;
  15628. }
  15629. /// Notify the current status to members
  15630. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15631. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15632. {
  15633. #if PACKETVER >= 20071128
  15634. struct map_session_data *sd = NULL;
  15635. enum send_target target = PARTY;
  15636. unsigned char buf[71];
  15637. instance_getsd(instance_id, sd, &target);
  15638. if (!sd)
  15639. return;
  15640. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15641. if (!db)
  15642. return;
  15643. WBUFW(buf,0) = 0x2cd;
  15644. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15645. WBUFL(buf,63) = limit1;
  15646. WBUFL(buf,67) = limit2;
  15647. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15648. #endif
  15649. return;
  15650. }
  15651. /// Notify a status change to members
  15652. /// S 0x2ce <Message ID>.L
  15653. /// 0 = Notification (EnterLimitDate update?)
  15654. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15655. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15656. /// 3 = The Memorial Dungeon has been removed.
  15657. /// 4 = Create failure (removes the instance window)
  15658. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15659. {
  15660. #if PACKETVER >= 20071128
  15661. struct map_session_data *sd = NULL;
  15662. enum send_target target = PARTY;
  15663. unsigned char buf[10];
  15664. instance_getsd(instance_id, sd, &target);
  15665. if (!sd)
  15666. return;
  15667. WBUFW(buf,0) = 0x2ce;
  15668. WBUFL(buf,2) = type;
  15669. WBUFL(buf,6) = limit;
  15670. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15671. #endif
  15672. return;
  15673. }
  15674. /// Destroy an instance from the status window
  15675. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15676. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15677. {
  15678. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15679. return;
  15680. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15681. switch (p->command) {
  15682. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15683. instance_destroy_command(sd);
  15684. break;
  15685. }
  15686. }
  15687. void clif_instance_info( struct map_session_data& sd ){
  15688. if( sd.instance_id > 0 ){
  15689. instance_reqinfo( &sd, sd.instance_id );
  15690. }
  15691. if( sd.status.party_id > 0 ){
  15692. struct party_data* p = party_search( sd.status.party_id );
  15693. if( p != nullptr && p->instance_id > 0 ){
  15694. instance_reqinfo( &sd, p->instance_id );
  15695. }
  15696. }
  15697. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15698. instance_reqinfo( &sd, sd.guild->instance_id );
  15699. }
  15700. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15701. instance_reqinfo( &sd, sd.clan->instance_id );
  15702. }
  15703. }
  15704. /// Notifies clients about item picked up by a party member.
  15705. /// 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)
  15706. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15707. #if PACKETVER >= 20071002
  15708. nullpo_retv( sd );
  15709. nullpo_retv( item_data );
  15710. struct item_data* id = itemdb_search( item_data->nameid );
  15711. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15712. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15713. p.AID = sd->status.account_id;
  15714. p.itemId = client_nameid( item_data->nameid );
  15715. p.identified = item_data->identify;
  15716. p.damaged = item_data->attribute;
  15717. p.refine = item_data->refine;
  15718. clif_addcards( &p.slot, item_data );
  15719. p.location = id->equip; // equip location
  15720. p.itemType = itemtype( id->nameid ); // item type
  15721. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15722. p.enchantgrade = item_data->enchantgrade;
  15723. #endif
  15724. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15725. #endif
  15726. }
  15727. /** Display gained exp.
  15728. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15729. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15730. * amount: INT32_MIN ~ INT32_MAX
  15731. * var id:
  15732. * SP_BASEEXP, SP_JOBEXP
  15733. * exp type:
  15734. * 0 = normal exp gained/lost
  15735. * 1 = quest exp gained/lost
  15736. * @param sd Player
  15737. * @param exp EXP value gained/loss
  15738. * @param type SP_BASEEXP, SP_JOBEXP
  15739. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15740. * @param lost True:if losing EXP
  15741. */
  15742. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15743. {
  15744. int fd;
  15745. int offset;
  15746. #if PACKETVER >= 20170830
  15747. int cmd = 0xacc;
  15748. #else
  15749. int cmd = 0x7f6;
  15750. #endif
  15751. nullpo_retv(sd);
  15752. fd = sd->fd;
  15753. WFIFOHEAD(fd, packet_len(cmd));
  15754. WFIFOW(fd,0) = cmd;
  15755. WFIFOL(fd,2) = sd->bl.id;
  15756. #if PACKETVER >= 20170830
  15757. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15758. offset = 4;
  15759. #else
  15760. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15761. offset = 0;
  15762. #endif
  15763. WFIFOW(fd,10+offset) = type;
  15764. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15765. WFIFOSET(fd,packet_len(cmd));
  15766. }
  15767. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15768. /// type:
  15769. /// 0 = Displays 'value' for 5 seconds.
  15770. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15771. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15772. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15773. /// value:
  15774. /// 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).
  15775. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15776. {
  15777. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15778. WFIFOW(sd->fd,0) = 0x1b1;
  15779. WFIFOB(sd->fd,2) = type;
  15780. WFIFOL(sd->fd,3) = value;
  15781. WFIFOSET(sd->fd, packet_len(0x1b1));
  15782. }
  15783. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15784. /// 021d <state>.L
  15785. /// state:
  15786. /// 0 = Full effects
  15787. /// 1 = Reduced effects
  15788. ///
  15789. /// NOTE: The state is used on Aegis for sending skill unit packet
  15790. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15791. /// whenever possible. Due to the way the decision check is
  15792. /// constructed, this state tracking was rendered useless,
  15793. /// as the only skill unit, that is sent with 0x1c9 is
  15794. /// Graffiti.
  15795. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15796. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15797. sd->state.lesseffect = ( isLess != 0 );
  15798. }
  15799. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15800. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15801. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15802. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15803. int type = RFIFOL(fd,info->pos[1]);
  15804. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15805. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15806. if( sd->state.trading || sd->npc_shopid )
  15807. return;
  15808. if( flag == 0 || n == 0) {
  15809. clif_menuskill_clear(sd);
  15810. return; // Canceled by player.
  15811. }
  15812. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15813. clif_menuskill_clear(sd);
  15814. return; // Prevent hacking.
  15815. }
  15816. switch( type ) {
  15817. case 0: // Change Material
  15818. skill_changematerial(sd,n,item_list);
  15819. break;
  15820. case 1: // Level 1: Pure to Rough
  15821. case 2: // Level 2: Rough to Pure
  15822. skill_elementalanalysis(sd,n,type,item_list);
  15823. break;
  15824. }
  15825. clif_menuskill_clear(sd);
  15826. return;
  15827. }
  15828. /*==========================================
  15829. * Elemental System
  15830. *==========================================*/
  15831. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15832. s_elemental_data *ed;
  15833. struct status_data *status;
  15834. int fd;
  15835. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15836. return;
  15837. fd = sd->fd;
  15838. status = &ed->battle_status;
  15839. WFIFOHEAD(fd,8);
  15840. WFIFOW(fd,0) = 0x81e;
  15841. WFIFOW(fd,2) = type;
  15842. switch( type ) {
  15843. case SP_HP:
  15844. WFIFOL(fd,4) = status->hp;
  15845. break;
  15846. case SP_MAXHP:
  15847. WFIFOL(fd,4) = status->max_hp;
  15848. break;
  15849. case SP_SP:
  15850. WFIFOL(fd,4) = status->sp;
  15851. break;
  15852. case SP_MAXSP:
  15853. WFIFOL(fd,4) = status->max_sp;
  15854. break;
  15855. }
  15856. WFIFOSET(fd,8);
  15857. }
  15858. void clif_elemental_info(struct map_session_data *sd) {
  15859. int fd;
  15860. s_elemental_data *ed;
  15861. struct status_data *status;
  15862. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15863. return;
  15864. fd = sd->fd;
  15865. status = &ed->battle_status;
  15866. WFIFOHEAD(fd,22);
  15867. WFIFOW(fd, 0) = 0x81d;
  15868. WFIFOL(fd, 2) = ed->bl.id;
  15869. WFIFOL(fd, 6) = status->hp;
  15870. WFIFOL(fd,10) = status->max_hp;
  15871. WFIFOL(fd,14) = status->sp;
  15872. WFIFOL(fd,18) = status->max_sp;
  15873. WFIFOSET(fd,22);
  15874. }
  15875. /// Buying Store System
  15876. ///
  15877. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15878. /// 0810 <slots>.B
  15879. void clif_buyingstore_open(struct map_session_data* sd)
  15880. {
  15881. int fd = sd->fd;
  15882. WFIFOHEAD(fd,packet_len(0x810));
  15883. WFIFOW(fd,0) = 0x810;
  15884. WFIFOB(fd,2) = sd->buyingstore.slots;
  15885. WFIFOSET(fd,packet_len(0x810));
  15886. }
  15887. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15888. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15889. /// result:
  15890. /// 0 = cancel
  15891. /// 1 = open
  15892. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15893. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15894. // TODO: Make this check global for all variable length packets.
  15895. // minimum packet length
  15896. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15897. 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 );
  15898. return;
  15899. }
  15900. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15901. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15902. return;
  15903. }
  15904. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15905. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15906. return;
  15907. }
  15908. char storename[MESSAGE_SIZE];
  15909. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15910. // so that buyingstore_create knows, how many elements it has access to
  15911. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15912. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15913. 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 ) );
  15914. return;
  15915. }
  15916. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15917. }
  15918. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15919. /// 0812 <result>.W <total weight>.L
  15920. /// result:
  15921. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15922. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15923. /// 8 = "No sale (purchase) information available." (0x705)
  15924. /// ? = nothing
  15925. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15926. {
  15927. int fd = sd->fd;
  15928. WFIFOHEAD(fd,packet_len(0x812));
  15929. WFIFOW(fd,0) = 0x812;
  15930. WFIFOW(fd,2) = result;
  15931. WFIFOL(fd,4) = weight;
  15932. WFIFOSET(fd,packet_len(0x812));
  15933. }
  15934. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15935. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15936. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15937. nullpo_retv( sd );
  15938. int fd = sd->fd;
  15939. if( !session_isActive( fd ) ){
  15940. return;
  15941. }
  15942. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15943. WFIFOHEAD( fd, length );
  15944. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15945. p->packetType = 0x813;
  15946. p->packetLength = length;
  15947. p->AID = sd->bl.id;
  15948. p->zenyLimit = sd->buyingstore.zenylimit;
  15949. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15950. p->items[i].price = sd->buyingstore.items[i].price;
  15951. p->items[i].amount = sd->buyingstore.items[i].amount;
  15952. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15953. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15954. }
  15955. WFIFOSET( fd, p->packetLength );
  15956. }
  15957. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15958. /// 0814 <account id>.L <store name>.80B
  15959. void clif_buyingstore_entry(struct map_session_data* sd)
  15960. {
  15961. uint8 buf[MESSAGE_SIZE+6];
  15962. WBUFW(buf,0) = 0x814;
  15963. WBUFL(buf,2) = sd->bl.id;
  15964. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15965. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15966. }
  15967. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15968. {
  15969. int fd = sd->fd;
  15970. WFIFOHEAD(fd,packet_len(0x814));
  15971. WFIFOW(fd,0) = 0x814;
  15972. WFIFOL(fd,2) = pl_sd->bl.id;
  15973. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15974. WFIFOSET(fd,packet_len(0x814));
  15975. }
  15976. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15977. /// 0815
  15978. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15979. {
  15980. buyingstore_close(sd);
  15981. }
  15982. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15983. /// 0816 <account id>.L
  15984. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15985. {
  15986. uint8 buf[6];
  15987. WBUFW(buf,0) = 0x816;
  15988. WBUFL(buf,2) = sd->bl.id;
  15989. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15990. }
  15991. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15992. {
  15993. int fd = sd->fd;
  15994. WFIFOHEAD(fd,packet_len(0x816));
  15995. WFIFOW(fd,0) = 0x816;
  15996. WFIFOL(fd,2) = pl_sd->bl.id;
  15997. WFIFOSET(fd,packet_len(0x816));
  15998. }
  15999. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  16000. /// 0817 <account id>.L
  16001. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  16002. {
  16003. uint32 account_id;
  16004. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  16005. buyingstore_open(sd, account_id);
  16006. }
  16007. /// Sends buying store item list.
  16008. /// 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)
  16009. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  16010. nullpo_retv( sd );
  16011. nullpo_retv( pl_sd );
  16012. int fd = sd->fd;
  16013. if( !session_isActive( fd ) ){
  16014. return;
  16015. }
  16016. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  16017. WFIFOHEAD( fd, length );
  16018. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  16019. p->packetType = 0x818;
  16020. p->packetLength = length;
  16021. p->AID = pl_sd->bl.id;
  16022. p->storeId = pl_sd->buyer_id;
  16023. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  16024. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  16025. p->items[i].price = pl_sd->buyingstore.items[i].price;
  16026. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  16027. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  16028. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  16029. }
  16030. WFIFOSET( fd, p->packetLength );
  16031. }
  16032. /// Request to sell items to a buying store.
  16033. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  16034. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  16035. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  16036. // minimum packet length
  16037. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  16038. 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 );
  16039. return;
  16040. }
  16041. // so that buyingstore_trade knows, how many elements it has access to
  16042. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  16043. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  16044. 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 ) );
  16045. return;
  16046. }
  16047. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  16048. }
  16049. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  16050. /// 081a <result>.W
  16051. /// result:
  16052. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  16053. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  16054. /// ? = nothing
  16055. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  16056. {
  16057. int fd = sd->fd;
  16058. WFIFOHEAD(fd,packet_len(0x81a));
  16059. WFIFOW(fd,0) = 0x81a;
  16060. WFIFOW(fd,2) = result;
  16061. WFIFOSET(fd,packet_len(0x81a));
  16062. }
  16063. /// Updates the zeny limit and an item in the buying store item list.
  16064. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  16065. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  16066. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  16067. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  16068. p.packetType = buyingStoreUpdateItemType;
  16069. p.itemId = client_nameid( nameid );
  16070. p.amount = amount;
  16071. p.zenyLimit = sd->buyingstore.zenylimit;
  16072. #if PACKETVER >= 20141016
  16073. p.zeny = zeny;
  16074. p.charId = char_id; // GID
  16075. p.updateTime = (int)time(NULL);
  16076. #endif
  16077. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16078. }
  16079. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  16080. /// 081c <index>.W <amount>.W <price>.L
  16081. /// message:
  16082. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  16083. ///
  16084. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  16085. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  16086. {
  16087. int fd = sd->fd;
  16088. WFIFOHEAD(fd,packet_len(0x81c));
  16089. WFIFOW(fd,0) = 0x81c;
  16090. WFIFOW(fd,2) = client_index( index );
  16091. WFIFOW(fd,4) = amount;
  16092. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  16093. WFIFOSET(fd,packet_len(0x81c));
  16094. }
  16095. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  16096. /// 0824 <result>.W <name id>.W
  16097. /// result:
  16098. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  16099. /// 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)
  16100. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  16101. /// ? = nothing
  16102. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  16103. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  16104. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  16105. p.result = result;
  16106. p.itemId = client_nameid( nameid );
  16107. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16108. }
  16109. /// Search Store Info System
  16110. ///
  16111. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  16112. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  16113. /// type:
  16114. /// 0 = Vending
  16115. /// 1 = Buying Store
  16116. ///
  16117. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16118. /// amount of card slots. If the client does not know about the item it
  16119. /// cannot be searched.
  16120. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  16121. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16122. // minimum packet length
  16123. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16124. 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 );
  16125. return;
  16126. }
  16127. // check, if there is enough data for the claimed count of items
  16128. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16129. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16130. 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 ) );
  16131. return;
  16132. }
  16133. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16134. if( count < p->itemsCount + p->cardsCount ){
  16135. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16136. return;
  16137. }
  16138. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16139. }
  16140. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16141. /// 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 }*
  16142. /// is first page:
  16143. /// 0 = appends to existing results
  16144. /// 1 = clears previous results before displaying this result set
  16145. /// is next page:
  16146. /// 0 = no "next" label
  16147. /// 1 = "next" label to retrieve more results
  16148. void clif_search_store_info_ack( struct map_session_data* sd ){
  16149. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  16150. nullpo_retv( sd );
  16151. int fd = sd->fd;
  16152. if( !session_isActive( fd ) ){
  16153. return;
  16154. }
  16155. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16156. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16157. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16158. WFIFOHEAD( fd, len );
  16159. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16160. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16161. p->packetLength = len;
  16162. p->firstPage = !sd->searchstore.pages;
  16163. p->nextPage = searchstore_querynext( sd );
  16164. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16165. for( int i = 0; i < end - start; i++ ) {
  16166. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16167. p->items[i].storeId = ssitem->store_id;
  16168. p->items[i].AID = ssitem->account_id;
  16169. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16170. p->items[i].itemId = client_nameid( ssitem->nameid );
  16171. p->items[i].itemType = itemtype( ssitem->nameid );
  16172. p->items[i].price = ssitem->price;
  16173. p->items[i].amount = ssitem->amount;
  16174. p->items[i].refine = ssitem->refine;
  16175. // make-up an item for clif_addcards
  16176. struct item it = {};
  16177. for( int j = 0; j < MAX_SLOTS; j++ ){
  16178. it.card[j] = ssitem->card[j];
  16179. }
  16180. it.nameid = ssitem->nameid;
  16181. it.amount = ssitem->amount;
  16182. clif_addcards( &p->items[i].slot, &it );
  16183. #if PACKETVER >= 20150226
  16184. clif_add_random_options( p->items[i].option_data, &it );
  16185. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16186. p->items[i].enchantgrade = ssitem->enchantgrade;
  16187. #endif
  16188. #endif
  16189. }
  16190. WFIFOSET( fd, len );
  16191. #endif
  16192. }
  16193. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16194. /// 0837 <reason>.B
  16195. /// reason:
  16196. /// 0 = "No matching stores were found." (0x70b)
  16197. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16198. /// 2 = "You cannot search anymore." (0x706)
  16199. /// 3 = "You cannot search yet." (0x708)
  16200. /// 4 = "No sale (purchase) information available." (0x705)
  16201. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  16202. {
  16203. int fd = sd->fd;
  16204. WFIFOHEAD(fd,packet_len(0x837));
  16205. WFIFOW(fd,0) = 0x837;
  16206. WFIFOB(fd,2) = reason;
  16207. WFIFOSET(fd,packet_len(0x837));
  16208. }
  16209. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16210. /// 0838
  16211. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  16212. {
  16213. searchstore_next(sd);
  16214. }
  16215. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16216. /// 083a <type>.W <remaining uses>.B
  16217. /// type:
  16218. /// 0 = Search Stores
  16219. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16220. void clif_open_search_store_info(struct map_session_data* sd)
  16221. {
  16222. int fd = sd->fd;
  16223. WFIFOHEAD(fd,packet_len(0x83a));
  16224. WFIFOW(fd,0) = 0x83a;
  16225. WFIFOW(fd,2) = sd->searchstore.effect;
  16226. #if PACKETVER > 20100701
  16227. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16228. #endif
  16229. WFIFOSET(fd,packet_len(0x83a));
  16230. }
  16231. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16232. /// 083b
  16233. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  16234. {
  16235. searchstore_close(sd);
  16236. }
  16237. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16238. /// 083c <account id>.L <store id>.L <nameid>.W
  16239. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  16240. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16241. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16242. }
  16243. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16244. /// 083d <xPos>.W <yPos>.W
  16245. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  16246. {
  16247. int fd = sd->fd;
  16248. WFIFOHEAD(fd,packet_len(0x83d));
  16249. WFIFOW(fd,0) = 0x83d;
  16250. WFIFOW(fd,2) = x;
  16251. WFIFOW(fd,4) = y;
  16252. WFIFOSET(fd,packet_len(0x83d));
  16253. }
  16254. /// Parse function for packet debugging.
  16255. void clif_parse_debug(int fd,struct map_session_data *sd)
  16256. {
  16257. int cmd, packet_len;
  16258. // clif_parse ensures, that there is at least 2 bytes of data
  16259. cmd = RFIFOW(fd,0);
  16260. if( sd ) {
  16261. packet_len = packet_db[cmd].len;
  16262. if( packet_len == 0 )
  16263. {// unknown
  16264. packet_len = RFIFOREST(fd);
  16265. }
  16266. else if( packet_len == -1 )
  16267. {// variable length
  16268. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16269. }
  16270. 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);
  16271. }
  16272. else
  16273. {
  16274. packet_len = RFIFOREST(fd);
  16275. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16276. }
  16277. ShowDump(RFIFOP(fd,0), packet_len);
  16278. }
  16279. /*==========================================
  16280. * Server tells client to display a window similar to Magnifier (item) one
  16281. * Server populates the window with avilable elemental converter options according to player's inventory
  16282. *------------------------------------------*/
  16283. void clif_elementalconverter_list( struct map_session_data *sd ){
  16284. nullpo_retv( sd );
  16285. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16286. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16287. int count = 0;
  16288. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16289. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16290. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16291. count++;
  16292. }
  16293. }
  16294. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16295. clif_send( p, p->packetLength, &sd->bl, SELF );
  16296. if( count > 0 ){
  16297. sd->menuskill_id = SA_CREATECON;
  16298. sd->menuskill_val = count;
  16299. }
  16300. }
  16301. /**
  16302. * Rune Knight
  16303. **/
  16304. void clif_millenniumshield(struct block_list *bl, short shields) {
  16305. #if PACKETVER >= 20081217
  16306. unsigned char buf[10];
  16307. WBUFW(buf,0) = 0x440;
  16308. WBUFL(buf,2) = bl->id;
  16309. WBUFW(buf,6) = shields;
  16310. WBUFW(buf,8) = 0;
  16311. clif_send(buf,packet_len(0x440),bl,AREA);
  16312. #endif
  16313. }
  16314. /**
  16315. * Mechanic
  16316. **/
  16317. /*==========================================
  16318. * Magic Decoy Material List
  16319. *------------------------------------------*/
  16320. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  16321. nullpo_retv( sd );
  16322. int fd = sd->fd;
  16323. if( !session_isActive( fd ) ){
  16324. return;
  16325. }
  16326. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16327. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16328. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16329. int count = 0;
  16330. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16331. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16332. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16333. count++;
  16334. }
  16335. }
  16336. if( count > 0 ) {
  16337. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16338. WFIFOSET( fd, p->packetLength );
  16339. sd->menuskill_id = NC_MAGICDECOY;
  16340. sd->menuskill_val = skill_lv;
  16341. sd->sc.comet_x = x;
  16342. sd->sc.comet_y = y;
  16343. }else{
  16344. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16345. }
  16346. }
  16347. /*==========================================
  16348. * Guillotine Cross Poisons List
  16349. *------------------------------------------*/
  16350. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16351. nullpo_retv( sd );
  16352. int fd = sd->fd;
  16353. if( !session_isActive( fd ) ){
  16354. return;
  16355. }
  16356. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16357. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16358. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16359. int count = 0;
  16360. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16361. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16362. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16363. count++;
  16364. }
  16365. }
  16366. if( count > 0 ){
  16367. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16368. WFIFOSET( fd, p->packetLength );
  16369. sd->menuskill_id = GC_POISONINGWEAPON;
  16370. sd->menuskill_val = skill_lv;
  16371. }else{
  16372. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16373. }
  16374. }
  16375. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16376. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16377. int fd, i, c;
  16378. nullpo_ret(sd);
  16379. fd = sd->fd;
  16380. if( !session_isActive(fd) )
  16381. return 0;
  16382. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16383. return 0;
  16384. WFIFOHEAD(fd, 2 * 6 + 4);
  16385. WFIFOW(fd,0) = 0x442;
  16386. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16387. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16388. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16389. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16390. {
  16391. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16392. c++;
  16393. }
  16394. if( c > 0 ) {
  16395. WFIFOW(fd,2) = 8 + c * 2;
  16396. WFIFOL(fd,4) = c;
  16397. WFIFOSET(fd,WFIFOW(fd,2));
  16398. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16399. sd->menuskill_val = c;
  16400. } else {
  16401. status_change_end(&sd->bl,SC_STOP);
  16402. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16403. }
  16404. return 1;
  16405. }
  16406. /*===========================================
  16407. * Skill list for Four Elemental Analysis
  16408. * and Change Material skills.
  16409. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16410. *------------------------------------------*/
  16411. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16412. #if PACKETVER >= 20090922
  16413. int fd = sd->fd;
  16414. nullpo_ret(sd);
  16415. sd->menuskill_id = skill_id; // To prevent hacking.
  16416. sd->menuskill_val = skill_lv;
  16417. if( skill_id == GN_CHANGEMATERIAL )
  16418. skill_lv = 0; // Changematerial
  16419. WFIFOHEAD(fd, packet_len(0x7e3));
  16420. WFIFOW(fd,0) = 0x7e3;
  16421. WFIFOL(fd,2) = skill_lv;
  16422. WFIFOL(fd,4) = 0;
  16423. WFIFOSET(fd, packet_len(0x7e3));
  16424. #endif
  16425. return 1;
  16426. }
  16427. /*==========================================
  16428. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16429. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16430. * RFIFOL(fd,2) - type (currently not used)
  16431. *------------------------------------------*/
  16432. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16433. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16434. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16435. if (sd->menuskill_id == SA_AUTOSPELL) {
  16436. sd->state.workinprogress = WIP_DISABLE_NONE;
  16437. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16438. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16439. if (pc_istrading(sd)) {
  16440. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16441. clif_menuskill_clear(sd);
  16442. return;
  16443. }
  16444. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16445. } else
  16446. return;
  16447. clif_menuskill_clear(sd);
  16448. }
  16449. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16450. /// 08cf <id>.L <type>.W <num>.W
  16451. void clif_spiritcharm(struct map_session_data *sd) {
  16452. unsigned char buf[10];
  16453. nullpo_retv(sd);
  16454. WBUFW(buf,0) = 0x08cf;
  16455. WBUFL(buf,2) = sd->bl.id;
  16456. WBUFW(buf,6) = sd->spiritcharm_type;
  16457. WBUFW(buf,8) = sd->spiritcharm;
  16458. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16459. }
  16460. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16461. /// 0907 <index>.W
  16462. ///
  16463. /// R 0908 <index>.w <type>.b
  16464. /// type:
  16465. /// 0 = move item to personal tab
  16466. /// 1 = move item to normal tab
  16467. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16468. #if PACKETVER >= 20111122
  16469. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16470. int index = RFIFOW(fd,info->pos[0]) - 2;
  16471. int type = RFIFOB(fd, info->pos[1]);
  16472. /* can't move while dead. */
  16473. if(pc_isdead(sd)) {
  16474. return;
  16475. }
  16476. if (index < 0 || index >= MAX_INVENTORY)
  16477. return;
  16478. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16479. sd->inventory.u.items_inventory[index].favorite = 0;
  16480. else if( type == 0 )
  16481. sd->inventory.u.items_inventory[index].favorite = 1;
  16482. else
  16483. return;/* nothing to do. */
  16484. clif_favorite_item(sd, index);
  16485. #endif
  16486. }
  16487. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16488. /// 0900 <index>.W <favorite>.B
  16489. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16490. int fd = sd->fd;
  16491. WFIFOHEAD(fd,packet_len(0x908));
  16492. WFIFOW(fd,0) = 0x908;
  16493. WFIFOW(fd,2) = index+2;
  16494. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16495. WFIFOSET(fd,packet_len(0x908));
  16496. }
  16497. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16498. void clif_snap( struct block_list *bl, short x, short y ) {
  16499. unsigned char buf[10];
  16500. WBUFW(buf,0) = 0x8d2;
  16501. WBUFL(buf,2) = bl->id;
  16502. WBUFW(buf,6) = x;
  16503. WBUFW(buf,8) = y;
  16504. if( disguised(bl) )
  16505. {
  16506. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16507. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16508. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16509. } else
  16510. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16511. }
  16512. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16513. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16514. #if PACKETVER >= 20120404
  16515. WFIFOHEAD(fd,packet_len(0x977));
  16516. WFIFOW(fd,0) = 0x977;
  16517. WFIFOL(fd,2) = md->bl.id;
  16518. WFIFOL(fd,6) = md->status.hp;
  16519. WFIFOL(fd,10) = md->status.max_hp;
  16520. WFIFOSET(fd,packet_len(0x977));
  16521. #endif
  16522. }
  16523. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16524. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16525. return;
  16526. }
  16527. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16528. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16529. WFIFOW(sd->fd,0) = 0x2c9;
  16530. WFIFOB(sd->fd,2) = flag;
  16531. WFIFOSET(sd->fd, packet_len(0x2c9));
  16532. }
  16533. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16534. /// 0979 <world name>.24B <char name>.24B
  16535. void clif_ackworldinfo(struct map_session_data* sd) {
  16536. int fd;
  16537. nullpo_retv(sd);
  16538. fd = sd->fd;
  16539. WFIFOHEAD(fd,packet_len(0x979));
  16540. WFIFOW(fd,0)=0x979;
  16541. //AID -> world name ?
  16542. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16543. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16544. WFIFOSET(fd,packet_len(0x979));
  16545. }
  16546. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16547. /// 0978 <AID>.L
  16548. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16549. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16550. if(sd)
  16551. clif_ackworldinfo(sd);
  16552. }
  16553. static void clif_loadConfirm( struct map_session_data *sd ){
  16554. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16555. nullpo_retv( sd );
  16556. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16557. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16558. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16559. clif_instance_info( *sd );
  16560. #endif
  16561. }
  16562. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16563. /// 0447
  16564. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16565. clif_loadConfirm( sd );
  16566. }
  16567. /// req world info (CZ_CLIENT_VERSION)
  16568. /// 044A <version>.L
  16569. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16570. //if(sd)
  16571. ;
  16572. }
  16573. /// Ranking list
  16574. /// ranking pointlist { <name>.24B <point>.L }*10
  16575. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16576. struct fame_list* list;
  16577. int i, size = MAX_FAME_LIST;
  16578. switch(rankingtype) {
  16579. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16580. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16581. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16582. // PK currently unsupported
  16583. case RANK_KILLER: list = NULL; size = 0; break;
  16584. default:
  16585. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16586. return;
  16587. }
  16588. //Packet size limits this list to 10 elements. [Skotlex]
  16589. for (i = 0; i < min(10,size); i++) {
  16590. if (list[i].id > 0) {
  16591. const char* name;
  16592. if (strcmp(list[i].name, "-") == 0 &&
  16593. (name = map_charid2nick(list[i].id)) != NULL)
  16594. {
  16595. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16596. } else {
  16597. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16598. }
  16599. } else {
  16600. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16601. }
  16602. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16603. }
  16604. for(;i < 10; i++) { //In case the MAX is less than 10.
  16605. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16606. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16607. }
  16608. }
  16609. /// Request for the blacksmith ranklist.
  16610. /// /blacksmith command sends this packet to the server.
  16611. /// 0217 (CZ_BLACKSMITH_RANK)
  16612. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16613. clif_ranklist(sd,RANK_BLACKSMITH);
  16614. }
  16615. /// Request for the alchemist ranklist.
  16616. /// /alchemist command sends this packet to the server.
  16617. /// 0218 (CZ_ALCHEMIST_RANK)
  16618. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16619. clif_ranklist(sd,RANK_ALCHEMIST);
  16620. }
  16621. /// Request for the taekwon ranklist.
  16622. /// /taekwon command sends this packet to the server.
  16623. /// 0225 (CZ_TAEKWON_RANK)
  16624. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16625. clif_ranklist(sd,RANK_TAEKWON);
  16626. }
  16627. /// Request for the killer ranklist.
  16628. /// /pk command sends this packet to the server.
  16629. /// 0237 (CZ_KILLER_RANK)
  16630. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16631. clif_ranklist(sd,RANK_KILLER);
  16632. }
  16633. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16634. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16635. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16636. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16637. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16638. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16639. enum e_rank rank;
  16640. #if PACKETVER < 20130710
  16641. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16642. short cmd;
  16643. switch( rankingType ){
  16644. case RANK_BLACKSMITH: cmd = 0x219; break;
  16645. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16646. case RANK_TAEKWON: cmd = 0x226; break;
  16647. case RANK_KILLER: cmd = 0x238; break;
  16648. default:
  16649. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16650. return;
  16651. }
  16652. // Can be safely casted here, since we validated it before
  16653. rank = (enum e_rank)rankingType;
  16654. WBUFW(buf,0) = cmd;
  16655. clif_sub_ranklist(buf,2,sd,rank);
  16656. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16657. #else
  16658. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16659. int mypoint = 0;
  16660. switch( rankingType ){
  16661. case RANK_BLACKSMITH:
  16662. case RANK_ALCHEMIST:
  16663. case RANK_TAEKWON:
  16664. case RANK_KILLER:
  16665. break;
  16666. default:
  16667. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16668. return;
  16669. }
  16670. // Can be safely casted here, since we validated it before
  16671. rank = (enum e_rank)rankingType;
  16672. WBUFW(buf,0) = 0x97d;
  16673. WBUFW(buf,2) = rank;
  16674. clif_sub_ranklist(buf,4,sd,rank);
  16675. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16676. case MAPID_BLACKSMITH:
  16677. case MAPID_ALCHEMIST:
  16678. case MAPID_TAEKWON:
  16679. mypoint = sd->status.fame;
  16680. }
  16681. WBUFL(buf,284) = mypoint; //mypoint
  16682. clif_send(buf, 288, &sd->bl, SELF);
  16683. #endif
  16684. }
  16685. /*
  16686. * 097c <type> (CZ_REQ_RANKING)
  16687. * type
  16688. * 0: /blacksmith
  16689. * 1: /alchemist
  16690. * 2: /taekwon
  16691. * 3: /pk
  16692. * */
  16693. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16694. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16695. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16696. clif_ranklist(sd,rankingtype);
  16697. }
  16698. /// Updates the fame rank points for the given ranking.
  16699. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16700. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16701. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16702. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16703. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16704. int fd = sd.fd;
  16705. #if PACKETVER < 20130710
  16706. short cmd;
  16707. switch(rankingtype){
  16708. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16709. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16710. case RANK_TAEKWON: cmd = 0x224; break;
  16711. default:
  16712. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16713. return;
  16714. }
  16715. WFIFOHEAD(fd,packet_len(cmd));
  16716. WFIFOW(fd,0) = cmd;
  16717. WFIFOL(fd,2) = point;
  16718. WFIFOL(fd,6) = sd.status.fame;
  16719. WFIFOSET(fd, packet_len(cmd));
  16720. #else
  16721. WFIFOHEAD(fd,packet_len(0x97e));
  16722. WFIFOW(fd,0) = 0x97e;
  16723. WFIFOW(fd,2) = rankingtype;
  16724. WFIFOL(fd,4) = point;
  16725. WFIFOL(fd,8) = sd.status.fame;
  16726. WFIFOSET(fd,packet_len(0x97e));
  16727. #endif
  16728. }
  16729. /**
  16730. * Transmit personal information to player. (rates)
  16731. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16732. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16733. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16734. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16735. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16736. * FIXME!
  16737. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16738. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16739. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16740. */
  16741. #ifdef VIP_ENABLE
  16742. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16743. if (sd) {
  16744. struct s_packet_db* info;
  16745. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16746. int cmd = 0, fd, i = 0;
  16747. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16748. int details_bexp[PINFO_MAX];
  16749. int details_drop[PINFO_MAX];
  16750. int details_penalty[PINFO_MAX];
  16751. /**
  16752. * Set for EXP
  16753. */
  16754. //0:PCRoom
  16755. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16756. if (details_bexp[0] == 100 || !details_bexp[0])
  16757. details_bexp[0] = 0;
  16758. else {
  16759. if (details_bexp[0] < 100) {
  16760. details_bexp[0] = 100 - details_bexp[0];
  16761. details_bexp[0] = 0 - details_bexp[0];
  16762. }
  16763. else
  16764. details_bexp[0] = details_bexp[0] - 100;
  16765. }
  16766. //1:Premium
  16767. if (pc_isvip(sd)) {
  16768. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16769. if (details_bexp[1] < 0)
  16770. details_bexp[1] = 0 - details_bexp[1];
  16771. }
  16772. else
  16773. details_bexp[1] = 0;
  16774. //2:Server
  16775. details_bexp[2] = battle_config.base_exp_rate;
  16776. if (details_bexp[2] == 100)
  16777. details_bexp[2] = 0;
  16778. else {
  16779. if (details_bexp[2] < 100) {
  16780. details_bexp[2] = 100 - details_bexp[2];
  16781. details_bexp[2] = 0 - details_bexp[2];
  16782. }
  16783. else
  16784. details_bexp[2] = details_bexp[2] - 100;
  16785. }
  16786. //3:TPLUS
  16787. details_bexp[3] = 0;
  16788. /* End - EXP set*/
  16789. /**
  16790. * Set for Drop rate
  16791. */
  16792. //0:PCRoom
  16793. details_drop[0] = 0;
  16794. //1:Premium
  16795. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16796. if (pc_isvip(sd)) {
  16797. if (details_drop[1] < 0)
  16798. details_drop[1] = 0 - details_drop[1];
  16799. }
  16800. else
  16801. details_drop[1] = 0;
  16802. //2:Server
  16803. details_drop[2] = battle_config.item_rate_common;
  16804. if (details_drop[2] == 100)
  16805. details_drop[2] = 0;
  16806. else {
  16807. if (details_drop[2] < 100) {
  16808. details_drop[2] = 100 - details_drop[2];
  16809. details_drop[2] = 0 - details_drop[2];
  16810. }
  16811. else
  16812. details_drop[2] = details_drop[2] - 100;
  16813. }
  16814. //3:TPLUS
  16815. details_drop[3] = 0;
  16816. /* End - Drop set*/
  16817. /**
  16818. * Set for Penalty rate
  16819. */
  16820. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16821. //0:PCRoom
  16822. details_penalty[0] = 0;
  16823. //1:Premium
  16824. if (pc_isvip(sd)) {
  16825. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16826. if (details_penalty[1] == 100)
  16827. details_penalty[1] = 0;
  16828. else {
  16829. if (details_penalty[1] < 100) {
  16830. details_penalty[1] = 100 - details_penalty[1];
  16831. details_penalty[1] = 0 - details_penalty[1];
  16832. }
  16833. else
  16834. details_penalty[1] = details_penalty[1] - 100;
  16835. }
  16836. }
  16837. else
  16838. details_penalty[1] = 0;
  16839. //2:Server
  16840. details_penalty[2] = battle_config.death_penalty_base;
  16841. if (details_penalty[2] == 100)
  16842. details_penalty[2] = 0;
  16843. else {
  16844. if (details_penalty[2] < 100) {
  16845. details_penalty[2] = 100 - details_penalty[2];
  16846. details_penalty[2] = 0 - details_penalty[2];
  16847. }
  16848. else
  16849. details_penalty[2] = details_penalty[2] - 100;
  16850. }
  16851. //3:TPLUS
  16852. details_penalty[3] = 0;
  16853. /* End - Penalty set*/
  16854. cmd = packet_db_ack[cmdtype];
  16855. info = &packet_db[cmd];
  16856. len = info->len; //this is the base len without details
  16857. if(!len) return; //version as packet disable
  16858. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16859. szdetails = 7;
  16860. factor = 1;
  16861. }
  16862. else if (cmd == 0x097b) {
  16863. tot_baseexp *= factor;
  16864. tot_drop *= factor;
  16865. tot_penalty *= factor;
  16866. }
  16867. fd = sd->fd;
  16868. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16869. WFIFOW(fd,0) = cmd;
  16870. for (i = 0; i < maxinfotype; i++) {
  16871. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16872. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16873. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16874. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16875. tot_baseexp += details_bexp[i]*factor;
  16876. tot_drop += details_penalty[i]*factor;
  16877. tot_penalty += details_drop[i]*factor;
  16878. len += szdetails;
  16879. }
  16880. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16881. if (cmd == 0x08cb) { //0x08cb version
  16882. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16883. WFIFOW(fd,info->pos[2]) = tot_drop;
  16884. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16885. }
  16886. else { //2013-08-07aRagexe uses 0x097b
  16887. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16888. WFIFOL(fd,info->pos[2]) = tot_drop;
  16889. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16890. }
  16891. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16892. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16893. WFIFOSET(fd,len);
  16894. }
  16895. }
  16896. #endif
  16897. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16898. char cmd[30];
  16899. int t_aid = RFIFOL(fd,2);
  16900. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16901. is_atcommand(fd, sd, cmd, 1);
  16902. }
  16903. /**
  16904. * Marks Crimson Marker target on mini-map to the caster
  16905. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16906. * @param fd
  16907. * @param bl Crimson Marker target
  16908. **/
  16909. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16910. struct s_packet_db* info;
  16911. int cmd = 0;
  16912. int16 len;
  16913. unsigned char buf[11];
  16914. nullpo_retv(sd);
  16915. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16916. if (!cmd)
  16917. cmd = 0x09C1; //default
  16918. info = &packet_db[cmd];
  16919. if (!(len = info->len))
  16920. return;
  16921. WBUFW(buf, 0) = cmd;
  16922. WBUFL(buf, info->pos[0]) = bl->id;
  16923. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16924. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16925. clif_send(buf, len, &sd->bl, SELF);
  16926. }
  16927. /**
  16928. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16929. **/
  16930. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16931. struct s_packet_db *info = NULL;
  16932. int cmd = 0;
  16933. nullpo_retv(sd);
  16934. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16935. info = &packet_db[cmd];
  16936. if (!cmd || !info->len)
  16937. return;
  16938. WFIFOHEAD(sd->fd, info->len);
  16939. WFIFOW(sd->fd, 0) = cmd;
  16940. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16941. WFIFOSET(sd->fd, info->len);
  16942. }
  16943. /**
  16944. * [Ind/Hercules]
  16945. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16946. **/
  16947. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16948. char buf[256];
  16949. size_t len;
  16950. nullpo_retv(bl);
  16951. if(!message)
  16952. return;
  16953. len = strlen(message)+1;
  16954. if( len > sizeof(buf)-8 ) {
  16955. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16956. len = sizeof(buf)-8;
  16957. }
  16958. WBUFW(buf,0) = 0x8b3;
  16959. WBUFW(buf,2) = (uint16)(len+8);
  16960. WBUFL(buf,4) = bl->id;
  16961. safestrncpy(WBUFCP(buf,8), message, len);
  16962. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16963. }
  16964. /**
  16965. * [Ind/Hercules]
  16966. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16967. **/
  16968. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16969. unsigned char buf[10];
  16970. nullpo_retv(sd);
  16971. WBUFW(buf,0) = 0x7fc;
  16972. WBUFL(buf,2) = prev_leader_aid;
  16973. WBUFL(buf,6) = new_leader_aid;
  16974. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16975. }
  16976. /**
  16977. * Sends a clan message to a player
  16978. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16979. **/
  16980. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16981. #if PACKETVER >= 20131223
  16982. struct map_session_data *sd;
  16983. uint8 buf[256];
  16984. if( len == 0 ){
  16985. return;
  16986. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16987. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16988. len = sizeof(buf)-5-NAME_LENGTH;
  16989. }
  16990. WBUFW(buf, 0) = 0x98e;
  16991. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16992. // 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
  16993. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16994. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16995. if((sd = clan_getavailablesd(clan)) != NULL)
  16996. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16997. #endif
  16998. }
  16999. /**
  17000. * Parses a clan message from a player.
  17001. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  17002. **/
  17003. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  17004. #if PACKETVER >= 20131223
  17005. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  17006. // validate packet and retrieve name and message
  17007. if( !clif_process_message(sd, false, name, message, output ) )
  17008. return;
  17009. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  17010. #endif
  17011. }
  17012. /**
  17013. * Sends the basic clan informations to the client.
  17014. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  17015. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  17016. **/
  17017. void clif_clan_basicinfo( struct map_session_data *sd ){
  17018. #if PACKETVER >= 20131223
  17019. int fd, offset, length, i, flag;
  17020. struct clan* clan;
  17021. char mapname[MAP_NAME_LENGTH_EXT];
  17022. nullpo_retv( sd );
  17023. nullpo_retv( clan = sd->clan );
  17024. // Check if the player has a valid session and is not autotrading
  17025. if( !clif_session_isValid( sd ) ){
  17026. return;
  17027. }
  17028. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  17029. fd = sd->fd;
  17030. WFIFOHEAD(fd,length);
  17031. memset( WFIFOP(fd, 0), 0, length );
  17032. WFIFOW( fd, 0 ) = 0x98a;
  17033. WFIFOL( fd, 4 ) = clan->id;
  17034. offset = 8;
  17035. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  17036. offset += NAME_LENGTH;
  17037. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  17038. offset += NAME_LENGTH;
  17039. mapindex_getmapname_ext( clan->map, mapname );
  17040. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  17041. offset += MAP_NAME_LENGTH_EXT;
  17042. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  17043. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  17044. for( flag = 0; flag < 2; flag++ ){
  17045. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  17046. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  17047. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  17048. offset += NAME_LENGTH;
  17049. }
  17050. }
  17051. }
  17052. WFIFOW( fd, 2 ) = offset;
  17053. WFIFOSET(fd,offset);
  17054. #endif
  17055. }
  17056. /**
  17057. * Updates the online and maximum player count of a clan.
  17058. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  17059. **/
  17060. void clif_clan_onlinecount( struct clan* clan ){
  17061. #if PACKETVER >= 20131223
  17062. uint8 buf[6];
  17063. struct map_session_data *sd;
  17064. WBUFW(buf,0) = 0x988;
  17065. WBUFW(buf,2) = clan->connect_member;
  17066. WBUFW(buf,4) = clan->max_member;
  17067. if((sd = clan_getavailablesd(clan)) != NULL)
  17068. clif_send(buf, 6, &sd->bl, CLAN);
  17069. #endif
  17070. }
  17071. /**
  17072. * Notifies the client that the player has left his clan.
  17073. * 0989 (ZC_ACK_CLAN_LEAVE)
  17074. **/
  17075. void clif_clan_leave( struct map_session_data* sd ){
  17076. #if PACKETVER >= 20131223
  17077. int fd;
  17078. nullpo_retv( sd );
  17079. if( !clif_session_isValid( sd ) ){
  17080. return;
  17081. }
  17082. fd = sd->fd;
  17083. WFIFOHEAD(fd,2);
  17084. WFIFOW(fd,0) = 0x989;
  17085. WFIFOSET(fd,2);
  17086. #endif
  17087. }
  17088. /**
  17089. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  17090. * 0A2F <result>.B <title_id>.L
  17091. */
  17092. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  17093. {
  17094. #if PACKETVER >= 20150513
  17095. int fd;
  17096. nullpo_retv(sd);
  17097. if (!clif_session_isValid(sd))
  17098. return;
  17099. fd = sd->fd;
  17100. WFIFOHEAD(fd, packet_len(0xa2f));
  17101. WFIFOW(fd, 0) = 0xa2f;
  17102. WFIFOB(fd, 2) = result;
  17103. WFIFOL(fd, 3) = title_id;
  17104. WFIFOSET(fd, packet_len(0xa2f));
  17105. #endif
  17106. }
  17107. /**
  17108. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  17109. * 0A2E <title_id>.L
  17110. */
  17111. void clif_parse_change_title(int fd, struct map_session_data *sd)
  17112. {
  17113. int title_id;
  17114. nullpo_retv(sd);
  17115. title_id = RFIFOL(fd, 2);
  17116. if( title_id == sd->status.title_id ){
  17117. // It is exactly the same as the old one
  17118. return;
  17119. }else if( title_id <= 0 ){
  17120. sd->status.title_id = 0;
  17121. }else{
  17122. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17123. clif_change_title_ack(sd, 1, title_id);
  17124. return;
  17125. }
  17126. sd->status.title_id = title_id;
  17127. }
  17128. clif_name_area(&sd->bl);
  17129. clif_change_title_ack(sd, 0, title_id);
  17130. }
  17131. #ifdef DUMP_UNKNOWN_PACKET
  17132. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17133. {
  17134. const char* packet_txt = "save/packet.txt";
  17135. FILE* fp;
  17136. time_t time_server;
  17137. struct tm *datetime;
  17138. char datestr[512];
  17139. time(&time_server); // get time in seconds since 1/1/1970
  17140. datetime = localtime(&time_server); // convert seconds in structure
  17141. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17142. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17143. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17144. if( sd ) {
  17145. 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);
  17146. } else {
  17147. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17148. }
  17149. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17150. fprintf(fp, "\n");
  17151. fclose(fp);
  17152. } else {
  17153. ShowError("Failed to write '%s'.\n", packet_txt);
  17154. // Dump on console instead
  17155. if( sd ) {
  17156. 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);
  17157. } else {
  17158. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17159. }
  17160. ShowDump(RFIFOP(fd,0), packet_len);
  17161. }
  17162. }
  17163. #endif
  17164. /// Roulette System
  17165. /// Author: Yommy
  17166. /// Opens the roulette window
  17167. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17168. void clif_roulette_open( struct map_session_data* sd ){
  17169. nullpo_retv( sd );
  17170. struct packet_roulette_open_ack p;
  17171. p.PacketType = 0xa1a;
  17172. p.Result = 0; // result
  17173. p.Serial = 0; // serial
  17174. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17175. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17176. p.AdditionItemID = -1; //! TODO: Display bonus item
  17177. p.GoldPoint = sd->roulette_point.gold;
  17178. p.SilverPoint = sd->roulette_point.silver;
  17179. p.BronzePoint = sd->roulette_point.bronze;
  17180. sd->state.roulette_open = true;
  17181. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17182. }
  17183. /// Request to open the roulette window
  17184. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17185. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  17186. nullpo_retv(sd);
  17187. if (!battle_config.feature_roulette) {
  17188. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17189. return;
  17190. }
  17191. clif_roulette_open(sd);
  17192. }
  17193. /// Sends the info about the available roulette rewards to the client
  17194. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17195. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17196. void clif_roulette_info( struct map_session_data* sd ){
  17197. nullpo_retv(sd);
  17198. struct packet_roulette_info_ack p;
  17199. p.PacketType = rouletteinfoackType;
  17200. p.PacketLength = sizeof(p);
  17201. p.RouletteSerial = 1;
  17202. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17203. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17204. p.ItemInfo[count].Row = i;
  17205. p.ItemInfo[count].Position = j;
  17206. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17207. p.ItemInfo[count].Count = rd.qty[i][j];
  17208. #if PACKETVER >= 20180511
  17209. p.ItemInfo[count].unused = 0;
  17210. #endif
  17211. count++;
  17212. }
  17213. }
  17214. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17215. }
  17216. /// Request the roulette reward data
  17217. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17218. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  17219. nullpo_retv(sd);
  17220. if (!battle_config.feature_roulette) {
  17221. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17222. return;
  17223. }
  17224. clif_roulette_info(sd);
  17225. }
  17226. /// Notification of the client that the roulette window was closed
  17227. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17228. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  17229. nullpo_retv(sd);
  17230. if (!battle_config.feature_roulette) {
  17231. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17232. return;
  17233. }
  17234. sd->state.roulette_open = false;
  17235. }
  17236. /// Response to a item reward request
  17237. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17238. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17239. #if PACKETVER >= 20141016
  17240. nullpo_retv(sd);
  17241. struct packet_roulette_itemrecv_ack p;
  17242. p.PacketType = roulettercvitemackType;
  17243. p.Result = type;
  17244. p.AdditionItemID = 0; //! TODO: Additional item
  17245. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17246. #endif
  17247. }
  17248. /**
  17249. * Claim roulette reward
  17250. * @param sd Player
  17251. * @return 0:Success
  17252. **/
  17253. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  17254. struct item it;
  17255. uint8 res = 1;
  17256. nullpo_retr(1, sd);
  17257. if (sd->roulette.prizeIdx < 0)
  17258. return RECV_ITEM_FAILED;
  17259. memset(&it, 0, sizeof(it));
  17260. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17261. it.identify = 1;
  17262. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  17263. ; // onSuccess
  17264. }
  17265. sd->roulette.claimPrize = false;
  17266. sd->roulette.prizeStage = 0;
  17267. sd->roulette.prizeIdx = -1;
  17268. sd->roulette.stage = 0;
  17269. return res;
  17270. }
  17271. /// Update Roulette window with current stats
  17272. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17273. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17274. nullpo_retv( sd );
  17275. struct packet_roulette_generate_ack p;
  17276. p.PacketType = roulettgenerateackType;
  17277. p.Result = result;
  17278. p.Step = stage;
  17279. p.Idx = prizeIdx;
  17280. p.AdditionItemID = bonusItemID;
  17281. p.RemainGold = sd->roulette_point.gold;
  17282. p.RemainSilver = sd->roulette_point.silver;
  17283. p.RemainBronze = sd->roulette_point.bronze;
  17284. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17285. }
  17286. /// Request to start the roulette
  17287. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17288. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  17289. enum GENERATE_ROULETTE_ACK result;
  17290. nullpo_retv(sd);
  17291. if (!battle_config.feature_roulette) {
  17292. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17293. return;
  17294. }
  17295. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17296. return;
  17297. }
  17298. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17299. sd->roulette.stage = 0;
  17300. sd->roulette.claimPrize = false;
  17301. sd->roulette.prizeStage = 0;
  17302. sd->roulette.prizeIdx = -1;
  17303. }
  17304. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17305. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17306. }else{
  17307. if (!sd->roulette.stage) {
  17308. if (sd->roulette_point.bronze > 0) {
  17309. sd->roulette_point.bronze -= 1;
  17310. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17311. } else if (sd->roulette_point.silver > 9) {
  17312. sd->roulette_point.silver -= 10;
  17313. sd->roulette.stage = 2;
  17314. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17315. } else if (sd->roulette_point.gold > 9) {
  17316. sd->roulette_point.gold -= 10;
  17317. sd->roulette.stage = 4;
  17318. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17319. }
  17320. }
  17321. sd->roulette.prizeStage = sd->roulette.stage;
  17322. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17323. sd->roulette.claimPrize = true;
  17324. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17325. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17326. result = GENERATE_ROULETTE_LOSING;
  17327. sd->roulette.stage = 0;
  17328. }else{
  17329. result = GENERATE_ROULETTE_SUCCESS;
  17330. sd->roulette.stage++;
  17331. }
  17332. }
  17333. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17334. }
  17335. /// Request to claim a prize
  17336. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17337. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17338. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17339. nullpo_retv(sd);
  17340. if (!battle_config.feature_roulette) {
  17341. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17342. return;
  17343. }
  17344. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17345. return;
  17346. }
  17347. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17348. switch (clif_roulette_getitem(sd)) {
  17349. case ADDITEM_SUCCESS:
  17350. type = RECV_ITEM_SUCCESS;
  17351. break;
  17352. case ADDITEM_INVALID:
  17353. case ADDITEM_OVERITEM:
  17354. case ADDITEM_OVERAMOUNT:
  17355. type = RECV_ITEM_OVERCOUNT;
  17356. break;
  17357. case ADDITEM_OVERWEIGHT:
  17358. type = RECV_ITEM_OVERWEIGHT;
  17359. break;
  17360. case ADDITEM_STACKLIMIT:
  17361. default:
  17362. type = RECV_ITEM_FAILED;
  17363. break;
  17364. }
  17365. }
  17366. clif_roulette_recvitem_ack(sd,type);
  17367. }
  17368. /// MERGE ITEM
  17369. /**
  17370. * Acknowledge the client about item merger result
  17371. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17372. * @param fd
  17373. * @param sd
  17374. **/
  17375. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  17376. unsigned char buf[9];
  17377. struct s_packet_db *info = NULL;
  17378. short cmd = 0;
  17379. nullpo_retv(sd);
  17380. if (!clif_session_isValid(sd))
  17381. return;
  17382. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  17383. return;
  17384. if (!(info = &packet_db[cmd]) || info->len == 0)
  17385. return;
  17386. WBUFW(buf, 0) = cmd;
  17387. WBUFW(buf, info->pos[0]) = index;
  17388. WBUFW(buf, info->pos[1]) = count;
  17389. WBUFB(buf, info->pos[2]) = type;
  17390. clif_send(buf, info->len, &sd->bl, SELF);
  17391. }
  17392. /**
  17393. * Check if item has the pair to be merged
  17394. * @param sd
  17395. * @param it Item
  17396. * @return True if has pair, False if not
  17397. **/
  17398. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17399. struct item *it_;
  17400. unsigned short i;
  17401. nullpo_retr(false, sd);
  17402. 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);
  17403. if (i < MAX_INVENTORY)
  17404. return true;
  17405. return false;
  17406. }
  17407. /**
  17408. * Check if item can be merged
  17409. * @param id Item Data
  17410. * @param it Item
  17411. * @return True if can be merged, False if not
  17412. **/
  17413. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17414. if (!id || !it)
  17415. return false;
  17416. if (id->type == IT_CASH)
  17417. return false;
  17418. if (!itemdb_isstackable2(id))
  17419. return false;
  17420. if (itemdb_isspecial(it->card[0]))
  17421. return false;
  17422. if (!it->unique_id)
  17423. return false;
  17424. return true;
  17425. }
  17426. /**
  17427. * Open available item to be merged.
  17428. * Only show 1 item in 1 process.
  17429. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17430. * @param sd
  17431. **/
  17432. void clif_merge_item_open(struct map_session_data *sd) {
  17433. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  17434. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  17435. int len = 0;
  17436. struct s_packet_db *info = NULL;
  17437. struct item *it;
  17438. nullpo_retv(sd);
  17439. if (!clif_session_isValid(sd))
  17440. return;
  17441. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  17442. return;
  17443. if (!(info = &packet_db[cmd]) || info->len == 0)
  17444. return;
  17445. // Get entries
  17446. for (i = 0; i < MAX_INVENTORY; i++) {
  17447. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  17448. continue;
  17449. if (clif_merge_item_has_pair(sd, it))
  17450. indexes[n++] = i;
  17451. }
  17452. if (n < 2) { // No item need to be merged
  17453. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17454. return;
  17455. }
  17456. WBUFW(buf, 0) = cmd;
  17457. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  17458. for (i = 0; i < n; i++) {
  17459. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  17460. }
  17461. clif_send(buf, len, &sd->bl, SELF);
  17462. }
  17463. /**
  17464. * Process item merger
  17465. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17466. * @param fd
  17467. * @param sd
  17468. **/
  17469. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17470. struct s_packet_db *info = NULL;
  17471. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17472. unsigned int count = 0;
  17473. struct item_data *id = NULL;
  17474. nullpo_retv(sd);
  17475. if (!clif_session_isValid(sd))
  17476. return;
  17477. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17478. return;
  17479. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17480. if (n < 2) { // No item need to be merged
  17481. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17482. return;
  17483. }
  17484. for (i = 0, j = 0; i < n; i++) {
  17485. uint16 idx = server_index( RFIFOW( fd, info->pos[1] + i * 2 ) );
  17486. if( idx >= MAX_INVENTORY ){
  17487. return;
  17488. }
  17489. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17490. continue;
  17491. indexes[j] = idx;
  17492. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17493. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17494. return;
  17495. }
  17496. count += sd->inventory.u.items_inventory[idx].amount;
  17497. j++;
  17498. }
  17499. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17500. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17501. return;
  17502. }
  17503. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17504. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17505. return;
  17506. }
  17507. // Merrrrge!!!!
  17508. for (i = 1; i < n; i++) {
  17509. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17510. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17511. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17512. sd->inventory_data[idx] = NULL;
  17513. clif_delitem(sd, idx, amt, 0);
  17514. }
  17515. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17516. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17517. }
  17518. /**
  17519. * Cancel item merge
  17520. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17521. * @param fd
  17522. * @param sd
  17523. **/
  17524. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17525. return; // Nothing todo yet
  17526. }
  17527. /**
  17528. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17529. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17530. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17531. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17532. **/
  17533. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17534. char name[NAME_LENGTH];
  17535. if( battle_config.broadcast_hide_name ){
  17536. std::string dispname = std::string( char_name );
  17537. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  17538. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  17539. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  17540. }else{
  17541. safestrncpy( name, char_name, sizeof( name ) );
  17542. }
  17543. switch( type ){
  17544. case ITEMOBTAIN_TYPE_BOXITEM:
  17545. {
  17546. struct packet_package_item_announce p;
  17547. p.PacketType = package_item_announceType;
  17548. p.type = type;
  17549. p.ItemID = client_nameid( nameid );
  17550. p.len = NAME_LENGTH;
  17551. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17552. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  17553. p.BoxItemID = client_nameid( container );
  17554. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17555. p.PacketLength = 15 + p.len;
  17556. #else
  17557. p.PacketLength = 11 + p.len;
  17558. #endif
  17559. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17560. }
  17561. break;
  17562. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17563. case ITEMOBTAIN_TYPE_NPC:
  17564. {
  17565. struct packet_item_drop_announce p;
  17566. p.PacketType = item_drop_announceType;
  17567. p.type = type;
  17568. p.ItemID = client_nameid( nameid );
  17569. p.len = NAME_LENGTH;
  17570. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17571. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17572. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17573. p.monsterNameLen = NAME_LENGTH;
  17574. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17575. }else{
  17576. p.monsterNameLen = 0;
  17577. p.monsterName[0] = '\0';
  17578. }
  17579. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17580. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17581. #else
  17582. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17583. #endif
  17584. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17585. }
  17586. break;
  17587. }
  17588. }
  17589. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17590. /// 0A02 <view>.W
  17591. /// Value <flag> has the following effects:
  17592. /// 1: Open a Dress Room window.
  17593. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17594. #if PACKETVER >= 20150513
  17595. int fd = sd->fd;
  17596. nullpo_retv(sd);
  17597. WFIFOHEAD(fd, packet_len(0xa02));
  17598. WFIFOW(fd,0) = 0xa02;
  17599. WFIFOW(fd,2) = flag;
  17600. WFIFOSET(fd, packet_len(0xa02));
  17601. #endif
  17602. }
  17603. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17604. /// 0A35 <result>.W
  17605. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17606. #if PACKETVER >= 20150513
  17607. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17608. // Ignore the request
  17609. // - Invalid item index
  17610. // - Invalid item ID or item doesn't exist
  17611. // - Item is already identified
  17612. if (idx < 0 || idx >= MAX_INVENTORY ||
  17613. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17614. sd->inventory.u.items_inventory[idx].identify)
  17615. return;
  17616. // Ignore the request - No magnifiers in inventory
  17617. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17618. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17619. return;
  17620. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17621. return;
  17622. skill_identify(sd, idx);
  17623. #endif
  17624. }
  17625. /// Starts navigation to the given target on client side
  17626. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17627. #if PACKETVER >= 20111010
  17628. int fd = sd->fd;
  17629. WFIFOHEAD(fd,27);
  17630. WFIFOW(fd,0) = 0x08e2;
  17631. // How detailed will our navigation be?
  17632. if( mob_id > 0 ){
  17633. x = 0;
  17634. y = 0;
  17635. WFIFOB(fd,2) = 3; // monster with destination field
  17636. }else if( x > 0 && y > 0 ){
  17637. WFIFOB(fd,2) = 0; // with coordinates
  17638. }else{
  17639. x = 0;
  17640. y = 0;
  17641. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17642. }
  17643. // Which services can be used for transportation?
  17644. WFIFOB(fd,3) = flag;
  17645. // If this flag is set, the navigation window will not be opened up
  17646. WFIFOB(fd,4) = hideWindow;
  17647. // Target map
  17648. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17649. // Target x
  17650. WFIFOW(fd,21) = x;
  17651. // Target y
  17652. WFIFOW(fd,23) = y;
  17653. // Target monster ID
  17654. WFIFOW(fd,25) = mob_id;
  17655. WFIFOSET(fd,27);
  17656. #endif
  17657. }
  17658. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17659. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17660. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17661. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17662. struct map_session_data *tsd;
  17663. struct block_list* tbl;
  17664. if( target == SELF ){
  17665. tsd = BL_CAST(BL_PC,bl);
  17666. tbl = &sd->bl;
  17667. }else{
  17668. tsd = sd;
  17669. tbl = bl;
  17670. }
  17671. nullpo_retv( tsd );
  17672. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17673. return;
  17674. }
  17675. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17676. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17677. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17678. p->aid = tsd->bl.id;
  17679. p->status = 1;
  17680. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17681. p->effects[i] = tsd->hatEffects[i];
  17682. }
  17683. clif_send( p, p->packetLength, tbl, target );
  17684. #endif
  17685. }
  17686. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17687. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17688. nullpo_retv( sd );
  17689. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17690. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17691. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17692. p->aid = sd->bl.id;
  17693. p->status = enable;
  17694. p->effects[0] = effectId;
  17695. clif_send( p, p->packetLength, &sd->bl, AREA );
  17696. #endif
  17697. }
  17698. /// Notify the client that a sale has started
  17699. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17700. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17701. #if PACKETVER_SUPPORTS_SALES
  17702. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17703. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17704. p.itemId = client_nameid( sale_item->nameid );
  17705. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17706. clif_send( &p, sizeof( p ), bl, target );
  17707. #endif
  17708. }
  17709. /// Notify the client that a sale has ended
  17710. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17711. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17712. #if PACKETVER_SUPPORTS_SALES
  17713. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17714. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17715. p.itemId = client_nameid( sale_item->nameid );
  17716. clif_send( &p, sizeof( p ), bl, target );
  17717. #endif
  17718. }
  17719. /// Update the remaining amount of a sale item.
  17720. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17721. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17722. #if PACKETVER_SUPPORTS_SALES
  17723. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17724. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17725. p.itemId = client_nameid( sale_item->nameid );
  17726. p.amount = sale_item->amount;
  17727. clif_send( &p, sizeof( p ), bl, target );
  17728. #endif
  17729. }
  17730. /// The client requested a refresh of the current remaining count of a sale item
  17731. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17732. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17733. #if PACKETVER_SUPPORTS_SALES
  17734. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17735. struct sale_item_data* sale;
  17736. if( p->AID != sd->status.account_id ){
  17737. return;
  17738. }
  17739. sale = sale_find_item( p->itemId, true );
  17740. if( sale == NULL ){
  17741. return;
  17742. }
  17743. clif_sale_amount(sale, &sd->bl, SELF);
  17744. #endif
  17745. }
  17746. /// Opens the sale administration window on the client
  17747. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17748. void clif_sale_open( struct map_session_data* sd ){
  17749. #if PACKETVER_SUPPORTS_SALES
  17750. nullpo_retv(sd);
  17751. if( sd->state.sale_open ){
  17752. return;
  17753. }
  17754. sd->state.sale_open = true;
  17755. int fd = sd->fd;
  17756. WFIFOHEAD(fd, 2);
  17757. WFIFOW(fd, 0) = 0x9b5;
  17758. WFIFOSET(fd, 2);
  17759. #endif
  17760. }
  17761. /// Client request to open the sale administration window.
  17762. /// This is sent by /limitedsale
  17763. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17764. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17765. #if PACKETVER_SUPPORTS_SALES
  17766. nullpo_retv(sd);
  17767. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17768. return;
  17769. }
  17770. char command[CHAT_SIZE_MAX];
  17771. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17772. is_atcommand(fd, sd, command, 1);
  17773. #endif
  17774. }
  17775. /// Closes the sale administration window on the client.
  17776. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17777. void clif_sale_close(struct map_session_data* sd) {
  17778. #if PACKETVER_SUPPORTS_SALES
  17779. nullpo_retv(sd);
  17780. if( !sd->state.sale_open ){
  17781. return;
  17782. }
  17783. sd->state.sale_open = false;
  17784. int fd = sd->fd;
  17785. WFIFOHEAD(fd, 2);
  17786. WFIFOW(fd, 0) = 0x9bd;
  17787. WFIFOSET(fd, 2);
  17788. #endif
  17789. }
  17790. /// Client request to close the sale administration window.
  17791. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17792. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17793. #if PACKETVER_SUPPORTS_SALES
  17794. nullpo_retv(sd);
  17795. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17796. return;
  17797. }
  17798. clif_sale_close(sd);
  17799. #endif
  17800. }
  17801. /// Reply to a item search request for item sale administration.
  17802. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17803. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17804. #if PACKETVER_SUPPORTS_SALES
  17805. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17806. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17807. if( item != NULL ){
  17808. p.result = 0;
  17809. p.itemId = client_nameid( item->nameid );
  17810. p.price = item->price;
  17811. }else{
  17812. p.result = 1;
  17813. p.itemId = 0;
  17814. p.price = 0;
  17815. }
  17816. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17817. #endif
  17818. }
  17819. /// Search request for an item sale administration.
  17820. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17821. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17822. #if PACKETVER_SUPPORTS_SALES
  17823. char item_name[ITEM_NAME_LENGTH];
  17824. nullpo_retv(sd);
  17825. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17826. return;
  17827. }
  17828. if( !sd->state.sale_open ){
  17829. return;
  17830. }
  17831. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17832. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17833. if( id ){
  17834. int i;
  17835. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17836. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17837. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17838. return;
  17839. }
  17840. }
  17841. }
  17842. // not found
  17843. clif_sale_search_reply( sd, NULL );
  17844. #endif
  17845. }
  17846. /// Reply if an item was successfully put on sale or not.
  17847. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17848. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17849. #if PACKETVER_SUPPORTS_SALES
  17850. int fd = sd->fd;
  17851. WFIFOHEAD(fd, 4);
  17852. WFIFOW(fd, 0) = 0x9af;
  17853. WFIFOW(fd, 2) = (uint16)result;
  17854. WFIFOSET(fd, 4);
  17855. #endif
  17856. }
  17857. /// A client request to put an item on sale.
  17858. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17859. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17860. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17861. #if PACKETVER_SUPPORTS_SALES
  17862. nullpo_retv( sd );
  17863. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17864. if( p->AID != sd->status.account_id ){
  17865. return;
  17866. }
  17867. if( !sd->state.sale_open ){
  17868. return;
  17869. }
  17870. time_t endTime = p->startTime + p->hours * 60 * 60;
  17871. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17872. #endif
  17873. }
  17874. /// Reply to an item removal from sale.
  17875. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17876. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17877. #if PACKETVER_SUPPORTS_SALES
  17878. int fd = sd->fd;
  17879. WFIFOHEAD(fd, 4);
  17880. WFIFOW(fd, 0) = 0x9b1;
  17881. WFIFOW(fd, 2) = failed;
  17882. WFIFOSET(fd, 4);
  17883. #endif
  17884. }
  17885. /// Request to remove an item from sale.
  17886. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17887. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17888. #if PACKETVER_SUPPORTS_SALES
  17889. nullpo_retv( sd );
  17890. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17891. if( p->AID != sd->status.account_id ){
  17892. return;
  17893. }
  17894. if( !sd->state.sale_open ){
  17895. return;
  17896. }
  17897. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17898. #endif
  17899. }
  17900. /// Achievement System
  17901. /// Author: Luxuri, Aleos
  17902. /**
  17903. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17904. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17905. */
  17906. void clif_achievement_list_all(struct map_session_data *sd)
  17907. {
  17908. nullpo_retv(sd);
  17909. if (!battle_config.feature_achievement) {
  17910. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17911. return;
  17912. }
  17913. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17914. if (count == 0)
  17915. return;
  17916. int len = (50 * count) + 22;
  17917. int fd = sd->fd;
  17918. int *info = achievement_level(sd, true);
  17919. WFIFOHEAD(fd,len);
  17920. WFIFOW(fd, 0) = 0xa23;
  17921. WFIFOW(fd, 2) = len;
  17922. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17923. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17924. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17925. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17926. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17927. for (int i = 0; i < count; i++) {
  17928. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17929. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17930. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17931. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17932. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17933. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17934. }
  17935. WFIFOSET(fd, len);
  17936. }
  17937. /**
  17938. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17939. * 0a24 <ACHPoint>.L
  17940. */
  17941. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17942. {
  17943. nullpo_retv(sd);
  17944. if (!battle_config.feature_achievement) {
  17945. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17946. return;
  17947. }
  17948. int fd = sd->fd;
  17949. int *info = achievement_level(sd, true);
  17950. WFIFOHEAD(fd, packet_len(0xa24));
  17951. WFIFOW(fd, 0) = 0xa24;
  17952. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17953. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17954. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17955. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17956. if (ach) {
  17957. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17958. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17959. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17960. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17961. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17962. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17963. } else
  17964. memset(WFIFOP(fd, 16), 0, 40);
  17965. WFIFOSET(fd, packet_len(0xa24));
  17966. }
  17967. /**
  17968. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17969. * 0a25 <achievementID>.L
  17970. */
  17971. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17972. {
  17973. nullpo_retv(sd);
  17974. if( sd->achievement_data.save )
  17975. intif_achievement_save(sd);
  17976. achievement_check_reward(sd, RFIFOL(fd,2));
  17977. }
  17978. /**
  17979. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17980. * 0a26 <result>.W <achievementID>.L
  17981. */
  17982. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17983. {
  17984. WFIFOHEAD(fd, packet_len(0xa26));
  17985. WFIFOW(fd, 0) = 0xa26;
  17986. WFIFOB(fd, 2) = result;
  17987. WFIFOL(fd, 3) = achievement_id;
  17988. WFIFOSET(fd, packet_len(0xa26));
  17989. }
  17990. /// Process the pet evolution request
  17991. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17992. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17993. #if PACKETVER >= 20141008
  17994. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17995. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17996. if (!pet) {
  17997. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17998. return;
  17999. }
  18000. pet_evolution(sd, pet->class_);
  18001. #endif
  18002. }
  18003. /// Sends the result of the evolution to the client.
  18004. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  18005. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  18006. #if PACKETVER >= 20141008
  18007. int fd = sd->fd;
  18008. WFIFOHEAD(fd, packet_len(0x9fc));
  18009. WFIFOW(fd, 0) = 0x9fc;
  18010. WFIFOL(fd, 2) = static_cast<uint32>(result);
  18011. WFIFOSET(fd, packet_len(0x9fc));
  18012. #endif
  18013. }
  18014. /*
  18015. * This packet is sent by /changedress or /nocosplay
  18016. *
  18017. * 0ae8
  18018. */
  18019. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  18020. #if PACKETVER >= 20180103
  18021. char command[CHAT_SIZE_MAX];
  18022. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  18023. is_atcommand( fd, sd, command, 1 );
  18024. #endif
  18025. }
  18026. /// Opens an UI window of the given type and initializes it with the given data
  18027. /// 0AE2 <type>.B <data>.L
  18028. void clif_ui_open( struct map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  18029. #if PACKETVER >= 20151202
  18030. // If the UI requires state tracking
  18031. switch( ui_type ){
  18032. case OUT_UI_STYLIST:
  18033. sd.state.stylist_open = true;
  18034. break;
  18035. case OUT_UI_ENCHANTGRADE:
  18036. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  18037. sd.state.enchantgrade_open = true;
  18038. break;
  18039. #else
  18040. return;
  18041. #endif
  18042. }
  18043. struct PACKET_ZC_UI_OPEN p = {};
  18044. p.PacketType = HEADER_ZC_UI_OPEN;
  18045. p.UIType = ui_type;
  18046. #if PACKETVER >= 20171122
  18047. p.data = data;
  18048. #endif
  18049. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  18050. #endif
  18051. }
  18052. /// Request to open an UI window of the given type
  18053. /// 0A68 <type>.B
  18054. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  18055. switch( RFIFOB(fd,2) ){
  18056. case IN_UI_ATTENDANCE:
  18057. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  18058. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  18059. }else if( pc_attendance_enabled() ){
  18060. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  18061. }else{
  18062. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  18063. }
  18064. break;
  18065. }
  18066. }
  18067. /// Response for attedance request
  18068. /// 0AF0 <unknown>.L <data>.L
  18069. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  18070. nullpo_retv(sd);
  18071. int fd = sd->fd;
  18072. WFIFOHEAD(fd,packet_len(0xAF0));
  18073. WFIFOW(fd,0) = 0xAF0;
  18074. WFIFOL(fd,2) = 0;
  18075. WFIFOL(fd,6) = data;
  18076. WFIFOSET(fd,packet_len(0xAF0));
  18077. }
  18078. /// Request from the client to retrieve today's attendance reward
  18079. /// 0AEF
  18080. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  18081. pc_attendance_claim_reward(sd);
  18082. }
  18083. /// Send out the percentage of weight that causes it to be displayed in red.
  18084. /// 0ADE <percentage>.L
  18085. void clif_weight_limit( struct map_session_data* sd ){
  18086. #if PACKETVER >= 20171025
  18087. nullpo_retv(sd);
  18088. int fd = sd->fd;
  18089. WFIFOHEAD(fd, packet_len(0xADE));
  18090. WFIFOW(fd, 0) = 0xADE;
  18091. #ifdef RENEWAL
  18092. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18093. #else
  18094. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18095. #endif
  18096. WFIFOSET(fd, packet_len(0xADE));
  18097. #endif
  18098. }
  18099. enum e_private_airship_response : uint32{
  18100. PRIVATEAIRSHIP_OK,
  18101. PRIVATEAIRSHIP_RETRY,
  18102. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18103. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18104. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18105. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18106. };
  18107. /// Send out the response to a private airship request
  18108. /// 0A4A <response>.L
  18109. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  18110. #if PACKETVER >= 20180321
  18111. nullpo_retv( sd );
  18112. int fd = sd->fd;
  18113. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18114. WFIFOW( fd, 0 ) = 0xA4A;
  18115. WFIFOL( fd, 2 ) = response;
  18116. WFIFOSET( fd, packet_len( 0xA4A ) );
  18117. #endif
  18118. }
  18119. /// Parses a request for a private airship
  18120. /// 0A49 <mapname>.16B <itemid>.W
  18121. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  18122. #if PACKETVER >= 20180321
  18123. // Check if the feature is enabled
  18124. if( !battle_config.feature_privateairship ){
  18125. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18126. return;
  18127. }
  18128. // Check if the player is allowed to warp from the source map
  18129. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18130. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18131. return;
  18132. }
  18133. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18134. char mapname[MAP_NAME_LENGTH_EXT];
  18135. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18136. int16 mapindex = mapindex_name2id( mapname );
  18137. // Check if we know the mapname
  18138. if( mapindex < 0 ){
  18139. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18140. return;
  18141. }
  18142. int16 mapid = map_mapindex2mapid( mapindex );
  18143. // Check if the map is available on this server
  18144. if( mapid < 0 ){
  18145. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18146. return;
  18147. }
  18148. // Check if the player tried to warp to the map he is on
  18149. if( sd->bl.m == mapid ){
  18150. // This is blocked by the client, but just to be sure
  18151. return;
  18152. }
  18153. // This can only be a hack, so we prevent it
  18154. if( map_getmapdata( mapid )->instance_id ){
  18155. // Ignore requests to warp directly into a running instance
  18156. return;
  18157. }
  18158. // Check if the player is allowed to warp to the target map
  18159. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18160. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18161. return;
  18162. }
  18163. t_itemid item_id = p->ItemID;
  18164. // Check if the item sent by the client is known to us
  18165. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18166. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18167. return;
  18168. }
  18169. int idx = pc_search_inventory( sd, item_id );
  18170. // Check if the player has the item at all
  18171. if( idx < 0 ){
  18172. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18173. return;
  18174. }
  18175. // Delete the chosen item
  18176. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18177. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18178. return;
  18179. }
  18180. // Warp the player to a random spot on the destination map
  18181. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18182. #endif
  18183. }
  18184. /// Sends out the usage history of the guild storage
  18185. /// 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
  18186. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18187. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18188. #if PACKETVER >= 20140205
  18189. nullpo_retv( sd );
  18190. int fd = sd->fd;
  18191. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18192. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18193. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18194. }else{
  18195. log.clear();
  18196. }
  18197. WFIFOHEAD( fd, size );
  18198. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18199. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18200. p->PacketLength = size;
  18201. p->result = result;
  18202. p->amount = (uint16)log.size();
  18203. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18204. for( int i = 0; i < log.size(); i++ ){
  18205. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18206. struct guild_log_entry& entry = log[i];
  18207. item->id = entry.id;
  18208. item->itemId = client_nameid( entry.item.nameid );
  18209. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18210. item->action = entry.amount > 0; // action = true(put), false(get)
  18211. item->refine = entry.item.refine;
  18212. item->uniqueId = entry.item.unique_id;
  18213. item->IsIdentified = entry.item.identify;
  18214. item->itemType = itemtype( entry.item.nameid );
  18215. clif_addcards( &item->slot, &entry.item );
  18216. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18217. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18218. item->attribute = entry.item.attribute;
  18219. }
  18220. }
  18221. WFIFOSET( fd, p->PacketLength );
  18222. #endif
  18223. }
  18224. /// Activates the client camera info or updates the client camera with the given values.
  18225. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18226. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18227. #if PACKETVER >= 20160525
  18228. int fd = sd->fd;
  18229. WFIFOHEAD(fd, packet_len(0xa78));
  18230. WFIFOW(fd, 0) = 0xa78;
  18231. WFIFOB(fd, 2) = show;
  18232. WFIFOF(fd, 3) = range;
  18233. WFIFOF(fd, 7) = rotation;
  18234. WFIFOF(fd, 11) = latitude;
  18235. WFIFOSET(fd, packet_len(0xa78));
  18236. #endif
  18237. }
  18238. /// Activates or deactives the client camera info or updates the camera settings.
  18239. /// This packet is triggered by /viewpointvalue or /setcamera
  18240. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18241. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  18242. char command[CHAT_SIZE_MAX];
  18243. // /viewpointvalue
  18244. if( RFIFOB( fd, 2 ) == 1 ){
  18245. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18246. // /setcamera
  18247. }else{
  18248. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18249. }
  18250. is_atcommand( fd, sd, command, 1 );
  18251. }
  18252. /// Send the full list of items in the equip switch window
  18253. /// 0a9b <length>.W { <index>.W <position>.L }*
  18254. void clif_equipswitch_list( struct map_session_data* sd ){
  18255. #if PACKETVER >= 20170208
  18256. int fd = sd->fd;
  18257. int offset, i, position;
  18258. WFIFOW(fd, 0) = 0xa9b;
  18259. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18260. short index = sd->equip_switch_index[i];
  18261. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18262. WFIFOW(fd, offset) = index + 2;
  18263. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18264. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18265. offset += 6;
  18266. }
  18267. }
  18268. WFIFOW(fd, 2) = offset;
  18269. WFIFOSET(fd, offset);
  18270. #endif
  18271. }
  18272. /// Acknowledgement for removing an equip to the equip switch window
  18273. /// 0a9a <index>.W <position.>.L <failure>.W
  18274. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18275. #if PACKETVER >= 20170208
  18276. int fd = sd->fd;
  18277. WFIFOHEAD(fd, packet_len(0xa9a));
  18278. WFIFOW(fd, 0) = 0xa9a;
  18279. WFIFOW(fd, 2) = index + 2;
  18280. WFIFOL(fd, 4) = pos;
  18281. WFIFOW(fd, 8) = failed;
  18282. WFIFOSET(fd, packet_len(0xa9a));
  18283. #endif
  18284. }
  18285. /// Request to remove an equip from the equip switch window
  18286. /// 0a99 <index>.W <position>.L <= 20170502
  18287. /// 0a99 <index>.W
  18288. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  18289. #if PACKETVER >= 20170208
  18290. uint16 index = RFIFOW(fd, 2) - 2;
  18291. bool removed = false;
  18292. if( !battle_config.feature_equipswitch ){
  18293. return;
  18294. }
  18295. // Check if the index is valid
  18296. if( index >= MAX_INVENTORY ){
  18297. return;
  18298. }
  18299. pc_equipswitch_remove( sd, index );
  18300. #endif
  18301. }
  18302. /// Acknowledgement for adding an equip to the equip switch window
  18303. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18304. /// 0a98 <index>.W <position.>.L <flag>.W
  18305. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18306. #if PACKETVER >= 20170208
  18307. int fd = sd->fd;
  18308. WFIFOHEAD(fd, packet_len(0xa98));
  18309. WFIFOW(fd, 0) = 0xa98;
  18310. WFIFOW(fd, 2) = index + 2;
  18311. WFIFOL(fd, 4) = pos;
  18312. #if PACKETVER <= 20170502
  18313. WFIFOL(fd, 8) = flag;
  18314. #else
  18315. WFIFOW(fd, 8) = flag;
  18316. #endif
  18317. WFIFOSET(fd,packet_len(0xa98));
  18318. #endif
  18319. }
  18320. /// Request to add an equip to the equip switch window
  18321. /// 0a97 <index>.W <position>.L
  18322. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  18323. #if PACKETVER >= 20170208
  18324. uint16 index = RFIFOW(fd, 2) - 2;
  18325. uint32 position = RFIFOL(fd, 4);
  18326. if( !battle_config.feature_equipswitch ){
  18327. return;
  18328. }
  18329. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18330. return;
  18331. }
  18332. if( sd->state.trading || sd->npc_shopid ){
  18333. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18334. return;
  18335. }
  18336. if( sd->inventory_data[index]->type == IT_AMMO ){
  18337. position = EQP_AMMO;
  18338. }
  18339. pc_equipitem( sd, index, position, true );
  18340. #endif
  18341. }
  18342. /// Acknowledgement packet for the full equip switch
  18343. /// 0a9d <failed>.W
  18344. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  18345. #if PACKETVER >= 20170208
  18346. int fd = sd->fd;
  18347. WFIFOHEAD(fd, packet_len(0xa9d));
  18348. WFIFOW(fd, 0) = 0xa9d;
  18349. WFIFOW(fd, 2) = failed;
  18350. WFIFOSET(fd, packet_len(0xa9d));
  18351. #endif
  18352. }
  18353. /// Request to do a full equip switch
  18354. /// 0a9c
  18355. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18356. #if PACKETVER >= 20170208
  18357. int i;
  18358. t_tick tick = gettick();
  18359. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18360. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18361. // Client will not let you send a request
  18362. return;
  18363. }
  18364. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18365. if( !battle_config.feature_equipswitch ){
  18366. return;
  18367. }
  18368. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18369. if( i == EQI_MAX ){
  18370. // client will show: "There is no item to replace." and should not even come here
  18371. clif_equipswitch_reply( sd, false );
  18372. return;
  18373. }
  18374. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18375. return;
  18376. }
  18377. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18378. #endif
  18379. }
  18380. /// Request to do a single equip switch
  18381. /// 0ace <index>.W
  18382. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18383. #if PACKETVER >= 20170502
  18384. uint16 index = RFIFOW(fd, 2) - 2;
  18385. if( !battle_config.feature_equipswitch ){
  18386. return;
  18387. }
  18388. // Check if the index is valid
  18389. if( index >= MAX_INVENTORY ){
  18390. return;
  18391. }
  18392. // Check if the item exists
  18393. if (sd->inventory_data[index] == nullptr)
  18394. return;
  18395. // Check if the item was already added to equip switch
  18396. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18397. if( sd->npc_id ){
  18398. #ifdef RENEWAL
  18399. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18400. clif_msg( sd, WORK_IN_PROGRESS );
  18401. return;
  18402. }
  18403. #endif
  18404. if( !sd->npc_item_flag ){
  18405. return;
  18406. }
  18407. }
  18408. pc_equipswitch( sd, index );
  18409. return;
  18410. }
  18411. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18412. #endif
  18413. }
  18414. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18415. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18416. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18417. // Only rolling cutter is supported for now
  18418. if( p->skillId != GC_ROLLINGCUTTER ){
  18419. return;
  18420. }
  18421. // Already running - cant happen on officials, since only one skill is supported
  18422. if( sd->skill_keep_using.skill_id != 0 ){
  18423. return;
  18424. }
  18425. sd->skill_keep_using.tid = INVALID_TIMER;
  18426. sd->skill_keep_using.skill_id = p->skillId;
  18427. sd->skill_keep_using.level = p->skillLv;
  18428. sd->skill_keep_using.target = p->targetId;
  18429. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18430. #endif
  18431. }
  18432. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18433. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18434. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18435. // Not running
  18436. if( sd->skill_keep_using.skill_id == 0 ){
  18437. return;
  18438. }
  18439. #if 0
  18440. // Hack
  18441. if( p->skillId != sd->skill_keep_using.skill_id ){
  18442. return;
  18443. }
  18444. #endif
  18445. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18446. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18447. sd->skill_keep_using.tid = INVALID_TIMER;
  18448. }
  18449. sd->skill_keep_using.skill_id = 0;
  18450. sd->skill_keep_using.level = 0;
  18451. sd->skill_keep_using.target = 0;
  18452. #endif
  18453. }
  18454. void clif_ping( struct map_session_data* sd ){
  18455. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18456. nullpo_retv( sd );
  18457. int fd = sd->fd;
  18458. if( !session_isActive( fd ) ){
  18459. return;
  18460. }
  18461. struct PACKET_ZC_PING_LIVE p = {};
  18462. p.packetType = HEADER_ZC_PING_LIVE;
  18463. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18464. #endif
  18465. }
  18466. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18467. nullpo_ret( sd );
  18468. int fd = sd->fd;
  18469. if( !session_isActive( fd ) ){
  18470. return 0;
  18471. }
  18472. t_tick tick = va_arg( ap, t_tick );
  18473. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18474. clif_ping( sd );
  18475. }
  18476. return 0;
  18477. }
  18478. TIMER_FUNC( clif_ping_timer ){
  18479. map_foreachpc( clif_ping_timer_sub, gettick() );
  18480. return 0;
  18481. }
  18482. /**
  18483. * Opens the refine UI on the designated client.
  18484. * 0aa0
  18485. */
  18486. void clif_refineui_open( struct map_session_data* sd ){
  18487. #if PACKETVER >= 20161012
  18488. nullpo_retv( sd );
  18489. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18490. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18491. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18492. sd->state.refineui_open = true;
  18493. #endif
  18494. }
  18495. /**
  18496. * Parses cancel/close of the refine UI on client side.
  18497. * 0aa4
  18498. */
  18499. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18500. #if PACKETVER >= 20161012
  18501. sd->state.refineui_open = false;
  18502. #endif
  18503. }
  18504. /**
  18505. * Adds the selected item into the refine UI and sends the possible materials
  18506. * to the client.
  18507. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18508. */
  18509. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18510. #if PACKETVER >= 20161012
  18511. int fd = sd->fd;
  18512. // Get the item db reference
  18513. struct item_data* id = sd->inventory_data[index];
  18514. // No item data was found
  18515. if( id == NULL ){
  18516. return;
  18517. }
  18518. // Check the inventory
  18519. struct item* item = &sd->inventory.u.items_inventory[index];
  18520. // No item was found at the given index
  18521. if( item == NULL ){
  18522. return;
  18523. }
  18524. // Check if the item is identified
  18525. if( !item->identify ){
  18526. return;
  18527. }
  18528. // Check if the item is broken
  18529. if( item->attribute ){
  18530. return;
  18531. }
  18532. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18533. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18534. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18535. p->itemIndex = client_index( index );
  18536. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18537. // No possibilities were found
  18538. if( info == nullptr ){
  18539. p->blacksmithBlessing = 0;
  18540. }else{
  18541. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18542. uint16 count = 0;
  18543. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18544. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18545. if( cost != nullptr ){
  18546. p->req[count].itemId = client_nameid( cost->nameid );
  18547. p->req[count].chance = (uint8)( cost->chance / 100 );
  18548. p->req[count].zeny = cost->zeny;
  18549. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18550. count++;
  18551. }
  18552. }
  18553. }
  18554. clif_send( p, p->packetLength, &sd->bl, SELF );
  18555. #endif
  18556. }
  18557. /**
  18558. * Client request to add an item to the refine UI.
  18559. * 0aa1 <index>.W
  18560. */
  18561. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18562. #if PACKETVER >= 20161012
  18563. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18564. uint16 index = server_index( p->index );
  18565. // Check if the refine UI is open
  18566. if( !sd->state.refineui_open ){
  18567. return;
  18568. }
  18569. // Check if the index is valid
  18570. if( index >= MAX_INVENTORY ){
  18571. return;
  18572. }
  18573. // Send out the requirements for the refine process
  18574. clif_refineui_info( sd, index );
  18575. #endif
  18576. }
  18577. /**
  18578. * Client requests to try to refine an item.
  18579. * 0aa3 <index>.W <material>.W <catalyst>.B
  18580. */
  18581. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18582. #if PACKETVER >= 20161012
  18583. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18584. uint16 index = server_index( p->index );
  18585. t_itemid material = p->itemId;
  18586. int16 j;
  18587. // Check if the refine UI is open
  18588. if( !sd->state.refineui_open ){
  18589. return;
  18590. }
  18591. // Check if the index is valid
  18592. if( index >= MAX_INVENTORY ){
  18593. return;
  18594. }
  18595. // Get the item db reference
  18596. struct item_data* id = sd->inventory_data[index];
  18597. // No item data was found
  18598. if( id == NULL ){
  18599. return;
  18600. }
  18601. // Check the inventory
  18602. struct item* item = &sd->inventory.u.items_inventory[index];
  18603. // No item was found at the given index
  18604. if( item == NULL ){
  18605. return;
  18606. }
  18607. // Check if the item is identified
  18608. if( !item->identify ){
  18609. return;
  18610. }
  18611. // Check if the item is broken
  18612. if( item->attribute ){
  18613. return;
  18614. }
  18615. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18616. // No refine possible
  18617. if( info == nullptr ){
  18618. return;
  18619. }
  18620. // No possibilities were found
  18621. if( info->costs.empty() ){
  18622. return;
  18623. }
  18624. // Check if the player has the selected material
  18625. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18626. return;
  18627. }
  18628. int16 blacksmith_index = -1;
  18629. uint16 blacksmith_amount = 0;
  18630. // Check if the player has enough blacksmith blessings
  18631. if( p->blacksmithBlessing != 0 ){
  18632. blacksmith_amount = info->blessing_amount;
  18633. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18634. if( blacksmith_amount == 0 ){
  18635. return;
  18636. }
  18637. // Check if the player has blacksmith blessings
  18638. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18639. return;
  18640. }
  18641. // Check if the player has enough blacksmith blessings
  18642. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18643. return;
  18644. }
  18645. }
  18646. std::shared_ptr<s_refine_cost> cost = nullptr;
  18647. for( const auto& pair : info->costs ){
  18648. if( pair.second->nameid == material ){
  18649. cost = pair.second;
  18650. break;
  18651. }
  18652. }
  18653. // The material was not in the list of possible materials
  18654. if( cost == nullptr ){
  18655. return;
  18656. }
  18657. // Try to pay for the refine
  18658. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18659. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18660. return;
  18661. }
  18662. // Delete the required material
  18663. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18664. return;
  18665. }
  18666. // Delete the required blacksmith blessings
  18667. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18668. return;
  18669. }
  18670. // Try to refine the item
  18671. if( cost->chance >= ( rnd() % 10000 ) ){
  18672. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18673. // Success
  18674. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18675. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18676. clif_misceffect( &sd->bl, 3 );
  18677. clif_refine( fd, 0, index, item->refine );
  18678. if( id->type == IT_WEAPON ){
  18679. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18680. }
  18681. clif_refineui_info( sd, index );
  18682. }else{
  18683. // Failure
  18684. // Blacksmith blessings were used to prevent breaking and downgrading
  18685. if( blacksmith_amount > 0 ){
  18686. clif_refine( fd, 3, index, item->refine );
  18687. clif_refineui_info( sd, index );
  18688. // Delete the item if it is breakable
  18689. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18690. clif_refine( fd, 1, index, item->refine );
  18691. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18692. // Downgrade the item if necessary
  18693. }else if( cost->downgrade_amount > 0 ){
  18694. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18695. clif_refine( fd, 2, index, item->refine );
  18696. clif_refineui_info(sd, index);
  18697. // Only show failure, but dont do anything
  18698. }else{
  18699. clif_refine( fd, 3, index, item->refine );
  18700. clif_refineui_info( sd, index );
  18701. }
  18702. clif_misceffect( &sd->bl, 2 );
  18703. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18704. }
  18705. #endif
  18706. }
  18707. void clif_unequipall_reply( struct map_session_data* sd, bool failed ){
  18708. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18709. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18710. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18711. p.result = failed;
  18712. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18713. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18714. }
  18715. void clif_parse_unequipall( int fd, struct map_session_data* sd ){
  18716. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18717. if( pc_cant_act( sd ) ){
  18718. clif_unequipall_reply( sd, true );
  18719. return;
  18720. }
  18721. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18722. if( sd->equip_index[i] >= 0 ){
  18723. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18724. }
  18725. }
  18726. clif_unequipall_reply( sd, false );
  18727. #endif
  18728. }
  18729. void clif_stylist_response( struct map_session_data* sd, bool failed ){
  18730. #if PACKETVER >= 20151104
  18731. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18732. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18733. p.flag = failed;
  18734. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18735. if( !failed ){
  18736. sd->state.stylist_open = false;
  18737. }
  18738. #endif
  18739. }
  18740. bool clif_parse_stylist_buy_sub( struct map_session_data* sd, _look look, int16 index ){
  18741. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18742. if( list == nullptr ){
  18743. return false;
  18744. }
  18745. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18746. if( entry == nullptr ){
  18747. return false;
  18748. }
  18749. std::shared_ptr<s_stylist_costs> costs;
  18750. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18751. costs = entry->doram;
  18752. }else{
  18753. costs = entry->human;
  18754. }
  18755. if( costs == nullptr ){
  18756. return false;
  18757. }
  18758. if( sd->status.zeny < costs->price ){
  18759. return false;
  18760. }
  18761. int16 inventoryIndex = -1;
  18762. if( costs->requiredItem != 0 ){
  18763. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18764. if( inventoryIndex < 0 ){
  18765. // No other option
  18766. if( costs->requiredItemBox == 0 ){
  18767. return false;
  18768. }
  18769. // Check if the box that contains the item is in the inventory
  18770. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18771. // The box containing the item also does not exist
  18772. if( inventoryIndex < 0 ){
  18773. return false;
  18774. }
  18775. }
  18776. }else if( costs->requiredItemBox != 0 ){
  18777. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18778. if( inventoryIndex < 0 ){
  18779. return false;
  18780. }
  18781. }
  18782. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18783. return false;
  18784. }
  18785. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18786. return false;
  18787. }
  18788. switch( look ){
  18789. case LOOK_HAIR:
  18790. case LOOK_HAIR_COLOR:
  18791. case LOOK_CLOTHES_COLOR:
  18792. case LOOK_BODY2:
  18793. pc_changelook( sd, look, entry->value );
  18794. break;
  18795. case LOOK_HEAD_BOTTOM:
  18796. case LOOK_HEAD_MID:
  18797. case LOOK_HEAD_TOP: {
  18798. struct mail_message msg = {};
  18799. msg.dest_id = sd->status.char_id;
  18800. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18801. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18802. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18803. msg.item[0].nameid = entry->value;
  18804. msg.item[0].identify = 1;
  18805. msg.item[0].amount = 1;
  18806. msg.status = MAIL_NEW;
  18807. msg.type = MAIL_INBOX_NORMAL;
  18808. msg.timestamp = time( nullptr );
  18809. intif_Mail_send( 0, &msg );
  18810. } break;
  18811. }
  18812. return true;
  18813. }
  18814. void clif_parse_stylist_buy( int fd, struct map_session_data* sd ){
  18815. #if PACKETVER >= 20151104
  18816. #if PACKETVER >= 20180516
  18817. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18818. #else
  18819. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18820. #endif
  18821. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18822. clif_stylist_response( sd, true );
  18823. return;
  18824. }
  18825. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18826. clif_stylist_response( sd, true );
  18827. return;
  18828. }
  18829. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18830. clif_stylist_response( sd, true );
  18831. return;
  18832. }
  18833. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18834. clif_stylist_response( sd, true );
  18835. return;
  18836. }
  18837. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18838. clif_stylist_response( sd, true );
  18839. return;
  18840. }
  18841. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18842. clif_stylist_response( sd, true );
  18843. return;
  18844. }
  18845. #if PACKETVER >= 20180516
  18846. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18847. clif_stylist_response( sd, true );
  18848. return;
  18849. }
  18850. #endif
  18851. clif_stylist_response( sd, false );
  18852. #endif
  18853. }
  18854. void clif_parse_stylist_close( int fd, struct map_session_data* sd ){
  18855. #if PACKETVER >= 20151104
  18856. sd->state.stylist_open = false;
  18857. #endif
  18858. }
  18859. void clif_inventory_expansion_info( struct map_session_data* sd ){
  18860. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18861. nullpo_retv( sd );
  18862. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18863. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18864. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18865. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18866. #endif
  18867. }
  18868. enum class e_inventory_expansion_response : uint8{
  18869. ASK_CONFIRMATION = 0,
  18870. FAILED,
  18871. BUSY,
  18872. MISSING_ITEM,
  18873. MAXIMUM_REACHED
  18874. };
  18875. void clif_inventory_expansion_response( struct map_session_data* sd, e_inventory_expansion_response response ){
  18876. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18877. nullpo_retv( sd );
  18878. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18879. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18880. p.result = (uint8)response;
  18881. p.itemId = sd->state.inventory_expansion_confirmation;
  18882. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18883. #endif
  18884. }
  18885. void clif_parse_inventory_expansion_request( int fd, struct map_session_data* sd ){
  18886. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18887. // Check if player is dead or busy with other stuff
  18888. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18889. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18890. return;
  18891. }
  18892. // Check if the player already reached the maximum
  18893. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18894. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18895. return;
  18896. }
  18897. static std::map<t_itemid, uint16> items = {
  18898. // The order of entries in this list defines which will be used first
  18899. // This order and the usable items are hardcoded into the client
  18900. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18901. { ITEMID_INVENTORY_EX_EVT, 10 },
  18902. { ITEMID_INVENTORY_EX_DIS, 10 },
  18903. { ITEMID_INVENTORY_EX, 10 },
  18904. };
  18905. int16 index = -1;
  18906. bool found_over_limit = false;
  18907. for( const auto& entry : items ){
  18908. // Check if the player has the required item
  18909. index = pc_search_inventory( sd, entry.first );
  18910. // Found an item
  18911. if( index >= 0 ){
  18912. // Check if the player would exceed the maximum
  18913. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18914. found_over_limit = true;
  18915. }else{
  18916. found_over_limit = false;
  18917. sd->state.inventory_expansion_confirmation = entry.first;
  18918. sd->state.inventory_expansion_amount = entry.second;
  18919. break;
  18920. }
  18921. }
  18922. }
  18923. // Check if an item was found
  18924. if( sd->state.inventory_expansion_confirmation == 0 ){
  18925. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18926. return;
  18927. }
  18928. // Check if an item would have been found, but the player would exceed the maximum
  18929. if( found_over_limit ){
  18930. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18931. return;
  18932. }
  18933. // The player met all requirements => ask him for confirmation
  18934. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18935. #endif
  18936. }
  18937. enum class e_inventory_expansion_result : uint8{
  18938. SUCCESS = 0,
  18939. FAILED,
  18940. BUSY,
  18941. MISSING_ITEM,
  18942. MAXIMUM_REACHED
  18943. };
  18944. void clif_inventory_expansion_result( struct map_session_data* sd, e_inventory_expansion_result result ){
  18945. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18946. nullpo_retv( sd );
  18947. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18948. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18949. p.result = (uint8)result;
  18950. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18951. // Reset the state tracking
  18952. sd->state.inventory_expansion_confirmation = 0;
  18953. sd->state.inventory_expansion_amount = 0;
  18954. #endif
  18955. }
  18956. void clif_parse_inventory_expansion_confirm( int fd, struct map_session_data* sd ){
  18957. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18958. if( sd->state.inventory_expansion_confirmation == 0 ){
  18959. return;
  18960. }
  18961. // Check if player is dead
  18962. if( pc_isdead( sd ) ){
  18963. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18964. return;
  18965. }
  18966. // Check if the player already reached the maximum
  18967. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18968. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18969. return;
  18970. }
  18971. // Check if the player has the required item
  18972. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18973. // The player did not have the item anymore
  18974. if( index < 0 ){
  18975. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18976. return;
  18977. }
  18978. // Check if the player would exceed the maximum
  18979. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18980. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18981. return;
  18982. }
  18983. // Delete the required item
  18984. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18985. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18986. return;
  18987. }
  18988. // Increase the slots
  18989. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18990. // Save player data (slots) and inventory data (removed item)
  18991. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18992. // Inform the player of success
  18993. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18994. clif_inventory_expansion_info( sd );
  18995. #endif
  18996. }
  18997. void clif_parse_inventory_expansion_reject( int fd, struct map_session_data* sd ){
  18998. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18999. sd->state.inventory_expansion_confirmation = 0;
  19000. sd->state.inventory_expansion_amount = 0;
  19001. #endif
  19002. }
  19003. void clif_barter_open( struct map_session_data& sd, struct npc_data& nd ){
  19004. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19005. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  19006. return;
  19007. }
  19008. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19009. if( barter == nullptr ){
  19010. return;
  19011. }
  19012. sd.state.barter_open = true;
  19013. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19014. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  19015. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  19016. int16 count = 0;
  19017. for( const auto& itemPair : barter->items ){
  19018. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  19019. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19020. item->nameid = client_nameid( id->nameid );
  19021. item->type = itemtype( id->nameid );
  19022. if( itemPair.second->stockLimited ){
  19023. item->amount = itemPair.second->stock;
  19024. }else{
  19025. item->amount = -1;
  19026. }
  19027. item->weight = id->weight;
  19028. item->index = itemPair.second->index;
  19029. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19030. item->viewSprite = id->look;
  19031. item->location = pc_equippoint_sub( &sd, id.get() );
  19032. #endif
  19033. // Use a loop if someone did not start with index 0
  19034. for( const auto& requirementPair : itemPair.second->requirements ){
  19035. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19036. item->currencyNameid = client_nameid( requirement->nameid );
  19037. item->currencyAmount = requirement->amount;
  19038. // It is a normal barter, cancel after first entry
  19039. break;
  19040. }
  19041. p->packetLength += (int16)( sizeof( *item ) );
  19042. count++;
  19043. }
  19044. clif_send( p, p->packetLength, &sd.bl, SELF );
  19045. #endif
  19046. }
  19047. void clif_parse_barter_close( int fd, struct map_session_data* sd ){
  19048. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19049. if( sd->state.barter_open ){
  19050. sd->npc_shopid = 0;
  19051. sd->state.barter_open = false;
  19052. }
  19053. #endif
  19054. }
  19055. void clif_parse_barter_buy( int fd, struct map_session_data* sd ){
  19056. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19057. // No shop open
  19058. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  19059. return;
  19060. }
  19061. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19062. // Unknown shop
  19063. if( nd == nullptr ){
  19064. return;
  19065. }
  19066. // Not a barter
  19067. if( nd->subtype != NPCTYPE_BARTER ){
  19068. return;
  19069. }
  19070. // It is an extended barter
  19071. if( nd->u.barter.extended ){
  19072. return;
  19073. }
  19074. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19075. if( barter == nullptr ){
  19076. return;
  19077. }
  19078. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19079. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  19080. // Empty purchase list
  19081. if( entries == 0 ){
  19082. return;
  19083. }
  19084. std::vector<s_barter_purchase> purchases;
  19085. purchases.reserve( entries );
  19086. // Make sure each shop index and target item id is only used once
  19087. for( int i = 0; i < entries; i++ ){
  19088. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19089. // Invalid shop index
  19090. if( item == nullptr ){
  19091. return;
  19092. }
  19093. for( int j = i + 1; j < entries; j++ ){
  19094. // Same shop index
  19095. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19096. return;
  19097. }
  19098. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19099. // Invalid shop index
  19100. if( item2 == nullptr ){
  19101. return;
  19102. }
  19103. // Same target item id
  19104. if( item->nameid == item2->nameid ){
  19105. return;
  19106. }
  19107. }
  19108. s_barter_purchase purchase = {};
  19109. purchase.item = item;
  19110. purchase.amount = p->list[i].amount;
  19111. purchases.push_back( purchase );
  19112. }
  19113. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19114. #endif
  19115. }
  19116. void clif_barter_extended_open( struct map_session_data& sd, struct npc_data& nd ){
  19117. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19118. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19119. return;
  19120. }
  19121. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19122. if( barter == nullptr ){
  19123. return;
  19124. }
  19125. sd.state.barter_extended_open = true;
  19126. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19127. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19128. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  19129. p->items_count = 0;
  19130. for( const auto& itemPair : barter->items ){
  19131. // Needs dynamic calculation, because of variable currencies
  19132. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  19133. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19134. item->nameid = client_nameid( id->nameid );
  19135. item->type = itemtype( id->nameid );
  19136. if( itemPair.second->stockLimited ){
  19137. item->amount = itemPair.second->stock;
  19138. }else{
  19139. item->amount = -1;
  19140. }
  19141. item->weight = id->weight;
  19142. item->index = itemPair.second->index;
  19143. item->zeny = itemPair.second->price;
  19144. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19145. item->viewSprite = id->look;
  19146. item->location = pc_equippoint_sub( &sd, id.get() );
  19147. #endif
  19148. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19149. p->items_count++;
  19150. item->currency_count = 0;
  19151. for( const auto& requirementPair : itemPair.second->requirements ){
  19152. // Needs dynamic calculation, because of variable currencies
  19153. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19154. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19155. req->nameid = requirement->nameid;
  19156. if( requirement->refine >= 0 ){
  19157. req->refine_level = requirement->refine;
  19158. }else{
  19159. req->refine_level = 0;
  19160. }
  19161. req->amount = requirement->amount;
  19162. req->type = itemtype( requirement->nameid );
  19163. p->packetLength += (int16)( sizeof( *req ) );
  19164. item->currency_count++;
  19165. }
  19166. }
  19167. clif_send( p, p->packetLength, &sd.bl, SELF );
  19168. #endif
  19169. }
  19170. void clif_parse_barter_extended_close( int fd, struct map_session_data* sd ){
  19171. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19172. if( sd->state.barter_extended_open ){
  19173. sd->npc_shopid = 0;
  19174. sd->state.barter_extended_open = false;
  19175. }
  19176. #endif
  19177. }
  19178. void clif_parse_barter_extended_buy( int fd, struct map_session_data* sd ){
  19179. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19180. // No shop open
  19181. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19182. return;
  19183. }
  19184. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19185. // Unknown shop
  19186. if( nd == nullptr ){
  19187. return;
  19188. }
  19189. // Not a barter
  19190. if( nd->subtype != NPCTYPE_BARTER ){
  19191. return;
  19192. }
  19193. // Not an extended barter
  19194. if( !nd->u.barter.extended ){
  19195. return;
  19196. }
  19197. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19198. if( barter == nullptr ){
  19199. return;
  19200. }
  19201. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19202. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19203. // Empty purchase list
  19204. if( entries == 0 ){
  19205. return;
  19206. }
  19207. std::vector<s_barter_purchase> purchases;
  19208. purchases.reserve( entries );
  19209. // Make sure each shop index and target item id is only used once
  19210. for( int i = 0; i < entries; i++ ){
  19211. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19212. // Invalid shop index
  19213. if( item == nullptr ){
  19214. return;
  19215. }
  19216. for( int j = i + 1; j < entries; j++ ){
  19217. // Same shop index
  19218. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19219. return;
  19220. }
  19221. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19222. // Invalid shop index
  19223. if( item2 == nullptr ){
  19224. return;
  19225. }
  19226. // Same target item id
  19227. if( item->nameid == item2->nameid ){
  19228. return;
  19229. }
  19230. }
  19231. s_barter_purchase purchase = {};
  19232. purchase.item = item;
  19233. purchase.amount = p->list[i].amount;
  19234. purchases.push_back( purchase );
  19235. }
  19236. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19237. #endif
  19238. }
  19239. void clif_summon_init(struct mob_data& md) {
  19240. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19241. struct block_list* master_bl = battle_get_master(&md.bl);
  19242. if( master_bl == nullptr ){
  19243. return;
  19244. }
  19245. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19246. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19247. p.summonAID = md.bl.id;
  19248. p.CurrentHP = md.status.hp;
  19249. p.MaxHP = md.status.max_hp;
  19250. clif_send( &p, sizeof( p ), master_bl, SELF );
  19251. #endif
  19252. }
  19253. void clif_summon_hp_bar(struct mob_data& md) {
  19254. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19255. struct block_list* master_bl = battle_get_master(&md.bl);
  19256. if( master_bl == nullptr ){
  19257. return;
  19258. }
  19259. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19260. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19261. p.summonAID = md.bl.id;
  19262. p.VarId = SP_HP; // HP parameter
  19263. p.Value = md.status.hp;
  19264. clif_send( &p, sizeof( p ), master_bl, SELF );
  19265. #endif
  19266. }
  19267. void clif_laphine_synthesis_open( struct map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19268. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19269. nullpo_retv( sd );
  19270. sd->state.laphine_synthesis = synthesis->item_id;
  19271. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19272. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19273. p.itemId = client_nameid( synthesis->item_id );
  19274. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19275. #endif
  19276. }
  19277. void clif_parse_laphine_synthesis_close( int fd, struct map_session_data* sd ){
  19278. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19279. sd->state.laphine_synthesis = 0;
  19280. #endif
  19281. }
  19282. enum e_laphine_synthesis_result : int16{
  19283. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19284. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19285. LAPHINE_SYNTHESIS_ITEM = 7
  19286. };
  19287. void clif_laphine_synthesis_result( struct map_session_data* sd, enum e_laphine_synthesis_result result ){
  19288. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19289. nullpo_retv( sd );
  19290. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19291. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19292. p.result = result;
  19293. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19294. #endif
  19295. }
  19296. void clif_parse_laphine_synthesis( int fd, struct map_session_data* sd ){
  19297. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19298. if( sd->state.laphine_synthesis == 0 ){
  19299. return;
  19300. }
  19301. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19302. if( sd->state.laphine_synthesis != p->itemId ){
  19303. return;
  19304. }
  19305. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19306. if( synthesis == nullptr ){
  19307. return;
  19308. }
  19309. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19310. // Player sent more or less than actually required
  19311. if( count != synthesis->requiredRequirements ){
  19312. return;
  19313. }
  19314. // Check for duplicates
  19315. for( size_t i = 0; i < count; i++ ){
  19316. for( size_t j = i + 1; j < count; j++ ){
  19317. if( p->items[i].index == p->items[j].index ){
  19318. return;
  19319. }
  19320. }
  19321. }
  19322. for( size_t i = 0; i < count; i++ ){
  19323. int16 index = server_index( p->items[i].index );
  19324. if( index >= MAX_INVENTORY ){
  19325. return;
  19326. }
  19327. if( sd->inventory_data[i] == nullptr ){
  19328. return;
  19329. }
  19330. struct item* item = &sd->inventory.u.items_inventory[index];
  19331. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19332. if( requirement == nullptr ){
  19333. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19334. return;
  19335. }
  19336. if( p->items[i].count != requirement->amount ){
  19337. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19338. return;
  19339. }
  19340. if( item->amount < requirement->amount ){
  19341. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19342. return;
  19343. }
  19344. if( item->refine < synthesis->minimumRefine ){
  19345. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19346. return;
  19347. }
  19348. if( item->refine > synthesis->maximumRefine ){
  19349. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19350. return;
  19351. }
  19352. if( item->equip != 0 ){
  19353. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19354. return;
  19355. }
  19356. if( item->equipSwitch != 0 ){
  19357. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19358. return;
  19359. }
  19360. }
  19361. // If triggered from item
  19362. if( sd->itemid == sd->state.laphine_synthesis ){
  19363. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19364. if( index < 0 ){
  19365. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19366. return;
  19367. }
  19368. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19369. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19370. return;
  19371. }
  19372. }
  19373. }
  19374. for( size_t i = 0; i < count; i++ ){
  19375. int16 index = server_index( p->items[i].index );
  19376. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19377. return;
  19378. }
  19379. }
  19380. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19381. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19382. #endif
  19383. }
  19384. void clif_laphine_upgrade_open( struct map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19385. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19386. nullpo_retv( sd );
  19387. sd->state.laphine_upgrade = upgrade->item_id;
  19388. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19389. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19390. p.itemId = client_nameid( upgrade->item_id );
  19391. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19392. #endif
  19393. }
  19394. void clif_parse_laphine_upgrade_close( int fd, struct map_session_data* sd ){
  19395. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19396. sd->state.laphine_upgrade = 0;
  19397. #endif
  19398. }
  19399. void clif_laphine_upgrade_result( struct map_session_data *sd, bool failed ){
  19400. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19401. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19402. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19403. p.result = failed;
  19404. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19405. #endif
  19406. }
  19407. static void clif_item_preview( struct map_session_data *sd, int16 index ){
  19408. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19409. nullpo_retv( sd );
  19410. struct item* item = &sd->inventory.u.items_inventory[index];
  19411. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19412. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19413. p.index = client_index( index );
  19414. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19415. p.isDamaged = item->attribute != 0;
  19416. #endif
  19417. p.refiningLevel = item->refine;
  19418. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19419. p.enchantgrade = item->enchantgrade;
  19420. #endif
  19421. clif_addcards( &p.slot, item );
  19422. clif_add_random_options( p.option_data, item );
  19423. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19424. #endif
  19425. }
  19426. void clif_parse_laphine_upgrade( int fd, struct map_session_data* sd ){
  19427. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19428. if( sd->state.laphine_upgrade == 0 ){
  19429. return;
  19430. }
  19431. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19432. if( sd->state.laphine_upgrade != p->itemId ){
  19433. return;
  19434. }
  19435. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19436. if( upgrade == nullptr ){
  19437. return;
  19438. }
  19439. uint16 index = server_index( p->index );
  19440. if( index >= MAX_INVENTORY ){
  19441. return;
  19442. }
  19443. if( sd->inventory_data[index] == nullptr ){
  19444. return;
  19445. }
  19446. struct item* item = &sd->inventory.u.items_inventory[index];
  19447. // Not a valid target item
  19448. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19449. clif_laphine_upgrade_result( sd, true );
  19450. return;
  19451. }
  19452. // If target item is not identified
  19453. if( item->identify == 0 ){
  19454. clif_laphine_upgrade_result( sd, true );
  19455. return;
  19456. }
  19457. // If target item is equipped
  19458. if( item->equip != 0 ){
  19459. clif_laphine_upgrade_result( sd, true );
  19460. return;
  19461. }
  19462. // If target item is in equipswitch
  19463. if( item->equipSwitch != 0 ){
  19464. clif_laphine_upgrade_result( sd, true );
  19465. return;
  19466. }
  19467. // Check minimum refine requirement
  19468. if( item->refine < upgrade->minimumRefine ){
  19469. clif_laphine_upgrade_result( sd, true );
  19470. return;
  19471. }
  19472. // Check maximum refine requirement
  19473. if( item->refine > upgrade->maximumRefine ){
  19474. clif_laphine_upgrade_result( sd, true );
  19475. return;
  19476. }
  19477. // If no cards are allowed
  19478. if( !upgrade->cardsAllowed ){
  19479. for( int i = 0; i < MAX_SLOTS; i++ ){
  19480. if( item->card[i] != 0 ){
  19481. clif_laphine_upgrade_result( sd, true );
  19482. return;
  19483. }
  19484. }
  19485. }
  19486. // If random options are required
  19487. if( upgrade->requiredRandomOptions > 0 ){
  19488. int i;
  19489. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19490. if( item->option[i].id != 0 ){
  19491. break;
  19492. }
  19493. }
  19494. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19495. clif_laphine_upgrade_result( sd, true );
  19496. return;
  19497. }
  19498. }
  19499. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19500. if( index2 < 0 ){
  19501. clif_laphine_upgrade_result( sd, true );
  19502. return;
  19503. }
  19504. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19505. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19506. return;
  19507. }
  19508. }
  19509. // Log removal of item
  19510. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19511. // Visually remove it from the client
  19512. clif_delitem( sd, index, 1, 0 );
  19513. // Apply the random options
  19514. if( upgrade->randomOptionGroup != nullptr ){
  19515. upgrade->randomOptionGroup->apply( *item );
  19516. }
  19517. // Change the refine rate if needed
  19518. if( upgrade->resultRefine > 0 ){
  19519. // Absolute refine level change
  19520. item->refine = max( item->refine, upgrade->resultRefine );
  19521. }else if( upgrade->resultRefineMaximum > 0 ){
  19522. // If a minimum is specified it can also downgrade
  19523. if( upgrade->resultRefineMinimum ){
  19524. item->refine = rnd_value( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum );
  19525. }else{
  19526. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19527. item->refine = rnd_value( item->refine, upgrade->resultRefineMaximum );
  19528. }
  19529. }else if( upgrade->resultRefineMinimum > 0 ){
  19530. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19531. item->refine = rnd_value( upgrade->resultRefineMinimum, MAX_REFINE );
  19532. }
  19533. // Log retrieving the item again -> with the new options
  19534. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19535. // Make it visible for the client again
  19536. clif_additem( sd, index, 1, 0 );
  19537. // Open a preview of the item
  19538. clif_item_preview( sd, index );
  19539. // Tell the client we are done
  19540. clif_laphine_upgrade_result( sd, false );
  19541. #endif
  19542. }
  19543. void clif_enchantgrade_add( struct map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19544. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19545. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19546. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19547. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19548. if( index < UINT16_MAX ){
  19549. p->index = client_index( index );
  19550. if( sd.inventory.u.items_inventory[index].refine >= gradeLevel->refine ){
  19551. p->success_chance = gradeLevel->chance / 100;
  19552. }else{
  19553. p->success_chance = 0;
  19554. }
  19555. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19556. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19557. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19558. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19559. // Not displayed by client
  19560. p->protect_itemid = 0;
  19561. p->protect_amount = 0;
  19562. int i = 0;
  19563. for( const auto& pair : gradeLevel->options ){
  19564. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19565. p->material_info[i].nameid = client_nameid( option->item );
  19566. p->material_info[i].amount = option->amount;
  19567. p->material_info[i].price = option->zeny;
  19568. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19569. p->material_info[i].breakable = option->breaking_rate > 0;
  19570. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19571. i++;
  19572. }
  19573. }else{
  19574. p->index = -1;
  19575. p->success_chance = 0;
  19576. p->blessing_info.id = 0;
  19577. p->blessing_info.amount = 0;
  19578. p->blessing_info.max_blessing = 0;
  19579. p->blessing_info.bonus = 0;
  19580. p->protect_itemid = 0;
  19581. p->protect_amount = 0;
  19582. }
  19583. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19584. #endif
  19585. }
  19586. void clif_parse_enchantgrade_add( int fd, struct map_session_data* sd ){
  19587. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19588. nullpo_retv( sd );
  19589. if( !sd->state.enchantgrade_open ){
  19590. return;
  19591. }
  19592. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19593. uint16 index = server_index( p->index );
  19594. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19595. return;
  19596. }
  19597. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19598. // Unsupported item type - no answer, because client should have actually prevented this request
  19599. if( enchantgrade == nullptr ){
  19600. return;
  19601. }
  19602. // Item can't be enhanced
  19603. if( !sd->inventory_data[index]->flag.gradable ){
  19604. return;
  19605. }
  19606. uint16 level = 0;
  19607. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19608. level = sd->inventory_data[index]->weapon_level;
  19609. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19610. level = sd->inventory_data[index]->armor_level;
  19611. }
  19612. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19613. // Cannot upgrade this weapon or armor level
  19614. if( enchantgradelevels == enchantgrade->levels.end() ){
  19615. clif_enchantgrade_add( *sd );
  19616. return;
  19617. }
  19618. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19619. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19620. if( enchantgradelevel == nullptr ){
  19621. return;
  19622. }
  19623. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19624. #endif
  19625. }
  19626. /// <summary>
  19627. /// Sends the result for trying to enchant an item
  19628. /// </summary>
  19629. /// <param name="sd">The player session</param>
  19630. /// <param name="index">The target item</param>
  19631. /// <param name="result">
  19632. /// 0= The grade has been successfully upgraded.
  19633. /// 1= Refinement failed.
  19634. /// 2= The refine level has decreased.
  19635. /// 3= Equipment destroyed.
  19636. /// 4= The equipment is protected.
  19637. /// </param>
  19638. void clif_enchantgrade_result( struct map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19639. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19640. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19641. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19642. p.index = client_index( index );
  19643. p.enchantgrade = sd.inventory.u.items_inventory[index].enchantgrade;
  19644. p.result = result;
  19645. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19646. #endif
  19647. }
  19648. void clif_enchantgrade_announce( struct map_session_data& sd, struct item& item, bool success ){
  19649. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19650. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19651. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19652. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19653. p.itemId = client_nameid( item.nameid );
  19654. p.enchantgrade = item.enchantgrade;
  19655. p.status = success;
  19656. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19657. #endif
  19658. }
  19659. void clif_parse_enchantgrade_start( int fd, struct map_session_data* sd ){
  19660. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19661. nullpo_retv( sd );
  19662. if( !sd->state.enchantgrade_open ){
  19663. return;
  19664. }
  19665. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19666. uint16 index = server_index( p->index );
  19667. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19668. return;
  19669. }
  19670. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19671. // Unsupported item type - no answer
  19672. if( enchantgrade == nullptr ){
  19673. return;
  19674. }
  19675. uint16 level = 0;
  19676. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19677. level = sd->inventory_data[index]->weapon_level;
  19678. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19679. level = sd->inventory_data[index]->armor_level;
  19680. }
  19681. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19682. // Cannot upgrade this weapon or armor level - no answer
  19683. if( enchantgradelevels == enchantgrade->levels.end() ){
  19684. return;
  19685. }
  19686. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19687. // Cannot increase enchantgrade any further - no answer
  19688. if( enchantgradelevel == nullptr ){
  19689. return;
  19690. }
  19691. // Not refined enough
  19692. if( sd->inventory.u.items_inventory[index].refine < enchantgradelevel->refine ){
  19693. return;
  19694. }
  19695. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19696. // Unknown option id - no answer
  19697. if( option == nullptr ){
  19698. return;
  19699. }
  19700. // Not enough zeny
  19701. if( sd->status.zeny < option->zeny ){
  19702. return;
  19703. }
  19704. uint16 totalChance = enchantgradelevel->chance;
  19705. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19706. std::unordered_map<uint16, uint16> requiredItems;
  19707. if( p->blessing_flag ){
  19708. // If the catalysator item is the same as the option item build the sum of amounts
  19709. if( enchantgradelevel->catalyst.item == option->item ){
  19710. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19711. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19712. if( index < 0 ){
  19713. return;
  19714. }
  19715. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19716. return;
  19717. }
  19718. requiredItems[index] = amount;
  19719. }else{
  19720. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19721. // Check catalysator item
  19722. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19723. if( index < 0 ){
  19724. return;
  19725. }
  19726. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19727. return;
  19728. }
  19729. requiredItems[index] = amount;
  19730. // Check option item
  19731. index = pc_search_inventory( sd, option->item );
  19732. if( index < 0 ){
  19733. return;
  19734. }
  19735. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19736. return;
  19737. }
  19738. requiredItems[index] = option->amount;
  19739. }
  19740. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19741. }else{
  19742. // Check option item
  19743. int16 index = pc_search_inventory( sd, option->item );
  19744. if( index < 0 ){
  19745. return;
  19746. }
  19747. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19748. return;
  19749. }
  19750. requiredItems[index] = option->amount;
  19751. }
  19752. // All items should be there, start deleting
  19753. for( const auto& pair : requiredItems ){
  19754. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19755. return;
  19756. }
  19757. }
  19758. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE, nullptr ) > 0 ){
  19759. return;
  19760. }
  19761. if( rnd()%10000 < totalChance ){
  19762. // Log removal of item
  19763. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19764. // Increase enchantgrade
  19765. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19766. // On successful enchantgrade increase the refine is reset
  19767. sd->inventory.u.items_inventory[index].refine = 0;
  19768. // Log retrieving the item again -> with the new refine and enchantgrade
  19769. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19770. // Show success
  19771. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19772. // Check if it has to be announced
  19773. if( enchantgradelevel->announce ){
  19774. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19775. }
  19776. }else{
  19777. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19778. if( enchantgradelevel->announce ){
  19779. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19780. }
  19781. // Delete the item if it is breakable
  19782. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19783. // Delete the item
  19784. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19785. // Show failure
  19786. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19787. // Downgrade the item if necessary
  19788. }else if( option->downgrade_amount > 0 ){
  19789. // Log removal of item
  19790. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19791. // Decrease refine level
  19792. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19793. // Log retrieving the item again -> with the new refine
  19794. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19795. // Show downgrade
  19796. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19797. // Only show failure, but dont do anything
  19798. }else{
  19799. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19800. }
  19801. }
  19802. #endif
  19803. }
  19804. void clif_parse_enchantgrade_close( int fd, struct map_session_data* sd ){
  19805. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19806. nullpo_retv( sd );
  19807. sd->state.enchantgrade_open = false;
  19808. #endif
  19809. }
  19810. void clif_reputation_type( struct map_session_data& sd, int64 type, int64 points ){
  19811. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19812. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19813. p->packetType = HEADER_ZC_REPUTE_INFO;
  19814. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19815. p->success = true;
  19816. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19817. entry->type = type;
  19818. entry->points = points;
  19819. clif_send( p, p->packetLength, &sd.bl, SELF );
  19820. #endif
  19821. }
  19822. void clif_reputation_list( struct map_session_data& sd ){
  19823. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19824. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19825. p->packetType = HEADER_ZC_REPUTE_INFO;
  19826. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19827. p->success = true;
  19828. size_t index = 0;
  19829. for( const auto& entry : reputation_db ){
  19830. std::shared_ptr<s_reputation> reputation = entry.second;
  19831. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19832. list_entry->type = reputation->id;
  19833. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19834. p->packetLength += sizeof( *list_entry );
  19835. index++;
  19836. }
  19837. clif_send( p, p->packetLength, &sd.bl, SELF );
  19838. #endif
  19839. }
  19840. void clif_item_reform_open( struct map_session_data& sd, t_itemid item ){
  19841. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19842. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19843. p.packetType = HEADER_ZC_OPEN_REFORM_UI;
  19844. p.itemId = item;
  19845. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19846. sd.state.item_reform = item;
  19847. #endif
  19848. }
  19849. void clif_parse_item_reform_close( int fd, struct map_session_data* sd ){
  19850. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19851. sd->state.item_reform = 0;
  19852. #endif
  19853. }
  19854. void clif_item_reform_result( struct map_session_data& sd, uint16 index, uint8 result ){
  19855. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19856. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19857. p.packetType = HEADER_ZC_ITEM_REFORM_ACK;
  19858. p.index = client_index( index );
  19859. p.result = result;
  19860. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19861. if( result == 0 ){
  19862. // Client closes the window on success
  19863. sd.state.item_reform = 0;
  19864. }
  19865. #endif
  19866. }
  19867. void clif_parse_item_reform_start( int fd, struct map_session_data* sd ){
  19868. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19869. // Not opened
  19870. if( sd->state.item_reform == 0 ){
  19871. return;
  19872. }
  19873. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19874. // Item mismatch
  19875. if( p->itemId != sd->state.item_reform ){
  19876. return;
  19877. }
  19878. uint16 index = server_index( p->index );
  19879. if( index >= MAX_INVENTORY ){
  19880. return;
  19881. }
  19882. if( sd->inventory_data[index] == nullptr ){
  19883. return;
  19884. }
  19885. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19886. if( reform == nullptr ){
  19887. return;
  19888. }
  19889. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19890. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19891. if( base == nullptr ){
  19892. return;
  19893. }
  19894. // If target item is not identified
  19895. if( selected_item.identify == 0 ){
  19896. return;
  19897. }
  19898. // If target item is equipped
  19899. if( selected_item.equip != 0 ){
  19900. return;
  19901. }
  19902. // Check minimum refine requirement
  19903. if( selected_item.refine < base->minimumRefine ){
  19904. return;
  19905. }
  19906. // Check maximum refine requirement
  19907. if( selected_item.refine > base->maximumRefine ){
  19908. return;
  19909. }
  19910. // If no cards are allowed
  19911. if( !base->cardsAllowed ){
  19912. for( int i = 0; i < MAX_SLOTS; i++ ){
  19913. if( selected_item.card[i] != 0 ){
  19914. return;
  19915. }
  19916. }
  19917. }
  19918. // If random options are required
  19919. if( base->requiredRandomOptions > 0 ){
  19920. int i;
  19921. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19922. if( selected_item.option[i].id != 0 ){
  19923. break;
  19924. }
  19925. }
  19926. if( ( i + 1 ) < base->requiredRandomOptions ){
  19927. return;
  19928. }
  19929. }
  19930. std::unordered_map<uint16, uint16> materials;
  19931. // Check if all materials exist
  19932. for( const auto& material : base->materials ){
  19933. int16 material_index = pc_search_inventory( sd, material.first );
  19934. if( material_index < 0 ){
  19935. return;
  19936. }
  19937. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19938. return;
  19939. }
  19940. materials[material_index] = material.second;
  19941. }
  19942. // Remove the material
  19943. for( const auto& material : materials ){
  19944. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19945. return;
  19946. }
  19947. }
  19948. // If triggered from item
  19949. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19950. return;
  19951. }
  19952. // Log removal of item
  19953. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19954. // Visually remove it from the client
  19955. clif_delitem( sd, index, 1, 0 );
  19956. // Apply the random options
  19957. if( base->randomOptionGroup != nullptr ){
  19958. base->randomOptionGroup->apply( selected_item );
  19959. }
  19960. // Change the refine rate if needed
  19961. if( base->refineChange != 0 ){
  19962. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19963. }
  19964. // Remove all cards and socket enchants
  19965. if( base->clearSlots ){
  19966. for( int i = 0; i < MAX_SLOTS; i++ ){
  19967. selected_item.card[i] = 0;
  19968. }
  19969. }
  19970. // Remove the current enchantgrade
  19971. if( base->removeEnchantgrade ){
  19972. selected_item.enchantgrade = 0;
  19973. }
  19974. // Finally change the item id
  19975. selected_item.nameid = base->resultItemId;
  19976. // Link inventory data cache to the new item
  19977. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19978. // Log retrieving the item again -> with the new options
  19979. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19980. // Make it visible for the client again
  19981. clif_additem( sd, index, 1, 0 );
  19982. clif_item_reform_result( *sd, index, 0 );
  19983. #endif
  19984. }
  19985. void clif_enchantwindow_open( struct map_session_data& sd, uint64 clientLuaIndex ){
  19986. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19987. // Hardcoded clientside check
  19988. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19989. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  19990. sd.state.item_enchant_index = 0;
  19991. return;
  19992. }
  19993. struct PACKET_ZC_UI_OPEN_V3 p = {};
  19994. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19995. p.type = OUT_UI_ENCHANT;
  19996. p.data = clientLuaIndex;
  19997. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19998. sd.state.item_enchant_index = clientLuaIndex;
  19999. #endif
  20000. }
  20001. void clif_enchantwindow_result( struct map_session_data& sd, bool success, t_itemid enchant = 0 ){
  20002. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20003. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  20004. p.packetType = HEADER_ZC_RESPONSE_ENCHANT;
  20005. if( success ){
  20006. p.messageId = C_ENCHANT_SUCCESS;
  20007. }else{
  20008. p.messageId = C_ENCHANT_FAILURE;
  20009. }
  20010. p.enchantItemId = enchant;
  20011. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20012. sd.state.item_enchant_index = 0;
  20013. #endif
  20014. }
  20015. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  20016. if( selected_item.equip != 0 ){
  20017. return false;
  20018. }
  20019. if( selected_item.equipSwitch != 0 ){
  20020. return false;
  20021. }
  20022. if( selected_item.attribute != 0 ){
  20023. return false;
  20024. }
  20025. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20026. return false;
  20027. }
  20028. if( selected_item.refine < enchant->minimumRefine ){
  20029. return false;
  20030. }
  20031. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20032. return false;
  20033. }
  20034. if( !enchant->allowRandomOptions ){
  20035. for( const s_item_randomoption& option : selected_item.option ){
  20036. if( option.id != 0 ){
  20037. return false;
  20038. }
  20039. }
  20040. }
  20041. return true;
  20042. }
  20043. void clif_parse_enchantwindow_general( int fd, struct map_session_data* sd ){
  20044. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20045. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  20046. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20047. return;
  20048. }
  20049. uint16 index = server_index( p->index );
  20050. if( index >= MAX_INVENTORY ){
  20051. return;
  20052. }
  20053. if( sd->inventory_data[index] == nullptr ){
  20054. return;
  20055. }
  20056. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20057. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20058. if( enchant == nullptr ){
  20059. return;
  20060. }
  20061. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20062. return;
  20063. }
  20064. uint16 slot = MAX_SLOTS;
  20065. for( uint16 nextSlot : enchant->order ){
  20066. if( selected_item.card[nextSlot] == 0 ){
  20067. slot = nextSlot;
  20068. break;
  20069. }
  20070. }
  20071. if( slot == MAX_SLOTS ){
  20072. return;
  20073. }
  20074. if( slot < sd->inventory_data[index]->slots ){
  20075. return;
  20076. }
  20077. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20078. if( enchant_slot == nullptr ){
  20079. return;
  20080. }
  20081. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  20082. if( enchants_for_enchantgrade == nullptr ){
  20083. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  20084. clif_enchantwindow_result( *sd, false );
  20085. return;
  20086. }
  20087. if( sd->status.zeny < enchant_slot->normal.zeny ){
  20088. return;
  20089. }
  20090. std::unordered_map<uint16, uint16> materials;
  20091. for( const auto& entry : enchant_slot->normal.materials ){
  20092. int16 idx = pc_search_inventory( sd, entry.first );
  20093. if( idx < 0 ){
  20094. return;
  20095. }
  20096. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20097. return;
  20098. }
  20099. materials[idx] = entry.second;
  20100. }
  20101. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20102. return;
  20103. }
  20104. for( const auto& entry : materials ){
  20105. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20106. return;
  20107. }
  20108. }
  20109. uint32 chance = enchant_slot->normal.chance;
  20110. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  20111. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  20112. }
  20113. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20114. clif_enchantwindow_result( *sd, false );
  20115. return;
  20116. }
  20117. // Log removal of item
  20118. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20119. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  20120. bool enchanted = false;
  20121. for( int i = 0; i < maximum; i++ ){
  20122. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20123. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  20124. selected_item.card[slot] = normal_enchant->item_id;
  20125. enchanted = true;
  20126. break;
  20127. }
  20128. }
  20129. if( !enchanted ){
  20130. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20131. selected_item.card[slot] = normal_enchant->item_id;
  20132. }
  20133. // Log retrieving the item again -> with the new enchant
  20134. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20135. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20136. #endif
  20137. }
  20138. void clif_parse_enchantwindow_perfect( int fd, struct map_session_data* sd ){
  20139. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20140. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  20141. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20142. return;
  20143. }
  20144. uint16 index = server_index( p->index );
  20145. if( index >= MAX_INVENTORY ){
  20146. return;
  20147. }
  20148. if( sd->inventory_data[index] == nullptr ){
  20149. return;
  20150. }
  20151. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20152. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20153. if( enchant == nullptr ){
  20154. return;
  20155. }
  20156. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20157. return;
  20158. }
  20159. uint16 slot = MAX_SLOTS;
  20160. for( uint16 nextSlot : enchant->order ){
  20161. if( selected_item.card[nextSlot] == 0 ){
  20162. slot = nextSlot;
  20163. break;
  20164. }
  20165. }
  20166. if( slot == MAX_SLOTS ){
  20167. return;
  20168. }
  20169. if( slot < sd->inventory_data[index]->slots ){
  20170. return;
  20171. }
  20172. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20173. if( enchant_slot == nullptr ){
  20174. return;
  20175. }
  20176. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->itemId );
  20177. if( perfect_enchant == nullptr ){
  20178. return;
  20179. }
  20180. if( sd->status.zeny < perfect_enchant->zeny ){
  20181. return;
  20182. }
  20183. std::unordered_map<uint16, uint16> materials;
  20184. for( const auto& entry : perfect_enchant->materials ){
  20185. int16 idx = pc_search_inventory( sd, entry.first );
  20186. if( idx < 0 ){
  20187. return;
  20188. }
  20189. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20190. return;
  20191. }
  20192. materials[idx] = entry.second;
  20193. }
  20194. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20195. return;
  20196. }
  20197. for( const auto& entry : materials ){
  20198. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20199. return;
  20200. }
  20201. }
  20202. // Log removal of item
  20203. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20204. selected_item.card[slot] = perfect_enchant->item_id;
  20205. // Log retrieving the item again -> with the new enchant
  20206. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20207. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20208. #endif
  20209. }
  20210. void clif_parse_enchantwindow_upgrade( int fd, struct map_session_data* sd ){
  20211. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20212. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20213. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20214. return;
  20215. }
  20216. uint16 index = server_index( p->index );
  20217. if( index >= MAX_INVENTORY ){
  20218. return;
  20219. }
  20220. if( sd->inventory_data[index] == nullptr ){
  20221. return;
  20222. }
  20223. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20224. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20225. if( enchant == nullptr ){
  20226. return;
  20227. }
  20228. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20229. return;
  20230. }
  20231. uint16 slot = p->slot;
  20232. if( slot >= MAX_SLOTS ){
  20233. return;
  20234. }
  20235. if( slot < sd->inventory_data[index]->slots ){
  20236. return;
  20237. }
  20238. if( selected_item.card[slot] == 0 ){
  20239. return;
  20240. }
  20241. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20242. if( enchant_slot == nullptr ){
  20243. return;
  20244. }
  20245. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20246. if( upgrade == nullptr ){
  20247. return;
  20248. }
  20249. if( sd->status.zeny < upgrade->zeny ){
  20250. return;
  20251. }
  20252. std::unordered_map<uint16, uint16> materials;
  20253. for( const auto& entry : upgrade->materials ){
  20254. int16 idx = pc_search_inventory( sd, entry.first );
  20255. if( idx < 0 ){
  20256. return;
  20257. }
  20258. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20259. return;
  20260. }
  20261. materials[idx] = entry.second;
  20262. }
  20263. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20264. return;
  20265. }
  20266. for( const auto& entry : materials ){
  20267. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20268. return;
  20269. }
  20270. }
  20271. // Log removal of item
  20272. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20273. selected_item.card[slot] = upgrade->upgrade_item_id;
  20274. // Log retrieving the item again -> with the new enchant
  20275. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20276. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20277. #endif
  20278. }
  20279. void clif_parse_enchantwindow_reset( int fd, struct map_session_data* sd ){
  20280. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20281. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20282. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20283. return;
  20284. }
  20285. uint16 index = server_index( p->index );
  20286. if( index >= MAX_INVENTORY ){
  20287. return;
  20288. }
  20289. if( sd->inventory_data[index] == nullptr ){
  20290. return;
  20291. }
  20292. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20293. if( selected_item.equip != 0 ){
  20294. return;
  20295. }
  20296. if( selected_item.equipSwitch != 0 ){
  20297. return;
  20298. }
  20299. if( selected_item.attribute != 0 ){
  20300. return;
  20301. }
  20302. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20303. if( enchant == nullptr ){
  20304. return;
  20305. }
  20306. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20307. return;
  20308. }
  20309. if( selected_item.refine < enchant->minimumRefine ){
  20310. return;
  20311. }
  20312. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20313. return;
  20314. }
  20315. bool is_enchanted = false;
  20316. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20317. if( selected_item.card[i] != 0 ){
  20318. is_enchanted = true;
  20319. break;
  20320. }
  20321. }
  20322. if( !is_enchanted ){
  20323. return;
  20324. }
  20325. if( sd->status.zeny < enchant->reset.zeny ){
  20326. return;
  20327. }
  20328. std::unordered_map<uint16, uint16> materials;
  20329. for( const auto& entry : enchant->reset.materials ){
  20330. int16 idx = pc_search_inventory( sd, entry.first );
  20331. if( idx < 0 ){
  20332. return;
  20333. }
  20334. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20335. return;
  20336. }
  20337. materials[idx] = entry.second;
  20338. }
  20339. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20340. return;
  20341. }
  20342. for( const auto& entry : materials ){
  20343. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20344. return;
  20345. }
  20346. }
  20347. uint32 chance = enchant->reset.chance;
  20348. if( chance == 0 ){
  20349. return;
  20350. }
  20351. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20352. clif_enchantwindow_result( *sd, false );
  20353. return;
  20354. }
  20355. // Log removal of item
  20356. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20357. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20358. selected_item.card[i] = 0;
  20359. }
  20360. // Log retrieving the item again -> with the new enchant
  20361. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20362. clif_enchantwindow_result( *sd, true );
  20363. #endif
  20364. }
  20365. void clif_parse_enchantwindow_close( int fd, struct map_session_data* sd ){
  20366. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20367. sd->state.item_enchant_index = 0;
  20368. #endif
  20369. }
  20370. void clif_parse_itempackage_select( int fd, struct map_session_data* sd ){
  20371. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20372. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20373. if( p->AID != sd->status.account_id ){
  20374. return;
  20375. }
  20376. uint16 index = server_index( p->index );
  20377. if( index >= MAX_INVENTORY ){
  20378. return;
  20379. }
  20380. if( sd->inventory_data[index] == nullptr ){
  20381. return;
  20382. }
  20383. if( sd->inventory_data[index]->nameid != p->itemID ){
  20384. return;
  20385. }
  20386. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20387. return;
  20388. }
  20389. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20390. if( package == nullptr ){
  20391. return;
  20392. }
  20393. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20394. if( group == nullptr ){
  20395. return;
  20396. }
  20397. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20398. return;
  20399. }
  20400. for( const auto& entry : group->items ){
  20401. struct item item = {};
  20402. item.nameid = entry.second->item_id;
  20403. item.identify = 1;
  20404. item.refine = (char)entry.second->refine;
  20405. if( entry.second->rentalhours ){
  20406. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20407. }
  20408. // Check if it is a pet egg
  20409. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20410. if( pet != nullptr ){
  20411. for( int i = 0; i < entry.second->amount; i++ ){
  20412. pet_create_egg( sd, item.nameid );
  20413. }
  20414. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20415. for( int i = 0; i < entry.second->amount; i++ ){
  20416. // New random options on each iteration
  20417. if( entry.second->randomOptionGroup != nullptr ){
  20418. entry.second->randomOptionGroup->apply( item );
  20419. }
  20420. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20421. }
  20422. }else{
  20423. if( entry.second->randomOptionGroup != nullptr ){
  20424. entry.second->randomOptionGroup->apply( item );
  20425. }
  20426. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20427. }
  20428. }
  20429. #endif
  20430. }
  20431. /*==========================================
  20432. * Main client packet processing function
  20433. *------------------------------------------*/
  20434. static int clif_parse(int fd)
  20435. {
  20436. int cmd, packet_len;
  20437. TBL_PC* sd;
  20438. int pnum;
  20439. #ifdef PACKET_OBFUSCATION
  20440. int cmd2;
  20441. #endif
  20442. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20443. // Note: "click masters" can do 80+ clicks in 10 seconds
  20444. 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]
  20445. { // begin main client packet processing loop
  20446. sd = (TBL_PC *)session[fd]->session_data;
  20447. if (session[fd]->flag.eof) {
  20448. if (sd) {
  20449. if (sd->state.autotrade) {
  20450. //Disassociate character from the socket connection.
  20451. session[fd]->session_data = NULL;
  20452. sd->fd = 0;
  20453. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20454. } else
  20455. if (sd->state.active) {
  20456. // Player logout display [Valaris]
  20457. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20458. clif_quitsave(fd, sd);
  20459. } else {
  20460. //Unusual logout (during log on/off/map-changer procedure)
  20461. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20462. map_quit(sd);
  20463. }
  20464. } else {
  20465. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20466. }
  20467. do_close(fd);
  20468. return 0;
  20469. }
  20470. if (RFIFOREST(fd) < 2)
  20471. return 0;
  20472. cmd = RFIFOW(fd, 0);
  20473. #ifdef PACKET_OBFUSCATION
  20474. // Check if it is a player that tries to connect to the map server.
  20475. if( sd ){
  20476. // Decrypt the current packet ID with the last key stored in the session.
  20477. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20478. }else{
  20479. // Store the original value for checking
  20480. cmd2 = cmd;
  20481. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20482. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20483. }
  20484. #endif
  20485. // filter out invalid / unsupported packets
  20486. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20487. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20488. #ifdef DUMP_INVALID_PACKET
  20489. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20490. #endif
  20491. #ifdef PACKET_OBFUSCATION_WARN
  20492. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20493. if( !sd ){
  20494. #ifdef PACKET_OBFUSCATION
  20495. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20496. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20497. }
  20498. #else
  20499. // Try to use the initial keys for the decryption of the packet ID.
  20500. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20501. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20502. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20503. }
  20504. #endif
  20505. }
  20506. #endif
  20507. set_eof(fd);
  20508. return 0;
  20509. }
  20510. // determine real packet length
  20511. packet_len = packet_db[cmd].len;
  20512. if (packet_len == -1) { // variable-length packet
  20513. if (RFIFOREST(fd) < 4)
  20514. return 0;
  20515. packet_len = RFIFOW(fd,2);
  20516. if (packet_len < 4 || packet_len > 32768) {
  20517. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20518. #ifdef DUMP_INVALID_PACKET
  20519. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20520. #endif
  20521. set_eof(fd);
  20522. return 0;
  20523. }
  20524. }
  20525. if ((int)RFIFOREST(fd) < packet_len){
  20526. 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 );
  20527. #ifdef DUMP_INVALID_PACKET
  20528. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20529. #endif
  20530. set_eof( fd );
  20531. return 0; // not enough data received to form the packet
  20532. }
  20533. #ifdef PACKET_OBFUSCATION
  20534. RFIFOW(fd, 0) = cmd;
  20535. if (sd)
  20536. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20537. #endif
  20538. if( packet_db[cmd].func == clif_parse_debug )
  20539. packet_db[cmd].func(fd, sd);
  20540. else if( packet_db[cmd].func != NULL ) {
  20541. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20542. ; //Only valid packet when there is no session
  20543. else
  20544. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20545. ; //Only valid packet when player is not on a map
  20546. else
  20547. packet_db[cmd].func(fd, sd);
  20548. }
  20549. #ifdef DUMP_UNKNOWN_PACKET
  20550. else DumpUnknown(fd,sd,cmd,packet_len);
  20551. #endif
  20552. RFIFOSKIP(fd, packet_len);
  20553. }; // main loop end
  20554. return 0;
  20555. }
  20556. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  20557. va_list argp;
  20558. int i;
  20559. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20560. return;
  20561. packet_db[cmd].len = length;
  20562. packet_db[cmd].func = func;
  20563. va_start(argp, func);
  20564. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20565. int offset = va_arg(argp, int);
  20566. if( offset == 0 ){
  20567. break;
  20568. }
  20569. packet_db[cmd].pos[i] = offset;
  20570. }
  20571. if( i == MAX_PACKET_POS ){
  20572. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20573. }
  20574. va_end(argp);
  20575. }
  20576. /*==========================================
  20577. * Reads packets and setups its array reference
  20578. *------------------------------------------*/
  20579. void packetdb_readdb(){
  20580. memset(packet_db,0,sizeof(packet_db));
  20581. memset(packet_db_ack,0,sizeof(packet_db_ack));
  20582. #include "clif_packetdb.hpp"
  20583. #include "clif_shuffle.hpp"
  20584. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20585. #ifdef PACKET_OBFUSCATION
  20586. 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]);
  20587. #else
  20588. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20589. #endif
  20590. }
  20591. /*==========================================
  20592. *
  20593. *------------------------------------------*/
  20594. void do_init_clif(void) {
  20595. const char* colors[COLOR_MAX] = {
  20596. "0x00FF00",
  20597. "0xFF0000",
  20598. "0xFFFFFF",
  20599. "0xFFFF00",
  20600. "0x00FFFF",
  20601. "0xB5FFB5",
  20602. };
  20603. int i;
  20604. /**
  20605. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20606. **/
  20607. for(i = 0; i < COLOR_MAX; i++) {
  20608. color_table[i] = strtoul(colors[i],NULL,0);
  20609. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  20610. }
  20611. packetdb_readdb();
  20612. set_defaultparse(clif_parse);
  20613. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20614. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20615. exit(EXIT_FAILURE);
  20616. }
  20617. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20618. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20619. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20620. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20621. if( battle_config.ping_timer_interval > 0 ){
  20622. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20623. }
  20624. #endif
  20625. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20626. }
  20627. void do_final_clif(void) {
  20628. ers_destroy(delay_clearunit_ers);
  20629. }