clif.cpp 647 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473
  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 "item_synthesis.hpp"
  40. #include "item_upgrade.hpp"
  41. #include "log.hpp"
  42. #include "mail.hpp"
  43. #include "map.hpp"
  44. #include "mercenary.hpp"
  45. #include "mob.hpp"
  46. #include "npc.hpp"
  47. #include "party.hpp"
  48. #include "pc.hpp"
  49. #include "pc_groups.hpp"
  50. #include "pet.hpp"
  51. #include "quest.hpp"
  52. #include "script.hpp"
  53. #include "skill.hpp"
  54. #include "status.hpp"
  55. #include "storage.hpp"
  56. #include "trade.hpp"
  57. #include "unit.hpp"
  58. #include "vending.hpp"
  59. using namespace rathena;
  60. static inline uint32 client_tick( t_tick tick ){
  61. return (uint32)tick;
  62. }
  63. #if PACKETVER >= 20170830
  64. static inline int64 client_exp(t_exp exp) {
  65. return (int64)u64min(exp, MAX_EXP);
  66. }
  67. #else
  68. static inline int32 client_exp(t_exp exp) {
  69. return (int32)u64min(exp, MAX_EXP);
  70. }
  71. #endif
  72. /* for clif_clearunit_delayed */
  73. static struct eri *delay_clearunit_ers;
  74. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  75. int packet_db_ack[MAX_ACK_FUNC + 1];
  76. // Reuseable global packet buffer to prevent too many allocations
  77. // Take socket.cpp::socket_max_client_packet into consideration
  78. static int8 packet_buffer[UINT16_MAX];
  79. unsigned long color_table[COLOR_MAX];
  80. #include "clif_obfuscation.hpp"
  81. static bool clif_session_isValid(struct map_session_data *sd);
  82. static void clif_loadConfirm( struct map_session_data *sd );
  83. #if PACKETVER >= 20150513
  84. enum mail_type {
  85. MAIL_TYPE_TEXT = 0x0,
  86. MAIL_TYPE_ZENY = 0x2,
  87. MAIL_TYPE_ITEM = 0x4,
  88. MAIL_TYPE_NPC = 0x8
  89. };
  90. #endif
  91. enum e_inventory_type{
  92. INVTYPE_INVENTORY = 0,
  93. INVTYPE_CART = 1,
  94. INVTYPE_STORAGE = 2,
  95. INVTYPE_GUILD_STORAGE = 3,
  96. };
  97. /** Converts item type to display it on client if necessary.
  98. * @param nameid: Item ID
  99. * @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
  100. */
  101. static inline int itemtype(t_itemid nameid) {
  102. 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
  103. int type = id->type;
  104. if( type == IT_SHADOWGEAR ) {
  105. if( id->equip&EQP_SHADOW_WEAPON )
  106. return IT_WEAPON;
  107. else
  108. return IT_ARMOR;
  109. }
  110. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  111. }
  112. // TODO: doc
  113. static inline uint16 client_index( uint16 server_index ){
  114. return server_index + 2;
  115. }
  116. static inline uint16 server_index( uint16 client_index ){
  117. return client_index - 2;
  118. }
  119. static inline uint16 client_storage_index( uint16 server_index ){
  120. return server_index + 1;
  121. }
  122. static inline uint16 server_storage_index( uint16 client_index ){
  123. return client_index - 1;
  124. }
  125. static inline uint32 disguised_bl_id( uint32 bl_id ){
  126. // Casting to prevent a compiler warning
  127. return -((int32)bl_id);
  128. }
  129. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  130. static inline uint32 client_nameid( t_itemid server_nameid ){
  131. t_itemid view = itemdb_viewid( server_nameid );
  132. if( view > 0 ){
  133. return view;
  134. }else{
  135. return server_nameid;
  136. }
  137. }
  138. #else
  139. static inline uint16 client_nameid( t_itemid server_nameid ){
  140. t_itemid view = itemdb_viewid( server_nameid );
  141. if( view > 0 ){
  142. if( view > UINT16_MAX ){
  143. return (uint16)UNKNOWN_ITEM_ID;
  144. }
  145. return (uint16)view;
  146. }else{
  147. if( server_nameid > UINT16_MAX ){
  148. return (uint16)UNKNOWN_ITEM_ID;
  149. }
  150. return (uint16)server_nameid;
  151. }
  152. }
  153. #endif
  154. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  155. p += pos;
  156. p[0] = (uint8)(x>>2);
  157. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  158. p[2] = (uint8)((y<<4) | (dir&0xf));
  159. }
  160. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  161. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  162. p += pos;
  163. p[0] = (uint8)(x0>>2);
  164. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  165. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  166. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  167. p[4] = (uint8)y1;
  168. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  169. }
  170. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  171. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  172. }
  173. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  174. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  175. }
  176. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  177. p += pos;
  178. if( x ) {
  179. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  180. }
  181. if( y ) {
  182. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  183. }
  184. if( dir ) {
  185. dir[0] = ( p[2] & 0x0f );
  186. }
  187. }
  188. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  189. p += pos;
  190. if( x0 ) {
  191. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  192. }
  193. if( y0 ) {
  194. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  195. }
  196. if( x1 ) {
  197. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  198. }
  199. if( y1 ) {
  200. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  201. }
  202. if( sx0 ) {
  203. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  204. }
  205. if( sy0 ) {
  206. sy0[0] = ( p[5] & 0x0f ) >> 0;
  207. }
  208. }
  209. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  210. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  211. }
  212. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  213. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  214. }
  215. //To idenfity disguised characters.
  216. static inline bool disguised(struct block_list* bl) {
  217. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  218. }
  219. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  220. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  221. if( len > max )
  222. len = max;
  223. mes[len-1] = '\0';
  224. return len;
  225. }
  226. static char map_ip_str[128];
  227. static uint32 map_ip;
  228. static uint32 bind_ip = INADDR_ANY;
  229. static uint16 map_port = 5121;
  230. static bool clif_ally_only = false;
  231. int map_fd;
  232. static int clif_parse (int fd);
  233. /*==========================================
  234. * Ip setting of map-server
  235. *------------------------------------------*/
  236. int clif_setip(const char* ip) {
  237. char ip_str[16];
  238. map_ip = host2ip(ip);
  239. if (!map_ip) {
  240. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  241. return 0;
  242. }
  243. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  244. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  245. return 1;
  246. }
  247. void clif_setbindip(const char* ip)
  248. {
  249. bind_ip = host2ip(ip);
  250. if (bind_ip) {
  251. char ip_str[16];
  252. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  253. } else {
  254. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  255. }
  256. }
  257. /*==========================================
  258. * Sets map port to 'port'
  259. * is run from map.cpp upon loading map server configuration
  260. *------------------------------------------*/
  261. void clif_setport(uint16 port)
  262. {
  263. map_port = port;
  264. }
  265. /*==========================================
  266. * Returns map server IP
  267. *------------------------------------------*/
  268. uint32 clif_getip(void)
  269. {
  270. return map_ip;
  271. }
  272. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  273. uint32 clif_refresh_ip(void)
  274. {
  275. uint32 new_ip;
  276. new_ip = host2ip(map_ip_str);
  277. if (new_ip && new_ip != map_ip) {
  278. map_ip = new_ip;
  279. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  280. return map_ip;
  281. }
  282. return 0;
  283. }
  284. /*==========================================
  285. * Returns map port which is set by clif_setport()
  286. *------------------------------------------*/
  287. uint16 clif_getport(void)
  288. {
  289. return map_port;
  290. }
  291. #if PACKETVER >= 20071106
  292. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  293. switch (bl->type) {
  294. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  295. case BL_ITEM: return 0x2; //ITEM_TYPE
  296. case BL_SKILL: return 0x3; //SKILL_TYPE
  297. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  298. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  299. case BL_NPC:
  300. // From 2017-07-26 on NPC type units can also use player sprites.
  301. // There is one exception and this is if they are walking.
  302. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  303. #if PACKETVER >= 20170726
  304. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0x6; //NPC_EVT_TYPE
  305. #else
  306. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  307. #endif
  308. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  309. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  310. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  311. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  312. default: return 0x1; //NPC_TYPE
  313. }
  314. }
  315. #endif
  316. static bool clif_session_isValid(struct map_session_data *sd) {
  317. return ( sd != nullptr && session_isActive(sd->fd) );
  318. }
  319. /*==========================================
  320. * sub process of clif_send
  321. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  322. * In order to send area-wise packets, such as:
  323. * - AREA : everyone nearby your area
  324. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  325. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  326. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  327. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  328. *------------------------------------------*/
  329. static int clif_send_sub(struct block_list *bl, va_list ap)
  330. {
  331. struct block_list *src_bl;
  332. struct map_session_data *sd;
  333. unsigned char *buf;
  334. int len, type, fd;
  335. nullpo_ret(bl);
  336. nullpo_ret(sd = (struct map_session_data *)bl);
  337. // Don't send to disconnected clients.
  338. if( !session_isActive( fd = sd->fd ) ){
  339. return 0;
  340. }
  341. buf = va_arg(ap,unsigned char*);
  342. len = va_arg(ap,int);
  343. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  344. type = va_arg(ap,int);
  345. switch(type) {
  346. case AREA_WOS:
  347. if (bl == src_bl)
  348. return 0;
  349. break;
  350. case AREA_WOC:
  351. if (sd->chatID || bl == src_bl)
  352. return 0;
  353. break;
  354. case AREA_WOSC:
  355. {
  356. if(src_bl->type == BL_PC) {
  357. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  358. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  359. return 0;
  360. }
  361. else if(src_bl->type == BL_NPC) {
  362. struct npc_data *nd = (struct npc_data *)src_bl;
  363. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  364. return 0;
  365. }
  366. }
  367. break;
  368. }
  369. /* unless visible, hold it here */
  370. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  371. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  372. return 0;
  373. WFIFOHEAD(fd, len);
  374. if (WFIFOP(fd,0) == buf) {
  375. ShowError("WARNING: Invalid use of clif_send function\n");
  376. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  377. ShowError(" Please correct your code.\n");
  378. // don't send to not move the pointer of the packet for next sessions in the loop
  379. //WFIFOSET(fd,0);//## TODO is this ok?
  380. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  381. return 0;
  382. }
  383. memcpy(WFIFOP(fd,0), buf, len);
  384. WFIFOSET(fd,len);
  385. return 0;
  386. }
  387. /*==========================================
  388. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  389. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  390. *------------------------------------------*/
  391. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  392. {
  393. int i;
  394. struct map_session_data *sd, *tsd;
  395. struct party_data *p = NULL;
  396. struct guild *g = NULL;
  397. std::shared_ptr<s_battleground_data> bg;
  398. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  399. struct s_mapiterator* iter;
  400. if( type != ALL_CLIENT )
  401. nullpo_ret(bl);
  402. sd = BL_CAST(BL_PC, bl);
  403. switch(type) {
  404. case ALL_CLIENT: //All player clients.
  405. iter = mapit_getallusers();
  406. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  407. if( session_isActive( fd = tsd->fd ) ){
  408. WFIFOHEAD( fd, len );
  409. memcpy( WFIFOP( fd, 0 ), buf, len );
  410. WFIFOSET( fd, len );
  411. }
  412. }
  413. mapit_free(iter);
  414. break;
  415. case ALL_SAMEMAP: //All players on the same map
  416. iter = mapit_getallusers();
  417. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  418. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  419. WFIFOHEAD( fd, len );
  420. memcpy( WFIFOP( fd, 0 ), buf, len );
  421. WFIFOSET( fd, len );
  422. }
  423. }
  424. mapit_free(iter);
  425. break;
  426. case AREA:
  427. case AREA_WOSC:
  428. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  429. clif_send (buf, len, bl, SELF);
  430. case AREA_WOC:
  431. case AREA_WOS:
  432. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  433. BL_PC, buf, len, bl, type);
  434. break;
  435. case AREA_CHAT_WOC:
  436. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  437. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  438. break;
  439. case CHAT:
  440. case CHAT_WOS:
  441. {
  442. struct chat_data *cd;
  443. if (sd) {
  444. cd = (struct chat_data*)map_id2bl(sd->chatID);
  445. } else if (bl->type == BL_CHAT) {
  446. cd = (struct chat_data*)bl;
  447. } else break;
  448. if (cd == NULL)
  449. break;
  450. for(i = 0; i < cd->users; i++) {
  451. if (type == CHAT_WOS && cd->usersd[i] == sd)
  452. continue;
  453. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  454. WFIFOHEAD(fd,len);
  455. memcpy(WFIFOP(fd,0), buf, len);
  456. WFIFOSET(fd,len);
  457. }
  458. }
  459. }
  460. break;
  461. case PARTY_AREA:
  462. case PARTY_AREA_WOS:
  463. x0 = bl->x - AREA_SIZE;
  464. y0 = bl->y - AREA_SIZE;
  465. x1 = bl->x + AREA_SIZE;
  466. y1 = bl->y + AREA_SIZE;
  467. case PARTY:
  468. case PARTY_WOS:
  469. case PARTY_SAMEMAP:
  470. case PARTY_SAMEMAP_WOS:
  471. if (sd && sd->status.party_id)
  472. p = party_search(sd->status.party_id);
  473. if (p) {
  474. for(i=0;i<MAX_PARTY;i++){
  475. if( (sd = p->data[i].sd) == NULL )
  476. continue;
  477. if( !session_isActive( fd = sd->fd ) )
  478. continue;
  479. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  480. continue;
  481. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  482. continue;
  483. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  484. continue;
  485. WFIFOHEAD(fd, len);
  486. memcpy(WFIFOP(fd, 0), buf, len);
  487. WFIFOSET(fd, len);
  488. }
  489. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  490. break;
  491. iter = mapit_getallusers();
  492. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  493. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  494. WFIFOHEAD( fd, len );
  495. memcpy( WFIFOP( fd, 0 ), buf, len );
  496. WFIFOSET( tsd->fd, len );
  497. }
  498. }
  499. mapit_free(iter);
  500. }
  501. break;
  502. case DUEL:
  503. case DUEL_WOS:
  504. if (!sd || !sd->duel_group) break; //Invalid usage.
  505. iter = mapit_getallusers();
  506. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  507. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  508. continue;
  509. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  510. WFIFOHEAD( fd, len );
  511. memcpy( WFIFOP( fd, 0 ), buf, len );
  512. WFIFOSET( fd, len );
  513. }
  514. }
  515. mapit_free(iter);
  516. break;
  517. case SELF:
  518. if( clif_session_isValid(sd) ){
  519. fd = sd->fd;
  520. WFIFOHEAD(fd,len);
  521. memcpy(WFIFOP(fd,0), buf, len);
  522. WFIFOSET(fd,len);
  523. }
  524. break;
  525. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  526. case GUILD_AREA:
  527. case GUILD_AREA_WOS:
  528. x0 = bl->x - AREA_SIZE;
  529. y0 = bl->y - AREA_SIZE;
  530. x1 = bl->x + AREA_SIZE;
  531. y1 = bl->y + AREA_SIZE;
  532. case GUILD_SAMEMAP:
  533. case GUILD_SAMEMAP_WOS:
  534. case GUILD:
  535. case GUILD_WOS:
  536. case GUILD_NOBG:
  537. if (sd && sd->status.guild_id)
  538. g = sd->guild;
  539. if (g) {
  540. for(i = 0; i < g->max_member; i++) {
  541. if( (sd = g->member[i].sd) != nullptr ){
  542. if( !session_isActive( fd = sd->fd ) )
  543. continue;
  544. if( type == GUILD_NOBG && sd->bg_id )
  545. continue;
  546. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  547. continue;
  548. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  549. continue;
  550. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  551. continue;
  552. WFIFOHEAD(fd,len);
  553. memcpy(WFIFOP(fd,0), buf, len);
  554. WFIFOSET(fd,len);
  555. }
  556. }
  557. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  558. break;
  559. iter = mapit_getallusers();
  560. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  561. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  562. WFIFOHEAD( fd, len );
  563. memcpy( WFIFOP( fd, 0 ), buf, len );
  564. WFIFOSET( fd, len );
  565. }
  566. }
  567. mapit_free(iter);
  568. }
  569. break;
  570. case BG_AREA:
  571. case BG_AREA_WOS:
  572. x0 = bl->x - AREA_SIZE;
  573. y0 = bl->y - AREA_SIZE;
  574. x1 = bl->x + AREA_SIZE;
  575. y1 = bl->y + AREA_SIZE;
  576. case BG_SAMEMAP:
  577. case BG_SAMEMAP_WOS:
  578. case BG:
  579. case BG_WOS:
  580. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  581. {
  582. for (const auto &member : bg->members) {
  583. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  584. continue;
  585. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  586. continue;
  587. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  588. continue;
  589. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  590. continue;
  591. WFIFOHEAD(fd,len);
  592. memcpy(WFIFOP(fd,0), buf, len);
  593. WFIFOSET(fd,len);
  594. }
  595. }
  596. break;
  597. case CLAN:
  598. if( sd && sd->clan ){
  599. struct clan* clan = sd->clan;
  600. for( i = 0; i < clan->max_member; i++ ){
  601. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  602. continue;
  603. }
  604. WFIFOHEAD(fd,len);
  605. memcpy(WFIFOP(fd,0), buf, len);
  606. WFIFOSET(fd,len);
  607. }
  608. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  609. break;
  610. iter = mapit_getallusers();
  611. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  612. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  613. WFIFOHEAD(fd, len);
  614. memcpy(WFIFOP(fd, 0), buf, len);
  615. WFIFOSET(fd, len);
  616. }
  617. }
  618. mapit_free(iter);
  619. }
  620. break;
  621. default:
  622. ShowError("clif_send: Unrecognized type %d\n",type);
  623. return -1;
  624. }
  625. return 0;
  626. }
  627. /// Notifies the client, that it's connection attempt was accepted.
  628. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  629. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  630. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  631. void clif_authok(struct map_session_data *sd)
  632. {
  633. #if PACKETVER < 20080102
  634. const int cmd = 0x73;
  635. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  636. const int cmd = 0x2eb;
  637. #else
  638. const int cmd = 0xa18;
  639. #endif
  640. int fd = sd->fd;
  641. WFIFOHEAD(fd,packet_len(cmd));
  642. WFIFOW(fd, 0) = cmd;
  643. WFIFOL(fd, 2) = client_tick(gettick());
  644. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  645. WFIFOB(fd, 9) = 5; // ignored
  646. WFIFOB(fd,10) = 5; // ignored
  647. #if PACKETVER >= 20080102
  648. WFIFOW(fd,11) = sd->status.font;
  649. #endif
  650. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  651. WFIFOB(fd,13) = sd->status.sex;
  652. #endif
  653. WFIFOSET(fd,packet_len(cmd));
  654. }
  655. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  656. /// 0074 <error code>.B
  657. /// error code:
  658. /// 0 = client type mismatch
  659. /// 1 = ID mismatch
  660. /// 2 = mobile - out of available time
  661. /// 3 = mobile - already logged in
  662. /// 4 = mobile - waiting state
  663. void clif_authrefuse(int fd, uint8 error_code)
  664. {
  665. WFIFOHEAD(fd,packet_len(0x74));
  666. WFIFOW(fd,0) = 0x74;
  667. WFIFOB(fd,2) = error_code;
  668. WFIFOSET(fd,packet_len(0x74));
  669. }
  670. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  671. /// 0081 <error code>.B
  672. /// error code:
  673. /// 0 = BAN_UNFAIR
  674. /// 1 = server closed -> MsgStringTable[4]
  675. /// 2 = ID already logged in -> MsgStringTable[5]
  676. /// 3 = timeout/too much lag -> MsgStringTable[241]
  677. /// 4 = server full -> MsgStringTable[264]
  678. /// 5 = underaged -> MsgStringTable[305]
  679. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  680. /// 9 = too many connections from this ip -> MsgStringTable[529]
  681. /// 10 = out of available time paid for -> MsgStringTable[530]
  682. /// 11 = BAN_PAY_SUSPEND
  683. /// 12 = BAN_PAY_CHANGE
  684. /// 13 = BAN_PAY_WRONGIP
  685. /// 14 = BAN_PAY_PNGAMEROOM
  686. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  687. /// 16 = BAN_JAPAN_REFUSE1
  688. /// 17 = BAN_JAPAN_REFUSE2
  689. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  690. /// 100 = BAN_PC_IP_UNFAIR
  691. /// 101 = BAN_PC_IP_COUNT_ALL
  692. /// 102 = BAN_PC_IP_COUNT
  693. /// 103 = BAN_GRAVITY_MEM_AGREE
  694. /// 104 = BAN_GAME_MEM_AGREE
  695. /// 105 = BAN_HAN_VALID
  696. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  697. /// 107 = BAN_OVER_CHARACTER_LIST
  698. /// 108 = BAN_IP_BLOCK
  699. /// 109 = BAN_INVALID_PWD_CNT
  700. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  701. /// ? = disconnected -> MsgStringTable[3]
  702. void clif_authfail_fd(int fd, int type)
  703. {
  704. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  705. return;
  706. WFIFOHEAD(fd, packet_len(0x81));
  707. WFIFOW(fd,0) = 0x81;
  708. WFIFOB(fd,2) = type;
  709. WFIFOSET(fd,packet_len(0x81));
  710. set_eof(fd);
  711. }
  712. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  713. /// 00b3 <type>.B
  714. /// type:
  715. /// 1 = disconnect, char-select
  716. /// ? = nothing
  717. void clif_charselectok(int id, uint8 ok)
  718. {
  719. struct map_session_data* sd;
  720. int fd;
  721. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  722. return;
  723. fd = sd->fd;
  724. WFIFOHEAD(fd,packet_len(0xb3));
  725. WFIFOW(fd,0) = 0xb3;
  726. WFIFOB(fd,2) = ok;
  727. WFIFOSET(fd,packet_len(0xb3));
  728. }
  729. /// Makes an item appear on the ground.
  730. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  731. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  732. /// 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)
  733. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  734. nullpo_retv(fitem);
  735. if( fitem->item.nameid == 0 ){
  736. return;
  737. }
  738. struct packet_dropflooritem p;
  739. p.PacketType = dropflooritemType;
  740. p.ITAID = fitem->bl.id;
  741. p.ITID = client_nameid( fitem->item.nameid );
  742. #if PACKETVER >= 20130000 /* not sure date */
  743. p.type = itemtype( fitem->item.nameid );
  744. #endif
  745. p.IsIdentified = fitem->item.identify ? 1 : 0;
  746. p.xPos = fitem->bl.x;
  747. p.yPos = fitem->bl.y;
  748. p.subX = fitem->subx;
  749. p.subY = fitem->suby;
  750. p.count = fitem->item.amount;
  751. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  752. if( canShowEffect ){
  753. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  754. if( dropEffect > 0 ){
  755. p.showdropeffect = 1;
  756. p.dropeffectmode = dropEffect - 1;
  757. }else{
  758. p.showdropeffect = 0;
  759. p.dropeffectmode = 0;
  760. }
  761. }else{
  762. p.showdropeffect = 0;
  763. p.dropeffectmode = 0;
  764. }
  765. #endif
  766. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  767. }
  768. /// Makes an item disappear from the ground.
  769. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  770. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  771. {
  772. unsigned char buf[16];
  773. nullpo_retv(fitem);
  774. WBUFW(buf,0) = 0xa1;
  775. WBUFL(buf,2) = fitem->bl.id;
  776. if ( !session_isActive( fd ) ){
  777. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  778. } else {
  779. WFIFOHEAD(fd,packet_len(0xa1));
  780. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  781. WFIFOSET(fd,packet_len(0xa1));
  782. }
  783. }
  784. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  785. /// 0080 <id>.L <type>.B
  786. /// type:
  787. /// 0 = out of sight
  788. /// 1 = died
  789. /// 2 = logged out
  790. /// 3 = teleport
  791. /// 4 = trickdead
  792. void clif_clearunit_single(int id, clr_type type, int fd)
  793. {
  794. WFIFOHEAD(fd, packet_len(0x80));
  795. WFIFOW(fd,0) = 0x80;
  796. WFIFOL(fd,2) = id;
  797. WFIFOB(fd,6) = type;
  798. WFIFOSET(fd, packet_len(0x80));
  799. }
  800. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  801. /// 0080 <id>.L <type>.B
  802. /// type:
  803. /// 0 = out of sight
  804. /// 1 = died
  805. /// 2 = logged out
  806. /// 3 = teleport
  807. /// 4 = trickdead
  808. void clif_clearunit_area(struct block_list* bl, clr_type type)
  809. {
  810. unsigned char buf[8];
  811. nullpo_retv(bl);
  812. WBUFW(buf,0) = 0x80;
  813. WBUFL(buf,2) = bl->id;
  814. WBUFB(buf,6) = type;
  815. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  816. if(disguised(bl)) {
  817. WBUFL(buf,2) = disguised_bl_id( bl->id );
  818. clif_send(buf, packet_len(0x80), bl, SELF);
  819. }
  820. }
  821. /// Used to make monsters with player-sprites disappear after dying
  822. /// like normal monsters, because the client does not remove those
  823. /// automatically.
  824. static TIMER_FUNC(clif_clearunit_delayed_sub){
  825. struct block_list *bl = (struct block_list *)data;
  826. clif_clearunit_area(bl, (clr_type) id);
  827. ers_free(delay_clearunit_ers,bl);
  828. return 0;
  829. }
  830. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  831. {
  832. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  833. memcpy (tbl, bl, sizeof (struct block_list));
  834. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  835. }
  836. void clif_get_weapon_view(struct map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  837. {
  838. if(sd->sc.option&OPTION_COSTUME)
  839. {
  840. *rhand = *lhand = 0;
  841. return;
  842. }
  843. #if PACKETVER < 4
  844. *rhand = sd->status.weapon;
  845. *lhand = sd->status.shield;
  846. #else
  847. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  848. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  849. {
  850. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  851. if (id->view_id > 0)
  852. *rhand = id->view_id;
  853. else
  854. *rhand = id->nameid;
  855. } else
  856. *rhand = 0;
  857. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  858. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  859. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  860. {
  861. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  862. if (id->view_id > 0)
  863. *lhand = id->view_id;
  864. else
  865. *lhand = id->nameid;
  866. } else
  867. *lhand = 0;
  868. #endif
  869. }
  870. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  871. static int clif_setlevel_sub(int lv) {
  872. if( lv < battle_config.max_lv ) {
  873. ;
  874. } else if( lv < battle_config.aura_lv ) {
  875. lv = battle_config.max_lv - 1;
  876. } else {
  877. lv = battle_config.max_lv;
  878. }
  879. return lv;
  880. }
  881. static int clif_setlevel(struct block_list* bl) {
  882. int lv = status_get_lv(bl);
  883. if( battle_config.client_limit_unit_lv&bl->type )
  884. return clif_setlevel_sub(lv);
  885. switch( bl->type ) {
  886. case BL_NPC:
  887. case BL_PET:
  888. // npcs and pets do not have level
  889. return 0;
  890. }
  891. return lv;
  892. }
  893. /*==========================================
  894. * Prepares 'unit standing/spawning' packet
  895. *------------------------------------------*/
  896. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  897. nullpo_retv( bl );
  898. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  899. struct status_change* sc = status_get_sc( bl );
  900. struct view_data* vd = status_get_viewdata( bl );
  901. int g_id = status_get_guild_id( bl );
  902. #if PACKETVER < 20091103
  903. if( !pcdb_checkid( vd->class_ ) ){
  904. struct packet_idle_unit2 p;
  905. p.PacketType = idle_unit2Type;
  906. #if PACKETVER >= 20071106
  907. p.objecttype = clif_bl_type( bl, walking );
  908. #endif
  909. p.GID = bl->id;
  910. p.speed = status_get_speed( bl );
  911. p.bodyState = ( sc ) ? sc->opt1 : 0;
  912. p.healthState = ( sc ) ? sc->opt2 : 0;
  913. p.effectState = ( sc ) ? sc->option : 0;
  914. p.job = vd->class_;
  915. p.head = vd->hair_style;
  916. p.weapon = vd->weapon;
  917. p.accessory = vd->head_bottom;
  918. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  919. // The hell, why flags work like this?
  920. p.shield = status_get_emblem_id( bl );
  921. p.accessory2 = GetWord( g_id, 1 );
  922. p.accessory3 = GetWord( g_id, 0 );
  923. }else{
  924. p.shield = vd->shield;
  925. p.accessory2 = vd->head_top;
  926. p.accessory3 = vd->head_mid;
  927. }
  928. p.headpalette = vd->hair_color;
  929. p.bodypalette = vd->cloth_color;
  930. p.headDir = ( sd )? sd->head_dir : 0;
  931. p.GUID = g_id;
  932. p.GEmblemVer = status_get_emblem_id( bl );
  933. p.honor = ( sd ) ? sd->status.manner : 0;
  934. p.virtue = ( sc ) ? sc->opt3 : 0;
  935. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  936. p.sex = vd->sex;
  937. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  938. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  939. p.state = vd->dead_sit;
  940. p.clevel = clif_setlevel( bl );
  941. clif_send( &p, sizeof( p ), tbl, target );
  942. return;
  943. }
  944. #endif
  945. struct packet_idle_unit p;
  946. p.PacketType = idle_unitType;
  947. #if PACKETVER >= 20091103
  948. p.PacketLength = sizeof(p);
  949. p.objecttype = clif_bl_type( bl, walking );
  950. #endif
  951. #if PACKETVER >= 20131223
  952. p.AID = bl->id;
  953. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  954. #else
  955. p.GID = bl->id;
  956. #endif
  957. p.speed = status_get_speed(bl);
  958. p.bodyState = (sc) ? sc->opt1 : 0;
  959. p.healthState = (sc) ? sc->opt2 : 0;
  960. // npc option changed?
  961. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  962. struct map_session_data* sd = (struct map_session_data*)tbl;
  963. struct npc_data* nd = (struct npc_data*)bl;
  964. int option = (sc) ? sc->option : 0;
  965. if( !nd->vd.dead_sit ){
  966. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  967. option ^= OPTION_CLOAK;
  968. }
  969. }
  970. p.effectState = option;
  971. }else{
  972. p.effectState = (sc) ? sc->option : 0;
  973. }
  974. p.job = vd->class_;
  975. p.head = vd->hair_style;
  976. p.weapon = vd->weapon;
  977. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  978. p.shield = vd->shield;
  979. #endif
  980. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  981. // The hell, why flags work like this?
  982. p.accessory = status_get_emblem_id( bl );
  983. p.accessory2 = GetWord( g_id, 1 );
  984. p.accessory3 = GetWord( g_id, 0 );
  985. }else{
  986. p.accessory = vd->head_bottom;
  987. p.accessory2 = vd->head_top;
  988. p.accessory3 = vd->head_mid;
  989. }
  990. p.headpalette = vd->hair_color;
  991. p.bodypalette = vd->cloth_color;
  992. p.headDir = (sd)? sd->head_dir : 0;
  993. #if PACKETVER >= 20101124
  994. p.robe = vd->robe;
  995. #endif
  996. p.GUID = g_id;
  997. p.GEmblemVer = status_get_emblem_id( bl );
  998. p.honor = (sd) ? sd->status.manner : 0;
  999. p.virtue = (sc) ? sc->opt3 : 0;
  1000. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1001. p.sex = vd->sex;
  1002. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1003. p.xSize = p.ySize = (sd) ? 5 : 0;
  1004. p.state = vd->dead_sit;
  1005. p.clevel = clif_setlevel( bl );
  1006. #if PACKETVER >= 20080102
  1007. p.font = (sd) ? sd->status.font : 0;
  1008. #endif
  1009. #if PACKETVER >= 20120221
  1010. 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 ) ) ){
  1011. p.maxHP = status_get_max_hp(bl);
  1012. p.HP = status_get_hp(bl);
  1013. }else{
  1014. p.maxHP = -1;
  1015. p.HP = -1;
  1016. }
  1017. if( bl->type == BL_MOB ){
  1018. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1019. }else if( bl->type == BL_PET ){
  1020. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1021. }else{
  1022. p.isBoss = BOSSTYPE_NONE;
  1023. }
  1024. #endif
  1025. #if PACKETVER >= 20150513
  1026. p.body = vd->body_style;
  1027. #endif
  1028. /* Might be earlier, this is when the named item bug began */
  1029. #if PACKETVER >= 20131223
  1030. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1031. #endif
  1032. clif_send( &p, sizeof( p ), tbl, target );
  1033. // if disguised, send to self
  1034. if( disguised( bl ) ){
  1035. #if PACKETVER >= 20091103
  1036. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1037. #if PACKETVER >= 20131223
  1038. p.AID = disguised_bl_id( bl->id );
  1039. #else
  1040. p.GID = disguised_bl_id( bl->id );
  1041. #endif
  1042. #else
  1043. p.GID = disguised_bl_id( bl->id );
  1044. #endif
  1045. clif_send(&p, sizeof(p), bl, SELF);
  1046. }
  1047. }
  1048. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1049. nullpo_retv( bl );
  1050. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1051. struct status_change* sc = status_get_sc( bl );
  1052. struct view_data* vd = status_get_viewdata( bl );
  1053. int g_id = status_get_guild_id( bl );
  1054. #if PACKETVER < 20091103
  1055. if( !pcdb_checkid( vd->class_ ) ){
  1056. struct packet_spawn_unit2 p;
  1057. p.PacketType = spawn_unit2Type;
  1058. #if PACKETVER >= 20071106
  1059. p.objecttype = clif_bl_type( bl, false );
  1060. #endif
  1061. p.GID = bl->id;
  1062. p.speed = status_get_speed( bl );
  1063. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1064. p.healthState = ( sc ) ? sc->opt2 : 0;
  1065. p.effectState = ( sc ) ? sc->option : 0;
  1066. p.head = vd->hair_style;
  1067. p.weapon = vd->weapon;
  1068. p.accessory = vd->head_bottom;
  1069. p.job = vd->class_;
  1070. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1071. // The hell, why flags work like this?
  1072. p.shield = status_get_emblem_id( bl );
  1073. p.accessory2 = GetWord( g_id, 1 );
  1074. p.accessory3 = GetWord( g_id, 0 );
  1075. }else{
  1076. p.shield = vd->shield;
  1077. p.accessory2 = vd->head_top;
  1078. p.accessory3 = vd->head_mid;
  1079. }
  1080. p.headpalette = vd->hair_color;
  1081. p.bodypalette = vd->cloth_color;
  1082. p.headDir = ( sd ) ? sd->head_dir : 0;
  1083. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1084. p.sex = vd->sex;
  1085. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1086. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1087. clif_send( &p, sizeof( p ), bl, target );
  1088. return;
  1089. }
  1090. #endif
  1091. struct packet_spawn_unit p;
  1092. p.PacketType = spawn_unitType;
  1093. #if PACKETVER >= 20091103
  1094. p.PacketLength = sizeof(p);
  1095. p.objecttype = clif_bl_type( bl, false );
  1096. #endif
  1097. #if PACKETVER >= 20131223
  1098. p.AID = bl->id;
  1099. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1100. #else
  1101. p.GID = bl->id;
  1102. #endif
  1103. p.speed = status_get_speed( bl );
  1104. p.bodyState = (sc) ? sc->opt1 : 0;
  1105. p.healthState = (sc) ? sc->opt2 : 0;
  1106. p.effectState = (sc) ? sc->option : 0;
  1107. p.job = vd->class_;
  1108. p.head = vd->hair_style;
  1109. p.weapon = vd->weapon;
  1110. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1111. p.shield = vd->shield;
  1112. #endif
  1113. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1114. // The hell, why flags work like this?
  1115. p.accessory = status_get_emblem_id( bl );
  1116. p.accessory2 = GetWord( g_id, 1 );
  1117. p.accessory3 = GetWord( g_id, 0 );
  1118. }else{
  1119. p.accessory = vd->head_bottom;
  1120. p.accessory2 = vd->head_top;
  1121. p.accessory3 = vd->head_mid;
  1122. }
  1123. p.headpalette = vd->hair_color;
  1124. p.bodypalette = vd->cloth_color;
  1125. p.headDir = (sd)? sd->head_dir : 0;
  1126. #if PACKETVER >= 20101124
  1127. p.robe = vd->robe;
  1128. #endif
  1129. p.GUID = g_id;
  1130. p.GEmblemVer = status_get_emblem_id( bl );
  1131. p.honor = (sd) ? sd->status.manner : 0;
  1132. p.virtue = (sc) ? sc->opt3 : 0;
  1133. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1134. p.sex = vd->sex;
  1135. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1136. p.xSize = p.ySize = (sd) ? 5 : 0;
  1137. p.clevel = clif_setlevel( bl );
  1138. #if PACKETVER >= 20080102
  1139. p.font = (sd) ? sd->status.font : 0;
  1140. #endif
  1141. #if PACKETVER >= 20120221
  1142. 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 ) ) ){
  1143. p.maxHP = status_get_max_hp( bl );
  1144. p.HP = status_get_hp( bl );
  1145. }else{
  1146. p.maxHP = -1;
  1147. p.HP = -1;
  1148. }
  1149. if( bl->type == BL_MOB ){
  1150. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1151. }else if( bl->type == BL_PET ){
  1152. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1153. }else{
  1154. p.isBoss = BOSSTYPE_NONE;
  1155. }
  1156. #endif
  1157. #if PACKETVER >= 20150513
  1158. p.body = vd->body_style;
  1159. #endif
  1160. /* Might be earlier, this is when the named item bug began */
  1161. #if PACKETVER >= 20131223
  1162. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1163. #endif
  1164. if( disguised( bl ) ){
  1165. nullpo_retv( sd );
  1166. if( sd->status.class_ != sd->disguise ){
  1167. clif_send( &p, sizeof( p ), bl, target );
  1168. }
  1169. #if PACKETVER >= 20091103
  1170. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1171. #if PACKETVER >= 20131223
  1172. p.AID = disguised_bl_id( bl->id );
  1173. #else
  1174. p.GID = disguised_bl_id( bl->id );
  1175. #endif
  1176. #else
  1177. p.GID = disguised_bl_id( bl->id );
  1178. #endif
  1179. clif_send( &p, sizeof( p ), bl, SELF );
  1180. }else{
  1181. clif_send( &p, sizeof( p ), bl, target );
  1182. }
  1183. }
  1184. /*==========================================
  1185. * Prepares 'unit walking' packet
  1186. *------------------------------------------*/
  1187. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1188. nullpo_retv( bl );
  1189. nullpo_retv( ud );
  1190. struct map_session_data* sd;
  1191. struct status_change* sc = status_get_sc( bl );
  1192. struct view_data* vd = status_get_viewdata( bl );
  1193. struct packet_unit_walking p;
  1194. int g_id = status_get_guild_id(bl);
  1195. sd = BL_CAST(BL_PC, bl);
  1196. p.PacketType = unit_walkingType;
  1197. #if PACKETVER >= 20091103
  1198. p.PacketLength = sizeof(p);
  1199. #endif
  1200. #if PACKETVER >= 20071106
  1201. p.objecttype = clif_bl_type( bl, true );
  1202. #endif
  1203. #if PACKETVER >= 20131223
  1204. p.AID = bl->id;
  1205. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1206. #else
  1207. p.GID = bl->id;
  1208. #endif
  1209. p.speed = status_get_speed(bl);
  1210. p.bodyState = (sc) ? sc->opt1 : 0;
  1211. p.healthState = (sc) ? sc->opt2 : 0;
  1212. p.effectState = (sc) ? sc->option : 0;
  1213. p.job = vd->class_;
  1214. p.head = vd->hair_style;
  1215. p.weapon = vd->weapon;
  1216. p.accessory = vd->head_bottom;
  1217. p.moveStartTime = client_tick(gettick());
  1218. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1219. p.shield = vd->shield;
  1220. #endif
  1221. p.accessory2 = vd->head_top;
  1222. p.accessory3 = vd->head_mid;
  1223. p.headpalette = vd->hair_color;
  1224. p.bodypalette = vd->cloth_color;
  1225. p.headDir = (sd) ? sd->head_dir : 0;
  1226. #if PACKETVER >= 20101124
  1227. p.robe = vd->robe;
  1228. #endif
  1229. p.GUID = g_id;
  1230. p.GEmblemVer = status_get_emblem_id(bl);
  1231. p.honor = (sd) ? sd->status.manner : 0;
  1232. p.virtue = (sc) ? sc->opt3 : 0;
  1233. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1234. p.sex = vd->sex;
  1235. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1236. p.xSize = p.ySize = (sd) ? 5 : 0;
  1237. p.clevel = clif_setlevel(bl);
  1238. #if PACKETVER >= 20080102
  1239. p.font = (sd) ? sd->status.font : 0;
  1240. #endif
  1241. #if PACKETVER >= 20120221
  1242. 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 ) ) ){
  1243. p.maxHP = status_get_max_hp(bl);
  1244. p.HP = status_get_hp(bl);
  1245. } else {
  1246. p.maxHP = -1;
  1247. p.HP = -1;
  1248. }
  1249. if( bl->type == BL_MOB ){
  1250. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1251. }else if( bl->type == BL_PET ){
  1252. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1253. }else{
  1254. p.isBoss = BOSSTYPE_NONE;
  1255. }
  1256. #endif
  1257. #if PACKETVER >= 20150513
  1258. p.body = vd->body_style;
  1259. #endif
  1260. /* Might be earlier, this is when the named item bug began */
  1261. #if PACKETVER >= 20131223
  1262. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1263. #endif
  1264. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1265. // if disguised, send the info to self
  1266. if( disguised( bl ) ){
  1267. #if PACKETVER >= 20091103
  1268. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1269. #if PACKETVER >= 20131223
  1270. p.AID = disguised_bl_id( bl->id );
  1271. #else
  1272. p.GID = disguised_bl_id( bl->id );
  1273. #endif
  1274. #else
  1275. p.GID = disguised_bl_id( bl->id );
  1276. #endif
  1277. clif_send(&p,sizeof(p),bl,SELF);
  1278. }
  1279. }
  1280. //Modifies the buffer for disguise characters and sends it to self.
  1281. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1282. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1283. {
  1284. #if PACKETVER >= 20091103
  1285. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1286. WBUFL(buf,5)=-bl->id;
  1287. #elif PACKETVER >= 20071106
  1288. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1289. WBUFL(buf,3)=-bl->id;
  1290. #else
  1291. WBUFL(buf,2)=-bl->id;
  1292. #endif
  1293. clif_send(buf, len, bl, SELF);
  1294. }
  1295. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1296. /// 01b0 <id>.L <type>.B <value>.L
  1297. /// type:
  1298. /// unused
  1299. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1300. {
  1301. nullpo_retv(bl);
  1302. if(!pcdb_checkid(class_))
  1303. {// player classes yield missing sprites
  1304. unsigned char buf[16];
  1305. WBUFW(buf,0)=0x1b0;
  1306. WBUFL(buf,2)=bl->id;
  1307. WBUFB(buf,6)=type;
  1308. WBUFL(buf,7)=class_;
  1309. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1310. }
  1311. }
  1312. /// Notifies the client of an object's Millenium Shields.
  1313. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1314. {
  1315. nullpo_retv(sd);
  1316. if (sd->sc.data[SC_MILLENNIUMSHIELD] == nullptr)
  1317. return;
  1318. WFIFOHEAD(fd, packet_len(0x440));
  1319. WFIFOW(fd, 0) = 0x440;
  1320. WFIFOL(fd, 2) = sd->bl.id;
  1321. WFIFOW(fd, 6) = sd->sc.data[SC_MILLENNIUMSHIELD]->val2;
  1322. WFIFOW(fd, 8) = 0;
  1323. WFIFOSET(fd, packet_len(0x440));
  1324. }
  1325. /*==========================================
  1326. * Kagerou/Oboro amulet spirit
  1327. *------------------------------------------*/
  1328. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1329. {
  1330. WFIFOHEAD(fd, packet_len(0x08cf));
  1331. WFIFOW(fd,0)=0x08cf;
  1332. WFIFOL(fd,2)=sd->bl.id;
  1333. WFIFOW(fd,6)=sd->spiritcharm_type;
  1334. WFIFOW(fd,8)=sd->spiritcharm;
  1335. WFIFOSET(fd, packet_len(0x08cf));
  1336. }
  1337. /*==========================================
  1338. * Run when player changes map / refreshes
  1339. * Tells its client to display all weather settings being used by this map
  1340. *------------------------------------------*/
  1341. static void clif_weather_check(struct map_session_data *sd)
  1342. {
  1343. int16 m = sd->bl.m;
  1344. int fd = sd->fd;
  1345. if (map_getmapflag(m, MF_SNOW)
  1346. || map_getmapflag(m, MF_CLOUDS)
  1347. || map_getmapflag(m, MF_FOG)
  1348. || map_getmapflag(m, MF_FIREWORKS)
  1349. || map_getmapflag(m, MF_SAKURA)
  1350. || map_getmapflag(m, MF_LEAVES)
  1351. || map_getmapflag(m, MF_CLOUDS2))
  1352. {
  1353. if (map_getmapflag(m, MF_SNOW))
  1354. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1355. if (map_getmapflag(m, MF_CLOUDS))
  1356. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1357. if (map_getmapflag(m, MF_CLOUDS2))
  1358. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1359. if (map_getmapflag(m, MF_FOG))
  1360. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1361. if (map_getmapflag(m, MF_FIREWORKS)) {
  1362. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1363. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1364. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1365. }
  1366. if (map_getmapflag(m, MF_SAKURA))
  1367. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1368. if (map_getmapflag(m, MF_LEAVES))
  1369. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1370. }
  1371. }
  1372. /**
  1373. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1374. **/
  1375. void clif_weather(int16 m)
  1376. {
  1377. struct s_mapiterator* iter;
  1378. struct map_session_data *sd=NULL;
  1379. iter = mapit_getallusers();
  1380. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1381. {
  1382. if( sd->bl.m == m )
  1383. clif_weather_check(sd);
  1384. }
  1385. mapit_free(iter);
  1386. }
  1387. /**
  1388. * Hide a NPC from the effects of Maya Purple card.
  1389. * @param bl: Block data
  1390. * @return True if NPC is disabled or false otherwise
  1391. */
  1392. static inline bool clif_npc_mayapurple(block_list *bl) {
  1393. nullpo_retr(false, bl);
  1394. if (bl->type == BL_NPC) {
  1395. npc_data *nd = map_id2nd(bl->id);
  1396. // TODO: Confirm if waitingroom cause any special cases
  1397. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1398. return true;
  1399. }
  1400. return false;
  1401. }
  1402. /**
  1403. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1404. **/
  1405. int clif_spawn( struct block_list *bl, bool walking ){
  1406. struct view_data *vd;
  1407. vd = status_get_viewdata(bl);
  1408. if( !vd || vd->class_ == JT_INVISIBLE )
  1409. return 0;
  1410. // Hide NPC from Maya Purple card
  1411. if (clif_npc_mayapurple(bl))
  1412. return 0;
  1413. if( bl->type == BL_NPC && !vd->dead_sit ){
  1414. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1415. }else{
  1416. clif_spawn_unit( bl, AREA_WOS );
  1417. }
  1418. if (vd->cloth_color)
  1419. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1420. if (vd->body_style)
  1421. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1422. switch (bl->type)
  1423. {
  1424. case BL_PC:
  1425. {
  1426. TBL_PC *sd = ((TBL_PC*)bl);
  1427. if (sd->spiritball > 0)
  1428. clif_spiritball(&sd->bl);
  1429. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  1430. clif_millenniumshield(&sd->bl, sd->sc.data[SC_MILLENNIUMSHIELD]->val2);
  1431. if (sd->soulball > 0)
  1432. clif_soulball(sd);
  1433. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1434. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1435. else if(sd->state.size==SZ_MEDIUM)
  1436. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1437. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1438. clif_sendbgemblem_area(sd);
  1439. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1440. clif_spiritcharm(sd);
  1441. if (sd->status.robe)
  1442. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1443. clif_efst_status_change_sub(bl, bl, AREA);
  1444. clif_hat_effects(sd,bl,AREA);
  1445. }
  1446. break;
  1447. case BL_MOB:
  1448. {
  1449. TBL_MOB *md = ((TBL_MOB*)bl);
  1450. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1451. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1452. else if(md->special_state.size==SZ_MEDIUM)
  1453. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1454. }
  1455. break;
  1456. case BL_NPC:
  1457. {
  1458. TBL_NPC *nd = ((TBL_NPC*)bl);
  1459. if( nd->size == SZ_BIG )
  1460. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1461. else if( nd->size == SZ_MEDIUM )
  1462. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1463. clif_efst_status_change_sub(bl, bl, AREA);
  1464. clif_progressbar_npc_area(nd);
  1465. }
  1466. break;
  1467. case BL_PET:
  1468. if (vd->head_bottom)
  1469. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1470. break;
  1471. }
  1472. return 0;
  1473. }
  1474. /// Sends information about owned homunculus to the client . [orn]
  1475. /// 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)
  1476. /// 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)
  1477. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1478. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1479. nullpo_retv( sd );
  1480. nullpo_retv( hd );
  1481. struct status_data *status = &hd->battle_status;
  1482. struct PACKET_ZC_PROPERTY_HOMUN p;
  1483. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1484. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1485. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1486. 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 );
  1487. p.level = hd->homunculus.level;
  1488. p.hunger = hd->homunculus.hunger;
  1489. p.intimacy = hd->homunculus.intimacy / 100;
  1490. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1491. p.itemId = 0; // equip id
  1492. #endif
  1493. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1494. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1495. p.hit = status->hit;
  1496. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1497. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1498. }else{
  1499. p.crit = status->cri / 10;
  1500. }
  1501. #ifdef RENEWAL
  1502. p.def = status->def + status->def2;
  1503. p.mdef = status->mdef + status->mdef2;
  1504. #else
  1505. p.def = status->def + status->vit;
  1506. p.mdef = status->mdef;
  1507. #endif
  1508. p.flee = status->flee;
  1509. p.amotion = (flag) ? 0 : status->amotion;
  1510. #if PACKETVER >= 20141016
  1511. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1512. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1513. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1514. p.hp = status->hp / ( status->max_hp / 100 );
  1515. p.maxHp = 100;
  1516. }else{
  1517. p.hp = status->hp;
  1518. p.maxHp = status->max_hp;
  1519. }
  1520. #else
  1521. if( status->max_hp > INT16_MAX ){
  1522. p.hp = status->hp / ( status->max_hp / 100 );
  1523. p.maxHp = 100;
  1524. }else{
  1525. p.hp = status->hp;
  1526. p.maxHp = status->max_hp;
  1527. }
  1528. #endif
  1529. if( status->max_sp > INT16_MAX ){
  1530. p.sp = status->sp / ( status->max_sp / 100 );
  1531. p.maxSp = 100;
  1532. }else{
  1533. p.sp = status->sp;
  1534. p.maxSp = status->max_sp;
  1535. }
  1536. p.exp = (uint32)hd->homunculus.exp;
  1537. p.expNext = (uint32)hd->exp_next;
  1538. switch( hom_class2type( hd->homunculus.class_ ) ){
  1539. case HT_REG:
  1540. case HT_EVO:
  1541. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1542. p.expNext = 0;
  1543. }
  1544. break;
  1545. case HT_S:
  1546. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1547. p.expNext = 0;
  1548. }
  1549. break;
  1550. }
  1551. p.skillPoints = hd->homunculus.skillpts;
  1552. p.range = status_get_range( &hd->bl );
  1553. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1554. #endif
  1555. }
  1556. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1557. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1558. /// type:
  1559. /// unused
  1560. /// state:
  1561. /// 0 = pre-init
  1562. /// 1 = intimacy
  1563. /// 2 = hunger
  1564. /// 3 = accessory?
  1565. /// ? = ignored
  1566. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1567. { //[orn]
  1568. int fd = sd->fd;
  1569. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1570. hom_calc_skilltree(sd->hd, 0);
  1571. WFIFOHEAD(fd, packet_len(0x230));
  1572. WFIFOW(fd,0)=0x230;
  1573. WFIFOB(fd,2)=0;
  1574. WFIFOB(fd,3)=state;
  1575. WFIFOL(fd,4)=sd->hd->bl.id;
  1576. WFIFOL(fd,8)=param;
  1577. WFIFOSET(fd,packet_len(0x230));
  1578. }
  1579. int clif_homskillinfoblock(struct map_session_data *sd)
  1580. { //[orn]
  1581. struct homun_data *hd;
  1582. int fd = sd->fd;
  1583. int i, len=4;
  1584. nullpo_ret(sd);
  1585. hd = sd->hd;
  1586. if ( !hd )
  1587. return 0 ;
  1588. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1589. WFIFOW(fd,0)=0x235;
  1590. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1591. int id = hd->homunculus.hskill[i].id;
  1592. if( id != 0 ){
  1593. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1594. short idx = hom_skill_get_index(id);
  1595. if (idx == -1)
  1596. continue;
  1597. WFIFOW(fd,len ) = id;
  1598. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1599. WFIFOW(fd,len+4) = 0;
  1600. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1601. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1602. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1603. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1604. 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;
  1605. len+=37;
  1606. }
  1607. }
  1608. WFIFOW(fd,2)=len;
  1609. WFIFOSET(fd,len);
  1610. return 0;
  1611. }
  1612. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1613. { //[orn]
  1614. struct homun_data *hd;
  1615. int fd;
  1616. short idx = -1;
  1617. nullpo_retv(sd);
  1618. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1619. return;
  1620. fd = sd->fd;
  1621. hd = sd->hd;
  1622. WFIFOHEAD(fd, packet_len(0x239));
  1623. WFIFOW(fd,0) = 0x239;
  1624. WFIFOW(fd,2) = skill_id;
  1625. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1626. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1627. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1628. 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;
  1629. WFIFOSET(fd,packet_len(0x239));
  1630. }
  1631. /// Result of request to feed a homun/merc.
  1632. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1633. /// result:
  1634. /// 0 = failure
  1635. /// 1 = success
  1636. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1637. nullpo_retv( sd );
  1638. struct PACKET_ZC_FEED_MER p;
  1639. p.packetType = 0x22f;
  1640. p.result = fail;
  1641. p.itemId = client_nameid( foodid );
  1642. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1643. }
  1644. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1645. /// 0087 <walk start time>.L <walk data>.6B
  1646. void clif_walkok(struct map_session_data *sd)
  1647. {
  1648. int fd=sd->fd;
  1649. WFIFOHEAD(fd, packet_len(0x87));
  1650. WFIFOW(fd,0)=0x87;
  1651. WFIFOL(fd,2)=client_tick(gettick());
  1652. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1653. WFIFOSET(fd,packet_len(0x87));
  1654. }
  1655. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1656. struct status_change *sc = NULL;
  1657. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1658. clif_ally_only = true;
  1659. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1660. if(vd->cloth_color)
  1661. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1662. if(vd->body_style)
  1663. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1664. switch(bl->type) {
  1665. case BL_PC:
  1666. {
  1667. TBL_PC *sd = ((TBL_PC*)bl);
  1668. // clif_movepc(sd);
  1669. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1670. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1671. else if(sd->state.size==SZ_MEDIUM)
  1672. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1673. if (sd->status.robe)
  1674. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1675. }
  1676. break;
  1677. case BL_MOB:
  1678. {
  1679. TBL_MOB *md = ((TBL_MOB*)bl);
  1680. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1681. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1682. else if(md->special_state.size==SZ_MEDIUM)
  1683. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1684. }
  1685. break;
  1686. case BL_PET:
  1687. if(vd->head_bottom) // needed to display pet equip properly
  1688. clif_pet_equip_area((TBL_PET*)bl);
  1689. break;
  1690. }
  1691. clif_ally_only = false;
  1692. }
  1693. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1694. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1695. /// Note: unit must not be self
  1696. void clif_move(struct unit_data *ud)
  1697. {
  1698. unsigned char buf[16];
  1699. struct view_data* vd;
  1700. struct block_list* bl = ud->bl;
  1701. struct status_change *sc = NULL;
  1702. vd = status_get_viewdata(bl);
  1703. if (!vd )
  1704. return;
  1705. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1706. else if( vd->class_ == JT_INVISIBLE ){
  1707. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1708. if(disguised(bl)) {
  1709. WBUFW(buf,0)=0x86;
  1710. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1711. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1712. WBUFL(buf,12)=client_tick(gettick());
  1713. clif_send(buf, packet_len(0x86), bl, SELF);
  1714. }
  1715. return;
  1716. }
  1717. // Hide NPC from Maya Purple card
  1718. if (clif_npc_mayapurple(bl))
  1719. return;
  1720. if (ud->state.speed_changed) {
  1721. // Since we don't know how to update the speed of other objects,
  1722. // use the old walk packet to update the data.
  1723. ud->state.speed_changed = 0;
  1724. clif_move2(bl, vd, ud);
  1725. return;
  1726. }
  1727. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1728. clif_ally_only = true;
  1729. WBUFW(buf,0)=0x86;
  1730. WBUFL(buf,2)=bl->id;
  1731. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1732. WBUFL(buf,12)=client_tick(gettick());
  1733. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1734. if (disguised(bl)) {
  1735. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1736. clif_send(buf, packet_len(0x86), bl, SELF);
  1737. }
  1738. clif_ally_only = false;
  1739. }
  1740. /*==========================================
  1741. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1742. *------------------------------------------*/
  1743. static TIMER_FUNC(clif_delayquit){
  1744. struct map_session_data *sd = NULL;
  1745. //Remove player from map server
  1746. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1747. map_quit(sd);
  1748. return 0;
  1749. }
  1750. /*==========================================
  1751. *
  1752. *------------------------------------------*/
  1753. void clif_quitsave(int fd,struct map_session_data *sd) {
  1754. if (!battle_config.prevent_logout ||
  1755. sd->canlog_tick == 0 ||
  1756. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1757. map_quit(sd);
  1758. else if (session_isValid(sd->fd)) {
  1759. //Disassociate session from player (session is deleted after this function was called)
  1760. //And set a timer to make him quit later.
  1761. session[sd->fd]->session_data = NULL;
  1762. sd->fd = 0;
  1763. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1764. }
  1765. }
  1766. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1767. /// 0091 <map name>.16B <x>.W <y>.W
  1768. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1769. {
  1770. nullpo_retv(sd);
  1771. int fd = sd->fd;
  1772. WFIFOHEAD(fd,packet_len(0x91));
  1773. WFIFOW(fd,0) = 0x91;
  1774. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1775. WFIFOW(fd,18) = x;
  1776. WFIFOW(fd,20) = y;
  1777. WFIFOSET(fd,packet_len(0x91));
  1778. }
  1779. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1780. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1781. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1782. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1783. {
  1784. int fd;
  1785. #if PACKETVER >= 20170315
  1786. int cmd = 0xac7;
  1787. #else
  1788. int cmd = 0x92;
  1789. #endif
  1790. nullpo_retv(sd);
  1791. fd = sd->fd;
  1792. WFIFOHEAD(fd,packet_len(cmd));
  1793. WFIFOW(fd,0) = cmd;
  1794. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1795. WFIFOW(fd,18) = x;
  1796. WFIFOW(fd,20) = y;
  1797. WFIFOL(fd,22) = htonl(ip);
  1798. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1799. #if PACKETVER >= 20170315
  1800. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1801. #endif
  1802. WFIFOSET(fd,packet_len(cmd));
  1803. }
  1804. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1805. /// This function combines both calls and allows to simplify the calling code
  1806. void clif_blown(struct block_list *bl)
  1807. {
  1808. clif_slide(bl, bl->x, bl->y);
  1809. clif_fixpos(bl);
  1810. }
  1811. /// Visually moves(slides) a character to x,y. If the target cell
  1812. /// isn't walkable, the char doesn't move at all. If the char is
  1813. /// sitting it will stand up (ZC_STOPMOVE).
  1814. /// 0088 <id>.L <x>.W <y>.W
  1815. void clif_fixpos(struct block_list *bl)
  1816. {
  1817. unsigned char buf[10];
  1818. nullpo_retv(bl);
  1819. WBUFW(buf,0) = 0x88;
  1820. WBUFL(buf,2) = bl->id;
  1821. WBUFW(buf,6) = bl->x;
  1822. WBUFW(buf,8) = bl->y;
  1823. clif_send(buf, packet_len(0x88), bl, AREA);
  1824. if( disguised(bl) ) {
  1825. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1826. clif_send(buf, packet_len(0x88), bl, SELF);
  1827. }
  1828. }
  1829. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1830. /// 00c4 <shop id>.L
  1831. void clif_npcbuysell(struct map_session_data* sd, int id)
  1832. {
  1833. int fd;
  1834. nullpo_retv(sd);
  1835. fd=sd->fd;
  1836. WFIFOHEAD(fd, packet_len(0xc4));
  1837. WFIFOW(fd,0)=0xc4;
  1838. WFIFOL(fd,2)=id;
  1839. WFIFOSET(fd,packet_len(0xc4));
  1840. }
  1841. /// Presents list of items, that can be bought in an NPC shop.
  1842. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1843. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1844. nullpo_retv( sd );
  1845. nullpo_retv( nd );
  1846. int fd = sd->fd;
  1847. if( !session_isActive( fd ) ){
  1848. return;
  1849. }
  1850. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1851. WFIFOHEAD( fd, len );
  1852. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1853. p->packetType = 0xc6;
  1854. int count = 0;
  1855. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1856. int val = nd->u.shop.shop_item[i].value;
  1857. p->items[count].price = val;
  1858. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1859. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1860. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1861. count++;
  1862. }
  1863. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1864. WFIFOSET( fd, p->packetLength );
  1865. }
  1866. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1867. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1868. void clif_selllist(struct map_session_data *sd)
  1869. {
  1870. int fd,i,c=0,val;
  1871. struct npc_data *nd;
  1872. nullpo_retv(sd);
  1873. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1874. return;
  1875. fd=sd->fd;
  1876. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1877. WFIFOW(fd,0)=0xc7;
  1878. for( i = 0; i < MAX_INVENTORY; i++ )
  1879. {
  1880. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1881. {
  1882. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1883. continue;
  1884. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1885. val = 0;
  1886. else {
  1887. val = sd->inventory_data[i]->value_sell;
  1888. if( val < 0 )
  1889. continue;
  1890. }
  1891. WFIFOW(fd,4+c*10)=i+2;
  1892. WFIFOL(fd,6+c*10)=val;
  1893. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1894. c++;
  1895. }
  1896. }
  1897. WFIFOW(fd,2)=c*10+4;
  1898. WFIFOSET(fd,WFIFOW(fd,2));
  1899. }
  1900. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1901. /// 09d4
  1902. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1903. // TODO: State tracking?
  1904. sd->npc_shopid = 0;
  1905. }
  1906. /**
  1907. * Presents list of items, that can be sold to a Market shop.
  1908. * @author: Ind and Yommy
  1909. **/
  1910. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1911. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1912. #if PACKETVER >= 20131223
  1913. nullpo_retv( sd );
  1914. nullpo_retv( nd );
  1915. if( sd->state.trading ){
  1916. return;
  1917. }
  1918. int fd = sd->fd;
  1919. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1920. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1921. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1922. int count = 0;
  1923. for( int i = 0; i < nd->u.shop.count; i++ ){
  1924. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1925. if( !item->nameid ){
  1926. continue;
  1927. }
  1928. struct item_data *id = itemdb_exists( item->nameid );
  1929. if( !id ){
  1930. continue;
  1931. }
  1932. p->list[count].nameid = client_nameid( item->nameid );
  1933. p->list[count].type = itemtype( item->nameid );
  1934. p->list[count].price = item->value;
  1935. p->list[count].qty = item->qty;
  1936. p->list[count].weight = id->weight;
  1937. count++;
  1938. }
  1939. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  1940. WFIFOSET( fd, p->packetLength );
  1941. sd->state.trading = 1;
  1942. #endif
  1943. }
  1944. /// Closes the Market shop window.
  1945. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1946. nullpo_retv(sd);
  1947. sd->npc_shopid = 0;
  1948. sd->state.trading = 0;
  1949. }
  1950. /// Purchase item from Market shop.
  1951. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  1952. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1953. #if PACKETVER >= 20131223
  1954. nullpo_retv( sd );
  1955. nullpo_retv( list );
  1956. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  1957. nullpo_retv( nd );
  1958. int fd = sd->fd;
  1959. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + n * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub ) );
  1960. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)WFIFOP( fd, 0 );
  1961. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  1962. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  1963. p->result = ( res == 0 ? 0 : -1 );
  1964. #else
  1965. p->result = ( res == 0 ? 1 : 0 );
  1966. #endif
  1967. int count = 0;
  1968. if( p->result ){
  1969. for( int i = 0, j; i < n; i++ ){
  1970. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  1971. // Not found
  1972. if( j == nd->u.shop.count ){
  1973. continue;
  1974. }
  1975. p->list[count].ITID = client_nameid( list[i].nameid );
  1976. p->list[count].qty = list[i].qty;
  1977. p->list[count].price = nd->u.shop.shop_item[j].value;
  1978. count++;
  1979. }
  1980. }
  1981. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  1982. WFIFOSET( fd, p->PacketLength );
  1983. #endif
  1984. }
  1985. /// Purchase item from Market shop.
  1986. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  1987. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1988. #if PACKETVER >= 20131223
  1989. nullpo_retv( sd );
  1990. if( !sd->npc_shopid ){
  1991. return;
  1992. }
  1993. const struct packet_npc_market_purchase *p = (struct packet_npc_market_purchase *)RFIFOP( fd, 0 );
  1994. int count = ( p->PacketLength - sizeof( struct packet_npc_market_purchase ) ) / sizeof( struct packet_npc_market_purchase_sub );
  1995. struct s_npc_buy_list *list;
  1996. CREATE( list, struct s_npc_buy_list, count );
  1997. // Sadly order is reverse
  1998. for( int i = 0; i < count; i++ ){
  1999. list[i].nameid = p->list[i].ITID;
  2000. list[i].qty = p->list[i].qty;
  2001. }
  2002. uint8 res = npc_buylist( sd, count, list );
  2003. clif_npc_market_purchase_ack( sd, res, count, list );
  2004. aFree( list );
  2005. #endif
  2006. }
  2007. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2008. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2009. /// Client behavior (dialog window):
  2010. /// - disable mouse targeting
  2011. /// - open the dialog window
  2012. /// - set npcid of dialog window (0 by default)
  2013. /// - if set to clear on next mes, clear contents
  2014. /// - append this text
  2015. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  2016. {
  2017. int fd = sd->fd;
  2018. int slen = strlen(mes) + 9;
  2019. WFIFOHEAD(fd, slen);
  2020. WFIFOW(fd,0)=0xb4;
  2021. WFIFOW(fd,2)=slen;
  2022. WFIFOL(fd,4)=npcid;
  2023. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2024. WFIFOSET(fd,WFIFOW(fd,2));
  2025. }
  2026. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2027. /// 00b5 <npc id>.L
  2028. /// Client behavior (dialog window):
  2029. /// - disable mouse targeting
  2030. /// - open the dialog window
  2031. /// - add 'next' button
  2032. /// When 'next' is pressed:
  2033. /// - 00B9 <npcid of dialog window>.L
  2034. /// - set to clear on next mes
  2035. /// - remove 'next' button
  2036. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2037. {
  2038. int fd;
  2039. nullpo_retv(sd);
  2040. fd=sd->fd;
  2041. WFIFOHEAD(fd, packet_len(0xb5));
  2042. WFIFOW(fd,0)=0xb5;
  2043. WFIFOL(fd,2)=npcid;
  2044. WFIFOSET(fd,packet_len(0xb5));
  2045. }
  2046. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2047. /// 00b6 <npc id>.L
  2048. /// Client behavior:
  2049. /// - if dialog window is open:
  2050. /// - remove 'next' button
  2051. /// - add 'close' button
  2052. /// - else:
  2053. /// - enable mouse targeting
  2054. /// - close the dialog window
  2055. /// - close the menu window
  2056. /// When 'close' is pressed:
  2057. /// - enable mouse targeting
  2058. /// - close the dialog window
  2059. /// - close the menu window
  2060. /// - 0146 <npcid of dialog window>.L
  2061. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2062. {
  2063. int fd;
  2064. nullpo_retv(sd);
  2065. fd=sd->fd;
  2066. WFIFOHEAD(fd, packet_len(0xb6));
  2067. WFIFOW(fd,0)=0xb6;
  2068. WFIFOL(fd,2)=npcid;
  2069. WFIFOSET(fd,packet_len(0xb6));
  2070. }
  2071. /**
  2072. * Close script when player is idle
  2073. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2074. * @author [Ind/Hercules]
  2075. * @param sd : player pointer
  2076. * @param npcid : npc gid to close
  2077. */
  2078. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2079. {
  2080. struct s_packet_db* info;
  2081. int16 len;
  2082. int cmd = 0;
  2083. int fd;
  2084. nullpo_retv(sd);
  2085. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2086. if(!cmd) cmd = 0x8d6; //default
  2087. info = &packet_db[cmd];
  2088. len = info->len;
  2089. fd = sd->fd;
  2090. WFIFOHEAD(fd, len);
  2091. WFIFOW(fd,0)=0x8d6;
  2092. WFIFOL(fd,info->pos[0])=npcid;
  2093. WFIFOSET(fd,len);
  2094. }
  2095. /*==========================================
  2096. *
  2097. *------------------------------------------*/
  2098. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2099. unsigned char *buf;
  2100. int fd = sd->fd;
  2101. sd->state.using_fake_npc = 1;
  2102. WFIFOHEAD(fd, packet_len(0x78));
  2103. buf = WFIFOP(fd,0);
  2104. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2105. WBUFW(buf,0)=0x78;
  2106. #if PACKETVER >= 20071106
  2107. WBUFB(buf,2) = 0; // object type
  2108. buf = WFIFOP(fd,1);
  2109. #endif
  2110. WBUFL(buf,2)=npcid;
  2111. WBUFW(buf,14)=111;
  2112. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2113. WBUFB(buf,49)=5;
  2114. WBUFB(buf,50)=5;
  2115. WFIFOSET(fd, packet_len(0x78));
  2116. }
  2117. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2118. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2119. /// Client behavior:
  2120. /// - disable mouse targeting
  2121. /// - close the menu window
  2122. /// - open the menu window
  2123. /// - add options to the menu (separated in the text by ":")
  2124. /// - set npcid of menu window
  2125. /// - if dialog window is open:
  2126. /// - remove 'next' button
  2127. /// When 'ok' is pressed:
  2128. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2129. /// - close the menu window
  2130. /// When 'cancel' is pressed:
  2131. /// - 00B8 <npcid of menu window>.L <-1>.B
  2132. /// - enable mouse targeting
  2133. /// - close a bunch of windows...
  2134. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2135. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2136. /// TODO investigate behavior of other windows [FlavioJS]
  2137. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2138. {
  2139. int fd = sd->fd;
  2140. int slen = strlen(mes) + 9;
  2141. struct block_list *bl = NULL;
  2142. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2143. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2144. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2145. clif_sendfakenpc(sd, npcid);
  2146. WFIFOHEAD(fd, slen);
  2147. WFIFOW(fd,0)=0xb7;
  2148. WFIFOW(fd,2)=slen;
  2149. WFIFOL(fd,4)=npcid;
  2150. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2151. WFIFOSET(fd,WFIFOW(fd,2));
  2152. }
  2153. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2154. /// 0142 <npc id>.L
  2155. /// Client behavior (inputnum window):
  2156. /// - if npcid exists in the client:
  2157. /// - open the inputnum window
  2158. /// - set npcid of inputnum window
  2159. /// When 'ok' is pressed:
  2160. /// - if inputnum window has text:
  2161. /// - if npcid exists in the client:
  2162. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2163. /// - close inputnum window
  2164. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2165. {
  2166. int fd;
  2167. struct block_list *bl = NULL;
  2168. nullpo_retv(sd);
  2169. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2170. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2171. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2172. clif_sendfakenpc(sd, npcid);
  2173. fd=sd->fd;
  2174. WFIFOHEAD(fd, packet_len(0x142));
  2175. WFIFOW(fd,0)=0x142;
  2176. WFIFOL(fd,2)=npcid;
  2177. WFIFOSET(fd,packet_len(0x142));
  2178. }
  2179. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2180. /// 01d4 <npc id>.L
  2181. /// Client behavior (inputstr window):
  2182. /// - if npcid is 0 or npcid exists in the client:
  2183. /// - open the inputstr window
  2184. /// - set npcid of inputstr window
  2185. /// When 'ok' is pressed:
  2186. /// - if inputstr window has text and isn't an insult(manner.txt):
  2187. /// - if npcid is 0 or npcid exists in the client:
  2188. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2189. /// - close inputstr window
  2190. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2191. {
  2192. int fd;
  2193. struct block_list *bl = NULL;
  2194. nullpo_retv(sd);
  2195. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2196. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2197. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2198. clif_sendfakenpc(sd, npcid);
  2199. fd=sd->fd;
  2200. WFIFOHEAD(fd, packet_len(0x1d4));
  2201. WFIFOW(fd,0)=0x1d4;
  2202. WFIFOL(fd,2)=npcid;
  2203. WFIFOSET(fd,packet_len(0x1d4));
  2204. }
  2205. /// Marks a position on client's minimap (ZC_COMPASS).
  2206. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2207. /// npc id:
  2208. /// is ignored in the client
  2209. /// type:
  2210. /// 0 = display mark for 15 seconds
  2211. /// 1 = display mark until dead or teleported
  2212. /// 2 = remove mark
  2213. /// color:
  2214. /// 0x00RRGGBB
  2215. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2216. {
  2217. int fd;
  2218. nullpo_retv(sd);
  2219. fd=sd->fd;
  2220. WFIFOHEAD(fd, packet_len(0x144));
  2221. WFIFOW(fd,0)=0x144;
  2222. WFIFOL(fd,2)=npc_id;
  2223. WFIFOL(fd,6)=type;
  2224. WFIFOL(fd,10)=x;
  2225. WFIFOL(fd,14)=y;
  2226. WFIFOB(fd,18)=id;
  2227. WFIFOL(fd,19)=color;
  2228. WFIFOSET(fd,packet_len(0x144));
  2229. }
  2230. /// Displays an illustration image.
  2231. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2232. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2233. /// type:
  2234. /// 0 = bottom left corner
  2235. /// 1 = bottom middle
  2236. /// 2 = bottom right corner
  2237. /// 3 = middle of screen, inside a movable window
  2238. /// 4 = middle of screen, movable with a close button, chrome-less
  2239. /// 255 = clear all displayed cutins
  2240. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2241. {
  2242. int fd;
  2243. nullpo_retv(sd);
  2244. fd=sd->fd;
  2245. WFIFOHEAD(fd, packet_len(0x1b3));
  2246. WFIFOW(fd,0)=0x1b3;
  2247. strncpy(WFIFOCP(fd,2),image,64);
  2248. WFIFOB(fd,66)=type;
  2249. WFIFOSET(fd,packet_len(0x1b3));
  2250. }
  2251. /*==========================================
  2252. * Fills in card data from the given item and into the buffer. [Skotlex]
  2253. *------------------------------------------*/
  2254. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2255. nullpo_retv( buf );
  2256. // Blank data
  2257. if( item == nullptr ){
  2258. buf->card[0] = 0;
  2259. buf->card[1] = 0;
  2260. buf->card[2] = 0;
  2261. buf->card[3] = 0;
  2262. return;
  2263. }
  2264. // Pet eggs
  2265. if( item->card[0] == CARD0_PET ){
  2266. buf->card[0] = 0;
  2267. buf->card[1] = 0;
  2268. // Pet intimacy
  2269. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2270. buf->card[2] = item->card[3] >> 1;
  2271. // Pet renamed flag
  2272. buf->card[3] = item->card[3] & 1;
  2273. return;
  2274. }
  2275. // Forged/created items
  2276. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2277. buf->card[0] = item->card[0];
  2278. buf->card[1] = item->card[1];
  2279. buf->card[2] = item->card[2];
  2280. buf->card[3] = item->card[3];
  2281. return;
  2282. }
  2283. int i = 0, j;
  2284. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2285. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2286. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2287. }
  2288. // Normal items.
  2289. for( int k = 0; k < 4; k++, i++ ){
  2290. if( item->card[i] > 0 ){
  2291. buf->card[k] = client_nameid( item->card[i] );
  2292. }else{
  2293. buf->card[k] = 0;
  2294. }
  2295. }
  2296. }
  2297. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2298. /// A maximum of 5 random options can be supported.
  2299. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2300. nullpo_retr( 0, it );
  2301. uint8 count = 0;
  2302. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2303. if( it->option[i].id ){
  2304. buf[i].index = it->option[i].id; // OptIndex
  2305. buf[i].value = it->option[i].value; // Value
  2306. buf[i].param = it->option[i].param; // Param1
  2307. count++;
  2308. }else{
  2309. buf[i].index = 0;
  2310. buf[i].value = 0;
  2311. buf[i].param = 0;
  2312. }
  2313. }
  2314. #if MAX_ITEM_RDM_OPT < 5
  2315. for( ; i < 5; i++ ){
  2316. buf[i].index = 0; // OptIndex
  2317. buf[i].value = 0; // Value
  2318. buf[i].param = 0; // Param1
  2319. }
  2320. #endif
  2321. return count;
  2322. }
  2323. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2324. /// 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)
  2325. /// 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)
  2326. /// 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)
  2327. /// 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)
  2328. /// 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)
  2329. /// 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)
  2330. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2331. nullpo_retv( sd );
  2332. int fd = sd->fd;
  2333. if( !session_isActive( fd ) ){
  2334. return;
  2335. }
  2336. struct packet_additem p;
  2337. if( fail ){
  2338. p = {};
  2339. }else{
  2340. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2341. return;
  2342. }
  2343. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2344. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2345. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2346. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2347. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2348. p.location = pc_equippoint(sd,n);
  2349. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2350. #if PACKETVER >= 20061218
  2351. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2352. #if PACKETVER >= 20071002
  2353. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2354. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2355. */
  2356. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2357. #if PACKETVER >= 20150226
  2358. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2359. #if PACKETVER >= 20160921
  2360. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2361. p.look = sd->inventory_data[n]->look;
  2362. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2363. p.enchantgrade = sd->inventory.u.items_inventory[n].enchantgrade;
  2364. #endif
  2365. #endif
  2366. #endif
  2367. #endif
  2368. #endif
  2369. }
  2370. p.PacketType = additemType;
  2371. p.Index = client_index( n );
  2372. p.count = amount;
  2373. p.result = fail;
  2374. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2375. }
  2376. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2377. /// 00af <index>.W <amount>.W
  2378. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2379. {
  2380. int fd;
  2381. nullpo_retv(sd);
  2382. fd=sd->fd;
  2383. WFIFOHEAD(fd, packet_len(0xaf));
  2384. WFIFOW(fd,0)=0xaf;
  2385. WFIFOW(fd,2)=n+2;
  2386. WFIFOW(fd,4)=amount;
  2387. WFIFOSET(fd,packet_len(0xaf));
  2388. }
  2389. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2390. /// 07fa <delete type>.W <index>.W <amount>.W
  2391. /// delete type:
  2392. /// 0 = Normal
  2393. /// 1 = Item used for a skill
  2394. /// 2 = Refine failed
  2395. /// 3 = Material changed
  2396. /// 4 = Moved to storage
  2397. /// 5 = Moved to cart
  2398. /// 6 = Item sold
  2399. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2400. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2401. {
  2402. #if PACKETVER < 20091117
  2403. clif_dropitem(sd,n,amount);
  2404. #else
  2405. int fd;
  2406. nullpo_retv(sd);
  2407. fd=sd->fd;
  2408. WFIFOHEAD(fd, packet_len(0x7fa));
  2409. WFIFOW(fd,0)=0x7fa;
  2410. WFIFOW(fd,2)=reason;
  2411. WFIFOW(fd,4)=n+2;
  2412. WFIFOW(fd,6)=amount;
  2413. WFIFOSET(fd,packet_len(0x7fa));
  2414. #endif
  2415. }
  2416. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2417. nullpo_retv( p );
  2418. nullpo_retv( it );
  2419. nullpo_retv( id );
  2420. p->index = idx;
  2421. p->ITID = client_nameid( it->nameid );
  2422. p->type = itemtype( it->nameid );
  2423. #if PACKETVER < 20120925
  2424. p->IsIdentified = it->identify ? 1 : 0;
  2425. #endif
  2426. p->location = eqp_pos;
  2427. p->WearState = it->equip;
  2428. #if PACKETVER < 20120925
  2429. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2430. #endif
  2431. p->RefiningLevel = it->refine;
  2432. clif_addcards( &p->slot, it );
  2433. #if PACKETVER >= 20071002
  2434. p->HireExpireDate = it->expire_time;
  2435. #endif
  2436. #if PACKETVER >= 20080102
  2437. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2438. #endif
  2439. #if PACKETVER >= 20100629
  2440. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2441. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2442. #endif
  2443. #if PACKETVER >= 20120925
  2444. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2445. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2446. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2447. p->Flag.SpareBits = 0;
  2448. #endif
  2449. #if PACKETVER >= 20150226
  2450. p->option_count = clif_add_random_options( p->option_data, it );
  2451. #endif
  2452. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2453. p->enchantgrade = it->enchantgrade;
  2454. #endif
  2455. }
  2456. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2457. nullpo_retv(p);
  2458. nullpo_retv(i);
  2459. nullpo_retv(id);
  2460. p->index = idx;
  2461. p->ITID = client_nameid( i->nameid );
  2462. p->type = itemtype( i->nameid );
  2463. #if PACKETVER < 20120925
  2464. p->IsIdentified = i->identify ? 1 : 0;
  2465. #endif
  2466. p->count = i->amount;
  2467. p->WearState = id->equip;
  2468. #if PACKETVER >= 5
  2469. clif_addcards( &p->slot, i );
  2470. #endif
  2471. #if PACKETVER >= 20080102
  2472. p->HireExpireDate = i->expire_time;
  2473. #endif
  2474. #if PACKETVER >= 20120925
  2475. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2476. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2477. p->Flag.SpareBits = 0;
  2478. #endif
  2479. }
  2480. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2481. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2482. nullpo_retv(sd);
  2483. nullpo_retv(name);
  2484. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2485. memset(buf, 0, sizeof(buf));
  2486. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2487. p->packetType = HEADER_ZC_INVENTORY_START;
  2488. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2489. p->invType = type;
  2490. #endif
  2491. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2492. int strLen = (int)safestrnlen(name, 24) + 1;
  2493. if (strLen > 24)
  2494. strLen = 24;
  2495. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2496. p->packetLength = len;
  2497. safestrncpy(p->name, name, strLen);
  2498. #else
  2499. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2500. safestrncpy(p->name, name, NAME_LENGTH);
  2501. #endif
  2502. clif_send( p, len, &sd->bl, SELF );
  2503. #endif
  2504. }
  2505. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2506. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2507. nullpo_retv(sd);
  2508. struct PACKET_ZC_INVENTORY_END p;
  2509. p.packetType = HEADER_ZC_INVENTORY_END;
  2510. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2511. p.invType = type;
  2512. #endif
  2513. p.flag = 0;
  2514. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2515. #endif
  2516. }
  2517. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2518. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2519. void clif_inventorylist( struct map_session_data *sd ){
  2520. nullpo_retv( sd );
  2521. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2522. e_inventory_type type = INVTYPE_INVENTORY;
  2523. clif_inventoryStart( sd, type, "" );
  2524. #endif
  2525. static struct packet_itemlist_normal itemlist_normal;
  2526. static struct packet_itemlist_equip itemlist_equip;
  2527. int equip = 0;
  2528. int normal = 0;
  2529. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2530. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2531. continue;
  2532. }
  2533. // Non-stackable (Equippable)
  2534. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2535. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2536. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2537. itemlist_equip.PacketType = inventorylistequipType;
  2538. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2539. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2540. itemlist_equip.invType = type;
  2541. #endif
  2542. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2543. equip = 0;
  2544. }
  2545. // Stackable (Normal)
  2546. }else{
  2547. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2548. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2549. itemlist_normal.PacketType = inventorylistnormalType;
  2550. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2551. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2552. itemlist_normal.invType = type;
  2553. #endif
  2554. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2555. normal = 0;
  2556. }
  2557. }
  2558. }
  2559. if( normal ){
  2560. itemlist_normal.PacketType = inventorylistnormalType;
  2561. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2562. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2563. itemlist_normal.invType = type;
  2564. #endif
  2565. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2566. }
  2567. if( sd->equip_index[EQI_AMMO] >= 0 )
  2568. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2569. if( equip ) {
  2570. itemlist_equip.PacketType = inventorylistequipType;
  2571. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2572. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2573. itemlist_equip.invType = type;
  2574. #endif
  2575. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2576. }
  2577. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2578. clif_inventoryEnd( sd, type );
  2579. #endif
  2580. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2581. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2582. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2583. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2584. continue;
  2585. if ( sd->inventory.u.items_inventory[i].favorite )
  2586. clif_favorite_item(sd, i);
  2587. }
  2588. #endif
  2589. }
  2590. //Required when items break/get-repaired. Only sends equippable item list.
  2591. void clif_equiplist( struct map_session_data *sd ){
  2592. // TODO: implement again => only send equip part
  2593. clif_inventorylist( sd );
  2594. }
  2595. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2596. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2597. e_inventory_type type = INVTYPE_STORAGE;
  2598. clif_inventoryStart( sd, type, storename );
  2599. #endif
  2600. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2601. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2602. int equip = 0;
  2603. int normal = 0;
  2604. for( int i = 0; i < items_length; i++ ){
  2605. if( items[i].nameid == 0 ){
  2606. continue;
  2607. }
  2608. struct item_data* id = itemdb_search( items[i].nameid );
  2609. // Non-stackable (Equippable)
  2610. if( !itemdb_isstackable2( id ) ){
  2611. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2612. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2613. storage_itemlist_equip.PacketType = storageListEquipType;
  2614. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2615. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2616. storage_itemlist_equip.invType = type;
  2617. #elif PACKETVER >= 20120925
  2618. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2619. #endif
  2620. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2621. equip = 0;
  2622. }
  2623. // Stackable (Normal)
  2624. }else{
  2625. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2626. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2627. storage_itemlist_normal.PacketType = storageListNormalType;
  2628. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2629. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2630. storage_itemlist_normal.invType = type;
  2631. #elif PACKETVER >= 20120925
  2632. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2633. #endif
  2634. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2635. normal = 0;
  2636. }
  2637. }
  2638. }
  2639. if( normal ){
  2640. storage_itemlist_normal.PacketType = storageListNormalType;
  2641. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2642. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2643. storage_itemlist_normal.invType = type;
  2644. #elif PACKETVER >= 20120925
  2645. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2646. #endif
  2647. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2648. }
  2649. if( equip ) {
  2650. storage_itemlist_equip.PacketType = storageListEquipType;
  2651. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2652. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2653. storage_itemlist_equip.invType = type;
  2654. #elif PACKETVER >= 20120925
  2655. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2656. #endif
  2657. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2658. }
  2659. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2660. clif_inventoryEnd( sd, type );
  2661. #endif
  2662. }
  2663. void clif_cartlist( struct map_session_data *sd ){
  2664. nullpo_retv( sd );
  2665. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2666. e_inventory_type type = INVTYPE_CART;
  2667. clif_inventoryStart( sd, type, "" );
  2668. #endif
  2669. static struct packet_itemlist_normal itemlist_normal;
  2670. static struct packet_itemlist_equip itemlist_equip;
  2671. int normal = 0;
  2672. int equip = 0;
  2673. for( int i = 0; i < MAX_CART; i++ ){
  2674. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2675. continue;
  2676. }
  2677. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2678. // Non-stackable (Equippable)
  2679. if( !itemdb_isstackable2(id) ){
  2680. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2681. // Stackable (Normal)
  2682. }else{
  2683. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2684. }
  2685. }
  2686. if( normal ){
  2687. itemlist_normal.PacketType = cartlistnormalType;
  2688. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2689. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2690. itemlist_normal.invType = type;
  2691. #endif
  2692. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2693. }
  2694. if( equip ){
  2695. itemlist_equip.PacketType = cartlistequipType;
  2696. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2697. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2698. itemlist_equip.invType = type;
  2699. #endif
  2700. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2701. }
  2702. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2703. clif_inventoryEnd( sd, type );
  2704. #endif
  2705. }
  2706. /// Removes cart (ZC_CARTOFF).
  2707. /// 012b
  2708. /// Client behaviour:
  2709. /// Closes the cart storage and removes all it's items from memory.
  2710. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2711. void clif_clearcart(int fd)
  2712. {
  2713. WFIFOHEAD(fd, packet_len(0x12b));
  2714. WFIFOW(fd,0) = 0x12b;
  2715. WFIFOSET(fd, packet_len(0x12b));
  2716. }
  2717. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2718. /// 01eb <account id>.L <x>.W <y>.W
  2719. void clif_guild_xy(struct map_session_data *sd)
  2720. {
  2721. unsigned char buf[10];
  2722. nullpo_retv(sd);
  2723. WBUFW(buf,0)=0x1eb;
  2724. WBUFL(buf,2)=sd->status.account_id;
  2725. WBUFW(buf,6)=sd->bl.x;
  2726. WBUFW(buf,8)=sd->bl.y;
  2727. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2728. }
  2729. /*==========================================
  2730. * Sends x/y dot to a single fd. [Skotlex]
  2731. *------------------------------------------*/
  2732. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2733. {
  2734. if( sd->bg_id )
  2735. return;
  2736. WFIFOHEAD(fd,packet_len(0x1eb));
  2737. WFIFOW(fd,0)=0x1eb;
  2738. WFIFOL(fd,2)=sd->status.account_id;
  2739. WFIFOW(fd,6)=sd->bl.x;
  2740. WFIFOW(fd,8)=sd->bl.y;
  2741. WFIFOSET(fd,packet_len(0x1eb));
  2742. }
  2743. // Guild XY locators [Valaris]
  2744. void clif_guild_xy_remove(struct map_session_data *sd)
  2745. {
  2746. unsigned char buf[10];
  2747. nullpo_retv(sd);
  2748. WBUFW(buf,0)=0x1eb;
  2749. WBUFL(buf,2)=sd->status.account_id;
  2750. WBUFW(buf,6)=-1;
  2751. WBUFW(buf,8)=-1;
  2752. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2753. }
  2754. /*==========================================
  2755. *
  2756. *------------------------------------------*/
  2757. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2758. {
  2759. struct map_session_data *sd, *tsd;
  2760. #if PACKETVER < 20100126
  2761. const int cmd = 0x106;
  2762. #else
  2763. const int cmd = 0x80e;
  2764. #endif
  2765. sd = va_arg(ap, struct map_session_data *);
  2766. tsd = (TBL_PC *)bl;
  2767. nullpo_ret(sd);
  2768. nullpo_ret(tsd);
  2769. if( !session_isActive(tsd->fd) || tsd == sd )
  2770. return 0;
  2771. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2772. return 0;
  2773. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2774. WFIFOW(tsd->fd,0) = cmd;
  2775. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2776. #if PACKETVER < 20100126
  2777. if( sd->battle_status.max_hp > INT16_MAX )
  2778. { //To correctly display the %hp bar. [Skotlex]
  2779. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2780. WFIFOW(tsd->fd,8) = 100;
  2781. } else {
  2782. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2783. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2784. }
  2785. #else
  2786. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2787. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2788. #endif
  2789. WFIFOSET(tsd->fd,packet_len(cmd));
  2790. return 0;
  2791. }
  2792. /*==========================================
  2793. * Server tells all players that are allowed to view HP bars
  2794. * and are nearby 'sd' that 'sd' hp bar was updated.
  2795. *------------------------------------------*/
  2796. static int clif_hpmeter(struct map_session_data *sd)
  2797. {
  2798. nullpo_ret(sd);
  2799. 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);
  2800. return 0;
  2801. }
  2802. /// Notifies client of a character parameter change.
  2803. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2804. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2805. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2806. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2807. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2808. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2809. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2810. /// TODO: Extract individual packets.
  2811. /// FIXME: Packet lengths from packet_len(cmd)
  2812. void clif_updatestatus(struct map_session_data *sd,int type)
  2813. {
  2814. int fd,len=8;
  2815. nullpo_retv(sd);
  2816. fd=sd->fd;
  2817. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2818. return;
  2819. WFIFOHEAD(fd, 14);
  2820. WFIFOW(fd,0)=0xb0;
  2821. WFIFOW(fd,2)=type;
  2822. switch(type){
  2823. // 00b0
  2824. case SP_WEIGHT:
  2825. pc_updateweightstatus(sd);
  2826. WFIFOHEAD(fd,14);
  2827. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2828. WFIFOW(fd,2)=type;
  2829. WFIFOL(fd,4)=sd->weight;
  2830. break;
  2831. case SP_MAXWEIGHT:
  2832. WFIFOL(fd,4)=sd->max_weight;
  2833. break;
  2834. case SP_SPEED:
  2835. WFIFOL(fd,4)=sd->battle_status.speed;
  2836. break;
  2837. case SP_BASELEVEL:
  2838. WFIFOL(fd,4)=sd->status.base_level;
  2839. break;
  2840. case SP_JOBLEVEL:
  2841. WFIFOL(fd,4)=sd->status.job_level;
  2842. break;
  2843. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2844. WFIFOL(fd,4)=sd->status.karma;
  2845. break;
  2846. case SP_MANNER:
  2847. WFIFOL(fd,4)=sd->status.manner;
  2848. break;
  2849. case SP_STATUSPOINT:
  2850. WFIFOL(fd,4)=sd->status.status_point;
  2851. break;
  2852. case SP_SKILLPOINT:
  2853. WFIFOL(fd,4)=sd->status.skill_point;
  2854. break;
  2855. case SP_HIT:
  2856. WFIFOL(fd,4)=sd->battle_status.hit;
  2857. break;
  2858. case SP_FLEE1:
  2859. WFIFOL(fd,4)=sd->battle_status.flee;
  2860. break;
  2861. case SP_FLEE2:
  2862. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2863. break;
  2864. case SP_MAXHP:
  2865. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2866. break;
  2867. case SP_MAXSP:
  2868. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2869. break;
  2870. case SP_HP:
  2871. // On officials the HP never go below 1, even if you die [Lemongrass]
  2872. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2873. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2874. break;
  2875. case SP_SP:
  2876. WFIFOL(fd,4)=sd->battle_status.sp;
  2877. break;
  2878. case SP_ASPD:
  2879. WFIFOL(fd,4)=sd->battle_status.amotion;
  2880. break;
  2881. case SP_ATK1:
  2882. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2883. break;
  2884. case SP_DEF1:
  2885. WFIFOL(fd,4)=pc_leftside_def(sd);
  2886. break;
  2887. case SP_MDEF1:
  2888. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2889. break;
  2890. case SP_ATK2:
  2891. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2892. break;
  2893. case SP_DEF2:
  2894. WFIFOL(fd,4)=pc_rightside_def(sd);
  2895. break;
  2896. case SP_MDEF2: {
  2897. //negative check (in case you have something like Berserk active)
  2898. int mdef2 = pc_rightside_mdef(sd);
  2899. WFIFOL(fd,4)=
  2900. #ifndef RENEWAL
  2901. ( mdef2 < 0 ) ? 0 :
  2902. #endif
  2903. mdef2;
  2904. }
  2905. break;
  2906. case SP_CRITICAL:
  2907. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2908. break;
  2909. case SP_MATK1:
  2910. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2911. break;
  2912. case SP_MATK2:
  2913. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2914. break;
  2915. case SP_ZENY:
  2916. WFIFOW(fd,0)=0xb1;
  2917. WFIFOL(fd,4)=sd->status.zeny;
  2918. break;
  2919. #if PACKETVER >= 20170830
  2920. case SP_BASEEXP:
  2921. WFIFOW(fd,0)=0xacb;
  2922. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2923. len = packet_len(0xacb);
  2924. break;
  2925. case SP_JOBEXP:
  2926. WFIFOW(fd,0)=0xacb;
  2927. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2928. len = packet_len(0xacb);
  2929. break;
  2930. case SP_NEXTBASEEXP:
  2931. WFIFOW(fd,0)=0xacb;
  2932. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  2933. len = packet_len(0xacb);
  2934. break;
  2935. case SP_NEXTJOBEXP:
  2936. WFIFOW(fd,0)=0xacb;
  2937. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  2938. len = packet_len(0xacb);
  2939. break;
  2940. #else
  2941. case SP_BASEEXP:
  2942. WFIFOW(fd,0)=0xb1;
  2943. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  2944. break;
  2945. case SP_JOBEXP:
  2946. WFIFOW(fd,0)=0xb1;
  2947. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  2948. break;
  2949. case SP_NEXTBASEEXP:
  2950. WFIFOW(fd,0)=0xb1;
  2951. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  2952. break;
  2953. case SP_NEXTJOBEXP:
  2954. WFIFOW(fd,0)=0xb1;
  2955. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  2956. break;
  2957. #endif
  2958. /**
  2959. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2960. **/
  2961. case SP_USTR:
  2962. case SP_UAGI:
  2963. case SP_UVIT:
  2964. case SP_UINT:
  2965. case SP_UDEX:
  2966. case SP_ULUK:
  2967. WFIFOW(fd,0)=0xbe;
  2968. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2969. len=5;
  2970. break;
  2971. /**
  2972. * Tells the client how far it is allowed to attack (weapon range)
  2973. **/
  2974. case SP_ATTACKRANGE:
  2975. WFIFOW(fd,0)=0x13a;
  2976. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2977. len=4;
  2978. break;
  2979. case SP_STR:
  2980. WFIFOW(fd,0)=0x141;
  2981. WFIFOL(fd,2)=type;
  2982. WFIFOL(fd,6)=sd->status.str;
  2983. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2984. len=14;
  2985. break;
  2986. case SP_AGI:
  2987. WFIFOW(fd,0)=0x141;
  2988. WFIFOL(fd,2)=type;
  2989. WFIFOL(fd,6)=sd->status.agi;
  2990. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2991. len=14;
  2992. break;
  2993. case SP_VIT:
  2994. WFIFOW(fd,0)=0x141;
  2995. WFIFOL(fd,2)=type;
  2996. WFIFOL(fd,6)=sd->status.vit;
  2997. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2998. len=14;
  2999. break;
  3000. case SP_INT:
  3001. WFIFOW(fd,0)=0x141;
  3002. WFIFOL(fd,2)=type;
  3003. WFIFOL(fd,6)=sd->status.int_;
  3004. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3005. len=14;
  3006. break;
  3007. case SP_DEX:
  3008. WFIFOW(fd,0)=0x141;
  3009. WFIFOL(fd,2)=type;
  3010. WFIFOL(fd,6)=sd->status.dex;
  3011. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3012. len=14;
  3013. break;
  3014. case SP_LUK:
  3015. WFIFOW(fd,0)=0x141;
  3016. WFIFOL(fd,2)=type;
  3017. WFIFOL(fd,6)=sd->status.luk;
  3018. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3019. len=14;
  3020. break;
  3021. case SP_CARTINFO:
  3022. WFIFOW(fd,0)=0x121;
  3023. WFIFOW(fd,2)=sd->cart_num;
  3024. WFIFOW(fd,4)=MAX_CART;
  3025. WFIFOL(fd,6)=sd->cart_weight;
  3026. WFIFOL(fd,10)=sd->cart_weight_max;
  3027. len=14;
  3028. break;
  3029. default:
  3030. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3031. return;
  3032. }
  3033. WFIFOSET(fd,len);
  3034. // Additional update packets that should be sent right after
  3035. switch( type ){
  3036. case SP_BASELEVEL:
  3037. if( sd->status.party_id ){
  3038. struct party_data* p;
  3039. int i;
  3040. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3041. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3042. if( i < MAX_PARTY ){
  3043. p->party.member[i].lv = sd->status.base_level;
  3044. clif_party_job_and_level(sd);
  3045. }
  3046. }
  3047. }
  3048. break;
  3049. case SP_HP:
  3050. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3051. clif_hpmeter(sd);
  3052. }
  3053. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3054. clif_party_hp(sd);
  3055. }
  3056. if( sd->bg_id ){
  3057. clif_bg_hp(sd);
  3058. }
  3059. break;
  3060. }
  3061. }
  3062. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3063. /// 01ab <account id>.L <var id>.W <value>.L
  3064. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3065. {
  3066. unsigned char buf[12];
  3067. nullpo_retv(sd);
  3068. WBUFW(buf,0)=0x1ab;
  3069. WBUFL(buf,2)=sd->bl.id;
  3070. WBUFW(buf,6)=type;
  3071. switch(type)
  3072. {
  3073. case SP_MANNER:
  3074. WBUFL(buf,8)=val;
  3075. break;
  3076. default:
  3077. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3078. return;
  3079. }
  3080. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3081. }
  3082. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3083. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3084. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3085. struct PACKET_ZC_SPRITE_CHANGE p;
  3086. p.packetType = sendLookType;
  3087. p.AID = id;
  3088. p.type = type;
  3089. p.val = val;
  3090. #if PACKETVER >= 4
  3091. p.val2 = val2;
  3092. #endif
  3093. clif_send( &p, sizeof( p ), bl, target );
  3094. }
  3095. /// Updates sprite/style properties of an object.
  3096. void clif_changelook(struct block_list *bl, int type, int val) {
  3097. struct map_session_data* sd;
  3098. struct status_change* sc;
  3099. struct view_data* vd;
  3100. enum send_target target = AREA;
  3101. int val2 = 0;
  3102. nullpo_retv(bl);
  3103. sd = BL_CAST(BL_PC, bl);
  3104. sc = status_get_sc(bl);
  3105. vd = status_get_viewdata(bl);
  3106. if( vd ) //temp hack to let Warp Portal change appearance
  3107. switch(type) {
  3108. case LOOK_WEAPON:
  3109. if (sd) {
  3110. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3111. val = vd->weapon;
  3112. }
  3113. else
  3114. vd->weapon = val;
  3115. break;
  3116. case LOOK_SHIELD:
  3117. if (sd) {
  3118. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3119. val = vd->shield;
  3120. }
  3121. else
  3122. vd->shield = val;
  3123. break;
  3124. case LOOK_BASE:
  3125. if (!sd)
  3126. break;
  3127. if ( val == JT_INVISIBLE )
  3128. return;
  3129. if (sd->sc.option&OPTION_COSTUME)
  3130. vd->weapon = vd->shield = 0;
  3131. if (!vd->cloth_color)
  3132. break;
  3133. if (sd) {
  3134. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3135. vd->cloth_color = 0;
  3136. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3137. vd->cloth_color = 0;
  3138. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3139. vd->cloth_color = 0;
  3140. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3141. vd->cloth_color = 0;
  3142. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3143. vd->cloth_color = 0;
  3144. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3145. vd->body_style = 0;
  3146. }
  3147. break;
  3148. case LOOK_HAIR:
  3149. vd->hair_style = val;
  3150. break;
  3151. case LOOK_HEAD_BOTTOM:
  3152. vd->head_bottom = val;
  3153. break;
  3154. case LOOK_HEAD_TOP:
  3155. vd->head_top = val;
  3156. break;
  3157. case LOOK_HEAD_MID:
  3158. vd->head_mid = val;
  3159. break;
  3160. case LOOK_HAIR_COLOR:
  3161. vd->hair_color = val;
  3162. break;
  3163. case LOOK_CLOTHES_COLOR:
  3164. if (val && sd) {
  3165. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3166. val = 0;
  3167. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3168. val = 0;
  3169. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3170. val = 0;
  3171. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3172. val = 0;
  3173. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3174. val = 0;
  3175. }
  3176. vd->cloth_color = val;
  3177. break;
  3178. case LOOK_SHOES:
  3179. #if PACKETVER > 3
  3180. if (sd) {
  3181. int n;
  3182. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3183. if(sd->inventory_data[n]->view_id > 0)
  3184. val = sd->inventory_data[n]->view_id;
  3185. else
  3186. val = sd->inventory.u.items_inventory[n].nameid;
  3187. } else
  3188. val = 0;
  3189. }
  3190. #endif
  3191. //Shoes? No packet uses this....
  3192. break;
  3193. case LOOK_BODY:
  3194. // unknown purpose
  3195. break;
  3196. case LOOK_ROBE:
  3197. #if PACKETVER < 20110111
  3198. return;
  3199. #else
  3200. vd->robe = val;
  3201. #endif
  3202. break;
  3203. case LOOK_BODY2:
  3204. #if PACKETVER < 20150513
  3205. return;
  3206. #else
  3207. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3208. val = 0;
  3209. vd->body_style = val;
  3210. #endif
  3211. break;
  3212. }
  3213. // prevent leaking the presence of GM-hidden objects
  3214. if( sc && sc->option&OPTION_INVISIBLE )
  3215. target = SELF;
  3216. #if PACKETVER < 4
  3217. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3218. #else
  3219. if (bl->type != BL_NPC) {
  3220. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3221. type = LOOK_WEAPON;
  3222. val = (vd ? vd->weapon : 0);
  3223. val2 = (vd ? vd->shield : 0);
  3224. }
  3225. if (disguised(bl)) {
  3226. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3227. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3228. } else
  3229. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3230. } else
  3231. unit_refresh(bl);
  3232. #endif
  3233. }
  3234. //Sends a change-base-look packet required for traps as they are triggered.
  3235. void clif_changetraplook(struct block_list *bl,int val) {
  3236. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3237. }
  3238. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3239. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3240. clif_sprite_change(bl, id, type, val, 0, target);
  3241. }
  3242. /// Character status (ZC_STATUS).
  3243. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3244. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3245. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3246. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3247. void clif_initialstatus(struct map_session_data *sd) {
  3248. int fd, mdef2;
  3249. unsigned char *buf;
  3250. nullpo_retv(sd);
  3251. fd=sd->fd;
  3252. WFIFOHEAD(fd, packet_len(0xbd));
  3253. buf = WFIFOP(fd,0);
  3254. WBUFW(buf,0) = 0xbd;
  3255. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3256. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3257. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3258. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3259. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3260. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3261. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3262. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3263. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3264. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3265. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3266. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3267. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3268. WBUFW(buf,16) = pc_leftside_atk(sd);
  3269. WBUFW(buf,18) = pc_rightside_atk(sd);
  3270. WBUFW(buf,20) = pc_rightside_matk(sd);
  3271. WBUFW(buf,22) = pc_leftside_matk(sd);
  3272. WBUFW(buf,24) = pc_leftside_def(sd);
  3273. WBUFW(buf,26) = pc_rightside_def(sd);
  3274. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3275. mdef2 = pc_rightside_mdef(sd);
  3276. WBUFW(buf,30) =
  3277. #ifndef RENEWAL
  3278. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3279. #endif
  3280. mdef2;
  3281. WBUFW(buf,32) = sd->battle_status.hit;
  3282. WBUFW(buf,34) = sd->battle_status.flee;
  3283. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3284. WBUFW(buf,38) = sd->battle_status.cri/10;
  3285. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3286. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3287. WFIFOSET(fd, packet_len(0xbd));
  3288. clif_updatestatus(sd, SP_STR);
  3289. clif_updatestatus(sd, SP_AGI);
  3290. clif_updatestatus(sd, SP_VIT);
  3291. clif_updatestatus(sd, SP_INT);
  3292. clif_updatestatus(sd, SP_DEX);
  3293. clif_updatestatus(sd, SP_LUK);
  3294. clif_updatestatus(sd, SP_ATTACKRANGE);
  3295. clif_updatestatus(sd, SP_ASPD);
  3296. }
  3297. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3298. /// 013c <index>.W
  3299. void clif_arrowequip(struct map_session_data *sd,int val) {
  3300. int fd;
  3301. nullpo_retv(sd);
  3302. #if PACKETVER >= 20121128
  3303. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3304. #endif
  3305. fd=sd->fd;
  3306. WFIFOHEAD(fd, packet_len(0x013c));
  3307. WFIFOW(fd,0) = 0x013c;
  3308. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3309. WFIFOSET(fd, packet_len(0x013c));
  3310. }
  3311. /// Ammunition action message (ZC_ACTION_FAILURE).
  3312. /// 013b <type>.W
  3313. /// type:
  3314. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3315. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3316. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3317. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3318. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3319. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3320. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3321. int fd;
  3322. nullpo_retv(sd);
  3323. fd=sd->fd;
  3324. WFIFOHEAD(fd, packet_len(0x013b));
  3325. WFIFOW(fd,0) = 0x013b;
  3326. WFIFOW(fd,2) = type;
  3327. WFIFOSET(fd, packet_len(0x013b));
  3328. }
  3329. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3330. /// 01ad <packet len>.W { <name id>.W }*
  3331. void clif_arrow_create_list( struct map_session_data *sd ){
  3332. nullpo_retv( sd );
  3333. int fd = sd->fd;
  3334. if( !session_isActive( fd ) ){
  3335. return;
  3336. }
  3337. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  3338. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  3339. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3340. int count = 0;
  3341. for( int i = 0; i < MAX_SKILL_ARROW_DB; i++ ){
  3342. t_itemid nameid = skill_arrow_db[i].nameid;
  3343. if( !itemdb_exists( nameid ) ){
  3344. continue;
  3345. }
  3346. int index = pc_search_inventory( sd, nameid );
  3347. if( index < 0 ){
  3348. continue;
  3349. }
  3350. if( sd->inventory.u.items_inventory[index].equip ){
  3351. continue;
  3352. }
  3353. if( !sd->inventory.u.items_inventory[index].identify ){
  3354. continue;
  3355. }
  3356. p->items[count].itemId = client_nameid( nameid );
  3357. count++;
  3358. }
  3359. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3360. WFIFOSET( fd, p->packetLength );
  3361. if( count > 0 ){
  3362. sd->menuskill_id = AC_MAKINGARROW;
  3363. sd->menuskill_val = count;
  3364. }
  3365. }
  3366. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3367. /// 00bc <status id>.W <result>.B <value>.B
  3368. /// status id:
  3369. /// SP_STR ~ SP_LUK
  3370. /// result:
  3371. /// 0 = failure
  3372. /// 1 = success
  3373. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3374. int fd;
  3375. nullpo_retv(sd);
  3376. fd=sd->fd;
  3377. WFIFOHEAD(fd, packet_len(0xbc));
  3378. WFIFOW(fd,0) = 0xbc;
  3379. WFIFOW(fd,2) = type;
  3380. WFIFOB(fd,4) = ok;
  3381. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3382. WFIFOSET(fd, packet_len(0xbc));
  3383. }
  3384. /// Notifies the client about the result of a request to equip an item.
  3385. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3386. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3387. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3388. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3389. /// @ok: //inversed forv2 v5
  3390. /// 0 = failure
  3391. /// 1 = success
  3392. /// 2 = failure due to low level
  3393. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3394. {
  3395. int fd = 0, cmd = 0, look = 0;
  3396. struct s_packet_db *info = NULL;
  3397. nullpo_retv(sd);
  3398. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3399. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3400. return;
  3401. fd = sd->fd;
  3402. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3403. look = sd->inventory_data[n]->look;
  3404. WFIFOHEAD(fd, info->len);
  3405. WFIFOW(fd, 0) = cmd;
  3406. WFIFOW(fd, info->pos[0]) = n+2;
  3407. switch (cmd) {
  3408. case 0xaa:
  3409. WFIFOW(fd, info->pos[1]) = pos;
  3410. #if PACKETVER < 20100629
  3411. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3412. #else
  3413. WFIFOL(fd, info->pos[2]) = look;
  3414. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3415. #endif
  3416. break;
  3417. case 0x8d0:
  3418. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3419. flag = 1;
  3420. case 0x999:
  3421. if (cmd == 0x999)
  3422. WFIFOL(fd, info->pos[1]) = pos;
  3423. else
  3424. WFIFOW(fd, info->pos[1]) = pos;
  3425. WFIFOL(fd, info->pos[2]) = look;
  3426. WFIFOW(fd, info->pos[3]) = flag;
  3427. break;
  3428. }
  3429. WFIFOSET(fd, info->len);
  3430. }
  3431. /// Notifies the client about the result of a request to take off an item.
  3432. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3433. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3434. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3435. /// @ok : //inversed for v2 v5
  3436. /// 0 = failure
  3437. /// 1 = success
  3438. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3439. {
  3440. int fd, header, offs = 0;
  3441. #if PACKETVER >= 20130000
  3442. header = 0x99a;
  3443. ok = ok ? 0 : 1;
  3444. #elif PACKETVER >= 20110824
  3445. header = 0x8d1;
  3446. ok = ok ? 0 : 1;
  3447. #else
  3448. header = 0xac;
  3449. #endif
  3450. nullpo_retv(sd);
  3451. fd=sd->fd;
  3452. WFIFOHEAD(fd, packet_len(header));
  3453. WFIFOW(fd,offs+0) = header;
  3454. WFIFOW(fd,offs+2) = n+2;
  3455. #if PACKETVER >= 20130000
  3456. WFIFOL(fd,offs+4) = pos;
  3457. offs += 2;
  3458. #else
  3459. WFIFOW(fd,offs+4) = pos;
  3460. #endif
  3461. WFIFOB(fd,offs+6) = ok;
  3462. WFIFOSET(fd, packet_len(header));
  3463. }
  3464. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3465. /// 019b <id>.L <effect id>.L
  3466. /// effect id:
  3467. /// 0 = base level up
  3468. /// 1 = job level up
  3469. /// 2 = refine failure
  3470. /// 3 = refine success
  3471. /// 4 = game over
  3472. /// 5 = pharmacy success
  3473. /// 6 = pharmacy failure
  3474. /// 7 = base level up (super novice)
  3475. /// 8 = job level up (super novice)
  3476. /// 9 = base level up (taekwon)
  3477. void clif_misceffect(struct block_list* bl,int type)
  3478. {
  3479. unsigned char buf[32];
  3480. nullpo_retv(bl);
  3481. WBUFW(buf,0) = 0x19b;
  3482. WBUFL(buf,2) = bl->id;
  3483. WBUFL(buf,6) = type;
  3484. clif_send(buf,packet_len(0x19b),bl,AREA);
  3485. }
  3486. /// Notifies clients in the area of a state change.
  3487. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3488. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3489. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3490. nullpo_retv( bl );
  3491. struct status_change* sc = status_get_sc( bl );
  3492. //How can an option change if there's no sc?
  3493. if( sc == nullptr ){
  3494. return;
  3495. }
  3496. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3497. struct PACKET_ZC_STATE_CHANGE p;
  3498. p.packetType = HEADER_ZC_STATE_CHANGE;
  3499. p.AID = bl->id;
  3500. p.bodyState = sc->opt1;
  3501. p.healthState = sc->opt2;
  3502. p.effectState = sc->option;
  3503. p.isPKModeON = sd ? sd->status.karma : false;
  3504. if( target == nullptr ){
  3505. if( disguised( bl ) ){
  3506. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3507. p.AID = disguised_bl_id( p.AID );
  3508. clif_send( &p, sizeof( p ), bl, SELF );
  3509. p.AID = disguised_bl_id( p.AID );
  3510. p.effectState = OPTION_INVISIBLE;
  3511. clif_send( &p, sizeof( p ), bl, SELF );
  3512. }else{
  3513. clif_send( &p, sizeof( p ), bl, AREA );
  3514. }
  3515. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3516. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3517. if( sc->data[SC_PROVOKE] ){
  3518. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3519. clif_status_change( bl, StatusIconChangeTable[SC_PROVOKE], 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3520. }
  3521. }else{
  3522. if( disguised( bl ) ){
  3523. p.AID = disguised_bl_id( p.AID );
  3524. clif_send( &p, sizeof( p ), target, SELF );
  3525. p.AID = disguised_bl_id( p.AID );
  3526. p.effectState = OPTION_INVISIBLE;
  3527. clif_send( &p, sizeof( p ), target, SELF );
  3528. }else{
  3529. clif_send( &p, sizeof( p ), target, SELF );
  3530. }
  3531. }
  3532. }
  3533. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3534. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3535. void clif_changeoption2(struct block_list* bl)
  3536. {
  3537. unsigned char buf[20];
  3538. struct status_change *sc;
  3539. sc = status_get_sc(bl);
  3540. if (!sc) return; //How can an option change if there's no sc?
  3541. WBUFW(buf,0) = 0x28a;
  3542. WBUFL(buf,2) = bl->id;
  3543. WBUFL(buf,6) = sc->option;
  3544. WBUFL(buf,10) = clif_setlevel(bl);
  3545. WBUFL(buf,14) = sc->opt3;
  3546. if(disguised(bl)) {
  3547. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3548. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3549. clif_send(buf,packet_len(0x28a),bl,SELF);
  3550. WBUFL(buf,2) = bl->id;
  3551. WBUFL(buf,6) = OPTION_INVISIBLE;
  3552. clif_send(buf,packet_len(0x28a),bl,SELF);
  3553. } else
  3554. clif_send(buf,packet_len(0x28a),bl,AREA);
  3555. }
  3556. /// Notifies the client about the result of an item use request.
  3557. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3558. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3559. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3560. nullpo_retv( sd );
  3561. int fd = sd->fd;
  3562. if( !session_isActive( fd ) ){
  3563. return;
  3564. }
  3565. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3566. return;
  3567. }
  3568. struct PACKET_ZC_USE_ITEM_ACK p;
  3569. p.packetType = useItemAckType;
  3570. p.index = index + 2;
  3571. #if PACKETVER > 3
  3572. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3573. p.AID = sd->bl.id;
  3574. #endif
  3575. p.amount = amount;
  3576. p.result = ok;
  3577. if( !ok ){
  3578. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3579. }else{
  3580. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3581. }
  3582. }
  3583. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3584. /// 00d6 <flag>.B
  3585. /// flag:
  3586. /// 0 = Room has been successfully created (opens chat room)
  3587. /// 1 = Room limit exceeded
  3588. /// 2 = Same room already exists
  3589. void clif_createchat(struct map_session_data* sd, int flag)
  3590. {
  3591. int fd;
  3592. nullpo_retv(sd);
  3593. fd = sd->fd;
  3594. WFIFOHEAD(fd,packet_len(0xd6));
  3595. WFIFOW(fd,0) = 0xd6;
  3596. WFIFOB(fd,2) = flag;
  3597. WFIFOSET(fd,packet_len(0xd6));
  3598. }
  3599. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3600. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3601. /// type:
  3602. /// 0 = private (password protected)
  3603. /// 1 = public
  3604. /// 2 = arena (npc waiting room)
  3605. /// 3 = PK zone (non-clickable)
  3606. void clif_dispchat(struct chat_data* cd, int fd)
  3607. {
  3608. unsigned char buf[128];
  3609. uint8 type;
  3610. if( cd == NULL || cd->owner == NULL )
  3611. return;
  3612. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3613. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3614. : 1;
  3615. WBUFW(buf, 0) = 0xd7;
  3616. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3617. WBUFL(buf, 4) = cd->owner->id;
  3618. WBUFL(buf, 8) = cd->bl.id;
  3619. WBUFW(buf,12) = cd->limit;
  3620. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3621. WBUFB(buf,16) = type;
  3622. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3623. if( session_isActive(fd) ) {
  3624. WFIFOHEAD(fd,WBUFW(buf,2));
  3625. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3626. WFIFOSET(fd,WBUFW(buf,2));
  3627. } else {
  3628. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3629. }
  3630. }
  3631. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3632. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3633. /// type:
  3634. /// 0 = private (password protected)
  3635. /// 1 = public
  3636. /// 2 = arena (npc waiting room)
  3637. /// 3 = PK zone (non-clickable)
  3638. void clif_changechatstatus(struct chat_data* cd)
  3639. {
  3640. unsigned char buf[128];
  3641. uint8 type;
  3642. if( cd == NULL || cd->usersd[0] == NULL )
  3643. return;
  3644. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3645. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3646. : 1;
  3647. WBUFW(buf, 0) = 0xdf;
  3648. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3649. WBUFL(buf, 4) = cd->owner->id;
  3650. WBUFL(buf, 8) = cd->bl.id;
  3651. WBUFW(buf,12) = cd->limit;
  3652. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3653. WBUFB(buf,16) = type;
  3654. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3655. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3656. }
  3657. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3658. /// 00d8 <chat id>.L
  3659. void clif_clearchat(struct chat_data *cd,int fd)
  3660. {
  3661. unsigned char buf[32];
  3662. nullpo_retv(cd);
  3663. WBUFW(buf,0) = 0xd8;
  3664. WBUFL(buf,2) = cd->bl.id;
  3665. if( session_isActive(fd) ) {
  3666. WFIFOHEAD(fd,packet_len(0xd8));
  3667. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3668. WFIFOSET(fd,packet_len(0xd8));
  3669. } else {
  3670. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3671. }
  3672. }
  3673. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3674. /// 00da <result>.B
  3675. /// result:
  3676. /// 0 = room full
  3677. /// 1 = wrong password
  3678. /// 2 = kicked
  3679. /// 3 = success (no message)
  3680. /// 4 = no enough zeny
  3681. /// 5 = too low level
  3682. /// 6 = too high level
  3683. /// 7 = unsuitable job class
  3684. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3685. {
  3686. int fd;
  3687. nullpo_retv(sd);
  3688. fd = sd->fd;
  3689. WFIFOHEAD(fd,packet_len(0xda));
  3690. WFIFOW(fd,0) = 0xda;
  3691. WFIFOB(fd,2) = flag;
  3692. WFIFOSET(fd,packet_len(0xda));
  3693. }
  3694. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3695. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3696. /// role:
  3697. /// 0 = owner (menu)
  3698. /// 1 = normal
  3699. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3700. {
  3701. int fd;
  3702. int i,t;
  3703. nullpo_retv(sd);
  3704. nullpo_retv(cd);
  3705. fd = sd->fd;
  3706. if (!session_isActive(fd))
  3707. return;
  3708. t = (int)(cd->owner->type == BL_NPC);
  3709. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3710. WFIFOW(fd, 0) = 0xdb;
  3711. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3712. WFIFOL(fd, 4) = cd->bl.id;
  3713. if(cd->owner->type == BL_NPC){
  3714. WFIFOL(fd, 30) = 1;
  3715. WFIFOL(fd, 8) = 0;
  3716. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3717. for (i = 0; i < cd->users; i++) {
  3718. WFIFOL(fd, 8+(i+1)*28) = 1;
  3719. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3720. }
  3721. }else{
  3722. for (i = 0; i < cd->users; i++) {
  3723. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3724. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3725. }
  3726. }
  3727. WFIFOSET(fd, WFIFOW(fd, 2));
  3728. }
  3729. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3730. /// 00dc <users>.W <name>.24B
  3731. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3732. {
  3733. unsigned char buf[29];
  3734. nullpo_retv(sd);
  3735. nullpo_retv(cd);
  3736. WBUFW(buf, 0) = 0xdc;
  3737. WBUFW(buf, 2) = cd->users;
  3738. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3739. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3740. }
  3741. /// Announce the new owner (ZC_ROLE_CHANGE).
  3742. /// 00e1 <role>.L <nick>.24B
  3743. /// role:
  3744. /// 0 = owner (menu)
  3745. /// 1 = normal
  3746. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3747. {
  3748. unsigned char buf[64];
  3749. nullpo_retv(sd);
  3750. nullpo_retv(cd);
  3751. WBUFW(buf, 0) = 0xe1;
  3752. WBUFL(buf, 2) = 1;
  3753. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3754. WBUFW(buf,30) = 0xe1;
  3755. WBUFL(buf,32) = 0;
  3756. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3757. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3758. }
  3759. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3760. /// 00dd <users>.W <nick>.24B <flag>.B
  3761. /// flag:
  3762. /// 0 = left
  3763. /// 1 = kicked
  3764. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3765. {
  3766. unsigned char buf[32];
  3767. nullpo_retv(sd);
  3768. nullpo_retv(cd);
  3769. WBUFW(buf, 0) = 0xdd;
  3770. WBUFW(buf, 2) = cd->users-1;
  3771. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3772. WBUFB(buf,28) = flag;
  3773. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3774. }
  3775. /// Opens a trade request window from char 'name'.
  3776. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3777. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3778. void clif_traderequest(struct map_session_data* sd, const char* name)
  3779. {
  3780. int fd = sd->fd;
  3781. #if PACKETVER < 6
  3782. WFIFOHEAD(fd,packet_len(0xe5));
  3783. WFIFOW(fd,0) = 0xe5;
  3784. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3785. WFIFOSET(fd,packet_len(0xe5));
  3786. #else
  3787. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3788. if( !tsd ) return;
  3789. WFIFOHEAD(fd,packet_len(0x1f4));
  3790. WFIFOW(fd,0) = 0x1f4;
  3791. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3792. WFIFOL(fd,26) = tsd->status.char_id;
  3793. WFIFOW(fd,30) = tsd->status.base_level;
  3794. WFIFOSET(fd,packet_len(0x1f4));
  3795. #endif
  3796. }
  3797. /// Reply to a trade-request.
  3798. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3799. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3800. /// result:
  3801. /// 0 = Char is too far
  3802. /// 1 = Character does not exist
  3803. /// 2 = Trade failed
  3804. /// 3 = Accept
  3805. /// 4 = Cancel
  3806. /// 5 = Busy
  3807. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3808. {
  3809. int fd = sd->fd;
  3810. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3811. if( PACKETVER < 6 || !tsd ) {
  3812. WFIFOHEAD(fd,packet_len(0xe7));
  3813. WFIFOW(fd,0) = 0xe7;
  3814. WFIFOB(fd,2) = type;
  3815. WFIFOSET(fd,packet_len(0xe7));
  3816. } else {
  3817. WFIFOHEAD(fd,packet_len(0x1f5));
  3818. WFIFOW(fd,0) = 0x1f5;
  3819. WFIFOB(fd,2) = type;
  3820. WFIFOL(fd,3) = tsd->status.char_id;
  3821. WFIFOW(fd,7) = tsd->status.base_level;
  3822. WFIFOSET(fd,packet_len(0x1f5));
  3823. }
  3824. }
  3825. /// Notifies the client about an item from other player in current trade.
  3826. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3827. /// 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)
  3828. /// 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)
  3829. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  3830. nullpo_retv( sd );
  3831. nullpo_retv( tsd );
  3832. int fd = tsd->fd;
  3833. if( !session_isActive( fd ) ){
  3834. return;
  3835. }
  3836. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3837. if( index ){
  3838. index = server_index( index );
  3839. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3840. return;
  3841. }
  3842. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3843. #if PACKETVER >= 20100223
  3844. p.itemType = sd->inventory_data[index]->type;
  3845. #endif
  3846. p.identified = sd->inventory.u.items_inventory[index].identify;
  3847. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3848. p.refine = sd->inventory.u.items_inventory[index].refine;
  3849. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3850. #if PACKETVER >= 20150226
  3851. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  3852. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3853. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  3854. p.viewSprite = sd->inventory_data[index]->look;
  3855. p.enchantgrade = sd->inventory.u.items_inventory[index].enchantgrade;
  3856. #endif
  3857. #endif
  3858. }else{
  3859. p = {};
  3860. }
  3861. p.packetType = tradeaddType;
  3862. p.amount = amount;
  3863. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  3864. }
  3865. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3866. /// 00ea <index>.W <result>.B
  3867. /// result:
  3868. /// 0 = success
  3869. /// 1 = overweight
  3870. /// 2 = trade canceled
  3871. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3872. {
  3873. int fd;
  3874. nullpo_retv(sd);
  3875. fd = sd->fd;
  3876. WFIFOHEAD(fd,packet_len(0xea));
  3877. WFIFOW(fd,0) = 0xea;
  3878. WFIFOW(fd,2) = index;
  3879. WFIFOB(fd,4) = fail;
  3880. WFIFOSET(fd,packet_len(0xea));
  3881. }
  3882. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3883. /// 00ec <who>.B
  3884. /// who:
  3885. /// 0 = self
  3886. /// 1 = other player
  3887. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3888. {
  3889. int fd;
  3890. nullpo_retv(sd);
  3891. fd = sd->fd;
  3892. WFIFOHEAD(fd,packet_len(0xec));
  3893. WFIFOW(fd,0) = 0xec;
  3894. WFIFOB(fd,2) = fail;
  3895. WFIFOSET(fd,packet_len(0xec));
  3896. }
  3897. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3898. /// 00ee
  3899. void clif_tradecancelled(struct map_session_data* sd)
  3900. {
  3901. int fd;
  3902. nullpo_retv(sd);
  3903. fd = sd->fd;
  3904. WFIFOHEAD(fd,packet_len(0xee));
  3905. WFIFOW(fd,0) = 0xee;
  3906. WFIFOSET(fd,packet_len(0xee));
  3907. }
  3908. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3909. /// 00f0 <result>.B
  3910. /// result:
  3911. /// 0 = success
  3912. /// 1 = failure
  3913. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3914. {
  3915. int fd;
  3916. nullpo_retv(sd);
  3917. fd = sd->fd;
  3918. WFIFOHEAD(fd,packet_len(0xf0));
  3919. WFIFOW(fd,0) = 0xf0;
  3920. WFIFOB(fd,2) = fail;
  3921. WFIFOSET(fd,packet_len(0xf0));
  3922. }
  3923. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3924. /// 00f1
  3925. /// NOTE: Unknown purpose. Items are not removed until the window is
  3926. /// refreshed (ex. by putting another item in there).
  3927. void clif_tradeundo(struct map_session_data* sd)
  3928. {
  3929. int fd = sd->fd;
  3930. WFIFOHEAD(fd,packet_len(0xf1));
  3931. WFIFOW(fd,0) = 0xf1;
  3932. WFIFOSET(fd,packet_len(0xf1));
  3933. }
  3934. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3935. /// 00f2 <current count>.W <max count>.W
  3936. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3937. {
  3938. int fd;
  3939. nullpo_retv(sd);
  3940. fd=sd->fd;
  3941. WFIFOHEAD(fd,packet_len(0xf2));
  3942. WFIFOW(fd,0) = 0xf2;
  3943. WFIFOW(fd,2) = amount;
  3944. WFIFOW(fd,4) = max_amount;
  3945. WFIFOSET(fd,packet_len(0xf2));
  3946. }
  3947. /// Notifies the client of an item being added to the storage.
  3948. /// 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)
  3949. /// 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)
  3950. /// 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)
  3951. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  3952. nullpo_retv( sd );
  3953. nullpo_retv( i );
  3954. int fd = sd->fd;
  3955. if( !session_isActive( fd ) ){
  3956. return;
  3957. }
  3958. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  3959. p.packetType = storageaddType; // Storage item added
  3960. p.index = client_storage_index( index ); // index
  3961. p.amount = amount; // amount
  3962. p.itemId = client_nameid( i->nameid ); // id
  3963. #if PACKETVER >= 5
  3964. p.itemType = itemtype( i->nameid ); //type
  3965. #endif
  3966. p.identified = i->identify; //identify flag
  3967. p.damaged = i->attribute; // attribute
  3968. p.refine = i->refine; //refine
  3969. clif_addcards( &p.slot, i );
  3970. #if PACKETVER >= 20150226
  3971. clif_add_random_options( p.option_data, i );
  3972. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3973. p.enchantgrade = i->enchantgrade;
  3974. #endif
  3975. #endif
  3976. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  3977. }
  3978. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3979. /// 00f6 <index>.W <amount>.L
  3980. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3981. {
  3982. int fd;
  3983. nullpo_retv(sd);
  3984. fd=sd->fd;
  3985. WFIFOHEAD(fd,packet_len(0xf6));
  3986. WFIFOW(fd,0)=0xf6; // Storage item removed
  3987. WFIFOW(fd,2)=client_storage_index(index);
  3988. WFIFOL(fd,4)=amount;
  3989. WFIFOSET(fd,packet_len(0xf6));
  3990. }
  3991. /// Closes storage (ZC_CLOSE_STORE).
  3992. /// 00f8
  3993. void clif_storageclose(struct map_session_data* sd)
  3994. {
  3995. int fd;
  3996. nullpo_retv(sd);
  3997. fd=sd->fd;
  3998. WFIFOHEAD(fd,packet_len(0xf8));
  3999. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4000. WFIFOSET(fd,packet_len(0xf8));
  4001. }
  4002. /// Notifies clients in an area of a player's souls.
  4003. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4004. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4005. /// 0b73 <id>.L <amount>.W
  4006. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4007. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4008. struct PACKET_ZC_UNCONFIRMED_SPIRITS3 p = {};
  4009. p.packetType = HEADER_ZC_UNCONFIRMED_SPIRITS3;
  4010. #else
  4011. struct PACKET_ZC_SPIRITS p = {};
  4012. p.packetType = HEADER_ZC_SPIRITS;
  4013. #endif
  4014. p.GID = sd->bl.id;
  4015. p.amount = sd->soulball;
  4016. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4017. }
  4018. /*==========================================
  4019. * Server tells 'sd' player client the abouts of 'dstsd' player
  4020. *------------------------------------------*/
  4021. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4022. {
  4023. struct block_list *d_bl;
  4024. int i;
  4025. if( dstsd->chatID ) {
  4026. struct chat_data *cd = NULL;
  4027. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4028. clif_dispchat(cd,sd->fd);
  4029. } else if( dstsd->state.vending )
  4030. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4031. else if( dstsd->state.buyingstore )
  4032. clif_buyingstore_entry_single(sd, dstsd);
  4033. if(dstsd->spiritball > 0)
  4034. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4035. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4036. clif_millenniumshield_single(sd->fd, dstsd);
  4037. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4038. clif_spiritcharm_single(sd->fd, dstsd);
  4039. if (dstsd->soulball > 0)
  4040. clif_soulball( dstsd, &sd->bl, SELF );
  4041. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4042. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4043. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4044. )
  4045. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4046. // display link (sd - dstsd) to sd
  4047. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4048. if( i < MAX_DEVOTION )
  4049. clif_devotion(&sd->bl, sd);
  4050. // display links (dstsd - devotees) to sd
  4051. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4052. if( i < MAX_DEVOTION )
  4053. clif_devotion(&dstsd->bl, sd);
  4054. // display link (dstsd - crusader) to sd
  4055. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4056. clif_devotion(d_bl, sd);
  4057. }
  4058. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4059. struct unit_data *ud;
  4060. struct view_data *vd;
  4061. bool option = false;
  4062. unsigned int option_val = 0;
  4063. vd = status_get_viewdata(bl);
  4064. if (!vd || vd->class_ == JT_INVISIBLE)
  4065. return;
  4066. // Hide NPC from Maya Purple card
  4067. if (clif_npc_mayapurple(bl))
  4068. return;
  4069. ud = unit_bl2ud(bl);
  4070. if( ud && ud->walktimer != INVALID_TIMER ){
  4071. clif_set_unit_walking( bl, sd, ud, SELF );
  4072. }else{
  4073. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4074. }
  4075. if (vd->cloth_color)
  4076. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4077. if (vd->body_style)
  4078. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4079. switch (bl->type)
  4080. {
  4081. case BL_PC:
  4082. {
  4083. TBL_PC* tsd = (TBL_PC*)bl;
  4084. clif_getareachar_pc(sd, tsd);
  4085. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4086. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4087. else if(tsd->state.size==SZ_MEDIUM)
  4088. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4089. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4090. clif_sendbgemblem_single(sd->fd,tsd);
  4091. if ( tsd->status.robe )
  4092. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4093. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4094. clif_hat_effects(sd,bl,SELF);
  4095. }
  4096. break;
  4097. case BL_MER: // Devotion Effects
  4098. if( ((TBL_MER*)bl)->devotion_flag )
  4099. clif_devotion(bl, sd);
  4100. break;
  4101. case BL_NPC:
  4102. {
  4103. TBL_NPC* nd = (TBL_NPC*)bl;
  4104. if( nd->chat_id )
  4105. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4106. if( nd->size == SZ_BIG )
  4107. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4108. else if( nd->size == SZ_MEDIUM )
  4109. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4110. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4111. clif_progressbar_npc(nd, sd);
  4112. }
  4113. break;
  4114. case BL_MOB:
  4115. {
  4116. TBL_MOB* md = (TBL_MOB*)bl;
  4117. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4118. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4119. else if(md->special_state.size==SZ_MEDIUM)
  4120. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4121. #if PACKETVER >= 20120404
  4122. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4123. int i;
  4124. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4125. if( md->dmglog[i].id == sd->status.char_id )
  4126. clif_monster_hp_bar(md, sd->fd);
  4127. }
  4128. #endif
  4129. }
  4130. break;
  4131. case BL_PET:
  4132. if (vd->head_bottom)
  4133. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4134. break;
  4135. }
  4136. }
  4137. //Modifies the type of damage according to status changes [Skotlex]
  4138. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4139. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4140. {
  4141. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4142. }
  4143. /*==========================================
  4144. * Estimates walk delay based on the damage criteria. [Skotlex]
  4145. *------------------------------------------*/
  4146. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4147. {
  4148. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4149. return 0;
  4150. if (bl->type == BL_PC) {
  4151. if (battle_config.pc_walk_delay_rate != 100)
  4152. delay = delay*battle_config.pc_walk_delay_rate/100;
  4153. } else
  4154. if (battle_config.walk_delay_rate != 100)
  4155. delay = delay*battle_config.walk_delay_rate/100;
  4156. if (div_ > 1) //Multi-hit skills mean higher delays.
  4157. delay += battle_config.multihit_delay*(div_-1);
  4158. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4159. }
  4160. /*========================================== [Playtester]
  4161. * Returns hallucination damage the client displays
  4162. *------------------------------------------*/
  4163. static int clif_hallucination_damage()
  4164. {
  4165. int digit = rnd() % 5 + 1;
  4166. switch (digit)
  4167. {
  4168. case 1:
  4169. return (rnd() % 10);
  4170. case 2:
  4171. return (rnd() % 100);
  4172. case 3:
  4173. return (rnd() % 1000);
  4174. case 4:
  4175. return (rnd() % 10000);
  4176. }
  4177. return (rnd() % 32767);
  4178. }
  4179. /// Sends a 'damage' packet (src performs action on dst)
  4180. /// 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)
  4181. /// 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)
  4182. /// 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)
  4183. /// type:
  4184. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4185. /// 1 = pick up item
  4186. /// 2 = sit down
  4187. /// 3 = stand up
  4188. /// 4 = damage (endure)
  4189. /// 5 = (splash?)
  4190. /// 6 = (skill?)
  4191. /// 7 = (repeat damage?)
  4192. /// 8 = multi-hit damage
  4193. /// 9 = multi-hit damage (endure)
  4194. /// 10 = critical hit
  4195. /// 11 = lucky dodge
  4196. /// 12 = (touch skill?)
  4197. /// 13 = multi-hit critical
  4198. 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)
  4199. {
  4200. unsigned char buf[34];
  4201. struct status_change *sc;
  4202. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4203. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4204. #if PACKETVER < 20071113
  4205. const int cmd = 0x8a;
  4206. int offset = 0;
  4207. #elif PACKETVER < 20131223
  4208. const int cmd = 0x2e1;
  4209. int offset = 2;
  4210. #else
  4211. const int cmd = 0x8c8;
  4212. int offset = 3;
  4213. #endif
  4214. nullpo_ret(src);
  4215. nullpo_ret(dst);
  4216. if (type != DMG_MULTI_HIT_CRITICAL)
  4217. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4218. sc = status_get_sc(dst);
  4219. if(sc && sc->count) {
  4220. if(sc->data[SC_HALLUCINATION]) {
  4221. if(damage) damage = clif_hallucination_damage();
  4222. if(damage2) damage2 = clif_hallucination_damage();
  4223. }
  4224. }
  4225. WBUFW(buf,0) = cmd;
  4226. WBUFL(buf,2) = src->id;
  4227. WBUFL(buf,6) = dst->id;
  4228. WBUFL(buf,10) = client_tick(tick);
  4229. WBUFL(buf,14) = sdelay;
  4230. WBUFL(buf,18) = ddelay;
  4231. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4232. #if PACKETVER < 20071113
  4233. WBUFW(buf,22) = damage ? div : 0;
  4234. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4235. #else
  4236. WBUFL(buf, 22) = damage ? div : 0;
  4237. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4238. #endif
  4239. } else {
  4240. #if PACKETVER < 20071113
  4241. WBUFW(buf,22) = min(damage, INT16_MAX);
  4242. WBUFW(buf,27+offset) = damage2;
  4243. #else
  4244. WBUFL(buf,22) = damage;
  4245. WBUFL(buf,27+offset) = damage2;
  4246. #endif
  4247. }
  4248. #if PACKETVER >= 20131223
  4249. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4250. #endif
  4251. WBUFW(buf,24+offset) = div;
  4252. WBUFB(buf,26+offset) = type;
  4253. if(disguised(dst)) {
  4254. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4255. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4256. clif_send(buf, packet_len(cmd), dst, SELF);
  4257. } else
  4258. clif_send(buf, packet_len(cmd), dst, AREA);
  4259. if(disguised(src)) {
  4260. WBUFL(buf,2) = disguised_bl_id( src->id );
  4261. if (disguised(dst))
  4262. WBUFL(buf,6) = dst->id;
  4263. #if PACKETVER < 20071113
  4264. if(damage > 0) WBUFW(buf,22) = -1;
  4265. if(damage2 > 0) WBUFW(buf,27) = -1;
  4266. #else
  4267. if(damage > 0) WBUFL(buf,22) = -1;
  4268. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4269. #endif
  4270. clif_send(buf,packet_len(cmd),src,SELF);
  4271. }
  4272. if(src == dst) {
  4273. unit_setdir(src, unit_getdir(src));
  4274. }
  4275. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4276. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4277. //Return adjusted can't walk delay for further processing.
  4278. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4279. }
  4280. /*==========================================
  4281. * src picks up dst
  4282. *------------------------------------------*/
  4283. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4284. {
  4285. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4286. unsigned char buf[32];
  4287. nullpo_retv(src);
  4288. nullpo_retv(dst);
  4289. WBUFW(buf, 0) = 0x8a;
  4290. WBUFL(buf, 2) = src->id;
  4291. WBUFL(buf, 6) = dst->id;
  4292. WBUFB(buf,26) = 1;
  4293. clif_send(buf, packet_len(0x8a), src, AREA);
  4294. }
  4295. /*==========================================
  4296. * inform clients in area that `bl` is sitting
  4297. *------------------------------------------*/
  4298. void clif_sitting(struct block_list* bl)
  4299. {
  4300. unsigned char buf[32];
  4301. nullpo_retv(bl);
  4302. WBUFW(buf, 0) = 0x8a;
  4303. WBUFL(buf, 2) = bl->id;
  4304. WBUFB(buf,26) = 2;
  4305. clif_send(buf, packet_len(0x8a), bl, AREA);
  4306. if(disguised(bl)) {
  4307. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4308. clif_send(buf, packet_len(0x8a), bl, SELF);
  4309. }
  4310. }
  4311. /*==========================================
  4312. * inform clients in area that `bl` is standing
  4313. *------------------------------------------*/
  4314. void clif_standing(struct block_list* bl)
  4315. {
  4316. unsigned char buf[32];
  4317. nullpo_retv(bl);
  4318. WBUFW(buf, 0) = 0x8a;
  4319. WBUFL(buf, 2) = bl->id;
  4320. WBUFB(buf,26) = 3;
  4321. clif_send(buf, packet_len(0x8a), bl, AREA);
  4322. if(disguised(bl)) {
  4323. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4324. clif_send(buf, packet_len(0x8a), bl, SELF);
  4325. }
  4326. }
  4327. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4328. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4329. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4330. {
  4331. unsigned char buf[32];
  4332. WBUFW(buf,0) = 0x192;
  4333. WBUFW(buf,2) = x;
  4334. WBUFW(buf,4) = y;
  4335. WBUFW(buf,6) = type;
  4336. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4337. if( session_isActive(fd) )
  4338. {
  4339. WFIFOHEAD(fd,packet_len(0x192));
  4340. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4341. WFIFOSET(fd,packet_len(0x192));
  4342. }
  4343. else
  4344. {
  4345. struct block_list dummy_bl;
  4346. dummy_bl.type = BL_NUL;
  4347. dummy_bl.x = x;
  4348. dummy_bl.y = y;
  4349. dummy_bl.m = m;
  4350. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4351. }
  4352. }
  4353. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4354. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4355. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4356. nullpo_retv( sd );
  4357. nullpo_retv( fitem );
  4358. struct PACKET_ZC_ITEM_ENTRY p;
  4359. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4360. p.AID = fitem->bl.id;
  4361. p.itemId = client_nameid( fitem->item.nameid );
  4362. p.identify = fitem->item.identify;
  4363. p.x = fitem->bl.x;
  4364. p.y = fitem->bl.y;
  4365. p.amount = fitem->item.amount;
  4366. p.subX = fitem->subx;
  4367. p.subY = fitem->suby;
  4368. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4369. }
  4370. /// Notifes client about Graffiti
  4371. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4372. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4373. unsigned char buf[128];
  4374. nullpo_retv(bl);
  4375. nullpo_retv(unit);
  4376. WBUFW(buf, 0) = 0x1c9;
  4377. WBUFL(buf, 2) = unit->bl.id;
  4378. WBUFL(buf, 6) = unit->group->src_id;
  4379. WBUFW(buf,10) = unit->bl.x;
  4380. WBUFW(buf,12) = unit->bl.y;
  4381. WBUFB(buf,14) = unit->group->unit_id;
  4382. WBUFB(buf,15) = 1;
  4383. WBUFB(buf,16) = 1;
  4384. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4385. clif_send(buf,packet_len(0x1c9),bl,target);
  4386. }
  4387. /// Notifies the client of a skill unit.
  4388. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4389. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4390. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4391. /// 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)
  4392. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4393. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4394. unsigned char buf[128];
  4395. nullpo_retv(bl);
  4396. nullpo_retv(unit);
  4397. if (bl->type == BL_PC)
  4398. fd = ((TBL_PC*)bl)->fd;
  4399. if (unit->group->state.guildaura)
  4400. return;
  4401. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4402. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4403. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4404. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4405. else
  4406. unit_id = unit->group->unit_id;
  4407. if (!visible)
  4408. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4409. #if PACKETVER >= 3
  4410. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4411. clif_graffiti(bl, unit, target);
  4412. return;
  4413. }
  4414. #endif
  4415. #if PACKETVER <= 20120702
  4416. header = 0x011f;
  4417. //#if PACKETVER < 20110718
  4418. // header = 0x011f;
  4419. //#elif PACKETVER < 20121212
  4420. // header = 0x08c7;
  4421. #elif PACKETVER < 20130731
  4422. header = 0x099f;
  4423. #else
  4424. header = 0x09ca;
  4425. #endif
  4426. len = packet_len(header);
  4427. WBUFW(buf,pos) = header;
  4428. if (header != 0x011f) {
  4429. WBUFW(buf, pos+2) = len;
  4430. pos += 2;
  4431. }
  4432. WBUFL(buf,pos+2) = unit->bl.id;
  4433. WBUFL(buf,pos+6) = unit->group->src_id;
  4434. WBUFW(buf,pos+10) = unit->bl.x;
  4435. WBUFW(buf,pos+12) = unit->bl.y;
  4436. switch (header) {
  4437. case 0x011f:
  4438. WBUFB(buf,pos+14) = unit_id;
  4439. WBUFB(buf,pos+15) = visible;
  4440. break;
  4441. case 0x08c7:
  4442. WBUFB(buf,pos+14) = unit_id;
  4443. WBUFW(buf,pos+15) = unit->range;
  4444. WBUFB(buf,pos+17) = visible;
  4445. break;
  4446. case 0x099f:
  4447. WBUFL(buf,pos+14) = unit_id;
  4448. WBUFW(buf,pos+18) = unit->range;
  4449. WBUFB(buf,pos+20) = visible;
  4450. break;
  4451. case 0x09ca:
  4452. WBUFL(buf,pos+14) = unit_id;
  4453. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4454. WBUFB(buf,pos+19) = visible;
  4455. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4456. break;
  4457. }
  4458. clif_send(buf, len, bl, target);
  4459. if (unit->group->skill_id == WZ_ICEWALL)
  4460. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4461. }
  4462. /*==========================================
  4463. * Server tells client to remove unit of id 'unit->bl.id'
  4464. *------------------------------------------*/
  4465. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4466. {
  4467. nullpo_retv(unit);
  4468. WFIFOHEAD(fd,packet_len(0x120));
  4469. WFIFOW(fd, 0)=0x120;
  4470. WFIFOL(fd, 2)=unit->bl.id;
  4471. WFIFOSET(fd,packet_len(0x120));
  4472. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4473. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4474. }
  4475. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4476. /// 0120 <id>.L
  4477. void clif_skill_delunit(struct skill_unit *unit)
  4478. {
  4479. unsigned char buf[16];
  4480. nullpo_retv(unit);
  4481. WBUFW(buf, 0)=0x120;
  4482. WBUFL(buf, 2)=unit->bl.id;
  4483. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4484. }
  4485. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4486. /// 01ac <id>.L
  4487. /// Only affects units with class [139,153] client-side.
  4488. void clif_skillunit_update(struct block_list* bl)
  4489. {
  4490. unsigned char buf[6];
  4491. nullpo_retv(bl);
  4492. WBUFW(buf,0) = 0x1ac;
  4493. WBUFL(buf,2) = bl->id;
  4494. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4495. }
  4496. /*==========================================
  4497. *
  4498. *------------------------------------------*/
  4499. static int clif_getareachar(struct block_list* bl,va_list ap)
  4500. {
  4501. struct map_session_data *sd;
  4502. nullpo_ret(bl);
  4503. sd=va_arg(ap,struct map_session_data*);
  4504. if (!clif_session_isValid(sd))
  4505. return 0;
  4506. switch(bl->type){
  4507. case BL_ITEM:
  4508. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4509. break;
  4510. case BL_SKILL:
  4511. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4512. break;
  4513. default:
  4514. if(&sd->bl == bl)
  4515. break;
  4516. clif_getareachar_unit(sd,bl);
  4517. break;
  4518. }
  4519. return 0;
  4520. }
  4521. /*==========================================
  4522. * tbl has gone out of view-size of bl
  4523. *------------------------------------------*/
  4524. int clif_outsight(struct block_list *bl,va_list ap)
  4525. {
  4526. struct block_list *tbl;
  4527. struct view_data *vd;
  4528. TBL_PC *sd, *tsd;
  4529. tbl=va_arg(ap,struct block_list*);
  4530. if(bl == tbl) return 0;
  4531. sd = BL_CAST(BL_PC, bl);
  4532. tsd = BL_CAST(BL_PC, tbl);
  4533. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4534. nullpo_ret(bl);
  4535. switch(bl->type){
  4536. case BL_PC:
  4537. if(sd->vd.class_ != JT_INVISIBLE)
  4538. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4539. if(sd->chatID){
  4540. struct chat_data *cd;
  4541. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4542. if(cd->usersd[0]==sd)
  4543. clif_dispchat(cd,tsd->fd);
  4544. }
  4545. if(sd->state.vending)
  4546. clif_closevendingboard(bl,tsd->fd);
  4547. if(sd->state.buyingstore)
  4548. clif_buyingstore_disappear_entry_single(tsd, sd);
  4549. break;
  4550. case BL_ITEM:
  4551. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4552. break;
  4553. case BL_SKILL:
  4554. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4555. break;
  4556. case BL_NPC:
  4557. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4558. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4559. break;
  4560. default:
  4561. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4562. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4563. break;
  4564. }
  4565. }
  4566. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4567. nullpo_ret(tbl);
  4568. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4569. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4570. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4571. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4572. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4573. }
  4574. return 0;
  4575. }
  4576. /*==========================================
  4577. * tbl has come into view of bl
  4578. *------------------------------------------*/
  4579. int clif_insight(struct block_list *bl,va_list ap)
  4580. {
  4581. struct block_list *tbl;
  4582. TBL_PC *sd, *tsd;
  4583. tbl=va_arg(ap,struct block_list*);
  4584. if (bl == tbl) return 0;
  4585. sd = BL_CAST(BL_PC, bl);
  4586. tsd = BL_CAST(BL_PC, tbl);
  4587. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4588. switch(bl->type){
  4589. case BL_ITEM:
  4590. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4591. break;
  4592. case BL_SKILL:
  4593. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4594. break;
  4595. default:
  4596. clif_getareachar_unit(tsd,bl);
  4597. break;
  4598. }
  4599. }
  4600. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4601. clif_getareachar_unit(sd,tbl);
  4602. }
  4603. return 0;
  4604. }
  4605. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4606. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4607. void clif_skillinfoblock(struct map_session_data *sd)
  4608. {
  4609. int fd;
  4610. int i,len,id;
  4611. nullpo_retv(sd);
  4612. fd = sd->fd;
  4613. if (!session_isActive(fd))
  4614. return;
  4615. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4616. WFIFOW(fd,0) = 0x10f;
  4617. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4618. {
  4619. if( (id = sd->status.skill[i].id) != 0 )
  4620. {
  4621. // workaround for bugreport:5348
  4622. if (len + 37 > 8192)
  4623. break;
  4624. WFIFOW(fd,len) = id;
  4625. WFIFOL(fd,len+2) = skill_get_inf(id);
  4626. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4627. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4628. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4629. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4630. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4631. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4632. else
  4633. WFIFOB(fd,len+36) = 0;
  4634. len += 37;
  4635. }
  4636. }
  4637. WFIFOW(fd,2)=len;
  4638. WFIFOSET(fd,len);
  4639. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4640. for ( ; i < MAX_SKILL; i++)
  4641. {
  4642. if( (id = sd->status.skill[i].id) != 0 )
  4643. {
  4644. clif_addskill(sd, id);
  4645. clif_skillinfo(sd, id, 0);
  4646. }
  4647. }
  4648. }
  4649. /**
  4650. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4651. **/
  4652. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4653. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4654. void clif_addskill(struct map_session_data *sd, int skill_id)
  4655. {
  4656. nullpo_retv(sd);
  4657. int fd = sd->fd;
  4658. uint16 idx = skill_get_index(skill_id);
  4659. if (!session_isActive(fd) || !idx)
  4660. return;
  4661. if( sd->status.skill[idx].id <= 0 )
  4662. return;
  4663. WFIFOHEAD(fd, packet_len(0x111));
  4664. WFIFOW(fd,0) = 0x111;
  4665. WFIFOW(fd,2) = skill_id;
  4666. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4667. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4668. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4669. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4670. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4671. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4672. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4673. else
  4674. WFIFOB(fd,38) = 0;
  4675. WFIFOSET(fd,packet_len(0x111));
  4676. }
  4677. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4678. /// 0441 <skill id>.W
  4679. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4680. {
  4681. #if PACKETVER >= 20081217
  4682. nullpo_retv(sd);
  4683. int fd = sd->fd;
  4684. uint16 idx = skill_get_index(skill_id);
  4685. if (!session_isActive(fd) || !idx)
  4686. return;
  4687. WFIFOHEAD(fd,packet_len(0x441));
  4688. WFIFOW(fd,0) = 0x441;
  4689. WFIFOW(fd,2) = skill_id;
  4690. WFIFOSET(fd,packet_len(0x441));
  4691. #endif
  4692. clif_skillinfoblock(sd);
  4693. }
  4694. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4695. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4696. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4697. nullpo_retv(sd);
  4698. int fd = sd->fd;
  4699. uint16 idx = skill_get_index(skill_id);
  4700. if (!session_isActive(fd) || !idx)
  4701. return;
  4702. WFIFOHEAD(fd, packet_len(0x10e));
  4703. WFIFOW(fd, 0) = 0x10e;
  4704. WFIFOW(fd, 2) = skill_id;
  4705. WFIFOW(fd, 4) = lv;
  4706. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4707. WFIFOW(fd, 8) = range;
  4708. WFIFOB(fd, 10) = upgradable;
  4709. WFIFOSET(fd, packet_len(0x10e));
  4710. }
  4711. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4712. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4713. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4714. {
  4715. nullpo_retv(sd);
  4716. const int fd = sd->fd;
  4717. uint16 idx = skill_get_index(skill_id);
  4718. if (!session_isActive(fd) || !idx)
  4719. return;
  4720. WFIFOHEAD(fd,packet_len(0x7e1));
  4721. WFIFOW(fd,0) = 0x7e1;
  4722. WFIFOW(fd,2) = skill_id;
  4723. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4724. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4725. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4726. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4727. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4728. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4729. else
  4730. WFIFOB(fd,14) = 0;
  4731. WFIFOSET(fd,packet_len(0x7e1));
  4732. }
  4733. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4734. #if PACKETVER >= 20151223
  4735. if( !battle_config.show_skill_scale ){
  4736. return;
  4737. }
  4738. struct PACKET_ZC_SKILL_SCALE p;
  4739. p.PacketType = skillscale;
  4740. p.AID = src_id;
  4741. p.skill_id = skill_id;
  4742. p.skill_lv = skill_lv;
  4743. p.x = x;
  4744. p.y = y;
  4745. p.casttime = casttime;
  4746. if( disguised( bl ) ){
  4747. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4748. p.AID = disguised_bl_id( bl->id );
  4749. clif_send( &p, sizeof( p ), bl, SELF );
  4750. }else{
  4751. clif_send( &p, sizeof( p ), bl, AREA );
  4752. }
  4753. #endif
  4754. }
  4755. /// Notifies clients in area, that an object is about to use a skill.
  4756. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4757. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4758. /// property:
  4759. /// 0 = Yellow cast aura
  4760. /// 1 = Water elemental cast aura
  4761. /// 2 = Earth elemental cast aura
  4762. /// 3 = Fire elemental cast aura
  4763. /// 4 = Wind elemental cast aura
  4764. /// 5 = Poison elemental cast aura
  4765. /// 6 = Holy elemental cast aura
  4766. /// ? = like 0
  4767. /// is disposable:
  4768. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4769. /// 1 = no text
  4770. 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)
  4771. {
  4772. #if PACKETVER < 20091124
  4773. const int cmd = 0x13e;
  4774. #else
  4775. const int cmd = 0x7fb;
  4776. #endif
  4777. unsigned char buf[32];
  4778. WBUFW(buf,0) = cmd;
  4779. WBUFL(buf,2) = src_id;
  4780. WBUFL(buf,6) = dst_id;
  4781. WBUFW(buf,10) = dst_x;
  4782. WBUFW(buf,12) = dst_y;
  4783. WBUFW(buf,14) = skill_id;
  4784. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4785. WBUFL(buf,20) = casttime;
  4786. #if PACKETVER >= 20091124
  4787. WBUFB(buf,24) = 0; // isDisposable
  4788. #endif
  4789. if (disguised(bl)) {
  4790. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4791. WBUFL(buf,2) = disguised_bl_id( src_id );
  4792. clif_send(buf,packet_len(cmd), bl, SELF);
  4793. } else
  4794. clif_send(buf,packet_len(cmd), bl, AREA);
  4795. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4796. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4797. }
  4798. }
  4799. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4800. /// 01b9 <id>.L
  4801. void clif_skillcastcancel(struct block_list* bl)
  4802. {
  4803. unsigned char buf[16];
  4804. nullpo_retv(bl);
  4805. WBUFW(buf,0) = 0x1b9;
  4806. WBUFL(buf,2) = bl->id;
  4807. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4808. }
  4809. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4810. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4811. /// num (only used when skill id = NV_BASIC and cause = 0):
  4812. /// 0 = "skill failed" MsgStringTable[159]
  4813. /// 1 = "no emotions" MsgStringTable[160]
  4814. /// 2 = "no sit" MsgStringTable[161]
  4815. /// 3 = "no chat" MsgStringTable[162]
  4816. /// 4 = "no party" MsgStringTable[163]
  4817. /// 5 = "no shout" MsgStringTable[164]
  4818. /// 6 = "no PKing" MsgStringTable[165]
  4819. /// 7 = "no alligning" MsgStringTable[383]
  4820. /// ? = ignored
  4821. /// cause:
  4822. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4823. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4824. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4825. /// "skill failed" MsgStringTable[204] (otherwise)
  4826. /// ... = @see enum useskill_fail_cause
  4827. /// ? = ignored
  4828. ///
  4829. /// if(result!=0) doesn't display any of the previous messages
  4830. /// Note: when this packet is received an unknown flag is always set to 0,
  4831. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4832. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  4833. nullpo_retv( sd );
  4834. int fd = sd->fd;
  4835. if( !session_isActive( fd ) ){
  4836. return;
  4837. }
  4838. if(battle_config.display_skill_fail&1)
  4839. return; //Disable all skill failed messages
  4840. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4841. return; //Disable delay failed messages
  4842. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4843. return;
  4844. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4845. return;
  4846. struct PACKET_ZC_ACK_TOUSESKILL p;
  4847. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  4848. p.skillId = skill_id;
  4849. p.btype = btype;
  4850. p.itemId = itemId;
  4851. p.flag = 0; // 0 - failed
  4852. p.cause = cause;
  4853. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4854. }
  4855. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4856. /// 043d <skill ID>.W <tick>.L
  4857. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4858. {
  4859. #if PACKETVER>=20081112
  4860. int fd;
  4861. nullpo_retv(sd);
  4862. fd=sd->fd;
  4863. WFIFOHEAD(fd,packet_len(0x43d));
  4864. WFIFOW(fd,0) = 0x43d;
  4865. WFIFOW(fd,2) = skill_id;
  4866. WFIFOL(fd,4) = client_tick(tick);
  4867. WFIFOSET(fd,packet_len(0x43d));
  4868. #endif
  4869. }
  4870. /// Skill attack effect and damage.
  4871. /// 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)
  4872. /// 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)
  4873. 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)
  4874. {
  4875. unsigned char buf[64];
  4876. struct status_change *sc;
  4877. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4878. nullpo_ret(src);
  4879. nullpo_ret(dst);
  4880. type = clif_calc_delay(type,div,damage,ddelay);
  4881. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4882. if(sc->data[SC_HALLUCINATION] && damage)
  4883. damage = clif_hallucination_damage();
  4884. }
  4885. #if PACKETVER < 3
  4886. WBUFW(buf,0)=0x114;
  4887. WBUFW(buf,2)=skill_id;
  4888. WBUFL(buf,4)=src->id;
  4889. WBUFL(buf,8)=dst->id;
  4890. WBUFL(buf,12)=client_tick(tick);
  4891. WBUFL(buf,16)=sdelay;
  4892. WBUFL(buf,20)=ddelay;
  4893. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4894. WBUFW(buf,24)=damage?div:0;
  4895. } else {
  4896. WBUFW(buf,24)=damage;
  4897. }
  4898. WBUFW(buf,26)=skill_lv;
  4899. WBUFW(buf,28)=div;
  4900. WBUFB(buf,30)=type;
  4901. if (disguised(dst)) {
  4902. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4903. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4904. clif_send(buf,packet_len(0x114),dst,SELF);
  4905. } else
  4906. clif_send(buf,packet_len(0x114),dst,AREA);
  4907. if(disguised(src)) {
  4908. WBUFL(buf,4)=disguised_bl_id(src->id);
  4909. if (disguised(dst))
  4910. WBUFL(buf,8)=dst->id;
  4911. if(damage > 0)
  4912. WBUFW(buf,24)=-1;
  4913. clif_send(buf,packet_len(0x114),src,SELF);
  4914. }
  4915. #else
  4916. WBUFW(buf,0)=0x1de;
  4917. WBUFW(buf,2)=skill_id;
  4918. WBUFL(buf,4)=src->id;
  4919. WBUFL(buf,8)=dst->id;
  4920. WBUFL(buf,12)=client_tick(tick);
  4921. WBUFL(buf,16)=sdelay;
  4922. WBUFL(buf,20)=ddelay;
  4923. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4924. WBUFL(buf,24)=damage?div:0;
  4925. } else {
  4926. WBUFL(buf,24)=damage;
  4927. }
  4928. WBUFW(buf,28)=skill_lv;
  4929. WBUFW(buf,30)=div;
  4930. // For some reason, late 2013 and newer clients have
  4931. // a issue that causes players and monsters to endure
  4932. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4933. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4934. #if PACKETVER < 20131223
  4935. WBUFB(buf,32)=type;
  4936. #else
  4937. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  4938. #endif
  4939. if (disguised(dst)) {
  4940. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4941. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4942. clif_send(buf,packet_len(0x1de),dst,SELF);
  4943. } else
  4944. clif_send(buf,packet_len(0x1de),dst,AREA);
  4945. if(disguised(src)) {
  4946. WBUFL(buf,4)=disguised_bl_id(src->id);
  4947. if (disguised(dst))
  4948. WBUFL(buf,8)=dst->id;
  4949. if(damage > 0)
  4950. WBUFL(buf,24)=-1;
  4951. clif_send(buf,packet_len(0x1de),src,SELF);
  4952. }
  4953. #endif
  4954. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4955. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4956. }
  4957. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4958. /// 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
  4959. /*
  4960. 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)
  4961. {
  4962. unsigned char buf[64];
  4963. struct status_change *sc;
  4964. nullpo_ret(src);
  4965. nullpo_ret(dst);
  4966. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4967. type = clif_calc_delay(type,div,damage,ddelay);
  4968. sc = status_get_sc(dst);
  4969. if(sc && sc->count) {
  4970. if(sc->data[SC_HALLUCINATION] && damage)
  4971. damage = clif_hallucination_damage();
  4972. }
  4973. WBUFW(buf,0)=0x115;
  4974. WBUFW(buf,2)=skill_id;
  4975. WBUFL(buf,4)=src->id;
  4976. WBUFL(buf,8)=dst->id;
  4977. WBUFL(buf,12)=client_tick(tick);
  4978. WBUFL(buf,16)=sdelay;
  4979. WBUFL(buf,20)=ddelay;
  4980. WBUFW(buf,24)=dst->x;
  4981. WBUFW(buf,26)=dst->y;
  4982. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4983. WBUFW(buf,28)=damage?div:0;
  4984. } else {
  4985. WBUFW(buf,28)=damage;
  4986. }
  4987. WBUFW(buf,30)=skill_lv;
  4988. WBUFW(buf,32)=div;
  4989. WBUFB(buf,34)=type;
  4990. clif_send(buf,packet_len(0x115),src,AREA);
  4991. if(disguised(src)) {
  4992. WBUFL(buf,4)=disguised_bl_id(src->id);
  4993. if(damage > 0)
  4994. WBUFW(buf,28)=-1;
  4995. clif_send(buf,packet_len(0x115),src,SELF);
  4996. }
  4997. if (disguised(dst)) {
  4998. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4999. if (disguised(src))
  5000. WBUFL(buf,4)=src->id;
  5001. else if(damage > 0)
  5002. WBUFW(buf,28)=-1;
  5003. clif_send(buf,packet_len(0x115),dst,SELF);
  5004. }
  5005. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5006. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5007. }
  5008. */
  5009. /// Non-damaging skill effect
  5010. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5011. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5012. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5013. {
  5014. unsigned char buf[17];
  5015. #if PACKETVER < 20130731
  5016. const int cmd = 0x11a;
  5017. #else
  5018. const int cmd = 0x9cb;
  5019. #endif
  5020. int offset = 0;
  5021. bool success = ( tick != 0 );
  5022. nullpo_ret(dst);
  5023. WBUFW(buf,0) = cmd;
  5024. WBUFW(buf,2) = skill_id;
  5025. #if PACKETVER < 20130731
  5026. WBUFW(buf,4) = min(heal, INT16_MAX);
  5027. #else
  5028. WBUFL(buf,4) = min(heal, INT32_MAX);
  5029. offset += 2;
  5030. #endif
  5031. WBUFL(buf,6+offset) = dst->id;
  5032. WBUFL(buf,10+offset) = src ? src->id : 0;
  5033. WBUFB(buf,14+offset) = success;
  5034. if (disguised(dst)) {
  5035. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5036. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5037. clif_send(buf, packet_len(cmd), dst, SELF);
  5038. } else
  5039. clif_send(buf, packet_len(cmd), dst, AREA);
  5040. if(src && disguised(src)) {
  5041. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5042. if (disguised(dst))
  5043. WBUFL(buf,6+offset) = dst->id;
  5044. clif_send(buf, packet_len(cmd), src, SELF);
  5045. }
  5046. return success;
  5047. }
  5048. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5049. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5050. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5051. {
  5052. unsigned char buf[32];
  5053. nullpo_retv(src);
  5054. WBUFW(buf,0)=0x117;
  5055. WBUFW(buf,2)=skill_id;
  5056. WBUFL(buf,4)=src->id;
  5057. WBUFW(buf,8)=val;
  5058. WBUFW(buf,10)=x;
  5059. WBUFW(buf,12)=y;
  5060. WBUFL(buf,14)=client_tick(tick);
  5061. if(disguised(src)) {
  5062. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5063. WBUFL(buf,4)=disguised_bl_id(src->id);
  5064. clif_send(buf,packet_len(0x117),src,SELF);
  5065. } else
  5066. clif_send(buf,packet_len(0x117),src,AREA);
  5067. }
  5068. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5069. /// 011c <skill id>.W { <map name>.16B }*4
  5070. 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)
  5071. {
  5072. int fd;
  5073. nullpo_retv(sd);
  5074. fd = sd->fd;
  5075. WFIFOHEAD(fd,packet_len(0x11c));
  5076. WFIFOW(fd,0) = 0x11c;
  5077. WFIFOW(fd,2) = skill_id;
  5078. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5079. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5080. else // normal map name
  5081. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5082. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5083. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5084. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5085. WFIFOSET(fd,packet_len(0x11c));
  5086. sd->menuskill_id = skill_id;
  5087. if (skill_id == AL_WARP) {
  5088. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5089. sd->state.workinprogress = WIP_DISABLE_ALL;
  5090. } else
  5091. sd->menuskill_val = skill_lv;
  5092. }
  5093. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5094. /// 011e <type>.B
  5095. /// type:
  5096. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5097. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5098. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5099. ///
  5100. /// @param sd Who receives the message
  5101. /// @param type What message
  5102. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5103. {
  5104. int fd;
  5105. nullpo_retv(sd);
  5106. fd=sd->fd;
  5107. WFIFOHEAD(fd,packet_len(0x11e));
  5108. WFIFOW(fd,0)=0x11e;
  5109. WFIFOB(fd,2)=type;
  5110. WFIFOSET(fd,packet_len(0x11e));
  5111. }
  5112. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5113. /// 0189 <type>.W
  5114. /// type:
  5115. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5116. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5117. ///
  5118. /// @param sd Who receives the message
  5119. /// @param type What message
  5120. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5121. {
  5122. int fd;
  5123. nullpo_retv(sd);
  5124. fd=sd->fd;
  5125. WFIFOHEAD(fd,packet_len(0x189));
  5126. WFIFOW(fd,0)=0x189;
  5127. WFIFOW(fd,2)=type;
  5128. WFIFOSET(fd,packet_len(0x189));
  5129. }
  5130. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5131. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5132. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5133. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5134. {
  5135. struct status_data *status;
  5136. unsigned char buf[64];
  5137. int i, fix;
  5138. nullpo_retv(sd);
  5139. nullpo_retv(dst);
  5140. if( dst->type != BL_MOB )
  5141. return;
  5142. status = status_get_status_data(dst);
  5143. WBUFW(buf, 0)=0x18c;
  5144. WBUFW(buf, 2)=status_get_class(dst);
  5145. WBUFW(buf, 4)=status_get_lv(dst);
  5146. WBUFW(buf, 6)=status->size;
  5147. WBUFL(buf, 8)=status->hp;
  5148. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5149. +(battle_config.estimation_type&2?status->def2:0);
  5150. WBUFW(buf,14)=status->race;
  5151. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5152. +(battle_config.estimation_type&2?status->mdef2:0);
  5153. WBUFW(buf,18)= status->def_ele;
  5154. for(i=0;i<9;i++)
  5155. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5156. WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5157. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5158. }
  5159. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5160. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5161. /// material id:
  5162. /// unused by the client
  5163. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5164. nullpo_retv(sd);
  5165. int fd = sd->fd;
  5166. if( !session_isActive( fd ) ){
  5167. return;
  5168. }
  5169. if (sd->menuskill_id == skill_id)
  5170. return; //Avoid resending the menu twice or more times...
  5171. if (skill_id == GC_CREATENEWPOISON)
  5172. skill_id = GC_RESEARCHNEWPOISON;
  5173. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5174. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5175. p->packetType = 0x18d;
  5176. int count = 0;
  5177. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5178. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5179. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5180. )
  5181. {
  5182. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5183. p->items[count].material[0] = 0;
  5184. p->items[count].material[1] = 0;
  5185. p->items[count].material[2] = 0;
  5186. count++;
  5187. }
  5188. }
  5189. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5190. WFIFOSET( fd, p->packetLength );
  5191. if( count > 0 ){
  5192. sd->menuskill_id = skill_id;
  5193. sd->menuskill_val = trigger;
  5194. return;
  5195. }
  5196. }
  5197. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5198. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5199. /// mk type:
  5200. /// 1 = cooking
  5201. /// 2 = arrow
  5202. /// 3 = elemental
  5203. /// 4 = GN_MIX_COOKING
  5204. /// 5 = GN_MAKEBOMB
  5205. /// 6 = GN_S_PHARMACY
  5206. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5207. nullpo_retv( sd );
  5208. // Avoid resending the menu twice or more times...
  5209. if( sd->menuskill_id == skill_id ){
  5210. return;
  5211. }
  5212. int fd = sd->fd;
  5213. if( !session_isActive( fd ) ){
  5214. return;
  5215. }
  5216. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5217. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5218. p->packetType = 0x25a;
  5219. p->makeItem = list_type; // list type
  5220. int count = 0;
  5221. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5222. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5223. continue;
  5224. }
  5225. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5226. count++;
  5227. }
  5228. if( count > 0 || skill_id == AM_PHARMACY ){
  5229. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5230. WFIFOSET( fd, p->packetLength );
  5231. sd->menuskill_id = skill_id;
  5232. sd->menuskill_val = trigger;
  5233. sd->menuskill_val2 = qty; // amount.
  5234. }else{
  5235. clif_menuskill_clear(sd);
  5236. #if PACKETVER >= 20090922
  5237. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5238. #else
  5239. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5240. WFIFOSET( fd, p->packetLength );
  5241. #endif
  5242. }
  5243. }
  5244. /// Notifies clients of a status change.
  5245. /// 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)]
  5246. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5247. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5248. /// @param bl Sends packet to clients around this object
  5249. /// @param id ID of object that has this effect
  5250. /// @param type Status icon see enum efst_types
  5251. /// @param flag 1:Active, 0:Deactive
  5252. /// @param tick Duration in ms
  5253. /// @param val1
  5254. /// @param val2
  5255. /// @param val3
  5256. 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)
  5257. {
  5258. unsigned char buf[32];
  5259. if (type == EFST_BLANK) //It shows nothing on the client...
  5260. return;
  5261. if (type == EFST_POSTDELAY && tick == 0)
  5262. return;
  5263. nullpo_retv(bl);
  5264. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5265. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5266. tick = 200;
  5267. #if PACKETVER >= 20120618
  5268. if (flag && battle_config.display_status_timers)
  5269. WBUFW(buf,0) = 0x983;
  5270. else
  5271. #elif PACKETVER >= 20090121
  5272. if (flag && battle_config.display_status_timers)
  5273. WBUFW(buf,0) = 0x43f;
  5274. else
  5275. #endif
  5276. WBUFW(buf,0) = 0x196;
  5277. WBUFW(buf,2) = type;
  5278. WBUFL(buf,4) = id;
  5279. WBUFB(buf,8) = flag;
  5280. #if PACKETVER >= 20120618
  5281. if (flag && battle_config.display_status_timers) {
  5282. if (tick <= 0)
  5283. tick = 9999; // this is indeed what official servers do
  5284. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5285. WBUFL(buf,13) = client_tick(tick);
  5286. WBUFL(buf,17) = val1;
  5287. WBUFL(buf,21) = val2;
  5288. WBUFL(buf,25) = val3;
  5289. }
  5290. #elif PACKETVER >= 20090121
  5291. if (flag && battle_config.display_status_timers) {
  5292. if (tick <= 0)
  5293. tick = 9999; // this is indeed what official servers do
  5294. WBUFL(buf,9) = client_tick(tick);
  5295. WBUFL(buf,13) = val1;
  5296. WBUFL(buf,17) = val2;
  5297. WBUFL(buf,21) = val3;
  5298. }
  5299. #endif
  5300. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5301. }
  5302. /* Sends status effect to clients around the bl
  5303. * @param bl Object that has the effect
  5304. * @param type Status icon see enum efst_types
  5305. * @param flag 1:Active, 0:Deactive
  5306. * @param tick Duration in ms
  5307. * @param val1
  5308. * @param val2
  5309. * @param val3
  5310. */
  5311. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5312. struct map_session_data *sd = NULL;
  5313. if (type == EFST_BLANK) //It shows nothing on the client...
  5314. return;
  5315. if (type == EFST_POSTDELAY && tick == 0)
  5316. return;
  5317. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5318. return;
  5319. nullpo_retv(bl);
  5320. sd = BL_CAST(BL_PC, bl);
  5321. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5322. return;
  5323. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5324. }
  5325. /**
  5326. * Send any active EFST to those around.
  5327. * @param tbl: Unit to send the packet to
  5328. * @param bl: Objects walking into view
  5329. * @param target: Client send type
  5330. */
  5331. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5332. unsigned char i;
  5333. struct sc_display_entry **sc_display;
  5334. unsigned char sc_display_count;
  5335. bool spheres_sent;
  5336. nullpo_retv(bl);
  5337. switch( bl->type ){
  5338. case BL_PC: {
  5339. struct map_session_data* sd = (struct map_session_data*)bl;
  5340. sc_display = sd->sc_display;
  5341. sc_display_count = sd->sc_display_count;
  5342. spheres_sent = !sd->state.connect_new;
  5343. }
  5344. break;
  5345. case BL_NPC: {
  5346. struct npc_data* nd = (struct npc_data*)bl;
  5347. sc_display = nd->sc_display;
  5348. sc_display_count = nd->sc_display_count;
  5349. spheres_sent = true;
  5350. }
  5351. break;
  5352. default:
  5353. return;
  5354. }
  5355. for (i = 0; i < sc_display_count; i++) {
  5356. enum sc_type type = sc_display[i]->type;
  5357. struct status_change *sc = status_get_sc(bl);
  5358. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5359. t_tick tick = 0;
  5360. if (td)
  5361. tick = DIFF_TICK(td->tick, gettick());
  5362. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5363. #if PACKETVER > 20120418
  5364. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5365. #else
  5366. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, AREA_WOS);
  5367. #endif
  5368. }else{
  5369. #if PACKETVER > 20120418
  5370. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5371. #else
  5372. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5373. #endif
  5374. }
  5375. }
  5376. }
  5377. /// Notifies the client when a player enters the screen with an active EFST.
  5378. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5379. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5380. 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) {
  5381. #if PACKETVER >= 20111108
  5382. unsigned char buf[32];
  5383. #if PACKETVER >= 20120618
  5384. const int cmd = 0x984;
  5385. #elif PACKETVER >= 20111108
  5386. const int cmd = 0x8ff;
  5387. #endif
  5388. int offset = 0;
  5389. if (type == EFST_BLANK)
  5390. return;
  5391. nullpo_retv(bl);
  5392. if (tick <= 0)
  5393. tick = 9999;
  5394. WBUFW(buf,offset + 0) = cmd;
  5395. WBUFL(buf,offset + 2) = tid;
  5396. WBUFW(buf,offset + 6) = type;
  5397. #if PACKETVER >= 20111108
  5398. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5399. #if PACKETVER >= 20120618
  5400. WBUFL(buf,offset + 12) = client_tick(tick);
  5401. offset += 4;
  5402. #endif
  5403. WBUFL(buf,offset + 12) = val1;
  5404. WBUFL(buf,offset + 16) = val2;
  5405. WBUFL(buf,offset + 20) = val3;
  5406. #endif
  5407. clif_send(buf,packet_len(cmd),bl,target);
  5408. #endif
  5409. }
  5410. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5411. /// 008e <packet len>.W <message>.?B
  5412. void clif_displaymessage(const int fd, const char* mes)
  5413. {
  5414. nullpo_retv(mes);
  5415. if( session_isActive( fd ) ){
  5416. char *message, *line;
  5417. message = aStrdup(mes);
  5418. line = strtok(message, "\n");
  5419. while(line != NULL) {
  5420. #if PACKETVER == 20141022
  5421. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5422. /** so we redirect to ZC_NPC_CHAT **/
  5423. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5424. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5425. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5426. if (len > 0) {
  5427. WFIFOHEAD(fd, 13 + len);
  5428. WFIFOW(fd, 0) = 0x2C1;
  5429. WFIFOW(fd, 2) = 13 + len;
  5430. WFIFOL(fd, 4) = 0;
  5431. WFIFOL(fd, 8) = color;
  5432. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5433. WFIFOSET(fd, WFIFOW(fd, 2));
  5434. }
  5435. #else
  5436. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5437. int len = strnlen(line, CHAT_SIZE_MAX);
  5438. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5439. WFIFOHEAD(fd, 5 + len);
  5440. WFIFOW(fd,0) = 0x8e;
  5441. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5442. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5443. WFIFOSET(fd, 5 + len);
  5444. }
  5445. #endif
  5446. line = strtok(NULL, "\n");
  5447. }
  5448. aFree(message);
  5449. }
  5450. }
  5451. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5452. /// 009a <packet len>.W <message>.?B
  5453. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5454. {
  5455. nullpo_retv(mes);
  5456. if (len < 2)
  5457. return;
  5458. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5459. p->packetType = HEADER_ZC_BROADCAST;
  5460. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5461. if( ( type&BC_BLUE ) != 0 ){
  5462. const char* color = "blue";
  5463. int16 length = (int16)strlen( color );
  5464. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5465. strcpy( p->message, color );
  5466. strncpy( &p->message[length], mes, len );
  5467. p->PacketLength += length;
  5468. }else if( ( type&BC_WOE ) != 0 ){
  5469. const char* color = "ssss";
  5470. int16 length = (int16)strlen( color );
  5471. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5472. strcpy( p->message, color );
  5473. strncpy( &p->message[length], mes, len );
  5474. p->PacketLength += length;
  5475. }else{
  5476. strncpy( p->message, mes, len );
  5477. }
  5478. clif_send( p, p->PacketLength, bl, target );
  5479. }
  5480. /*==========================================
  5481. * Displays a message on a 'bl' to all it's nearby clients
  5482. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5483. *------------------------------------------*/
  5484. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5485. nullpo_retv(bl);
  5486. nullpo_retv(message);
  5487. int16 len = (int16)( strlen( message ) + 1 );
  5488. if( len > CHAT_SIZE_MAX ) {
  5489. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5490. len = CHAT_SIZE_MAX;
  5491. }
  5492. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5493. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5494. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5495. p->GID = bl->id;
  5496. safestrncpy( p->Message, message, len );
  5497. clif_send( p, p->PacketLength, bl, target );
  5498. }
  5499. /// Send broadcast message with font formatting.
  5500. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5501. 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)
  5502. {
  5503. nullpo_retv(mes);
  5504. if (len < 2)
  5505. return;
  5506. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5507. p->packetType = HEADER_ZC_BROADCAST2;
  5508. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5509. p->fontColor = fontColor;
  5510. p->fontType = fontType;
  5511. p->fontSize = fontSize;
  5512. p->fontAlign = fontAlign;
  5513. p->fontY = fontY;
  5514. strncpy( p->message, mes, len );
  5515. clif_send( p, p->PacketLength, bl, target );
  5516. }
  5517. /*
  5518. * Display *msg to all *users in channel
  5519. */
  5520. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5521. DBIterator *iter;
  5522. struct map_session_data *user;
  5523. unsigned short msg_len = 0, len = 0;
  5524. unsigned char buf[CHAT_SIZE_MAX];
  5525. if (!channel || !msg)
  5526. return;
  5527. msg_len = (unsigned short)(strlen(msg) + 1);
  5528. if( msg_len > sizeof(buf)-12 ) {
  5529. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5530. msg_len = sizeof(buf)-12;
  5531. }
  5532. WBUFW(buf,0) = 0x2C1;
  5533. WBUFW(buf,2) = (len = msg_len + 12);
  5534. WBUFL(buf,4) = 0;
  5535. WBUFL(buf,8) = color;
  5536. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5537. iter = db_iterator(channel->users);
  5538. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5539. clif_send(buf, len, &user->bl, SELF);
  5540. }
  5541. dbi_destroy(iter);
  5542. }
  5543. /// Displays heal effect.
  5544. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5545. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5546. /// var id:
  5547. /// 5 = HP (SP_HP)
  5548. /// 7 = SP (SP_SP)
  5549. /// ? = ignored
  5550. void clif_heal(int fd,int type,int val) {
  5551. #if PACKETVER < 20141022
  5552. const int cmd = 0x13d;
  5553. #else
  5554. const int cmd = 0xa27;
  5555. #endif
  5556. WFIFOHEAD(fd, packet_len(cmd));
  5557. WFIFOW(fd,0) = cmd;
  5558. WFIFOW(fd,2) = type;
  5559. #if PACKETVER < 20141022
  5560. WFIFOW(fd,4) = min(val, INT16_MAX);
  5561. #else
  5562. WFIFOL(fd,4) = min(val, INT32_MAX);
  5563. #endif
  5564. WFIFOSET(fd, packet_len(cmd));
  5565. }
  5566. /// Displays resurrection effect (ZC_RESURRECTION).
  5567. /// 0148 <id>.L <type>.W
  5568. /// type:
  5569. /// ignored
  5570. void clif_resurrection(struct block_list *bl,int type)
  5571. {
  5572. unsigned char buf[16];
  5573. nullpo_retv(bl);
  5574. WBUFW(buf,0)=0x148;
  5575. WBUFL(buf,2)=bl->id;
  5576. WBUFW(buf,6)=0;
  5577. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5578. if (disguised(bl))
  5579. clif_spawn(bl);
  5580. }
  5581. /// Sets the map property
  5582. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5583. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5584. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5585. {
  5586. #if PACKETVER >= 20121010
  5587. short cmd = 0x99b;
  5588. unsigned char buf[8];
  5589. #else
  5590. short cmd = 0x199;
  5591. unsigned char buf[4];
  5592. #endif
  5593. WBUFW(buf,0)=cmd;
  5594. WBUFW(buf,2)=property;
  5595. #if PACKETVER >= 20121010
  5596. struct map_data *mapdata = map_getmapdata(bl->m);
  5597. 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)
  5598. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5599. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5600. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5601. ((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
  5602. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5603. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5604. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5605. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5606. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5607. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5608. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5609. #endif
  5610. clif_send(buf,packet_len(cmd),bl,t);
  5611. }
  5612. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5613. /// 01d6 <type>.W
  5614. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5615. {
  5616. int fd;
  5617. nullpo_retv(sd);
  5618. fd=sd->fd;
  5619. WFIFOHEAD(fd,packet_len(0x1D6));
  5620. WFIFOW(fd,0)=0x1D6;
  5621. WFIFOW(fd,2)=type;
  5622. WFIFOSET(fd,packet_len(0x1D6));
  5623. }
  5624. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5625. /// 019a <id>.L <ranking>.L <total>.L
  5626. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5627. {
  5628. if(type == 2) {
  5629. int fd = sd->fd;
  5630. WFIFOHEAD(fd,packet_len(0x19a));
  5631. WFIFOW(fd,0) = 0x19a;
  5632. WFIFOL(fd,2) = sd->bl.id;
  5633. WFIFOL(fd,6) = pvprank;
  5634. WFIFOL(fd,10) = pvpnum;
  5635. WFIFOSET(fd,packet_len(0x19a));
  5636. } else {
  5637. unsigned char buf[32];
  5638. WBUFW(buf,0) = 0x19a;
  5639. WBUFL(buf,2) = sd->bl.id;
  5640. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5641. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5642. else
  5643. WBUFL(buf,6) = pvprank;
  5644. WBUFL(buf,10) = pvpnum;
  5645. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5646. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5647. else if(!type)
  5648. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5649. else
  5650. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5651. }
  5652. }
  5653. /*==========================================
  5654. *
  5655. *------------------------------------------*/
  5656. void clif_map_property_mapall(int map_idx, enum map_property property)
  5657. {
  5658. struct block_list bl;
  5659. bl.id = 0;
  5660. bl.type = BL_NUL;
  5661. bl.m = map_idx;
  5662. clif_map_property( &bl, property, ALL_SAMEMAP );
  5663. }
  5664. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5665. /// 0188 <result>.W <index>.W <refine>.W
  5666. /// result:
  5667. /// 0 = success
  5668. /// 1 = failure
  5669. /// 2 = downgrade
  5670. void clif_refine(int fd, int fail, int index, int val)
  5671. {
  5672. WFIFOHEAD(fd,packet_len(0x188));
  5673. WFIFOW(fd,0)=0x188;
  5674. WFIFOW(fd,2)=fail;
  5675. WFIFOW(fd,4)=index+2;
  5676. WFIFOW(fd,6)=val;
  5677. WFIFOSET(fd,packet_len(0x188));
  5678. }
  5679. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5680. /// 0223 <result>.L <nameid>.W
  5681. /// result:
  5682. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5683. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5684. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5685. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5686. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5687. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5688. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5689. p.result = result;
  5690. p.itemId = client_nameid( item_id );
  5691. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5692. }
  5693. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5694. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5695. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5696. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5697. int fd;
  5698. nullpo_retv(sd);
  5699. fd = sd->fd;
  5700. #if PACKETVER < 20091104
  5701. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5702. WFIFOW(fd,0) = 0x97;
  5703. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5704. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5705. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5706. WFIFOSET(fd,WFIFOW(fd,2));
  5707. #else
  5708. struct map_session_data *ssd = map_nick2sd(nick,false);
  5709. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5710. WFIFOW(fd,0) = 0x97;
  5711. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5712. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5713. // If it is not a message from the server or a player from another map-server
  5714. if( ssd ){
  5715. gmlvl = pc_get_group_level(ssd);
  5716. }
  5717. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5718. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5719. WFIFOSET(fd,WFIFOW(fd,2));
  5720. #endif
  5721. }
  5722. /// Inform the player about the result of his whisper action
  5723. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5724. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5725. /// result:
  5726. /// 0 = success to send wisper
  5727. /// 1 = target character is not loged in
  5728. /// 2 = ignored by target
  5729. /// 3 = everyone ignored by target
  5730. void clif_wis_end(int fd, int result)
  5731. {
  5732. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5733. #if PACKETVER < 20131223
  5734. const int cmd = 0x98;
  5735. #else
  5736. const int cmd = 0x9df;
  5737. #endif
  5738. if (!sd)
  5739. return;
  5740. WFIFOHEAD(fd,packet_len(cmd));
  5741. WFIFOW(fd,0) = cmd;
  5742. WFIFOB(fd,2) = (char)result;
  5743. #if PACKETVER >= 20131223
  5744. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5745. #endif
  5746. WFIFOSET(fd,packet_len(cmd));
  5747. }
  5748. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5749. /// 0194 <char id>.L <name>.24B
  5750. /// 0af7 <flag>.W <char id>.L <name>.24B
  5751. void clif_solved_charname(int fd, int charid, const char* name)
  5752. {
  5753. #if PACKETVER >= 20180221
  5754. WFIFOHEAD(fd,packet_len(0xaf7));
  5755. WFIFOW(fd,0) = 0xaf7;
  5756. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5757. WFIFOL(fd,4) = charid;
  5758. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5759. WFIFOSET(fd,packet_len(0x0af7));
  5760. #else
  5761. WFIFOHEAD(fd,packet_len(0x194));
  5762. WFIFOW(fd,0)=0x194;
  5763. WFIFOL(fd,2)=charid;
  5764. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5765. WFIFOSET(fd,packet_len(0x194));
  5766. #endif
  5767. }
  5768. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5769. /// 017b <packet len>.W { <name id>.W }*
  5770. void clif_use_card(struct map_session_data *sd,int idx)
  5771. {
  5772. int i,c,ep;
  5773. int fd=sd->fd;
  5774. nullpo_retv(sd);
  5775. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5776. return;
  5777. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5778. return; //Avoid parsing invalid item indexes (no card/no item)
  5779. ep=sd->inventory_data[idx]->equip;
  5780. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5781. WFIFOW(fd,0)=0x17b;
  5782. for(i=c=0;i<MAX_INVENTORY;i++){
  5783. int j;
  5784. if(sd->inventory_data[i] == NULL)
  5785. continue;
  5786. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5787. continue;
  5788. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5789. continue;
  5790. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5791. continue;
  5792. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5793. continue;
  5794. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5795. continue;
  5796. 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.
  5797. continue;
  5798. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5799. if( j == sd->inventory_data[i]->slots ) // No room
  5800. continue;
  5801. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5802. continue;
  5803. WFIFOW(fd,4+c*2)=i+2;
  5804. c++;
  5805. }
  5806. if( !c ) return; // no item is available for card insertion
  5807. WFIFOW(fd,2)=4+c*2;
  5808. WFIFOSET(fd,WFIFOW(fd,2));
  5809. }
  5810. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5811. /// 017d <equip index>.W <card index>.W <result>.B
  5812. /// result:
  5813. /// 0 = success
  5814. /// 1 = failure
  5815. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5816. {
  5817. int fd;
  5818. nullpo_retv(sd);
  5819. fd=sd->fd;
  5820. WFIFOHEAD(fd,packet_len(0x17d));
  5821. WFIFOW(fd,0)=0x17d;
  5822. WFIFOW(fd,2)=idx_equip+2;
  5823. WFIFOW(fd,4)=idx_card+2;
  5824. WFIFOB(fd,6)=flag;
  5825. WFIFOSET(fd,packet_len(0x17d));
  5826. }
  5827. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5828. /// 0177 <packet len>.W { <index>.W }*
  5829. void clif_item_identify_list(struct map_session_data *sd)
  5830. {
  5831. int i,c;
  5832. int fd;
  5833. nullpo_retv(sd);
  5834. fd=sd->fd;
  5835. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5836. WFIFOW(fd,0)=0x177;
  5837. for(i=c=0;i<MAX_INVENTORY;i++){
  5838. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5839. WFIFOW(fd,c*2+4)=client_index(i);
  5840. c++;
  5841. }
  5842. }
  5843. if(c > 0) {
  5844. WFIFOW(fd,2)=c*2+4;
  5845. WFIFOSET(fd,WFIFOW(fd,2));
  5846. sd->menuskill_id = MC_IDENTIFY;
  5847. sd->menuskill_val = c;
  5848. sd->state.workinprogress = WIP_DISABLE_ALL;
  5849. }
  5850. }
  5851. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5852. /// 0179 <index>.W <result>.B
  5853. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5854. {
  5855. int fd;
  5856. nullpo_retv(sd);
  5857. fd=sd->fd;
  5858. WFIFOHEAD(fd,packet_len(0x179));
  5859. WFIFOW(fd, 0)=0x179;
  5860. WFIFOW(fd, 2)=idx+2;
  5861. WFIFOB(fd, 4)=flag;
  5862. WFIFOSET(fd,packet_len(0x179));
  5863. }
  5864. /// Presents a list of items that can be repaired.
  5865. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  5866. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  5867. nullpo_retv( sd );
  5868. nullpo_retv( dstsd );
  5869. int fd = sd->fd;
  5870. if( !session_isActive( fd ) ){
  5871. return;
  5872. }
  5873. int len = MAX_INVENTORY * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5874. // Preallocate the maximum size
  5875. WFIFOHEAD( fd, len );
  5876. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  5877. int c = 0;
  5878. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5879. 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)){
  5880. p->items[c].index = i;
  5881. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  5882. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  5883. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  5884. c++;
  5885. }
  5886. }
  5887. if( c > 0 ){
  5888. p->packetType = 0x1fc;
  5889. // Recalculate real length
  5890. len = c * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5891. p->packetLength = len;
  5892. WFIFOSET( fd, len );
  5893. sd->menuskill_id = BS_REPAIRWEAPON;
  5894. sd->menuskill_val = dstsd->bl.id;
  5895. sd->menuskill_val2 = lv;
  5896. }else{
  5897. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  5898. }
  5899. }
  5900. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5901. /// 01fe <index>.W <result>.B
  5902. /// index:
  5903. /// ignored (inventory index)
  5904. /// result:
  5905. /// 0 = Item repair success.
  5906. /// 1 = Item repair failure.
  5907. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5908. {
  5909. int fd;
  5910. nullpo_retv(sd);
  5911. fd = sd->fd;
  5912. WFIFOHEAD(fd,packet_len(0x1fe));
  5913. WFIFOW(fd, 0)=0x1fe;
  5914. WFIFOW(fd, 2)=idx+2;
  5915. WFIFOB(fd, 4)=flag;
  5916. WFIFOSET(fd,packet_len(0x1fe));
  5917. }
  5918. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5919. /// 02bb <equip location>.W <account id>.L
  5920. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5921. {
  5922. int fd = sd->fd;
  5923. WFIFOHEAD(fd,packet_len(0x2bb));
  5924. WFIFOW(fd,0) = 0x2bb;
  5925. WFIFOW(fd,2) = position;
  5926. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5927. WFIFOSET(fd,packet_len(0x2bb));
  5928. }
  5929. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5930. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5931. void clif_item_refine_list( struct map_session_data *sd ){
  5932. nullpo_retv( sd );
  5933. int fd = sd->fd;
  5934. if( !session_isActive( fd ) ){
  5935. return;
  5936. }
  5937. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * MAX_INVENTORY );
  5938. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)WFIFOP( fd, 0 );
  5939. p->packetType = 0x221;
  5940. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  5941. int refine_item[5];
  5942. refine_item[0] = -1;
  5943. refine_item[1] = pc_search_inventory( sd, ITEMID_PHRACON );
  5944. refine_item[2] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  5945. refine_item[3] = refine_item[4] = pc_search_inventory( sd, ITEMID_ORIDECON );
  5946. int count = 0;
  5947. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5948. uint16 wlv;
  5949. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5950. sd->inventory.u.items_inventory[i].identify && ( wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid ) ) >= 1 &&
  5951. refine_item[wlv] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  5952. p->items[count].index = client_index( i );
  5953. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  5954. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  5955. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  5956. count++;
  5957. }
  5958. }
  5959. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  5960. WFIFOSET( fd, p->packetLength );
  5961. if( count > 0 ){
  5962. sd->menuskill_id = WS_WEAPONREFINE;
  5963. sd->menuskill_val = skill_lv;
  5964. }
  5965. }
  5966. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5967. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5968. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  5969. nullpo_retv( sd );
  5970. struct PACKET_ZC_AUTORUN_SKILL p;
  5971. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  5972. p.skill_id = skill_id;
  5973. p.skill_type = skill_get_inf( skill_id );
  5974. p.skill_lv = skill_lv;
  5975. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  5976. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  5977. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  5978. p.up_flag = false;
  5979. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5980. }
  5981. /// Adds an item to character's cart.
  5982. /// 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)
  5983. /// 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)
  5984. /// 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)
  5985. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  5986. nullpo_retv( sd );
  5987. int fd = sd->fd;
  5988. if( !session_isActive( fd ) ){
  5989. return;
  5990. }
  5991. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  5992. return;
  5993. }
  5994. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  5995. p.packetType = cartaddType;
  5996. p.index = client_index( n );
  5997. p.amount = amount;
  5998. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  5999. #if PACKETVER >= 5
  6000. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6001. #endif
  6002. p.identified = sd->cart.u.items_cart[n].identify;
  6003. p.damaged = sd->cart.u.items_cart[n].attribute;
  6004. p.refine = sd->cart.u.items_cart[n].refine;
  6005. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6006. #if PACKETVER >= 20150226
  6007. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6008. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6009. p.enchantgrade = sd->cart.u.items_cart[n].enchantgrade;
  6010. #endif
  6011. #endif
  6012. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6013. }
  6014. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6015. /* Acknowledge an item have been added to cart
  6016. * 012c <result>B
  6017. * result :
  6018. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6019. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6020. */
  6021. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6022. {
  6023. int fd;
  6024. unsigned char *buf;
  6025. nullpo_retv(sd);
  6026. fd = sd->fd;
  6027. buf = WFIFOP(fd,0);
  6028. WBUFW(buf,0) = 0x12c;
  6029. WBUFB(buf,2) = flag;
  6030. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6031. }
  6032. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6033. void clif_bank_open(struct map_session_data *sd){
  6034. int fd;
  6035. nullpo_retv(sd);
  6036. fd = sd->fd;
  6037. WFIFOHEAD(fd,4);
  6038. WFIFOW(fd,0) = 0x09b7;
  6039. WFIFOW(fd,2) = 0;
  6040. WFIFOSET(fd,4);
  6041. }
  6042. /*
  6043. * Request to Open the banking system
  6044. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6045. */
  6046. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6047. //TODO check if preventing trade or stuff like that
  6048. //also mark something in case char ain't available for saving, should we check now ?
  6049. nullpo_retv(sd);
  6050. if( !battle_config.feature_banking ) {
  6051. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6052. return;
  6053. }
  6054. else {
  6055. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6056. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6057. if(sd->status.account_id == aid){
  6058. sd->state.banking = 1;
  6059. //request save ?
  6060. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6061. //on succes open bank ?
  6062. clif_bank_open(sd);
  6063. }
  6064. }
  6065. }
  6066. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6067. void clif_bank_close(struct map_session_data *sd){
  6068. int fd;
  6069. nullpo_retv(sd);
  6070. fd = sd->fd;
  6071. WFIFOHEAD(fd,4);
  6072. WFIFOW(fd,0) = 0x09B9;
  6073. WFIFOW(fd,2) = 0;
  6074. WFIFOSET(fd,4);
  6075. }
  6076. /*
  6077. * Request to close the banking system
  6078. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6079. */
  6080. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6081. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6082. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6083. nullpo_retv(sd);
  6084. if( !battle_config.feature_banking ) {
  6085. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6086. //still allow to go trough to not stuck player if we have disable it while they was in
  6087. }
  6088. if(sd->status.account_id == aid){
  6089. sd->state.banking = 0;
  6090. clif_bank_close(sd);
  6091. }
  6092. }
  6093. /*
  6094. * Display how much we got in bank (I suppose)
  6095. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6096. */
  6097. void clif_Bank_Check(struct map_session_data* sd) {
  6098. unsigned char buf[13];
  6099. struct s_packet_db* info;
  6100. int16 len;
  6101. int cmd = 0;
  6102. nullpo_retv(sd);
  6103. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6104. if(!cmd) cmd = 0x09A6; //default
  6105. info = &packet_db[cmd];
  6106. len = info->len;
  6107. if(!len) return; //version as packet disable
  6108. // sd->state.banking = 1; //mark opening and closing
  6109. WBUFW(buf,0) = cmd;
  6110. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6111. WBUFW(buf,info->pos[1]) = 0; //reason
  6112. clif_send(buf,len,&sd->bl,SELF);
  6113. }
  6114. /*
  6115. * Requesting the data in bank
  6116. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6117. */
  6118. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6119. nullpo_retv(sd);
  6120. if( !battle_config.feature_banking ) {
  6121. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6122. return;
  6123. }
  6124. else {
  6125. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6126. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6127. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6128. clif_Bank_Check(sd);
  6129. }
  6130. }
  6131. /*
  6132. * Acknowledge of deposit some money in bank
  6133. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6134. */
  6135. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6136. unsigned char buf[17];
  6137. struct s_packet_db* info;
  6138. int16 len;
  6139. int cmd =0;
  6140. nullpo_retv(sd);
  6141. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6142. if(!cmd) cmd = 0x09A8;
  6143. info = &packet_db[cmd];
  6144. len = info->len;
  6145. if(!len) return; //version as packet disable
  6146. WBUFW(buf,0) = cmd;
  6147. WBUFW(buf,info->pos[0]) = (short)reason;
  6148. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6149. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6150. clif_send(buf,len,&sd->bl,SELF);
  6151. }
  6152. /*
  6153. * Request saving some money in bank
  6154. * @author : original [Yommy/Hercules]
  6155. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6156. */
  6157. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6158. nullpo_retv(sd);
  6159. if( !battle_config.feature_banking ) {
  6160. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6161. return;
  6162. }
  6163. else {
  6164. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6165. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6166. int money = RFIFOL(fd,info->pos[1]);
  6167. if(sd->status.account_id == aid){
  6168. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6169. clif_bank_deposit(sd,reason);
  6170. }
  6171. }
  6172. }
  6173. /*
  6174. * Acknowledge of withdrawing some money from bank
  6175. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6176. */
  6177. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6178. unsigned char buf[17];
  6179. struct s_packet_db* info;
  6180. int16 len;
  6181. int cmd;
  6182. nullpo_retv(sd);
  6183. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6184. if(!cmd) cmd = 0x09AA;
  6185. info = &packet_db[cmd];
  6186. len = info->len;
  6187. if(!len) return; //version as packet disable
  6188. WBUFW(buf,0) = cmd;
  6189. WBUFW(buf,info->pos[0]) = (short)reason;
  6190. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6191. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6192. clif_send(buf,len,&sd->bl,SELF);
  6193. }
  6194. /*
  6195. * Request Withdrawing some money from bank
  6196. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6197. */
  6198. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6199. nullpo_retv(sd);
  6200. if( !battle_config.feature_banking ) {
  6201. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6202. return;
  6203. }
  6204. else {
  6205. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6206. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6207. int money = RFIFOL(fd,info->pos[1]);
  6208. if(sd->status.account_id == aid){
  6209. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6210. clif_bank_withdraw(sd,reason);
  6211. }
  6212. }
  6213. }
  6214. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6215. /// 0125 <index>.W <amount>.L
  6216. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6217. {
  6218. int fd;
  6219. nullpo_retv(sd);
  6220. fd=sd->fd;
  6221. WFIFOHEAD(fd,packet_len(0x125));
  6222. WFIFOW(fd,0)=0x125;
  6223. WFIFOW(fd,2)=n+2;
  6224. WFIFOL(fd,4)=amount;
  6225. WFIFOSET(fd,packet_len(0x125));
  6226. }
  6227. /// Opens the shop creation menu (ZC_OPENSTORE).
  6228. /// 012d <num>.W
  6229. /// num:
  6230. /// number of allowed item slots
  6231. void clif_openvendingreq(struct map_session_data* sd, int num)
  6232. {
  6233. int fd;
  6234. nullpo_retv(sd);
  6235. fd = sd->fd;
  6236. WFIFOHEAD(fd,packet_len(0x12d));
  6237. WFIFOW(fd,0) = 0x12d;
  6238. WFIFOW(fd,2) = num;
  6239. WFIFOSET(fd,packet_len(0x12d));
  6240. }
  6241. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6242. /// 0131 <owner id>.L <message>.80B
  6243. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6244. {
  6245. unsigned char buf[128];
  6246. nullpo_retv(bl);
  6247. WBUFW(buf,0) = 0x131;
  6248. WBUFL(buf,2) = bl->id;
  6249. safestrncpy(WBUFCP(buf,6), message, 80);
  6250. if( session_isActive(fd) ) {
  6251. WFIFOHEAD(fd,packet_len(0x131));
  6252. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6253. WFIFOSET(fd,packet_len(0x131));
  6254. } else {
  6255. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6256. }
  6257. }
  6258. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6259. /// 0132 <owner id>.L
  6260. void clif_closevendingboard(struct block_list* bl, int fd)
  6261. {
  6262. unsigned char buf[16];
  6263. nullpo_retv(bl);
  6264. WBUFW(buf,0) = 0x132;
  6265. WBUFL(buf,2) = bl->id;
  6266. if( session_isActive(fd) ) {
  6267. WFIFOHEAD(fd,packet_len(0x132));
  6268. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6269. WFIFOSET(fd,packet_len(0x132));
  6270. } else {
  6271. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6272. }
  6273. }
  6274. /// Sends a list of items in a shop.
  6275. /// 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)
  6276. /// 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)
  6277. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6278. nullpo_retv( sd );
  6279. nullpo_retv( vsd );
  6280. nullpo_retv( vsd->vending );
  6281. int fd = sd->fd;
  6282. if( !session_isActive( fd ) ){
  6283. return;
  6284. }
  6285. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6286. WFIFOHEAD( fd, len );
  6287. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6288. p->packetType = vendinglistType;
  6289. p->packetLength = len;
  6290. p->AID = vsd->status.account_id;
  6291. #if PACKETVER >= 20100105
  6292. p->venderId = vsd->vender_id;
  6293. #endif
  6294. for( int i = 0; i < vsd->vend_num; i++ ){
  6295. int index = vsd->vending[i].index;
  6296. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6297. p->items[i].price = vsd->vending[i].value;
  6298. p->items[i].amount = vsd->vending[i].amount;
  6299. p->items[i].index = client_index( index );
  6300. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6301. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6302. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6303. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6304. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6305. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6306. #if PACKETVER >= 20150226
  6307. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6308. #if PACKETVER >= 20160921
  6309. p->items[i].location = pc_equippoint_sub( sd, data );
  6310. p->items[i].viewSprite = data->look;
  6311. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6312. p->items[i].enchantgrade = vsd->cart.u.items_cart[index].enchantgrade;
  6313. #endif
  6314. #endif
  6315. #endif
  6316. }
  6317. WFIFOSET( fd, len );
  6318. }
  6319. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6320. /// 0135 <index>.W <amount>.W <result>.B
  6321. /// result:
  6322. /// 0 = success
  6323. /// 1 = not enough zeny
  6324. /// 2 = overweight
  6325. /// 4 = out of stock
  6326. /// 5 = "cannot use an npc shop while in a trade"
  6327. /// 6 = Because the store information was incorrect the item was not purchased.
  6328. /// 7 = No sales information.
  6329. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6330. {
  6331. int fd;
  6332. nullpo_retv(sd);
  6333. fd = sd->fd;
  6334. WFIFOHEAD(fd,packet_len(0x135));
  6335. WFIFOW(fd,0) = 0x135;
  6336. WFIFOW(fd,2) = index+2;
  6337. WFIFOW(fd,4) = amount;
  6338. WFIFOB(fd,6) = fail;
  6339. WFIFOSET(fd,packet_len(0x135));
  6340. }
  6341. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6342. /// 0a28 <Result>.B
  6343. /// result:
  6344. /// 0 = Successed
  6345. /// 1 = Failed
  6346. void clif_openvending_ack(struct map_session_data* sd, int result)
  6347. {
  6348. int fd;
  6349. nullpo_retv(sd);
  6350. fd = sd->fd;
  6351. WFIFOHEAD(fd, 3);
  6352. WFIFOW(fd,0) = 0xa28;
  6353. WFIFOB(fd,2) = result;
  6354. WFIFOSET(fd, 3);
  6355. }
  6356. /// Shop creation success.
  6357. /// 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)
  6358. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6359. nullpo_retv( sd );
  6360. nullpo_retv( vending );
  6361. int fd = sd->fd;
  6362. if( !session_isActive( fd ) ){
  6363. return;
  6364. }
  6365. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6366. WFIFOHEAD( fd, len );
  6367. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6368. p->packetType = openvendingType;
  6369. p->packetLength = len;
  6370. p->AID = id;
  6371. for( int i = 0; i < sd->vend_num; i++ ) {
  6372. int index = vending[i].index;
  6373. p->items[i].price = vending[i].value;
  6374. p->items[i].index = client_index( index );
  6375. p->items[i].amount = vending[i].amount;
  6376. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6377. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6378. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6379. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6380. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6381. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6382. #if PACKETVER >= 20150226
  6383. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6384. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6385. p->items[i].enchantgrade = sd->cart.u.items_cart[index].enchantgrade;
  6386. #endif
  6387. #endif
  6388. }
  6389. WFIFOSET( fd, len );
  6390. #if PACKETVER >= 20141022
  6391. /// 0 = Successed
  6392. /// 1 = Failed
  6393. clif_openvending_ack( sd, 0 );
  6394. #endif
  6395. }
  6396. /// Inform merchant that someone has bought an item.
  6397. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6398. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6399. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6400. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6401. const int cmd = 0x137;
  6402. #else
  6403. const int cmd = 0x9e5;
  6404. #endif
  6405. int fd = sd->fd;
  6406. nullpo_retv(sd);
  6407. WFIFOHEAD(fd,packet_len(cmd));
  6408. WFIFOW(fd,0) = cmd;
  6409. WFIFOW(fd,2) = index+2;
  6410. WFIFOW(fd,4) = amount;
  6411. #if PACKETVER >= 20141016
  6412. WFIFOL(fd,6) = char_id; // GID
  6413. WFIFOL(fd,10) = (int)time(NULL); // Date
  6414. WFIFOL(fd,14) = zeny; // zeny
  6415. #endif
  6416. WFIFOSET(fd,packet_len(cmd));
  6417. }
  6418. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6419. /// 00fa <result>.B
  6420. /// result:
  6421. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6422. /// 1 = MsgStringTable[78]="party name already exists"
  6423. /// 2 = MsgStringTable[79]="already in a party"
  6424. /// 3 = cannot organize parties on this map
  6425. /// ? = nothing
  6426. void clif_party_created(struct map_session_data *sd,int result)
  6427. {
  6428. int fd;
  6429. nullpo_retv(sd);
  6430. fd=sd->fd;
  6431. WFIFOHEAD(fd,packet_len(0xfa));
  6432. WFIFOW(fd,0)=0xfa;
  6433. WFIFOB(fd,2)=result;
  6434. WFIFOSET(fd,packet_len(0xfa));
  6435. }
  6436. /// Adds new member to a party.
  6437. /// 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)
  6438. /// 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)
  6439. /// 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)
  6440. /// role:
  6441. /// 0 = leader
  6442. /// 1 = normal
  6443. /// state:
  6444. /// 0 = connected
  6445. /// 1 = disconnected
  6446. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6447. {
  6448. int i;
  6449. #if PACKETVER < 20170502
  6450. unsigned char buf[81];
  6451. int cmd = 0x1e9;
  6452. int offset = 0;
  6453. #else
  6454. unsigned char buf[85];
  6455. int cmd = 0xa43;
  6456. int offset = 4;
  6457. #endif
  6458. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6459. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6460. } else {
  6461. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6462. }
  6463. if (i >= MAX_PARTY) return; //Should never happen...
  6464. sd = p->data[i].sd;
  6465. WBUFW(buf, 0) = cmd;
  6466. WBUFL(buf, 2) = sd->status.account_id;
  6467. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6468. #if PACKETVER >= 20170502
  6469. WBUFW(buf,10) = sd->status.class_;
  6470. WBUFW(buf,12) = sd->status.base_level;
  6471. #endif
  6472. WBUFW(buf,offset+10) = sd->bl.x;
  6473. WBUFW(buf,offset+12) = sd->bl.y;
  6474. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6475. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6476. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6477. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6478. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6479. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6480. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6481. }
  6482. /// Sends party information (ZC_GROUP_LIST).
  6483. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6484. /// role:
  6485. /// 0 = leader
  6486. /// 1 = normal
  6487. /// state:
  6488. /// 0 = connected
  6489. /// 1 = disconnected
  6490. /// 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
  6491. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6492. {
  6493. struct map_session_data* party_sd = NULL;
  6494. int i, c;
  6495. #if PACKETVER < 20170502
  6496. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6497. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6498. int cmd = 0xfb;
  6499. #else
  6500. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6501. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6502. int cmd = 0xa44;
  6503. #endif
  6504. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6505. nullpo_retv(p);
  6506. WBUFW(buf,0) = cmd;
  6507. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6508. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6509. {
  6510. struct party_member* m = &p->party.member[i];
  6511. if(!m->account_id) continue;
  6512. if(party_sd == NULL) party_sd = p->data[i].sd;
  6513. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6514. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6515. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6516. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6517. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6518. #if PACKETVER >= 20170502
  6519. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6520. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6521. #endif
  6522. c++;
  6523. }
  6524. #if PACKETVER < 20170502
  6525. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6526. #else
  6527. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6528. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6529. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6530. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6531. #endif
  6532. if(sd) { // send only to self
  6533. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6534. } else if (party_sd) { // send to whole party
  6535. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6536. }
  6537. }
  6538. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6539. /// 02c9 <flag>.B
  6540. /// flag:
  6541. /// 0 = allow party invites
  6542. /// 1 = auto-deny party invites
  6543. void clif_partyinvitationstate(struct map_session_data* sd)
  6544. {
  6545. int fd;
  6546. nullpo_retv(sd);
  6547. fd = sd->fd;
  6548. WFIFOHEAD(fd, packet_len(0x2c9));
  6549. WFIFOW(fd, 0) = 0x2c9;
  6550. WFIFOB(fd, 2) = 0; // not implemented
  6551. WFIFOSET(fd, packet_len(0x2c9));
  6552. }
  6553. /// Party invitation request.
  6554. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6555. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6556. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6557. {
  6558. #if PACKETVER < 20070821
  6559. const int cmd = 0xfe;
  6560. #else
  6561. const int cmd = 0x2c6;
  6562. #endif
  6563. int fd;
  6564. struct party_data *p;
  6565. nullpo_retv(sd);
  6566. nullpo_retv(tsd);
  6567. fd=tsd->fd;
  6568. if( (p=party_search(sd->status.party_id))==NULL )
  6569. return;
  6570. WFIFOHEAD(fd,packet_len(cmd));
  6571. WFIFOW(fd,0)=cmd;
  6572. WFIFOL(fd,2)=sd->status.party_id;
  6573. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6574. WFIFOSET(fd,packet_len(cmd));
  6575. }
  6576. /// Party invite result.
  6577. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6578. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6579. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6580. {
  6581. int fd;
  6582. nullpo_retv(sd);
  6583. fd=sd->fd;
  6584. #if PACKETVER < 20070904
  6585. if( reply == PARTY_REPLY_OFFLINE ) {
  6586. clif_displaymessage(fd, msg_txt(sd,3));
  6587. return;
  6588. }
  6589. #endif
  6590. #if PACKETVER < 20070821
  6591. WFIFOHEAD(fd,packet_len(0xfd));
  6592. WFIFOW(fd,0) = 0xfd;
  6593. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6594. WFIFOB(fd,26) = reply;
  6595. WFIFOSET(fd,packet_len(0xfd));
  6596. #else
  6597. WFIFOHEAD(fd,packet_len(0x2c5));
  6598. WFIFOW(fd,0) = 0x2c5;
  6599. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6600. WFIFOL(fd,26) = reply;
  6601. WFIFOSET(fd,packet_len(0x2c5));
  6602. #endif
  6603. }
  6604. /// Updates party settings.
  6605. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6606. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6607. /// exp option:
  6608. /// 0 = exp sharing disabled
  6609. /// 1 = exp sharing enabled
  6610. /// 2 = cannot change exp sharing
  6611. ///
  6612. /// flag:
  6613. /// 0 = send to party
  6614. /// 1 = send to sd
  6615. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6616. {
  6617. unsigned char buf[16];
  6618. #if PACKETVER < 20090603
  6619. const int cmd = 0x101;
  6620. #else
  6621. const int cmd = 0x7d8;
  6622. #endif
  6623. nullpo_retv(p);
  6624. if(!sd && flag==0){
  6625. int i;
  6626. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6627. if (i < MAX_PARTY)
  6628. sd = p->data[i].sd;
  6629. }
  6630. if(!sd) return;
  6631. WBUFW(buf,0)=cmd;
  6632. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6633. #if PACKETVER >= 20090603
  6634. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6635. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6636. #endif
  6637. if(flag==0)
  6638. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6639. else
  6640. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6641. }
  6642. /**
  6643. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6644. * @param sd Send the notification for this player
  6645. * @param account_id Account ID of kicked member
  6646. * @param name Name of kicked member
  6647. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6648. * @param target Send target
  6649. **/
  6650. 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) {
  6651. unsigned char buf[2+4+NAME_LENGTH+1];
  6652. if (!sd)
  6653. return;
  6654. WBUFW(buf,0) = 0x0105;
  6655. WBUFL(buf,2) = account_id;
  6656. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6657. WBUFB(buf,6+NAME_LENGTH) = result;
  6658. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6659. }
  6660. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6661. /// 0109 <packet len>.W <account id>.L <message>.?B
  6662. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6663. {
  6664. struct map_session_data *sd;
  6665. int i;
  6666. nullpo_retv(p);
  6667. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6668. if(i < MAX_PARTY){
  6669. unsigned char buf[1024];
  6670. if( len > sizeof(buf)-8 )
  6671. {
  6672. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6673. len = sizeof(buf)-8;
  6674. }
  6675. sd = p->data[i].sd;
  6676. WBUFW(buf,0)=0x109;
  6677. WBUFW(buf,2)=len+8;
  6678. WBUFL(buf,4)=account_id;
  6679. safestrncpy(WBUFCP(buf,8), mes, len);
  6680. clif_send(buf,len+8,&sd->bl,PARTY);
  6681. }
  6682. }
  6683. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6684. /// 0107 <account id>.L <x>.W <y>.W
  6685. void clif_party_xy(struct map_session_data *sd)
  6686. {
  6687. unsigned char buf[16];
  6688. nullpo_retv(sd);
  6689. WBUFW(buf,0)=0x107;
  6690. WBUFL(buf,2)=sd->status.account_id;
  6691. WBUFW(buf,6)=sd->bl.x;
  6692. WBUFW(buf,8)=sd->bl.y;
  6693. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6694. }
  6695. /*==========================================
  6696. * Sends x/y dot to a single fd. [Skotlex]
  6697. *------------------------------------------*/
  6698. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6699. {
  6700. WFIFOHEAD(fd,packet_len(0x107));
  6701. WFIFOW(fd,0)=0x107;
  6702. WFIFOL(fd,2)=sd->status.account_id;
  6703. WFIFOW(fd,6)=sd->bl.x;
  6704. WFIFOW(fd,8)=sd->bl.y;
  6705. WFIFOSET(fd,packet_len(0x107));
  6706. }
  6707. /// Updates HP bar of a party member.
  6708. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6709. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6710. void clif_party_hp(struct map_session_data *sd)
  6711. {
  6712. unsigned char buf[16];
  6713. #if PACKETVER < 20100126
  6714. const int cmd = 0x106;
  6715. #else
  6716. const int cmd = 0x80e;
  6717. #endif
  6718. nullpo_retv(sd);
  6719. WBUFW(buf,0)=cmd;
  6720. WBUFL(buf,2)=sd->status.account_id;
  6721. #if PACKETVER < 20100126
  6722. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6723. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6724. WBUFW(buf,8) = 100;
  6725. } else {
  6726. WBUFW(buf,6) = sd->battle_status.hp;
  6727. WBUFW(buf,8) = sd->battle_status.max_hp;
  6728. }
  6729. #else
  6730. WBUFL(buf,6) = sd->battle_status.hp;
  6731. WBUFL(buf,10) = sd->battle_status.max_hp;
  6732. #endif
  6733. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6734. }
  6735. /// Notifies the party members of a character's death or revival.
  6736. /// 0AB2 <GID>.L <dead>.B
  6737. void clif_party_dead( struct map_session_data *sd ){
  6738. #if PACKETVER >= 20170502
  6739. unsigned char buf[7];
  6740. nullpo_retv(sd);
  6741. WBUFW(buf, 0) = 0xab2;
  6742. WBUFL(buf, 2) = sd->status.account_id;
  6743. WBUFB(buf, 6) = pc_isdead(sd);
  6744. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6745. #endif
  6746. }
  6747. /// Updates the job and level of a party member
  6748. /// 0abd <account id>.L <job>.W <level>.W
  6749. void clif_party_job_and_level(struct map_session_data *sd){
  6750. #if PACKETVER >= 20170502
  6751. unsigned char buf[10];
  6752. nullpo_retv(sd);
  6753. WBUFW(buf, 0) = 0xabd;
  6754. WBUFL(buf, 2) = sd->status.account_id;
  6755. WBUFW(buf, 6) = sd->status.class_;
  6756. WBUFW(buf, 8) = sd->status.base_level;
  6757. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6758. #endif
  6759. }
  6760. /*==========================================
  6761. * Sends HP bar to a single fd. [Skotlex]
  6762. *------------------------------------------*/
  6763. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6764. {
  6765. #if PACKETVER < 20100126
  6766. const int cmd = 0x106;
  6767. #else
  6768. const int cmd = 0x80e;
  6769. #endif
  6770. WFIFOHEAD(fd,packet_len(cmd));
  6771. WFIFOW(fd,0) = cmd;
  6772. WFIFOL(fd,2) = id;
  6773. #if PACKETVER < 20100126
  6774. if( maxhp > INT16_MAX )
  6775. {// To correctly display the %hp bar. [Skotlex]
  6776. WFIFOW(fd,6) = hp/(maxhp/100);
  6777. WFIFOW(fd,8) = 100;
  6778. } else {
  6779. WFIFOW(fd,6) = hp;
  6780. WFIFOW(fd,8) = maxhp;
  6781. }
  6782. #else
  6783. WFIFOL(fd,6) = hp;
  6784. WFIFOL(fd,10) = maxhp;
  6785. #endif
  6786. WFIFOSET(fd, packet_len(cmd));
  6787. }
  6788. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6789. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6790. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6791. {
  6792. int fd;
  6793. nullpo_retv(sd);
  6794. nullpo_retv(bl);
  6795. fd=sd->fd;
  6796. WFIFOHEAD(fd,packet_len(0x139));
  6797. WFIFOW(fd, 0)=0x139;
  6798. WFIFOL(fd, 2)=bl->id;
  6799. WFIFOW(fd, 6)=bl->x;
  6800. WFIFOW(fd, 8)=bl->y;
  6801. WFIFOW(fd,10)=sd->bl.x;
  6802. WFIFOW(fd,12)=sd->bl.y;
  6803. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6804. WFIFOSET(fd,packet_len(0x139));
  6805. }
  6806. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6807. /// 018f <result>.W <name id>.W
  6808. /// result:
  6809. /// 0 = success
  6810. /// 1 = failure
  6811. /// 2 = success (alchemist)
  6812. /// 3 = failure (alchemist)
  6813. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  6814. nullpo_retv( sd );
  6815. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6816. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6817. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6818. p.result = flag;
  6819. p.itemId = client_nameid( nameid );
  6820. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6821. }
  6822. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6823. /// 019e
  6824. void clif_catch_process(struct map_session_data *sd)
  6825. {
  6826. int fd;
  6827. nullpo_retv(sd);
  6828. fd=sd->fd;
  6829. WFIFOHEAD(fd,packet_len(0x19e));
  6830. WFIFOW(fd,0)=0x19e;
  6831. WFIFOSET(fd,packet_len(0x19e));
  6832. }
  6833. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6834. /// 01a0 <result>.B
  6835. /// 0 = failure
  6836. /// 1 = success
  6837. void clif_pet_roulette(struct map_session_data *sd,int data)
  6838. {
  6839. int fd;
  6840. nullpo_retv(sd);
  6841. fd=sd->fd;
  6842. WFIFOHEAD(fd,packet_len(0x1a0));
  6843. WFIFOW(fd,0)=0x1a0;
  6844. WFIFOB(fd,2)=data;
  6845. WFIFOSET(fd,packet_len(0x1a0));
  6846. }
  6847. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6848. /// 01a6 <packet len>.W { <index>.W }*
  6849. void clif_sendegg(struct map_session_data *sd)
  6850. {
  6851. int i,n=0,fd;
  6852. nullpo_retv(sd);
  6853. fd=sd->fd;
  6854. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6855. clif_displaymessage(fd, msg_txt(sd,666));
  6856. return;
  6857. }
  6858. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6859. WFIFOW(fd,0)=0x1a6;
  6860. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6861. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  6862. sd->inventory_data[i]->type != IT_PETEGG ||
  6863. sd->inventory.u.items_inventory[i].amount <= 0)
  6864. continue;
  6865. WFIFOW(fd,n*2+4)=client_index(i);
  6866. n++;
  6867. }
  6868. WFIFOW(fd,2)=4+n*2;
  6869. WFIFOSET(fd,WFIFOW(fd,2));
  6870. sd->menuskill_id = SA_TAMINGMONSTER;
  6871. sd->menuskill_val = -1;
  6872. }
  6873. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6874. /// 01a4 <type>.B <id>.L <data>.L
  6875. /// type:
  6876. /// 0 = pre-init (data = 0)
  6877. /// 1 = intimacy (data = 0~4)
  6878. /// 2 = hunger (data = 0~4)
  6879. /// 3 = accessory
  6880. /// 4 = performance (data = 1~3: normal, 4: special)
  6881. /// 5 = hairstyle
  6882. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6883. ///
  6884. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6885. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6886. {
  6887. uint8 buf[16];
  6888. nullpo_retv(pd);
  6889. WBUFW(buf,0) = 0x1a4;
  6890. WBUFB(buf,2) = type;
  6891. WBUFL(buf,3) = pd->bl.id;
  6892. WBUFL(buf,7) = param;
  6893. if (sd)
  6894. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6895. else
  6896. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6897. }
  6898. /// Pet's base data (ZC_PROPERTY_PET).
  6899. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6900. void clif_send_petstatus(struct map_session_data *sd)
  6901. {
  6902. int fd;
  6903. struct s_pet *pet;
  6904. nullpo_retv(sd);
  6905. nullpo_retv(sd->pd);
  6906. fd=sd->fd;
  6907. pet = &sd->pd->pet;
  6908. WFIFOHEAD(fd,packet_len(0x1a2));
  6909. WFIFOW(fd,0)=0x1a2;
  6910. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6911. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6912. WFIFOW(fd,27)=pet->level;
  6913. WFIFOW(fd,29)=pet->hungry;
  6914. WFIFOW(fd,31)=pet->intimate;
  6915. WFIFOW(fd,33)=pet->equip;
  6916. #if PACKETVER >= 20081126
  6917. WFIFOW(fd,35)=pet->class_;
  6918. #endif
  6919. WFIFOSET(fd,packet_len(0x1a2));
  6920. }
  6921. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6922. /// 01aa <id>.L <data>.L
  6923. /// data:
  6924. /// @see CZ_PET_ACT.
  6925. void clif_pet_emotion(struct pet_data *pd,int param)
  6926. {
  6927. unsigned char buf[16];
  6928. nullpo_retv(pd);
  6929. memset(buf,0,packet_len(0x1aa));
  6930. WBUFW(buf,0)=0x1aa;
  6931. WBUFL(buf,2)=pd->bl.id;
  6932. WBUFL(buf,6)=param;
  6933. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6934. }
  6935. /// Result of request to feed a pet (ZC_FEED_PET).
  6936. /// 01a3 <result>.B <name id>.W
  6937. /// result:
  6938. /// 0 = failure
  6939. /// 1 = success
  6940. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  6941. nullpo_retv( sd );
  6942. struct PACKET_ZC_FEED_PET p;
  6943. p.packetType = 0x1a3;
  6944. p.result = fail;
  6945. p.itemId = client_nameid( foodid );
  6946. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6947. }
  6948. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6949. /// 01cd { <skill id>.L }*7
  6950. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6951. {
  6952. nullpo_retv(sd);
  6953. int fd = sd->fd;
  6954. #ifdef RENEWAL
  6955. uint16 autospell_skill[][2] = {
  6956. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  6957. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  6958. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  6959. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  6960. };
  6961. int count = 0;
  6962. WFIFOHEAD(fd, 2 * 6 + 4);
  6963. WFIFOW(fd, 0) = 0x442;
  6964. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  6965. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  6966. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  6967. count++;
  6968. }
  6969. }
  6970. WFIFOW(fd, 2) = 8 + count * 2;
  6971. WFIFOL(fd, 4) = count;
  6972. WFIFOSET(fd, WFIFOW(fd, 2));
  6973. #else
  6974. WFIFOHEAD(fd,packet_len(0x1cd));
  6975. WFIFOW(fd, 0)=0x1cd;
  6976. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6977. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6978. else
  6979. WFIFOL(fd,2)= 0x00000000;
  6980. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6981. WFIFOL(fd,6)= MG_COLDBOLT;
  6982. else
  6983. WFIFOL(fd,6)= 0x00000000;
  6984. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6985. WFIFOL(fd,10)= MG_FIREBOLT;
  6986. else
  6987. WFIFOL(fd,10)= 0x00000000;
  6988. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6989. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6990. else
  6991. WFIFOL(fd,14)= 0x00000000;
  6992. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6993. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6994. else
  6995. WFIFOL(fd,18)= 0x00000000;
  6996. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6997. WFIFOL(fd,22)= MG_FIREBALL;
  6998. else
  6999. WFIFOL(fd,22)= 0x00000000;
  7000. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7001. WFIFOL(fd,26)= MG_FROSTDIVER;
  7002. else
  7003. WFIFOL(fd,26)= 0x00000000;
  7004. WFIFOSET(fd,packet_len(0x1cd));
  7005. #endif
  7006. sd->menuskill_id = SA_AUTOSPELL;
  7007. sd->menuskill_val = skill_lv;
  7008. }
  7009. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7010. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7011. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7012. {
  7013. unsigned char buf[56];
  7014. nullpo_retv(src);
  7015. memset(buf,0,packet_len(0x1cf));
  7016. WBUFW(buf,0) = 0x1cf;
  7017. WBUFL(buf,2) = src->id;
  7018. if( src->type == BL_MER )
  7019. {
  7020. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7021. if( md && md->master && md->devotion_flag )
  7022. WBUFL(buf,6) = md->master->bl.id;
  7023. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7024. }
  7025. else
  7026. {
  7027. int i;
  7028. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7029. if( sd == NULL )
  7030. return;
  7031. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7032. WBUFL(buf,6+4*i) = sd->devotion[i];
  7033. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7034. }
  7035. if( tsd )
  7036. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7037. else
  7038. clif_send(buf, packet_len(0x1cf), src, AREA);
  7039. }
  7040. /// Notifies the client of an object's spirits.
  7041. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7042. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7043. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7044. nullpo_retv( bl );
  7045. struct PACKET_ZC_SPIRITS p = {};
  7046. p.packetType = HEADER_ZC_SPIRITS;
  7047. p.GID = bl->id;
  7048. switch( bl->type ){
  7049. case BL_PC:
  7050. p.amount = ( (struct map_session_data*)bl )->spiritball;
  7051. break;
  7052. case BL_HOM:
  7053. p.amount = ( (struct homun_data*)bl )->homunculus.spiritball;
  7054. break;
  7055. }
  7056. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7057. }
  7058. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7059. /// 01d2 <account id>.L <delay>.L
  7060. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7061. {
  7062. unsigned char buf[32];
  7063. nullpo_retv(bl);
  7064. WBUFW(buf,0)=0x1d2;
  7065. WBUFL(buf,2)=bl->id;
  7066. WBUFL(buf,6)=client_tick(wait);
  7067. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7068. }
  7069. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7070. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7071. /// flag:
  7072. /// 0 = inactive
  7073. /// 1 = active
  7074. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7075. {
  7076. unsigned char buf[32];
  7077. nullpo_retv(src);
  7078. WBUFW(buf,0)=0x1d1;
  7079. WBUFL(buf,2)=src->id;
  7080. WBUFL(buf,6)=dst_id;
  7081. WBUFL(buf,10)=active;
  7082. clif_send(buf,packet_len(0x1d1),src,AREA);
  7083. }
  7084. /// MVP effect (ZC_MVP).
  7085. /// 010c <account id>.L
  7086. void clif_mvp_effect(struct map_session_data *sd)
  7087. {
  7088. unsigned char buf[16];
  7089. nullpo_retv(sd);
  7090. WBUFW(buf,0)=0x10c;
  7091. WBUFL(buf,2)=sd->bl.id;
  7092. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7093. }
  7094. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7095. /// 010a <name id>.W
  7096. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7097. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7098. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7099. p.itemId = client_nameid( nameid );
  7100. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7101. }
  7102. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7103. /// 010b <exp>.L
  7104. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7105. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7106. if (battle_config.mvp_exp_reward_message) {
  7107. char e_msg[CHAT_SIZE_MAX];
  7108. sprintf(e_msg, msg_txt(sd, 717), exp);
  7109. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7110. }
  7111. #else
  7112. int fd;
  7113. nullpo_retv(sd);
  7114. fd = sd->fd;
  7115. WFIFOHEAD(fd, packet_len(0x10b));
  7116. WFIFOW(fd,0) = 0x10b;
  7117. WFIFOL(fd,2) = (uint32)min( exp, MAX_EXP );
  7118. WFIFOSET(fd, packet_len(0x10b));
  7119. #endif
  7120. }
  7121. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7122. /// 010d
  7123. ///
  7124. /// "You are the MVP, but cannot obtain the reward because
  7125. /// you are overweight."
  7126. void clif_mvp_noitem(struct map_session_data* sd)
  7127. {
  7128. int fd = sd->fd;
  7129. WFIFOHEAD(fd,packet_len(0x10d));
  7130. WFIFOW(fd,0) = 0x10d;
  7131. WFIFOSET(fd,packet_len(0x10d));
  7132. }
  7133. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7134. /// 0167 <result>.B
  7135. /// result:
  7136. /// 0 = "Guild has been created."
  7137. /// 1 = "You are already in a Guild."
  7138. /// 2 = "That Guild Name already exists."
  7139. /// 3 = "You need the neccessary item to create a Guild."
  7140. void clif_guild_created(struct map_session_data *sd,int flag)
  7141. {
  7142. int fd;
  7143. nullpo_retv(sd);
  7144. fd=sd->fd;
  7145. WFIFOHEAD(fd,packet_len(0x167));
  7146. WFIFOW(fd,0)=0x167;
  7147. WFIFOB(fd,2)=flag;
  7148. WFIFOSET(fd,packet_len(0x167));
  7149. }
  7150. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7151. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7152. /// mode:
  7153. /// &0x01 = allow invite
  7154. /// &0x10 = allow expel
  7155. void clif_guild_belonginfo(struct map_session_data *sd)
  7156. {
  7157. int ps,fd;
  7158. struct guild* g;
  7159. nullpo_retv(sd);
  7160. nullpo_retv(g = sd->guild);
  7161. fd=sd->fd;
  7162. ps=guild_getposition(sd);
  7163. WFIFOHEAD(fd,packet_len(0x16c));
  7164. WFIFOW(fd,0)=0x16c;
  7165. WFIFOL(fd,2)=g->guild_id;
  7166. WFIFOL(fd,6)=g->emblem_id;
  7167. WFIFOL(fd,10)=g->position[ps].mode;
  7168. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7169. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7170. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7171. WFIFOSET(fd,packet_len(0x16c));
  7172. }
  7173. /// Guild member login notice.
  7174. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7175. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7176. /// status:
  7177. /// 0 = offline
  7178. /// 1 = online
  7179. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7180. {
  7181. unsigned char buf[64];
  7182. struct map_session_data* sd;
  7183. nullpo_retv(g);
  7184. WBUFW(buf, 0)=0x1f2;
  7185. WBUFL(buf, 2)=g->member[idx].account_id;
  7186. WBUFL(buf, 6)=g->member[idx].char_id;
  7187. WBUFL(buf,10)=flag;
  7188. if( ( sd = g->member[idx].sd ) != NULL )
  7189. {
  7190. WBUFW(buf,14) = sd->status.sex;
  7191. WBUFW(buf,16) = sd->status.hair;
  7192. WBUFW(buf,18) = sd->status.hair_color;
  7193. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7194. }
  7195. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7196. {
  7197. WBUFW(buf,14) = 0;
  7198. WBUFW(buf,16) = 0;
  7199. WBUFW(buf,18) = 0;
  7200. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7201. }
  7202. }
  7203. // Function `clif_guild_memberlogin_notice` sends info about
  7204. // logins and logouts of a guild member to the rest members.
  7205. // But at the 1st time (after a player login or map changing)
  7206. // the client won't show the message.
  7207. // So I suggest use this function for sending "first-time-info"
  7208. // to some player on entering the game or changing location.
  7209. // At next time the client would always show the message.
  7210. // The function sends all the statuses in the single packet
  7211. // to economize traffic. [LuzZza]
  7212. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7213. {
  7214. struct guild *g;
  7215. unsigned char buf[14*128];
  7216. int i, count=0, p_len;
  7217. nullpo_retv(sd);
  7218. p_len = packet_len(0x16d);
  7219. if(!(g = sd->guild))
  7220. return;
  7221. for(i=0; i<g->max_member; i++) {
  7222. if(g->member[i].account_id > 0 &&
  7223. g->member[i].account_id != sd->status.account_id) {
  7224. WBUFW(buf,count*p_len) = 0x16d;
  7225. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7226. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7227. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7228. count++;
  7229. }
  7230. }
  7231. clif_send(buf, p_len*count, &sd->bl, SELF);
  7232. }
  7233. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7234. /// 014e <menu flag>.L
  7235. /// menu flag:
  7236. /// 0x00 = Basic Info (always on)
  7237. /// &0x01 = Member manager
  7238. /// &0x02 = Positions
  7239. /// &0x04 = Skills
  7240. /// &0x10 = Expulsion list
  7241. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7242. /// &0x80 = Notice
  7243. void clif_guild_masterormember(struct map_session_data *sd)
  7244. {
  7245. int fd;
  7246. nullpo_retv(sd);
  7247. fd=sd->fd;
  7248. WFIFOHEAD(fd,packet_len(0x14e));
  7249. WFIFOW(fd,0) = 0x14e;
  7250. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7251. WFIFOSET(fd,packet_len(0x14e));
  7252. }
  7253. /// Guild basic information (Territories [Valaris])
  7254. /// 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)
  7255. /// 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)
  7256. /// 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)
  7257. void clif_guild_basicinfo(struct map_session_data *sd) {
  7258. int fd;
  7259. struct guild *g;
  7260. #if PACKETVER < 20160622
  7261. int cmd = 0x1b6;
  7262. int offset = NAME_LENGTH;
  7263. #else
  7264. int cmd = 0xa84;
  7265. int offset = 0;
  7266. #endif
  7267. nullpo_retv(sd);
  7268. fd = sd->fd;
  7269. if( (g = sd->guild) == NULL )
  7270. return;
  7271. WFIFOHEAD(fd,packet_len(cmd));
  7272. WFIFOW(fd, 0)=cmd;
  7273. WFIFOL(fd, 2)=g->guild_id;
  7274. WFIFOL(fd, 6)=g->guild_lv;
  7275. WFIFOL(fd,10)=g->connect_member;
  7276. WFIFOL(fd,14)=g->max_member;
  7277. WFIFOL(fd,18)=g->average_lv;
  7278. WFIFOL(fd,22)=(uint32)cap_value(g->exp, 0, MAX_GUILD_EXP);
  7279. WFIFOL(fd,26)=(uint32)cap_value(g->next_exp, 0, MAX_GUILD_EXP);
  7280. WFIFOL(fd,30)=0; // Tax Points
  7281. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7282. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7283. WFIFOL(fd,42)=g->emblem_id;
  7284. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7285. #if PACKETVER < 20160622
  7286. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7287. #endif
  7288. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7289. WFIFOL(fd,70+offset+16) = 0; // zeny
  7290. #if PACKETVER >= 20160622
  7291. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7292. #endif
  7293. WFIFOSET(fd,packet_len(cmd));
  7294. }
  7295. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7296. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7297. void clif_guild_allianceinfo(struct map_session_data *sd)
  7298. {
  7299. int fd,i,c;
  7300. struct guild *g;
  7301. nullpo_retv(sd);
  7302. if( (g = sd->guild) == NULL )
  7303. return;
  7304. fd = sd->fd;
  7305. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7306. WFIFOW(fd, 0)=0x14c;
  7307. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7308. struct guild_alliance *a=&g->alliance[i];
  7309. if(a->guild_id>0){
  7310. WFIFOL(fd,c*32+4)=a->opposition;
  7311. WFIFOL(fd,c*32+8)=a->guild_id;
  7312. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7313. c++;
  7314. }
  7315. }
  7316. WFIFOW(fd, 2)=c*32+4;
  7317. WFIFOSET(fd,WFIFOW(fd,2));
  7318. }
  7319. /// Guild member manager information
  7320. /// 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)
  7321. /// state:
  7322. /// 0 = offline
  7323. /// 1 = online
  7324. /// memo:
  7325. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7326. /// 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)
  7327. void clif_guild_memberlist(struct map_session_data *sd)
  7328. {
  7329. int fd;
  7330. int i,c;
  7331. struct guild *g;
  7332. #if PACKETVER < 20161026
  7333. int cmd = 0x154;
  7334. int size = 104;
  7335. #else
  7336. int cmd = 0xaa5;
  7337. int size = 34;
  7338. #endif
  7339. nullpo_retv(sd);
  7340. if( !session_isActive(fd = sd->fd) )
  7341. return;
  7342. if( (g = sd->guild) == NULL )
  7343. return;
  7344. WFIFOHEAD(fd, g->max_member * size + 4);
  7345. WFIFOW(fd, 0)=cmd;
  7346. for(i=0,c=0;i<g->max_member;i++){
  7347. struct guild_member *m=&g->member[i];
  7348. if(m->account_id==0)
  7349. continue;
  7350. WFIFOL(fd,c*size+ 4)=m->account_id;
  7351. WFIFOL(fd,c*size+ 8)=m->char_id;
  7352. WFIFOW(fd,c*size+12)=m->hair;
  7353. WFIFOW(fd,c*size+14)=m->hair_color;
  7354. WFIFOW(fd,c*size+16)=m->gender;
  7355. WFIFOW(fd,c*size+18)=m->class_;
  7356. WFIFOW(fd,c*size+20)=m->lv;
  7357. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7358. WFIFOL(fd,c*size+26)=m->online;
  7359. WFIFOL(fd,c*size+30)=m->position;
  7360. #if PACKETVER < 20161026
  7361. 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.
  7362. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7363. #else
  7364. WFIFOL(fd,c*size+34)=m->last_login;
  7365. #endif
  7366. c++;
  7367. }
  7368. WFIFOW(fd, 2)=c*size+4;
  7369. WFIFOSET(fd,WFIFOW(fd,2));
  7370. }
  7371. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7372. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7373. void clif_guild_positionnamelist(struct map_session_data *sd)
  7374. {
  7375. int i,fd;
  7376. struct guild *g;
  7377. nullpo_retv(sd);
  7378. if( (g = sd->guild) == NULL )
  7379. return;
  7380. fd = sd->fd;
  7381. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7382. WFIFOW(fd, 0)=0x166;
  7383. for(i=0;i<MAX_GUILDPOSITION;i++){
  7384. WFIFOL(fd,i*28+4)=i;
  7385. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7386. }
  7387. WFIFOW(fd,2)=i*28+4;
  7388. WFIFOSET(fd,WFIFOW(fd,2));
  7389. }
  7390. /// Guild position information (ZC_POSITION_INFO).
  7391. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7392. /// mode:
  7393. /// &0x01 = allow invite
  7394. /// &0x10 = allow expel
  7395. /// ranking:
  7396. /// TODO
  7397. void clif_guild_positioninfolist(struct map_session_data *sd)
  7398. {
  7399. int i,fd;
  7400. struct guild *g;
  7401. nullpo_retv(sd);
  7402. if( (g = sd->guild) == NULL )
  7403. return;
  7404. fd = sd->fd;
  7405. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7406. WFIFOW(fd, 0)=0x160;
  7407. for(i=0;i<MAX_GUILDPOSITION;i++){
  7408. struct guild_position *p=&g->position[i];
  7409. WFIFOL(fd,i*16+ 4)=i;
  7410. WFIFOL(fd,i*16+ 8)=p->mode;
  7411. WFIFOL(fd,i*16+12)=i;
  7412. WFIFOL(fd,i*16+16)=p->exp_mode;
  7413. }
  7414. WFIFOW(fd, 2)=i*16+4;
  7415. WFIFOSET(fd,WFIFOW(fd,2));
  7416. }
  7417. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7418. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7419. /// mode:
  7420. /// &0x01 = allow invite
  7421. /// &0x10 = allow expel
  7422. /// ranking:
  7423. /// TODO
  7424. void clif_guild_positionchanged(struct guild *g,int idx)
  7425. {
  7426. // FIXME: This packet is intended to update the clients after a
  7427. // commit of position info changes, not sending one packet per
  7428. // position.
  7429. struct map_session_data *sd;
  7430. unsigned char buf[128];
  7431. nullpo_retv(g);
  7432. WBUFW(buf, 0)=0x174;
  7433. WBUFW(buf, 2)=44; // packet len
  7434. // GUILD_REG_POSITION_INFO{
  7435. WBUFL(buf, 4)=idx;
  7436. WBUFL(buf, 8)=g->position[idx].mode;
  7437. WBUFL(buf,12)=idx;
  7438. WBUFL(buf,16)=g->position[idx].exp_mode;
  7439. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7440. // }*
  7441. if( (sd=guild_getavailablesd(g))!=NULL )
  7442. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7443. }
  7444. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7445. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7446. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7447. {
  7448. // FIXME: This packet is intended to update the clients after a
  7449. // commit of member position assignment changes, not sending one
  7450. // packet per position.
  7451. struct map_session_data *sd;
  7452. unsigned char buf[64];
  7453. nullpo_retv(g);
  7454. WBUFW(buf, 0)=0x156;
  7455. WBUFW(buf, 2)=16; // packet len
  7456. // MEMBER_POSITION_INFO{
  7457. WBUFL(buf, 4)=g->member[idx].account_id;
  7458. WBUFL(buf, 8)=g->member[idx].char_id;
  7459. WBUFL(buf,12)=g->member[idx].position;
  7460. // }*
  7461. if( (sd=guild_getavailablesd(g))!=NULL )
  7462. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7463. }
  7464. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7465. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7466. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7467. {
  7468. int fd;
  7469. nullpo_retv(sd);
  7470. nullpo_retv(g);
  7471. fd = sd->fd;
  7472. if( g->emblem_len <= 0 )
  7473. return;
  7474. WFIFOHEAD(fd,g->emblem_len+12);
  7475. WFIFOW(fd,0)=0x152;
  7476. WFIFOW(fd,2)=g->emblem_len+12;
  7477. WFIFOL(fd,4)=g->guild_id;
  7478. WFIFOL(fd,8)=g->emblem_id;
  7479. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7480. WFIFOSET(fd,WFIFOW(fd,2));
  7481. }
  7482. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7483. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7484. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7485. void clif_guild_emblem_area(struct block_list* bl)
  7486. {
  7487. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7488. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7489. PACKET_ZC_CHANGE_GUILD p{};
  7490. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7491. p.guild_id = status_get_guild_id(bl);
  7492. p.emblem_id = status_get_emblem_id(bl);
  7493. #if PACKETVER < 20190724
  7494. p.aid = bl->id;
  7495. #else
  7496. p.unknown = 0;
  7497. #endif
  7498. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7499. }
  7500. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7501. /// 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 }*
  7502. void clif_guild_skillinfo(struct map_session_data* sd)
  7503. {
  7504. int fd;
  7505. struct guild* g;
  7506. int i,c;
  7507. nullpo_retv(sd);
  7508. if( (g = sd->guild) == NULL )
  7509. return;
  7510. fd = sd->fd;
  7511. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7512. WFIFOW(fd,0) = 0x0162;
  7513. WFIFOW(fd,4) = g->skill_point;
  7514. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7515. {
  7516. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7517. {
  7518. int id = g->skill[i].id;
  7519. int p = 6 + c*37;
  7520. WFIFOW(fd,p+0) = id;
  7521. WFIFOL(fd,p+2) = skill_get_inf(id);
  7522. WFIFOW(fd,p+6) = g->skill[i].lv;
  7523. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7524. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7525. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7526. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7527. c++;
  7528. }
  7529. }
  7530. WFIFOW(fd,2) = 6 + c*37;
  7531. WFIFOSET(fd,WFIFOW(fd,2));
  7532. }
  7533. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7534. /// 016f <subject>.60B <notice>.120B
  7535. void clif_guild_notice(struct map_session_data* sd)
  7536. {
  7537. struct guild* g;
  7538. nullpo_retv(sd);
  7539. nullpo_retv(g = sd->guild);
  7540. int fd = sd->fd;
  7541. if ( !session_isActive(fd) )
  7542. return;
  7543. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7544. return;
  7545. WFIFOHEAD(fd,packet_len(0x16f));
  7546. WFIFOW(fd,0) = 0x16f;
  7547. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7548. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7549. WFIFOSET(fd,packet_len(0x16f));
  7550. }
  7551. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7552. /// 016a <guild id>.L <guild name>.24B
  7553. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7554. {
  7555. int fd;
  7556. nullpo_retv(sd);
  7557. nullpo_retv(g);
  7558. fd=sd->fd;
  7559. WFIFOHEAD(fd,packet_len(0x16a));
  7560. WFIFOW(fd,0)=0x16a;
  7561. WFIFOL(fd,2)=g->guild_id;
  7562. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7563. WFIFOSET(fd,packet_len(0x16a));
  7564. }
  7565. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7566. /// 0169 <answer>.B
  7567. /// answer:
  7568. /// 0 = Already in guild.
  7569. /// 1 = Offer rejected.
  7570. /// 2 = Offer accepted.
  7571. /// 3 = Guild full.
  7572. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7573. {
  7574. int fd;
  7575. nullpo_retv(sd);
  7576. fd=sd->fd;
  7577. WFIFOHEAD(fd,packet_len(0x169));
  7578. WFIFOW(fd,0)=0x169;
  7579. WFIFOB(fd,2)=flag;
  7580. WFIFOSET(fd,packet_len(0x169));
  7581. }
  7582. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7583. /// 015a <char name>.24B <reason>.40B
  7584. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7585. {
  7586. unsigned char buf[128];
  7587. nullpo_retv(sd);
  7588. WBUFW(buf, 0)=0x15a;
  7589. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7590. memcpy(WBUFP(buf,26),mes,40);
  7591. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7592. }
  7593. /// Notifies clients of a guild of an expelled member.
  7594. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7595. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7596. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7597. {
  7598. unsigned char buf[128];
  7599. #if PACKETVER < 20100803
  7600. const unsigned short cmd = 0x15c;
  7601. #else
  7602. const unsigned short cmd = 0x839;
  7603. #endif
  7604. nullpo_retv(sd);
  7605. WBUFW(buf,0) = cmd;
  7606. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7607. safestrncpy(WBUFCP(buf,26), mes, 40);
  7608. #if PACKETVER < 20100803
  7609. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7610. #endif
  7611. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7612. }
  7613. /// Guild expulsion list (ZC_BAN_LIST).
  7614. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7615. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7616. void clif_guild_expulsionlist(struct map_session_data* sd)
  7617. {
  7618. #if PACKETVER < 20100803
  7619. const int offset = NAME_LENGTH*2+40;
  7620. #else
  7621. const int offset = NAME_LENGTH+40;
  7622. #endif
  7623. int fd, i, c = 0;
  7624. struct guild* g;
  7625. nullpo_retv(sd);
  7626. if( (g = sd->guild) == NULL )
  7627. return;
  7628. fd = sd->fd;
  7629. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7630. WFIFOW(fd,0) = 0x163;
  7631. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7632. {
  7633. struct guild_expulsion* e = &g->expulsion[i];
  7634. if( e->account_id > 0 )
  7635. {
  7636. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7637. #if PACKETVER < 20100803
  7638. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7639. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7640. #else
  7641. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7642. #endif
  7643. c++;
  7644. }
  7645. }
  7646. WFIFOW(fd,2) = 4 + c*offset;
  7647. WFIFOSET(fd,WFIFOW(fd,2));
  7648. }
  7649. /// Guild chat message (ZC_GUILD_CHAT).
  7650. /// 017f <packet len>.W <message>.?B
  7651. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7652. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7653. struct map_session_data *sd;
  7654. uint8 buf[256];
  7655. if( len == 0 )
  7656. {
  7657. return;
  7658. }
  7659. else if( len > sizeof(buf)-5 )
  7660. {
  7661. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7662. len = sizeof(buf)-5;
  7663. }
  7664. WBUFW(buf, 0) = 0x17f;
  7665. WBUFW(buf, 2) = len + 5;
  7666. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7667. if ((sd = guild_getavailablesd(g)) != NULL)
  7668. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7669. }
  7670. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7671. /// 0171 <inviter account id>.L <guild name>.24B
  7672. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7673. {
  7674. int fd;
  7675. nullpo_retv(sd);
  7676. fd=sd->fd;
  7677. WFIFOHEAD(fd,packet_len(0x171));
  7678. WFIFOW(fd,0)=0x171;
  7679. WFIFOL(fd,2)=account_id;
  7680. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7681. WFIFOSET(fd,packet_len(0x171));
  7682. }
  7683. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7684. /// 0173 <answer>.B
  7685. /// answer:
  7686. /// 0 = Already allied.
  7687. /// 1 = You rejected the offer.
  7688. /// 2 = You accepted the offer.
  7689. /// 3 = They have too any alliances.
  7690. /// 4 = You have too many alliances.
  7691. /// 5 = Alliances are disabled.
  7692. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7693. {
  7694. int fd;
  7695. nullpo_retv(sd);
  7696. fd=sd->fd;
  7697. WFIFOHEAD(fd,packet_len(0x173));
  7698. WFIFOW(fd,0)=0x173;
  7699. WFIFOL(fd,2)=flag;
  7700. WFIFOSET(fd,packet_len(0x173));
  7701. }
  7702. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7703. /// 0184 <other guild id>.L <relation>.L
  7704. /// relation:
  7705. /// 0 = Ally
  7706. /// 1 = Enemy
  7707. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7708. {
  7709. nullpo_retv(sd);
  7710. int fd = sd->fd;
  7711. if ( !session_isActive(fd) )
  7712. return;
  7713. WFIFOHEAD(fd,packet_len(0x184));
  7714. WFIFOW(fd,0)=0x184;
  7715. WFIFOL(fd,2)=guild_id;
  7716. WFIFOL(fd,6)=flag;
  7717. WFIFOSET(fd,packet_len(0x184));
  7718. }
  7719. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7720. /// 0181 <result>.B
  7721. /// result:
  7722. /// 0 = Antagonist has been set.
  7723. /// 1 = Guild has too many Antagonists.
  7724. /// 2 = Already set as an Antagonist.
  7725. /// 3 = Antagonists are disabled.
  7726. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7727. {
  7728. int fd;
  7729. nullpo_retv(sd);
  7730. fd=sd->fd;
  7731. WFIFOHEAD(fd,packet_len(0x181));
  7732. WFIFOW(fd,0)=0x181;
  7733. WFIFOB(fd,2)=flag;
  7734. WFIFOSET(fd,packet_len(0x181));
  7735. }
  7736. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7737. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7738. /*
  7739. void clif_guild_allianceadded(struct guild *g,int idx)
  7740. {
  7741. unsigned char buf[64];
  7742. WBUFW(buf,0)=0x185;
  7743. WBUFL(buf,2)=g->alliance[idx].opposition;
  7744. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7745. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7746. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7747. }
  7748. */
  7749. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7750. /// 015e <reason>.L
  7751. /// 0 = success
  7752. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7753. /// 2 = there are still members in the guild
  7754. void clif_guild_broken(struct map_session_data *sd,int flag)
  7755. {
  7756. int fd;
  7757. nullpo_retv(sd);
  7758. fd=sd->fd;
  7759. WFIFOHEAD(fd,packet_len(0x15e));
  7760. WFIFOW(fd,0)=0x15e;
  7761. WFIFOL(fd,2)=flag;
  7762. WFIFOSET(fd,packet_len(0x15e));
  7763. }
  7764. /// Displays emotion on an object (ZC_EMOTION).
  7765. /// 00c0 <id>.L <type>.B
  7766. /// type:
  7767. /// enum emotion_type
  7768. void clif_emotion(struct block_list *bl,int type)
  7769. {
  7770. unsigned char buf[8];
  7771. nullpo_retv(bl);
  7772. WBUFW(buf,0)=0xc0;
  7773. WBUFL(buf,2)=bl->id;
  7774. WBUFB(buf,6)=type;
  7775. clif_send(buf,packet_len(0xc0),bl,AREA);
  7776. }
  7777. /// Displays the contents of a talkiebox trap.
  7778. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7779. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7780. nullpo_retv( bl );
  7781. nullpo_retv( talkie );
  7782. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7783. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7784. p.aid = bl->id;
  7785. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7786. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7787. }
  7788. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7789. /// 01ea <id>.L
  7790. void clif_wedding_effect(struct block_list *bl)
  7791. {
  7792. unsigned char buf[6];
  7793. nullpo_retv(bl);
  7794. WBUFW(buf,0) = 0x1ea;
  7795. WBUFL(buf,2) = bl->id;
  7796. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7797. }
  7798. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7799. /// 01e6 <partner name>.24B
  7800. void clif_callpartner(struct map_session_data *sd)
  7801. {
  7802. unsigned char buf[26];
  7803. nullpo_retv(sd);
  7804. WBUFW(buf,0) = 0x1e6;
  7805. if( sd->status.partner_id ) {
  7806. const char *p = map_charid2nick(sd->status.partner_id);
  7807. struct map_session_data *p_sd = pc_get_partner(sd);
  7808. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7809. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7810. else
  7811. WBUFB(buf,2) = 0;
  7812. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7813. WBUFB(buf,2) = 0;
  7814. }
  7815. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7816. }
  7817. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7818. /// 01e4
  7819. /// This packet while still implemented by the client is no longer being officially used.
  7820. /*
  7821. void clif_marriage_process(struct map_session_data *sd)
  7822. {
  7823. int fd;
  7824. nullpo_retv(sd);
  7825. fd=sd->fd;
  7826. WFIFOHEAD(fd,packet_len(0x1e4));
  7827. WFIFOW(fd,0)=0x1e4;
  7828. WFIFOSET(fd,packet_len(0x1e4));
  7829. }
  7830. */
  7831. /// Notice of divorce (ZC_DIVORCE).
  7832. /// 0205 <partner name>.24B
  7833. void clif_divorced(struct map_session_data* sd, const char* name)
  7834. {
  7835. int fd;
  7836. nullpo_retv(sd);
  7837. fd=sd->fd;
  7838. WFIFOHEAD(fd,packet_len(0x205));
  7839. WFIFOW(fd,0)=0x205;
  7840. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7841. WFIFOSET(fd, packet_len(0x205));
  7842. }
  7843. /// Marriage proposal (ZC_REQ_COUPLE).
  7844. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7845. /// This packet while still implemented by the client is no longer being officially used.
  7846. /*
  7847. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7848. {
  7849. nullpo_retv(sd);
  7850. WFIFOHEAD(fd,packet_len(0x1e2));
  7851. WFIFOW(fd,0) = 0x1e2;
  7852. WFIFOL(fd,2) = ssd->status.account_id;
  7853. WFIFOL(fd,6) = ssd->status.char_id;
  7854. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7855. WFIFOSET(fd, packet_len(0x1e2));
  7856. }
  7857. */
  7858. /*==========================================
  7859. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7860. *------------------------------------------*/
  7861. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7862. {
  7863. unsigned char buf[256];
  7864. if( len == 0 ) {
  7865. return;
  7866. } else if( len > sizeof(buf)-5 ) {
  7867. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7868. len = sizeof(buf)-5;
  7869. }
  7870. WBUFW(buf, 0) = 0x17f;
  7871. WBUFW(buf, 2) = len + 5;
  7872. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7873. clif_send(buf, WBUFW(buf,2), src, target);
  7874. }
  7875. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7876. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7877. /// 00cd <result>.B
  7878. /// result:
  7879. /// 0 = failure
  7880. /// 1 = success
  7881. void clif_GM_kickack(struct map_session_data *sd, int id)
  7882. {
  7883. int fd;
  7884. nullpo_retv(sd);
  7885. fd = sd->fd;
  7886. WFIFOHEAD(fd,packet_len(0xcd));
  7887. WFIFOW(fd,0) = 0xcd;
  7888. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7889. WFIFOSET(fd, packet_len(0xcd));
  7890. }
  7891. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7892. {
  7893. nullpo_retv(tsd);
  7894. if (sd == NULL)
  7895. tsd->state.keepshop = true;
  7896. if (session_isActive(tsd->fd))
  7897. clif_authfail_fd(tsd->fd, 15);
  7898. else
  7899. map_quit(tsd);
  7900. if (sd)
  7901. clif_GM_kickack(sd, tsd->status.account_id);
  7902. }
  7903. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7904. /// 014a <result>.L
  7905. /// result:
  7906. /// 0 = "A manner point has been successfully aligned."
  7907. /// 1 = MP_FAILURE_EXHAUST
  7908. /// 2 = MP_FAILURE_ALREADY_GIVING
  7909. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7910. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7911. /// 5 = "You got a good point from %s."
  7912. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7913. {
  7914. int fd;
  7915. nullpo_retv(sd);
  7916. fd = sd->fd;
  7917. WFIFOHEAD(fd,packet_len(0x14a));
  7918. WFIFOW(fd,0) = 0x14a;
  7919. WFIFOL(fd,2) = type;
  7920. WFIFOSET(fd, packet_len(0x14a));
  7921. }
  7922. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7923. /// 014b <type>.B <GM name>.24B
  7924. /// type:
  7925. /// 0 = positive (unmute)
  7926. /// 1 = negative (mute)
  7927. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7928. {
  7929. int fd;
  7930. nullpo_retv(sd);
  7931. nullpo_retv(tsd);
  7932. fd = tsd->fd;
  7933. WFIFOHEAD(fd,packet_len(0x14b));
  7934. WFIFOW(fd,0) = 0x14b;
  7935. WFIFOB(fd,2) = type;
  7936. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7937. WFIFOSET(fd, packet_len(0x14b));
  7938. }
  7939. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7940. /// 00d1 <type>.B <result>.B
  7941. /// type:
  7942. /// 0 = /ex (deny)
  7943. /// 1 = /in (allow)
  7944. /// result:
  7945. /// 0 = success
  7946. /// 1 = failure
  7947. /// 2 = too many blocks
  7948. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7949. {
  7950. int fd;
  7951. nullpo_retv(sd);
  7952. fd=sd->fd;
  7953. WFIFOHEAD(fd,packet_len(0xd1));
  7954. WFIFOW(fd,0)=0xd1;
  7955. WFIFOB(fd,2)=type;
  7956. WFIFOB(fd,3)=flag;
  7957. WFIFOSET(fd,packet_len(0xd1));
  7958. }
  7959. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7960. /// 00d2 <type>.B <result>.B
  7961. /// type:
  7962. /// 0 = /exall (deny)
  7963. /// 1 = /inall (allow)
  7964. /// result:
  7965. /// 0 = success
  7966. /// 1 = failure
  7967. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7968. {
  7969. int fd;
  7970. nullpo_retv(sd);
  7971. fd=sd->fd;
  7972. WFIFOHEAD(fd,packet_len(0xd2));
  7973. WFIFOW(fd,0)=0xd2;
  7974. WFIFOB(fd,2)=type;
  7975. WFIFOB(fd,3)=flag;
  7976. WFIFOSET(fd,packet_len(0xd2));
  7977. }
  7978. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7979. /// 07fe <bgm>.24B
  7980. void clif_playBGM(struct map_session_data* sd, const char* name)
  7981. {
  7982. int fd;
  7983. nullpo_retv(sd);
  7984. fd = sd->fd;
  7985. WFIFOHEAD(fd,packet_len(0x7fe));
  7986. WFIFOW(fd,0) = 0x7fe;
  7987. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7988. WFIFOSET(fd,packet_len(0x7fe));
  7989. }
  7990. /// Plays/stops a wave sound (ZC_SOUND).
  7991. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7992. /// file name:
  7993. /// relative to data\wav
  7994. /// act:
  7995. /// 0 = play (once)
  7996. /// 1 = play (repeat, does not work)
  7997. /// 2 = stops all sound instances of file name (does not work)
  7998. /// term:
  7999. /// unknown purpose, only relevant to act = 1
  8000. /// npc id:
  8001. /// The accustic direction of the sound is determined by the
  8002. /// relative position of the NPC to the player (3D sound).
  8003. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8004. {
  8005. int fd;
  8006. nullpo_retv(sd);
  8007. nullpo_retv(bl);
  8008. fd = sd->fd;
  8009. WFIFOHEAD(fd,packet_len(0x1d3));
  8010. WFIFOW(fd,0) = 0x1d3;
  8011. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8012. WFIFOB(fd,26) = type;
  8013. WFIFOL(fd,27) = 0;
  8014. WFIFOL(fd,31) = bl->id;
  8015. WFIFOSET(fd,packet_len(0x1d3));
  8016. }
  8017. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8018. {
  8019. unsigned char buf[40];
  8020. nullpo_retv(bl);
  8021. WBUFW(buf,0) = 0x1d3;
  8022. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8023. WBUFB(buf,26) = type;
  8024. WBUFL(buf,27) = 0;
  8025. WBUFL(buf,31) = bl->id;
  8026. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8027. }
  8028. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8029. /// 01f3 <id>.L <effect id>.L
  8030. /// effect id:
  8031. /// @see doc/effect_list.txt
  8032. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8033. {
  8034. unsigned char buf[24];
  8035. nullpo_retv(bl);
  8036. memset(buf, 0, packet_len(0x1f3));
  8037. WBUFW(buf,0) = 0x1f3;
  8038. WBUFL(buf,2) = bl->id;
  8039. WBUFL(buf,6) = type;
  8040. clif_send(buf, packet_len(0x1f3), bl, target);
  8041. if (disguised(bl)) {
  8042. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8043. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8044. }
  8045. }
  8046. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8047. {
  8048. WFIFOHEAD(fd,10);
  8049. WFIFOW(fd,0) = 0x1f3;
  8050. WFIFOL(fd,2) = bl->id;
  8051. WFIFOL(fd,6) = type;
  8052. WFIFOSET(fd,10);
  8053. }
  8054. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8055. /// 0284 <id>.L <effect id>.L <num data>.L
  8056. /// effect id:
  8057. /// @see doc/effect_list.txt
  8058. /// num data:
  8059. /// effect-dependent value
  8060. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8061. {
  8062. uint8 buf[14];
  8063. WBUFW(buf,0) = 0x284;
  8064. WBUFL(buf,2) = bl->id;
  8065. WBUFL(buf,6) = effect_id;
  8066. WBUFL(buf,10) = num;
  8067. clif_send(buf, packet_len(0x284), bl, target);
  8068. if( disguised(bl) )
  8069. {
  8070. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8071. clif_send(buf, packet_len(0x284), bl, SELF);
  8072. }
  8073. }
  8074. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8075. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8076. 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) {
  8077. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8078. uint8 buf[CHAT_SIZE_MAX];
  8079. nullpo_retv(bl);
  8080. if (msg_len > sizeof(buf) - 12) {
  8081. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8082. msg_len = sizeof(buf) - 12;
  8083. }
  8084. if (rgb2bgr)
  8085. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8086. WBUFW(buf,0) = 0x2C1;
  8087. WBUFW(buf,2) = msg_len + 12;
  8088. WBUFL(buf,4) = bl->id;
  8089. WBUFL(buf,8) = color;
  8090. memcpy(WBUFCP(buf,12), msg, msg_len);
  8091. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8092. }
  8093. /**
  8094. * Notifies the client that the storage window is still open
  8095. *
  8096. * Should only be used in cases where the client closed the
  8097. * storage window without server's consent
  8098. */
  8099. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8100. // Notify the client that the storage is open
  8101. if( sd->state.storage_flag == 1 ) {
  8102. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8103. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8104. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8105. }
  8106. // Notify the client that the gstorage is open otherwise it will
  8107. // remain locked forever and nobody will be able to access it
  8108. if( sd->state.storage_flag == 2 ) {
  8109. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8110. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8111. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8112. else {
  8113. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8114. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8115. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8116. }
  8117. }
  8118. // Notify the client that the premium storage is open
  8119. if (sd->state.storage_flag == 3) {
  8120. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8121. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8122. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8123. }
  8124. }
  8125. // refresh the client's screen, getting rid of any effects
  8126. void clif_refresh(struct map_session_data *sd)
  8127. {
  8128. nullpo_retv(sd);
  8129. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8130. clif_inventorylist(sd);
  8131. clif_equipswitch_list(sd);
  8132. if(pc_iscarton(sd)) {
  8133. clif_cartlist(sd);
  8134. clif_updatestatus(sd,SP_CARTINFO);
  8135. }
  8136. clif_updatestatus(sd,SP_WEIGHT);
  8137. clif_updatestatus(sd,SP_MAXWEIGHT);
  8138. clif_updatestatus(sd,SP_STR);
  8139. clif_updatestatus(sd,SP_AGI);
  8140. clif_updatestatus(sd,SP_VIT);
  8141. clif_updatestatus(sd,SP_INT);
  8142. clif_updatestatus(sd,SP_DEX);
  8143. clif_updatestatus(sd,SP_LUK);
  8144. if (sd->spiritball)
  8145. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8146. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8147. clif_millenniumshield_single(sd->fd, sd);
  8148. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8149. clif_spiritcharm_single(sd->fd, sd);
  8150. if (sd->soulball)
  8151. clif_soulball( sd, &sd->bl, SELF );
  8152. if (sd->vd.cloth_color)
  8153. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8154. if (sd->vd.body_style)
  8155. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8156. if(hom_is_active(sd->hd))
  8157. clif_send_homdata(sd,SP_ACK,0);
  8158. if( sd->md ) {
  8159. clif_mercenary_info(sd);
  8160. clif_mercenary_skillblock(sd);
  8161. }
  8162. if( sd->ed )
  8163. clif_elemental_info(sd);
  8164. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8165. clif_weather_check(sd);
  8166. if( sd->chatID )
  8167. chat_leavechat(sd,0);
  8168. if( sd->state.vending )
  8169. clif_openvending(sd, sd->bl.id, sd->vending);
  8170. if( pc_issit(sd) )
  8171. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8172. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8173. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8174. else
  8175. clif_changed_dir(&sd->bl, SELF);
  8176. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8177. //Issue #2143
  8178. //Cancel Trading State
  8179. if (sd->state.trading)
  8180. trade_tradecancel(sd);
  8181. //Cancel Buying/Selling State
  8182. if (sd->state.buyingstore)
  8183. buyingstore_close(sd);
  8184. mail_clear(sd);
  8185. clif_loadConfirm( sd );
  8186. if( disguised(&sd->bl) ) {/* refresh-da */
  8187. short disguise = sd->disguise;
  8188. pc_disguise(sd, 0);
  8189. pc_disguise(sd, disguise);
  8190. }
  8191. clif_refresh_storagewindow(sd);
  8192. }
  8193. /// Updates the object's (bl) name on client.
  8194. /// Used to update when a char leaves a party/guild. [Skotlex]
  8195. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8196. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8197. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8198. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8199. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8200. nullpo_retv( src );
  8201. nullpo_retv( bl );
  8202. switch( bl->type ){
  8203. case BL_PC: {
  8204. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8205. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8206. packet.gid = bl->id;
  8207. map_session_data *sd = (map_session_data *)bl;
  8208. //Requesting your own "shadow" name. [Skotlex]
  8209. if( src == bl && target == SELF && sd->disguise ){
  8210. packet.gid = -bl->id;
  8211. }
  8212. if( sd->fakename[0] ) {
  8213. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8214. clif_send( &packet, sizeof(packet), src, target );
  8215. return;
  8216. }
  8217. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8218. party_data *p = nullptr;
  8219. if( sd->status.party_id ){
  8220. p = party_search( sd->status.party_id );
  8221. }
  8222. // do not display party unless the player is also in a guild
  8223. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8224. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8225. }
  8226. if( sd->guild ){
  8227. int position;
  8228. // Will get the position of the guild the player is in
  8229. position = guild_getposition( sd );
  8230. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8231. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8232. }else if( sd->clan ){
  8233. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8234. }
  8235. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8236. packet.title_id = sd->status.title_id; // Title ID
  8237. #endif
  8238. clif_send(&packet, sizeof(packet), src, target);
  8239. }
  8240. break;
  8241. //[blackhole89]
  8242. case BL_HOM:
  8243. case BL_MER:
  8244. case BL_PET:
  8245. case BL_NPC:
  8246. case BL_ELEM: {
  8247. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8248. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8249. packet.gid = bl->id;
  8250. switch (bl->type) {
  8251. case BL_HOM:
  8252. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8253. break;
  8254. case BL_MER:
  8255. memcpy(packet.name, ((TBL_MER *)bl)->db->name, NAME_LENGTH);
  8256. break;
  8257. case BL_PET:
  8258. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8259. break;
  8260. case BL_NPC:
  8261. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8262. break;
  8263. case BL_ELEM:
  8264. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name, NAME_LENGTH);
  8265. break;
  8266. }
  8267. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8268. unit_data *ud = unit_bl2ud(bl);
  8269. if (ud != nullptr) {
  8270. memcpy(packet.title, ud->title, NAME_LENGTH);
  8271. packet.groupId = ud->group_id;
  8272. }
  8273. #endif
  8274. clif_send(&packet, sizeof(packet), src, target);
  8275. }
  8276. break;
  8277. case BL_MOB: {
  8278. mob_data *md = (mob_data *)bl;
  8279. if( md->guardian_data && md->guardian_data->guild_id ){
  8280. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8281. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8282. packet.gid = bl->id;
  8283. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8284. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8285. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8286. clif_send(&packet, sizeof(packet), src, target);
  8287. }else if( battle_config.show_mob_info ){
  8288. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8289. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8290. packet.gid = bl->id;
  8291. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8292. char mobhp[50], *str_p = mobhp;
  8293. if( battle_config.show_mob_info&4 ){
  8294. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8295. }
  8296. if( battle_config.show_mob_info&1 ){
  8297. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8298. }
  8299. if( battle_config.show_mob_info&2 ){
  8300. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8301. }
  8302. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8303. if( str_p != mobhp ){
  8304. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8305. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8306. }
  8307. clif_send(&packet, sizeof(packet), src, target);
  8308. } else {
  8309. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8310. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8311. packet.gid = bl->id;
  8312. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8313. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8314. unit_data *ud = unit_bl2ud(bl);
  8315. if (ud != nullptr) {
  8316. memcpy(packet.title, ud->title, NAME_LENGTH);
  8317. packet.groupId = ud->group_id;
  8318. }
  8319. #endif
  8320. clif_send(&packet, sizeof(packet), src, target);
  8321. }
  8322. }
  8323. break;
  8324. case BL_CHAT:
  8325. case BL_SKILL:
  8326. // Newer clients request this, but do not need an answer
  8327. return;
  8328. default:
  8329. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8330. return;
  8331. }
  8332. }
  8333. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8334. /// 01ff <id>.L <x>.W <y>.W
  8335. ///
  8336. /// Visually moves(instant) a character to x,y. The char moves even
  8337. /// when the target cell isn't walkable. If the char is sitting it
  8338. /// stays that way.
  8339. void clif_slide(struct block_list *bl, int x, int y)
  8340. {
  8341. unsigned char buf[10];
  8342. nullpo_retv(bl);
  8343. WBUFW(buf, 0) = 0x01ff;
  8344. WBUFL(buf, 2) = bl->id;
  8345. WBUFW(buf, 6) = x;
  8346. WBUFW(buf, 8) = y;
  8347. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8348. if( disguised(bl) )
  8349. {
  8350. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8351. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8352. }
  8353. }
  8354. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8355. /// 008d <packet len>.W <id>.L <message>.?B
  8356. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8357. {
  8358. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8359. int len_mes = strlen(mes)+1; //Account for \0
  8360. if (len_mes > sizeof(buf)-8) {
  8361. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8362. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8363. }
  8364. // send message to others
  8365. if (flag == AREA) {
  8366. WBUFW(buf,0) = 0x8d;
  8367. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8368. WBUFL(buf,4) = bl->id;
  8369. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8370. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8371. }
  8372. // send back message to the speaker
  8373. if( bl->type == BL_PC ) {
  8374. WBUFW(buf,0) = 0x8e;
  8375. WBUFW(buf, 2) = len_mes + 4;
  8376. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8377. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8378. }
  8379. }
  8380. /*==========================
  8381. * Minimap fix [Kevin]
  8382. * Remove dot from minimap
  8383. *--------------------------*/
  8384. void clif_party_xy_remove(struct map_session_data *sd)
  8385. {
  8386. unsigned char buf[16];
  8387. nullpo_retv(sd);
  8388. WBUFW(buf,0)=0x107;
  8389. WBUFL(buf,2)=sd->status.account_id;
  8390. WBUFW(buf,6)=-1;
  8391. WBUFW(buf,8)=-1;
  8392. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8393. }
  8394. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8395. /// 0215 <msg id>.L
  8396. /// msg id:
  8397. /// 0x15 = End all negative status (PA_GOSPEL)
  8398. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8399. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8400. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8401. /// 0x19 = All stats +20 (PA_GOSPEL)
  8402. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8403. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8404. /// 0x1e = DEF +25% (PA_GOSPEL)
  8405. /// 0x1f = ATK +100% (PA_GOSPEL)
  8406. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8407. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8408. /// ? = nothing
  8409. void clif_gospel_info(struct map_session_data *sd, int type)
  8410. {
  8411. int fd=sd->fd;
  8412. WFIFOHEAD(fd,packet_len(0x215));
  8413. WFIFOW(fd,0)=0x215;
  8414. WFIFOL(fd,2)=type;
  8415. WFIFOSET(fd, packet_len(0x215));
  8416. }
  8417. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8418. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8419. /// result:
  8420. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8421. /// star:
  8422. /// 0 = Place of the Sun
  8423. /// 1 = Place of the Moon
  8424. /// 2 = Place of the Stars
  8425. /// 1 = Star Gladiator %s's %s: <mapname>
  8426. /// star:
  8427. /// 0 = Place of the Sun
  8428. /// 1 = Place of the Moon
  8429. /// 2 = Place of the Stars
  8430. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8431. /// star:
  8432. /// 0 = Target of the Sun
  8433. /// 1 = Target of the Moon
  8434. /// 2 = Target of the Stars
  8435. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8436. /// star:
  8437. /// 0 = Monster of the Sun
  8438. /// 1 = Monster of the Moon
  8439. /// 2 = Monster of the Stars
  8440. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8441. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8442. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8443. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8444. /// 40 = Target HP : <monster_id used as HP>
  8445. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8446. {
  8447. int fd = sd->fd;
  8448. WFIFOHEAD(fd,packet_len(0x20e));
  8449. WFIFOW(fd,0) = 0x20e;
  8450. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8451. WFIFOL(fd,26) = monster_id;
  8452. WFIFOB(fd,30) = star;
  8453. WFIFOB(fd,31) = result;
  8454. WFIFOSET(fd,packet_len(0x20e));
  8455. }
  8456. /*==========================================
  8457. * Info about Star Glaldiator save map [Komurka]
  8458. * type: 1: Information, 0: Map registered
  8459. *------------------------------------------*/
  8460. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8461. {
  8462. char mapname[MAP_NAME_LENGTH_EXT];
  8463. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8464. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8465. }
  8466. /*==========================================
  8467. * Info about Star Glaldiator hate mob [Komurka]
  8468. * type: 1: Register mob, 0: Information.
  8469. *------------------------------------------*/
  8470. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8471. {
  8472. if( pcdb_checkid(class_) ) {
  8473. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8474. } else if( mobdb_checkid(class_) ) {
  8475. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8476. } else {
  8477. 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);
  8478. }
  8479. }
  8480. /*==========================================
  8481. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8482. *------------------------------------------*/
  8483. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8484. {
  8485. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8486. }
  8487. /*==========================================
  8488. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8489. *------------------------------------------*/
  8490. void clif_feel_hate_reset(struct map_session_data *sd)
  8491. {
  8492. clif_starskill(sd, "", 0, 0, 30);
  8493. }
  8494. /// Send out reply to configuration change
  8495. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8496. /// type: see enum e_config_type
  8497. /// value:
  8498. /// false = disabled
  8499. /// true = enabled
  8500. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8501. int fd;
  8502. nullpo_retv(sd);
  8503. fd = sd->fd;
  8504. WFIFOHEAD(fd, packet_len(0x2d9));
  8505. WFIFOW(fd, 0) = 0x2d9;
  8506. WFIFOL(fd, 2) = type;
  8507. WFIFOL(fd, 6) = enabled;
  8508. WFIFOSET(fd, packet_len(0x2d9));
  8509. }
  8510. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8511. /// 02da <open equip window>.B
  8512. /// open equip window:
  8513. /// 0 = disabled
  8514. /// 1 = enabled
  8515. void clif_equipcheckbox(struct map_session_data* sd)
  8516. {
  8517. int fd;
  8518. nullpo_retv(sd);
  8519. fd = sd->fd;
  8520. WFIFOHEAD(fd, packet_len(0x2da));
  8521. WFIFOW(fd, 0) = 0x2da;
  8522. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8523. WFIFOSET(fd, packet_len(0x2da));
  8524. }
  8525. /// Sends info about a player's equipped items.
  8526. /// 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)
  8527. /// 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)
  8528. /// 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)
  8529. /// 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)
  8530. /// 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)
  8531. /// 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)
  8532. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8533. nullpo_retv( sd );
  8534. nullpo_retv( tsd );
  8535. struct packet_viewequip_ack packet;
  8536. int equip = 0;
  8537. for( int i = 0; i < EQI_MAX; i++ ){
  8538. int k = tsd->equip_index[i];
  8539. if( k >= 0 ){
  8540. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8541. continue;
  8542. }
  8543. if( !tsd->inventory.u.items_inventory[k].equip ){
  8544. continue;
  8545. }
  8546. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8547. continue;
  8548. }
  8549. clif_item_equip( client_index( k ), &packet.list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8550. }
  8551. }
  8552. packet.PacketType = viewequipackType;
  8553. packet.PacketLength = ( sizeof( packet ) - sizeof( packet.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  8554. safestrncpy( packet.characterName, tsd->status.name, NAME_LENGTH );
  8555. packet.job = tsd->status.class_;
  8556. packet.head = tsd->vd.hair_style;
  8557. packet.accessory = tsd->vd.head_bottom;
  8558. packet.accessory2 = tsd->vd.head_mid;
  8559. packet.accessory3 = tsd->vd.head_top;
  8560. #if PACKETVER >= 20110111
  8561. packet.robe = tsd->vd.robe;
  8562. #endif
  8563. packet.headpalette = tsd->vd.hair_color;
  8564. packet.bodypalette = tsd->vd.cloth_color;
  8565. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8566. packet.body2 = tsd->vd.body_style;
  8567. #endif
  8568. packet.sex = tsd->vd.sex;
  8569. clif_send( &packet, packet.PacketLength, &sd->bl, SELF );
  8570. }
  8571. /// Display msgstringtable.txt string (ZC_MSG).
  8572. /// 0291 <message>.W
  8573. void clif_msg(struct map_session_data* sd, unsigned short id)
  8574. {
  8575. int fd;
  8576. nullpo_retv(sd);
  8577. fd = sd->fd;
  8578. WFIFOHEAD(fd, packet_len(0x291));
  8579. WFIFOW(fd, 0) = 0x291;
  8580. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8581. WFIFOSET(fd, packet_len(0x291));
  8582. }
  8583. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8584. /// 0x7e2 <message>.W <value>.L
  8585. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8586. {
  8587. int fd = sd->fd;
  8588. WFIFOHEAD(fd, packet_len(0x7e2));
  8589. WFIFOW(fd,0) = 0x7e2;
  8590. WFIFOW(fd,2) = id;
  8591. WFIFOL(fd,4) = value;
  8592. WFIFOSET(fd, packet_len(0x7e2));
  8593. }
  8594. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8595. /// 07e6 <skill id>.W <msg id>.L
  8596. ///
  8597. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8598. /// "[SkillName] Message"
  8599. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8600. {
  8601. int fd = sd->fd;
  8602. WFIFOHEAD(fd, packet_len(0x7e6));
  8603. WFIFOW(fd,0) = 0x7e6;
  8604. WFIFOW(fd,2) = skill_id;
  8605. WFIFOL(fd,4) = msg_id;
  8606. WFIFOSET(fd, packet_len(0x7e6));
  8607. }
  8608. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8609. /// 09cd <msg id>.W <color>.L
  8610. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8611. nullpo_retv(sd);
  8612. int fd = sd->fd;
  8613. WFIFOHEAD(fd, packet_len(0x9cd));
  8614. WFIFOW(fd, 0) = 0x9cd;
  8615. WFIFOW(fd, 2) = msg_id;
  8616. WFIFOL(fd, 4) = color;
  8617. WFIFOSET(fd, packet_len(0x9cd));
  8618. }
  8619. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8620. /// Returns true if the packet was parsed successfully.
  8621. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8622. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8623. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8624. const char* seperator = " : ";
  8625. int fd;
  8626. struct s_packet_db* info;
  8627. uint16 packetLength, inputLength;
  8628. const char *input, *name, *message;
  8629. size_t nameLength, messageLength;
  8630. fd = sd->fd;
  8631. info = &packet_db[RFIFOW(fd,0)];
  8632. packetLength = RFIFOW(fd,info->pos[0]);
  8633. input = RFIFOCP(fd,info->pos[1]);
  8634. // basic structure check for the 4-byte header
  8635. if( packetLength < 4 ){
  8636. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8637. return false;
  8638. }else{
  8639. inputLength = packetLength - 4;
  8640. }
  8641. // process <name> part of the packet
  8642. if( whisperFormat ) {
  8643. // name has fixed width
  8644. if( inputLength < NAME_LENGTH + 1 ) {
  8645. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8646. return false;
  8647. }
  8648. name = input;
  8649. // validate name
  8650. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8651. // only restriction is that the name must be zero-terminated
  8652. if( name[nameLength] != '\0' ) {
  8653. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8654. return false;
  8655. }
  8656. message = input + NAME_LENGTH;
  8657. messageLength = inputLength - NAME_LENGTH;
  8658. }else{
  8659. // name and message are separated by ' : '
  8660. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8661. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8662. // check if there's enough data provided
  8663. if( inputLength < nameLength + seperatorLength + 1 ){
  8664. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8665. return false;
  8666. }
  8667. name = input;
  8668. // validate name
  8669. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8670. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8671. {
  8672. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8673. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8674. set_eof(sd->fd); // Just kick them out to correct it.
  8675. return false;
  8676. }
  8677. message = input + nameLength + seperatorLength;
  8678. messageLength = inputLength - nameLength - seperatorLength;
  8679. }
  8680. #if PACKETVER < 20151001
  8681. // the declared length must match real length
  8682. if( messageLength != strnlen(message, messageLength)+1 ) {
  8683. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8684. return false;
  8685. }
  8686. // verify <message> part of the packet
  8687. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8688. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8689. return false;
  8690. }
  8691. #else
  8692. // No zero termination anymore
  8693. messageLength += 1;
  8694. #endif
  8695. // messages mustn't be too long
  8696. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8697. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8698. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8699. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8700. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8701. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8702. return false;
  8703. }
  8704. // If it is not a whisper message, set the name to the fakename of the player
  8705. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8706. strcpy( out_name, sd->fakename );
  8707. }else{
  8708. safestrncpy( out_name, name, nameLength + 1 );
  8709. }
  8710. safestrncpy( out_message, message, messageLength );
  8711. if( whisperFormat ){
  8712. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8713. out_full_message[nameLength] = '\0';
  8714. }else{
  8715. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8716. }
  8717. if( is_atcommand( fd, sd, out_message, 1 ) )
  8718. return false;
  8719. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8720. return false; //no "chatting" while muted.
  8721. if( battle_config.min_chat_delay ) { //[Skotlex]
  8722. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8723. return false;
  8724. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8725. }
  8726. if (battle_config.idletime_option&IDLE_CHAT)
  8727. sd->idletime = last_tick;
  8728. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8729. sd->idletime_hom = last_tick;
  8730. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8731. sd->idletime_mer = last_tick;
  8732. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8733. return true;
  8734. }
  8735. /**
  8736. * Displays a message if the player enters a PK Zone (during pk_mode)
  8737. * @param sd: Player data
  8738. */
  8739. inline void clif_pk_mode_message(struct map_session_data * sd)
  8740. {
  8741. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8742. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8743. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8744. char output[CHAT_SIZE_MAX];
  8745. // 1504: You've entered a PK Zone (safe until level %d).
  8746. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8747. battle_config.pk_min_level);
  8748. clif_showscript(&sd->bl, output, SELF);
  8749. } else {
  8750. // 1503: You've entered a PK Zone.
  8751. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8752. }
  8753. }
  8754. return;
  8755. }
  8756. // ---------------------
  8757. // clif_parse_wanttoconnect
  8758. // ---------------------
  8759. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8760. // error codes:
  8761. // 0 - Success
  8762. // 1 - Unknown packet_ver
  8763. // 2 - Invalid account_id
  8764. // 3 - Invalid char_id
  8765. // 4 - Invalid login_id1 (reserved)
  8766. // 5 - Invalid client_tick (reserved)
  8767. // 6 - Invalid sex
  8768. // Only the first 'invalid' error that appears is used.
  8769. static int clif_parse_WantToConnection_sub(int fd)
  8770. {
  8771. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8772. unsigned short cmd;
  8773. //By default, start searching on the default one.
  8774. cmd = RFIFOW(fd, 0);
  8775. packet_len = RFIFOREST(fd);
  8776. // FIXME: If the packet is not received at once, this will FAIL.
  8777. // Figure out, when it happens, that only part of the packet is
  8778. // received, or fix the function to be able to deal with that
  8779. // case.
  8780. if( packet_len != packet_db[cmd].len )
  8781. return 1; /* wrong length */
  8782. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8783. return 2; /* invalid account_id */
  8784. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8785. return 3; /* invalid char_id */
  8786. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8787. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8788. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8789. return 6; /* invalid sex */
  8790. else
  8791. return 0;
  8792. }
  8793. /// Request to connect to map-server.
  8794. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8795. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8796. /// There are various variants of this packet, some of them have padding between fields.
  8797. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8798. {
  8799. struct block_list* bl;
  8800. struct auth_node* node;
  8801. int cmd, account_id, char_id, login_id1, sex, err;
  8802. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8803. if (sd) {
  8804. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8805. return;
  8806. }
  8807. cmd = RFIFOW(fd, 0);
  8808. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8809. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8810. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8811. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8812. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8813. err = clif_parse_WantToConnection_sub(fd);
  8814. if( err ){ // connection rejected
  8815. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8816. err == 1 ? "." :
  8817. err == 2 ? ", possibly for having an invalid account_id." :
  8818. err == 3 ? ", possibly for having an invalid char_id." :
  8819. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8820. err == 4 ? ", possibly for having an invalid login_id1." :
  8821. err == 5 ? ", possibly for having an invalid client_tick." :
  8822. */
  8823. err == 6 ? ", possibly for having an invalid sex." :
  8824. ". ERROR invalid error code"));
  8825. WFIFOHEAD(fd,packet_len(0x6a));
  8826. WFIFOW(fd,0) = 0x6a;
  8827. WFIFOB(fd,2) = err;
  8828. WFIFOSET(fd,packet_len(0x6a));
  8829. #ifdef DUMP_INVALID_PACKET
  8830. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8831. #endif
  8832. RFIFOSKIP(fd, RFIFOREST(fd));
  8833. set_eof(fd);
  8834. return;
  8835. }
  8836. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8837. clif_authfail_fd(fd,1);// server closed
  8838. return;
  8839. }
  8840. //Check for double login.
  8841. bl = map_id2bl(account_id);
  8842. if(bl && bl->type != BL_PC) {
  8843. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8844. WFIFOHEAD(fd,packet_len(0x6a));
  8845. WFIFOW(fd,0) = 0x6a;
  8846. WFIFOB(fd,2) = 3; // Rejected by server
  8847. WFIFOSET(fd,packet_len(0x6a));
  8848. set_eof(fd);
  8849. return;
  8850. }
  8851. if (bl ||
  8852. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8853. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8854. {
  8855. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8856. return;
  8857. }
  8858. CREATE(sd, TBL_PC, 1);
  8859. sd->fd = fd;
  8860. #ifdef PACKET_OBFUSCATION
  8861. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8862. #endif
  8863. session[fd]->session_data = sd;
  8864. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8865. #if PACKETVER < 20070521
  8866. WFIFOHEAD(fd,4);
  8867. WFIFOL(fd,0) = sd->bl.id;
  8868. WFIFOSET(fd,4);
  8869. #else
  8870. WFIFOHEAD(fd,packet_len(0x283));
  8871. WFIFOW(fd,0) = 0x283;
  8872. WFIFOL(fd,2) = sd->bl.id;
  8873. WFIFOSET(fd,packet_len(0x283));
  8874. #endif
  8875. chrif_authreq(sd,false);
  8876. }
  8877. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8878. /// 007d
  8879. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8880. {
  8881. bool guild_notice = false;
  8882. if(sd->bl.prev != NULL)
  8883. return;
  8884. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8885. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8886. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8887. sd->state.connect_new = 0;
  8888. return;
  8889. }
  8890. if (sd->state.rewarp) { //Rewarp player.
  8891. sd->state.rewarp = 0;
  8892. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8893. return;
  8894. }
  8895. sd->state.warping = 0;
  8896. // look
  8897. #if PACKETVER < 4
  8898. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8899. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8900. #else
  8901. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8902. #endif
  8903. pc_set_costume_view(sd);
  8904. if(sd->vd.cloth_color)
  8905. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8906. if(sd->vd.body_style)
  8907. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8908. // item
  8909. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8910. pc_checkitem(sd);
  8911. clif_equipswitch_list(sd);
  8912. // cart
  8913. if(pc_iscarton(sd)) {
  8914. clif_cartlist(sd);
  8915. clif_updatestatus(sd,SP_CARTINFO);
  8916. }
  8917. // weight
  8918. clif_updatestatus(sd,SP_WEIGHT);
  8919. clif_updatestatus(sd,SP_MAXWEIGHT);
  8920. // guild
  8921. // (needs to go before clif_spawn() to show guild emblems correctly)
  8922. if(sd->status.guild_id)
  8923. guild_send_memberinfoshort(sd,1);
  8924. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8925. if(battle_config.pc_invincible_time > 0) {
  8926. if(mapdata_flag_gvg(mapdata))
  8927. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8928. else
  8929. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8930. }
  8931. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8932. map_spawnmobs(sd->bl.m);
  8933. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8934. mapdata->users_pvp++;
  8935. }
  8936. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8937. // reset the callshop flag if the player changes map
  8938. sd->state.callshop = 0;
  8939. if(map_addblock(&sd->bl))
  8940. return;
  8941. clif_spawn(&sd->bl);
  8942. // Party
  8943. // (needs to go after clif_spawn() to show hp bars correctly)
  8944. if(sd->status.party_id) {
  8945. party_send_movemap(sd);
  8946. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8947. }
  8948. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8949. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8950. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8951. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8952. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8953. sd->pvp_rank = 0;
  8954. sd->pvp_lastusers = 0;
  8955. sd->pvp_point = 5;
  8956. sd->pvp_won = 0;
  8957. sd->pvp_lost = 0;
  8958. }
  8959. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8960. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8961. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8962. else if (mapdata->flag[MF_GVG_DUNGEON])
  8963. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8964. else if( mapdata_flag_gvg(mapdata) )
  8965. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8966. else
  8967. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8968. // info about nearby objects
  8969. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8970. 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);
  8971. // pet
  8972. if( sd->pd ) {
  8973. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8974. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8975. pet_return_egg( sd, sd->pd );
  8976. } else {
  8977. if(map_addblock(&sd->pd->bl))
  8978. return;
  8979. clif_spawn(&sd->pd->bl);
  8980. clif_send_petdata(sd,sd->pd,0,0);
  8981. clif_send_petstatus(sd);
  8982. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8983. }
  8984. }
  8985. //homunculus [blackhole89]
  8986. if( hom_is_active(sd->hd) ) {
  8987. if(map_addblock(&sd->hd->bl))
  8988. return;
  8989. clif_spawn(&sd->hd->bl);
  8990. clif_send_homdata(sd,SP_ACK,0);
  8991. clif_hominfo(sd,sd->hd,1);
  8992. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8993. clif_homskillinfoblock(sd);
  8994. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8995. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8996. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8997. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8998. }
  8999. if( sd->md ) {
  9000. if(map_addblock(&sd->md->bl))
  9001. return;
  9002. clif_spawn(&sd->md->bl);
  9003. clif_mercenary_info(sd);
  9004. clif_mercenary_skillblock(sd);
  9005. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  9006. }
  9007. if( sd->ed ) {
  9008. if (map_addblock(&sd->ed->bl))
  9009. return;
  9010. clif_spawn(&sd->ed->bl);
  9011. clif_elemental_info(sd);
  9012. clif_elemental_updatestatus(sd,SP_HP);
  9013. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9014. clif_elemental_updatestatus(sd,SP_SP);
  9015. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9016. }
  9017. if(sd->state.connect_new) {
  9018. int lv;
  9019. guild_notice = true;
  9020. clif_skillinfoblock(sd);
  9021. clif_hotkeys_send(sd,0);
  9022. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9023. clif_hotkeys_send(sd,1);
  9024. #endif
  9025. clif_updatestatus(sd,SP_BASEEXP);
  9026. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9027. clif_updatestatus(sd,SP_JOBEXP);
  9028. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9029. clif_updatestatus(sd,SP_SKILLPOINT);
  9030. clif_initialstatus(sd);
  9031. if (sd->sc.option&OPTION_FALCON)
  9032. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9033. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9034. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9035. else if (sd->sc.option&OPTION_WUGRIDER)
  9036. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9037. else if (sd->sc.data[SC_ALL_RIDING])
  9038. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9039. if(sd->status.manner < 0)
  9040. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9041. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9042. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9043. if(sd->bl.m == sd->feel_map[0].m
  9044. || sd->bl.m == sd->feel_map[1].m
  9045. || sd->bl.m == sd->feel_map[2].m)
  9046. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9047. }
  9048. if(sd->pd && sd->pd->pet.intimate > 900)
  9049. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9050. if(hom_is_active(sd->hd))
  9051. hom_init_timers(sd->hd);
  9052. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9053. sd->state.night = 1;
  9054. clif_status_load(&sd->bl, EFST_SKE, 1);
  9055. }
  9056. // Notify everyone that this char logged in [Skotlex].
  9057. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9058. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9059. //Login Event
  9060. npc_script_event(sd, NPCE_LOGIN);
  9061. }
  9062. } else {
  9063. //For some reason the client "loses" these on warp/map-change.
  9064. clif_updatestatus(sd,SP_STR);
  9065. clif_updatestatus(sd,SP_AGI);
  9066. clif_updatestatus(sd,SP_VIT);
  9067. clif_updatestatus(sd,SP_INT);
  9068. clif_updatestatus(sd,SP_DEX);
  9069. clif_updatestatus(sd,SP_LUK);
  9070. // abort currently running script
  9071. sd->state.using_fake_npc = 0;
  9072. sd->state.menu_or_input = 0;
  9073. sd->npc_menu = 0;
  9074. if(sd->npc_id)
  9075. npc_event_dequeue(sd);
  9076. }
  9077. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9078. #if PACKETVER >= 20070918
  9079. clif_partyinvitationstate(sd);
  9080. clif_equipcheckbox(sd);
  9081. #endif
  9082. #if PACKETVER >= 20141008
  9083. if( battle_config.pet_autofeed_always ){
  9084. // Always send ON or OFF
  9085. if( sd->pd && battle_config.feature_pet_autofeed ){
  9086. clif_configuration( sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed );
  9087. }else{
  9088. clif_configuration( sd, CONFIG_PET_AUTOFEED, false );
  9089. }
  9090. }else{
  9091. // Only send when enabled
  9092. if( sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed ){
  9093. clif_configuration( sd, CONFIG_PET_AUTOFEED, true );
  9094. }
  9095. }
  9096. #endif
  9097. #if PACKETVER >= 20170920
  9098. if( battle_config.homunculus_autofeed_always ){
  9099. // Always send ON or OFF
  9100. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9101. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9102. }else{
  9103. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9104. }
  9105. }else{
  9106. // Only send when enabled
  9107. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9108. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9109. }
  9110. }
  9111. #endif
  9112. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9113. clif_guild_notice(sd); // Displays after VIP
  9114. guild_notice = false; // Do not display it twice
  9115. }
  9116. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9117. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9118. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9119. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9120. }
  9121. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9122. { //Display night.
  9123. if( !sd->state.night )
  9124. {
  9125. sd->state.night = 1;
  9126. clif_status_load(&sd->bl, EFST_SKE, 1);
  9127. }
  9128. }
  9129. else if( sd->state.night )
  9130. { //Clear night display.
  9131. sd->state.night = 0;
  9132. clif_status_load(&sd->bl, EFST_SKE, 0);
  9133. }
  9134. if( mapdata->flag[MF_BATTLEGROUND] )
  9135. {
  9136. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9137. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9138. clif_bg_updatescore_single(sd);
  9139. }
  9140. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9141. {
  9142. char output[128];
  9143. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9144. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9145. }
  9146. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9147. mapdata->hpmeter_visible++;
  9148. sd->state.hpmeter_visible = 1;
  9149. }
  9150. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9151. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9152. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9153. #ifdef VIP_ENABLE
  9154. if (!sd->state.connect_new &&
  9155. !sd->vip.disableshowrate &&
  9156. sd->state.pmap != sd->bl.m &&
  9157. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9158. )
  9159. {
  9160. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9161. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9162. }
  9163. #endif
  9164. // Instances do not need their own channels
  9165. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9166. channel_mjoin(sd); //join new map
  9167. clif_pk_mode_message(sd);
  9168. }
  9169. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9170. clif_guild_notice(sd); // Displays at end
  9171. }
  9172. mail_clear(sd);
  9173. /* Guild Aura Init */
  9174. if( sd->guild && sd->state.gmaster_flag ) {
  9175. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9176. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9177. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9178. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9179. }
  9180. if( sd->state.vending ) { /* show we have a vending */
  9181. clif_openvending(sd,sd->bl.id,sd->vending);
  9182. clif_showvendingboard(&sd->bl,sd->message,0);
  9183. }
  9184. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9185. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9186. npc_script_event(sd, NPCE_LOADMAP);
  9187. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9188. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9189. if (sd->sc.opt2) //Client loses these on warp.
  9190. clif_changeoption(&sd->bl);
  9191. 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)) {
  9192. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9193. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9194. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9195. }
  9196. clif_weather_check(sd);
  9197. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9198. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9199. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9200. else
  9201. sd->areanpc.clear();
  9202. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9203. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9204. pc_setdead(sd);
  9205. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9206. if(pc_isdead(sd))
  9207. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9208. else {
  9209. skill_usave_trigger(sd);
  9210. if (battle_config.spawn_direction)
  9211. clif_changed_dir(&sd->bl, SELF);
  9212. }
  9213. // Trigger skill effects if you appear standing on them
  9214. if(!battle_config.pc_invincible_time)
  9215. skill_unit_move(&sd->bl,gettick(),1);
  9216. pc_show_questinfo_reinit(sd);
  9217. pc_show_questinfo(sd);
  9218. #if PACKETVER >= 20150513
  9219. if( sd->mail.inbox.unread ){
  9220. clif_Mail_new(sd, 0, NULL, NULL);
  9221. }
  9222. #endif
  9223. sd->state.connect_new = 0;
  9224. sd->state.changemap = false;
  9225. }
  9226. /// Server's tick (ZC_NOTIFY_TIME).
  9227. /// 007f <time>.L
  9228. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9229. {
  9230. int fd = sd->fd;
  9231. WFIFOHEAD(fd,packet_len(0x7f));
  9232. WFIFOW(fd,0) = 0x7f;
  9233. WFIFOL(fd,2) = client_tick(time);
  9234. WFIFOSET(fd,packet_len(0x7f));
  9235. }
  9236. /// Request for server's tick.
  9237. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9238. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9239. /// There are various variants of this packet, some of them have padding between fields.
  9240. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9241. {
  9242. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9243. clif_notify_time(sd, gettick());
  9244. }
  9245. /// Sends hotkey bar.
  9246. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9247. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9248. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9249. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9250. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9251. #ifdef HOTKEY_SAVING
  9252. nullpo_retv( sd );
  9253. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9254. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9255. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9256. if( tab == 0 ){
  9257. p.rotate = sd->status.hotkey_rowshift;
  9258. }else{
  9259. p.rotate = sd->status.hotkey_rowshift2;
  9260. }
  9261. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9262. p.tab = tab;
  9263. #endif
  9264. #endif
  9265. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9266. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9267. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9268. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9269. }
  9270. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9271. #endif
  9272. }
  9273. /// Request to update a position on the hotkey row bar
  9274. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9275. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9276. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9277. if( p->tab == 0 ){
  9278. sd->status.hotkey_rowshift = p->rowshift;
  9279. }else{
  9280. sd->status.hotkey_rowshift2 = p->rowshift;
  9281. }
  9282. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9283. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9284. sd->status.hotkey_rowshift = p->rowshift;
  9285. #endif
  9286. }
  9287. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9288. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9289. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9290. #ifdef HOTKEY_SAVING
  9291. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9292. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9293. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9294. if( idx >= MAX_HOTKEYS_DB ){
  9295. return;
  9296. }
  9297. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9298. sd->status.hotkeys[idx].id = p->hotkey.id;
  9299. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9300. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9301. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9302. const unsigned short idx = p->index;
  9303. if( idx >= MAX_HOTKEYS_DB ){
  9304. return;
  9305. }
  9306. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9307. sd->status.hotkeys[idx].id = p->hotkey.id;
  9308. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9309. #endif
  9310. #endif
  9311. }
  9312. /// Displays cast-like progress bar (ZC_PROGRESS).
  9313. /// 02f0 <color>.L <time>.L
  9314. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9315. {
  9316. int fd = sd->fd;
  9317. WFIFOHEAD(fd,packet_len(0x2f0));
  9318. WFIFOW(fd,0) = 0x2f0;
  9319. WFIFOL(fd,2) = color;
  9320. WFIFOL(fd,6) = second;
  9321. WFIFOSET(fd,packet_len(0x2f0));
  9322. }
  9323. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9324. /// 02f2
  9325. void clif_progressbar_abort(struct map_session_data * sd)
  9326. {
  9327. int fd = sd->fd;
  9328. WFIFOHEAD(fd,packet_len(0x2f2));
  9329. WFIFOW(fd,0) = 0x2f2;
  9330. WFIFOSET(fd,packet_len(0x2f2));
  9331. }
  9332. /// Notification from the client, that the progress bar has reached 100%.
  9333. /// 02f1 (CZ_PROGRESS)
  9334. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9335. // No progressbar active, ignore it
  9336. if( !sd->progressbar.npc_id ){
  9337. return;
  9338. }
  9339. int npc_id = sd->progressbar.npc_id;
  9340. bool closing = false;
  9341. // Check if the progress was canceled
  9342. if( gettick() < sd->progressbar.timeout && sd->st ){
  9343. closing = true;
  9344. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9345. // If a message window was open, offer a close button to the user
  9346. if( sd->st->mes_active ){
  9347. clif_scriptclose( sd, npc_id );
  9348. }
  9349. }
  9350. sd->progressbar.npc_id = 0;
  9351. sd->progressbar.timeout = 0;
  9352. sd->state.workinprogress = WIP_DISABLE_NONE;
  9353. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9354. sd->idletime = last_tick;
  9355. }
  9356. npc_scriptcont(sd, npc_id, closing);
  9357. }
  9358. /// Displays cast-like progress bar on a NPC
  9359. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9360. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9361. #if PACKETVER >= 20130821
  9362. unsigned char buf[14];
  9363. if( nd->progressbar.timeout > 0 ){
  9364. WBUFW(buf,0) = 0x9d1;
  9365. WBUFL(buf,2) = nd->bl.id;
  9366. WBUFL(buf,6) = nd->progressbar.color;
  9367. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9368. if( sd ){
  9369. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9370. }else{
  9371. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9372. }
  9373. }
  9374. #endif
  9375. }
  9376. /// Request to walk to a certain position on the current map.
  9377. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9378. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9379. /// There are various variants of this packet, some of them have padding between fields.
  9380. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9381. {
  9382. short x, y;
  9383. if (pc_isdead(sd)) {
  9384. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9385. return;
  9386. }
  9387. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9388. ; //You CAN walk on this OPT1 value.
  9389. else if (sd->progressbar.npc_id) {
  9390. clif_progressbar_abort(sd);
  9391. return; // First walk attempt cancels the progress bar
  9392. } else if (pc_cant_act(sd))
  9393. return;
  9394. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9395. return;
  9396. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9397. //A move command one cell west is only valid if the target cell is free
  9398. if(battle_config.official_cell_stack_limit > 0
  9399. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9400. return;
  9401. // Cloaking wall check is actually updated when you click to process next movement
  9402. // not when you move each cell. This is official behaviour.
  9403. if (sd->sc.data[SC_CLOAKING])
  9404. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9405. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9406. pc_delinvincibletimer(sd);
  9407. //Set last idle time... [Skotlex]
  9408. if (battle_config.idletime_option&IDLE_WALK)
  9409. sd->idletime = last_tick;
  9410. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9411. sd->idletime_hom = last_tick;
  9412. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9413. sd->idletime_mer = last_tick;
  9414. unit_walktoxy(&sd->bl, x, y, 4);
  9415. }
  9416. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9417. /// 018b <result>.W
  9418. /// result:
  9419. /// 0 = disconnect (quit)
  9420. /// 1 = cannot disconnect (wait 10 seconds)
  9421. /// ? = ignored
  9422. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9423. {
  9424. int fd = sd->fd;
  9425. WFIFOHEAD(fd,packet_len(0x18b));
  9426. WFIFOW(fd,0) = 0x18b;
  9427. WFIFOW(fd,2) = result;
  9428. WFIFOSET(fd,packet_len(0x18b));
  9429. }
  9430. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9431. /// 018a <type>.W
  9432. /// type:
  9433. /// 0 = quit
  9434. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9435. {
  9436. /* Rovert's prevent logout option fixed [Valaris] */
  9437. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9438. 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] &&
  9439. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9440. {
  9441. pc_damage_log_clear(sd,0);
  9442. clif_disconnect_ack(sd, 0);
  9443. flush_fifo( fd );
  9444. if( battle_config.drop_connection_on_quit ){
  9445. set_eof( fd );
  9446. }
  9447. } else {
  9448. clif_disconnect_ack(sd, 1);
  9449. }
  9450. }
  9451. /// Requesting unit's name.
  9452. /// 0094 <id>.L (CZ_REQNAME)
  9453. /// 0368 <id>.L (CZ_REQNAME2)
  9454. /// There are various variants of this packet, some of them have padding between fields.
  9455. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9456. {
  9457. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9458. struct block_list* bl;
  9459. //struct status_change *sc;
  9460. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9461. id = sd->bl.id;
  9462. bl = map_id2bl(id);
  9463. if( bl == NULL )
  9464. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9465. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9466. return; // Block namerequests past view range
  9467. // 'see people in GM hide' cheat detection
  9468. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9469. sc = status_get_sc(bl);
  9470. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9471. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9472. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9473. ) {
  9474. char gm_msg[256];
  9475. 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);
  9476. ShowWarning(gm_msg);
  9477. // information is sent to all online GMs
  9478. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9479. return;
  9480. }
  9481. */
  9482. clif_name(&sd->bl,bl,SELF);
  9483. }
  9484. /// Validates and processes global messages
  9485. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9486. /// There are various variants of this packet.
  9487. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9488. {
  9489. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9490. size_t length;
  9491. // validate packet and retrieve name and message
  9492. if( !clif_process_message(sd, false, name, message, output ) )
  9493. return;
  9494. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9495. channel_send(sd->gcbind,sd,message);
  9496. return;
  9497. }
  9498. // send message to others (using the send buffer for temp. storage)
  9499. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9500. length = strlen(output) + 1;
  9501. // send back message to the speaker
  9502. WFIFOHEAD(fd,4+length);
  9503. WFIFOW(fd,0) = 0x8e;
  9504. WFIFOW(fd,2) = (uint16)(4+length);
  9505. safestrncpy(WFIFOCP(fd,4), output, length );
  9506. WFIFOSET(fd, WFIFOW(fd,2));
  9507. #ifdef PCRE_SUPPORT
  9508. // trigger listening npcs
  9509. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9510. #endif
  9511. // Chat logging type 'O' / Global Chat
  9512. 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);
  9513. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9514. }
  9515. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9516. /// Request to warp to a map on given coordinates.
  9517. /// 0140 <map name>.16B <x>.W <y>.W
  9518. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9519. {
  9520. char command[MAP_NAME_LENGTH_EXT+25];
  9521. char* map_name;
  9522. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9523. map_name = RFIFOCP(fd,info->pos[0]);
  9524. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9525. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9526. RFIFOW(fd,info->pos[1]), //x
  9527. RFIFOW(fd,info->pos[2])); //y
  9528. is_atcommand(fd, sd, command, 1);
  9529. }
  9530. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9531. /// 009c <id>.L <head dir>.W <dir>.B
  9532. /// head dir:
  9533. /// 0 = straight
  9534. /// 1 = turned CW
  9535. /// 2 = turned CCW
  9536. /// dir:
  9537. /// 0 = north
  9538. /// 1 = northwest
  9539. /// 2 = west
  9540. /// 3 = southwest
  9541. /// 4 = south
  9542. /// 5 = southeast
  9543. /// 6 = east
  9544. /// 7 = northeast
  9545. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9546. {
  9547. unsigned char buf[64];
  9548. WBUFW(buf,0) = 0x9c;
  9549. WBUFL(buf,2) = bl->id;
  9550. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9551. WBUFB(buf,8) = unit_getdir(bl);
  9552. clif_send(buf, packet_len(0x9c), bl, target);
  9553. if (disguised(bl)) {
  9554. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9555. WBUFW(buf,6) = 0;
  9556. clif_send(buf, packet_len(0x9c), bl, SELF);
  9557. }
  9558. }
  9559. /// Request to change own body and head direction.
  9560. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9561. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9562. /// There are various variants of this packet, some of them have padding between fields.
  9563. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9564. {
  9565. unsigned char headdir, dir;
  9566. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9567. headdir = RFIFOB(fd,info->pos[0]);
  9568. dir = RFIFOB(fd,info->pos[1]);
  9569. pc_setdir(sd, dir, headdir);
  9570. clif_changed_dir(&sd->bl, AREA_WOS);
  9571. }
  9572. /// Request to show an emotion (CZ_REQ_EMOTION).
  9573. /// 00bf <type>.B
  9574. /// type:
  9575. /// @see enum emotion_type
  9576. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9577. {
  9578. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9579. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9580. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9581. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9582. return;
  9583. }
  9584. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9585. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9586. sd->emotionlasttime = time(NULL);
  9587. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9588. return;
  9589. }
  9590. sd->emotionlasttime = time(NULL);
  9591. if (battle_config.idletime_option&IDLE_EMOTION)
  9592. sd->idletime = last_tick;
  9593. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9594. sd->idletime_hom = last_tick;
  9595. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9596. sd->idletime_mer = last_tick;
  9597. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9598. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9599. return;
  9600. }
  9601. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9602. emoticon = rnd()%6+ET_DICE1;
  9603. }
  9604. clif_emotion(&sd->bl, emoticon);
  9605. } else
  9606. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9607. }
  9608. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9609. /// 00c2 <count>.L
  9610. void clif_user_count(struct map_session_data* sd, int count)
  9611. {
  9612. int fd = sd->fd;
  9613. WFIFOHEAD(fd,packet_len(0xc2));
  9614. WFIFOW(fd,0) = 0xc2;
  9615. WFIFOL(fd,2) = count;
  9616. WFIFOSET(fd,packet_len(0xc2));
  9617. }
  9618. /// /w /who (CZ_REQ_USER_COUNT).
  9619. /// Request to display amount of currently connected players.
  9620. /// 00c1
  9621. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9622. {
  9623. clif_user_count(sd, map_getusers());
  9624. }
  9625. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9626. {
  9627. if (pc_isdead(sd)) {
  9628. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9629. return;
  9630. }
  9631. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9632. // (not all are included in pc_can_attack)
  9633. if (sd->sc.count &&
  9634. (sd->sc.data[SC_TRICKDEAD] ||
  9635. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9636. sd->sc.data[SC_BLADESTOP] ||
  9637. sd->sc.data[SC__MANHOLE] ||
  9638. sd->sc.data[SC_SUHIDE] ||
  9639. sd->sc.data[SC_GRAVITYCONTROL]))
  9640. return;
  9641. if(action_type != 0x00 && action_type != 0x07)
  9642. pc_stop_walking(sd, 1);
  9643. pc_stop_attack(sd);
  9644. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9645. target_id = sd->bl.id;
  9646. switch(action_type)
  9647. {
  9648. case 0x00: // once attack
  9649. case 0x07: // continuous attack
  9650. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9651. return;
  9652. if( sd->sc.option&OPTION_COSTUME )
  9653. return;
  9654. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9655. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9656. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9657. return;
  9658. }
  9659. }
  9660. pc_delinvincibletimer(sd);
  9661. if (battle_config.idletime_option&IDLE_ATTACK)
  9662. sd->idletime = last_tick;
  9663. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9664. sd->idletime_hom = last_tick;
  9665. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9666. sd->idletime_mer = last_tick;
  9667. unit_attack(&sd->bl, target_id, action_type != 0);
  9668. break;
  9669. case 0x02: // sitdown
  9670. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9671. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9672. break;
  9673. }
  9674. if(pc_issit(sd)) {
  9675. //Bugged client? Just refresh them.
  9676. clif_sitting(&sd->bl);
  9677. return;
  9678. }
  9679. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9680. break;
  9681. if (sd->sc.count && (
  9682. sd->sc.data[SC_DANCING] ||
  9683. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9684. )) //No sitting during these states either.
  9685. break;
  9686. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9687. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9688. break;
  9689. }
  9690. if (battle_config.idletime_option&IDLE_SIT)
  9691. sd->idletime = last_tick;
  9692. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9693. sd->idletime_hom = last_tick;
  9694. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9695. sd->idletime_mer = last_tick;
  9696. pc_setsit(sd);
  9697. skill_sit(sd, true);
  9698. clif_sitting(&sd->bl);
  9699. break;
  9700. case 0x03: // standup
  9701. if (!pc_issit(sd)) {
  9702. //Bugged client? Just refresh them.
  9703. clif_standing(&sd->bl);
  9704. return;
  9705. }
  9706. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9707. break;
  9708. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9709. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9710. break;
  9711. }
  9712. if (pc_setstand(sd, false)) {
  9713. if (battle_config.idletime_option&IDLE_SIT)
  9714. sd->idletime = last_tick;
  9715. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9716. sd->idletime_hom = last_tick;
  9717. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9718. sd->idletime_mer = last_tick;
  9719. skill_sit(sd, false);
  9720. clif_standing(&sd->bl);
  9721. }
  9722. break;
  9723. }
  9724. }
  9725. /// Request for an action.
  9726. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9727. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9728. /// action:
  9729. /// 0 = attack
  9730. /// 1 = pick up item
  9731. /// 2 = sit down
  9732. /// 3 = stand up
  9733. /// 7 = continous attack
  9734. /// 12 = (touch skill?)
  9735. /// There are various variants of this packet, some of them have padding between fields.
  9736. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9737. {
  9738. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9739. clif_parse_ActionRequest_sub(sd,
  9740. RFIFOB(fd,info->pos[1]),
  9741. RFIFOL(fd,info->pos[0]),
  9742. gettick()
  9743. );
  9744. }
  9745. /// Response to the death/system menu (CZ_RESTART).
  9746. /// 00b2 <type>.B
  9747. /// type:
  9748. /// 0 = restart (respawn)
  9749. /// 1 = char-select (disconnect)
  9750. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9751. {
  9752. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9753. case 0x00:
  9754. pc_respawn(sd,CLR_OUTSIGHT);
  9755. break;
  9756. case 0x01:
  9757. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9758. 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] &&
  9759. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9760. { //Send to char-server for character selection.
  9761. pc_damage_log_clear(sd,0);
  9762. chrif_charselectreq(sd, session[fd]->client_addr);
  9763. } else {
  9764. clif_disconnect_ack(sd, 1);
  9765. }
  9766. break;
  9767. }
  9768. }
  9769. /// Validates and processes whispered messages (CZ_WHISPER).
  9770. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9771. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9772. {
  9773. struct map_session_data* dstsd;
  9774. int i;
  9775. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9776. // validate packet and retrieve name and message
  9777. if( !clif_process_message( sd, true, target, message, output ) )
  9778. return;
  9779. // Chat logging type 'W' / Whisper
  9780. 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);
  9781. //-------------------------------------------------------//
  9782. // Lordalfa - Paperboy - To whisper NPC commands //
  9783. //-------------------------------------------------------//
  9784. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9785. {
  9786. char* str = target+4; //Skip the NPC: string part.
  9787. struct npc_data* npc;
  9788. if ((npc = npc_name2id(str))) {
  9789. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9790. char *split;
  9791. char event[EVENT_NAME_LENGTH];
  9792. str = message;
  9793. // skip codepage indicator, if detected
  9794. if( str[0] == '|' && strlen(str) >= 4 )
  9795. str += 3;
  9796. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9797. split = strchr(str,'#');
  9798. if( split == NULL ) { // use the remaining string
  9799. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9800. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9801. split_data[i][0] = '\0';
  9802. break;
  9803. }
  9804. *split = '\0';
  9805. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9806. str = split+1;
  9807. }
  9808. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9809. char variablename[CHAT_SIZE_MAX];
  9810. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9811. set_var_str( sd, variablename, split_data[i] );
  9812. }
  9813. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9814. npc_event(sd,event,0); // Calls the NPC label
  9815. return;
  9816. }
  9817. } else if( target[0] == '#' ) {
  9818. struct Channel *channel = NULL;
  9819. char* chname = target;
  9820. channel = channel_name2channel(chname,sd,3);
  9821. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9822. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9823. channel_send(channel,sd,message);
  9824. }
  9825. else if( channel->pass[0] == '\0') { //no pass needed
  9826. if (channel_join(channel,sd)==0)
  9827. channel_send(channel,sd,message); //join success
  9828. }
  9829. else {
  9830. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9831. }
  9832. return;
  9833. }
  9834. }
  9835. // searching destination character
  9836. dstsd = map_nick2sd(target,false);
  9837. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9838. // player is not on this map-server
  9839. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9840. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9841. // and if we ask for 'Test', we must not contact 'test' player
  9842. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9843. intif_wis_message(sd, target, message, strlen(message) + 1);
  9844. return;
  9845. }
  9846. // if player ignores everyone
  9847. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9848. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9849. clif_wis_end(fd, 1); // 1: target character is not logged in
  9850. else
  9851. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9852. return;
  9853. }
  9854. // if player is autotrading
  9855. if (dstsd->state.autotrade == 1){
  9856. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9857. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9858. return;
  9859. }
  9860. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9861. // if player ignores the source character
  9862. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9863. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9864. clif_wis_end(fd, 2); // 2: ignored by target
  9865. return;
  9866. }
  9867. }
  9868. // notify sender of success
  9869. clif_wis_end(fd, 0); // 0: success to send wisper
  9870. // Normal message
  9871. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9872. }
  9873. /// /b /nb (CZ_BROADCAST).
  9874. /// Request to broadcast a message on whole server.
  9875. /// 0099 <packet len>.W <text>.?B 00
  9876. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9877. char command[CHAT_SIZE_MAX+11];
  9878. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9879. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9880. char* msg = RFIFOCP(fd,info->pos[1]);
  9881. // as the length varies depending on the command used, just block unreasonably long strings
  9882. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9883. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9884. is_atcommand(fd, sd, command, 1);
  9885. }
  9886. /// Request to pick up an item.
  9887. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9888. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9889. /// There are various variants of this packet, some of them have padding between fields.
  9890. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9891. {
  9892. struct flooritem_data *fitem;
  9893. int map_object_id;
  9894. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9895. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9896. do {
  9897. if (pc_isdead(sd)) {
  9898. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9899. break;
  9900. }
  9901. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9902. break;
  9903. if (pc_cant_act(sd))
  9904. break;
  9905. if (!pc_takeitem(sd, fitem))
  9906. break;
  9907. return;
  9908. } while (0);
  9909. // Client REQUIRES a fail packet or you can no longer pick items.
  9910. clif_additem(sd,0,0,6);
  9911. }
  9912. /// Request to drop an item.
  9913. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9914. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9915. /// There are various variants of this packet, some of them have padding between fields.
  9916. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9917. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9918. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9919. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9920. for(;;) {
  9921. if (pc_isdead(sd))
  9922. break;
  9923. if (pc_cant_act2(sd) || sd->npc_id)
  9924. break;
  9925. if (sd->sc.count && (
  9926. sd->sc.data[SC_AUTOCOUNTER] ||
  9927. sd->sc.data[SC_BLADESTOP] ||
  9928. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9929. ))
  9930. break;
  9931. if (!pc_dropitem(sd, item_index, item_amount))
  9932. break;
  9933. if (battle_config.idletime_option&IDLE_DROPITEM)
  9934. sd->idletime = last_tick;
  9935. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  9936. sd->idletime_hom = last_tick;
  9937. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  9938. sd->idletime_mer = last_tick;
  9939. return;
  9940. }
  9941. //Because the client does not like being ignored.
  9942. clif_dropitem(sd, item_index,0);
  9943. }
  9944. /// Request to use an item.
  9945. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9946. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9947. /// There are various variants of this packet, some of them have padding between fields.
  9948. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9949. {
  9950. int n;
  9951. if (pc_isdead(sd)) {
  9952. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9953. return;
  9954. }
  9955. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || sd->state.lapine_ui || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9956. clif_msg(sd, WORK_IN_PROGRESS);
  9957. return;
  9958. }
  9959. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9960. if (battle_config.idletime_option&IDLE_USEITEM)
  9961. sd->idletime = last_tick;
  9962. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9963. sd->idletime_hom = last_tick;
  9964. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  9965. sd->idletime_mer = last_tick;
  9966. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9967. if(n <0 || n >= MAX_INVENTORY)
  9968. return;
  9969. if (!pc_useitem(sd,n))
  9970. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9971. }
  9972. /// Request to equip an item
  9973. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9974. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9975. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9976. {
  9977. int index;
  9978. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9979. if(pc_isdead(sd)) {
  9980. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9981. return;
  9982. }
  9983. index = RFIFOW(fd,info->pos[0])-2;
  9984. if (index < 0 || index >= MAX_INVENTORY)
  9985. return; //Out of bounds check.
  9986. if(sd->npc_id && !sd->npc_item_flag) {
  9987. return;
  9988. } else if (sd->state.storage_flag || sd->sc.opt1)
  9989. ; //You can equip/unequip stuff while storage is open/under status changes
  9990. else if (pc_cant_act2(sd))
  9991. return;
  9992. if(!sd->inventory.u.items_inventory[index].identify) {
  9993. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9994. return;
  9995. }
  9996. if(!sd->inventory_data[index])
  9997. return;
  9998. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9999. pet_equipitem(sd,index);
  10000. return;
  10001. }
  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. //Client doesn't send the position for ammo.
  10009. if(sd->inventory_data[index]->type == IT_AMMO)
  10010. pc_equipitem(sd,index,EQP_AMMO);
  10011. else {
  10012. int req_pos;
  10013. #if PACKETVER >= 20120925
  10014. req_pos = RFIFOL(fd,info->pos[1]);
  10015. #else
  10016. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10017. #endif
  10018. pc_equipitem(sd,index,req_pos);
  10019. }
  10020. }
  10021. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10022. /// 00ab <index>.W
  10023. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10024. {
  10025. int index;
  10026. if(pc_isdead(sd)) {
  10027. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10028. return;
  10029. }
  10030. if (sd->npc_id && !sd->npc_item_flag) {
  10031. return;
  10032. } else if (sd->state.storage_flag || sd->sc.opt1)
  10033. ; //You can equip/unequip stuff while storage is open/under status changes
  10034. else if (pc_cant_act2(sd))
  10035. return;
  10036. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10037. if (battle_config.idletime_option&IDLE_USEITEM)
  10038. sd->idletime = last_tick;
  10039. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10040. sd->idletime_hom = last_tick;
  10041. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10042. sd->idletime_mer = last_tick;
  10043. pc_unequipitem(sd,index,1);
  10044. }
  10045. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10046. /// 0090 <id>.L <type>.B
  10047. /// type:
  10048. /// 1 = click
  10049. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10050. {
  10051. struct block_list *bl;
  10052. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10053. if(pc_isdead(sd)) {
  10054. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10055. return;
  10056. }
  10057. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10058. #ifdef RENEWAL
  10059. clif_msg( sd, WORK_IN_PROGRESS );
  10060. #endif
  10061. return;
  10062. }
  10063. if( sd->state.mail_writing )
  10064. return;
  10065. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10066. //type = RFIFOB(fd,info->pos[1]);
  10067. if (!bl) return;
  10068. switch (bl->type) {
  10069. case BL_MOB:
  10070. case BL_PC:
  10071. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10072. break;
  10073. case BL_NPC:
  10074. #ifdef RENEWAL
  10075. 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
  10076. clif_msg(sd, WORK_IN_PROGRESS);
  10077. break;
  10078. }
  10079. #endif
  10080. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10081. struct npc_data* nd = (struct npc_data*)bl;
  10082. // Progressbar is running
  10083. if( nd->progressbar.timeout > 0 ){
  10084. return;
  10085. }
  10086. npc_click(sd,nd);
  10087. }
  10088. break;
  10089. }
  10090. }
  10091. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10092. /// 00c5 <id>.L <type>.B
  10093. /// type:
  10094. /// 0 = buy
  10095. /// 1 = sell
  10096. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10097. {
  10098. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10099. if (sd->state.trading)
  10100. return;
  10101. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10102. }
  10103. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10104. /// 00ca <result>.B
  10105. /// result:
  10106. /// 0 = "The deal has successfully completed."
  10107. /// 1 = "You do not have enough zeny."
  10108. /// 2 = "You are over your Weight Limit."
  10109. /// 3 = "Out of the maximum capacity, you have too many items."
  10110. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10111. /// 10 = "Props open-air store sales will be traded in RODEX"
  10112. /// 11 = "The exchange failed."
  10113. /// 12 = "The exchange was well done."
  10114. /// 13 = "The item is already sold and out of stock."
  10115. /// 14 = "There is not enough goods to exchange."
  10116. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10117. {
  10118. int fd = sd->fd;
  10119. WFIFOHEAD(fd,packet_len(0xca));
  10120. WFIFOW(fd,0) = 0xca;
  10121. WFIFOB(fd,2) = result;
  10122. WFIFOSET(fd,packet_len(0xca));
  10123. }
  10124. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10125. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10126. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10127. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10128. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10129. int result;
  10130. if( sd->state.trading || !sd->npc_shopid )
  10131. result = 1;
  10132. else
  10133. result = npc_buylist( sd, n, (struct s_npc_buy_list*)p->items );
  10134. sd->npc_shopid = 0; //Clear shop data.
  10135. clif_npc_buy_result(sd, result);
  10136. }
  10137. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10138. /// 00cb <result>.B
  10139. /// result:
  10140. /// 0 = "The deal has successfully completed."
  10141. /// 1 = "The deal has failed."
  10142. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10143. {
  10144. int fd = sd->fd;
  10145. WFIFOHEAD(fd,packet_len(0xcb));
  10146. WFIFOW(fd,0) = 0xcb;
  10147. WFIFOB(fd,2) = result;
  10148. WFIFOSET(fd,packet_len(0xcb));
  10149. }
  10150. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10151. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10152. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10153. {
  10154. int fail=0,n;
  10155. unsigned short *item_list;
  10156. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10157. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10158. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10159. if (sd->state.trading || !sd->npc_shopid)
  10160. fail = 1;
  10161. else
  10162. fail = npc_selllist(sd,n,item_list);
  10163. sd->npc_shopid = 0; //Clear shop data.
  10164. clif_npc_sell_result(sd, fail);
  10165. }
  10166. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10167. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10168. /// type:
  10169. /// 0 = private
  10170. /// 1 = public
  10171. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10172. {
  10173. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10174. int len = RFIFOW(fd,info->pos[0])-15;
  10175. int limit = RFIFOW(fd,info->pos[1]);
  10176. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10177. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10178. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10179. char s_password[CHATROOM_PASS_SIZE];
  10180. char s_title[CHATROOM_TITLE_SIZE];
  10181. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10182. return;
  10183. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10184. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10185. return;
  10186. }
  10187. if( npc_isnear(&sd->bl) ) {
  10188. // uncomment to send msg_txt.
  10189. //char output[150];
  10190. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10191. //clif_displaymessage(sd->fd, output);
  10192. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10193. return;
  10194. }
  10195. if( len <= 0 )
  10196. return; // invalid input
  10197. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10198. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10199. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10200. }
  10201. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10202. /// 00d9 <chat ID>.L <passwd>.8B
  10203. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10204. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10205. int chatid = RFIFOL(fd,info->pos[0]);
  10206. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10207. chat_joinchat(sd,chatid,password);
  10208. }
  10209. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10210. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10211. /// type:
  10212. /// 0 = private
  10213. /// 1 = public
  10214. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  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( len <= 0 )
  10224. return; // invalid input
  10225. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10226. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10227. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10228. }
  10229. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10230. /// 00e0 <role>.L <nick>.24B
  10231. /// role:
  10232. /// 0 = owner
  10233. /// 1 = normal
  10234. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10235. {
  10236. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10237. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10238. }
  10239. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10240. /// 00e2 <name>.24B
  10241. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10242. {
  10243. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10244. }
  10245. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10246. /// 00e3
  10247. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10248. {
  10249. chat_leavechat(sd,0);
  10250. }
  10251. //Handles notifying asker and rejecter of what has just ocurred.
  10252. //Type is used to determine the correct msg_txt to use:
  10253. //0:
  10254. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10255. {
  10256. const char* msg;
  10257. char output[256];
  10258. // Your request has been rejected by autoreject option.
  10259. msg = msg_txt(sd,392);
  10260. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10261. //Notice that a request was rejected.
  10262. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10263. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10264. }
  10265. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10266. /// 00e4 <account id>.L
  10267. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10268. {
  10269. struct map_session_data *t_sd;
  10270. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10271. if(!sd->chatID && pc_cant_act(sd))
  10272. return; //You can trade while in a chatroom.
  10273. if(t_sd){
  10274. // @noask [LuzZza]
  10275. if(t_sd->state.noask) {
  10276. clif_noask_sub(sd, t_sd, 0);
  10277. return;
  10278. }
  10279. if (t_sd->state.mail_writing) {
  10280. int old = sd->trade_partner;
  10281. // Fake trading
  10282. sd->trade_partner = t_sd->status.account_id;
  10283. clif_tradestart(sd, 5);
  10284. // Restore old state
  10285. sd->trade_partner = old;
  10286. return;
  10287. }
  10288. }
  10289. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10290. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10291. return;
  10292. }
  10293. trade_traderequest(sd,t_sd);
  10294. }
  10295. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10296. /// 00e6 <result>.B
  10297. /// result:
  10298. /// 3 = accepted
  10299. /// 4 = rejected
  10300. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10301. {
  10302. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10303. }
  10304. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10305. /// 00e8 <index>.W <amount>.L
  10306. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10307. {
  10308. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10309. short index = RFIFOW(fd,info->pos[0]);
  10310. int amount = RFIFOL(fd,info->pos[1]);
  10311. if( index == 0 )
  10312. trade_tradeaddzeny(sd, amount);
  10313. else
  10314. trade_tradeadditem(sd, index, (short)amount);
  10315. }
  10316. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10317. /// 00eb
  10318. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10319. {
  10320. trade_tradeok(sd);
  10321. }
  10322. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10323. /// 00ed
  10324. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10325. {
  10326. trade_tradecancel(sd);
  10327. }
  10328. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10329. /// 00ef
  10330. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10331. {
  10332. trade_tradecommit(sd);
  10333. }
  10334. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10335. /// 0118
  10336. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10337. {
  10338. pc_stop_attack(sd);
  10339. if (sd) sd->ud.state.attack_continue = 0;
  10340. }
  10341. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10342. /// 0126 <index>.W <amount>.L
  10343. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10344. {
  10345. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10346. if (pc_istrading(sd))
  10347. return;
  10348. if (!pc_iscarton(sd))
  10349. return;
  10350. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10351. }
  10352. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10353. /// 0127 <index>.W <amount>.L
  10354. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10355. {
  10356. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10357. if (!pc_iscarton(sd))
  10358. return;
  10359. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10360. }
  10361. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10362. /// 012a
  10363. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10364. {
  10365. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10366. #ifdef NEW_CARTS
  10367. && sd->sc.data[SC_PUSH_CART] )
  10368. pc_setcart(sd,0);
  10369. #else
  10370. )
  10371. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10372. #endif
  10373. else // priority to remove this option before we can clear cart
  10374. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10375. }
  10376. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10377. /// 097f <Length>.W <identity>.L <type>.B
  10378. void clif_SelectCart(struct map_session_data *sd) {
  10379. #if PACKETVER >= 20150826
  10380. int i = 0, carts = 3;
  10381. int fd = sd->fd;
  10382. WFIFOHEAD(fd,8 + carts);
  10383. WFIFOW(fd,0) = 0x97f;
  10384. WFIFOW(fd,2) = 8 + carts;
  10385. WFIFOL(fd,4) = sd->status.account_id;
  10386. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10387. for( i = 0; i < carts; i++ ) {
  10388. WFIFOB(fd,8 + i) = 10 + i;
  10389. }
  10390. WFIFOSET(fd,8 + carts);
  10391. #endif
  10392. }
  10393. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10394. /// 0980 <identity>.L <type>.B
  10395. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10396. #if PACKETVER >= 20150826
  10397. int type;
  10398. // Check identity
  10399. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10400. return;
  10401. type = (int)RFIFOB(fd,6);
  10402. // Check type
  10403. if( type < 10 || type > 12 )
  10404. return;
  10405. pc_setcart(sd, type);
  10406. #endif
  10407. }
  10408. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10409. /// 01af <num>.W
  10410. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10411. {// TODO: State tracking?
  10412. int type;
  10413. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10414. return;
  10415. #ifdef RENEWAL
  10416. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10417. clif_msg(sd, WORK_IN_PROGRESS);
  10418. return;
  10419. }
  10420. #endif
  10421. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10422. if(
  10423. #ifdef NEW_CARTS
  10424. #if PACKETVER >= 20191106
  10425. (type == 13 && sd->status.base_level > 100) ||
  10426. #endif
  10427. (type == 9 && sd->status.base_level > 130) ||
  10428. (type == 8 && sd->status.base_level > 120) ||
  10429. (type == 7 && sd->status.base_level > 110) ||
  10430. (type == 6 && sd->status.base_level > 100) ||
  10431. #endif
  10432. (type == 5 && sd->status.base_level > 90) ||
  10433. (type == 4 && sd->status.base_level > 80) ||
  10434. (type == 3 && sd->status.base_level > 65) ||
  10435. (type == 2 && sd->status.base_level > 40) ||
  10436. (type == 1))
  10437. pc_setcart(sd, type);
  10438. }
  10439. /// Request to increase status (CZ_STATUS_CHANGE).
  10440. /// 00bb <status id>.W <amount>.B
  10441. /// status id:
  10442. /// SP_STR ~ SP_LUK
  10443. /// amount:
  10444. /// Old clients always send 1 for this, even when using /str+ and the like.
  10445. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10446. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10447. {
  10448. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10449. if( increase_amount < 0 ) {
  10450. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10451. fd, increase_amount);
  10452. }
  10453. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10454. }
  10455. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10456. /// 0112 <skill id>.W
  10457. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10458. {
  10459. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10460. }
  10461. 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)
  10462. {
  10463. int lv;
  10464. if( !hd )
  10465. return;
  10466. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10467. clif_emotion(&hd->bl, ET_THINK);
  10468. return;
  10469. }
  10470. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10471. target_id = hd->bl.id;
  10472. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10473. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10474. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10475. clif_emotion(&hd->bl, ET_THINK);
  10476. if (hd->master)
  10477. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10478. return;
  10479. }
  10480. lv = hom_checkskill(hd, skill_id);
  10481. if( skill_lv > lv )
  10482. skill_lv = lv;
  10483. if( skill_lv )
  10484. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10485. }
  10486. 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)
  10487. {
  10488. int lv;
  10489. if( !hd )
  10490. return;
  10491. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10492. clif_emotion(&hd->bl, ET_THINK);
  10493. return;
  10494. }
  10495. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10496. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10497. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10498. clif_emotion(&hd->bl, ET_THINK);
  10499. if (hd->master)
  10500. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10501. return;
  10502. }
  10503. #ifdef RENEWAL
  10504. if (hd->sc.data[SC_BASILICA_CELL])
  10505. #else
  10506. if (hd->sc.data[SC_BASILICA])
  10507. #endif
  10508. return;
  10509. lv = hom_checkskill(hd, skill_id);
  10510. if( skill_lv > lv )
  10511. skill_lv = lv;
  10512. if( skill_lv )
  10513. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10514. }
  10515. 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)
  10516. {
  10517. int lv;
  10518. if( !md )
  10519. return;
  10520. if( skill_isNotOk_mercenary(skill_id, md) )
  10521. return;
  10522. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10523. target_id = md->bl.id;
  10524. if( md->ud.skilltimer != INVALID_TIMER )
  10525. {
  10526. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10527. }
  10528. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10529. return;
  10530. lv = mercenary_checkskill(md, skill_id);
  10531. if( skill_lv > lv )
  10532. skill_lv = lv;
  10533. if( skill_lv )
  10534. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10535. }
  10536. 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)
  10537. {
  10538. int lv;
  10539. if( !md )
  10540. return;
  10541. if( skill_isNotOk_mercenary(skill_id, md) )
  10542. return;
  10543. if( md->ud.skilltimer != INVALID_TIMER )
  10544. return;
  10545. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10546. {
  10547. if (md->master)
  10548. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10549. return;
  10550. }
  10551. #ifdef RENEWAL
  10552. if (md->sc.data[SC_BASILICA_CELL])
  10553. #else
  10554. if (md->sc.data[SC_BASILICA])
  10555. #endif
  10556. return;
  10557. lv = mercenary_checkskill(md, skill_id);
  10558. if( skill_lv > lv )
  10559. skill_lv = lv;
  10560. if( skill_lv )
  10561. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10562. }
  10563. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10564. t_tick tick = gettick();
  10565. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10566. int inf = skill_get_inf(skill_id);
  10567. if (inf&INF_GROUND_SKILL || !inf)
  10568. return; //Using a ground/passive skill on a target? WRONG.
  10569. if (sd->state.block_action & PCBLOCK_SKILL) {
  10570. clif_msg(sd, WORK_IN_PROGRESS);
  10571. return;
  10572. }
  10573. if( SKILL_CHK_HOMUN(skill_id) ) {
  10574. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10575. return;
  10576. }
  10577. if( SKILL_CHK_MERC(skill_id) ) {
  10578. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10579. return;
  10580. }
  10581. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10582. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10583. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10584. sd->idletime = last_tick;
  10585. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10586. sd->idletime_hom = last_tick;
  10587. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10588. sd->idletime_mer = last_tick;
  10589. if( sd->npc_id ){
  10590. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10591. #ifdef RENEWAL
  10592. clif_msg( sd, WORK_IN_PROGRESS );
  10593. #endif
  10594. return;
  10595. }
  10596. }
  10597. if ((pc_cant_act2(sd) || sd->chatID) &&
  10598. skill_id != RK_REFRESH &&
  10599. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10600. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10601. return;
  10602. if( pc_issit(sd) )
  10603. return;
  10604. if( skill_isNotOk(skill_id, sd) )
  10605. return;
  10606. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10607. target_id = sd->bl.id; // never trust the client
  10608. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10609. target_id = sd->bl.id;
  10610. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10611. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10612. return;
  10613. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10614. if( sd->skillitem != skill_id ) {
  10615. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10616. return;
  10617. }
  10618. }
  10619. if( sd->sc.option&OPTION_COSTUME )
  10620. return;
  10621. #ifndef RENEWAL
  10622. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10623. return; // On basilica only caster can use Basilica again to stop it.
  10624. #endif
  10625. if( sd->menuskill_id ) {
  10626. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10627. clif_menuskill_clear(sd); //Cancel pet capture.
  10628. }else if( sd->menuskill_id == SG_FEEL ){
  10629. clif_menuskill_clear( sd ); // Cancel selection
  10630. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10631. return; //Can't use skills while a menu is open.
  10632. }
  10633. if( sd->skillitem == skill_id ) {
  10634. if( skill_lv != sd->skillitemlv )
  10635. skill_lv = sd->skillitemlv;
  10636. if( !(inf&INF_SELF_SKILL) )
  10637. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10638. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10639. return;
  10640. }
  10641. sd->skillitem = sd->skillitemlv = 0;
  10642. if( SKILL_CHK_GUILD(skill_id) ) {
  10643. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10644. skill_lv = guild_checkskill(sd->guild, skill_id);
  10645. else
  10646. skill_lv = 0;
  10647. } else {
  10648. if( skill_id != ALL_EQSWITCH ){
  10649. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10650. }
  10651. }
  10652. pc_delinvincibletimer(sd);
  10653. if( skill_lv )
  10654. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10655. }
  10656. /// Request to use a targeted skill.
  10657. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10658. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10659. /// There are various variants of this packet, some of them have padding between fields.
  10660. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10661. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10662. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10663. }
  10664. /*==========================================
  10665. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10666. *------------------------------------------*/
  10667. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10668. {
  10669. t_tick tick = gettick();
  10670. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10671. return; //Using a target skill on the ground? WRONG.
  10672. if (sd->state.block_action & PCBLOCK_SKILL) {
  10673. clif_msg(sd, WORK_IN_PROGRESS);
  10674. return;
  10675. }
  10676. if( SKILL_CHK_HOMUN(skill_id) ) {
  10677. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10678. return;
  10679. }
  10680. if( SKILL_CHK_MERC(skill_id) ) {
  10681. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10682. return;
  10683. }
  10684. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10685. #ifdef RENEWAL
  10686. clif_msg( sd, WORK_IN_PROGRESS );
  10687. #endif
  10688. return;
  10689. }
  10690. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10691. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10692. sd->idletime = last_tick;
  10693. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10694. sd->idletime_hom = last_tick;
  10695. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10696. sd->idletime_mer = last_tick;
  10697. if( skill_isNotOk(skill_id, sd) )
  10698. return;
  10699. if( skillmoreinfo != -1 ) {
  10700. if( pc_issit(sd) ) {
  10701. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10702. return;
  10703. }
  10704. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10705. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10706. }
  10707. if( sd->ud.skilltimer != INVALID_TIMER )
  10708. return;
  10709. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10710. if( sd->skillitem != skill_id ) {
  10711. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10712. return;
  10713. }
  10714. }
  10715. if( sd->sc.option&OPTION_COSTUME )
  10716. return;
  10717. #ifndef RENEWAL
  10718. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10719. return; // On basilica only caster can use Basilica again to stop it.
  10720. #endif
  10721. if( sd->menuskill_id ) {
  10722. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10723. clif_menuskill_clear(sd); //Cancel pet capture.
  10724. }else if( sd->menuskill_id == SG_FEEL ){
  10725. clif_menuskill_clear( sd ); // Cancel selection
  10726. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10727. return; //Can't use skills while a menu is open.
  10728. }
  10729. pc_delinvincibletimer(sd);
  10730. if( sd->skillitem == skill_id ) {
  10731. if( skill_lv != sd->skillitemlv )
  10732. skill_lv = sd->skillitemlv;
  10733. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10734. } else {
  10735. int lv;
  10736. sd->skillitem = sd->skillitemlv = 0;
  10737. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10738. if( skill_lv > lv )
  10739. skill_lv = lv;
  10740. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10741. }
  10742. }
  10743. }
  10744. /// Request to use a ground skill.
  10745. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10746. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10747. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10748. /// There are various variants of this packet, some of them have padding between fields.
  10749. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10750. {
  10751. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10752. if (pc_cant_act(sd))
  10753. return;
  10754. if (pc_issit(sd))
  10755. return;
  10756. clif_parse_UseSkillToPosSub(fd, sd,
  10757. RFIFOW(fd,info->pos[0]), //skill lv
  10758. RFIFOW(fd,info->pos[1]), //skill num
  10759. RFIFOW(fd,info->pos[2]), //pos x
  10760. RFIFOW(fd,info->pos[3]), //pos y
  10761. // TODO: find out what this is intended to do
  10762. //RFIFOB(fd, info->pos[4])
  10763. -1 //Skill more info.
  10764. );
  10765. }
  10766. /// Request to use a ground skill with text.
  10767. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10768. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10769. /// There are various variants of this packet, some of them have padding between fields.
  10770. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10771. {
  10772. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10773. if (pc_cant_act(sd))
  10774. return;
  10775. if (pc_issit(sd))
  10776. return;
  10777. clif_parse_UseSkillToPosSub(fd, sd,
  10778. RFIFOW(fd,info->pos[0]), //Skill lv
  10779. RFIFOW(fd,info->pos[1]), //Skill num
  10780. RFIFOW(fd,info->pos[2]), //pos x
  10781. RFIFOW(fd,info->pos[3]), //pos y
  10782. info->pos[4] //skill more info
  10783. );
  10784. }
  10785. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10786. /// 011b <skill id>.W <map name>.16B
  10787. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10788. {
  10789. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10790. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10791. char map_name[MAP_NAME_LENGTH];
  10792. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10793. sd->state.workinprogress = WIP_DISABLE_NONE;
  10794. if(skill_id != sd->menuskill_id)
  10795. return;
  10796. //It is possible to use teleport with the storage window open bugreport:8027
  10797. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10798. clif_menuskill_clear(sd);
  10799. return;
  10800. }
  10801. pc_delinvincibletimer(sd);
  10802. skill_castend_map(sd,skill_id,map_name);
  10803. }
  10804. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10805. /// 011d
  10806. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10807. {
  10808. if (!pc_isdead(sd))
  10809. pc_memo(sd,-1);
  10810. }
  10811. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10812. /// 018e <name id>.W { <material id>.W }*3
  10813. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10814. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10815. switch( sd->menuskill_id ) {
  10816. case -1:
  10817. case AM_PHARMACY:
  10818. case RK_RUNEMASTERY:
  10819. case GC_RESEARCHNEWPOISON:
  10820. break;
  10821. default:
  10822. return;
  10823. }
  10824. if (pc_istrading(sd)) {
  10825. //Make it fail to avoid shop exploits where you sell something different than you see.
  10826. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10827. clif_menuskill_clear(sd);
  10828. return;
  10829. }
  10830. int produce_idx;
  10831. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10832. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10833. clif_menuskill_clear(sd);
  10834. }
  10835. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10836. /// 025b <mk type>.W <name id>.W
  10837. /// mk type:
  10838. /// 1 = cooking
  10839. /// 2 = arrow
  10840. /// 3 = elemental
  10841. /// 4 = GN_MIX_COOKING
  10842. /// 5 = GN_MAKEBOMB
  10843. /// 6 = GN_S_PHARMACY
  10844. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10845. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10846. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10847. short food_idx = -1;
  10848. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10849. return;
  10850. if (pc_istrading(sd)) {
  10851. //Make it fail to avoid shop exploits where you sell something different than you see.
  10852. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10853. clif_menuskill_clear(sd);
  10854. return;
  10855. }
  10856. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10857. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10858. clif_menuskill_clear(sd);
  10859. }
  10860. /// Answer to repair weapon item selection dialog
  10861. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10862. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10863. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  10864. const struct PACKET_CZ_REQ_ITEMREPAIR *p = (struct PACKET_CZ_REQ_ITEMREPAIR *)RFIFOP( fd, 0 );
  10865. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10866. return;
  10867. if (pc_istrading(sd)) {
  10868. //Make it fail to avoid shop exploits where you sell something different than you see.
  10869. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10870. clif_menuskill_clear(sd);
  10871. return;
  10872. }
  10873. skill_repairweapon( sd, p->index );
  10874. clif_menuskill_clear(sd);
  10875. }
  10876. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10877. /// 0222 <index>.L
  10878. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  10879. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10880. return;
  10881. if (pc_istrading(sd)) {
  10882. //Make it fail to avoid shop exploits where you sell something different than you see.
  10883. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10884. clif_menuskill_clear(sd);
  10885. return;
  10886. }
  10887. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  10888. clif_menuskill_clear(sd);
  10889. }
  10890. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10891. /// 00b8 <npc id>.L <choice>.B
  10892. /// choice:
  10893. /// 1~254 = menu item
  10894. /// 255 = cancel
  10895. /// NOTE: If there were more than 254 items in the list, choice
  10896. /// overflows to choice%256.
  10897. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10898. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10899. int npc_id = RFIFOL(fd,info->pos[0]);
  10900. uint8 select = RFIFOB(fd,info->pos[1]);
  10901. #ifdef SECURE_NPCTIMEOUT
  10902. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  10903. return;
  10904. #endif
  10905. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10906. TBL_NPC* nd = map_id2nd(npc_id);
  10907. 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);
  10908. clif_GM_kick(NULL,sd);
  10909. return;
  10910. }
  10911. sd->npc_menu = select;
  10912. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  10913. sd->idletime = last_tick;
  10914. }
  10915. npc_scriptcont(sd,npc_id, false);
  10916. }
  10917. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10918. /// 00b9 <npc id>.L
  10919. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10920. {
  10921. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  10922. sd->idletime = last_tick;
  10923. }
  10924. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10925. }
  10926. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10927. /// 0143 <npc id>.L <value>.L
  10928. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10929. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10930. int npcid = RFIFOL(fd,info->pos[0]);
  10931. int amount = (int)RFIFOL(fd,info->pos[1]);
  10932. sd->npc_amount = amount;
  10933. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  10934. sd->idletime = last_tick;
  10935. }
  10936. npc_scriptcont(sd, npcid, false);
  10937. }
  10938. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10939. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10940. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10941. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10942. int message_len = RFIFOW(fd,info->pos[0])-8;
  10943. int npcid = RFIFOL(fd,info->pos[1]);
  10944. const char* message = RFIFOCP(fd,info->pos[2]);
  10945. if( message_len <= 0 )
  10946. return; // invalid input
  10947. #if PACKETVER >= 20151001
  10948. message_len++;
  10949. #endif
  10950. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10951. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  10952. sd->idletime = last_tick;
  10953. }
  10954. npc_scriptcont(sd, npcid, false);
  10955. }
  10956. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10957. /// 0146 <npc id>.L
  10958. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10959. {
  10960. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10961. return;
  10962. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  10963. sd->idletime = last_tick;
  10964. }
  10965. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10966. }
  10967. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10968. /// 0178 <index>.W
  10969. /// index:
  10970. /// -1 = cancel
  10971. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10972. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10973. if (sd->menuskill_id != MC_IDENTIFY)
  10974. return;
  10975. // Ignore the request
  10976. // - Invalid item index
  10977. // - Invalid item ID or item doesn't exist
  10978. // - Item is already identified
  10979. if (idx < 0 || idx >= MAX_INVENTORY ||
  10980. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  10981. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10982. sd->state.workinprogress = WIP_DISABLE_NONE;
  10983. clif_menuskill_clear(sd);
  10984. return;
  10985. }
  10986. skill_identify(sd, idx);
  10987. clif_menuskill_clear(sd);
  10988. }
  10989. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10990. /// 01ae <name id>.W
  10991. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10992. if (pc_istrading(sd)) {
  10993. //Make it fail to avoid shop exploits where you sell something different than you see.
  10994. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10995. clif_menuskill_clear(sd);
  10996. return;
  10997. }
  10998. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  10999. switch (sd->menuskill_id) {
  11000. case AC_MAKINGARROW:
  11001. skill_arrow_create(sd,p->itemId);
  11002. break;
  11003. case SA_CREATECON:
  11004. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11005. break;
  11006. case GC_POISONINGWEAPON:
  11007. skill_poisoningweapon(sd,p->itemId);
  11008. break;
  11009. case NC_MAGICDECOY:
  11010. skill_magicdecoy(sd,p->itemId);
  11011. break;
  11012. }
  11013. clif_menuskill_clear(sd);
  11014. }
  11015. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11016. /// 01ce <skill id>.L
  11017. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11018. {
  11019. if (sd->menuskill_id != SA_AUTOSPELL)
  11020. return;
  11021. sd->state.workinprogress = WIP_DISABLE_NONE;
  11022. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11023. clif_menuskill_clear(sd);
  11024. }
  11025. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11026. /// 017a <card index>.W
  11027. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11028. {
  11029. if (sd->state.trading != 0)
  11030. return;
  11031. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11032. }
  11033. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11034. /// 017c <card index>.W <equip index>.W
  11035. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11036. {
  11037. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11038. if (sd->state.trading != 0)
  11039. return;
  11040. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11041. }
  11042. /// Request of character's name by char ID.
  11043. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11044. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11045. /// There are various variants of this packet, some of them have padding between fields.
  11046. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11047. {
  11048. int charid;
  11049. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11050. map_reqnickdb(sd, charid);
  11051. }
  11052. /// /resetskill /resetstate (CZ_RESET).
  11053. /// Request to reset stats or skills.
  11054. /// 0197 <type>.W
  11055. /// type:
  11056. /// 0 = state
  11057. /// 1 = skill
  11058. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11059. char cmd[15];
  11060. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11061. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11062. else
  11063. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11064. is_atcommand(fd, sd, cmd, 1);
  11065. }
  11066. /// /lb /nlb (CZ_LOCALBROADCAST).
  11067. /// Request to broadcast a message on current map.
  11068. /// 019c <packet len>.W <text>.?B
  11069. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11070. {
  11071. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11072. char command[CHAT_SIZE_MAX+16];
  11073. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11074. char* msg = RFIFOCP(fd,info->pos[1]);
  11075. // as the length varies depending on the command used, just block unreasonably long strings
  11076. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11077. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11078. is_atcommand(fd, sd, command, 1);
  11079. }
  11080. /// Request to move an item from inventory to storage.
  11081. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11082. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11083. /// There are various variants of this packet, some of them have padding between fields.
  11084. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11085. {
  11086. int item_index, item_amount;
  11087. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11088. if (pc_istrading(sd))
  11089. return;
  11090. item_index = RFIFOW(fd,info->pos[0])-2;
  11091. item_amount = RFIFOL(fd,info->pos[1]);
  11092. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11093. return;
  11094. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11095. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11096. return;
  11097. }
  11098. if (sd->state.storage_flag == 1)
  11099. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11100. else
  11101. if (sd->state.storage_flag == 2)
  11102. storage_guild_storageadd(sd, item_index, item_amount);
  11103. else if (sd->state.storage_flag == 3)
  11104. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11105. }
  11106. /// Request to move an item from storage to inventory.
  11107. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11108. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11109. /// There are various variants of this packet, some of them have padding between fields.
  11110. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11111. {
  11112. int item_index, item_amount;
  11113. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11114. item_index = RFIFOW(fd,info->pos[0])-1;
  11115. item_amount = RFIFOL(fd,info->pos[1]);
  11116. if (sd->state.storage_flag == 1)
  11117. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11118. else if(sd->state.storage_flag == 2)
  11119. storage_guild_storageget(sd, item_index, item_amount);
  11120. else if(sd->state.storage_flag == 3)
  11121. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11122. }
  11123. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11124. /// 0129 <index>.W <amount>.L
  11125. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11126. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11127. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11128. int amount = RFIFOL(fd,info->pos[1]);
  11129. if( sd->state.vending )
  11130. return;
  11131. if (!pc_iscarton(sd))
  11132. return;
  11133. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11134. return;
  11135. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11136. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11137. return;
  11138. }
  11139. if (sd->state.storage_flag == 1)
  11140. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11141. else if (sd->state.storage_flag == 2)
  11142. storage_guild_storageaddfromcart(sd, idx, amount);
  11143. else if (sd->state.storage_flag == 3)
  11144. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11145. }
  11146. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11147. /// 0128 <index>.W <amount>.L
  11148. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11149. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11150. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11151. int amount = RFIFOL(fd,info->pos[1]);
  11152. if( sd->state.vending )
  11153. return;
  11154. if (!pc_iscarton(sd))
  11155. return;
  11156. if (sd->state.storage_flag == 1)
  11157. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11158. else
  11159. if (sd->state.storage_flag == 2)
  11160. storage_guild_storagegettocart(sd, idx, amount);
  11161. else if (sd->state.storage_flag == 3)
  11162. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11163. }
  11164. /// Request to close storage (CZ_CLOSE_STORE).
  11165. /// 00f7
  11166. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11167. {
  11168. if( sd->state.storage_flag == 1 )
  11169. storage_storageclose(sd);
  11170. else
  11171. if( sd->state.storage_flag == 2 )
  11172. storage_guild_storageclose(sd);
  11173. else if( sd->state.storage_flag == 3 )
  11174. storage_premiumStorage_close(sd);
  11175. }
  11176. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11177. /// 023a <info>.W
  11178. /// info:
  11179. /// 0 = password has not been set yet
  11180. /// 1 = storage is password-protected
  11181. /// 8 = too many wrong passwords
  11182. /// ? = ignored
  11183. /// NOTE: This packet is only available on certain non-kRO clients.
  11184. void clif_storagepassword(struct map_session_data* sd, short info)
  11185. {
  11186. int fd = sd->fd;
  11187. WFIFOHEAD(fd,packet_len(0x23a));
  11188. WFIFOW(fd,0) = 0x23a;
  11189. WFIFOW(fd,2) = info;
  11190. WFIFOSET(fd,packet_len(0x23a));
  11191. }
  11192. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11193. /// 023b <type>.W <password>.16B <new password>.16B
  11194. /// type:
  11195. /// 2 = change password
  11196. /// 3 = check password
  11197. /// NOTE: This packet is only available on certain non-kRO clients.
  11198. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11199. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11200. // int type = RFIFOW(fd,info->pos[0]);
  11201. // char* password = RFIFOP(fd,info->pos[1]);
  11202. // char* new_password = RFIFOP(fd,info->pos[2]);
  11203. // storage_changepass(sd,password,new_password);
  11204. }
  11205. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11206. /// 023c <result>.W <error count>.W
  11207. /// result:
  11208. /// 4 = password change success
  11209. /// 5 = password change failure
  11210. /// 6 = password check success
  11211. /// 7 = password check failure
  11212. /// 8 = too many wrong passwords
  11213. /// ? = ignored
  11214. /// NOTE: This packet is only available on certain non-kRO clients.
  11215. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11216. {
  11217. int fd = sd->fd;
  11218. WFIFOHEAD(fd,packet_len(0x23c));
  11219. WFIFOW(fd,0) = 0x23c;
  11220. WFIFOW(fd,2) = result;
  11221. WFIFOW(fd,4) = error_count;
  11222. WFIFOSET(fd,packet_len(0x23c));
  11223. }
  11224. /// Party creation request
  11225. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11226. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11227. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11228. name[NAME_LENGTH-1] = '\0';
  11229. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11230. clif_displaymessage(fd, msg_txt(sd,227));
  11231. return;
  11232. }
  11233. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11234. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11235. return;
  11236. }
  11237. party_create(sd,name,0,0);
  11238. }
  11239. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11240. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11241. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11242. char* name = RFIFOCP(fd,info->pos[0]);
  11243. int item1 = RFIFOB(fd,info->pos[1]);
  11244. int item2 = RFIFOB(fd,info->pos[2]);
  11245. name[NAME_LENGTH-1] = '\0';
  11246. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11247. clif_displaymessage(fd, msg_txt(sd,227));
  11248. return;
  11249. }
  11250. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11251. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11252. return;
  11253. }
  11254. party_create(sd,name,item1,item2);
  11255. }
  11256. /// Party invitation request
  11257. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11258. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11259. {
  11260. struct map_session_data *t_sd;
  11261. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11262. clif_displaymessage(fd, msg_txt(sd,227));
  11263. return;
  11264. }
  11265. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11266. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11267. clif_noask_sub(sd, t_sd, 1);
  11268. return;
  11269. }
  11270. party_invite(sd, t_sd);
  11271. }
  11272. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11273. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11274. struct map_session_data *t_sd;
  11275. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11276. name[NAME_LENGTH-1] = '\0';
  11277. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11278. clif_displaymessage(fd, msg_txt(sd,227));
  11279. return;
  11280. }
  11281. t_sd = map_nick2sd(name,false);
  11282. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11283. clif_noask_sub(sd, t_sd, 1);
  11284. return;
  11285. }
  11286. party_invite(sd, t_sd);
  11287. }
  11288. /// Party invitation reply
  11289. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11290. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11291. /// flag:
  11292. /// 0 = reject
  11293. /// 1 = accept
  11294. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11295. {
  11296. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11297. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11298. RFIFOL(fd,info->pos[1]));
  11299. }
  11300. //(CZ_PARTY_JOIN_REQ_ACK)
  11301. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11302. {
  11303. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11304. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11305. RFIFOB(fd,info->pos[1]));
  11306. }
  11307. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11308. /// 0100
  11309. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11310. {
  11311. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11312. clif_displaymessage(fd, msg_txt(sd,227));
  11313. return;
  11314. }
  11315. party_leave(sd);
  11316. }
  11317. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11318. /// 0103 <account id>.L <char name>.24B
  11319. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11320. {
  11321. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11322. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11323. clif_displaymessage(fd, msg_txt(sd,227));
  11324. return;
  11325. }
  11326. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11327. RFIFOCP(fd,info->pos[1]));
  11328. }
  11329. /// Request to change party options.
  11330. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11331. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11332. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11333. {
  11334. struct party_data *p;
  11335. int i,expflag;
  11336. int cmd = RFIFOW(fd,0);
  11337. struct s_packet_db* info = &packet_db[cmd];
  11338. if( !sd->status.party_id )
  11339. return;
  11340. p = party_search(sd->status.party_id);
  11341. if( p == NULL )
  11342. return;
  11343. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11344. if( i == MAX_PARTY )
  11345. return; //Shouldn't happen
  11346. if( !p->party.member[i].leader )
  11347. return;
  11348. expflag = RFIFOL(fd,info->pos[0]);
  11349. if(cmd == 0x0102){ //Client can't change the item-field
  11350. party_changeoption(sd, expflag, p->party.item);
  11351. }
  11352. else {
  11353. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11354. party_changeoption(sd, expflag, itemflag);
  11355. }
  11356. }
  11357. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11358. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11359. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11360. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11361. // validate packet and retrieve name and message
  11362. if( !clif_process_message( sd, false, name, message, output ) )
  11363. return;
  11364. party_send_message(sd, output, strlen(output) + 1 );
  11365. }
  11366. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11367. /// 07da <account id>.L
  11368. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11369. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11370. }
  11371. /// Party Booking in KRO [Spiria]
  11372. ///
  11373. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11374. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11375. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11376. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11377. short level = RFIFOW(fd,info->pos[0]);
  11378. short mapid = RFIFOW(fd,info->pos[1]);
  11379. int idxpbj = info->pos[2];
  11380. short job[MAX_PARTY_BOOKING_JOBS];
  11381. int i;
  11382. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11383. job[i] = RFIFOB(fd,idxpbj+i*2);
  11384. party_booking_register(sd, level, mapid, job);
  11385. }
  11386. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11387. /// 0803 <result>.W
  11388. /// result:
  11389. /// 0 = success
  11390. /// 1 = failure
  11391. /// 2 = already registered
  11392. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11393. {
  11394. int fd = sd->fd;
  11395. WFIFOHEAD(fd,packet_len(0x803));
  11396. WFIFOW(fd,0) = 0x803;
  11397. WFIFOW(fd,2) = flag;
  11398. WFIFOSET(fd,packet_len(0x803));
  11399. }
  11400. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11401. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11402. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11403. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11404. short level = RFIFOW(fd,info->pos[0]);
  11405. short mapid = RFIFOW(fd,info->pos[1]);
  11406. short job = RFIFOW(fd,info->pos[2]);
  11407. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11408. short resultcount = RFIFOW(fd,info->pos[4]);
  11409. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11410. }
  11411. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11412. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11413. /// more results:
  11414. /// 0 = no
  11415. /// 1 = yes
  11416. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11417. {
  11418. int i, j;
  11419. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11420. struct party_booking_ad_info *pb_ad;
  11421. WFIFOHEAD(fd,size*count + 5);
  11422. WFIFOW(fd,0) = 0x805;
  11423. WFIFOW(fd,2) = size*count + 5;
  11424. WFIFOB(fd,4) = more_result;
  11425. for(i=0; i<count; i++)
  11426. {
  11427. pb_ad = results[i];
  11428. WFIFOL(fd,i*size+5) = pb_ad->index;
  11429. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11430. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11431. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11432. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11433. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11434. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11435. }
  11436. WFIFOSET(fd,WFIFOW(fd,2));
  11437. }
  11438. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11439. /// 0806
  11440. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11441. {
  11442. if(party_booking_delete(sd))
  11443. clif_PartyBookingDeleteAck(sd, 0);
  11444. }
  11445. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11446. /// 0807 <result>.W
  11447. /// result:
  11448. /// 0 = success
  11449. /// 1 = success (auto-removed expired ad)
  11450. /// 2 = failure
  11451. /// 3 = nothing registered
  11452. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11453. {
  11454. int fd = sd->fd;
  11455. WFIFOHEAD(fd,packet_len(0x807));
  11456. WFIFOW(fd,0) = 0x807;
  11457. WFIFOW(fd,2) = flag;
  11458. WFIFOSET(fd,packet_len(0x807));
  11459. }
  11460. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11461. /// 0808 { <job>.W }*6
  11462. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11463. {
  11464. short job[MAX_PARTY_BOOKING_JOBS];
  11465. int i;
  11466. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11467. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11468. job[i] = RFIFOW(fd,idxpbu+i*2);
  11469. party_booking_update(sd, job);
  11470. }
  11471. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11472. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11473. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11474. {
  11475. int i;
  11476. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11477. if(pb_ad == NULL) return;
  11478. WBUFW(buf,0) = 0x809;
  11479. WBUFL(buf,2) = pb_ad->index;
  11480. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11481. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11482. WBUFW(buf,34) = pb_ad->p_detail.level;
  11483. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11484. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11485. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11486. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11487. }
  11488. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11489. /// 080a <index>.L { <job>.W }*6
  11490. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11491. {
  11492. int i;
  11493. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11494. if(pb_ad == NULL) return;
  11495. WBUFW(buf,0) = 0x80a;
  11496. WBUFL(buf,2) = pb_ad->index;
  11497. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11498. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11499. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11500. }
  11501. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11502. /// 080b <index>.L
  11503. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11504. {
  11505. uint8 buf[6];
  11506. WBUFW(buf,0) = 0x80b;
  11507. WBUFL(buf,2) = index;
  11508. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11509. }
  11510. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11511. /// 012e
  11512. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11513. {
  11514. vending_closevending(sd);
  11515. }
  11516. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11517. /// 0130 <account id>.L
  11518. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11519. {
  11520. if( sd->npc_id ) {// using an NPC
  11521. return;
  11522. }
  11523. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11524. }
  11525. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11526. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11527. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11528. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11529. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11530. int id = (int)RFIFOL(fd,info->pos[1]);
  11531. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11532. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11533. // whether it fails or not, the buy window is closed
  11534. sd->vended_id = 0;
  11535. }
  11536. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11537. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11538. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11539. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11540. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11541. int aid = (int)RFIFOL(fd,info->pos[1]);
  11542. int uid = (int)RFIFOL(fd,info->pos[2]);
  11543. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11544. vending_purchasereq(sd, aid, uid, data, len/4);
  11545. // whether it fails or not, the buy window is closed
  11546. sd->vended_id = 0;
  11547. }
  11548. /// Confirm or cancel the shop preparation window.
  11549. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11550. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11551. /// result:
  11552. /// 0 = canceled
  11553. /// 1 = open
  11554. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11555. int cmd = RFIFOW(fd,0);
  11556. struct s_packet_db* info = &packet_db[cmd];
  11557. short len = (short)RFIFOW(fd,info->pos[0]);
  11558. const char* message = RFIFOCP(fd,info->pos[1]);
  11559. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11560. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11561. len -= 84;
  11562. }
  11563. else { //(CZ_REQ_OPENSTORE2)
  11564. bool flag;
  11565. len -= 85;
  11566. flag = RFIFOB(fd,info->pos[2]) != 0;
  11567. if (!flag) {
  11568. sd->state.prevend = 0;
  11569. sd->state.workinprogress = WIP_DISABLE_NONE;
  11570. }
  11571. }
  11572. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11573. return;
  11574. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11575. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11576. return;
  11577. }
  11578. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11579. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11580. return;
  11581. }
  11582. if( message[0] == '\0' ) // invalid input
  11583. return;
  11584. vending_openvending(sd, message, data, len/8, NULL);
  11585. }
  11586. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11587. /// 0165 <char id>.L <guild name>.24B
  11588. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11589. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11590. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11591. name[NAME_LENGTH-1] = '\0';
  11592. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11593. clif_displaymessage(fd, msg_txt(sd,228));
  11594. return;
  11595. }
  11596. if(sd->clan){
  11597. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11598. return;
  11599. }
  11600. guild_create(sd, name);
  11601. }
  11602. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11603. /// 014d
  11604. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11605. {
  11606. clif_guild_masterormember(sd);
  11607. }
  11608. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11609. /// 014f <type>.L
  11610. /// type:
  11611. /// 0 = basic info
  11612. /// 1 = member manager
  11613. /// 2 = positions
  11614. /// 3 = skills
  11615. /// 4 = expulsion list
  11616. /// 5 = unknown (GM_ALLGUILDLIST)
  11617. /// 6 = notice
  11618. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11619. {
  11620. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11621. if( !sd->status.guild_id && !sd->bg_id )
  11622. return;
  11623. switch( type )
  11624. {
  11625. case 0: // Basic Information Guild, hostile alliance information
  11626. clif_guild_basicinfo(sd);
  11627. clif_guild_allianceinfo(sd);
  11628. break;
  11629. case 1: // Members list, list job title
  11630. clif_guild_positionnamelist(sd);
  11631. clif_guild_memberlist(sd);
  11632. break;
  11633. case 2: // List job title, title information list
  11634. clif_guild_positionnamelist(sd);
  11635. clif_guild_positioninfolist(sd);
  11636. break;
  11637. case 3: // Skill list
  11638. clif_guild_skillinfo(sd);
  11639. break;
  11640. case 4: // Expulsion list
  11641. clif_guild_expulsionlist(sd);
  11642. break;
  11643. default:
  11644. ShowError("clif: guild request info: unknown type %d\n", type);
  11645. break;
  11646. }
  11647. }
  11648. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11649. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11650. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11651. {
  11652. int i;
  11653. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11654. int len = RFIFOW(fd,info->pos[0]);
  11655. int idxgpos = info->pos[1];
  11656. if(!sd->state.gmaster_flag)
  11657. return;
  11658. for(i = idxgpos; i < len; i += 40 ){
  11659. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11660. }
  11661. }
  11662. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11663. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11664. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11665. {
  11666. int i;
  11667. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11668. int len = RFIFOW(fd,info->pos[0]);
  11669. int idxgpos = info->pos[1];
  11670. if(!sd->state.gmaster_flag)
  11671. return;
  11672. // Guild leadership change
  11673. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11674. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11675. clif_msg(sd, GUILD_MASTER_WOE);
  11676. return;
  11677. }
  11678. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11679. clif_msg(sd, GUILD_MASTER_DELAY);
  11680. return;
  11681. }
  11682. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11683. return;
  11684. }
  11685. for(i=idxgpos;i<len;i+=12){
  11686. int position = RFIFOL(fd,i+8);
  11687. if( position > 0 ){
  11688. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11689. }
  11690. }
  11691. }
  11692. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11693. /// 0151 <guild id>.L
  11694. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11695. {
  11696. struct guild* g;
  11697. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11698. if( (g = guild_search(guild_id)) != NULL )
  11699. clif_guild_emblem(sd,g);
  11700. }
  11701. /// Validates data of a guild emblem (compressed bitmap)
  11702. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11703. EMBVALIDATE_SUCCESS = 0,
  11704. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11705. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11706. };
  11707. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11708. {
  11709. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11710. unsigned long buf_len = sizeof(buf);
  11711. int offset = 0;
  11712. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11713. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11714. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11715. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11716. ))
  11717. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11718. if(battle_config.emblem_transparency_limit != 100) {
  11719. int i, transcount = 1, tmp[3];
  11720. for(i = offset; i < buf_len-1; i++) {
  11721. int j = i%3;
  11722. tmp[j] = RBUFL(buf,i);
  11723. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11724. transcount++;
  11725. }
  11726. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11727. return EMBVALIDATE_ERR_TRANSPARENCY;
  11728. }
  11729. return EMBVALIDATE_SUCCESS;
  11730. }
  11731. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11732. /// 0153 <packet len>.W <emblem data>.?B
  11733. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11734. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11735. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11736. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11737. int emb_val=0;
  11738. if( !emblem_len || !sd->state.gmaster_flag )
  11739. return;
  11740. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11741. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11742. return;
  11743. }
  11744. emb_val = clif_validate_emblem(emblem, emblem_len);
  11745. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11746. 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);
  11747. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11748. return;
  11749. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11750. char output[128];
  11751. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11752. 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"
  11753. return;
  11754. }
  11755. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11756. }
  11757. /// Request to update the guild emblem id (version, according to Gravity)
  11758. /// 0b46 <guild id>.L <version>.L
  11759. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  11760. nullpo_retv(sd);
  11761. #if PACKETVER >= 20190724
  11762. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11763. guild* g = sd->guild;
  11764. if (g == nullptr || g->guild_id != p->guild_id)
  11765. return;
  11766. if (!sd->state.gmaster_flag)
  11767. return;
  11768. if (!battle_config.emblem_woe_change && is_agit_start()) {
  11769. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11770. return;
  11771. }
  11772. guild_change_emblem_version(sd, p->version);
  11773. #endif
  11774. }
  11775. /// Guild notice update request (CZ_GUILD_NOTICE).
  11776. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11777. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11778. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11779. int guild_id = RFIFOL(fd,info->pos[0]);
  11780. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11781. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11782. if(!sd->state.gmaster_flag)
  11783. return;
  11784. // compensate for some client defects when using multilanguage mode
  11785. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11786. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11787. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11788. guild_change_notice(sd, guild_id, msg1, msg2);
  11789. }
  11790. // Helper function for guild invite functions
  11791. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11792. {
  11793. if (t_sd == NULL) // not online or does not exist
  11794. return 1;
  11795. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11796. clif_displaymessage(fd, msg_txt(sd,228));
  11797. return 1;
  11798. }
  11799. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11800. clif_noask_sub(sd, t_sd, 2);
  11801. return 1;
  11802. }
  11803. // Players in a clan can not join a guild
  11804. if(t_sd && t_sd->clan){
  11805. return 1;
  11806. }
  11807. guild_invite(sd, t_sd);
  11808. return 0;
  11809. }
  11810. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11811. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11812. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11813. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11814. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11815. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11816. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11817. if (clif_sub_guild_invite(fd, sd, t_sd))
  11818. return;
  11819. }
  11820. /// Guild invite request (/guildinvite)
  11821. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11822. void
  11823. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11824. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11825. if (clif_sub_guild_invite(fd, sd, t_sd))
  11826. return;
  11827. }
  11828. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11829. /// 016b <guild id>.L <answer>.L
  11830. /// answer:
  11831. /// 0 = refuse
  11832. /// 1 = accept
  11833. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11834. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11835. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11836. RFIFOL(fd,info->pos[1]));
  11837. }
  11838. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11839. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11840. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11841. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11842. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11843. clif_displaymessage(fd, msg_txt(sd,228));
  11844. return;
  11845. }
  11846. if( sd->bg_id ) {
  11847. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11848. return;
  11849. }
  11850. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11851. RFIFOL(fd,info->pos[1]),
  11852. RFIFOL(fd,info->pos[2]),
  11853. RFIFOCP(fd,info->pos[3]));
  11854. }
  11855. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11856. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11857. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11858. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11859. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11860. { // Guild locked.
  11861. clif_displaymessage(fd, msg_txt(sd,228));
  11862. return;
  11863. }
  11864. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11865. RFIFOL(fd,info->pos[1]),
  11866. RFIFOL(fd,info->pos[2]),
  11867. RFIFOCP(fd,info->pos[3]));
  11868. }
  11869. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11870. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11871. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11872. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11873. // validate packet and retrieve name and message
  11874. if( !clif_process_message( sd, false, name, message, output ) )
  11875. return;
  11876. if( sd->bg_id )
  11877. bg_send_message(sd, output, strlen(output) );
  11878. else
  11879. guild_send_message(sd, output, strlen(output) );
  11880. }
  11881. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11882. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11883. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11884. {
  11885. struct map_session_data *t_sd;
  11886. if(!sd->state.gmaster_flag)
  11887. return;
  11888. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11889. clif_displaymessage(fd, msg_txt(sd,228));
  11890. return;
  11891. }
  11892. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11893. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11894. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11895. // @noask [LuzZza]
  11896. if(t_sd && t_sd->state.noask) {
  11897. clif_noask_sub(sd, t_sd, 3);
  11898. return;
  11899. }
  11900. guild_reqalliance(sd,t_sd);
  11901. }
  11902. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11903. /// 0172 <inviter account id>.L <answer>.L
  11904. /// answer:
  11905. /// 0 = refuse
  11906. /// 1 = accept
  11907. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11908. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11909. guild_reply_reqalliance(sd,
  11910. RFIFOL(fd,info->pos[0]),
  11911. RFIFOL(fd,info->pos[1]));
  11912. }
  11913. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11914. /// 0183 <opponent guild id>.L <relation>.L
  11915. /// relation:
  11916. /// 0 = Ally
  11917. /// 1 = Enemy
  11918. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11919. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11920. if(!sd->state.gmaster_flag)
  11921. return;
  11922. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11923. clif_displaymessage(fd, msg_txt(sd,228));
  11924. return;
  11925. }
  11926. guild_delalliance(sd,
  11927. RFIFOL(fd,info->pos[0]),
  11928. RFIFOL(fd,info->pos[1]));
  11929. }
  11930. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11931. /// 0180 <account id>.L
  11932. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11933. {
  11934. struct map_session_data *t_sd;
  11935. if(!sd->state.gmaster_flag)
  11936. return;
  11937. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11938. clif_displaymessage(fd, msg_txt(sd,228));
  11939. return;
  11940. }
  11941. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11942. // @noask [LuzZza]
  11943. if(t_sd && t_sd->state.noask) {
  11944. clif_noask_sub(sd, t_sd, 4);
  11945. return;
  11946. }
  11947. guild_opposition(sd,t_sd);
  11948. }
  11949. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11950. /// 015d <key>.40B
  11951. /// key:
  11952. /// now guild name; might have been (intended) email, since the
  11953. /// field name and size is same as the one in CH_DELETE_CHAR.
  11954. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11955. {
  11956. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11957. clif_displaymessage(fd, msg_txt(sd,228));
  11958. return;
  11959. }
  11960. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11961. }
  11962. /// Pet
  11963. ///
  11964. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11965. /// 01a1 <type>.B
  11966. /// type:
  11967. /// 0 = pet information
  11968. /// 1 = feed
  11969. /// 2 = performance
  11970. /// 3 = return to egg
  11971. /// 4 = unequip accessory
  11972. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11973. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11974. }
  11975. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11976. /// 019f <id>.L
  11977. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11978. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11979. }
  11980. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11981. /// 01a7 <index>.W
  11982. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11983. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11984. return;
  11985. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11986. clif_menuskill_clear(sd);
  11987. }
  11988. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11989. /// 01a9 <data>.L
  11990. /// data:
  11991. /// is either emotion (@see enum emotion_type) or a compound value
  11992. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11993. /// entry (given in parentheses) in data\pettalktable.xml
  11994. /// act id:
  11995. /// 0 = feeding
  11996. /// 1 = hunting
  11997. /// 2 = danger
  11998. /// 3 = dead
  11999. /// 4 = normal (stand)
  12000. /// 5 = special performance (perfor_s)
  12001. /// 6 = level up (levelup)
  12002. /// 7 = performance 1 (perfor_1)
  12003. /// 8 = performance 2 (perfor_2)
  12004. /// 9 = performance 3 (perfor_3)
  12005. /// 10 = log-in greeting (connect)
  12006. /// hungry value:
  12007. /// 0 = very hungry (hungry)
  12008. /// 1 = hungry (bit_hungry)
  12009. /// 2 = satisfied (noting)
  12010. /// 3 = stuffed (full)
  12011. /// 4 = full (so_full)
  12012. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12013. {
  12014. if(sd->pd)
  12015. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12016. }
  12017. /// Request to change pet's name (CZ_RENAME_PET).
  12018. /// 01a5 <name>.24B
  12019. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12020. {
  12021. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12022. }
  12023. /// /kill (CZ_DISCONNECT_CHARACTER).
  12024. /// Request to disconnect a character.
  12025. /// 00cc <account id>.L
  12026. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12027. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12028. {
  12029. struct block_list *target;
  12030. int tid;
  12031. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12032. target = map_id2bl(tid);
  12033. if (!target) {
  12034. clif_GM_kickack(sd, 0);
  12035. return;
  12036. }
  12037. switch (target->type) {
  12038. case BL_PC:
  12039. {
  12040. char command[NAME_LENGTH+6];
  12041. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12042. is_atcommand(fd, sd, command, 1);
  12043. }
  12044. break;
  12045. /**
  12046. * This one does not invoke any atcommand, so we need to check for permissions.
  12047. */
  12048. case BL_MOB:
  12049. {
  12050. char command[100];
  12051. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12052. clif_GM_kickack(sd, 0);
  12053. return;
  12054. }
  12055. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12056. log_atcommand(sd, command);
  12057. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12058. }
  12059. break;
  12060. case BL_NPC:
  12061. {
  12062. struct npc_data* nd = (struct npc_data *)target;
  12063. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12064. npc_unload_duplicates(nd);
  12065. npc_unload(nd,true);
  12066. npc_read_event_script();
  12067. }
  12068. }
  12069. break;
  12070. default:
  12071. clif_GM_kickack(sd, 0);
  12072. }
  12073. }
  12074. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12075. /// Request to disconnect all characters.
  12076. /// 00ce
  12077. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12078. char cmd[15];
  12079. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12080. is_atcommand(fd, sd, cmd, 1);
  12081. }
  12082. /// /remove (CZ_REMOVE_AID).
  12083. /// Request to warp to a character with given login ID.
  12084. /// 01ba <account name>.24B
  12085. /// /shift (CZ_SHIFT).
  12086. /// Request to warp to a character with given name.
  12087. /// 01bb <char name>.24B
  12088. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12089. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12090. char *player_name;
  12091. char command[NAME_LENGTH+8];
  12092. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12093. player_name[NAME_LENGTH-1] = '\0';
  12094. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12095. is_atcommand(fd, sd, command, 1);
  12096. }
  12097. /// /remove (CZ_REMOVE_AID_SSO).
  12098. /// Request to warp to a character with given account ID.
  12099. /// 0843 <account id>.L
  12100. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12101. {
  12102. uint32 account_id;
  12103. struct map_session_data* pl_sd;
  12104. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12105. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12106. char command[NAME_LENGTH+8];
  12107. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12108. is_atcommand(fd, sd, command, 1);
  12109. }
  12110. }
  12111. /// /recall (CZ_RECALL).
  12112. /// Request to summon a player with given login ID to own position.
  12113. /// 01bc <account name>.24B
  12114. /// /summon (CZ_RECALL_GID).
  12115. /// Request to summon a player with given name to own position.
  12116. /// 01bd <char name>.24B
  12117. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12118. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12119. char *player_name;
  12120. char command [NAME_LENGTH+8];
  12121. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12122. player_name[NAME_LENGTH-1] = '\0';
  12123. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12124. is_atcommand(fd, sd, command, 1);
  12125. }
  12126. /// /recall (CZ_RECALL_SSO).
  12127. /// Request to summon a player with given account ID to own position.
  12128. /// 0842 <account id>.L
  12129. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12130. {
  12131. uint32 account_id;
  12132. struct map_session_data* pl_sd;
  12133. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12134. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12135. char command[NAME_LENGTH+8];
  12136. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12137. is_atcommand(fd, sd, command, 1);
  12138. }
  12139. }
  12140. /// /item /monster (CZ_ITEM_CREATE).
  12141. /// Request to execute GM commands.
  12142. /// Usage:
  12143. /// /item n - summon n monster or acquire n item/s
  12144. /// /item money - grants 2147483647 zenies
  12145. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12146. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12147. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12148. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12149. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12150. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12151. /// 013f <item/mob name>.24B
  12152. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12153. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12154. {
  12155. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12156. int mob_id = 0;
  12157. struct item_data *id = NULL;
  12158. StringBuf command;
  12159. char *str;
  12160. //#if PACKETVER >= 20131218
  12161. // char str[100];
  12162. //#else
  12163. // char str[24];
  12164. //#endif
  12165. str = RFIFOCP(fd,info->pos[0]);
  12166. if (!str || str[0] == '\0')
  12167. return;
  12168. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12169. return;
  12170. trim(str);
  12171. // Zeny
  12172. if( strcmpi(str, "money") == 0 ) {
  12173. StringBuf_Init(&command);
  12174. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12175. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12176. StringBuf_Destroy(&command);
  12177. return;
  12178. }
  12179. // Item
  12180. if( (id = itemdb_searchname(str)) ) {
  12181. StringBuf_Init(&command);
  12182. if( !itemdb_isstackable2(id) ) //Nonstackable
  12183. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12184. else {
  12185. if (id->flag.guid)
  12186. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12187. else
  12188. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12189. }
  12190. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12191. StringBuf_Destroy(&command);
  12192. return;
  12193. }
  12194. // Monster
  12195. if ((mob_id = mobdb_searchname(str)) == 0)
  12196. mob_id = mobdb_checkid(atoi(str));
  12197. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12198. if( mob != nullptr ) {
  12199. StringBuf_Init(&command);
  12200. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12201. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12202. StringBuf_Destroy(&command);
  12203. return;
  12204. }
  12205. }
  12206. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12207. /// 019d <effect state>.L
  12208. /// effect state:
  12209. /// TODO: Any OPTION_* ?
  12210. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12211. char cmd[6];
  12212. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12213. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12214. is_atcommand(fd, sd, cmd, 1);
  12215. }
  12216. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12217. /// 0149 <account id>.L <type>.B <value>.W
  12218. /// type:
  12219. /// 0 = positive points
  12220. /// 1 = negative points
  12221. /// 2 = self mute (+10 minutes)
  12222. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12223. {
  12224. int id, type, value;
  12225. struct map_session_data *dstsd;
  12226. char command[NAME_LENGTH+15];
  12227. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12228. id = RFIFOL(fd,info->pos[0]);
  12229. type = RFIFOB(fd,info->pos[1]);
  12230. value = RFIFOW(fd,info->pos[2]);
  12231. if( type == 0 )
  12232. value = -value;
  12233. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12234. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12235. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12236. return;
  12237. dstsd = map_id2sd(id);
  12238. if( dstsd == NULL )
  12239. return;
  12240. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12241. is_atcommand(fd, sd, command, 1);
  12242. }
  12243. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12244. /// GM adjustment of a player's manner value by -60.
  12245. /// 0212 <char name>.24B
  12246. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12247. {
  12248. char command[NAME_LENGTH+15];
  12249. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12250. name[NAME_LENGTH-1] = '\0';
  12251. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12252. is_atcommand(fd, sd, command, 1);
  12253. }
  12254. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12255. /// 01e0 <account id>.L <account name>.24B
  12256. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12257. {
  12258. WFIFOHEAD(fd,packet_len(0x1e0));
  12259. WFIFOW(fd,0) = 0x1e0;
  12260. WFIFOL(fd,2) = account_id;
  12261. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12262. WFIFOSET(fd,packet_len(0x1e0));
  12263. }
  12264. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12265. /// 01df <account id>.L
  12266. //! TODO: Figure out how does this actually work
  12267. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12268. {
  12269. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12270. /*
  12271. char query[30];
  12272. safesnprintf(query,sizeof(query),"%d", account_id);
  12273. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12274. */
  12275. clif_account_name(fd, account_id, "");
  12276. }
  12277. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12278. /// GM single cell type change request.
  12279. /// 0198 <x>.W <y>.W <type>.W
  12280. /// type:
  12281. /// 0 = not walkable
  12282. /// 1 = walkable
  12283. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12284. {
  12285. int x,y,type;
  12286. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12287. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12288. return;
  12289. x = RFIFOW(fd,info->pos[0]);
  12290. y = RFIFOW(fd,info->pos[1]);
  12291. type = RFIFOW(fd,info->pos[2]);
  12292. map_setgatcell(sd->bl.m,x,y,type);
  12293. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12294. //FIXME: once players leave the map, the client 'forgets' this information.
  12295. }
  12296. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12297. /// Request to allow/deny whispers from a nick.
  12298. /// 00cf <nick>.24B <type>.B
  12299. /// type:
  12300. /// 0 = (/ex nick) deny speech from nick
  12301. /// 1 = (/in nick) allow speech from nick
  12302. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12303. {
  12304. char* nick;
  12305. uint8 type;
  12306. int i;
  12307. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12308. nick = RFIFOCP(fd,info->pos[0]);
  12309. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12310. type = RFIFOB(fd,info->pos[1]);
  12311. if( type == 0 ) { // Add name to ignore list (block)
  12312. if (strcmp(wisp_server_name, nick) == 0) {
  12313. clif_wisexin(sd, type, 1); // fail
  12314. return;
  12315. }
  12316. // try to find a free spot, while checking for duplicates at the same time
  12317. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12318. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12319. clif_wisexin(sd, type, 2); // too many blocks
  12320. return;
  12321. }
  12322. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12323. clif_wisexin(sd, type, 0); // Aegis reports success.
  12324. return;
  12325. }
  12326. //Insert in position i
  12327. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12328. } else { // Remove name from ignore list (unblock)
  12329. // find entry
  12330. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12331. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12332. clif_wisexin(sd, type, 1); // fail
  12333. return;
  12334. }
  12335. // move everything one place down to overwrite removed entry
  12336. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12337. // wipe last entry
  12338. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12339. }
  12340. clif_wisexin(sd, type, 0); // success
  12341. }
  12342. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12343. /// Request to allow/deny all whispers.
  12344. /// 00d0 <type>.B
  12345. /// type:
  12346. /// 0 = (/exall) deny all speech
  12347. /// 1 = (/inall) allow all speech
  12348. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12349. {
  12350. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12351. if( type == 0 ) {// Deny all
  12352. if( sd->state.ignoreAll ) {
  12353. flag = 1; // fail
  12354. } else {
  12355. sd->state.ignoreAll = 1;
  12356. flag = 0; // success
  12357. }
  12358. } else {//Unblock everyone
  12359. if( sd->state.ignoreAll ) {
  12360. sd->state.ignoreAll = 0;
  12361. flag = 0; // success
  12362. } else {
  12363. if (sd->ignore[0].name[0] != '\0')
  12364. { //Wipe the ignore list.
  12365. memset(sd->ignore, 0, sizeof(sd->ignore));
  12366. flag = 0; // success
  12367. } else {
  12368. flag = 1; // fail
  12369. }
  12370. }
  12371. }
  12372. clif_wisall(sd, type, flag);
  12373. }
  12374. /// Whisper ignore list (ZC_WHISPER_LIST).
  12375. /// 00d4 <packet len>.W { <char name>.24B }*
  12376. void clif_PMIgnoreList(struct map_session_data* sd)
  12377. {
  12378. int i, fd = sd->fd;
  12379. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12380. WFIFOW(fd,0) = 0xd4;
  12381. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12382. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12383. }
  12384. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12385. WFIFOSET(fd,WFIFOW(fd,2));
  12386. }
  12387. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12388. /// 00d3
  12389. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12390. {
  12391. clif_PMIgnoreList(sd);
  12392. }
  12393. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12394. /// 01e7
  12395. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12396. {
  12397. if (sd->state.doridori) return;
  12398. switch (sd->class_&MAPID_UPPERMASK) {
  12399. case MAPID_SOUL_LINKER:
  12400. case MAPID_STAR_GLADIATOR:
  12401. case MAPID_TAEKWON:
  12402. if (!sd->state.rest)
  12403. break;
  12404. case MAPID_SUPER_NOVICE:
  12405. case MAPID_SUPER_BABY:
  12406. case MAPID_SUPER_NOVICE_E:
  12407. case MAPID_SUPER_BABY_E:
  12408. sd->state.doridori=1;
  12409. break;
  12410. }
  12411. }
  12412. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12413. /// 01ed
  12414. /// Note: This packet is caused by 7 lines of any text, followed by
  12415. /// the prayer and an another line of any text. The prayer is
  12416. /// defined by lines 790~793 in data\msgstringtable.txt
  12417. /// "Dear angel, can you hear my voice?"
  12418. /// "I am" (space separated player name) "Super Novice~"
  12419. /// "Help me out~ Please~ T_T"
  12420. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12421. {
  12422. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12423. t_exp next = pc_nextbaseexp(sd);
  12424. if( next ) {
  12425. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12426. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12427. 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]
  12428. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12429. }
  12430. }
  12431. }
  12432. }
  12433. /// Friends List
  12434. ///
  12435. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12436. /// 0206 <account id>.L <char id>.L <state>.B
  12437. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12438. /// state:
  12439. /// 0 = online
  12440. /// 1 = offline
  12441. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12442. {
  12443. int i, fd = sd->fd;
  12444. //Seek friend.
  12445. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12446. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12447. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12448. return; //Not found
  12449. WFIFOHEAD(fd,packet_len(0x206));
  12450. WFIFOW(fd, 0) = 0x206;
  12451. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12452. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12453. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12454. #if PACKETVER >= 20180221
  12455. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12456. #endif
  12457. WFIFOSET(fd, packet_len(0x206));
  12458. }
  12459. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12460. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12461. {
  12462. uint32 account_id, char_id, online;
  12463. account_id = va_arg(ap, int);
  12464. char_id = va_arg(ap, int);
  12465. online = va_arg(ap, int);
  12466. clif_friendslist_toggle(sd, account_id, char_id, online);
  12467. return 0;
  12468. }
  12469. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12470. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12471. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12472. void clif_friendslist_send(struct map_session_data *sd)
  12473. {
  12474. int i = 0, n, fd = sd->fd;
  12475. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12476. const int size = 8 + NAME_LENGTH;
  12477. #else
  12478. const int size = 8;
  12479. #endif
  12480. // Send friends list
  12481. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12482. WFIFOW(fd, 0) = 0x201;
  12483. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12484. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12485. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12486. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12487. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12488. #endif
  12489. }
  12490. if (i) {
  12491. WFIFOW(fd,2) = 4 + size * i;
  12492. WFIFOSET(fd, WFIFOW(fd,2));
  12493. }
  12494. for (n = 0; n < i; n++) { //Sending the online players
  12495. if (map_charid2sd(sd->status.friends[n].char_id))
  12496. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12497. }
  12498. }
  12499. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12500. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12501. /// result:
  12502. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12503. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12504. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12505. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12506. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12507. {
  12508. int fd;
  12509. nullpo_retv(sd);
  12510. fd = sd->fd;
  12511. WFIFOHEAD(fd,packet_len(0x209));
  12512. WFIFOW(fd,0) = 0x209;
  12513. WFIFOW(fd,2) = type;
  12514. if (f_sd) {
  12515. WFIFOL(fd,4) = f_sd->status.account_id;
  12516. WFIFOL(fd,8) = f_sd->status.char_id;
  12517. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12518. }
  12519. WFIFOSET(fd, packet_len(0x209));
  12520. }
  12521. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12522. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12523. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12524. {
  12525. int fd = sd->fd;
  12526. WFIFOHEAD(fd,packet_len(0x207));
  12527. WFIFOW(fd,0) = 0x207;
  12528. WFIFOL(fd,2) = account_id;
  12529. WFIFOL(fd,6) = char_id;
  12530. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12531. WFIFOSET(fd,packet_len(0x207));
  12532. }
  12533. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12534. /// 0202 <name>.24B
  12535. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12536. {
  12537. struct map_session_data *f_sd;
  12538. int i;
  12539. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12540. // Friend doesn't exist (no player with this name)
  12541. if (f_sd == NULL) {
  12542. clif_displaymessage(fd, msg_txt(sd,3));
  12543. return;
  12544. }
  12545. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12546. return;
  12547. }
  12548. // ensure that the request player's friend list is not full
  12549. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12550. if( i == MAX_FRIENDS ){
  12551. clif_friendslist_reqack(sd, f_sd, 2);
  12552. return;
  12553. }
  12554. // @noask [LuzZza]
  12555. if(f_sd->state.noask) {
  12556. clif_noask_sub(sd, f_sd, 5);
  12557. return;
  12558. }
  12559. // Friend already exists
  12560. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12561. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12562. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12563. return;
  12564. }
  12565. }
  12566. f_sd->friend_req = sd->status.char_id;
  12567. sd->friend_req = f_sd->status.char_id;
  12568. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12569. }
  12570. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12571. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12572. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12573. /// reply:
  12574. /// 0 = rejected
  12575. /// 1 = accepted
  12576. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12577. {
  12578. struct map_session_data *f_sd;
  12579. uint32 account_id;
  12580. char reply;
  12581. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12582. account_id = RFIFOL(fd,info->pos[0]);
  12583. //char_id = RFIFOL(fd,info->pos[1]);
  12584. #if PACKETVER < 6
  12585. reply = RFIFOB(fd,info->pos[2]);
  12586. #else
  12587. reply = RFIFOL(fd,info->pos[2]);
  12588. #endif
  12589. if( sd->bl.id == account_id ) {// adding oneself as friend
  12590. return;
  12591. }
  12592. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12593. if (f_sd == NULL)
  12594. return;
  12595. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12596. clif_friendslist_reqack(f_sd, sd, 1);
  12597. else {
  12598. int i;
  12599. // Find an empty slot
  12600. for (i = 0; i < MAX_FRIENDS; i++)
  12601. if (f_sd->status.friends[i].char_id == 0)
  12602. break;
  12603. if (i == MAX_FRIENDS) {
  12604. clif_friendslist_reqack(f_sd, sd, 2);
  12605. return;
  12606. }
  12607. f_sd->status.friends[i].account_id = sd->status.account_id;
  12608. f_sd->status.friends[i].char_id = sd->status.char_id;
  12609. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12610. clif_friendslist_reqack(f_sd, sd, 0);
  12611. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12612. if (battle_config.friend_auto_add) {
  12613. // Also add f_sd to sd's friendlist.
  12614. for (i = 0; i < MAX_FRIENDS; i++) {
  12615. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12616. return; //No need to add anything.
  12617. if (sd->status.friends[i].char_id == 0)
  12618. break;
  12619. }
  12620. if (i == MAX_FRIENDS) {
  12621. clif_friendslist_reqack(sd, f_sd, 2);
  12622. return;
  12623. }
  12624. sd->status.friends[i].account_id = f_sd->status.account_id;
  12625. sd->status.friends[i].char_id = f_sd->status.char_id;
  12626. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12627. clif_friendslist_reqack(sd, f_sd, 0);
  12628. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12629. }
  12630. }
  12631. }
  12632. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12633. /// 0203 <account id>.L <char id>.L
  12634. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12635. {
  12636. struct map_session_data *f_sd = NULL;
  12637. uint32 account_id, char_id;
  12638. int i, j;
  12639. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12640. account_id = RFIFOL(fd,info->pos[0]);
  12641. char_id = RFIFOL(fd,info->pos[1]);
  12642. // Search friend
  12643. for (i = 0; i < MAX_FRIENDS &&
  12644. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12645. if (i == MAX_FRIENDS) {
  12646. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12647. return;
  12648. }
  12649. //remove from friend's list first
  12650. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12651. for (i = 0; i < MAX_FRIENDS &&
  12652. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12653. if (i != MAX_FRIENDS) {
  12654. // move all chars up
  12655. for(j = i + 1; j < MAX_FRIENDS; j++)
  12656. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12657. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12658. //should the guy be notified of some message? we should add it here if so
  12659. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12660. WFIFOW(f_sd->fd,0) = 0x20a;
  12661. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12662. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12663. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12664. }
  12665. } else { //friend not online -- ask char server to delete from his friendlist
  12666. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12667. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12668. return;
  12669. }
  12670. }
  12671. // We can now delete from original requester
  12672. for (i = 0; i < MAX_FRIENDS &&
  12673. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12674. // move all chars up
  12675. for(j = i + 1; j < MAX_FRIENDS; j++)
  12676. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12677. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12678. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12679. WFIFOHEAD(fd,packet_len(0x20a));
  12680. WFIFOW(fd,0) = 0x20a;
  12681. WFIFOL(fd,2) = account_id;
  12682. WFIFOL(fd,6) = char_id;
  12683. WFIFOSET(fd, packet_len(0x20a));
  12684. }
  12685. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12686. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12687. void clif_PVPInfo(struct map_session_data* sd)
  12688. {
  12689. int fd = sd->fd;
  12690. WFIFOHEAD(fd,packet_len(0x210));
  12691. WFIFOW(fd,0) = 0x210;
  12692. WFIFOL(fd,2) = sd->status.char_id;
  12693. WFIFOL(fd,6) = sd->status.account_id;
  12694. WFIFOL(fd,10) = sd->pvp_won; // times won
  12695. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12696. WFIFOL(fd,18) = sd->pvp_point;
  12697. WFIFOSET(fd, packet_len(0x210));
  12698. }
  12699. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12700. /// 020f <char id>.L <account id>.L
  12701. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12702. {
  12703. // TODO: Is there a way to use this on an another player (char/acc id)?
  12704. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12705. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12706. clif_PVPInfo(sd);
  12707. }
  12708. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12709. /// 0254 <which>.B
  12710. /// which: (unused atm for security purpose)
  12711. /// 0 = sun
  12712. /// 1 = moon
  12713. /// 2 = star
  12714. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12715. {
  12716. int i;
  12717. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12718. if (sd->menuskill_id != SG_FEEL)
  12719. return;
  12720. i = sd->menuskill_val-1;
  12721. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12722. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12723. sd->feel_map[i].m = sd->bl.m;
  12724. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12725. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12726. // clif_misceffect2(&sd->bl, 0x1b0);
  12727. // clif_misceffect2(&sd->bl, 0x21f);
  12728. clif_feel_info(sd, i, 0);
  12729. clif_menuskill_clear(sd);
  12730. }
  12731. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12732. /// 0253 <which>.B
  12733. /// which:
  12734. /// 0 = sun
  12735. /// 1 = moon
  12736. /// 2 = star
  12737. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12738. {
  12739. WFIFOHEAD(fd,packet_len(0x253));
  12740. WFIFOW(fd,0)=0x253;
  12741. WFIFOB(fd,2)=TOB(skill_lv-1);
  12742. WFIFOSET(fd, packet_len(0x253));
  12743. sd->menuskill_id = SG_FEEL;
  12744. sd->menuskill_val = skill_lv;
  12745. }
  12746. /// Request to change homunculus' name (CZ_RENAME_MER).
  12747. /// 0231 <name>.24B
  12748. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12749. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12750. }
  12751. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12752. /// 0234 <id>.L
  12753. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12754. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12755. struct block_list *bl = NULL;
  12756. struct unit_data *ud = NULL;
  12757. if( sd->md && sd->md->bl.id == id )
  12758. bl = &sd->md->bl;
  12759. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12760. bl = &sd->hd->bl; // Moving Homunculus
  12761. else
  12762. return;
  12763. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12764. ud = unit_bl2ud(bl);
  12765. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12766. }
  12767. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12768. /// 0232 <id>.L <position data>.3B
  12769. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12770. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12771. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12772. struct block_list *bl = NULL;
  12773. short x, y;
  12774. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12775. if( sd->md && sd->md->bl.id == id )
  12776. bl = &sd->md->bl; // Moving Mercenary
  12777. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12778. bl = &sd->hd->bl; // Moving Homunculus
  12779. else
  12780. return;
  12781. unit_walktoxy(bl, x, y, 4);
  12782. }
  12783. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12784. /// 0233 <id>.L <target id>.L <action>.B
  12785. /// action:
  12786. /// always 0
  12787. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12788. {
  12789. struct block_list *bl = NULL;
  12790. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12791. int id = RFIFOL(fd,info->pos[0]);
  12792. int target_id = RFIFOL(fd,info->pos[1]);
  12793. int action_type = RFIFOB(fd,info->pos[2]);
  12794. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12795. bl = &sd->hd->bl;
  12796. else if( sd->md && sd->md->bl.id == id )
  12797. bl = &sd->md->bl;
  12798. else return;
  12799. unit_stop_attack(bl);
  12800. unit_attack(bl, target_id, action_type != 0);
  12801. }
  12802. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12803. /// 022d <type>.W <command>.B
  12804. /// type:
  12805. /// always 0
  12806. /// command:
  12807. /// 0 = homunculus information
  12808. /// 1 = feed
  12809. /// 2 = delete
  12810. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12811. { //[orn]
  12812. int cmd = RFIFOW(fd,0);
  12813. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12814. if(!hom_is_active(sd->hd))
  12815. return;
  12816. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12817. }
  12818. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12819. /// 0292
  12820. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12821. {
  12822. pc_revive_item(sd);
  12823. }
  12824. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12825. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12826. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12827. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12828. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12829. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12830. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12831. void clif_check(int fd, struct map_session_data* pl_sd)
  12832. {
  12833. WFIFOHEAD(fd,packet_len(0x214));
  12834. WFIFOW(fd, 0) = 0x214;
  12835. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12836. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12837. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12838. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12839. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12840. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12841. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12842. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12843. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12844. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12845. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12846. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12847. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12848. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12849. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12850. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12851. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12852. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12853. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12854. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12855. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12856. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12857. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12858. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12859. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12860. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12861. WFIFOSET(fd,packet_len(0x214));
  12862. }
  12863. /// /check (CZ_REQ_STATUS_GM).
  12864. /// Request character's status values.
  12865. /// 0213 <char name>.24B
  12866. void clif_parse_Check(int fd, struct map_session_data *sd)
  12867. {
  12868. char charname[NAME_LENGTH];
  12869. struct map_session_data* pl_sd;
  12870. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12871. return;
  12872. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12873. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12874. {
  12875. return;
  12876. }
  12877. clif_check(fd, pl_sd);
  12878. }
  12879. /// MAIL SYSTEM
  12880. /// By Zephyrus
  12881. ///
  12882. /// Notification about the result of adding an item to mail
  12883. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12884. /// result:
  12885. /// 0 = success
  12886. /// 1 = failure
  12887. /// 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)
  12888. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12889. /// result:
  12890. /// 0 = success
  12891. /// 1 = over weight
  12892. /// 2 = fatal error
  12893. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  12894. int fd = sd->fd;
  12895. #if PACKETVER < 20150513
  12896. WFIFOHEAD(fd,packet_len(0x255));
  12897. WFIFOW(fd,0) = 0x255;
  12898. WFIFOW(fd,2) = index;
  12899. WFIFOB(fd,4) = flag;
  12900. WFIFOSET(fd,packet_len(0x255));
  12901. #else
  12902. struct PACKET_ZC_ADD_ITEM_TO_MAIL p;
  12903. if( flag ){
  12904. memset( &p, 0, sizeof( p ) );
  12905. }else{
  12906. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  12907. p.index = index;
  12908. p.count = amount;
  12909. p.itemId = client_nameid( item->nameid );
  12910. p.type = itemtype( item->nameid );
  12911. p.IsIdentified = item->identify ? 1 : 0;
  12912. p.IsDamaged = item->attribute ? 1 : 0;
  12913. p.refiningLevel = item->refine;
  12914. clif_addcards( &p.slot, item );
  12915. clif_add_random_options( p.optionData, item );
  12916. p.weight = 0;
  12917. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  12918. if( sd->mail.item[i].nameid == 0 ){
  12919. continue;
  12920. }
  12921. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12922. }
  12923. p.favorite = item->favorite;
  12924. p.location = pc_equippoint( sd, server_index( index ) );
  12925. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  12926. p.enchantgrade = item->enchantgrade;
  12927. #endif
  12928. }
  12929. p.PacketType = rodexadditem;
  12930. p.result = flag;
  12931. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  12932. #endif
  12933. }
  12934. /// Notification about the result of retrieving a mail attachment
  12935. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12936. /// result:
  12937. /// 0 = success
  12938. /// 1 = failure
  12939. /// 2 = too many items
  12940. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12941. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12942. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12943. #if PACKETVER < 20150513
  12944. int fd = sd->fd;
  12945. WFIFOHEAD(fd,packet_len(0x245));
  12946. WFIFOW(fd,0) = 0x245;
  12947. WFIFOB(fd,2) = result;
  12948. WFIFOSET(fd,packet_len(0x245));
  12949. #else
  12950. switch( type ){
  12951. case MAIL_ATT_ITEM:
  12952. case MAIL_ATT_ZENY:
  12953. break;
  12954. default:
  12955. return;
  12956. }
  12957. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  12958. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  12959. p.MailID = msg->id;
  12960. p.opentype = msg->type;
  12961. p.result = result;
  12962. clif_send(&p, sizeof(p), &sd->bl, SELF);
  12963. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12964. #endif
  12965. }
  12966. /// Notification about the result of sending a mail
  12967. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12968. /// result:
  12969. /// 0 = success
  12970. /// 1 = recipinent does not exist
  12971. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12972. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12973. #if PACKETVER < 20150513
  12974. int fd = sd->fd;
  12975. WFIFOHEAD(fd,packet_len(0x249));
  12976. WFIFOW(fd,0) = 0x249;
  12977. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12978. WFIFOSET(fd,packet_len(0x249));
  12979. #else
  12980. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  12981. p.PacketType = rodexwriteresult;
  12982. p.result = result;
  12983. clif_send(&p, sizeof(p), &sd->bl, SELF);
  12984. #endif
  12985. }
  12986. /// Notification about the result of deleting a mail.
  12987. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12988. /// result:
  12989. /// 0 = success
  12990. /// 1 = failure
  12991. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12992. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12993. #if PACKETVER < 20150513
  12994. int fd = sd->fd;
  12995. WFIFOHEAD(fd, packet_len(0x257));
  12996. WFIFOW(fd,0) = 0x257;
  12997. WFIFOL(fd,2) = msg->id;
  12998. WFIFOW(fd,6) = !success;
  12999. WFIFOSET(fd, packet_len(0x257));
  13000. #else
  13001. // This is only a success notification
  13002. if( success ){
  13003. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13004. p.PacketType = rodexdelete;
  13005. p.opentype = msg->type;
  13006. p.MailID = msg->id;
  13007. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13008. }
  13009. #endif
  13010. }
  13011. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13012. /// 0274 <mail id>.L <result>.W
  13013. /// result:
  13014. /// 0 = success
  13015. /// 1 = failure
  13016. void clif_Mail_return(int fd, int mail_id, short fail)
  13017. {
  13018. WFIFOHEAD(fd,packet_len(0x274));
  13019. WFIFOW(fd,0) = 0x274;
  13020. WFIFOL(fd,2) = mail_id;
  13021. WFIFOW(fd,6) = fail;
  13022. WFIFOSET(fd,packet_len(0x274));
  13023. }
  13024. /// Notification about new mail.
  13025. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13026. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13027. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13028. #if PACKETVER < 20150513
  13029. int fd = sd->fd;
  13030. WFIFOHEAD(fd,packet_len(0x24a));
  13031. WFIFOW(fd,0) = 0x24a;
  13032. WFIFOL(fd,2) = mail_id;
  13033. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13034. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13035. WFIFOSET(fd,packet_len(0x24a));
  13036. #else
  13037. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13038. p.PacketType = rodexicon;
  13039. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13040. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13041. #endif
  13042. }
  13043. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13044. /// 0260 <type>.L
  13045. /// type:
  13046. /// 0 = open
  13047. /// 1 = close
  13048. void clif_Mail_window(int fd, int flag)
  13049. {
  13050. WFIFOHEAD(fd,packet_len(0x260));
  13051. WFIFOW(fd,0) = 0x260;
  13052. WFIFOL(fd,2) = flag;
  13053. WFIFOSET(fd,packet_len(0x260));
  13054. }
  13055. /// Lists mails stored in inbox.
  13056. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13057. /// read:
  13058. /// 0 = unread
  13059. /// 1 = read
  13060. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13061. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13062. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13063. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13064. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13065. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13066. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13067. #if PACKETVER < 20150513
  13068. int fd = sd->fd;
  13069. struct mail_data *md = &sd->mail.inbox;
  13070. struct mail_message *msg;
  13071. int len, i, j;
  13072. len = 8 + (73 * md->amount);
  13073. WFIFOHEAD(fd,len);
  13074. WFIFOW(fd,0) = 0x240;
  13075. WFIFOW(fd,2) = len;
  13076. WFIFOL(fd,4) = md->amount;
  13077. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13078. {
  13079. msg = &md->msg[i];
  13080. if (msg->id < 1)
  13081. continue;
  13082. WFIFOL(fd,8+73*j) = msg->id;
  13083. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13084. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13085. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13086. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13087. j++;
  13088. }
  13089. WFIFOSET(fd,len);
  13090. if( md->full ) {// TODO: is this official?
  13091. char output[100];
  13092. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13093. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13094. }
  13095. #else
  13096. int fd = sd->fd;
  13097. struct mail_data *md = &sd->mail.inbox;
  13098. struct mail_message *msg;
  13099. int i, j, k, offset, titleLength;
  13100. uint8 mailType, amount, remaining;
  13101. uint32 now = (uint32)time(NULL);
  13102. #if PACKETVER >= 20170419
  13103. int cmd = 0xac2;
  13104. #elif PACKETVER >= 20160601
  13105. int cmd = 0xa7d;
  13106. #else
  13107. int cmd = 0x9f0;
  13108. #endif
  13109. if( battle_config.mail_daily_count ){
  13110. mail_refresh_remaining_amount(sd);
  13111. }
  13112. #if PACKETVER >= 20170419
  13113. // Always send all
  13114. i = md->amount;
  13115. #else
  13116. // If a starting mail id was sent
  13117. if( mailID != 0 ){
  13118. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13119. // Unknown mail
  13120. if( i == md->amount ){
  13121. // Ignore the request for now
  13122. return; // TODO: Should we just show the first page instead?
  13123. }
  13124. // It was actually the oldest/first mail, there is no further page
  13125. if( i == 0 ){
  13126. return;
  13127. }
  13128. // We actually want the next/older mail
  13129. i -= 1;
  13130. }else{
  13131. i = md->amount;
  13132. }
  13133. #endif
  13134. // Count the remaining mails from the starting mail or the beginning
  13135. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13136. for( j = i, remaining = 0; j >= 0; j-- ){
  13137. msg = &md->msg[j];
  13138. if (msg->id < 1)
  13139. continue;
  13140. #if PACKETVER < 20170419
  13141. if (msg->type != type)
  13142. continue;
  13143. #endif
  13144. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13145. continue;
  13146. remaining++;
  13147. }
  13148. #if PACKETVER >= 20170419
  13149. // Always send all
  13150. amount = remaining;
  13151. #else
  13152. if( remaining > MAIL_PAGE_SIZE ){
  13153. amount = MAIL_PAGE_SIZE;
  13154. }else{
  13155. amount = remaining;
  13156. }
  13157. #endif
  13158. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13159. WFIFOW(fd, 0) = cmd;
  13160. #if PACKETVER >= 20170419
  13161. WFIFOB(fd, 4) = 1; // Unknown
  13162. offset = 5;
  13163. #else
  13164. WFIFOB(fd, 4) = type;
  13165. WFIFOB(fd, 5) = amount;
  13166. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13167. offset = 7;
  13168. #endif
  13169. for( amount = 0; i >= 0; i-- ){
  13170. msg = &md->msg[i];
  13171. if (msg->id < 1)
  13172. continue;
  13173. #if PACKETVER < 20170419
  13174. if (msg->type != type)
  13175. continue;
  13176. #endif
  13177. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13178. continue;
  13179. #if PACKETVER >= 20170419
  13180. WFIFOB(fd, offset) = msg->type;
  13181. offset += 1;
  13182. #endif
  13183. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13184. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13185. mailType = MAIL_TYPE_TEXT; // Normal letter
  13186. if( msg->zeny > 0 ){
  13187. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13188. }
  13189. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13190. if( msg->item[k].nameid > 0 ){
  13191. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13192. break;
  13193. }
  13194. }
  13195. #if PACKETVER >= 20170419
  13196. // If it came from an npc?
  13197. if( !msg->send_id ){
  13198. mailType |= MAIL_TYPE_NPC;
  13199. }
  13200. #endif
  13201. WFIFOB(fd, offset + 9) = mailType;
  13202. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13203. #if PACKETVER < 20170419
  13204. // How much time has passed since you received the mail
  13205. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13206. offset += 4;
  13207. #endif
  13208. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13209. if( msg->scheduled_deletion > 0 ){
  13210. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13211. }else{
  13212. // Fake the scheduled deletion to one year in the future
  13213. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13214. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13215. }
  13216. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13217. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13218. offset += 40 + titleLength;
  13219. }
  13220. WFIFOW(fd, 2) = (int16)offset;
  13221. WFIFOSET(fd, offset);
  13222. #endif
  13223. }
  13224. /// Mail inbox list request.
  13225. /// 023f (CZ_MAIL_GET_LIST)
  13226. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13227. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13228. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13229. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13230. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13231. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13232. #if PACKETVER < 20150513
  13233. struct mail_data* md = &sd->mail.inbox;
  13234. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13235. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13236. else
  13237. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13238. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13239. mail_removezeny(sd, false);
  13240. #else
  13241. int cmd = RFIFOW(fd, 0);
  13242. #if PACKETVER < 20170419
  13243. uint8 openType = RFIFOB(fd, 2);
  13244. uint64 mailId = RFIFOQ(fd, 3);
  13245. #else
  13246. uint8 openType;
  13247. uint64 mailId = RFIFOQ(fd, 2);
  13248. int i;
  13249. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13250. if( i == MAIL_MAX_INBOX ){
  13251. openType = MAIL_INBOX_NORMAL;
  13252. mailId = 0;
  13253. }else{
  13254. openType = sd->mail.inbox.msg[i].type;
  13255. mailId = 0;
  13256. }
  13257. #endif
  13258. switch( openType ){
  13259. case MAIL_INBOX_NORMAL:
  13260. case MAIL_INBOX_ACCOUNT:
  13261. case MAIL_INBOX_RETURNED:
  13262. break;
  13263. default:
  13264. // Unknown type: ignore request
  13265. return;
  13266. }
  13267. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13268. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13269. return;
  13270. }
  13271. // If it is not a next page request
  13272. if( cmd != 0x9ee ){
  13273. mailId = 0;
  13274. }
  13275. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13276. #endif
  13277. }
  13278. /// Opens a mail
  13279. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13280. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13281. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13282. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13283. /// { }*n
  13284. // TODO: Packet description => for repeated block
  13285. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13286. int i, fd = sd->fd;
  13287. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13288. if( i == MAIL_MAX_INBOX ) {
  13289. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13290. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13291. return;
  13292. } else {
  13293. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13294. struct item *item;
  13295. struct item_data *data;
  13296. int msg_len = strlen(msg->body);
  13297. if( msg_len == 0 ) {
  13298. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13299. msg_len = strlen(msg->body);
  13300. }
  13301. #if PACKETVER < 20150513
  13302. item = &msg->item[0];
  13303. int len = 101 + msg_len;
  13304. WFIFOHEAD(fd,len);
  13305. WFIFOW(fd,0) = 0x242;
  13306. WFIFOW(fd,2) = len;
  13307. WFIFOL(fd,4) = msg->id;
  13308. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13309. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13310. WFIFOL(fd,72) = 0;
  13311. WFIFOL(fd,76) = msg->zeny;
  13312. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13313. WFIFOL(fd,80) = item->amount;
  13314. WFIFOW(fd,84) = client_nameid( item->nameid );
  13315. WFIFOW(fd,86) = itemtype( item->nameid );
  13316. WFIFOB(fd,88) = item->identify;
  13317. WFIFOB(fd,89) = item->attribute;
  13318. WFIFOB(fd,90) = item->refine;
  13319. WFIFOW(fd,91) = item->card[0];
  13320. WFIFOW(fd,93) = item->card[1];
  13321. WFIFOW(fd,95) = item->card[2];
  13322. WFIFOW(fd,97) = item->card[3];
  13323. } else // no item, set all to zero
  13324. memset(WFIFOP(fd,80), 0x00, 19);
  13325. WFIFOB(fd,99) = (unsigned char)msg_len;
  13326. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13327. WFIFOSET(fd,len);
  13328. #else
  13329. msg_len += 1; // Zero Termination
  13330. int length = sizeof( struct PACKET_ZC_READ_MAIL ) + MAIL_BODY_LENGTH + sizeof( struct mail_item ) * MAIL_MAX_ITEM;
  13331. WFIFOHEAD( fd, length );
  13332. struct PACKET_ZC_READ_MAIL *p = (struct PACKET_ZC_READ_MAIL *)WFIFOP( fd, 0 );
  13333. p->PacketType = rodexread;
  13334. p->PacketLength = length;
  13335. p->opentype = msg->type;
  13336. p->MailID = msg->id;
  13337. p->TextcontentsLength = msg_len;
  13338. p->zeny = msg->zeny;
  13339. int offset = sizeof( struct PACKET_ZC_READ_MAIL );
  13340. safestrncpy( WFIFOCP( fd, offset ), msg->body, msg_len );
  13341. offset += msg_len;
  13342. int count = 0;
  13343. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13344. item = &msg->item[j];
  13345. if( item->nameid > 0 && item->amount > 0 && ( data = itemdb_exists( item->nameid ) ) != NULL ){
  13346. struct mail_item* mailitem = (struct mail_item *)WFIFOP( fd, offset );
  13347. mailitem->ITID = client_nameid( item->nameid );
  13348. mailitem->count = item->amount;
  13349. mailitem->type = itemtype( item->nameid );
  13350. mailitem->IsIdentified = item->identify ? 1 : 0;
  13351. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13352. mailitem->refiningLevel = item->refine;
  13353. mailitem->location = pc_equippoint_sub( sd, data );
  13354. mailitem->viewSprite = data->look;
  13355. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13356. clif_addcards( &mailitem->slot, item );
  13357. clif_add_random_options( mailitem->optionData, item );
  13358. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13359. mailitem->enchantgrade = item->enchantgrade;
  13360. #endif
  13361. offset += sizeof( struct mail_item );
  13362. count++;
  13363. }
  13364. }
  13365. p->ItemCnt = count;
  13366. p->PacketLength = sizeof( struct PACKET_ZC_READ_MAIL ) + p->TextcontentsLength + sizeof( struct mail_item ) * p->ItemCnt;
  13367. WFIFOSET( fd, p->PacketLength );
  13368. #endif
  13369. if (msg->status == MAIL_UNREAD) {
  13370. msg->status = MAIL_READ;
  13371. intif_Mail_read(mail_id);
  13372. clif_parse_Mail_refreshinbox(fd, sd);
  13373. sd->mail.inbox.unread--;
  13374. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13375. }
  13376. }
  13377. }
  13378. /// Request to open a mail.
  13379. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13380. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13381. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13382. #if PACKETVER < 20150513
  13383. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13384. #else
  13385. //uint8 openType = RFIFOB(fd, 2);
  13386. int mail_id = (int)RFIFOQ(fd, 3);
  13387. #endif
  13388. if( mail_id <= 0 )
  13389. return;
  13390. if( mail_invalid_operation(sd) )
  13391. return;
  13392. clif_Mail_read(sd, mail_id);
  13393. }
  13394. /// Allow a player to begin writing a mail
  13395. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13396. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13397. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13398. p.PacketType = rodexopenwrite;
  13399. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13400. p.result = success;
  13401. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13402. }
  13403. /// Request to start writing a mail
  13404. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13405. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13406. char name[NAME_LENGTH];
  13407. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13408. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13409. clif_send_Mail_beginwrite_ack(sd, name, false);
  13410. return;
  13411. }
  13412. mail_clear(sd);
  13413. sd->state.mail_writing = true;
  13414. clif_send_Mail_beginwrite_ack(sd, name,true);
  13415. }
  13416. /// Notification that the client cancelled writing a mail
  13417. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13418. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13419. sd->state.mail_writing = false;
  13420. }
  13421. /// Give the client information about the recipient, if available
  13422. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13423. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13424. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13425. PACKET_ZC_CHECKNAME p = { 0 };
  13426. p.PacketType = rodexcheckplayer;
  13427. p.CharId = char_id;
  13428. p.Class = class_;
  13429. p.BaseLevel = level;
  13430. #if PACKETVER >= 20160302
  13431. strncpy(p.Name, name, NAME_LENGTH);
  13432. #endif
  13433. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13434. }
  13435. /// Request information about the recipient
  13436. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13437. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13438. static char name[NAME_LENGTH];
  13439. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13440. intif_mail_checkreceiver(sd, name);
  13441. }
  13442. /// Request to receive mail's attachment.
  13443. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13444. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13445. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13446. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13447. int i;
  13448. struct mail_message* msg;
  13449. #if PACKETVER < 20150513
  13450. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13451. int attachment = MAIL_ATT_ALL;
  13452. #else
  13453. uint16 packet_id = RFIFOW(fd, 0);
  13454. int mail_id = (int)RFIFOQ(fd, 2);
  13455. //int openType = RFIFOB(fd, 10);
  13456. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13457. #endif
  13458. if( !chrif_isconnected() )
  13459. return;
  13460. if( mail_id <= 0 )
  13461. return;
  13462. if( mail_invalid_operation(sd) )
  13463. return;
  13464. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13465. if( i == MAIL_MAX_INBOX )
  13466. return;
  13467. msg = &sd->mail.inbox.msg[i];
  13468. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13469. attachment &= ~MAIL_ATT_ZENY;
  13470. }
  13471. if( attachment&MAIL_ATT_ITEM ){
  13472. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13473. // No items were found
  13474. if( i == MAIL_MAX_ITEM ){
  13475. attachment &= ~MAIL_ATT_ITEM;
  13476. }
  13477. }
  13478. // Either no attachment requested at all or there are no zeny or items in the mail
  13479. if( attachment == MAIL_ATT_NONE ){
  13480. return;
  13481. }
  13482. if( attachment&MAIL_ATT_ZENY ){
  13483. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13484. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13485. return;
  13486. }else{
  13487. // Store the pending zeny (required for the "retrieve all" feature)
  13488. sd->mail.pending_zeny += msg->zeny;
  13489. // To make sure another request fails
  13490. msg->zeny = 0;
  13491. }
  13492. }
  13493. if( attachment&MAIL_ATT_ITEM ){
  13494. int slots = 0, totalweight = 0;
  13495. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13496. struct item* item = &msg->item[i];
  13497. if( item->nameid > 0 && item->amount > 0 ){
  13498. struct item_data *data;
  13499. if((data = itemdb_exists(item->nameid)) == NULL)
  13500. continue;
  13501. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13502. case CHKADDITEM_NEW:
  13503. slots += data->inventorySlotNeeded( item->amount );
  13504. break;
  13505. case CHKADDITEM_OVERAMOUNT:
  13506. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13507. return;
  13508. }
  13509. totalweight += data->weight * item->amount;
  13510. }
  13511. }
  13512. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13513. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13514. return;
  13515. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13516. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13517. return;
  13518. }
  13519. // To make sure another request fails
  13520. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13521. // Store the pending weight (required for the "retrieve all" feature)
  13522. sd->mail.pending_weight += totalweight;
  13523. // Store the pending slots (required for the "retrieve all" feature)
  13524. sd->mail.pending_slots += slots;
  13525. }
  13526. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13527. }
  13528. /// Request to delete a mail.
  13529. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13530. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13531. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13532. #if PACKETVER < 20150513
  13533. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13534. #else
  13535. //int openType = RFIFOB(fd, 2);
  13536. int mail_id = (int)RFIFOQ(fd, 3);
  13537. #endif
  13538. int i, j;
  13539. if( !chrif_isconnected() )
  13540. return;
  13541. if( mail_id <= 0 )
  13542. return;
  13543. if( mail_invalid_operation(sd) )
  13544. return;
  13545. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13546. if (i < MAIL_MAX_INBOX) {
  13547. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13548. // can't delete mail without removing zeny first
  13549. if( msg->zeny > 0 ){
  13550. clif_mail_delete(sd, msg, false);
  13551. return;
  13552. }
  13553. // can't delete mail without removing attachment(s) first
  13554. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13555. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13556. clif_mail_delete(sd, msg, false);
  13557. return;
  13558. }
  13559. }
  13560. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13561. sd->mail.inbox.unread--;
  13562. clif_Mail_new(sd,0,NULL,NULL);
  13563. }
  13564. }
  13565. }
  13566. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13567. /// 0273 <mail id>.L <receive name>.24B
  13568. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13569. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13570. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13571. int i;
  13572. if( mail_id <= 0 )
  13573. return;
  13574. if( mail_invalid_operation(sd) )
  13575. return;
  13576. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13577. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13578. intif_Mail_return(sd->status.char_id, mail_id);
  13579. else
  13580. clif_Mail_return(sd->fd, mail_id, 1);
  13581. }
  13582. /// Request to add an item or Zeny to mail.
  13583. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13584. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13585. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13586. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13587. uint16 idx = RFIFOW(fd,info->pos[0]);
  13588. #if PACKETVER < 20150513
  13589. int amount = RFIFOL(fd,info->pos[1]);
  13590. #else
  13591. int amount = RFIFOW(fd,info->pos[1]);
  13592. #endif
  13593. unsigned char flag;
  13594. if( !chrif_isconnected() )
  13595. return;
  13596. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13597. return;
  13598. if (sd->inventory_data[server_index(idx)] == nullptr)
  13599. return;
  13600. flag = mail_setitem(sd, idx, amount);
  13601. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13602. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13603. }else{
  13604. clif_Mail_setattachment(sd,idx,amount,flag);
  13605. }
  13606. }
  13607. /// Remove an item from a mail
  13608. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13609. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13610. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13611. p.PacketType = rodexremoveitem;
  13612. p.result = success;
  13613. p.index = index;
  13614. p.cnt = amount;
  13615. int total = 0;
  13616. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13617. if( sd->mail.item[i].nameid == 0 ){
  13618. break;
  13619. }
  13620. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13621. }
  13622. p.weight = total;
  13623. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13624. }
  13625. /// Request to reset mail item and/or Zeny
  13626. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13627. /// type:
  13628. /// 0 = reset all
  13629. /// 1 = remove item
  13630. /// 2 = remove zeny
  13631. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13632. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13633. {
  13634. #if PACKETVER < 20150513
  13635. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13636. if (type == 0 || type == 1)
  13637. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13638. if (type == 0 || type == 2)
  13639. mail_removezeny(sd, false);
  13640. #else
  13641. uint16 index = RFIFOW(fd, 2);
  13642. uint16 count = RFIFOW(fd, 4);
  13643. mail_removeitem(sd,0,index,count);
  13644. #endif
  13645. }
  13646. /// Request to send mail
  13647. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13648. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13649. /// 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)
  13650. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13651. #if PACKETVER < 20150513
  13652. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13653. if( !chrif_isconnected() )
  13654. return;
  13655. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13656. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13657. return;
  13658. }
  13659. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13660. #else
  13661. uint16 length = RFIFOW(fd, 2);
  13662. if( length < 0x3e ){
  13663. ShowWarning("Too short...\n");
  13664. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13665. return;
  13666. }
  13667. // Forged request without a begin writing packet?
  13668. if( !sd->state.mail_writing ){
  13669. return; // Ignore it
  13670. }
  13671. char receiver[NAME_LENGTH];
  13672. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13673. // char sender[NAME_LENGTH];
  13674. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13675. uint64 zeny = RFIFOQ(fd, 52);
  13676. uint16 titleLength = RFIFOW(fd, 60);
  13677. uint16 textLength = RFIFOW(fd, 62);
  13678. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13679. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13680. char title[MAIL_TITLE_LENGTH];
  13681. char text[MAIL_BODY_LENGTH];
  13682. #if PACKETVER <= 20160330
  13683. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13684. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13685. #else
  13686. // 64 = <char id>.L
  13687. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13688. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13689. #endif
  13690. if( zeny > 0 ){
  13691. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13692. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13693. return;
  13694. }
  13695. }
  13696. mail_send(sd, receiver, title, text, realTextLength);
  13697. #endif
  13698. }
  13699. /// AUCTION SYSTEM
  13700. /// By Zephyrus
  13701. ///
  13702. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13703. /// 025f <type>.L
  13704. /// type:
  13705. /// 0 = open
  13706. /// 1 = close
  13707. void clif_Auction_openwindow(struct map_session_data *sd)
  13708. {
  13709. int fd = sd->fd;
  13710. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13711. return;
  13712. if( !battle_config.feature_auction )
  13713. return;
  13714. WFIFOHEAD(fd,packet_len(0x25f));
  13715. WFIFOW(fd,0) = 0x25f;
  13716. WFIFOL(fd,2) = 0;
  13717. WFIFOSET(fd,packet_len(0x25f));
  13718. }
  13719. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13720. /// 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 }*
  13721. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13722. {
  13723. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13724. struct auction_data auction;
  13725. WFIFOHEAD(fd,12 + (count * 83));
  13726. WFIFOW(fd,0) = 0x252;
  13727. WFIFOW(fd,2) = 12 + (count * 83);
  13728. WFIFOL(fd,4) = pages;
  13729. WFIFOL(fd,8) = count;
  13730. for( i = 0; i < count; i++ ) {
  13731. int k = 12 + (i * 83);
  13732. memcpy(&auction, RBUFP(buf,i * len), len);
  13733. WFIFOL(fd,k) = auction.auction_id;
  13734. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13735. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13736. WFIFOL(fd,30+k) = auction.type;
  13737. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13738. WFIFOB(fd,36+k) = auction.item.identify;
  13739. WFIFOB(fd,37+k) = auction.item.attribute;
  13740. WFIFOB(fd,38+k) = auction.item.refine;
  13741. WFIFOW(fd,39+k) = auction.item.card[0];
  13742. WFIFOW(fd,41+k) = auction.item.card[1];
  13743. WFIFOW(fd,43+k) = auction.item.card[2];
  13744. WFIFOW(fd,45+k) = auction.item.card[3];
  13745. WFIFOL(fd,47+k) = auction.price;
  13746. WFIFOL(fd,51+k) = auction.buynow;
  13747. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13748. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13749. }
  13750. WFIFOSET(fd,WFIFOW(fd,2));
  13751. }
  13752. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13753. /// 0256 <index>.W <result>.B
  13754. /// result:
  13755. /// 0 = success
  13756. /// 1 = failure
  13757. static void clif_Auction_setitem(int fd, int index, bool fail)
  13758. {
  13759. WFIFOHEAD(fd,packet_len(0x256));
  13760. WFIFOW(fd,0) = 0x256;
  13761. WFIFOW(fd,2) = index;
  13762. WFIFOB(fd,4) = fail;
  13763. WFIFOSET(fd,packet_len(0x256));
  13764. }
  13765. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13766. /// 024b <type>.W
  13767. /// type:
  13768. /// 0 = create (any other action in auction window)
  13769. /// 1 = cancel (cancel pressed on register tab)
  13770. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13771. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13772. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13773. if( sd->auction.amount > 0 )
  13774. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13775. sd->auction.amount = 0;
  13776. }
  13777. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13778. /// 024c <index>.W <count>.L
  13779. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13780. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13781. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13782. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13783. struct item_data *item;
  13784. if( !battle_config.feature_auction )
  13785. return;
  13786. if( sd->auction.amount > 0 )
  13787. sd->auction.amount = 0;
  13788. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13789. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13790. return;
  13791. }
  13792. 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.
  13793. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13794. return;
  13795. }
  13796. 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) )
  13797. { // Consumable or pets are not allowed
  13798. clif_Auction_setitem(sd->fd, idx, true);
  13799. return;
  13800. }
  13801. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13802. !sd->inventory.u.items_inventory[idx].identify ||
  13803. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13804. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13805. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13806. clif_Auction_setitem(sd->fd, idx, true);
  13807. return;
  13808. }
  13809. sd->auction.index = idx;
  13810. sd->auction.amount = amount;
  13811. clif_Auction_setitem(fd, idx + 2, false);
  13812. }
  13813. /// Result from an auction action (ZC_AUCTION_RESULT).
  13814. /// 0250 <result>.B
  13815. /// result:
  13816. /// 0 = You have failed to bid into the auction
  13817. /// 1 = You have successfully bid in the auction
  13818. /// 2 = The auction has been canceled
  13819. /// 3 = An auction with at least one bidder cannot be canceled
  13820. /// 4 = You cannot register more than 5 items in an auction at a time
  13821. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13822. /// 6 = You have won the auction
  13823. /// 7 = You have failed to win the auction
  13824. /// 8 = You do not have enough Zeny
  13825. /// 9 = You cannot place more than 5 bids at a time
  13826. void clif_Auction_message(int fd, unsigned char flag)
  13827. {
  13828. WFIFOHEAD(fd,packet_len(0x250));
  13829. WFIFOW(fd,0) = 0x250;
  13830. WFIFOB(fd,2) = flag;
  13831. WFIFOSET(fd,packet_len(0x250));
  13832. }
  13833. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13834. /// 025e <result>.W
  13835. /// result:
  13836. /// 0 = You have ended the auction
  13837. /// 1 = You cannot end the auction
  13838. /// 2 = Auction ID is incorrect
  13839. void clif_Auction_close(int fd, unsigned char flag)
  13840. {
  13841. WFIFOHEAD(fd,packet_len(0x25e));
  13842. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13843. WFIFOW(fd,2) = flag;
  13844. WFIFOSET(fd,packet_len(0x25e));
  13845. }
  13846. /// Request to add an auction (CZ_AUCTION_ADD).
  13847. /// 024d <now money>.L <max money>.L <delete hour>.W
  13848. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13849. {
  13850. struct auction_data auction;
  13851. struct item_data *item;
  13852. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13853. if( !battle_config.feature_auction )
  13854. return;
  13855. auction.price = RFIFOL(fd,info->pos[0]);
  13856. auction.buynow = RFIFOL(fd,info->pos[1]);
  13857. auction.hours = RFIFOW(fd,info->pos[2]);
  13858. // Invalid Situations...
  13859. if( sd->auction.amount < 1 ) {
  13860. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13861. return;
  13862. }
  13863. if( auction.price >= auction.buynow ) {
  13864. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13865. return;
  13866. }
  13867. if( auction.hours < 1 || auction.hours > 48 ) {
  13868. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13869. return;
  13870. }
  13871. // Auction checks...
  13872. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13873. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13874. clif_Auction_message(fd, 2); // The auction has been canceled
  13875. return;
  13876. }
  13877. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13878. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13879. return;
  13880. }
  13881. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13882. auction.buynow = battle_config.auction_maximumprice;
  13883. if( auction.price >= auction.buynow )
  13884. auction.price = auction.buynow - 1;
  13885. }
  13886. auction.auction_id = 0;
  13887. auction.seller_id = sd->status.char_id;
  13888. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13889. auction.buyer_id = 0;
  13890. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13891. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13892. {
  13893. clif_Auction_message(fd, 2); // The auction has been canceled
  13894. return;
  13895. }
  13896. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13897. { // Just in case
  13898. clif_Auction_message(fd, 2); // The auction has been canceled
  13899. return;
  13900. }
  13901. safestrncpy(auction.item_name, item->ename.c_str(), sizeof(auction.item_name));
  13902. auction.type = item->type;
  13903. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13904. auction.item.amount = 1;
  13905. auction.timestamp = 0;
  13906. if( !intif_Auction_register(&auction) )
  13907. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13908. else
  13909. {
  13910. int zeny = auction.hours*battle_config.auction_feeperhour;
  13911. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13912. sd->auction.amount = 0;
  13913. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13914. }
  13915. }
  13916. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13917. /// 024e <auction id>.L
  13918. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13919. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13920. intif_Auction_cancel(sd->status.char_id, auction_id);
  13921. }
  13922. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13923. /// 025d <auction id>.L
  13924. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13925. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13926. intif_Auction_close(sd->status.char_id, auction_id);
  13927. }
  13928. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13929. /// 024f <auction id>.L <money>.L
  13930. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13931. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13932. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13933. int bid = RFIFOL(fd,info->pos[1]);
  13934. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13935. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13936. return;
  13937. }
  13938. if( bid <= 0 )
  13939. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13940. else if( bid > sd->status.zeny )
  13941. clif_Auction_message(fd, 8); // You do not have enough zeny
  13942. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13943. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13944. else {
  13945. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13946. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13947. }
  13948. }
  13949. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13950. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13951. /// search type:
  13952. /// 0 = armor
  13953. /// 1 = weapon
  13954. /// 2 = card
  13955. /// 3 = misc
  13956. /// 4 = name search
  13957. /// 5 = auction id search
  13958. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13959. char search_text[NAME_LENGTH];
  13960. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13961. short type = RFIFOW(fd,info->pos[0]);
  13962. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13963. int page = RFIFOW(fd,info->pos[3]);
  13964. if( !battle_config.feature_auction )
  13965. return;
  13966. clif_parse_Auction_cancelreg(fd, sd);
  13967. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13968. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13969. }
  13970. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13971. /// 025c <type>.W
  13972. /// type:
  13973. /// 0 = sell (own auctions)
  13974. /// 1 = buy (own bids)
  13975. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13976. {
  13977. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13978. if( !battle_config.feature_auction )
  13979. return;
  13980. clif_parse_Auction_cancelreg(fd, sd);
  13981. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13982. }
  13983. /// CASH/POINT SHOP
  13984. ///
  13985. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  13986. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  13987. nullpo_retv( sd );
  13988. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  13989. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  13990. p.cashPoints = sd->cashPoints;
  13991. p.kafraPoints = sd->kafraPoints;
  13992. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  13993. p.tab = tab;
  13994. #endif
  13995. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13996. #endif
  13997. }
  13998. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13999. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14000. nullpo_retv( sd );
  14001. int tab = 0;
  14002. #if PACKETVER >= 20191224
  14003. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14004. tab = p->tab;
  14005. #endif
  14006. sd->state.cashshop_open = true;
  14007. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14008. clif_cashshop_open( sd, tab );
  14009. #endif
  14010. }
  14011. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14012. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14013. sd->state.cashshop_open = false;
  14014. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14015. // No need to do anything here
  14016. #endif
  14017. }
  14018. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14019. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14020. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14021. // [4144] packet exists only in 2011 and was dropped after
  14022. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14023. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14024. int j;
  14025. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14026. return;
  14027. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14028. WFIFOW(fd, 0) = 0x8c0;
  14029. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14030. WFIFOL(fd, 4) = tab;
  14031. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14032. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14033. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14034. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14035. }
  14036. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14037. #endif
  14038. }
  14039. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14040. void clif_cashshop_list( struct map_session_data* sd ){
  14041. nullpo_retv( sd );
  14042. int fd = sd->fd;
  14043. if( !session_isActive( fd ) ){
  14044. return;
  14045. }
  14046. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14047. // Skip empty tabs, the client only expects filled ones
  14048. if( cash_shop_items[tab].count == 0 ){
  14049. continue;
  14050. }
  14051. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14052. WFIFOHEAD( fd, len );
  14053. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14054. p->packetType = 0x8ca;
  14055. p->packetLength = len;
  14056. p->count = cash_shop_items[tab].count;
  14057. p->tabNum = tab;
  14058. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14059. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14060. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14061. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14062. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14063. if( id == nullptr ){
  14064. p->items[i].location = 0;
  14065. p->items[i].viewSprite = 0;
  14066. }else{
  14067. p->items[i].location = pc_equippoint_sub( sd, id );
  14068. p->items[i].viewSprite = id->look;
  14069. }
  14070. #endif
  14071. }
  14072. WFIFOSET( fd, len );
  14073. }
  14074. }
  14075. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14076. if( !sd->status.cashshop_sent ) {
  14077. clif_cashshop_list( sd );
  14078. #if PACKETVER_SUPPORTS_SALES
  14079. sale_notify_login(sd);
  14080. #endif
  14081. sd->status.cashshop_sent = true;
  14082. }
  14083. }
  14084. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14085. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14086. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14087. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14088. nullpo_retv( sd );
  14089. nullpo_retv( nd );
  14090. int fd = sd->fd;
  14091. if( !session_isActive( fd ) ){
  14092. return;
  14093. }
  14094. sd->npc_shopid = nd->bl.id;
  14095. int cost[2] = { 0, 0 };
  14096. npc_shop_currency_type( sd, nd, cost, true );
  14097. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14098. WFIFOHEAD( fd, len );
  14099. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14100. p->packetType = 0x287;
  14101. p->packetLength = len;
  14102. p->cashPoints = cost[0];
  14103. #if PACKETVER >= 20070711
  14104. p->kafraPoints = cost[1];
  14105. #endif
  14106. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14107. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14108. p->items[i].price = nd->u.shop.shop_item[i].value;
  14109. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14110. p->items[i].itemType = itemtype( id->nameid );
  14111. p->items[i].itemId = client_nameid( id->nameid );
  14112. }
  14113. WFIFOSET( fd, len );
  14114. }
  14115. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14116. /// 0289 <cash point>.L <error>.W
  14117. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14118. /// error:
  14119. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14120. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14121. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14122. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14123. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14124. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14125. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14126. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14127. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14128. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14129. {
  14130. int fd, cost[2] = { 0, 0 };
  14131. struct npc_data *nd;
  14132. nullpo_retv(sd);
  14133. fd = sd->fd;
  14134. nd = map_id2nd(sd->npc_shopid);
  14135. npc_shop_currency_type(sd, nd, cost, false);
  14136. WFIFOHEAD(fd, packet_len(0x289));
  14137. WFIFOW(fd,0) = 0x289;
  14138. WFIFOL(fd,2) = cost[0];
  14139. #if PACKETVER < 20070711
  14140. WFIFOW(fd,6) = TOW(error);
  14141. #else
  14142. WFIFOL(fd,6) = cost[1];
  14143. WFIFOW(fd,10) = TOW(error);
  14144. #endif
  14145. WFIFOSET(fd, packet_len(0x289));
  14146. }
  14147. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14148. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14149. nullpo_retv( sd );
  14150. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14151. packet.packetType = 0x849;
  14152. if( item_id != 0 ){
  14153. packet.itemId = client_nameid( item_id );
  14154. }else{
  14155. packet.itemId = 0;
  14156. }
  14157. packet.result = result;
  14158. packet.cashPoints = sd->cashPoints;
  14159. packet.kafraPoints = sd->kafraPoints;
  14160. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14161. #endif
  14162. }
  14163. /// Request to buy item(s) from cash shop.
  14164. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14165. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14166. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14167. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14168. nullpo_retv( sd );
  14169. if( sd->state.trading || !sd->npc_shopid ){
  14170. clif_cashshop_ack( sd, 1 );
  14171. return;
  14172. }
  14173. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14174. #if PACKETVER < 20070711
  14175. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14176. #elif PACKETVER < 20101116
  14177. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14178. #else
  14179. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14180. 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 ){
  14181. 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 );
  14182. return;
  14183. }
  14184. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, p->count, p->items ) );
  14185. #endif
  14186. }
  14187. /// Request to buy item(s) from cash shop.
  14188. /// 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)
  14189. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14190. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14191. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14192. 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 ){
  14193. 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 );
  14194. return;
  14195. }
  14196. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14197. }
  14198. /// Adoption System
  14199. ///
  14200. /// Adoption message (ZC_BABYMSG).
  14201. /// 0216 <msg>.L
  14202. /// msg:
  14203. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14204. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14205. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14206. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14207. {
  14208. int fd = sd->fd;
  14209. WFIFOHEAD(fd,6);
  14210. WFIFOW(fd,0) = 0x216;
  14211. WFIFOL(fd,2) = type;
  14212. WFIFOSET(fd,6);
  14213. }
  14214. /// Adoption confirmation (ZC_REQ_BABY).
  14215. /// 01f6 <account id>.L <char id>.L <name>.B
  14216. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14217. {
  14218. int fd = sd->fd;
  14219. WFIFOHEAD(fd,34);
  14220. WFIFOW(fd,0) = 0x1f6;
  14221. WFIFOL(fd,2) = src->status.account_id;
  14222. WFIFOL(fd,6) = p_id;
  14223. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14224. WFIFOSET(fd,34);
  14225. }
  14226. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14227. /// 01f9 <account id>.L
  14228. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14229. {
  14230. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14231. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14232. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14233. {
  14234. tsd->adopt_invite = sd->status.account_id;
  14235. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14236. }
  14237. }
  14238. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14239. /// 01f7 <account id>.L <char id>.L <answer>.L
  14240. /// answer:
  14241. /// 0 = rejected
  14242. /// 1 = accepted
  14243. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14244. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14245. int p1_id = RFIFOL(fd,info->pos[0]);
  14246. int p2_id = RFIFOL(fd,info->pos[1]);
  14247. int result = RFIFOL(fd,info->pos[2]);
  14248. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14249. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14250. int pid = sd->adopt_invite;
  14251. sd->adopt_invite = 0;
  14252. if( p1_sd == NULL || p2_sd == NULL )
  14253. return; // Both players need to be online
  14254. if( pid != p1_sd->status.account_id )
  14255. return; // Incorrect values
  14256. if( result == 0 )
  14257. return; // Rejected
  14258. pc_adoption(p1_sd, p2_sd, sd);
  14259. }
  14260. /// Convex Mirror (ZC_BOSS_INFO).
  14261. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14262. /// infoType:
  14263. /// BOSS_INFO_NOT = No boss on this map.
  14264. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14265. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14266. /// BOSS_INFO_DEAD = Boss is dead.
  14267. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14268. {
  14269. int fd = sd->fd;
  14270. WFIFOHEAD(fd,70);
  14271. memset(WFIFOP(fd,0),0,70);
  14272. WFIFOW(fd,0) = 0x293;
  14273. switch (flag) {
  14274. case BOSS_INFO_NOT:
  14275. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14276. // No data required
  14277. break;
  14278. case BOSS_INFO_ALIVE:
  14279. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14280. // Update X/Y
  14281. WFIFOL(fd,3) = md->bl.x;
  14282. WFIFOL(fd,7) = md->bl.y;
  14283. break;
  14284. case BOSS_INFO_ALIVE_WITHMSG:
  14285. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14286. // Current X/Y
  14287. WFIFOL(fd,3) = md->bl.x;
  14288. WFIFOL(fd,7) = md->bl.y;
  14289. break;
  14290. case BOSS_INFO_DEAD:
  14291. {
  14292. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14293. unsigned int seconds;
  14294. int hours, minutes;
  14295. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14296. hours = seconds / (60 * 60);
  14297. seconds = seconds - (60 * 60 * hours);
  14298. minutes = seconds / 60;
  14299. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14300. // Add respawn info
  14301. WFIFOW(fd,11) = hours; // Hours
  14302. WFIFOW(fd,13) = minutes; // Minutes
  14303. }
  14304. break;
  14305. }
  14306. if (md != NULL)
  14307. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14308. WFIFOSET(fd,70);
  14309. }
  14310. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14311. /// 02d6 <account id>.L
  14312. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14313. {
  14314. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14315. struct map_session_data* tsd = map_id2sd(aid);
  14316. if (!tsd)
  14317. return;
  14318. if (sd->bl.m != tsd->bl.m)
  14319. return;
  14320. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14321. clif_viewequip_ack(sd, tsd);
  14322. else
  14323. clif_msg(sd, VIEW_EQUIP_FAIL);
  14324. }
  14325. /// Request to a configuration.
  14326. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14327. /// type: see enum e_config_type
  14328. /// flag:
  14329. /// false = disabled
  14330. /// true = enabled
  14331. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14332. int cmd = RFIFOW(fd,0);
  14333. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14334. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14335. switch( type ){
  14336. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14337. sd->status.show_equip = flag;
  14338. break;
  14339. case CONFIG_PET_AUTOFEED:
  14340. // Player can not click this if he does not have a pet
  14341. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14342. return;
  14343. }
  14344. sd->pd->pet.autofeed = flag;
  14345. break;
  14346. case CONFIG_HOMUNCULUS_AUTOFEED:
  14347. // Player can not click this if he does not have a homunculus or it is vaporized
  14348. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14349. return;
  14350. }
  14351. sd->hd->homunculus.autofeed = flag;
  14352. break;
  14353. default:
  14354. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14355. return;
  14356. }
  14357. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14358. }
  14359. /// Request to change party invitation tick.
  14360. /// value:
  14361. /// 0 = disabled
  14362. /// 1 = enabled
  14363. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14364. {
  14365. bool flag = RFIFOB(fd,6) ? true : false;
  14366. sd->status.allow_party = flag;
  14367. clif_partytickack(sd, flag);
  14368. }
  14369. /// Questlog System [Kevin] [Inkfish]
  14370. ///
  14371. /**
  14372. * Safe check to init packet len & quest num for player.
  14373. * @param def_len
  14374. * @param info_len Length of each quest info.
  14375. * @param avail_quests Avail quests that player has.
  14376. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14377. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14378. **/
  14379. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14380. (*limit_out) = (0xFFFF - def_len) / info_len;
  14381. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14382. (*len_out) = ((*limit_out) * info_len) + def_len;
  14383. }
  14384. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14385. std::string race_name;
  14386. switch( objective->race ){
  14387. case RC_FORMLESS: race_name = "Formless"; break;
  14388. case RC_UNDEAD: race_name = "Undead"; break;
  14389. case RC_BRUTE: race_name = "Brute"; break;
  14390. case RC_PLANT: race_name = "Plant"; break;
  14391. case RC_INSECT: race_name = "Insect"; break;
  14392. case RC_FISH: race_name = "Fish"; break;
  14393. case RC_DEMON: race_name = "Demon"; break;
  14394. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14395. case RC_ANGEL: race_name = "Angel"; break;
  14396. case RC_DRAGON: race_name = "Dragon"; break;
  14397. default:
  14398. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14399. // Fallthrough
  14400. case RC_ALL: race_name = ""; break;
  14401. }
  14402. std::string size_name;
  14403. switch( objective->size ){
  14404. case SZ_SMALL: size_name = "Small"; break;
  14405. case SZ_MEDIUM: size_name = "Medium"; break;
  14406. case SZ_BIG: size_name = "Large"; break;
  14407. default:
  14408. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14409. // Fallthrough
  14410. case SZ_ALL: size_name = ""; break;
  14411. }
  14412. std::string ele_name;
  14413. switch( objective->element ){
  14414. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14415. case ELE_WATER: ele_name = "Water Element"; break;
  14416. case ELE_EARTH: ele_name = "Earth Element"; break;
  14417. case ELE_FIRE: ele_name = "Fire Element"; break;
  14418. case ELE_WIND: ele_name = "Wind Element"; break;
  14419. case ELE_POISON: ele_name = "Poison Element"; break;
  14420. case ELE_HOLY: ele_name = "Holy Element"; break;
  14421. case ELE_DARK: ele_name = "Shadow Element"; break;
  14422. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14423. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14424. default:
  14425. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14426. // Fallthrough
  14427. case ELE_ALL: ele_name = ""; break;
  14428. }
  14429. std::string str;
  14430. if( !objective->map_name.empty() ){
  14431. str += objective->map_name;
  14432. }
  14433. if( !race_name.empty() ){
  14434. if( !str.empty() ){
  14435. str += ", ";
  14436. }
  14437. str += race_name;
  14438. }
  14439. if( !size_name.empty() ){
  14440. if( !str.empty() ){
  14441. str += ", ";
  14442. }
  14443. str += size_name;
  14444. }
  14445. if( !ele_name.empty() ){
  14446. if( !str.empty() ){
  14447. str += ", ";
  14448. }
  14449. str += ele_name;
  14450. }
  14451. return str;
  14452. }
  14453. /// Sends list of all quest states
  14454. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14455. /// 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)
  14456. /// 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)
  14457. void clif_quest_send_list(struct map_session_data *sd)
  14458. {
  14459. nullpo_retv(sd);
  14460. int fd = sd->fd;
  14461. int i;
  14462. int offset = 8;
  14463. int limit = 0;
  14464. #if PACKETVER >= 20141022
  14465. #if PACKETVER >= 20150513
  14466. int size = 22 + NAME_LENGTH;
  14467. #else
  14468. int size = 10 + NAME_LENGTH;
  14469. #endif
  14470. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14471. WFIFOHEAD(fd,i);
  14472. #if PACKETVER >= 20150513
  14473. WFIFOW(fd, 0) = 0x9f8;
  14474. #else
  14475. WFIFOW(fd, 0) = 0x97a;
  14476. #endif
  14477. WFIFOL(fd, 4) = limit;
  14478. for (i = 0; i < limit; i++) {
  14479. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14480. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14481. offset += 4;
  14482. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14483. offset++;
  14484. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14485. offset += 4;
  14486. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14487. offset += 4;
  14488. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14489. offset += 2;
  14490. if (!qi->objectives.empty()) {
  14491. std::shared_ptr<s_mob_db> mob;
  14492. for (int j = 0; j < qi->objectives.size(); j++) {
  14493. mob = mob_db.find(qi->objectives[j]->mob_id);
  14494. e_race race = qi->objectives[j]->race;
  14495. e_size size = qi->objectives[j]->size;
  14496. e_element element = qi->objectives[j]->element;
  14497. #if PACKETVER >= 20150513
  14498. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14499. offset += 4;
  14500. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14501. offset += 4;
  14502. #endif
  14503. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14504. offset += 4;
  14505. #if PACKETVER >= 20150513
  14506. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14507. offset += 2;
  14508. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14509. offset += 2;
  14510. #endif
  14511. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14512. offset += 2;
  14513. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14514. offset += 2;
  14515. if (mob && qi->objectives[j]->mob_id > 0)
  14516. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14517. else
  14518. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14519. offset += NAME_LENGTH;
  14520. }
  14521. }
  14522. }
  14523. WFIFOW(fd, 2) = offset;
  14524. WFIFOSET(fd, offset);
  14525. #else
  14526. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14527. WFIFOHEAD(fd,i);
  14528. WFIFOW(fd, 0) = 0x2b1;
  14529. WFIFOL(fd, 4) = limit;
  14530. for (i = 0; i < limit; i++) {
  14531. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14532. offset += 4;
  14533. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14534. offset += 1;
  14535. }
  14536. WFIFOW(fd, 2) = offset;
  14537. WFIFOSET(fd, offset);
  14538. #endif
  14539. }
  14540. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14541. /// 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
  14542. void clif_quest_send_mission(struct map_session_data *sd)
  14543. {
  14544. nullpo_retv(sd);
  14545. int fd = sd->fd;
  14546. int limit = 0;
  14547. int len = sd->avail_quests*104+8;
  14548. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14549. WFIFOHEAD(fd, len);
  14550. WFIFOW(fd, 0) = 0x2b2;
  14551. WFIFOW(fd, 2) = len;
  14552. WFIFOL(fd, 4) = limit;
  14553. for (int i = 0; i < limit; i++) {
  14554. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14555. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14556. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14557. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14558. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14559. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14560. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14561. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14562. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14563. if (mob && qi->objectives[j]->mob_id > 0)
  14564. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14565. else
  14566. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14567. }
  14568. }
  14569. WFIFOSET(fd, len);
  14570. }
  14571. /// Notification about a new quest
  14572. /// 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)
  14573. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14574. /// 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)
  14575. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14576. {
  14577. nullpo_retv(sd);
  14578. nullpo_retv(qd);
  14579. int fd = sd->fd;
  14580. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14581. if (!qi)
  14582. return;
  14583. #if PACKETVER >= 20150513
  14584. int cmd = 0x9f9;
  14585. #else
  14586. int cmd = 0x2b3;
  14587. #endif
  14588. WFIFOHEAD(fd, packet_len(cmd));
  14589. WFIFOW(fd, 0) = cmd;
  14590. WFIFOL(fd, 2) = qd->quest_id;
  14591. WFIFOB(fd, 6) = qd->state;
  14592. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14593. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14594. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14595. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14596. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14597. e_race race = qi->objectives[i]->race;
  14598. e_size size = qi->objectives[i]->size;
  14599. e_element element = qi->objectives[i]->element;
  14600. #if PACKETVER >= 20150513
  14601. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14602. offset += 4;
  14603. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14604. offset += 4;
  14605. #endif
  14606. 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
  14607. offset += 4;
  14608. #if PACKETVER >= 20150513
  14609. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14610. offset += 2;
  14611. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14612. offset += 2;
  14613. #endif
  14614. WFIFOW(fd, offset) = qd->count[i];
  14615. offset += 2;
  14616. if (mob && qi->objectives[i]->mob_id > 0)
  14617. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14618. else
  14619. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14620. offset += NAME_LENGTH;
  14621. }
  14622. WFIFOSET(fd, packet_len(cmd));
  14623. #if PACKETVER >= 20150513
  14624. int len = 4 + qi->objectives.size() * 12;
  14625. WFIFOHEAD(fd, len);
  14626. WFIFOW(fd, 0) = 0x8fe;
  14627. WFIFOW(fd, 2) = len;
  14628. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14629. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14630. WFIFOL(fd, offset+4) = qi->objectives[i]->mob_id;
  14631. WFIFOW(fd, offset + 10) = qi->objectives[i]->count;
  14632. WFIFOW(fd, offset + 12) = qd->count[i];
  14633. }
  14634. WFIFOSET(fd, len);
  14635. #endif
  14636. }
  14637. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14638. /// 02b4 <quest id>.L
  14639. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14640. {
  14641. int fd = sd->fd;
  14642. WFIFOHEAD(fd, packet_len(0x2b4));
  14643. WFIFOW(fd, 0) = 0x2b4;
  14644. WFIFOL(fd, 2) = quest_id;
  14645. WFIFOSET(fd, packet_len(0x2b4));
  14646. }
  14647. /// Notification of an update to the hunting mission counter
  14648. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14649. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14650. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  14651. {
  14652. int fd = sd->fd;
  14653. int offset = 6;
  14654. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14655. int len = qi->objectives.size() * 12 + 6;
  14656. #if PACKETVER >= 20150513
  14657. int cmd = 0x9fa;
  14658. #else
  14659. int cmd = 0x2b5;
  14660. #endif
  14661. WFIFOHEAD(fd, len);
  14662. WFIFOW(fd, 0) = cmd;
  14663. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14664. for (int i = 0; i < qi->objectives.size(); i++) {
  14665. WFIFOL(fd, offset) = qd->quest_id;
  14666. offset += 4;
  14667. #if PACKETVER >= 20150513
  14668. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14669. offset += 4;
  14670. #else
  14671. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14672. offset += 4;
  14673. #endif
  14674. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14675. offset += 2;
  14676. WFIFOW(fd, offset) = qd->count[i];
  14677. offset += 2;
  14678. }
  14679. WFIFOW(fd, 2) = offset;
  14680. WFIFOSET(fd, offset);
  14681. }
  14682. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14683. /// 02b6 <quest id>.L <active>.B
  14684. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14685. {
  14686. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14687. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14688. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14689. }
  14690. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14691. /// 02b7 <quest id>.L <active>.B
  14692. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14693. {
  14694. int fd = sd->fd;
  14695. WFIFOHEAD(fd, packet_len(0x2b7));
  14696. WFIFOW(fd, 0) = 0x2b7;
  14697. WFIFOL(fd, 2) = quest_id;
  14698. WFIFOB(fd, 6) = active;
  14699. WFIFOSET(fd, packet_len(0x2b7));
  14700. }
  14701. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14702. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14703. /// effect:
  14704. /// 0 = none
  14705. /// 1 = exclamation mark icon
  14706. /// 2 = question mark icon
  14707. /// color:
  14708. /// 0 = yellow
  14709. /// 1 = orange
  14710. /// 2 = green
  14711. /// 3 = purple
  14712. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14713. {
  14714. #if PACKETVER >= 20090218
  14715. nullpo_retv(sd);
  14716. nullpo_retv(bl);
  14717. int fd = sd->fd;
  14718. WFIFOHEAD(fd, packet_len(0x446));
  14719. WFIFOW(fd, 0) = 0x446;
  14720. WFIFOL(fd, 2) = bl->id;
  14721. WFIFOW(fd, 6) = bl->x;
  14722. WFIFOW(fd, 8) = bl->y;
  14723. WFIFOW(fd, 10) = effect;
  14724. WFIFOW(fd, 12) = color;
  14725. WFIFOSET(fd, packet_len(0x446));
  14726. #endif
  14727. }
  14728. /// Mercenary System
  14729. ///
  14730. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14731. /// 02a2 <var id>.W <value>.L
  14732. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14733. {
  14734. struct mercenary_data *md;
  14735. struct status_data *status;
  14736. int fd;
  14737. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14738. return;
  14739. fd = sd->fd;
  14740. status = &md->battle_status;
  14741. WFIFOHEAD(fd,packet_len(0x2a2));
  14742. WFIFOW(fd,0) = 0x2a2;
  14743. WFIFOW(fd,2) = type;
  14744. switch( type ) {
  14745. case SP_ATK1:
  14746. {
  14747. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14748. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14749. }
  14750. break;
  14751. case SP_MATK1:
  14752. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14753. break;
  14754. case SP_HIT:
  14755. WFIFOL(fd,4) = status->hit;
  14756. break;
  14757. case SP_CRITICAL:
  14758. WFIFOL(fd,4) = status->cri/10;
  14759. break;
  14760. case SP_DEF1:
  14761. WFIFOL(fd,4) = status->def;
  14762. break;
  14763. case SP_MDEF1:
  14764. WFIFOL(fd,4) = status->mdef;
  14765. break;
  14766. case SP_MERCFLEE:
  14767. WFIFOL(fd,4) = status->flee;
  14768. break;
  14769. case SP_ASPD:
  14770. WFIFOL(fd,4) = status->amotion;
  14771. break;
  14772. case SP_HP:
  14773. WFIFOL(fd,4) = status->hp;
  14774. break;
  14775. case SP_MAXHP:
  14776. WFIFOL(fd,4) = status->max_hp;
  14777. break;
  14778. case SP_SP:
  14779. WFIFOL(fd,4) = status->sp;
  14780. break;
  14781. case SP_MAXSP:
  14782. WFIFOL(fd,4) = status->max_sp;
  14783. break;
  14784. case SP_MERCKILLS:
  14785. WFIFOL(fd,4) = md->mercenary.kill_count;
  14786. break;
  14787. case SP_MERCFAITH:
  14788. WFIFOL(fd,4) = mercenary_get_faith(md);
  14789. break;
  14790. }
  14791. WFIFOSET(fd,packet_len(0x2a2));
  14792. }
  14793. /// Mercenary base status data (ZC_MER_INIT).
  14794. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14795. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14796. /// <calls>.L <kills>.L <atk range>.W
  14797. void clif_mercenary_info(struct map_session_data *sd)
  14798. {
  14799. int fd;
  14800. struct mercenary_data *md;
  14801. struct status_data *status;
  14802. int atk;
  14803. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14804. return;
  14805. fd = sd->fd;
  14806. status = &md->battle_status;
  14807. WFIFOHEAD(fd,packet_len(0x29b));
  14808. WFIFOW(fd,0) = 0x29b;
  14809. WFIFOL(fd,2) = md->bl.id;
  14810. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14811. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14812. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14813. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14814. WFIFOW(fd,10) = status->hit;
  14815. WFIFOW(fd,12) = status->cri/10;
  14816. WFIFOW(fd,14) = status->def;
  14817. WFIFOW(fd,16) = status->mdef;
  14818. WFIFOW(fd,18) = status->flee;
  14819. WFIFOW(fd,20) = status->amotion;
  14820. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14821. WFIFOW(fd,46) = md->db->lv;
  14822. WFIFOL(fd,48) = status->hp;
  14823. WFIFOL(fd,52) = status->max_hp;
  14824. WFIFOL(fd,56) = status->sp;
  14825. WFIFOL(fd,60) = status->max_sp;
  14826. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14827. WFIFOW(fd,68) = mercenary_get_faith(md);
  14828. WFIFOL(fd,70) = mercenary_get_calls(md);
  14829. WFIFOL(fd,74) = md->mercenary.kill_count;
  14830. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14831. WFIFOSET(fd,packet_len(0x29b));
  14832. }
  14833. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14834. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14835. void clif_mercenary_skillblock(struct map_session_data *sd)
  14836. {
  14837. struct mercenary_data *md;
  14838. int fd, i, len = 4;
  14839. if( sd == NULL || (md = sd->md) == NULL )
  14840. return;
  14841. fd = sd->fd;
  14842. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14843. WFIFOW(fd,0) = 0x29d;
  14844. for( i = 0; i < MAX_MERCSKILL; i++ )
  14845. {
  14846. uint16 id;
  14847. short idx = -1;
  14848. if( (id = md->db->skill[i].id) == 0 )
  14849. continue;
  14850. if ((idx = mercenary_skill_get_index(id)) == -1)
  14851. continue;
  14852. WFIFOW(fd,len) = id;
  14853. WFIFOL(fd,len+2) = skill_get_inf(id);
  14854. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14855. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14856. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14857. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14858. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14859. len += 37;
  14860. }
  14861. WFIFOW(fd,2) = len;
  14862. WFIFOSET(fd,len);
  14863. }
  14864. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14865. /// 029f <command>.B
  14866. /// 1 = mercenary information
  14867. /// 2 = delete
  14868. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14869. {
  14870. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14871. if( sd->md == NULL )
  14872. return;
  14873. if( option == 2 ) mercenary_delete(sd->md, 2);
  14874. }
  14875. /// Mercenary Message
  14876. /// message:
  14877. /// 0 = Mercenary soldier's duty hour is over.
  14878. /// 1 = Your mercenary soldier has been killed.
  14879. /// 2 = Your mercenary soldier has been fired.
  14880. /// 3 = Your mercenary soldier has ran away.
  14881. void clif_mercenary_message(struct map_session_data* sd, int message){
  14882. clif_msg(sd, MERC_MSG_BASE + message);
  14883. }
  14884. /// Notification about the remaining time of a rental item.
  14885. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  14886. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  14887. // '<ItemName>' item will disappear in <seconds/60> minutes.
  14888. struct PACKET_ZC_CASH_TIME_COUNTER p;
  14889. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  14890. p.itemId = client_nameid( nameid );
  14891. p.seconds = seconds;
  14892. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14893. }
  14894. /// Deletes a rental item from client's inventory.
  14895. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  14896. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  14897. // '<ItemName>' item has been deleted from the Inventory
  14898. struct PACKET_ZC_CASH_ITEM_DELETE p;
  14899. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  14900. p.index = client_index( index );
  14901. p.itemId = client_nameid( nameid );
  14902. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14903. }
  14904. /// Book Reading (ZC_READ_BOOK).
  14905. /// 0294 <book id>.L <page>.L
  14906. void clif_readbook(int fd, int book_id, int page)
  14907. {
  14908. WFIFOHEAD(fd,packet_len(0x294));
  14909. WFIFOW(fd,0) = 0x294;
  14910. WFIFOL(fd,2) = book_id;
  14911. WFIFOL(fd,6) = page;
  14912. WFIFOSET(fd,packet_len(0x294));
  14913. }
  14914. /// Battlegrounds
  14915. ///
  14916. /// Updates HP bar of a camp member.
  14917. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14918. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14919. void clif_bg_hp(struct map_session_data *sd) {
  14920. #if PACKETVER < 20140613
  14921. unsigned char buf[34];
  14922. const int cmd = 0x2e0;
  14923. #else
  14924. unsigned char buf[14];
  14925. const int cmd = 0xa0e;
  14926. #endif
  14927. nullpo_retv(sd);
  14928. WBUFW(buf,0) = cmd;
  14929. WBUFL(buf,2) = sd->status.account_id;
  14930. #if PACKETVER < 20140613
  14931. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14932. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14933. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14934. WBUFW(buf,32) = 100;
  14935. } else {
  14936. WBUFW(buf,30) = sd->battle_status.hp;
  14937. WBUFW(buf,32) = sd->battle_status.max_hp;
  14938. }
  14939. #else
  14940. if( sd->battle_status.max_hp > INT32_MAX ) {
  14941. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14942. WBUFL(buf,10) = 100;
  14943. } else {
  14944. WBUFL(buf,6) = sd->battle_status.hp;
  14945. WBUFL(buf,10) = sd->battle_status.max_hp;
  14946. }
  14947. #endif
  14948. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14949. }
  14950. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14951. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14952. void clif_bg_xy(struct map_session_data *sd)
  14953. {
  14954. unsigned char buf[36];
  14955. nullpo_retv(sd);
  14956. WBUFW(buf,0)=0x2df;
  14957. WBUFL(buf,2)=sd->status.account_id;
  14958. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14959. WBUFW(buf,30)=sd->status.class_;
  14960. WBUFW(buf,32)=sd->bl.x;
  14961. WBUFW(buf,34)=sd->bl.y;
  14962. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14963. }
  14964. void clif_bg_xy_remove(struct map_session_data *sd)
  14965. {
  14966. unsigned char buf[36];
  14967. nullpo_retv(sd);
  14968. WBUFW(buf,0)=0x2df;
  14969. WBUFL(buf,2)=sd->status.account_id;
  14970. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14971. WBUFW(buf,30)=0;
  14972. WBUFW(buf,32)=-1;
  14973. WBUFW(buf,34)=-1;
  14974. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14975. }
  14976. /// Notifies clients of a battleground message.
  14977. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  14978. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  14979. struct map_session_data *sd = bg_getavailablesd( bg );
  14980. if( sd == nullptr ){
  14981. return;
  14982. }
  14983. // limit length
  14984. len = min( len + 1, CHAT_SIZE_MAX );
  14985. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  14986. WBUFW(buf,0) = 0x2dc;
  14987. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14988. WBUFL(buf,4) = src_id;
  14989. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14990. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  14991. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14992. }
  14993. /// Validates and processes battlechat messages.
  14994. /// All messages that are sent after enabling battleground chat with /battlechat.
  14995. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  14996. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14997. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14998. if( !clif_process_message( sd, false, name, message, output ) )
  14999. return;
  15000. bg_send_message(sd, output, strlen(output) );
  15001. }
  15002. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15003. /// 02de <camp A points>.W <camp B points>.W
  15004. void clif_bg_updatescore(int16 m)
  15005. {
  15006. struct block_list bl;
  15007. unsigned char buf[6];
  15008. struct map_data *mapdata = map_getmapdata(m);
  15009. bl.id = 0;
  15010. bl.type = BL_NUL;
  15011. bl.m = m;
  15012. WBUFW(buf,0) = 0x2de;
  15013. WBUFW(buf,2) = mapdata->bgscore_lion;
  15014. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15015. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15016. }
  15017. void clif_bg_updatescore_single(struct map_session_data *sd)
  15018. {
  15019. int fd;
  15020. nullpo_retv(sd);
  15021. fd = sd->fd;
  15022. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15023. WFIFOHEAD(fd,packet_len(0x2de));
  15024. WFIFOW(fd,0) = 0x2de;
  15025. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15026. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15027. WFIFOSET(fd,packet_len(0x2de));
  15028. }
  15029. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15030. /// 02dd <account id>.L <name>.24B <camp>.W
  15031. void clif_sendbgemblem_area(struct map_session_data *sd)
  15032. {
  15033. unsigned char buf[33];
  15034. nullpo_retv(sd);
  15035. WBUFW(buf, 0) = 0x2dd;
  15036. WBUFL(buf,2) = sd->bl.id;
  15037. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15038. WBUFW(buf,30) = sd->bg_id;
  15039. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15040. }
  15041. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15042. {
  15043. nullpo_retv(sd);
  15044. WFIFOHEAD(fd,32);
  15045. WFIFOW(fd,0) = 0x2dd;
  15046. WFIFOL(fd,2) = sd->bl.id;
  15047. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15048. WFIFOW(fd,30) = sd->bg_id;
  15049. WFIFOSET(fd,packet_len(0x2dd));
  15050. }
  15051. /// Battlegrounds queue incoming apply request from client.
  15052. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15053. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15054. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15055. {
  15056. if (!battle_config.feature_bgqueue)
  15057. return;
  15058. nullpo_retv(sd);
  15059. short type = RFIFOW(fd,2);
  15060. char name[NAME_LENGTH];
  15061. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15062. if (sd->bg_queue_id > 0) {
  15063. //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);
  15064. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15065. return;
  15066. } else if (type == 1) // Solo
  15067. bg_queue_join_solo(name, sd);
  15068. else if (type == 2) // Party
  15069. bg_queue_join_party(name, sd);
  15070. else if (type == 4) // Guild
  15071. bg_queue_join_guild(name, sd);
  15072. else {
  15073. 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);
  15074. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15075. return;
  15076. }
  15077. }
  15078. /// Outgoing battlegrounds queue apply result.
  15079. /// Result types: @see e_bg_queue_apply_ack
  15080. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15081. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15082. {
  15083. nullpo_retv(sd);
  15084. int fd = sd->fd;
  15085. WFIFOHEAD(fd, packet_len(0x8d8));
  15086. WFIFOW(fd,0) = 0x8d8;
  15087. WFIFOB(fd,2) = result;
  15088. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15089. WFIFOSET(fd, packet_len(0x8d8));
  15090. }
  15091. /// Outgoing battlegrounds queue apply notification.
  15092. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15093. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15094. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15095. {
  15096. nullpo_retv(sd);
  15097. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15098. if (queue == nullptr) {
  15099. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15100. return;
  15101. }
  15102. int fd = sd->fd;
  15103. WFIFOHEAD(fd, packet_len(0x8d9));
  15104. WFIFOW(fd,0) = 0x8d9;
  15105. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15106. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15107. WFIFOSET(fd, packet_len(0x8d9));
  15108. }
  15109. /// Battlegrounds queue outgoing cancel result.
  15110. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15111. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15112. {
  15113. nullpo_retv(sd);
  15114. int fd = sd->fd;
  15115. WFIFOHEAD(fd, packet_len(0x8d8));
  15116. WFIFOW(fd,0) = 0x8db;
  15117. WFIFOB(fd,2) = success;
  15118. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15119. WFIFOSET(fd, packet_len(0x8d8));
  15120. }
  15121. /// Battlegrounds queue incoming cancel request from client.
  15122. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15123. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15124. {
  15125. if (!battle_config.feature_bgqueue)
  15126. return;
  15127. nullpo_retv(sd);
  15128. bool success;
  15129. if (sd->bg_queue_id > 0) {
  15130. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15131. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15132. 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.
  15133. else
  15134. success = bg_queue_leave(sd);
  15135. } else {
  15136. 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);
  15137. success = false;
  15138. }
  15139. char name[NAME_LENGTH];
  15140. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15141. clif_bg_queue_cancel_result(success, name, sd);
  15142. }
  15143. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15144. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15145. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15146. {
  15147. nullpo_retv(sd);
  15148. int fd = sd->fd;
  15149. WFIFOHEAD(fd, packet_len(0x8df));
  15150. WFIFOW(fd,0) = 0x8df;
  15151. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15152. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15153. WFIFOSET(fd, packet_len(0x8df));
  15154. }
  15155. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15156. /// Result types: 1(Accept), 2(Decline).
  15157. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15158. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15159. {
  15160. nullpo_retv(sd);
  15161. if(sd->bg_queue_id > 0) {
  15162. uint8 result = RFIFOB(fd, 2);
  15163. if(result == 1) { // Accept
  15164. bg_queue_on_accept_invite(sd);
  15165. } else if(result == 2) { // Decline
  15166. bg_queue_leave(sd);
  15167. clif_bg_queue_entry_init(sd);
  15168. }
  15169. }
  15170. }
  15171. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15172. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15173. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15174. {
  15175. nullpo_retv(sd);
  15176. int fd = sd->fd;
  15177. WFIFOHEAD(fd, packet_len(0x8e1));
  15178. WFIFOW(fd,0) = 0x8e1;
  15179. WFIFOB(fd,2) = result;
  15180. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15181. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15182. WFIFOSET(fd, packet_len(0x8e1));
  15183. }
  15184. /// Battlegrounds queue incoming queue number request from client.
  15185. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15186. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15187. {
  15188. nullpo_retv(sd);
  15189. char name[NAME_LENGTH];
  15190. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15191. clif_bg_queue_apply_notify(name, sd);
  15192. }
  15193. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15194. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15195. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15196. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15197. {
  15198. nullpo_retv(sd);
  15199. int fd = sd->fd;
  15200. WFIFOHEAD(fd, packet_len(0x90e));
  15201. WFIFOW(fd,0) = 0x90e;
  15202. WFIFOSET(fd, packet_len(0x90e));
  15203. }
  15204. /// Custom Fonts (ZC_NOTIFY_FONT).
  15205. /// 02ef <account_id>.L <font id>.W
  15206. void clif_font(struct map_session_data *sd)
  15207. {
  15208. #if PACKETVER >= 20080102
  15209. unsigned char buf[8];
  15210. nullpo_retv(sd);
  15211. WBUFW(buf,0) = 0x2ef;
  15212. WBUFL(buf,2) = sd->bl.id;
  15213. WBUFW(buf,6) = sd->status.font;
  15214. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15215. #endif
  15216. }
  15217. /// Required to start the instancing information window on Client
  15218. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15219. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15220. void clif_instance_create(int instance_id, int num)
  15221. {
  15222. #if PACKETVER >= 20071128
  15223. struct map_session_data *sd = NULL;
  15224. enum send_target target = PARTY;
  15225. unsigned char buf[65];
  15226. instance_getsd(instance_id, sd, &target);
  15227. if (!sd)
  15228. return;
  15229. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15230. if (!db)
  15231. return;
  15232. WBUFW(buf,0) = 0x2cb;
  15233. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15234. WBUFW(buf,63) = num;
  15235. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15236. #endif
  15237. return;
  15238. }
  15239. /// To announce Instancing queue creation if no maps available
  15240. /// S 0x2cc <Standby Position>.W
  15241. void clif_instance_changewait(int instance_id, int num)
  15242. {
  15243. #if PACKETVER >= 20071128
  15244. struct map_session_data *sd = NULL;
  15245. enum send_target target = PARTY;
  15246. unsigned char buf[4];
  15247. instance_getsd(instance_id, sd, &target);
  15248. if (!sd)
  15249. return;
  15250. WBUFW(buf,0) = 0x2cc;
  15251. WBUFW(buf,2) = num;
  15252. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15253. #endif
  15254. return;
  15255. }
  15256. /// Notify the current status to members
  15257. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15258. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15259. {
  15260. #if PACKETVER >= 20071128
  15261. struct map_session_data *sd = NULL;
  15262. enum send_target target = PARTY;
  15263. unsigned char buf[71];
  15264. instance_getsd(instance_id, sd, &target);
  15265. if (!sd)
  15266. return;
  15267. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15268. if (!db)
  15269. return;
  15270. WBUFW(buf,0) = 0x2cd;
  15271. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15272. WBUFL(buf,63) = limit1;
  15273. WBUFL(buf,67) = limit2;
  15274. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15275. #endif
  15276. return;
  15277. }
  15278. /// Notify a status change to members
  15279. /// S 0x2ce <Message ID>.L
  15280. /// 0 = Notification (EnterLimitDate update?)
  15281. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15282. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15283. /// 3 = The Memorial Dungeon has been removed.
  15284. /// 4 = Create failure (removes the instance window)
  15285. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15286. {
  15287. #if PACKETVER >= 20071128
  15288. struct map_session_data *sd = NULL;
  15289. enum send_target target = PARTY;
  15290. unsigned char buf[10];
  15291. instance_getsd(instance_id, sd, &target);
  15292. if (!sd)
  15293. return;
  15294. WBUFW(buf,0) = 0x2ce;
  15295. WBUFL(buf,2) = type;
  15296. WBUFL(buf,6) = limit;
  15297. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15298. #endif
  15299. return;
  15300. }
  15301. /// Destroy an instance from the status window
  15302. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15303. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15304. {
  15305. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15306. return;
  15307. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15308. switch (p->command) {
  15309. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15310. instance_destroy_command(sd);
  15311. break;
  15312. }
  15313. }
  15314. /// Notifies clients about item picked up by a party member.
  15315. /// 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)
  15316. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15317. #if PACKETVER >= 20071002
  15318. nullpo_retv( sd );
  15319. nullpo_retv( item_data );
  15320. struct item_data* id = itemdb_search( item_data->nameid );
  15321. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15322. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15323. p.AID = sd->status.account_id;
  15324. p.itemId = client_nameid( item_data->nameid );
  15325. p.identified = item_data->identify;
  15326. p.damaged = item_data->attribute;
  15327. p.refine = item_data->refine;
  15328. clif_addcards( &p.slot, item_data );
  15329. p.location = id->equip; // equip location
  15330. p.itemType = itemtype( id->nameid ); // item type
  15331. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15332. p.enchantgrade = item_data->enchantgrade;
  15333. #endif
  15334. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15335. #endif
  15336. }
  15337. /** Display gained exp.
  15338. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15339. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15340. * amount: INT32_MIN ~ INT32_MAX
  15341. * var id:
  15342. * SP_BASEEXP, SP_JOBEXP
  15343. * exp type:
  15344. * 0 = normal exp gained/lost
  15345. * 1 = quest exp gained/lost
  15346. * @param sd Player
  15347. * @param exp EXP value gained/loss
  15348. * @param type SP_BASEEXP, SP_JOBEXP
  15349. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15350. * @param lost True:if losing EXP
  15351. */
  15352. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15353. {
  15354. int fd;
  15355. int offset;
  15356. #if PACKETVER >= 20170830
  15357. int cmd = 0xacc;
  15358. #else
  15359. int cmd = 0x7f6;
  15360. #endif
  15361. nullpo_retv(sd);
  15362. fd = sd->fd;
  15363. WFIFOHEAD(fd, packet_len(cmd));
  15364. WFIFOW(fd,0) = cmd;
  15365. WFIFOL(fd,2) = sd->bl.id;
  15366. #if PACKETVER >= 20170830
  15367. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15368. offset = 4;
  15369. #else
  15370. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15371. offset = 0;
  15372. #endif
  15373. WFIFOW(fd,10+offset) = type;
  15374. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15375. WFIFOSET(fd,packet_len(cmd));
  15376. }
  15377. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15378. /// type:
  15379. /// 0 = Displays 'value' for 5 seconds.
  15380. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15381. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15382. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15383. /// value:
  15384. /// 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).
  15385. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15386. {
  15387. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15388. WFIFOW(sd->fd,0) = 0x1b1;
  15389. WFIFOB(sd->fd,2) = type;
  15390. WFIFOL(sd->fd,3) = value;
  15391. WFIFOSET(sd->fd, packet_len(0x1b1));
  15392. }
  15393. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15394. /// 021d <state>.L
  15395. /// state:
  15396. /// 0 = Full effects
  15397. /// 1 = Reduced effects
  15398. ///
  15399. /// NOTE: The state is used on Aegis for sending skill unit packet
  15400. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15401. /// whenever possible. Due to the way the decision check is
  15402. /// constructed, this state tracking was rendered useless,
  15403. /// as the only skill unit, that is sent with 0x1c9 is
  15404. /// Graffiti.
  15405. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15406. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15407. sd->state.lesseffect = ( isLess != 0 );
  15408. }
  15409. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15410. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15411. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15412. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15413. int type = RFIFOL(fd,info->pos[1]);
  15414. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15415. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15416. if( sd->state.trading || sd->npc_shopid )
  15417. return;
  15418. if( flag == 0 || n == 0) {
  15419. clif_menuskill_clear(sd);
  15420. return; // Canceled by player.
  15421. }
  15422. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15423. clif_menuskill_clear(sd);
  15424. return; // Prevent hacking.
  15425. }
  15426. switch( type ) {
  15427. case 0: // Change Material
  15428. skill_changematerial(sd,n,item_list);
  15429. break;
  15430. case 1: // Level 1: Pure to Rough
  15431. case 2: // Level 2: Rough to Pure
  15432. skill_elementalanalysis(sd,n,type,item_list);
  15433. break;
  15434. }
  15435. clif_menuskill_clear(sd);
  15436. return;
  15437. }
  15438. /*==========================================
  15439. * Elemental System
  15440. *==========================================*/
  15441. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15442. struct elemental_data *ed;
  15443. struct status_data *status;
  15444. int fd;
  15445. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15446. return;
  15447. fd = sd->fd;
  15448. status = &ed->battle_status;
  15449. WFIFOHEAD(fd,8);
  15450. WFIFOW(fd,0) = 0x81e;
  15451. WFIFOW(fd,2) = type;
  15452. switch( type ) {
  15453. case SP_HP:
  15454. WFIFOL(fd,4) = status->hp;
  15455. break;
  15456. case SP_MAXHP:
  15457. WFIFOL(fd,4) = status->max_hp;
  15458. break;
  15459. case SP_SP:
  15460. WFIFOL(fd,4) = status->sp;
  15461. break;
  15462. case SP_MAXSP:
  15463. WFIFOL(fd,4) = status->max_sp;
  15464. break;
  15465. }
  15466. WFIFOSET(fd,8);
  15467. }
  15468. void clif_elemental_info(struct map_session_data *sd) {
  15469. int fd;
  15470. struct elemental_data *ed;
  15471. struct status_data *status;
  15472. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15473. return;
  15474. fd = sd->fd;
  15475. status = &ed->battle_status;
  15476. WFIFOHEAD(fd,22);
  15477. WFIFOW(fd, 0) = 0x81d;
  15478. WFIFOL(fd, 2) = ed->bl.id;
  15479. WFIFOL(fd, 6) = status->hp;
  15480. WFIFOL(fd,10) = status->max_hp;
  15481. WFIFOL(fd,14) = status->sp;
  15482. WFIFOL(fd,18) = status->max_sp;
  15483. WFIFOSET(fd,22);
  15484. }
  15485. /// Buying Store System
  15486. ///
  15487. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15488. /// 0810 <slots>.B
  15489. void clif_buyingstore_open(struct map_session_data* sd)
  15490. {
  15491. int fd = sd->fd;
  15492. WFIFOHEAD(fd,packet_len(0x810));
  15493. WFIFOW(fd,0) = 0x810;
  15494. WFIFOB(fd,2) = sd->buyingstore.slots;
  15495. WFIFOSET(fd,packet_len(0x810));
  15496. }
  15497. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15498. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15499. /// result:
  15500. /// 0 = cancel
  15501. /// 1 = open
  15502. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15503. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15504. // TODO: Make this check global for all variable length packets.
  15505. // minimum packet length
  15506. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15507. 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 );
  15508. return;
  15509. }
  15510. char storename[MESSAGE_SIZE];
  15511. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15512. // so that buyingstore_create knows, how many elements it has access to
  15513. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15514. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15515. 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 ) );
  15516. return;
  15517. }
  15518. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15519. }
  15520. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15521. /// 0812 <result>.W <total weight>.L
  15522. /// result:
  15523. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15524. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15525. /// 8 = "No sale (purchase) information available." (0x705)
  15526. /// ? = nothing
  15527. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15528. {
  15529. int fd = sd->fd;
  15530. WFIFOHEAD(fd,packet_len(0x812));
  15531. WFIFOW(fd,0) = 0x812;
  15532. WFIFOW(fd,2) = result;
  15533. WFIFOL(fd,4) = weight;
  15534. WFIFOSET(fd,packet_len(0x812));
  15535. }
  15536. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15537. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15538. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15539. nullpo_retv( sd );
  15540. int fd = sd->fd;
  15541. if( !session_isActive( fd ) ){
  15542. return;
  15543. }
  15544. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15545. WFIFOHEAD( fd, length );
  15546. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15547. p->packetType = 0x813;
  15548. p->packetLength = length;
  15549. p->AID = sd->bl.id;
  15550. p->zenyLimit = sd->buyingstore.zenylimit;
  15551. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15552. p->items[i].price = sd->buyingstore.items[i].price;
  15553. p->items[i].amount = sd->buyingstore.items[i].amount;
  15554. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15555. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15556. }
  15557. WFIFOSET( fd, p->packetLength );
  15558. }
  15559. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15560. /// 0814 <account id>.L <store name>.80B
  15561. void clif_buyingstore_entry(struct map_session_data* sd)
  15562. {
  15563. uint8 buf[MESSAGE_SIZE+6];
  15564. WBUFW(buf,0) = 0x814;
  15565. WBUFL(buf,2) = sd->bl.id;
  15566. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15567. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15568. }
  15569. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15570. {
  15571. int fd = sd->fd;
  15572. WFIFOHEAD(fd,packet_len(0x814));
  15573. WFIFOW(fd,0) = 0x814;
  15574. WFIFOL(fd,2) = pl_sd->bl.id;
  15575. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15576. WFIFOSET(fd,packet_len(0x814));
  15577. }
  15578. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15579. /// 0815
  15580. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15581. {
  15582. buyingstore_close(sd);
  15583. }
  15584. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15585. /// 0816 <account id>.L
  15586. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15587. {
  15588. uint8 buf[6];
  15589. WBUFW(buf,0) = 0x816;
  15590. WBUFL(buf,2) = sd->bl.id;
  15591. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15592. }
  15593. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15594. {
  15595. int fd = sd->fd;
  15596. WFIFOHEAD(fd,packet_len(0x816));
  15597. WFIFOW(fd,0) = 0x816;
  15598. WFIFOL(fd,2) = pl_sd->bl.id;
  15599. WFIFOSET(fd,packet_len(0x816));
  15600. }
  15601. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15602. /// 0817 <account id>.L
  15603. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15604. {
  15605. uint32 account_id;
  15606. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15607. buyingstore_open(sd, account_id);
  15608. }
  15609. /// Sends buying store item list.
  15610. /// 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)
  15611. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15612. nullpo_retv( sd );
  15613. nullpo_retv( pl_sd );
  15614. int fd = sd->fd;
  15615. if( !session_isActive( fd ) ){
  15616. return;
  15617. }
  15618. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15619. WFIFOHEAD( fd, length );
  15620. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15621. p->packetType = 0x818;
  15622. p->packetLength = length;
  15623. p->AID = pl_sd->bl.id;
  15624. p->storeId = pl_sd->buyer_id;
  15625. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15626. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15627. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15628. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15629. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15630. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15631. }
  15632. WFIFOSET( fd, p->packetLength );
  15633. }
  15634. /// Request to sell items to a buying store.
  15635. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15636. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15637. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15638. // minimum packet length
  15639. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15640. 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 );
  15641. return;
  15642. }
  15643. // so that buyingstore_trade knows, how many elements it has access to
  15644. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15645. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15646. 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 ) );
  15647. return;
  15648. }
  15649. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15650. }
  15651. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15652. /// 081a <result>.W
  15653. /// result:
  15654. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15655. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15656. /// ? = nothing
  15657. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15658. {
  15659. int fd = sd->fd;
  15660. WFIFOHEAD(fd,packet_len(0x81a));
  15661. WFIFOW(fd,0) = 0x81a;
  15662. WFIFOW(fd,2) = result;
  15663. WFIFOSET(fd,packet_len(0x81a));
  15664. }
  15665. /// Updates the zeny limit and an item in the buying store item list.
  15666. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15667. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15668. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15669. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15670. p.packetType = buyingStoreUpdateItemType;
  15671. p.itemId = client_nameid( nameid );
  15672. p.amount = amount;
  15673. p.zenyLimit = sd->buyingstore.zenylimit;
  15674. #if PACKETVER >= 20141016
  15675. p.zeny = zeny;
  15676. p.charId = char_id; // GID
  15677. p.updateTime = (int)time(NULL);
  15678. #endif
  15679. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15680. }
  15681. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15682. /// 081c <index>.W <amount>.W <price>.L
  15683. /// message:
  15684. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15685. ///
  15686. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15687. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15688. {
  15689. int fd = sd->fd;
  15690. WFIFOHEAD(fd,packet_len(0x81c));
  15691. WFIFOW(fd,0) = 0x81c;
  15692. WFIFOW(fd,2) = client_index( index );
  15693. WFIFOW(fd,4) = amount;
  15694. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15695. WFIFOSET(fd,packet_len(0x81c));
  15696. }
  15697. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15698. /// 0824 <result>.W <name id>.W
  15699. /// result:
  15700. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15701. /// 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)
  15702. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15703. /// ? = nothing
  15704. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  15705. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15706. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15707. p.result = result;
  15708. p.itemId = client_nameid( nameid );
  15709. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15710. }
  15711. /// Search Store Info System
  15712. ///
  15713. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15714. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15715. /// type:
  15716. /// 0 = Vending
  15717. /// 1 = Buying Store
  15718. ///
  15719. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15720. /// amount of card slots. If the client does not know about the item it
  15721. /// cannot be searched.
  15722. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  15723. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15724. // minimum packet length
  15725. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15726. 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 );
  15727. return;
  15728. }
  15729. // check, if there is enough data for the claimed count of items
  15730. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15731. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15732. 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 ) );
  15733. return;
  15734. }
  15735. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15736. if( count < p->itemsCount + p->cardsCount ){
  15737. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15738. return;
  15739. }
  15740. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15741. }
  15742. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15743. /// 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 }*
  15744. /// is first page:
  15745. /// 0 = appends to existing results
  15746. /// 1 = clears previous results before displaying this result set
  15747. /// is next page:
  15748. /// 0 = no "next" label
  15749. /// 1 = "next" label to retrieve more results
  15750. void clif_search_store_info_ack( struct map_session_data* sd ){
  15751. nullpo_retv( sd );
  15752. int fd = sd->fd;
  15753. if( !session_isActive( fd ) ){
  15754. return;
  15755. }
  15756. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15757. unsigned int end = umin( sd->searchstore.count, start + SEARCHSTORE_RESULTS_PER_PAGE );
  15758. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15759. WFIFOHEAD( fd, len );
  15760. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15761. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15762. p->packetLength = len;
  15763. p->firstPage = !sd->searchstore.pages;
  15764. p->nextPage = searchstore_querynext( sd );
  15765. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15766. for( int i = start; i < end; i++ ) {
  15767. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15768. p->items[i].storeId = ssitem->store_id;
  15769. p->items[i].AID = ssitem->account_id;
  15770. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15771. p->items[i].itemId = client_nameid( ssitem->nameid );
  15772. p->items[i].itemType = itemtype( ssitem->nameid );
  15773. p->items[i].price = ssitem->price;
  15774. p->items[i].amount = ssitem->amount;
  15775. p->items[i].refine = ssitem->refine;
  15776. // make-up an item for clif_addcards
  15777. struct item it;
  15778. memset( &it, 0, sizeof( it ) );
  15779. memcpy( &it.card, &ssitem->card, sizeof( it.card ) );
  15780. it.nameid = ssitem->nameid;
  15781. it.amount = ssitem->amount;
  15782. clif_addcards( &p->items[i].slot, &it );
  15783. #if PACKETVER >= 20150226
  15784. clif_add_random_options( p->items[i].option_data, &it );
  15785. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15786. p->items[i].enchantgrade = ssitem->enchantgrade;
  15787. #endif
  15788. #endif
  15789. }
  15790. WFIFOSET( fd, len );
  15791. }
  15792. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15793. /// 0837 <reason>.B
  15794. /// reason:
  15795. /// 0 = "No matching stores were found." (0x70b)
  15796. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15797. /// 2 = "You cannot search anymore." (0x706)
  15798. /// 3 = "You cannot search yet." (0x708)
  15799. /// 4 = "No sale (purchase) information available." (0x705)
  15800. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15801. {
  15802. int fd = sd->fd;
  15803. WFIFOHEAD(fd,packet_len(0x837));
  15804. WFIFOW(fd,0) = 0x837;
  15805. WFIFOB(fd,2) = reason;
  15806. WFIFOSET(fd,packet_len(0x837));
  15807. }
  15808. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15809. /// 0838
  15810. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15811. {
  15812. searchstore_next(sd);
  15813. }
  15814. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15815. /// 083a <type>.W <remaining uses>.B
  15816. /// type:
  15817. /// 0 = Search Stores
  15818. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15819. void clif_open_search_store_info(struct map_session_data* sd)
  15820. {
  15821. int fd = sd->fd;
  15822. WFIFOHEAD(fd,packet_len(0x83a));
  15823. WFIFOW(fd,0) = 0x83a;
  15824. WFIFOW(fd,2) = sd->searchstore.effect;
  15825. #if PACKETVER > 20100701
  15826. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15827. #endif
  15828. WFIFOSET(fd,packet_len(0x83a));
  15829. }
  15830. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15831. /// 083b
  15832. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15833. {
  15834. searchstore_close(sd);
  15835. }
  15836. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15837. /// 083c <account id>.L <store id>.L <nameid>.W
  15838. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  15839. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  15840. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  15841. }
  15842. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15843. /// 083d <xPos>.W <yPos>.W
  15844. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15845. {
  15846. int fd = sd->fd;
  15847. WFIFOHEAD(fd,packet_len(0x83d));
  15848. WFIFOW(fd,0) = 0x83d;
  15849. WFIFOW(fd,2) = x;
  15850. WFIFOW(fd,4) = y;
  15851. WFIFOSET(fd,packet_len(0x83d));
  15852. }
  15853. /// Parse function for packet debugging.
  15854. void clif_parse_debug(int fd,struct map_session_data *sd)
  15855. {
  15856. int cmd, packet_len;
  15857. // clif_parse ensures, that there is at least 2 bytes of data
  15858. cmd = RFIFOW(fd,0);
  15859. if( sd ) {
  15860. packet_len = packet_db[cmd].len;
  15861. if( packet_len == 0 )
  15862. {// unknown
  15863. packet_len = RFIFOREST(fd);
  15864. }
  15865. else if( packet_len == -1 )
  15866. {// variable length
  15867. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15868. }
  15869. 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);
  15870. }
  15871. else
  15872. {
  15873. packet_len = RFIFOREST(fd);
  15874. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15875. }
  15876. ShowDump(RFIFOP(fd,0), packet_len);
  15877. }
  15878. /*==========================================
  15879. * Server tells client to display a window similar to Magnifier (item) one
  15880. * Server populates the window with avilable elemental converter options according to player's inventory
  15881. *------------------------------------------*/
  15882. void clif_elementalconverter_list( struct map_session_data *sd ){
  15883. nullpo_retv( sd );
  15884. int fd = sd->fd;
  15885. if( !session_isActive( fd ) ){
  15886. return;
  15887. }
  15888. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15889. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15890. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15891. int count = 0;
  15892. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  15893. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  15894. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  15895. count++;
  15896. }
  15897. }
  15898. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15899. WFIFOSET( fd, p->packetLength );
  15900. if( count > 0 ){
  15901. sd->menuskill_id = SA_CREATECON;
  15902. sd->menuskill_val = count;
  15903. }
  15904. }
  15905. /**
  15906. * Rune Knight
  15907. **/
  15908. void clif_millenniumshield(struct block_list *bl, short shields) {
  15909. #if PACKETVER >= 20081217
  15910. unsigned char buf[10];
  15911. WBUFW(buf,0) = 0x440;
  15912. WBUFL(buf,2) = bl->id;
  15913. WBUFW(buf,6) = shields;
  15914. WBUFW(buf,8) = 0;
  15915. clif_send(buf,packet_len(0x440),bl,AREA);
  15916. #endif
  15917. }
  15918. /**
  15919. * Mechanic
  15920. **/
  15921. /*==========================================
  15922. * Magic Decoy Material List
  15923. *------------------------------------------*/
  15924. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  15925. nullpo_retv( sd );
  15926. int fd = sd->fd;
  15927. if( !session_isActive( fd ) ){
  15928. return;
  15929. }
  15930. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15931. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  15932. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15933. int count = 0;
  15934. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15935. if( itemdb_group_item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  15936. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15937. count++;
  15938. }
  15939. }
  15940. if( count > 0 ) {
  15941. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15942. WFIFOSET( fd, p->packetLength );
  15943. sd->menuskill_id = NC_MAGICDECOY;
  15944. sd->menuskill_val = skill_lv;
  15945. sd->sc.comet_x = x;
  15946. sd->sc.comet_y = y;
  15947. }else{
  15948. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  15949. }
  15950. }
  15951. /*==========================================
  15952. * Guillotine Cross Poisons List
  15953. *------------------------------------------*/
  15954. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  15955. nullpo_retv( sd );
  15956. int fd = sd->fd;
  15957. if( !session_isActive( fd ) ){
  15958. return;
  15959. }
  15960. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15961. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15962. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15963. int count = 0;
  15964. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15965. if( itemdb_group_item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  15966. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15967. count++;
  15968. }
  15969. }
  15970. if( count > 0 ){
  15971. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15972. WFIFOSET( fd, p->packetLength );
  15973. sd->menuskill_id = GC_POISONINGWEAPON;
  15974. sd->menuskill_val = skill_lv;
  15975. }else{
  15976. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  15977. }
  15978. }
  15979. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15980. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15981. int fd, i, c;
  15982. nullpo_ret(sd);
  15983. fd = sd->fd;
  15984. if( !session_isActive(fd) )
  15985. return 0;
  15986. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15987. return 0;
  15988. WFIFOHEAD(fd, 2 * 6 + 4);
  15989. WFIFOW(fd,0) = 0x442;
  15990. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15991. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15992. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15993. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  15994. {
  15995. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15996. c++;
  15997. }
  15998. if( c > 0 ) {
  15999. WFIFOW(fd,2) = 8 + c * 2;
  16000. WFIFOL(fd,4) = c;
  16001. WFIFOSET(fd,WFIFOW(fd,2));
  16002. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16003. sd->menuskill_val = c;
  16004. } else {
  16005. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  16006. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16007. }
  16008. return 1;
  16009. }
  16010. /*===========================================
  16011. * Skill list for Four Elemental Analysis
  16012. * and Change Material skills.
  16013. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16014. *------------------------------------------*/
  16015. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16016. #if PACKETVER >= 20090922
  16017. int fd = sd->fd;
  16018. nullpo_ret(sd);
  16019. sd->menuskill_id = skill_id; // To prevent hacking.
  16020. sd->menuskill_val = skill_lv;
  16021. if( skill_id == GN_CHANGEMATERIAL )
  16022. skill_lv = 0; // Changematerial
  16023. WFIFOHEAD(fd, packet_len(0x7e3));
  16024. WFIFOW(fd,0) = 0x7e3;
  16025. WFIFOL(fd,2) = skill_lv;
  16026. WFIFOL(fd,4) = 0;
  16027. WFIFOSET(fd, packet_len(0x7e3));
  16028. #endif
  16029. return 1;
  16030. }
  16031. /*==========================================
  16032. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16033. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16034. * RFIFOL(fd,2) - type (currently not used)
  16035. *------------------------------------------*/
  16036. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16037. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16038. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16039. if (sd->menuskill_id == SA_AUTOSPELL) {
  16040. sd->state.workinprogress = WIP_DISABLE_NONE;
  16041. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16042. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16043. if (pc_istrading(sd)) {
  16044. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16045. clif_menuskill_clear(sd);
  16046. return;
  16047. }
  16048. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16049. } else
  16050. return;
  16051. clif_menuskill_clear(sd);
  16052. }
  16053. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16054. /// 08cf <id>.L <type>.W <num>.W
  16055. void clif_spiritcharm(struct map_session_data *sd) {
  16056. unsigned char buf[10];
  16057. nullpo_retv(sd);
  16058. WBUFW(buf,0) = 0x08cf;
  16059. WBUFL(buf,2) = sd->bl.id;
  16060. WBUFW(buf,6) = sd->spiritcharm_type;
  16061. WBUFW(buf,8) = sd->spiritcharm;
  16062. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16063. }
  16064. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16065. /// 0907 <index>.W
  16066. ///
  16067. /// R 0908 <index>.w <type>.b
  16068. /// type:
  16069. /// 0 = move item to personal tab
  16070. /// 1 = move item to normal tab
  16071. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16072. #if PACKETVER >= 20111122
  16073. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16074. int index = RFIFOW(fd,info->pos[0]) - 2;
  16075. int type = RFIFOB(fd, info->pos[1]);
  16076. /* can't move while dead. */
  16077. if(pc_isdead(sd)) {
  16078. return;
  16079. }
  16080. if (index < 0 || index >= MAX_INVENTORY)
  16081. return;
  16082. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16083. sd->inventory.u.items_inventory[index].favorite = 0;
  16084. else if( type == 0 )
  16085. sd->inventory.u.items_inventory[index].favorite = 1;
  16086. else
  16087. return;/* nothing to do. */
  16088. clif_favorite_item(sd, index);
  16089. #endif
  16090. }
  16091. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16092. /// 0900 <index>.W <favorite>.B
  16093. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16094. int fd = sd->fd;
  16095. WFIFOHEAD(fd,packet_len(0x908));
  16096. WFIFOW(fd,0) = 0x908;
  16097. WFIFOW(fd,2) = index+2;
  16098. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16099. WFIFOSET(fd,packet_len(0x908));
  16100. }
  16101. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16102. void clif_snap( struct block_list *bl, short x, short y ) {
  16103. unsigned char buf[10];
  16104. WBUFW(buf,0) = 0x8d2;
  16105. WBUFL(buf,2) = bl->id;
  16106. WBUFW(buf,6) = x;
  16107. WBUFW(buf,8) = y;
  16108. if( disguised(bl) )
  16109. {
  16110. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16111. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16112. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16113. } else
  16114. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16115. }
  16116. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16117. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16118. #if PACKETVER >= 20120404
  16119. WFIFOHEAD(fd,packet_len(0x977));
  16120. WFIFOW(fd,0) = 0x977;
  16121. WFIFOL(fd,2) = md->bl.id;
  16122. WFIFOL(fd,6) = md->status.hp;
  16123. WFIFOL(fd,10) = md->status.max_hp;
  16124. WFIFOSET(fd,packet_len(0x977));
  16125. #endif
  16126. }
  16127. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16128. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16129. return;
  16130. }
  16131. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16132. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16133. WFIFOW(sd->fd,0) = 0x2c9;
  16134. WFIFOB(sd->fd,2) = flag;
  16135. WFIFOSET(sd->fd, packet_len(0x2c9));
  16136. }
  16137. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16138. /// 0979 <world name>.24B <char name>.24B
  16139. void clif_ackworldinfo(struct map_session_data* sd) {
  16140. int fd;
  16141. nullpo_retv(sd);
  16142. fd = sd->fd;
  16143. WFIFOHEAD(fd,packet_len(0x979));
  16144. WFIFOW(fd,0)=0x979;
  16145. //AID -> world name ?
  16146. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16147. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16148. WFIFOSET(fd,packet_len(0x979));
  16149. }
  16150. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16151. /// 0978 <AID>.L
  16152. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16153. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16154. if(sd)
  16155. clif_ackworldinfo(sd);
  16156. }
  16157. static void clif_loadConfirm( struct map_session_data *sd ){
  16158. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16159. nullpo_retv( sd );
  16160. struct PACKET_ZC_LOAD_CONFIRM p;
  16161. p.packetType = HEADER_ZC_LOAD_CONFIRM;
  16162. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16163. if (sd->instance_id > 0)
  16164. instance_reqinfo(sd, sd->instance_id);
  16165. if (sd->status.party_id > 0)
  16166. party_member_joined(sd);
  16167. if (sd->status.guild_id > 0)
  16168. guild_member_joined(sd);
  16169. if (sd->status.clan_id > 0)
  16170. clan_member_joined(sd);
  16171. #endif
  16172. }
  16173. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16174. /// 0447
  16175. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16176. clif_loadConfirm( sd );
  16177. }
  16178. /// req world info (CZ_CLIENT_VERSION)
  16179. /// 044A <version>.L
  16180. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16181. //if(sd)
  16182. ;
  16183. }
  16184. /// Ranking list
  16185. /// ranking pointlist { <name>.24B <point>.L }*10
  16186. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16187. struct fame_list* list;
  16188. int i, size = MAX_FAME_LIST;
  16189. switch(rankingtype) {
  16190. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16191. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16192. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16193. // PK currently unsupported
  16194. case RANK_KILLER: list = NULL; size = 0; break;
  16195. default:
  16196. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16197. return;
  16198. }
  16199. //Packet size limits this list to 10 elements. [Skotlex]
  16200. for (i = 0; i < min(10,size); i++) {
  16201. if (list[i].id > 0) {
  16202. const char* name;
  16203. if (strcmp(list[i].name, "-") == 0 &&
  16204. (name = map_charid2nick(list[i].id)) != NULL)
  16205. {
  16206. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16207. } else {
  16208. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16209. }
  16210. } else {
  16211. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16212. }
  16213. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16214. }
  16215. for(;i < 10; i++) { //In case the MAX is less than 10.
  16216. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16217. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16218. }
  16219. }
  16220. /// Request for the blacksmith ranklist.
  16221. /// /blacksmith command sends this packet to the server.
  16222. /// 0217 (CZ_BLACKSMITH_RANK)
  16223. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16224. clif_ranklist(sd,RANK_BLACKSMITH);
  16225. }
  16226. /// Request for the alchemist ranklist.
  16227. /// /alchemist command sends this packet to the server.
  16228. /// 0218 (CZ_ALCHEMIST_RANK)
  16229. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16230. clif_ranklist(sd,RANK_ALCHEMIST);
  16231. }
  16232. /// Request for the taekwon ranklist.
  16233. /// /taekwon command sends this packet to the server.
  16234. /// 0225 (CZ_TAEKWON_RANK)
  16235. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16236. clif_ranklist(sd,RANK_TAEKWON);
  16237. }
  16238. /// Request for the killer ranklist.
  16239. /// /pk command sends this packet to the server.
  16240. /// 0237 (CZ_KILLER_RANK)
  16241. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16242. clif_ranklist(sd,RANK_KILLER);
  16243. }
  16244. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16245. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16246. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16247. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16248. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16249. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16250. enum e_rank rank;
  16251. #if PACKETVER < 20130710
  16252. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16253. short cmd;
  16254. switch( rankingType ){
  16255. case RANK_BLACKSMITH: cmd = 0x219; break;
  16256. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16257. case RANK_TAEKWON: cmd = 0x226; break;
  16258. case RANK_KILLER: cmd = 0x238; break;
  16259. default:
  16260. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16261. return;
  16262. }
  16263. // Can be safely casted here, since we validated it before
  16264. rank = (enum e_rank)rankingType;
  16265. WBUFW(buf,0) = cmd;
  16266. clif_sub_ranklist(buf,2,sd,rank);
  16267. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16268. #else
  16269. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16270. int mypoint = 0;
  16271. switch( rankingType ){
  16272. case RANK_BLACKSMITH:
  16273. case RANK_ALCHEMIST:
  16274. case RANK_TAEKWON:
  16275. case RANK_KILLER:
  16276. break;
  16277. default:
  16278. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16279. return;
  16280. }
  16281. // Can be safely casted here, since we validated it before
  16282. rank = (enum e_rank)rankingType;
  16283. WBUFW(buf,0) = 0x97d;
  16284. WBUFW(buf,2) = rank;
  16285. clif_sub_ranklist(buf,4,sd,rank);
  16286. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16287. case MAPID_BLACKSMITH:
  16288. case MAPID_ALCHEMIST:
  16289. case MAPID_TAEKWON:
  16290. mypoint = sd->status.fame;
  16291. }
  16292. WBUFL(buf,284) = mypoint; //mypoint
  16293. clif_send(buf, 288, &sd->bl, SELF);
  16294. #endif
  16295. }
  16296. /*
  16297. * 097c <type> (CZ_REQ_RANKING)
  16298. * type
  16299. * 0: /blacksmith
  16300. * 1: /alchemist
  16301. * 2: /taekwon
  16302. * 3: /pk
  16303. * */
  16304. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16305. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16306. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16307. clif_ranklist(sd,rankingtype);
  16308. }
  16309. /// Updates the fame rank points for the given ranking.
  16310. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16311. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16312. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16313. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16314. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  16315. int fd=sd->fd;
  16316. #if PACKETVER < 20130710
  16317. short cmd;
  16318. switch(rankingtype){
  16319. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16320. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16321. case RANK_TAEKWON: cmd = 0x224; break;
  16322. default:
  16323. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16324. return;
  16325. }
  16326. WFIFOHEAD(fd,packet_len(cmd));
  16327. WFIFOW(fd,0) = cmd;
  16328. WFIFOL(fd,2) = point;
  16329. WFIFOL(fd,6) = sd->status.fame;
  16330. WFIFOSET(fd, packet_len(cmd));
  16331. #else
  16332. WFIFOHEAD(fd,packet_len(0x97e));
  16333. WFIFOW(fd,0) = 0x97e;
  16334. WFIFOW(fd,2) = rankingtype;
  16335. WFIFOL(fd,4) = point;
  16336. WFIFOL(fd,8) = sd->status.fame;
  16337. WFIFOSET(fd,packet_len(0x97e));
  16338. #endif
  16339. }
  16340. /**
  16341. * Transmit personal information to player. (rates)
  16342. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16343. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16344. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16345. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16346. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16347. * FIXME!
  16348. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16349. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16350. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16351. */
  16352. #ifdef VIP_ENABLE
  16353. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16354. if (sd) {
  16355. struct s_packet_db* info;
  16356. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16357. int cmd = 0, fd, i = 0;
  16358. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16359. int details_bexp[PINFO_MAX];
  16360. int details_drop[PINFO_MAX];
  16361. int details_penalty[PINFO_MAX];
  16362. /**
  16363. * Set for EXP
  16364. */
  16365. //0:PCRoom
  16366. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16367. if (details_bexp[0] == 100 || !details_bexp[0])
  16368. details_bexp[0] = 0;
  16369. else {
  16370. if (details_bexp[0] < 100) {
  16371. details_bexp[0] = 100 - details_bexp[0];
  16372. details_bexp[0] = 0 - details_bexp[0];
  16373. }
  16374. else
  16375. details_bexp[0] = details_bexp[0] - 100;
  16376. }
  16377. //1:Premium
  16378. if (pc_isvip(sd)) {
  16379. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16380. if (details_bexp[1] < 0)
  16381. details_bexp[1] = 0 - details_bexp[1];
  16382. }
  16383. else
  16384. details_bexp[1] = 0;
  16385. //2:Server
  16386. details_bexp[2] = battle_config.base_exp_rate;
  16387. if (details_bexp[2] == 100)
  16388. details_bexp[2] = 0;
  16389. else {
  16390. if (details_bexp[2] < 100) {
  16391. details_bexp[2] = 100 - details_bexp[2];
  16392. details_bexp[2] = 0 - details_bexp[2];
  16393. }
  16394. else
  16395. details_bexp[2] = details_bexp[2] - 100;
  16396. }
  16397. //3:TPLUS
  16398. details_bexp[3] = 0;
  16399. /* End - EXP set*/
  16400. /**
  16401. * Set for Drop rate
  16402. */
  16403. //0:PCRoom
  16404. details_drop[0] = 0;
  16405. //1:Premium
  16406. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16407. if (pc_isvip(sd)) {
  16408. if (details_drop[1] < 0)
  16409. details_drop[1] = 0 - details_drop[1];
  16410. }
  16411. else
  16412. details_drop[1] = 0;
  16413. //2:Server
  16414. details_drop[2] = battle_config.item_rate_common;
  16415. if (details_drop[2] == 100)
  16416. details_drop[2] = 0;
  16417. else {
  16418. if (details_drop[2] < 100) {
  16419. details_drop[2] = 100 - details_drop[2];
  16420. details_drop[2] = 0 - details_drop[2];
  16421. }
  16422. else
  16423. details_drop[2] = details_drop[2] - 100;
  16424. }
  16425. //3:TPLUS
  16426. details_drop[3] = 0;
  16427. /* End - Drop set*/
  16428. /**
  16429. * Set for Penalty rate
  16430. */
  16431. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16432. //0:PCRoom
  16433. details_penalty[0] = 0;
  16434. //1:Premium
  16435. if (pc_isvip(sd)) {
  16436. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16437. if (details_penalty[1] == 100)
  16438. details_penalty[1] = 0;
  16439. else {
  16440. if (details_penalty[1] < 100) {
  16441. details_penalty[1] = 100 - details_penalty[1];
  16442. details_penalty[1] = 0 - details_penalty[1];
  16443. }
  16444. else
  16445. details_penalty[1] = details_penalty[1] - 100;
  16446. }
  16447. }
  16448. else
  16449. details_penalty[1] = 0;
  16450. //2:Server
  16451. details_penalty[2] = battle_config.death_penalty_base;
  16452. if (details_penalty[2] == 100)
  16453. details_penalty[2] = 0;
  16454. else {
  16455. if (details_penalty[2] < 100) {
  16456. details_penalty[2] = 100 - details_penalty[2];
  16457. details_penalty[2] = 0 - details_penalty[2];
  16458. }
  16459. else
  16460. details_penalty[2] = details_penalty[2] - 100;
  16461. }
  16462. //3:TPLUS
  16463. details_penalty[3] = 0;
  16464. /* End - Penalty set*/
  16465. cmd = packet_db_ack[cmdtype];
  16466. info = &packet_db[cmd];
  16467. len = info->len; //this is the base len without details
  16468. if(!len) return; //version as packet disable
  16469. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16470. szdetails = 7;
  16471. factor = 1;
  16472. }
  16473. else if (cmd == 0x097b) {
  16474. tot_baseexp *= factor;
  16475. tot_drop *= factor;
  16476. tot_penalty *= factor;
  16477. }
  16478. fd = sd->fd;
  16479. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16480. WFIFOW(fd,0) = cmd;
  16481. for (i = 0; i < maxinfotype; i++) {
  16482. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16483. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16484. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16485. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16486. tot_baseexp += details_bexp[i]*factor;
  16487. tot_drop += details_penalty[i]*factor;
  16488. tot_penalty += details_drop[i]*factor;
  16489. len += szdetails;
  16490. }
  16491. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16492. if (cmd == 0x08cb) { //0x08cb version
  16493. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16494. WFIFOW(fd,info->pos[2]) = tot_drop;
  16495. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16496. }
  16497. else { //2013-08-07aRagexe uses 0x097b
  16498. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16499. WFIFOL(fd,info->pos[2]) = tot_drop;
  16500. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16501. }
  16502. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16503. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16504. WFIFOSET(fd,len);
  16505. }
  16506. }
  16507. #endif
  16508. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16509. char cmd[30];
  16510. int t_aid = RFIFOL(fd,2);
  16511. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16512. is_atcommand(fd, sd, cmd, 1);
  16513. }
  16514. /**
  16515. * Marks Crimson Marker target on mini-map to the caster
  16516. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16517. * @param fd
  16518. * @param bl Crimson Marker target
  16519. **/
  16520. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16521. struct s_packet_db* info;
  16522. int cmd = 0;
  16523. int16 len;
  16524. unsigned char buf[11];
  16525. nullpo_retv(sd);
  16526. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16527. if (!cmd)
  16528. cmd = 0x09C1; //default
  16529. info = &packet_db[cmd];
  16530. if (!(len = info->len))
  16531. return;
  16532. WBUFW(buf, 0) = cmd;
  16533. WBUFL(buf, info->pos[0]) = bl->id;
  16534. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16535. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16536. clif_send(buf, len, &sd->bl, SELF);
  16537. }
  16538. /**
  16539. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16540. **/
  16541. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16542. struct s_packet_db *info = NULL;
  16543. int cmd = 0;
  16544. nullpo_retv(sd);
  16545. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16546. info = &packet_db[cmd];
  16547. if (!cmd || !info->len)
  16548. return;
  16549. WFIFOHEAD(sd->fd, info->len);
  16550. WFIFOW(sd->fd, 0) = cmd;
  16551. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16552. WFIFOSET(sd->fd, info->len);
  16553. }
  16554. /**
  16555. * [Ind/Hercules]
  16556. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16557. **/
  16558. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16559. char buf[256];
  16560. size_t len;
  16561. nullpo_retv(bl);
  16562. if(!message)
  16563. return;
  16564. len = strlen(message)+1;
  16565. if( len > sizeof(buf)-8 ) {
  16566. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16567. len = sizeof(buf)-8;
  16568. }
  16569. WBUFW(buf,0) = 0x8b3;
  16570. WBUFW(buf,2) = (uint16)(len+8);
  16571. WBUFL(buf,4) = bl->id;
  16572. safestrncpy(WBUFCP(buf,8), message, len);
  16573. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16574. }
  16575. /**
  16576. * [Ind/Hercules]
  16577. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16578. **/
  16579. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16580. unsigned char buf[10];
  16581. nullpo_retv(sd);
  16582. WBUFW(buf,0) = 0x7fc;
  16583. WBUFL(buf,2) = prev_leader_aid;
  16584. WBUFL(buf,6) = new_leader_aid;
  16585. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16586. }
  16587. /**
  16588. * Sends a clan message to a player
  16589. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16590. **/
  16591. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16592. #if PACKETVER >= 20131223
  16593. struct map_session_data *sd;
  16594. uint8 buf[256];
  16595. if( len == 0 ){
  16596. return;
  16597. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16598. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16599. len = sizeof(buf)-5-NAME_LENGTH;
  16600. }
  16601. WBUFW(buf, 0) = 0x98e;
  16602. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16603. // 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
  16604. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16605. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16606. if((sd = clan_getavailablesd(clan)) != NULL)
  16607. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16608. #endif
  16609. }
  16610. /**
  16611. * Parses a clan message from a player.
  16612. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16613. **/
  16614. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16615. #if PACKETVER >= 20131223
  16616. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16617. // validate packet and retrieve name and message
  16618. if( !clif_process_message(sd, false, name, message, output ) )
  16619. return;
  16620. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16621. #endif
  16622. }
  16623. /**
  16624. * Sends the basic clan informations to the client.
  16625. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16626. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16627. **/
  16628. void clif_clan_basicinfo( struct map_session_data *sd ){
  16629. #if PACKETVER >= 20131223
  16630. int fd, offset, length, i, flag;
  16631. struct clan* clan;
  16632. char mapname[MAP_NAME_LENGTH_EXT];
  16633. nullpo_retv( sd );
  16634. nullpo_retv( clan = sd->clan );
  16635. // Check if the player has a valid session and is not autotrading
  16636. if( !clif_session_isValid( sd ) ){
  16637. return;
  16638. }
  16639. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16640. fd = sd->fd;
  16641. WFIFOHEAD(fd,length);
  16642. memset( WFIFOP(fd, 0), 0, length );
  16643. WFIFOW( fd, 0 ) = 0x98a;
  16644. WFIFOL( fd, 4 ) = clan->id;
  16645. offset = 8;
  16646. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16647. offset += NAME_LENGTH;
  16648. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16649. offset += NAME_LENGTH;
  16650. mapindex_getmapname_ext( clan->map, mapname );
  16651. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16652. offset += MAP_NAME_LENGTH_EXT;
  16653. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16654. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16655. for( flag = 0; flag < 2; flag++ ){
  16656. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16657. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16658. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16659. offset += NAME_LENGTH;
  16660. }
  16661. }
  16662. }
  16663. WFIFOW( fd, 2 ) = offset;
  16664. WFIFOSET(fd,offset);
  16665. #endif
  16666. }
  16667. /**
  16668. * Updates the online and maximum player count of a clan.
  16669. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16670. **/
  16671. void clif_clan_onlinecount( struct clan* clan ){
  16672. #if PACKETVER >= 20131223
  16673. uint8 buf[6];
  16674. struct map_session_data *sd;
  16675. WBUFW(buf,0) = 0x988;
  16676. WBUFW(buf,2) = clan->connect_member;
  16677. WBUFW(buf,4) = clan->max_member;
  16678. if((sd = clan_getavailablesd(clan)) != NULL)
  16679. clif_send(buf, 6, &sd->bl, CLAN);
  16680. #endif
  16681. }
  16682. /**
  16683. * Notifies the client that the player has left his clan.
  16684. * 0989 (ZC_ACK_CLAN_LEAVE)
  16685. **/
  16686. void clif_clan_leave( struct map_session_data* sd ){
  16687. #if PACKETVER >= 20131223
  16688. int fd;
  16689. nullpo_retv( sd );
  16690. if( !clif_session_isValid( sd ) ){
  16691. return;
  16692. }
  16693. fd = sd->fd;
  16694. WFIFOHEAD(fd,2);
  16695. WFIFOW(fd,0) = 0x989;
  16696. WFIFOSET(fd,2);
  16697. #endif
  16698. }
  16699. /**
  16700. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16701. * 0A2F <result>.B <title_id>.L
  16702. */
  16703. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16704. {
  16705. #if PACKETVER >= 20150513
  16706. int fd;
  16707. nullpo_retv(sd);
  16708. if (!clif_session_isValid(sd))
  16709. return;
  16710. fd = sd->fd;
  16711. WFIFOHEAD(fd, packet_len(0xa2f));
  16712. WFIFOW(fd, 0) = 0xa2f;
  16713. WFIFOB(fd, 2) = result;
  16714. WFIFOL(fd, 3) = title_id;
  16715. WFIFOSET(fd, packet_len(0xa2f));
  16716. #endif
  16717. }
  16718. /**
  16719. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16720. * 0A2E <title_id>.L
  16721. */
  16722. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16723. {
  16724. int title_id;
  16725. nullpo_retv(sd);
  16726. title_id = RFIFOL(fd, 2);
  16727. if( title_id == sd->status.title_id ){
  16728. // It is exactly the same as the old one
  16729. return;
  16730. }else if( title_id <= 0 ){
  16731. sd->status.title_id = 0;
  16732. }else{
  16733. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16734. clif_change_title_ack(sd, 1, title_id);
  16735. return;
  16736. }
  16737. sd->status.title_id = title_id;
  16738. }
  16739. clif_name_area(&sd->bl);
  16740. clif_change_title_ack(sd, 0, title_id);
  16741. }
  16742. #ifdef DUMP_UNKNOWN_PACKET
  16743. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16744. {
  16745. const char* packet_txt = "save/packet.txt";
  16746. FILE* fp;
  16747. time_t time_server;
  16748. struct tm *datetime;
  16749. char datestr[512];
  16750. time(&time_server); // get time in seconds since 1/1/1970
  16751. datetime = localtime(&time_server); // convert seconds in structure
  16752. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16753. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16754. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16755. if( sd ) {
  16756. 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);
  16757. } else {
  16758. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16759. }
  16760. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16761. fprintf(fp, "\n");
  16762. fclose(fp);
  16763. } else {
  16764. ShowError("Failed to write '%s'.\n", packet_txt);
  16765. // Dump on console instead
  16766. if( sd ) {
  16767. 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);
  16768. } else {
  16769. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16770. }
  16771. ShowDump(RFIFOP(fd,0), packet_len);
  16772. }
  16773. }
  16774. #endif
  16775. /// Roulette System
  16776. /// Author: Yommy
  16777. /// Opens the roulette window
  16778. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16779. void clif_roulette_open( struct map_session_data* sd ){
  16780. nullpo_retv( sd );
  16781. struct packet_roulette_open_ack p;
  16782. p.PacketType = 0xa1a;
  16783. p.Result = 0; // result
  16784. p.Serial = 0; // serial
  16785. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16786. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16787. p.AdditionItemID = -1; //! TODO: Display bonus item
  16788. p.GoldPoint = sd->roulette_point.gold;
  16789. p.SilverPoint = sd->roulette_point.silver;
  16790. p.BronzePoint = sd->roulette_point.bronze;
  16791. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16792. }
  16793. /// Request to open the roulette window
  16794. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16795. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16796. nullpo_retv(sd);
  16797. if (!battle_config.feature_roulette) {
  16798. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16799. return;
  16800. }
  16801. clif_roulette_open(sd);
  16802. }
  16803. /// Sends the info about the available roulette rewards to the client
  16804. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16805. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16806. void clif_roulette_info( struct map_session_data* sd ){
  16807. nullpo_retv(sd);
  16808. struct packet_roulette_info_ack p;
  16809. p.PacketType = rouletteinfoackType;
  16810. p.PacketLength = sizeof(p);
  16811. p.RouletteSerial = 1;
  16812. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16813. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16814. p.ItemInfo[count].Row = i;
  16815. p.ItemInfo[count].Position = j;
  16816. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  16817. p.ItemInfo[count].Count = rd.qty[i][j];
  16818. #if PACKETVER >= 20180511
  16819. p.ItemInfo[count].unused = 0;
  16820. #endif
  16821. count++;
  16822. }
  16823. }
  16824. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16825. }
  16826. /// Request the roulette reward data
  16827. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16828. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16829. nullpo_retv(sd);
  16830. if (!battle_config.feature_roulette) {
  16831. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16832. return;
  16833. }
  16834. clif_roulette_info(sd);
  16835. }
  16836. /// Notification of the client that the roulette window was closed
  16837. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16838. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16839. nullpo_retv(sd);
  16840. if (!battle_config.feature_roulette) {
  16841. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16842. return;
  16843. }
  16844. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16845. }
  16846. /// Response to a item reward request
  16847. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16848. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16849. #if PACKETVER >= 20141016
  16850. nullpo_retv(sd);
  16851. struct packet_roulette_itemrecv_ack p;
  16852. p.PacketType = roulettercvitemackType;
  16853. p.Result = type;
  16854. p.AdditionItemID = 0; //! TODO: Additional item
  16855. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16856. #endif
  16857. }
  16858. /**
  16859. * Claim roulette reward
  16860. * @param sd Player
  16861. * @return 0:Success
  16862. **/
  16863. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16864. struct item it;
  16865. uint8 res = 1;
  16866. nullpo_retr(1, sd);
  16867. if (sd->roulette.prizeIdx < 0)
  16868. return RECV_ITEM_FAILED;
  16869. memset(&it, 0, sizeof(it));
  16870. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16871. it.identify = 1;
  16872. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16873. ; // onSuccess
  16874. }
  16875. sd->roulette.claimPrize = false;
  16876. sd->roulette.prizeStage = 0;
  16877. sd->roulette.prizeIdx = -1;
  16878. sd->roulette.stage = 0;
  16879. return res;
  16880. }
  16881. /// Update Roulette window with current stats
  16882. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16883. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  16884. nullpo_retv( sd );
  16885. struct packet_roulette_generate_ack p;
  16886. p.PacketType = roulettgenerateackType;
  16887. p.Result = result;
  16888. p.Step = stage;
  16889. p.Idx = prizeIdx;
  16890. p.AdditionItemID = bonusItemID;
  16891. p.RemainGold = sd->roulette_point.gold;
  16892. p.RemainSilver = sd->roulette_point.silver;
  16893. p.RemainBronze = sd->roulette_point.bronze;
  16894. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16895. }
  16896. /// Request to start the roulette
  16897. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16898. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16899. enum GENERATE_ROULETTE_ACK result;
  16900. nullpo_retv(sd);
  16901. if (!battle_config.feature_roulette) {
  16902. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16903. return;
  16904. }
  16905. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16906. return;
  16907. }
  16908. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16909. sd->roulette.stage = 0;
  16910. sd->roulette.claimPrize = false;
  16911. sd->roulette.prizeStage = 0;
  16912. sd->roulette.prizeIdx = -1;
  16913. }
  16914. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16915. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16916. }else{
  16917. if (!sd->roulette.stage) {
  16918. if (sd->roulette_point.bronze > 0) {
  16919. sd->roulette_point.bronze -= 1;
  16920. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16921. } else if (sd->roulette_point.silver > 9) {
  16922. sd->roulette_point.silver -= 10;
  16923. sd->roulette.stage = 2;
  16924. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16925. } else if (sd->roulette_point.gold > 9) {
  16926. sd->roulette_point.gold -= 10;
  16927. sd->roulette.stage = 4;
  16928. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16929. }
  16930. }
  16931. sd->roulette.prizeStage = sd->roulette.stage;
  16932. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16933. sd->roulette.claimPrize = true;
  16934. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16935. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16936. result = GENERATE_ROULETTE_LOSING;
  16937. sd->roulette.stage = 0;
  16938. }else{
  16939. result = GENERATE_ROULETTE_SUCCESS;
  16940. sd->roulette.stage++;
  16941. }
  16942. }
  16943. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16944. }
  16945. /// Request to claim a prize
  16946. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16947. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16948. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16949. nullpo_retv(sd);
  16950. if (!battle_config.feature_roulette) {
  16951. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16952. return;
  16953. }
  16954. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16955. return;
  16956. }
  16957. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16958. switch (clif_roulette_getitem(sd)) {
  16959. case ADDITEM_SUCCESS:
  16960. type = RECV_ITEM_SUCCESS;
  16961. break;
  16962. case ADDITEM_INVALID:
  16963. case ADDITEM_OVERITEM:
  16964. case ADDITEM_OVERAMOUNT:
  16965. type = RECV_ITEM_OVERCOUNT;
  16966. break;
  16967. case ADDITEM_OVERWEIGHT:
  16968. type = RECV_ITEM_OVERWEIGHT;
  16969. break;
  16970. case ADDITEM_STACKLIMIT:
  16971. default:
  16972. type = RECV_ITEM_FAILED;
  16973. break;
  16974. }
  16975. }
  16976. clif_roulette_recvitem_ack(sd,type);
  16977. }
  16978. /// MERGE ITEM
  16979. /**
  16980. * Acknowledge the client about item merger result
  16981. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16982. * @param fd
  16983. * @param sd
  16984. **/
  16985. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16986. unsigned char buf[9];
  16987. struct s_packet_db *info = NULL;
  16988. short cmd = 0;
  16989. nullpo_retv(sd);
  16990. if (!clif_session_isValid(sd))
  16991. return;
  16992. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16993. return;
  16994. if (!(info = &packet_db[cmd]) || info->len == 0)
  16995. return;
  16996. WBUFW(buf, 0) = cmd;
  16997. WBUFW(buf, info->pos[0]) = index;
  16998. WBUFW(buf, info->pos[1]) = count;
  16999. WBUFB(buf, info->pos[2]) = type;
  17000. clif_send(buf, info->len, &sd->bl, SELF);
  17001. }
  17002. /**
  17003. * Check if item has the pair to be merged
  17004. * @param sd
  17005. * @param it Item
  17006. * @return True if has pair, False if not
  17007. **/
  17008. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17009. struct item *it_;
  17010. unsigned short i;
  17011. nullpo_retr(false, sd);
  17012. 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);
  17013. if (i < MAX_INVENTORY)
  17014. return true;
  17015. return false;
  17016. }
  17017. /**
  17018. * Check if item can be merged
  17019. * @param id Item Data
  17020. * @param it Item
  17021. * @return True if can be merged, False if not
  17022. **/
  17023. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17024. if (!id || !it)
  17025. return false;
  17026. if (id->type == IT_CASH)
  17027. return false;
  17028. if (!itemdb_isstackable2(id))
  17029. return false;
  17030. if (itemdb_isspecial(it->card[0]))
  17031. return false;
  17032. if (!it->unique_id)
  17033. return false;
  17034. return true;
  17035. }
  17036. /**
  17037. * Open available item to be merged.
  17038. * Only show 1 item in 1 process.
  17039. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17040. * @param sd
  17041. **/
  17042. void clif_merge_item_open(struct map_session_data *sd) {
  17043. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  17044. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  17045. int len = 0;
  17046. struct s_packet_db *info = NULL;
  17047. struct item *it;
  17048. nullpo_retv(sd);
  17049. if (!clif_session_isValid(sd))
  17050. return;
  17051. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  17052. return;
  17053. if (!(info = &packet_db[cmd]) || info->len == 0)
  17054. return;
  17055. // Get entries
  17056. for (i = 0; i < MAX_INVENTORY; i++) {
  17057. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  17058. continue;
  17059. if (clif_merge_item_has_pair(sd, it))
  17060. indexes[n++] = i;
  17061. }
  17062. if (n < 2) { // No item need to be merged
  17063. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17064. return;
  17065. }
  17066. WBUFW(buf, 0) = cmd;
  17067. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  17068. for (i = 0; i < n; i++) {
  17069. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  17070. }
  17071. clif_send(buf, len, &sd->bl, SELF);
  17072. }
  17073. /**
  17074. * Process item merger
  17075. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17076. * @param fd
  17077. * @param sd
  17078. **/
  17079. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17080. struct s_packet_db *info = NULL;
  17081. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17082. unsigned int count = 0;
  17083. struct item_data *id = NULL;
  17084. nullpo_retv(sd);
  17085. if (!clif_session_isValid(sd))
  17086. return;
  17087. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17088. return;
  17089. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17090. if (n < 2) { // No item need to be merged
  17091. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17092. return;
  17093. }
  17094. for (i = 0, j = 0; i < n; i++) {
  17095. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  17096. if( idx < 0 || idx >= MAX_INVENTORY ){
  17097. return;
  17098. }
  17099. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17100. continue;
  17101. indexes[j] = idx;
  17102. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17103. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17104. return;
  17105. }
  17106. count += sd->inventory.u.items_inventory[idx].amount;
  17107. j++;
  17108. }
  17109. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17110. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17111. return;
  17112. }
  17113. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17114. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17115. return;
  17116. }
  17117. // Merrrrge!!!!
  17118. for (i = 1; i < n; i++) {
  17119. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17120. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17121. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17122. sd->inventory_data[idx] = NULL;
  17123. clif_delitem(sd, idx, amt, 0);
  17124. }
  17125. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17126. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17127. }
  17128. /**
  17129. * Cancel item merge
  17130. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17131. * @param fd
  17132. * @param sd
  17133. **/
  17134. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17135. return; // Nothing todo yet
  17136. }
  17137. /**
  17138. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17139. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17140. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17141. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17142. **/
  17143. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17144. char name[NAME_LENGTH];
  17145. if( battle_config.broadcast_hide_name ){
  17146. std::string dispname = std::string( char_name );
  17147. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  17148. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  17149. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  17150. }else{
  17151. safestrncpy( name, char_name, sizeof( name ) );
  17152. }
  17153. switch( type ){
  17154. case ITEMOBTAIN_TYPE_BOXITEM:
  17155. {
  17156. struct packet_package_item_announce p;
  17157. p.PacketType = package_item_announceType;
  17158. p.type = type;
  17159. p.ItemID = client_nameid( nameid );
  17160. p.len = NAME_LENGTH;
  17161. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17162. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  17163. p.BoxItemID = client_nameid( container );
  17164. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17165. p.PacketLength = 15 + p.len;
  17166. #else
  17167. p.PacketLength = 11 + p.len;
  17168. #endif
  17169. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17170. }
  17171. break;
  17172. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17173. case ITEMOBTAIN_TYPE_NPC:
  17174. {
  17175. struct packet_item_drop_announce p;
  17176. p.PacketType = item_drop_announceType;
  17177. p.type = type;
  17178. p.ItemID = client_nameid( nameid );
  17179. p.len = NAME_LENGTH;
  17180. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17181. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17182. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17183. p.monsterNameLen = NAME_LENGTH;
  17184. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17185. }else{
  17186. p.monsterNameLen = 0;
  17187. p.monsterName[0] = '\0';
  17188. }
  17189. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17190. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17191. #else
  17192. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17193. #endif
  17194. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17195. }
  17196. break;
  17197. }
  17198. }
  17199. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17200. /// 0A02 <view>.W
  17201. /// Value <flag> has the following effects:
  17202. /// 1: Open a Dress Room window.
  17203. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17204. #if PACKETVER >= 20150513
  17205. int fd = sd->fd;
  17206. nullpo_retv(sd);
  17207. WFIFOHEAD(fd, packet_len(0xa02));
  17208. WFIFOW(fd,0) = 0xa02;
  17209. WFIFOW(fd,2) = flag;
  17210. WFIFOSET(fd, packet_len(0xa02));
  17211. #endif
  17212. }
  17213. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17214. /// 0A35 <result>.W
  17215. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17216. #if PACKETVER >= 20150513
  17217. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17218. // Ignore the request
  17219. // - Invalid item index
  17220. // - Invalid item ID or item doesn't exist
  17221. // - Item is already identified
  17222. if (idx < 0 || idx >= MAX_INVENTORY ||
  17223. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17224. sd->inventory.u.items_inventory[idx].identify)
  17225. return;
  17226. // Ignore the request - No magnifiers in inventory
  17227. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17228. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17229. return;
  17230. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17231. return;
  17232. skill_identify(sd, idx);
  17233. #endif
  17234. }
  17235. /// Starts navigation to the given target on client side
  17236. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17237. #if PACKETVER >= 20111010
  17238. int fd = sd->fd;
  17239. WFIFOHEAD(fd,27);
  17240. WFIFOW(fd,0) = 0x08e2;
  17241. // How detailed will our navigation be?
  17242. if( mob_id > 0 ){
  17243. x = 0;
  17244. y = 0;
  17245. WFIFOB(fd,2) = 3; // monster with destination field
  17246. }else if( x > 0 && y > 0 ){
  17247. WFIFOB(fd,2) = 0; // with coordinates
  17248. }else{
  17249. x = 0;
  17250. y = 0;
  17251. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17252. }
  17253. // Which services can be used for transportation?
  17254. WFIFOB(fd,3) = flag;
  17255. // If this flag is set, the navigation window will not be opened up
  17256. WFIFOB(fd,4) = hideWindow;
  17257. // Target map
  17258. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17259. // Target x
  17260. WFIFOW(fd,21) = x;
  17261. // Target y
  17262. WFIFOW(fd,23) = y;
  17263. // Target monster ID
  17264. WFIFOW(fd,25) = mob_id;
  17265. WFIFOSET(fd,27);
  17266. #endif
  17267. }
  17268. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17269. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17270. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17271. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17272. struct map_session_data *tsd;
  17273. struct block_list* tbl;
  17274. if( target == SELF ){
  17275. tsd = BL_CAST(BL_PC,bl);
  17276. tbl = &sd->bl;
  17277. }else{
  17278. tsd = sd;
  17279. tbl = bl;
  17280. }
  17281. nullpo_retv( tsd );
  17282. if( tsd->hatEffects.empty() ){
  17283. return;
  17284. }
  17285. struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
  17286. p->packetType = HEADER_ZC_HAT_EFFECT;
  17287. p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17288. p->aid = tsd->bl.id;
  17289. p->status = 1;
  17290. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17291. p->effects[i] = tsd->hatEffects[i];
  17292. }
  17293. clif_send( p, p->packetLength, tbl, target );
  17294. #endif
  17295. }
  17296. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17297. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17298. nullpo_retv( sd );
  17299. struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
  17300. p->packetType = HEADER_ZC_HAT_EFFECT;
  17301. p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) );
  17302. p->aid = sd->bl.id;
  17303. p->status = enable;
  17304. p->effects[0] = effectId;
  17305. clif_send( p, p->packetLength, &sd->bl, AREA );
  17306. #endif
  17307. }
  17308. /// Notify the client that a sale has started
  17309. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17310. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17311. #if PACKETVER_SUPPORTS_SALES
  17312. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17313. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17314. p.itemId = client_nameid( sale_item->nameid );
  17315. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17316. clif_send( &p, sizeof( p ), bl, target );
  17317. #endif
  17318. }
  17319. /// Notify the client that a sale has ended
  17320. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17321. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17322. #if PACKETVER_SUPPORTS_SALES
  17323. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17324. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17325. p.itemId = client_nameid( sale_item->nameid );
  17326. clif_send( &p, sizeof( p ), bl, target );
  17327. #endif
  17328. }
  17329. /// Update the remaining amount of a sale item.
  17330. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17331. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17332. #if PACKETVER_SUPPORTS_SALES
  17333. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17334. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17335. p.itemId = client_nameid( sale_item->nameid );
  17336. p.amount = sale_item->amount;
  17337. clif_send( &p, sizeof( p ), bl, target );
  17338. #endif
  17339. }
  17340. /// The client requested a refresh of the current remaining count of a sale item
  17341. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17342. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17343. #if PACKETVER_SUPPORTS_SALES
  17344. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17345. struct sale_item_data* sale;
  17346. if( p->AID != sd->status.account_id ){
  17347. return;
  17348. }
  17349. sale = sale_find_item( p->itemId, true );
  17350. if( sale == NULL ){
  17351. return;
  17352. }
  17353. clif_sale_amount(sale, &sd->bl, SELF);
  17354. #endif
  17355. }
  17356. /// Opens the sale administration window on the client
  17357. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17358. void clif_sale_open( struct map_session_data* sd ){
  17359. #if PACKETVER_SUPPORTS_SALES
  17360. nullpo_retv(sd);
  17361. if( sd->state.sale_open ){
  17362. return;
  17363. }
  17364. sd->state.sale_open = true;
  17365. int fd = sd->fd;
  17366. WFIFOHEAD(fd, 2);
  17367. WFIFOW(fd, 0) = 0x9b5;
  17368. WFIFOSET(fd, 2);
  17369. #endif
  17370. }
  17371. /// Client request to open the sale administration window.
  17372. /// This is sent by /limitedsale
  17373. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17374. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17375. #if PACKETVER_SUPPORTS_SALES
  17376. nullpo_retv(sd);
  17377. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17378. return;
  17379. }
  17380. char command[CHAT_SIZE_MAX];
  17381. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17382. is_atcommand(fd, sd, command, 1);
  17383. #endif
  17384. }
  17385. /// Closes the sale administration window on the client.
  17386. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17387. void clif_sale_close(struct map_session_data* sd) {
  17388. #if PACKETVER_SUPPORTS_SALES
  17389. nullpo_retv(sd);
  17390. if( !sd->state.sale_open ){
  17391. return;
  17392. }
  17393. sd->state.sale_open = false;
  17394. int fd = sd->fd;
  17395. WFIFOHEAD(fd, 2);
  17396. WFIFOW(fd, 0) = 0x9bd;
  17397. WFIFOSET(fd, 2);
  17398. #endif
  17399. }
  17400. /// Client request to close the sale administration window.
  17401. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17402. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17403. #if PACKETVER_SUPPORTS_SALES
  17404. nullpo_retv(sd);
  17405. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17406. return;
  17407. }
  17408. clif_sale_close(sd);
  17409. #endif
  17410. }
  17411. /// Reply to a item search request for item sale administration.
  17412. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17413. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17414. #if PACKETVER_SUPPORTS_SALES
  17415. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17416. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17417. if( item != NULL ){
  17418. p.result = 0;
  17419. p.itemId = client_nameid( item->nameid );
  17420. p.price = item->price;
  17421. }else{
  17422. p.result = 1;
  17423. p.itemId = 0;
  17424. p.price = 0;
  17425. }
  17426. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17427. #endif
  17428. }
  17429. /// Search request for an item sale administration.
  17430. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17431. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17432. #if PACKETVER_SUPPORTS_SALES
  17433. char item_name[ITEM_NAME_LENGTH];
  17434. struct item_data *id = NULL;
  17435. nullpo_retv(sd);
  17436. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17437. return;
  17438. }
  17439. if( !sd->state.sale_open ){
  17440. return;
  17441. }
  17442. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17443. id = itemdb_searchname(item_name);
  17444. if( id ){
  17445. int i;
  17446. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17447. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17448. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17449. return;
  17450. }
  17451. }
  17452. }
  17453. // not found
  17454. clif_sale_search_reply( sd, NULL );
  17455. #endif
  17456. }
  17457. /// Reply if an item was successfully put on sale or not.
  17458. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17459. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17460. #if PACKETVER_SUPPORTS_SALES
  17461. int fd = sd->fd;
  17462. WFIFOHEAD(fd, 4);
  17463. WFIFOW(fd, 0) = 0x9af;
  17464. WFIFOW(fd, 2) = (uint16)result;
  17465. WFIFOSET(fd, 4);
  17466. #endif
  17467. }
  17468. /// A client request to put an item on sale.
  17469. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17470. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17471. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17472. #if PACKETVER_SUPPORTS_SALES
  17473. nullpo_retv( sd );
  17474. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17475. if( p->AID != sd->status.account_id ){
  17476. return;
  17477. }
  17478. if( !sd->state.sale_open ){
  17479. return;
  17480. }
  17481. time_t endTime = p->startTime + p->hours * 60 * 60;
  17482. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17483. #endif
  17484. }
  17485. /// Reply to an item removal from sale.
  17486. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17487. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17488. #if PACKETVER_SUPPORTS_SALES
  17489. int fd = sd->fd;
  17490. WFIFOHEAD(fd, 4);
  17491. WFIFOW(fd, 0) = 0x9b1;
  17492. WFIFOW(fd, 2) = failed;
  17493. WFIFOSET(fd, 4);
  17494. #endif
  17495. }
  17496. /// Request to remove an item from sale.
  17497. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17498. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17499. #if PACKETVER_SUPPORTS_SALES
  17500. nullpo_retv( sd );
  17501. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17502. if( p->AID != sd->status.account_id ){
  17503. return;
  17504. }
  17505. if( !sd->state.sale_open ){
  17506. return;
  17507. }
  17508. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17509. #endif
  17510. }
  17511. /// Achievement System
  17512. /// Author: Luxuri, Aleos
  17513. /**
  17514. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17515. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17516. */
  17517. void clif_achievement_list_all(struct map_session_data *sd)
  17518. {
  17519. nullpo_retv(sd);
  17520. if (!battle_config.feature_achievement) {
  17521. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17522. return;
  17523. }
  17524. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17525. if (count == 0)
  17526. return;
  17527. int len = (50 * count) + 22;
  17528. int fd = sd->fd;
  17529. int *info = achievement_level(sd, true);
  17530. WFIFOHEAD(fd,len);
  17531. WFIFOW(fd, 0) = 0xa23;
  17532. WFIFOW(fd, 2) = len;
  17533. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17534. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17535. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17536. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17537. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17538. for (int i = 0; i < count; i++) {
  17539. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17540. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17541. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17542. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17543. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17544. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17545. }
  17546. WFIFOSET(fd, len);
  17547. }
  17548. /**
  17549. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17550. * 0a24 <ACHPoint>.L
  17551. */
  17552. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17553. {
  17554. nullpo_retv(sd);
  17555. if (!battle_config.feature_achievement) {
  17556. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17557. return;
  17558. }
  17559. int fd = sd->fd;
  17560. int *info = achievement_level(sd, true);
  17561. WFIFOHEAD(fd, packet_len(0xa24));
  17562. WFIFOW(fd, 0) = 0xa24;
  17563. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17564. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17565. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17566. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17567. if (ach) {
  17568. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17569. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17570. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17571. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17572. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17573. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17574. } else
  17575. memset(WFIFOP(fd, 16), 0, 40);
  17576. WFIFOSET(fd, packet_len(0xa24));
  17577. }
  17578. /**
  17579. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17580. * 0a25 <achievementID>.L
  17581. */
  17582. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17583. {
  17584. nullpo_retv(sd);
  17585. if( sd->achievement_data.save )
  17586. intif_achievement_save(sd);
  17587. achievement_check_reward(sd, RFIFOL(fd,2));
  17588. }
  17589. /**
  17590. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17591. * 0a26 <result>.W <achievementID>.L
  17592. */
  17593. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17594. {
  17595. WFIFOHEAD(fd, packet_len(0xa26));
  17596. WFIFOW(fd, 0) = 0xa26;
  17597. WFIFOB(fd, 2) = result;
  17598. WFIFOL(fd, 3) = achievement_id;
  17599. WFIFOSET(fd, packet_len(0xa26));
  17600. }
  17601. /// Process the pet evolution request
  17602. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17603. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17604. #if PACKETVER >= 20141008
  17605. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17606. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17607. if (!pet) {
  17608. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17609. return;
  17610. }
  17611. pet_evolution(sd, pet->class_);
  17612. #endif
  17613. }
  17614. /// Sends the result of the evolution to the client.
  17615. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17616. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17617. #if PACKETVER >= 20141008
  17618. int fd = sd->fd;
  17619. WFIFOHEAD(fd, packet_len(0x9fc));
  17620. WFIFOW(fd, 0) = 0x9fc;
  17621. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17622. WFIFOSET(fd, packet_len(0x9fc));
  17623. #endif
  17624. }
  17625. /*
  17626. * This packet is sent by /changedress or /nocosplay
  17627. *
  17628. * 0ae8
  17629. */
  17630. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17631. #if PACKETVER >= 20180103
  17632. char command[CHAT_SIZE_MAX];
  17633. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17634. is_atcommand( fd, sd, command, 1 );
  17635. #endif
  17636. }
  17637. /// Opens an UI window of the given type and initializes it with the given data
  17638. /// 0AE2 <type>.B <data>.L
  17639. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17640. nullpo_retv(sd);
  17641. int fd = sd->fd;
  17642. WFIFOHEAD(fd,packet_len(0xae2));
  17643. WFIFOW(fd,0) = 0xae2;
  17644. WFIFOB(fd,2) = ui_type;
  17645. WFIFOL(fd,3) = data;
  17646. WFIFOSET(fd,packet_len(0xae2));
  17647. }
  17648. /// Request to open an UI window of the given type
  17649. /// 0A68 <type>.B
  17650. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17651. switch( RFIFOB(fd,2) ){
  17652. case IN_UI_ATTENDANCE:
  17653. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17654. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17655. }else if( pc_attendance_enabled() ){
  17656. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17657. }else{
  17658. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17659. }
  17660. break;
  17661. }
  17662. }
  17663. /// Response for attedance request
  17664. /// 0AF0 <unknown>.L <data>.L
  17665. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17666. nullpo_retv(sd);
  17667. int fd = sd->fd;
  17668. WFIFOHEAD(fd,packet_len(0xAF0));
  17669. WFIFOW(fd,0) = 0xAF0;
  17670. WFIFOL(fd,2) = 0;
  17671. WFIFOL(fd,6) = data;
  17672. WFIFOSET(fd,packet_len(0xAF0));
  17673. }
  17674. /// Request from the client to retrieve today's attendance reward
  17675. /// 0AEF
  17676. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17677. pc_attendance_claim_reward(sd);
  17678. }
  17679. /// Send out the percentage of weight that causes it to be displayed in red.
  17680. /// 0ADE <percentage>.L
  17681. void clif_weight_limit( struct map_session_data* sd ){
  17682. #if PACKETVER >= 20171025
  17683. nullpo_retv(sd);
  17684. int fd = sd->fd;
  17685. WFIFOHEAD(fd, packet_len(0xADE));
  17686. WFIFOW(fd, 0) = 0xADE;
  17687. #ifdef RENEWAL
  17688. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17689. #else
  17690. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17691. #endif
  17692. WFIFOSET(fd, packet_len(0xADE));
  17693. #endif
  17694. }
  17695. enum e_private_airship_response : uint32{
  17696. PRIVATEAIRSHIP_OK,
  17697. PRIVATEAIRSHIP_RETRY,
  17698. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17699. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17700. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17701. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17702. };
  17703. /// Send out the response to a private airship request
  17704. /// 0A4A <response>.L
  17705. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17706. #if PACKETVER >= 20180321
  17707. nullpo_retv( sd );
  17708. int fd = sd->fd;
  17709. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17710. WFIFOW( fd, 0 ) = 0xA4A;
  17711. WFIFOL( fd, 2 ) = response;
  17712. WFIFOSET( fd, packet_len( 0xA4A ) );
  17713. #endif
  17714. }
  17715. /// Parses a request for a private airship
  17716. /// 0A49 <mapname>.16B <itemid>.W
  17717. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17718. #if PACKETVER >= 20180321
  17719. // Check if the feature is enabled
  17720. if( !battle_config.feature_privateairship ){
  17721. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17722. return;
  17723. }
  17724. // Check if the player is allowed to warp from the source map
  17725. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17726. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17727. return;
  17728. }
  17729. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17730. char mapname[MAP_NAME_LENGTH_EXT];
  17731. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17732. int16 mapindex = mapindex_name2id( mapname );
  17733. // Check if we know the mapname
  17734. if( mapindex < 0 ){
  17735. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17736. return;
  17737. }
  17738. int16 mapid = map_mapindex2mapid( mapindex );
  17739. // Check if the map is available on this server
  17740. if( mapid < 0 ){
  17741. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17742. return;
  17743. }
  17744. // Check if the player tried to warp to the map he is on
  17745. if( sd->bl.m == mapid ){
  17746. // This is blocked by the client, but just to be sure
  17747. return;
  17748. }
  17749. // This can only be a hack, so we prevent it
  17750. if( map_getmapdata( mapid )->instance_id ){
  17751. // Ignore requests to warp directly into a running instance
  17752. return;
  17753. }
  17754. // Check if the player is allowed to warp to the target map
  17755. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17756. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17757. return;
  17758. }
  17759. t_itemid item_id = p->ItemID;
  17760. // Check if the item sent by the client is known to us
  17761. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17762. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17763. return;
  17764. }
  17765. int idx = pc_search_inventory( sd, item_id );
  17766. // Check if the player has the item at all
  17767. if( idx < 0 ){
  17768. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17769. return;
  17770. }
  17771. // Delete the chosen item
  17772. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17773. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17774. return;
  17775. }
  17776. // Warp the player to a random spot on the destination map
  17777. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17778. #endif
  17779. }
  17780. /// Sends out the usage history of the guild storage
  17781. /// 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
  17782. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17783. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17784. #if PACKETVER >= 20140205
  17785. nullpo_retv( sd );
  17786. int fd = sd->fd;
  17787. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17788. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17789. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17790. }else{
  17791. log.clear();
  17792. }
  17793. WFIFOHEAD( fd, size );
  17794. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  17795. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17796. p->PacketLength = size;
  17797. p->result = result;
  17798. p->amount = (uint16)log.size();
  17799. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17800. for( int i = 0; i < log.size(); i++ ){
  17801. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  17802. struct guild_log_entry& entry = log[i];
  17803. item->id = entry.id;
  17804. item->itemId = client_nameid( entry.item.nameid );
  17805. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  17806. item->action = entry.amount > 0; // action = true(put), false(get)
  17807. item->refine = entry.item.refine;
  17808. item->uniqueId = entry.item.unique_id;
  17809. item->IsIdentified = entry.item.identify;
  17810. item->itemType = itemtype( entry.item.nameid );
  17811. clif_addcards( &item->slot, &entry.item );
  17812. safestrncpy( item->name, entry.name, NAME_LENGTH );
  17813. safestrncpy( item->time, entry.time, NAME_LENGTH );
  17814. item->attribute = entry.item.attribute;
  17815. }
  17816. }
  17817. WFIFOSET( fd, p->PacketLength );
  17818. #endif
  17819. }
  17820. /// Activates the client camera info or updates the client camera with the given values.
  17821. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17822. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17823. #if PACKETVER >= 20160525
  17824. int fd = sd->fd;
  17825. WFIFOHEAD(fd, packet_len(0xa78));
  17826. WFIFOW(fd, 0) = 0xa78;
  17827. WFIFOB(fd, 2) = show;
  17828. WFIFOF(fd, 3) = range;
  17829. WFIFOF(fd, 7) = rotation;
  17830. WFIFOF(fd, 11) = latitude;
  17831. WFIFOSET(fd, packet_len(0xa78));
  17832. #endif
  17833. }
  17834. /// Activates or deactives the client camera info or updates the camera settings.
  17835. /// This packet is triggered by /viewpointvalue or /setcamera
  17836. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17837. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17838. char command[CHAT_SIZE_MAX];
  17839. // /viewpointvalue
  17840. if( RFIFOB( fd, 2 ) == 1 ){
  17841. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17842. // /setcamera
  17843. }else{
  17844. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17845. }
  17846. is_atcommand( fd, sd, command, 1 );
  17847. }
  17848. /// Send the full list of items in the equip switch window
  17849. /// 0a9b <length>.W { <index>.W <position>.L }*
  17850. void clif_equipswitch_list( struct map_session_data* sd ){
  17851. #if PACKETVER >= 20170208
  17852. int fd = sd->fd;
  17853. int offset, i, position;
  17854. WFIFOW(fd, 0) = 0xa9b;
  17855. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17856. short index = sd->equip_switch_index[i];
  17857. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17858. WFIFOW(fd, offset) = index + 2;
  17859. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17860. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17861. offset += 6;
  17862. }
  17863. }
  17864. WFIFOW(fd, 2) = offset;
  17865. WFIFOSET(fd, offset);
  17866. #endif
  17867. }
  17868. /// Acknowledgement for removing an equip to the equip switch window
  17869. /// 0a9a <index>.W <position.>.L <failure>.W
  17870. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17871. #if PACKETVER >= 20170208
  17872. int fd = sd->fd;
  17873. WFIFOHEAD(fd, packet_len(0xa9a));
  17874. WFIFOW(fd, 0) = 0xa9a;
  17875. WFIFOW(fd, 2) = index + 2;
  17876. WFIFOL(fd, 4) = pos;
  17877. WFIFOW(fd, 8) = failed;
  17878. WFIFOSET(fd, packet_len(0xa9a));
  17879. #endif
  17880. }
  17881. /// Request to remove an equip from the equip switch window
  17882. /// 0a99 <index>.W <position>.L <= 20170502
  17883. /// 0a99 <index>.W
  17884. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17885. #if PACKETVER >= 20170208
  17886. uint16 index = RFIFOW(fd, 2) - 2;
  17887. bool removed = false;
  17888. if( !battle_config.feature_equipswitch ){
  17889. return;
  17890. }
  17891. // Check if the index is valid
  17892. if( index >= MAX_INVENTORY ){
  17893. return;
  17894. }
  17895. pc_equipswitch_remove( sd, index );
  17896. #endif
  17897. }
  17898. /// Acknowledgement for adding an equip to the equip switch window
  17899. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  17900. /// 0a98 <index>.W <position.>.L <flag>.W
  17901. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  17902. #if PACKETVER >= 20170208
  17903. int fd = sd->fd;
  17904. WFIFOHEAD(fd, packet_len(0xa98));
  17905. WFIFOW(fd, 0) = 0xa98;
  17906. WFIFOW(fd, 2) = index + 2;
  17907. WFIFOL(fd, 4) = pos;
  17908. #if PACKETVER <= 20170502
  17909. WFIFOL(fd, 8) = flag;
  17910. #else
  17911. WFIFOW(fd, 8) = flag;
  17912. #endif
  17913. WFIFOSET(fd,packet_len(0xa98));
  17914. #endif
  17915. }
  17916. /// Request to add an equip to the equip switch window
  17917. /// 0a97 <index>.W <position>.L
  17918. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17919. #if PACKETVER >= 20170208
  17920. uint16 index = RFIFOW(fd, 2) - 2;
  17921. uint32 position = RFIFOL(fd, 4);
  17922. if( !battle_config.feature_equipswitch ){
  17923. return;
  17924. }
  17925. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17926. return;
  17927. }
  17928. if( sd->state.trading || sd->npc_shopid ){
  17929. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  17930. return;
  17931. }
  17932. if( sd->inventory_data[index]->type == IT_AMMO ){
  17933. position = EQP_AMMO;
  17934. }
  17935. pc_equipitem( sd, index, position, true );
  17936. #endif
  17937. }
  17938. /// Acknowledgement packet for the full equip switch
  17939. /// 0a9d <failed>.W
  17940. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17941. #if PACKETVER >= 20170208
  17942. int fd = sd->fd;
  17943. WFIFOHEAD(fd, packet_len(0xa9d));
  17944. WFIFOW(fd, 0) = 0xa9d;
  17945. WFIFOW(fd, 2) = failed;
  17946. WFIFOSET(fd, packet_len(0xa9d));
  17947. #endif
  17948. }
  17949. /// Request to do a full equip switch
  17950. /// 0a9c
  17951. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  17952. #if PACKETVER >= 20170208
  17953. int i;
  17954. t_tick tick = gettick();
  17955. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  17956. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  17957. // Client will not let you send a request
  17958. return;
  17959. }
  17960. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  17961. if( !battle_config.feature_equipswitch ){
  17962. return;
  17963. }
  17964. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  17965. if( i == EQI_MAX ){
  17966. // client will show: "There is no item to replace." and should not even come here
  17967. clif_equipswitch_reply( sd, false );
  17968. return;
  17969. }
  17970. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  17971. return;
  17972. }
  17973. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  17974. #endif
  17975. }
  17976. /// Request to do a single equip switch
  17977. /// 0ace <index>.W
  17978. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  17979. #if PACKETVER >= 20170502
  17980. uint16 index = RFIFOW(fd, 2) - 2;
  17981. if( !battle_config.feature_equipswitch ){
  17982. return;
  17983. }
  17984. // Check if the index is valid
  17985. if( index >= MAX_INVENTORY ){
  17986. return;
  17987. }
  17988. // Check if the item exists
  17989. if (sd->inventory_data[index] == nullptr)
  17990. return;
  17991. // Check if the item was already added to equip switch
  17992. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  17993. if( sd->npc_id ){
  17994. #ifdef RENEWAL
  17995. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  17996. clif_msg( sd, WORK_IN_PROGRESS );
  17997. return;
  17998. }
  17999. #endif
  18000. if( !sd->npc_item_flag ){
  18001. return;
  18002. }
  18003. }
  18004. pc_equipswitch( sd, index );
  18005. return;
  18006. }
  18007. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18008. #endif
  18009. }
  18010. void clif_parse_StartUseSkillToId(int fd, struct map_session_data *sd) {
  18011. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18012. const struct PACKET_CZ_START_USE_SKILL *p = (struct PACKET_CZ_START_USE_SKILL *)RFIFOP(fd, 0);
  18013. // Only rolling cutter is supported for now
  18014. if (p->skillId != GC_ROLLINGCUTTER) {
  18015. return;
  18016. }
  18017. // Already running - cant happen on officials, since only one skill is supported
  18018. if (sd->skill_keep_using.skill_id != 0) {
  18019. return;
  18020. }
  18021. sd->skill_keep_using.tid = INVALID_TIMER;
  18022. sd->skill_keep_using.skill_id = p->skillId;
  18023. sd->skill_keep_using.level = p->skillLv;
  18024. sd->skill_keep_using.target = p->targetId;
  18025. clif_parse_skill_toid(sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target);
  18026. #endif
  18027. }
  18028. void clif_parse_StopUseSkillToId(int fd, struct map_session_data *sd) {
  18029. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18030. const struct PACKET_CZ_STOP_USE_SKILL *p = (struct PACKET_CZ_STOP_USE_SKILL *)RFIFOP(fd, 0);
  18031. // Not running
  18032. if (sd->skill_keep_using.skill_id == 0) {
  18033. return;
  18034. }
  18035. #if 0
  18036. // Hack
  18037. if (p->skillId != sd->skill_keep_using.skill_id) {
  18038. return;
  18039. }
  18040. #endif
  18041. if (sd->skill_keep_using.tid != INVALID_TIMER) {
  18042. delete_timer(sd->skill_keep_using.tid, skill_keep_using);
  18043. sd->skill_keep_using.tid = INVALID_TIMER;
  18044. }
  18045. sd->skill_keep_using.skill_id = 0;
  18046. sd->skill_keep_using.level = 0;
  18047. sd->skill_keep_using.target = 0;
  18048. #endif
  18049. }
  18050. void clif_ping(struct map_session_data *sd) {
  18051. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18052. nullpo_retv(sd);
  18053. int fd = sd->fd;
  18054. if (!session_isActive(fd)) {
  18055. return;
  18056. }
  18057. struct PACKET_ZC_PING p;
  18058. p.packetType = HEADER_ZC_PING;
  18059. clif_send(&p, sizeof(p), &sd->bl, SELF);
  18060. #endif
  18061. }
  18062. int clif_ping_timer_sub(struct map_session_data *sd, va_list ap) {
  18063. nullpo_ret(sd);
  18064. int fd = sd->fd;
  18065. if (!session_isActive(fd)) {
  18066. return 0;
  18067. }
  18068. t_tick tick = va_arg(ap, t_tick);
  18069. if (session[fd]->wdata_tick + battle_config.ping_time < tick) {
  18070. clif_ping(sd);
  18071. }
  18072. return 0;
  18073. }
  18074. TIMER_FUNC(clif_ping_timer) {
  18075. map_foreachpc(clif_ping_timer_sub, gettick());
  18076. return 0;
  18077. }
  18078. /**
  18079. * Opens the refine UI on the designated client.
  18080. * 0aa0
  18081. */
  18082. void clif_refineui_open( struct map_session_data* sd ){
  18083. #if PACKETVER >= 20161012
  18084. nullpo_retv( sd );
  18085. struct PACKET_ZC_REFINE_OPEN_WINDOW p;
  18086. p.packetType = HEADER_ZC_REFINE_OPEN_WINDOW;
  18087. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18088. sd->state.refineui_open = true;
  18089. #endif
  18090. }
  18091. /**
  18092. * Parses cancel/close of the refine UI on client side.
  18093. * 0aa4
  18094. */
  18095. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18096. #if PACKETVER >= 20161012
  18097. sd->state.refineui_open = false;
  18098. #endif
  18099. }
  18100. /**
  18101. * Adds the selected item into the refine UI and sends the possible materials
  18102. * to the client.
  18103. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18104. */
  18105. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18106. #if PACKETVER >= 20161012
  18107. int fd = sd->fd;
  18108. // Get the item db reference
  18109. struct item_data* id = sd->inventory_data[index];
  18110. // No item data was found
  18111. if( id == NULL ){
  18112. return;
  18113. }
  18114. // Check the inventory
  18115. struct item* item = &sd->inventory.u.items_inventory[index];
  18116. // No item was found at the given index
  18117. if( item == NULL ){
  18118. return;
  18119. }
  18120. // Check if the item is identified
  18121. if( !item->identify ){
  18122. return;
  18123. }
  18124. // Check if the item is broken
  18125. if( item->attribute ){
  18126. return;
  18127. }
  18128. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18129. // No refine possible
  18130. if( info == nullptr ){
  18131. return;
  18132. }
  18133. // No possibilities were found
  18134. if( info->costs.empty() ){
  18135. return;
  18136. }
  18137. uint16 length = (uint16)( sizeof( struct PACKET_ZC_REFINE_ADD_ITEM ) + REFINE_COST_MAX * sizeof( struct PACKET_ZC_REFINE_ADD_ITEM_SUB ) );
  18138. // Preallocate the size
  18139. WFIFOHEAD( fd, length );
  18140. struct PACKET_ZC_REFINE_ADD_ITEM* p = (struct PACKET_ZC_REFINE_ADD_ITEM*)WFIFOP( fd, 0 );
  18141. p->packetType = HEADER_ZC_REFINE_ADD_ITEM;
  18142. p->itemIndex = client_index( index );
  18143. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18144. uint16 count = 0;
  18145. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18146. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18147. if( cost != nullptr ){
  18148. p->req[count].itemId = client_nameid( cost->nameid );
  18149. p->req[count].chance = (uint8)( cost->chance / 100 );
  18150. p->req[count].zeny = cost->zeny;
  18151. count++;
  18152. }
  18153. }
  18154. p->packtLength = (uint16)( sizeof( struct PACKET_ZC_REFINE_ADD_ITEM ) + count * sizeof( struct PACKET_ZC_REFINE_ADD_ITEM_SUB ) );
  18155. WFIFOSET( fd, p->packtLength );
  18156. #endif
  18157. }
  18158. /**
  18159. * Client request to add an item to the refine UI.
  18160. * 0aa1 <index>.W
  18161. */
  18162. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18163. #if PACKETVER >= 20161012
  18164. struct PACKET_CZ_REFINE_ADD_ITEM* p = (struct PACKET_CZ_REFINE_ADD_ITEM*)RFIFOP( fd, 0 );
  18165. uint16 index = server_index( p->index );
  18166. // Check if the refine UI is open
  18167. if( !sd->state.refineui_open ){
  18168. return;
  18169. }
  18170. // Check if the index is valid
  18171. if( index >= MAX_INVENTORY ){
  18172. return;
  18173. }
  18174. // Send out the requirements for the refine process
  18175. clif_refineui_info( sd, index );
  18176. #endif
  18177. }
  18178. /**
  18179. * Client requests to try to refine an item.
  18180. * 0aa3 <index>.W <material>.W <catalyst>.B
  18181. */
  18182. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18183. #if PACKETVER >= 20161012
  18184. struct PACKET_CZ_REFINE_ITEM_REQUEST* p = (struct PACKET_CZ_REFINE_ITEM_REQUEST*)RFIFOP( fd, 0 );
  18185. uint16 index = server_index( p->index );
  18186. t_itemid material = p->itemId;
  18187. int16 j;
  18188. // Check if the refine UI is open
  18189. if( !sd->state.refineui_open ){
  18190. return;
  18191. }
  18192. // Check if the index is valid
  18193. if( index >= MAX_INVENTORY ){
  18194. return;
  18195. }
  18196. // Get the item db reference
  18197. struct item_data* id = sd->inventory_data[index];
  18198. // No item data was found
  18199. if( id == NULL ){
  18200. return;
  18201. }
  18202. // Check the inventory
  18203. struct item* item = &sd->inventory.u.items_inventory[index];
  18204. // No item was found at the given index
  18205. if( item == NULL ){
  18206. return;
  18207. }
  18208. // Check if the item is identified
  18209. if( !item->identify ){
  18210. return;
  18211. }
  18212. // Check if the item is broken
  18213. if( item->attribute ){
  18214. return;
  18215. }
  18216. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18217. // No refine possible
  18218. if( info == nullptr ){
  18219. return;
  18220. }
  18221. // No possibilities were found
  18222. if( info->costs.empty() ){
  18223. return;
  18224. }
  18225. // Check if the player has the selected material
  18226. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18227. return;
  18228. }
  18229. int16 blacksmith_index = -1;
  18230. uint16 blacksmith_amount = 0;
  18231. // Check if the player has enough blacksmith blessings
  18232. if( p->blacksmithBlessing != 0 ){
  18233. blacksmith_amount = info->blessing_amount;
  18234. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18235. if( blacksmith_amount == 0 ){
  18236. return;
  18237. }
  18238. // Check if the player has blacksmith blessings
  18239. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18240. return;
  18241. }
  18242. // Check if the player has enough blacksmith blessings
  18243. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18244. return;
  18245. }
  18246. }
  18247. std::shared_ptr<s_refine_cost> cost = nullptr;
  18248. for( const auto& pair : info->costs ){
  18249. if( pair.second->nameid == material ){
  18250. cost = pair.second;
  18251. break;
  18252. }
  18253. }
  18254. // The material was not in the list of possible materials
  18255. if( cost == nullptr ){
  18256. return;
  18257. }
  18258. // Try to pay for the refine
  18259. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18260. clif_npc_buy_result( sd, 1 ); // "You do not have enough zeny."
  18261. return;
  18262. }
  18263. // Delete the required material
  18264. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18265. return;
  18266. }
  18267. // Delete the required blacksmith blessings
  18268. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18269. return;
  18270. }
  18271. // Try to refine the item
  18272. if( cost->chance >= ( rnd() % 10000 ) ){
  18273. // Success
  18274. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18275. clif_misceffect( &sd->bl, 3 );
  18276. clif_refine( fd, 0, index, item->refine );
  18277. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->wlv, item->refine );
  18278. clif_refineui_info( sd, index );
  18279. }else{
  18280. // Failure
  18281. // Blacksmith blessings were used to prevent breaking and downgrading
  18282. if( blacksmith_amount > 0 ){
  18283. clif_refine( fd, 3, index, item->refine );
  18284. // Delete the item if it is breakable
  18285. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18286. clif_refine( fd, 1, index, item->refine );
  18287. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_CONSUME );
  18288. // Downgrade the item if necessary
  18289. }else if( cost->downgrade_amount > 0 ){
  18290. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18291. clif_refine( fd, 2, index, item->refine );
  18292. clif_refineui_info(sd, index);
  18293. // Only show failure, but dont do anything
  18294. }else{
  18295. clif_refine( fd, 3, index, item->refine );
  18296. }
  18297. clif_misceffect( &sd->bl, 2 );
  18298. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18299. }
  18300. #endif
  18301. }
  18302. /**
  18303. * Reset Lapine UI variables
  18304. * @param sd: Player
  18305. */
  18306. static void clif_lapine_ui_reset(map_session_data *sd) {
  18307. sd->state.lapine_ui = 0;
  18308. sd->last_lapine_box = 0;
  18309. sd->itemid = sd->itemindex = -1;
  18310. }
  18311. /**
  18312. * Open Lapine Synthesis UI
  18313. * @param sd: Player
  18314. * @param itemid: ID for synthesis item
  18315. * 0A4E <itemid>.W (ZC_LAPINE_SYNTHESIS_OPEN)
  18316. * 0A4E <itemid>.L (ZC_LAPINE_SYNTHESIS_OPEN PACKETVER >= 20181121)
  18317. */
  18318. bool clif_synthesisui_open(struct map_session_data *sd, t_itemid itemid) {
  18319. #ifdef FEATURE_LAPINE_UI
  18320. nullpo_retr(false, sd);
  18321. PACKET_ZC_LAPINEDDUKDDAK_OPEN p;
  18322. p.packetType = HEADER_ZC_LAPINEDDUKDDAK_OPEN;
  18323. p.itemId = client_nameid(itemid);
  18324. clif_send(&p, sizeof(p), &sd->bl, SELF);
  18325. return true;
  18326. #else
  18327. return false;
  18328. #endif
  18329. }
  18330. /**
  18331. * Send Lapine Synthesis result to player
  18332. * @param sd: Player
  18333. * @param result: @see e_item_synthesis_result
  18334. * 0A50 <result>.W (ZC_LAPINE_SYNTHESIS_RESULT)
  18335. */
  18336. void clif_synthesisui_result(struct map_session_data *sd, e_item_synthesis_result result) {
  18337. #ifdef FEATURE_LAPINE_UI
  18338. nullpo_retv(sd);
  18339. clif_lapine_ui_reset(sd);
  18340. PACKET_ZC_LAPINEDDUKDDAK_RESULT p;
  18341. p.packetType = HEADER_ZC_LAPINEDDUKDDAK_RESULT;
  18342. p.result = result;
  18343. clif_send(&p, sizeof(p), &sd->bl, SELF);
  18344. #endif
  18345. }
  18346. /**
  18347. * Received selected items from Lapine Synthesis UI
  18348. * @param fd
  18349. * @param sd
  18350. * 0A4F <length>.W <itemid>.W { <index>.W <count>.W }.*4B (CZ_LAPINE_SYNTHESIS_ACK)
  18351. * 0A4F <length>.W <itemid>.L { <index>.W <count>.W }.*4B (CZ_LAPINE_SYNTHESIS_ACK PACKETVER >= 20181121)
  18352. */
  18353. void clif_parse_lapineSynthesis_submit(int fd, struct map_session_data* sd) {
  18354. #ifdef FEATURE_LAPINE_UI
  18355. nullpo_retv(sd);
  18356. if (pc_istrading(sd)) {
  18357. clif_synthesisui_result(sd, SYNTHESIS_INVALID_ITEM);
  18358. return;
  18359. }
  18360. if (!(sd->state.lapine_ui&1)) {
  18361. set_eof(sd->fd);
  18362. return;
  18363. }
  18364. s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  18365. if (!info) {
  18366. set_eof(sd->fd);
  18367. return;
  18368. }
  18369. int len = RFIFOW(fd, info->pos[0]), i = 0, n = (len - info->pos[2]) / info->pos[3];
  18370. #if PACKETVER >= 20181121
  18371. t_itemid itemid = RFIFOL(fd, info->pos[1]);
  18372. #else
  18373. t_itemid itemid = RFIFOW(fd, info->pos[1]);
  18374. #endif
  18375. item_data *id;
  18376. if (n < 1 || n > MAX_SYNTHESIS_SOURCES || sd->last_lapine_box != itemid || sd->last_lapine_box != sd->itemid || !(id = itemdb_exists(itemid))) {
  18377. //clif_synthesisui_result(sd, SYNTHESIS_INVALID_ITEM);
  18378. set_eof(sd->fd);
  18379. return;
  18380. }
  18381. if (!(sd->state.lapine_ui&4) && id->flag.delay_consume) {
  18382. item *it;
  18383. if (sd->itemindex == -1 || sd->itemid == -1 || !(it = &sd->inventory.u.items_inventory[sd->itemindex]) || it->nameid != itemid) {
  18384. //clif_synthesisui_result(sd, SYNTHESIS_INVALID_ITEM);
  18385. set_eof(sd->fd);
  18386. return;
  18387. }
  18388. if (id->flag.delay_consume != 2)
  18389. pc_delitem(sd, sd->itemindex, 1, 0, 0, LOG_TYPE_CONSUME);
  18390. }
  18391. std::vector<s_item_synthesis_list> items;
  18392. for (; i < n; i++) {
  18393. int index = RFIFOW(fd, info->pos[2] + i * info->pos[3]) - 2;
  18394. int amount = RFIFOW(fd, info->pos[2] + i * info->pos[3] + 2);
  18395. if (amount < 1 || index < 0 || index >= MAX_INVENTORY) {
  18396. //clif_synthesisui_result(sd, SYNTHESIS_INVALID_ITEM);
  18397. set_eof(sd->fd);
  18398. return;
  18399. }
  18400. s_item_synthesis_list item;
  18401. item.index = (uint16)index;
  18402. item.amount = (uint16)amount;
  18403. items.push_back(item);
  18404. }
  18405. clif_synthesisui_result(sd, item_synthesis_submit(sd, itemid, items));
  18406. clif_lapine_ui_reset(sd);
  18407. #endif
  18408. }
  18409. /**
  18410. * Close Lapine Synthesis UI
  18411. * @param fd
  18412. * @param sd
  18413. * 0A70 CZ_LAPINE_SYNTHESIS_CLOSE
  18414. */
  18415. void clif_parse_lapineSynthesis_close(int fd, struct map_session_data* sd) {
  18416. #ifdef FEATURE_LAPINE_UI
  18417. nullpo_retv(sd);
  18418. clif_lapine_ui_reset(sd);
  18419. #endif
  18420. }
  18421. /**
  18422. * Open Lapine Upgrade UI
  18423. * @param sd: Player
  18424. * @param itemid: ID for upgrade item
  18425. * 0AB4 <itemid>.W (ZC_LAPINE_UPGRADE_OPEN)
  18426. * 0AB4 <itemid>.L (ZC_LAPINE_UPGRADE_OPEN PACKETVER >= 20181121)
  18427. */
  18428. bool clif_lapine_upgrade_open(struct map_session_data *sd, t_itemid itemid) {
  18429. #ifdef FEATURE_LAPINE_UI
  18430. nullpo_retr(false, sd);
  18431. PACKET_ZC_LAPINEUPGRADE_OPEN p;
  18432. p.packetType = HEADER_ZC_LAPINEUPGRADE_OPEN;
  18433. p.itemId = client_nameid(itemid);
  18434. clif_send(&p, sizeof(p), &sd->bl, SELF);
  18435. return true;
  18436. #else
  18437. return false;
  18438. #endif
  18439. }
  18440. /**
  18441. * Send Lapine Upgrade result to player
  18442. * @param sd: Player
  18443. * @param result: @see e_item_upgrade_result
  18444. * 0AB7 <result>.W (ZC_LAPINE_UPGRADE_RESULT)
  18445. */
  18446. void clif_lapine_upgrade_result(struct map_session_data *sd, e_item_upgrade_result result) {
  18447. #ifdef FEATURE_LAPINE_UI
  18448. nullpo_retv(sd);
  18449. clif_lapine_ui_reset(sd);
  18450. PACKET_ZC_LAPINEUPGRADE_RESULT p;
  18451. p.packetType = HEADER_ZC_LAPINEUPGRADE_RESULT;
  18452. p.result = result;
  18453. clif_send(&p, sizeof(p), &sd->bl, SELF);
  18454. #endif
  18455. }
  18456. /**
  18457. * Received selected item from Lapine Upgrade UI
  18458. * @param fd
  18459. * @param sd
  18460. * 0AB6 <itemid>.W <index>.W (CZ_LAPINE_UPGRADE_ACK)
  18461. * 0AB6 <itemid>.L <index>.W (CZ_LAPINE_UPGRADE_ACK PACKETVER >= 20181121)
  18462. */
  18463. void clif_parse_lapineUpgrade_submit(int fd, struct map_session_data* sd) {
  18464. #ifdef FEATURE_LAPINE_UI
  18465. nullpo_retv(sd);
  18466. if (pc_istrading(sd)) {
  18467. clif_lapine_upgrade_result(sd, LAPINE_UPRAGDE_FAILURE);
  18468. return;
  18469. }
  18470. if (!(sd->state.lapine_ui&2)) {
  18471. set_eof(sd->fd);
  18472. return;
  18473. }
  18474. s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  18475. if (!info) {
  18476. set_eof(sd->fd);
  18477. return;
  18478. }
  18479. short index = RFIFOW(fd, info->pos[1]) - 2;
  18480. t_itemid itemid;
  18481. #if PACKETVER >= 20181121
  18482. itemid = RFIFOL(fd, info->pos[0]);
  18483. #else
  18484. itemid = RFIFOW(fd, info->pos[0]);
  18485. #endif
  18486. item_data *id;
  18487. if (sd->last_lapine_box != itemid || sd->last_lapine_box != sd->itemid || index < 0 || index >= MAX_INVENTORY || !(id = itemdb_search(sd->last_lapine_box))) {
  18488. //clif_lapine_upgrade_result(sd, LAPINE_UPRAGDE_FAILURE);
  18489. set_eof(sd->fd);
  18490. return;
  18491. }
  18492. if (!(sd->state.lapine_ui&4) && id->flag.delay_consume) {
  18493. if (sd->itemindex == -1 || sd->itemid == -1) {
  18494. //clif_lapine_upgrade_result(sd, LAPINE_UPRAGDE_FAILURE);
  18495. set_eof(sd->fd);
  18496. return;
  18497. }
  18498. if (id->flag.delay_consume != 2)
  18499. pc_delitem(sd, sd->itemindex, 1, 0, 0, LOG_TYPE_CONSUME);
  18500. }
  18501. clif_lapine_upgrade_result(sd, item_upgrade_submit(sd, itemid, index));
  18502. clif_lapine_ui_reset(sd);
  18503. #endif
  18504. }
  18505. /**
  18506. * Close Lapine Upgrade UI
  18507. * @param fd
  18508. * @param sd
  18509. * 0AB5 CZ_LAPINE_UPGRADE_CLOSE
  18510. */
  18511. void clif_parse_lapineUpgrade_close(int fd, struct map_session_data* sd) {
  18512. #ifdef FEATURE_LAPINE_UI
  18513. nullpo_retv(sd);
  18514. clif_lapine_ui_reset(sd);
  18515. #endif
  18516. }
  18517. /*==========================================
  18518. * Main client packet processing function
  18519. *------------------------------------------*/
  18520. static int clif_parse(int fd)
  18521. {
  18522. int cmd, packet_len;
  18523. TBL_PC* sd;
  18524. int pnum;
  18525. #ifdef PACKET_OBFUSCATION
  18526. int cmd2;
  18527. #endif
  18528. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  18529. // Note: "click masters" can do 80+ clicks in 10 seconds
  18530. 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]
  18531. { // begin main client packet processing loop
  18532. sd = (TBL_PC *)session[fd]->session_data;
  18533. if (session[fd]->flag.eof) {
  18534. if (sd) {
  18535. if (sd->state.autotrade) {
  18536. //Disassociate character from the socket connection.
  18537. session[fd]->session_data = NULL;
  18538. sd->fd = 0;
  18539. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  18540. } else
  18541. if (sd->state.active) {
  18542. // Player logout display [Valaris]
  18543. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  18544. clif_quitsave(fd, sd);
  18545. } else {
  18546. //Unusual logout (during log on/off/map-changer procedure)
  18547. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  18548. map_quit(sd);
  18549. }
  18550. } else {
  18551. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  18552. }
  18553. do_close(fd);
  18554. return 0;
  18555. }
  18556. if (RFIFOREST(fd) < 2)
  18557. return 0;
  18558. cmd = RFIFOW(fd, 0);
  18559. #ifdef PACKET_OBFUSCATION
  18560. // Check if it is a player that tries to connect to the map server.
  18561. if( sd ){
  18562. // Decrypt the current packet ID with the last key stored in the session.
  18563. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  18564. }else{
  18565. // Store the original value for checking
  18566. cmd2 = cmd;
  18567. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  18568. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  18569. }
  18570. #endif
  18571. // filter out invalid / unsupported packets
  18572. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  18573. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  18574. #ifdef DUMP_INVALID_PACKET
  18575. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  18576. #endif
  18577. #ifdef PACKET_OBFUSCATION_WARN
  18578. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  18579. if( !sd ){
  18580. #ifdef PACKET_OBFUSCATION
  18581. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  18582. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  18583. }
  18584. #else
  18585. // Try to use the initial keys for the decryption of the packet ID.
  18586. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  18587. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  18588. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  18589. }
  18590. #endif
  18591. }
  18592. #endif
  18593. set_eof(fd);
  18594. return 0;
  18595. }
  18596. // determine real packet length
  18597. packet_len = packet_db[cmd].len;
  18598. if (packet_len == -1) { // variable-length packet
  18599. if (RFIFOREST(fd) < 4)
  18600. return 0;
  18601. packet_len = RFIFOW(fd,2);
  18602. if (packet_len < 4 || packet_len > 32768) {
  18603. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  18604. #ifdef DUMP_INVALID_PACKET
  18605. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  18606. #endif
  18607. set_eof(fd);
  18608. return 0;
  18609. }
  18610. }
  18611. if ((int)RFIFOREST(fd) < packet_len){
  18612. 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 );
  18613. #ifdef DUMP_INVALID_PACKET
  18614. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  18615. #endif
  18616. set_eof( fd );
  18617. return 0; // not enough data received to form the packet
  18618. }
  18619. #ifdef PACKET_OBFUSCATION
  18620. RFIFOW(fd, 0) = cmd;
  18621. if (sd)
  18622. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  18623. #endif
  18624. if( packet_db[cmd].func == clif_parse_debug )
  18625. packet_db[cmd].func(fd, sd);
  18626. else if( packet_db[cmd].func != NULL ) {
  18627. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  18628. ; //Only valid packet when there is no session
  18629. else
  18630. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  18631. ; //Only valid packet when player is not on a map
  18632. else
  18633. packet_db[cmd].func(fd, sd);
  18634. }
  18635. #ifdef DUMP_UNKNOWN_PACKET
  18636. else DumpUnknown(fd,sd,cmd,packet_len);
  18637. #endif
  18638. RFIFOSKIP(fd, packet_len);
  18639. }; // main loop end
  18640. return 0;
  18641. }
  18642. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  18643. va_list argp;
  18644. int i;
  18645. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  18646. return;
  18647. packet_db[cmd].len = length;
  18648. packet_db[cmd].func = func;
  18649. va_start(argp, func);
  18650. for( i = 0; i < MAX_PACKET_POS; i++ ){
  18651. int offset = va_arg(argp, int);
  18652. if( offset == 0 ){
  18653. break;
  18654. }
  18655. packet_db[cmd].pos[i] = offset;
  18656. }
  18657. if( i == MAX_PACKET_POS ){
  18658. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  18659. }
  18660. va_end(argp);
  18661. }
  18662. /*==========================================
  18663. * Reads packets and setups its array reference
  18664. *------------------------------------------*/
  18665. void packetdb_readdb(){
  18666. memset(packet_db,0,sizeof(packet_db));
  18667. memset(packet_db_ack,0,sizeof(packet_db_ack));
  18668. #include "clif_packetdb.hpp"
  18669. #include "clif_shuffle.hpp"
  18670. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  18671. #ifdef PACKET_OBFUSCATION
  18672. 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]);
  18673. #else
  18674. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  18675. #endif
  18676. }
  18677. /*==========================================
  18678. *
  18679. *------------------------------------------*/
  18680. void do_init_clif(void) {
  18681. const char* colors[COLOR_MAX] = {
  18682. "0x00FF00",
  18683. "0xFF0000",
  18684. "0xFFFFFF",
  18685. "0xFFFF00",
  18686. "0x00FFFF",
  18687. "0xB5FFB5",
  18688. };
  18689. int i;
  18690. /**
  18691. * Setup Color Table (saves unnecessary load of strtoul on every call)
  18692. **/
  18693. for(i = 0; i < COLOR_MAX; i++) {
  18694. color_table[i] = strtoul(colors[i],NULL,0);
  18695. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  18696. }
  18697. packetdb_readdb();
  18698. set_defaultparse(clif_parse);
  18699. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  18700. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  18701. exit(EXIT_FAILURE);
  18702. }
  18703. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  18704. add_timer_func_list(clif_delayquit, "clif_delayquit");
  18705. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  18706. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  18707. if( battle_config.ping_timer_interval > 0 ){
  18708. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  18709. }
  18710. #endif
  18711. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  18712. }
  18713. void do_final_clif(void) {
  18714. ers_destroy(delay_clearunit_ers);
  18715. }