clif.cpp 643 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289
  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: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  297. case BL_NPC:
  298. // From 2017-07-26 on NPC type units can also use player sprites.
  299. // There is one exception and this is if they are walking.
  300. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  301. #if PACKETVER >= 20170726
  302. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0xC; // New walking NPC type
  303. #else
  304. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  305. #endif
  306. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  307. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  308. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  309. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  310. default: return 0x1; //NPC_TYPE
  311. }
  312. }
  313. #endif
  314. static bool clif_session_isValid(struct map_session_data *sd) {
  315. return ( sd != nullptr && session_isActive(sd->fd) );
  316. }
  317. /*==========================================
  318. * sub process of clif_send
  319. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  320. * In order to send area-wise packets, such as:
  321. * - AREA : everyone nearby your area
  322. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  323. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  324. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  325. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  326. *------------------------------------------*/
  327. static int clif_send_sub(struct block_list *bl, va_list ap)
  328. {
  329. struct block_list *src_bl;
  330. struct map_session_data *sd;
  331. unsigned char *buf;
  332. int len, type, fd;
  333. nullpo_ret(bl);
  334. nullpo_ret(sd = (struct map_session_data *)bl);
  335. // Don't send to disconnected clients.
  336. if( !session_isActive( fd = sd->fd ) ){
  337. return 0;
  338. }
  339. buf = va_arg(ap,unsigned char*);
  340. len = va_arg(ap,int);
  341. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  342. type = va_arg(ap,int);
  343. switch(type) {
  344. case AREA_WOS:
  345. if (bl == src_bl)
  346. return 0;
  347. break;
  348. case AREA_WOC:
  349. if (sd->chatID || bl == src_bl)
  350. return 0;
  351. break;
  352. case AREA_WOSC:
  353. {
  354. if(src_bl->type == BL_PC) {
  355. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  356. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  357. return 0;
  358. }
  359. else if(src_bl->type == BL_NPC) {
  360. struct npc_data *nd = (struct npc_data *)src_bl;
  361. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  362. return 0;
  363. }
  364. }
  365. break;
  366. }
  367. /* unless visible, hold it here */
  368. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  369. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  370. return 0;
  371. WFIFOHEAD(fd, len);
  372. if (WFIFOP(fd,0) == buf) {
  373. ShowError("WARNING: Invalid use of clif_send function\n");
  374. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  375. ShowError(" Please correct your code.\n");
  376. // don't send to not move the pointer of the packet for next sessions in the loop
  377. //WFIFOSET(fd,0);//## TODO is this ok?
  378. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  379. return 0;
  380. }
  381. memcpy(WFIFOP(fd,0), buf, len);
  382. WFIFOSET(fd,len);
  383. return 0;
  384. }
  385. /*==========================================
  386. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  387. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  388. *------------------------------------------*/
  389. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  390. {
  391. int i;
  392. struct map_session_data *sd, *tsd;
  393. struct party_data *p = NULL;
  394. struct guild *g = NULL;
  395. std::shared_ptr<s_battleground_data> bg;
  396. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  397. struct s_mapiterator* iter;
  398. if( type != ALL_CLIENT )
  399. nullpo_ret(bl);
  400. sd = BL_CAST(BL_PC, bl);
  401. switch(type) {
  402. case ALL_CLIENT: //All player clients.
  403. iter = mapit_getallusers();
  404. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  405. if( session_isActive( fd = tsd->fd ) ){
  406. WFIFOHEAD( fd, len );
  407. memcpy( WFIFOP( fd, 0 ), buf, len );
  408. WFIFOSET( fd, len );
  409. }
  410. }
  411. mapit_free(iter);
  412. break;
  413. case ALL_SAMEMAP: //All players on the same map
  414. iter = mapit_getallusers();
  415. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  416. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  417. WFIFOHEAD( fd, len );
  418. memcpy( WFIFOP( fd, 0 ), buf, len );
  419. WFIFOSET( fd, len );
  420. }
  421. }
  422. mapit_free(iter);
  423. break;
  424. case AREA:
  425. case AREA_WOSC:
  426. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  427. clif_send (buf, len, bl, SELF);
  428. case AREA_WOC:
  429. case AREA_WOS:
  430. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  431. BL_PC, buf, len, bl, type);
  432. break;
  433. case AREA_CHAT_WOC:
  434. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  435. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  436. break;
  437. case CHAT:
  438. case CHAT_WOS:
  439. {
  440. struct chat_data *cd;
  441. if (sd) {
  442. cd = (struct chat_data*)map_id2bl(sd->chatID);
  443. } else if (bl->type == BL_CHAT) {
  444. cd = (struct chat_data*)bl;
  445. } else break;
  446. if (cd == NULL)
  447. break;
  448. for(i = 0; i < cd->users; i++) {
  449. if (type == CHAT_WOS && cd->usersd[i] == sd)
  450. continue;
  451. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  452. WFIFOHEAD(fd,len);
  453. memcpy(WFIFOP(fd,0), buf, len);
  454. WFIFOSET(fd,len);
  455. }
  456. }
  457. }
  458. break;
  459. case PARTY_AREA:
  460. case PARTY_AREA_WOS:
  461. x0 = bl->x - AREA_SIZE;
  462. y0 = bl->y - AREA_SIZE;
  463. x1 = bl->x + AREA_SIZE;
  464. y1 = bl->y + AREA_SIZE;
  465. case PARTY:
  466. case PARTY_WOS:
  467. case PARTY_SAMEMAP:
  468. case PARTY_SAMEMAP_WOS:
  469. if (sd && sd->status.party_id)
  470. p = party_search(sd->status.party_id);
  471. if (p) {
  472. for(i=0;i<MAX_PARTY;i++){
  473. if( (sd = p->data[i].sd) == NULL )
  474. continue;
  475. if( !session_isActive( fd = sd->fd ) )
  476. continue;
  477. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  478. continue;
  479. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  480. continue;
  481. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  482. continue;
  483. WFIFOHEAD(fd, len);
  484. memcpy(WFIFOP(fd, 0), buf, len);
  485. WFIFOSET(fd, len);
  486. }
  487. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  488. break;
  489. iter = mapit_getallusers();
  490. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  491. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  492. WFIFOHEAD( fd, len );
  493. memcpy( WFIFOP( fd, 0 ), buf, len );
  494. WFIFOSET( tsd->fd, len );
  495. }
  496. }
  497. mapit_free(iter);
  498. }
  499. break;
  500. case DUEL:
  501. case DUEL_WOS:
  502. if (!sd || !sd->duel_group) break; //Invalid usage.
  503. iter = mapit_getallusers();
  504. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  505. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  506. continue;
  507. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  508. WFIFOHEAD( fd, len );
  509. memcpy( WFIFOP( fd, 0 ), buf, len );
  510. WFIFOSET( fd, len );
  511. }
  512. }
  513. mapit_free(iter);
  514. break;
  515. case SELF:
  516. if( clif_session_isValid(sd) ){
  517. fd = sd->fd;
  518. WFIFOHEAD(fd,len);
  519. memcpy(WFIFOP(fd,0), buf, len);
  520. WFIFOSET(fd,len);
  521. }
  522. break;
  523. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  524. case GUILD_AREA:
  525. case GUILD_AREA_WOS:
  526. x0 = bl->x - AREA_SIZE;
  527. y0 = bl->y - AREA_SIZE;
  528. x1 = bl->x + AREA_SIZE;
  529. y1 = bl->y + AREA_SIZE;
  530. case GUILD_SAMEMAP:
  531. case GUILD_SAMEMAP_WOS:
  532. case GUILD:
  533. case GUILD_WOS:
  534. case GUILD_NOBG:
  535. if (sd && sd->status.guild_id)
  536. g = sd->guild;
  537. if (g) {
  538. for(i = 0; i < g->max_member; i++) {
  539. if( (sd = g->member[i].sd) != nullptr ){
  540. if( !session_isActive( fd = sd->fd ) )
  541. continue;
  542. if( type == GUILD_NOBG && sd->bg_id )
  543. continue;
  544. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  545. continue;
  546. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  547. continue;
  548. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  549. continue;
  550. WFIFOHEAD(fd,len);
  551. memcpy(WFIFOP(fd,0), buf, len);
  552. WFIFOSET(fd,len);
  553. }
  554. }
  555. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  556. break;
  557. iter = mapit_getallusers();
  558. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  559. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  560. WFIFOHEAD( fd, len );
  561. memcpy( WFIFOP( fd, 0 ), buf, len );
  562. WFIFOSET( fd, len );
  563. }
  564. }
  565. mapit_free(iter);
  566. }
  567. break;
  568. case BG_AREA:
  569. case BG_AREA_WOS:
  570. x0 = bl->x - AREA_SIZE;
  571. y0 = bl->y - AREA_SIZE;
  572. x1 = bl->x + AREA_SIZE;
  573. y1 = bl->y + AREA_SIZE;
  574. case BG_SAMEMAP:
  575. case BG_SAMEMAP_WOS:
  576. case BG:
  577. case BG_WOS:
  578. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  579. {
  580. for (const auto &member : bg->members) {
  581. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  582. continue;
  583. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  584. continue;
  585. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  586. continue;
  587. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  588. continue;
  589. WFIFOHEAD(fd,len);
  590. memcpy(WFIFOP(fd,0), buf, len);
  591. WFIFOSET(fd,len);
  592. }
  593. }
  594. break;
  595. case CLAN:
  596. if( sd && sd->clan ){
  597. struct clan* clan = sd->clan;
  598. for( i = 0; i < clan->max_member; i++ ){
  599. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  600. continue;
  601. }
  602. WFIFOHEAD(fd,len);
  603. memcpy(WFIFOP(fd,0), buf, len);
  604. WFIFOSET(fd,len);
  605. }
  606. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  607. break;
  608. iter = mapit_getallusers();
  609. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  610. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  611. WFIFOHEAD(fd, len);
  612. memcpy(WFIFOP(fd, 0), buf, len);
  613. WFIFOSET(fd, len);
  614. }
  615. }
  616. mapit_free(iter);
  617. }
  618. break;
  619. default:
  620. ShowError("clif_send: Unrecognized type %d\n",type);
  621. return -1;
  622. }
  623. return 0;
  624. }
  625. /// Notifies the client, that it's connection attempt was accepted.
  626. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  627. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  628. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  629. void clif_authok(struct map_session_data *sd)
  630. {
  631. #if PACKETVER < 20080102
  632. const int cmd = 0x73;
  633. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  634. const int cmd = 0x2eb;
  635. #else
  636. const int cmd = 0xa18;
  637. #endif
  638. int fd = sd->fd;
  639. WFIFOHEAD(fd,packet_len(cmd));
  640. WFIFOW(fd, 0) = cmd;
  641. WFIFOL(fd, 2) = client_tick(gettick());
  642. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  643. WFIFOB(fd, 9) = 5; // ignored
  644. WFIFOB(fd,10) = 5; // ignored
  645. #if PACKETVER >= 20080102
  646. WFIFOW(fd,11) = sd->status.font;
  647. #endif
  648. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  649. WFIFOB(fd,13) = sd->status.sex;
  650. #endif
  651. WFIFOSET(fd,packet_len(cmd));
  652. }
  653. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  654. /// 0074 <error code>.B
  655. /// error code:
  656. /// 0 = client type mismatch
  657. /// 1 = ID mismatch
  658. /// 2 = mobile - out of available time
  659. /// 3 = mobile - already logged in
  660. /// 4 = mobile - waiting state
  661. void clif_authrefuse(int fd, uint8 error_code)
  662. {
  663. WFIFOHEAD(fd,packet_len(0x74));
  664. WFIFOW(fd,0) = 0x74;
  665. WFIFOB(fd,2) = error_code;
  666. WFIFOSET(fd,packet_len(0x74));
  667. }
  668. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  669. /// 0081 <error code>.B
  670. /// error code:
  671. /// 0 = BAN_UNFAIR
  672. /// 1 = server closed -> MsgStringTable[4]
  673. /// 2 = ID already logged in -> MsgStringTable[5]
  674. /// 3 = timeout/too much lag -> MsgStringTable[241]
  675. /// 4 = server full -> MsgStringTable[264]
  676. /// 5 = underaged -> MsgStringTable[305]
  677. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  678. /// 9 = too many connections from this ip -> MsgStringTable[529]
  679. /// 10 = out of available time paid for -> MsgStringTable[530]
  680. /// 11 = BAN_PAY_SUSPEND
  681. /// 12 = BAN_PAY_CHANGE
  682. /// 13 = BAN_PAY_WRONGIP
  683. /// 14 = BAN_PAY_PNGAMEROOM
  684. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  685. /// 16 = BAN_JAPAN_REFUSE1
  686. /// 17 = BAN_JAPAN_REFUSE2
  687. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  688. /// 100 = BAN_PC_IP_UNFAIR
  689. /// 101 = BAN_PC_IP_COUNT_ALL
  690. /// 102 = BAN_PC_IP_COUNT
  691. /// 103 = BAN_GRAVITY_MEM_AGREE
  692. /// 104 = BAN_GAME_MEM_AGREE
  693. /// 105 = BAN_HAN_VALID
  694. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  695. /// 107 = BAN_OVER_CHARACTER_LIST
  696. /// 108 = BAN_IP_BLOCK
  697. /// 109 = BAN_INVALID_PWD_CNT
  698. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  699. /// ? = disconnected -> MsgStringTable[3]
  700. void clif_authfail_fd(int fd, int type)
  701. {
  702. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  703. return;
  704. WFIFOHEAD(fd, packet_len(0x81));
  705. WFIFOW(fd,0) = 0x81;
  706. WFIFOB(fd,2) = type;
  707. WFIFOSET(fd,packet_len(0x81));
  708. set_eof(fd);
  709. }
  710. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  711. /// 00b3 <type>.B
  712. /// type:
  713. /// 1 = disconnect, char-select
  714. /// ? = nothing
  715. void clif_charselectok(int id, uint8 ok)
  716. {
  717. struct map_session_data* sd;
  718. int fd;
  719. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  720. return;
  721. fd = sd->fd;
  722. WFIFOHEAD(fd,packet_len(0xb3));
  723. WFIFOW(fd,0) = 0xb3;
  724. WFIFOB(fd,2) = ok;
  725. WFIFOSET(fd,packet_len(0xb3));
  726. }
  727. /// Makes an item appear on the ground.
  728. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  729. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  730. /// 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)
  731. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  732. nullpo_retv(fitem);
  733. if( fitem->item.nameid == 0 ){
  734. return;
  735. }
  736. struct packet_dropflooritem p;
  737. p.PacketType = dropflooritemType;
  738. p.ITAID = fitem->bl.id;
  739. p.ITID = client_nameid( fitem->item.nameid );
  740. #if PACKETVER >= 20130000 /* not sure date */
  741. p.type = itemtype( fitem->item.nameid );
  742. #endif
  743. p.IsIdentified = fitem->item.identify ? 1 : 0;
  744. p.xPos = fitem->bl.x;
  745. p.yPos = fitem->bl.y;
  746. p.subX = fitem->subx;
  747. p.subY = fitem->suby;
  748. p.count = fitem->item.amount;
  749. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  750. if( canShowEffect ){
  751. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  752. if( dropEffect > 0 ){
  753. p.showdropeffect = 1;
  754. p.dropeffectmode = dropEffect - 1;
  755. }else if (battle_config.rndopt_drop_pillar != 0){
  756. uint8 optionCount = 0;
  757. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  758. if (fitem->item.option[i].id != 0) {
  759. optionCount++;
  760. }
  761. }
  762. if (optionCount > 0) {
  763. p.showdropeffect = 1;
  764. if (optionCount == 1)
  765. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  766. else if (optionCount == 2)
  767. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  768. else
  769. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  770. } else {
  771. p.showdropeffect = 0;
  772. p.dropeffectmode = DROPEFFECT_NONE;
  773. }
  774. } else {
  775. p.showdropeffect = 0;
  776. p.dropeffectmode = DROPEFFECT_NONE;
  777. }
  778. }else{
  779. p.showdropeffect = 0;
  780. p.dropeffectmode = DROPEFFECT_NONE;
  781. }
  782. #endif
  783. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  784. }
  785. /// Makes an item disappear from the ground.
  786. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  787. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  788. {
  789. unsigned char buf[16];
  790. nullpo_retv(fitem);
  791. WBUFW(buf,0) = 0xa1;
  792. WBUFL(buf,2) = fitem->bl.id;
  793. if ( !session_isActive( fd ) ){
  794. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  795. } else {
  796. WFIFOHEAD(fd,packet_len(0xa1));
  797. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  798. WFIFOSET(fd,packet_len(0xa1));
  799. }
  800. }
  801. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  802. /// 0080 <id>.L <type>.B
  803. /// type:
  804. /// 0 = out of sight
  805. /// 1 = died
  806. /// 2 = logged out
  807. /// 3 = teleport
  808. /// 4 = trickdead
  809. void clif_clearunit_single(int id, clr_type type, int fd)
  810. {
  811. WFIFOHEAD(fd, packet_len(0x80));
  812. WFIFOW(fd,0) = 0x80;
  813. WFIFOL(fd,2) = id;
  814. WFIFOB(fd,6) = type;
  815. WFIFOSET(fd, packet_len(0x80));
  816. }
  817. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  818. /// 0080 <id>.L <type>.B
  819. /// type:
  820. /// 0 = out of sight
  821. /// 1 = died
  822. /// 2 = logged out
  823. /// 3 = teleport
  824. /// 4 = trickdead
  825. void clif_clearunit_area(struct block_list* bl, clr_type type)
  826. {
  827. unsigned char buf[8];
  828. nullpo_retv(bl);
  829. WBUFW(buf,0) = 0x80;
  830. WBUFL(buf,2) = bl->id;
  831. WBUFB(buf,6) = type;
  832. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  833. if(disguised(bl)) {
  834. WBUFL(buf,2) = disguised_bl_id( bl->id );
  835. clif_send(buf, packet_len(0x80), bl, SELF);
  836. }
  837. }
  838. /// Used to make monsters with player-sprites disappear after dying
  839. /// like normal monsters, because the client does not remove those
  840. /// automatically.
  841. static TIMER_FUNC(clif_clearunit_delayed_sub){
  842. struct block_list *bl = (struct block_list *)data;
  843. clif_clearunit_area(bl, (clr_type) id);
  844. ers_free(delay_clearunit_ers,bl);
  845. return 0;
  846. }
  847. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  848. {
  849. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  850. memcpy (tbl, bl, sizeof (struct block_list));
  851. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  852. }
  853. void clif_get_weapon_view(struct map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  854. {
  855. if(sd->sc.option&OPTION_COSTUME)
  856. {
  857. *rhand = *lhand = 0;
  858. return;
  859. }
  860. #if PACKETVER < 4
  861. *rhand = sd->status.weapon;
  862. *lhand = sd->status.shield;
  863. #else
  864. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  865. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  866. {
  867. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  868. if (id->view_id > 0)
  869. *rhand = id->view_id;
  870. else
  871. *rhand = id->nameid;
  872. } else
  873. *rhand = 0;
  874. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  875. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  876. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  877. {
  878. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  879. if (id->view_id > 0)
  880. *lhand = id->view_id;
  881. else
  882. *lhand = id->nameid;
  883. } else
  884. *lhand = 0;
  885. #endif
  886. }
  887. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  888. static int clif_setlevel_sub(int lv) {
  889. if( lv < battle_config.max_lv ) {
  890. ;
  891. } else if( lv < battle_config.aura_lv ) {
  892. lv = battle_config.max_lv - 1;
  893. } else {
  894. lv = battle_config.max_lv;
  895. }
  896. return lv;
  897. }
  898. static int clif_setlevel(struct block_list* bl) {
  899. int lv = status_get_lv(bl);
  900. if( battle_config.client_limit_unit_lv&bl->type )
  901. return clif_setlevel_sub(lv);
  902. switch( bl->type ) {
  903. case BL_NPC:
  904. case BL_PET:
  905. // npcs and pets do not have level
  906. return 0;
  907. }
  908. return lv;
  909. }
  910. /*==========================================
  911. * Prepares 'unit standing/spawning' packet
  912. *------------------------------------------*/
  913. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  914. nullpo_retv( bl );
  915. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  916. struct status_change* sc = status_get_sc( bl );
  917. struct view_data* vd = status_get_viewdata( bl );
  918. int g_id = status_get_guild_id( bl );
  919. #if PACKETVER < 20091103
  920. if( !pcdb_checkid( vd->class_ ) ){
  921. struct packet_idle_unit2 p;
  922. p.PacketType = idle_unit2Type;
  923. #if PACKETVER >= 20071106
  924. p.objecttype = clif_bl_type( bl, walking );
  925. #endif
  926. p.GID = bl->id;
  927. p.speed = status_get_speed( bl );
  928. p.bodyState = ( sc ) ? sc->opt1 : 0;
  929. p.healthState = ( sc ) ? sc->opt2 : 0;
  930. p.effectState = ( sc ) ? sc->option : 0;
  931. p.job = vd->class_;
  932. p.head = vd->hair_style;
  933. p.weapon = vd->weapon;
  934. p.accessory = vd->head_bottom;
  935. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  936. // The hell, why flags work like this?
  937. p.shield = status_get_emblem_id( bl );
  938. p.accessory2 = GetWord( g_id, 1 );
  939. p.accessory3 = GetWord( g_id, 0 );
  940. }else{
  941. p.shield = vd->shield;
  942. p.accessory2 = vd->head_top;
  943. p.accessory3 = vd->head_mid;
  944. }
  945. p.headpalette = vd->hair_color;
  946. p.bodypalette = vd->cloth_color;
  947. p.headDir = ( sd )? sd->head_dir : 0;
  948. p.GUID = g_id;
  949. p.GEmblemVer = status_get_emblem_id( bl );
  950. p.honor = ( sd ) ? sd->status.manner : 0;
  951. p.virtue = ( sc ) ? sc->opt3 : 0;
  952. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  953. p.sex = vd->sex;
  954. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  955. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  956. p.state = vd->dead_sit;
  957. p.clevel = clif_setlevel( bl );
  958. clif_send( &p, sizeof( p ), tbl, target );
  959. return;
  960. }
  961. #endif
  962. struct packet_idle_unit p;
  963. p.PacketType = idle_unitType;
  964. #if PACKETVER >= 20091103
  965. p.PacketLength = sizeof(p);
  966. p.objecttype = clif_bl_type( bl, walking );
  967. #endif
  968. #if PACKETVER >= 20131223
  969. p.AID = bl->id;
  970. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  971. #else
  972. p.GID = bl->id;
  973. #endif
  974. p.speed = status_get_speed(bl);
  975. p.bodyState = (sc) ? sc->opt1 : 0;
  976. p.healthState = (sc) ? sc->opt2 : 0;
  977. // npc option changed?
  978. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  979. struct map_session_data* sd = (struct map_session_data*)tbl;
  980. struct npc_data* nd = (struct npc_data*)bl;
  981. int option = (sc) ? sc->option : 0;
  982. if( !nd->vd.dead_sit ){
  983. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  984. option ^= OPTION_CLOAK;
  985. }
  986. }
  987. p.effectState = option;
  988. }else{
  989. p.effectState = (sc) ? sc->option : 0;
  990. }
  991. p.job = vd->class_;
  992. p.head = vd->hair_style;
  993. p.weapon = vd->weapon;
  994. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  995. p.shield = vd->shield;
  996. #endif
  997. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  998. // The hell, why flags work like this?
  999. p.accessory = status_get_emblem_id( bl );
  1000. p.accessory2 = GetWord( g_id, 1 );
  1001. p.accessory3 = GetWord( g_id, 0 );
  1002. }else{
  1003. p.accessory = vd->head_bottom;
  1004. p.accessory2 = vd->head_top;
  1005. p.accessory3 = vd->head_mid;
  1006. }
  1007. p.headpalette = vd->hair_color;
  1008. p.bodypalette = vd->cloth_color;
  1009. p.headDir = (sd)? sd->head_dir : 0;
  1010. #if PACKETVER >= 20101124
  1011. p.robe = vd->robe;
  1012. #endif
  1013. p.GUID = g_id;
  1014. p.GEmblemVer = status_get_emblem_id( bl );
  1015. p.honor = (sd) ? sd->status.manner : 0;
  1016. p.virtue = (sc) ? sc->opt3 : 0;
  1017. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1018. p.sex = vd->sex;
  1019. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1020. p.xSize = p.ySize = (sd) ? 5 : 0;
  1021. p.state = vd->dead_sit;
  1022. p.clevel = clif_setlevel( bl );
  1023. #if PACKETVER >= 20080102
  1024. p.font = (sd) ? sd->status.font : 0;
  1025. #endif
  1026. #if PACKETVER >= 20120221
  1027. 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 ) ) ){
  1028. p.maxHP = status_get_max_hp(bl);
  1029. p.HP = status_get_hp(bl);
  1030. }else{
  1031. p.maxHP = -1;
  1032. p.HP = -1;
  1033. }
  1034. if( bl->type == BL_MOB ){
  1035. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1036. }else if( bl->type == BL_PET ){
  1037. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1038. }else{
  1039. p.isBoss = BOSSTYPE_NONE;
  1040. }
  1041. #endif
  1042. #if PACKETVER >= 20150513
  1043. p.body = vd->body_style;
  1044. #endif
  1045. /* Might be earlier, this is when the named item bug began */
  1046. #if PACKETVER >= 20131223
  1047. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1048. #endif
  1049. clif_send( &p, sizeof( p ), tbl, target );
  1050. // if disguised, send to self
  1051. if( disguised( bl ) ){
  1052. #if PACKETVER >= 20091103
  1053. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1054. #if PACKETVER >= 20131223
  1055. p.AID = disguised_bl_id( bl->id );
  1056. #else
  1057. p.GID = disguised_bl_id( bl->id );
  1058. #endif
  1059. #else
  1060. p.GID = disguised_bl_id( bl->id );
  1061. #endif
  1062. clif_send(&p, sizeof(p), bl, SELF);
  1063. }
  1064. }
  1065. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1066. nullpo_retv( bl );
  1067. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1068. struct status_change* sc = status_get_sc( bl );
  1069. struct view_data* vd = status_get_viewdata( bl );
  1070. int g_id = status_get_guild_id( bl );
  1071. #if PACKETVER < 20091103
  1072. if( !pcdb_checkid( vd->class_ ) ){
  1073. struct packet_spawn_unit2 p;
  1074. p.PacketType = spawn_unit2Type;
  1075. #if PACKETVER >= 20071106
  1076. p.objecttype = clif_bl_type( bl, false );
  1077. #endif
  1078. p.GID = bl->id;
  1079. p.speed = status_get_speed( bl );
  1080. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1081. p.healthState = ( sc ) ? sc->opt2 : 0;
  1082. p.effectState = ( sc ) ? sc->option : 0;
  1083. p.head = vd->hair_style;
  1084. p.weapon = vd->weapon;
  1085. p.accessory = vd->head_bottom;
  1086. p.job = vd->class_;
  1087. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1088. // The hell, why flags work like this?
  1089. p.shield = status_get_emblem_id( bl );
  1090. p.accessory2 = GetWord( g_id, 1 );
  1091. p.accessory3 = GetWord( g_id, 0 );
  1092. }else{
  1093. p.shield = vd->shield;
  1094. p.accessory2 = vd->head_top;
  1095. p.accessory3 = vd->head_mid;
  1096. }
  1097. p.headpalette = vd->hair_color;
  1098. p.bodypalette = vd->cloth_color;
  1099. p.headDir = ( sd ) ? sd->head_dir : 0;
  1100. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1101. p.sex = vd->sex;
  1102. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1103. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1104. clif_send( &p, sizeof( p ), bl, target );
  1105. return;
  1106. }
  1107. #endif
  1108. struct packet_spawn_unit p;
  1109. p.PacketType = spawn_unitType;
  1110. #if PACKETVER >= 20091103
  1111. p.PacketLength = sizeof(p);
  1112. p.objecttype = clif_bl_type( bl, false );
  1113. #endif
  1114. #if PACKETVER >= 20131223
  1115. p.AID = bl->id;
  1116. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1117. #else
  1118. p.GID = bl->id;
  1119. #endif
  1120. p.speed = status_get_speed( bl );
  1121. p.bodyState = (sc) ? sc->opt1 : 0;
  1122. p.healthState = (sc) ? sc->opt2 : 0;
  1123. p.effectState = (sc) ? sc->option : 0;
  1124. p.job = vd->class_;
  1125. p.head = vd->hair_style;
  1126. p.weapon = vd->weapon;
  1127. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1128. p.shield = vd->shield;
  1129. #endif
  1130. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1131. // The hell, why flags work like this?
  1132. p.accessory = status_get_emblem_id( bl );
  1133. p.accessory2 = GetWord( g_id, 1 );
  1134. p.accessory3 = GetWord( g_id, 0 );
  1135. }else{
  1136. p.accessory = vd->head_bottom;
  1137. p.accessory2 = vd->head_top;
  1138. p.accessory3 = vd->head_mid;
  1139. }
  1140. p.headpalette = vd->hair_color;
  1141. p.bodypalette = vd->cloth_color;
  1142. p.headDir = (sd)? sd->head_dir : 0;
  1143. #if PACKETVER >= 20101124
  1144. p.robe = vd->robe;
  1145. #endif
  1146. p.GUID = g_id;
  1147. p.GEmblemVer = status_get_emblem_id( bl );
  1148. p.honor = (sd) ? sd->status.manner : 0;
  1149. p.virtue = (sc) ? sc->opt3 : 0;
  1150. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1151. p.sex = vd->sex;
  1152. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1153. p.xSize = p.ySize = (sd) ? 5 : 0;
  1154. p.clevel = clif_setlevel( bl );
  1155. #if PACKETVER >= 20080102
  1156. p.font = (sd) ? sd->status.font : 0;
  1157. #endif
  1158. #if PACKETVER >= 20120221
  1159. 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 ) ) ){
  1160. p.maxHP = status_get_max_hp( bl );
  1161. p.HP = status_get_hp( bl );
  1162. }else{
  1163. p.maxHP = -1;
  1164. p.HP = -1;
  1165. }
  1166. if( bl->type == BL_MOB ){
  1167. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1168. }else if( bl->type == BL_PET ){
  1169. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1170. }else{
  1171. p.isBoss = BOSSTYPE_NONE;
  1172. }
  1173. #endif
  1174. #if PACKETVER >= 20150513
  1175. p.body = vd->body_style;
  1176. #endif
  1177. /* Might be earlier, this is when the named item bug began */
  1178. #if PACKETVER >= 20131223
  1179. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1180. #endif
  1181. if( disguised( bl ) ){
  1182. nullpo_retv( sd );
  1183. if( sd->status.class_ != sd->disguise ){
  1184. clif_send( &p, sizeof( p ), bl, target );
  1185. }
  1186. #if PACKETVER >= 20091103
  1187. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1188. #if PACKETVER >= 20131223
  1189. p.AID = disguised_bl_id( bl->id );
  1190. #else
  1191. p.GID = disguised_bl_id( bl->id );
  1192. #endif
  1193. #else
  1194. p.GID = disguised_bl_id( bl->id );
  1195. #endif
  1196. clif_send( &p, sizeof( p ), bl, SELF );
  1197. }else{
  1198. clif_send( &p, sizeof( p ), bl, target );
  1199. }
  1200. }
  1201. /*==========================================
  1202. * Prepares 'unit walking' packet
  1203. *------------------------------------------*/
  1204. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1205. nullpo_retv( bl );
  1206. nullpo_retv( ud );
  1207. struct map_session_data* sd;
  1208. struct status_change* sc = status_get_sc( bl );
  1209. struct view_data* vd = status_get_viewdata( bl );
  1210. struct packet_unit_walking p;
  1211. int g_id = status_get_guild_id(bl);
  1212. sd = BL_CAST(BL_PC, bl);
  1213. p.PacketType = unit_walkingType;
  1214. #if PACKETVER >= 20091103
  1215. p.PacketLength = sizeof(p);
  1216. #endif
  1217. #if PACKETVER >= 20071106
  1218. p.objecttype = clif_bl_type( bl, true );
  1219. #endif
  1220. #if PACKETVER >= 20131223
  1221. p.AID = bl->id;
  1222. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1223. #else
  1224. p.GID = bl->id;
  1225. #endif
  1226. p.speed = status_get_speed(bl);
  1227. p.bodyState = (sc) ? sc->opt1 : 0;
  1228. p.healthState = (sc) ? sc->opt2 : 0;
  1229. p.effectState = (sc) ? sc->option : 0;
  1230. p.job = vd->class_;
  1231. p.head = vd->hair_style;
  1232. p.weapon = vd->weapon;
  1233. p.accessory = vd->head_bottom;
  1234. p.moveStartTime = client_tick(gettick());
  1235. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1236. p.shield = vd->shield;
  1237. #endif
  1238. p.accessory2 = vd->head_top;
  1239. p.accessory3 = vd->head_mid;
  1240. p.headpalette = vd->hair_color;
  1241. p.bodypalette = vd->cloth_color;
  1242. p.headDir = (sd) ? sd->head_dir : 0;
  1243. #if PACKETVER >= 20101124
  1244. p.robe = vd->robe;
  1245. #endif
  1246. p.GUID = g_id;
  1247. p.GEmblemVer = status_get_emblem_id(bl);
  1248. p.honor = (sd) ? sd->status.manner : 0;
  1249. p.virtue = (sc) ? sc->opt3 : 0;
  1250. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1251. p.sex = vd->sex;
  1252. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1253. p.xSize = p.ySize = (sd) ? 5 : 0;
  1254. p.clevel = clif_setlevel(bl);
  1255. #if PACKETVER >= 20080102
  1256. p.font = (sd) ? sd->status.font : 0;
  1257. #endif
  1258. #if PACKETVER >= 20120221
  1259. 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 ) ) ){
  1260. p.maxHP = status_get_max_hp(bl);
  1261. p.HP = status_get_hp(bl);
  1262. } else {
  1263. p.maxHP = -1;
  1264. p.HP = -1;
  1265. }
  1266. if( bl->type == BL_MOB ){
  1267. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1268. }else if( bl->type == BL_PET ){
  1269. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1270. }else{
  1271. p.isBoss = BOSSTYPE_NONE;
  1272. }
  1273. #endif
  1274. #if PACKETVER >= 20150513
  1275. p.body = vd->body_style;
  1276. #endif
  1277. /* Might be earlier, this is when the named item bug began */
  1278. #if PACKETVER >= 20131223
  1279. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1280. #endif
  1281. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1282. // if disguised, send the info to self
  1283. if( disguised( bl ) ){
  1284. #if PACKETVER >= 20091103
  1285. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1286. #if PACKETVER >= 20131223
  1287. p.AID = disguised_bl_id( bl->id );
  1288. #else
  1289. p.GID = disguised_bl_id( bl->id );
  1290. #endif
  1291. #else
  1292. p.GID = disguised_bl_id( bl->id );
  1293. #endif
  1294. clif_send(&p,sizeof(p),bl,SELF);
  1295. }
  1296. }
  1297. //Modifies the buffer for disguise characters and sends it to self.
  1298. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1299. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1300. {
  1301. #if PACKETVER >= 20091103
  1302. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1303. WBUFL(buf,5)=-bl->id;
  1304. #elif PACKETVER >= 20071106
  1305. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1306. WBUFL(buf,3)=-bl->id;
  1307. #else
  1308. WBUFL(buf,2)=-bl->id;
  1309. #endif
  1310. clif_send(buf, len, bl, SELF);
  1311. }
  1312. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1313. /// 01b0 <id>.L <type>.B <value>.L
  1314. /// type:
  1315. /// unused
  1316. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1317. {
  1318. nullpo_retv(bl);
  1319. if(!pcdb_checkid(class_))
  1320. {// player classes yield missing sprites
  1321. unsigned char buf[16];
  1322. WBUFW(buf,0)=0x1b0;
  1323. WBUFL(buf,2)=bl->id;
  1324. WBUFB(buf,6)=type;
  1325. WBUFL(buf,7)=class_;
  1326. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1327. }
  1328. }
  1329. /// Notifies the client of an object's Millenium Shields.
  1330. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1331. {
  1332. nullpo_retv(sd);
  1333. if (sd->sc.data[SC_MILLENNIUMSHIELD] == nullptr)
  1334. return;
  1335. WFIFOHEAD(fd, packet_len(0x440));
  1336. WFIFOW(fd, 0) = 0x440;
  1337. WFIFOL(fd, 2) = sd->bl.id;
  1338. WFIFOW(fd, 6) = sd->sc.data[SC_MILLENNIUMSHIELD]->val2;
  1339. WFIFOW(fd, 8) = 0;
  1340. WFIFOSET(fd, packet_len(0x440));
  1341. }
  1342. /*==========================================
  1343. * Kagerou/Oboro amulet spirit
  1344. *------------------------------------------*/
  1345. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1346. {
  1347. WFIFOHEAD(fd, packet_len(0x08cf));
  1348. WFIFOW(fd,0)=0x08cf;
  1349. WFIFOL(fd,2)=sd->bl.id;
  1350. WFIFOW(fd,6)=sd->spiritcharm_type;
  1351. WFIFOW(fd,8)=sd->spiritcharm;
  1352. WFIFOSET(fd, packet_len(0x08cf));
  1353. }
  1354. /*==========================================
  1355. * Run when player changes map / refreshes
  1356. * Tells its client to display all weather settings being used by this map
  1357. *------------------------------------------*/
  1358. static void clif_weather_check(struct map_session_data *sd)
  1359. {
  1360. int16 m = sd->bl.m;
  1361. int fd = sd->fd;
  1362. if (map_getmapflag(m, MF_SNOW)
  1363. || map_getmapflag(m, MF_CLOUDS)
  1364. || map_getmapflag(m, MF_FOG)
  1365. || map_getmapflag(m, MF_FIREWORKS)
  1366. || map_getmapflag(m, MF_SAKURA)
  1367. || map_getmapflag(m, MF_LEAVES)
  1368. || map_getmapflag(m, MF_CLOUDS2))
  1369. {
  1370. if (map_getmapflag(m, MF_SNOW))
  1371. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1372. if (map_getmapflag(m, MF_CLOUDS))
  1373. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1374. if (map_getmapflag(m, MF_CLOUDS2))
  1375. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1376. if (map_getmapflag(m, MF_FOG))
  1377. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1378. if (map_getmapflag(m, MF_FIREWORKS)) {
  1379. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1380. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1381. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1382. }
  1383. if (map_getmapflag(m, MF_SAKURA))
  1384. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1385. if (map_getmapflag(m, MF_LEAVES))
  1386. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1387. }
  1388. }
  1389. /**
  1390. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1391. **/
  1392. void clif_weather(int16 m)
  1393. {
  1394. struct s_mapiterator* iter;
  1395. struct map_session_data *sd=NULL;
  1396. iter = mapit_getallusers();
  1397. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1398. {
  1399. if( sd->bl.m == m )
  1400. clif_weather_check(sd);
  1401. }
  1402. mapit_free(iter);
  1403. }
  1404. /**
  1405. * Hide a NPC from the effects of Maya Purple card.
  1406. * @param bl: Block data
  1407. * @return True if NPC is disabled or false otherwise
  1408. */
  1409. static inline bool clif_npc_mayapurple(block_list *bl) {
  1410. nullpo_retr(false, bl);
  1411. if (bl->type == BL_NPC) {
  1412. npc_data *nd = map_id2nd(bl->id);
  1413. // TODO: Confirm if waitingroom cause any special cases
  1414. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1415. return true;
  1416. }
  1417. return false;
  1418. }
  1419. /**
  1420. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1421. **/
  1422. int clif_spawn( struct block_list *bl, bool walking ){
  1423. struct view_data *vd;
  1424. vd = status_get_viewdata(bl);
  1425. if( !vd || vd->class_ == JT_INVISIBLE )
  1426. return 0;
  1427. // Hide NPC from Maya Purple card
  1428. if (clif_npc_mayapurple(bl))
  1429. return 0;
  1430. if( bl->type == BL_NPC && !vd->dead_sit ){
  1431. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1432. }else{
  1433. clif_spawn_unit( bl, AREA_WOS );
  1434. }
  1435. if (vd->cloth_color)
  1436. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1437. if (vd->body_style)
  1438. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1439. switch (bl->type)
  1440. {
  1441. case BL_PC:
  1442. {
  1443. TBL_PC *sd = ((TBL_PC*)bl);
  1444. if (sd->spiritball > 0)
  1445. clif_spiritball(&sd->bl);
  1446. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  1447. clif_millenniumshield(&sd->bl, sd->sc.data[SC_MILLENNIUMSHIELD]->val2);
  1448. if (sd->soulball > 0)
  1449. clif_soulball(sd);
  1450. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1451. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1452. else if(sd->state.size==SZ_MEDIUM)
  1453. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1454. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1455. clif_sendbgemblem_area(sd);
  1456. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1457. clif_spiritcharm(sd);
  1458. if (sd->status.robe)
  1459. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1460. clif_efst_status_change_sub(bl, bl, AREA);
  1461. clif_hat_effects(sd,bl,AREA);
  1462. }
  1463. break;
  1464. case BL_MOB:
  1465. {
  1466. TBL_MOB *md = ((TBL_MOB*)bl);
  1467. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1468. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1469. else if(md->special_state.size==SZ_MEDIUM)
  1470. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1471. }
  1472. break;
  1473. case BL_NPC:
  1474. {
  1475. TBL_NPC *nd = ((TBL_NPC*)bl);
  1476. if( nd->size == SZ_BIG )
  1477. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1478. else if( nd->size == SZ_MEDIUM )
  1479. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1480. clif_efst_status_change_sub(bl, bl, AREA);
  1481. clif_progressbar_npc_area(nd);
  1482. }
  1483. break;
  1484. case BL_PET:
  1485. if (vd->head_bottom)
  1486. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1487. break;
  1488. }
  1489. return 0;
  1490. }
  1491. /// Sends information about owned homunculus to the client . [orn]
  1492. /// 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)
  1493. /// 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)
  1494. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1495. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1496. nullpo_retv( sd );
  1497. nullpo_retv( hd );
  1498. struct status_data *status = &hd->battle_status;
  1499. struct PACKET_ZC_PROPERTY_HOMUN p;
  1500. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1501. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1502. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1503. 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 );
  1504. p.level = hd->homunculus.level;
  1505. p.hunger = hd->homunculus.hunger;
  1506. p.intimacy = hd->homunculus.intimacy / 100;
  1507. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1508. p.itemId = 0; // equip id
  1509. #endif
  1510. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1511. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1512. p.hit = status->hit;
  1513. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1514. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1515. }else{
  1516. p.crit = status->cri / 10;
  1517. }
  1518. #ifdef RENEWAL
  1519. p.def = status->def + status->def2;
  1520. p.mdef = status->mdef + status->mdef2;
  1521. #else
  1522. p.def = status->def + status->vit;
  1523. p.mdef = status->mdef;
  1524. #endif
  1525. p.flee = status->flee;
  1526. p.amotion = (flag) ? 0 : status->amotion;
  1527. #if PACKETVER >= 20141016
  1528. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1529. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1530. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1531. p.hp = status->hp / ( status->max_hp / 100 );
  1532. p.maxHp = 100;
  1533. }else{
  1534. p.hp = status->hp;
  1535. p.maxHp = status->max_hp;
  1536. }
  1537. #else
  1538. if( status->max_hp > INT16_MAX ){
  1539. p.hp = status->hp / ( status->max_hp / 100 );
  1540. p.maxHp = 100;
  1541. }else{
  1542. p.hp = status->hp;
  1543. p.maxHp = status->max_hp;
  1544. }
  1545. #endif
  1546. if( status->max_sp > INT16_MAX ){
  1547. p.sp = status->sp / ( status->max_sp / 100 );
  1548. p.maxSp = 100;
  1549. }else{
  1550. p.sp = status->sp;
  1551. p.maxSp = status->max_sp;
  1552. }
  1553. p.exp = (uint32)hd->homunculus.exp;
  1554. p.expNext = (uint32)hd->exp_next;
  1555. switch( hom_class2type( hd->homunculus.class_ ) ){
  1556. case HT_REG:
  1557. case HT_EVO:
  1558. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1559. p.expNext = 0;
  1560. }
  1561. break;
  1562. case HT_S:
  1563. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1564. p.expNext = 0;
  1565. }
  1566. break;
  1567. }
  1568. p.skillPoints = hd->homunculus.skillpts;
  1569. p.range = status_get_range( &hd->bl );
  1570. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1571. #endif
  1572. }
  1573. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1574. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1575. /// type:
  1576. /// unused
  1577. /// state:
  1578. /// 0 = pre-init
  1579. /// 1 = intimacy
  1580. /// 2 = hunger
  1581. /// 3 = accessory?
  1582. /// ? = ignored
  1583. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1584. { //[orn]
  1585. int fd = sd->fd;
  1586. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1587. hom_calc_skilltree(sd->hd, 0);
  1588. WFIFOHEAD(fd, packet_len(0x230));
  1589. WFIFOW(fd,0)=0x230;
  1590. WFIFOB(fd,2)=0;
  1591. WFIFOB(fd,3)=state;
  1592. WFIFOL(fd,4)=sd->hd->bl.id;
  1593. WFIFOL(fd,8)=param;
  1594. WFIFOSET(fd,packet_len(0x230));
  1595. }
  1596. int clif_homskillinfoblock(struct map_session_data *sd)
  1597. { //[orn]
  1598. struct homun_data *hd;
  1599. int fd = sd->fd;
  1600. int i, len=4;
  1601. nullpo_ret(sd);
  1602. hd = sd->hd;
  1603. if ( !hd )
  1604. return 0 ;
  1605. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1606. WFIFOW(fd,0)=0x235;
  1607. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1608. int id = hd->homunculus.hskill[i].id;
  1609. if( id != 0 ){
  1610. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1611. short idx = hom_skill_get_index(id);
  1612. if (idx == -1)
  1613. continue;
  1614. WFIFOW(fd,len ) = id;
  1615. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1616. WFIFOW(fd,len+4) = 0;
  1617. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1618. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1619. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1620. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1621. 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;
  1622. len+=37;
  1623. }
  1624. }
  1625. WFIFOW(fd,2)=len;
  1626. WFIFOSET(fd,len);
  1627. return 0;
  1628. }
  1629. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1630. { //[orn]
  1631. struct homun_data *hd;
  1632. int fd;
  1633. short idx = -1;
  1634. nullpo_retv(sd);
  1635. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1636. return;
  1637. fd = sd->fd;
  1638. hd = sd->hd;
  1639. WFIFOHEAD(fd, packet_len(0x239));
  1640. WFIFOW(fd,0) = 0x239;
  1641. WFIFOW(fd,2) = skill_id;
  1642. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1643. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1644. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1645. 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;
  1646. WFIFOSET(fd,packet_len(0x239));
  1647. }
  1648. /// Result of request to feed a homun/merc.
  1649. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1650. /// result:
  1651. /// 0 = failure
  1652. /// 1 = success
  1653. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1654. nullpo_retv( sd );
  1655. struct PACKET_ZC_FEED_MER p;
  1656. p.packetType = 0x22f;
  1657. p.result = fail;
  1658. p.itemId = client_nameid( foodid );
  1659. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1660. }
  1661. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1662. /// 0087 <walk start time>.L <walk data>.6B
  1663. void clif_walkok(struct map_session_data *sd)
  1664. {
  1665. int fd=sd->fd;
  1666. WFIFOHEAD(fd, packet_len(0x87));
  1667. WFIFOW(fd,0)=0x87;
  1668. WFIFOL(fd,2)=client_tick(gettick());
  1669. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1670. WFIFOSET(fd,packet_len(0x87));
  1671. }
  1672. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1673. struct status_change *sc = NULL;
  1674. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1675. clif_ally_only = true;
  1676. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1677. if(vd->cloth_color)
  1678. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1679. if(vd->body_style)
  1680. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1681. switch(bl->type) {
  1682. case BL_PC:
  1683. {
  1684. TBL_PC *sd = ((TBL_PC*)bl);
  1685. // clif_movepc(sd);
  1686. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1687. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1688. else if(sd->state.size==SZ_MEDIUM)
  1689. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1690. if (sd->status.robe)
  1691. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1692. }
  1693. break;
  1694. case BL_MOB:
  1695. {
  1696. TBL_MOB *md = ((TBL_MOB*)bl);
  1697. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1698. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1699. else if(md->special_state.size==SZ_MEDIUM)
  1700. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1701. }
  1702. break;
  1703. case BL_PET:
  1704. if(vd->head_bottom) // needed to display pet equip properly
  1705. clif_pet_equip_area((TBL_PET*)bl);
  1706. break;
  1707. }
  1708. clif_ally_only = false;
  1709. }
  1710. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1711. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1712. /// Note: unit must not be self
  1713. void clif_move(struct unit_data *ud)
  1714. {
  1715. unsigned char buf[16];
  1716. struct view_data* vd;
  1717. struct block_list* bl = ud->bl;
  1718. struct status_change *sc = NULL;
  1719. vd = status_get_viewdata(bl);
  1720. if (!vd )
  1721. return;
  1722. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1723. else if( vd->class_ == JT_INVISIBLE ){
  1724. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1725. if(disguised(bl)) {
  1726. WBUFW(buf,0)=0x86;
  1727. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1728. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1729. WBUFL(buf,12)=client_tick(gettick());
  1730. clif_send(buf, packet_len(0x86), bl, SELF);
  1731. }
  1732. return;
  1733. }
  1734. // Hide NPC from Maya Purple card
  1735. if (clif_npc_mayapurple(bl))
  1736. return;
  1737. if (ud->state.speed_changed) {
  1738. // Since we don't know how to update the speed of other objects,
  1739. // use the old walk packet to update the data.
  1740. ud->state.speed_changed = 0;
  1741. clif_move2(bl, vd, ud);
  1742. return;
  1743. }
  1744. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1745. clif_ally_only = true;
  1746. WBUFW(buf,0)=0x86;
  1747. WBUFL(buf,2)=bl->id;
  1748. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1749. WBUFL(buf,12)=client_tick(gettick());
  1750. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1751. if (disguised(bl)) {
  1752. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1753. clif_send(buf, packet_len(0x86), bl, SELF);
  1754. }
  1755. clif_ally_only = false;
  1756. }
  1757. /*==========================================
  1758. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1759. *------------------------------------------*/
  1760. static TIMER_FUNC(clif_delayquit){
  1761. struct map_session_data *sd = NULL;
  1762. //Remove player from map server
  1763. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1764. map_quit(sd);
  1765. return 0;
  1766. }
  1767. /*==========================================
  1768. *
  1769. *------------------------------------------*/
  1770. void clif_quitsave(int fd,struct map_session_data *sd) {
  1771. if (!battle_config.prevent_logout ||
  1772. sd->canlog_tick == 0 ||
  1773. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1774. map_quit(sd);
  1775. else if (session_isValid(sd->fd)) {
  1776. //Disassociate session from player (session is deleted after this function was called)
  1777. //And set a timer to make him quit later.
  1778. session[sd->fd]->session_data = NULL;
  1779. sd->fd = 0;
  1780. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1781. }
  1782. }
  1783. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1784. /// 0091 <map name>.16B <x>.W <y>.W
  1785. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1786. {
  1787. nullpo_retv(sd);
  1788. int fd = sd->fd;
  1789. WFIFOHEAD(fd,packet_len(0x91));
  1790. WFIFOW(fd,0) = 0x91;
  1791. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1792. WFIFOW(fd,18) = x;
  1793. WFIFOW(fd,20) = y;
  1794. WFIFOSET(fd,packet_len(0x91));
  1795. }
  1796. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1797. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1798. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1799. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1800. {
  1801. int fd;
  1802. #if PACKETVER >= 20170315
  1803. int cmd = 0xac7;
  1804. #else
  1805. int cmd = 0x92;
  1806. #endif
  1807. nullpo_retv(sd);
  1808. fd = sd->fd;
  1809. WFIFOHEAD(fd,packet_len(cmd));
  1810. WFIFOW(fd,0) = cmd;
  1811. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1812. WFIFOW(fd,18) = x;
  1813. WFIFOW(fd,20) = y;
  1814. WFIFOL(fd,22) = htonl(ip);
  1815. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1816. #if PACKETVER >= 20170315
  1817. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1818. #endif
  1819. WFIFOSET(fd,packet_len(cmd));
  1820. }
  1821. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1822. /// This function combines both calls and allows to simplify the calling code
  1823. void clif_blown(struct block_list *bl)
  1824. {
  1825. clif_slide(bl, bl->x, bl->y);
  1826. clif_fixpos(bl);
  1827. }
  1828. /// Visually moves(slides) a character to x,y. If the target cell
  1829. /// isn't walkable, the char doesn't move at all. If the char is
  1830. /// sitting it will stand up (ZC_STOPMOVE).
  1831. /// 0088 <id>.L <x>.W <y>.W
  1832. void clif_fixpos(struct block_list *bl)
  1833. {
  1834. unsigned char buf[10];
  1835. nullpo_retv(bl);
  1836. WBUFW(buf,0) = 0x88;
  1837. WBUFL(buf,2) = bl->id;
  1838. WBUFW(buf,6) = bl->x;
  1839. WBUFW(buf,8) = bl->y;
  1840. clif_send(buf, packet_len(0x88), bl, AREA);
  1841. if( disguised(bl) ) {
  1842. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1843. clif_send(buf, packet_len(0x88), bl, SELF);
  1844. }
  1845. }
  1846. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1847. /// 00c4 <shop id>.L
  1848. void clif_npcbuysell(struct map_session_data* sd, int id)
  1849. {
  1850. int fd;
  1851. nullpo_retv(sd);
  1852. fd=sd->fd;
  1853. WFIFOHEAD(fd, packet_len(0xc4));
  1854. WFIFOW(fd,0)=0xc4;
  1855. WFIFOL(fd,2)=id;
  1856. WFIFOSET(fd,packet_len(0xc4));
  1857. }
  1858. /// Presents list of items, that can be bought in an NPC shop.
  1859. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1860. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1861. nullpo_retv( sd );
  1862. nullpo_retv( nd );
  1863. int fd = sd->fd;
  1864. if( !session_isActive( fd ) ){
  1865. return;
  1866. }
  1867. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1868. WFIFOHEAD( fd, len );
  1869. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1870. p->packetType = 0xc6;
  1871. int count = 0;
  1872. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1873. int val = nd->u.shop.shop_item[i].value;
  1874. p->items[count].price = val;
  1875. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1876. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1877. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1878. count++;
  1879. }
  1880. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1881. WFIFOSET( fd, p->packetLength );
  1882. }
  1883. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1884. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1885. void clif_selllist(struct map_session_data *sd)
  1886. {
  1887. int fd,i,c=0,val;
  1888. struct npc_data *nd;
  1889. nullpo_retv(sd);
  1890. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1891. return;
  1892. fd=sd->fd;
  1893. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1894. WFIFOW(fd,0)=0xc7;
  1895. for( i = 0; i < MAX_INVENTORY; i++ )
  1896. {
  1897. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1898. {
  1899. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1900. continue;
  1901. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1902. val = 0;
  1903. else {
  1904. val = sd->inventory_data[i]->value_sell;
  1905. if( val < 0 )
  1906. continue;
  1907. }
  1908. WFIFOW(fd,4+c*10)=i+2;
  1909. WFIFOL(fd,6+c*10)=val;
  1910. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1911. c++;
  1912. }
  1913. }
  1914. WFIFOW(fd,2)=c*10+4;
  1915. WFIFOSET(fd,WFIFOW(fd,2));
  1916. }
  1917. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1918. /// 09d4
  1919. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1920. // TODO: State tracking?
  1921. sd->npc_shopid = 0;
  1922. }
  1923. /**
  1924. * Presents list of items, that can be sold to a Market shop.
  1925. * @author: Ind and Yommy
  1926. **/
  1927. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1928. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1929. #if PACKETVER >= 20131223
  1930. nullpo_retv( sd );
  1931. nullpo_retv( nd );
  1932. if( sd->state.trading ){
  1933. return;
  1934. }
  1935. int fd = sd->fd;
  1936. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1937. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1938. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1939. int count = 0;
  1940. for( int i = 0; i < nd->u.shop.count; i++ ){
  1941. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1942. if( !item->nameid ){
  1943. continue;
  1944. }
  1945. struct item_data *id = itemdb_exists( item->nameid );
  1946. if( !id ){
  1947. continue;
  1948. }
  1949. p->list[count].nameid = client_nameid( item->nameid );
  1950. p->list[count].type = itemtype( item->nameid );
  1951. p->list[count].price = item->value;
  1952. p->list[count].qty = item->qty;
  1953. p->list[count].weight = id->weight;
  1954. count++;
  1955. }
  1956. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  1957. WFIFOSET( fd, p->packetLength );
  1958. sd->state.trading = 1;
  1959. #endif
  1960. }
  1961. /// Closes the Market shop window.
  1962. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1963. nullpo_retv(sd);
  1964. sd->npc_shopid = 0;
  1965. sd->state.trading = 0;
  1966. }
  1967. /// Purchase item from Market shop.
  1968. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  1969. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1970. #if PACKETVER >= 20131223
  1971. nullpo_retv( sd );
  1972. nullpo_retv( list );
  1973. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  1974. nullpo_retv( nd );
  1975. int fd = sd->fd;
  1976. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + n * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub ) );
  1977. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)WFIFOP( fd, 0 );
  1978. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  1979. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  1980. p->result = ( res == 0 ? 0 : -1 );
  1981. #else
  1982. p->result = ( res == 0 ? 1 : 0 );
  1983. #endif
  1984. int count = 0;
  1985. if( p->result ){
  1986. for( int i = 0, j; i < n; i++ ){
  1987. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  1988. // Not found
  1989. if( j == nd->u.shop.count ){
  1990. continue;
  1991. }
  1992. p->list[count].ITID = client_nameid( list[i].nameid );
  1993. p->list[count].qty = list[i].qty;
  1994. p->list[count].price = nd->u.shop.shop_item[j].value;
  1995. count++;
  1996. }
  1997. }
  1998. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  1999. WFIFOSET( fd, p->PacketLength );
  2000. #endif
  2001. }
  2002. /// Purchase item from Market shop.
  2003. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2004. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  2005. #if PACKETVER >= 20131223
  2006. nullpo_retv( sd );
  2007. if( !sd->npc_shopid ){
  2008. return;
  2009. }
  2010. const struct packet_npc_market_purchase *p = (struct packet_npc_market_purchase *)RFIFOP( fd, 0 );
  2011. int count = ( p->PacketLength - sizeof( struct packet_npc_market_purchase ) ) / sizeof( struct packet_npc_market_purchase_sub );
  2012. struct s_npc_buy_list *list;
  2013. CREATE( list, struct s_npc_buy_list, count );
  2014. // Sadly order is reverse
  2015. for( int i = 0; i < count; i++ ){
  2016. list[i].nameid = p->list[i].ITID;
  2017. list[i].qty = p->list[i].qty;
  2018. }
  2019. uint8 res = npc_buylist( sd, count, list );
  2020. clif_npc_market_purchase_ack( sd, res, count, list );
  2021. aFree( list );
  2022. #endif
  2023. }
  2024. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2025. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2026. /// Client behavior (dialog window):
  2027. /// - disable mouse targeting
  2028. /// - open the dialog window
  2029. /// - set npcid of dialog window (0 by default)
  2030. /// - if set to clear on next mes, clear contents
  2031. /// - append this text
  2032. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  2033. {
  2034. int fd = sd->fd;
  2035. int slen = strlen(mes) + 9;
  2036. WFIFOHEAD(fd, slen);
  2037. WFIFOW(fd,0)=0xb4;
  2038. WFIFOW(fd,2)=slen;
  2039. WFIFOL(fd,4)=npcid;
  2040. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2041. WFIFOSET(fd,WFIFOW(fd,2));
  2042. }
  2043. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2044. /// 00b5 <npc id>.L
  2045. /// Client behavior (dialog window):
  2046. /// - disable mouse targeting
  2047. /// - open the dialog window
  2048. /// - add 'next' button
  2049. /// When 'next' is pressed:
  2050. /// - 00B9 <npcid of dialog window>.L
  2051. /// - set to clear on next mes
  2052. /// - remove 'next' button
  2053. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2054. {
  2055. int fd;
  2056. nullpo_retv(sd);
  2057. fd=sd->fd;
  2058. WFIFOHEAD(fd, packet_len(0xb5));
  2059. WFIFOW(fd,0)=0xb5;
  2060. WFIFOL(fd,2)=npcid;
  2061. WFIFOSET(fd,packet_len(0xb5));
  2062. }
  2063. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2064. /// 00b6 <npc id>.L
  2065. /// Client behavior:
  2066. /// - if dialog window is open:
  2067. /// - remove 'next' button
  2068. /// - add 'close' button
  2069. /// - else:
  2070. /// - enable mouse targeting
  2071. /// - close the dialog window
  2072. /// - close the menu window
  2073. /// When 'close' is pressed:
  2074. /// - enable mouse targeting
  2075. /// - close the dialog window
  2076. /// - close the menu window
  2077. /// - 0146 <npcid of dialog window>.L
  2078. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2079. {
  2080. int fd;
  2081. nullpo_retv(sd);
  2082. fd=sd->fd;
  2083. WFIFOHEAD(fd, packet_len(0xb6));
  2084. WFIFOW(fd,0)=0xb6;
  2085. WFIFOL(fd,2)=npcid;
  2086. WFIFOSET(fd,packet_len(0xb6));
  2087. }
  2088. /**
  2089. * Close script when player is idle
  2090. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2091. * @author [Ind/Hercules]
  2092. * @param sd : player pointer
  2093. * @param npcid : npc gid to close
  2094. */
  2095. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2096. {
  2097. struct s_packet_db* info;
  2098. int16 len;
  2099. int cmd = 0;
  2100. int fd;
  2101. nullpo_retv(sd);
  2102. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2103. if(!cmd) cmd = 0x8d6; //default
  2104. info = &packet_db[cmd];
  2105. len = info->len;
  2106. fd = sd->fd;
  2107. WFIFOHEAD(fd, len);
  2108. WFIFOW(fd,0)=0x8d6;
  2109. WFIFOL(fd,info->pos[0])=npcid;
  2110. WFIFOSET(fd,len);
  2111. }
  2112. /*==========================================
  2113. *
  2114. *------------------------------------------*/
  2115. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2116. unsigned char *buf;
  2117. int fd = sd->fd;
  2118. sd->state.using_fake_npc = 1;
  2119. WFIFOHEAD(fd, packet_len(0x78));
  2120. buf = WFIFOP(fd,0);
  2121. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2122. WBUFW(buf,0)=0x78;
  2123. #if PACKETVER >= 20071106
  2124. WBUFB(buf,2) = 0; // object type
  2125. buf = WFIFOP(fd,1);
  2126. #endif
  2127. WBUFL(buf,2)=npcid;
  2128. WBUFW(buf,14)=111;
  2129. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2130. WBUFB(buf,49)=5;
  2131. WBUFB(buf,50)=5;
  2132. WFIFOSET(fd, packet_len(0x78));
  2133. }
  2134. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2135. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2136. /// Client behavior:
  2137. /// - disable mouse targeting
  2138. /// - close the menu window
  2139. /// - open the menu window
  2140. /// - add options to the menu (separated in the text by ":")
  2141. /// - set npcid of menu window
  2142. /// - if dialog window is open:
  2143. /// - remove 'next' button
  2144. /// When 'ok' is pressed:
  2145. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2146. /// - close the menu window
  2147. /// When 'cancel' is pressed:
  2148. /// - 00B8 <npcid of menu window>.L <-1>.B
  2149. /// - enable mouse targeting
  2150. /// - close a bunch of windows...
  2151. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2152. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2153. /// TODO investigate behavior of other windows [FlavioJS]
  2154. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2155. {
  2156. int fd = sd->fd;
  2157. int slen = strlen(mes) + 9;
  2158. struct block_list *bl = NULL;
  2159. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2160. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2161. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2162. clif_sendfakenpc(sd, npcid);
  2163. WFIFOHEAD(fd, slen);
  2164. WFIFOW(fd,0)=0xb7;
  2165. WFIFOW(fd,2)=slen;
  2166. WFIFOL(fd,4)=npcid;
  2167. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2168. WFIFOSET(fd,WFIFOW(fd,2));
  2169. }
  2170. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2171. /// 0142 <npc id>.L
  2172. /// Client behavior (inputnum window):
  2173. /// - if npcid exists in the client:
  2174. /// - open the inputnum window
  2175. /// - set npcid of inputnum window
  2176. /// When 'ok' is pressed:
  2177. /// - if inputnum window has text:
  2178. /// - if npcid exists in the client:
  2179. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2180. /// - close inputnum window
  2181. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2182. {
  2183. int fd;
  2184. struct block_list *bl = NULL;
  2185. nullpo_retv(sd);
  2186. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2187. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2188. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2189. clif_sendfakenpc(sd, npcid);
  2190. fd=sd->fd;
  2191. WFIFOHEAD(fd, packet_len(0x142));
  2192. WFIFOW(fd,0)=0x142;
  2193. WFIFOL(fd,2)=npcid;
  2194. WFIFOSET(fd,packet_len(0x142));
  2195. }
  2196. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2197. /// 01d4 <npc id>.L
  2198. /// Client behavior (inputstr window):
  2199. /// - if npcid is 0 or npcid exists in the client:
  2200. /// - open the inputstr window
  2201. /// - set npcid of inputstr window
  2202. /// When 'ok' is pressed:
  2203. /// - if inputstr window has text and isn't an insult(manner.txt):
  2204. /// - if npcid is 0 or npcid exists in the client:
  2205. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2206. /// - close inputstr window
  2207. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2208. {
  2209. int fd;
  2210. struct block_list *bl = NULL;
  2211. nullpo_retv(sd);
  2212. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2213. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2214. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2215. clif_sendfakenpc(sd, npcid);
  2216. fd=sd->fd;
  2217. WFIFOHEAD(fd, packet_len(0x1d4));
  2218. WFIFOW(fd,0)=0x1d4;
  2219. WFIFOL(fd,2)=npcid;
  2220. WFIFOSET(fd,packet_len(0x1d4));
  2221. }
  2222. /// Marks a position on client's minimap (ZC_COMPASS).
  2223. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2224. /// npc id:
  2225. /// is ignored in the client
  2226. /// type:
  2227. /// 0 = display mark for 15 seconds
  2228. /// 1 = display mark until dead or teleported
  2229. /// 2 = remove mark
  2230. /// color:
  2231. /// 0x00RRGGBB
  2232. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2233. {
  2234. int fd;
  2235. nullpo_retv(sd);
  2236. fd=sd->fd;
  2237. WFIFOHEAD(fd, packet_len(0x144));
  2238. WFIFOW(fd,0)=0x144;
  2239. WFIFOL(fd,2)=npc_id;
  2240. WFIFOL(fd,6)=type;
  2241. WFIFOL(fd,10)=x;
  2242. WFIFOL(fd,14)=y;
  2243. WFIFOB(fd,18)=id;
  2244. WFIFOL(fd,19)=color;
  2245. WFIFOSET(fd,packet_len(0x144));
  2246. }
  2247. /// Displays an illustration image.
  2248. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2249. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2250. /// type:
  2251. /// 0 = bottom left corner
  2252. /// 1 = bottom middle
  2253. /// 2 = bottom right corner
  2254. /// 3 = middle of screen, inside a movable window
  2255. /// 4 = middle of screen, movable with a close button, chrome-less
  2256. /// 255 = clear all displayed cutins
  2257. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2258. {
  2259. int fd;
  2260. nullpo_retv(sd);
  2261. fd=sd->fd;
  2262. WFIFOHEAD(fd, packet_len(0x1b3));
  2263. WFIFOW(fd,0)=0x1b3;
  2264. strncpy(WFIFOCP(fd,2),image,64);
  2265. WFIFOB(fd,66)=type;
  2266. WFIFOSET(fd,packet_len(0x1b3));
  2267. }
  2268. /*==========================================
  2269. * Fills in card data from the given item and into the buffer. [Skotlex]
  2270. *------------------------------------------*/
  2271. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2272. nullpo_retv( buf );
  2273. // Blank data
  2274. if( item == nullptr ){
  2275. buf->card[0] = 0;
  2276. buf->card[1] = 0;
  2277. buf->card[2] = 0;
  2278. buf->card[3] = 0;
  2279. return;
  2280. }
  2281. // Pet eggs
  2282. if( item->card[0] == CARD0_PET ){
  2283. buf->card[0] = 0;
  2284. buf->card[1] = 0;
  2285. // Pet intimacy
  2286. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2287. buf->card[2] = item->card[3] >> 1;
  2288. // Pet renamed flag
  2289. buf->card[3] = item->card[3] & 1;
  2290. return;
  2291. }
  2292. // Forged/created items
  2293. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2294. buf->card[0] = item->card[0];
  2295. buf->card[1] = item->card[1];
  2296. buf->card[2] = item->card[2];
  2297. buf->card[3] = item->card[3];
  2298. return;
  2299. }
  2300. int i = 0, j;
  2301. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2302. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2303. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2304. }
  2305. // Normal items.
  2306. for( int k = 0; k < 4; k++, i++ ){
  2307. if( item->card[i] > 0 ){
  2308. buf->card[k] = client_nameid( item->card[i] );
  2309. }else{
  2310. buf->card[k] = 0;
  2311. }
  2312. }
  2313. }
  2314. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2315. /// A maximum of 5 random options can be supported.
  2316. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2317. nullpo_retr( 0, it );
  2318. uint8 count = 0;
  2319. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2320. if( it->option[i].id ){
  2321. buf[i].index = it->option[i].id; // OptIndex
  2322. buf[i].value = it->option[i].value; // Value
  2323. buf[i].param = it->option[i].param; // Param1
  2324. count++;
  2325. }else{
  2326. buf[i].index = 0;
  2327. buf[i].value = 0;
  2328. buf[i].param = 0;
  2329. }
  2330. }
  2331. #if MAX_ITEM_RDM_OPT < 5
  2332. for( ; i < 5; i++ ){
  2333. buf[i].index = 0; // OptIndex
  2334. buf[i].value = 0; // Value
  2335. buf[i].param = 0; // Param1
  2336. }
  2337. #endif
  2338. return count;
  2339. }
  2340. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2341. /// 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)
  2342. /// 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)
  2343. /// 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)
  2344. /// 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)
  2345. /// 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)
  2346. /// 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)
  2347. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2348. nullpo_retv( sd );
  2349. int fd = sd->fd;
  2350. if( !session_isActive( fd ) ){
  2351. return;
  2352. }
  2353. struct packet_additem p;
  2354. if( fail ){
  2355. p = {};
  2356. }else{
  2357. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2358. return;
  2359. }
  2360. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2361. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2362. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2363. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2364. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2365. p.location = pc_equippoint(sd,n);
  2366. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2367. #if PACKETVER >= 20061218
  2368. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2369. #if PACKETVER >= 20071002
  2370. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2371. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2372. */
  2373. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2374. #if PACKETVER >= 20150226
  2375. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2376. #if PACKETVER >= 20160921
  2377. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2378. p.look = sd->inventory_data[n]->look;
  2379. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2380. p.enchantgrade = sd->inventory.u.items_inventory[n].enchantgrade;
  2381. #endif
  2382. #endif
  2383. #endif
  2384. #endif
  2385. #endif
  2386. }
  2387. p.PacketType = additemType;
  2388. p.Index = client_index( n );
  2389. p.count = amount;
  2390. p.result = fail;
  2391. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2392. }
  2393. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2394. /// 00af <index>.W <amount>.W
  2395. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2396. {
  2397. int fd;
  2398. nullpo_retv(sd);
  2399. fd=sd->fd;
  2400. WFIFOHEAD(fd, packet_len(0xaf));
  2401. WFIFOW(fd,0)=0xaf;
  2402. WFIFOW(fd,2)=n+2;
  2403. WFIFOW(fd,4)=amount;
  2404. WFIFOSET(fd,packet_len(0xaf));
  2405. }
  2406. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2407. /// 07fa <delete type>.W <index>.W <amount>.W
  2408. /// delete type:
  2409. /// 0 = Normal
  2410. /// 1 = Item used for a skill
  2411. /// 2 = Refine failed
  2412. /// 3 = Material changed
  2413. /// 4 = Moved to storage
  2414. /// 5 = Moved to cart
  2415. /// 6 = Item sold
  2416. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2417. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2418. {
  2419. #if PACKETVER < 20091117
  2420. clif_dropitem(sd,n,amount);
  2421. #else
  2422. int fd;
  2423. nullpo_retv(sd);
  2424. fd=sd->fd;
  2425. WFIFOHEAD(fd, packet_len(0x7fa));
  2426. WFIFOW(fd,0)=0x7fa;
  2427. WFIFOW(fd,2)=reason;
  2428. WFIFOW(fd,4)=n+2;
  2429. WFIFOW(fd,6)=amount;
  2430. WFIFOSET(fd,packet_len(0x7fa));
  2431. #endif
  2432. }
  2433. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2434. nullpo_retv( p );
  2435. nullpo_retv( it );
  2436. nullpo_retv( id );
  2437. p->index = idx;
  2438. p->ITID = client_nameid( it->nameid );
  2439. p->type = itemtype( it->nameid );
  2440. #if PACKETVER < 20120925
  2441. p->IsIdentified = it->identify ? 1 : 0;
  2442. #endif
  2443. p->location = eqp_pos;
  2444. p->WearState = it->equip;
  2445. #if PACKETVER < 20120925
  2446. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2447. #endif
  2448. p->RefiningLevel = it->refine;
  2449. clif_addcards( &p->slot, it );
  2450. #if PACKETVER >= 20071002
  2451. p->HireExpireDate = it->expire_time;
  2452. #endif
  2453. #if PACKETVER >= 20080102
  2454. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2455. #endif
  2456. #if PACKETVER >= 20100629
  2457. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2458. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2459. #endif
  2460. #if PACKETVER >= 20120925
  2461. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2462. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2463. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2464. p->Flag.SpareBits = 0;
  2465. #endif
  2466. #if PACKETVER >= 20150226
  2467. p->option_count = clif_add_random_options( p->option_data, it );
  2468. #endif
  2469. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2470. p->enchantgrade = it->enchantgrade;
  2471. #endif
  2472. }
  2473. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2474. nullpo_retv(p);
  2475. nullpo_retv(i);
  2476. nullpo_retv(id);
  2477. p->index = idx;
  2478. p->ITID = client_nameid( i->nameid );
  2479. p->type = itemtype( i->nameid );
  2480. #if PACKETVER < 20120925
  2481. p->IsIdentified = i->identify ? 1 : 0;
  2482. #endif
  2483. p->count = i->amount;
  2484. p->WearState = id->equip;
  2485. #if PACKETVER >= 5
  2486. clif_addcards( &p->slot, i );
  2487. #endif
  2488. #if PACKETVER >= 20080102
  2489. p->HireExpireDate = i->expire_time;
  2490. #endif
  2491. #if PACKETVER >= 20120925
  2492. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2493. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2494. p->Flag.SpareBits = 0;
  2495. #endif
  2496. }
  2497. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2498. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2499. nullpo_retv(sd);
  2500. nullpo_retv(name);
  2501. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2502. memset(buf, 0, sizeof(buf));
  2503. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2504. p->packetType = HEADER_ZC_INVENTORY_START;
  2505. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2506. p->invType = type;
  2507. #endif
  2508. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2509. int strLen = (int)safestrnlen(name, 24) + 1;
  2510. if (strLen > 24)
  2511. strLen = 24;
  2512. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2513. p->packetLength = len;
  2514. safestrncpy(p->name, name, strLen);
  2515. #else
  2516. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2517. safestrncpy(p->name, name, NAME_LENGTH);
  2518. #endif
  2519. clif_send( p, len, &sd->bl, SELF );
  2520. #endif
  2521. }
  2522. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2523. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2524. nullpo_retv(sd);
  2525. struct PACKET_ZC_INVENTORY_END p;
  2526. p.packetType = HEADER_ZC_INVENTORY_END;
  2527. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2528. p.invType = type;
  2529. #endif
  2530. p.flag = 0;
  2531. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2532. #endif
  2533. }
  2534. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2535. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2536. void clif_inventorylist( struct map_session_data *sd ){
  2537. nullpo_retv( sd );
  2538. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2539. e_inventory_type type = INVTYPE_INVENTORY;
  2540. clif_inventoryStart( sd, type, "" );
  2541. #endif
  2542. static struct packet_itemlist_normal itemlist_normal;
  2543. static struct packet_itemlist_equip itemlist_equip;
  2544. int equip = 0;
  2545. int normal = 0;
  2546. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2547. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2548. continue;
  2549. }
  2550. // Non-stackable (Equippable)
  2551. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2552. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2553. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2554. itemlist_equip.PacketType = inventorylistequipType;
  2555. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2556. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2557. itemlist_equip.invType = type;
  2558. #endif
  2559. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2560. equip = 0;
  2561. }
  2562. // Stackable (Normal)
  2563. }else{
  2564. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2565. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2566. itemlist_normal.PacketType = inventorylistnormalType;
  2567. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2568. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2569. itemlist_normal.invType = type;
  2570. #endif
  2571. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2572. normal = 0;
  2573. }
  2574. }
  2575. }
  2576. if( normal ){
  2577. itemlist_normal.PacketType = inventorylistnormalType;
  2578. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2579. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2580. itemlist_normal.invType = type;
  2581. #endif
  2582. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2583. }
  2584. if( sd->equip_index[EQI_AMMO] >= 0 )
  2585. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2586. if( equip ) {
  2587. itemlist_equip.PacketType = inventorylistequipType;
  2588. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2589. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2590. itemlist_equip.invType = type;
  2591. #endif
  2592. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2593. }
  2594. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2595. clif_inventoryEnd( sd, type );
  2596. #endif
  2597. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2598. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2599. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2600. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2601. continue;
  2602. if ( sd->inventory.u.items_inventory[i].favorite )
  2603. clif_favorite_item(sd, i);
  2604. }
  2605. #endif
  2606. }
  2607. //Required when items break/get-repaired. Only sends equippable item list.
  2608. void clif_equiplist( struct map_session_data *sd ){
  2609. // TODO: implement again => only send equip part
  2610. clif_inventorylist( sd );
  2611. }
  2612. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2613. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2614. e_inventory_type type = INVTYPE_STORAGE;
  2615. clif_inventoryStart( sd, type, storename );
  2616. #endif
  2617. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2618. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2619. int equip = 0;
  2620. int normal = 0;
  2621. for( int i = 0; i < items_length; i++ ){
  2622. if( items[i].nameid == 0 ){
  2623. continue;
  2624. }
  2625. struct item_data* id = itemdb_search( items[i].nameid );
  2626. // Non-stackable (Equippable)
  2627. if( !itemdb_isstackable2( id ) ){
  2628. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2629. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2630. storage_itemlist_equip.PacketType = storageListEquipType;
  2631. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2632. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2633. storage_itemlist_equip.invType = type;
  2634. #elif PACKETVER >= 20120925
  2635. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2636. #endif
  2637. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2638. equip = 0;
  2639. }
  2640. // Stackable (Normal)
  2641. }else{
  2642. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2643. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2644. storage_itemlist_normal.PacketType = storageListNormalType;
  2645. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2646. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2647. storage_itemlist_normal.invType = type;
  2648. #elif PACKETVER >= 20120925
  2649. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2650. #endif
  2651. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2652. normal = 0;
  2653. }
  2654. }
  2655. }
  2656. if( normal ){
  2657. storage_itemlist_normal.PacketType = storageListNormalType;
  2658. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2659. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2660. storage_itemlist_normal.invType = type;
  2661. #elif PACKETVER >= 20120925
  2662. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2663. #endif
  2664. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2665. }
  2666. if( equip ) {
  2667. storage_itemlist_equip.PacketType = storageListEquipType;
  2668. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2669. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2670. storage_itemlist_equip.invType = type;
  2671. #elif PACKETVER >= 20120925
  2672. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2673. #endif
  2674. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2675. }
  2676. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2677. clif_inventoryEnd( sd, type );
  2678. #endif
  2679. }
  2680. void clif_cartlist( struct map_session_data *sd ){
  2681. nullpo_retv( sd );
  2682. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2683. e_inventory_type type = INVTYPE_CART;
  2684. clif_inventoryStart( sd, type, "" );
  2685. #endif
  2686. static struct packet_itemlist_normal itemlist_normal;
  2687. static struct packet_itemlist_equip itemlist_equip;
  2688. int normal = 0;
  2689. int equip = 0;
  2690. for( int i = 0; i < MAX_CART; i++ ){
  2691. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2692. continue;
  2693. }
  2694. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2695. // Non-stackable (Equippable)
  2696. if( !itemdb_isstackable2(id) ){
  2697. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2698. // Stackable (Normal)
  2699. }else{
  2700. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2701. }
  2702. }
  2703. if( normal ){
  2704. itemlist_normal.PacketType = cartlistnormalType;
  2705. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2706. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2707. itemlist_normal.invType = type;
  2708. #endif
  2709. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2710. }
  2711. if( equip ){
  2712. itemlist_equip.PacketType = cartlistequipType;
  2713. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2714. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2715. itemlist_equip.invType = type;
  2716. #endif
  2717. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2718. }
  2719. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2720. clif_inventoryEnd( sd, type );
  2721. #endif
  2722. }
  2723. /// Removes cart (ZC_CARTOFF).
  2724. /// 012b
  2725. /// Client behaviour:
  2726. /// Closes the cart storage and removes all it's items from memory.
  2727. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2728. void clif_clearcart(int fd)
  2729. {
  2730. WFIFOHEAD(fd, packet_len(0x12b));
  2731. WFIFOW(fd,0) = 0x12b;
  2732. WFIFOSET(fd, packet_len(0x12b));
  2733. }
  2734. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2735. /// 01eb <account id>.L <x>.W <y>.W
  2736. void clif_guild_xy(struct map_session_data *sd)
  2737. {
  2738. unsigned char buf[10];
  2739. nullpo_retv(sd);
  2740. WBUFW(buf,0)=0x1eb;
  2741. WBUFL(buf,2)=sd->status.account_id;
  2742. WBUFW(buf,6)=sd->bl.x;
  2743. WBUFW(buf,8)=sd->bl.y;
  2744. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2745. }
  2746. /*==========================================
  2747. * Sends x/y dot to a single fd. [Skotlex]
  2748. *------------------------------------------*/
  2749. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2750. {
  2751. if( sd->bg_id )
  2752. return;
  2753. WFIFOHEAD(fd,packet_len(0x1eb));
  2754. WFIFOW(fd,0)=0x1eb;
  2755. WFIFOL(fd,2)=sd->status.account_id;
  2756. WFIFOW(fd,6)=sd->bl.x;
  2757. WFIFOW(fd,8)=sd->bl.y;
  2758. WFIFOSET(fd,packet_len(0x1eb));
  2759. }
  2760. // Guild XY locators [Valaris]
  2761. void clif_guild_xy_remove(struct map_session_data *sd)
  2762. {
  2763. unsigned char buf[10];
  2764. nullpo_retv(sd);
  2765. WBUFW(buf,0)=0x1eb;
  2766. WBUFL(buf,2)=sd->status.account_id;
  2767. WBUFW(buf,6)=-1;
  2768. WBUFW(buf,8)=-1;
  2769. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2770. }
  2771. /*==========================================
  2772. *
  2773. *------------------------------------------*/
  2774. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2775. {
  2776. struct map_session_data *sd, *tsd;
  2777. #if PACKETVER < 20100126
  2778. const int cmd = 0x106;
  2779. #else
  2780. const int cmd = 0x80e;
  2781. #endif
  2782. sd = va_arg(ap, struct map_session_data *);
  2783. tsd = (TBL_PC *)bl;
  2784. nullpo_ret(sd);
  2785. nullpo_ret(tsd);
  2786. if( !session_isActive(tsd->fd) || tsd == sd )
  2787. return 0;
  2788. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2789. return 0;
  2790. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2791. WFIFOW(tsd->fd,0) = cmd;
  2792. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2793. #if PACKETVER < 20100126
  2794. if( sd->battle_status.max_hp > INT16_MAX )
  2795. { //To correctly display the %hp bar. [Skotlex]
  2796. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2797. WFIFOW(tsd->fd,8) = 100;
  2798. } else {
  2799. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2800. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2801. }
  2802. #else
  2803. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2804. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2805. #endif
  2806. WFIFOSET(tsd->fd,packet_len(cmd));
  2807. return 0;
  2808. }
  2809. /*==========================================
  2810. * Server tells all players that are allowed to view HP bars
  2811. * and are nearby 'sd' that 'sd' hp bar was updated.
  2812. *------------------------------------------*/
  2813. static int clif_hpmeter(struct map_session_data *sd)
  2814. {
  2815. nullpo_ret(sd);
  2816. 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);
  2817. return 0;
  2818. }
  2819. /// Notifies client of a character parameter change.
  2820. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2821. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2822. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2823. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2824. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2825. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2826. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2827. /// TODO: Extract individual packets.
  2828. /// FIXME: Packet lengths from packet_len(cmd)
  2829. void clif_updatestatus(struct map_session_data *sd,int type)
  2830. {
  2831. int fd,len=8;
  2832. nullpo_retv(sd);
  2833. fd=sd->fd;
  2834. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2835. return;
  2836. WFIFOHEAD(fd, 14);
  2837. WFIFOW(fd,0)=0xb0;
  2838. WFIFOW(fd,2)=type;
  2839. switch(type){
  2840. // 00b0
  2841. case SP_WEIGHT:
  2842. pc_updateweightstatus(sd);
  2843. WFIFOHEAD(fd,14);
  2844. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2845. WFIFOW(fd,2)=type;
  2846. WFIFOL(fd,4)=sd->weight;
  2847. break;
  2848. case SP_MAXWEIGHT:
  2849. WFIFOL(fd,4)=sd->max_weight;
  2850. break;
  2851. case SP_SPEED:
  2852. WFIFOL(fd,4)=sd->battle_status.speed;
  2853. break;
  2854. case SP_BASELEVEL:
  2855. WFIFOL(fd,4)=sd->status.base_level;
  2856. break;
  2857. case SP_JOBLEVEL:
  2858. WFIFOL(fd,4)=sd->status.job_level;
  2859. break;
  2860. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2861. WFIFOL(fd,4)=sd->status.karma;
  2862. break;
  2863. case SP_MANNER:
  2864. WFIFOL(fd,4)=sd->status.manner;
  2865. break;
  2866. case SP_STATUSPOINT:
  2867. WFIFOL(fd,4)=sd->status.status_point;
  2868. break;
  2869. case SP_SKILLPOINT:
  2870. WFIFOL(fd,4)=sd->status.skill_point;
  2871. break;
  2872. case SP_HIT:
  2873. WFIFOL(fd,4)=sd->battle_status.hit;
  2874. break;
  2875. case SP_FLEE1:
  2876. WFIFOL(fd,4)=sd->battle_status.flee;
  2877. break;
  2878. case SP_FLEE2:
  2879. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2880. break;
  2881. case SP_MAXHP:
  2882. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2883. break;
  2884. case SP_MAXSP:
  2885. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2886. break;
  2887. case SP_HP:
  2888. // On officials the HP never go below 1, even if you die [Lemongrass]
  2889. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2890. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2891. break;
  2892. case SP_SP:
  2893. WFIFOL(fd,4)=sd->battle_status.sp;
  2894. break;
  2895. case SP_ASPD:
  2896. WFIFOL(fd,4)=sd->battle_status.amotion;
  2897. break;
  2898. case SP_ATK1:
  2899. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2900. break;
  2901. case SP_DEF1:
  2902. WFIFOL(fd,4)=pc_leftside_def(sd);
  2903. break;
  2904. case SP_MDEF1:
  2905. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2906. break;
  2907. case SP_ATK2:
  2908. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2909. break;
  2910. case SP_DEF2:
  2911. WFIFOL(fd,4)=pc_rightside_def(sd);
  2912. break;
  2913. case SP_MDEF2: {
  2914. //negative check (in case you have something like Berserk active)
  2915. int mdef2 = pc_rightside_mdef(sd);
  2916. WFIFOL(fd,4)=
  2917. #ifndef RENEWAL
  2918. ( mdef2 < 0 ) ? 0 :
  2919. #endif
  2920. mdef2;
  2921. }
  2922. break;
  2923. case SP_CRITICAL:
  2924. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2925. break;
  2926. case SP_MATK1:
  2927. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2928. break;
  2929. case SP_MATK2:
  2930. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2931. break;
  2932. case SP_ZENY:
  2933. WFIFOW(fd,0)=0xb1;
  2934. WFIFOL(fd,4)=sd->status.zeny;
  2935. break;
  2936. #if PACKETVER >= 20170830
  2937. case SP_BASEEXP:
  2938. WFIFOW(fd,0)=0xacb;
  2939. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2940. len = packet_len(0xacb);
  2941. break;
  2942. case SP_JOBEXP:
  2943. WFIFOW(fd,0)=0xacb;
  2944. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2945. len = packet_len(0xacb);
  2946. break;
  2947. case SP_NEXTBASEEXP:
  2948. WFIFOW(fd,0)=0xacb;
  2949. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  2950. len = packet_len(0xacb);
  2951. break;
  2952. case SP_NEXTJOBEXP:
  2953. WFIFOW(fd,0)=0xacb;
  2954. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  2955. len = packet_len(0xacb);
  2956. break;
  2957. #else
  2958. case SP_BASEEXP:
  2959. WFIFOW(fd,0)=0xb1;
  2960. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  2961. break;
  2962. case SP_JOBEXP:
  2963. WFIFOW(fd,0)=0xb1;
  2964. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  2965. break;
  2966. case SP_NEXTBASEEXP:
  2967. WFIFOW(fd,0)=0xb1;
  2968. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  2969. break;
  2970. case SP_NEXTJOBEXP:
  2971. WFIFOW(fd,0)=0xb1;
  2972. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  2973. break;
  2974. #endif
  2975. /**
  2976. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2977. **/
  2978. case SP_USTR:
  2979. case SP_UAGI:
  2980. case SP_UVIT:
  2981. case SP_UINT:
  2982. case SP_UDEX:
  2983. case SP_ULUK:
  2984. WFIFOW(fd,0)=0xbe;
  2985. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2986. len=5;
  2987. break;
  2988. /**
  2989. * Tells the client how far it is allowed to attack (weapon range)
  2990. **/
  2991. case SP_ATTACKRANGE:
  2992. WFIFOW(fd,0)=0x13a;
  2993. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2994. len=4;
  2995. break;
  2996. case SP_STR:
  2997. WFIFOW(fd,0)=0x141;
  2998. WFIFOL(fd,2)=type;
  2999. WFIFOL(fd,6)=sd->status.str;
  3000. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3001. len=14;
  3002. break;
  3003. case SP_AGI:
  3004. WFIFOW(fd,0)=0x141;
  3005. WFIFOL(fd,2)=type;
  3006. WFIFOL(fd,6)=sd->status.agi;
  3007. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3008. len=14;
  3009. break;
  3010. case SP_VIT:
  3011. WFIFOW(fd,0)=0x141;
  3012. WFIFOL(fd,2)=type;
  3013. WFIFOL(fd,6)=sd->status.vit;
  3014. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3015. len=14;
  3016. break;
  3017. case SP_INT:
  3018. WFIFOW(fd,0)=0x141;
  3019. WFIFOL(fd,2)=type;
  3020. WFIFOL(fd,6)=sd->status.int_;
  3021. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3022. len=14;
  3023. break;
  3024. case SP_DEX:
  3025. WFIFOW(fd,0)=0x141;
  3026. WFIFOL(fd,2)=type;
  3027. WFIFOL(fd,6)=sd->status.dex;
  3028. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3029. len=14;
  3030. break;
  3031. case SP_LUK:
  3032. WFIFOW(fd,0)=0x141;
  3033. WFIFOL(fd,2)=type;
  3034. WFIFOL(fd,6)=sd->status.luk;
  3035. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3036. len=14;
  3037. break;
  3038. case SP_CARTINFO:
  3039. WFIFOW(fd,0)=0x121;
  3040. WFIFOW(fd,2)=sd->cart_num;
  3041. WFIFOW(fd,4)=MAX_CART;
  3042. WFIFOL(fd,6)=sd->cart_weight;
  3043. WFIFOL(fd,10)=sd->cart_weight_max;
  3044. len=14;
  3045. break;
  3046. default:
  3047. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3048. return;
  3049. }
  3050. WFIFOSET(fd,len);
  3051. // Additional update packets that should be sent right after
  3052. switch( type ){
  3053. case SP_BASELEVEL:
  3054. if( sd->status.party_id ){
  3055. struct party_data* p;
  3056. int i;
  3057. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3058. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3059. if( i < MAX_PARTY ){
  3060. p->party.member[i].lv = sd->status.base_level;
  3061. clif_party_job_and_level(sd);
  3062. }
  3063. }
  3064. }
  3065. break;
  3066. case SP_HP:
  3067. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3068. clif_hpmeter(sd);
  3069. }
  3070. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3071. clif_party_hp(sd);
  3072. }
  3073. if( sd->bg_id ){
  3074. clif_bg_hp(sd);
  3075. }
  3076. break;
  3077. }
  3078. }
  3079. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3080. /// 01ab <account id>.L <var id>.W <value>.L
  3081. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3082. {
  3083. unsigned char buf[12];
  3084. nullpo_retv(sd);
  3085. WBUFW(buf,0)=0x1ab;
  3086. WBUFL(buf,2)=sd->bl.id;
  3087. WBUFW(buf,6)=type;
  3088. switch(type)
  3089. {
  3090. case SP_MANNER:
  3091. WBUFL(buf,8)=val;
  3092. break;
  3093. default:
  3094. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3095. return;
  3096. }
  3097. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3098. }
  3099. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3100. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3101. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3102. struct PACKET_ZC_SPRITE_CHANGE p;
  3103. p.packetType = sendLookType;
  3104. p.AID = id;
  3105. p.type = type;
  3106. p.val = val;
  3107. #if PACKETVER >= 4
  3108. p.val2 = val2;
  3109. #endif
  3110. clif_send( &p, sizeof( p ), bl, target );
  3111. }
  3112. /// Updates sprite/style properties of an object.
  3113. void clif_changelook(struct block_list *bl, int type, int val) {
  3114. struct map_session_data* sd;
  3115. struct status_change* sc;
  3116. struct view_data* vd;
  3117. enum send_target target = AREA;
  3118. int val2 = 0;
  3119. nullpo_retv(bl);
  3120. sd = BL_CAST(BL_PC, bl);
  3121. sc = status_get_sc(bl);
  3122. vd = status_get_viewdata(bl);
  3123. if( vd ) //temp hack to let Warp Portal change appearance
  3124. switch(type) {
  3125. case LOOK_WEAPON:
  3126. if (sd) {
  3127. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3128. val = vd->weapon;
  3129. }
  3130. else
  3131. vd->weapon = val;
  3132. break;
  3133. case LOOK_SHIELD:
  3134. if (sd) {
  3135. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3136. val = vd->shield;
  3137. }
  3138. else
  3139. vd->shield = val;
  3140. break;
  3141. case LOOK_BASE:
  3142. if (!sd)
  3143. break;
  3144. if ( val == JT_INVISIBLE )
  3145. return;
  3146. if (sd->sc.option&OPTION_COSTUME)
  3147. vd->weapon = vd->shield = 0;
  3148. if (!vd->cloth_color)
  3149. break;
  3150. if (sd) {
  3151. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3152. vd->cloth_color = 0;
  3153. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3154. vd->cloth_color = 0;
  3155. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3156. vd->cloth_color = 0;
  3157. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3158. vd->cloth_color = 0;
  3159. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3160. vd->cloth_color = 0;
  3161. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3162. vd->body_style = 0;
  3163. }
  3164. break;
  3165. case LOOK_HAIR:
  3166. vd->hair_style = val;
  3167. break;
  3168. case LOOK_HEAD_BOTTOM:
  3169. vd->head_bottom = val;
  3170. break;
  3171. case LOOK_HEAD_TOP:
  3172. vd->head_top = val;
  3173. break;
  3174. case LOOK_HEAD_MID:
  3175. vd->head_mid = val;
  3176. break;
  3177. case LOOK_HAIR_COLOR:
  3178. vd->hair_color = val;
  3179. break;
  3180. case LOOK_CLOTHES_COLOR:
  3181. if (val && sd) {
  3182. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3183. val = 0;
  3184. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3185. val = 0;
  3186. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3187. val = 0;
  3188. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3189. val = 0;
  3190. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3191. val = 0;
  3192. }
  3193. vd->cloth_color = val;
  3194. break;
  3195. case LOOK_SHOES:
  3196. #if PACKETVER > 3
  3197. if (sd) {
  3198. int n;
  3199. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3200. if(sd->inventory_data[n]->view_id > 0)
  3201. val = sd->inventory_data[n]->view_id;
  3202. else
  3203. val = sd->inventory.u.items_inventory[n].nameid;
  3204. } else
  3205. val = 0;
  3206. }
  3207. #endif
  3208. //Shoes? No packet uses this....
  3209. break;
  3210. case LOOK_BODY:
  3211. // unknown purpose
  3212. break;
  3213. case LOOK_ROBE:
  3214. #if PACKETVER < 20110111
  3215. return;
  3216. #else
  3217. vd->robe = val;
  3218. #endif
  3219. break;
  3220. case LOOK_BODY2:
  3221. #if PACKETVER < 20150513
  3222. return;
  3223. #else
  3224. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3225. val = 0;
  3226. vd->body_style = val;
  3227. #endif
  3228. break;
  3229. }
  3230. // prevent leaking the presence of GM-hidden objects
  3231. if( sc && sc->option&OPTION_INVISIBLE )
  3232. target = SELF;
  3233. #if PACKETVER < 4
  3234. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3235. #else
  3236. if (bl->type != BL_NPC) {
  3237. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3238. type = LOOK_WEAPON;
  3239. val = (vd ? vd->weapon : 0);
  3240. val2 = (vd ? vd->shield : 0);
  3241. }
  3242. if (disguised(bl)) {
  3243. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3244. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3245. } else
  3246. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3247. } else
  3248. unit_refresh(bl);
  3249. #endif
  3250. }
  3251. //Sends a change-base-look packet required for traps as they are triggered.
  3252. void clif_changetraplook(struct block_list *bl,int val) {
  3253. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3254. }
  3255. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3256. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3257. clif_sprite_change(bl, id, type, val, 0, target);
  3258. }
  3259. /// Character status (ZC_STATUS).
  3260. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3261. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3262. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3263. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3264. void clif_initialstatus(struct map_session_data *sd) {
  3265. int fd, mdef2;
  3266. unsigned char *buf;
  3267. nullpo_retv(sd);
  3268. fd=sd->fd;
  3269. WFIFOHEAD(fd, packet_len(0xbd));
  3270. buf = WFIFOP(fd,0);
  3271. WBUFW(buf,0) = 0xbd;
  3272. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3273. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3274. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3275. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3276. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3277. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3278. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3279. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3280. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3281. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3282. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3283. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3284. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3285. WBUFW(buf,16) = pc_leftside_atk(sd);
  3286. WBUFW(buf,18) = pc_rightside_atk(sd);
  3287. WBUFW(buf,20) = pc_rightside_matk(sd);
  3288. WBUFW(buf,22) = pc_leftside_matk(sd);
  3289. WBUFW(buf,24) = pc_leftside_def(sd);
  3290. WBUFW(buf,26) = pc_rightside_def(sd);
  3291. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3292. mdef2 = pc_rightside_mdef(sd);
  3293. WBUFW(buf,30) =
  3294. #ifndef RENEWAL
  3295. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3296. #endif
  3297. mdef2;
  3298. WBUFW(buf,32) = sd->battle_status.hit;
  3299. WBUFW(buf,34) = sd->battle_status.flee;
  3300. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3301. WBUFW(buf,38) = sd->battle_status.cri/10;
  3302. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3303. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3304. WFIFOSET(fd, packet_len(0xbd));
  3305. clif_updatestatus(sd, SP_STR);
  3306. clif_updatestatus(sd, SP_AGI);
  3307. clif_updatestatus(sd, SP_VIT);
  3308. clif_updatestatus(sd, SP_INT);
  3309. clif_updatestatus(sd, SP_DEX);
  3310. clif_updatestatus(sd, SP_LUK);
  3311. clif_updatestatus(sd, SP_ATTACKRANGE);
  3312. clif_updatestatus(sd, SP_ASPD);
  3313. }
  3314. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3315. /// 013c <index>.W
  3316. void clif_arrowequip(struct map_session_data *sd,int val) {
  3317. int fd;
  3318. nullpo_retv(sd);
  3319. #if PACKETVER >= 20121128
  3320. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3321. #endif
  3322. fd=sd->fd;
  3323. WFIFOHEAD(fd, packet_len(0x013c));
  3324. WFIFOW(fd,0) = 0x013c;
  3325. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3326. WFIFOSET(fd, packet_len(0x013c));
  3327. }
  3328. /// Ammunition action message (ZC_ACTION_FAILURE).
  3329. /// 013b <type>.W
  3330. /// type:
  3331. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3332. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3333. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3334. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3335. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3336. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3337. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3338. int fd;
  3339. nullpo_retv(sd);
  3340. fd=sd->fd;
  3341. WFIFOHEAD(fd, packet_len(0x013b));
  3342. WFIFOW(fd,0) = 0x013b;
  3343. WFIFOW(fd,2) = type;
  3344. WFIFOSET(fd, packet_len(0x013b));
  3345. }
  3346. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3347. /// 01ad <packet len>.W { <name id>.W }*
  3348. void clif_arrow_create_list( struct map_session_data *sd ){
  3349. nullpo_retv( sd );
  3350. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3351. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3352. int count = 0;
  3353. for (const auto &it : skill_arrow_db) {
  3354. t_itemid nameid = it.second->nameid;
  3355. if( !item_db.exists( nameid ) ){
  3356. continue;
  3357. }
  3358. int index = pc_search_inventory( sd, nameid );
  3359. if( index < 0 ){
  3360. continue;
  3361. }
  3362. if( sd->inventory.u.items_inventory[index].equip ){
  3363. continue;
  3364. }
  3365. if( !sd->inventory.u.items_inventory[index].identify ){
  3366. continue;
  3367. }
  3368. p->items[count].itemId = client_nameid( nameid );
  3369. count++;
  3370. }
  3371. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3372. clif_send( p, p->packetLength, &sd->bl, SELF );
  3373. if( count > 0 ){
  3374. sd->menuskill_id = AC_MAKINGARROW;
  3375. sd->menuskill_val = count;
  3376. }
  3377. }
  3378. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3379. /// 00bc <status id>.W <result>.B <value>.B
  3380. /// status id:
  3381. /// SP_STR ~ SP_LUK
  3382. /// result:
  3383. /// 0 = failure
  3384. /// 1 = success
  3385. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3386. int fd;
  3387. nullpo_retv(sd);
  3388. fd=sd->fd;
  3389. WFIFOHEAD(fd, packet_len(0xbc));
  3390. WFIFOW(fd,0) = 0xbc;
  3391. WFIFOW(fd,2) = type;
  3392. WFIFOB(fd,4) = ok;
  3393. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3394. WFIFOSET(fd, packet_len(0xbc));
  3395. }
  3396. /// Notifies the client about the result of a request to equip an item.
  3397. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3398. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3399. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3400. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3401. /// @ok: //inversed forv2 v5
  3402. /// 0 = failure
  3403. /// 1 = success
  3404. /// 2 = failure due to low level
  3405. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3406. {
  3407. int fd = 0, cmd = 0, look = 0;
  3408. struct s_packet_db *info = NULL;
  3409. nullpo_retv(sd);
  3410. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3411. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3412. return;
  3413. fd = sd->fd;
  3414. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3415. look = sd->inventory_data[n]->look;
  3416. WFIFOHEAD(fd, info->len);
  3417. WFIFOW(fd, 0) = cmd;
  3418. WFIFOW(fd, info->pos[0]) = n+2;
  3419. switch (cmd) {
  3420. case 0xaa:
  3421. WFIFOW(fd, info->pos[1]) = pos;
  3422. #if PACKETVER < 20100629
  3423. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3424. #else
  3425. WFIFOL(fd, info->pos[2]) = look;
  3426. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3427. #endif
  3428. break;
  3429. case 0x8d0:
  3430. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3431. flag = 1;
  3432. case 0x999:
  3433. if (cmd == 0x999)
  3434. WFIFOL(fd, info->pos[1]) = pos;
  3435. else
  3436. WFIFOW(fd, info->pos[1]) = pos;
  3437. WFIFOL(fd, info->pos[2]) = look;
  3438. WFIFOW(fd, info->pos[3]) = flag;
  3439. break;
  3440. }
  3441. WFIFOSET(fd, info->len);
  3442. }
  3443. /// Notifies the client about the result of a request to take off an item.
  3444. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3445. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3446. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3447. /// @ok : //inversed for v2 v5
  3448. /// 0 = failure
  3449. /// 1 = success
  3450. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3451. {
  3452. int fd, header, offs = 0;
  3453. #if PACKETVER >= 20130000
  3454. header = 0x99a;
  3455. ok = ok ? 0 : 1;
  3456. #elif PACKETVER >= 20110824
  3457. header = 0x8d1;
  3458. ok = ok ? 0 : 1;
  3459. #else
  3460. header = 0xac;
  3461. #endif
  3462. nullpo_retv(sd);
  3463. fd=sd->fd;
  3464. WFIFOHEAD(fd, packet_len(header));
  3465. WFIFOW(fd,offs+0) = header;
  3466. WFIFOW(fd,offs+2) = n+2;
  3467. #if PACKETVER >= 20130000
  3468. WFIFOL(fd,offs+4) = pos;
  3469. offs += 2;
  3470. #else
  3471. WFIFOW(fd,offs+4) = pos;
  3472. #endif
  3473. WFIFOB(fd,offs+6) = ok;
  3474. WFIFOSET(fd, packet_len(header));
  3475. }
  3476. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3477. /// 019b <id>.L <effect id>.L
  3478. /// effect id:
  3479. /// 0 = base level up
  3480. /// 1 = job level up
  3481. /// 2 = refine failure
  3482. /// 3 = refine success
  3483. /// 4 = game over
  3484. /// 5 = pharmacy success
  3485. /// 6 = pharmacy failure
  3486. /// 7 = base level up (super novice)
  3487. /// 8 = job level up (super novice)
  3488. /// 9 = base level up (taekwon)
  3489. void clif_misceffect(struct block_list* bl,int type)
  3490. {
  3491. unsigned char buf[32];
  3492. nullpo_retv(bl);
  3493. WBUFW(buf,0) = 0x19b;
  3494. WBUFL(buf,2) = bl->id;
  3495. WBUFL(buf,6) = type;
  3496. clif_send(buf,packet_len(0x19b),bl,AREA);
  3497. }
  3498. /// Notifies clients in the area of a state change.
  3499. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3500. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3501. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3502. nullpo_retv( bl );
  3503. struct status_change* sc = status_get_sc( bl );
  3504. //How can an option change if there's no sc?
  3505. if( sc == nullptr ){
  3506. return;
  3507. }
  3508. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3509. struct PACKET_ZC_STATE_CHANGE p;
  3510. p.packetType = HEADER_ZC_STATE_CHANGE;
  3511. p.AID = bl->id;
  3512. p.bodyState = sc->opt1;
  3513. p.healthState = sc->opt2;
  3514. p.effectState = sc->option;
  3515. p.isPKModeON = sd ? sd->status.karma : false;
  3516. if( target == nullptr ){
  3517. if( disguised( bl ) ){
  3518. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3519. p.AID = disguised_bl_id( p.AID );
  3520. clif_send( &p, sizeof( p ), bl, SELF );
  3521. p.AID = disguised_bl_id( p.AID );
  3522. p.effectState = OPTION_INVISIBLE;
  3523. clif_send( &p, sizeof( p ), bl, SELF );
  3524. }else{
  3525. clif_send( &p, sizeof( p ), bl, AREA );
  3526. }
  3527. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3528. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3529. if( sc->data[SC_PROVOKE] ){
  3530. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3531. clif_status_change( bl, StatusIconChangeTable[SC_PROVOKE], 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3532. }
  3533. }else{
  3534. if( disguised( bl ) ){
  3535. p.AID = disguised_bl_id( p.AID );
  3536. clif_send( &p, sizeof( p ), target, SELF );
  3537. p.AID = disguised_bl_id( p.AID );
  3538. p.effectState = OPTION_INVISIBLE;
  3539. clif_send( &p, sizeof( p ), target, SELF );
  3540. }else{
  3541. clif_send( &p, sizeof( p ), target, SELF );
  3542. }
  3543. }
  3544. }
  3545. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3546. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3547. void clif_changeoption2(struct block_list* bl)
  3548. {
  3549. unsigned char buf[20];
  3550. struct status_change *sc;
  3551. sc = status_get_sc(bl);
  3552. if (!sc) return; //How can an option change if there's no sc?
  3553. WBUFW(buf,0) = 0x28a;
  3554. WBUFL(buf,2) = bl->id;
  3555. WBUFL(buf,6) = sc->option;
  3556. WBUFL(buf,10) = clif_setlevel(bl);
  3557. WBUFL(buf,14) = sc->opt3;
  3558. if(disguised(bl)) {
  3559. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3560. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3561. clif_send(buf,packet_len(0x28a),bl,SELF);
  3562. WBUFL(buf,2) = bl->id;
  3563. WBUFL(buf,6) = OPTION_INVISIBLE;
  3564. clif_send(buf,packet_len(0x28a),bl,SELF);
  3565. } else
  3566. clif_send(buf,packet_len(0x28a),bl,AREA);
  3567. }
  3568. /// Notifies the client about the result of an item use request.
  3569. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3570. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3571. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3572. nullpo_retv( sd );
  3573. int fd = sd->fd;
  3574. if( !session_isActive( fd ) ){
  3575. return;
  3576. }
  3577. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3578. return;
  3579. }
  3580. struct PACKET_ZC_USE_ITEM_ACK p;
  3581. p.packetType = useItemAckType;
  3582. p.index = index + 2;
  3583. #if PACKETVER > 3
  3584. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3585. p.AID = sd->bl.id;
  3586. #endif
  3587. p.amount = amount;
  3588. p.result = ok;
  3589. if( !ok ){
  3590. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3591. }else{
  3592. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3593. }
  3594. }
  3595. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3596. /// 00d6 <flag>.B
  3597. /// flag:
  3598. /// 0 = Room has been successfully created (opens chat room)
  3599. /// 1 = Room limit exceeded
  3600. /// 2 = Same room already exists
  3601. void clif_createchat(struct map_session_data* sd, int flag)
  3602. {
  3603. int fd;
  3604. nullpo_retv(sd);
  3605. fd = sd->fd;
  3606. WFIFOHEAD(fd,packet_len(0xd6));
  3607. WFIFOW(fd,0) = 0xd6;
  3608. WFIFOB(fd,2) = flag;
  3609. WFIFOSET(fd,packet_len(0xd6));
  3610. }
  3611. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3612. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3613. /// type:
  3614. /// 0 = private (password protected)
  3615. /// 1 = public
  3616. /// 2 = arena (npc waiting room)
  3617. /// 3 = PK zone (non-clickable)
  3618. void clif_dispchat(struct chat_data* cd, int fd)
  3619. {
  3620. unsigned char buf[128];
  3621. uint8 type;
  3622. if( cd == NULL || cd->owner == NULL )
  3623. return;
  3624. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3625. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3626. : 1;
  3627. WBUFW(buf, 0) = 0xd7;
  3628. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3629. WBUFL(buf, 4) = cd->owner->id;
  3630. WBUFL(buf, 8) = cd->bl.id;
  3631. WBUFW(buf,12) = cd->limit;
  3632. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3633. WBUFB(buf,16) = type;
  3634. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3635. if( session_isActive(fd) ) {
  3636. WFIFOHEAD(fd,WBUFW(buf,2));
  3637. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3638. WFIFOSET(fd,WBUFW(buf,2));
  3639. } else {
  3640. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3641. }
  3642. }
  3643. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3644. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3645. /// type:
  3646. /// 0 = private (password protected)
  3647. /// 1 = public
  3648. /// 2 = arena (npc waiting room)
  3649. /// 3 = PK zone (non-clickable)
  3650. void clif_changechatstatus(struct chat_data* cd)
  3651. {
  3652. unsigned char buf[128];
  3653. uint8 type;
  3654. if( cd == NULL || cd->usersd[0] == NULL )
  3655. return;
  3656. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3657. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3658. : 1;
  3659. WBUFW(buf, 0) = 0xdf;
  3660. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3661. WBUFL(buf, 4) = cd->owner->id;
  3662. WBUFL(buf, 8) = cd->bl.id;
  3663. WBUFW(buf,12) = cd->limit;
  3664. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3665. WBUFB(buf,16) = type;
  3666. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3667. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3668. }
  3669. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3670. /// 00d8 <chat id>.L
  3671. void clif_clearchat(struct chat_data *cd,int fd)
  3672. {
  3673. unsigned char buf[32];
  3674. nullpo_retv(cd);
  3675. WBUFW(buf,0) = 0xd8;
  3676. WBUFL(buf,2) = cd->bl.id;
  3677. if( session_isActive(fd) ) {
  3678. WFIFOHEAD(fd,packet_len(0xd8));
  3679. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3680. WFIFOSET(fd,packet_len(0xd8));
  3681. } else {
  3682. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3683. }
  3684. }
  3685. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3686. /// 00da <result>.B
  3687. /// result:
  3688. /// 0 = room full
  3689. /// 1 = wrong password
  3690. /// 2 = kicked
  3691. /// 3 = success (no message)
  3692. /// 4 = no enough zeny
  3693. /// 5 = too low level
  3694. /// 6 = too high level
  3695. /// 7 = unsuitable job class
  3696. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3697. {
  3698. int fd;
  3699. nullpo_retv(sd);
  3700. fd = sd->fd;
  3701. WFIFOHEAD(fd,packet_len(0xda));
  3702. WFIFOW(fd,0) = 0xda;
  3703. WFIFOB(fd,2) = flag;
  3704. WFIFOSET(fd,packet_len(0xda));
  3705. }
  3706. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3707. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3708. /// role:
  3709. /// 0 = owner (menu)
  3710. /// 1 = normal
  3711. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3712. {
  3713. int fd;
  3714. int i,t;
  3715. nullpo_retv(sd);
  3716. nullpo_retv(cd);
  3717. fd = sd->fd;
  3718. if (!session_isActive(fd))
  3719. return;
  3720. t = (int)(cd->owner->type == BL_NPC);
  3721. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3722. WFIFOW(fd, 0) = 0xdb;
  3723. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3724. WFIFOL(fd, 4) = cd->bl.id;
  3725. if(cd->owner->type == BL_NPC){
  3726. WFIFOL(fd, 30) = 1;
  3727. WFIFOL(fd, 8) = 0;
  3728. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3729. for (i = 0; i < cd->users; i++) {
  3730. WFIFOL(fd, 8+(i+1)*28) = 1;
  3731. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3732. }
  3733. }else{
  3734. for (i = 0; i < cd->users; i++) {
  3735. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3736. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3737. }
  3738. }
  3739. WFIFOSET(fd, WFIFOW(fd, 2));
  3740. }
  3741. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3742. /// 00dc <users>.W <name>.24B
  3743. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3744. {
  3745. unsigned char buf[29];
  3746. nullpo_retv(sd);
  3747. nullpo_retv(cd);
  3748. WBUFW(buf, 0) = 0xdc;
  3749. WBUFW(buf, 2) = cd->users;
  3750. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3751. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3752. }
  3753. /// Announce the new owner (ZC_ROLE_CHANGE).
  3754. /// 00e1 <role>.L <nick>.24B
  3755. /// role:
  3756. /// 0 = owner (menu)
  3757. /// 1 = normal
  3758. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3759. {
  3760. unsigned char buf[64];
  3761. nullpo_retv(sd);
  3762. nullpo_retv(cd);
  3763. WBUFW(buf, 0) = 0xe1;
  3764. WBUFL(buf, 2) = 1;
  3765. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3766. WBUFW(buf,30) = 0xe1;
  3767. WBUFL(buf,32) = 0;
  3768. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3769. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3770. }
  3771. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3772. /// 00dd <users>.W <nick>.24B <flag>.B
  3773. /// flag:
  3774. /// 0 = left
  3775. /// 1 = kicked
  3776. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3777. {
  3778. unsigned char buf[32];
  3779. nullpo_retv(sd);
  3780. nullpo_retv(cd);
  3781. WBUFW(buf, 0) = 0xdd;
  3782. WBUFW(buf, 2) = cd->users-1;
  3783. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3784. WBUFB(buf,28) = flag;
  3785. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3786. }
  3787. /// Opens a trade request window from char 'name'.
  3788. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3789. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3790. void clif_traderequest(struct map_session_data* sd, const char* name)
  3791. {
  3792. int fd = sd->fd;
  3793. #if PACKETVER < 6
  3794. WFIFOHEAD(fd,packet_len(0xe5));
  3795. WFIFOW(fd,0) = 0xe5;
  3796. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3797. WFIFOSET(fd,packet_len(0xe5));
  3798. #else
  3799. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3800. if( !tsd ) return;
  3801. WFIFOHEAD(fd,packet_len(0x1f4));
  3802. WFIFOW(fd,0) = 0x1f4;
  3803. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3804. WFIFOL(fd,26) = tsd->status.char_id;
  3805. WFIFOW(fd,30) = tsd->status.base_level;
  3806. WFIFOSET(fd,packet_len(0x1f4));
  3807. #endif
  3808. }
  3809. /// Reply to a trade-request.
  3810. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3811. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3812. /// result:
  3813. /// 0 = Char is too far
  3814. /// 1 = Character does not exist
  3815. /// 2 = Trade failed
  3816. /// 3 = Accept
  3817. /// 4 = Cancel
  3818. /// 5 = Busy
  3819. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3820. {
  3821. int fd = sd->fd;
  3822. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3823. if( PACKETVER < 6 || !tsd ) {
  3824. WFIFOHEAD(fd,packet_len(0xe7));
  3825. WFIFOW(fd,0) = 0xe7;
  3826. WFIFOB(fd,2) = type;
  3827. WFIFOSET(fd,packet_len(0xe7));
  3828. } else {
  3829. WFIFOHEAD(fd,packet_len(0x1f5));
  3830. WFIFOW(fd,0) = 0x1f5;
  3831. WFIFOB(fd,2) = type;
  3832. WFIFOL(fd,3) = tsd->status.char_id;
  3833. WFIFOW(fd,7) = tsd->status.base_level;
  3834. WFIFOSET(fd,packet_len(0x1f5));
  3835. }
  3836. }
  3837. /// Notifies the client about an item from other player in current trade.
  3838. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3839. /// 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)
  3840. /// 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)
  3841. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  3842. nullpo_retv( sd );
  3843. nullpo_retv( tsd );
  3844. int fd = tsd->fd;
  3845. if( !session_isActive( fd ) ){
  3846. return;
  3847. }
  3848. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3849. if( index ){
  3850. index = server_index( index );
  3851. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3852. return;
  3853. }
  3854. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3855. #if PACKETVER >= 20100223
  3856. p.itemType = sd->inventory_data[index]->type;
  3857. #endif
  3858. p.identified = sd->inventory.u.items_inventory[index].identify;
  3859. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3860. p.refine = sd->inventory.u.items_inventory[index].refine;
  3861. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3862. #if PACKETVER >= 20150226
  3863. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  3864. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3865. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  3866. p.viewSprite = sd->inventory_data[index]->look;
  3867. p.enchantgrade = sd->inventory.u.items_inventory[index].enchantgrade;
  3868. #endif
  3869. #endif
  3870. }else{
  3871. p = {};
  3872. }
  3873. p.packetType = tradeaddType;
  3874. p.amount = amount;
  3875. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  3876. }
  3877. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3878. /// 00ea <index>.W <result>.B
  3879. /// result:
  3880. /// 0 = success
  3881. /// 1 = overweight
  3882. /// 2 = trade canceled
  3883. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3884. {
  3885. int fd;
  3886. nullpo_retv(sd);
  3887. fd = sd->fd;
  3888. WFIFOHEAD(fd,packet_len(0xea));
  3889. WFIFOW(fd,0) = 0xea;
  3890. WFIFOW(fd,2) = index;
  3891. WFIFOB(fd,4) = fail;
  3892. WFIFOSET(fd,packet_len(0xea));
  3893. }
  3894. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3895. /// 00ec <who>.B
  3896. /// who:
  3897. /// 0 = self
  3898. /// 1 = other player
  3899. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3900. {
  3901. int fd;
  3902. nullpo_retv(sd);
  3903. fd = sd->fd;
  3904. WFIFOHEAD(fd,packet_len(0xec));
  3905. WFIFOW(fd,0) = 0xec;
  3906. WFIFOB(fd,2) = fail;
  3907. WFIFOSET(fd,packet_len(0xec));
  3908. }
  3909. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3910. /// 00ee
  3911. void clif_tradecancelled(struct map_session_data* sd)
  3912. {
  3913. int fd;
  3914. nullpo_retv(sd);
  3915. fd = sd->fd;
  3916. WFIFOHEAD(fd,packet_len(0xee));
  3917. WFIFOW(fd,0) = 0xee;
  3918. WFIFOSET(fd,packet_len(0xee));
  3919. }
  3920. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3921. /// 00f0 <result>.B
  3922. /// result:
  3923. /// 0 = success
  3924. /// 1 = failure
  3925. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3926. {
  3927. int fd;
  3928. nullpo_retv(sd);
  3929. fd = sd->fd;
  3930. WFIFOHEAD(fd,packet_len(0xf0));
  3931. WFIFOW(fd,0) = 0xf0;
  3932. WFIFOB(fd,2) = fail;
  3933. WFIFOSET(fd,packet_len(0xf0));
  3934. }
  3935. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3936. /// 00f1
  3937. /// NOTE: Unknown purpose. Items are not removed until the window is
  3938. /// refreshed (ex. by putting another item in there).
  3939. void clif_tradeundo(struct map_session_data* sd)
  3940. {
  3941. int fd = sd->fd;
  3942. WFIFOHEAD(fd,packet_len(0xf1));
  3943. WFIFOW(fd,0) = 0xf1;
  3944. WFIFOSET(fd,packet_len(0xf1));
  3945. }
  3946. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3947. /// 00f2 <current count>.W <max count>.W
  3948. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3949. {
  3950. int fd;
  3951. nullpo_retv(sd);
  3952. fd=sd->fd;
  3953. WFIFOHEAD(fd,packet_len(0xf2));
  3954. WFIFOW(fd,0) = 0xf2;
  3955. WFIFOW(fd,2) = amount;
  3956. WFIFOW(fd,4) = max_amount;
  3957. WFIFOSET(fd,packet_len(0xf2));
  3958. }
  3959. /// Notifies the client of an item being added to the storage.
  3960. /// 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)
  3961. /// 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)
  3962. /// 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)
  3963. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  3964. nullpo_retv( sd );
  3965. nullpo_retv( i );
  3966. int fd = sd->fd;
  3967. if( !session_isActive( fd ) ){
  3968. return;
  3969. }
  3970. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  3971. p.packetType = storageaddType; // Storage item added
  3972. p.index = client_storage_index( index ); // index
  3973. p.amount = amount; // amount
  3974. p.itemId = client_nameid( i->nameid ); // id
  3975. #if PACKETVER >= 5
  3976. p.itemType = itemtype( i->nameid ); //type
  3977. #endif
  3978. p.identified = i->identify; //identify flag
  3979. p.damaged = i->attribute; // attribute
  3980. p.refine = i->refine; //refine
  3981. clif_addcards( &p.slot, i );
  3982. #if PACKETVER >= 20150226
  3983. clif_add_random_options( p.option_data, i );
  3984. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3985. p.enchantgrade = i->enchantgrade;
  3986. #endif
  3987. #endif
  3988. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  3989. }
  3990. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3991. /// 00f6 <index>.W <amount>.L
  3992. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3993. {
  3994. int fd;
  3995. nullpo_retv(sd);
  3996. fd=sd->fd;
  3997. WFIFOHEAD(fd,packet_len(0xf6));
  3998. WFIFOW(fd,0)=0xf6; // Storage item removed
  3999. WFIFOW(fd,2)=client_storage_index(index);
  4000. WFIFOL(fd,4)=amount;
  4001. WFIFOSET(fd,packet_len(0xf6));
  4002. }
  4003. /// Closes storage (ZC_CLOSE_STORE).
  4004. /// 00f8
  4005. void clif_storageclose(struct map_session_data* sd)
  4006. {
  4007. int fd;
  4008. nullpo_retv(sd);
  4009. fd=sd->fd;
  4010. WFIFOHEAD(fd,packet_len(0xf8));
  4011. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4012. WFIFOSET(fd,packet_len(0xf8));
  4013. }
  4014. /// Notifies clients in an area of a player's souls.
  4015. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4016. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4017. /// 0b73 <id>.L <amount>.W
  4018. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4019. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4020. struct PACKET_ZC_UNCONFIRMED_SPIRITS3 p = {};
  4021. p.packetType = HEADER_ZC_UNCONFIRMED_SPIRITS3;
  4022. #else
  4023. struct PACKET_ZC_SPIRITS p = {};
  4024. p.packetType = HEADER_ZC_SPIRITS;
  4025. #endif
  4026. p.GID = sd->bl.id;
  4027. p.amount = sd->soulball;
  4028. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4029. }
  4030. /*==========================================
  4031. * Server tells 'sd' player client the abouts of 'dstsd' player
  4032. *------------------------------------------*/
  4033. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4034. {
  4035. struct block_list *d_bl;
  4036. int i;
  4037. if( dstsd->chatID ) {
  4038. struct chat_data *cd = NULL;
  4039. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4040. clif_dispchat(cd,sd->fd);
  4041. } else if( dstsd->state.vending )
  4042. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4043. else if( dstsd->state.buyingstore )
  4044. clif_buyingstore_entry_single(sd, dstsd);
  4045. if(dstsd->spiritball > 0)
  4046. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4047. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4048. clif_millenniumshield_single(sd->fd, dstsd);
  4049. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4050. clif_spiritcharm_single(sd->fd, dstsd);
  4051. if (dstsd->soulball > 0)
  4052. clif_soulball( dstsd, &sd->bl, SELF );
  4053. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4054. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4055. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4056. )
  4057. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4058. // display link (sd - dstsd) to sd
  4059. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4060. if( i < MAX_DEVOTION )
  4061. clif_devotion(&sd->bl, sd);
  4062. // display links (dstsd - devotees) to sd
  4063. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4064. if( i < MAX_DEVOTION )
  4065. clif_devotion(&dstsd->bl, sd);
  4066. // display link (dstsd - crusader) to sd
  4067. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4068. clif_devotion(d_bl, sd);
  4069. }
  4070. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4071. struct unit_data *ud;
  4072. struct view_data *vd;
  4073. bool option = false;
  4074. unsigned int option_val = 0;
  4075. vd = status_get_viewdata(bl);
  4076. if (!vd || vd->class_ == JT_INVISIBLE)
  4077. return;
  4078. // Hide NPC from Maya Purple card
  4079. if (clif_npc_mayapurple(bl))
  4080. return;
  4081. ud = unit_bl2ud(bl);
  4082. if( ud && ud->walktimer != INVALID_TIMER ){
  4083. clif_set_unit_walking( bl, sd, ud, SELF );
  4084. }else{
  4085. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4086. }
  4087. if (vd->cloth_color)
  4088. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4089. if (vd->body_style)
  4090. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4091. switch (bl->type)
  4092. {
  4093. case BL_PC:
  4094. {
  4095. TBL_PC* tsd = (TBL_PC*)bl;
  4096. clif_getareachar_pc(sd, tsd);
  4097. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4098. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4099. else if(tsd->state.size==SZ_MEDIUM)
  4100. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4101. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4102. clif_sendbgemblem_single(sd->fd,tsd);
  4103. if ( tsd->status.robe )
  4104. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4105. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4106. clif_hat_effects(sd,bl,SELF);
  4107. }
  4108. break;
  4109. case BL_MER: // Devotion Effects
  4110. if( ((TBL_MER*)bl)->devotion_flag )
  4111. clif_devotion(bl, sd);
  4112. break;
  4113. case BL_NPC:
  4114. {
  4115. TBL_NPC* nd = (TBL_NPC*)bl;
  4116. if( nd->chat_id )
  4117. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4118. if( nd->size == SZ_BIG )
  4119. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4120. else if( nd->size == SZ_MEDIUM )
  4121. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4122. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4123. clif_progressbar_npc(nd, sd);
  4124. }
  4125. break;
  4126. case BL_MOB:
  4127. {
  4128. TBL_MOB* md = (TBL_MOB*)bl;
  4129. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4130. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4131. else if(md->special_state.size==SZ_MEDIUM)
  4132. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4133. #if PACKETVER >= 20120404
  4134. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4135. int i;
  4136. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4137. if( md->dmglog[i].id == sd->status.char_id )
  4138. clif_monster_hp_bar(md, sd->fd);
  4139. }
  4140. #endif
  4141. }
  4142. break;
  4143. case BL_PET:
  4144. if (vd->head_bottom)
  4145. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4146. break;
  4147. }
  4148. }
  4149. //Modifies the type of damage according to status changes [Skotlex]
  4150. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4151. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4152. {
  4153. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4154. }
  4155. /*==========================================
  4156. * Estimates walk delay based on the damage criteria. [Skotlex]
  4157. *------------------------------------------*/
  4158. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4159. {
  4160. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4161. return 0;
  4162. if (bl->type == BL_PC) {
  4163. if (battle_config.pc_walk_delay_rate != 100)
  4164. delay = delay*battle_config.pc_walk_delay_rate/100;
  4165. } else
  4166. if (battle_config.walk_delay_rate != 100)
  4167. delay = delay*battle_config.walk_delay_rate/100;
  4168. if (div_ > 1) //Multi-hit skills mean higher delays.
  4169. delay += battle_config.multihit_delay*(div_-1);
  4170. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4171. }
  4172. /*========================================== [Playtester]
  4173. * Returns hallucination damage the client displays
  4174. *------------------------------------------*/
  4175. static int clif_hallucination_damage()
  4176. {
  4177. int digit = rnd() % 5 + 1;
  4178. switch (digit)
  4179. {
  4180. case 1:
  4181. return (rnd() % 10);
  4182. case 2:
  4183. return (rnd() % 100);
  4184. case 3:
  4185. return (rnd() % 1000);
  4186. case 4:
  4187. return (rnd() % 10000);
  4188. }
  4189. return (rnd() % 32767);
  4190. }
  4191. /// Sends a 'damage' packet (src performs action on dst)
  4192. /// 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)
  4193. /// 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)
  4194. /// 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)
  4195. /// type:
  4196. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4197. /// 1 = pick up item
  4198. /// 2 = sit down
  4199. /// 3 = stand up
  4200. /// 4 = damage (endure)
  4201. /// 5 = (splash?)
  4202. /// 6 = (skill?)
  4203. /// 7 = (repeat damage?)
  4204. /// 8 = multi-hit damage
  4205. /// 9 = multi-hit damage (endure)
  4206. /// 10 = critical hit
  4207. /// 11 = lucky dodge
  4208. /// 12 = (touch skill?)
  4209. /// 13 = multi-hit critical
  4210. 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)
  4211. {
  4212. unsigned char buf[34];
  4213. struct status_change *sc;
  4214. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4215. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4216. #if PACKETVER < 20071113
  4217. const int cmd = 0x8a;
  4218. int offset = 0;
  4219. #elif PACKETVER < 20131223
  4220. const int cmd = 0x2e1;
  4221. int offset = 2;
  4222. #else
  4223. const int cmd = 0x8c8;
  4224. int offset = 3;
  4225. #endif
  4226. nullpo_ret(src);
  4227. nullpo_ret(dst);
  4228. if (type != DMG_MULTI_HIT_CRITICAL)
  4229. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4230. sc = status_get_sc(dst);
  4231. if(sc && sc->count) {
  4232. if(sc->data[SC_HALLUCINATION]) {
  4233. if(damage) damage = clif_hallucination_damage();
  4234. if(damage2) damage2 = clif_hallucination_damage();
  4235. }
  4236. }
  4237. WBUFW(buf,0) = cmd;
  4238. WBUFL(buf,2) = src->id;
  4239. WBUFL(buf,6) = dst->id;
  4240. WBUFL(buf,10) = client_tick(tick);
  4241. WBUFL(buf,14) = sdelay;
  4242. WBUFL(buf,18) = ddelay;
  4243. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4244. #if PACKETVER < 20071113
  4245. WBUFW(buf,22) = damage ? div : 0;
  4246. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4247. #else
  4248. WBUFL(buf, 22) = damage ? div : 0;
  4249. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4250. #endif
  4251. } else {
  4252. #if PACKETVER < 20071113
  4253. WBUFW(buf,22) = min(damage, INT16_MAX);
  4254. WBUFW(buf,27+offset) = damage2;
  4255. #else
  4256. WBUFL(buf,22) = damage;
  4257. WBUFL(buf,27+offset) = damage2;
  4258. #endif
  4259. }
  4260. #if PACKETVER >= 20131223
  4261. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4262. #endif
  4263. WBUFW(buf,24+offset) = div;
  4264. WBUFB(buf,26+offset) = type;
  4265. if(disguised(dst)) {
  4266. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4267. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4268. clif_send(buf, packet_len(cmd), dst, SELF);
  4269. } else
  4270. clif_send(buf, packet_len(cmd), dst, AREA);
  4271. if(disguised(src)) {
  4272. WBUFL(buf,2) = disguised_bl_id( src->id );
  4273. if (disguised(dst))
  4274. WBUFL(buf,6) = dst->id;
  4275. #if PACKETVER < 20071113
  4276. if(damage > 0) WBUFW(buf,22) = -1;
  4277. if(damage2 > 0) WBUFW(buf,27) = -1;
  4278. #else
  4279. if(damage > 0) WBUFL(buf,22) = -1;
  4280. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4281. #endif
  4282. clif_send(buf,packet_len(cmd),src,SELF);
  4283. }
  4284. if(src == dst) {
  4285. unit_setdir(src, unit_getdir(src));
  4286. }
  4287. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4288. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4289. //Return adjusted can't walk delay for further processing.
  4290. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4291. }
  4292. /*==========================================
  4293. * src picks up dst
  4294. *------------------------------------------*/
  4295. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4296. {
  4297. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4298. unsigned char buf[32];
  4299. nullpo_retv(src);
  4300. nullpo_retv(dst);
  4301. WBUFW(buf, 0) = 0x8a;
  4302. WBUFL(buf, 2) = src->id;
  4303. WBUFL(buf, 6) = dst->id;
  4304. WBUFB(buf,26) = 1;
  4305. clif_send(buf, packet_len(0x8a), src, AREA);
  4306. }
  4307. /*==========================================
  4308. * inform clients in area that `bl` is sitting
  4309. *------------------------------------------*/
  4310. void clif_sitting(struct block_list* bl)
  4311. {
  4312. unsigned char buf[32];
  4313. nullpo_retv(bl);
  4314. WBUFW(buf, 0) = 0x8a;
  4315. WBUFL(buf, 2) = bl->id;
  4316. WBUFB(buf,26) = 2;
  4317. clif_send(buf, packet_len(0x8a), bl, AREA);
  4318. if(disguised(bl)) {
  4319. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4320. clif_send(buf, packet_len(0x8a), bl, SELF);
  4321. }
  4322. }
  4323. /*==========================================
  4324. * inform clients in area that `bl` is standing
  4325. *------------------------------------------*/
  4326. void clif_standing(struct block_list* bl)
  4327. {
  4328. unsigned char buf[32];
  4329. nullpo_retv(bl);
  4330. WBUFW(buf, 0) = 0x8a;
  4331. WBUFL(buf, 2) = bl->id;
  4332. WBUFB(buf,26) = 3;
  4333. clif_send(buf, packet_len(0x8a), bl, AREA);
  4334. if(disguised(bl)) {
  4335. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4336. clif_send(buf, packet_len(0x8a), bl, SELF);
  4337. }
  4338. }
  4339. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4340. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4341. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4342. {
  4343. unsigned char buf[32];
  4344. WBUFW(buf,0) = 0x192;
  4345. WBUFW(buf,2) = x;
  4346. WBUFW(buf,4) = y;
  4347. WBUFW(buf,6) = type;
  4348. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4349. if( session_isActive(fd) )
  4350. {
  4351. WFIFOHEAD(fd,packet_len(0x192));
  4352. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4353. WFIFOSET(fd,packet_len(0x192));
  4354. }
  4355. else
  4356. {
  4357. struct block_list dummy_bl;
  4358. dummy_bl.type = BL_NUL;
  4359. dummy_bl.x = x;
  4360. dummy_bl.y = y;
  4361. dummy_bl.m = m;
  4362. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4363. }
  4364. }
  4365. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4366. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4367. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4368. nullpo_retv( sd );
  4369. nullpo_retv( fitem );
  4370. struct PACKET_ZC_ITEM_ENTRY p;
  4371. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4372. p.AID = fitem->bl.id;
  4373. p.itemId = client_nameid( fitem->item.nameid );
  4374. p.identify = fitem->item.identify;
  4375. p.x = fitem->bl.x;
  4376. p.y = fitem->bl.y;
  4377. p.amount = fitem->item.amount;
  4378. p.subX = fitem->subx;
  4379. p.subY = fitem->suby;
  4380. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4381. }
  4382. /// Notifes client about Graffiti
  4383. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4384. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4385. unsigned char buf[128];
  4386. nullpo_retv(bl);
  4387. nullpo_retv(unit);
  4388. WBUFW(buf, 0) = 0x1c9;
  4389. WBUFL(buf, 2) = unit->bl.id;
  4390. WBUFL(buf, 6) = unit->group->src_id;
  4391. WBUFW(buf,10) = unit->bl.x;
  4392. WBUFW(buf,12) = unit->bl.y;
  4393. WBUFB(buf,14) = unit->group->unit_id;
  4394. WBUFB(buf,15) = 1;
  4395. WBUFB(buf,16) = 1;
  4396. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4397. clif_send(buf,packet_len(0x1c9),bl,target);
  4398. }
  4399. /// Notifies the client of a skill unit.
  4400. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4401. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4402. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4403. /// 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)
  4404. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4405. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4406. unsigned char buf[128];
  4407. nullpo_retv(bl);
  4408. nullpo_retv(unit);
  4409. if (bl->type == BL_PC)
  4410. fd = ((TBL_PC*)bl)->fd;
  4411. if (unit->group->state.guildaura)
  4412. return;
  4413. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4414. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4415. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4416. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4417. else
  4418. unit_id = unit->group->unit_id;
  4419. if (!visible)
  4420. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4421. #if PACKETVER >= 3
  4422. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4423. clif_graffiti(bl, unit, target);
  4424. return;
  4425. }
  4426. #endif
  4427. #if PACKETVER <= 20120702
  4428. header = 0x011f;
  4429. //#if PACKETVER < 20110718
  4430. // header = 0x011f;
  4431. //#elif PACKETVER < 20121212
  4432. // header = 0x08c7;
  4433. #elif PACKETVER < 20130731
  4434. header = 0x099f;
  4435. #else
  4436. header = 0x09ca;
  4437. #endif
  4438. len = packet_len(header);
  4439. WBUFW(buf,pos) = header;
  4440. if (header != 0x011f) {
  4441. WBUFW(buf, pos+2) = len;
  4442. pos += 2;
  4443. }
  4444. WBUFL(buf,pos+2) = unit->bl.id;
  4445. WBUFL(buf,pos+6) = unit->group->src_id;
  4446. WBUFW(buf,pos+10) = unit->bl.x;
  4447. WBUFW(buf,pos+12) = unit->bl.y;
  4448. switch (header) {
  4449. case 0x011f:
  4450. WBUFB(buf,pos+14) = unit_id;
  4451. WBUFB(buf,pos+15) = visible;
  4452. break;
  4453. case 0x08c7:
  4454. WBUFB(buf,pos+14) = unit_id;
  4455. WBUFW(buf,pos+15) = unit->range;
  4456. WBUFB(buf,pos+17) = visible;
  4457. break;
  4458. case 0x099f:
  4459. WBUFL(buf,pos+14) = unit_id;
  4460. WBUFW(buf,pos+18) = unit->range;
  4461. WBUFB(buf,pos+20) = visible;
  4462. break;
  4463. case 0x09ca:
  4464. WBUFL(buf,pos+14) = unit_id;
  4465. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4466. WBUFB(buf,pos+19) = visible;
  4467. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4468. break;
  4469. }
  4470. clif_send(buf, len, bl, target);
  4471. if (unit->group->skill_id == WZ_ICEWALL)
  4472. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4473. }
  4474. /*==========================================
  4475. * Server tells client to remove unit of id 'unit->bl.id'
  4476. *------------------------------------------*/
  4477. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4478. {
  4479. nullpo_retv(unit);
  4480. WFIFOHEAD(fd,packet_len(0x120));
  4481. WFIFOW(fd, 0)=0x120;
  4482. WFIFOL(fd, 2)=unit->bl.id;
  4483. WFIFOSET(fd,packet_len(0x120));
  4484. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4485. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4486. }
  4487. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4488. /// 0120 <id>.L
  4489. void clif_skill_delunit(struct skill_unit *unit)
  4490. {
  4491. unsigned char buf[16];
  4492. nullpo_retv(unit);
  4493. WBUFW(buf, 0)=0x120;
  4494. WBUFL(buf, 2)=unit->bl.id;
  4495. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4496. }
  4497. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4498. /// 01ac <id>.L
  4499. /// Only affects units with class [139,153] client-side.
  4500. void clif_skillunit_update(struct block_list* bl)
  4501. {
  4502. unsigned char buf[6];
  4503. nullpo_retv(bl);
  4504. WBUFW(buf,0) = 0x1ac;
  4505. WBUFL(buf,2) = bl->id;
  4506. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4507. }
  4508. /*==========================================
  4509. *
  4510. *------------------------------------------*/
  4511. static int clif_getareachar(struct block_list* bl,va_list ap)
  4512. {
  4513. struct map_session_data *sd;
  4514. nullpo_ret(bl);
  4515. sd=va_arg(ap,struct map_session_data*);
  4516. if (!clif_session_isValid(sd))
  4517. return 0;
  4518. switch(bl->type){
  4519. case BL_ITEM:
  4520. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4521. break;
  4522. case BL_SKILL:
  4523. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4524. break;
  4525. default:
  4526. if(&sd->bl == bl)
  4527. break;
  4528. clif_getareachar_unit(sd,bl);
  4529. break;
  4530. }
  4531. return 0;
  4532. }
  4533. /*==========================================
  4534. * tbl has gone out of view-size of bl
  4535. *------------------------------------------*/
  4536. int clif_outsight(struct block_list *bl,va_list ap)
  4537. {
  4538. struct block_list *tbl;
  4539. struct view_data *vd;
  4540. TBL_PC *sd, *tsd;
  4541. tbl=va_arg(ap,struct block_list*);
  4542. if(bl == tbl) return 0;
  4543. sd = BL_CAST(BL_PC, bl);
  4544. tsd = BL_CAST(BL_PC, tbl);
  4545. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4546. nullpo_ret(bl);
  4547. switch(bl->type){
  4548. case BL_PC:
  4549. if(sd->vd.class_ != JT_INVISIBLE)
  4550. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4551. if(sd->chatID){
  4552. struct chat_data *cd;
  4553. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4554. if(cd->usersd[0]==sd)
  4555. clif_dispchat(cd,tsd->fd);
  4556. }
  4557. if(sd->state.vending)
  4558. clif_closevendingboard(bl,tsd->fd);
  4559. if(sd->state.buyingstore)
  4560. clif_buyingstore_disappear_entry_single(tsd, sd);
  4561. break;
  4562. case BL_ITEM:
  4563. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4564. break;
  4565. case BL_SKILL:
  4566. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4567. break;
  4568. case BL_NPC:
  4569. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4570. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4571. break;
  4572. default:
  4573. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4574. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4575. break;
  4576. }
  4577. }
  4578. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4579. nullpo_ret(tbl);
  4580. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4581. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4582. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4583. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4584. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4585. }
  4586. return 0;
  4587. }
  4588. /*==========================================
  4589. * tbl has come into view of bl
  4590. *------------------------------------------*/
  4591. int clif_insight(struct block_list *bl,va_list ap)
  4592. {
  4593. struct block_list *tbl;
  4594. TBL_PC *sd, *tsd;
  4595. tbl=va_arg(ap,struct block_list*);
  4596. if (bl == tbl) return 0;
  4597. sd = BL_CAST(BL_PC, bl);
  4598. tsd = BL_CAST(BL_PC, tbl);
  4599. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4600. switch(bl->type){
  4601. case BL_ITEM:
  4602. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4603. break;
  4604. case BL_SKILL:
  4605. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4606. break;
  4607. default:
  4608. clif_getareachar_unit(tsd,bl);
  4609. break;
  4610. }
  4611. }
  4612. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4613. clif_getareachar_unit(sd,tbl);
  4614. }
  4615. return 0;
  4616. }
  4617. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4618. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4619. void clif_skillinfoblock(struct map_session_data *sd)
  4620. {
  4621. int fd;
  4622. int i,len,id;
  4623. nullpo_retv(sd);
  4624. fd = sd->fd;
  4625. if (!session_isActive(fd))
  4626. return;
  4627. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4628. WFIFOW(fd,0) = 0x10f;
  4629. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4630. {
  4631. if( (id = sd->status.skill[i].id) != 0 )
  4632. {
  4633. // workaround for bugreport:5348
  4634. if (len + 37 > 8192)
  4635. break;
  4636. WFIFOW(fd,len) = id;
  4637. WFIFOL(fd,len+2) = skill_get_inf(id);
  4638. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4639. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4640. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4641. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4642. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4643. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4644. else
  4645. WFIFOB(fd,len+36) = 0;
  4646. len += 37;
  4647. }
  4648. }
  4649. WFIFOW(fd,2)=len;
  4650. WFIFOSET(fd,len);
  4651. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4652. for ( ; i < MAX_SKILL; i++)
  4653. {
  4654. if( (id = sd->status.skill[i].id) != 0 )
  4655. {
  4656. clif_addskill(sd, id);
  4657. clif_skillinfo(sd, id, 0);
  4658. }
  4659. }
  4660. }
  4661. /**
  4662. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4663. **/
  4664. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4665. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4666. void clif_addskill(struct map_session_data *sd, int skill_id)
  4667. {
  4668. nullpo_retv(sd);
  4669. int fd = sd->fd;
  4670. uint16 idx = skill_get_index(skill_id);
  4671. if (!session_isActive(fd) || !idx)
  4672. return;
  4673. if( sd->status.skill[idx].id <= 0 )
  4674. return;
  4675. WFIFOHEAD(fd, packet_len(0x111));
  4676. WFIFOW(fd,0) = 0x111;
  4677. WFIFOW(fd,2) = skill_id;
  4678. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4679. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4680. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4681. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4682. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4683. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4684. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4685. else
  4686. WFIFOB(fd,38) = 0;
  4687. WFIFOSET(fd,packet_len(0x111));
  4688. }
  4689. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4690. /// 0441 <skill id>.W
  4691. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4692. {
  4693. #if PACKETVER >= 20081217
  4694. nullpo_retv(sd);
  4695. int fd = sd->fd;
  4696. uint16 idx = skill_get_index(skill_id);
  4697. if (!session_isActive(fd) || !idx)
  4698. return;
  4699. WFIFOHEAD(fd,packet_len(0x441));
  4700. WFIFOW(fd,0) = 0x441;
  4701. WFIFOW(fd,2) = skill_id;
  4702. WFIFOSET(fd,packet_len(0x441));
  4703. #endif
  4704. clif_skillinfoblock(sd);
  4705. }
  4706. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4707. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4708. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4709. nullpo_retv(sd);
  4710. int fd = sd->fd;
  4711. uint16 idx = skill_get_index(skill_id);
  4712. if (!session_isActive(fd) || !idx)
  4713. return;
  4714. WFIFOHEAD(fd, packet_len(0x10e));
  4715. WFIFOW(fd, 0) = 0x10e;
  4716. WFIFOW(fd, 2) = skill_id;
  4717. WFIFOW(fd, 4) = lv;
  4718. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4719. WFIFOW(fd, 8) = range;
  4720. WFIFOB(fd, 10) = upgradable;
  4721. WFIFOSET(fd, packet_len(0x10e));
  4722. }
  4723. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4724. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4725. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4726. {
  4727. nullpo_retv(sd);
  4728. const int fd = sd->fd;
  4729. uint16 idx = skill_get_index(skill_id);
  4730. if (!session_isActive(fd) || !idx)
  4731. return;
  4732. WFIFOHEAD(fd,packet_len(0x7e1));
  4733. WFIFOW(fd,0) = 0x7e1;
  4734. WFIFOW(fd,2) = skill_id;
  4735. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4736. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4737. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4738. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4739. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4740. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4741. else
  4742. WFIFOB(fd,14) = 0;
  4743. WFIFOSET(fd,packet_len(0x7e1));
  4744. }
  4745. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4746. #if PACKETVER >= 20151223
  4747. if( !battle_config.show_skill_scale ){
  4748. return;
  4749. }
  4750. struct PACKET_ZC_SKILL_SCALE p;
  4751. p.PacketType = skillscale;
  4752. p.AID = src_id;
  4753. p.skill_id = skill_id;
  4754. p.skill_lv = skill_lv;
  4755. p.x = x;
  4756. p.y = y;
  4757. p.casttime = casttime;
  4758. if( disguised( bl ) ){
  4759. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4760. p.AID = disguised_bl_id( bl->id );
  4761. clif_send( &p, sizeof( p ), bl, SELF );
  4762. }else{
  4763. clif_send( &p, sizeof( p ), bl, AREA );
  4764. }
  4765. #endif
  4766. }
  4767. /// Notifies clients in area, that an object is about to use a skill.
  4768. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4769. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4770. /// property:
  4771. /// 0 = Yellow cast aura
  4772. /// 1 = Water elemental cast aura
  4773. /// 2 = Earth elemental cast aura
  4774. /// 3 = Fire elemental cast aura
  4775. /// 4 = Wind elemental cast aura
  4776. /// 5 = Poison elemental cast aura
  4777. /// 6 = Holy elemental cast aura
  4778. /// ? = like 0
  4779. /// is disposable:
  4780. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4781. /// 1 = no text
  4782. 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)
  4783. {
  4784. #if PACKETVER < 20091124
  4785. const int cmd = 0x13e;
  4786. #else
  4787. const int cmd = 0x7fb;
  4788. #endif
  4789. unsigned char buf[32];
  4790. WBUFW(buf,0) = cmd;
  4791. WBUFL(buf,2) = src_id;
  4792. WBUFL(buf,6) = dst_id;
  4793. WBUFW(buf,10) = dst_x;
  4794. WBUFW(buf,12) = dst_y;
  4795. WBUFW(buf,14) = skill_id;
  4796. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4797. WBUFL(buf,20) = casttime;
  4798. #if PACKETVER >= 20091124
  4799. WBUFB(buf,24) = 0; // isDisposable
  4800. #endif
  4801. if (disguised(bl)) {
  4802. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4803. WBUFL(buf,2) = disguised_bl_id( src_id );
  4804. clif_send(buf,packet_len(cmd), bl, SELF);
  4805. } else
  4806. clif_send(buf,packet_len(cmd), bl, AREA);
  4807. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4808. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4809. }
  4810. }
  4811. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4812. /// 01b9 <id>.L
  4813. void clif_skillcastcancel(struct block_list* bl)
  4814. {
  4815. unsigned char buf[16];
  4816. nullpo_retv(bl);
  4817. WBUFW(buf,0) = 0x1b9;
  4818. WBUFL(buf,2) = bl->id;
  4819. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4820. }
  4821. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4822. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4823. /// num (only used when skill id = NV_BASIC and cause = 0):
  4824. /// 0 = "skill failed" MsgStringTable[159]
  4825. /// 1 = "no emotions" MsgStringTable[160]
  4826. /// 2 = "no sit" MsgStringTable[161]
  4827. /// 3 = "no chat" MsgStringTable[162]
  4828. /// 4 = "no party" MsgStringTable[163]
  4829. /// 5 = "no shout" MsgStringTable[164]
  4830. /// 6 = "no PKing" MsgStringTable[165]
  4831. /// 7 = "no alligning" MsgStringTable[383]
  4832. /// ? = ignored
  4833. /// cause:
  4834. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4835. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4836. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4837. /// "skill failed" MsgStringTable[204] (otherwise)
  4838. /// ... = @see enum useskill_fail_cause
  4839. /// ? = ignored
  4840. ///
  4841. /// if(result!=0) doesn't display any of the previous messages
  4842. /// Note: when this packet is received an unknown flag is always set to 0,
  4843. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4844. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  4845. nullpo_retv( sd );
  4846. int fd = sd->fd;
  4847. if( !session_isActive( fd ) ){
  4848. return;
  4849. }
  4850. if(battle_config.display_skill_fail&1)
  4851. return; //Disable all skill failed messages
  4852. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4853. return; //Disable delay failed messages
  4854. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4855. return;
  4856. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4857. return;
  4858. struct PACKET_ZC_ACK_TOUSESKILL p;
  4859. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  4860. p.skillId = skill_id;
  4861. p.btype = btype;
  4862. p.itemId = itemId;
  4863. p.flag = 0; // 0 - failed
  4864. p.cause = cause;
  4865. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4866. }
  4867. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4868. /// 043d <skill ID>.W <tick>.L
  4869. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4870. {
  4871. #if PACKETVER>=20081112
  4872. int fd;
  4873. nullpo_retv(sd);
  4874. fd=sd->fd;
  4875. WFIFOHEAD(fd,packet_len(0x43d));
  4876. WFIFOW(fd,0) = 0x43d;
  4877. WFIFOW(fd,2) = skill_id;
  4878. WFIFOL(fd,4) = client_tick(tick);
  4879. WFIFOSET(fd,packet_len(0x43d));
  4880. #endif
  4881. }
  4882. /// Skill attack effect and damage.
  4883. /// 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)
  4884. /// 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)
  4885. 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)
  4886. {
  4887. unsigned char buf[64];
  4888. struct status_change *sc;
  4889. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4890. nullpo_ret(src);
  4891. nullpo_ret(dst);
  4892. type = clif_calc_delay(type,div,damage,ddelay);
  4893. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4894. if(sc->data[SC_HALLUCINATION] && damage)
  4895. damage = clif_hallucination_damage();
  4896. }
  4897. #if PACKETVER < 3
  4898. WBUFW(buf,0)=0x114;
  4899. WBUFW(buf,2)=skill_id;
  4900. WBUFL(buf,4)=src->id;
  4901. WBUFL(buf,8)=dst->id;
  4902. WBUFL(buf,12)=client_tick(tick);
  4903. WBUFL(buf,16)=sdelay;
  4904. WBUFL(buf,20)=ddelay;
  4905. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4906. WBUFW(buf,24)=damage?div:0;
  4907. } else {
  4908. WBUFW(buf,24)=damage;
  4909. }
  4910. WBUFW(buf,26)=skill_lv;
  4911. WBUFW(buf,28)=div;
  4912. WBUFB(buf,30)=type;
  4913. if (disguised(dst)) {
  4914. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4915. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4916. clif_send(buf,packet_len(0x114),dst,SELF);
  4917. } else
  4918. clif_send(buf,packet_len(0x114),dst,AREA);
  4919. if(disguised(src)) {
  4920. WBUFL(buf,4)=disguised_bl_id(src->id);
  4921. if (disguised(dst))
  4922. WBUFL(buf,8)=dst->id;
  4923. if(damage > 0)
  4924. WBUFW(buf,24)=-1;
  4925. clif_send(buf,packet_len(0x114),src,SELF);
  4926. }
  4927. #else
  4928. WBUFW(buf,0)=0x1de;
  4929. WBUFW(buf,2)=skill_id;
  4930. WBUFL(buf,4)=src->id;
  4931. WBUFL(buf,8)=dst->id;
  4932. WBUFL(buf,12)=client_tick(tick);
  4933. WBUFL(buf,16)=sdelay;
  4934. WBUFL(buf,20)=ddelay;
  4935. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4936. WBUFL(buf,24)=damage?div:0;
  4937. } else {
  4938. WBUFL(buf,24)=damage;
  4939. }
  4940. WBUFW(buf,28)=skill_lv;
  4941. WBUFW(buf,30)=div;
  4942. // For some reason, late 2013 and newer clients have
  4943. // a issue that causes players and monsters to endure
  4944. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4945. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4946. #if PACKETVER < 20131223
  4947. WBUFB(buf,32)=type;
  4948. #else
  4949. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  4950. #endif
  4951. if (disguised(dst)) {
  4952. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4953. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4954. clif_send(buf,packet_len(0x1de),dst,SELF);
  4955. } else
  4956. clif_send(buf,packet_len(0x1de),dst,AREA);
  4957. if(disguised(src)) {
  4958. WBUFL(buf,4)=disguised_bl_id(src->id);
  4959. if (disguised(dst))
  4960. WBUFL(buf,8)=dst->id;
  4961. if(damage > 0)
  4962. WBUFL(buf,24)=-1;
  4963. clif_send(buf,packet_len(0x1de),src,SELF);
  4964. }
  4965. #endif
  4966. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4967. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4968. }
  4969. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4970. /// 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
  4971. /*
  4972. 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)
  4973. {
  4974. unsigned char buf[64];
  4975. struct status_change *sc;
  4976. nullpo_ret(src);
  4977. nullpo_ret(dst);
  4978. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4979. type = clif_calc_delay(type,div,damage,ddelay);
  4980. sc = status_get_sc(dst);
  4981. if(sc && sc->count) {
  4982. if(sc->data[SC_HALLUCINATION] && damage)
  4983. damage = clif_hallucination_damage();
  4984. }
  4985. WBUFW(buf,0)=0x115;
  4986. WBUFW(buf,2)=skill_id;
  4987. WBUFL(buf,4)=src->id;
  4988. WBUFL(buf,8)=dst->id;
  4989. WBUFL(buf,12)=client_tick(tick);
  4990. WBUFL(buf,16)=sdelay;
  4991. WBUFL(buf,20)=ddelay;
  4992. WBUFW(buf,24)=dst->x;
  4993. WBUFW(buf,26)=dst->y;
  4994. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4995. WBUFW(buf,28)=damage?div:0;
  4996. } else {
  4997. WBUFW(buf,28)=damage;
  4998. }
  4999. WBUFW(buf,30)=skill_lv;
  5000. WBUFW(buf,32)=div;
  5001. WBUFB(buf,34)=type;
  5002. clif_send(buf,packet_len(0x115),src,AREA);
  5003. if(disguised(src)) {
  5004. WBUFL(buf,4)=disguised_bl_id(src->id);
  5005. if(damage > 0)
  5006. WBUFW(buf,28)=-1;
  5007. clif_send(buf,packet_len(0x115),src,SELF);
  5008. }
  5009. if (disguised(dst)) {
  5010. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5011. if (disguised(src))
  5012. WBUFL(buf,4)=src->id;
  5013. else if(damage > 0)
  5014. WBUFW(buf,28)=-1;
  5015. clif_send(buf,packet_len(0x115),dst,SELF);
  5016. }
  5017. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5018. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5019. }
  5020. */
  5021. /// Non-damaging skill effect
  5022. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5023. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5024. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5025. {
  5026. unsigned char buf[17];
  5027. #if PACKETVER < 20130731
  5028. const int cmd = 0x11a;
  5029. #else
  5030. const int cmd = 0x9cb;
  5031. #endif
  5032. int offset = 0;
  5033. bool success = ( tick != 0 );
  5034. nullpo_ret(dst);
  5035. WBUFW(buf,0) = cmd;
  5036. WBUFW(buf,2) = skill_id;
  5037. #if PACKETVER < 20130731
  5038. WBUFW(buf,4) = min(heal, INT16_MAX);
  5039. #else
  5040. WBUFL(buf,4) = min(heal, INT32_MAX);
  5041. offset += 2;
  5042. #endif
  5043. WBUFL(buf,6+offset) = dst->id;
  5044. WBUFL(buf,10+offset) = src ? src->id : 0;
  5045. WBUFB(buf,14+offset) = success;
  5046. if (disguised(dst)) {
  5047. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5048. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5049. clif_send(buf, packet_len(cmd), dst, SELF);
  5050. } else
  5051. clif_send(buf, packet_len(cmd), dst, AREA);
  5052. if(src && disguised(src)) {
  5053. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5054. if (disguised(dst))
  5055. WBUFL(buf,6+offset) = dst->id;
  5056. clif_send(buf, packet_len(cmd), src, SELF);
  5057. }
  5058. return success;
  5059. }
  5060. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5061. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5062. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5063. {
  5064. unsigned char buf[32];
  5065. nullpo_retv(src);
  5066. WBUFW(buf,0)=0x117;
  5067. WBUFW(buf,2)=skill_id;
  5068. WBUFL(buf,4)=src->id;
  5069. WBUFW(buf,8)=val;
  5070. WBUFW(buf,10)=x;
  5071. WBUFW(buf,12)=y;
  5072. WBUFL(buf,14)=client_tick(tick);
  5073. if(disguised(src)) {
  5074. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5075. WBUFL(buf,4)=disguised_bl_id(src->id);
  5076. clif_send(buf,packet_len(0x117),src,SELF);
  5077. } else
  5078. clif_send(buf,packet_len(0x117),src,AREA);
  5079. }
  5080. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5081. /// 011c <skill id>.W { <map name>.16B }*4
  5082. 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)
  5083. {
  5084. int fd;
  5085. nullpo_retv(sd);
  5086. fd = sd->fd;
  5087. WFIFOHEAD(fd,packet_len(0x11c));
  5088. WFIFOW(fd,0) = 0x11c;
  5089. WFIFOW(fd,2) = skill_id;
  5090. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5091. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5092. else // normal map name
  5093. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5094. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5095. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5096. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5097. WFIFOSET(fd,packet_len(0x11c));
  5098. sd->menuskill_id = skill_id;
  5099. if (skill_id == AL_WARP) {
  5100. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5101. sd->state.workinprogress = WIP_DISABLE_ALL;
  5102. } else
  5103. sd->menuskill_val = skill_lv;
  5104. }
  5105. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5106. /// 011e <type>.B
  5107. /// type:
  5108. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5109. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5110. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5111. ///
  5112. /// @param sd Who receives the message
  5113. /// @param type What message
  5114. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5115. {
  5116. int fd;
  5117. nullpo_retv(sd);
  5118. fd=sd->fd;
  5119. WFIFOHEAD(fd,packet_len(0x11e));
  5120. WFIFOW(fd,0)=0x11e;
  5121. WFIFOB(fd,2)=type;
  5122. WFIFOSET(fd,packet_len(0x11e));
  5123. }
  5124. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5125. /// 0189 <type>.W
  5126. /// type:
  5127. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5128. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5129. ///
  5130. /// @param sd Who receives the message
  5131. /// @param type What message
  5132. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5133. {
  5134. int fd;
  5135. nullpo_retv(sd);
  5136. fd=sd->fd;
  5137. WFIFOHEAD(fd,packet_len(0x189));
  5138. WFIFOW(fd,0)=0x189;
  5139. WFIFOW(fd,2)=type;
  5140. WFIFOSET(fd,packet_len(0x189));
  5141. }
  5142. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5143. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5144. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5145. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5146. {
  5147. struct status_data *status;
  5148. unsigned char buf[64];
  5149. int i, fix;
  5150. nullpo_retv(sd);
  5151. nullpo_retv(dst);
  5152. if( dst->type != BL_MOB )
  5153. return;
  5154. status = status_get_status_data(dst);
  5155. WBUFW(buf, 0)=0x18c;
  5156. WBUFW(buf, 2)=status_get_class(dst);
  5157. WBUFW(buf, 4)=status_get_lv(dst);
  5158. WBUFW(buf, 6)=status->size;
  5159. WBUFL(buf, 8)=status->hp;
  5160. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5161. +(battle_config.estimation_type&2?status->def2:0);
  5162. WBUFW(buf,14)=status->race;
  5163. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5164. +(battle_config.estimation_type&2?status->mdef2:0);
  5165. WBUFW(buf,18)= status->def_ele;
  5166. for(i=0;i<9;i++)
  5167. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5168. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5169. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5170. }
  5171. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5172. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5173. /// material id:
  5174. /// unused by the client
  5175. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5176. nullpo_retv(sd);
  5177. int fd = sd->fd;
  5178. if( !session_isActive( fd ) ){
  5179. return;
  5180. }
  5181. if (sd->menuskill_id == skill_id)
  5182. return; //Avoid resending the menu twice or more times...
  5183. if (skill_id == GC_CREATENEWPOISON)
  5184. skill_id = GC_RESEARCHNEWPOISON;
  5185. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5186. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5187. p->packetType = 0x18d;
  5188. int count = 0;
  5189. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5190. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5191. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5192. )
  5193. {
  5194. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5195. p->items[count].material[0] = 0;
  5196. p->items[count].material[1] = 0;
  5197. p->items[count].material[2] = 0;
  5198. count++;
  5199. }
  5200. }
  5201. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5202. WFIFOSET( fd, p->packetLength );
  5203. if( count > 0 ){
  5204. sd->menuskill_id = skill_id;
  5205. sd->menuskill_val = trigger;
  5206. return;
  5207. }
  5208. }
  5209. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5210. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5211. /// mk type:
  5212. /// 1 = cooking
  5213. /// 2 = arrow
  5214. /// 3 = elemental
  5215. /// 4 = GN_MIX_COOKING
  5216. /// 5 = GN_MAKEBOMB
  5217. /// 6 = GN_S_PHARMACY
  5218. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5219. nullpo_retv( sd );
  5220. // Avoid resending the menu twice or more times...
  5221. if( sd->menuskill_id == skill_id ){
  5222. return;
  5223. }
  5224. int fd = sd->fd;
  5225. if( !session_isActive( fd ) ){
  5226. return;
  5227. }
  5228. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5229. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5230. p->packetType = 0x25a;
  5231. p->makeItem = list_type; // list type
  5232. int count = 0;
  5233. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5234. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5235. continue;
  5236. }
  5237. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5238. count++;
  5239. }
  5240. if( count > 0 || skill_id == AM_PHARMACY ){
  5241. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5242. WFIFOSET( fd, p->packetLength );
  5243. sd->menuskill_id = skill_id;
  5244. sd->menuskill_val = trigger;
  5245. sd->menuskill_val2 = qty; // amount.
  5246. }else{
  5247. clif_menuskill_clear(sd);
  5248. #if PACKETVER >= 20090922
  5249. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5250. #else
  5251. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5252. WFIFOSET( fd, p->packetLength );
  5253. #endif
  5254. }
  5255. }
  5256. /// Notifies clients of a status change.
  5257. /// 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)]
  5258. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5259. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5260. /// @param bl Sends packet to clients around this object
  5261. /// @param id ID of object that has this effect
  5262. /// @param type Status icon see enum efst_types
  5263. /// @param flag 1:Active, 0:Deactive
  5264. /// @param tick Duration in ms
  5265. /// @param val1
  5266. /// @param val2
  5267. /// @param val3
  5268. 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)
  5269. {
  5270. unsigned char buf[32];
  5271. if (type == EFST_BLANK) //It shows nothing on the client...
  5272. return;
  5273. if (type == EFST_POSTDELAY && tick == 0)
  5274. return;
  5275. nullpo_retv(bl);
  5276. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5277. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5278. tick = 200;
  5279. #if PACKETVER >= 20120618
  5280. if (flag && battle_config.display_status_timers)
  5281. WBUFW(buf,0) = 0x983;
  5282. else
  5283. #elif PACKETVER >= 20090121
  5284. if (flag && battle_config.display_status_timers)
  5285. WBUFW(buf,0) = 0x43f;
  5286. else
  5287. #endif
  5288. WBUFW(buf,0) = 0x196;
  5289. WBUFW(buf,2) = type;
  5290. WBUFL(buf,4) = id;
  5291. WBUFB(buf,8) = flag;
  5292. #if PACKETVER >= 20120618
  5293. if (flag && battle_config.display_status_timers) {
  5294. if (tick <= 0)
  5295. tick = 9999; // this is indeed what official servers do
  5296. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5297. WBUFL(buf,13) = client_tick(tick);
  5298. WBUFL(buf,17) = val1;
  5299. WBUFL(buf,21) = val2;
  5300. WBUFL(buf,25) = val3;
  5301. }
  5302. #elif PACKETVER >= 20090121
  5303. if (flag && battle_config.display_status_timers) {
  5304. if (tick <= 0)
  5305. tick = 9999; // this is indeed what official servers do
  5306. WBUFL(buf,9) = client_tick(tick);
  5307. WBUFL(buf,13) = val1;
  5308. WBUFL(buf,17) = val2;
  5309. WBUFL(buf,21) = val3;
  5310. }
  5311. #endif
  5312. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5313. }
  5314. /* Sends status effect to clients around the bl
  5315. * @param bl Object that has the effect
  5316. * @param type Status icon see enum efst_types
  5317. * @param flag 1:Active, 0:Deactive
  5318. * @param tick Duration in ms
  5319. * @param val1
  5320. * @param val2
  5321. * @param val3
  5322. */
  5323. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5324. struct map_session_data *sd = NULL;
  5325. if (type == EFST_BLANK) //It shows nothing on the client...
  5326. return;
  5327. if (type == EFST_POSTDELAY && tick == 0)
  5328. return;
  5329. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5330. return;
  5331. nullpo_retv(bl);
  5332. sd = BL_CAST(BL_PC, bl);
  5333. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5334. return;
  5335. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5336. }
  5337. /**
  5338. * Send any active EFST to those around.
  5339. * @param tbl: Unit to send the packet to
  5340. * @param bl: Objects walking into view
  5341. * @param target: Client send type
  5342. */
  5343. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5344. unsigned char i;
  5345. struct sc_display_entry **sc_display;
  5346. unsigned char sc_display_count;
  5347. bool spheres_sent;
  5348. nullpo_retv(bl);
  5349. switch( bl->type ){
  5350. case BL_PC: {
  5351. struct map_session_data* sd = (struct map_session_data*)bl;
  5352. sc_display = sd->sc_display;
  5353. sc_display_count = sd->sc_display_count;
  5354. spheres_sent = !sd->state.connect_new;
  5355. }
  5356. break;
  5357. case BL_NPC: {
  5358. struct npc_data* nd = (struct npc_data*)bl;
  5359. sc_display = nd->sc_display;
  5360. sc_display_count = nd->sc_display_count;
  5361. spheres_sent = true;
  5362. }
  5363. break;
  5364. default:
  5365. return;
  5366. }
  5367. for (i = 0; i < sc_display_count; i++) {
  5368. enum sc_type type = sc_display[i]->type;
  5369. struct status_change *sc = status_get_sc(bl);
  5370. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5371. t_tick tick = 0;
  5372. if (td)
  5373. tick = DIFF_TICK(td->tick, gettick());
  5374. // Status changes that need special handling
  5375. switch( type ){
  5376. case SC_SPHERE_1:
  5377. case SC_SPHERE_2:
  5378. case SC_SPHERE_3:
  5379. case SC_SPHERE_4:
  5380. case SC_SPHERE_5:
  5381. if( spheres_sent ){
  5382. target = AREA_WOS;
  5383. }
  5384. break;
  5385. case SC_HELLS_PLANT:
  5386. if( sc && sc->data[type] ){
  5387. tick = sc->data[type]->val4;
  5388. }
  5389. break;
  5390. }
  5391. #if PACKETVER > 20120418
  5392. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5393. #else
  5394. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5395. #endif
  5396. }
  5397. }
  5398. /// Notifies the client when a player enters the screen with an active EFST.
  5399. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5400. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5401. 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) {
  5402. #if PACKETVER >= 20111108
  5403. unsigned char buf[32];
  5404. #if PACKETVER >= 20120618
  5405. const int cmd = 0x984;
  5406. #elif PACKETVER >= 20111108
  5407. const int cmd = 0x8ff;
  5408. #endif
  5409. int offset = 0;
  5410. if (type == EFST_BLANK)
  5411. return;
  5412. nullpo_retv(bl);
  5413. if (tick <= 0)
  5414. tick = 9999;
  5415. WBUFW(buf,offset + 0) = cmd;
  5416. WBUFL(buf,offset + 2) = tid;
  5417. WBUFW(buf,offset + 6) = type;
  5418. #if PACKETVER >= 20111108
  5419. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5420. #if PACKETVER >= 20120618
  5421. WBUFL(buf,offset + 12) = client_tick(tick);
  5422. offset += 4;
  5423. #endif
  5424. WBUFL(buf,offset + 12) = val1;
  5425. WBUFL(buf,offset + 16) = val2;
  5426. WBUFL(buf,offset + 20) = val3;
  5427. #endif
  5428. clif_send(buf,packet_len(cmd),bl,target);
  5429. #endif
  5430. }
  5431. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5432. /// 008e <packet len>.W <message>.?B
  5433. void clif_displaymessage(const int fd, const char* mes)
  5434. {
  5435. nullpo_retv(mes);
  5436. if( session_isActive( fd ) ){
  5437. char *message, *line;
  5438. message = aStrdup(mes);
  5439. line = strtok(message, "\n");
  5440. while(line != NULL) {
  5441. #if PACKETVER == 20141022
  5442. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5443. /** so we redirect to ZC_NPC_CHAT **/
  5444. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5445. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5446. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5447. if (len > 0) {
  5448. WFIFOHEAD(fd, 13 + len);
  5449. WFIFOW(fd, 0) = 0x2C1;
  5450. WFIFOW(fd, 2) = 13 + len;
  5451. WFIFOL(fd, 4) = 0;
  5452. WFIFOL(fd, 8) = color;
  5453. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5454. WFIFOSET(fd, WFIFOW(fd, 2));
  5455. }
  5456. #else
  5457. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5458. int len = strnlen(line, CHAT_SIZE_MAX);
  5459. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5460. WFIFOHEAD(fd, 5 + len);
  5461. WFIFOW(fd,0) = 0x8e;
  5462. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5463. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5464. WFIFOSET(fd, 5 + len);
  5465. }
  5466. #endif
  5467. line = strtok(NULL, "\n");
  5468. }
  5469. aFree(message);
  5470. }
  5471. }
  5472. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5473. /// 009a <packet len>.W <message>.?B
  5474. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5475. {
  5476. nullpo_retv(mes);
  5477. if (len < 2)
  5478. return;
  5479. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5480. p->packetType = HEADER_ZC_BROADCAST;
  5481. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5482. if( ( type&BC_BLUE ) != 0 ){
  5483. const char* color = "blue";
  5484. int16 length = (int16)strlen( color );
  5485. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5486. strcpy( p->message, color );
  5487. strncpy( &p->message[length], mes, len );
  5488. p->PacketLength += length;
  5489. }else if( ( type&BC_WOE ) != 0 ){
  5490. const char* color = "ssss";
  5491. int16 length = (int16)strlen( color );
  5492. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5493. strcpy( p->message, color );
  5494. strncpy( &p->message[length], mes, len );
  5495. p->PacketLength += length;
  5496. }else{
  5497. strncpy( p->message, mes, len );
  5498. }
  5499. clif_send( p, p->PacketLength, bl, target );
  5500. }
  5501. /*==========================================
  5502. * Displays a message on a 'bl' to all it's nearby clients
  5503. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5504. *------------------------------------------*/
  5505. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5506. nullpo_retv(bl);
  5507. nullpo_retv(message);
  5508. int16 len = (int16)( strlen( message ) + 1 );
  5509. if( len > CHAT_SIZE_MAX ) {
  5510. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5511. len = CHAT_SIZE_MAX;
  5512. }
  5513. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5514. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5515. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5516. p->GID = bl->id;
  5517. safestrncpy( p->Message, message, len );
  5518. clif_send( p, p->PacketLength, bl, target );
  5519. }
  5520. /// Send broadcast message with font formatting.
  5521. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5522. 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)
  5523. {
  5524. nullpo_retv(mes);
  5525. if (len < 2)
  5526. return;
  5527. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5528. p->packetType = HEADER_ZC_BROADCAST2;
  5529. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5530. p->fontColor = fontColor;
  5531. p->fontType = fontType;
  5532. p->fontSize = fontSize;
  5533. p->fontAlign = fontAlign;
  5534. p->fontY = fontY;
  5535. strncpy( p->message, mes, len );
  5536. clif_send( p, p->PacketLength, bl, target );
  5537. }
  5538. /*
  5539. * Display *msg to all *users in channel
  5540. */
  5541. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5542. DBIterator *iter;
  5543. struct map_session_data *user;
  5544. unsigned short msg_len = 0, len = 0;
  5545. unsigned char buf[CHAT_SIZE_MAX];
  5546. if (!channel || !msg)
  5547. return;
  5548. msg_len = (unsigned short)(strlen(msg) + 1);
  5549. if( msg_len > sizeof(buf)-12 ) {
  5550. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5551. msg_len = sizeof(buf)-12;
  5552. }
  5553. WBUFW(buf,0) = 0x2C1;
  5554. WBUFW(buf,2) = (len = msg_len + 12);
  5555. WBUFL(buf,4) = 0;
  5556. WBUFL(buf,8) = color;
  5557. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5558. iter = db_iterator(channel->users);
  5559. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5560. clif_send(buf, len, &user->bl, SELF);
  5561. }
  5562. dbi_destroy(iter);
  5563. }
  5564. /// Displays heal effect.
  5565. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5566. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5567. /// var id:
  5568. /// 5 = HP (SP_HP)
  5569. /// 7 = SP (SP_SP)
  5570. /// ? = ignored
  5571. void clif_heal(int fd,int type,int val) {
  5572. #if PACKETVER < 20141022
  5573. const int cmd = 0x13d;
  5574. #else
  5575. const int cmd = 0xa27;
  5576. #endif
  5577. WFIFOHEAD(fd, packet_len(cmd));
  5578. WFIFOW(fd,0) = cmd;
  5579. WFIFOW(fd,2) = type;
  5580. #if PACKETVER < 20141022
  5581. WFIFOW(fd,4) = min(val, INT16_MAX);
  5582. #else
  5583. WFIFOL(fd,4) = min(val, INT32_MAX);
  5584. #endif
  5585. WFIFOSET(fd, packet_len(cmd));
  5586. }
  5587. /// Displays resurrection effect (ZC_RESURRECTION).
  5588. /// 0148 <id>.L <type>.W
  5589. /// type:
  5590. /// ignored
  5591. void clif_resurrection(struct block_list *bl,int type)
  5592. {
  5593. unsigned char buf[16];
  5594. nullpo_retv(bl);
  5595. WBUFW(buf,0)=0x148;
  5596. WBUFL(buf,2)=bl->id;
  5597. WBUFW(buf,6)=0;
  5598. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5599. if (disguised(bl))
  5600. clif_spawn(bl);
  5601. }
  5602. /// Sets the map property
  5603. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5604. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5605. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5606. {
  5607. #if PACKETVER >= 20121010
  5608. short cmd = 0x99b;
  5609. unsigned char buf[8];
  5610. #else
  5611. short cmd = 0x199;
  5612. unsigned char buf[4];
  5613. #endif
  5614. WBUFW(buf,0)=cmd;
  5615. WBUFW(buf,2)=property;
  5616. #if PACKETVER >= 20121010
  5617. struct map_data *mapdata = map_getmapdata(bl->m);
  5618. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0 || (bl->type == BL_PC && ((TBL_PC *)bl)->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5619. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5620. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5621. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5622. ((mapdata->flag[MF_NOLOCKON] || mapdata_flag_vs(mapdata)?1:0)<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5623. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5624. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5625. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5626. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5627. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5628. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5629. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5630. #endif
  5631. clif_send(buf,packet_len(cmd),bl,t);
  5632. }
  5633. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5634. /// 01d6 <type>.W
  5635. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5636. {
  5637. int fd;
  5638. nullpo_retv(sd);
  5639. fd=sd->fd;
  5640. WFIFOHEAD(fd,packet_len(0x1D6));
  5641. WFIFOW(fd,0)=0x1D6;
  5642. WFIFOW(fd,2)=type;
  5643. WFIFOSET(fd,packet_len(0x1D6));
  5644. }
  5645. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5646. /// 019a <id>.L <ranking>.L <total>.L
  5647. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5648. {
  5649. if(type == 2) {
  5650. int fd = sd->fd;
  5651. WFIFOHEAD(fd,packet_len(0x19a));
  5652. WFIFOW(fd,0) = 0x19a;
  5653. WFIFOL(fd,2) = sd->bl.id;
  5654. WFIFOL(fd,6) = pvprank;
  5655. WFIFOL(fd,10) = pvpnum;
  5656. WFIFOSET(fd,packet_len(0x19a));
  5657. } else {
  5658. unsigned char buf[32];
  5659. WBUFW(buf,0) = 0x19a;
  5660. WBUFL(buf,2) = sd->bl.id;
  5661. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5662. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5663. else
  5664. WBUFL(buf,6) = pvprank;
  5665. WBUFL(buf,10) = pvpnum;
  5666. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5667. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5668. else if(!type)
  5669. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5670. else
  5671. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5672. }
  5673. }
  5674. /*==========================================
  5675. *
  5676. *------------------------------------------*/
  5677. void clif_map_property_mapall(int map_idx, enum map_property property)
  5678. {
  5679. struct block_list bl;
  5680. bl.id = 0;
  5681. bl.type = BL_NUL;
  5682. bl.m = map_idx;
  5683. clif_map_property( &bl, property, ALL_SAMEMAP );
  5684. }
  5685. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5686. /// 0188 <result>.W <index>.W <refine>.W
  5687. /// result:
  5688. /// 0 = success
  5689. /// 1 = failure
  5690. /// 2 = downgrade
  5691. void clif_refine(int fd, int fail, int index, int val)
  5692. {
  5693. WFIFOHEAD(fd,packet_len(0x188));
  5694. WFIFOW(fd,0)=0x188;
  5695. WFIFOW(fd,2)=fail;
  5696. WFIFOW(fd,4)=index+2;
  5697. WFIFOW(fd,6)=val;
  5698. WFIFOSET(fd,packet_len(0x188));
  5699. }
  5700. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5701. /// 0223 <result>.L <nameid>.W
  5702. /// result:
  5703. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5704. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5705. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5706. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5707. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5708. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5709. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5710. p.result = result;
  5711. p.itemId = client_nameid( item_id );
  5712. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5713. }
  5714. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5715. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5716. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5717. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5718. int fd;
  5719. nullpo_retv(sd);
  5720. fd = sd->fd;
  5721. #if PACKETVER < 20091104
  5722. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5723. WFIFOW(fd,0) = 0x97;
  5724. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5725. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5726. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5727. WFIFOSET(fd,WFIFOW(fd,2));
  5728. #else
  5729. struct map_session_data *ssd = map_nick2sd(nick,false);
  5730. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5731. WFIFOW(fd,0) = 0x97;
  5732. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5733. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5734. // If it is not a message from the server or a player from another map-server
  5735. if( ssd ){
  5736. gmlvl = pc_get_group_level(ssd);
  5737. }
  5738. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5739. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5740. WFIFOSET(fd,WFIFOW(fd,2));
  5741. #endif
  5742. }
  5743. /// Inform the player about the result of his whisper action
  5744. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5745. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5746. /// result:
  5747. /// 0 = success to send wisper
  5748. /// 1 = target character is not loged in
  5749. /// 2 = ignored by target
  5750. /// 3 = everyone ignored by target
  5751. void clif_wis_end(int fd, int result)
  5752. {
  5753. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5754. #if PACKETVER < 20131223
  5755. const int cmd = 0x98;
  5756. #else
  5757. const int cmd = 0x9df;
  5758. #endif
  5759. if (!sd)
  5760. return;
  5761. WFIFOHEAD(fd,packet_len(cmd));
  5762. WFIFOW(fd,0) = cmd;
  5763. WFIFOB(fd,2) = (char)result;
  5764. #if PACKETVER >= 20131223
  5765. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5766. #endif
  5767. WFIFOSET(fd,packet_len(cmd));
  5768. }
  5769. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5770. /// 0194 <char id>.L <name>.24B
  5771. /// 0af7 <flag>.W <char id>.L <name>.24B
  5772. void clif_solved_charname(int fd, int charid, const char* name)
  5773. {
  5774. #if PACKETVER >= 20180221
  5775. WFIFOHEAD(fd,packet_len(0xaf7));
  5776. WFIFOW(fd,0) = 0xaf7;
  5777. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5778. WFIFOL(fd,4) = charid;
  5779. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5780. WFIFOSET(fd,packet_len(0x0af7));
  5781. #else
  5782. WFIFOHEAD(fd,packet_len(0x194));
  5783. WFIFOW(fd,0)=0x194;
  5784. WFIFOL(fd,2)=charid;
  5785. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5786. WFIFOSET(fd,packet_len(0x194));
  5787. #endif
  5788. }
  5789. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5790. /// 017b <packet len>.W { <name id>.W }*
  5791. void clif_use_card(struct map_session_data *sd,int idx)
  5792. {
  5793. int i,c,ep;
  5794. int fd=sd->fd;
  5795. nullpo_retv(sd);
  5796. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5797. return;
  5798. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5799. return; //Avoid parsing invalid item indexes (no card/no item)
  5800. ep=sd->inventory_data[idx]->equip;
  5801. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5802. WFIFOW(fd,0)=0x17b;
  5803. for(i=c=0;i<MAX_INVENTORY;i++){
  5804. int j;
  5805. if(sd->inventory_data[i] == NULL)
  5806. continue;
  5807. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5808. continue;
  5809. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5810. continue;
  5811. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5812. continue;
  5813. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5814. continue;
  5815. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5816. continue;
  5817. 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.
  5818. continue;
  5819. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5820. if( j == sd->inventory_data[i]->slots ) // No room
  5821. continue;
  5822. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5823. continue;
  5824. WFIFOW(fd,4+c*2)=i+2;
  5825. c++;
  5826. }
  5827. if( !c ) return; // no item is available for card insertion
  5828. WFIFOW(fd,2)=4+c*2;
  5829. WFIFOSET(fd,WFIFOW(fd,2));
  5830. }
  5831. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5832. /// 017d <equip index>.W <card index>.W <result>.B
  5833. /// result:
  5834. /// 0 = success
  5835. /// 1 = failure
  5836. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5837. {
  5838. int fd;
  5839. nullpo_retv(sd);
  5840. fd=sd->fd;
  5841. WFIFOHEAD(fd,packet_len(0x17d));
  5842. WFIFOW(fd,0)=0x17d;
  5843. WFIFOW(fd,2)=idx_equip+2;
  5844. WFIFOW(fd,4)=idx_card+2;
  5845. WFIFOB(fd,6)=flag;
  5846. WFIFOSET(fd,packet_len(0x17d));
  5847. }
  5848. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5849. /// 0177 <packet len>.W { <index>.W }*
  5850. void clif_item_identify_list(struct map_session_data *sd)
  5851. {
  5852. int i,c;
  5853. int fd;
  5854. nullpo_retv(sd);
  5855. fd=sd->fd;
  5856. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5857. WFIFOW(fd,0)=0x177;
  5858. for(i=c=0;i<MAX_INVENTORY;i++){
  5859. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5860. WFIFOW(fd,c*2+4)=client_index(i);
  5861. c++;
  5862. }
  5863. }
  5864. if(c > 0) {
  5865. WFIFOW(fd,2)=c*2+4;
  5866. WFIFOSET(fd,WFIFOW(fd,2));
  5867. sd->menuskill_id = MC_IDENTIFY;
  5868. sd->menuskill_val = c;
  5869. sd->state.workinprogress = WIP_DISABLE_ALL;
  5870. }
  5871. }
  5872. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5873. /// 0179 <index>.W <result>.B
  5874. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5875. {
  5876. int fd;
  5877. nullpo_retv(sd);
  5878. fd=sd->fd;
  5879. WFIFOHEAD(fd,packet_len(0x179));
  5880. WFIFOW(fd, 0)=0x179;
  5881. WFIFOW(fd, 2)=idx+2;
  5882. WFIFOB(fd, 4)=flag;
  5883. WFIFOSET(fd,packet_len(0x179));
  5884. }
  5885. /// Presents a list of items that can be repaired.
  5886. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  5887. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  5888. nullpo_retv( sd );
  5889. nullpo_retv( dstsd );
  5890. int fd = sd->fd;
  5891. if( !session_isActive( fd ) ){
  5892. return;
  5893. }
  5894. int len = MAX_INVENTORY * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5895. // Preallocate the maximum size
  5896. WFIFOHEAD( fd, len );
  5897. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  5898. int c = 0;
  5899. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5900. 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)){
  5901. p->items[c].index = i;
  5902. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  5903. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  5904. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  5905. c++;
  5906. }
  5907. }
  5908. if( c > 0 ){
  5909. p->packetType = 0x1fc;
  5910. // Recalculate real length
  5911. len = c * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5912. p->packetLength = len;
  5913. WFIFOSET( fd, len );
  5914. sd->menuskill_id = BS_REPAIRWEAPON;
  5915. sd->menuskill_val = dstsd->bl.id;
  5916. sd->menuskill_val2 = lv;
  5917. }else{
  5918. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  5919. }
  5920. }
  5921. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5922. /// 01fe <index>.W <result>.B
  5923. /// index:
  5924. /// ignored (inventory index)
  5925. /// result:
  5926. /// 0 = Item repair success.
  5927. /// 1 = Item repair failure.
  5928. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5929. {
  5930. int fd;
  5931. nullpo_retv(sd);
  5932. fd = sd->fd;
  5933. WFIFOHEAD(fd,packet_len(0x1fe));
  5934. WFIFOW(fd, 0)=0x1fe;
  5935. WFIFOW(fd, 2)=idx+2;
  5936. WFIFOB(fd, 4)=flag;
  5937. WFIFOSET(fd,packet_len(0x1fe));
  5938. }
  5939. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5940. /// 02bb <equip location>.W <account id>.L
  5941. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5942. {
  5943. int fd = sd->fd;
  5944. WFIFOHEAD(fd,packet_len(0x2bb));
  5945. WFIFOW(fd,0) = 0x2bb;
  5946. WFIFOW(fd,2) = position;
  5947. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5948. WFIFOSET(fd,packet_len(0x2bb));
  5949. }
  5950. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5951. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5952. void clif_item_refine_list( struct map_session_data *sd ){
  5953. nullpo_retv( sd );
  5954. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  5955. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  5956. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  5957. int refine_item[MAX_WEAPON_LEVEL];
  5958. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  5959. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  5960. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  5961. #ifdef RENEWAL
  5962. refine_item[4] = -1;
  5963. #endif
  5964. int count = 0;
  5965. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5966. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5967. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  5968. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  5969. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  5970. p->items[count].index = client_index( i );
  5971. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  5972. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  5973. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  5974. count++;
  5975. }
  5976. }
  5977. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  5978. clif_send( p, p->packetLength, &sd->bl, SELF );
  5979. if( count > 0 ){
  5980. sd->menuskill_id = WS_WEAPONREFINE;
  5981. sd->menuskill_val = skill_lv;
  5982. }
  5983. }
  5984. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5985. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5986. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  5987. nullpo_retv( sd );
  5988. struct PACKET_ZC_AUTORUN_SKILL p;
  5989. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  5990. p.skill_id = skill_id;
  5991. p.skill_type = skill_get_inf( skill_id );
  5992. p.skill_lv = skill_lv;
  5993. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  5994. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  5995. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  5996. p.up_flag = false;
  5997. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5998. }
  5999. /// Adds an item to character's cart.
  6000. /// 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)
  6001. /// 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)
  6002. /// 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)
  6003. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6004. nullpo_retv( sd );
  6005. int fd = sd->fd;
  6006. if( !session_isActive( fd ) ){
  6007. return;
  6008. }
  6009. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6010. return;
  6011. }
  6012. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6013. p.packetType = cartaddType;
  6014. p.index = client_index( n );
  6015. p.amount = amount;
  6016. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6017. #if PACKETVER >= 5
  6018. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6019. #endif
  6020. p.identified = sd->cart.u.items_cart[n].identify;
  6021. p.damaged = sd->cart.u.items_cart[n].attribute;
  6022. p.refine = sd->cart.u.items_cart[n].refine;
  6023. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6024. #if PACKETVER >= 20150226
  6025. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6026. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6027. p.enchantgrade = sd->cart.u.items_cart[n].enchantgrade;
  6028. #endif
  6029. #endif
  6030. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6031. }
  6032. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6033. /* Acknowledge an item have been added to cart
  6034. * 012c <result>B
  6035. * result :
  6036. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6037. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6038. */
  6039. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6040. {
  6041. int fd;
  6042. unsigned char *buf;
  6043. nullpo_retv(sd);
  6044. fd = sd->fd;
  6045. buf = WFIFOP(fd,0);
  6046. WBUFW(buf,0) = 0x12c;
  6047. WBUFB(buf,2) = flag;
  6048. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6049. }
  6050. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6051. void clif_bank_open(struct map_session_data *sd){
  6052. int fd;
  6053. nullpo_retv(sd);
  6054. fd = sd->fd;
  6055. WFIFOHEAD(fd,4);
  6056. WFIFOW(fd,0) = 0x09b7;
  6057. WFIFOW(fd,2) = 0;
  6058. WFIFOSET(fd,4);
  6059. }
  6060. /*
  6061. * Request to Open the banking system
  6062. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6063. */
  6064. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6065. //TODO check if preventing trade or stuff like that
  6066. //also mark something in case char ain't available for saving, should we check now ?
  6067. nullpo_retv(sd);
  6068. if( !battle_config.feature_banking ) {
  6069. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6070. return;
  6071. }
  6072. else {
  6073. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6074. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6075. if(sd->status.account_id == aid){
  6076. sd->state.banking = 1;
  6077. //request save ?
  6078. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6079. //on succes open bank ?
  6080. clif_bank_open(sd);
  6081. }
  6082. }
  6083. }
  6084. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6085. void clif_bank_close(struct map_session_data *sd){
  6086. int fd;
  6087. nullpo_retv(sd);
  6088. fd = sd->fd;
  6089. WFIFOHEAD(fd,4);
  6090. WFIFOW(fd,0) = 0x09B9;
  6091. WFIFOW(fd,2) = 0;
  6092. WFIFOSET(fd,4);
  6093. }
  6094. /*
  6095. * Request to close the banking system
  6096. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6097. */
  6098. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6099. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6100. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6101. nullpo_retv(sd);
  6102. if( !battle_config.feature_banking ) {
  6103. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6104. //still allow to go trough to not stuck player if we have disable it while they was in
  6105. }
  6106. if(sd->status.account_id == aid){
  6107. sd->state.banking = 0;
  6108. clif_bank_close(sd);
  6109. }
  6110. }
  6111. /*
  6112. * Display how much we got in bank (I suppose)
  6113. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6114. */
  6115. void clif_Bank_Check(struct map_session_data* sd) {
  6116. unsigned char buf[13];
  6117. struct s_packet_db* info;
  6118. int16 len;
  6119. int cmd = 0;
  6120. nullpo_retv(sd);
  6121. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6122. if(!cmd) cmd = 0x09A6; //default
  6123. info = &packet_db[cmd];
  6124. len = info->len;
  6125. if(!len) return; //version as packet disable
  6126. // sd->state.banking = 1; //mark opening and closing
  6127. WBUFW(buf,0) = cmd;
  6128. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6129. WBUFW(buf,info->pos[1]) = 0; //reason
  6130. clif_send(buf,len,&sd->bl,SELF);
  6131. }
  6132. /*
  6133. * Requesting the data in bank
  6134. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6135. */
  6136. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6137. nullpo_retv(sd);
  6138. if( !battle_config.feature_banking ) {
  6139. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6140. return;
  6141. }
  6142. else {
  6143. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6144. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6145. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6146. clif_Bank_Check(sd);
  6147. }
  6148. }
  6149. /*
  6150. * Acknowledge of deposit some money in bank
  6151. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6152. */
  6153. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6154. unsigned char buf[17];
  6155. struct s_packet_db* info;
  6156. int16 len;
  6157. int cmd =0;
  6158. nullpo_retv(sd);
  6159. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6160. if(!cmd) cmd = 0x09A8;
  6161. info = &packet_db[cmd];
  6162. len = info->len;
  6163. if(!len) return; //version as packet disable
  6164. WBUFW(buf,0) = cmd;
  6165. WBUFW(buf,info->pos[0]) = (short)reason;
  6166. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6167. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6168. clif_send(buf,len,&sd->bl,SELF);
  6169. }
  6170. /*
  6171. * Request saving some money in bank
  6172. * @author : original [Yommy/Hercules]
  6173. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6174. */
  6175. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6176. nullpo_retv(sd);
  6177. if( !battle_config.feature_banking ) {
  6178. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6179. return;
  6180. }
  6181. else {
  6182. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6183. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6184. int money = RFIFOL(fd,info->pos[1]);
  6185. if(sd->status.account_id == aid){
  6186. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6187. clif_bank_deposit(sd,reason);
  6188. }
  6189. }
  6190. }
  6191. /*
  6192. * Acknowledge of withdrawing some money from bank
  6193. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6194. */
  6195. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6196. unsigned char buf[17];
  6197. struct s_packet_db* info;
  6198. int16 len;
  6199. int cmd;
  6200. nullpo_retv(sd);
  6201. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6202. if(!cmd) cmd = 0x09AA;
  6203. info = &packet_db[cmd];
  6204. len = info->len;
  6205. if(!len) return; //version as packet disable
  6206. WBUFW(buf,0) = cmd;
  6207. WBUFW(buf,info->pos[0]) = (short)reason;
  6208. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6209. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6210. clif_send(buf,len,&sd->bl,SELF);
  6211. }
  6212. /*
  6213. * Request Withdrawing some money from bank
  6214. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6215. */
  6216. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6217. nullpo_retv(sd);
  6218. if( !battle_config.feature_banking ) {
  6219. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6220. return;
  6221. }
  6222. else {
  6223. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6224. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6225. int money = RFIFOL(fd,info->pos[1]);
  6226. if(sd->status.account_id == aid){
  6227. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6228. clif_bank_withdraw(sd,reason);
  6229. }
  6230. }
  6231. }
  6232. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6233. /// 0125 <index>.W <amount>.L
  6234. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6235. {
  6236. int fd;
  6237. nullpo_retv(sd);
  6238. fd=sd->fd;
  6239. WFIFOHEAD(fd,packet_len(0x125));
  6240. WFIFOW(fd,0)=0x125;
  6241. WFIFOW(fd,2)=n+2;
  6242. WFIFOL(fd,4)=amount;
  6243. WFIFOSET(fd,packet_len(0x125));
  6244. }
  6245. /// Opens the shop creation menu (ZC_OPENSTORE).
  6246. /// 012d <num>.W
  6247. /// num:
  6248. /// number of allowed item slots
  6249. void clif_openvendingreq(struct map_session_data* sd, int num)
  6250. {
  6251. int fd;
  6252. nullpo_retv(sd);
  6253. fd = sd->fd;
  6254. WFIFOHEAD(fd,packet_len(0x12d));
  6255. WFIFOW(fd,0) = 0x12d;
  6256. WFIFOW(fd,2) = num;
  6257. WFIFOSET(fd,packet_len(0x12d));
  6258. }
  6259. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6260. /// 0131 <owner id>.L <message>.80B
  6261. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6262. {
  6263. unsigned char buf[128];
  6264. nullpo_retv(bl);
  6265. WBUFW(buf,0) = 0x131;
  6266. WBUFL(buf,2) = bl->id;
  6267. safestrncpy(WBUFCP(buf,6), message, 80);
  6268. if( session_isActive(fd) ) {
  6269. WFIFOHEAD(fd,packet_len(0x131));
  6270. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6271. WFIFOSET(fd,packet_len(0x131));
  6272. } else {
  6273. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6274. }
  6275. }
  6276. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6277. /// 0132 <owner id>.L
  6278. void clif_closevendingboard(struct block_list* bl, int fd)
  6279. {
  6280. unsigned char buf[16];
  6281. nullpo_retv(bl);
  6282. WBUFW(buf,0) = 0x132;
  6283. WBUFL(buf,2) = bl->id;
  6284. if( session_isActive(fd) ) {
  6285. WFIFOHEAD(fd,packet_len(0x132));
  6286. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6287. WFIFOSET(fd,packet_len(0x132));
  6288. } else {
  6289. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6290. }
  6291. }
  6292. /// Sends a list of items in a shop.
  6293. /// 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)
  6294. /// 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)
  6295. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6296. nullpo_retv( sd );
  6297. nullpo_retv( vsd );
  6298. nullpo_retv( vsd->vending );
  6299. int fd = sd->fd;
  6300. if( !session_isActive( fd ) ){
  6301. return;
  6302. }
  6303. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6304. WFIFOHEAD( fd, len );
  6305. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6306. p->packetType = vendinglistType;
  6307. p->packetLength = len;
  6308. p->AID = vsd->status.account_id;
  6309. #if PACKETVER >= 20100105
  6310. p->venderId = vsd->vender_id;
  6311. #endif
  6312. for( int i = 0; i < vsd->vend_num; i++ ){
  6313. int index = vsd->vending[i].index;
  6314. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6315. p->items[i].price = vsd->vending[i].value;
  6316. p->items[i].amount = vsd->vending[i].amount;
  6317. p->items[i].index = client_index( index );
  6318. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6319. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6320. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6321. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6322. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6323. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6324. #if PACKETVER >= 20150226
  6325. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6326. #if PACKETVER >= 20160921
  6327. p->items[i].location = pc_equippoint_sub( sd, data );
  6328. p->items[i].viewSprite = data->look;
  6329. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6330. p->items[i].enchantgrade = vsd->cart.u.items_cart[index].enchantgrade;
  6331. #endif
  6332. #endif
  6333. #endif
  6334. }
  6335. WFIFOSET( fd, len );
  6336. }
  6337. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6338. /// 0135 <index>.W <amount>.W <result>.B
  6339. /// result:
  6340. /// 0 = success
  6341. /// 1 = not enough zeny
  6342. /// 2 = overweight
  6343. /// 4 = out of stock
  6344. /// 5 = "cannot use an npc shop while in a trade"
  6345. /// 6 = Because the store information was incorrect the item was not purchased.
  6346. /// 7 = No sales information.
  6347. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6348. {
  6349. int fd;
  6350. nullpo_retv(sd);
  6351. fd = sd->fd;
  6352. WFIFOHEAD(fd,packet_len(0x135));
  6353. WFIFOW(fd,0) = 0x135;
  6354. WFIFOW(fd,2) = index+2;
  6355. WFIFOW(fd,4) = amount;
  6356. WFIFOB(fd,6) = fail;
  6357. WFIFOSET(fd,packet_len(0x135));
  6358. }
  6359. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6360. /// 0a28 <Result>.B
  6361. /// result:
  6362. /// 0 = Successed
  6363. /// 1 = Failed
  6364. void clif_openvending_ack(struct map_session_data* sd, int result)
  6365. {
  6366. int fd;
  6367. nullpo_retv(sd);
  6368. fd = sd->fd;
  6369. WFIFOHEAD(fd, 3);
  6370. WFIFOW(fd,0) = 0xa28;
  6371. WFIFOB(fd,2) = result;
  6372. WFIFOSET(fd, 3);
  6373. }
  6374. /// Shop creation success.
  6375. /// 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)
  6376. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6377. nullpo_retv( sd );
  6378. nullpo_retv( vending );
  6379. int fd = sd->fd;
  6380. if( !session_isActive( fd ) ){
  6381. return;
  6382. }
  6383. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6384. WFIFOHEAD( fd, len );
  6385. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6386. p->packetType = openvendingType;
  6387. p->packetLength = len;
  6388. p->AID = id;
  6389. for( int i = 0; i < sd->vend_num; i++ ) {
  6390. int index = vending[i].index;
  6391. p->items[i].price = vending[i].value;
  6392. p->items[i].index = client_index( index );
  6393. p->items[i].amount = vending[i].amount;
  6394. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6395. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6396. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6397. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6398. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6399. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6400. #if PACKETVER >= 20150226
  6401. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6402. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6403. p->items[i].enchantgrade = sd->cart.u.items_cart[index].enchantgrade;
  6404. #endif
  6405. #endif
  6406. }
  6407. WFIFOSET( fd, len );
  6408. #if PACKETVER >= 20141022
  6409. /// 0 = Successed
  6410. /// 1 = Failed
  6411. clif_openvending_ack( sd, 0 );
  6412. #endif
  6413. }
  6414. /// Inform merchant that someone has bought an item.
  6415. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6416. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6417. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6418. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6419. const int cmd = 0x137;
  6420. #else
  6421. const int cmd = 0x9e5;
  6422. #endif
  6423. int fd = sd->fd;
  6424. nullpo_retv(sd);
  6425. WFIFOHEAD(fd,packet_len(cmd));
  6426. WFIFOW(fd,0) = cmd;
  6427. WFIFOW(fd,2) = index+2;
  6428. WFIFOW(fd,4) = amount;
  6429. #if PACKETVER >= 20141016
  6430. WFIFOL(fd,6) = char_id; // GID
  6431. WFIFOL(fd,10) = (int)time(NULL); // Date
  6432. WFIFOL(fd,14) = zeny; // zeny
  6433. #endif
  6434. WFIFOSET(fd,packet_len(cmd));
  6435. }
  6436. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6437. /// 00fa <result>.B
  6438. /// result:
  6439. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6440. /// 1 = MsgStringTable[78]="party name already exists"
  6441. /// 2 = MsgStringTable[79]="already in a party"
  6442. /// 3 = cannot organize parties on this map
  6443. /// ? = nothing
  6444. void clif_party_created(struct map_session_data *sd,int result)
  6445. {
  6446. int fd;
  6447. nullpo_retv(sd);
  6448. fd=sd->fd;
  6449. WFIFOHEAD(fd,packet_len(0xfa));
  6450. WFIFOW(fd,0)=0xfa;
  6451. WFIFOB(fd,2)=result;
  6452. WFIFOSET(fd,packet_len(0xfa));
  6453. }
  6454. /// Adds new member to a party.
  6455. /// 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)
  6456. /// 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)
  6457. /// 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)
  6458. /// role:
  6459. /// 0 = leader
  6460. /// 1 = normal
  6461. /// state:
  6462. /// 0 = connected
  6463. /// 1 = disconnected
  6464. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6465. {
  6466. int i;
  6467. #if PACKETVER < 20170502
  6468. unsigned char buf[81];
  6469. int cmd = 0x1e9;
  6470. int offset = 0;
  6471. #else
  6472. unsigned char buf[85];
  6473. int cmd = 0xa43;
  6474. int offset = 4;
  6475. #endif
  6476. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6477. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6478. } else {
  6479. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6480. }
  6481. if (i >= MAX_PARTY) return; //Should never happen...
  6482. sd = p->data[i].sd;
  6483. WBUFW(buf, 0) = cmd;
  6484. WBUFL(buf, 2) = sd->status.account_id;
  6485. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6486. #if PACKETVER >= 20170502
  6487. WBUFW(buf,10) = sd->status.class_;
  6488. WBUFW(buf,12) = sd->status.base_level;
  6489. #endif
  6490. WBUFW(buf,offset+10) = sd->bl.x;
  6491. WBUFW(buf,offset+12) = sd->bl.y;
  6492. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6493. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6494. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6495. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6496. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6497. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6498. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6499. }
  6500. /// Sends party information (ZC_GROUP_LIST).
  6501. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6502. /// role:
  6503. /// 0 = leader
  6504. /// 1 = normal
  6505. /// state:
  6506. /// 0 = connected
  6507. /// 1 = disconnected
  6508. /// 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
  6509. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6510. {
  6511. struct map_session_data* party_sd = NULL;
  6512. int i, c;
  6513. #if PACKETVER < 20170502
  6514. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6515. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6516. int cmd = 0xfb;
  6517. #else
  6518. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6519. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6520. int cmd = 0xa44;
  6521. #endif
  6522. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6523. nullpo_retv(p);
  6524. WBUFW(buf,0) = cmd;
  6525. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6526. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6527. {
  6528. struct party_member* m = &p->party.member[i];
  6529. if(!m->account_id) continue;
  6530. if(party_sd == NULL) party_sd = p->data[i].sd;
  6531. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6532. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6533. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6534. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6535. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6536. #if PACKETVER >= 20170502
  6537. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6538. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6539. #endif
  6540. c++;
  6541. }
  6542. #if PACKETVER < 20170502
  6543. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6544. #else
  6545. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6546. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6547. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6548. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6549. #endif
  6550. if(sd) { // send only to self
  6551. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6552. } else if (party_sd) { // send to whole party
  6553. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6554. }
  6555. }
  6556. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6557. /// 02c9 <flag>.B
  6558. /// flag:
  6559. /// 0 = allow party invites
  6560. /// 1 = auto-deny party invites
  6561. void clif_partyinvitationstate(struct map_session_data* sd)
  6562. {
  6563. int fd;
  6564. nullpo_retv(sd);
  6565. fd = sd->fd;
  6566. WFIFOHEAD(fd, packet_len(0x2c9));
  6567. WFIFOW(fd, 0) = 0x2c9;
  6568. WFIFOB(fd, 2) = 0; // not implemented
  6569. WFIFOSET(fd, packet_len(0x2c9));
  6570. }
  6571. /// Party invitation request.
  6572. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6573. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6574. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6575. {
  6576. #if PACKETVER < 20070821
  6577. const int cmd = 0xfe;
  6578. #else
  6579. const int cmd = 0x2c6;
  6580. #endif
  6581. int fd;
  6582. struct party_data *p;
  6583. nullpo_retv(sd);
  6584. nullpo_retv(tsd);
  6585. fd=tsd->fd;
  6586. if( (p=party_search(sd->status.party_id))==NULL )
  6587. return;
  6588. WFIFOHEAD(fd,packet_len(cmd));
  6589. WFIFOW(fd,0)=cmd;
  6590. WFIFOL(fd,2)=sd->status.party_id;
  6591. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6592. WFIFOSET(fd,packet_len(cmd));
  6593. }
  6594. /// Party invite result.
  6595. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6596. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6597. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6598. {
  6599. int fd;
  6600. nullpo_retv(sd);
  6601. fd=sd->fd;
  6602. #if PACKETVER < 20070904
  6603. if( reply == PARTY_REPLY_OFFLINE ) {
  6604. clif_displaymessage(fd, msg_txt(sd,3));
  6605. return;
  6606. }
  6607. #endif
  6608. #if PACKETVER < 20070821
  6609. WFIFOHEAD(fd,packet_len(0xfd));
  6610. WFIFOW(fd,0) = 0xfd;
  6611. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6612. WFIFOB(fd,26) = reply;
  6613. WFIFOSET(fd,packet_len(0xfd));
  6614. #else
  6615. WFIFOHEAD(fd,packet_len(0x2c5));
  6616. WFIFOW(fd,0) = 0x2c5;
  6617. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6618. WFIFOL(fd,26) = reply;
  6619. WFIFOSET(fd,packet_len(0x2c5));
  6620. #endif
  6621. }
  6622. /// Updates party settings.
  6623. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6624. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6625. /// exp option:
  6626. /// 0 = exp sharing disabled
  6627. /// 1 = exp sharing enabled
  6628. /// 2 = cannot change exp sharing
  6629. ///
  6630. /// flag:
  6631. /// 0 = send to party
  6632. /// 1 = send to sd
  6633. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6634. {
  6635. unsigned char buf[16];
  6636. #if PACKETVER < 20090603
  6637. const int cmd = 0x101;
  6638. #else
  6639. const int cmd = 0x7d8;
  6640. #endif
  6641. nullpo_retv(p);
  6642. if(!sd && flag==0){
  6643. int i;
  6644. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6645. if (i < MAX_PARTY)
  6646. sd = p->data[i].sd;
  6647. }
  6648. if(!sd) return;
  6649. WBUFW(buf,0)=cmd;
  6650. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6651. #if PACKETVER >= 20090603
  6652. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6653. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6654. #endif
  6655. if(flag==0)
  6656. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6657. else
  6658. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6659. }
  6660. /**
  6661. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6662. * @param sd Send the notification for this player
  6663. * @param account_id Account ID of kicked member
  6664. * @param name Name of kicked member
  6665. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6666. * @param target Send target
  6667. **/
  6668. 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) {
  6669. unsigned char buf[2+4+NAME_LENGTH+1];
  6670. if (!sd)
  6671. return;
  6672. WBUFW(buf,0) = 0x0105;
  6673. WBUFL(buf,2) = account_id;
  6674. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6675. WBUFB(buf,6+NAME_LENGTH) = result;
  6676. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6677. }
  6678. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6679. /// 0109 <packet len>.W <account id>.L <message>.?B
  6680. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6681. {
  6682. struct map_session_data *sd;
  6683. int i;
  6684. nullpo_retv(p);
  6685. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6686. if(i < MAX_PARTY){
  6687. unsigned char buf[1024];
  6688. if( len > sizeof(buf)-8 )
  6689. {
  6690. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6691. len = sizeof(buf)-8;
  6692. }
  6693. sd = p->data[i].sd;
  6694. WBUFW(buf,0)=0x109;
  6695. WBUFW(buf,2)=len+8;
  6696. WBUFL(buf,4)=account_id;
  6697. safestrncpy(WBUFCP(buf,8), mes, len);
  6698. clif_send(buf,len+8,&sd->bl,PARTY);
  6699. }
  6700. }
  6701. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6702. /// 0107 <account id>.L <x>.W <y>.W
  6703. void clif_party_xy(struct map_session_data *sd)
  6704. {
  6705. unsigned char buf[16];
  6706. nullpo_retv(sd);
  6707. WBUFW(buf,0)=0x107;
  6708. WBUFL(buf,2)=sd->status.account_id;
  6709. WBUFW(buf,6)=sd->bl.x;
  6710. WBUFW(buf,8)=sd->bl.y;
  6711. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6712. }
  6713. /*==========================================
  6714. * Sends x/y dot to a single fd. [Skotlex]
  6715. *------------------------------------------*/
  6716. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6717. {
  6718. WFIFOHEAD(fd,packet_len(0x107));
  6719. WFIFOW(fd,0)=0x107;
  6720. WFIFOL(fd,2)=sd->status.account_id;
  6721. WFIFOW(fd,6)=sd->bl.x;
  6722. WFIFOW(fd,8)=sd->bl.y;
  6723. WFIFOSET(fd,packet_len(0x107));
  6724. }
  6725. /// Updates HP bar of a party member.
  6726. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6727. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6728. void clif_party_hp(struct map_session_data *sd)
  6729. {
  6730. unsigned char buf[16];
  6731. #if PACKETVER < 20100126
  6732. const int cmd = 0x106;
  6733. #else
  6734. const int cmd = 0x80e;
  6735. #endif
  6736. nullpo_retv(sd);
  6737. WBUFW(buf,0)=cmd;
  6738. WBUFL(buf,2)=sd->status.account_id;
  6739. #if PACKETVER < 20100126
  6740. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6741. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6742. WBUFW(buf,8) = 100;
  6743. } else {
  6744. WBUFW(buf,6) = sd->battle_status.hp;
  6745. WBUFW(buf,8) = sd->battle_status.max_hp;
  6746. }
  6747. #else
  6748. WBUFL(buf,6) = sd->battle_status.hp;
  6749. WBUFL(buf,10) = sd->battle_status.max_hp;
  6750. #endif
  6751. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6752. }
  6753. /// Notifies the party members of a character's death or revival.
  6754. /// 0AB2 <GID>.L <dead>.B
  6755. void clif_party_dead( struct map_session_data *sd ){
  6756. #if PACKETVER >= 20170502
  6757. unsigned char buf[7];
  6758. nullpo_retv(sd);
  6759. WBUFW(buf, 0) = 0xab2;
  6760. WBUFL(buf, 2) = sd->status.account_id;
  6761. WBUFB(buf, 6) = pc_isdead(sd);
  6762. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6763. #endif
  6764. }
  6765. /// Updates the job and level of a party member
  6766. /// 0abd <account id>.L <job>.W <level>.W
  6767. void clif_party_job_and_level(struct map_session_data *sd){
  6768. #if PACKETVER >= 20170502
  6769. unsigned char buf[10];
  6770. nullpo_retv(sd);
  6771. WBUFW(buf, 0) = 0xabd;
  6772. WBUFL(buf, 2) = sd->status.account_id;
  6773. WBUFW(buf, 6) = sd->status.class_;
  6774. WBUFW(buf, 8) = sd->status.base_level;
  6775. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6776. #endif
  6777. }
  6778. /*==========================================
  6779. * Sends HP bar to a single fd. [Skotlex]
  6780. *------------------------------------------*/
  6781. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6782. {
  6783. #if PACKETVER < 20100126
  6784. const int cmd = 0x106;
  6785. #else
  6786. const int cmd = 0x80e;
  6787. #endif
  6788. WFIFOHEAD(fd,packet_len(cmd));
  6789. WFIFOW(fd,0) = cmd;
  6790. WFIFOL(fd,2) = id;
  6791. #if PACKETVER < 20100126
  6792. if( maxhp > INT16_MAX )
  6793. {// To correctly display the %hp bar. [Skotlex]
  6794. WFIFOW(fd,6) = hp/(maxhp/100);
  6795. WFIFOW(fd,8) = 100;
  6796. } else {
  6797. WFIFOW(fd,6) = hp;
  6798. WFIFOW(fd,8) = maxhp;
  6799. }
  6800. #else
  6801. WFIFOL(fd,6) = hp;
  6802. WFIFOL(fd,10) = maxhp;
  6803. #endif
  6804. WFIFOSET(fd, packet_len(cmd));
  6805. }
  6806. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6807. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6808. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6809. {
  6810. int fd;
  6811. nullpo_retv(sd);
  6812. nullpo_retv(bl);
  6813. fd=sd->fd;
  6814. WFIFOHEAD(fd,packet_len(0x139));
  6815. WFIFOW(fd, 0)=0x139;
  6816. WFIFOL(fd, 2)=bl->id;
  6817. WFIFOW(fd, 6)=bl->x;
  6818. WFIFOW(fd, 8)=bl->y;
  6819. WFIFOW(fd,10)=sd->bl.x;
  6820. WFIFOW(fd,12)=sd->bl.y;
  6821. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6822. WFIFOSET(fd,packet_len(0x139));
  6823. }
  6824. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6825. /// 018f <result>.W <name id>.W
  6826. /// result:
  6827. /// 0 = success
  6828. /// 1 = failure
  6829. /// 2 = success (alchemist)
  6830. /// 3 = failure (alchemist)
  6831. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  6832. nullpo_retv( sd );
  6833. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6834. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6835. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6836. p.result = flag;
  6837. p.itemId = client_nameid( nameid );
  6838. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6839. }
  6840. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6841. /// 019e
  6842. void clif_catch_process(struct map_session_data *sd)
  6843. {
  6844. int fd;
  6845. nullpo_retv(sd);
  6846. fd=sd->fd;
  6847. WFIFOHEAD(fd,packet_len(0x19e));
  6848. WFIFOW(fd,0)=0x19e;
  6849. WFIFOSET(fd,packet_len(0x19e));
  6850. }
  6851. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6852. /// 01a0 <result>.B
  6853. /// 0 = failure
  6854. /// 1 = success
  6855. void clif_pet_roulette(struct map_session_data *sd,int data)
  6856. {
  6857. int fd;
  6858. nullpo_retv(sd);
  6859. fd=sd->fd;
  6860. WFIFOHEAD(fd,packet_len(0x1a0));
  6861. WFIFOW(fd,0)=0x1a0;
  6862. WFIFOB(fd,2)=data;
  6863. WFIFOSET(fd,packet_len(0x1a0));
  6864. }
  6865. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6866. /// 01a6 <packet len>.W { <index>.W }*
  6867. void clif_sendegg(struct map_session_data *sd)
  6868. {
  6869. int i,n=0,fd;
  6870. nullpo_retv(sd);
  6871. fd=sd->fd;
  6872. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6873. clif_displaymessage(fd, msg_txt(sd,666));
  6874. return;
  6875. }
  6876. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6877. WFIFOW(fd,0)=0x1a6;
  6878. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6879. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  6880. sd->inventory_data[i]->type != IT_PETEGG ||
  6881. sd->inventory.u.items_inventory[i].amount <= 0)
  6882. continue;
  6883. WFIFOW(fd,n*2+4)=client_index(i);
  6884. n++;
  6885. }
  6886. WFIFOW(fd,2)=4+n*2;
  6887. WFIFOSET(fd,WFIFOW(fd,2));
  6888. sd->menuskill_id = SA_TAMINGMONSTER;
  6889. sd->menuskill_val = -1;
  6890. }
  6891. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6892. /// 01a4 <type>.B <id>.L <data>.L
  6893. /// type:
  6894. /// 0 = pre-init (data = 0)
  6895. /// 1 = intimacy (data = 0~4)
  6896. /// 2 = hunger (data = 0~4)
  6897. /// 3 = accessory
  6898. /// 4 = performance (data = 1~3: normal, 4: special)
  6899. /// 5 = hairstyle
  6900. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6901. ///
  6902. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6903. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6904. {
  6905. uint8 buf[16];
  6906. nullpo_retv(pd);
  6907. WBUFW(buf,0) = 0x1a4;
  6908. WBUFB(buf,2) = type;
  6909. WBUFL(buf,3) = pd->bl.id;
  6910. WBUFL(buf,7) = param;
  6911. if (sd)
  6912. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6913. else
  6914. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6915. }
  6916. /// Pet's base data (ZC_PROPERTY_PET).
  6917. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6918. void clif_send_petstatus(struct map_session_data *sd)
  6919. {
  6920. int fd;
  6921. struct s_pet *pet;
  6922. nullpo_retv(sd);
  6923. nullpo_retv(sd->pd);
  6924. fd=sd->fd;
  6925. pet = &sd->pd->pet;
  6926. WFIFOHEAD(fd,packet_len(0x1a2));
  6927. WFIFOW(fd,0)=0x1a2;
  6928. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6929. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6930. WFIFOW(fd,27)=pet->level;
  6931. WFIFOW(fd,29)=pet->hungry;
  6932. WFIFOW(fd,31)=pet->intimate;
  6933. WFIFOW(fd,33)=pet->equip;
  6934. #if PACKETVER >= 20081126
  6935. WFIFOW(fd,35)=pet->class_;
  6936. #endif
  6937. WFIFOSET(fd,packet_len(0x1a2));
  6938. }
  6939. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6940. /// 01aa <id>.L <data>.L
  6941. /// data:
  6942. /// @see CZ_PET_ACT.
  6943. void clif_pet_emotion(struct pet_data *pd,int param)
  6944. {
  6945. unsigned char buf[16];
  6946. nullpo_retv(pd);
  6947. memset(buf,0,packet_len(0x1aa));
  6948. WBUFW(buf,0)=0x1aa;
  6949. WBUFL(buf,2)=pd->bl.id;
  6950. WBUFL(buf,6)=param;
  6951. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6952. }
  6953. /// Result of request to feed a pet (ZC_FEED_PET).
  6954. /// 01a3 <result>.B <name id>.W
  6955. /// result:
  6956. /// 0 = failure
  6957. /// 1 = success
  6958. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  6959. nullpo_retv( sd );
  6960. struct PACKET_ZC_FEED_PET p;
  6961. p.packetType = 0x1a3;
  6962. p.result = fail;
  6963. p.itemId = client_nameid( foodid );
  6964. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6965. }
  6966. /// Send pet auto feed info.
  6967. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  6968. #if PACKETVER >= 20141008
  6969. nullpo_retv(sd);
  6970. if (force || battle_config.pet_autofeed_always) {
  6971. // Always send ON or OFF
  6972. if (sd->pd && battle_config.feature_pet_autofeed) {
  6973. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  6974. }
  6975. else {
  6976. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  6977. }
  6978. }
  6979. else {
  6980. // Only send when enabled
  6981. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  6982. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  6983. }
  6984. }
  6985. #endif
  6986. }
  6987. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6988. /// 01cd { <skill id>.L }*7
  6989. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6990. {
  6991. nullpo_retv(sd);
  6992. int fd = sd->fd;
  6993. #ifdef RENEWAL
  6994. uint16 autospell_skill[][2] = {
  6995. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  6996. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  6997. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  6998. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  6999. };
  7000. int count = 0;
  7001. WFIFOHEAD(fd, 2 * 6 + 4);
  7002. WFIFOW(fd, 0) = 0x442;
  7003. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7004. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7005. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7006. count++;
  7007. }
  7008. }
  7009. WFIFOW(fd, 2) = 8 + count * 2;
  7010. WFIFOL(fd, 4) = count;
  7011. WFIFOSET(fd, WFIFOW(fd, 2));
  7012. #else
  7013. WFIFOHEAD(fd,packet_len(0x1cd));
  7014. WFIFOW(fd, 0)=0x1cd;
  7015. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7016. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7017. else
  7018. WFIFOL(fd,2)= 0x00000000;
  7019. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7020. WFIFOL(fd,6)= MG_COLDBOLT;
  7021. else
  7022. WFIFOL(fd,6)= 0x00000000;
  7023. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7024. WFIFOL(fd,10)= MG_FIREBOLT;
  7025. else
  7026. WFIFOL(fd,10)= 0x00000000;
  7027. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7028. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7029. else
  7030. WFIFOL(fd,14)= 0x00000000;
  7031. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7032. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7033. else
  7034. WFIFOL(fd,18)= 0x00000000;
  7035. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7036. WFIFOL(fd,22)= MG_FIREBALL;
  7037. else
  7038. WFIFOL(fd,22)= 0x00000000;
  7039. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7040. WFIFOL(fd,26)= MG_FROSTDIVER;
  7041. else
  7042. WFIFOL(fd,26)= 0x00000000;
  7043. WFIFOSET(fd,packet_len(0x1cd));
  7044. #endif
  7045. sd->menuskill_id = SA_AUTOSPELL;
  7046. sd->menuskill_val = skill_lv;
  7047. }
  7048. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7049. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7050. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7051. {
  7052. unsigned char buf[56];
  7053. nullpo_retv(src);
  7054. memset(buf,0,packet_len(0x1cf));
  7055. WBUFW(buf,0) = 0x1cf;
  7056. WBUFL(buf,2) = src->id;
  7057. if( src->type == BL_MER )
  7058. {
  7059. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7060. if( md && md->master && md->devotion_flag )
  7061. WBUFL(buf,6) = md->master->bl.id;
  7062. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7063. }
  7064. else
  7065. {
  7066. int i;
  7067. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7068. if( sd == NULL )
  7069. return;
  7070. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7071. WBUFL(buf,6+4*i) = sd->devotion[i];
  7072. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7073. }
  7074. if( tsd )
  7075. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7076. else
  7077. clif_send(buf, packet_len(0x1cf), src, AREA);
  7078. }
  7079. /// Notifies the client of an object's spirits.
  7080. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7081. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7082. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7083. nullpo_retv( bl );
  7084. struct PACKET_ZC_SPIRITS p = {};
  7085. p.packetType = HEADER_ZC_SPIRITS;
  7086. p.GID = bl->id;
  7087. switch( bl->type ){
  7088. case BL_PC:
  7089. p.amount = ( (struct map_session_data*)bl )->spiritball;
  7090. break;
  7091. case BL_HOM:
  7092. p.amount = ( (struct homun_data*)bl )->homunculus.spiritball;
  7093. break;
  7094. }
  7095. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7096. }
  7097. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7098. /// 01d2 <account id>.L <delay>.L
  7099. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7100. {
  7101. unsigned char buf[32];
  7102. nullpo_retv(bl);
  7103. WBUFW(buf,0)=0x1d2;
  7104. WBUFL(buf,2)=bl->id;
  7105. WBUFL(buf,6)=client_tick(wait);
  7106. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7107. }
  7108. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7109. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7110. /// flag:
  7111. /// 0 = inactive
  7112. /// 1 = active
  7113. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7114. {
  7115. unsigned char buf[32];
  7116. nullpo_retv(src);
  7117. WBUFW(buf,0)=0x1d1;
  7118. WBUFL(buf,2)=src->id;
  7119. WBUFL(buf,6)=dst_id;
  7120. WBUFL(buf,10)=active;
  7121. clif_send(buf,packet_len(0x1d1),src,AREA);
  7122. }
  7123. /// MVP effect (ZC_MVP).
  7124. /// 010c <account id>.L
  7125. void clif_mvp_effect(struct map_session_data *sd)
  7126. {
  7127. unsigned char buf[16];
  7128. nullpo_retv(sd);
  7129. WBUFW(buf,0)=0x10c;
  7130. WBUFL(buf,2)=sd->bl.id;
  7131. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7132. }
  7133. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7134. /// 010a <name id>.W
  7135. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7136. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7137. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7138. p.itemId = client_nameid( nameid );
  7139. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7140. }
  7141. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7142. /// 010b <exp>.L
  7143. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7144. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7145. if (battle_config.mvp_exp_reward_message) {
  7146. char e_msg[CHAT_SIZE_MAX];
  7147. sprintf(e_msg, msg_txt(sd, 717), exp);
  7148. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7149. }
  7150. #else
  7151. int fd;
  7152. nullpo_retv(sd);
  7153. fd = sd->fd;
  7154. WFIFOHEAD(fd, packet_len(0x10b));
  7155. WFIFOW(fd,0) = 0x10b;
  7156. WFIFOL(fd,2) = (uint32)min( exp, MAX_EXP );
  7157. WFIFOSET(fd, packet_len(0x10b));
  7158. #endif
  7159. }
  7160. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7161. /// 010d
  7162. ///
  7163. /// "You are the MVP, but cannot obtain the reward because
  7164. /// you are overweight."
  7165. void clif_mvp_noitem(struct map_session_data* sd)
  7166. {
  7167. int fd = sd->fd;
  7168. WFIFOHEAD(fd,packet_len(0x10d));
  7169. WFIFOW(fd,0) = 0x10d;
  7170. WFIFOSET(fd,packet_len(0x10d));
  7171. }
  7172. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7173. /// 0167 <result>.B
  7174. /// result:
  7175. /// 0 = "Guild has been created."
  7176. /// 1 = "You are already in a Guild."
  7177. /// 2 = "That Guild Name already exists."
  7178. /// 3 = "You need the neccessary item to create a Guild."
  7179. void clif_guild_created(struct map_session_data *sd,int flag)
  7180. {
  7181. int fd;
  7182. nullpo_retv(sd);
  7183. fd=sd->fd;
  7184. WFIFOHEAD(fd,packet_len(0x167));
  7185. WFIFOW(fd,0)=0x167;
  7186. WFIFOB(fd,2)=flag;
  7187. WFIFOSET(fd,packet_len(0x167));
  7188. }
  7189. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7190. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7191. /// mode:
  7192. /// &0x01 = allow invite
  7193. /// &0x10 = allow expel
  7194. void clif_guild_belonginfo(struct map_session_data *sd)
  7195. {
  7196. int ps,fd;
  7197. struct guild* g;
  7198. nullpo_retv(sd);
  7199. nullpo_retv(g = sd->guild);
  7200. fd=sd->fd;
  7201. ps=guild_getposition(sd);
  7202. WFIFOHEAD(fd,packet_len(0x16c));
  7203. WFIFOW(fd,0)=0x16c;
  7204. WFIFOL(fd,2)=g->guild_id;
  7205. WFIFOL(fd,6)=g->emblem_id;
  7206. WFIFOL(fd,10)=g->position[ps].mode;
  7207. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7208. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7209. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7210. WFIFOSET(fd,packet_len(0x16c));
  7211. }
  7212. /// Guild member login notice.
  7213. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7214. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7215. /// status:
  7216. /// 0 = offline
  7217. /// 1 = online
  7218. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7219. {
  7220. unsigned char buf[64];
  7221. struct map_session_data* sd;
  7222. nullpo_retv(g);
  7223. WBUFW(buf, 0)=0x1f2;
  7224. WBUFL(buf, 2)=g->member[idx].account_id;
  7225. WBUFL(buf, 6)=g->member[idx].char_id;
  7226. WBUFL(buf,10)=flag;
  7227. if( ( sd = g->member[idx].sd ) != NULL )
  7228. {
  7229. WBUFW(buf,14) = sd->status.sex;
  7230. WBUFW(buf,16) = sd->status.hair;
  7231. WBUFW(buf,18) = sd->status.hair_color;
  7232. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7233. }
  7234. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7235. {
  7236. WBUFW(buf,14) = 0;
  7237. WBUFW(buf,16) = 0;
  7238. WBUFW(buf,18) = 0;
  7239. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7240. }
  7241. }
  7242. // Function `clif_guild_memberlogin_notice` sends info about
  7243. // logins and logouts of a guild member to the rest members.
  7244. // But at the 1st time (after a player login or map changing)
  7245. // the client won't show the message.
  7246. // So I suggest use this function for sending "first-time-info"
  7247. // to some player on entering the game or changing location.
  7248. // At next time the client would always show the message.
  7249. // The function sends all the statuses in the single packet
  7250. // to economize traffic. [LuzZza]
  7251. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7252. {
  7253. struct guild *g;
  7254. unsigned char buf[14*128];
  7255. int i, count=0, p_len;
  7256. nullpo_retv(sd);
  7257. p_len = packet_len(0x16d);
  7258. if(!(g = sd->guild))
  7259. return;
  7260. for(i=0; i<g->max_member; i++) {
  7261. if(g->member[i].account_id > 0 &&
  7262. g->member[i].account_id != sd->status.account_id) {
  7263. WBUFW(buf,count*p_len) = 0x16d;
  7264. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7265. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7266. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7267. count++;
  7268. }
  7269. }
  7270. clif_send(buf, p_len*count, &sd->bl, SELF);
  7271. }
  7272. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7273. /// 014e <menu flag>.L
  7274. /// menu flag:
  7275. /// 0x00 = Basic Info (always on)
  7276. /// &0x01 = Member manager
  7277. /// &0x02 = Positions
  7278. /// &0x04 = Skills
  7279. /// &0x10 = Expulsion list
  7280. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7281. /// &0x80 = Notice
  7282. void clif_guild_masterormember(struct map_session_data *sd)
  7283. {
  7284. int fd;
  7285. nullpo_retv(sd);
  7286. fd=sd->fd;
  7287. WFIFOHEAD(fd,packet_len(0x14e));
  7288. WFIFOW(fd,0) = 0x14e;
  7289. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7290. WFIFOSET(fd,packet_len(0x14e));
  7291. }
  7292. /// Guild basic information (Territories [Valaris])
  7293. /// 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)
  7294. /// 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)
  7295. /// 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)
  7296. void clif_guild_basicinfo(struct map_session_data *sd) {
  7297. int fd;
  7298. struct guild *g;
  7299. #if PACKETVER < 20160622
  7300. int cmd = 0x1b6;
  7301. int offset = NAME_LENGTH;
  7302. #else
  7303. int cmd = 0xa84;
  7304. int offset = 0;
  7305. #endif
  7306. nullpo_retv(sd);
  7307. fd = sd->fd;
  7308. if( (g = sd->guild) == NULL )
  7309. return;
  7310. WFIFOHEAD(fd,packet_len(cmd));
  7311. WFIFOW(fd, 0)=cmd;
  7312. WFIFOL(fd, 2)=g->guild_id;
  7313. WFIFOL(fd, 6)=g->guild_lv;
  7314. WFIFOL(fd,10)=g->connect_member;
  7315. WFIFOL(fd,14)=g->max_member;
  7316. WFIFOL(fd,18)=g->average_lv;
  7317. WFIFOL(fd,22)=(uint32)cap_value(g->exp, 0, MAX_GUILD_EXP);
  7318. WFIFOL(fd,26)=(uint32)cap_value(g->next_exp, 0, MAX_GUILD_EXP);
  7319. WFIFOL(fd,30)=0; // Tax Points
  7320. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7321. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7322. WFIFOL(fd,42)=g->emblem_id;
  7323. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7324. #if PACKETVER < 20160622
  7325. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7326. #endif
  7327. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7328. WFIFOL(fd,70+offset+16) = 0; // zeny
  7329. #if PACKETVER >= 20160622
  7330. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7331. #endif
  7332. WFIFOSET(fd,packet_len(cmd));
  7333. }
  7334. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7335. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7336. void clif_guild_allianceinfo(struct map_session_data *sd)
  7337. {
  7338. int fd,i,c;
  7339. struct guild *g;
  7340. nullpo_retv(sd);
  7341. if( (g = sd->guild) == NULL )
  7342. return;
  7343. fd = sd->fd;
  7344. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7345. WFIFOW(fd, 0)=0x14c;
  7346. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7347. struct guild_alliance *a=&g->alliance[i];
  7348. if(a->guild_id>0){
  7349. WFIFOL(fd,c*32+4)=a->opposition;
  7350. WFIFOL(fd,c*32+8)=a->guild_id;
  7351. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7352. c++;
  7353. }
  7354. }
  7355. WFIFOW(fd, 2)=c*32+4;
  7356. WFIFOSET(fd,WFIFOW(fd,2));
  7357. }
  7358. /// Guild member manager information
  7359. /// 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)
  7360. /// state:
  7361. /// 0 = offline
  7362. /// 1 = online
  7363. /// memo:
  7364. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7365. /// 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)
  7366. void clif_guild_memberlist(struct map_session_data *sd)
  7367. {
  7368. int fd;
  7369. int i,c;
  7370. struct guild *g;
  7371. #if PACKETVER < 20161026
  7372. int cmd = 0x154;
  7373. int size = 104;
  7374. #else
  7375. int cmd = 0xaa5;
  7376. int size = 34;
  7377. #endif
  7378. nullpo_retv(sd);
  7379. if( !session_isActive(fd = sd->fd) )
  7380. return;
  7381. if( (g = sd->guild) == NULL )
  7382. return;
  7383. WFIFOHEAD(fd, g->max_member * size + 4);
  7384. WFIFOW(fd, 0)=cmd;
  7385. for(i=0,c=0;i<g->max_member;i++){
  7386. struct guild_member *m=&g->member[i];
  7387. if(m->account_id==0)
  7388. continue;
  7389. WFIFOL(fd,c*size+ 4)=m->account_id;
  7390. WFIFOL(fd,c*size+ 8)=m->char_id;
  7391. WFIFOW(fd,c*size+12)=m->hair;
  7392. WFIFOW(fd,c*size+14)=m->hair_color;
  7393. WFIFOW(fd,c*size+16)=m->gender;
  7394. WFIFOW(fd,c*size+18)=m->class_;
  7395. WFIFOW(fd,c*size+20)=m->lv;
  7396. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7397. WFIFOL(fd,c*size+26)=m->online;
  7398. WFIFOL(fd,c*size+30)=m->position;
  7399. #if PACKETVER < 20161026
  7400. 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.
  7401. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7402. #else
  7403. WFIFOL(fd,c*size+34)=m->last_login;
  7404. #endif
  7405. c++;
  7406. }
  7407. WFIFOW(fd, 2)=c*size+4;
  7408. WFIFOSET(fd,WFIFOW(fd,2));
  7409. }
  7410. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7411. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7412. void clif_guild_positionnamelist(struct map_session_data *sd)
  7413. {
  7414. int i,fd;
  7415. struct guild *g;
  7416. nullpo_retv(sd);
  7417. if( (g = sd->guild) == NULL )
  7418. return;
  7419. fd = sd->fd;
  7420. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7421. WFIFOW(fd, 0)=0x166;
  7422. for(i=0;i<MAX_GUILDPOSITION;i++){
  7423. WFIFOL(fd,i*28+4)=i;
  7424. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7425. }
  7426. WFIFOW(fd,2)=i*28+4;
  7427. WFIFOSET(fd,WFIFOW(fd,2));
  7428. }
  7429. /// Guild position information (ZC_POSITION_INFO).
  7430. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7431. /// mode:
  7432. /// &0x01 = allow invite
  7433. /// &0x10 = allow expel
  7434. /// ranking:
  7435. /// TODO
  7436. void clif_guild_positioninfolist(struct map_session_data *sd)
  7437. {
  7438. int i,fd;
  7439. struct guild *g;
  7440. nullpo_retv(sd);
  7441. if( (g = sd->guild) == NULL )
  7442. return;
  7443. fd = sd->fd;
  7444. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7445. WFIFOW(fd, 0)=0x160;
  7446. for(i=0;i<MAX_GUILDPOSITION;i++){
  7447. struct guild_position *p=&g->position[i];
  7448. WFIFOL(fd,i*16+ 4)=i;
  7449. WFIFOL(fd,i*16+ 8)=p->mode;
  7450. WFIFOL(fd,i*16+12)=i;
  7451. WFIFOL(fd,i*16+16)=p->exp_mode;
  7452. }
  7453. WFIFOW(fd, 2)=i*16+4;
  7454. WFIFOSET(fd,WFIFOW(fd,2));
  7455. }
  7456. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7457. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7458. /// mode:
  7459. /// &0x01 = allow invite
  7460. /// &0x10 = allow expel
  7461. /// ranking:
  7462. /// TODO
  7463. void clif_guild_positionchanged(struct guild *g,int idx)
  7464. {
  7465. // FIXME: This packet is intended to update the clients after a
  7466. // commit of position info changes, not sending one packet per
  7467. // position.
  7468. struct map_session_data *sd;
  7469. unsigned char buf[128];
  7470. nullpo_retv(g);
  7471. WBUFW(buf, 0)=0x174;
  7472. WBUFW(buf, 2)=44; // packet len
  7473. // GUILD_REG_POSITION_INFO{
  7474. WBUFL(buf, 4)=idx;
  7475. WBUFL(buf, 8)=g->position[idx].mode;
  7476. WBUFL(buf,12)=idx;
  7477. WBUFL(buf,16)=g->position[idx].exp_mode;
  7478. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7479. // }*
  7480. if( (sd=guild_getavailablesd(g))!=NULL )
  7481. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7482. }
  7483. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7484. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7485. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7486. {
  7487. // FIXME: This packet is intended to update the clients after a
  7488. // commit of member position assignment changes, not sending one
  7489. // packet per position.
  7490. struct map_session_data *sd;
  7491. unsigned char buf[64];
  7492. nullpo_retv(g);
  7493. WBUFW(buf, 0)=0x156;
  7494. WBUFW(buf, 2)=16; // packet len
  7495. // MEMBER_POSITION_INFO{
  7496. WBUFL(buf, 4)=g->member[idx].account_id;
  7497. WBUFL(buf, 8)=g->member[idx].char_id;
  7498. WBUFL(buf,12)=g->member[idx].position;
  7499. // }*
  7500. if( (sd=guild_getavailablesd(g))!=NULL )
  7501. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7502. }
  7503. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7504. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7505. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7506. {
  7507. int fd;
  7508. nullpo_retv(sd);
  7509. nullpo_retv(g);
  7510. fd = sd->fd;
  7511. if( g->emblem_len <= 0 )
  7512. return;
  7513. WFIFOHEAD(fd,g->emblem_len+12);
  7514. WFIFOW(fd,0)=0x152;
  7515. WFIFOW(fd,2)=g->emblem_len+12;
  7516. WFIFOL(fd,4)=g->guild_id;
  7517. WFIFOL(fd,8)=g->emblem_id;
  7518. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7519. WFIFOSET(fd,WFIFOW(fd,2));
  7520. }
  7521. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7522. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7523. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7524. void clif_guild_emblem_area(struct block_list* bl)
  7525. {
  7526. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7527. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7528. PACKET_ZC_CHANGE_GUILD p{};
  7529. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7530. p.guild_id = status_get_guild_id(bl);
  7531. p.emblem_id = status_get_emblem_id(bl);
  7532. #if PACKETVER < 20190724
  7533. p.aid = bl->id;
  7534. #else
  7535. p.unknown = 0;
  7536. #endif
  7537. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7538. }
  7539. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7540. /// 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 }*
  7541. void clif_guild_skillinfo(struct map_session_data* sd)
  7542. {
  7543. int fd;
  7544. struct guild* g;
  7545. int i,c;
  7546. nullpo_retv(sd);
  7547. if( (g = sd->guild) == NULL )
  7548. return;
  7549. fd = sd->fd;
  7550. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7551. WFIFOW(fd,0) = 0x0162;
  7552. WFIFOW(fd,4) = g->skill_point;
  7553. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7554. {
  7555. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7556. {
  7557. int id = g->skill[i].id;
  7558. int p = 6 + c*37;
  7559. WFIFOW(fd,p+0) = id;
  7560. WFIFOL(fd,p+2) = skill_get_inf(id);
  7561. WFIFOW(fd,p+6) = g->skill[i].lv;
  7562. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7563. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7564. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7565. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7566. c++;
  7567. }
  7568. }
  7569. WFIFOW(fd,2) = 6 + c*37;
  7570. WFIFOSET(fd,WFIFOW(fd,2));
  7571. }
  7572. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7573. /// 016f <subject>.60B <notice>.120B
  7574. void clif_guild_notice(struct map_session_data* sd)
  7575. {
  7576. struct guild* g;
  7577. nullpo_retv(sd);
  7578. nullpo_retv(g = sd->guild);
  7579. int fd = sd->fd;
  7580. if ( !session_isActive(fd) )
  7581. return;
  7582. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7583. return;
  7584. WFIFOHEAD(fd,packet_len(0x16f));
  7585. WFIFOW(fd,0) = 0x16f;
  7586. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7587. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7588. WFIFOSET(fd,packet_len(0x16f));
  7589. }
  7590. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7591. /// 016a <guild id>.L <guild name>.24B
  7592. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7593. {
  7594. int fd;
  7595. nullpo_retv(sd);
  7596. nullpo_retv(g);
  7597. fd=sd->fd;
  7598. WFIFOHEAD(fd,packet_len(0x16a));
  7599. WFIFOW(fd,0)=0x16a;
  7600. WFIFOL(fd,2)=g->guild_id;
  7601. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7602. WFIFOSET(fd,packet_len(0x16a));
  7603. }
  7604. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7605. /// 0169 <answer>.B
  7606. /// answer:
  7607. /// 0 = Already in guild.
  7608. /// 1 = Offer rejected.
  7609. /// 2 = Offer accepted.
  7610. /// 3 = Guild full.
  7611. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7612. {
  7613. int fd;
  7614. nullpo_retv(sd);
  7615. fd=sd->fd;
  7616. WFIFOHEAD(fd,packet_len(0x169));
  7617. WFIFOW(fd,0)=0x169;
  7618. WFIFOB(fd,2)=flag;
  7619. WFIFOSET(fd,packet_len(0x169));
  7620. }
  7621. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7622. /// 015a <char name>.24B <reason>.40B
  7623. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7624. {
  7625. unsigned char buf[128];
  7626. nullpo_retv(sd);
  7627. WBUFW(buf, 0)=0x15a;
  7628. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7629. memcpy(WBUFP(buf,26),mes,40);
  7630. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7631. }
  7632. /// Notifies clients of a guild of an expelled member.
  7633. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7634. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7635. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7636. {
  7637. unsigned char buf[128];
  7638. #if PACKETVER < 20100803
  7639. const unsigned short cmd = 0x15c;
  7640. #else
  7641. const unsigned short cmd = 0x839;
  7642. #endif
  7643. nullpo_retv(sd);
  7644. WBUFW(buf,0) = cmd;
  7645. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7646. safestrncpy(WBUFCP(buf,26), mes, 40);
  7647. #if PACKETVER < 20100803
  7648. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7649. #endif
  7650. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7651. }
  7652. /// Guild expulsion list (ZC_BAN_LIST).
  7653. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7654. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7655. void clif_guild_expulsionlist(struct map_session_data* sd)
  7656. {
  7657. #if PACKETVER < 20100803
  7658. const int offset = NAME_LENGTH*2+40;
  7659. #else
  7660. const int offset = NAME_LENGTH+40;
  7661. #endif
  7662. int fd, i, c = 0;
  7663. struct guild* g;
  7664. nullpo_retv(sd);
  7665. if( (g = sd->guild) == NULL )
  7666. return;
  7667. fd = sd->fd;
  7668. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7669. WFIFOW(fd,0) = 0x163;
  7670. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7671. {
  7672. struct guild_expulsion* e = &g->expulsion[i];
  7673. if( e->account_id > 0 )
  7674. {
  7675. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7676. #if PACKETVER < 20100803
  7677. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7678. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7679. #else
  7680. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7681. #endif
  7682. c++;
  7683. }
  7684. }
  7685. WFIFOW(fd,2) = 4 + c*offset;
  7686. WFIFOSET(fd,WFIFOW(fd,2));
  7687. }
  7688. /// Guild chat message (ZC_GUILD_CHAT).
  7689. /// 017f <packet len>.W <message>.?B
  7690. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7691. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7692. struct map_session_data *sd;
  7693. uint8 buf[256];
  7694. if( len == 0 )
  7695. {
  7696. return;
  7697. }
  7698. else if( len > sizeof(buf)-5 )
  7699. {
  7700. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7701. len = sizeof(buf)-5;
  7702. }
  7703. WBUFW(buf, 0) = 0x17f;
  7704. WBUFW(buf, 2) = len + 5;
  7705. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7706. if ((sd = guild_getavailablesd(g)) != NULL)
  7707. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7708. }
  7709. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7710. /// 0171 <inviter account id>.L <guild name>.24B
  7711. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7712. {
  7713. int fd;
  7714. nullpo_retv(sd);
  7715. fd=sd->fd;
  7716. WFIFOHEAD(fd,packet_len(0x171));
  7717. WFIFOW(fd,0)=0x171;
  7718. WFIFOL(fd,2)=account_id;
  7719. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7720. WFIFOSET(fd,packet_len(0x171));
  7721. }
  7722. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7723. /// 0173 <answer>.B
  7724. /// answer:
  7725. /// 0 = Already allied.
  7726. /// 1 = You rejected the offer.
  7727. /// 2 = You accepted the offer.
  7728. /// 3 = They have too any alliances.
  7729. /// 4 = You have too many alliances.
  7730. /// 5 = Alliances are disabled.
  7731. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7732. {
  7733. int fd;
  7734. nullpo_retv(sd);
  7735. fd=sd->fd;
  7736. WFIFOHEAD(fd,packet_len(0x173));
  7737. WFIFOW(fd,0)=0x173;
  7738. WFIFOL(fd,2)=flag;
  7739. WFIFOSET(fd,packet_len(0x173));
  7740. }
  7741. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7742. /// 0184 <other guild id>.L <relation>.L
  7743. /// relation:
  7744. /// 0 = Ally
  7745. /// 1 = Enemy
  7746. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7747. {
  7748. nullpo_retv(sd);
  7749. int fd = sd->fd;
  7750. if ( !session_isActive(fd) )
  7751. return;
  7752. WFIFOHEAD(fd,packet_len(0x184));
  7753. WFIFOW(fd,0)=0x184;
  7754. WFIFOL(fd,2)=guild_id;
  7755. WFIFOL(fd,6)=flag;
  7756. WFIFOSET(fd,packet_len(0x184));
  7757. }
  7758. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7759. /// 0181 <result>.B
  7760. /// result:
  7761. /// 0 = Antagonist has been set.
  7762. /// 1 = Guild has too many Antagonists.
  7763. /// 2 = Already set as an Antagonist.
  7764. /// 3 = Antagonists are disabled.
  7765. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7766. {
  7767. int fd;
  7768. nullpo_retv(sd);
  7769. fd=sd->fd;
  7770. WFIFOHEAD(fd,packet_len(0x181));
  7771. WFIFOW(fd,0)=0x181;
  7772. WFIFOB(fd,2)=flag;
  7773. WFIFOSET(fd,packet_len(0x181));
  7774. }
  7775. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7776. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7777. /*
  7778. void clif_guild_allianceadded(struct guild *g,int idx)
  7779. {
  7780. unsigned char buf[64];
  7781. WBUFW(buf,0)=0x185;
  7782. WBUFL(buf,2)=g->alliance[idx].opposition;
  7783. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7784. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7785. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7786. }
  7787. */
  7788. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7789. /// 015e <reason>.L
  7790. /// 0 = success
  7791. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7792. /// 2 = there are still members in the guild
  7793. void clif_guild_broken(struct map_session_data *sd,int flag)
  7794. {
  7795. int fd;
  7796. nullpo_retv(sd);
  7797. fd=sd->fd;
  7798. WFIFOHEAD(fd,packet_len(0x15e));
  7799. WFIFOW(fd,0)=0x15e;
  7800. WFIFOL(fd,2)=flag;
  7801. WFIFOSET(fd,packet_len(0x15e));
  7802. }
  7803. /// Displays emotion on an object (ZC_EMOTION).
  7804. /// 00c0 <id>.L <type>.B
  7805. /// type:
  7806. /// enum emotion_type
  7807. void clif_emotion(struct block_list *bl,int type)
  7808. {
  7809. unsigned char buf[8];
  7810. nullpo_retv(bl);
  7811. WBUFW(buf,0)=0xc0;
  7812. WBUFL(buf,2)=bl->id;
  7813. WBUFB(buf,6)=type;
  7814. clif_send(buf,packet_len(0xc0),bl,AREA);
  7815. }
  7816. /// Displays the contents of a talkiebox trap.
  7817. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7818. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7819. nullpo_retv( bl );
  7820. nullpo_retv( talkie );
  7821. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7822. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7823. p.aid = bl->id;
  7824. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7825. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7826. }
  7827. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7828. /// 01ea <id>.L
  7829. void clif_wedding_effect(struct block_list *bl)
  7830. {
  7831. unsigned char buf[6];
  7832. nullpo_retv(bl);
  7833. WBUFW(buf,0) = 0x1ea;
  7834. WBUFL(buf,2) = bl->id;
  7835. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7836. }
  7837. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7838. /// 01e6 <partner name>.24B
  7839. void clif_callpartner(struct map_session_data *sd)
  7840. {
  7841. unsigned char buf[26];
  7842. nullpo_retv(sd);
  7843. WBUFW(buf,0) = 0x1e6;
  7844. if( sd->status.partner_id ) {
  7845. const char *p = map_charid2nick(sd->status.partner_id);
  7846. struct map_session_data *p_sd = pc_get_partner(sd);
  7847. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7848. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7849. else
  7850. WBUFB(buf,2) = 0;
  7851. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7852. WBUFB(buf,2) = 0;
  7853. }
  7854. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7855. }
  7856. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7857. /// 01e4
  7858. /// This packet while still implemented by the client is no longer being officially used.
  7859. /*
  7860. void clif_marriage_process(struct map_session_data *sd)
  7861. {
  7862. int fd;
  7863. nullpo_retv(sd);
  7864. fd=sd->fd;
  7865. WFIFOHEAD(fd,packet_len(0x1e4));
  7866. WFIFOW(fd,0)=0x1e4;
  7867. WFIFOSET(fd,packet_len(0x1e4));
  7868. }
  7869. */
  7870. /// Notice of divorce (ZC_DIVORCE).
  7871. /// 0205 <partner name>.24B
  7872. void clif_divorced(struct map_session_data* sd, const char* name)
  7873. {
  7874. int fd;
  7875. nullpo_retv(sd);
  7876. fd=sd->fd;
  7877. WFIFOHEAD(fd,packet_len(0x205));
  7878. WFIFOW(fd,0)=0x205;
  7879. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7880. WFIFOSET(fd, packet_len(0x205));
  7881. }
  7882. /// Marriage proposal (ZC_REQ_COUPLE).
  7883. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7884. /// This packet while still implemented by the client is no longer being officially used.
  7885. /*
  7886. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7887. {
  7888. nullpo_retv(sd);
  7889. WFIFOHEAD(fd,packet_len(0x1e2));
  7890. WFIFOW(fd,0) = 0x1e2;
  7891. WFIFOL(fd,2) = ssd->status.account_id;
  7892. WFIFOL(fd,6) = ssd->status.char_id;
  7893. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7894. WFIFOSET(fd, packet_len(0x1e2));
  7895. }
  7896. */
  7897. /*==========================================
  7898. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7899. *------------------------------------------*/
  7900. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7901. {
  7902. unsigned char buf[256];
  7903. if( len == 0 ) {
  7904. return;
  7905. } else if( len > sizeof(buf)-5 ) {
  7906. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7907. len = sizeof(buf)-5;
  7908. }
  7909. WBUFW(buf, 0) = 0x17f;
  7910. WBUFW(buf, 2) = len + 5;
  7911. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7912. clif_send(buf, WBUFW(buf,2), src, target);
  7913. }
  7914. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7915. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7916. /// 00cd <result>.B
  7917. /// result:
  7918. /// 0 = failure
  7919. /// 1 = success
  7920. void clif_GM_kickack(struct map_session_data *sd, int id)
  7921. {
  7922. int fd;
  7923. nullpo_retv(sd);
  7924. fd = sd->fd;
  7925. WFIFOHEAD(fd,packet_len(0xcd));
  7926. WFIFOW(fd,0) = 0xcd;
  7927. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7928. WFIFOSET(fd, packet_len(0xcd));
  7929. }
  7930. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7931. {
  7932. nullpo_retv(tsd);
  7933. if (sd == NULL)
  7934. tsd->state.keepshop = true;
  7935. if (session_isActive(tsd->fd))
  7936. clif_authfail_fd(tsd->fd, 15);
  7937. else
  7938. map_quit(tsd);
  7939. if (sd)
  7940. clif_GM_kickack(sd, tsd->status.account_id);
  7941. }
  7942. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7943. /// 014a <result>.L
  7944. /// result:
  7945. /// 0 = "A manner point has been successfully aligned."
  7946. /// 1 = MP_FAILURE_EXHAUST
  7947. /// 2 = MP_FAILURE_ALREADY_GIVING
  7948. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7949. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7950. /// 5 = "You got a good point from %s."
  7951. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7952. {
  7953. int fd;
  7954. nullpo_retv(sd);
  7955. fd = sd->fd;
  7956. WFIFOHEAD(fd,packet_len(0x14a));
  7957. WFIFOW(fd,0) = 0x14a;
  7958. WFIFOL(fd,2) = type;
  7959. WFIFOSET(fd, packet_len(0x14a));
  7960. }
  7961. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7962. /// 014b <type>.B <GM name>.24B
  7963. /// type:
  7964. /// 0 = positive (unmute)
  7965. /// 1 = negative (mute)
  7966. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7967. {
  7968. int fd;
  7969. nullpo_retv(sd);
  7970. nullpo_retv(tsd);
  7971. fd = tsd->fd;
  7972. WFIFOHEAD(fd,packet_len(0x14b));
  7973. WFIFOW(fd,0) = 0x14b;
  7974. WFIFOB(fd,2) = type;
  7975. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7976. WFIFOSET(fd, packet_len(0x14b));
  7977. }
  7978. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7979. /// 00d1 <type>.B <result>.B
  7980. /// type:
  7981. /// 0 = /ex (deny)
  7982. /// 1 = /in (allow)
  7983. /// result:
  7984. /// 0 = success
  7985. /// 1 = failure
  7986. /// 2 = too many blocks
  7987. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7988. {
  7989. int fd;
  7990. nullpo_retv(sd);
  7991. fd=sd->fd;
  7992. WFIFOHEAD(fd,packet_len(0xd1));
  7993. WFIFOW(fd,0)=0xd1;
  7994. WFIFOB(fd,2)=type;
  7995. WFIFOB(fd,3)=flag;
  7996. WFIFOSET(fd,packet_len(0xd1));
  7997. }
  7998. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7999. /// 00d2 <type>.B <result>.B
  8000. /// type:
  8001. /// 0 = /exall (deny)
  8002. /// 1 = /inall (allow)
  8003. /// result:
  8004. /// 0 = success
  8005. /// 1 = failure
  8006. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8007. {
  8008. int fd;
  8009. nullpo_retv(sd);
  8010. fd=sd->fd;
  8011. WFIFOHEAD(fd,packet_len(0xd2));
  8012. WFIFOW(fd,0)=0xd2;
  8013. WFIFOB(fd,2)=type;
  8014. WFIFOB(fd,3)=flag;
  8015. WFIFOSET(fd,packet_len(0xd2));
  8016. }
  8017. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8018. /// 07fe <bgm>.24B
  8019. void clif_playBGM(struct map_session_data* sd, const char* name)
  8020. {
  8021. int fd;
  8022. nullpo_retv(sd);
  8023. fd = sd->fd;
  8024. WFIFOHEAD(fd,packet_len(0x7fe));
  8025. WFIFOW(fd,0) = 0x7fe;
  8026. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8027. WFIFOSET(fd,packet_len(0x7fe));
  8028. }
  8029. /// Plays/stops a wave sound (ZC_SOUND).
  8030. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8031. /// file name:
  8032. /// relative to data\wav
  8033. /// act:
  8034. /// 0 = play (once)
  8035. /// 1 = play (repeat, does not work)
  8036. /// 2 = stops all sound instances of file name (does not work)
  8037. /// term:
  8038. /// unknown purpose, only relevant to act = 1
  8039. /// npc id:
  8040. /// The accustic direction of the sound is determined by the
  8041. /// relative position of the NPC to the player (3D sound).
  8042. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8043. {
  8044. int fd;
  8045. nullpo_retv(sd);
  8046. nullpo_retv(bl);
  8047. fd = sd->fd;
  8048. WFIFOHEAD(fd,packet_len(0x1d3));
  8049. WFIFOW(fd,0) = 0x1d3;
  8050. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8051. WFIFOB(fd,26) = type;
  8052. WFIFOL(fd,27) = 0;
  8053. WFIFOL(fd,31) = bl->id;
  8054. WFIFOSET(fd,packet_len(0x1d3));
  8055. }
  8056. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8057. {
  8058. unsigned char buf[40];
  8059. nullpo_retv(bl);
  8060. WBUFW(buf,0) = 0x1d3;
  8061. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8062. WBUFB(buf,26) = type;
  8063. WBUFL(buf,27) = 0;
  8064. WBUFL(buf,31) = bl->id;
  8065. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8066. }
  8067. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8068. /// 01f3 <id>.L <effect id>.L
  8069. /// effect id:
  8070. /// @see doc/effect_list.txt
  8071. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8072. {
  8073. unsigned char buf[24];
  8074. nullpo_retv(bl);
  8075. memset(buf, 0, packet_len(0x1f3));
  8076. WBUFW(buf,0) = 0x1f3;
  8077. WBUFL(buf,2) = bl->id;
  8078. WBUFL(buf,6) = type;
  8079. clif_send(buf, packet_len(0x1f3), bl, target);
  8080. if (disguised(bl)) {
  8081. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8082. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8083. }
  8084. }
  8085. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8086. {
  8087. WFIFOHEAD(fd,10);
  8088. WFIFOW(fd,0) = 0x1f3;
  8089. WFIFOL(fd,2) = bl->id;
  8090. WFIFOL(fd,6) = type;
  8091. WFIFOSET(fd,10);
  8092. }
  8093. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8094. /// 0284 <id>.L <effect id>.L <num data>.L
  8095. /// effect id:
  8096. /// @see doc/effect_list.txt
  8097. /// num data:
  8098. /// effect-dependent value
  8099. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8100. {
  8101. uint8 buf[14];
  8102. WBUFW(buf,0) = 0x284;
  8103. WBUFL(buf,2) = bl->id;
  8104. WBUFL(buf,6) = effect_id;
  8105. WBUFL(buf,10) = num;
  8106. clif_send(buf, packet_len(0x284), bl, target);
  8107. if( disguised(bl) )
  8108. {
  8109. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8110. clif_send(buf, packet_len(0x284), bl, SELF);
  8111. }
  8112. }
  8113. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8114. {
  8115. #if PACKETVER >= 20181002
  8116. nullpo_retv( bl_src );
  8117. nullpo_retv( bl_target );
  8118. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8119. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8120. p.aid = bl_src->id;
  8121. p.effectId = effect;
  8122. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8123. if( disguised(bl_src) )
  8124. {
  8125. p.aid = disguised_bl_id( bl_src->id );
  8126. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8127. }
  8128. #endif
  8129. }
  8130. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8131. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8132. 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) {
  8133. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8134. uint8 buf[CHAT_SIZE_MAX];
  8135. nullpo_retv(bl);
  8136. if (msg_len > sizeof(buf) - 12) {
  8137. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8138. msg_len = sizeof(buf) - 12;
  8139. }
  8140. if (rgb2bgr)
  8141. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8142. WBUFW(buf,0) = 0x2C1;
  8143. WBUFW(buf,2) = msg_len + 12;
  8144. WBUFL(buf,4) = bl->id;
  8145. WBUFL(buf,8) = color;
  8146. memcpy(WBUFCP(buf,12), msg, msg_len);
  8147. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8148. }
  8149. /**
  8150. * Notifies the client that the storage window is still open
  8151. *
  8152. * Should only be used in cases where the client closed the
  8153. * storage window without server's consent
  8154. */
  8155. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8156. // Notify the client that the storage is open
  8157. if( sd->state.storage_flag == 1 ) {
  8158. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8159. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8160. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8161. }
  8162. // Notify the client that the gstorage is open otherwise it will
  8163. // remain locked forever and nobody will be able to access it
  8164. if( sd->state.storage_flag == 2 ) {
  8165. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8166. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8167. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8168. else {
  8169. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8170. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8171. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8172. }
  8173. }
  8174. // Notify the client that the premium storage is open
  8175. if (sd->state.storage_flag == 3) {
  8176. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8177. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8178. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8179. }
  8180. }
  8181. // refresh the client's screen, getting rid of any effects
  8182. void clif_refresh(struct map_session_data *sd)
  8183. {
  8184. nullpo_retv(sd);
  8185. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8186. clif_inventorylist(sd);
  8187. clif_equipswitch_list(sd);
  8188. if(pc_iscarton(sd)) {
  8189. clif_cartlist(sd);
  8190. clif_updatestatus(sd,SP_CARTINFO);
  8191. }
  8192. clif_updatestatus(sd,SP_WEIGHT);
  8193. clif_updatestatus(sd,SP_MAXWEIGHT);
  8194. clif_updatestatus(sd,SP_STR);
  8195. clif_updatestatus(sd,SP_AGI);
  8196. clif_updatestatus(sd,SP_VIT);
  8197. clif_updatestatus(sd,SP_INT);
  8198. clif_updatestatus(sd,SP_DEX);
  8199. clif_updatestatus(sd,SP_LUK);
  8200. if (sd->spiritball)
  8201. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8202. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8203. clif_millenniumshield_single(sd->fd, sd);
  8204. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8205. clif_spiritcharm_single(sd->fd, sd);
  8206. if (sd->soulball)
  8207. clif_soulball( sd, &sd->bl, SELF );
  8208. if (sd->vd.cloth_color)
  8209. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8210. if (sd->vd.body_style)
  8211. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8212. if(hom_is_active(sd->hd))
  8213. clif_send_homdata(sd,SP_ACK,0);
  8214. if( sd->md ) {
  8215. clif_mercenary_info(sd);
  8216. clif_mercenary_skillblock(sd);
  8217. }
  8218. if( sd->ed )
  8219. clif_elemental_info(sd);
  8220. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8221. clif_weather_check(sd);
  8222. if( sd->chatID )
  8223. chat_leavechat(sd,0);
  8224. if( sd->state.vending )
  8225. clif_openvending(sd, sd->bl.id, sd->vending);
  8226. if( pc_issit(sd) )
  8227. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8228. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8229. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8230. else
  8231. clif_changed_dir(&sd->bl, SELF);
  8232. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8233. //Issue #2143
  8234. //Cancel Trading State
  8235. if (sd->state.trading)
  8236. trade_tradecancel(sd);
  8237. //Cancel Buying/Selling State
  8238. if (sd->state.buyingstore)
  8239. buyingstore_close(sd);
  8240. mail_clear(sd);
  8241. clif_loadConfirm( sd );
  8242. if( disguised(&sd->bl) ) {/* refresh-da */
  8243. short disguise = sd->disguise;
  8244. pc_disguise(sd, 0);
  8245. pc_disguise(sd, disguise);
  8246. }
  8247. clif_refresh_storagewindow(sd);
  8248. }
  8249. /// Updates the object's (bl) name on client.
  8250. /// Used to update when a char leaves a party/guild. [Skotlex]
  8251. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8252. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8253. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8254. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8255. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8256. nullpo_retv( src );
  8257. nullpo_retv( bl );
  8258. switch( bl->type ){
  8259. case BL_PC: {
  8260. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8261. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8262. packet.gid = bl->id;
  8263. map_session_data *sd = (map_session_data *)bl;
  8264. //Requesting your own "shadow" name. [Skotlex]
  8265. if( src == bl && target == SELF && sd->disguise ){
  8266. packet.gid = -bl->id;
  8267. }
  8268. if( sd->fakename[0] ) {
  8269. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8270. clif_send( &packet, sizeof(packet), src, target );
  8271. return;
  8272. }
  8273. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8274. party_data *p = nullptr;
  8275. if( sd->status.party_id ){
  8276. p = party_search( sd->status.party_id );
  8277. }
  8278. // do not display party unless the player is also in a guild
  8279. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8280. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8281. }
  8282. if( sd->guild ){
  8283. int position;
  8284. // Will get the position of the guild the player is in
  8285. position = guild_getposition( sd );
  8286. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8287. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8288. }else if( sd->clan ){
  8289. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8290. }
  8291. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8292. packet.title_id = sd->status.title_id; // Title ID
  8293. #endif
  8294. clif_send(&packet, sizeof(packet), src, target);
  8295. }
  8296. break;
  8297. //[blackhole89]
  8298. case BL_HOM:
  8299. case BL_MER:
  8300. case BL_PET:
  8301. case BL_NPC:
  8302. case BL_ELEM: {
  8303. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8304. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8305. packet.gid = bl->id;
  8306. switch (bl->type) {
  8307. case BL_HOM:
  8308. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8309. break;
  8310. case BL_MER:
  8311. memcpy(packet.name, ((TBL_MER *)bl)->db->name, NAME_LENGTH);
  8312. break;
  8313. case BL_PET:
  8314. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8315. break;
  8316. case BL_NPC:
  8317. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8318. break;
  8319. case BL_ELEM:
  8320. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name, NAME_LENGTH);
  8321. break;
  8322. }
  8323. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8324. unit_data *ud = unit_bl2ud(bl);
  8325. if (ud != nullptr) {
  8326. memcpy(packet.title, ud->title, NAME_LENGTH);
  8327. packet.groupId = ud->group_id;
  8328. }
  8329. #endif
  8330. clif_send(&packet, sizeof(packet), src, target);
  8331. }
  8332. break;
  8333. case BL_MOB: {
  8334. mob_data *md = (mob_data *)bl;
  8335. if( md->guardian_data && md->guardian_data->guild_id ){
  8336. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8337. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8338. packet.gid = bl->id;
  8339. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8340. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8341. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8342. clif_send(&packet, sizeof(packet), src, target);
  8343. }else if( battle_config.show_mob_info ){
  8344. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8345. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8346. packet.gid = bl->id;
  8347. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8348. char mobhp[50], *str_p = mobhp;
  8349. if( battle_config.show_mob_info&4 ){
  8350. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8351. }
  8352. if( battle_config.show_mob_info&1 ){
  8353. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8354. }
  8355. if( battle_config.show_mob_info&2 ){
  8356. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8357. }
  8358. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8359. if( str_p != mobhp ){
  8360. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8361. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8362. }
  8363. clif_send(&packet, sizeof(packet), src, target);
  8364. } else {
  8365. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8366. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8367. packet.gid = bl->id;
  8368. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8369. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8370. unit_data *ud = unit_bl2ud(bl);
  8371. if (ud != nullptr) {
  8372. memcpy(packet.title, ud->title, NAME_LENGTH);
  8373. packet.groupId = ud->group_id;
  8374. }
  8375. #endif
  8376. clif_send(&packet, sizeof(packet), src, target);
  8377. }
  8378. }
  8379. break;
  8380. case BL_CHAT:
  8381. case BL_SKILL:
  8382. // Newer clients request this, but do not need an answer
  8383. return;
  8384. default:
  8385. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8386. return;
  8387. }
  8388. }
  8389. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8390. /// 01ff <id>.L <x>.W <y>.W
  8391. ///
  8392. /// Visually moves(instant) a character to x,y. The char moves even
  8393. /// when the target cell isn't walkable. If the char is sitting it
  8394. /// stays that way.
  8395. void clif_slide(struct block_list *bl, int x, int y)
  8396. {
  8397. unsigned char buf[10];
  8398. nullpo_retv(bl);
  8399. WBUFW(buf, 0) = 0x01ff;
  8400. WBUFL(buf, 2) = bl->id;
  8401. WBUFW(buf, 6) = x;
  8402. WBUFW(buf, 8) = y;
  8403. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8404. if( disguised(bl) )
  8405. {
  8406. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8407. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8408. }
  8409. }
  8410. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8411. /// 008d <packet len>.W <id>.L <message>.?B
  8412. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8413. {
  8414. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8415. int len_mes = strlen(mes)+1; //Account for \0
  8416. if (len_mes > sizeof(buf)-8) {
  8417. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8418. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8419. }
  8420. // send message to others
  8421. if (flag == AREA) {
  8422. WBUFW(buf,0) = 0x8d;
  8423. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8424. WBUFL(buf,4) = bl->id;
  8425. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8426. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8427. }
  8428. // send back message to the speaker
  8429. if( bl->type == BL_PC ) {
  8430. WBUFW(buf,0) = 0x8e;
  8431. WBUFW(buf, 2) = len_mes + 4;
  8432. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8433. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8434. }
  8435. }
  8436. /*==========================
  8437. * Minimap fix [Kevin]
  8438. * Remove dot from minimap
  8439. *--------------------------*/
  8440. void clif_party_xy_remove(struct map_session_data *sd)
  8441. {
  8442. unsigned char buf[16];
  8443. nullpo_retv(sd);
  8444. WBUFW(buf,0)=0x107;
  8445. WBUFL(buf,2)=sd->status.account_id;
  8446. WBUFW(buf,6)=-1;
  8447. WBUFW(buf,8)=-1;
  8448. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8449. }
  8450. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8451. /// 0215 <msg id>.L
  8452. /// msg id:
  8453. /// 0x15 = End all negative status (PA_GOSPEL)
  8454. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8455. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8456. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8457. /// 0x19 = All stats +20 (PA_GOSPEL)
  8458. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8459. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8460. /// 0x1e = DEF +25% (PA_GOSPEL)
  8461. /// 0x1f = ATK +100% (PA_GOSPEL)
  8462. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8463. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8464. /// ? = nothing
  8465. void clif_gospel_info(struct map_session_data *sd, int type)
  8466. {
  8467. int fd=sd->fd;
  8468. WFIFOHEAD(fd,packet_len(0x215));
  8469. WFIFOW(fd,0)=0x215;
  8470. WFIFOL(fd,2)=type;
  8471. WFIFOSET(fd, packet_len(0x215));
  8472. }
  8473. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8474. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8475. /// result:
  8476. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8477. /// star:
  8478. /// 0 = Place of the Sun
  8479. /// 1 = Place of the Moon
  8480. /// 2 = Place of the Stars
  8481. /// 1 = Star Gladiator %s's %s: <mapname>
  8482. /// star:
  8483. /// 0 = Place of the Sun
  8484. /// 1 = Place of the Moon
  8485. /// 2 = Place of the Stars
  8486. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8487. /// star:
  8488. /// 0 = Target of the Sun
  8489. /// 1 = Target of the Moon
  8490. /// 2 = Target of the Stars
  8491. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8492. /// star:
  8493. /// 0 = Monster of the Sun
  8494. /// 1 = Monster of the Moon
  8495. /// 2 = Monster of the Stars
  8496. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8497. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8498. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8499. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8500. /// 40 = Target HP : <monster_id used as HP>
  8501. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8502. {
  8503. int fd = sd->fd;
  8504. WFIFOHEAD(fd,packet_len(0x20e));
  8505. WFIFOW(fd,0) = 0x20e;
  8506. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8507. WFIFOL(fd,26) = monster_id;
  8508. WFIFOB(fd,30) = star;
  8509. WFIFOB(fd,31) = result;
  8510. WFIFOSET(fd,packet_len(0x20e));
  8511. }
  8512. /*==========================================
  8513. * Info about Star Glaldiator save map [Komurka]
  8514. * type: 1: Information, 0: Map registered
  8515. *------------------------------------------*/
  8516. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8517. {
  8518. char mapname[MAP_NAME_LENGTH_EXT];
  8519. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8520. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8521. }
  8522. /*==========================================
  8523. * Info about Star Glaldiator hate mob [Komurka]
  8524. * type: 1: Register mob, 0: Information.
  8525. *------------------------------------------*/
  8526. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8527. {
  8528. if( pcdb_checkid(class_) ) {
  8529. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8530. } else if( mobdb_checkid(class_) ) {
  8531. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8532. } else {
  8533. 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);
  8534. }
  8535. }
  8536. /*==========================================
  8537. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8538. *------------------------------------------*/
  8539. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8540. {
  8541. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8542. }
  8543. /*==========================================
  8544. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8545. *------------------------------------------*/
  8546. void clif_feel_hate_reset(struct map_session_data *sd)
  8547. {
  8548. clif_starskill(sd, "", 0, 0, 30);
  8549. }
  8550. /// Send out reply to configuration change
  8551. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8552. /// type: see enum e_config_type
  8553. /// value:
  8554. /// false = disabled
  8555. /// true = enabled
  8556. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8557. int fd;
  8558. nullpo_retv(sd);
  8559. fd = sd->fd;
  8560. WFIFOHEAD(fd, packet_len(0x2d9));
  8561. WFIFOW(fd, 0) = 0x2d9;
  8562. WFIFOL(fd, 2) = type;
  8563. WFIFOL(fd, 6) = enabled;
  8564. WFIFOSET(fd, packet_len(0x2d9));
  8565. }
  8566. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8567. /// 02da <open equip window>.B
  8568. /// open equip window:
  8569. /// 0 = disabled
  8570. /// 1 = enabled
  8571. void clif_equipcheckbox(struct map_session_data* sd)
  8572. {
  8573. int fd;
  8574. nullpo_retv(sd);
  8575. fd = sd->fd;
  8576. WFIFOHEAD(fd, packet_len(0x2da));
  8577. WFIFOW(fd, 0) = 0x2da;
  8578. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8579. WFIFOSET(fd, packet_len(0x2da));
  8580. }
  8581. /// Sends info about a player's equipped items.
  8582. /// 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)
  8583. /// 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)
  8584. /// 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)
  8585. /// 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)
  8586. /// 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)
  8587. /// 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)
  8588. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8589. nullpo_retv( sd );
  8590. nullpo_retv( tsd );
  8591. struct packet_viewequip_ack packet;
  8592. int equip = 0;
  8593. for( int i = 0; i < EQI_MAX; i++ ){
  8594. int k = tsd->equip_index[i];
  8595. if( k >= 0 ){
  8596. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8597. continue;
  8598. }
  8599. if( !tsd->inventory.u.items_inventory[k].equip ){
  8600. continue;
  8601. }
  8602. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8603. continue;
  8604. }
  8605. clif_item_equip( client_index( k ), &packet.list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8606. }
  8607. }
  8608. packet.PacketType = viewequipackType;
  8609. packet.PacketLength = ( sizeof( packet ) - sizeof( packet.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  8610. safestrncpy( packet.characterName, tsd->status.name, NAME_LENGTH );
  8611. packet.job = tsd->status.class_;
  8612. packet.head = tsd->vd.hair_style;
  8613. packet.accessory = tsd->vd.head_bottom;
  8614. packet.accessory2 = tsd->vd.head_mid;
  8615. packet.accessory3 = tsd->vd.head_top;
  8616. #if PACKETVER >= 20110111
  8617. packet.robe = tsd->vd.robe;
  8618. #endif
  8619. packet.headpalette = tsd->vd.hair_color;
  8620. packet.bodypalette = tsd->vd.cloth_color;
  8621. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8622. packet.body2 = tsd->vd.body_style;
  8623. #endif
  8624. packet.sex = tsd->vd.sex;
  8625. clif_send( &packet, packet.PacketLength, &sd->bl, SELF );
  8626. }
  8627. /// Display msgstringtable.txt string (ZC_MSG).
  8628. /// 0291 <message>.W
  8629. void clif_msg(struct map_session_data* sd, unsigned short id)
  8630. {
  8631. int fd;
  8632. nullpo_retv(sd);
  8633. fd = sd->fd;
  8634. WFIFOHEAD(fd, packet_len(0x291));
  8635. WFIFOW(fd, 0) = 0x291;
  8636. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8637. WFIFOSET(fd, packet_len(0x291));
  8638. }
  8639. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8640. /// 0x7e2 <message>.W <value>.L
  8641. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8642. {
  8643. int fd = sd->fd;
  8644. WFIFOHEAD(fd, packet_len(0x7e2));
  8645. WFIFOW(fd,0) = 0x7e2;
  8646. WFIFOW(fd,2) = id;
  8647. WFIFOL(fd,4) = value;
  8648. WFIFOSET(fd, packet_len(0x7e2));
  8649. }
  8650. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8651. /// 07e6 <skill id>.W <msg id>.L
  8652. ///
  8653. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8654. /// "[SkillName] Message"
  8655. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8656. {
  8657. int fd = sd->fd;
  8658. WFIFOHEAD(fd, packet_len(0x7e6));
  8659. WFIFOW(fd,0) = 0x7e6;
  8660. WFIFOW(fd,2) = skill_id;
  8661. WFIFOL(fd,4) = msg_id;
  8662. WFIFOSET(fd, packet_len(0x7e6));
  8663. }
  8664. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8665. /// 09cd <msg id>.W <color>.L
  8666. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8667. nullpo_retv(sd);
  8668. int fd = sd->fd;
  8669. WFIFOHEAD(fd, packet_len(0x9cd));
  8670. WFIFOW(fd, 0) = 0x9cd;
  8671. WFIFOW(fd, 2) = msg_id;
  8672. WFIFOL(fd, 4) = color;
  8673. WFIFOSET(fd, packet_len(0x9cd));
  8674. }
  8675. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8676. /// Returns true if the packet was parsed successfully.
  8677. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8678. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8679. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8680. const char* seperator = " : ";
  8681. int fd;
  8682. struct s_packet_db* info;
  8683. uint16 packetLength, inputLength;
  8684. const char *input, *name, *message;
  8685. size_t nameLength, messageLength;
  8686. fd = sd->fd;
  8687. info = &packet_db[RFIFOW(fd,0)];
  8688. packetLength = RFIFOW(fd,info->pos[0]);
  8689. input = RFIFOCP(fd,info->pos[1]);
  8690. // basic structure check for the 4-byte header
  8691. if( packetLength < 4 ){
  8692. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8693. return false;
  8694. }else{
  8695. inputLength = packetLength - 4;
  8696. }
  8697. // process <name> part of the packet
  8698. if( whisperFormat ) {
  8699. // name has fixed width
  8700. if( inputLength < NAME_LENGTH + 1 ) {
  8701. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8702. return false;
  8703. }
  8704. name = input;
  8705. // validate name
  8706. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8707. // only restriction is that the name must be zero-terminated
  8708. if( name[nameLength] != '\0' ) {
  8709. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8710. return false;
  8711. }
  8712. message = input + NAME_LENGTH;
  8713. messageLength = inputLength - NAME_LENGTH;
  8714. }else{
  8715. // name and message are separated by ' : '
  8716. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8717. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8718. // check if there's enough data provided
  8719. if( inputLength < nameLength + seperatorLength + 1 ){
  8720. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8721. return false;
  8722. }
  8723. name = input;
  8724. // validate name
  8725. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8726. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8727. {
  8728. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8729. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8730. set_eof(sd->fd); // Just kick them out to correct it.
  8731. return false;
  8732. }
  8733. message = input + nameLength + seperatorLength;
  8734. messageLength = inputLength - nameLength - seperatorLength;
  8735. }
  8736. #if PACKETVER < 20151001
  8737. // the declared length must match real length
  8738. if( messageLength != strnlen(message, messageLength)+1 ) {
  8739. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8740. return false;
  8741. }
  8742. // verify <message> part of the packet
  8743. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8744. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8745. return false;
  8746. }
  8747. #else
  8748. // No zero termination anymore
  8749. messageLength += 1;
  8750. #endif
  8751. // messages mustn't be too long
  8752. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8753. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8754. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8755. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8756. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8757. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8758. return false;
  8759. }
  8760. // If it is not a whisper message, set the name to the fakename of the player
  8761. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8762. strcpy( out_name, sd->fakename );
  8763. }else{
  8764. safestrncpy( out_name, name, nameLength + 1 );
  8765. }
  8766. safestrncpy( out_message, message, messageLength );
  8767. if( whisperFormat ){
  8768. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8769. out_full_message[nameLength] = '\0';
  8770. }else{
  8771. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8772. }
  8773. if( is_atcommand( fd, sd, out_message, 1 ) )
  8774. return false;
  8775. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8776. return false; //no "chatting" while muted.
  8777. if( battle_config.min_chat_delay ) { //[Skotlex]
  8778. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8779. return false;
  8780. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8781. }
  8782. if (battle_config.idletime_option&IDLE_CHAT)
  8783. sd->idletime = last_tick;
  8784. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8785. sd->idletime_hom = last_tick;
  8786. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8787. sd->idletime_mer = last_tick;
  8788. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8789. return true;
  8790. }
  8791. /**
  8792. * Displays a message if the player enters a PK Zone (during pk_mode)
  8793. * @param sd: Player data
  8794. */
  8795. inline void clif_pk_mode_message(struct map_session_data * sd)
  8796. {
  8797. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8798. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8799. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8800. char output[CHAT_SIZE_MAX];
  8801. // 1504: You've entered a PK Zone (safe until level %d).
  8802. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8803. battle_config.pk_min_level);
  8804. clif_showscript(&sd->bl, output, SELF);
  8805. } else {
  8806. // 1503: You've entered a PK Zone.
  8807. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8808. }
  8809. }
  8810. return;
  8811. }
  8812. // ---------------------
  8813. // clif_parse_wanttoconnect
  8814. // ---------------------
  8815. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8816. // error codes:
  8817. // 0 - Success
  8818. // 1 - Unknown packet_ver
  8819. // 2 - Invalid account_id
  8820. // 3 - Invalid char_id
  8821. // 4 - Invalid login_id1 (reserved)
  8822. // 5 - Invalid client_tick (reserved)
  8823. // 6 - Invalid sex
  8824. // Only the first 'invalid' error that appears is used.
  8825. static int clif_parse_WantToConnection_sub(int fd)
  8826. {
  8827. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8828. unsigned short cmd;
  8829. //By default, start searching on the default one.
  8830. cmd = RFIFOW(fd, 0);
  8831. packet_len = RFIFOREST(fd);
  8832. // FIXME: If the packet is not received at once, this will FAIL.
  8833. // Figure out, when it happens, that only part of the packet is
  8834. // received, or fix the function to be able to deal with that
  8835. // case.
  8836. if( packet_len != packet_db[cmd].len )
  8837. return 1; /* wrong length */
  8838. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8839. return 2; /* invalid account_id */
  8840. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8841. return 3; /* invalid char_id */
  8842. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8843. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8844. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8845. return 6; /* invalid sex */
  8846. else
  8847. return 0;
  8848. }
  8849. /// Request to connect to map-server.
  8850. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8851. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8852. /// There are various variants of this packet, some of them have padding between fields.
  8853. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8854. {
  8855. struct block_list* bl;
  8856. struct auth_node* node;
  8857. int cmd, account_id, char_id, login_id1, sex, err;
  8858. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8859. if (sd) {
  8860. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8861. return;
  8862. }
  8863. cmd = RFIFOW(fd, 0);
  8864. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8865. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8866. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8867. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8868. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8869. err = clif_parse_WantToConnection_sub(fd);
  8870. if( err ){ // connection rejected
  8871. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8872. err == 1 ? "." :
  8873. err == 2 ? ", possibly for having an invalid account_id." :
  8874. err == 3 ? ", possibly for having an invalid char_id." :
  8875. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8876. err == 4 ? ", possibly for having an invalid login_id1." :
  8877. err == 5 ? ", possibly for having an invalid client_tick." :
  8878. */
  8879. err == 6 ? ", possibly for having an invalid sex." :
  8880. ". ERROR invalid error code"));
  8881. WFIFOHEAD(fd,packet_len(0x6a));
  8882. WFIFOW(fd,0) = 0x6a;
  8883. WFIFOB(fd,2) = err;
  8884. WFIFOSET(fd,packet_len(0x6a));
  8885. #ifdef DUMP_INVALID_PACKET
  8886. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8887. #endif
  8888. RFIFOSKIP(fd, RFIFOREST(fd));
  8889. set_eof(fd);
  8890. return;
  8891. }
  8892. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8893. clif_authfail_fd(fd,1);// server closed
  8894. return;
  8895. }
  8896. //Check for double login.
  8897. bl = map_id2bl(account_id);
  8898. if(bl && bl->type != BL_PC) {
  8899. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8900. WFIFOHEAD(fd,packet_len(0x6a));
  8901. WFIFOW(fd,0) = 0x6a;
  8902. WFIFOB(fd,2) = 3; // Rejected by server
  8903. WFIFOSET(fd,packet_len(0x6a));
  8904. set_eof(fd);
  8905. return;
  8906. }
  8907. if (bl ||
  8908. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8909. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8910. {
  8911. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8912. return;
  8913. }
  8914. CREATE(sd, TBL_PC, 1);
  8915. sd->fd = fd;
  8916. #ifdef PACKET_OBFUSCATION
  8917. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8918. #endif
  8919. session[fd]->session_data = sd;
  8920. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8921. #if PACKETVER < 20070521
  8922. WFIFOHEAD(fd,4);
  8923. WFIFOL(fd,0) = sd->bl.id;
  8924. WFIFOSET(fd,4);
  8925. #else
  8926. WFIFOHEAD(fd,packet_len(0x283));
  8927. WFIFOW(fd,0) = 0x283;
  8928. WFIFOL(fd,2) = sd->bl.id;
  8929. WFIFOSET(fd,packet_len(0x283));
  8930. #endif
  8931. chrif_authreq(sd,false);
  8932. }
  8933. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8934. /// 007d
  8935. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8936. {
  8937. bool guild_notice = false;
  8938. if(sd->bl.prev != NULL)
  8939. return;
  8940. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8941. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8942. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8943. sd->state.connect_new = 0;
  8944. return;
  8945. }
  8946. if (sd->state.rewarp) { //Rewarp player.
  8947. sd->state.rewarp = 0;
  8948. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8949. return;
  8950. }
  8951. sd->state.warping = 0;
  8952. // look
  8953. #if PACKETVER < 4
  8954. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8955. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8956. #else
  8957. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8958. #endif
  8959. pc_set_costume_view(sd);
  8960. if(sd->vd.cloth_color)
  8961. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8962. if(sd->vd.body_style)
  8963. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8964. // item
  8965. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8966. pc_checkitem(sd);
  8967. clif_equipswitch_list(sd);
  8968. // cart
  8969. if(pc_iscarton(sd)) {
  8970. clif_cartlist(sd);
  8971. clif_updatestatus(sd,SP_CARTINFO);
  8972. }
  8973. // weight
  8974. clif_updatestatus(sd,SP_WEIGHT);
  8975. clif_updatestatus(sd,SP_MAXWEIGHT);
  8976. // guild
  8977. // (needs to go before clif_spawn() to show guild emblems correctly)
  8978. if(sd->status.guild_id)
  8979. guild_send_memberinfoshort(sd,1);
  8980. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8981. if(battle_config.pc_invincible_time > 0) {
  8982. if(mapdata_flag_gvg(mapdata))
  8983. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8984. else
  8985. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8986. }
  8987. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8988. map_spawnmobs(sd->bl.m);
  8989. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8990. mapdata->users_pvp++;
  8991. }
  8992. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8993. // reset the callshop flag if the player changes map
  8994. sd->state.callshop = 0;
  8995. if(map_addblock(&sd->bl))
  8996. return;
  8997. clif_spawn(&sd->bl);
  8998. // Party
  8999. // (needs to go after clif_spawn() to show hp bars correctly)
  9000. if(sd->status.party_id) {
  9001. party_send_movemap(sd);
  9002. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  9003. }
  9004. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9005. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9006. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9007. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9008. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9009. sd->pvp_rank = 0;
  9010. sd->pvp_lastusers = 0;
  9011. sd->pvp_point = 5;
  9012. sd->pvp_won = 0;
  9013. sd->pvp_lost = 0;
  9014. }
  9015. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9016. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9017. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9018. else if (mapdata->flag[MF_GVG_DUNGEON])
  9019. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9020. else if( mapdata_flag_gvg(mapdata) )
  9021. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9022. else
  9023. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9024. // info about nearby objects
  9025. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9026. 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);
  9027. // pet
  9028. if( sd->pd ) {
  9029. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9030. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9031. pet_return_egg( sd, sd->pd );
  9032. } else {
  9033. if(map_addblock(&sd->pd->bl))
  9034. return;
  9035. clif_spawn(&sd->pd->bl);
  9036. clif_send_petdata(sd,sd->pd,0,0);
  9037. clif_send_petstatus(sd);
  9038. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9039. }
  9040. }
  9041. //homunculus [blackhole89]
  9042. if( hom_is_active(sd->hd) ) {
  9043. if(map_addblock(&sd->hd->bl))
  9044. return;
  9045. clif_spawn(&sd->hd->bl);
  9046. clif_send_homdata(sd,SP_ACK,0);
  9047. clif_hominfo(sd,sd->hd,1);
  9048. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9049. clif_homskillinfoblock(sd);
  9050. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9051. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  9052. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9053. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9054. }
  9055. if( sd->md ) {
  9056. if(map_addblock(&sd->md->bl))
  9057. return;
  9058. clif_spawn(&sd->md->bl);
  9059. clif_mercenary_info(sd);
  9060. clif_mercenary_skillblock(sd);
  9061. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  9062. }
  9063. if( sd->ed ) {
  9064. if (map_addblock(&sd->ed->bl))
  9065. return;
  9066. clif_spawn(&sd->ed->bl);
  9067. clif_elemental_info(sd);
  9068. clif_elemental_updatestatus(sd,SP_HP);
  9069. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9070. clif_elemental_updatestatus(sd,SP_SP);
  9071. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9072. }
  9073. if(sd->state.connect_new) {
  9074. int lv;
  9075. guild_notice = true;
  9076. clif_skillinfoblock(sd);
  9077. clif_hotkeys_send(sd,0);
  9078. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9079. clif_hotkeys_send(sd,1);
  9080. #endif
  9081. clif_updatestatus(sd,SP_BASEEXP);
  9082. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9083. clif_updatestatus(sd,SP_JOBEXP);
  9084. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9085. clif_updatestatus(sd,SP_SKILLPOINT);
  9086. clif_initialstatus(sd);
  9087. if (sd->sc.option&OPTION_FALCON)
  9088. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9089. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9090. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9091. else if (sd->sc.option&OPTION_WUGRIDER)
  9092. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9093. else if (sd->sc.data[SC_ALL_RIDING])
  9094. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9095. if(sd->status.manner < 0)
  9096. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9097. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9098. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9099. if(sd->bl.m == sd->feel_map[0].m
  9100. || sd->bl.m == sd->feel_map[1].m
  9101. || sd->bl.m == sd->feel_map[2].m)
  9102. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9103. }
  9104. if(sd->pd && sd->pd->pet.intimate > 900)
  9105. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9106. if(hom_is_active(sd->hd))
  9107. hom_init_timers(sd->hd);
  9108. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9109. sd->state.night = 1;
  9110. clif_status_load(&sd->bl, EFST_SKE, 1);
  9111. }
  9112. // Notify everyone that this char logged in [Skotlex].
  9113. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9114. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9115. //Login Event
  9116. npc_script_event(sd, NPCE_LOGIN);
  9117. }
  9118. } else {
  9119. //For some reason the client "loses" these on warp/map-change.
  9120. clif_updatestatus(sd,SP_STR);
  9121. clif_updatestatus(sd,SP_AGI);
  9122. clif_updatestatus(sd,SP_VIT);
  9123. clif_updatestatus(sd,SP_INT);
  9124. clif_updatestatus(sd,SP_DEX);
  9125. clif_updatestatus(sd,SP_LUK);
  9126. // abort currently running script
  9127. sd->state.using_fake_npc = 0;
  9128. sd->state.menu_or_input = 0;
  9129. sd->npc_menu = 0;
  9130. if(sd->npc_id)
  9131. npc_event_dequeue(sd);
  9132. }
  9133. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9134. #if PACKETVER >= 20070918
  9135. clif_partyinvitationstate(sd);
  9136. clif_equipcheckbox(sd);
  9137. #endif
  9138. clif_pet_autofeed_status(sd,false);
  9139. #if PACKETVER >= 20170920
  9140. if( battle_config.homunculus_autofeed_always ){
  9141. // Always send ON or OFF
  9142. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9143. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9144. }else{
  9145. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9146. }
  9147. }else{
  9148. // Only send when enabled
  9149. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9150. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9151. }
  9152. }
  9153. #endif
  9154. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9155. clif_guild_notice(sd); // Displays after VIP
  9156. guild_notice = false; // Do not display it twice
  9157. }
  9158. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9159. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9160. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9161. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9162. }
  9163. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9164. { //Display night.
  9165. if( !sd->state.night )
  9166. {
  9167. sd->state.night = 1;
  9168. clif_status_load(&sd->bl, EFST_SKE, 1);
  9169. }
  9170. }
  9171. else if( sd->state.night )
  9172. { //Clear night display.
  9173. sd->state.night = 0;
  9174. clif_status_load(&sd->bl, EFST_SKE, 0);
  9175. }
  9176. if( mapdata->flag[MF_BATTLEGROUND] )
  9177. {
  9178. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9179. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9180. clif_bg_updatescore_single(sd);
  9181. }
  9182. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9183. {
  9184. char output[128];
  9185. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9186. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9187. }
  9188. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9189. mapdata->hpmeter_visible++;
  9190. sd->state.hpmeter_visible = 1;
  9191. }
  9192. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9193. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9194. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9195. #ifdef VIP_ENABLE
  9196. if (!sd->state.connect_new &&
  9197. !sd->vip.disableshowrate &&
  9198. sd->state.pmap != sd->bl.m &&
  9199. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9200. )
  9201. {
  9202. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9203. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9204. }
  9205. #endif
  9206. // Instances do not need their own channels
  9207. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9208. channel_mjoin(sd); //join new map
  9209. clif_pk_mode_message(sd);
  9210. }
  9211. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9212. clif_guild_notice(sd); // Displays at end
  9213. }
  9214. mail_clear(sd);
  9215. /* Guild Aura Init */
  9216. if( sd->guild && sd->state.gmaster_flag ) {
  9217. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9218. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9219. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9220. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9221. }
  9222. if( sd->state.vending ) { /* show we have a vending */
  9223. clif_openvending(sd,sd->bl.id,sd->vending);
  9224. clif_showvendingboard(&sd->bl,sd->message,0);
  9225. }
  9226. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9227. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9228. npc_script_event(sd, NPCE_LOADMAP);
  9229. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9230. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9231. if (sd->sc.opt2) //Client loses these on warp.
  9232. clif_changeoption(&sd->bl);
  9233. 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)) {
  9234. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9235. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9236. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9237. }
  9238. clif_weather_check(sd);
  9239. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9240. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9241. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9242. else
  9243. sd->areanpc.clear();
  9244. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9245. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9246. pc_setdead(sd);
  9247. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9248. if(pc_isdead(sd))
  9249. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9250. else {
  9251. skill_usave_trigger(sd);
  9252. if (battle_config.spawn_direction)
  9253. clif_changed_dir(&sd->bl, SELF);
  9254. }
  9255. // Trigger skill effects if you appear standing on them
  9256. if(!battle_config.pc_invincible_time)
  9257. skill_unit_move(&sd->bl,gettick(),1);
  9258. pc_show_questinfo_reinit(sd);
  9259. pc_show_questinfo(sd);
  9260. #if PACKETVER >= 20150513
  9261. if( sd->mail.inbox.unread ){
  9262. clif_Mail_new(sd, 0, NULL, NULL);
  9263. }
  9264. #endif
  9265. sd->state.connect_new = 0;
  9266. sd->state.changemap = false;
  9267. }
  9268. /// Server's tick (ZC_NOTIFY_TIME).
  9269. /// 007f <time>.L
  9270. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9271. {
  9272. int fd = sd->fd;
  9273. WFIFOHEAD(fd,packet_len(0x7f));
  9274. WFIFOW(fd,0) = 0x7f;
  9275. WFIFOL(fd,2) = client_tick(time);
  9276. WFIFOSET(fd,packet_len(0x7f));
  9277. }
  9278. /// Request for server's tick.
  9279. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9280. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9281. /// There are various variants of this packet, some of them have padding between fields.
  9282. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9283. {
  9284. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9285. clif_notify_time(sd, gettick());
  9286. }
  9287. /// Sends hotkey bar.
  9288. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9289. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9290. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9291. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9292. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9293. #ifdef HOTKEY_SAVING
  9294. nullpo_retv( sd );
  9295. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9296. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9297. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9298. if( tab == 0 ){
  9299. p.rotate = sd->status.hotkey_rowshift;
  9300. }else{
  9301. p.rotate = sd->status.hotkey_rowshift2;
  9302. }
  9303. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9304. p.tab = tab;
  9305. #endif
  9306. #endif
  9307. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9308. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9309. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9310. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9311. }
  9312. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9313. #endif
  9314. }
  9315. /// Request to update a position on the hotkey row bar
  9316. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9317. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9318. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9319. if( p->tab == 0 ){
  9320. sd->status.hotkey_rowshift = p->rowshift;
  9321. }else{
  9322. sd->status.hotkey_rowshift2 = p->rowshift;
  9323. }
  9324. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9325. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9326. sd->status.hotkey_rowshift = p->rowshift;
  9327. #endif
  9328. }
  9329. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9330. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9331. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9332. #ifdef HOTKEY_SAVING
  9333. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9334. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9335. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9336. if( idx >= MAX_HOTKEYS_DB ){
  9337. return;
  9338. }
  9339. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9340. sd->status.hotkeys[idx].id = p->hotkey.id;
  9341. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9342. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9343. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9344. const unsigned short idx = p->index;
  9345. if( idx >= MAX_HOTKEYS_DB ){
  9346. return;
  9347. }
  9348. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9349. sd->status.hotkeys[idx].id = p->hotkey.id;
  9350. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9351. #endif
  9352. #endif
  9353. }
  9354. /// Displays cast-like progress bar (ZC_PROGRESS).
  9355. /// 02f0 <color>.L <time>.L
  9356. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9357. {
  9358. int fd = sd->fd;
  9359. WFIFOHEAD(fd,packet_len(0x2f0));
  9360. WFIFOW(fd,0) = 0x2f0;
  9361. WFIFOL(fd,2) = color;
  9362. WFIFOL(fd,6) = second;
  9363. WFIFOSET(fd,packet_len(0x2f0));
  9364. }
  9365. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9366. /// 02f2
  9367. void clif_progressbar_abort(struct map_session_data * sd)
  9368. {
  9369. int fd = sd->fd;
  9370. WFIFOHEAD(fd,packet_len(0x2f2));
  9371. WFIFOW(fd,0) = 0x2f2;
  9372. WFIFOSET(fd,packet_len(0x2f2));
  9373. }
  9374. /// Notification from the client, that the progress bar has reached 100%.
  9375. /// 02f1 (CZ_PROGRESS)
  9376. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9377. // No progressbar active, ignore it
  9378. if( !sd->progressbar.npc_id ){
  9379. return;
  9380. }
  9381. int npc_id = sd->progressbar.npc_id;
  9382. bool closing = false;
  9383. // Check if the progress was canceled
  9384. if( gettick() < sd->progressbar.timeout && sd->st ){
  9385. closing = true;
  9386. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9387. // If a message window was open, offer a close button to the user
  9388. if( sd->st->mes_active ){
  9389. clif_scriptclose( sd, npc_id );
  9390. }
  9391. }
  9392. sd->progressbar.npc_id = 0;
  9393. sd->progressbar.timeout = 0;
  9394. sd->state.workinprogress = WIP_DISABLE_NONE;
  9395. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9396. sd->idletime = last_tick;
  9397. }
  9398. npc_scriptcont(sd, npc_id, closing);
  9399. }
  9400. /// Displays cast-like progress bar on a NPC
  9401. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9402. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9403. #if PACKETVER >= 20130821
  9404. unsigned char buf[14];
  9405. if( nd->progressbar.timeout > 0 ){
  9406. WBUFW(buf,0) = 0x9d1;
  9407. WBUFL(buf,2) = nd->bl.id;
  9408. WBUFL(buf,6) = nd->progressbar.color;
  9409. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9410. if( sd ){
  9411. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9412. }else{
  9413. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9414. }
  9415. }
  9416. #endif
  9417. }
  9418. /// Request to walk to a certain position on the current map.
  9419. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9420. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9421. /// There are various variants of this packet, some of them have padding between fields.
  9422. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9423. {
  9424. short x, y;
  9425. if (pc_isdead(sd)) {
  9426. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9427. return;
  9428. }
  9429. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9430. ; //You CAN walk on this OPT1 value.
  9431. else if (sd->progressbar.npc_id) {
  9432. clif_progressbar_abort(sd);
  9433. return; // First walk attempt cancels the progress bar
  9434. } else if (pc_cant_act(sd))
  9435. return;
  9436. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9437. return;
  9438. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9439. //A move command one cell west is only valid if the target cell is free
  9440. if(battle_config.official_cell_stack_limit > 0
  9441. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9442. return;
  9443. // Cloaking wall check is actually updated when you click to process next movement
  9444. // not when you move each cell. This is official behaviour.
  9445. if (sd->sc.data[SC_CLOAKING])
  9446. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9447. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9448. pc_delinvincibletimer(sd);
  9449. //Set last idle time... [Skotlex]
  9450. if (battle_config.idletime_option&IDLE_WALK)
  9451. sd->idletime = last_tick;
  9452. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9453. sd->idletime_hom = last_tick;
  9454. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9455. sd->idletime_mer = last_tick;
  9456. unit_walktoxy(&sd->bl, x, y, 4);
  9457. }
  9458. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9459. /// 018b <result>.W
  9460. /// result:
  9461. /// 0 = disconnect (quit)
  9462. /// 1 = cannot disconnect (wait 10 seconds)
  9463. /// ? = ignored
  9464. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9465. {
  9466. int fd = sd->fd;
  9467. WFIFOHEAD(fd,packet_len(0x18b));
  9468. WFIFOW(fd,0) = 0x18b;
  9469. WFIFOW(fd,2) = result;
  9470. WFIFOSET(fd,packet_len(0x18b));
  9471. }
  9472. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9473. /// 018a <type>.W
  9474. /// type:
  9475. /// 0 = quit
  9476. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9477. {
  9478. /* Rovert's prevent logout option fixed [Valaris] */
  9479. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9480. 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] &&
  9481. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9482. {
  9483. pc_damage_log_clear(sd,0);
  9484. clif_disconnect_ack(sd, 0);
  9485. flush_fifo( fd );
  9486. if( battle_config.drop_connection_on_quit ){
  9487. set_eof( fd );
  9488. }
  9489. } else {
  9490. clif_disconnect_ack(sd, 1);
  9491. }
  9492. }
  9493. /// Requesting unit's name.
  9494. /// 0094 <id>.L (CZ_REQNAME)
  9495. /// 0368 <id>.L (CZ_REQNAME2)
  9496. /// There are various variants of this packet, some of them have padding between fields.
  9497. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9498. {
  9499. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9500. struct block_list* bl;
  9501. //struct status_change *sc;
  9502. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9503. id = sd->bl.id;
  9504. bl = map_id2bl(id);
  9505. if( bl == NULL )
  9506. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9507. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9508. return; // Block namerequests past view range
  9509. // 'see people in GM hide' cheat detection
  9510. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9511. sc = status_get_sc(bl);
  9512. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9513. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9514. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9515. ) {
  9516. char gm_msg[256];
  9517. 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);
  9518. ShowWarning(gm_msg);
  9519. // information is sent to all online GMs
  9520. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9521. return;
  9522. }
  9523. */
  9524. clif_name(&sd->bl,bl,SELF);
  9525. }
  9526. /// Validates and processes global messages
  9527. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9528. /// There are various variants of this packet.
  9529. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9530. {
  9531. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9532. size_t length;
  9533. // validate packet and retrieve name and message
  9534. if( !clif_process_message(sd, false, name, message, output ) )
  9535. return;
  9536. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9537. channel_send(sd->gcbind,sd,message);
  9538. return;
  9539. }
  9540. // send message to others (using the send buffer for temp. storage)
  9541. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9542. length = strlen(output) + 1;
  9543. // send back message to the speaker
  9544. WFIFOHEAD(fd,4+length);
  9545. WFIFOW(fd,0) = 0x8e;
  9546. WFIFOW(fd,2) = (uint16)(4+length);
  9547. safestrncpy(WFIFOCP(fd,4), output, length );
  9548. WFIFOSET(fd, WFIFOW(fd,2));
  9549. #ifdef PCRE_SUPPORT
  9550. // trigger listening npcs
  9551. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9552. #endif
  9553. // Chat logging type 'O' / Global Chat
  9554. 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);
  9555. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9556. }
  9557. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9558. /// Request to warp to a map on given coordinates.
  9559. /// 0140 <map name>.16B <x>.W <y>.W
  9560. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9561. {
  9562. char command[MAP_NAME_LENGTH_EXT+25];
  9563. char* map_name;
  9564. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9565. map_name = RFIFOCP(fd,info->pos[0]);
  9566. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9567. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9568. RFIFOW(fd,info->pos[1]), //x
  9569. RFIFOW(fd,info->pos[2])); //y
  9570. is_atcommand(fd, sd, command, 1);
  9571. }
  9572. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9573. /// 009c <id>.L <head dir>.W <dir>.B
  9574. /// head dir:
  9575. /// 0 = straight
  9576. /// 1 = turned CW
  9577. /// 2 = turned CCW
  9578. /// dir:
  9579. /// 0 = north
  9580. /// 1 = northwest
  9581. /// 2 = west
  9582. /// 3 = southwest
  9583. /// 4 = south
  9584. /// 5 = southeast
  9585. /// 6 = east
  9586. /// 7 = northeast
  9587. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9588. {
  9589. unsigned char buf[64];
  9590. WBUFW(buf,0) = 0x9c;
  9591. WBUFL(buf,2) = bl->id;
  9592. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9593. WBUFB(buf,8) = unit_getdir(bl);
  9594. clif_send(buf, packet_len(0x9c), bl, target);
  9595. if (disguised(bl)) {
  9596. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9597. WBUFW(buf,6) = 0;
  9598. clif_send(buf, packet_len(0x9c), bl, SELF);
  9599. }
  9600. }
  9601. /// Request to change own body and head direction.
  9602. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9603. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9604. /// There are various variants of this packet, some of them have padding between fields.
  9605. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9606. {
  9607. unsigned char headdir, dir;
  9608. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9609. headdir = RFIFOB(fd,info->pos[0]);
  9610. dir = RFIFOB(fd,info->pos[1]);
  9611. pc_setdir(sd, dir, headdir);
  9612. clif_changed_dir(&sd->bl, AREA_WOS);
  9613. }
  9614. /// Request to show an emotion (CZ_REQ_EMOTION).
  9615. /// 00bf <type>.B
  9616. /// type:
  9617. /// @see enum emotion_type
  9618. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9619. {
  9620. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9621. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9622. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9623. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9624. return;
  9625. }
  9626. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9627. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9628. sd->emotionlasttime = time(NULL);
  9629. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9630. return;
  9631. }
  9632. sd->emotionlasttime = time(NULL);
  9633. if (battle_config.idletime_option&IDLE_EMOTION)
  9634. sd->idletime = last_tick;
  9635. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9636. sd->idletime_hom = last_tick;
  9637. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9638. sd->idletime_mer = last_tick;
  9639. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9640. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9641. return;
  9642. }
  9643. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9644. emoticon = rnd()%6+ET_DICE1;
  9645. }
  9646. clif_emotion(&sd->bl, emoticon);
  9647. } else
  9648. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9649. }
  9650. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9651. /// 00c2 <count>.L
  9652. void clif_user_count(struct map_session_data* sd, int count)
  9653. {
  9654. int fd = sd->fd;
  9655. WFIFOHEAD(fd,packet_len(0xc2));
  9656. WFIFOW(fd,0) = 0xc2;
  9657. WFIFOL(fd,2) = count;
  9658. WFIFOSET(fd,packet_len(0xc2));
  9659. }
  9660. /// /w /who (CZ_REQ_USER_COUNT).
  9661. /// Request to display amount of currently connected players.
  9662. /// 00c1
  9663. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9664. {
  9665. clif_user_count(sd, map_getusers());
  9666. }
  9667. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9668. {
  9669. if (pc_isdead(sd)) {
  9670. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9671. return;
  9672. }
  9673. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9674. // (not all are included in pc_can_attack)
  9675. if (sd->sc.count &&
  9676. (sd->sc.data[SC_TRICKDEAD] ||
  9677. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9678. sd->sc.data[SC_BLADESTOP] ||
  9679. sd->sc.data[SC__MANHOLE] ||
  9680. sd->sc.data[SC_SUHIDE] ||
  9681. sd->sc.data[SC_GRAVITYCONTROL]))
  9682. return;
  9683. if(action_type != 0x00 && action_type != 0x07)
  9684. pc_stop_walking(sd, 1);
  9685. pc_stop_attack(sd);
  9686. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9687. target_id = sd->bl.id;
  9688. switch(action_type)
  9689. {
  9690. case 0x00: // once attack
  9691. case 0x07: // continuous attack
  9692. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9693. return;
  9694. if( sd->sc.option&OPTION_COSTUME )
  9695. return;
  9696. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9697. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9698. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9699. return;
  9700. }
  9701. }
  9702. pc_delinvincibletimer(sd);
  9703. if (battle_config.idletime_option&IDLE_ATTACK)
  9704. sd->idletime = last_tick;
  9705. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9706. sd->idletime_hom = last_tick;
  9707. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9708. sd->idletime_mer = last_tick;
  9709. unit_attack(&sd->bl, target_id, action_type != 0);
  9710. break;
  9711. case 0x02: // sitdown
  9712. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9713. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9714. break;
  9715. }
  9716. if(pc_issit(sd)) {
  9717. //Bugged client? Just refresh them.
  9718. clif_sitting(&sd->bl);
  9719. return;
  9720. }
  9721. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9722. break;
  9723. if (sd->sc.count && (
  9724. sd->sc.data[SC_DANCING] ||
  9725. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9726. )) //No sitting during these states either.
  9727. break;
  9728. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9729. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9730. break;
  9731. }
  9732. if (battle_config.idletime_option&IDLE_SIT)
  9733. sd->idletime = last_tick;
  9734. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9735. sd->idletime_hom = last_tick;
  9736. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9737. sd->idletime_mer = last_tick;
  9738. pc_setsit(sd);
  9739. skill_sit(sd, true);
  9740. clif_sitting(&sd->bl);
  9741. break;
  9742. case 0x03: // standup
  9743. if (!pc_issit(sd)) {
  9744. //Bugged client? Just refresh them.
  9745. clif_standing(&sd->bl);
  9746. return;
  9747. }
  9748. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9749. break;
  9750. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9751. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9752. break;
  9753. }
  9754. if (pc_setstand(sd, false)) {
  9755. if (battle_config.idletime_option&IDLE_SIT)
  9756. sd->idletime = last_tick;
  9757. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9758. sd->idletime_hom = last_tick;
  9759. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9760. sd->idletime_mer = last_tick;
  9761. skill_sit(sd, false);
  9762. clif_standing(&sd->bl);
  9763. }
  9764. break;
  9765. }
  9766. }
  9767. /// Request for an action.
  9768. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9769. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9770. /// action:
  9771. /// 0 = attack
  9772. /// 1 = pick up item
  9773. /// 2 = sit down
  9774. /// 3 = stand up
  9775. /// 7 = continous attack
  9776. /// 12 = (touch skill?)
  9777. /// There are various variants of this packet, some of them have padding between fields.
  9778. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9779. {
  9780. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9781. clif_parse_ActionRequest_sub(sd,
  9782. RFIFOB(fd,info->pos[1]),
  9783. RFIFOL(fd,info->pos[0]),
  9784. gettick()
  9785. );
  9786. }
  9787. /// Response to the death/system menu (CZ_RESTART).
  9788. /// 00b2 <type>.B
  9789. /// type:
  9790. /// 0 = restart (respawn)
  9791. /// 1 = char-select (disconnect)
  9792. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9793. {
  9794. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9795. case 0x00:
  9796. pc_respawn(sd,CLR_OUTSIGHT);
  9797. break;
  9798. case 0x01:
  9799. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9800. 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] &&
  9801. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9802. { //Send to char-server for character selection.
  9803. pc_damage_log_clear(sd,0);
  9804. chrif_charselectreq(sd, session[fd]->client_addr);
  9805. } else {
  9806. clif_disconnect_ack(sd, 1);
  9807. }
  9808. break;
  9809. }
  9810. }
  9811. /// Validates and processes whispered messages (CZ_WHISPER).
  9812. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9813. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9814. {
  9815. struct map_session_data* dstsd;
  9816. int i;
  9817. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9818. // validate packet and retrieve name and message
  9819. if( !clif_process_message( sd, true, target, message, output ) )
  9820. return;
  9821. // Chat logging type 'W' / Whisper
  9822. 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);
  9823. //-------------------------------------------------------//
  9824. // Lordalfa - Paperboy - To whisper NPC commands //
  9825. //-------------------------------------------------------//
  9826. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9827. {
  9828. char* str = target+4; //Skip the NPC: string part.
  9829. struct npc_data* npc;
  9830. if ((npc = npc_name2id(str))) {
  9831. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9832. char *split;
  9833. char event[EVENT_NAME_LENGTH];
  9834. str = message;
  9835. // skip codepage indicator, if detected
  9836. if( str[0] == '|' && strlen(str) >= 4 )
  9837. str += 3;
  9838. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9839. split = strchr(str,'#');
  9840. if( split == NULL ) { // use the remaining string
  9841. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9842. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9843. split_data[i][0] = '\0';
  9844. break;
  9845. }
  9846. *split = '\0';
  9847. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9848. str = split+1;
  9849. }
  9850. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9851. char variablename[CHAT_SIZE_MAX];
  9852. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9853. set_var_str( sd, variablename, split_data[i] );
  9854. }
  9855. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9856. npc_event(sd,event,0); // Calls the NPC label
  9857. return;
  9858. }
  9859. } else if( target[0] == '#' ) {
  9860. struct Channel *channel = NULL;
  9861. char* chname = target;
  9862. channel = channel_name2channel(chname,sd,3);
  9863. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9864. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9865. channel_send(channel,sd,message);
  9866. }
  9867. else if( channel->pass[0] == '\0') { //no pass needed
  9868. if (channel_join(channel,sd)==0)
  9869. channel_send(channel,sd,message); //join success
  9870. }
  9871. else {
  9872. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9873. }
  9874. return;
  9875. }
  9876. }
  9877. // searching destination character
  9878. dstsd = map_nick2sd(target,false);
  9879. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9880. // player is not on this map-server
  9881. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9882. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9883. // and if we ask for 'Test', we must not contact 'test' player
  9884. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9885. intif_wis_message(sd, target, message, strlen(message) + 1);
  9886. return;
  9887. }
  9888. // if player ignores everyone
  9889. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9890. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9891. clif_wis_end(fd, 1); // 1: target character is not logged in
  9892. else
  9893. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9894. return;
  9895. }
  9896. // if player is autotrading
  9897. if (dstsd->state.autotrade == 1){
  9898. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9899. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9900. return;
  9901. }
  9902. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9903. // if player ignores the source character
  9904. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9905. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9906. clif_wis_end(fd, 2); // 2: ignored by target
  9907. return;
  9908. }
  9909. }
  9910. // notify sender of success
  9911. clif_wis_end(fd, 0); // 0: success to send wisper
  9912. // Normal message
  9913. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9914. }
  9915. /// /b /nb (CZ_BROADCAST).
  9916. /// Request to broadcast a message on whole server.
  9917. /// 0099 <packet len>.W <text>.?B 00
  9918. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9919. char command[CHAT_SIZE_MAX+11];
  9920. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9921. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9922. char* msg = RFIFOCP(fd,info->pos[1]);
  9923. // as the length varies depending on the command used, just block unreasonably long strings
  9924. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9925. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9926. is_atcommand(fd, sd, command, 1);
  9927. }
  9928. /// Request to pick up an item.
  9929. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9930. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9931. /// There are various variants of this packet, some of them have padding between fields.
  9932. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9933. {
  9934. struct flooritem_data *fitem;
  9935. int map_object_id;
  9936. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9937. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9938. do {
  9939. if (pc_isdead(sd)) {
  9940. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9941. break;
  9942. }
  9943. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9944. break;
  9945. if (pc_cant_act(sd))
  9946. break;
  9947. if (!pc_takeitem(sd, fitem))
  9948. break;
  9949. return;
  9950. } while (0);
  9951. // Client REQUIRES a fail packet or you can no longer pick items.
  9952. clif_additem(sd,0,0,6);
  9953. }
  9954. /// Request to drop an item.
  9955. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9956. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9957. /// There are various variants of this packet, some of them have padding between fields.
  9958. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9959. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9960. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9961. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9962. for(;;) {
  9963. if (pc_isdead(sd))
  9964. break;
  9965. if (pc_cant_act2(sd) || sd->npc_id)
  9966. break;
  9967. if (sd->sc.count && (
  9968. sd->sc.data[SC_AUTOCOUNTER] ||
  9969. sd->sc.data[SC_BLADESTOP] ||
  9970. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9971. ))
  9972. break;
  9973. if (!pc_dropitem(sd, item_index, item_amount))
  9974. break;
  9975. if (battle_config.idletime_option&IDLE_DROPITEM)
  9976. sd->idletime = last_tick;
  9977. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  9978. sd->idletime_hom = last_tick;
  9979. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  9980. sd->idletime_mer = last_tick;
  9981. return;
  9982. }
  9983. //Because the client does not like being ignored.
  9984. clif_dropitem(sd, item_index,0);
  9985. }
  9986. /// Request to use an item.
  9987. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9988. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9989. /// There are various variants of this packet, some of them have padding between fields.
  9990. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9991. {
  9992. int n;
  9993. if (pc_isdead(sd)) {
  9994. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9995. return;
  9996. }
  9997. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9998. clif_msg(sd, WORK_IN_PROGRESS);
  9999. return;
  10000. }
  10001. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10002. if (battle_config.idletime_option&IDLE_USEITEM)
  10003. sd->idletime = last_tick;
  10004. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10005. sd->idletime_hom = last_tick;
  10006. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10007. sd->idletime_mer = last_tick;
  10008. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10009. if(n <0 || n >= MAX_INVENTORY)
  10010. return;
  10011. if (!pc_useitem(sd,n))
  10012. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10013. }
  10014. /// Request to equip an item
  10015. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10016. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10017. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10018. {
  10019. int index;
  10020. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10021. if(pc_isdead(sd)) {
  10022. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10023. return;
  10024. }
  10025. index = RFIFOW(fd,info->pos[0])-2;
  10026. if (index < 0 || index >= MAX_INVENTORY)
  10027. return; //Out of bounds check.
  10028. if(sd->npc_id && !sd->npc_item_flag) {
  10029. return;
  10030. } else if (sd->state.storage_flag || sd->sc.opt1)
  10031. ; //You can equip/unequip stuff while storage is open/under status changes
  10032. else if (pc_cant_act2(sd))
  10033. return;
  10034. if(!sd->inventory.u.items_inventory[index].identify) {
  10035. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  10036. return;
  10037. }
  10038. if(!sd->inventory_data[index])
  10039. return;
  10040. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10041. pet_equipitem(sd,index);
  10042. return;
  10043. }
  10044. if (battle_config.idletime_option&IDLE_USEITEM)
  10045. sd->idletime = last_tick;
  10046. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10047. sd->idletime_hom = last_tick;
  10048. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10049. sd->idletime_mer = last_tick;
  10050. //Client doesn't send the position for ammo.
  10051. if(sd->inventory_data[index]->type == IT_AMMO)
  10052. pc_equipitem(sd,index,EQP_AMMO);
  10053. else {
  10054. int req_pos;
  10055. #if PACKETVER >= 20120925
  10056. req_pos = RFIFOL(fd,info->pos[1]);
  10057. #else
  10058. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10059. #endif
  10060. pc_equipitem(sd,index,req_pos);
  10061. }
  10062. }
  10063. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10064. /// 00ab <index>.W
  10065. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10066. {
  10067. int index;
  10068. if(pc_isdead(sd)) {
  10069. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10070. return;
  10071. }
  10072. if (sd->npc_id && !sd->npc_item_flag) {
  10073. return;
  10074. } else if (sd->state.storage_flag || sd->sc.opt1)
  10075. ; //You can equip/unequip stuff while storage is open/under status changes
  10076. else if (pc_cant_act2(sd))
  10077. return;
  10078. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10079. if (battle_config.idletime_option&IDLE_USEITEM)
  10080. sd->idletime = last_tick;
  10081. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10082. sd->idletime_hom = last_tick;
  10083. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10084. sd->idletime_mer = last_tick;
  10085. pc_unequipitem(sd,index,1);
  10086. }
  10087. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10088. /// 0090 <id>.L <type>.B
  10089. /// type:
  10090. /// 1 = click
  10091. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10092. {
  10093. struct block_list *bl;
  10094. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10095. if(pc_isdead(sd)) {
  10096. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10097. return;
  10098. }
  10099. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10100. #ifdef RENEWAL
  10101. clif_msg( sd, WORK_IN_PROGRESS );
  10102. #endif
  10103. return;
  10104. }
  10105. if( sd->state.mail_writing )
  10106. return;
  10107. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10108. //type = RFIFOB(fd,info->pos[1]);
  10109. if (!bl) return;
  10110. switch (bl->type) {
  10111. case BL_MOB:
  10112. case BL_PC:
  10113. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10114. break;
  10115. case BL_NPC:
  10116. #ifdef RENEWAL
  10117. 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
  10118. clif_msg(sd, WORK_IN_PROGRESS);
  10119. break;
  10120. }
  10121. #endif
  10122. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10123. struct npc_data* nd = (struct npc_data*)bl;
  10124. // Progressbar is running
  10125. if( nd->progressbar.timeout > 0 ){
  10126. return;
  10127. }
  10128. npc_click(sd,nd);
  10129. }
  10130. break;
  10131. }
  10132. }
  10133. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10134. /// 00c5 <id>.L <type>.B
  10135. /// type:
  10136. /// 0 = buy
  10137. /// 1 = sell
  10138. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10139. {
  10140. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10141. if (sd->state.trading)
  10142. return;
  10143. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10144. }
  10145. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10146. /// 00ca <result>.B
  10147. /// result:
  10148. /// 0 = "The deal has successfully completed."
  10149. /// 1 = "You do not have enough zeny."
  10150. /// 2 = "You are over your Weight Limit."
  10151. /// 3 = "Out of the maximum capacity, you have too many items."
  10152. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10153. /// 10 = "Props open-air store sales will be traded in RODEX"
  10154. /// 11 = "The exchange failed."
  10155. /// 12 = "The exchange was well done."
  10156. /// 13 = "The item is already sold and out of stock."
  10157. /// 14 = "There is not enough goods to exchange."
  10158. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10159. {
  10160. int fd = sd->fd;
  10161. WFIFOHEAD(fd,packet_len(0xca));
  10162. WFIFOW(fd,0) = 0xca;
  10163. WFIFOB(fd,2) = result;
  10164. WFIFOSET(fd,packet_len(0xca));
  10165. }
  10166. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10167. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10168. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10169. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10170. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10171. int result;
  10172. if( sd->state.trading || !sd->npc_shopid )
  10173. result = 1;
  10174. else
  10175. result = npc_buylist( sd, n, (struct s_npc_buy_list*)p->items );
  10176. sd->npc_shopid = 0; //Clear shop data.
  10177. clif_npc_buy_result(sd, result);
  10178. }
  10179. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10180. /// 00cb <result>.B
  10181. /// result:
  10182. /// 0 = "The deal has successfully completed."
  10183. /// 1 = "The deal has failed."
  10184. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10185. {
  10186. int fd = sd->fd;
  10187. WFIFOHEAD(fd,packet_len(0xcb));
  10188. WFIFOW(fd,0) = 0xcb;
  10189. WFIFOB(fd,2) = result;
  10190. WFIFOSET(fd,packet_len(0xcb));
  10191. }
  10192. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10193. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10194. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10195. {
  10196. int fail=0,n;
  10197. unsigned short *item_list;
  10198. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10199. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10200. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10201. if (sd->state.trading || !sd->npc_shopid)
  10202. fail = 1;
  10203. else
  10204. fail = npc_selllist(sd,n,item_list);
  10205. sd->npc_shopid = 0; //Clear shop data.
  10206. clif_npc_sell_result(sd, fail);
  10207. }
  10208. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10209. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10210. /// type:
  10211. /// 0 = private
  10212. /// 1 = public
  10213. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10214. {
  10215. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10216. int len = RFIFOW(fd,info->pos[0])-15;
  10217. int limit = RFIFOW(fd,info->pos[1]);
  10218. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10219. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10220. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10221. char s_password[CHATROOM_PASS_SIZE];
  10222. char s_title[CHATROOM_TITLE_SIZE];
  10223. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10224. return;
  10225. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10226. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10227. return;
  10228. }
  10229. if( npc_isnear(&sd->bl) ) {
  10230. // uncomment to send msg_txt.
  10231. //char output[150];
  10232. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10233. //clif_displaymessage(sd->fd, output);
  10234. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10235. return;
  10236. }
  10237. if( len <= 0 )
  10238. return; // invalid input
  10239. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10240. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10241. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10242. }
  10243. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10244. /// 00d9 <chat ID>.L <passwd>.8B
  10245. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10246. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10247. int chatid = RFIFOL(fd,info->pos[0]);
  10248. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10249. chat_joinchat(sd,chatid,password);
  10250. }
  10251. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10252. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10253. /// type:
  10254. /// 0 = private
  10255. /// 1 = public
  10256. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10257. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10258. int len = RFIFOW(fd,info->pos[0])-15;
  10259. int limit = RFIFOW(fd,info->pos[1]);
  10260. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10261. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10262. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10263. char s_password[CHATROOM_PASS_SIZE];
  10264. char s_title[CHATROOM_TITLE_SIZE];
  10265. if( len <= 0 )
  10266. return; // invalid input
  10267. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10268. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10269. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10270. }
  10271. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10272. /// 00e0 <role>.L <nick>.24B
  10273. /// role:
  10274. /// 0 = owner
  10275. /// 1 = normal
  10276. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10277. {
  10278. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10279. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10280. }
  10281. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10282. /// 00e2 <name>.24B
  10283. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10284. {
  10285. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10286. }
  10287. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10288. /// 00e3
  10289. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10290. {
  10291. chat_leavechat(sd,0);
  10292. }
  10293. //Handles notifying asker and rejecter of what has just ocurred.
  10294. //Type is used to determine the correct msg_txt to use:
  10295. //0:
  10296. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10297. {
  10298. const char* msg;
  10299. char output[256];
  10300. // Your request has been rejected by autoreject option.
  10301. msg = msg_txt(sd,392);
  10302. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10303. //Notice that a request was rejected.
  10304. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10305. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10306. }
  10307. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10308. /// 00e4 <account id>.L
  10309. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10310. {
  10311. struct map_session_data *t_sd;
  10312. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10313. if(!sd->chatID && pc_cant_act(sd))
  10314. return; //You can trade while in a chatroom.
  10315. if(t_sd){
  10316. // @noask [LuzZza]
  10317. if(t_sd->state.noask) {
  10318. clif_noask_sub(sd, t_sd, 0);
  10319. return;
  10320. }
  10321. if (t_sd->state.mail_writing) {
  10322. int old = sd->trade_partner;
  10323. // Fake trading
  10324. sd->trade_partner = t_sd->status.account_id;
  10325. clif_tradestart(sd, 5);
  10326. // Restore old state
  10327. sd->trade_partner = old;
  10328. return;
  10329. }
  10330. }
  10331. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10332. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10333. return;
  10334. }
  10335. trade_traderequest(sd,t_sd);
  10336. }
  10337. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10338. /// 00e6 <result>.B
  10339. /// result:
  10340. /// 3 = accepted
  10341. /// 4 = rejected
  10342. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10343. {
  10344. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10345. }
  10346. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10347. /// 00e8 <index>.W <amount>.L
  10348. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10349. {
  10350. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10351. short index = RFIFOW(fd,info->pos[0]);
  10352. int amount = RFIFOL(fd,info->pos[1]);
  10353. if( index == 0 )
  10354. trade_tradeaddzeny(sd, amount);
  10355. else
  10356. trade_tradeadditem(sd, index, (short)amount);
  10357. }
  10358. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10359. /// 00eb
  10360. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10361. {
  10362. trade_tradeok(sd);
  10363. }
  10364. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10365. /// 00ed
  10366. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10367. {
  10368. trade_tradecancel(sd);
  10369. }
  10370. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10371. /// 00ef
  10372. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10373. {
  10374. trade_tradecommit(sd);
  10375. }
  10376. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10377. /// 0118
  10378. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10379. {
  10380. pc_stop_attack(sd);
  10381. if (sd) sd->ud.state.attack_continue = 0;
  10382. }
  10383. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10384. /// 0126 <index>.W <amount>.L
  10385. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10386. {
  10387. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10388. if (pc_istrading(sd))
  10389. return;
  10390. if (!pc_iscarton(sd))
  10391. return;
  10392. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10393. }
  10394. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10395. /// 0127 <index>.W <amount>.L
  10396. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10397. {
  10398. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10399. if (!pc_iscarton(sd))
  10400. return;
  10401. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10402. }
  10403. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10404. /// 012a
  10405. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10406. {
  10407. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10408. #ifdef NEW_CARTS
  10409. && sd->sc.data[SC_PUSH_CART] )
  10410. pc_setcart(sd,0);
  10411. #else
  10412. )
  10413. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10414. #endif
  10415. else // priority to remove this option before we can clear cart
  10416. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10417. }
  10418. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10419. /// 097f <Length>.W <identity>.L <type>.B
  10420. void clif_SelectCart(struct map_session_data *sd) {
  10421. #if PACKETVER >= 20150826
  10422. int i = 0, carts = 3;
  10423. int fd = sd->fd;
  10424. WFIFOHEAD(fd,8 + carts);
  10425. WFIFOW(fd,0) = 0x97f;
  10426. WFIFOW(fd,2) = 8 + carts;
  10427. WFIFOL(fd,4) = sd->status.account_id;
  10428. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10429. for( i = 0; i < carts; i++ ) {
  10430. WFIFOB(fd,8 + i) = 10 + i;
  10431. }
  10432. WFIFOSET(fd,8 + carts);
  10433. #endif
  10434. }
  10435. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10436. /// 0980 <identity>.L <type>.B
  10437. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10438. #if PACKETVER >= 20150826
  10439. int type;
  10440. // Check identity
  10441. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10442. return;
  10443. type = (int)RFIFOB(fd,6);
  10444. // Check type
  10445. if( type < 10 || type > 12 )
  10446. return;
  10447. pc_setcart(sd, type);
  10448. #endif
  10449. }
  10450. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10451. /// 01af <num>.W
  10452. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10453. {// TODO: State tracking?
  10454. int type;
  10455. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10456. return;
  10457. #ifdef RENEWAL
  10458. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10459. clif_msg(sd, WORK_IN_PROGRESS);
  10460. return;
  10461. }
  10462. #endif
  10463. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10464. if(
  10465. #ifdef NEW_CARTS
  10466. #if PACKETVER >= 20191106
  10467. (type == 13 && sd->status.base_level > 100) ||
  10468. #endif
  10469. (type == 9 && sd->status.base_level > 130) ||
  10470. (type == 8 && sd->status.base_level > 120) ||
  10471. (type == 7 && sd->status.base_level > 110) ||
  10472. (type == 6 && sd->status.base_level > 100) ||
  10473. #endif
  10474. (type == 5 && sd->status.base_level > 90) ||
  10475. (type == 4 && sd->status.base_level > 80) ||
  10476. (type == 3 && sd->status.base_level > 65) ||
  10477. (type == 2 && sd->status.base_level > 40) ||
  10478. (type == 1))
  10479. pc_setcart(sd, type);
  10480. }
  10481. /// Request to increase status (CZ_STATUS_CHANGE).
  10482. /// 00bb <status id>.W <amount>.B
  10483. /// status id:
  10484. /// SP_STR ~ SP_LUK
  10485. /// amount:
  10486. /// Old clients always send 1 for this, even when using /str+ and the like.
  10487. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10488. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10489. {
  10490. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10491. if( increase_amount < 0 ) {
  10492. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10493. fd, increase_amount);
  10494. }
  10495. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10496. }
  10497. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10498. /// 0112 <skill id>.W
  10499. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10500. {
  10501. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10502. }
  10503. 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)
  10504. {
  10505. int lv;
  10506. if( !hd )
  10507. return;
  10508. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10509. clif_emotion(&hd->bl, ET_THINK);
  10510. return;
  10511. }
  10512. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10513. target_id = hd->bl.id;
  10514. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10515. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10516. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10517. clif_emotion(&hd->bl, ET_THINK);
  10518. if (hd->master)
  10519. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10520. return;
  10521. }
  10522. lv = hom_checkskill(hd, skill_id);
  10523. if( skill_lv > lv )
  10524. skill_lv = lv;
  10525. if( skill_lv )
  10526. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10527. }
  10528. 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)
  10529. {
  10530. int lv;
  10531. if( !hd )
  10532. return;
  10533. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10534. clif_emotion(&hd->bl, ET_THINK);
  10535. return;
  10536. }
  10537. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10538. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10539. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10540. clif_emotion(&hd->bl, ET_THINK);
  10541. if (hd->master)
  10542. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10543. return;
  10544. }
  10545. #ifdef RENEWAL
  10546. if (hd->sc.data[SC_BASILICA_CELL])
  10547. #else
  10548. if (hd->sc.data[SC_BASILICA])
  10549. #endif
  10550. return;
  10551. lv = hom_checkskill(hd, skill_id);
  10552. if( skill_lv > lv )
  10553. skill_lv = lv;
  10554. if( skill_lv )
  10555. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10556. }
  10557. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10558. {
  10559. int lv;
  10560. if( !md )
  10561. return;
  10562. if( skill_isNotOk_mercenary(skill_id, md) )
  10563. return;
  10564. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10565. target_id = md->bl.id;
  10566. if( md->ud.skilltimer != INVALID_TIMER )
  10567. {
  10568. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10569. }
  10570. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10571. return;
  10572. lv = mercenary_checkskill(md, skill_id);
  10573. if( skill_lv > lv )
  10574. skill_lv = lv;
  10575. if( skill_lv )
  10576. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10577. }
  10578. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10579. {
  10580. int lv;
  10581. if( !md )
  10582. return;
  10583. if( skill_isNotOk_mercenary(skill_id, md) )
  10584. return;
  10585. if( md->ud.skilltimer != INVALID_TIMER )
  10586. return;
  10587. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10588. {
  10589. if (md->master)
  10590. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10591. return;
  10592. }
  10593. #ifdef RENEWAL
  10594. if (md->sc.data[SC_BASILICA_CELL])
  10595. #else
  10596. if (md->sc.data[SC_BASILICA])
  10597. #endif
  10598. return;
  10599. lv = mercenary_checkskill(md, skill_id);
  10600. if( skill_lv > lv )
  10601. skill_lv = lv;
  10602. if( skill_lv )
  10603. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10604. }
  10605. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10606. t_tick tick = gettick();
  10607. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10608. int inf = skill_get_inf(skill_id);
  10609. if (inf&INF_GROUND_SKILL || !inf)
  10610. return; //Using a ground/passive skill on a target? WRONG.
  10611. if (sd->state.block_action & PCBLOCK_SKILL) {
  10612. clif_msg(sd, WORK_IN_PROGRESS);
  10613. return;
  10614. }
  10615. if( SKILL_CHK_HOMUN(skill_id) ) {
  10616. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10617. return;
  10618. }
  10619. if( SKILL_CHK_MERC(skill_id) ) {
  10620. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10621. return;
  10622. }
  10623. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10624. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10625. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10626. sd->idletime = last_tick;
  10627. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10628. sd->idletime_hom = last_tick;
  10629. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10630. sd->idletime_mer = last_tick;
  10631. if( sd->npc_id ){
  10632. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10633. #ifdef RENEWAL
  10634. clif_msg( sd, WORK_IN_PROGRESS );
  10635. #endif
  10636. return;
  10637. }
  10638. }
  10639. if ((pc_cant_act2(sd) || sd->chatID) &&
  10640. skill_id != RK_REFRESH &&
  10641. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10642. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10643. return;
  10644. if( pc_issit(sd) )
  10645. return;
  10646. if( skill_isNotOk(skill_id, sd) )
  10647. return;
  10648. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10649. target_id = sd->bl.id; // never trust the client
  10650. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10651. target_id = sd->bl.id;
  10652. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10653. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10654. return;
  10655. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10656. if( sd->skillitem != skill_id ) {
  10657. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10658. return;
  10659. }
  10660. }
  10661. if( sd->sc.option&OPTION_COSTUME )
  10662. return;
  10663. #ifndef RENEWAL
  10664. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10665. return; // On basilica only caster can use Basilica again to stop it.
  10666. #endif
  10667. if( sd->menuskill_id ) {
  10668. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10669. clif_menuskill_clear(sd); //Cancel pet capture.
  10670. }else if( sd->menuskill_id == SG_FEEL ){
  10671. clif_menuskill_clear( sd ); // Cancel selection
  10672. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10673. return; //Can't use skills while a menu is open.
  10674. }
  10675. if( sd->skillitem == skill_id ) {
  10676. if( skill_lv != sd->skillitemlv )
  10677. skill_lv = sd->skillitemlv;
  10678. if( !(inf&INF_SELF_SKILL) )
  10679. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10680. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10681. return;
  10682. }
  10683. sd->skillitem = sd->skillitemlv = 0;
  10684. if( SKILL_CHK_GUILD(skill_id) ) {
  10685. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10686. skill_lv = guild_checkskill(sd->guild, skill_id);
  10687. else
  10688. skill_lv = 0;
  10689. } else {
  10690. if( skill_id != ALL_EQSWITCH ){
  10691. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10692. }
  10693. }
  10694. pc_delinvincibletimer(sd);
  10695. if( skill_lv )
  10696. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10697. }
  10698. /// Request to use a targeted skill.
  10699. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10700. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10701. /// There are various variants of this packet, some of them have padding between fields.
  10702. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10703. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10704. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10705. }
  10706. /*==========================================
  10707. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10708. *------------------------------------------*/
  10709. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10710. {
  10711. t_tick tick = gettick();
  10712. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10713. return; //Using a target skill on the ground? WRONG.
  10714. if (sd->state.block_action & PCBLOCK_SKILL) {
  10715. clif_msg(sd, WORK_IN_PROGRESS);
  10716. return;
  10717. }
  10718. if( SKILL_CHK_HOMUN(skill_id) ) {
  10719. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10720. return;
  10721. }
  10722. if( SKILL_CHK_MERC(skill_id) ) {
  10723. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10724. return;
  10725. }
  10726. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10727. #ifdef RENEWAL
  10728. clif_msg( sd, WORK_IN_PROGRESS );
  10729. #endif
  10730. return;
  10731. }
  10732. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10733. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10734. sd->idletime = last_tick;
  10735. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10736. sd->idletime_hom = last_tick;
  10737. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10738. sd->idletime_mer = last_tick;
  10739. if( skill_isNotOk(skill_id, sd) )
  10740. return;
  10741. if( skillmoreinfo != -1 ) {
  10742. if( pc_issit(sd) ) {
  10743. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10744. return;
  10745. }
  10746. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10747. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10748. }
  10749. if( sd->ud.skilltimer != INVALID_TIMER )
  10750. return;
  10751. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10752. if( sd->skillitem != skill_id ) {
  10753. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10754. return;
  10755. }
  10756. }
  10757. if( sd->sc.option&OPTION_COSTUME )
  10758. return;
  10759. #ifndef RENEWAL
  10760. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10761. return; // On basilica only caster can use Basilica again to stop it.
  10762. #endif
  10763. if( sd->menuskill_id ) {
  10764. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10765. clif_menuskill_clear(sd); //Cancel pet capture.
  10766. }else if( sd->menuskill_id == SG_FEEL ){
  10767. clif_menuskill_clear( sd ); // Cancel selection
  10768. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10769. return; //Can't use skills while a menu is open.
  10770. }
  10771. pc_delinvincibletimer(sd);
  10772. if( sd->skillitem == skill_id ) {
  10773. if( skill_lv != sd->skillitemlv )
  10774. skill_lv = sd->skillitemlv;
  10775. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10776. } else {
  10777. int lv;
  10778. sd->skillitem = sd->skillitemlv = 0;
  10779. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10780. if( skill_lv > lv )
  10781. skill_lv = lv;
  10782. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10783. }
  10784. }
  10785. }
  10786. /// Request to use a ground skill.
  10787. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10788. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10789. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10790. /// There are various variants of this packet, some of them have padding between fields.
  10791. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10792. {
  10793. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10794. if (pc_cant_act(sd))
  10795. return;
  10796. if (pc_issit(sd))
  10797. return;
  10798. clif_parse_UseSkillToPosSub(fd, sd,
  10799. RFIFOW(fd,info->pos[0]), //skill lv
  10800. RFIFOW(fd,info->pos[1]), //skill num
  10801. RFIFOW(fd,info->pos[2]), //pos x
  10802. RFIFOW(fd,info->pos[3]), //pos y
  10803. // TODO: find out what this is intended to do
  10804. //RFIFOB(fd, info->pos[4])
  10805. -1 //Skill more info.
  10806. );
  10807. }
  10808. /// Request to use a ground skill with text.
  10809. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10810. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10811. /// There are various variants of this packet, some of them have padding between fields.
  10812. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10813. {
  10814. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10815. if (pc_cant_act(sd))
  10816. return;
  10817. if (pc_issit(sd))
  10818. return;
  10819. clif_parse_UseSkillToPosSub(fd, sd,
  10820. RFIFOW(fd,info->pos[0]), //Skill lv
  10821. RFIFOW(fd,info->pos[1]), //Skill num
  10822. RFIFOW(fd,info->pos[2]), //pos x
  10823. RFIFOW(fd,info->pos[3]), //pos y
  10824. info->pos[4] //skill more info
  10825. );
  10826. }
  10827. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10828. /// 011b <skill id>.W <map name>.16B
  10829. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10830. {
  10831. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10832. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10833. char map_name[MAP_NAME_LENGTH];
  10834. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10835. sd->state.workinprogress = WIP_DISABLE_NONE;
  10836. if(skill_id != sd->menuskill_id)
  10837. return;
  10838. //It is possible to use teleport with the storage window open bugreport:8027
  10839. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10840. clif_menuskill_clear(sd);
  10841. return;
  10842. }
  10843. pc_delinvincibletimer(sd);
  10844. skill_castend_map(sd,skill_id,map_name);
  10845. }
  10846. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10847. /// 011d
  10848. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10849. {
  10850. if (!pc_isdead(sd))
  10851. pc_memo(sd,-1);
  10852. }
  10853. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10854. /// 018e <name id>.W { <material id>.W }*3
  10855. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10856. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10857. switch( sd->menuskill_id ) {
  10858. case -1:
  10859. case AM_PHARMACY:
  10860. case RK_RUNEMASTERY:
  10861. case GC_RESEARCHNEWPOISON:
  10862. break;
  10863. default:
  10864. return;
  10865. }
  10866. if (pc_istrading(sd)) {
  10867. //Make it fail to avoid shop exploits where you sell something different than you see.
  10868. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10869. clif_menuskill_clear(sd);
  10870. return;
  10871. }
  10872. int produce_idx;
  10873. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10874. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10875. clif_menuskill_clear(sd);
  10876. }
  10877. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10878. /// 025b <mk type>.W <name id>.W
  10879. /// mk type:
  10880. /// 1 = cooking
  10881. /// 2 = arrow
  10882. /// 3 = elemental
  10883. /// 4 = GN_MIX_COOKING
  10884. /// 5 = GN_MAKEBOMB
  10885. /// 6 = GN_S_PHARMACY
  10886. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10887. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10888. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10889. short food_idx = -1;
  10890. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10891. return;
  10892. if (pc_istrading(sd)) {
  10893. //Make it fail to avoid shop exploits where you sell something different than you see.
  10894. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10895. clif_menuskill_clear(sd);
  10896. return;
  10897. }
  10898. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10899. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10900. clif_menuskill_clear(sd);
  10901. }
  10902. /// Answer to repair weapon item selection dialog
  10903. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10904. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10905. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  10906. const struct PACKET_CZ_REQ_ITEMREPAIR *p = (struct PACKET_CZ_REQ_ITEMREPAIR *)RFIFOP( fd, 0 );
  10907. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10908. return;
  10909. if (pc_istrading(sd)) {
  10910. //Make it fail to avoid shop exploits where you sell something different than you see.
  10911. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10912. clif_menuskill_clear(sd);
  10913. return;
  10914. }
  10915. skill_repairweapon( sd, p->index );
  10916. clif_menuskill_clear(sd);
  10917. }
  10918. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10919. /// 0222 <index>.L
  10920. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  10921. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10922. return;
  10923. if (pc_istrading(sd)) {
  10924. //Make it fail to avoid shop exploits where you sell something different than you see.
  10925. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10926. clif_menuskill_clear(sd);
  10927. return;
  10928. }
  10929. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  10930. clif_menuskill_clear(sd);
  10931. }
  10932. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10933. /// 00b8 <npc id>.L <choice>.B
  10934. /// choice:
  10935. /// 1~254 = menu item
  10936. /// 255 = cancel
  10937. /// NOTE: If there were more than 254 items in the list, choice
  10938. /// overflows to choice%256.
  10939. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10940. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10941. int npc_id = RFIFOL(fd,info->pos[0]);
  10942. uint8 select = RFIFOB(fd,info->pos[1]);
  10943. #ifdef SECURE_NPCTIMEOUT
  10944. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  10945. return;
  10946. #endif
  10947. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10948. TBL_NPC* nd = map_id2nd(npc_id);
  10949. 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);
  10950. clif_GM_kick(NULL,sd);
  10951. return;
  10952. }
  10953. sd->npc_menu = select;
  10954. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  10955. sd->idletime = last_tick;
  10956. }
  10957. npc_scriptcont(sd,npc_id, false);
  10958. }
  10959. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10960. /// 00b9 <npc id>.L
  10961. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10962. {
  10963. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  10964. sd->idletime = last_tick;
  10965. }
  10966. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10967. }
  10968. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10969. /// 0143 <npc id>.L <value>.L
  10970. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10971. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10972. int npcid = RFIFOL(fd,info->pos[0]);
  10973. int amount = (int)RFIFOL(fd,info->pos[1]);
  10974. sd->npc_amount = amount;
  10975. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  10976. sd->idletime = last_tick;
  10977. }
  10978. npc_scriptcont(sd, npcid, false);
  10979. }
  10980. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10981. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10982. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10983. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10984. int message_len = RFIFOW(fd,info->pos[0])-8;
  10985. int npcid = RFIFOL(fd,info->pos[1]);
  10986. const char* message = RFIFOCP(fd,info->pos[2]);
  10987. if( message_len <= 0 )
  10988. return; // invalid input
  10989. #if PACKETVER >= 20151001
  10990. message_len++;
  10991. #endif
  10992. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10993. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  10994. sd->idletime = last_tick;
  10995. }
  10996. npc_scriptcont(sd, npcid, false);
  10997. }
  10998. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10999. /// 0146 <npc id>.L
  11000. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11001. {
  11002. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11003. return;
  11004. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11005. sd->idletime = last_tick;
  11006. }
  11007. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11008. }
  11009. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11010. /// 0178 <index>.W
  11011. /// index:
  11012. /// -1 = cancel
  11013. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11014. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11015. if (sd->menuskill_id != MC_IDENTIFY)
  11016. return;
  11017. // Ignore the request
  11018. // - Invalid item index
  11019. // - Invalid item ID or item doesn't exist
  11020. // - Item is already identified
  11021. if (idx < 0 || idx >= MAX_INVENTORY ||
  11022. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11023. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11024. sd->state.workinprogress = WIP_DISABLE_NONE;
  11025. clif_menuskill_clear(sd);
  11026. return;
  11027. }
  11028. skill_identify(sd, idx);
  11029. clif_menuskill_clear(sd);
  11030. }
  11031. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11032. /// 01ae <name id>.W
  11033. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11034. if (pc_istrading(sd)) {
  11035. //Make it fail to avoid shop exploits where you sell something different than you see.
  11036. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11037. clif_menuskill_clear(sd);
  11038. return;
  11039. }
  11040. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11041. switch (sd->menuskill_id) {
  11042. case AC_MAKINGARROW:
  11043. skill_arrow_create(sd,p->itemId);
  11044. break;
  11045. case SA_CREATECON:
  11046. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11047. break;
  11048. case GC_POISONINGWEAPON:
  11049. skill_poisoningweapon(sd,p->itemId);
  11050. break;
  11051. case NC_MAGICDECOY:
  11052. skill_magicdecoy(sd,p->itemId);
  11053. break;
  11054. }
  11055. clif_menuskill_clear(sd);
  11056. }
  11057. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11058. /// 01ce <skill id>.L
  11059. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11060. {
  11061. if (sd->menuskill_id != SA_AUTOSPELL)
  11062. return;
  11063. sd->state.workinprogress = WIP_DISABLE_NONE;
  11064. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11065. clif_menuskill_clear(sd);
  11066. }
  11067. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11068. /// 017a <card index>.W
  11069. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11070. {
  11071. if (sd->state.trading != 0)
  11072. return;
  11073. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11074. }
  11075. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11076. /// 017c <card index>.W <equip index>.W
  11077. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11078. {
  11079. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11080. if (sd->state.trading != 0)
  11081. return;
  11082. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11083. }
  11084. /// Request of character's name by char ID.
  11085. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11086. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11087. /// There are various variants of this packet, some of them have padding between fields.
  11088. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11089. {
  11090. int charid;
  11091. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11092. map_reqnickdb(sd, charid);
  11093. }
  11094. /// /resetskill /resetstate (CZ_RESET).
  11095. /// Request to reset stats or skills.
  11096. /// 0197 <type>.W
  11097. /// type:
  11098. /// 0 = state
  11099. /// 1 = skill
  11100. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11101. char cmd[15];
  11102. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11103. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11104. else
  11105. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11106. is_atcommand(fd, sd, cmd, 1);
  11107. }
  11108. /// /lb /nlb (CZ_LOCALBROADCAST).
  11109. /// Request to broadcast a message on current map.
  11110. /// 019c <packet len>.W <text>.?B
  11111. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11112. {
  11113. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11114. char command[CHAT_SIZE_MAX+16];
  11115. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11116. char* msg = RFIFOCP(fd,info->pos[1]);
  11117. // as the length varies depending on the command used, just block unreasonably long strings
  11118. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11119. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11120. is_atcommand(fd, sd, command, 1);
  11121. }
  11122. /// Request to move an item from inventory to storage.
  11123. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11124. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11125. /// There are various variants of this packet, some of them have padding between fields.
  11126. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11127. {
  11128. int item_index, item_amount;
  11129. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11130. if (pc_istrading(sd))
  11131. return;
  11132. item_index = RFIFOW(fd,info->pos[0])-2;
  11133. item_amount = RFIFOL(fd,info->pos[1]);
  11134. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11135. return;
  11136. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11137. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11138. return;
  11139. }
  11140. if (sd->state.storage_flag == 1)
  11141. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11142. else
  11143. if (sd->state.storage_flag == 2)
  11144. storage_guild_storageadd(sd, item_index, item_amount);
  11145. else if (sd->state.storage_flag == 3)
  11146. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11147. }
  11148. /// Request to move an item from storage to inventory.
  11149. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11150. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11151. /// There are various variants of this packet, some of them have padding between fields.
  11152. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11153. {
  11154. int item_index, item_amount;
  11155. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11156. item_index = RFIFOW(fd,info->pos[0])-1;
  11157. item_amount = RFIFOL(fd,info->pos[1]);
  11158. if (sd->state.storage_flag == 1)
  11159. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11160. else if(sd->state.storage_flag == 2)
  11161. storage_guild_storageget(sd, item_index, item_amount);
  11162. else if(sd->state.storage_flag == 3)
  11163. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11164. }
  11165. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11166. /// 0129 <index>.W <amount>.L
  11167. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11168. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11169. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11170. int amount = RFIFOL(fd,info->pos[1]);
  11171. if( sd->state.vending )
  11172. return;
  11173. if (!pc_iscarton(sd))
  11174. return;
  11175. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11176. return;
  11177. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11178. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11179. return;
  11180. }
  11181. if (sd->state.storage_flag == 1)
  11182. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11183. else if (sd->state.storage_flag == 2)
  11184. storage_guild_storageaddfromcart(sd, idx, amount);
  11185. else if (sd->state.storage_flag == 3)
  11186. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11187. }
  11188. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11189. /// 0128 <index>.W <amount>.L
  11190. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11191. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11192. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11193. int amount = RFIFOL(fd,info->pos[1]);
  11194. if( sd->state.vending )
  11195. return;
  11196. if (!pc_iscarton(sd))
  11197. return;
  11198. if (sd->state.storage_flag == 1)
  11199. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11200. else
  11201. if (sd->state.storage_flag == 2)
  11202. storage_guild_storagegettocart(sd, idx, amount);
  11203. else if (sd->state.storage_flag == 3)
  11204. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11205. }
  11206. /// Request to close storage (CZ_CLOSE_STORE).
  11207. /// 00f7
  11208. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11209. {
  11210. if( sd->state.storage_flag == 1 )
  11211. storage_storageclose(sd);
  11212. else
  11213. if( sd->state.storage_flag == 2 )
  11214. storage_guild_storageclose(sd);
  11215. else if( sd->state.storage_flag == 3 )
  11216. storage_premiumStorage_close(sd);
  11217. }
  11218. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11219. /// 023a <info>.W
  11220. /// info:
  11221. /// 0 = password has not been set yet
  11222. /// 1 = storage is password-protected
  11223. /// 8 = too many wrong passwords
  11224. /// ? = ignored
  11225. /// NOTE: This packet is only available on certain non-kRO clients.
  11226. void clif_storagepassword(struct map_session_data* sd, short info)
  11227. {
  11228. int fd = sd->fd;
  11229. WFIFOHEAD(fd,packet_len(0x23a));
  11230. WFIFOW(fd,0) = 0x23a;
  11231. WFIFOW(fd,2) = info;
  11232. WFIFOSET(fd,packet_len(0x23a));
  11233. }
  11234. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11235. /// 023b <type>.W <password>.16B <new password>.16B
  11236. /// type:
  11237. /// 2 = change password
  11238. /// 3 = check password
  11239. /// NOTE: This packet is only available on certain non-kRO clients.
  11240. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11241. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11242. // int type = RFIFOW(fd,info->pos[0]);
  11243. // char* password = RFIFOP(fd,info->pos[1]);
  11244. // char* new_password = RFIFOP(fd,info->pos[2]);
  11245. // storage_changepass(sd,password,new_password);
  11246. }
  11247. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11248. /// 023c <result>.W <error count>.W
  11249. /// result:
  11250. /// 4 = password change success
  11251. /// 5 = password change failure
  11252. /// 6 = password check success
  11253. /// 7 = password check failure
  11254. /// 8 = too many wrong passwords
  11255. /// ? = ignored
  11256. /// NOTE: This packet is only available on certain non-kRO clients.
  11257. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11258. {
  11259. int fd = sd->fd;
  11260. WFIFOHEAD(fd,packet_len(0x23c));
  11261. WFIFOW(fd,0) = 0x23c;
  11262. WFIFOW(fd,2) = result;
  11263. WFIFOW(fd,4) = error_count;
  11264. WFIFOSET(fd,packet_len(0x23c));
  11265. }
  11266. /// Party creation request
  11267. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11268. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11269. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11270. name[NAME_LENGTH-1] = '\0';
  11271. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11272. clif_displaymessage(fd, msg_txt(sd,227));
  11273. return;
  11274. }
  11275. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11276. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11277. return;
  11278. }
  11279. party_create(sd,name,0,0);
  11280. }
  11281. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11282. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11283. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11284. char* name = RFIFOCP(fd,info->pos[0]);
  11285. int item1 = RFIFOB(fd,info->pos[1]);
  11286. int item2 = RFIFOB(fd,info->pos[2]);
  11287. name[NAME_LENGTH-1] = '\0';
  11288. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11289. clif_displaymessage(fd, msg_txt(sd,227));
  11290. return;
  11291. }
  11292. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11293. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11294. return;
  11295. }
  11296. party_create(sd,name,item1,item2);
  11297. }
  11298. /// Party invitation request
  11299. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11300. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11301. {
  11302. struct map_session_data *t_sd;
  11303. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11304. clif_displaymessage(fd, msg_txt(sd,227));
  11305. return;
  11306. }
  11307. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11308. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11309. clif_noask_sub(sd, t_sd, 1);
  11310. return;
  11311. }
  11312. party_invite(sd, t_sd);
  11313. }
  11314. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11315. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11316. struct map_session_data *t_sd;
  11317. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11318. name[NAME_LENGTH-1] = '\0';
  11319. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11320. clif_displaymessage(fd, msg_txt(sd,227));
  11321. return;
  11322. }
  11323. t_sd = map_nick2sd(name,false);
  11324. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11325. clif_noask_sub(sd, t_sd, 1);
  11326. return;
  11327. }
  11328. party_invite(sd, t_sd);
  11329. }
  11330. /// Party invitation reply
  11331. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11332. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11333. /// flag:
  11334. /// 0 = reject
  11335. /// 1 = accept
  11336. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11337. {
  11338. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11339. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11340. RFIFOL(fd,info->pos[1]));
  11341. }
  11342. //(CZ_PARTY_JOIN_REQ_ACK)
  11343. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11344. {
  11345. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11346. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11347. RFIFOB(fd,info->pos[1]));
  11348. }
  11349. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11350. /// 0100
  11351. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11352. {
  11353. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11354. clif_displaymessage(fd, msg_txt(sd,227));
  11355. return;
  11356. }
  11357. party_leave(sd);
  11358. }
  11359. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11360. /// 0103 <account id>.L <char name>.24B
  11361. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11362. {
  11363. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11364. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11365. clif_displaymessage(fd, msg_txt(sd,227));
  11366. return;
  11367. }
  11368. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11369. RFIFOCP(fd,info->pos[1]));
  11370. }
  11371. /// Request to change party options.
  11372. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11373. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11374. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11375. {
  11376. struct party_data *p;
  11377. int i,expflag;
  11378. int cmd = RFIFOW(fd,0);
  11379. struct s_packet_db* info = &packet_db[cmd];
  11380. if( !sd->status.party_id )
  11381. return;
  11382. p = party_search(sd->status.party_id);
  11383. if( p == NULL )
  11384. return;
  11385. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11386. if( i == MAX_PARTY )
  11387. return; //Shouldn't happen
  11388. if( !p->party.member[i].leader )
  11389. return;
  11390. expflag = RFIFOL(fd,info->pos[0]);
  11391. if(cmd == 0x0102){ //Client can't change the item-field
  11392. party_changeoption(sd, expflag, p->party.item);
  11393. }
  11394. else {
  11395. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11396. party_changeoption(sd, expflag, itemflag);
  11397. }
  11398. }
  11399. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11400. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11401. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11402. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11403. // validate packet and retrieve name and message
  11404. if( !clif_process_message( sd, false, name, message, output ) )
  11405. return;
  11406. party_send_message(sd, output, strlen(output) + 1 );
  11407. }
  11408. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11409. /// 07da <account id>.L
  11410. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11411. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11412. }
  11413. /// Party Booking in KRO [Spiria]
  11414. ///
  11415. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11416. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11417. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11418. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11419. short level = RFIFOW(fd,info->pos[0]);
  11420. short mapid = RFIFOW(fd,info->pos[1]);
  11421. int idxpbj = info->pos[2];
  11422. short job[MAX_PARTY_BOOKING_JOBS];
  11423. int i;
  11424. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11425. job[i] = RFIFOB(fd,idxpbj+i*2);
  11426. party_booking_register(sd, level, mapid, job);
  11427. }
  11428. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11429. /// 0803 <result>.W
  11430. /// result:
  11431. /// 0 = success
  11432. /// 1 = failure
  11433. /// 2 = already registered
  11434. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11435. {
  11436. int fd = sd->fd;
  11437. WFIFOHEAD(fd,packet_len(0x803));
  11438. WFIFOW(fd,0) = 0x803;
  11439. WFIFOW(fd,2) = flag;
  11440. WFIFOSET(fd,packet_len(0x803));
  11441. }
  11442. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11443. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11444. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11445. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11446. short level = RFIFOW(fd,info->pos[0]);
  11447. short mapid = RFIFOW(fd,info->pos[1]);
  11448. short job = RFIFOW(fd,info->pos[2]);
  11449. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11450. short resultcount = RFIFOW(fd,info->pos[4]);
  11451. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11452. }
  11453. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11454. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11455. /// more results:
  11456. /// 0 = no
  11457. /// 1 = yes
  11458. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11459. {
  11460. int i, j;
  11461. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11462. struct party_booking_ad_info *pb_ad;
  11463. WFIFOHEAD(fd,size*count + 5);
  11464. WFIFOW(fd,0) = 0x805;
  11465. WFIFOW(fd,2) = size*count + 5;
  11466. WFIFOB(fd,4) = more_result;
  11467. for(i=0; i<count; i++)
  11468. {
  11469. pb_ad = results[i];
  11470. WFIFOL(fd,i*size+5) = pb_ad->index;
  11471. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11472. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11473. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11474. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11475. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11476. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11477. }
  11478. WFIFOSET(fd,WFIFOW(fd,2));
  11479. }
  11480. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11481. /// 0806
  11482. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11483. {
  11484. if(party_booking_delete(sd))
  11485. clif_PartyBookingDeleteAck(sd, 0);
  11486. }
  11487. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11488. /// 0807 <result>.W
  11489. /// result:
  11490. /// 0 = success
  11491. /// 1 = success (auto-removed expired ad)
  11492. /// 2 = failure
  11493. /// 3 = nothing registered
  11494. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11495. {
  11496. int fd = sd->fd;
  11497. WFIFOHEAD(fd,packet_len(0x807));
  11498. WFIFOW(fd,0) = 0x807;
  11499. WFIFOW(fd,2) = flag;
  11500. WFIFOSET(fd,packet_len(0x807));
  11501. }
  11502. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11503. /// 0808 { <job>.W }*6
  11504. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11505. {
  11506. short job[MAX_PARTY_BOOKING_JOBS];
  11507. int i;
  11508. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11509. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11510. job[i] = RFIFOW(fd,idxpbu+i*2);
  11511. party_booking_update(sd, job);
  11512. }
  11513. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11514. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11515. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11516. {
  11517. int i;
  11518. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11519. if(pb_ad == NULL) return;
  11520. WBUFW(buf,0) = 0x809;
  11521. WBUFL(buf,2) = pb_ad->index;
  11522. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11523. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11524. WBUFW(buf,34) = pb_ad->p_detail.level;
  11525. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11526. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11527. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11528. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11529. }
  11530. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11531. /// 080a <index>.L { <job>.W }*6
  11532. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11533. {
  11534. int i;
  11535. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11536. if(pb_ad == NULL) return;
  11537. WBUFW(buf,0) = 0x80a;
  11538. WBUFL(buf,2) = pb_ad->index;
  11539. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11540. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11541. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11542. }
  11543. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11544. /// 080b <index>.L
  11545. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11546. {
  11547. uint8 buf[6];
  11548. WBUFW(buf,0) = 0x80b;
  11549. WBUFL(buf,2) = index;
  11550. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11551. }
  11552. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11553. /// 012e
  11554. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11555. {
  11556. vending_closevending(sd);
  11557. }
  11558. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11559. /// 0130 <account id>.L
  11560. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11561. {
  11562. if( sd->npc_id ) {// using an NPC
  11563. return;
  11564. }
  11565. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11566. }
  11567. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11568. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11569. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11570. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11571. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11572. int id = (int)RFIFOL(fd,info->pos[1]);
  11573. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11574. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11575. // whether it fails or not, the buy window is closed
  11576. sd->vended_id = 0;
  11577. }
  11578. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11579. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11580. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11581. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11582. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11583. int aid = (int)RFIFOL(fd,info->pos[1]);
  11584. int uid = (int)RFIFOL(fd,info->pos[2]);
  11585. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11586. vending_purchasereq(sd, aid, uid, data, len/4);
  11587. // whether it fails or not, the buy window is closed
  11588. sd->vended_id = 0;
  11589. }
  11590. /// Confirm or cancel the shop preparation window.
  11591. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11592. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11593. /// result:
  11594. /// 0 = canceled
  11595. /// 1 = open
  11596. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11597. int cmd = RFIFOW(fd,0);
  11598. struct s_packet_db* info = &packet_db[cmd];
  11599. short len = (short)RFIFOW(fd,info->pos[0]);
  11600. const char* message = RFIFOCP(fd,info->pos[1]);
  11601. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11602. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11603. len -= 84;
  11604. }
  11605. else { //(CZ_REQ_OPENSTORE2)
  11606. bool flag;
  11607. len -= 85;
  11608. flag = RFIFOB(fd,info->pos[2]) != 0;
  11609. if (!flag) {
  11610. sd->state.prevend = 0;
  11611. sd->state.workinprogress = WIP_DISABLE_NONE;
  11612. }
  11613. }
  11614. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11615. return;
  11616. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11617. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11618. return;
  11619. }
  11620. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11621. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11622. return;
  11623. }
  11624. if( message[0] == '\0' ) // invalid input
  11625. return;
  11626. vending_openvending(sd, message, data, len/8, NULL);
  11627. }
  11628. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11629. /// 0165 <char id>.L <guild name>.24B
  11630. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11631. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11632. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11633. name[NAME_LENGTH-1] = '\0';
  11634. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11635. clif_displaymessage(fd, msg_txt(sd,228));
  11636. return;
  11637. }
  11638. if(sd->clan){
  11639. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11640. return;
  11641. }
  11642. guild_create(sd, name);
  11643. }
  11644. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11645. /// 014d
  11646. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11647. {
  11648. clif_guild_masterormember(sd);
  11649. }
  11650. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11651. /// 014f <type>.L
  11652. /// type:
  11653. /// 0 = basic info
  11654. /// 1 = member manager
  11655. /// 2 = positions
  11656. /// 3 = skills
  11657. /// 4 = expulsion list
  11658. /// 5 = unknown (GM_ALLGUILDLIST)
  11659. /// 6 = notice
  11660. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11661. {
  11662. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11663. if( !sd->status.guild_id && !sd->bg_id )
  11664. return;
  11665. switch( type )
  11666. {
  11667. case 0: // Basic Information Guild, hostile alliance information
  11668. clif_guild_basicinfo(sd);
  11669. clif_guild_allianceinfo(sd);
  11670. break;
  11671. case 1: // Members list, list job title
  11672. clif_guild_positionnamelist(sd);
  11673. clif_guild_memberlist(sd);
  11674. break;
  11675. case 2: // List job title, title information list
  11676. clif_guild_positionnamelist(sd);
  11677. clif_guild_positioninfolist(sd);
  11678. break;
  11679. case 3: // Skill list
  11680. clif_guild_skillinfo(sd);
  11681. break;
  11682. case 4: // Expulsion list
  11683. clif_guild_expulsionlist(sd);
  11684. break;
  11685. default:
  11686. ShowError("clif: guild request info: unknown type %d\n", type);
  11687. break;
  11688. }
  11689. }
  11690. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11691. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11692. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11693. {
  11694. int i;
  11695. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11696. int len = RFIFOW(fd,info->pos[0]);
  11697. int idxgpos = info->pos[1];
  11698. if(!sd->state.gmaster_flag)
  11699. return;
  11700. for(i = idxgpos; i < len; i += 40 ){
  11701. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11702. }
  11703. }
  11704. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11705. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11706. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11707. {
  11708. int i;
  11709. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11710. int len = RFIFOW(fd,info->pos[0]);
  11711. int idxgpos = info->pos[1];
  11712. if(!sd->state.gmaster_flag)
  11713. return;
  11714. // Guild leadership change
  11715. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11716. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11717. clif_msg(sd, GUILD_MASTER_WOE);
  11718. return;
  11719. }
  11720. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11721. clif_msg(sd, GUILD_MASTER_DELAY);
  11722. return;
  11723. }
  11724. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11725. return;
  11726. }
  11727. for(i=idxgpos;i<len;i+=12){
  11728. int position = RFIFOL(fd,i+8);
  11729. if( position > 0 ){
  11730. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11731. }
  11732. }
  11733. }
  11734. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11735. /// 0151 <guild id>.L
  11736. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11737. {
  11738. struct guild* g;
  11739. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11740. if( (g = guild_search(guild_id)) != NULL )
  11741. clif_guild_emblem(sd,g);
  11742. }
  11743. /// Validates data of a guild emblem (compressed bitmap)
  11744. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11745. EMBVALIDATE_SUCCESS = 0,
  11746. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11747. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11748. };
  11749. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11750. {
  11751. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11752. unsigned long buf_len = sizeof(buf);
  11753. int offset = 0;
  11754. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11755. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11756. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11757. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11758. ))
  11759. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11760. if(battle_config.emblem_transparency_limit != 100) {
  11761. int i, transcount = 1, tmp[3];
  11762. for(i = offset; i < buf_len-1; i++) {
  11763. int j = i%3;
  11764. tmp[j] = RBUFL(buf,i);
  11765. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11766. transcount++;
  11767. }
  11768. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11769. return EMBVALIDATE_ERR_TRANSPARENCY;
  11770. }
  11771. return EMBVALIDATE_SUCCESS;
  11772. }
  11773. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11774. /// 0153 <packet len>.W <emblem data>.?B
  11775. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11776. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11777. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11778. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11779. int emb_val=0;
  11780. if( !emblem_len || !sd->state.gmaster_flag )
  11781. return;
  11782. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11783. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11784. return;
  11785. }
  11786. emb_val = clif_validate_emblem(emblem, emblem_len);
  11787. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11788. 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);
  11789. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11790. return;
  11791. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11792. char output[128];
  11793. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11794. 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"
  11795. return;
  11796. }
  11797. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11798. }
  11799. /// Request to update the guild emblem id (version, according to Gravity)
  11800. /// 0b46 <guild id>.L <version>.L
  11801. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  11802. nullpo_retv(sd);
  11803. #if PACKETVER >= 20190724
  11804. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11805. guild* g = sd->guild;
  11806. if (g == nullptr || g->guild_id != p->guild_id)
  11807. return;
  11808. if (!sd->state.gmaster_flag)
  11809. return;
  11810. if (!battle_config.emblem_woe_change && is_agit_start()) {
  11811. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11812. return;
  11813. }
  11814. guild_change_emblem_version(sd, p->version);
  11815. #endif
  11816. }
  11817. /// Guild notice update request (CZ_GUILD_NOTICE).
  11818. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11819. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11820. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11821. int guild_id = RFIFOL(fd,info->pos[0]);
  11822. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11823. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11824. if(!sd->state.gmaster_flag)
  11825. return;
  11826. // compensate for some client defects when using multilanguage mode
  11827. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11828. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11829. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11830. guild_change_notice(sd, guild_id, msg1, msg2);
  11831. }
  11832. // Helper function for guild invite functions
  11833. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11834. {
  11835. if (t_sd == NULL) // not online or does not exist
  11836. return 1;
  11837. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11838. clif_displaymessage(fd, msg_txt(sd,228));
  11839. return 1;
  11840. }
  11841. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11842. clif_noask_sub(sd, t_sd, 2);
  11843. return 1;
  11844. }
  11845. // Players in a clan can not join a guild
  11846. if(t_sd && t_sd->clan){
  11847. return 1;
  11848. }
  11849. guild_invite(sd, t_sd);
  11850. return 0;
  11851. }
  11852. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11853. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11854. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11855. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11856. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11857. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11858. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11859. if (clif_sub_guild_invite(fd, sd, t_sd))
  11860. return;
  11861. }
  11862. /// Guild invite request (/guildinvite)
  11863. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11864. void
  11865. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11866. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11867. if (clif_sub_guild_invite(fd, sd, t_sd))
  11868. return;
  11869. }
  11870. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11871. /// 016b <guild id>.L <answer>.L
  11872. /// answer:
  11873. /// 0 = refuse
  11874. /// 1 = accept
  11875. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11876. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11877. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11878. RFIFOL(fd,info->pos[1]));
  11879. }
  11880. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11881. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11882. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11883. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11884. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11885. clif_displaymessage(fd, msg_txt(sd,228));
  11886. return;
  11887. }
  11888. if( sd->bg_id ) {
  11889. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11890. return;
  11891. }
  11892. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11893. RFIFOL(fd,info->pos[1]),
  11894. RFIFOL(fd,info->pos[2]),
  11895. RFIFOCP(fd,info->pos[3]));
  11896. }
  11897. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11898. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11899. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11900. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11901. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11902. { // Guild locked.
  11903. clif_displaymessage(fd, msg_txt(sd,228));
  11904. return;
  11905. }
  11906. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11907. RFIFOL(fd,info->pos[1]),
  11908. RFIFOL(fd,info->pos[2]),
  11909. RFIFOCP(fd,info->pos[3]));
  11910. }
  11911. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11912. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11913. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11914. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11915. // validate packet and retrieve name and message
  11916. if( !clif_process_message( sd, false, name, message, output ) )
  11917. return;
  11918. if( sd->bg_id )
  11919. bg_send_message(sd, output, strlen(output) );
  11920. else
  11921. guild_send_message(sd, output, strlen(output) );
  11922. }
  11923. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11924. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11925. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11926. {
  11927. struct map_session_data *t_sd;
  11928. if(!sd->state.gmaster_flag)
  11929. return;
  11930. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11931. clif_displaymessage(fd, msg_txt(sd,228));
  11932. return;
  11933. }
  11934. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11935. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11936. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11937. // @noask [LuzZza]
  11938. if(t_sd && t_sd->state.noask) {
  11939. clif_noask_sub(sd, t_sd, 3);
  11940. return;
  11941. }
  11942. guild_reqalliance(sd,t_sd);
  11943. }
  11944. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11945. /// 0172 <inviter account id>.L <answer>.L
  11946. /// answer:
  11947. /// 0 = refuse
  11948. /// 1 = accept
  11949. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11950. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11951. guild_reply_reqalliance(sd,
  11952. RFIFOL(fd,info->pos[0]),
  11953. RFIFOL(fd,info->pos[1]));
  11954. }
  11955. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11956. /// 0183 <opponent guild id>.L <relation>.L
  11957. /// relation:
  11958. /// 0 = Ally
  11959. /// 1 = Enemy
  11960. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11961. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11962. if(!sd->state.gmaster_flag)
  11963. return;
  11964. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11965. clif_displaymessage(fd, msg_txt(sd,228));
  11966. return;
  11967. }
  11968. guild_delalliance(sd,
  11969. RFIFOL(fd,info->pos[0]),
  11970. RFIFOL(fd,info->pos[1]));
  11971. }
  11972. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11973. /// 0180 <account id>.L
  11974. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11975. {
  11976. struct map_session_data *t_sd;
  11977. if(!sd->state.gmaster_flag)
  11978. return;
  11979. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11980. clif_displaymessage(fd, msg_txt(sd,228));
  11981. return;
  11982. }
  11983. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11984. // @noask [LuzZza]
  11985. if(t_sd && t_sd->state.noask) {
  11986. clif_noask_sub(sd, t_sd, 4);
  11987. return;
  11988. }
  11989. guild_opposition(sd,t_sd);
  11990. }
  11991. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11992. /// 015d <key>.40B
  11993. /// key:
  11994. /// now guild name; might have been (intended) email, since the
  11995. /// field name and size is same as the one in CH_DELETE_CHAR.
  11996. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11997. {
  11998. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11999. clif_displaymessage(fd, msg_txt(sd,228));
  12000. return;
  12001. }
  12002. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12003. }
  12004. /// Pet
  12005. ///
  12006. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12007. /// 01a1 <type>.B
  12008. /// type:
  12009. /// 0 = pet information
  12010. /// 1 = feed
  12011. /// 2 = performance
  12012. /// 3 = return to egg
  12013. /// 4 = unequip accessory
  12014. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12015. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12016. }
  12017. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12018. /// 019f <id>.L
  12019. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12020. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12021. }
  12022. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12023. /// 01a7 <index>.W
  12024. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12025. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12026. return;
  12027. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12028. clif_menuskill_clear(sd);
  12029. }
  12030. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12031. /// 01a9 <data>.L
  12032. /// data:
  12033. /// is either emotion (@see enum emotion_type) or a compound value
  12034. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12035. /// entry (given in parentheses) in data\pettalktable.xml
  12036. /// act id:
  12037. /// 0 = feeding
  12038. /// 1 = hunting
  12039. /// 2 = danger
  12040. /// 3 = dead
  12041. /// 4 = normal (stand)
  12042. /// 5 = special performance (perfor_s)
  12043. /// 6 = level up (levelup)
  12044. /// 7 = performance 1 (perfor_1)
  12045. /// 8 = performance 2 (perfor_2)
  12046. /// 9 = performance 3 (perfor_3)
  12047. /// 10 = log-in greeting (connect)
  12048. /// hungry value:
  12049. /// 0 = very hungry (hungry)
  12050. /// 1 = hungry (bit_hungry)
  12051. /// 2 = satisfied (noting)
  12052. /// 3 = stuffed (full)
  12053. /// 4 = full (so_full)
  12054. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12055. {
  12056. if(sd->pd)
  12057. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12058. }
  12059. /// Request to change pet's name (CZ_RENAME_PET).
  12060. /// 01a5 <name>.24B
  12061. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12062. {
  12063. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12064. }
  12065. /// /kill (CZ_DISCONNECT_CHARACTER).
  12066. /// Request to disconnect a character.
  12067. /// 00cc <account id>.L
  12068. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12069. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12070. {
  12071. struct block_list *target;
  12072. int tid;
  12073. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12074. target = map_id2bl(tid);
  12075. if (!target) {
  12076. clif_GM_kickack(sd, 0);
  12077. return;
  12078. }
  12079. switch (target->type) {
  12080. case BL_PC:
  12081. {
  12082. char command[NAME_LENGTH+6];
  12083. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12084. is_atcommand(fd, sd, command, 1);
  12085. }
  12086. break;
  12087. /**
  12088. * This one does not invoke any atcommand, so we need to check for permissions.
  12089. */
  12090. case BL_MOB:
  12091. {
  12092. char command[100];
  12093. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12094. clif_GM_kickack(sd, 0);
  12095. return;
  12096. }
  12097. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12098. log_atcommand(sd, command);
  12099. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12100. }
  12101. break;
  12102. case BL_NPC:
  12103. {
  12104. struct npc_data* nd = (struct npc_data *)target;
  12105. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12106. npc_unload_duplicates(nd);
  12107. npc_unload(nd,true);
  12108. npc_read_event_script();
  12109. }
  12110. }
  12111. break;
  12112. default:
  12113. clif_GM_kickack(sd, 0);
  12114. }
  12115. }
  12116. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12117. /// Request to disconnect all characters.
  12118. /// 00ce
  12119. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12120. char cmd[15];
  12121. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12122. is_atcommand(fd, sd, cmd, 1);
  12123. }
  12124. /// /remove (CZ_REMOVE_AID).
  12125. /// Request to warp to a character with given login ID.
  12126. /// 01ba <account name>.24B
  12127. /// /shift (CZ_SHIFT).
  12128. /// Request to warp to a character with given name.
  12129. /// 01bb <char name>.24B
  12130. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12131. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12132. char *player_name;
  12133. char command[NAME_LENGTH+8];
  12134. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12135. player_name[NAME_LENGTH-1] = '\0';
  12136. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12137. is_atcommand(fd, sd, command, 1);
  12138. }
  12139. /// /remove (CZ_REMOVE_AID_SSO).
  12140. /// Request to warp to a character with given account ID.
  12141. /// 0843 <account id>.L
  12142. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12143. {
  12144. uint32 account_id;
  12145. struct map_session_data* pl_sd;
  12146. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12147. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12148. char command[NAME_LENGTH+8];
  12149. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12150. is_atcommand(fd, sd, command, 1);
  12151. }
  12152. }
  12153. /// /recall (CZ_RECALL).
  12154. /// Request to summon a player with given login ID to own position.
  12155. /// 01bc <account name>.24B
  12156. /// /summon (CZ_RECALL_GID).
  12157. /// Request to summon a player with given name to own position.
  12158. /// 01bd <char name>.24B
  12159. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12160. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12161. char *player_name;
  12162. char command [NAME_LENGTH+8];
  12163. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12164. player_name[NAME_LENGTH-1] = '\0';
  12165. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12166. is_atcommand(fd, sd, command, 1);
  12167. }
  12168. /// /recall (CZ_RECALL_SSO).
  12169. /// Request to summon a player with given account ID to own position.
  12170. /// 0842 <account id>.L
  12171. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12172. {
  12173. uint32 account_id;
  12174. struct map_session_data* pl_sd;
  12175. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12176. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12177. char command[NAME_LENGTH+8];
  12178. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12179. is_atcommand(fd, sd, command, 1);
  12180. }
  12181. }
  12182. /// /item /monster (CZ_ITEM_CREATE).
  12183. /// Request to execute GM commands.
  12184. /// Usage:
  12185. /// /item n - summon n monster or acquire n item/s
  12186. /// /item money - grants 2147483647 zenies
  12187. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12188. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12189. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12190. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12191. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12192. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12193. /// 013f <item/mob name>.24B
  12194. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12195. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12196. {
  12197. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12198. int mob_id = 0;
  12199. StringBuf command;
  12200. char *str;
  12201. //#if PACKETVER >= 20131218
  12202. // char str[100];
  12203. //#else
  12204. // char str[24];
  12205. //#endif
  12206. str = RFIFOCP(fd,info->pos[0]);
  12207. if (!str || str[0] == '\0')
  12208. return;
  12209. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12210. return;
  12211. trim(str);
  12212. // Zeny
  12213. if( strcmpi(str, "money") == 0 ) {
  12214. StringBuf_Init(&command);
  12215. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12216. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12217. StringBuf_Destroy(&command);
  12218. return;
  12219. }
  12220. std::shared_ptr<item_data> id = item_db.searchname( str );
  12221. // Item
  12222. if( id ){
  12223. StringBuf_Init(&command);
  12224. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12225. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12226. }else{
  12227. if (id->flag.guid)
  12228. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12229. else
  12230. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12231. }
  12232. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12233. StringBuf_Destroy(&command);
  12234. return;
  12235. }
  12236. // Monster
  12237. if ((mob_id = mobdb_searchname(str)) == 0)
  12238. mob_id = mobdb_checkid(atoi(str));
  12239. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12240. if( mob != nullptr ) {
  12241. StringBuf_Init(&command);
  12242. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12243. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12244. StringBuf_Destroy(&command);
  12245. return;
  12246. }
  12247. }
  12248. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12249. /// 019d <effect state>.L
  12250. /// effect state:
  12251. /// TODO: Any OPTION_* ?
  12252. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12253. char cmd[6];
  12254. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12255. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12256. is_atcommand(fd, sd, cmd, 1);
  12257. }
  12258. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12259. /// 0149 <account id>.L <type>.B <value>.W
  12260. /// type:
  12261. /// 0 = positive points
  12262. /// 1 = negative points
  12263. /// 2 = self mute (+10 minutes)
  12264. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12265. {
  12266. int id, type, value;
  12267. struct map_session_data *dstsd;
  12268. char command[NAME_LENGTH+15];
  12269. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12270. id = RFIFOL(fd,info->pos[0]);
  12271. type = RFIFOB(fd,info->pos[1]);
  12272. value = RFIFOW(fd,info->pos[2]);
  12273. if( type == 0 )
  12274. value = -value;
  12275. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12276. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12277. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12278. return;
  12279. dstsd = map_id2sd(id);
  12280. if( dstsd == NULL )
  12281. return;
  12282. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12283. is_atcommand(fd, sd, command, 1);
  12284. }
  12285. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12286. /// GM adjustment of a player's manner value by -60.
  12287. /// 0212 <char name>.24B
  12288. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12289. {
  12290. char command[NAME_LENGTH+15];
  12291. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12292. name[NAME_LENGTH-1] = '\0';
  12293. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12294. is_atcommand(fd, sd, command, 1);
  12295. }
  12296. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12297. /// 01e0 <account id>.L <account name>.24B
  12298. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12299. {
  12300. WFIFOHEAD(fd,packet_len(0x1e0));
  12301. WFIFOW(fd,0) = 0x1e0;
  12302. WFIFOL(fd,2) = account_id;
  12303. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12304. WFIFOSET(fd,packet_len(0x1e0));
  12305. }
  12306. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12307. /// 01df <account id>.L
  12308. //! TODO: Figure out how does this actually work
  12309. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12310. {
  12311. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12312. /*
  12313. char query[30];
  12314. safesnprintf(query,sizeof(query),"%d", account_id);
  12315. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12316. */
  12317. clif_account_name(fd, account_id, "");
  12318. }
  12319. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12320. /// GM single cell type change request.
  12321. /// 0198 <x>.W <y>.W <type>.W
  12322. /// type:
  12323. /// 0 = not walkable
  12324. /// 1 = walkable
  12325. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12326. {
  12327. int x,y,type;
  12328. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12329. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12330. return;
  12331. x = RFIFOW(fd,info->pos[0]);
  12332. y = RFIFOW(fd,info->pos[1]);
  12333. type = RFIFOW(fd,info->pos[2]);
  12334. map_setgatcell(sd->bl.m,x,y,type);
  12335. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12336. //FIXME: once players leave the map, the client 'forgets' this information.
  12337. }
  12338. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12339. /// Request to allow/deny whispers from a nick.
  12340. /// 00cf <nick>.24B <type>.B
  12341. /// type:
  12342. /// 0 = (/ex nick) deny speech from nick
  12343. /// 1 = (/in nick) allow speech from nick
  12344. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12345. {
  12346. char* nick;
  12347. uint8 type;
  12348. int i;
  12349. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12350. nick = RFIFOCP(fd,info->pos[0]);
  12351. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12352. type = RFIFOB(fd,info->pos[1]);
  12353. if( type == 0 ) { // Add name to ignore list (block)
  12354. if (strcmp(wisp_server_name, nick) == 0) {
  12355. clif_wisexin(sd, type, 1); // fail
  12356. return;
  12357. }
  12358. // try to find a free spot, while checking for duplicates at the same time
  12359. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12360. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12361. clif_wisexin(sd, type, 2); // too many blocks
  12362. return;
  12363. }
  12364. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12365. clif_wisexin(sd, type, 0); // Aegis reports success.
  12366. return;
  12367. }
  12368. //Insert in position i
  12369. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12370. } else { // Remove name from ignore list (unblock)
  12371. // find entry
  12372. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12373. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12374. clif_wisexin(sd, type, 1); // fail
  12375. return;
  12376. }
  12377. // move everything one place down to overwrite removed entry
  12378. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12379. // wipe last entry
  12380. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12381. }
  12382. clif_wisexin(sd, type, 0); // success
  12383. }
  12384. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12385. /// Request to allow/deny all whispers.
  12386. /// 00d0 <type>.B
  12387. /// type:
  12388. /// 0 = (/exall) deny all speech
  12389. /// 1 = (/inall) allow all speech
  12390. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12391. {
  12392. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12393. if( type == 0 ) {// Deny all
  12394. if( sd->state.ignoreAll ) {
  12395. flag = 1; // fail
  12396. } else {
  12397. sd->state.ignoreAll = 1;
  12398. flag = 0; // success
  12399. }
  12400. } else {//Unblock everyone
  12401. if( sd->state.ignoreAll ) {
  12402. sd->state.ignoreAll = 0;
  12403. flag = 0; // success
  12404. } else {
  12405. if (sd->ignore[0].name[0] != '\0')
  12406. { //Wipe the ignore list.
  12407. memset(sd->ignore, 0, sizeof(sd->ignore));
  12408. flag = 0; // success
  12409. } else {
  12410. flag = 1; // fail
  12411. }
  12412. }
  12413. }
  12414. clif_wisall(sd, type, flag);
  12415. }
  12416. /// Whisper ignore list (ZC_WHISPER_LIST).
  12417. /// 00d4 <packet len>.W { <char name>.24B }*
  12418. void clif_PMIgnoreList(struct map_session_data* sd)
  12419. {
  12420. int i, fd = sd->fd;
  12421. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12422. WFIFOW(fd,0) = 0xd4;
  12423. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12424. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12425. }
  12426. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12427. WFIFOSET(fd,WFIFOW(fd,2));
  12428. }
  12429. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12430. /// 00d3
  12431. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12432. {
  12433. clif_PMIgnoreList(sd);
  12434. }
  12435. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12436. /// 01e7
  12437. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12438. {
  12439. if (sd->state.doridori) return;
  12440. switch (sd->class_&MAPID_UPPERMASK) {
  12441. case MAPID_SOUL_LINKER:
  12442. case MAPID_STAR_GLADIATOR:
  12443. case MAPID_TAEKWON:
  12444. if (!sd->state.rest)
  12445. break;
  12446. case MAPID_SUPER_NOVICE:
  12447. case MAPID_SUPER_BABY:
  12448. case MAPID_SUPER_NOVICE_E:
  12449. case MAPID_SUPER_BABY_E:
  12450. sd->state.doridori=1;
  12451. break;
  12452. }
  12453. }
  12454. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12455. /// 01ed
  12456. /// Note: This packet is caused by 7 lines of any text, followed by
  12457. /// the prayer and an another line of any text. The prayer is
  12458. /// defined by lines 790~793 in data\msgstringtable.txt
  12459. /// "Dear angel, can you hear my voice?"
  12460. /// "I am" (space separated player name) "Super Novice~"
  12461. /// "Help me out~ Please~ T_T"
  12462. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12463. {
  12464. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12465. t_exp next = pc_nextbaseexp(sd);
  12466. if( next ) {
  12467. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12468. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12469. sc_start(&sd->bl,&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12470. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12471. }
  12472. }
  12473. }
  12474. }
  12475. /// Friends List
  12476. ///
  12477. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12478. /// 0206 <account id>.L <char id>.L <state>.B
  12479. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12480. /// state:
  12481. /// 0 = online
  12482. /// 1 = offline
  12483. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12484. {
  12485. int i, fd = sd->fd;
  12486. //Seek friend.
  12487. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12488. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12489. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12490. return; //Not found
  12491. WFIFOHEAD(fd,packet_len(0x206));
  12492. WFIFOW(fd, 0) = 0x206;
  12493. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12494. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12495. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12496. #if PACKETVER >= 20180221
  12497. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12498. #endif
  12499. WFIFOSET(fd, packet_len(0x206));
  12500. }
  12501. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12502. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12503. {
  12504. uint32 account_id, char_id, online;
  12505. account_id = va_arg(ap, int);
  12506. char_id = va_arg(ap, int);
  12507. online = va_arg(ap, int);
  12508. clif_friendslist_toggle(sd, account_id, char_id, online);
  12509. return 0;
  12510. }
  12511. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12512. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12513. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12514. void clif_friendslist_send(struct map_session_data *sd)
  12515. {
  12516. int i = 0, n, fd = sd->fd;
  12517. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12518. const int size = 8 + NAME_LENGTH;
  12519. #else
  12520. const int size = 8;
  12521. #endif
  12522. // Send friends list
  12523. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12524. WFIFOW(fd, 0) = 0x201;
  12525. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12526. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12527. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12528. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12529. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12530. #endif
  12531. }
  12532. if (i) {
  12533. WFIFOW(fd,2) = 4 + size * i;
  12534. WFIFOSET(fd, WFIFOW(fd,2));
  12535. }
  12536. for (n = 0; n < i; n++) { //Sending the online players
  12537. if (map_charid2sd(sd->status.friends[n].char_id))
  12538. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12539. }
  12540. }
  12541. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12542. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12543. /// result:
  12544. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12545. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12546. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12547. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12548. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12549. {
  12550. int fd;
  12551. nullpo_retv(sd);
  12552. fd = sd->fd;
  12553. WFIFOHEAD(fd,packet_len(0x209));
  12554. WFIFOW(fd,0) = 0x209;
  12555. WFIFOW(fd,2) = type;
  12556. if (f_sd) {
  12557. WFIFOL(fd,4) = f_sd->status.account_id;
  12558. WFIFOL(fd,8) = f_sd->status.char_id;
  12559. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12560. }
  12561. WFIFOSET(fd, packet_len(0x209));
  12562. }
  12563. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12564. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12565. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12566. {
  12567. int fd = sd->fd;
  12568. WFIFOHEAD(fd,packet_len(0x207));
  12569. WFIFOW(fd,0) = 0x207;
  12570. WFIFOL(fd,2) = account_id;
  12571. WFIFOL(fd,6) = char_id;
  12572. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12573. WFIFOSET(fd,packet_len(0x207));
  12574. }
  12575. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12576. /// 0202 <name>.24B
  12577. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12578. {
  12579. struct map_session_data *f_sd;
  12580. int i;
  12581. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12582. // Friend doesn't exist (no player with this name)
  12583. if (f_sd == NULL) {
  12584. clif_displaymessage(fd, msg_txt(sd,3));
  12585. return;
  12586. }
  12587. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12588. return;
  12589. }
  12590. // ensure that the request player's friend list is not full
  12591. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12592. if( i == MAX_FRIENDS ){
  12593. clif_friendslist_reqack(sd, f_sd, 2);
  12594. return;
  12595. }
  12596. // @noask [LuzZza]
  12597. if(f_sd->state.noask) {
  12598. clif_noask_sub(sd, f_sd, 5);
  12599. return;
  12600. }
  12601. // Friend already exists
  12602. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12603. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12604. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12605. return;
  12606. }
  12607. }
  12608. f_sd->friend_req = sd->status.char_id;
  12609. sd->friend_req = f_sd->status.char_id;
  12610. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12611. }
  12612. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12613. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12614. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12615. /// reply:
  12616. /// 0 = rejected
  12617. /// 1 = accepted
  12618. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12619. {
  12620. struct map_session_data *f_sd;
  12621. uint32 account_id;
  12622. char reply;
  12623. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12624. account_id = RFIFOL(fd,info->pos[0]);
  12625. //char_id = RFIFOL(fd,info->pos[1]);
  12626. #if PACKETVER < 6
  12627. reply = RFIFOB(fd,info->pos[2]);
  12628. #else
  12629. reply = RFIFOL(fd,info->pos[2]);
  12630. #endif
  12631. if( sd->bl.id == account_id ) {// adding oneself as friend
  12632. return;
  12633. }
  12634. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12635. if (f_sd == NULL)
  12636. return;
  12637. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12638. clif_friendslist_reqack(f_sd, sd, 1);
  12639. else {
  12640. int i;
  12641. // Find an empty slot
  12642. for (i = 0; i < MAX_FRIENDS; i++)
  12643. if (f_sd->status.friends[i].char_id == 0)
  12644. break;
  12645. if (i == MAX_FRIENDS) {
  12646. clif_friendslist_reqack(f_sd, sd, 2);
  12647. return;
  12648. }
  12649. f_sd->status.friends[i].account_id = sd->status.account_id;
  12650. f_sd->status.friends[i].char_id = sd->status.char_id;
  12651. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12652. clif_friendslist_reqack(f_sd, sd, 0);
  12653. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12654. if (battle_config.friend_auto_add) {
  12655. // Also add f_sd to sd's friendlist.
  12656. for (i = 0; i < MAX_FRIENDS; i++) {
  12657. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12658. return; //No need to add anything.
  12659. if (sd->status.friends[i].char_id == 0)
  12660. break;
  12661. }
  12662. if (i == MAX_FRIENDS) {
  12663. clif_friendslist_reqack(sd, f_sd, 2);
  12664. return;
  12665. }
  12666. sd->status.friends[i].account_id = f_sd->status.account_id;
  12667. sd->status.friends[i].char_id = f_sd->status.char_id;
  12668. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12669. clif_friendslist_reqack(sd, f_sd, 0);
  12670. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12671. }
  12672. }
  12673. }
  12674. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12675. /// 0203 <account id>.L <char id>.L
  12676. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12677. {
  12678. struct map_session_data *f_sd = NULL;
  12679. uint32 account_id, char_id;
  12680. int i, j;
  12681. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12682. account_id = RFIFOL(fd,info->pos[0]);
  12683. char_id = RFIFOL(fd,info->pos[1]);
  12684. // Search friend
  12685. for (i = 0; i < MAX_FRIENDS &&
  12686. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12687. if (i == MAX_FRIENDS) {
  12688. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12689. return;
  12690. }
  12691. //remove from friend's list first
  12692. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12693. for (i = 0; i < MAX_FRIENDS &&
  12694. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12695. if (i != MAX_FRIENDS) {
  12696. // move all chars up
  12697. for(j = i + 1; j < MAX_FRIENDS; j++)
  12698. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12699. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12700. //should the guy be notified of some message? we should add it here if so
  12701. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12702. WFIFOW(f_sd->fd,0) = 0x20a;
  12703. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12704. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12705. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12706. }
  12707. } else { //friend not online -- ask char server to delete from his friendlist
  12708. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12709. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12710. return;
  12711. }
  12712. }
  12713. // We can now delete from original requester
  12714. for (i = 0; i < MAX_FRIENDS &&
  12715. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12716. // move all chars up
  12717. for(j = i + 1; j < MAX_FRIENDS; j++)
  12718. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12719. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12720. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12721. WFIFOHEAD(fd,packet_len(0x20a));
  12722. WFIFOW(fd,0) = 0x20a;
  12723. WFIFOL(fd,2) = account_id;
  12724. WFIFOL(fd,6) = char_id;
  12725. WFIFOSET(fd, packet_len(0x20a));
  12726. }
  12727. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12728. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12729. void clif_PVPInfo(struct map_session_data* sd)
  12730. {
  12731. int fd = sd->fd;
  12732. WFIFOHEAD(fd,packet_len(0x210));
  12733. WFIFOW(fd,0) = 0x210;
  12734. WFIFOL(fd,2) = sd->status.char_id;
  12735. WFIFOL(fd,6) = sd->status.account_id;
  12736. WFIFOL(fd,10) = sd->pvp_won; // times won
  12737. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12738. WFIFOL(fd,18) = sd->pvp_point;
  12739. WFIFOSET(fd, packet_len(0x210));
  12740. }
  12741. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12742. /// 020f <char id>.L <account id>.L
  12743. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12744. {
  12745. // TODO: Is there a way to use this on an another player (char/acc id)?
  12746. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12747. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12748. clif_PVPInfo(sd);
  12749. }
  12750. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12751. /// 0254 <which>.B
  12752. /// which: (unused atm for security purpose)
  12753. /// 0 = sun
  12754. /// 1 = moon
  12755. /// 2 = star
  12756. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12757. {
  12758. int i;
  12759. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12760. if (sd->menuskill_id != SG_FEEL)
  12761. return;
  12762. i = sd->menuskill_val-1;
  12763. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12764. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12765. sd->feel_map[i].m = sd->bl.m;
  12766. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12767. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12768. // clif_misceffect2(&sd->bl, 0x1b0);
  12769. // clif_misceffect2(&sd->bl, 0x21f);
  12770. clif_feel_info(sd, i, 0);
  12771. clif_menuskill_clear(sd);
  12772. }
  12773. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12774. /// 0253 <which>.B
  12775. /// which:
  12776. /// 0 = sun
  12777. /// 1 = moon
  12778. /// 2 = star
  12779. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12780. {
  12781. WFIFOHEAD(fd,packet_len(0x253));
  12782. WFIFOW(fd,0)=0x253;
  12783. WFIFOB(fd,2)=TOB(skill_lv-1);
  12784. WFIFOSET(fd, packet_len(0x253));
  12785. sd->menuskill_id = SG_FEEL;
  12786. sd->menuskill_val = skill_lv;
  12787. }
  12788. /// Request to change homunculus' name (CZ_RENAME_MER).
  12789. /// 0231 <name>.24B
  12790. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12791. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12792. }
  12793. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12794. /// 0234 <id>.L
  12795. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12796. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12797. struct block_list *bl = NULL;
  12798. struct unit_data *ud = NULL;
  12799. if( sd->md && sd->md->bl.id == id )
  12800. bl = &sd->md->bl;
  12801. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12802. bl = &sd->hd->bl; // Moving Homunculus
  12803. else
  12804. return;
  12805. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12806. ud = unit_bl2ud(bl);
  12807. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12808. }
  12809. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12810. /// 0232 <id>.L <position data>.3B
  12811. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12812. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12813. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12814. struct block_list *bl = NULL;
  12815. short x, y;
  12816. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12817. if( sd->md && sd->md->bl.id == id )
  12818. bl = &sd->md->bl; // Moving Mercenary
  12819. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12820. bl = &sd->hd->bl; // Moving Homunculus
  12821. else
  12822. return;
  12823. unit_walktoxy(bl, x, y, 4);
  12824. }
  12825. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12826. /// 0233 <id>.L <target id>.L <action>.B
  12827. /// action:
  12828. /// always 0
  12829. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12830. {
  12831. struct block_list *bl = NULL;
  12832. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12833. int id = RFIFOL(fd,info->pos[0]);
  12834. int target_id = RFIFOL(fd,info->pos[1]);
  12835. int action_type = RFIFOB(fd,info->pos[2]);
  12836. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12837. bl = &sd->hd->bl;
  12838. else if( sd->md && sd->md->bl.id == id )
  12839. bl = &sd->md->bl;
  12840. else return;
  12841. unit_stop_attack(bl);
  12842. unit_attack(bl, target_id, action_type != 0);
  12843. }
  12844. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12845. /// 022d <type>.W <command>.B
  12846. /// type:
  12847. /// always 0
  12848. /// command:
  12849. /// 0 = homunculus information
  12850. /// 1 = feed
  12851. /// 2 = delete
  12852. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12853. { //[orn]
  12854. int cmd = RFIFOW(fd,0);
  12855. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12856. if(!hom_is_active(sd->hd))
  12857. return;
  12858. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12859. }
  12860. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12861. /// 0292
  12862. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12863. {
  12864. pc_revive_item(sd);
  12865. }
  12866. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12867. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12868. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12869. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12870. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12871. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12872. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12873. void clif_check(int fd, struct map_session_data* pl_sd)
  12874. {
  12875. WFIFOHEAD(fd,packet_len(0x214));
  12876. WFIFOW(fd, 0) = 0x214;
  12877. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12878. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12879. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12880. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12881. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12882. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12883. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12884. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12885. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12886. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12887. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12888. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12889. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12890. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12891. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12892. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12893. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12894. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12895. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12896. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12897. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12898. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12899. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12900. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12901. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12902. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12903. WFIFOSET(fd,packet_len(0x214));
  12904. }
  12905. /// /check (CZ_REQ_STATUS_GM).
  12906. /// Request character's status values.
  12907. /// 0213 <char name>.24B
  12908. void clif_parse_Check(int fd, struct map_session_data *sd)
  12909. {
  12910. char charname[NAME_LENGTH];
  12911. struct map_session_data* pl_sd;
  12912. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12913. return;
  12914. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12915. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12916. {
  12917. return;
  12918. }
  12919. clif_check(fd, pl_sd);
  12920. }
  12921. /// MAIL SYSTEM
  12922. /// By Zephyrus
  12923. ///
  12924. /// Notification about the result of adding an item to mail
  12925. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12926. /// result:
  12927. /// 0 = success
  12928. /// 1 = failure
  12929. /// 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)
  12930. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12931. /// result:
  12932. /// 0 = success
  12933. /// 1 = over weight
  12934. /// 2 = fatal error
  12935. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  12936. int fd = sd->fd;
  12937. #if PACKETVER < 20150513
  12938. WFIFOHEAD(fd,packet_len(0x255));
  12939. WFIFOW(fd,0) = 0x255;
  12940. WFIFOW(fd,2) = index;
  12941. WFIFOB(fd,4) = flag;
  12942. WFIFOSET(fd,packet_len(0x255));
  12943. #else
  12944. struct PACKET_ZC_ADD_ITEM_TO_MAIL p;
  12945. if( flag ){
  12946. memset( &p, 0, sizeof( p ) );
  12947. }else{
  12948. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  12949. p.index = index;
  12950. p.count = amount;
  12951. p.itemId = client_nameid( item->nameid );
  12952. p.type = itemtype( item->nameid );
  12953. p.IsIdentified = item->identify ? 1 : 0;
  12954. p.IsDamaged = item->attribute ? 1 : 0;
  12955. p.refiningLevel = item->refine;
  12956. clif_addcards( &p.slot, item );
  12957. clif_add_random_options( p.optionData, item );
  12958. p.weight = 0;
  12959. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  12960. if( sd->mail.item[i].nameid == 0 ){
  12961. continue;
  12962. }
  12963. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12964. }
  12965. p.favorite = item->favorite;
  12966. p.location = pc_equippoint( sd, server_index( index ) );
  12967. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  12968. p.enchantgrade = item->enchantgrade;
  12969. #endif
  12970. }
  12971. p.PacketType = rodexadditem;
  12972. p.result = flag;
  12973. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  12974. #endif
  12975. }
  12976. /// Notification about the result of retrieving a mail attachment
  12977. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12978. /// result:
  12979. /// 0 = success
  12980. /// 1 = failure
  12981. /// 2 = too many items
  12982. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12983. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12984. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12985. #if PACKETVER < 20150513
  12986. int fd = sd->fd;
  12987. WFIFOHEAD(fd,packet_len(0x245));
  12988. WFIFOW(fd,0) = 0x245;
  12989. WFIFOB(fd,2) = result;
  12990. WFIFOSET(fd,packet_len(0x245));
  12991. #else
  12992. switch( type ){
  12993. case MAIL_ATT_ITEM:
  12994. case MAIL_ATT_ZENY:
  12995. break;
  12996. default:
  12997. return;
  12998. }
  12999. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13000. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13001. p.MailID = msg->id;
  13002. p.opentype = msg->type;
  13003. p.result = result;
  13004. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13005. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13006. #endif
  13007. }
  13008. /// Notification about the result of sending a mail
  13009. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13010. /// result:
  13011. /// 0 = success
  13012. /// 1 = recipinent does not exist
  13013. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13014. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13015. #if PACKETVER < 20150513
  13016. int fd = sd->fd;
  13017. WFIFOHEAD(fd,packet_len(0x249));
  13018. WFIFOW(fd,0) = 0x249;
  13019. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13020. WFIFOSET(fd,packet_len(0x249));
  13021. #else
  13022. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13023. p.PacketType = rodexwriteresult;
  13024. p.result = result;
  13025. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13026. #endif
  13027. }
  13028. /// Notification about the result of deleting a mail.
  13029. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13030. /// result:
  13031. /// 0 = success
  13032. /// 1 = failure
  13033. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13034. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13035. #if PACKETVER < 20150513
  13036. int fd = sd->fd;
  13037. WFIFOHEAD(fd, packet_len(0x257));
  13038. WFIFOW(fd,0) = 0x257;
  13039. WFIFOL(fd,2) = msg->id;
  13040. WFIFOW(fd,6) = !success;
  13041. WFIFOSET(fd, packet_len(0x257));
  13042. #else
  13043. // This is only a success notification
  13044. if( success ){
  13045. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13046. p.PacketType = rodexdelete;
  13047. p.opentype = msg->type;
  13048. p.MailID = msg->id;
  13049. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13050. }
  13051. #endif
  13052. }
  13053. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13054. /// 0274 <mail id>.L <result>.W
  13055. /// result:
  13056. /// 0 = success
  13057. /// 1 = failure
  13058. void clif_Mail_return(int fd, int mail_id, short fail)
  13059. {
  13060. WFIFOHEAD(fd,packet_len(0x274));
  13061. WFIFOW(fd,0) = 0x274;
  13062. WFIFOL(fd,2) = mail_id;
  13063. WFIFOW(fd,6) = fail;
  13064. WFIFOSET(fd,packet_len(0x274));
  13065. }
  13066. /// Notification about new mail.
  13067. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13068. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13069. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13070. #if PACKETVER < 20150513
  13071. int fd = sd->fd;
  13072. WFIFOHEAD(fd,packet_len(0x24a));
  13073. WFIFOW(fd,0) = 0x24a;
  13074. WFIFOL(fd,2) = mail_id;
  13075. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13076. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13077. WFIFOSET(fd,packet_len(0x24a));
  13078. #else
  13079. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13080. p.PacketType = rodexicon;
  13081. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13082. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13083. #endif
  13084. }
  13085. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13086. /// 0260 <type>.L
  13087. /// type:
  13088. /// 0 = open
  13089. /// 1 = close
  13090. void clif_Mail_window(int fd, int flag)
  13091. {
  13092. WFIFOHEAD(fd,packet_len(0x260));
  13093. WFIFOW(fd,0) = 0x260;
  13094. WFIFOL(fd,2) = flag;
  13095. WFIFOSET(fd,packet_len(0x260));
  13096. }
  13097. /// Lists mails stored in inbox.
  13098. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13099. /// read:
  13100. /// 0 = unread
  13101. /// 1 = read
  13102. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13103. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13104. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13105. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13106. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13107. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13108. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13109. #if PACKETVER < 20150513
  13110. int fd = sd->fd;
  13111. struct mail_data *md = &sd->mail.inbox;
  13112. struct mail_message *msg;
  13113. int len, i, j;
  13114. len = 8 + (73 * md->amount);
  13115. WFIFOHEAD(fd,len);
  13116. WFIFOW(fd,0) = 0x240;
  13117. WFIFOW(fd,2) = len;
  13118. WFIFOL(fd,4) = md->amount;
  13119. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13120. {
  13121. msg = &md->msg[i];
  13122. if (msg->id < 1)
  13123. continue;
  13124. WFIFOL(fd,8+73*j) = msg->id;
  13125. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13126. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13127. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13128. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13129. j++;
  13130. }
  13131. WFIFOSET(fd,len);
  13132. if( md->full ) {// TODO: is this official?
  13133. char output[100];
  13134. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13135. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13136. }
  13137. #else
  13138. int fd = sd->fd;
  13139. struct mail_data *md = &sd->mail.inbox;
  13140. struct mail_message *msg;
  13141. int i, j, k, offset, titleLength;
  13142. uint8 mailType, amount, remaining;
  13143. uint32 now = (uint32)time(NULL);
  13144. #if PACKETVER >= 20170419
  13145. int cmd = 0xac2;
  13146. #elif PACKETVER >= 20160601
  13147. int cmd = 0xa7d;
  13148. #else
  13149. int cmd = 0x9f0;
  13150. #endif
  13151. if( battle_config.mail_daily_count ){
  13152. mail_refresh_remaining_amount(sd);
  13153. }
  13154. #if PACKETVER >= 20170419
  13155. // Always send all
  13156. i = md->amount;
  13157. #else
  13158. // If a starting mail id was sent
  13159. if( mailID != 0 ){
  13160. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13161. // Unknown mail
  13162. if( i == md->amount ){
  13163. // Ignore the request for now
  13164. return; // TODO: Should we just show the first page instead?
  13165. }
  13166. // It was actually the oldest/first mail, there is no further page
  13167. if( i == 0 ){
  13168. return;
  13169. }
  13170. // We actually want the next/older mail
  13171. i -= 1;
  13172. }else{
  13173. i = md->amount;
  13174. }
  13175. #endif
  13176. // Count the remaining mails from the starting mail or the beginning
  13177. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13178. for( j = i, remaining = 0; j >= 0; j-- ){
  13179. msg = &md->msg[j];
  13180. if (msg->id < 1)
  13181. continue;
  13182. #if PACKETVER < 20170419
  13183. if (msg->type != type)
  13184. continue;
  13185. #endif
  13186. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13187. continue;
  13188. remaining++;
  13189. }
  13190. #if PACKETVER >= 20170419
  13191. // Always send all
  13192. amount = remaining;
  13193. #else
  13194. if( remaining > MAIL_PAGE_SIZE ){
  13195. amount = MAIL_PAGE_SIZE;
  13196. }else{
  13197. amount = remaining;
  13198. }
  13199. #endif
  13200. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13201. WFIFOW(fd, 0) = cmd;
  13202. #if PACKETVER >= 20170419
  13203. WFIFOB(fd, 4) = 1; // Unknown
  13204. offset = 5;
  13205. #else
  13206. WFIFOB(fd, 4) = type;
  13207. WFIFOB(fd, 5) = amount;
  13208. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13209. offset = 7;
  13210. #endif
  13211. for( amount = 0; i >= 0; i-- ){
  13212. msg = &md->msg[i];
  13213. if (msg->id < 1)
  13214. continue;
  13215. #if PACKETVER < 20170419
  13216. if (msg->type != type)
  13217. continue;
  13218. #endif
  13219. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13220. continue;
  13221. #if PACKETVER >= 20170419
  13222. WFIFOB(fd, offset) = msg->type;
  13223. offset += 1;
  13224. #endif
  13225. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13226. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13227. mailType = MAIL_TYPE_TEXT; // Normal letter
  13228. if( msg->zeny > 0 ){
  13229. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13230. }
  13231. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13232. if( msg->item[k].nameid > 0 ){
  13233. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13234. break;
  13235. }
  13236. }
  13237. #if PACKETVER >= 20170419
  13238. // If it came from an npc?
  13239. if( !msg->send_id ){
  13240. mailType |= MAIL_TYPE_NPC;
  13241. }
  13242. #endif
  13243. WFIFOB(fd, offset + 9) = mailType;
  13244. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13245. #if PACKETVER < 20170419
  13246. // How much time has passed since you received the mail
  13247. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13248. offset += 4;
  13249. #endif
  13250. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13251. if( msg->scheduled_deletion > 0 ){
  13252. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13253. }else{
  13254. // Fake the scheduled deletion to one year in the future
  13255. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13256. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13257. }
  13258. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13259. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13260. offset += 40 + titleLength;
  13261. }
  13262. WFIFOW(fd, 2) = (int16)offset;
  13263. WFIFOSET(fd, offset);
  13264. #endif
  13265. }
  13266. /// Mail inbox list request.
  13267. /// 023f (CZ_MAIL_GET_LIST)
  13268. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13269. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13270. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13271. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13272. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13273. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13274. if( mail_invalid_operation( sd ) ){
  13275. return;
  13276. }
  13277. #if PACKETVER < 20150513
  13278. struct mail_data* md = &sd->mail.inbox;
  13279. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13280. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13281. else
  13282. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13283. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13284. mail_removezeny(sd, false);
  13285. #else
  13286. int cmd = RFIFOW(fd, 0);
  13287. #if PACKETVER < 20170419
  13288. uint8 openType = RFIFOB(fd, 2);
  13289. uint64 mailId = RFIFOQ(fd, 3);
  13290. #else
  13291. uint8 openType;
  13292. uint64 mailId = RFIFOQ(fd, 2);
  13293. int i;
  13294. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13295. if( i == MAIL_MAX_INBOX ){
  13296. openType = MAIL_INBOX_NORMAL;
  13297. mailId = 0;
  13298. }else{
  13299. openType = sd->mail.inbox.msg[i].type;
  13300. mailId = 0;
  13301. }
  13302. #endif
  13303. switch( openType ){
  13304. case MAIL_INBOX_NORMAL:
  13305. case MAIL_INBOX_ACCOUNT:
  13306. case MAIL_INBOX_RETURNED:
  13307. break;
  13308. default:
  13309. // Unknown type: ignore request
  13310. return;
  13311. }
  13312. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13313. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13314. return;
  13315. }
  13316. // If it is not a next page request
  13317. if( cmd != 0x9ee ){
  13318. mailId = 0;
  13319. }
  13320. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13321. #endif
  13322. }
  13323. /// Opens a mail
  13324. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13325. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13326. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13327. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13328. /// { }*n
  13329. // TODO: Packet description => for repeated block
  13330. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13331. int i, fd = sd->fd;
  13332. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13333. if( i == MAIL_MAX_INBOX ) {
  13334. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13335. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13336. return;
  13337. } else {
  13338. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13339. struct item *item;
  13340. struct item_data *data;
  13341. int msg_len = strlen(msg->body);
  13342. if( msg_len == 0 ) {
  13343. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13344. msg_len = strlen(msg->body);
  13345. }
  13346. #if PACKETVER < 20150513
  13347. item = &msg->item[0];
  13348. int len = 101 + msg_len;
  13349. WFIFOHEAD(fd,len);
  13350. WFIFOW(fd,0) = 0x242;
  13351. WFIFOW(fd,2) = len;
  13352. WFIFOL(fd,4) = msg->id;
  13353. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13354. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13355. WFIFOL(fd,72) = 0;
  13356. WFIFOL(fd,76) = msg->zeny;
  13357. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13358. WFIFOL(fd,80) = item->amount;
  13359. WFIFOW(fd,84) = client_nameid( item->nameid );
  13360. WFIFOW(fd,86) = itemtype( item->nameid );
  13361. WFIFOB(fd,88) = item->identify;
  13362. WFIFOB(fd,89) = item->attribute;
  13363. WFIFOB(fd,90) = item->refine;
  13364. WFIFOW(fd,91) = item->card[0];
  13365. WFIFOW(fd,93) = item->card[1];
  13366. WFIFOW(fd,95) = item->card[2];
  13367. WFIFOW(fd,97) = item->card[3];
  13368. } else // no item, set all to zero
  13369. memset(WFIFOP(fd,80), 0x00, 19);
  13370. WFIFOB(fd,99) = (unsigned char)msg_len;
  13371. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13372. WFIFOSET(fd,len);
  13373. #else
  13374. msg_len += 1; // Zero Termination
  13375. int length = sizeof( struct PACKET_ZC_READ_MAIL ) + MAIL_BODY_LENGTH + sizeof( struct mail_item ) * MAIL_MAX_ITEM;
  13376. WFIFOHEAD( fd, length );
  13377. struct PACKET_ZC_READ_MAIL *p = (struct PACKET_ZC_READ_MAIL *)WFIFOP( fd, 0 );
  13378. p->PacketType = rodexread;
  13379. p->PacketLength = length;
  13380. p->opentype = msg->type;
  13381. p->MailID = msg->id;
  13382. p->TextcontentsLength = msg_len;
  13383. p->zeny = msg->zeny;
  13384. int offset = sizeof( struct PACKET_ZC_READ_MAIL );
  13385. safestrncpy( WFIFOCP( fd, offset ), msg->body, msg_len );
  13386. offset += msg_len;
  13387. int count = 0;
  13388. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13389. item = &msg->item[j];
  13390. if( item->nameid > 0 && item->amount > 0 && ( data = itemdb_exists( item->nameid ) ) != NULL ){
  13391. struct mail_item* mailitem = (struct mail_item *)WFIFOP( fd, offset );
  13392. mailitem->ITID = client_nameid( item->nameid );
  13393. mailitem->count = item->amount;
  13394. mailitem->type = itemtype( item->nameid );
  13395. mailitem->IsIdentified = item->identify ? 1 : 0;
  13396. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13397. mailitem->refiningLevel = item->refine;
  13398. mailitem->location = pc_equippoint_sub( sd, data );
  13399. mailitem->viewSprite = data->look;
  13400. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13401. clif_addcards( &mailitem->slot, item );
  13402. clif_add_random_options( mailitem->optionData, item );
  13403. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13404. mailitem->enchantgrade = item->enchantgrade;
  13405. #endif
  13406. offset += sizeof( struct mail_item );
  13407. count++;
  13408. }
  13409. }
  13410. p->ItemCnt = count;
  13411. p->PacketLength = sizeof( struct PACKET_ZC_READ_MAIL ) + p->TextcontentsLength + sizeof( struct mail_item ) * p->ItemCnt;
  13412. WFIFOSET( fd, p->PacketLength );
  13413. #endif
  13414. if (msg->status == MAIL_UNREAD) {
  13415. msg->status = MAIL_READ;
  13416. intif_Mail_read(mail_id);
  13417. clif_parse_Mail_refreshinbox(fd, sd);
  13418. sd->mail.inbox.unread--;
  13419. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13420. }
  13421. }
  13422. }
  13423. /// Request to open a mail.
  13424. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13425. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13426. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13427. #if PACKETVER < 20150513
  13428. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13429. #else
  13430. //uint8 openType = RFIFOB(fd, 2);
  13431. int mail_id = (int)RFIFOQ(fd, 3);
  13432. #endif
  13433. if( mail_id <= 0 )
  13434. return;
  13435. if( mail_invalid_operation(sd) )
  13436. return;
  13437. clif_Mail_read(sd, mail_id);
  13438. }
  13439. /// Allow a player to begin writing a mail
  13440. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13441. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13442. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13443. p.PacketType = rodexopenwrite;
  13444. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13445. p.result = success;
  13446. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13447. }
  13448. /// Request to start writing a mail
  13449. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13450. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13451. char name[NAME_LENGTH];
  13452. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13453. if( mail_invalid_operation( sd ) ){
  13454. return;
  13455. }
  13456. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13457. clif_send_Mail_beginwrite_ack(sd, name, false);
  13458. return;
  13459. }
  13460. mail_clear(sd);
  13461. sd->state.mail_writing = true;
  13462. clif_send_Mail_beginwrite_ack(sd, name,true);
  13463. }
  13464. /// Notification that the client cancelled writing a mail
  13465. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13466. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13467. sd->state.mail_writing = false;
  13468. }
  13469. /// Give the client information about the recipient, if available
  13470. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13471. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13472. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13473. PACKET_ZC_CHECKNAME p = { 0 };
  13474. p.PacketType = rodexcheckplayer;
  13475. p.CharId = char_id;
  13476. p.Class = class_;
  13477. p.BaseLevel = level;
  13478. #if PACKETVER >= 20160302
  13479. strncpy(p.Name, name, NAME_LENGTH);
  13480. #endif
  13481. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13482. }
  13483. /// Request information about the recipient
  13484. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13485. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13486. static char name[NAME_LENGTH];
  13487. if( mail_invalid_operation( sd ) ){
  13488. return;
  13489. }
  13490. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13491. intif_mail_checkreceiver(sd, name);
  13492. }
  13493. /// Request to receive mail's attachment.
  13494. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13495. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13496. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13497. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13498. int i;
  13499. struct mail_message* msg;
  13500. #if PACKETVER < 20150513
  13501. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13502. int attachment = MAIL_ATT_ALL;
  13503. #else
  13504. uint16 packet_id = RFIFOW(fd, 0);
  13505. int mail_id = (int)RFIFOQ(fd, 2);
  13506. //int openType = RFIFOB(fd, 10);
  13507. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13508. #endif
  13509. if( !chrif_isconnected() )
  13510. return;
  13511. if( mail_id <= 0 )
  13512. return;
  13513. if( mail_invalid_operation(sd) )
  13514. return;
  13515. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13516. if( i == MAIL_MAX_INBOX )
  13517. return;
  13518. msg = &sd->mail.inbox.msg[i];
  13519. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13520. attachment &= ~MAIL_ATT_ZENY;
  13521. }
  13522. if( attachment&MAIL_ATT_ITEM ){
  13523. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13524. // No items were found
  13525. if( i == MAIL_MAX_ITEM ){
  13526. attachment &= ~MAIL_ATT_ITEM;
  13527. }
  13528. }
  13529. // Either no attachment requested at all or there are no zeny or items in the mail
  13530. if( attachment == MAIL_ATT_NONE ){
  13531. return;
  13532. }
  13533. if( attachment&MAIL_ATT_ZENY ){
  13534. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13535. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13536. return;
  13537. }else{
  13538. // Store the pending zeny (required for the "retrieve all" feature)
  13539. sd->mail.pending_zeny += msg->zeny;
  13540. // To make sure another request fails
  13541. msg->zeny = 0;
  13542. }
  13543. }
  13544. if( attachment&MAIL_ATT_ITEM ){
  13545. int slots = 0, totalweight = 0;
  13546. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13547. struct item* item = &msg->item[i];
  13548. if( item->nameid > 0 && item->amount > 0 ){
  13549. struct item_data *data;
  13550. if((data = itemdb_exists(item->nameid)) == NULL)
  13551. continue;
  13552. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13553. case CHKADDITEM_NEW:
  13554. slots += data->inventorySlotNeeded( item->amount );
  13555. break;
  13556. case CHKADDITEM_OVERAMOUNT:
  13557. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13558. return;
  13559. }
  13560. totalweight += data->weight * item->amount;
  13561. }
  13562. }
  13563. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13564. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13565. return;
  13566. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13567. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13568. return;
  13569. }
  13570. // To make sure another request fails
  13571. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13572. // Store the pending weight (required for the "retrieve all" feature)
  13573. sd->mail.pending_weight += totalweight;
  13574. // Store the pending slots (required for the "retrieve all" feature)
  13575. sd->mail.pending_slots += slots;
  13576. }
  13577. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13578. }
  13579. /// Request to delete a mail.
  13580. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13581. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13582. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13583. #if PACKETVER < 20150513
  13584. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13585. #else
  13586. //int openType = RFIFOB(fd, 2);
  13587. int mail_id = (int)RFIFOQ(fd, 3);
  13588. #endif
  13589. int i, j;
  13590. if( !chrif_isconnected() )
  13591. return;
  13592. if( mail_id <= 0 )
  13593. return;
  13594. if( mail_invalid_operation(sd) )
  13595. return;
  13596. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13597. if (i < MAIL_MAX_INBOX) {
  13598. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13599. // can't delete mail without removing zeny first
  13600. if( msg->zeny > 0 ){
  13601. clif_mail_delete(sd, msg, false);
  13602. return;
  13603. }
  13604. // can't delete mail without removing attachment(s) first
  13605. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13606. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13607. clif_mail_delete(sd, msg, false);
  13608. return;
  13609. }
  13610. }
  13611. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13612. sd->mail.inbox.unread--;
  13613. clif_Mail_new(sd,0,NULL,NULL);
  13614. }
  13615. }
  13616. }
  13617. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13618. /// 0273 <mail id>.L <receive name>.24B
  13619. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13620. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13621. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13622. int i;
  13623. if( mail_id <= 0 )
  13624. return;
  13625. if( mail_invalid_operation(sd) )
  13626. return;
  13627. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13628. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13629. intif_Mail_return(sd->status.char_id, mail_id);
  13630. else
  13631. clif_Mail_return(sd->fd, mail_id, 1);
  13632. }
  13633. /// Request to add an item or Zeny to mail.
  13634. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13635. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13636. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13637. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13638. uint16 idx = RFIFOW(fd,info->pos[0]);
  13639. #if PACKETVER < 20150513
  13640. int amount = RFIFOL(fd,info->pos[1]);
  13641. #else
  13642. int amount = RFIFOW(fd,info->pos[1]);
  13643. #endif
  13644. unsigned char flag;
  13645. if( !chrif_isconnected() )
  13646. return;
  13647. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13648. return;
  13649. if (sd->inventory_data[server_index(idx)] == nullptr)
  13650. return;
  13651. if( mail_invalid_operation( sd ) ){
  13652. return;
  13653. }
  13654. flag = mail_setitem(sd, idx, amount);
  13655. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13656. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13657. }else{
  13658. clif_Mail_setattachment(sd,idx,amount,flag);
  13659. }
  13660. }
  13661. /// Remove an item from a mail
  13662. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13663. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13664. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13665. p.PacketType = rodexremoveitem;
  13666. p.result = success;
  13667. p.index = index;
  13668. p.cnt = amount;
  13669. int total = 0;
  13670. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13671. if( sd->mail.item[i].nameid == 0 ){
  13672. break;
  13673. }
  13674. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13675. }
  13676. p.weight = total;
  13677. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13678. }
  13679. /// Request to reset mail item and/or Zeny
  13680. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13681. /// type:
  13682. /// 0 = reset all
  13683. /// 1 = remove item
  13684. /// 2 = remove zeny
  13685. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13686. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13687. {
  13688. #if PACKETVER < 20150513
  13689. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13690. if (type == 0 || type == 1)
  13691. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13692. if (type == 0 || type == 2)
  13693. mail_removezeny(sd, false);
  13694. #else
  13695. uint16 index = RFIFOW(fd, 2);
  13696. uint16 count = RFIFOW(fd, 4);
  13697. mail_removeitem(sd,0,index,count);
  13698. #endif
  13699. }
  13700. /// Request to send mail
  13701. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13702. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13703. /// 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)
  13704. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13705. #if PACKETVER < 20150513
  13706. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13707. if( !chrif_isconnected() )
  13708. return;
  13709. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13710. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13711. return;
  13712. }
  13713. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13714. #else
  13715. uint16 length = RFIFOW(fd, 2);
  13716. if( length < 0x3e ){
  13717. ShowWarning("Too short...\n");
  13718. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13719. return;
  13720. }
  13721. if( mail_invalid_operation( sd ) ){
  13722. return;
  13723. }
  13724. // Forged request without a begin writing packet?
  13725. if( !sd->state.mail_writing ){
  13726. return; // Ignore it
  13727. }
  13728. char receiver[NAME_LENGTH];
  13729. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13730. // char sender[NAME_LENGTH];
  13731. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13732. uint64 zeny = RFIFOQ(fd, 52);
  13733. uint16 titleLength = RFIFOW(fd, 60);
  13734. uint16 textLength = RFIFOW(fd, 62);
  13735. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13736. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13737. char title[MAIL_TITLE_LENGTH];
  13738. char text[MAIL_BODY_LENGTH];
  13739. #if PACKETVER <= 20160330
  13740. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13741. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13742. #else
  13743. // 64 = <char id>.L
  13744. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13745. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13746. #endif
  13747. if( zeny > 0 ){
  13748. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13749. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13750. return;
  13751. }
  13752. }
  13753. mail_send(sd, receiver, title, text, realTextLength);
  13754. #endif
  13755. }
  13756. /// AUCTION SYSTEM
  13757. /// By Zephyrus
  13758. ///
  13759. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13760. /// 025f <type>.L
  13761. /// type:
  13762. /// 0 = open
  13763. /// 1 = close
  13764. void clif_Auction_openwindow(struct map_session_data *sd)
  13765. {
  13766. int fd = sd->fd;
  13767. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13768. return;
  13769. if( !battle_config.feature_auction )
  13770. return;
  13771. WFIFOHEAD(fd,packet_len(0x25f));
  13772. WFIFOW(fd,0) = 0x25f;
  13773. WFIFOL(fd,2) = 0;
  13774. WFIFOSET(fd,packet_len(0x25f));
  13775. }
  13776. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13777. /// 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 }*
  13778. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13779. {
  13780. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13781. struct auction_data auction;
  13782. WFIFOHEAD(fd,12 + (count * 83));
  13783. WFIFOW(fd,0) = 0x252;
  13784. WFIFOW(fd,2) = 12 + (count * 83);
  13785. WFIFOL(fd,4) = pages;
  13786. WFIFOL(fd,8) = count;
  13787. for( i = 0; i < count; i++ ) {
  13788. int k = 12 + (i * 83);
  13789. memcpy(&auction, RBUFP(buf,i * len), len);
  13790. WFIFOL(fd,k) = auction.auction_id;
  13791. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13792. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13793. WFIFOL(fd,30+k) = auction.type;
  13794. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13795. WFIFOB(fd,36+k) = auction.item.identify;
  13796. WFIFOB(fd,37+k) = auction.item.attribute;
  13797. WFIFOB(fd,38+k) = auction.item.refine;
  13798. WFIFOW(fd,39+k) = auction.item.card[0];
  13799. WFIFOW(fd,41+k) = auction.item.card[1];
  13800. WFIFOW(fd,43+k) = auction.item.card[2];
  13801. WFIFOW(fd,45+k) = auction.item.card[3];
  13802. WFIFOL(fd,47+k) = auction.price;
  13803. WFIFOL(fd,51+k) = auction.buynow;
  13804. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13805. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13806. }
  13807. WFIFOSET(fd,WFIFOW(fd,2));
  13808. }
  13809. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13810. /// 0256 <index>.W <result>.B
  13811. /// result:
  13812. /// 0 = success
  13813. /// 1 = failure
  13814. static void clif_Auction_setitem(int fd, int index, bool fail)
  13815. {
  13816. WFIFOHEAD(fd,packet_len(0x256));
  13817. WFIFOW(fd,0) = 0x256;
  13818. WFIFOW(fd,2) = index;
  13819. WFIFOB(fd,4) = fail;
  13820. WFIFOSET(fd,packet_len(0x256));
  13821. }
  13822. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13823. /// 024b <type>.W
  13824. /// type:
  13825. /// 0 = create (any other action in auction window)
  13826. /// 1 = cancel (cancel pressed on register tab)
  13827. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13828. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13829. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13830. if( sd->auction.amount > 0 )
  13831. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13832. sd->auction.amount = 0;
  13833. }
  13834. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13835. /// 024c <index>.W <count>.L
  13836. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13837. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13838. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13839. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13840. struct item_data *item;
  13841. if( !battle_config.feature_auction )
  13842. return;
  13843. if( sd->auction.amount > 0 )
  13844. sd->auction.amount = 0;
  13845. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13846. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13847. return;
  13848. }
  13849. 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.
  13850. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13851. return;
  13852. }
  13853. if( (item = itemdb_exists(sd->inventory.u.items_inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC || item->type == IT_SHADOWGEAR) )
  13854. { // Consumable or pets are not allowed
  13855. clif_Auction_setitem(sd->fd, idx, true);
  13856. return;
  13857. }
  13858. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13859. !sd->inventory.u.items_inventory[idx].identify ||
  13860. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13861. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13862. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13863. clif_Auction_setitem(sd->fd, idx, true);
  13864. return;
  13865. }
  13866. sd->auction.index = idx;
  13867. sd->auction.amount = amount;
  13868. clif_Auction_setitem(fd, idx + 2, false);
  13869. }
  13870. /// Result from an auction action (ZC_AUCTION_RESULT).
  13871. /// 0250 <result>.B
  13872. /// result:
  13873. /// 0 = You have failed to bid into the auction
  13874. /// 1 = You have successfully bid in the auction
  13875. /// 2 = The auction has been canceled
  13876. /// 3 = An auction with at least one bidder cannot be canceled
  13877. /// 4 = You cannot register more than 5 items in an auction at a time
  13878. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13879. /// 6 = You have won the auction
  13880. /// 7 = You have failed to win the auction
  13881. /// 8 = You do not have enough Zeny
  13882. /// 9 = You cannot place more than 5 bids at a time
  13883. void clif_Auction_message(int fd, unsigned char flag)
  13884. {
  13885. WFIFOHEAD(fd,packet_len(0x250));
  13886. WFIFOW(fd,0) = 0x250;
  13887. WFIFOB(fd,2) = flag;
  13888. WFIFOSET(fd,packet_len(0x250));
  13889. }
  13890. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13891. /// 025e <result>.W
  13892. /// result:
  13893. /// 0 = You have ended the auction
  13894. /// 1 = You cannot end the auction
  13895. /// 2 = Auction ID is incorrect
  13896. void clif_Auction_close(int fd, unsigned char flag)
  13897. {
  13898. WFIFOHEAD(fd,packet_len(0x25e));
  13899. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13900. WFIFOW(fd,2) = flag;
  13901. WFIFOSET(fd,packet_len(0x25e));
  13902. }
  13903. /// Request to add an auction (CZ_AUCTION_ADD).
  13904. /// 024d <now money>.L <max money>.L <delete hour>.W
  13905. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13906. {
  13907. struct auction_data auction;
  13908. struct item_data *item;
  13909. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13910. if( !battle_config.feature_auction )
  13911. return;
  13912. auction.price = RFIFOL(fd,info->pos[0]);
  13913. auction.buynow = RFIFOL(fd,info->pos[1]);
  13914. auction.hours = RFIFOW(fd,info->pos[2]);
  13915. // Invalid Situations...
  13916. if( sd->auction.amount < 1 ) {
  13917. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13918. return;
  13919. }
  13920. if( auction.price >= auction.buynow ) {
  13921. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13922. return;
  13923. }
  13924. if( auction.hours < 1 || auction.hours > 48 ) {
  13925. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13926. return;
  13927. }
  13928. // Auction checks...
  13929. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13930. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13931. clif_Auction_message(fd, 2); // The auction has been canceled
  13932. return;
  13933. }
  13934. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13935. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13936. return;
  13937. }
  13938. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13939. auction.buynow = battle_config.auction_maximumprice;
  13940. if( auction.price >= auction.buynow )
  13941. auction.price = auction.buynow - 1;
  13942. }
  13943. auction.auction_id = 0;
  13944. auction.seller_id = sd->status.char_id;
  13945. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13946. auction.buyer_id = 0;
  13947. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13948. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13949. {
  13950. clif_Auction_message(fd, 2); // The auction has been canceled
  13951. return;
  13952. }
  13953. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13954. { // Just in case
  13955. clif_Auction_message(fd, 2); // The auction has been canceled
  13956. return;
  13957. }
  13958. safestrncpy(auction.item_name, item->ename.c_str(), sizeof(auction.item_name));
  13959. auction.type = item->type;
  13960. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13961. auction.item.amount = 1;
  13962. auction.timestamp = 0;
  13963. if( !intif_Auction_register(&auction) )
  13964. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13965. else
  13966. {
  13967. int zeny = auction.hours*battle_config.auction_feeperhour;
  13968. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13969. sd->auction.amount = 0;
  13970. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13971. }
  13972. }
  13973. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13974. /// 024e <auction id>.L
  13975. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13976. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13977. intif_Auction_cancel(sd->status.char_id, auction_id);
  13978. }
  13979. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13980. /// 025d <auction id>.L
  13981. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13982. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13983. intif_Auction_close(sd->status.char_id, auction_id);
  13984. }
  13985. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13986. /// 024f <auction id>.L <money>.L
  13987. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13988. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13989. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13990. int bid = RFIFOL(fd,info->pos[1]);
  13991. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13992. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13993. return;
  13994. }
  13995. if( bid <= 0 )
  13996. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13997. else if( bid > sd->status.zeny )
  13998. clif_Auction_message(fd, 8); // You do not have enough zeny
  13999. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14000. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14001. else {
  14002. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14003. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14004. }
  14005. }
  14006. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14007. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14008. /// search type:
  14009. /// 0 = armor
  14010. /// 1 = weapon
  14011. /// 2 = card
  14012. /// 3 = misc
  14013. /// 4 = name search
  14014. /// 5 = auction id search
  14015. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  14016. char search_text[NAME_LENGTH];
  14017. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14018. short type = RFIFOW(fd,info->pos[0]);
  14019. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14020. int page = RFIFOW(fd,info->pos[3]);
  14021. if( !battle_config.feature_auction )
  14022. return;
  14023. clif_parse_Auction_cancelreg(fd, sd);
  14024. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14025. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14026. }
  14027. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14028. /// 025c <type>.W
  14029. /// type:
  14030. /// 0 = sell (own auctions)
  14031. /// 1 = buy (own bids)
  14032. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  14033. {
  14034. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14035. if( !battle_config.feature_auction )
  14036. return;
  14037. clif_parse_Auction_cancelreg(fd, sd);
  14038. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14039. }
  14040. /// CASH/POINT SHOP
  14041. ///
  14042. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  14043. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14044. nullpo_retv( sd );
  14045. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14046. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14047. p.cashPoints = sd->cashPoints;
  14048. p.kafraPoints = sd->kafraPoints;
  14049. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14050. p.tab = tab;
  14051. #endif
  14052. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14053. #endif
  14054. }
  14055. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  14056. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14057. nullpo_retv( sd );
  14058. int tab = 0;
  14059. #if PACKETVER >= 20191224
  14060. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14061. tab = p->tab;
  14062. #endif
  14063. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14064. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14065. return;
  14066. }
  14067. sd->state.cashshop_open = true;
  14068. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14069. clif_cashshop_open( sd, tab );
  14070. #endif
  14071. }
  14072. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14073. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14074. sd->state.cashshop_open = false;
  14075. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14076. // No need to do anything here
  14077. #endif
  14078. }
  14079. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14080. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14081. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14082. // [4144] packet exists only in 2011 and was dropped after
  14083. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14084. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14085. int j;
  14086. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14087. return;
  14088. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14089. WFIFOW(fd, 0) = 0x8c0;
  14090. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14091. WFIFOL(fd, 4) = tab;
  14092. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14093. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14094. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14095. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14096. }
  14097. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14098. #endif
  14099. }
  14100. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14101. void clif_cashshop_list( struct map_session_data* sd ){
  14102. nullpo_retv( sd );
  14103. int fd = sd->fd;
  14104. if( !session_isActive( fd ) ){
  14105. return;
  14106. }
  14107. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14108. // Skip empty tabs, the client only expects filled ones
  14109. if( cash_shop_items[tab].count == 0 ){
  14110. continue;
  14111. }
  14112. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14113. WFIFOHEAD( fd, len );
  14114. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14115. p->packetType = 0x8ca;
  14116. p->packetLength = len;
  14117. p->count = cash_shop_items[tab].count;
  14118. p->tabNum = tab;
  14119. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14120. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14121. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14122. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14123. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14124. if( id == nullptr ){
  14125. p->items[i].location = 0;
  14126. p->items[i].viewSprite = 0;
  14127. }else{
  14128. p->items[i].location = pc_equippoint_sub( sd, id );
  14129. p->items[i].viewSprite = id->look;
  14130. }
  14131. #endif
  14132. }
  14133. WFIFOSET( fd, len );
  14134. }
  14135. }
  14136. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14137. if( !sd->status.cashshop_sent ) {
  14138. clif_cashshop_list( sd );
  14139. #if PACKETVER_SUPPORTS_SALES
  14140. sale_notify_login(sd);
  14141. #endif
  14142. sd->status.cashshop_sent = true;
  14143. }
  14144. }
  14145. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14146. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14147. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14148. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14149. nullpo_retv( sd );
  14150. nullpo_retv( nd );
  14151. int fd = sd->fd;
  14152. if( !session_isActive( fd ) ){
  14153. return;
  14154. }
  14155. sd->npc_shopid = nd->bl.id;
  14156. int cost[2] = { 0, 0 };
  14157. npc_shop_currency_type( sd, nd, cost, true );
  14158. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14159. WFIFOHEAD( fd, len );
  14160. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14161. p->packetType = 0x287;
  14162. p->packetLength = len;
  14163. p->cashPoints = cost[0];
  14164. #if PACKETVER >= 20070711
  14165. p->kafraPoints = cost[1];
  14166. #endif
  14167. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14168. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14169. p->items[i].price = nd->u.shop.shop_item[i].value;
  14170. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14171. p->items[i].itemType = itemtype( id->nameid );
  14172. p->items[i].itemId = client_nameid( id->nameid );
  14173. }
  14174. WFIFOSET( fd, len );
  14175. }
  14176. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14177. /// 0289 <cash point>.L <error>.W
  14178. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14179. /// error:
  14180. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14181. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14182. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14183. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14184. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14185. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14186. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14187. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14188. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14189. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14190. {
  14191. int fd, cost[2] = { 0, 0 };
  14192. struct npc_data *nd;
  14193. nullpo_retv(sd);
  14194. fd = sd->fd;
  14195. nd = map_id2nd(sd->npc_shopid);
  14196. npc_shop_currency_type(sd, nd, cost, false);
  14197. WFIFOHEAD(fd, packet_len(0x289));
  14198. WFIFOW(fd,0) = 0x289;
  14199. WFIFOL(fd,2) = cost[0];
  14200. #if PACKETVER < 20070711
  14201. WFIFOW(fd,6) = TOW(error);
  14202. #else
  14203. WFIFOL(fd,6) = cost[1];
  14204. WFIFOW(fd,10) = TOW(error);
  14205. #endif
  14206. WFIFOSET(fd, packet_len(0x289));
  14207. }
  14208. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14209. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14210. nullpo_retv( sd );
  14211. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14212. packet.packetType = 0x849;
  14213. if( item_id != 0 ){
  14214. packet.itemId = client_nameid( item_id );
  14215. }else{
  14216. packet.itemId = 0;
  14217. }
  14218. packet.result = result;
  14219. packet.cashPoints = sd->cashPoints;
  14220. packet.kafraPoints = sd->kafraPoints;
  14221. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14222. #endif
  14223. }
  14224. /// Request to buy item(s) from cash shop.
  14225. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14226. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14227. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14228. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14229. nullpo_retv( sd );
  14230. if( sd->state.trading || !sd->npc_shopid ){
  14231. clif_cashshop_ack( sd, 1 );
  14232. return;
  14233. }
  14234. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14235. #if PACKETVER < 20070711
  14236. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14237. #elif PACKETVER < 20101116
  14238. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14239. #else
  14240. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14241. 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 ){
  14242. 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 );
  14243. return;
  14244. }
  14245. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, p->count, p->items ) );
  14246. #endif
  14247. }
  14248. /// Request to buy item(s) from cash shop.
  14249. /// 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)
  14250. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14251. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14252. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14253. 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 ){
  14254. 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 );
  14255. return;
  14256. }
  14257. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14258. }
  14259. /// Adoption System
  14260. ///
  14261. /// Adoption message (ZC_BABYMSG).
  14262. /// 0216 <msg>.L
  14263. /// msg:
  14264. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14265. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14266. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14267. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14268. {
  14269. int fd = sd->fd;
  14270. WFIFOHEAD(fd,6);
  14271. WFIFOW(fd,0) = 0x216;
  14272. WFIFOL(fd,2) = type;
  14273. WFIFOSET(fd,6);
  14274. }
  14275. /// Adoption confirmation (ZC_REQ_BABY).
  14276. /// 01f6 <account id>.L <char id>.L <name>.B
  14277. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14278. {
  14279. int fd = sd->fd;
  14280. WFIFOHEAD(fd,34);
  14281. WFIFOW(fd,0) = 0x1f6;
  14282. WFIFOL(fd,2) = src->status.account_id;
  14283. WFIFOL(fd,6) = p_id;
  14284. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14285. WFIFOSET(fd,34);
  14286. }
  14287. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14288. /// 01f9 <account id>.L
  14289. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14290. {
  14291. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14292. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14293. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14294. {
  14295. tsd->adopt_invite = sd->status.account_id;
  14296. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14297. }
  14298. }
  14299. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14300. /// 01f7 <account id>.L <char id>.L <answer>.L
  14301. /// answer:
  14302. /// 0 = rejected
  14303. /// 1 = accepted
  14304. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14305. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14306. int p1_id = RFIFOL(fd,info->pos[0]);
  14307. int p2_id = RFIFOL(fd,info->pos[1]);
  14308. int result = RFIFOL(fd,info->pos[2]);
  14309. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14310. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14311. int pid = sd->adopt_invite;
  14312. sd->adopt_invite = 0;
  14313. if( p1_sd == NULL || p2_sd == NULL )
  14314. return; // Both players need to be online
  14315. if( pid != p1_sd->status.account_id )
  14316. return; // Incorrect values
  14317. if( result == 0 )
  14318. return; // Rejected
  14319. pc_adoption(p1_sd, p2_sd, sd);
  14320. }
  14321. /// Convex Mirror (ZC_BOSS_INFO).
  14322. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14323. /// infoType:
  14324. /// BOSS_INFO_NOT = No boss on this map.
  14325. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14326. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14327. /// BOSS_INFO_DEAD = Boss is dead.
  14328. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14329. {
  14330. int fd = sd->fd;
  14331. WFIFOHEAD(fd,70);
  14332. memset(WFIFOP(fd,0),0,70);
  14333. WFIFOW(fd,0) = 0x293;
  14334. switch (flag) {
  14335. case BOSS_INFO_NOT:
  14336. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14337. // No data required
  14338. break;
  14339. case BOSS_INFO_ALIVE:
  14340. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14341. // Update X/Y
  14342. WFIFOL(fd,3) = md->bl.x;
  14343. WFIFOL(fd,7) = md->bl.y;
  14344. break;
  14345. case BOSS_INFO_ALIVE_WITHMSG:
  14346. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14347. // Current X/Y
  14348. WFIFOL(fd,3) = md->bl.x;
  14349. WFIFOL(fd,7) = md->bl.y;
  14350. break;
  14351. case BOSS_INFO_DEAD:
  14352. {
  14353. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14354. unsigned int seconds;
  14355. int hours, minutes;
  14356. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14357. hours = seconds / (60 * 60);
  14358. seconds = seconds - (60 * 60 * hours);
  14359. minutes = seconds / 60;
  14360. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14361. // Add respawn info
  14362. WFIFOW(fd,11) = hours; // Hours
  14363. WFIFOW(fd,13) = minutes; // Minutes
  14364. }
  14365. break;
  14366. }
  14367. if (md != NULL)
  14368. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14369. WFIFOSET(fd,70);
  14370. }
  14371. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14372. /// 02d6 <account id>.L
  14373. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14374. {
  14375. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14376. struct map_session_data* tsd = map_id2sd(aid);
  14377. if (!tsd)
  14378. return;
  14379. if (sd->bl.m != tsd->bl.m)
  14380. return;
  14381. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14382. clif_viewequip_ack(sd, tsd);
  14383. else
  14384. clif_msg(sd, VIEW_EQUIP_FAIL);
  14385. }
  14386. /// Request to a configuration.
  14387. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14388. /// type: see enum e_config_type
  14389. /// flag:
  14390. /// false = disabled
  14391. /// true = enabled
  14392. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14393. int cmd = RFIFOW(fd,0);
  14394. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14395. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14396. switch( type ){
  14397. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14398. sd->status.show_equip = flag;
  14399. break;
  14400. case CONFIG_PET_AUTOFEED:
  14401. // Player can not click this if he does not have a pet
  14402. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14403. return;
  14404. }
  14405. sd->pd->pet.autofeed = flag;
  14406. break;
  14407. case CONFIG_HOMUNCULUS_AUTOFEED:
  14408. // Player can not click this if he does not have a homunculus or it is vaporized
  14409. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14410. return;
  14411. }
  14412. sd->hd->homunculus.autofeed = flag;
  14413. break;
  14414. default:
  14415. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14416. return;
  14417. }
  14418. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14419. }
  14420. /// Request to change party invitation tick.
  14421. /// value:
  14422. /// 0 = disabled
  14423. /// 1 = enabled
  14424. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14425. {
  14426. bool flag = RFIFOB(fd,6) ? true : false;
  14427. sd->status.allow_party = flag;
  14428. clif_partytickack(sd, flag);
  14429. }
  14430. /// Questlog System [Kevin] [Inkfish]
  14431. ///
  14432. /**
  14433. * Safe check to init packet len & quest num for player.
  14434. * @param def_len
  14435. * @param info_len Length of each quest info.
  14436. * @param avail_quests Avail quests that player has.
  14437. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14438. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14439. **/
  14440. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14441. (*limit_out) = (0xFFFF - def_len) / info_len;
  14442. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14443. (*len_out) = ((*limit_out) * info_len) + def_len;
  14444. }
  14445. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14446. std::string race_name;
  14447. switch( objective->race ){
  14448. case RC_FORMLESS: race_name = "Formless"; break;
  14449. case RC_UNDEAD: race_name = "Undead"; break;
  14450. case RC_BRUTE: race_name = "Brute"; break;
  14451. case RC_PLANT: race_name = "Plant"; break;
  14452. case RC_INSECT: race_name = "Insect"; break;
  14453. case RC_FISH: race_name = "Fish"; break;
  14454. case RC_DEMON: race_name = "Demon"; break;
  14455. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14456. case RC_ANGEL: race_name = "Angel"; break;
  14457. case RC_DRAGON: race_name = "Dragon"; break;
  14458. default:
  14459. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14460. // Fallthrough
  14461. case RC_ALL: race_name = ""; break;
  14462. }
  14463. std::string size_name;
  14464. switch( objective->size ){
  14465. case SZ_SMALL: size_name = "Small"; break;
  14466. case SZ_MEDIUM: size_name = "Medium"; break;
  14467. case SZ_BIG: size_name = "Large"; break;
  14468. default:
  14469. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14470. // Fallthrough
  14471. case SZ_ALL: size_name = ""; break;
  14472. }
  14473. std::string ele_name;
  14474. switch( objective->element ){
  14475. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14476. case ELE_WATER: ele_name = "Water Element"; break;
  14477. case ELE_EARTH: ele_name = "Earth Element"; break;
  14478. case ELE_FIRE: ele_name = "Fire Element"; break;
  14479. case ELE_WIND: ele_name = "Wind Element"; break;
  14480. case ELE_POISON: ele_name = "Poison Element"; break;
  14481. case ELE_HOLY: ele_name = "Holy Element"; break;
  14482. case ELE_DARK: ele_name = "Shadow Element"; break;
  14483. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14484. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14485. default:
  14486. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14487. // Fallthrough
  14488. case ELE_ALL: ele_name = ""; break;
  14489. }
  14490. std::string str;
  14491. if( !objective->map_name.empty() ){
  14492. str += objective->map_name;
  14493. }
  14494. if( !race_name.empty() ){
  14495. if( !str.empty() ){
  14496. str += ", ";
  14497. }
  14498. str += race_name;
  14499. }
  14500. if( !size_name.empty() ){
  14501. if( !str.empty() ){
  14502. str += ", ";
  14503. }
  14504. str += size_name;
  14505. }
  14506. if( !ele_name.empty() ){
  14507. if( !str.empty() ){
  14508. str += ", ";
  14509. }
  14510. str += ele_name;
  14511. }
  14512. return str;
  14513. }
  14514. /// Sends list of all quest states
  14515. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14516. /// 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)
  14517. /// 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)
  14518. void clif_quest_send_list(struct map_session_data *sd)
  14519. {
  14520. nullpo_retv(sd);
  14521. int fd = sd->fd;
  14522. int i;
  14523. int offset = 8;
  14524. int limit = 0;
  14525. #if PACKETVER >= 20141022
  14526. #if PACKETVER >= 20150513
  14527. int size = 22 + NAME_LENGTH;
  14528. #else
  14529. int size = 10 + NAME_LENGTH;
  14530. #endif
  14531. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14532. WFIFOHEAD(fd,i);
  14533. #if PACKETVER >= 20150513
  14534. WFIFOW(fd, 0) = 0x9f8;
  14535. #else
  14536. WFIFOW(fd, 0) = 0x97a;
  14537. #endif
  14538. WFIFOL(fd, 4) = limit;
  14539. for (i = 0; i < limit; i++) {
  14540. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14541. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14542. offset += 4;
  14543. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14544. offset++;
  14545. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14546. offset += 4;
  14547. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14548. offset += 4;
  14549. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14550. offset += 2;
  14551. if (!qi->objectives.empty()) {
  14552. std::shared_ptr<s_mob_db> mob;
  14553. for (int j = 0; j < qi->objectives.size(); j++) {
  14554. mob = mob_db.find(qi->objectives[j]->mob_id);
  14555. e_race race = qi->objectives[j]->race;
  14556. e_size size = qi->objectives[j]->size;
  14557. e_element element = qi->objectives[j]->element;
  14558. #if PACKETVER >= 20150513
  14559. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14560. offset += 4;
  14561. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14562. offset += 4;
  14563. #endif
  14564. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14565. offset += 4;
  14566. #if PACKETVER >= 20150513
  14567. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14568. offset += 2;
  14569. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14570. offset += 2;
  14571. #endif
  14572. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14573. offset += 2;
  14574. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14575. offset += 2;
  14576. if (mob && qi->objectives[j]->mob_id > 0)
  14577. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14578. else
  14579. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14580. offset += NAME_LENGTH;
  14581. }
  14582. }
  14583. }
  14584. WFIFOW(fd, 2) = offset;
  14585. WFIFOSET(fd, offset);
  14586. #else
  14587. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14588. WFIFOHEAD(fd,i);
  14589. WFIFOW(fd, 0) = 0x2b1;
  14590. WFIFOL(fd, 4) = limit;
  14591. for (i = 0; i < limit; i++) {
  14592. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14593. offset += 4;
  14594. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14595. offset += 1;
  14596. }
  14597. WFIFOW(fd, 2) = offset;
  14598. WFIFOSET(fd, offset);
  14599. #endif
  14600. }
  14601. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14602. /// 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
  14603. void clif_quest_send_mission(struct map_session_data *sd)
  14604. {
  14605. nullpo_retv(sd);
  14606. int fd = sd->fd;
  14607. int limit = 0;
  14608. int len = sd->avail_quests*104+8;
  14609. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14610. WFIFOHEAD(fd, len);
  14611. WFIFOW(fd, 0) = 0x2b2;
  14612. WFIFOW(fd, 2) = len;
  14613. WFIFOL(fd, 4) = limit;
  14614. for (int i = 0; i < limit; i++) {
  14615. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14616. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14617. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14618. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14619. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14620. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14621. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14622. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14623. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14624. if (mob && qi->objectives[j]->mob_id > 0)
  14625. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14626. else
  14627. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14628. }
  14629. }
  14630. WFIFOSET(fd, len);
  14631. }
  14632. /// Notification about a new quest
  14633. /// 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)
  14634. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14635. /// 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)
  14636. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14637. {
  14638. nullpo_retv(sd);
  14639. nullpo_retv(qd);
  14640. int fd = sd->fd;
  14641. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14642. if (!qi)
  14643. return;
  14644. #if PACKETVER >= 20150513
  14645. int cmd = 0x9f9;
  14646. #else
  14647. int cmd = 0x2b3;
  14648. #endif
  14649. WFIFOHEAD(fd, packet_len(cmd));
  14650. WFIFOW(fd, 0) = cmd;
  14651. WFIFOL(fd, 2) = qd->quest_id;
  14652. WFIFOB(fd, 6) = qd->state;
  14653. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14654. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14655. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14656. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14657. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14658. e_race race = qi->objectives[i]->race;
  14659. e_size size = qi->objectives[i]->size;
  14660. e_element element = qi->objectives[i]->element;
  14661. #if PACKETVER >= 20150513
  14662. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14663. offset += 4;
  14664. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14665. offset += 4;
  14666. #endif
  14667. 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
  14668. offset += 4;
  14669. #if PACKETVER >= 20150513
  14670. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14671. offset += 2;
  14672. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14673. offset += 2;
  14674. #endif
  14675. WFIFOW(fd, offset) = qd->count[i];
  14676. offset += 2;
  14677. if (mob && qi->objectives[i]->mob_id > 0)
  14678. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14679. else
  14680. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14681. offset += NAME_LENGTH;
  14682. }
  14683. WFIFOSET(fd, packet_len(cmd));
  14684. #if PACKETVER >= 20150513
  14685. int len = 4 + qi->objectives.size() * 12;
  14686. WFIFOHEAD(fd, len);
  14687. WFIFOW(fd, 0) = 0x8fe;
  14688. WFIFOW(fd, 2) = len;
  14689. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14690. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14691. WFIFOL(fd, offset+4) = qi->objectives[i]->mob_id;
  14692. WFIFOW(fd, offset + 10) = qi->objectives[i]->count;
  14693. WFIFOW(fd, offset + 12) = qd->count[i];
  14694. }
  14695. WFIFOSET(fd, len);
  14696. #endif
  14697. }
  14698. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14699. /// 02b4 <quest id>.L
  14700. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14701. {
  14702. int fd = sd->fd;
  14703. WFIFOHEAD(fd, packet_len(0x2b4));
  14704. WFIFOW(fd, 0) = 0x2b4;
  14705. WFIFOL(fd, 2) = quest_id;
  14706. WFIFOSET(fd, packet_len(0x2b4));
  14707. }
  14708. /// Notification of an update to the hunting mission counter
  14709. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14710. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14711. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  14712. {
  14713. int fd = sd->fd;
  14714. int offset = 6;
  14715. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14716. int len = qi->objectives.size() * 12 + 6;
  14717. #if PACKETVER >= 20150513
  14718. int cmd = 0x9fa;
  14719. #else
  14720. int cmd = 0x2b5;
  14721. #endif
  14722. WFIFOHEAD(fd, len);
  14723. WFIFOW(fd, 0) = cmd;
  14724. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14725. for (int i = 0; i < qi->objectives.size(); i++) {
  14726. WFIFOL(fd, offset) = qd->quest_id;
  14727. offset += 4;
  14728. #if PACKETVER >= 20150513
  14729. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14730. offset += 4;
  14731. #else
  14732. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14733. offset += 4;
  14734. #endif
  14735. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14736. offset += 2;
  14737. WFIFOW(fd, offset) = qd->count[i];
  14738. offset += 2;
  14739. }
  14740. WFIFOW(fd, 2) = offset;
  14741. WFIFOSET(fd, offset);
  14742. }
  14743. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14744. /// 02b6 <quest id>.L <active>.B
  14745. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14746. {
  14747. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14748. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14749. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14750. }
  14751. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14752. /// 02b7 <quest id>.L <active>.B
  14753. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14754. {
  14755. int fd = sd->fd;
  14756. WFIFOHEAD(fd, packet_len(0x2b7));
  14757. WFIFOW(fd, 0) = 0x2b7;
  14758. WFIFOL(fd, 2) = quest_id;
  14759. WFIFOB(fd, 6) = active;
  14760. WFIFOSET(fd, packet_len(0x2b7));
  14761. }
  14762. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14763. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14764. /// effect:
  14765. /// 0 = none
  14766. /// 1 = exclamation mark icon
  14767. /// 2 = question mark icon
  14768. /// color:
  14769. /// 0 = yellow
  14770. /// 1 = orange
  14771. /// 2 = green
  14772. /// 3 = purple
  14773. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14774. {
  14775. #if PACKETVER >= 20090218
  14776. nullpo_retv(sd);
  14777. nullpo_retv(bl);
  14778. int fd = sd->fd;
  14779. WFIFOHEAD(fd, packet_len(0x446));
  14780. WFIFOW(fd, 0) = 0x446;
  14781. WFIFOL(fd, 2) = bl->id;
  14782. WFIFOW(fd, 6) = bl->x;
  14783. WFIFOW(fd, 8) = bl->y;
  14784. WFIFOW(fd, 10) = effect;
  14785. WFIFOW(fd, 12) = color;
  14786. WFIFOSET(fd, packet_len(0x446));
  14787. #endif
  14788. }
  14789. /// Mercenary System
  14790. ///
  14791. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14792. /// 02a2 <var id>.W <value>.L
  14793. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14794. {
  14795. struct mercenary_data *md;
  14796. struct status_data *status;
  14797. int fd;
  14798. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14799. return;
  14800. fd = sd->fd;
  14801. status = &md->battle_status;
  14802. WFIFOHEAD(fd,packet_len(0x2a2));
  14803. WFIFOW(fd,0) = 0x2a2;
  14804. WFIFOW(fd,2) = type;
  14805. switch( type ) {
  14806. case SP_ATK1:
  14807. {
  14808. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14809. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14810. }
  14811. break;
  14812. case SP_MATK1:
  14813. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14814. break;
  14815. case SP_HIT:
  14816. WFIFOL(fd,4) = status->hit;
  14817. break;
  14818. case SP_CRITICAL:
  14819. WFIFOL(fd,4) = status->cri/10;
  14820. break;
  14821. case SP_DEF1:
  14822. WFIFOL(fd,4) = status->def;
  14823. break;
  14824. case SP_MDEF1:
  14825. WFIFOL(fd,4) = status->mdef;
  14826. break;
  14827. case SP_MERCFLEE:
  14828. WFIFOL(fd,4) = status->flee;
  14829. break;
  14830. case SP_ASPD:
  14831. WFIFOL(fd,4) = status->amotion;
  14832. break;
  14833. case SP_HP:
  14834. WFIFOL(fd,4) = status->hp;
  14835. break;
  14836. case SP_MAXHP:
  14837. WFIFOL(fd,4) = status->max_hp;
  14838. break;
  14839. case SP_SP:
  14840. WFIFOL(fd,4) = status->sp;
  14841. break;
  14842. case SP_MAXSP:
  14843. WFIFOL(fd,4) = status->max_sp;
  14844. break;
  14845. case SP_MERCKILLS:
  14846. WFIFOL(fd,4) = md->mercenary.kill_count;
  14847. break;
  14848. case SP_MERCFAITH:
  14849. WFIFOL(fd,4) = mercenary_get_faith(md);
  14850. break;
  14851. }
  14852. WFIFOSET(fd,packet_len(0x2a2));
  14853. }
  14854. /// Mercenary base status data (ZC_MER_INIT).
  14855. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14856. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14857. /// <calls>.L <kills>.L <atk range>.W
  14858. void clif_mercenary_info(struct map_session_data *sd)
  14859. {
  14860. int fd;
  14861. struct mercenary_data *md;
  14862. struct status_data *status;
  14863. int atk;
  14864. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14865. return;
  14866. fd = sd->fd;
  14867. status = &md->battle_status;
  14868. WFIFOHEAD(fd,packet_len(0x29b));
  14869. WFIFOW(fd,0) = 0x29b;
  14870. WFIFOL(fd,2) = md->bl.id;
  14871. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14872. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14873. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14874. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14875. WFIFOW(fd,10) = status->hit;
  14876. WFIFOW(fd,12) = status->cri/10;
  14877. WFIFOW(fd,14) = status->def;
  14878. WFIFOW(fd,16) = status->mdef;
  14879. WFIFOW(fd,18) = status->flee;
  14880. WFIFOW(fd,20) = status->amotion;
  14881. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14882. WFIFOW(fd,46) = md->db->lv;
  14883. WFIFOL(fd,48) = status->hp;
  14884. WFIFOL(fd,52) = status->max_hp;
  14885. WFIFOL(fd,56) = status->sp;
  14886. WFIFOL(fd,60) = status->max_sp;
  14887. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14888. WFIFOW(fd,68) = mercenary_get_faith(md);
  14889. WFIFOL(fd,70) = mercenary_get_calls(md);
  14890. WFIFOL(fd,74) = md->mercenary.kill_count;
  14891. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14892. WFIFOSET(fd,packet_len(0x29b));
  14893. }
  14894. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14895. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14896. void clif_mercenary_skillblock(struct map_session_data *sd)
  14897. {
  14898. struct mercenary_data *md;
  14899. int fd, i, len = 4;
  14900. if( sd == NULL || (md = sd->md) == NULL )
  14901. return;
  14902. fd = sd->fd;
  14903. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14904. WFIFOW(fd,0) = 0x29d;
  14905. for( i = 0; i < MAX_MERCSKILL; i++ )
  14906. {
  14907. uint16 id;
  14908. short idx = -1;
  14909. if( (id = md->db->skill[i].id) == 0 )
  14910. continue;
  14911. if ((idx = mercenary_skill_get_index(id)) == -1)
  14912. continue;
  14913. WFIFOW(fd,len) = id;
  14914. WFIFOL(fd,len+2) = skill_get_inf(id);
  14915. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14916. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14917. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14918. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14919. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14920. len += 37;
  14921. }
  14922. WFIFOW(fd,2) = len;
  14923. WFIFOSET(fd,len);
  14924. }
  14925. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14926. /// 029f <command>.B
  14927. /// 1 = mercenary information
  14928. /// 2 = delete
  14929. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14930. {
  14931. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14932. if( sd->md == NULL )
  14933. return;
  14934. if( option == 2 ) mercenary_delete(sd->md, 2);
  14935. }
  14936. /// Mercenary Message
  14937. /// message:
  14938. /// 0 = Mercenary soldier's duty hour is over.
  14939. /// 1 = Your mercenary soldier has been killed.
  14940. /// 2 = Your mercenary soldier has been fired.
  14941. /// 3 = Your mercenary soldier has ran away.
  14942. void clif_mercenary_message(struct map_session_data* sd, int message){
  14943. clif_msg(sd, MERC_MSG_BASE + message);
  14944. }
  14945. /// Notification about the remaining time of a rental item.
  14946. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  14947. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  14948. // '<ItemName>' item will disappear in <seconds/60> minutes.
  14949. struct PACKET_ZC_CASH_TIME_COUNTER p;
  14950. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  14951. p.itemId = client_nameid( nameid );
  14952. p.seconds = seconds;
  14953. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14954. }
  14955. /// Deletes a rental item from client's inventory.
  14956. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  14957. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  14958. // '<ItemName>' item has been deleted from the Inventory
  14959. struct PACKET_ZC_CASH_ITEM_DELETE p;
  14960. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  14961. p.index = client_index( index );
  14962. p.itemId = client_nameid( nameid );
  14963. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14964. }
  14965. /// Book Reading (ZC_READ_BOOK).
  14966. /// 0294 <book id>.L <page>.L
  14967. void clif_readbook(int fd, int book_id, int page)
  14968. {
  14969. WFIFOHEAD(fd,packet_len(0x294));
  14970. WFIFOW(fd,0) = 0x294;
  14971. WFIFOL(fd,2) = book_id;
  14972. WFIFOL(fd,6) = page;
  14973. WFIFOSET(fd,packet_len(0x294));
  14974. }
  14975. /// Battlegrounds
  14976. ///
  14977. /// Updates HP bar of a camp member.
  14978. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14979. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14980. void clif_bg_hp(struct map_session_data *sd) {
  14981. #if PACKETVER < 20140613
  14982. unsigned char buf[34];
  14983. const int cmd = 0x2e0;
  14984. #else
  14985. unsigned char buf[14];
  14986. const int cmd = 0xa0e;
  14987. #endif
  14988. nullpo_retv(sd);
  14989. WBUFW(buf,0) = cmd;
  14990. WBUFL(buf,2) = sd->status.account_id;
  14991. #if PACKETVER < 20140613
  14992. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14993. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14994. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14995. WBUFW(buf,32) = 100;
  14996. } else {
  14997. WBUFW(buf,30) = sd->battle_status.hp;
  14998. WBUFW(buf,32) = sd->battle_status.max_hp;
  14999. }
  15000. #else
  15001. if( sd->battle_status.max_hp > INT32_MAX ) {
  15002. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15003. WBUFL(buf,10) = 100;
  15004. } else {
  15005. WBUFL(buf,6) = sd->battle_status.hp;
  15006. WBUFL(buf,10) = sd->battle_status.max_hp;
  15007. }
  15008. #endif
  15009. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15010. }
  15011. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15012. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15013. void clif_bg_xy(struct map_session_data *sd)
  15014. {
  15015. unsigned char buf[36];
  15016. nullpo_retv(sd);
  15017. WBUFW(buf,0)=0x2df;
  15018. WBUFL(buf,2)=sd->status.account_id;
  15019. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15020. WBUFW(buf,30)=sd->status.class_;
  15021. WBUFW(buf,32)=sd->bl.x;
  15022. WBUFW(buf,34)=sd->bl.y;
  15023. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15024. }
  15025. void clif_bg_xy_remove(struct map_session_data *sd)
  15026. {
  15027. unsigned char buf[36];
  15028. nullpo_retv(sd);
  15029. WBUFW(buf,0)=0x2df;
  15030. WBUFL(buf,2)=sd->status.account_id;
  15031. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15032. WBUFW(buf,30)=0;
  15033. WBUFW(buf,32)=-1;
  15034. WBUFW(buf,34)=-1;
  15035. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15036. }
  15037. /// Notifies clients of a battleground message.
  15038. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15039. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15040. struct map_session_data *sd = bg_getavailablesd( bg );
  15041. if( sd == nullptr ){
  15042. return;
  15043. }
  15044. // limit length
  15045. len = min( len + 1, CHAT_SIZE_MAX );
  15046. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15047. WBUFW(buf,0) = 0x2dc;
  15048. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15049. WBUFL(buf,4) = src_id;
  15050. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15051. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15052. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15053. }
  15054. /// Validates and processes battlechat messages.
  15055. /// All messages that are sent after enabling battleground chat with /battlechat.
  15056. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15057. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  15058. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15059. if( !clif_process_message( sd, false, name, message, output ) )
  15060. return;
  15061. bg_send_message(sd, output, strlen(output) );
  15062. }
  15063. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15064. /// 02de <camp A points>.W <camp B points>.W
  15065. void clif_bg_updatescore(int16 m)
  15066. {
  15067. struct block_list bl;
  15068. unsigned char buf[6];
  15069. struct map_data *mapdata = map_getmapdata(m);
  15070. bl.id = 0;
  15071. bl.type = BL_NUL;
  15072. bl.m = m;
  15073. WBUFW(buf,0) = 0x2de;
  15074. WBUFW(buf,2) = mapdata->bgscore_lion;
  15075. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15076. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15077. }
  15078. void clif_bg_updatescore_single(struct map_session_data *sd)
  15079. {
  15080. int fd;
  15081. nullpo_retv(sd);
  15082. fd = sd->fd;
  15083. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15084. WFIFOHEAD(fd,packet_len(0x2de));
  15085. WFIFOW(fd,0) = 0x2de;
  15086. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15087. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15088. WFIFOSET(fd,packet_len(0x2de));
  15089. }
  15090. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15091. /// 02dd <account id>.L <name>.24B <camp>.W
  15092. void clif_sendbgemblem_area(struct map_session_data *sd)
  15093. {
  15094. unsigned char buf[33];
  15095. nullpo_retv(sd);
  15096. WBUFW(buf, 0) = 0x2dd;
  15097. WBUFL(buf,2) = sd->bl.id;
  15098. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15099. WBUFW(buf,30) = sd->bg_id;
  15100. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15101. }
  15102. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15103. {
  15104. nullpo_retv(sd);
  15105. WFIFOHEAD(fd,32);
  15106. WFIFOW(fd,0) = 0x2dd;
  15107. WFIFOL(fd,2) = sd->bl.id;
  15108. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15109. WFIFOW(fd,30) = sd->bg_id;
  15110. WFIFOSET(fd,packet_len(0x2dd));
  15111. }
  15112. /// Battlegrounds queue incoming apply request from client.
  15113. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15114. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15115. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15116. {
  15117. if (!battle_config.feature_bgqueue)
  15118. return;
  15119. nullpo_retv(sd);
  15120. short type = RFIFOW(fd,2);
  15121. char name[NAME_LENGTH];
  15122. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15123. if (sd->bg_queue_id > 0) {
  15124. //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);
  15125. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15126. return;
  15127. } else if (type == 1) // Solo
  15128. bg_queue_join_solo(name, sd);
  15129. else if (type == 2) // Party
  15130. bg_queue_join_party(name, sd);
  15131. else if (type == 4) // Guild
  15132. bg_queue_join_guild(name, sd);
  15133. else {
  15134. 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);
  15135. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15136. return;
  15137. }
  15138. }
  15139. /// Outgoing battlegrounds queue apply result.
  15140. /// Result types: @see e_bg_queue_apply_ack
  15141. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15142. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15143. {
  15144. nullpo_retv(sd);
  15145. int fd = sd->fd;
  15146. WFIFOHEAD(fd, packet_len(0x8d8));
  15147. WFIFOW(fd,0) = 0x8d8;
  15148. WFIFOB(fd,2) = result;
  15149. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15150. WFIFOSET(fd, packet_len(0x8d8));
  15151. }
  15152. /// Outgoing battlegrounds queue apply notification.
  15153. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15154. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15155. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15156. {
  15157. nullpo_retv(sd);
  15158. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15159. if (queue == nullptr) {
  15160. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15161. return;
  15162. }
  15163. int fd = sd->fd;
  15164. WFIFOHEAD(fd, packet_len(0x8d9));
  15165. WFIFOW(fd,0) = 0x8d9;
  15166. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15167. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15168. WFIFOSET(fd, packet_len(0x8d9));
  15169. }
  15170. /// Battlegrounds queue outgoing cancel result.
  15171. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15172. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15173. {
  15174. nullpo_retv(sd);
  15175. int fd = sd->fd;
  15176. WFIFOHEAD(fd, packet_len(0x8d8));
  15177. WFIFOW(fd,0) = 0x8db;
  15178. WFIFOB(fd,2) = success;
  15179. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15180. WFIFOSET(fd, packet_len(0x8d8));
  15181. }
  15182. /// Battlegrounds queue incoming cancel request from client.
  15183. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15184. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15185. {
  15186. if (!battle_config.feature_bgqueue)
  15187. return;
  15188. nullpo_retv(sd);
  15189. bool success;
  15190. if (sd->bg_queue_id > 0) {
  15191. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15192. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15193. 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.
  15194. else
  15195. success = bg_queue_leave(sd);
  15196. } else {
  15197. 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);
  15198. success = false;
  15199. }
  15200. char name[NAME_LENGTH];
  15201. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15202. clif_bg_queue_cancel_result(success, name, sd);
  15203. }
  15204. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15205. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15206. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15207. {
  15208. nullpo_retv(sd);
  15209. int fd = sd->fd;
  15210. WFIFOHEAD(fd, packet_len(0x8df));
  15211. WFIFOW(fd,0) = 0x8df;
  15212. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15213. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15214. WFIFOSET(fd, packet_len(0x8df));
  15215. }
  15216. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15217. /// Result types: 1(Accept), 2(Decline).
  15218. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15219. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15220. {
  15221. nullpo_retv(sd);
  15222. if(sd->bg_queue_id > 0) {
  15223. uint8 result = RFIFOB(fd, 2);
  15224. if(result == 1) { // Accept
  15225. bg_queue_on_accept_invite(sd);
  15226. } else if(result == 2) { // Decline
  15227. bg_queue_leave(sd);
  15228. clif_bg_queue_entry_init(sd);
  15229. }
  15230. }
  15231. }
  15232. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15233. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15234. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15235. {
  15236. nullpo_retv(sd);
  15237. int fd = sd->fd;
  15238. WFIFOHEAD(fd, packet_len(0x8e1));
  15239. WFIFOW(fd,0) = 0x8e1;
  15240. WFIFOB(fd,2) = result;
  15241. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15242. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15243. WFIFOSET(fd, packet_len(0x8e1));
  15244. }
  15245. /// Battlegrounds queue incoming queue number request from client.
  15246. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15247. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15248. {
  15249. nullpo_retv(sd);
  15250. char name[NAME_LENGTH];
  15251. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15252. clif_bg_queue_apply_notify(name, sd);
  15253. }
  15254. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15255. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15256. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15257. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15258. {
  15259. nullpo_retv(sd);
  15260. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15261. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15262. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15263. }
  15264. /// Custom Fonts (ZC_NOTIFY_FONT).
  15265. /// 02ef <account_id>.L <font id>.W
  15266. void clif_font(struct map_session_data *sd)
  15267. {
  15268. #if PACKETVER >= 20080102
  15269. unsigned char buf[8];
  15270. nullpo_retv(sd);
  15271. WBUFW(buf,0) = 0x2ef;
  15272. WBUFL(buf,2) = sd->bl.id;
  15273. WBUFW(buf,6) = sd->status.font;
  15274. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15275. #endif
  15276. }
  15277. /// Required to start the instancing information window on Client
  15278. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15279. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15280. void clif_instance_create(int instance_id, int num)
  15281. {
  15282. #if PACKETVER >= 20071128
  15283. struct map_session_data *sd = NULL;
  15284. enum send_target target = PARTY;
  15285. unsigned char buf[65];
  15286. instance_getsd(instance_id, sd, &target);
  15287. if (!sd)
  15288. return;
  15289. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15290. if (!db)
  15291. return;
  15292. WBUFW(buf,0) = 0x2cb;
  15293. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15294. WBUFW(buf,63) = num;
  15295. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15296. #endif
  15297. return;
  15298. }
  15299. /// To announce Instancing queue creation if no maps available
  15300. /// S 0x2cc <Standby Position>.W
  15301. void clif_instance_changewait(int instance_id, int num)
  15302. {
  15303. #if PACKETVER >= 20071128
  15304. struct map_session_data *sd = NULL;
  15305. enum send_target target = PARTY;
  15306. unsigned char buf[4];
  15307. instance_getsd(instance_id, sd, &target);
  15308. if (!sd)
  15309. return;
  15310. WBUFW(buf,0) = 0x2cc;
  15311. WBUFW(buf,2) = num;
  15312. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15313. #endif
  15314. return;
  15315. }
  15316. /// Notify the current status to members
  15317. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15318. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15319. {
  15320. #if PACKETVER >= 20071128
  15321. struct map_session_data *sd = NULL;
  15322. enum send_target target = PARTY;
  15323. unsigned char buf[71];
  15324. instance_getsd(instance_id, sd, &target);
  15325. if (!sd)
  15326. return;
  15327. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15328. if (!db)
  15329. return;
  15330. WBUFW(buf,0) = 0x2cd;
  15331. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15332. WBUFL(buf,63) = limit1;
  15333. WBUFL(buf,67) = limit2;
  15334. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15335. #endif
  15336. return;
  15337. }
  15338. /// Notify a status change to members
  15339. /// S 0x2ce <Message ID>.L
  15340. /// 0 = Notification (EnterLimitDate update?)
  15341. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15342. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15343. /// 3 = The Memorial Dungeon has been removed.
  15344. /// 4 = Create failure (removes the instance window)
  15345. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15346. {
  15347. #if PACKETVER >= 20071128
  15348. struct map_session_data *sd = NULL;
  15349. enum send_target target = PARTY;
  15350. unsigned char buf[10];
  15351. instance_getsd(instance_id, sd, &target);
  15352. if (!sd)
  15353. return;
  15354. WBUFW(buf,0) = 0x2ce;
  15355. WBUFL(buf,2) = type;
  15356. WBUFL(buf,6) = limit;
  15357. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15358. #endif
  15359. return;
  15360. }
  15361. /// Destroy an instance from the status window
  15362. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15363. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15364. {
  15365. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15366. return;
  15367. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15368. switch (p->command) {
  15369. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15370. instance_destroy_command(sd);
  15371. break;
  15372. }
  15373. }
  15374. /// Notifies clients about item picked up by a party member.
  15375. /// 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)
  15376. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15377. #if PACKETVER >= 20071002
  15378. nullpo_retv( sd );
  15379. nullpo_retv( item_data );
  15380. struct item_data* id = itemdb_search( item_data->nameid );
  15381. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15382. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15383. p.AID = sd->status.account_id;
  15384. p.itemId = client_nameid( item_data->nameid );
  15385. p.identified = item_data->identify;
  15386. p.damaged = item_data->attribute;
  15387. p.refine = item_data->refine;
  15388. clif_addcards( &p.slot, item_data );
  15389. p.location = id->equip; // equip location
  15390. p.itemType = itemtype( id->nameid ); // item type
  15391. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15392. p.enchantgrade = item_data->enchantgrade;
  15393. #endif
  15394. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15395. #endif
  15396. }
  15397. /** Display gained exp.
  15398. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15399. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15400. * amount: INT32_MIN ~ INT32_MAX
  15401. * var id:
  15402. * SP_BASEEXP, SP_JOBEXP
  15403. * exp type:
  15404. * 0 = normal exp gained/lost
  15405. * 1 = quest exp gained/lost
  15406. * @param sd Player
  15407. * @param exp EXP value gained/loss
  15408. * @param type SP_BASEEXP, SP_JOBEXP
  15409. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15410. * @param lost True:if losing EXP
  15411. */
  15412. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15413. {
  15414. int fd;
  15415. int offset;
  15416. #if PACKETVER >= 20170830
  15417. int cmd = 0xacc;
  15418. #else
  15419. int cmd = 0x7f6;
  15420. #endif
  15421. nullpo_retv(sd);
  15422. fd = sd->fd;
  15423. WFIFOHEAD(fd, packet_len(cmd));
  15424. WFIFOW(fd,0) = cmd;
  15425. WFIFOL(fd,2) = sd->bl.id;
  15426. #if PACKETVER >= 20170830
  15427. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15428. offset = 4;
  15429. #else
  15430. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15431. offset = 0;
  15432. #endif
  15433. WFIFOW(fd,10+offset) = type;
  15434. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15435. WFIFOSET(fd,packet_len(cmd));
  15436. }
  15437. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15438. /// type:
  15439. /// 0 = Displays 'value' for 5 seconds.
  15440. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15441. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15442. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15443. /// value:
  15444. /// 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).
  15445. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15446. {
  15447. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15448. WFIFOW(sd->fd,0) = 0x1b1;
  15449. WFIFOB(sd->fd,2) = type;
  15450. WFIFOL(sd->fd,3) = value;
  15451. WFIFOSET(sd->fd, packet_len(0x1b1));
  15452. }
  15453. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15454. /// 021d <state>.L
  15455. /// state:
  15456. /// 0 = Full effects
  15457. /// 1 = Reduced effects
  15458. ///
  15459. /// NOTE: The state is used on Aegis for sending skill unit packet
  15460. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15461. /// whenever possible. Due to the way the decision check is
  15462. /// constructed, this state tracking was rendered useless,
  15463. /// as the only skill unit, that is sent with 0x1c9 is
  15464. /// Graffiti.
  15465. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15466. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15467. sd->state.lesseffect = ( isLess != 0 );
  15468. }
  15469. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15470. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15471. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15472. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15473. int type = RFIFOL(fd,info->pos[1]);
  15474. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15475. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15476. if( sd->state.trading || sd->npc_shopid )
  15477. return;
  15478. if( flag == 0 || n == 0) {
  15479. clif_menuskill_clear(sd);
  15480. return; // Canceled by player.
  15481. }
  15482. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15483. clif_menuskill_clear(sd);
  15484. return; // Prevent hacking.
  15485. }
  15486. switch( type ) {
  15487. case 0: // Change Material
  15488. skill_changematerial(sd,n,item_list);
  15489. break;
  15490. case 1: // Level 1: Pure to Rough
  15491. case 2: // Level 2: Rough to Pure
  15492. skill_elementalanalysis(sd,n,type,item_list);
  15493. break;
  15494. }
  15495. clif_menuskill_clear(sd);
  15496. return;
  15497. }
  15498. /*==========================================
  15499. * Elemental System
  15500. *==========================================*/
  15501. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15502. struct elemental_data *ed;
  15503. struct status_data *status;
  15504. int fd;
  15505. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15506. return;
  15507. fd = sd->fd;
  15508. status = &ed->battle_status;
  15509. WFIFOHEAD(fd,8);
  15510. WFIFOW(fd,0) = 0x81e;
  15511. WFIFOW(fd,2) = type;
  15512. switch( type ) {
  15513. case SP_HP:
  15514. WFIFOL(fd,4) = status->hp;
  15515. break;
  15516. case SP_MAXHP:
  15517. WFIFOL(fd,4) = status->max_hp;
  15518. break;
  15519. case SP_SP:
  15520. WFIFOL(fd,4) = status->sp;
  15521. break;
  15522. case SP_MAXSP:
  15523. WFIFOL(fd,4) = status->max_sp;
  15524. break;
  15525. }
  15526. WFIFOSET(fd,8);
  15527. }
  15528. void clif_elemental_info(struct map_session_data *sd) {
  15529. int fd;
  15530. struct elemental_data *ed;
  15531. struct status_data *status;
  15532. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15533. return;
  15534. fd = sd->fd;
  15535. status = &ed->battle_status;
  15536. WFIFOHEAD(fd,22);
  15537. WFIFOW(fd, 0) = 0x81d;
  15538. WFIFOL(fd, 2) = ed->bl.id;
  15539. WFIFOL(fd, 6) = status->hp;
  15540. WFIFOL(fd,10) = status->max_hp;
  15541. WFIFOL(fd,14) = status->sp;
  15542. WFIFOL(fd,18) = status->max_sp;
  15543. WFIFOSET(fd,22);
  15544. }
  15545. /// Buying Store System
  15546. ///
  15547. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15548. /// 0810 <slots>.B
  15549. void clif_buyingstore_open(struct map_session_data* sd)
  15550. {
  15551. int fd = sd->fd;
  15552. WFIFOHEAD(fd,packet_len(0x810));
  15553. WFIFOW(fd,0) = 0x810;
  15554. WFIFOB(fd,2) = sd->buyingstore.slots;
  15555. WFIFOSET(fd,packet_len(0x810));
  15556. }
  15557. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15558. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15559. /// result:
  15560. /// 0 = cancel
  15561. /// 1 = open
  15562. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15563. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15564. // TODO: Make this check global for all variable length packets.
  15565. // minimum packet length
  15566. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15567. 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 );
  15568. return;
  15569. }
  15570. char storename[MESSAGE_SIZE];
  15571. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15572. // so that buyingstore_create knows, how many elements it has access to
  15573. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15574. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15575. 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 ) );
  15576. return;
  15577. }
  15578. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15579. }
  15580. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15581. /// 0812 <result>.W <total weight>.L
  15582. /// result:
  15583. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15584. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15585. /// 8 = "No sale (purchase) information available." (0x705)
  15586. /// ? = nothing
  15587. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15588. {
  15589. int fd = sd->fd;
  15590. WFIFOHEAD(fd,packet_len(0x812));
  15591. WFIFOW(fd,0) = 0x812;
  15592. WFIFOW(fd,2) = result;
  15593. WFIFOL(fd,4) = weight;
  15594. WFIFOSET(fd,packet_len(0x812));
  15595. }
  15596. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15597. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15598. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15599. nullpo_retv( sd );
  15600. int fd = sd->fd;
  15601. if( !session_isActive( fd ) ){
  15602. return;
  15603. }
  15604. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15605. WFIFOHEAD( fd, length );
  15606. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15607. p->packetType = 0x813;
  15608. p->packetLength = length;
  15609. p->AID = sd->bl.id;
  15610. p->zenyLimit = sd->buyingstore.zenylimit;
  15611. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15612. p->items[i].price = sd->buyingstore.items[i].price;
  15613. p->items[i].amount = sd->buyingstore.items[i].amount;
  15614. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15615. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15616. }
  15617. WFIFOSET( fd, p->packetLength );
  15618. }
  15619. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15620. /// 0814 <account id>.L <store name>.80B
  15621. void clif_buyingstore_entry(struct map_session_data* sd)
  15622. {
  15623. uint8 buf[MESSAGE_SIZE+6];
  15624. WBUFW(buf,0) = 0x814;
  15625. WBUFL(buf,2) = sd->bl.id;
  15626. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15627. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15628. }
  15629. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15630. {
  15631. int fd = sd->fd;
  15632. WFIFOHEAD(fd,packet_len(0x814));
  15633. WFIFOW(fd,0) = 0x814;
  15634. WFIFOL(fd,2) = pl_sd->bl.id;
  15635. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15636. WFIFOSET(fd,packet_len(0x814));
  15637. }
  15638. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15639. /// 0815
  15640. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15641. {
  15642. buyingstore_close(sd);
  15643. }
  15644. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15645. /// 0816 <account id>.L
  15646. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15647. {
  15648. uint8 buf[6];
  15649. WBUFW(buf,0) = 0x816;
  15650. WBUFL(buf,2) = sd->bl.id;
  15651. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15652. }
  15653. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15654. {
  15655. int fd = sd->fd;
  15656. WFIFOHEAD(fd,packet_len(0x816));
  15657. WFIFOW(fd,0) = 0x816;
  15658. WFIFOL(fd,2) = pl_sd->bl.id;
  15659. WFIFOSET(fd,packet_len(0x816));
  15660. }
  15661. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15662. /// 0817 <account id>.L
  15663. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15664. {
  15665. uint32 account_id;
  15666. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15667. buyingstore_open(sd, account_id);
  15668. }
  15669. /// Sends buying store item list.
  15670. /// 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)
  15671. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15672. nullpo_retv( sd );
  15673. nullpo_retv( pl_sd );
  15674. int fd = sd->fd;
  15675. if( !session_isActive( fd ) ){
  15676. return;
  15677. }
  15678. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15679. WFIFOHEAD( fd, length );
  15680. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15681. p->packetType = 0x818;
  15682. p->packetLength = length;
  15683. p->AID = pl_sd->bl.id;
  15684. p->storeId = pl_sd->buyer_id;
  15685. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15686. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15687. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15688. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15689. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15690. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15691. }
  15692. WFIFOSET( fd, p->packetLength );
  15693. }
  15694. /// Request to sell items to a buying store.
  15695. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15696. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15697. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15698. // minimum packet length
  15699. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15700. 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 );
  15701. return;
  15702. }
  15703. // so that buyingstore_trade knows, how many elements it has access to
  15704. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15705. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15706. 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 ) );
  15707. return;
  15708. }
  15709. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15710. }
  15711. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15712. /// 081a <result>.W
  15713. /// result:
  15714. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15715. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15716. /// ? = nothing
  15717. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15718. {
  15719. int fd = sd->fd;
  15720. WFIFOHEAD(fd,packet_len(0x81a));
  15721. WFIFOW(fd,0) = 0x81a;
  15722. WFIFOW(fd,2) = result;
  15723. WFIFOSET(fd,packet_len(0x81a));
  15724. }
  15725. /// Updates the zeny limit and an item in the buying store item list.
  15726. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15727. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15728. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15729. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15730. p.packetType = buyingStoreUpdateItemType;
  15731. p.itemId = client_nameid( nameid );
  15732. p.amount = amount;
  15733. p.zenyLimit = sd->buyingstore.zenylimit;
  15734. #if PACKETVER >= 20141016
  15735. p.zeny = zeny;
  15736. p.charId = char_id; // GID
  15737. p.updateTime = (int)time(NULL);
  15738. #endif
  15739. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15740. }
  15741. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15742. /// 081c <index>.W <amount>.W <price>.L
  15743. /// message:
  15744. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15745. ///
  15746. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15747. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15748. {
  15749. int fd = sd->fd;
  15750. WFIFOHEAD(fd,packet_len(0x81c));
  15751. WFIFOW(fd,0) = 0x81c;
  15752. WFIFOW(fd,2) = client_index( index );
  15753. WFIFOW(fd,4) = amount;
  15754. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15755. WFIFOSET(fd,packet_len(0x81c));
  15756. }
  15757. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15758. /// 0824 <result>.W <name id>.W
  15759. /// result:
  15760. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15761. /// 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)
  15762. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15763. /// ? = nothing
  15764. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  15765. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15766. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15767. p.result = result;
  15768. p.itemId = client_nameid( nameid );
  15769. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15770. }
  15771. /// Search Store Info System
  15772. ///
  15773. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15774. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15775. /// type:
  15776. /// 0 = Vending
  15777. /// 1 = Buying Store
  15778. ///
  15779. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15780. /// amount of card slots. If the client does not know about the item it
  15781. /// cannot be searched.
  15782. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  15783. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15784. // minimum packet length
  15785. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15786. 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 );
  15787. return;
  15788. }
  15789. // check, if there is enough data for the claimed count of items
  15790. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15791. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15792. 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 ) );
  15793. return;
  15794. }
  15795. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15796. if( count < p->itemsCount + p->cardsCount ){
  15797. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15798. return;
  15799. }
  15800. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15801. }
  15802. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15803. /// 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 }*
  15804. /// is first page:
  15805. /// 0 = appends to existing results
  15806. /// 1 = clears previous results before displaying this result set
  15807. /// is next page:
  15808. /// 0 = no "next" label
  15809. /// 1 = "next" label to retrieve more results
  15810. void clif_search_store_info_ack( struct map_session_data* sd ){
  15811. nullpo_retv( sd );
  15812. int fd = sd->fd;
  15813. if( !session_isActive( fd ) ){
  15814. return;
  15815. }
  15816. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15817. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  15818. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15819. WFIFOHEAD( fd, len );
  15820. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15821. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15822. p->packetLength = len;
  15823. p->firstPage = !sd->searchstore.pages;
  15824. p->nextPage = searchstore_querynext( sd );
  15825. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15826. for( int i = 0; i < end - start; i++ ) {
  15827. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  15828. p->items[i].storeId = ssitem->store_id;
  15829. p->items[i].AID = ssitem->account_id;
  15830. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15831. p->items[i].itemId = client_nameid( ssitem->nameid );
  15832. p->items[i].itemType = itemtype( ssitem->nameid );
  15833. p->items[i].price = ssitem->price;
  15834. p->items[i].amount = ssitem->amount;
  15835. p->items[i].refine = ssitem->refine;
  15836. // make-up an item for clif_addcards
  15837. struct item it = {};
  15838. for( int j = 0; j < MAX_SLOTS; j++ ){
  15839. it.card[j] = ssitem->card[j];
  15840. }
  15841. it.nameid = ssitem->nameid;
  15842. it.amount = ssitem->amount;
  15843. clif_addcards( &p->items[i].slot, &it );
  15844. #if PACKETVER >= 20150226
  15845. clif_add_random_options( p->items[i].option_data, &it );
  15846. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15847. p->items[i].enchantgrade = ssitem->enchantgrade;
  15848. #endif
  15849. #endif
  15850. }
  15851. WFIFOSET( fd, len );
  15852. }
  15853. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15854. /// 0837 <reason>.B
  15855. /// reason:
  15856. /// 0 = "No matching stores were found." (0x70b)
  15857. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15858. /// 2 = "You cannot search anymore." (0x706)
  15859. /// 3 = "You cannot search yet." (0x708)
  15860. /// 4 = "No sale (purchase) information available." (0x705)
  15861. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15862. {
  15863. int fd = sd->fd;
  15864. WFIFOHEAD(fd,packet_len(0x837));
  15865. WFIFOW(fd,0) = 0x837;
  15866. WFIFOB(fd,2) = reason;
  15867. WFIFOSET(fd,packet_len(0x837));
  15868. }
  15869. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15870. /// 0838
  15871. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15872. {
  15873. searchstore_next(sd);
  15874. }
  15875. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15876. /// 083a <type>.W <remaining uses>.B
  15877. /// type:
  15878. /// 0 = Search Stores
  15879. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15880. void clif_open_search_store_info(struct map_session_data* sd)
  15881. {
  15882. int fd = sd->fd;
  15883. WFIFOHEAD(fd,packet_len(0x83a));
  15884. WFIFOW(fd,0) = 0x83a;
  15885. WFIFOW(fd,2) = sd->searchstore.effect;
  15886. #if PACKETVER > 20100701
  15887. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15888. #endif
  15889. WFIFOSET(fd,packet_len(0x83a));
  15890. }
  15891. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15892. /// 083b
  15893. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15894. {
  15895. searchstore_close(sd);
  15896. }
  15897. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15898. /// 083c <account id>.L <store id>.L <nameid>.W
  15899. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  15900. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  15901. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  15902. }
  15903. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15904. /// 083d <xPos>.W <yPos>.W
  15905. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15906. {
  15907. int fd = sd->fd;
  15908. WFIFOHEAD(fd,packet_len(0x83d));
  15909. WFIFOW(fd,0) = 0x83d;
  15910. WFIFOW(fd,2) = x;
  15911. WFIFOW(fd,4) = y;
  15912. WFIFOSET(fd,packet_len(0x83d));
  15913. }
  15914. /// Parse function for packet debugging.
  15915. void clif_parse_debug(int fd,struct map_session_data *sd)
  15916. {
  15917. int cmd, packet_len;
  15918. // clif_parse ensures, that there is at least 2 bytes of data
  15919. cmd = RFIFOW(fd,0);
  15920. if( sd ) {
  15921. packet_len = packet_db[cmd].len;
  15922. if( packet_len == 0 )
  15923. {// unknown
  15924. packet_len = RFIFOREST(fd);
  15925. }
  15926. else if( packet_len == -1 )
  15927. {// variable length
  15928. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15929. }
  15930. 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);
  15931. }
  15932. else
  15933. {
  15934. packet_len = RFIFOREST(fd);
  15935. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15936. }
  15937. ShowDump(RFIFOP(fd,0), packet_len);
  15938. }
  15939. /*==========================================
  15940. * Server tells client to display a window similar to Magnifier (item) one
  15941. * Server populates the window with avilable elemental converter options according to player's inventory
  15942. *------------------------------------------*/
  15943. void clif_elementalconverter_list( struct map_session_data *sd ){
  15944. nullpo_retv( sd );
  15945. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  15946. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15947. int count = 0;
  15948. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  15949. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  15950. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  15951. count++;
  15952. }
  15953. }
  15954. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15955. clif_send( p, p->packetLength, &sd->bl, SELF );
  15956. if( count > 0 ){
  15957. sd->menuskill_id = SA_CREATECON;
  15958. sd->menuskill_val = count;
  15959. }
  15960. }
  15961. /**
  15962. * Rune Knight
  15963. **/
  15964. void clif_millenniumshield(struct block_list *bl, short shields) {
  15965. #if PACKETVER >= 20081217
  15966. unsigned char buf[10];
  15967. WBUFW(buf,0) = 0x440;
  15968. WBUFL(buf,2) = bl->id;
  15969. WBUFW(buf,6) = shields;
  15970. WBUFW(buf,8) = 0;
  15971. clif_send(buf,packet_len(0x440),bl,AREA);
  15972. #endif
  15973. }
  15974. /**
  15975. * Mechanic
  15976. **/
  15977. /*==========================================
  15978. * Magic Decoy Material List
  15979. *------------------------------------------*/
  15980. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  15981. nullpo_retv( sd );
  15982. int fd = sd->fd;
  15983. if( !session_isActive( fd ) ){
  15984. return;
  15985. }
  15986. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15987. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  15988. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15989. int count = 0;
  15990. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15991. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  15992. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15993. count++;
  15994. }
  15995. }
  15996. if( count > 0 ) {
  15997. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15998. WFIFOSET( fd, p->packetLength );
  15999. sd->menuskill_id = NC_MAGICDECOY;
  16000. sd->menuskill_val = skill_lv;
  16001. sd->sc.comet_x = x;
  16002. sd->sc.comet_y = y;
  16003. }else{
  16004. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16005. }
  16006. }
  16007. /*==========================================
  16008. * Guillotine Cross Poisons List
  16009. *------------------------------------------*/
  16010. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16011. nullpo_retv( sd );
  16012. int fd = sd->fd;
  16013. if( !session_isActive( fd ) ){
  16014. return;
  16015. }
  16016. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16017. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16018. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16019. int count = 0;
  16020. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16021. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16022. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16023. count++;
  16024. }
  16025. }
  16026. if( count > 0 ){
  16027. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16028. WFIFOSET( fd, p->packetLength );
  16029. sd->menuskill_id = GC_POISONINGWEAPON;
  16030. sd->menuskill_val = skill_lv;
  16031. }else{
  16032. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16033. }
  16034. }
  16035. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16036. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16037. int fd, i, c;
  16038. nullpo_ret(sd);
  16039. fd = sd->fd;
  16040. if( !session_isActive(fd) )
  16041. return 0;
  16042. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16043. return 0;
  16044. WFIFOHEAD(fd, 2 * 6 + 4);
  16045. WFIFOW(fd,0) = 0x442;
  16046. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16047. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16048. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16049. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16050. {
  16051. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16052. c++;
  16053. }
  16054. if( c > 0 ) {
  16055. WFIFOW(fd,2) = 8 + c * 2;
  16056. WFIFOL(fd,4) = c;
  16057. WFIFOSET(fd,WFIFOW(fd,2));
  16058. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16059. sd->menuskill_val = c;
  16060. } else {
  16061. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  16062. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16063. }
  16064. return 1;
  16065. }
  16066. /*===========================================
  16067. * Skill list for Four Elemental Analysis
  16068. * and Change Material skills.
  16069. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16070. *------------------------------------------*/
  16071. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16072. #if PACKETVER >= 20090922
  16073. int fd = sd->fd;
  16074. nullpo_ret(sd);
  16075. sd->menuskill_id = skill_id; // To prevent hacking.
  16076. sd->menuskill_val = skill_lv;
  16077. if( skill_id == GN_CHANGEMATERIAL )
  16078. skill_lv = 0; // Changematerial
  16079. WFIFOHEAD(fd, packet_len(0x7e3));
  16080. WFIFOW(fd,0) = 0x7e3;
  16081. WFIFOL(fd,2) = skill_lv;
  16082. WFIFOL(fd,4) = 0;
  16083. WFIFOSET(fd, packet_len(0x7e3));
  16084. #endif
  16085. return 1;
  16086. }
  16087. /*==========================================
  16088. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16089. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16090. * RFIFOL(fd,2) - type (currently not used)
  16091. *------------------------------------------*/
  16092. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16093. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16094. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16095. if (sd->menuskill_id == SA_AUTOSPELL) {
  16096. sd->state.workinprogress = WIP_DISABLE_NONE;
  16097. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16098. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16099. if (pc_istrading(sd)) {
  16100. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16101. clif_menuskill_clear(sd);
  16102. return;
  16103. }
  16104. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16105. } else
  16106. return;
  16107. clif_menuskill_clear(sd);
  16108. }
  16109. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16110. /// 08cf <id>.L <type>.W <num>.W
  16111. void clif_spiritcharm(struct map_session_data *sd) {
  16112. unsigned char buf[10];
  16113. nullpo_retv(sd);
  16114. WBUFW(buf,0) = 0x08cf;
  16115. WBUFL(buf,2) = sd->bl.id;
  16116. WBUFW(buf,6) = sd->spiritcharm_type;
  16117. WBUFW(buf,8) = sd->spiritcharm;
  16118. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16119. }
  16120. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16121. /// 0907 <index>.W
  16122. ///
  16123. /// R 0908 <index>.w <type>.b
  16124. /// type:
  16125. /// 0 = move item to personal tab
  16126. /// 1 = move item to normal tab
  16127. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16128. #if PACKETVER >= 20111122
  16129. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16130. int index = RFIFOW(fd,info->pos[0]) - 2;
  16131. int type = RFIFOB(fd, info->pos[1]);
  16132. /* can't move while dead. */
  16133. if(pc_isdead(sd)) {
  16134. return;
  16135. }
  16136. if (index < 0 || index >= MAX_INVENTORY)
  16137. return;
  16138. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16139. sd->inventory.u.items_inventory[index].favorite = 0;
  16140. else if( type == 0 )
  16141. sd->inventory.u.items_inventory[index].favorite = 1;
  16142. else
  16143. return;/* nothing to do. */
  16144. clif_favorite_item(sd, index);
  16145. #endif
  16146. }
  16147. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16148. /// 0900 <index>.W <favorite>.B
  16149. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16150. int fd = sd->fd;
  16151. WFIFOHEAD(fd,packet_len(0x908));
  16152. WFIFOW(fd,0) = 0x908;
  16153. WFIFOW(fd,2) = index+2;
  16154. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16155. WFIFOSET(fd,packet_len(0x908));
  16156. }
  16157. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16158. void clif_snap( struct block_list *bl, short x, short y ) {
  16159. unsigned char buf[10];
  16160. WBUFW(buf,0) = 0x8d2;
  16161. WBUFL(buf,2) = bl->id;
  16162. WBUFW(buf,6) = x;
  16163. WBUFW(buf,8) = y;
  16164. if( disguised(bl) )
  16165. {
  16166. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16167. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16168. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16169. } else
  16170. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16171. }
  16172. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16173. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16174. #if PACKETVER >= 20120404
  16175. WFIFOHEAD(fd,packet_len(0x977));
  16176. WFIFOW(fd,0) = 0x977;
  16177. WFIFOL(fd,2) = md->bl.id;
  16178. WFIFOL(fd,6) = md->status.hp;
  16179. WFIFOL(fd,10) = md->status.max_hp;
  16180. WFIFOSET(fd,packet_len(0x977));
  16181. #endif
  16182. }
  16183. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16184. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16185. return;
  16186. }
  16187. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16188. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16189. WFIFOW(sd->fd,0) = 0x2c9;
  16190. WFIFOB(sd->fd,2) = flag;
  16191. WFIFOSET(sd->fd, packet_len(0x2c9));
  16192. }
  16193. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16194. /// 0979 <world name>.24B <char name>.24B
  16195. void clif_ackworldinfo(struct map_session_data* sd) {
  16196. int fd;
  16197. nullpo_retv(sd);
  16198. fd = sd->fd;
  16199. WFIFOHEAD(fd,packet_len(0x979));
  16200. WFIFOW(fd,0)=0x979;
  16201. //AID -> world name ?
  16202. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16203. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16204. WFIFOSET(fd,packet_len(0x979));
  16205. }
  16206. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16207. /// 0978 <AID>.L
  16208. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16209. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16210. if(sd)
  16211. clif_ackworldinfo(sd);
  16212. }
  16213. static void clif_loadConfirm( struct map_session_data *sd ){
  16214. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16215. nullpo_retv( sd );
  16216. struct PACKET_ZC_LOAD_CONFIRM p;
  16217. p.packetType = HEADER_ZC_LOAD_CONFIRM;
  16218. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16219. if (sd->instance_id > 0)
  16220. instance_reqinfo(sd, sd->instance_id);
  16221. if (sd->status.party_id > 0)
  16222. party_member_joined(sd);
  16223. if (sd->status.guild_id > 0)
  16224. guild_member_joined(sd);
  16225. if (sd->status.clan_id > 0)
  16226. clan_member_joined(sd);
  16227. #endif
  16228. }
  16229. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16230. /// 0447
  16231. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16232. clif_loadConfirm( sd );
  16233. }
  16234. /// req world info (CZ_CLIENT_VERSION)
  16235. /// 044A <version>.L
  16236. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16237. //if(sd)
  16238. ;
  16239. }
  16240. /// Ranking list
  16241. /// ranking pointlist { <name>.24B <point>.L }*10
  16242. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16243. struct fame_list* list;
  16244. int i, size = MAX_FAME_LIST;
  16245. switch(rankingtype) {
  16246. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16247. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16248. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16249. // PK currently unsupported
  16250. case RANK_KILLER: list = NULL; size = 0; break;
  16251. default:
  16252. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16253. return;
  16254. }
  16255. //Packet size limits this list to 10 elements. [Skotlex]
  16256. for (i = 0; i < min(10,size); i++) {
  16257. if (list[i].id > 0) {
  16258. const char* name;
  16259. if (strcmp(list[i].name, "-") == 0 &&
  16260. (name = map_charid2nick(list[i].id)) != NULL)
  16261. {
  16262. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16263. } else {
  16264. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16265. }
  16266. } else {
  16267. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16268. }
  16269. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16270. }
  16271. for(;i < 10; i++) { //In case the MAX is less than 10.
  16272. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16273. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16274. }
  16275. }
  16276. /// Request for the blacksmith ranklist.
  16277. /// /blacksmith command sends this packet to the server.
  16278. /// 0217 (CZ_BLACKSMITH_RANK)
  16279. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16280. clif_ranklist(sd,RANK_BLACKSMITH);
  16281. }
  16282. /// Request for the alchemist ranklist.
  16283. /// /alchemist command sends this packet to the server.
  16284. /// 0218 (CZ_ALCHEMIST_RANK)
  16285. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16286. clif_ranklist(sd,RANK_ALCHEMIST);
  16287. }
  16288. /// Request for the taekwon ranklist.
  16289. /// /taekwon command sends this packet to the server.
  16290. /// 0225 (CZ_TAEKWON_RANK)
  16291. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16292. clif_ranklist(sd,RANK_TAEKWON);
  16293. }
  16294. /// Request for the killer ranklist.
  16295. /// /pk command sends this packet to the server.
  16296. /// 0237 (CZ_KILLER_RANK)
  16297. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16298. clif_ranklist(sd,RANK_KILLER);
  16299. }
  16300. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16301. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16302. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16303. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16304. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16305. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16306. enum e_rank rank;
  16307. #if PACKETVER < 20130710
  16308. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16309. short cmd;
  16310. switch( rankingType ){
  16311. case RANK_BLACKSMITH: cmd = 0x219; break;
  16312. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16313. case RANK_TAEKWON: cmd = 0x226; break;
  16314. case RANK_KILLER: cmd = 0x238; break;
  16315. default:
  16316. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16317. return;
  16318. }
  16319. // Can be safely casted here, since we validated it before
  16320. rank = (enum e_rank)rankingType;
  16321. WBUFW(buf,0) = cmd;
  16322. clif_sub_ranklist(buf,2,sd,rank);
  16323. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16324. #else
  16325. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16326. int mypoint = 0;
  16327. switch( rankingType ){
  16328. case RANK_BLACKSMITH:
  16329. case RANK_ALCHEMIST:
  16330. case RANK_TAEKWON:
  16331. case RANK_KILLER:
  16332. break;
  16333. default:
  16334. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16335. return;
  16336. }
  16337. // Can be safely casted here, since we validated it before
  16338. rank = (enum e_rank)rankingType;
  16339. WBUFW(buf,0) = 0x97d;
  16340. WBUFW(buf,2) = rank;
  16341. clif_sub_ranklist(buf,4,sd,rank);
  16342. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16343. case MAPID_BLACKSMITH:
  16344. case MAPID_ALCHEMIST:
  16345. case MAPID_TAEKWON:
  16346. mypoint = sd->status.fame;
  16347. }
  16348. WBUFL(buf,284) = mypoint; //mypoint
  16349. clif_send(buf, 288, &sd->bl, SELF);
  16350. #endif
  16351. }
  16352. /*
  16353. * 097c <type> (CZ_REQ_RANKING)
  16354. * type
  16355. * 0: /blacksmith
  16356. * 1: /alchemist
  16357. * 2: /taekwon
  16358. * 3: /pk
  16359. * */
  16360. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16361. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16362. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16363. clif_ranklist(sd,rankingtype);
  16364. }
  16365. /// Updates the fame rank points for the given ranking.
  16366. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16367. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16368. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16369. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16370. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  16371. int fd=sd->fd;
  16372. #if PACKETVER < 20130710
  16373. short cmd;
  16374. switch(rankingtype){
  16375. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16376. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16377. case RANK_TAEKWON: cmd = 0x224; break;
  16378. default:
  16379. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16380. return;
  16381. }
  16382. WFIFOHEAD(fd,packet_len(cmd));
  16383. WFIFOW(fd,0) = cmd;
  16384. WFIFOL(fd,2) = point;
  16385. WFIFOL(fd,6) = sd->status.fame;
  16386. WFIFOSET(fd, packet_len(cmd));
  16387. #else
  16388. WFIFOHEAD(fd,packet_len(0x97e));
  16389. WFIFOW(fd,0) = 0x97e;
  16390. WFIFOW(fd,2) = rankingtype;
  16391. WFIFOL(fd,4) = point;
  16392. WFIFOL(fd,8) = sd->status.fame;
  16393. WFIFOSET(fd,packet_len(0x97e));
  16394. #endif
  16395. }
  16396. /**
  16397. * Transmit personal information to player. (rates)
  16398. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16399. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16400. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16401. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16402. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16403. * FIXME!
  16404. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16405. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16406. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16407. */
  16408. #ifdef VIP_ENABLE
  16409. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16410. if (sd) {
  16411. struct s_packet_db* info;
  16412. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16413. int cmd = 0, fd, i = 0;
  16414. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16415. int details_bexp[PINFO_MAX];
  16416. int details_drop[PINFO_MAX];
  16417. int details_penalty[PINFO_MAX];
  16418. /**
  16419. * Set for EXP
  16420. */
  16421. //0:PCRoom
  16422. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16423. if (details_bexp[0] == 100 || !details_bexp[0])
  16424. details_bexp[0] = 0;
  16425. else {
  16426. if (details_bexp[0] < 100) {
  16427. details_bexp[0] = 100 - details_bexp[0];
  16428. details_bexp[0] = 0 - details_bexp[0];
  16429. }
  16430. else
  16431. details_bexp[0] = details_bexp[0] - 100;
  16432. }
  16433. //1:Premium
  16434. if (pc_isvip(sd)) {
  16435. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16436. if (details_bexp[1] < 0)
  16437. details_bexp[1] = 0 - details_bexp[1];
  16438. }
  16439. else
  16440. details_bexp[1] = 0;
  16441. //2:Server
  16442. details_bexp[2] = battle_config.base_exp_rate;
  16443. if (details_bexp[2] == 100)
  16444. details_bexp[2] = 0;
  16445. else {
  16446. if (details_bexp[2] < 100) {
  16447. details_bexp[2] = 100 - details_bexp[2];
  16448. details_bexp[2] = 0 - details_bexp[2];
  16449. }
  16450. else
  16451. details_bexp[2] = details_bexp[2] - 100;
  16452. }
  16453. //3:TPLUS
  16454. details_bexp[3] = 0;
  16455. /* End - EXP set*/
  16456. /**
  16457. * Set for Drop rate
  16458. */
  16459. //0:PCRoom
  16460. details_drop[0] = 0;
  16461. //1:Premium
  16462. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16463. if (pc_isvip(sd)) {
  16464. if (details_drop[1] < 0)
  16465. details_drop[1] = 0 - details_drop[1];
  16466. }
  16467. else
  16468. details_drop[1] = 0;
  16469. //2:Server
  16470. details_drop[2] = battle_config.item_rate_common;
  16471. if (details_drop[2] == 100)
  16472. details_drop[2] = 0;
  16473. else {
  16474. if (details_drop[2] < 100) {
  16475. details_drop[2] = 100 - details_drop[2];
  16476. details_drop[2] = 0 - details_drop[2];
  16477. }
  16478. else
  16479. details_drop[2] = details_drop[2] - 100;
  16480. }
  16481. //3:TPLUS
  16482. details_drop[3] = 0;
  16483. /* End - Drop set*/
  16484. /**
  16485. * Set for Penalty rate
  16486. */
  16487. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16488. //0:PCRoom
  16489. details_penalty[0] = 0;
  16490. //1:Premium
  16491. if (pc_isvip(sd)) {
  16492. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16493. if (details_penalty[1] == 100)
  16494. details_penalty[1] = 0;
  16495. else {
  16496. if (details_penalty[1] < 100) {
  16497. details_penalty[1] = 100 - details_penalty[1];
  16498. details_penalty[1] = 0 - details_penalty[1];
  16499. }
  16500. else
  16501. details_penalty[1] = details_penalty[1] - 100;
  16502. }
  16503. }
  16504. else
  16505. details_penalty[1] = 0;
  16506. //2:Server
  16507. details_penalty[2] = battle_config.death_penalty_base;
  16508. if (details_penalty[2] == 100)
  16509. details_penalty[2] = 0;
  16510. else {
  16511. if (details_penalty[2] < 100) {
  16512. details_penalty[2] = 100 - details_penalty[2];
  16513. details_penalty[2] = 0 - details_penalty[2];
  16514. }
  16515. else
  16516. details_penalty[2] = details_penalty[2] - 100;
  16517. }
  16518. //3:TPLUS
  16519. details_penalty[3] = 0;
  16520. /* End - Penalty set*/
  16521. cmd = packet_db_ack[cmdtype];
  16522. info = &packet_db[cmd];
  16523. len = info->len; //this is the base len without details
  16524. if(!len) return; //version as packet disable
  16525. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16526. szdetails = 7;
  16527. factor = 1;
  16528. }
  16529. else if (cmd == 0x097b) {
  16530. tot_baseexp *= factor;
  16531. tot_drop *= factor;
  16532. tot_penalty *= factor;
  16533. }
  16534. fd = sd->fd;
  16535. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16536. WFIFOW(fd,0) = cmd;
  16537. for (i = 0; i < maxinfotype; i++) {
  16538. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16539. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16540. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16541. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16542. tot_baseexp += details_bexp[i]*factor;
  16543. tot_drop += details_penalty[i]*factor;
  16544. tot_penalty += details_drop[i]*factor;
  16545. len += szdetails;
  16546. }
  16547. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16548. if (cmd == 0x08cb) { //0x08cb version
  16549. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16550. WFIFOW(fd,info->pos[2]) = tot_drop;
  16551. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16552. }
  16553. else { //2013-08-07aRagexe uses 0x097b
  16554. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16555. WFIFOL(fd,info->pos[2]) = tot_drop;
  16556. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16557. }
  16558. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16559. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16560. WFIFOSET(fd,len);
  16561. }
  16562. }
  16563. #endif
  16564. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16565. char cmd[30];
  16566. int t_aid = RFIFOL(fd,2);
  16567. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16568. is_atcommand(fd, sd, cmd, 1);
  16569. }
  16570. /**
  16571. * Marks Crimson Marker target on mini-map to the caster
  16572. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16573. * @param fd
  16574. * @param bl Crimson Marker target
  16575. **/
  16576. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16577. struct s_packet_db* info;
  16578. int cmd = 0;
  16579. int16 len;
  16580. unsigned char buf[11];
  16581. nullpo_retv(sd);
  16582. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16583. if (!cmd)
  16584. cmd = 0x09C1; //default
  16585. info = &packet_db[cmd];
  16586. if (!(len = info->len))
  16587. return;
  16588. WBUFW(buf, 0) = cmd;
  16589. WBUFL(buf, info->pos[0]) = bl->id;
  16590. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16591. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16592. clif_send(buf, len, &sd->bl, SELF);
  16593. }
  16594. /**
  16595. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16596. **/
  16597. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16598. struct s_packet_db *info = NULL;
  16599. int cmd = 0;
  16600. nullpo_retv(sd);
  16601. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16602. info = &packet_db[cmd];
  16603. if (!cmd || !info->len)
  16604. return;
  16605. WFIFOHEAD(sd->fd, info->len);
  16606. WFIFOW(sd->fd, 0) = cmd;
  16607. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16608. WFIFOSET(sd->fd, info->len);
  16609. }
  16610. /**
  16611. * [Ind/Hercules]
  16612. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16613. **/
  16614. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16615. char buf[256];
  16616. size_t len;
  16617. nullpo_retv(bl);
  16618. if(!message)
  16619. return;
  16620. len = strlen(message)+1;
  16621. if( len > sizeof(buf)-8 ) {
  16622. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16623. len = sizeof(buf)-8;
  16624. }
  16625. WBUFW(buf,0) = 0x8b3;
  16626. WBUFW(buf,2) = (uint16)(len+8);
  16627. WBUFL(buf,4) = bl->id;
  16628. safestrncpy(WBUFCP(buf,8), message, len);
  16629. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16630. }
  16631. /**
  16632. * [Ind/Hercules]
  16633. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16634. **/
  16635. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16636. unsigned char buf[10];
  16637. nullpo_retv(sd);
  16638. WBUFW(buf,0) = 0x7fc;
  16639. WBUFL(buf,2) = prev_leader_aid;
  16640. WBUFL(buf,6) = new_leader_aid;
  16641. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16642. }
  16643. /**
  16644. * Sends a clan message to a player
  16645. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16646. **/
  16647. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16648. #if PACKETVER >= 20131223
  16649. struct map_session_data *sd;
  16650. uint8 buf[256];
  16651. if( len == 0 ){
  16652. return;
  16653. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16654. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16655. len = sizeof(buf)-5-NAME_LENGTH;
  16656. }
  16657. WBUFW(buf, 0) = 0x98e;
  16658. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16659. // 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
  16660. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16661. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16662. if((sd = clan_getavailablesd(clan)) != NULL)
  16663. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16664. #endif
  16665. }
  16666. /**
  16667. * Parses a clan message from a player.
  16668. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16669. **/
  16670. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16671. #if PACKETVER >= 20131223
  16672. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16673. // validate packet and retrieve name and message
  16674. if( !clif_process_message(sd, false, name, message, output ) )
  16675. return;
  16676. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16677. #endif
  16678. }
  16679. /**
  16680. * Sends the basic clan informations to the client.
  16681. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16682. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16683. **/
  16684. void clif_clan_basicinfo( struct map_session_data *sd ){
  16685. #if PACKETVER >= 20131223
  16686. int fd, offset, length, i, flag;
  16687. struct clan* clan;
  16688. char mapname[MAP_NAME_LENGTH_EXT];
  16689. nullpo_retv( sd );
  16690. nullpo_retv( clan = sd->clan );
  16691. // Check if the player has a valid session and is not autotrading
  16692. if( !clif_session_isValid( sd ) ){
  16693. return;
  16694. }
  16695. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16696. fd = sd->fd;
  16697. WFIFOHEAD(fd,length);
  16698. memset( WFIFOP(fd, 0), 0, length );
  16699. WFIFOW( fd, 0 ) = 0x98a;
  16700. WFIFOL( fd, 4 ) = clan->id;
  16701. offset = 8;
  16702. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16703. offset += NAME_LENGTH;
  16704. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16705. offset += NAME_LENGTH;
  16706. mapindex_getmapname_ext( clan->map, mapname );
  16707. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16708. offset += MAP_NAME_LENGTH_EXT;
  16709. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16710. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16711. for( flag = 0; flag < 2; flag++ ){
  16712. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16713. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16714. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16715. offset += NAME_LENGTH;
  16716. }
  16717. }
  16718. }
  16719. WFIFOW( fd, 2 ) = offset;
  16720. WFIFOSET(fd,offset);
  16721. #endif
  16722. }
  16723. /**
  16724. * Updates the online and maximum player count of a clan.
  16725. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16726. **/
  16727. void clif_clan_onlinecount( struct clan* clan ){
  16728. #if PACKETVER >= 20131223
  16729. uint8 buf[6];
  16730. struct map_session_data *sd;
  16731. WBUFW(buf,0) = 0x988;
  16732. WBUFW(buf,2) = clan->connect_member;
  16733. WBUFW(buf,4) = clan->max_member;
  16734. if((sd = clan_getavailablesd(clan)) != NULL)
  16735. clif_send(buf, 6, &sd->bl, CLAN);
  16736. #endif
  16737. }
  16738. /**
  16739. * Notifies the client that the player has left his clan.
  16740. * 0989 (ZC_ACK_CLAN_LEAVE)
  16741. **/
  16742. void clif_clan_leave( struct map_session_data* sd ){
  16743. #if PACKETVER >= 20131223
  16744. int fd;
  16745. nullpo_retv( sd );
  16746. if( !clif_session_isValid( sd ) ){
  16747. return;
  16748. }
  16749. fd = sd->fd;
  16750. WFIFOHEAD(fd,2);
  16751. WFIFOW(fd,0) = 0x989;
  16752. WFIFOSET(fd,2);
  16753. #endif
  16754. }
  16755. /**
  16756. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16757. * 0A2F <result>.B <title_id>.L
  16758. */
  16759. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16760. {
  16761. #if PACKETVER >= 20150513
  16762. int fd;
  16763. nullpo_retv(sd);
  16764. if (!clif_session_isValid(sd))
  16765. return;
  16766. fd = sd->fd;
  16767. WFIFOHEAD(fd, packet_len(0xa2f));
  16768. WFIFOW(fd, 0) = 0xa2f;
  16769. WFIFOB(fd, 2) = result;
  16770. WFIFOL(fd, 3) = title_id;
  16771. WFIFOSET(fd, packet_len(0xa2f));
  16772. #endif
  16773. }
  16774. /**
  16775. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16776. * 0A2E <title_id>.L
  16777. */
  16778. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16779. {
  16780. int title_id;
  16781. nullpo_retv(sd);
  16782. title_id = RFIFOL(fd, 2);
  16783. if( title_id == sd->status.title_id ){
  16784. // It is exactly the same as the old one
  16785. return;
  16786. }else if( title_id <= 0 ){
  16787. sd->status.title_id = 0;
  16788. }else{
  16789. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16790. clif_change_title_ack(sd, 1, title_id);
  16791. return;
  16792. }
  16793. sd->status.title_id = title_id;
  16794. }
  16795. clif_name_area(&sd->bl);
  16796. clif_change_title_ack(sd, 0, title_id);
  16797. }
  16798. #ifdef DUMP_UNKNOWN_PACKET
  16799. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16800. {
  16801. const char* packet_txt = "save/packet.txt";
  16802. FILE* fp;
  16803. time_t time_server;
  16804. struct tm *datetime;
  16805. char datestr[512];
  16806. time(&time_server); // get time in seconds since 1/1/1970
  16807. datetime = localtime(&time_server); // convert seconds in structure
  16808. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16809. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16810. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16811. if( sd ) {
  16812. 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);
  16813. } else {
  16814. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16815. }
  16816. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16817. fprintf(fp, "\n");
  16818. fclose(fp);
  16819. } else {
  16820. ShowError("Failed to write '%s'.\n", packet_txt);
  16821. // Dump on console instead
  16822. if( sd ) {
  16823. 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);
  16824. } else {
  16825. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16826. }
  16827. ShowDump(RFIFOP(fd,0), packet_len);
  16828. }
  16829. }
  16830. #endif
  16831. /// Roulette System
  16832. /// Author: Yommy
  16833. /// Opens the roulette window
  16834. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16835. void clif_roulette_open( struct map_session_data* sd ){
  16836. nullpo_retv( sd );
  16837. struct packet_roulette_open_ack p;
  16838. p.PacketType = 0xa1a;
  16839. p.Result = 0; // result
  16840. p.Serial = 0; // serial
  16841. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16842. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16843. p.AdditionItemID = -1; //! TODO: Display bonus item
  16844. p.GoldPoint = sd->roulette_point.gold;
  16845. p.SilverPoint = sd->roulette_point.silver;
  16846. p.BronzePoint = sd->roulette_point.bronze;
  16847. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16848. }
  16849. /// Request to open the roulette window
  16850. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16851. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16852. nullpo_retv(sd);
  16853. if (!battle_config.feature_roulette) {
  16854. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16855. return;
  16856. }
  16857. clif_roulette_open(sd);
  16858. }
  16859. /// Sends the info about the available roulette rewards to the client
  16860. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16861. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16862. void clif_roulette_info( struct map_session_data* sd ){
  16863. nullpo_retv(sd);
  16864. struct packet_roulette_info_ack p;
  16865. p.PacketType = rouletteinfoackType;
  16866. p.PacketLength = sizeof(p);
  16867. p.RouletteSerial = 1;
  16868. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16869. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16870. p.ItemInfo[count].Row = i;
  16871. p.ItemInfo[count].Position = j;
  16872. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  16873. p.ItemInfo[count].Count = rd.qty[i][j];
  16874. #if PACKETVER >= 20180511
  16875. p.ItemInfo[count].unused = 0;
  16876. #endif
  16877. count++;
  16878. }
  16879. }
  16880. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16881. }
  16882. /// Request the roulette reward data
  16883. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16884. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16885. nullpo_retv(sd);
  16886. if (!battle_config.feature_roulette) {
  16887. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16888. return;
  16889. }
  16890. clif_roulette_info(sd);
  16891. }
  16892. /// Notification of the client that the roulette window was closed
  16893. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16894. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16895. nullpo_retv(sd);
  16896. if (!battle_config.feature_roulette) {
  16897. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16898. return;
  16899. }
  16900. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16901. }
  16902. /// Response to a item reward request
  16903. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16904. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16905. #if PACKETVER >= 20141016
  16906. nullpo_retv(sd);
  16907. struct packet_roulette_itemrecv_ack p;
  16908. p.PacketType = roulettercvitemackType;
  16909. p.Result = type;
  16910. p.AdditionItemID = 0; //! TODO: Additional item
  16911. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16912. #endif
  16913. }
  16914. /**
  16915. * Claim roulette reward
  16916. * @param sd Player
  16917. * @return 0:Success
  16918. **/
  16919. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16920. struct item it;
  16921. uint8 res = 1;
  16922. nullpo_retr(1, sd);
  16923. if (sd->roulette.prizeIdx < 0)
  16924. return RECV_ITEM_FAILED;
  16925. memset(&it, 0, sizeof(it));
  16926. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16927. it.identify = 1;
  16928. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16929. ; // onSuccess
  16930. }
  16931. sd->roulette.claimPrize = false;
  16932. sd->roulette.prizeStage = 0;
  16933. sd->roulette.prizeIdx = -1;
  16934. sd->roulette.stage = 0;
  16935. return res;
  16936. }
  16937. /// Update Roulette window with current stats
  16938. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16939. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  16940. nullpo_retv( sd );
  16941. struct packet_roulette_generate_ack p;
  16942. p.PacketType = roulettgenerateackType;
  16943. p.Result = result;
  16944. p.Step = stage;
  16945. p.Idx = prizeIdx;
  16946. p.AdditionItemID = bonusItemID;
  16947. p.RemainGold = sd->roulette_point.gold;
  16948. p.RemainSilver = sd->roulette_point.silver;
  16949. p.RemainBronze = sd->roulette_point.bronze;
  16950. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16951. }
  16952. /// Request to start the roulette
  16953. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16954. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16955. enum GENERATE_ROULETTE_ACK result;
  16956. nullpo_retv(sd);
  16957. if (!battle_config.feature_roulette) {
  16958. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16959. return;
  16960. }
  16961. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16962. return;
  16963. }
  16964. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16965. sd->roulette.stage = 0;
  16966. sd->roulette.claimPrize = false;
  16967. sd->roulette.prizeStage = 0;
  16968. sd->roulette.prizeIdx = -1;
  16969. }
  16970. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16971. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16972. }else{
  16973. if (!sd->roulette.stage) {
  16974. if (sd->roulette_point.bronze > 0) {
  16975. sd->roulette_point.bronze -= 1;
  16976. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16977. } else if (sd->roulette_point.silver > 9) {
  16978. sd->roulette_point.silver -= 10;
  16979. sd->roulette.stage = 2;
  16980. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16981. } else if (sd->roulette_point.gold > 9) {
  16982. sd->roulette_point.gold -= 10;
  16983. sd->roulette.stage = 4;
  16984. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16985. }
  16986. }
  16987. sd->roulette.prizeStage = sd->roulette.stage;
  16988. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16989. sd->roulette.claimPrize = true;
  16990. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16991. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16992. result = GENERATE_ROULETTE_LOSING;
  16993. sd->roulette.stage = 0;
  16994. }else{
  16995. result = GENERATE_ROULETTE_SUCCESS;
  16996. sd->roulette.stage++;
  16997. }
  16998. }
  16999. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17000. }
  17001. /// Request to claim a prize
  17002. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17003. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17004. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17005. nullpo_retv(sd);
  17006. if (!battle_config.feature_roulette) {
  17007. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17008. return;
  17009. }
  17010. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17011. return;
  17012. }
  17013. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17014. switch (clif_roulette_getitem(sd)) {
  17015. case ADDITEM_SUCCESS:
  17016. type = RECV_ITEM_SUCCESS;
  17017. break;
  17018. case ADDITEM_INVALID:
  17019. case ADDITEM_OVERITEM:
  17020. case ADDITEM_OVERAMOUNT:
  17021. type = RECV_ITEM_OVERCOUNT;
  17022. break;
  17023. case ADDITEM_OVERWEIGHT:
  17024. type = RECV_ITEM_OVERWEIGHT;
  17025. break;
  17026. case ADDITEM_STACKLIMIT:
  17027. default:
  17028. type = RECV_ITEM_FAILED;
  17029. break;
  17030. }
  17031. }
  17032. clif_roulette_recvitem_ack(sd,type);
  17033. }
  17034. /// MERGE ITEM
  17035. /**
  17036. * Acknowledge the client about item merger result
  17037. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17038. * @param fd
  17039. * @param sd
  17040. **/
  17041. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  17042. unsigned char buf[9];
  17043. struct s_packet_db *info = NULL;
  17044. short cmd = 0;
  17045. nullpo_retv(sd);
  17046. if (!clif_session_isValid(sd))
  17047. return;
  17048. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  17049. return;
  17050. if (!(info = &packet_db[cmd]) || info->len == 0)
  17051. return;
  17052. WBUFW(buf, 0) = cmd;
  17053. WBUFW(buf, info->pos[0]) = index;
  17054. WBUFW(buf, info->pos[1]) = count;
  17055. WBUFB(buf, info->pos[2]) = type;
  17056. clif_send(buf, info->len, &sd->bl, SELF);
  17057. }
  17058. /**
  17059. * Check if item has the pair to be merged
  17060. * @param sd
  17061. * @param it Item
  17062. * @return True if has pair, False if not
  17063. **/
  17064. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17065. struct item *it_;
  17066. unsigned short i;
  17067. nullpo_retr(false, sd);
  17068. 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);
  17069. if (i < MAX_INVENTORY)
  17070. return true;
  17071. return false;
  17072. }
  17073. /**
  17074. * Check if item can be merged
  17075. * @param id Item Data
  17076. * @param it Item
  17077. * @return True if can be merged, False if not
  17078. **/
  17079. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17080. if (!id || !it)
  17081. return false;
  17082. if (id->type == IT_CASH)
  17083. return false;
  17084. if (!itemdb_isstackable2(id))
  17085. return false;
  17086. if (itemdb_isspecial(it->card[0]))
  17087. return false;
  17088. if (!it->unique_id)
  17089. return false;
  17090. return true;
  17091. }
  17092. /**
  17093. * Open available item to be merged.
  17094. * Only show 1 item in 1 process.
  17095. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17096. * @param sd
  17097. **/
  17098. void clif_merge_item_open(struct map_session_data *sd) {
  17099. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  17100. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  17101. int len = 0;
  17102. struct s_packet_db *info = NULL;
  17103. struct item *it;
  17104. nullpo_retv(sd);
  17105. if (!clif_session_isValid(sd))
  17106. return;
  17107. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  17108. return;
  17109. if (!(info = &packet_db[cmd]) || info->len == 0)
  17110. return;
  17111. // Get entries
  17112. for (i = 0; i < MAX_INVENTORY; i++) {
  17113. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  17114. continue;
  17115. if (clif_merge_item_has_pair(sd, it))
  17116. indexes[n++] = i;
  17117. }
  17118. if (n < 2) { // No item need to be merged
  17119. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17120. return;
  17121. }
  17122. WBUFW(buf, 0) = cmd;
  17123. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  17124. for (i = 0; i < n; i++) {
  17125. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  17126. }
  17127. clif_send(buf, len, &sd->bl, SELF);
  17128. }
  17129. /**
  17130. * Process item merger
  17131. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17132. * @param fd
  17133. * @param sd
  17134. **/
  17135. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17136. struct s_packet_db *info = NULL;
  17137. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17138. unsigned int count = 0;
  17139. struct item_data *id = NULL;
  17140. nullpo_retv(sd);
  17141. if (!clif_session_isValid(sd))
  17142. return;
  17143. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17144. return;
  17145. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17146. if (n < 2) { // No item need to be merged
  17147. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17148. return;
  17149. }
  17150. for (i = 0, j = 0; i < n; i++) {
  17151. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  17152. if( idx < 0 || idx >= MAX_INVENTORY ){
  17153. return;
  17154. }
  17155. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17156. continue;
  17157. indexes[j] = idx;
  17158. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17159. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17160. return;
  17161. }
  17162. count += sd->inventory.u.items_inventory[idx].amount;
  17163. j++;
  17164. }
  17165. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17166. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17167. return;
  17168. }
  17169. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17170. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17171. return;
  17172. }
  17173. // Merrrrge!!!!
  17174. for (i = 1; i < n; i++) {
  17175. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17176. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17177. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17178. sd->inventory_data[idx] = NULL;
  17179. clif_delitem(sd, idx, amt, 0);
  17180. }
  17181. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17182. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17183. }
  17184. /**
  17185. * Cancel item merge
  17186. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17187. * @param fd
  17188. * @param sd
  17189. **/
  17190. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17191. return; // Nothing todo yet
  17192. }
  17193. /**
  17194. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17195. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17196. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17197. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17198. **/
  17199. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17200. char name[NAME_LENGTH];
  17201. if( battle_config.broadcast_hide_name ){
  17202. std::string dispname = std::string( char_name );
  17203. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  17204. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  17205. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  17206. }else{
  17207. safestrncpy( name, char_name, sizeof( name ) );
  17208. }
  17209. switch( type ){
  17210. case ITEMOBTAIN_TYPE_BOXITEM:
  17211. {
  17212. struct packet_package_item_announce p;
  17213. p.PacketType = package_item_announceType;
  17214. p.type = type;
  17215. p.ItemID = client_nameid( nameid );
  17216. p.len = NAME_LENGTH;
  17217. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17218. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  17219. p.BoxItemID = client_nameid( container );
  17220. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17221. p.PacketLength = 15 + p.len;
  17222. #else
  17223. p.PacketLength = 11 + p.len;
  17224. #endif
  17225. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17226. }
  17227. break;
  17228. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17229. case ITEMOBTAIN_TYPE_NPC:
  17230. {
  17231. struct packet_item_drop_announce p;
  17232. p.PacketType = item_drop_announceType;
  17233. p.type = type;
  17234. p.ItemID = client_nameid( nameid );
  17235. p.len = NAME_LENGTH;
  17236. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17237. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17238. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17239. p.monsterNameLen = NAME_LENGTH;
  17240. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17241. }else{
  17242. p.monsterNameLen = 0;
  17243. p.monsterName[0] = '\0';
  17244. }
  17245. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17246. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17247. #else
  17248. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17249. #endif
  17250. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17251. }
  17252. break;
  17253. }
  17254. }
  17255. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17256. /// 0A02 <view>.W
  17257. /// Value <flag> has the following effects:
  17258. /// 1: Open a Dress Room window.
  17259. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17260. #if PACKETVER >= 20150513
  17261. int fd = sd->fd;
  17262. nullpo_retv(sd);
  17263. WFIFOHEAD(fd, packet_len(0xa02));
  17264. WFIFOW(fd,0) = 0xa02;
  17265. WFIFOW(fd,2) = flag;
  17266. WFIFOSET(fd, packet_len(0xa02));
  17267. #endif
  17268. }
  17269. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17270. /// 0A35 <result>.W
  17271. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17272. #if PACKETVER >= 20150513
  17273. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17274. // Ignore the request
  17275. // - Invalid item index
  17276. // - Invalid item ID or item doesn't exist
  17277. // - Item is already identified
  17278. if (idx < 0 || idx >= MAX_INVENTORY ||
  17279. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17280. sd->inventory.u.items_inventory[idx].identify)
  17281. return;
  17282. // Ignore the request - No magnifiers in inventory
  17283. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17284. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17285. return;
  17286. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17287. return;
  17288. skill_identify(sd, idx);
  17289. #endif
  17290. }
  17291. /// Starts navigation to the given target on client side
  17292. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17293. #if PACKETVER >= 20111010
  17294. int fd = sd->fd;
  17295. WFIFOHEAD(fd,27);
  17296. WFIFOW(fd,0) = 0x08e2;
  17297. // How detailed will our navigation be?
  17298. if( mob_id > 0 ){
  17299. x = 0;
  17300. y = 0;
  17301. WFIFOB(fd,2) = 3; // monster with destination field
  17302. }else if( x > 0 && y > 0 ){
  17303. WFIFOB(fd,2) = 0; // with coordinates
  17304. }else{
  17305. x = 0;
  17306. y = 0;
  17307. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17308. }
  17309. // Which services can be used for transportation?
  17310. WFIFOB(fd,3) = flag;
  17311. // If this flag is set, the navigation window will not be opened up
  17312. WFIFOB(fd,4) = hideWindow;
  17313. // Target map
  17314. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17315. // Target x
  17316. WFIFOW(fd,21) = x;
  17317. // Target y
  17318. WFIFOW(fd,23) = y;
  17319. // Target monster ID
  17320. WFIFOW(fd,25) = mob_id;
  17321. WFIFOSET(fd,27);
  17322. #endif
  17323. }
  17324. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17325. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17326. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17327. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17328. struct map_session_data *tsd;
  17329. struct block_list* tbl;
  17330. if( target == SELF ){
  17331. tsd = BL_CAST(BL_PC,bl);
  17332. tbl = &sd->bl;
  17333. }else{
  17334. tsd = sd;
  17335. tbl = bl;
  17336. }
  17337. nullpo_retv( tsd );
  17338. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17339. return;
  17340. }
  17341. struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
  17342. p->packetType = HEADER_ZC_HAT_EFFECT;
  17343. p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17344. p->aid = tsd->bl.id;
  17345. p->status = 1;
  17346. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17347. p->effects[i] = tsd->hatEffects[i];
  17348. }
  17349. clif_send( p, p->packetLength, tbl, target );
  17350. #endif
  17351. }
  17352. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17353. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17354. nullpo_retv( sd );
  17355. struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
  17356. p->packetType = HEADER_ZC_HAT_EFFECT;
  17357. p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) );
  17358. p->aid = sd->bl.id;
  17359. p->status = enable;
  17360. p->effects[0] = effectId;
  17361. clif_send( p, p->packetLength, &sd->bl, AREA );
  17362. #endif
  17363. }
  17364. /// Notify the client that a sale has started
  17365. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17366. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17367. #if PACKETVER_SUPPORTS_SALES
  17368. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17369. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17370. p.itemId = client_nameid( sale_item->nameid );
  17371. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17372. clif_send( &p, sizeof( p ), bl, target );
  17373. #endif
  17374. }
  17375. /// Notify the client that a sale has ended
  17376. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17377. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17378. #if PACKETVER_SUPPORTS_SALES
  17379. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17380. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17381. p.itemId = client_nameid( sale_item->nameid );
  17382. clif_send( &p, sizeof( p ), bl, target );
  17383. #endif
  17384. }
  17385. /// Update the remaining amount of a sale item.
  17386. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17387. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17388. #if PACKETVER_SUPPORTS_SALES
  17389. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17390. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17391. p.itemId = client_nameid( sale_item->nameid );
  17392. p.amount = sale_item->amount;
  17393. clif_send( &p, sizeof( p ), bl, target );
  17394. #endif
  17395. }
  17396. /// The client requested a refresh of the current remaining count of a sale item
  17397. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17398. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17399. #if PACKETVER_SUPPORTS_SALES
  17400. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17401. struct sale_item_data* sale;
  17402. if( p->AID != sd->status.account_id ){
  17403. return;
  17404. }
  17405. sale = sale_find_item( p->itemId, true );
  17406. if( sale == NULL ){
  17407. return;
  17408. }
  17409. clif_sale_amount(sale, &sd->bl, SELF);
  17410. #endif
  17411. }
  17412. /// Opens the sale administration window on the client
  17413. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17414. void clif_sale_open( struct map_session_data* sd ){
  17415. #if PACKETVER_SUPPORTS_SALES
  17416. nullpo_retv(sd);
  17417. if( sd->state.sale_open ){
  17418. return;
  17419. }
  17420. sd->state.sale_open = true;
  17421. int fd = sd->fd;
  17422. WFIFOHEAD(fd, 2);
  17423. WFIFOW(fd, 0) = 0x9b5;
  17424. WFIFOSET(fd, 2);
  17425. #endif
  17426. }
  17427. /// Client request to open the sale administration window.
  17428. /// This is sent by /limitedsale
  17429. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17430. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17431. #if PACKETVER_SUPPORTS_SALES
  17432. nullpo_retv(sd);
  17433. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17434. return;
  17435. }
  17436. char command[CHAT_SIZE_MAX];
  17437. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17438. is_atcommand(fd, sd, command, 1);
  17439. #endif
  17440. }
  17441. /// Closes the sale administration window on the client.
  17442. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17443. void clif_sale_close(struct map_session_data* sd) {
  17444. #if PACKETVER_SUPPORTS_SALES
  17445. nullpo_retv(sd);
  17446. if( !sd->state.sale_open ){
  17447. return;
  17448. }
  17449. sd->state.sale_open = false;
  17450. int fd = sd->fd;
  17451. WFIFOHEAD(fd, 2);
  17452. WFIFOW(fd, 0) = 0x9bd;
  17453. WFIFOSET(fd, 2);
  17454. #endif
  17455. }
  17456. /// Client request to close the sale administration window.
  17457. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17458. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17459. #if PACKETVER_SUPPORTS_SALES
  17460. nullpo_retv(sd);
  17461. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17462. return;
  17463. }
  17464. clif_sale_close(sd);
  17465. #endif
  17466. }
  17467. /// Reply to a item search request for item sale administration.
  17468. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17469. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17470. #if PACKETVER_SUPPORTS_SALES
  17471. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17472. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17473. if( item != NULL ){
  17474. p.result = 0;
  17475. p.itemId = client_nameid( item->nameid );
  17476. p.price = item->price;
  17477. }else{
  17478. p.result = 1;
  17479. p.itemId = 0;
  17480. p.price = 0;
  17481. }
  17482. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17483. #endif
  17484. }
  17485. /// Search request for an item sale administration.
  17486. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17487. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17488. #if PACKETVER_SUPPORTS_SALES
  17489. char item_name[ITEM_NAME_LENGTH];
  17490. nullpo_retv(sd);
  17491. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17492. return;
  17493. }
  17494. if( !sd->state.sale_open ){
  17495. return;
  17496. }
  17497. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17498. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17499. if( id ){
  17500. int i;
  17501. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17502. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17503. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17504. return;
  17505. }
  17506. }
  17507. }
  17508. // not found
  17509. clif_sale_search_reply( sd, NULL );
  17510. #endif
  17511. }
  17512. /// Reply if an item was successfully put on sale or not.
  17513. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17514. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17515. #if PACKETVER_SUPPORTS_SALES
  17516. int fd = sd->fd;
  17517. WFIFOHEAD(fd, 4);
  17518. WFIFOW(fd, 0) = 0x9af;
  17519. WFIFOW(fd, 2) = (uint16)result;
  17520. WFIFOSET(fd, 4);
  17521. #endif
  17522. }
  17523. /// A client request to put an item on sale.
  17524. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17525. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17526. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17527. #if PACKETVER_SUPPORTS_SALES
  17528. nullpo_retv( sd );
  17529. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17530. if( p->AID != sd->status.account_id ){
  17531. return;
  17532. }
  17533. if( !sd->state.sale_open ){
  17534. return;
  17535. }
  17536. time_t endTime = p->startTime + p->hours * 60 * 60;
  17537. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17538. #endif
  17539. }
  17540. /// Reply to an item removal from sale.
  17541. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17542. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17543. #if PACKETVER_SUPPORTS_SALES
  17544. int fd = sd->fd;
  17545. WFIFOHEAD(fd, 4);
  17546. WFIFOW(fd, 0) = 0x9b1;
  17547. WFIFOW(fd, 2) = failed;
  17548. WFIFOSET(fd, 4);
  17549. #endif
  17550. }
  17551. /// Request to remove an item from sale.
  17552. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17553. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17554. #if PACKETVER_SUPPORTS_SALES
  17555. nullpo_retv( sd );
  17556. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17557. if( p->AID != sd->status.account_id ){
  17558. return;
  17559. }
  17560. if( !sd->state.sale_open ){
  17561. return;
  17562. }
  17563. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17564. #endif
  17565. }
  17566. /// Achievement System
  17567. /// Author: Luxuri, Aleos
  17568. /**
  17569. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17570. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17571. */
  17572. void clif_achievement_list_all(struct map_session_data *sd)
  17573. {
  17574. nullpo_retv(sd);
  17575. if (!battle_config.feature_achievement) {
  17576. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17577. return;
  17578. }
  17579. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17580. if (count == 0)
  17581. return;
  17582. int len = (50 * count) + 22;
  17583. int fd = sd->fd;
  17584. int *info = achievement_level(sd, true);
  17585. WFIFOHEAD(fd,len);
  17586. WFIFOW(fd, 0) = 0xa23;
  17587. WFIFOW(fd, 2) = len;
  17588. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17589. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17590. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17591. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17592. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17593. for (int i = 0; i < count; i++) {
  17594. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17595. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17596. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17597. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17598. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17599. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17600. }
  17601. WFIFOSET(fd, len);
  17602. }
  17603. /**
  17604. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17605. * 0a24 <ACHPoint>.L
  17606. */
  17607. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17608. {
  17609. nullpo_retv(sd);
  17610. if (!battle_config.feature_achievement) {
  17611. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17612. return;
  17613. }
  17614. int fd = sd->fd;
  17615. int *info = achievement_level(sd, true);
  17616. WFIFOHEAD(fd, packet_len(0xa24));
  17617. WFIFOW(fd, 0) = 0xa24;
  17618. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17619. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17620. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17621. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17622. if (ach) {
  17623. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17624. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17625. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17626. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17627. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17628. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17629. } else
  17630. memset(WFIFOP(fd, 16), 0, 40);
  17631. WFIFOSET(fd, packet_len(0xa24));
  17632. }
  17633. /**
  17634. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17635. * 0a25 <achievementID>.L
  17636. */
  17637. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17638. {
  17639. nullpo_retv(sd);
  17640. if( sd->achievement_data.save )
  17641. intif_achievement_save(sd);
  17642. achievement_check_reward(sd, RFIFOL(fd,2));
  17643. }
  17644. /**
  17645. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17646. * 0a26 <result>.W <achievementID>.L
  17647. */
  17648. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17649. {
  17650. WFIFOHEAD(fd, packet_len(0xa26));
  17651. WFIFOW(fd, 0) = 0xa26;
  17652. WFIFOB(fd, 2) = result;
  17653. WFIFOL(fd, 3) = achievement_id;
  17654. WFIFOSET(fd, packet_len(0xa26));
  17655. }
  17656. /// Process the pet evolution request
  17657. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17658. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17659. #if PACKETVER >= 20141008
  17660. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17661. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17662. if (!pet) {
  17663. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17664. return;
  17665. }
  17666. pet_evolution(sd, pet->class_);
  17667. #endif
  17668. }
  17669. /// Sends the result of the evolution to the client.
  17670. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17671. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17672. #if PACKETVER >= 20141008
  17673. int fd = sd->fd;
  17674. WFIFOHEAD(fd, packet_len(0x9fc));
  17675. WFIFOW(fd, 0) = 0x9fc;
  17676. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17677. WFIFOSET(fd, packet_len(0x9fc));
  17678. #endif
  17679. }
  17680. /*
  17681. * This packet is sent by /changedress or /nocosplay
  17682. *
  17683. * 0ae8
  17684. */
  17685. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17686. #if PACKETVER >= 20180103
  17687. char command[CHAT_SIZE_MAX];
  17688. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17689. is_atcommand( fd, sd, command, 1 );
  17690. #endif
  17691. }
  17692. /// Opens an UI window of the given type and initializes it with the given data
  17693. /// 0AE2 <type>.B <data>.L
  17694. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17695. nullpo_retv(sd);
  17696. int fd = sd->fd;
  17697. WFIFOHEAD(fd,packet_len(0xae2));
  17698. WFIFOW(fd,0) = 0xae2;
  17699. WFIFOB(fd,2) = ui_type;
  17700. WFIFOL(fd,3) = data;
  17701. WFIFOSET(fd,packet_len(0xae2));
  17702. }
  17703. /// Request to open an UI window of the given type
  17704. /// 0A68 <type>.B
  17705. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17706. switch( RFIFOB(fd,2) ){
  17707. case IN_UI_ATTENDANCE:
  17708. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17709. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17710. }else if( pc_attendance_enabled() ){
  17711. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17712. }else{
  17713. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17714. }
  17715. break;
  17716. }
  17717. }
  17718. /// Response for attedance request
  17719. /// 0AF0 <unknown>.L <data>.L
  17720. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17721. nullpo_retv(sd);
  17722. int fd = sd->fd;
  17723. WFIFOHEAD(fd,packet_len(0xAF0));
  17724. WFIFOW(fd,0) = 0xAF0;
  17725. WFIFOL(fd,2) = 0;
  17726. WFIFOL(fd,6) = data;
  17727. WFIFOSET(fd,packet_len(0xAF0));
  17728. }
  17729. /// Request from the client to retrieve today's attendance reward
  17730. /// 0AEF
  17731. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17732. pc_attendance_claim_reward(sd);
  17733. }
  17734. /// Send out the percentage of weight that causes it to be displayed in red.
  17735. /// 0ADE <percentage>.L
  17736. void clif_weight_limit( struct map_session_data* sd ){
  17737. #if PACKETVER >= 20171025
  17738. nullpo_retv(sd);
  17739. int fd = sd->fd;
  17740. WFIFOHEAD(fd, packet_len(0xADE));
  17741. WFIFOW(fd, 0) = 0xADE;
  17742. #ifdef RENEWAL
  17743. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17744. #else
  17745. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17746. #endif
  17747. WFIFOSET(fd, packet_len(0xADE));
  17748. #endif
  17749. }
  17750. enum e_private_airship_response : uint32{
  17751. PRIVATEAIRSHIP_OK,
  17752. PRIVATEAIRSHIP_RETRY,
  17753. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17754. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17755. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17756. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17757. };
  17758. /// Send out the response to a private airship request
  17759. /// 0A4A <response>.L
  17760. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17761. #if PACKETVER >= 20180321
  17762. nullpo_retv( sd );
  17763. int fd = sd->fd;
  17764. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17765. WFIFOW( fd, 0 ) = 0xA4A;
  17766. WFIFOL( fd, 2 ) = response;
  17767. WFIFOSET( fd, packet_len( 0xA4A ) );
  17768. #endif
  17769. }
  17770. /// Parses a request for a private airship
  17771. /// 0A49 <mapname>.16B <itemid>.W
  17772. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17773. #if PACKETVER >= 20180321
  17774. // Check if the feature is enabled
  17775. if( !battle_config.feature_privateairship ){
  17776. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17777. return;
  17778. }
  17779. // Check if the player is allowed to warp from the source map
  17780. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17781. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17782. return;
  17783. }
  17784. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17785. char mapname[MAP_NAME_LENGTH_EXT];
  17786. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17787. int16 mapindex = mapindex_name2id( mapname );
  17788. // Check if we know the mapname
  17789. if( mapindex < 0 ){
  17790. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17791. return;
  17792. }
  17793. int16 mapid = map_mapindex2mapid( mapindex );
  17794. // Check if the map is available on this server
  17795. if( mapid < 0 ){
  17796. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17797. return;
  17798. }
  17799. // Check if the player tried to warp to the map he is on
  17800. if( sd->bl.m == mapid ){
  17801. // This is blocked by the client, but just to be sure
  17802. return;
  17803. }
  17804. // This can only be a hack, so we prevent it
  17805. if( map_getmapdata( mapid )->instance_id ){
  17806. // Ignore requests to warp directly into a running instance
  17807. return;
  17808. }
  17809. // Check if the player is allowed to warp to the target map
  17810. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17811. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17812. return;
  17813. }
  17814. t_itemid item_id = p->ItemID;
  17815. // Check if the item sent by the client is known to us
  17816. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17817. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17818. return;
  17819. }
  17820. int idx = pc_search_inventory( sd, item_id );
  17821. // Check if the player has the item at all
  17822. if( idx < 0 ){
  17823. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17824. return;
  17825. }
  17826. // Delete the chosen item
  17827. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17828. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17829. return;
  17830. }
  17831. // Warp the player to a random spot on the destination map
  17832. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17833. #endif
  17834. }
  17835. /// Sends out the usage history of the guild storage
  17836. /// 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
  17837. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17838. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17839. #if PACKETVER >= 20140205
  17840. nullpo_retv( sd );
  17841. int fd = sd->fd;
  17842. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17843. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17844. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17845. }else{
  17846. log.clear();
  17847. }
  17848. WFIFOHEAD( fd, size );
  17849. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  17850. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17851. p->PacketLength = size;
  17852. p->result = result;
  17853. p->amount = (uint16)log.size();
  17854. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17855. for( int i = 0; i < log.size(); i++ ){
  17856. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  17857. struct guild_log_entry& entry = log[i];
  17858. item->id = entry.id;
  17859. item->itemId = client_nameid( entry.item.nameid );
  17860. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  17861. item->action = entry.amount > 0; // action = true(put), false(get)
  17862. item->refine = entry.item.refine;
  17863. item->uniqueId = entry.item.unique_id;
  17864. item->IsIdentified = entry.item.identify;
  17865. item->itemType = itemtype( entry.item.nameid );
  17866. clif_addcards( &item->slot, &entry.item );
  17867. safestrncpy( item->name, entry.name, NAME_LENGTH );
  17868. safestrncpy( item->time, entry.time, NAME_LENGTH );
  17869. item->attribute = entry.item.attribute;
  17870. }
  17871. }
  17872. WFIFOSET( fd, p->PacketLength );
  17873. #endif
  17874. }
  17875. /// Activates the client camera info or updates the client camera with the given values.
  17876. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17877. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17878. #if PACKETVER >= 20160525
  17879. int fd = sd->fd;
  17880. WFIFOHEAD(fd, packet_len(0xa78));
  17881. WFIFOW(fd, 0) = 0xa78;
  17882. WFIFOB(fd, 2) = show;
  17883. WFIFOF(fd, 3) = range;
  17884. WFIFOF(fd, 7) = rotation;
  17885. WFIFOF(fd, 11) = latitude;
  17886. WFIFOSET(fd, packet_len(0xa78));
  17887. #endif
  17888. }
  17889. /// Activates or deactives the client camera info or updates the camera settings.
  17890. /// This packet is triggered by /viewpointvalue or /setcamera
  17891. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17892. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17893. char command[CHAT_SIZE_MAX];
  17894. // /viewpointvalue
  17895. if( RFIFOB( fd, 2 ) == 1 ){
  17896. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17897. // /setcamera
  17898. }else{
  17899. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17900. }
  17901. is_atcommand( fd, sd, command, 1 );
  17902. }
  17903. /// Send the full list of items in the equip switch window
  17904. /// 0a9b <length>.W { <index>.W <position>.L }*
  17905. void clif_equipswitch_list( struct map_session_data* sd ){
  17906. #if PACKETVER >= 20170208
  17907. int fd = sd->fd;
  17908. int offset, i, position;
  17909. WFIFOW(fd, 0) = 0xa9b;
  17910. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17911. short index = sd->equip_switch_index[i];
  17912. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17913. WFIFOW(fd, offset) = index + 2;
  17914. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17915. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17916. offset += 6;
  17917. }
  17918. }
  17919. WFIFOW(fd, 2) = offset;
  17920. WFIFOSET(fd, offset);
  17921. #endif
  17922. }
  17923. /// Acknowledgement for removing an equip to the equip switch window
  17924. /// 0a9a <index>.W <position.>.L <failure>.W
  17925. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17926. #if PACKETVER >= 20170208
  17927. int fd = sd->fd;
  17928. WFIFOHEAD(fd, packet_len(0xa9a));
  17929. WFIFOW(fd, 0) = 0xa9a;
  17930. WFIFOW(fd, 2) = index + 2;
  17931. WFIFOL(fd, 4) = pos;
  17932. WFIFOW(fd, 8) = failed;
  17933. WFIFOSET(fd, packet_len(0xa9a));
  17934. #endif
  17935. }
  17936. /// Request to remove an equip from the equip switch window
  17937. /// 0a99 <index>.W <position>.L <= 20170502
  17938. /// 0a99 <index>.W
  17939. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17940. #if PACKETVER >= 20170208
  17941. uint16 index = RFIFOW(fd, 2) - 2;
  17942. bool removed = false;
  17943. if( !battle_config.feature_equipswitch ){
  17944. return;
  17945. }
  17946. // Check if the index is valid
  17947. if( index >= MAX_INVENTORY ){
  17948. return;
  17949. }
  17950. pc_equipswitch_remove( sd, index );
  17951. #endif
  17952. }
  17953. /// Acknowledgement for adding an equip to the equip switch window
  17954. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  17955. /// 0a98 <index>.W <position.>.L <flag>.W
  17956. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  17957. #if PACKETVER >= 20170208
  17958. int fd = sd->fd;
  17959. WFIFOHEAD(fd, packet_len(0xa98));
  17960. WFIFOW(fd, 0) = 0xa98;
  17961. WFIFOW(fd, 2) = index + 2;
  17962. WFIFOL(fd, 4) = pos;
  17963. #if PACKETVER <= 20170502
  17964. WFIFOL(fd, 8) = flag;
  17965. #else
  17966. WFIFOW(fd, 8) = flag;
  17967. #endif
  17968. WFIFOSET(fd,packet_len(0xa98));
  17969. #endif
  17970. }
  17971. /// Request to add an equip to the equip switch window
  17972. /// 0a97 <index>.W <position>.L
  17973. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17974. #if PACKETVER >= 20170208
  17975. uint16 index = RFIFOW(fd, 2) - 2;
  17976. uint32 position = RFIFOL(fd, 4);
  17977. if( !battle_config.feature_equipswitch ){
  17978. return;
  17979. }
  17980. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17981. return;
  17982. }
  17983. if( sd->state.trading || sd->npc_shopid ){
  17984. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  17985. return;
  17986. }
  17987. if( sd->inventory_data[index]->type == IT_AMMO ){
  17988. position = EQP_AMMO;
  17989. }
  17990. pc_equipitem( sd, index, position, true );
  17991. #endif
  17992. }
  17993. /// Acknowledgement packet for the full equip switch
  17994. /// 0a9d <failed>.W
  17995. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17996. #if PACKETVER >= 20170208
  17997. int fd = sd->fd;
  17998. WFIFOHEAD(fd, packet_len(0xa9d));
  17999. WFIFOW(fd, 0) = 0xa9d;
  18000. WFIFOW(fd, 2) = failed;
  18001. WFIFOSET(fd, packet_len(0xa9d));
  18002. #endif
  18003. }
  18004. /// Request to do a full equip switch
  18005. /// 0a9c
  18006. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18007. #if PACKETVER >= 20170208
  18008. int i;
  18009. t_tick tick = gettick();
  18010. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18011. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18012. // Client will not let you send a request
  18013. return;
  18014. }
  18015. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18016. if( !battle_config.feature_equipswitch ){
  18017. return;
  18018. }
  18019. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18020. if( i == EQI_MAX ){
  18021. // client will show: "There is no item to replace." and should not even come here
  18022. clif_equipswitch_reply( sd, false );
  18023. return;
  18024. }
  18025. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18026. return;
  18027. }
  18028. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18029. #endif
  18030. }
  18031. /// Request to do a single equip switch
  18032. /// 0ace <index>.W
  18033. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18034. #if PACKETVER >= 20170502
  18035. uint16 index = RFIFOW(fd, 2) - 2;
  18036. if( !battle_config.feature_equipswitch ){
  18037. return;
  18038. }
  18039. // Check if the index is valid
  18040. if( index >= MAX_INVENTORY ){
  18041. return;
  18042. }
  18043. // Check if the item exists
  18044. if (sd->inventory_data[index] == nullptr)
  18045. return;
  18046. // Check if the item was already added to equip switch
  18047. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18048. if( sd->npc_id ){
  18049. #ifdef RENEWAL
  18050. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18051. clif_msg( sd, WORK_IN_PROGRESS );
  18052. return;
  18053. }
  18054. #endif
  18055. if( !sd->npc_item_flag ){
  18056. return;
  18057. }
  18058. }
  18059. pc_equipswitch( sd, index );
  18060. return;
  18061. }
  18062. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18063. #endif
  18064. }
  18065. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18066. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18067. const struct PACKET_CZ_START_USE_SKILL *p = (struct PACKET_CZ_START_USE_SKILL *)RFIFOP( fd, 0 );
  18068. // Only rolling cutter is supported for now
  18069. if( p->skillId != GC_ROLLINGCUTTER ){
  18070. return;
  18071. }
  18072. // Already running - cant happen on officials, since only one skill is supported
  18073. if( sd->skill_keep_using.skill_id != 0 ){
  18074. return;
  18075. }
  18076. sd->skill_keep_using.tid = INVALID_TIMER;
  18077. sd->skill_keep_using.skill_id = p->skillId;
  18078. sd->skill_keep_using.level = p->skillLv;
  18079. sd->skill_keep_using.target = p->targetId;
  18080. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18081. #endif
  18082. }
  18083. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18084. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18085. const struct PACKET_CZ_STOP_USE_SKILL *p = (struct PACKET_CZ_STOP_USE_SKILL *)RFIFOP( fd, 0 );
  18086. // Not running
  18087. if( sd->skill_keep_using.skill_id == 0 ){
  18088. return;
  18089. }
  18090. #if 0
  18091. // Hack
  18092. if( p->skillId != sd->skill_keep_using.skill_id ){
  18093. return;
  18094. }
  18095. #endif
  18096. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18097. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18098. sd->skill_keep_using.tid = INVALID_TIMER;
  18099. }
  18100. sd->skill_keep_using.skill_id = 0;
  18101. sd->skill_keep_using.level = 0;
  18102. sd->skill_keep_using.target = 0;
  18103. #endif
  18104. }
  18105. void clif_ping( struct map_session_data* sd ){
  18106. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18107. nullpo_retv( sd );
  18108. int fd = sd->fd;
  18109. if( !session_isActive( fd ) ){
  18110. return;
  18111. }
  18112. struct PACKET_ZC_PING p;
  18113. p.packetType = HEADER_ZC_PING;
  18114. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18115. #endif
  18116. }
  18117. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18118. nullpo_ret( sd );
  18119. int fd = sd->fd;
  18120. if( !session_isActive( fd ) ){
  18121. return 0;
  18122. }
  18123. t_tick tick = va_arg( ap, t_tick );
  18124. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18125. clif_ping( sd );
  18126. }
  18127. return 0;
  18128. }
  18129. TIMER_FUNC( clif_ping_timer ){
  18130. map_foreachpc( clif_ping_timer_sub, gettick() );
  18131. return 0;
  18132. }
  18133. /**
  18134. * Opens the refine UI on the designated client.
  18135. * 0aa0
  18136. */
  18137. void clif_refineui_open( struct map_session_data* sd ){
  18138. #if PACKETVER >= 20161012
  18139. nullpo_retv( sd );
  18140. struct PACKET_ZC_REFINE_OPEN_WINDOW p;
  18141. p.packetType = HEADER_ZC_REFINE_OPEN_WINDOW;
  18142. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18143. sd->state.refineui_open = true;
  18144. #endif
  18145. }
  18146. /**
  18147. * Parses cancel/close of the refine UI on client side.
  18148. * 0aa4
  18149. */
  18150. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18151. #if PACKETVER >= 20161012
  18152. sd->state.refineui_open = false;
  18153. #endif
  18154. }
  18155. /**
  18156. * Adds the selected item into the refine UI and sends the possible materials
  18157. * to the client.
  18158. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18159. */
  18160. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18161. #if PACKETVER >= 20161012
  18162. int fd = sd->fd;
  18163. // Get the item db reference
  18164. struct item_data* id = sd->inventory_data[index];
  18165. // No item data was found
  18166. if( id == NULL ){
  18167. return;
  18168. }
  18169. // Check the inventory
  18170. struct item* item = &sd->inventory.u.items_inventory[index];
  18171. // No item was found at the given index
  18172. if( item == NULL ){
  18173. return;
  18174. }
  18175. // Check if the item is identified
  18176. if( !item->identify ){
  18177. return;
  18178. }
  18179. // Check if the item is broken
  18180. if( item->attribute ){
  18181. return;
  18182. }
  18183. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18184. // No refine possible
  18185. if( info == nullptr ){
  18186. return;
  18187. }
  18188. // No possibilities were found
  18189. if( info->costs.empty() ){
  18190. return;
  18191. }
  18192. uint16 length = (uint16)( sizeof( struct PACKET_ZC_REFINE_ADD_ITEM ) + REFINE_COST_MAX * sizeof( struct PACKET_ZC_REFINE_ADD_ITEM_SUB ) );
  18193. // Preallocate the size
  18194. WFIFOHEAD( fd, length );
  18195. struct PACKET_ZC_REFINE_ADD_ITEM* p = (struct PACKET_ZC_REFINE_ADD_ITEM*)WFIFOP( fd, 0 );
  18196. p->packetType = HEADER_ZC_REFINE_ADD_ITEM;
  18197. p->itemIndex = client_index( index );
  18198. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18199. uint16 count = 0;
  18200. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18201. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18202. if( cost != nullptr ){
  18203. p->req[count].itemId = client_nameid( cost->nameid );
  18204. p->req[count].chance = (uint8)( cost->chance / 100 );
  18205. p->req[count].zeny = cost->zeny;
  18206. count++;
  18207. }
  18208. }
  18209. p->packtLength = (uint16)( sizeof( struct PACKET_ZC_REFINE_ADD_ITEM ) + count * sizeof( struct PACKET_ZC_REFINE_ADD_ITEM_SUB ) );
  18210. WFIFOSET( fd, p->packtLength );
  18211. #endif
  18212. }
  18213. /**
  18214. * Client request to add an item to the refine UI.
  18215. * 0aa1 <index>.W
  18216. */
  18217. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18218. #if PACKETVER >= 20161012
  18219. struct PACKET_CZ_REFINE_ADD_ITEM* p = (struct PACKET_CZ_REFINE_ADD_ITEM*)RFIFOP( fd, 0 );
  18220. uint16 index = server_index( p->index );
  18221. // Check if the refine UI is open
  18222. if( !sd->state.refineui_open ){
  18223. return;
  18224. }
  18225. // Check if the index is valid
  18226. if( index >= MAX_INVENTORY ){
  18227. return;
  18228. }
  18229. // Send out the requirements for the refine process
  18230. clif_refineui_info( sd, index );
  18231. #endif
  18232. }
  18233. /**
  18234. * Client requests to try to refine an item.
  18235. * 0aa3 <index>.W <material>.W <catalyst>.B
  18236. */
  18237. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18238. #if PACKETVER >= 20161012
  18239. struct PACKET_CZ_REFINE_ITEM_REQUEST* p = (struct PACKET_CZ_REFINE_ITEM_REQUEST*)RFIFOP( fd, 0 );
  18240. uint16 index = server_index( p->index );
  18241. t_itemid material = p->itemId;
  18242. int16 j;
  18243. // Check if the refine UI is open
  18244. if( !sd->state.refineui_open ){
  18245. return;
  18246. }
  18247. // Check if the index is valid
  18248. if( index >= MAX_INVENTORY ){
  18249. return;
  18250. }
  18251. // Get the item db reference
  18252. struct item_data* id = sd->inventory_data[index];
  18253. // No item data was found
  18254. if( id == NULL ){
  18255. return;
  18256. }
  18257. // Check the inventory
  18258. struct item* item = &sd->inventory.u.items_inventory[index];
  18259. // No item was found at the given index
  18260. if( item == NULL ){
  18261. return;
  18262. }
  18263. // Check if the item is identified
  18264. if( !item->identify ){
  18265. return;
  18266. }
  18267. // Check if the item is broken
  18268. if( item->attribute ){
  18269. return;
  18270. }
  18271. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18272. // No refine possible
  18273. if( info == nullptr ){
  18274. return;
  18275. }
  18276. // No possibilities were found
  18277. if( info->costs.empty() ){
  18278. return;
  18279. }
  18280. // Check if the player has the selected material
  18281. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18282. return;
  18283. }
  18284. int16 blacksmith_index = -1;
  18285. uint16 blacksmith_amount = 0;
  18286. // Check if the player has enough blacksmith blessings
  18287. if( p->blacksmithBlessing != 0 ){
  18288. blacksmith_amount = info->blessing_amount;
  18289. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18290. if( blacksmith_amount == 0 ){
  18291. return;
  18292. }
  18293. // Check if the player has blacksmith blessings
  18294. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18295. return;
  18296. }
  18297. // Check if the player has enough blacksmith blessings
  18298. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18299. return;
  18300. }
  18301. }
  18302. std::shared_ptr<s_refine_cost> cost = nullptr;
  18303. for( const auto& pair : info->costs ){
  18304. if( pair.second->nameid == material ){
  18305. cost = pair.second;
  18306. break;
  18307. }
  18308. }
  18309. // The material was not in the list of possible materials
  18310. if( cost == nullptr ){
  18311. return;
  18312. }
  18313. // Try to pay for the refine
  18314. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18315. clif_npc_buy_result( sd, 1 ); // "You do not have enough zeny."
  18316. return;
  18317. }
  18318. // Delete the required material
  18319. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18320. return;
  18321. }
  18322. // Delete the required blacksmith blessings
  18323. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18324. return;
  18325. }
  18326. // Try to refine the item
  18327. if( cost->chance >= ( rnd() % 10000 ) ){
  18328. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18329. // Success
  18330. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18331. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18332. clif_misceffect( &sd->bl, 3 );
  18333. clif_refine( fd, 0, index, item->refine );
  18334. if( id->type == IT_WEAPON ){
  18335. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18336. }
  18337. clif_refineui_info( sd, index );
  18338. }else{
  18339. // Failure
  18340. // Blacksmith blessings were used to prevent breaking and downgrading
  18341. if( blacksmith_amount > 0 ){
  18342. clif_refine( fd, 3, index, item->refine );
  18343. clif_refineui_info( sd, index );
  18344. // Delete the item if it is breakable
  18345. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18346. clif_refine( fd, 1, index, item->refine );
  18347. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18348. // Downgrade the item if necessary
  18349. }else if( cost->downgrade_amount > 0 ){
  18350. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18351. clif_refine( fd, 2, index, item->refine );
  18352. clif_refineui_info(sd, index);
  18353. // Only show failure, but dont do anything
  18354. }else{
  18355. clif_refine( fd, 3, index, item->refine );
  18356. clif_refineui_info( sd, index );
  18357. }
  18358. clif_misceffect( &sd->bl, 2 );
  18359. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18360. }
  18361. #endif
  18362. }
  18363. /*==========================================
  18364. * Main client packet processing function
  18365. *------------------------------------------*/
  18366. static int clif_parse(int fd)
  18367. {
  18368. int cmd, packet_len;
  18369. TBL_PC* sd;
  18370. int pnum;
  18371. #ifdef PACKET_OBFUSCATION
  18372. int cmd2;
  18373. #endif
  18374. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  18375. // Note: "click masters" can do 80+ clicks in 10 seconds
  18376. 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]
  18377. { // begin main client packet processing loop
  18378. sd = (TBL_PC *)session[fd]->session_data;
  18379. if (session[fd]->flag.eof) {
  18380. if (sd) {
  18381. if (sd->state.autotrade) {
  18382. //Disassociate character from the socket connection.
  18383. session[fd]->session_data = NULL;
  18384. sd->fd = 0;
  18385. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  18386. } else
  18387. if (sd->state.active) {
  18388. // Player logout display [Valaris]
  18389. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  18390. clif_quitsave(fd, sd);
  18391. } else {
  18392. //Unusual logout (during log on/off/map-changer procedure)
  18393. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  18394. map_quit(sd);
  18395. }
  18396. } else {
  18397. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  18398. }
  18399. do_close(fd);
  18400. return 0;
  18401. }
  18402. if (RFIFOREST(fd) < 2)
  18403. return 0;
  18404. cmd = RFIFOW(fd, 0);
  18405. #ifdef PACKET_OBFUSCATION
  18406. // Check if it is a player that tries to connect to the map server.
  18407. if( sd ){
  18408. // Decrypt the current packet ID with the last key stored in the session.
  18409. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  18410. }else{
  18411. // Store the original value for checking
  18412. cmd2 = cmd;
  18413. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  18414. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  18415. }
  18416. #endif
  18417. // filter out invalid / unsupported packets
  18418. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  18419. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  18420. #ifdef DUMP_INVALID_PACKET
  18421. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  18422. #endif
  18423. #ifdef PACKET_OBFUSCATION_WARN
  18424. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  18425. if( !sd ){
  18426. #ifdef PACKET_OBFUSCATION
  18427. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  18428. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  18429. }
  18430. #else
  18431. // Try to use the initial keys for the decryption of the packet ID.
  18432. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  18433. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  18434. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  18435. }
  18436. #endif
  18437. }
  18438. #endif
  18439. set_eof(fd);
  18440. return 0;
  18441. }
  18442. // determine real packet length
  18443. packet_len = packet_db[cmd].len;
  18444. if (packet_len == -1) { // variable-length packet
  18445. if (RFIFOREST(fd) < 4)
  18446. return 0;
  18447. packet_len = RFIFOW(fd,2);
  18448. if (packet_len < 4 || packet_len > 32768) {
  18449. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  18450. #ifdef DUMP_INVALID_PACKET
  18451. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  18452. #endif
  18453. set_eof(fd);
  18454. return 0;
  18455. }
  18456. }
  18457. if ((int)RFIFOREST(fd) < packet_len){
  18458. 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 );
  18459. #ifdef DUMP_INVALID_PACKET
  18460. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  18461. #endif
  18462. set_eof( fd );
  18463. return 0; // not enough data received to form the packet
  18464. }
  18465. #ifdef PACKET_OBFUSCATION
  18466. RFIFOW(fd, 0) = cmd;
  18467. if (sd)
  18468. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  18469. #endif
  18470. if( packet_db[cmd].func == clif_parse_debug )
  18471. packet_db[cmd].func(fd, sd);
  18472. else if( packet_db[cmd].func != NULL ) {
  18473. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  18474. ; //Only valid packet when there is no session
  18475. else
  18476. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  18477. ; //Only valid packet when player is not on a map
  18478. else
  18479. packet_db[cmd].func(fd, sd);
  18480. }
  18481. #ifdef DUMP_UNKNOWN_PACKET
  18482. else DumpUnknown(fd,sd,cmd,packet_len);
  18483. #endif
  18484. RFIFOSKIP(fd, packet_len);
  18485. }; // main loop end
  18486. return 0;
  18487. }
  18488. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  18489. va_list argp;
  18490. int i;
  18491. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  18492. return;
  18493. packet_db[cmd].len = length;
  18494. packet_db[cmd].func = func;
  18495. va_start(argp, func);
  18496. for( i = 0; i < MAX_PACKET_POS; i++ ){
  18497. int offset = va_arg(argp, int);
  18498. if( offset == 0 ){
  18499. break;
  18500. }
  18501. packet_db[cmd].pos[i] = offset;
  18502. }
  18503. if( i == MAX_PACKET_POS ){
  18504. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  18505. }
  18506. va_end(argp);
  18507. }
  18508. /*==========================================
  18509. * Reads packets and setups its array reference
  18510. *------------------------------------------*/
  18511. void packetdb_readdb(){
  18512. memset(packet_db,0,sizeof(packet_db));
  18513. memset(packet_db_ack,0,sizeof(packet_db_ack));
  18514. #include "clif_packetdb.hpp"
  18515. #include "clif_shuffle.hpp"
  18516. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  18517. #ifdef PACKET_OBFUSCATION
  18518. 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]);
  18519. #else
  18520. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  18521. #endif
  18522. }
  18523. /*==========================================
  18524. *
  18525. *------------------------------------------*/
  18526. void do_init_clif(void) {
  18527. const char* colors[COLOR_MAX] = {
  18528. "0x00FF00",
  18529. "0xFF0000",
  18530. "0xFFFFFF",
  18531. "0xFFFF00",
  18532. "0x00FFFF",
  18533. "0xB5FFB5",
  18534. };
  18535. int i;
  18536. /**
  18537. * Setup Color Table (saves unnecessary load of strtoul on every call)
  18538. **/
  18539. for(i = 0; i < COLOR_MAX; i++) {
  18540. color_table[i] = strtoul(colors[i],NULL,0);
  18541. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  18542. }
  18543. packetdb_readdb();
  18544. set_defaultparse(clif_parse);
  18545. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  18546. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  18547. exit(EXIT_FAILURE);
  18548. }
  18549. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  18550. add_timer_func_list(clif_delayquit, "clif_delayquit");
  18551. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  18552. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  18553. if( battle_config.ping_timer_interval > 0 ){
  18554. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  18555. }
  18556. #endif
  18557. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  18558. }
  18559. void do_final_clif(void) {
  18560. ers_destroy(delay_clearunit_ers);
  18561. }