clif.cpp 681 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // Copyright (c) Hercules Dev Team - Licensed under GNU GPL
  3. // For more information, see LICENCE in the main folder
  4. #include "clif.hpp"
  5. #include <cstdarg>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <ctime>
  10. #include "../common/cbasetypes.hpp"
  11. #include "../common/conf.hpp"
  12. #include "../common/ers.hpp"
  13. #include "../common/grfio.hpp"
  14. #include "../common/malloc.hpp"
  15. #include "../common/nullpo.hpp"
  16. #include "../common/random.hpp"
  17. #include "../common/showmsg.hpp"
  18. #include "../common/socket.hpp"
  19. #include "../common/strlib.hpp"
  20. #include "../common/timer.hpp"
  21. #include "../common/utilities.hpp"
  22. #include "../common/utils.hpp"
  23. #include "achievement.hpp"
  24. #include "atcommand.hpp"
  25. #include "battle.hpp"
  26. #include "battleground.hpp"
  27. #include "cashshop.hpp"
  28. #include "channel.hpp"
  29. #include "chat.hpp"
  30. #include "chrif.hpp"
  31. #include "clan.hpp"
  32. #include "clif.hpp"
  33. #include "elemental.hpp"
  34. #include "guild.hpp"
  35. #include "homunculus.hpp"
  36. #include "instance.hpp"
  37. #include "intif.hpp"
  38. #include "itemdb.hpp"
  39. #include "log.hpp"
  40. #include "mail.hpp"
  41. #include "map.hpp"
  42. #include "mercenary.hpp"
  43. #include "mob.hpp"
  44. #include "npc.hpp"
  45. #include "party.hpp"
  46. #include "pc.hpp"
  47. #include "pc_groups.hpp"
  48. #include "pet.hpp"
  49. #include "quest.hpp"
  50. #include "script.hpp"
  51. #include "skill.hpp"
  52. #include "status.hpp"
  53. #include "storage.hpp"
  54. #include "trade.hpp"
  55. #include "unit.hpp"
  56. #include "vending.hpp"
  57. using namespace rathena;
  58. static inline uint32 client_tick( t_tick tick ){
  59. return (uint32)tick;
  60. }
  61. #if PACKETVER >= 20170830
  62. static inline int64 client_exp(t_exp exp) {
  63. return (int64)u64min(exp, MAX_EXP);
  64. }
  65. #else
  66. static inline int32 client_exp(t_exp exp) {
  67. return (int32)u64min(exp, MAX_EXP);
  68. }
  69. #endif
  70. /* for clif_clearunit_delayed */
  71. static struct eri *delay_clearunit_ers;
  72. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  73. int packet_db_ack[MAX_ACK_FUNC + 1];
  74. // Reuseable global packet buffer to prevent too many allocations
  75. // Take socket.cpp::socket_max_client_packet into consideration
  76. static int8 packet_buffer[UINT16_MAX];
  77. unsigned long color_table[COLOR_MAX];
  78. #include "clif_obfuscation.hpp"
  79. static bool clif_session_isValid(struct map_session_data *sd);
  80. static void clif_loadConfirm( struct map_session_data *sd );
  81. #if PACKETVER >= 20150513
  82. enum mail_type {
  83. MAIL_TYPE_TEXT = 0x0,
  84. MAIL_TYPE_ZENY = 0x2,
  85. MAIL_TYPE_ITEM = 0x4,
  86. MAIL_TYPE_NPC = 0x8
  87. };
  88. #endif
  89. enum e_inventory_type{
  90. INVTYPE_INVENTORY = 0,
  91. INVTYPE_CART = 1,
  92. INVTYPE_STORAGE = 2,
  93. INVTYPE_GUILD_STORAGE = 3,
  94. };
  95. /** Converts item type to display it on client if necessary.
  96. * @param nameid: Item ID
  97. * @return item type. For IT_PETEGG will be displayed as IT_ARMOR. If Shadow Weapon of IT_SHADOWGEAR as IT_WEAPON and else as IT_ARMOR
  98. */
  99. static inline int itemtype(t_itemid nameid) {
  100. struct item_data* id = itemdb_search(nameid); //Use itemdb_search, so non-existance item will use dummy data and won't crash the server. bugreport:8468
  101. int type = id->type;
  102. if( type == IT_SHADOWGEAR ) {
  103. if( id->equip&EQP_SHADOW_WEAPON )
  104. return IT_WEAPON;
  105. else
  106. return IT_ARMOR;
  107. }
  108. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  109. }
  110. // TODO: doc
  111. static inline uint16 client_index( uint16 server_index ){
  112. return server_index + 2;
  113. }
  114. static inline uint16 server_index( uint16 client_index ){
  115. return client_index - 2;
  116. }
  117. static inline uint16 client_storage_index( uint16 server_index ){
  118. return server_index + 1;
  119. }
  120. static inline uint16 server_storage_index( uint16 client_index ){
  121. return client_index - 1;
  122. }
  123. static inline uint32 disguised_bl_id( uint32 bl_id ){
  124. // Casting to prevent a compiler warning
  125. return -((int32)bl_id);
  126. }
  127. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  128. static inline uint32 client_nameid( t_itemid server_nameid ){
  129. t_itemid view = itemdb_viewid( server_nameid );
  130. if( view > 0 ){
  131. return view;
  132. }else{
  133. return server_nameid;
  134. }
  135. }
  136. #else
  137. static inline uint16 client_nameid( t_itemid server_nameid ){
  138. t_itemid view = itemdb_viewid( server_nameid );
  139. if( view > 0 ){
  140. if( view > UINT16_MAX ){
  141. return (uint16)UNKNOWN_ITEM_ID;
  142. }
  143. return (uint16)view;
  144. }else{
  145. if( server_nameid > UINT16_MAX ){
  146. return (uint16)UNKNOWN_ITEM_ID;
  147. }
  148. return (uint16)server_nameid;
  149. }
  150. }
  151. #endif
  152. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  153. p += pos;
  154. p[0] = (uint8)(x>>2);
  155. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  156. p[2] = (uint8)((y<<4) | (dir&0xf));
  157. }
  158. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  159. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  160. p += pos;
  161. p[0] = (uint8)(x0>>2);
  162. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  163. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  164. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  165. p[4] = (uint8)y1;
  166. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  167. }
  168. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  169. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  170. }
  171. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  172. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  173. }
  174. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  175. p += pos;
  176. if( x ) {
  177. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  178. }
  179. if( y ) {
  180. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  181. }
  182. if( dir ) {
  183. dir[0] = ( p[2] & 0x0f );
  184. }
  185. }
  186. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  187. p += pos;
  188. if( x0 ) {
  189. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  190. }
  191. if( y0 ) {
  192. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  193. }
  194. if( x1 ) {
  195. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  196. }
  197. if( y1 ) {
  198. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  199. }
  200. if( sx0 ) {
  201. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  202. }
  203. if( sy0 ) {
  204. sy0[0] = ( p[5] & 0x0f ) >> 0;
  205. }
  206. }
  207. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  208. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  209. }
  210. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  211. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  212. }
  213. //To idenfity disguised characters.
  214. static inline bool disguised(struct block_list* bl) {
  215. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  216. }
  217. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  218. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  219. if( len > max )
  220. len = max;
  221. mes[len-1] = '\0';
  222. return len;
  223. }
  224. static char map_ip_str[128];
  225. static uint32 map_ip;
  226. static uint32 bind_ip = INADDR_ANY;
  227. static uint16 map_port = 5121;
  228. static bool clif_ally_only = false;
  229. int map_fd;
  230. static int clif_parse (int fd);
  231. /*==========================================
  232. * Ip setting of map-server
  233. *------------------------------------------*/
  234. int clif_setip(const char* ip) {
  235. char ip_str[16];
  236. map_ip = host2ip(ip);
  237. if (!map_ip) {
  238. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  239. return 0;
  240. }
  241. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  242. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  243. return 1;
  244. }
  245. void clif_setbindip(const char* ip)
  246. {
  247. bind_ip = host2ip(ip);
  248. if (bind_ip) {
  249. char ip_str[16];
  250. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  251. } else {
  252. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  253. }
  254. }
  255. /*==========================================
  256. * Sets map port to 'port'
  257. * is run from map.cpp upon loading map server configuration
  258. *------------------------------------------*/
  259. void clif_setport(uint16 port)
  260. {
  261. map_port = port;
  262. }
  263. /*==========================================
  264. * Returns map server IP
  265. *------------------------------------------*/
  266. uint32 clif_getip(void)
  267. {
  268. return map_ip;
  269. }
  270. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  271. uint32 clif_refresh_ip(void)
  272. {
  273. uint32 new_ip;
  274. new_ip = host2ip(map_ip_str);
  275. if (new_ip && new_ip != map_ip) {
  276. map_ip = new_ip;
  277. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  278. return map_ip;
  279. }
  280. return 0;
  281. }
  282. /*==========================================
  283. * Returns map port which is set by clif_setport()
  284. *------------------------------------------*/
  285. uint16 clif_getport(void)
  286. {
  287. return map_port;
  288. }
  289. #if PACKETVER >= 20071106
  290. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  291. switch (bl->type) {
  292. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  293. case BL_ITEM: return 0x2; //ITEM_TYPE
  294. case BL_SKILL: return 0x3; //SKILL_TYPE
  295. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  296. case BL_MOB:
  297. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  298. return 0x0; //PC_TYPE
  299. }else{
  300. switch( ( (mob_data*)bl )->special_state.ai ){
  301. case AI_ABR:
  302. return 0xd; //NPC_ABR_TYPE
  303. case AI_BIONIC:
  304. return 0xe; //NPC_BIONIC_TYPE
  305. default:
  306. return 0x5; //NPC_MOB_TYPE
  307. }
  308. }
  309. case BL_NPC:
  310. // From 2017-07-26 on NPC type units can also use player sprites.
  311. // There is one exception and this is if they are walking.
  312. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  313. #if PACKETVER >= 20170726
  314. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0xC; // New walking NPC type
  315. #else
  316. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  317. #endif
  318. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  319. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  320. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  321. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  322. default: return 0x1; //NPC_TYPE
  323. }
  324. }
  325. #endif
  326. static bool clif_session_isValid(struct map_session_data *sd) {
  327. return ( sd != nullptr && session_isActive(sd->fd) );
  328. }
  329. /*==========================================
  330. * sub process of clif_send
  331. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  332. * In order to send area-wise packets, such as:
  333. * - AREA : everyone nearby your area
  334. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  335. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  336. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  337. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  338. *------------------------------------------*/
  339. static int clif_send_sub(struct block_list *bl, va_list ap)
  340. {
  341. struct block_list *src_bl;
  342. struct map_session_data *sd;
  343. unsigned char *buf;
  344. int len, type, fd;
  345. nullpo_ret(bl);
  346. nullpo_ret(sd = (struct map_session_data *)bl);
  347. // Don't send to disconnected clients.
  348. if( !session_isActive( fd = sd->fd ) ){
  349. return 0;
  350. }
  351. buf = va_arg(ap,unsigned char*);
  352. len = va_arg(ap,int);
  353. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  354. type = va_arg(ap,int);
  355. switch(type) {
  356. case AREA_WOS:
  357. if (bl == src_bl)
  358. return 0;
  359. break;
  360. case AREA_WOC:
  361. if (sd->chatID || bl == src_bl)
  362. return 0;
  363. break;
  364. case AREA_WOSC:
  365. {
  366. if(src_bl->type == BL_PC) {
  367. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  368. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  369. return 0;
  370. }
  371. else if(src_bl->type == BL_NPC) {
  372. struct npc_data *nd = (struct npc_data *)src_bl;
  373. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  374. return 0;
  375. }
  376. }
  377. break;
  378. }
  379. /* unless visible, hold it here */
  380. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  381. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  382. return 0;
  383. WFIFOHEAD(fd, len);
  384. if (WFIFOP(fd,0) == buf) {
  385. ShowError("WARNING: Invalid use of clif_send function\n");
  386. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  387. ShowError(" Please correct your code.\n");
  388. // don't send to not move the pointer of the packet for next sessions in the loop
  389. //WFIFOSET(fd,0);//## TODO is this ok?
  390. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  391. return 0;
  392. }
  393. memcpy(WFIFOP(fd,0), buf, len);
  394. WFIFOSET(fd,len);
  395. return 0;
  396. }
  397. /*==========================================
  398. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  399. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  400. *------------------------------------------*/
  401. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  402. {
  403. int i;
  404. struct map_session_data *sd, *tsd;
  405. struct party_data *p = NULL;
  406. struct guild *g = NULL;
  407. std::shared_ptr<s_battleground_data> bg;
  408. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  409. struct s_mapiterator* iter;
  410. if( type != ALL_CLIENT )
  411. nullpo_ret(bl);
  412. sd = BL_CAST(BL_PC, bl);
  413. switch(type) {
  414. case ALL_CLIENT: //All player clients.
  415. iter = mapit_getallusers();
  416. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  417. if( session_isActive( fd = tsd->fd ) ){
  418. WFIFOHEAD( fd, len );
  419. memcpy( WFIFOP( fd, 0 ), buf, len );
  420. WFIFOSET( fd, len );
  421. }
  422. }
  423. mapit_free(iter);
  424. break;
  425. case ALL_SAMEMAP: //All players on the same map
  426. iter = mapit_getallusers();
  427. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  428. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  429. WFIFOHEAD( fd, len );
  430. memcpy( WFIFOP( fd, 0 ), buf, len );
  431. WFIFOSET( fd, len );
  432. }
  433. }
  434. mapit_free(iter);
  435. break;
  436. case AREA:
  437. case AREA_WOSC:
  438. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  439. clif_send (buf, len, bl, SELF);
  440. case AREA_WOC:
  441. case AREA_WOS:
  442. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  443. BL_PC, buf, len, bl, type);
  444. break;
  445. case AREA_CHAT_WOC:
  446. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  447. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  448. break;
  449. case CHAT:
  450. case CHAT_WOS:
  451. {
  452. struct chat_data *cd;
  453. if (sd) {
  454. cd = (struct chat_data*)map_id2bl(sd->chatID);
  455. } else if (bl->type == BL_CHAT) {
  456. cd = (struct chat_data*)bl;
  457. } else break;
  458. if (cd == NULL)
  459. break;
  460. for(i = 0; i < cd->users; i++) {
  461. if (type == CHAT_WOS && cd->usersd[i] == sd)
  462. continue;
  463. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  464. WFIFOHEAD(fd,len);
  465. memcpy(WFIFOP(fd,0), buf, len);
  466. WFIFOSET(fd,len);
  467. }
  468. }
  469. }
  470. break;
  471. case PARTY_AREA:
  472. case PARTY_AREA_WOS:
  473. x0 = bl->x - AREA_SIZE;
  474. y0 = bl->y - AREA_SIZE;
  475. x1 = bl->x + AREA_SIZE;
  476. y1 = bl->y + AREA_SIZE;
  477. case PARTY:
  478. case PARTY_WOS:
  479. case PARTY_SAMEMAP:
  480. case PARTY_SAMEMAP_WOS:
  481. if (sd && sd->status.party_id)
  482. p = party_search(sd->status.party_id);
  483. if (p) {
  484. for(i=0;i<MAX_PARTY;i++){
  485. if( (sd = p->data[i].sd) == NULL )
  486. continue;
  487. if( !session_isActive( fd = sd->fd ) )
  488. continue;
  489. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  490. continue;
  491. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  492. continue;
  493. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  494. continue;
  495. WFIFOHEAD(fd, len);
  496. memcpy(WFIFOP(fd, 0), buf, len);
  497. WFIFOSET(fd, len);
  498. }
  499. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  500. break;
  501. iter = mapit_getallusers();
  502. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  503. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  504. WFIFOHEAD( fd, len );
  505. memcpy( WFIFOP( fd, 0 ), buf, len );
  506. WFIFOSET( tsd->fd, len );
  507. }
  508. }
  509. mapit_free(iter);
  510. }
  511. break;
  512. case DUEL:
  513. case DUEL_WOS:
  514. if (!sd || !sd->duel_group) break; //Invalid usage.
  515. iter = mapit_getallusers();
  516. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  517. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  518. continue;
  519. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  520. WFIFOHEAD( fd, len );
  521. memcpy( WFIFOP( fd, 0 ), buf, len );
  522. WFIFOSET( fd, len );
  523. }
  524. }
  525. mapit_free(iter);
  526. break;
  527. case SELF:
  528. if( clif_session_isValid(sd) ){
  529. fd = sd->fd;
  530. WFIFOHEAD(fd,len);
  531. memcpy(WFIFOP(fd,0), buf, len);
  532. WFIFOSET(fd,len);
  533. }
  534. break;
  535. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  536. case GUILD_AREA:
  537. case GUILD_AREA_WOS:
  538. x0 = bl->x - AREA_SIZE;
  539. y0 = bl->y - AREA_SIZE;
  540. x1 = bl->x + AREA_SIZE;
  541. y1 = bl->y + AREA_SIZE;
  542. case GUILD_SAMEMAP:
  543. case GUILD_SAMEMAP_WOS:
  544. case GUILD:
  545. case GUILD_WOS:
  546. case GUILD_NOBG:
  547. if (sd && sd->status.guild_id)
  548. g = sd->guild;
  549. if (g) {
  550. for(i = 0; i < g->max_member; i++) {
  551. if( (sd = g->member[i].sd) != nullptr ){
  552. if( !session_isActive( fd = sd->fd ) )
  553. continue;
  554. if( type == GUILD_NOBG && sd->bg_id )
  555. continue;
  556. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  557. continue;
  558. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  559. continue;
  560. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  561. continue;
  562. WFIFOHEAD(fd,len);
  563. memcpy(WFIFOP(fd,0), buf, len);
  564. WFIFOSET(fd,len);
  565. }
  566. }
  567. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  568. break;
  569. iter = mapit_getallusers();
  570. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  571. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  572. WFIFOHEAD( fd, len );
  573. memcpy( WFIFOP( fd, 0 ), buf, len );
  574. WFIFOSET( fd, len );
  575. }
  576. }
  577. mapit_free(iter);
  578. }
  579. break;
  580. case BG_AREA:
  581. case BG_AREA_WOS:
  582. x0 = bl->x - AREA_SIZE;
  583. y0 = bl->y - AREA_SIZE;
  584. x1 = bl->x + AREA_SIZE;
  585. y1 = bl->y + AREA_SIZE;
  586. case BG_SAMEMAP:
  587. case BG_SAMEMAP_WOS:
  588. case BG:
  589. case BG_WOS:
  590. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  591. {
  592. for (const auto &member : bg->members) {
  593. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  594. continue;
  595. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  596. continue;
  597. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  598. continue;
  599. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  600. continue;
  601. WFIFOHEAD(fd,len);
  602. memcpy(WFIFOP(fd,0), buf, len);
  603. WFIFOSET(fd,len);
  604. }
  605. }
  606. break;
  607. case CLAN:
  608. if( sd && sd->clan ){
  609. struct clan* clan = sd->clan;
  610. for( i = 0; i < clan->max_member; i++ ){
  611. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  612. continue;
  613. }
  614. WFIFOHEAD(fd,len);
  615. memcpy(WFIFOP(fd,0), buf, len);
  616. WFIFOSET(fd,len);
  617. }
  618. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  619. break;
  620. iter = mapit_getallusers();
  621. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  622. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  623. WFIFOHEAD(fd, len);
  624. memcpy(WFIFOP(fd, 0), buf, len);
  625. WFIFOSET(fd, len);
  626. }
  627. }
  628. mapit_free(iter);
  629. }
  630. break;
  631. default:
  632. ShowError("clif_send: Unrecognized type %d\n",type);
  633. return -1;
  634. }
  635. return 0;
  636. }
  637. /// Notifies the client, that it's connection attempt was accepted.
  638. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  639. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  640. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  641. void clif_authok(struct map_session_data *sd)
  642. {
  643. #if PACKETVER < 20080102
  644. const int cmd = 0x73;
  645. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  646. const int cmd = 0x2eb;
  647. #else
  648. const int cmd = 0xa18;
  649. #endif
  650. int fd = sd->fd;
  651. WFIFOHEAD(fd,packet_len(cmd));
  652. WFIFOW(fd, 0) = cmd;
  653. WFIFOL(fd, 2) = client_tick(gettick());
  654. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  655. WFIFOB(fd, 9) = 5; // ignored
  656. WFIFOB(fd,10) = 5; // ignored
  657. #if PACKETVER >= 20080102
  658. WFIFOW(fd,11) = sd->status.font;
  659. #endif
  660. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  661. WFIFOB(fd,13) = sd->status.sex;
  662. #endif
  663. WFIFOSET(fd,packet_len(cmd));
  664. }
  665. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  666. /// 0074 <error code>.B
  667. /// error code:
  668. /// 0 = client type mismatch
  669. /// 1 = ID mismatch
  670. /// 2 = mobile - out of available time
  671. /// 3 = mobile - already logged in
  672. /// 4 = mobile - waiting state
  673. void clif_authrefuse(int fd, uint8 error_code)
  674. {
  675. WFIFOHEAD(fd,packet_len(0x74));
  676. WFIFOW(fd,0) = 0x74;
  677. WFIFOB(fd,2) = error_code;
  678. WFIFOSET(fd,packet_len(0x74));
  679. }
  680. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  681. /// 0081 <error code>.B
  682. /// error code:
  683. /// 0 = BAN_UNFAIR
  684. /// 1 = server closed -> MsgStringTable[4]
  685. /// 2 = ID already logged in -> MsgStringTable[5]
  686. /// 3 = timeout/too much lag -> MsgStringTable[241]
  687. /// 4 = server full -> MsgStringTable[264]
  688. /// 5 = underaged -> MsgStringTable[305]
  689. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  690. /// 9 = too many connections from this ip -> MsgStringTable[529]
  691. /// 10 = out of available time paid for -> MsgStringTable[530]
  692. /// 11 = BAN_PAY_SUSPEND
  693. /// 12 = BAN_PAY_CHANGE
  694. /// 13 = BAN_PAY_WRONGIP
  695. /// 14 = BAN_PAY_PNGAMEROOM
  696. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  697. /// 16 = BAN_JAPAN_REFUSE1
  698. /// 17 = BAN_JAPAN_REFUSE2
  699. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  700. /// 100 = BAN_PC_IP_UNFAIR
  701. /// 101 = BAN_PC_IP_COUNT_ALL
  702. /// 102 = BAN_PC_IP_COUNT
  703. /// 103 = BAN_GRAVITY_MEM_AGREE
  704. /// 104 = BAN_GAME_MEM_AGREE
  705. /// 105 = BAN_HAN_VALID
  706. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  707. /// 107 = BAN_OVER_CHARACTER_LIST
  708. /// 108 = BAN_IP_BLOCK
  709. /// 109 = BAN_INVALID_PWD_CNT
  710. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  711. /// ? = disconnected -> MsgStringTable[3]
  712. void clif_authfail_fd(int fd, int type)
  713. {
  714. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  715. return;
  716. WFIFOHEAD(fd, packet_len(0x81));
  717. WFIFOW(fd,0) = 0x81;
  718. WFIFOB(fd,2) = type;
  719. WFIFOSET(fd,packet_len(0x81));
  720. set_eof(fd);
  721. }
  722. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  723. /// 00b3 <type>.B
  724. /// type:
  725. /// 1 = disconnect, char-select
  726. /// ? = nothing
  727. void clif_charselectok(int id, uint8 ok)
  728. {
  729. struct map_session_data* sd;
  730. int fd;
  731. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  732. return;
  733. fd = sd->fd;
  734. WFIFOHEAD(fd,packet_len(0xb3));
  735. WFIFOW(fd,0) = 0xb3;
  736. WFIFOB(fd,2) = ok;
  737. WFIFOSET(fd,packet_len(0xb3));
  738. }
  739. /// Makes an item appear on the ground.
  740. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  741. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  742. /// 0ADD <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W <show drop effect>.B <drop effect mode>.W (ZC_ITEM_FALL_ENTRY5)
  743. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  744. nullpo_retv(fitem);
  745. if( fitem->item.nameid == 0 ){
  746. return;
  747. }
  748. struct packet_dropflooritem p;
  749. p.PacketType = dropflooritemType;
  750. p.ITAID = fitem->bl.id;
  751. p.ITID = client_nameid( fitem->item.nameid );
  752. #if PACKETVER >= 20130000 /* not sure date */
  753. p.type = itemtype( fitem->item.nameid );
  754. #endif
  755. p.IsIdentified = fitem->item.identify ? 1 : 0;
  756. p.xPos = fitem->bl.x;
  757. p.yPos = fitem->bl.y;
  758. p.subX = fitem->subx;
  759. p.subY = fitem->suby;
  760. p.count = fitem->item.amount;
  761. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  762. if( canShowEffect ){
  763. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  764. if( dropEffect > 0 ){
  765. p.showdropeffect = 1;
  766. p.dropeffectmode = dropEffect - 1;
  767. }else if (battle_config.rndopt_drop_pillar != 0){
  768. uint8 optionCount = 0;
  769. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  770. if (fitem->item.option[i].id != 0) {
  771. optionCount++;
  772. }
  773. }
  774. if (optionCount > 0) {
  775. p.showdropeffect = 1;
  776. if (optionCount == 1)
  777. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  778. else if (optionCount == 2)
  779. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  780. else
  781. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  782. } else {
  783. p.showdropeffect = 0;
  784. p.dropeffectmode = DROPEFFECT_NONE;
  785. }
  786. } else {
  787. p.showdropeffect = 0;
  788. p.dropeffectmode = DROPEFFECT_NONE;
  789. }
  790. }else{
  791. p.showdropeffect = 0;
  792. p.dropeffectmode = DROPEFFECT_NONE;
  793. }
  794. #endif
  795. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  796. }
  797. /// Makes an item disappear from the ground.
  798. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  799. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  800. {
  801. unsigned char buf[16];
  802. nullpo_retv(fitem);
  803. WBUFW(buf,0) = 0xa1;
  804. WBUFL(buf,2) = fitem->bl.id;
  805. if ( !session_isActive( fd ) ){
  806. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  807. } else {
  808. WFIFOHEAD(fd,packet_len(0xa1));
  809. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  810. WFIFOSET(fd,packet_len(0xa1));
  811. }
  812. }
  813. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  814. /// 0080 <id>.L <type>.B
  815. /// type:
  816. /// 0 = out of sight
  817. /// 1 = died
  818. /// 2 = logged out
  819. /// 3 = teleport
  820. /// 4 = trickdead
  821. void clif_clearunit_single(int id, clr_type type, int fd)
  822. {
  823. WFIFOHEAD(fd, packet_len(0x80));
  824. WFIFOW(fd,0) = 0x80;
  825. WFIFOL(fd,2) = id;
  826. WFIFOB(fd,6) = type;
  827. WFIFOSET(fd, packet_len(0x80));
  828. }
  829. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  830. /// 0080 <id>.L <type>.B
  831. /// type:
  832. /// 0 = out of sight
  833. /// 1 = died
  834. /// 2 = logged out
  835. /// 3 = teleport
  836. /// 4 = trickdead
  837. void clif_clearunit_area(struct block_list* bl, clr_type type)
  838. {
  839. unsigned char buf[8];
  840. nullpo_retv(bl);
  841. WBUFW(buf,0) = 0x80;
  842. WBUFL(buf,2) = bl->id;
  843. WBUFB(buf,6) = type;
  844. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  845. if(disguised(bl)) {
  846. WBUFL(buf,2) = disguised_bl_id( bl->id );
  847. clif_send(buf, packet_len(0x80), bl, SELF);
  848. }
  849. }
  850. /// Used to make monsters with player-sprites disappear after dying
  851. /// like normal monsters, because the client does not remove those
  852. /// automatically.
  853. static TIMER_FUNC(clif_clearunit_delayed_sub){
  854. struct block_list *bl = (struct block_list *)data;
  855. clif_clearunit_area(bl, (clr_type) id);
  856. ers_free(delay_clearunit_ers,bl);
  857. return 0;
  858. }
  859. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  860. {
  861. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  862. memcpy (tbl, bl, sizeof (struct block_list));
  863. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  864. }
  865. void clif_get_weapon_view(struct map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  866. {
  867. if(sd->sc.option&OPTION_COSTUME)
  868. {
  869. *rhand = *lhand = 0;
  870. return;
  871. }
  872. #if PACKETVER < 4
  873. *rhand = sd->status.weapon;
  874. *lhand = sd->status.shield;
  875. #else
  876. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  877. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  878. {
  879. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  880. if (id->view_id > 0)
  881. *rhand = id->view_id;
  882. else
  883. *rhand = id->nameid;
  884. } else
  885. *rhand = 0;
  886. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  887. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  888. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  889. {
  890. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  891. if (id->view_id > 0)
  892. *lhand = id->view_id;
  893. else
  894. *lhand = id->nameid;
  895. } else
  896. *lhand = 0;
  897. #endif
  898. }
  899. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  900. static int clif_setlevel_sub(int lv) {
  901. if( lv < battle_config.max_lv ) {
  902. ;
  903. } else if( lv < battle_config.aura_lv ) {
  904. lv = battle_config.max_lv - 1;
  905. } else {
  906. lv = battle_config.max_lv;
  907. }
  908. return lv;
  909. }
  910. static int clif_setlevel(struct block_list* bl) {
  911. int lv = status_get_lv(bl);
  912. if( battle_config.client_limit_unit_lv&bl->type )
  913. return clif_setlevel_sub(lv);
  914. switch( bl->type ) {
  915. case BL_NPC:
  916. case BL_PET:
  917. // npcs and pets do not have level
  918. return 0;
  919. }
  920. return lv;
  921. }
  922. /*==========================================
  923. * Prepares 'unit standing/spawning' packet
  924. *------------------------------------------*/
  925. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  926. nullpo_retv( bl );
  927. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  928. struct status_change* sc = status_get_sc( bl );
  929. struct view_data* vd = status_get_viewdata( bl );
  930. int g_id = status_get_guild_id( bl );
  931. #if PACKETVER < 20091103
  932. if( !pcdb_checkid( vd->class_ ) ){
  933. struct packet_idle_unit2 p;
  934. p.PacketType = idle_unit2Type;
  935. #if PACKETVER >= 20071106
  936. p.objecttype = clif_bl_type( bl, walking );
  937. #endif
  938. p.GID = bl->id;
  939. p.speed = status_get_speed( bl );
  940. p.bodyState = ( sc ) ? sc->opt1 : 0;
  941. p.healthState = ( sc ) ? sc->opt2 : 0;
  942. p.effectState = ( sc ) ? sc->option : 0;
  943. p.job = vd->class_;
  944. p.head = vd->hair_style;
  945. p.weapon = vd->weapon;
  946. p.accessory = vd->head_bottom;
  947. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  948. // The hell, why flags work like this?
  949. p.shield = status_get_emblem_id( bl );
  950. p.accessory2 = GetWord( g_id, 1 );
  951. p.accessory3 = GetWord( g_id, 0 );
  952. }else{
  953. p.shield = vd->shield;
  954. p.accessory2 = vd->head_top;
  955. p.accessory3 = vd->head_mid;
  956. }
  957. p.headpalette = vd->hair_color;
  958. p.bodypalette = vd->cloth_color;
  959. p.headDir = ( sd )? sd->head_dir : 0;
  960. p.GUID = g_id;
  961. p.GEmblemVer = status_get_emblem_id( bl );
  962. p.honor = ( sd ) ? sd->status.manner : 0;
  963. p.virtue = ( sc ) ? sc->opt3 : 0;
  964. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  965. p.sex = vd->sex;
  966. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  967. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  968. p.state = vd->dead_sit;
  969. p.clevel = clif_setlevel( bl );
  970. clif_send( &p, sizeof( p ), tbl, target );
  971. return;
  972. }
  973. #endif
  974. struct packet_idle_unit p;
  975. p.PacketType = idle_unitType;
  976. #if PACKETVER >= 20091103
  977. p.PacketLength = sizeof(p);
  978. p.objecttype = clif_bl_type( bl, walking );
  979. #endif
  980. #if PACKETVER >= 20131223
  981. p.AID = bl->id;
  982. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  983. #else
  984. p.GID = bl->id;
  985. #endif
  986. p.speed = status_get_speed(bl);
  987. p.bodyState = (sc) ? sc->opt1 : 0;
  988. p.healthState = (sc) ? sc->opt2 : 0;
  989. // npc option changed?
  990. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  991. struct map_session_data* sd = (struct map_session_data*)tbl;
  992. struct npc_data* nd = (struct npc_data*)bl;
  993. int option = (sc) ? sc->option : 0;
  994. if( !nd->vd.dead_sit ){
  995. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  996. option ^= OPTION_CLOAK;
  997. }
  998. }
  999. p.effectState = option;
  1000. }else{
  1001. p.effectState = (sc) ? sc->option : 0;
  1002. }
  1003. p.job = vd->class_;
  1004. p.head = vd->hair_style;
  1005. p.weapon = vd->weapon;
  1006. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1007. p.shield = vd->shield;
  1008. #endif
  1009. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1010. // The hell, why flags work like this?
  1011. p.accessory = status_get_emblem_id( bl );
  1012. p.accessory2 = GetWord( g_id, 1 );
  1013. p.accessory3 = GetWord( g_id, 0 );
  1014. }else{
  1015. p.accessory = vd->head_bottom;
  1016. p.accessory2 = vd->head_top;
  1017. p.accessory3 = vd->head_mid;
  1018. }
  1019. p.headpalette = vd->hair_color;
  1020. p.bodypalette = vd->cloth_color;
  1021. p.headDir = (sd)? sd->head_dir : 0;
  1022. #if PACKETVER >= 20101124
  1023. p.robe = vd->robe;
  1024. #endif
  1025. p.GUID = g_id;
  1026. p.GEmblemVer = status_get_emblem_id( bl );
  1027. p.honor = (sd) ? sd->status.manner : 0;
  1028. p.virtue = (sc) ? sc->opt3 : 0;
  1029. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1030. p.sex = vd->sex;
  1031. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1032. p.xSize = p.ySize = (sd) ? 5 : 0;
  1033. p.state = vd->dead_sit;
  1034. p.clevel = clif_setlevel( bl );
  1035. #if PACKETVER >= 20080102
  1036. p.font = (sd) ? sd->status.font : 0;
  1037. #endif
  1038. #if PACKETVER >= 20120221
  1039. if( battle_config.monster_hp_bars_info && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && bl->type == BL_MOB && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1040. p.maxHP = status_get_max_hp(bl);
  1041. p.HP = status_get_hp(bl);
  1042. }else{
  1043. p.maxHP = -1;
  1044. p.HP = -1;
  1045. }
  1046. if( bl->type == BL_MOB ){
  1047. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1048. }else if( bl->type == BL_PET ){
  1049. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1050. }else{
  1051. p.isBoss = BOSSTYPE_NONE;
  1052. }
  1053. #endif
  1054. #if PACKETVER >= 20150513
  1055. p.body = vd->body_style;
  1056. #endif
  1057. /* Might be earlier, this is when the named item bug began */
  1058. #if PACKETVER >= 20131223
  1059. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1060. #endif
  1061. clif_send( &p, sizeof( p ), tbl, target );
  1062. // if disguised, send to self
  1063. if( disguised( bl ) ){
  1064. #if PACKETVER >= 20091103
  1065. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1066. #if PACKETVER >= 20131223
  1067. p.AID = disguised_bl_id( bl->id );
  1068. #else
  1069. p.GID = disguised_bl_id( bl->id );
  1070. #endif
  1071. #else
  1072. p.GID = disguised_bl_id( bl->id );
  1073. #endif
  1074. clif_send(&p, sizeof(p), bl, SELF);
  1075. }
  1076. }
  1077. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1078. nullpo_retv( bl );
  1079. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1080. struct status_change* sc = status_get_sc( bl );
  1081. struct view_data* vd = status_get_viewdata( bl );
  1082. int g_id = status_get_guild_id( bl );
  1083. #if PACKETVER < 20091103
  1084. if( !pcdb_checkid( vd->class_ ) ){
  1085. struct packet_spawn_unit2 p;
  1086. p.PacketType = spawn_unit2Type;
  1087. #if PACKETVER >= 20071106
  1088. p.objecttype = clif_bl_type( bl, false );
  1089. #endif
  1090. p.GID = bl->id;
  1091. p.speed = status_get_speed( bl );
  1092. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1093. p.healthState = ( sc ) ? sc->opt2 : 0;
  1094. p.effectState = ( sc ) ? sc->option : 0;
  1095. p.head = vd->hair_style;
  1096. p.weapon = vd->weapon;
  1097. p.accessory = vd->head_bottom;
  1098. p.job = vd->class_;
  1099. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1100. // The hell, why flags work like this?
  1101. p.shield = status_get_emblem_id( bl );
  1102. p.accessory2 = GetWord( g_id, 1 );
  1103. p.accessory3 = GetWord( g_id, 0 );
  1104. }else{
  1105. p.shield = vd->shield;
  1106. p.accessory2 = vd->head_top;
  1107. p.accessory3 = vd->head_mid;
  1108. }
  1109. p.headpalette = vd->hair_color;
  1110. p.bodypalette = vd->cloth_color;
  1111. p.headDir = ( sd ) ? sd->head_dir : 0;
  1112. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1113. p.sex = vd->sex;
  1114. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1115. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1116. clif_send( &p, sizeof( p ), bl, target );
  1117. return;
  1118. }
  1119. #endif
  1120. struct packet_spawn_unit p;
  1121. p.PacketType = spawn_unitType;
  1122. #if PACKETVER >= 20091103
  1123. p.PacketLength = sizeof(p);
  1124. p.objecttype = clif_bl_type( bl, false );
  1125. #endif
  1126. #if PACKETVER >= 20131223
  1127. p.AID = bl->id;
  1128. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1129. #else
  1130. p.GID = bl->id;
  1131. #endif
  1132. p.speed = status_get_speed( bl );
  1133. p.bodyState = (sc) ? sc->opt1 : 0;
  1134. p.healthState = (sc) ? sc->opt2 : 0;
  1135. p.effectState = (sc) ? sc->option : 0;
  1136. p.job = vd->class_;
  1137. p.head = vd->hair_style;
  1138. p.weapon = vd->weapon;
  1139. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1140. p.shield = vd->shield;
  1141. #endif
  1142. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1143. // The hell, why flags work like this?
  1144. p.accessory = status_get_emblem_id( bl );
  1145. p.accessory2 = GetWord( g_id, 1 );
  1146. p.accessory3 = GetWord( g_id, 0 );
  1147. }else{
  1148. p.accessory = vd->head_bottom;
  1149. p.accessory2 = vd->head_top;
  1150. p.accessory3 = vd->head_mid;
  1151. }
  1152. p.headpalette = vd->hair_color;
  1153. p.bodypalette = vd->cloth_color;
  1154. p.headDir = (sd)? sd->head_dir : 0;
  1155. #if PACKETVER >= 20101124
  1156. p.robe = vd->robe;
  1157. #endif
  1158. p.GUID = g_id;
  1159. p.GEmblemVer = status_get_emblem_id( bl );
  1160. p.honor = (sd) ? sd->status.manner : 0;
  1161. p.virtue = (sc) ? sc->opt3 : 0;
  1162. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1163. p.sex = vd->sex;
  1164. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1165. p.xSize = p.ySize = (sd) ? 5 : 0;
  1166. p.clevel = clif_setlevel( bl );
  1167. #if PACKETVER >= 20080102
  1168. p.font = (sd) ? sd->status.font : 0;
  1169. #endif
  1170. #if PACKETVER >= 20120221
  1171. if( battle_config.monster_hp_bars_info && bl->type == BL_MOB && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1172. p.maxHP = status_get_max_hp( bl );
  1173. p.HP = status_get_hp( bl );
  1174. }else{
  1175. p.maxHP = -1;
  1176. p.HP = -1;
  1177. }
  1178. if( bl->type == BL_MOB ){
  1179. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1180. }else if( bl->type == BL_PET ){
  1181. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1182. }else{
  1183. p.isBoss = BOSSTYPE_NONE;
  1184. }
  1185. #endif
  1186. #if PACKETVER >= 20150513
  1187. p.body = vd->body_style;
  1188. #endif
  1189. /* Might be earlier, this is when the named item bug began */
  1190. #if PACKETVER >= 20131223
  1191. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1192. #endif
  1193. if( disguised( bl ) ){
  1194. nullpo_retv( sd );
  1195. if( sd->status.class_ != sd->disguise ){
  1196. clif_send( &p, sizeof( p ), bl, target );
  1197. }
  1198. #if PACKETVER >= 20091103
  1199. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1200. #if PACKETVER >= 20131223
  1201. p.AID = disguised_bl_id( bl->id );
  1202. #else
  1203. p.GID = disguised_bl_id( bl->id );
  1204. #endif
  1205. #else
  1206. p.GID = disguised_bl_id( bl->id );
  1207. #endif
  1208. clif_send( &p, sizeof( p ), bl, SELF );
  1209. }else{
  1210. clif_send( &p, sizeof( p ), bl, target );
  1211. }
  1212. }
  1213. /*==========================================
  1214. * Prepares 'unit walking' packet
  1215. *------------------------------------------*/
  1216. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1217. nullpo_retv( bl );
  1218. nullpo_retv( ud );
  1219. struct map_session_data* sd;
  1220. struct status_change* sc = status_get_sc( bl );
  1221. struct view_data* vd = status_get_viewdata( bl );
  1222. struct packet_unit_walking p;
  1223. int g_id = status_get_guild_id(bl);
  1224. sd = BL_CAST(BL_PC, bl);
  1225. p.PacketType = unit_walkingType;
  1226. #if PACKETVER >= 20091103
  1227. p.PacketLength = sizeof(p);
  1228. #endif
  1229. #if PACKETVER >= 20071106
  1230. p.objecttype = clif_bl_type( bl, true );
  1231. #endif
  1232. #if PACKETVER >= 20131223
  1233. p.AID = bl->id;
  1234. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1235. #else
  1236. p.GID = bl->id;
  1237. #endif
  1238. p.speed = status_get_speed(bl);
  1239. p.bodyState = (sc) ? sc->opt1 : 0;
  1240. p.healthState = (sc) ? sc->opt2 : 0;
  1241. p.effectState = (sc) ? sc->option : 0;
  1242. p.job = vd->class_;
  1243. p.head = vd->hair_style;
  1244. p.weapon = vd->weapon;
  1245. p.accessory = vd->head_bottom;
  1246. p.moveStartTime = client_tick(gettick());
  1247. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1248. p.shield = vd->shield;
  1249. #endif
  1250. p.accessory2 = vd->head_top;
  1251. p.accessory3 = vd->head_mid;
  1252. p.headpalette = vd->hair_color;
  1253. p.bodypalette = vd->cloth_color;
  1254. p.headDir = (sd) ? sd->head_dir : 0;
  1255. #if PACKETVER >= 20101124
  1256. p.robe = vd->robe;
  1257. #endif
  1258. p.GUID = g_id;
  1259. p.GEmblemVer = status_get_emblem_id(bl);
  1260. p.honor = (sd) ? sd->status.manner : 0;
  1261. p.virtue = (sc) ? sc->opt3 : 0;
  1262. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1263. p.sex = vd->sex;
  1264. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1265. p.xSize = p.ySize = (sd) ? 5 : 0;
  1266. p.clevel = clif_setlevel(bl);
  1267. #if PACKETVER >= 20080102
  1268. p.font = (sd) ? sd->status.font : 0;
  1269. #endif
  1270. #if PACKETVER >= 20120221
  1271. if( battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR) && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp( bl ) ) ){
  1272. p.maxHP = status_get_max_hp(bl);
  1273. p.HP = status_get_hp(bl);
  1274. } else {
  1275. p.maxHP = -1;
  1276. p.HP = -1;
  1277. }
  1278. if( bl->type == BL_MOB ){
  1279. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1280. }else if( bl->type == BL_PET ){
  1281. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1282. }else{
  1283. p.isBoss = BOSSTYPE_NONE;
  1284. }
  1285. #endif
  1286. #if PACKETVER >= 20150513
  1287. p.body = vd->body_style;
  1288. #endif
  1289. /* Might be earlier, this is when the named item bug began */
  1290. #if PACKETVER >= 20131223
  1291. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1292. #endif
  1293. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1294. // if disguised, send the info to self
  1295. if( disguised( bl ) ){
  1296. #if PACKETVER >= 20091103
  1297. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1298. #if PACKETVER >= 20131223
  1299. p.AID = disguised_bl_id( bl->id );
  1300. #else
  1301. p.GID = disguised_bl_id( bl->id );
  1302. #endif
  1303. #else
  1304. p.GID = disguised_bl_id( bl->id );
  1305. #endif
  1306. clif_send(&p,sizeof(p),bl,SELF);
  1307. }
  1308. }
  1309. //Modifies the buffer for disguise characters and sends it to self.
  1310. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1311. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1312. {
  1313. #if PACKETVER >= 20091103
  1314. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1315. WBUFL(buf,5)=-bl->id;
  1316. #elif PACKETVER >= 20071106
  1317. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1318. WBUFL(buf,3)=-bl->id;
  1319. #else
  1320. WBUFL(buf,2)=-bl->id;
  1321. #endif
  1322. clif_send(buf, len, bl, SELF);
  1323. }
  1324. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1325. /// 01b0 <id>.L <type>.B <value>.L
  1326. /// type:
  1327. /// unused
  1328. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1329. {
  1330. nullpo_retv(bl);
  1331. if(!pcdb_checkid(class_))
  1332. {// player classes yield missing sprites
  1333. unsigned char buf[16];
  1334. WBUFW(buf,0)=0x1b0;
  1335. WBUFL(buf,2)=bl->id;
  1336. WBUFB(buf,6)=type;
  1337. WBUFL(buf,7)=class_;
  1338. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1339. }
  1340. }
  1341. void clif_servantball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1342. struct PACKET_ZC_SPIRITS p = {};
  1343. p.packetType = HEADER_ZC_SPIRITS;
  1344. p.GID = sd.bl.id;
  1345. p.amount = sd.servantball;
  1346. if( target == nullptr ){
  1347. target = &sd.bl;
  1348. }
  1349. clif_send( &p, sizeof( p ), target, send_target );
  1350. }
  1351. void clif_abyssball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1352. struct PACKET_ZC_SPIRITS p = {};
  1353. p.packetType = HEADER_ZC_SPIRITS;
  1354. p.GID = sd.bl.id;
  1355. p.amount = sd.abyssball;
  1356. if( target == nullptr ){
  1357. target = &sd.bl;
  1358. }
  1359. clif_send( &p, sizeof( p ), target, send_target );
  1360. }
  1361. /// Notifies the client of an object's Millenium Shields.
  1362. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1363. {
  1364. nullpo_retv(sd);
  1365. if (sd->sc.data[SC_MILLENNIUMSHIELD] == nullptr)
  1366. return;
  1367. WFIFOHEAD(fd, packet_len(0x440));
  1368. WFIFOW(fd, 0) = 0x440;
  1369. WFIFOL(fd, 2) = sd->bl.id;
  1370. WFIFOW(fd, 6) = sd->sc.data[SC_MILLENNIUMSHIELD]->val2;
  1371. WFIFOW(fd, 8) = 0;
  1372. WFIFOSET(fd, packet_len(0x440));
  1373. }
  1374. /*==========================================
  1375. * Kagerou/Oboro amulet spirit
  1376. *------------------------------------------*/
  1377. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1378. {
  1379. WFIFOHEAD(fd, packet_len(0x08cf));
  1380. WFIFOW(fd,0)=0x08cf;
  1381. WFIFOL(fd,2)=sd->bl.id;
  1382. WFIFOW(fd,6)=sd->spiritcharm_type;
  1383. WFIFOW(fd,8)=sd->spiritcharm;
  1384. WFIFOSET(fd, packet_len(0x08cf));
  1385. }
  1386. /*==========================================
  1387. * Run when player changes map / refreshes
  1388. * Tells its client to display all weather settings being used by this map
  1389. *------------------------------------------*/
  1390. static void clif_weather_check(struct map_session_data *sd)
  1391. {
  1392. int16 m = sd->bl.m;
  1393. int fd = sd->fd;
  1394. if (map_getmapflag(m, MF_SNOW)
  1395. || map_getmapflag(m, MF_CLOUDS)
  1396. || map_getmapflag(m, MF_FOG)
  1397. || map_getmapflag(m, MF_FIREWORKS)
  1398. || map_getmapflag(m, MF_SAKURA)
  1399. || map_getmapflag(m, MF_LEAVES)
  1400. || map_getmapflag(m, MF_CLOUDS2))
  1401. {
  1402. if (map_getmapflag(m, MF_SNOW))
  1403. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1404. if (map_getmapflag(m, MF_CLOUDS))
  1405. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1406. if (map_getmapflag(m, MF_CLOUDS2))
  1407. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1408. if (map_getmapflag(m, MF_FOG))
  1409. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1410. if (map_getmapflag(m, MF_FIREWORKS)) {
  1411. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1412. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1413. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1414. }
  1415. if (map_getmapflag(m, MF_SAKURA))
  1416. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1417. if (map_getmapflag(m, MF_LEAVES))
  1418. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1419. }
  1420. }
  1421. /**
  1422. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1423. **/
  1424. void clif_weather(int16 m)
  1425. {
  1426. struct s_mapiterator* iter;
  1427. struct map_session_data *sd=NULL;
  1428. iter = mapit_getallusers();
  1429. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1430. {
  1431. if( sd->bl.m == m )
  1432. clif_weather_check(sd);
  1433. }
  1434. mapit_free(iter);
  1435. }
  1436. /**
  1437. * Hide a NPC from the effects of Maya Purple card.
  1438. * @param bl: Block data
  1439. * @return True if NPC is disabled or false otherwise
  1440. */
  1441. static inline bool clif_npc_mayapurple(block_list *bl) {
  1442. nullpo_retr(false, bl);
  1443. if (bl->type == BL_NPC) {
  1444. npc_data *nd = map_id2nd(bl->id);
  1445. // TODO: Confirm if waitingroom cause any special cases
  1446. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1447. return true;
  1448. }
  1449. return false;
  1450. }
  1451. /**
  1452. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1453. **/
  1454. int clif_spawn( struct block_list *bl, bool walking ){
  1455. struct view_data *vd;
  1456. vd = status_get_viewdata(bl);
  1457. if( !vd || vd->class_ == JT_INVISIBLE )
  1458. return 0;
  1459. // Hide NPC from Maya Purple card
  1460. if (clif_npc_mayapurple(bl))
  1461. return 0;
  1462. if( bl->type == BL_NPC && !vd->dead_sit ){
  1463. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1464. }else{
  1465. clif_spawn_unit( bl, AREA_WOS );
  1466. }
  1467. if (vd->cloth_color)
  1468. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1469. if (vd->body_style)
  1470. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1471. switch (bl->type)
  1472. {
  1473. case BL_PC:
  1474. {
  1475. TBL_PC *sd = ((TBL_PC*)bl);
  1476. if (sd->spiritball > 0)
  1477. clif_spiritball(&sd->bl);
  1478. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  1479. clif_millenniumshield(&sd->bl, sd->sc.data[SC_MILLENNIUMSHIELD]->val2);
  1480. if (sd->soulball > 0)
  1481. clif_soulball(sd);
  1482. if (sd->servantball > 0)
  1483. clif_servantball( *sd );
  1484. if (sd->abyssball > 0)
  1485. clif_abyssball( *sd );
  1486. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1487. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1488. else if(sd->state.size==SZ_MEDIUM)
  1489. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1490. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1491. clif_sendbgemblem_area(sd);
  1492. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1493. clif_spiritcharm(sd);
  1494. if (sd->status.robe)
  1495. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1496. clif_efst_status_change_sub(bl, bl, AREA);
  1497. clif_hat_effects(sd,bl,AREA);
  1498. }
  1499. break;
  1500. case BL_MOB:
  1501. {
  1502. TBL_MOB *md = ((TBL_MOB*)bl);
  1503. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1504. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1505. else if(md->special_state.size==SZ_MEDIUM)
  1506. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1507. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1508. clif_summon_init(*md);
  1509. }
  1510. break;
  1511. case BL_NPC:
  1512. {
  1513. TBL_NPC *nd = ((TBL_NPC*)bl);
  1514. if( nd->size == SZ_BIG )
  1515. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1516. else if( nd->size == SZ_MEDIUM )
  1517. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1518. clif_efst_status_change_sub(bl, bl, AREA);
  1519. clif_progressbar_npc_area(nd);
  1520. }
  1521. break;
  1522. case BL_PET:
  1523. if (vd->head_bottom)
  1524. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1525. break;
  1526. }
  1527. return 0;
  1528. }
  1529. /// Sends information about owned homunculus to the client . [orn]
  1530. /// 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)
  1531. /// 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)
  1532. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1533. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1534. nullpo_retv( sd );
  1535. nullpo_retv( hd );
  1536. struct status_data *status = &hd->battle_status;
  1537. struct PACKET_ZC_PROPERTY_HOMUN p;
  1538. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1539. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1540. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1541. 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 );
  1542. p.level = hd->homunculus.level;
  1543. p.hunger = hd->homunculus.hunger;
  1544. p.intimacy = hd->homunculus.intimacy / 100;
  1545. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1546. p.itemId = 0; // equip id
  1547. #endif
  1548. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1549. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1550. p.hit = status->hit;
  1551. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1552. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1553. }else{
  1554. p.crit = status->cri / 10;
  1555. }
  1556. #ifdef RENEWAL
  1557. p.def = status->def + status->def2;
  1558. p.mdef = status->mdef + status->mdef2;
  1559. #else
  1560. p.def = status->def + status->vit;
  1561. p.mdef = status->mdef;
  1562. #endif
  1563. p.flee = status->flee;
  1564. p.amotion = (flag) ? 0 : status->amotion;
  1565. #if PACKETVER >= 20141016
  1566. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1567. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1568. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1569. p.hp = status->hp / ( status->max_hp / 100 );
  1570. p.maxHp = 100;
  1571. }else{
  1572. p.hp = status->hp;
  1573. p.maxHp = status->max_hp;
  1574. }
  1575. #else
  1576. if( status->max_hp > INT16_MAX ){
  1577. p.hp = status->hp / ( status->max_hp / 100 );
  1578. p.maxHp = 100;
  1579. }else{
  1580. p.hp = status->hp;
  1581. p.maxHp = status->max_hp;
  1582. }
  1583. #endif
  1584. if( status->max_sp > INT16_MAX ){
  1585. p.sp = status->sp / ( status->max_sp / 100 );
  1586. p.maxSp = 100;
  1587. }else{
  1588. p.sp = status->sp;
  1589. p.maxSp = status->max_sp;
  1590. }
  1591. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1592. p.exp = hd->homunculus.exp;
  1593. p.expNext = hd->exp_next;
  1594. #else
  1595. p.exp = (uint32)hd->homunculus.exp;
  1596. p.expNext = (uint32)hd->exp_next;
  1597. #endif
  1598. switch( hom_class2type( hd->homunculus.class_ ) ){
  1599. case HT_REG:
  1600. case HT_EVO:
  1601. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1602. p.expNext = 0;
  1603. }
  1604. break;
  1605. case HT_S:
  1606. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1607. p.expNext = 0;
  1608. }
  1609. break;
  1610. }
  1611. p.skillPoints = hd->homunculus.skillpts;
  1612. p.range = status_get_range( &hd->bl );
  1613. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1614. #endif
  1615. }
  1616. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1617. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1618. /// type:
  1619. /// unused
  1620. /// state:
  1621. /// 0 = pre-init
  1622. /// 1 = intimacy
  1623. /// 2 = hunger
  1624. /// 3 = accessory?
  1625. /// ? = ignored
  1626. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1627. { //[orn]
  1628. int fd = sd->fd;
  1629. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1630. hom_calc_skilltree(sd->hd, 0);
  1631. WFIFOHEAD(fd, packet_len(0x230));
  1632. WFIFOW(fd,0)=0x230;
  1633. WFIFOB(fd,2)=0;
  1634. WFIFOB(fd,3)=state;
  1635. WFIFOL(fd,4)=sd->hd->bl.id;
  1636. WFIFOL(fd,8)=param;
  1637. WFIFOSET(fd,packet_len(0x230));
  1638. }
  1639. int clif_homskillinfoblock(struct map_session_data *sd)
  1640. { //[orn]
  1641. struct homun_data *hd;
  1642. int fd = sd->fd;
  1643. int i, len=4;
  1644. nullpo_ret(sd);
  1645. hd = sd->hd;
  1646. if ( !hd )
  1647. return 0 ;
  1648. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1649. WFIFOW(fd,0)=0x235;
  1650. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1651. int id = hd->homunculus.hskill[i].id;
  1652. if( id != 0 ){
  1653. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1654. short idx = hom_skill_get_index(id);
  1655. if (idx == -1)
  1656. continue;
  1657. WFIFOW(fd,len ) = id;
  1658. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1659. WFIFOW(fd,len+4) = 0;
  1660. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1661. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1662. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1663. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1664. 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;
  1665. len+=37;
  1666. }
  1667. }
  1668. WFIFOW(fd,2)=len;
  1669. WFIFOSET(fd,len);
  1670. return 0;
  1671. }
  1672. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1673. { //[orn]
  1674. struct homun_data *hd;
  1675. int fd;
  1676. short idx = -1;
  1677. nullpo_retv(sd);
  1678. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1679. return;
  1680. fd = sd->fd;
  1681. hd = sd->hd;
  1682. WFIFOHEAD(fd, packet_len(0x239));
  1683. WFIFOW(fd,0) = 0x239;
  1684. WFIFOW(fd,2) = skill_id;
  1685. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1686. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1687. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1688. 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;
  1689. WFIFOSET(fd,packet_len(0x239));
  1690. }
  1691. /// Result of request to feed a homun/merc.
  1692. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1693. /// result:
  1694. /// 0 = failure
  1695. /// 1 = success
  1696. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1697. nullpo_retv( sd );
  1698. struct PACKET_ZC_FEED_MER p;
  1699. p.packetType = 0x22f;
  1700. p.result = fail;
  1701. p.itemId = client_nameid( foodid );
  1702. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1703. }
  1704. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1705. /// 0087 <walk start time>.L <walk data>.6B
  1706. void clif_walkok(struct map_session_data *sd)
  1707. {
  1708. int fd=sd->fd;
  1709. WFIFOHEAD(fd, packet_len(0x87));
  1710. WFIFOW(fd,0)=0x87;
  1711. WFIFOL(fd,2)=client_tick(gettick());
  1712. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1713. WFIFOSET(fd,packet_len(0x87));
  1714. }
  1715. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1716. struct status_change *sc = NULL;
  1717. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1718. clif_ally_only = true;
  1719. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1720. if(vd->cloth_color)
  1721. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1722. if(vd->body_style)
  1723. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1724. switch(bl->type) {
  1725. case BL_PC:
  1726. {
  1727. TBL_PC *sd = ((TBL_PC*)bl);
  1728. // clif_movepc(sd);
  1729. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1730. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1731. else if(sd->state.size==SZ_MEDIUM)
  1732. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1733. if (sd->status.robe)
  1734. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1735. }
  1736. break;
  1737. case BL_MOB:
  1738. {
  1739. TBL_MOB *md = ((TBL_MOB*)bl);
  1740. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1741. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1742. else if(md->special_state.size==SZ_MEDIUM)
  1743. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1744. }
  1745. break;
  1746. case BL_PET:
  1747. if(vd->head_bottom) // needed to display pet equip properly
  1748. clif_pet_equip_area((TBL_PET*)bl);
  1749. break;
  1750. }
  1751. clif_ally_only = false;
  1752. }
  1753. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1754. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1755. /// Note: unit must not be self
  1756. void clif_move(struct unit_data *ud)
  1757. {
  1758. unsigned char buf[16];
  1759. struct view_data* vd;
  1760. struct block_list* bl = ud->bl;
  1761. struct status_change *sc = NULL;
  1762. vd = status_get_viewdata(bl);
  1763. if (!vd )
  1764. return;
  1765. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1766. else if( vd->class_ == JT_INVISIBLE ){
  1767. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1768. if(disguised(bl)) {
  1769. WBUFW(buf,0)=0x86;
  1770. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1771. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1772. WBUFL(buf,12)=client_tick(gettick());
  1773. clif_send(buf, packet_len(0x86), bl, SELF);
  1774. }
  1775. return;
  1776. }
  1777. // Hide NPC from Maya Purple card
  1778. if (clif_npc_mayapurple(bl))
  1779. return;
  1780. if (ud->state.speed_changed) {
  1781. // Since we don't know how to update the speed of other objects,
  1782. // use the old walk packet to update the data.
  1783. ud->state.speed_changed = 0;
  1784. clif_move2(bl, vd, ud);
  1785. return;
  1786. }
  1787. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1788. clif_ally_only = true;
  1789. WBUFW(buf,0)=0x86;
  1790. WBUFL(buf,2)=bl->id;
  1791. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1792. WBUFL(buf,12)=client_tick(gettick());
  1793. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1794. if (disguised(bl)) {
  1795. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1796. clif_send(buf, packet_len(0x86), bl, SELF);
  1797. }
  1798. clif_ally_only = false;
  1799. }
  1800. /*==========================================
  1801. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1802. *------------------------------------------*/
  1803. static TIMER_FUNC(clif_delayquit){
  1804. struct map_session_data *sd = NULL;
  1805. //Remove player from map server
  1806. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1807. map_quit(sd);
  1808. return 0;
  1809. }
  1810. /*==========================================
  1811. *
  1812. *------------------------------------------*/
  1813. void clif_quitsave(int fd,struct map_session_data *sd) {
  1814. if (!battle_config.prevent_logout ||
  1815. sd->canlog_tick == 0 ||
  1816. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1817. map_quit(sd);
  1818. else if (session_isValid(sd->fd)) {
  1819. //Disassociate session from player (session is deleted after this function was called)
  1820. //And set a timer to make him quit later.
  1821. session[sd->fd]->session_data = NULL;
  1822. sd->fd = 0;
  1823. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1824. }
  1825. }
  1826. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1827. /// 0091 <map name>.16B <x>.W <y>.W
  1828. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1829. {
  1830. nullpo_retv(sd);
  1831. int fd = sd->fd;
  1832. WFIFOHEAD(fd,packet_len(0x91));
  1833. WFIFOW(fd,0) = 0x91;
  1834. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1835. WFIFOW(fd,18) = x;
  1836. WFIFOW(fd,20) = y;
  1837. WFIFOSET(fd,packet_len(0x91));
  1838. }
  1839. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1840. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1841. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1842. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1843. {
  1844. int fd;
  1845. #if PACKETVER >= 20170315
  1846. int cmd = 0xac7;
  1847. #else
  1848. int cmd = 0x92;
  1849. #endif
  1850. nullpo_retv(sd);
  1851. fd = sd->fd;
  1852. WFIFOHEAD(fd,packet_len(cmd));
  1853. WFIFOW(fd,0) = cmd;
  1854. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1855. WFIFOW(fd,18) = x;
  1856. WFIFOW(fd,20) = y;
  1857. WFIFOL(fd,22) = htonl(ip);
  1858. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1859. #if PACKETVER >= 20170315
  1860. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1861. #endif
  1862. WFIFOSET(fd,packet_len(cmd));
  1863. }
  1864. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1865. /// This function combines both calls and allows to simplify the calling code
  1866. void clif_blown(struct block_list *bl)
  1867. {
  1868. clif_slide(bl, bl->x, bl->y);
  1869. clif_fixpos(bl);
  1870. }
  1871. /// Visually moves(slides) a character to x,y. If the target cell
  1872. /// isn't walkable, the char doesn't move at all. If the char is
  1873. /// sitting it will stand up (ZC_STOPMOVE).
  1874. /// 0088 <id>.L <x>.W <y>.W
  1875. void clif_fixpos(struct block_list *bl)
  1876. {
  1877. unsigned char buf[10];
  1878. nullpo_retv(bl);
  1879. WBUFW(buf,0) = 0x88;
  1880. WBUFL(buf,2) = bl->id;
  1881. WBUFW(buf,6) = bl->x;
  1882. WBUFW(buf,8) = bl->y;
  1883. clif_send(buf, packet_len(0x88), bl, AREA);
  1884. if( disguised(bl) ) {
  1885. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1886. clif_send(buf, packet_len(0x88), bl, SELF);
  1887. }
  1888. }
  1889. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1890. /// 00c4 <shop id>.L
  1891. void clif_npcbuysell(struct map_session_data* sd, int id)
  1892. {
  1893. int fd;
  1894. nullpo_retv(sd);
  1895. fd=sd->fd;
  1896. WFIFOHEAD(fd, packet_len(0xc4));
  1897. WFIFOW(fd,0)=0xc4;
  1898. WFIFOL(fd,2)=id;
  1899. WFIFOSET(fd,packet_len(0xc4));
  1900. }
  1901. /// Presents list of items, that can be bought in an NPC shop.
  1902. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1903. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1904. nullpo_retv( sd );
  1905. nullpo_retv( nd );
  1906. int fd = sd->fd;
  1907. if( !session_isActive( fd ) ){
  1908. return;
  1909. }
  1910. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1911. WFIFOHEAD( fd, len );
  1912. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1913. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1914. int count = 0;
  1915. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1916. int val = nd->u.shop.shop_item[i].value;
  1917. p->items[count].price = val;
  1918. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1919. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1920. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1921. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1922. struct item_data* id = itemdb_exists( nd->u.shop.shop_item[i].nameid );
  1923. p->items[count].viewSprite = id->look;
  1924. p->items[count].location = pc_equippoint_sub( sd, id );
  1925. #endif
  1926. count++;
  1927. }
  1928. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1929. WFIFOSET( fd, p->packetLength );
  1930. }
  1931. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1932. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1933. void clif_selllist(struct map_session_data *sd)
  1934. {
  1935. int fd,i,c=0,val;
  1936. struct npc_data *nd;
  1937. nullpo_retv(sd);
  1938. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1939. return;
  1940. fd=sd->fd;
  1941. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1942. WFIFOW(fd,0)=0xc7;
  1943. for( i = 0; i < MAX_INVENTORY; i++ )
  1944. {
  1945. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1946. {
  1947. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1948. continue;
  1949. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1950. val = 0;
  1951. else {
  1952. val = sd->inventory_data[i]->value_sell;
  1953. if( val < 0 )
  1954. continue;
  1955. }
  1956. WFIFOW(fd,4+c*10)=i+2;
  1957. WFIFOL(fd,6+c*10)=val;
  1958. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1959. c++;
  1960. }
  1961. }
  1962. WFIFOW(fd,2)=c*10+4;
  1963. WFIFOSET(fd,WFIFOW(fd,2));
  1964. }
  1965. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1966. /// 09d4
  1967. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1968. // TODO: State tracking?
  1969. sd->npc_shopid = 0;
  1970. }
  1971. /**
  1972. * Presents list of items, that can be sold to a Market shop.
  1973. * @author: Ind and Yommy
  1974. **/
  1975. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1976. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1977. #if PACKETVER >= 20131223
  1978. nullpo_retv( sd );
  1979. nullpo_retv( nd );
  1980. if( sd->state.trading ){
  1981. return;
  1982. }
  1983. int fd = sd->fd;
  1984. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1985. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1986. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1987. int count = 0;
  1988. for( int i = 0; i < nd->u.shop.count; i++ ){
  1989. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1990. if( !item->nameid ){
  1991. continue;
  1992. }
  1993. struct item_data *id = itemdb_exists( item->nameid );
  1994. if( !id ){
  1995. continue;
  1996. }
  1997. // Out of stock
  1998. if( item->qty == 0 ){
  1999. continue;
  2000. }
  2001. p->list[count].nameid = client_nameid( item->nameid );
  2002. p->list[count].type = itemtype( item->nameid );
  2003. p->list[count].price = item->value;
  2004. p->list[count].qty = item->qty;
  2005. p->list[count].weight = id->weight;
  2006. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2007. p->list[count].location = pc_equippoint_sub( sd, id );
  2008. #endif
  2009. count++;
  2010. }
  2011. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2012. WFIFOSET( fd, p->packetLength );
  2013. sd->state.trading = 1;
  2014. #endif
  2015. }
  2016. /// Closes the Market shop window.
  2017. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  2018. nullpo_retv(sd);
  2019. sd->npc_shopid = 0;
  2020. sd->state.trading = 0;
  2021. }
  2022. /// Purchase item from Market shop.
  2023. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2024. void clif_npc_market_purchase_ack( struct map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2025. #if PACKETVER >= 20131223
  2026. nullpo_retv( sd );
  2027. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2028. nullpo_retv( nd );
  2029. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2030. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2031. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2032. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2033. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2034. #else
  2035. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2036. #endif
  2037. if( p->result ){
  2038. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2039. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2040. // Not found
  2041. if( j == nd->u.shop.count ){
  2042. continue;
  2043. }
  2044. p->list[count].ITID = client_nameid( list[i].nameid );
  2045. p->list[count].qty = list[i].qty;
  2046. p->list[count].price = nd->u.shop.shop_item[j].value;
  2047. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2048. count++;
  2049. }
  2050. }
  2051. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2052. #endif
  2053. }
  2054. /// Purchase item from Market shop.
  2055. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2056. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  2057. #if PACKETVER >= 20131223
  2058. nullpo_retv( sd );
  2059. if( !sd->npc_shopid ){
  2060. return;
  2061. }
  2062. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2063. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2064. std::vector<s_npc_buy_list> items;
  2065. items.reserve( count );
  2066. for( int i = 0; i < count; i++ ){
  2067. s_npc_buy_list item = {};
  2068. item.nameid = p->list[i].ITID;
  2069. item.qty = p->list[i].qty;
  2070. items.push_back( item );
  2071. }
  2072. e_purchase_result res = npc_buylist( sd, items );
  2073. clif_npc_market_purchase_ack( sd, res, items );
  2074. #endif
  2075. }
  2076. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2077. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2078. /// Client behavior (dialog window):
  2079. /// - disable mouse targeting
  2080. /// - open the dialog window
  2081. /// - set npcid of dialog window (0 by default)
  2082. /// - if set to clear on next mes, clear contents
  2083. /// - append this text
  2084. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  2085. {
  2086. int fd = sd->fd;
  2087. int slen = strlen(mes) + 9;
  2088. WFIFOHEAD(fd, slen);
  2089. WFIFOW(fd,0)=0xb4;
  2090. WFIFOW(fd,2)=slen;
  2091. WFIFOL(fd,4)=npcid;
  2092. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2093. WFIFOSET(fd,WFIFOW(fd,2));
  2094. }
  2095. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2096. /// 00b5 <npc id>.L
  2097. /// Client behavior (dialog window):
  2098. /// - disable mouse targeting
  2099. /// - open the dialog window
  2100. /// - add 'next' button
  2101. /// When 'next' is pressed:
  2102. /// - 00B9 <npcid of dialog window>.L
  2103. /// - set to clear on next mes
  2104. /// - remove 'next' button
  2105. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2106. {
  2107. int fd;
  2108. nullpo_retv(sd);
  2109. fd=sd->fd;
  2110. WFIFOHEAD(fd, packet_len(0xb5));
  2111. WFIFOW(fd,0)=0xb5;
  2112. WFIFOL(fd,2)=npcid;
  2113. WFIFOSET(fd,packet_len(0xb5));
  2114. }
  2115. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2116. /// 00b6 <npc id>.L
  2117. /// Client behavior:
  2118. /// - if dialog window is open:
  2119. /// - remove 'next' button
  2120. /// - add 'close' button
  2121. /// - else:
  2122. /// - enable mouse targeting
  2123. /// - close the dialog window
  2124. /// - close the menu window
  2125. /// When 'close' is pressed:
  2126. /// - enable mouse targeting
  2127. /// - close the dialog window
  2128. /// - close the menu window
  2129. /// - 0146 <npcid of dialog window>.L
  2130. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2131. {
  2132. int fd;
  2133. nullpo_retv(sd);
  2134. fd=sd->fd;
  2135. WFIFOHEAD(fd, packet_len(0xb6));
  2136. WFIFOW(fd,0)=0xb6;
  2137. WFIFOL(fd,2)=npcid;
  2138. WFIFOSET(fd,packet_len(0xb6));
  2139. }
  2140. /**
  2141. * Close script when player is idle
  2142. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2143. * @author [Ind/Hercules]
  2144. * @param sd : player pointer
  2145. * @param npcid : npc gid to close
  2146. */
  2147. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2148. {
  2149. struct s_packet_db* info;
  2150. int16 len;
  2151. int cmd = 0;
  2152. int fd;
  2153. nullpo_retv(sd);
  2154. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2155. if(!cmd) cmd = 0x8d6; //default
  2156. info = &packet_db[cmd];
  2157. len = info->len;
  2158. fd = sd->fd;
  2159. WFIFOHEAD(fd, len);
  2160. WFIFOW(fd,0)=0x8d6;
  2161. WFIFOL(fd,info->pos[0])=npcid;
  2162. WFIFOSET(fd,len);
  2163. }
  2164. /*==========================================
  2165. *
  2166. *------------------------------------------*/
  2167. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2168. unsigned char *buf;
  2169. int fd = sd->fd;
  2170. sd->state.using_fake_npc = 1;
  2171. WFIFOHEAD(fd, packet_len(0x78));
  2172. buf = WFIFOP(fd,0);
  2173. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2174. WBUFW(buf,0)=0x78;
  2175. #if PACKETVER >= 20071106
  2176. WBUFB(buf,2) = 0; // object type
  2177. buf = WFIFOP(fd,1);
  2178. #endif
  2179. WBUFL(buf,2)=npcid;
  2180. WBUFW(buf,14)=111;
  2181. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2182. WBUFB(buf,49)=5;
  2183. WBUFB(buf,50)=5;
  2184. WFIFOSET(fd, packet_len(0x78));
  2185. }
  2186. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2187. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2188. /// Client behavior:
  2189. /// - disable mouse targeting
  2190. /// - close the menu window
  2191. /// - open the menu window
  2192. /// - add options to the menu (separated in the text by ":")
  2193. /// - set npcid of menu window
  2194. /// - if dialog window is open:
  2195. /// - remove 'next' button
  2196. /// When 'ok' is pressed:
  2197. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2198. /// - close the menu window
  2199. /// When 'cancel' is pressed:
  2200. /// - 00B8 <npcid of menu window>.L <-1>.B
  2201. /// - enable mouse targeting
  2202. /// - close a bunch of windows...
  2203. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2204. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2205. /// TODO investigate behavior of other windows [FlavioJS]
  2206. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2207. {
  2208. int fd = sd->fd;
  2209. int slen = strlen(mes) + 9;
  2210. struct block_list *bl = NULL;
  2211. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2212. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2213. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2214. clif_sendfakenpc(sd, npcid);
  2215. WFIFOHEAD(fd, slen);
  2216. WFIFOW(fd,0)=0xb7;
  2217. WFIFOW(fd,2)=slen;
  2218. WFIFOL(fd,4)=npcid;
  2219. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2220. WFIFOSET(fd,WFIFOW(fd,2));
  2221. }
  2222. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2223. /// 0142 <npc id>.L
  2224. /// Client behavior (inputnum window):
  2225. /// - if npcid exists in the client:
  2226. /// - open the inputnum window
  2227. /// - set npcid of inputnum window
  2228. /// When 'ok' is pressed:
  2229. /// - if inputnum window has text:
  2230. /// - if npcid exists in the client:
  2231. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2232. /// - close inputnum window
  2233. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2234. {
  2235. int fd;
  2236. struct block_list *bl = NULL;
  2237. nullpo_retv(sd);
  2238. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2239. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2240. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2241. clif_sendfakenpc(sd, npcid);
  2242. fd=sd->fd;
  2243. WFIFOHEAD(fd, packet_len(0x142));
  2244. WFIFOW(fd,0)=0x142;
  2245. WFIFOL(fd,2)=npcid;
  2246. WFIFOSET(fd,packet_len(0x142));
  2247. }
  2248. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2249. /// 01d4 <npc id>.L
  2250. /// Client behavior (inputstr window):
  2251. /// - if npcid is 0 or npcid exists in the client:
  2252. /// - open the inputstr window
  2253. /// - set npcid of inputstr window
  2254. /// When 'ok' is pressed:
  2255. /// - if inputstr window has text and isn't an insult(manner.txt):
  2256. /// - if npcid is 0 or npcid exists in the client:
  2257. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2258. /// - close inputstr window
  2259. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2260. {
  2261. int fd;
  2262. struct block_list *bl = NULL;
  2263. nullpo_retv(sd);
  2264. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2265. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2266. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2267. clif_sendfakenpc(sd, npcid);
  2268. fd=sd->fd;
  2269. WFIFOHEAD(fd, packet_len(0x1d4));
  2270. WFIFOW(fd,0)=0x1d4;
  2271. WFIFOL(fd,2)=npcid;
  2272. WFIFOSET(fd,packet_len(0x1d4));
  2273. }
  2274. /// Marks a position on client's minimap (ZC_COMPASS).
  2275. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2276. /// npc id:
  2277. /// is ignored in the client
  2278. /// type:
  2279. /// 0 = display mark for 15 seconds
  2280. /// 1 = display mark until dead or teleported
  2281. /// 2 = remove mark
  2282. /// color:
  2283. /// 0x00RRGGBB
  2284. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2285. {
  2286. int fd;
  2287. nullpo_retv(sd);
  2288. fd=sd->fd;
  2289. WFIFOHEAD(fd, packet_len(0x144));
  2290. WFIFOW(fd,0)=0x144;
  2291. WFIFOL(fd,2)=npc_id;
  2292. WFIFOL(fd,6)=type;
  2293. WFIFOL(fd,10)=x;
  2294. WFIFOL(fd,14)=y;
  2295. WFIFOB(fd,18)=id;
  2296. WFIFOL(fd,19)=color;
  2297. WFIFOSET(fd,packet_len(0x144));
  2298. }
  2299. /// Displays an illustration image.
  2300. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2301. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2302. /// type:
  2303. /// 0 = bottom left corner
  2304. /// 1 = bottom middle
  2305. /// 2 = bottom right corner
  2306. /// 3 = middle of screen, inside a movable window
  2307. /// 4 = middle of screen, movable with a close button, chrome-less
  2308. /// 255 = clear all displayed cutins
  2309. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2310. {
  2311. int fd;
  2312. nullpo_retv(sd);
  2313. fd=sd->fd;
  2314. WFIFOHEAD(fd, packet_len(0x1b3));
  2315. WFIFOW(fd,0)=0x1b3;
  2316. strncpy(WFIFOCP(fd,2),image,64);
  2317. WFIFOB(fd,66)=type;
  2318. WFIFOSET(fd,packet_len(0x1b3));
  2319. }
  2320. /*==========================================
  2321. * Fills in card data from the given item and into the buffer. [Skotlex]
  2322. *------------------------------------------*/
  2323. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2324. nullpo_retv( buf );
  2325. // Blank data
  2326. if( item == nullptr ){
  2327. buf->card[0] = 0;
  2328. buf->card[1] = 0;
  2329. buf->card[2] = 0;
  2330. buf->card[3] = 0;
  2331. return;
  2332. }
  2333. // Pet eggs
  2334. if( item->card[0] == CARD0_PET ){
  2335. buf->card[0] = 0;
  2336. buf->card[1] = 0;
  2337. // Pet intimacy
  2338. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2339. buf->card[2] = item->card[3] >> 1;
  2340. // Pet renamed flag
  2341. buf->card[3] = item->card[3] & 1;
  2342. return;
  2343. }
  2344. // Forged/created items
  2345. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2346. buf->card[0] = item->card[0];
  2347. buf->card[1] = item->card[1];
  2348. buf->card[2] = item->card[2];
  2349. buf->card[3] = item->card[3];
  2350. return;
  2351. }
  2352. int i = 0, j;
  2353. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2354. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2355. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2356. }
  2357. // Normal items.
  2358. for( int k = 0; k < 4; k++, i++ ){
  2359. if( item->card[i] > 0 ){
  2360. buf->card[k] = client_nameid( item->card[i] );
  2361. }else{
  2362. buf->card[k] = 0;
  2363. }
  2364. }
  2365. }
  2366. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2367. /// A maximum of 5 random options can be supported.
  2368. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2369. nullpo_retr( 0, it );
  2370. uint8 count = 0;
  2371. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2372. if( it->option[i].id ){
  2373. buf[i].index = it->option[i].id; // OptIndex
  2374. buf[i].value = it->option[i].value; // Value
  2375. buf[i].param = it->option[i].param; // Param1
  2376. count++;
  2377. }else{
  2378. buf[i].index = 0;
  2379. buf[i].value = 0;
  2380. buf[i].param = 0;
  2381. }
  2382. }
  2383. #if MAX_ITEM_RDM_OPT < 5
  2384. for( ; i < 5; i++ ){
  2385. buf[i].index = 0; // OptIndex
  2386. buf[i].value = 0; // Value
  2387. buf[i].param = 0; // Param1
  2388. }
  2389. #endif
  2390. return count;
  2391. }
  2392. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2393. /// 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)
  2394. /// 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)
  2395. /// 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)
  2396. /// 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)
  2397. /// 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)
  2398. /// 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)
  2399. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2400. nullpo_retv( sd );
  2401. int fd = sd->fd;
  2402. if( !session_isActive( fd ) ){
  2403. return;
  2404. }
  2405. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2406. if( fail ){
  2407. p = {};
  2408. }else{
  2409. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2410. return;
  2411. }
  2412. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2413. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2414. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2415. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2416. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2417. p.location = pc_equippoint(sd,n);
  2418. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2419. #if PACKETVER >= 20061218
  2420. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2421. #if PACKETVER >= 20071002
  2422. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2423. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2424. */
  2425. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2426. #if PACKETVER >= 20150226
  2427. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2428. #if PACKETVER >= 20160921
  2429. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2430. p.look = sd->inventory_data[n]->look;
  2431. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2432. p.enchantgrade = sd->inventory.u.items_inventory[n].enchantgrade;
  2433. #endif
  2434. #endif
  2435. #endif
  2436. #endif
  2437. #endif
  2438. }
  2439. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2440. p.Index = client_index( n );
  2441. p.count = amount;
  2442. p.result = fail;
  2443. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2444. }
  2445. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2446. /// 00af <index>.W <amount>.W
  2447. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2448. {
  2449. int fd;
  2450. nullpo_retv(sd);
  2451. fd=sd->fd;
  2452. WFIFOHEAD(fd, packet_len(0xaf));
  2453. WFIFOW(fd,0)=0xaf;
  2454. WFIFOW(fd,2)=n+2;
  2455. WFIFOW(fd,4)=amount;
  2456. WFIFOSET(fd,packet_len(0xaf));
  2457. }
  2458. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2459. /// 07fa <delete type>.W <index>.W <amount>.W
  2460. /// delete type:
  2461. /// 0 = Normal
  2462. /// 1 = Item used for a skill
  2463. /// 2 = Refine failed
  2464. /// 3 = Material changed
  2465. /// 4 = Moved to storage
  2466. /// 5 = Moved to cart
  2467. /// 6 = Item sold
  2468. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2469. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2470. {
  2471. #if PACKETVER < 20091117
  2472. clif_dropitem(sd,n,amount);
  2473. #else
  2474. int fd;
  2475. nullpo_retv(sd);
  2476. fd=sd->fd;
  2477. WFIFOHEAD(fd, packet_len(0x7fa));
  2478. WFIFOW(fd,0)=0x7fa;
  2479. WFIFOW(fd,2)=reason;
  2480. WFIFOW(fd,4)=n+2;
  2481. WFIFOW(fd,6)=amount;
  2482. WFIFOSET(fd,packet_len(0x7fa));
  2483. #endif
  2484. }
  2485. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2486. nullpo_retv( p );
  2487. nullpo_retv( it );
  2488. nullpo_retv( id );
  2489. p->index = idx;
  2490. p->ITID = client_nameid( it->nameid );
  2491. p->type = itemtype( it->nameid );
  2492. #if PACKETVER < 20120925
  2493. p->IsIdentified = it->identify ? 1 : 0;
  2494. #endif
  2495. p->location = eqp_pos;
  2496. p->WearState = it->equip;
  2497. #if PACKETVER < 20120925
  2498. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2499. #endif
  2500. p->RefiningLevel = it->refine;
  2501. clif_addcards( &p->slot, it );
  2502. #if PACKETVER >= 20071002
  2503. p->HireExpireDate = it->expire_time;
  2504. #endif
  2505. #if PACKETVER >= 20080102
  2506. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2507. #endif
  2508. #if PACKETVER >= 20100629
  2509. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2510. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2511. #endif
  2512. #if PACKETVER >= 20120925
  2513. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2514. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2515. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2516. p->Flag.SpareBits = 0;
  2517. #endif
  2518. #if PACKETVER >= 20150226
  2519. p->option_count = clif_add_random_options( p->option_data, it );
  2520. #endif
  2521. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2522. p->enchantgrade = it->enchantgrade;
  2523. #endif
  2524. }
  2525. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2526. nullpo_retv(p);
  2527. nullpo_retv(i);
  2528. nullpo_retv(id);
  2529. p->index = idx;
  2530. p->ITID = client_nameid( i->nameid );
  2531. p->type = itemtype( i->nameid );
  2532. #if PACKETVER < 20120925
  2533. p->IsIdentified = i->identify ? 1 : 0;
  2534. #endif
  2535. p->count = i->amount;
  2536. p->WearState = id->equip;
  2537. #if PACKETVER >= 5
  2538. clif_addcards( &p->slot, i );
  2539. #endif
  2540. #if PACKETVER >= 20080102
  2541. p->HireExpireDate = i->expire_time;
  2542. #endif
  2543. #if PACKETVER >= 20120925
  2544. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2545. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2546. p->Flag.SpareBits = 0;
  2547. #endif
  2548. }
  2549. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2550. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2551. nullpo_retv(sd);
  2552. nullpo_retv(name);
  2553. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2554. memset(buf, 0, sizeof(buf));
  2555. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2556. p->packetType = HEADER_ZC_INVENTORY_START;
  2557. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2558. p->invType = type;
  2559. #endif
  2560. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2561. int strLen = (int)safestrnlen(name, 24) + 1;
  2562. if (strLen > 24)
  2563. strLen = 24;
  2564. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2565. p->packetLength = len;
  2566. safestrncpy(p->name, name, strLen);
  2567. #else
  2568. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2569. safestrncpy(p->name, name, NAME_LENGTH);
  2570. #endif
  2571. clif_send( p, len, &sd->bl, SELF );
  2572. #endif
  2573. }
  2574. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2575. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2576. nullpo_retv(sd);
  2577. struct PACKET_ZC_INVENTORY_END p;
  2578. p.packetType = HEADER_ZC_INVENTORY_END;
  2579. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2580. p.invType = type;
  2581. #endif
  2582. p.flag = 0;
  2583. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2584. #endif
  2585. }
  2586. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2587. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2588. void clif_inventorylist( struct map_session_data *sd ){
  2589. nullpo_retv( sd );
  2590. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2591. e_inventory_type type = INVTYPE_INVENTORY;
  2592. clif_inventoryStart( sd, type, "" );
  2593. #endif
  2594. static struct packet_itemlist_normal itemlist_normal;
  2595. static struct packet_itemlist_equip itemlist_equip;
  2596. int equip = 0;
  2597. int normal = 0;
  2598. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2599. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2600. continue;
  2601. }
  2602. // Non-stackable (Equippable)
  2603. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2604. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2605. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2606. itemlist_equip.PacketType = inventorylistequipType;
  2607. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2608. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2609. itemlist_equip.invType = type;
  2610. #endif
  2611. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2612. equip = 0;
  2613. }
  2614. // Stackable (Normal)
  2615. }else{
  2616. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2617. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2618. itemlist_normal.PacketType = inventorylistnormalType;
  2619. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2620. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2621. itemlist_normal.invType = type;
  2622. #endif
  2623. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2624. normal = 0;
  2625. }
  2626. }
  2627. }
  2628. if( normal ){
  2629. itemlist_normal.PacketType = inventorylistnormalType;
  2630. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2631. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2632. itemlist_normal.invType = type;
  2633. #endif
  2634. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2635. }
  2636. if( sd->equip_index[EQI_AMMO] >= 0 )
  2637. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2638. if( equip ) {
  2639. itemlist_equip.PacketType = inventorylistequipType;
  2640. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2641. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2642. itemlist_equip.invType = type;
  2643. #endif
  2644. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2645. }
  2646. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2647. clif_inventoryEnd( sd, type );
  2648. #endif
  2649. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2650. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2651. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2652. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2653. continue;
  2654. if ( sd->inventory.u.items_inventory[i].favorite )
  2655. clif_favorite_item(sd, i);
  2656. }
  2657. #endif
  2658. }
  2659. //Required when items break/get-repaired. Only sends equippable item list.
  2660. void clif_equiplist( struct map_session_data *sd ){
  2661. // TODO: implement again => only send equip part
  2662. clif_inventorylist( sd );
  2663. }
  2664. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2665. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2666. e_inventory_type type = INVTYPE_STORAGE;
  2667. clif_inventoryStart( sd, type, storename );
  2668. #endif
  2669. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2670. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2671. int equip = 0;
  2672. int normal = 0;
  2673. for( int i = 0; i < items_length; i++ ){
  2674. if( items[i].nameid == 0 ){
  2675. continue;
  2676. }
  2677. struct item_data* id = itemdb_search( items[i].nameid );
  2678. // Non-stackable (Equippable)
  2679. if( !itemdb_isstackable2( id ) ){
  2680. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2681. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2682. storage_itemlist_equip.PacketType = storageListEquipType;
  2683. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2684. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2685. storage_itemlist_equip.invType = type;
  2686. #elif PACKETVER >= 20120925
  2687. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2688. #endif
  2689. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2690. equip = 0;
  2691. }
  2692. // Stackable (Normal)
  2693. }else{
  2694. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2695. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2696. storage_itemlist_normal.PacketType = storageListNormalType;
  2697. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2698. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2699. storage_itemlist_normal.invType = type;
  2700. #elif PACKETVER >= 20120925
  2701. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2702. #endif
  2703. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2704. normal = 0;
  2705. }
  2706. }
  2707. }
  2708. if( normal ){
  2709. storage_itemlist_normal.PacketType = storageListNormalType;
  2710. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2711. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2712. storage_itemlist_normal.invType = type;
  2713. #elif PACKETVER >= 20120925
  2714. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2715. #endif
  2716. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2717. }
  2718. if( equip ) {
  2719. storage_itemlist_equip.PacketType = storageListEquipType;
  2720. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2721. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2722. storage_itemlist_equip.invType = type;
  2723. #elif PACKETVER >= 20120925
  2724. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2725. #endif
  2726. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2727. }
  2728. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2729. clif_inventoryEnd( sd, type );
  2730. #endif
  2731. }
  2732. void clif_cartlist( struct map_session_data *sd ){
  2733. nullpo_retv( sd );
  2734. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2735. e_inventory_type type = INVTYPE_CART;
  2736. clif_inventoryStart( sd, type, "" );
  2737. #endif
  2738. static struct packet_itemlist_normal itemlist_normal;
  2739. static struct packet_itemlist_equip itemlist_equip;
  2740. int normal = 0;
  2741. int equip = 0;
  2742. for( int i = 0; i < MAX_CART; i++ ){
  2743. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2744. continue;
  2745. }
  2746. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2747. // Non-stackable (Equippable)
  2748. if( !itemdb_isstackable2(id) ){
  2749. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2750. // Stackable (Normal)
  2751. }else{
  2752. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2753. }
  2754. }
  2755. if( normal ){
  2756. itemlist_normal.PacketType = cartlistnormalType;
  2757. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2758. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2759. itemlist_normal.invType = type;
  2760. #endif
  2761. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2762. }
  2763. if( equip ){
  2764. itemlist_equip.PacketType = cartlistequipType;
  2765. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2766. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2767. itemlist_equip.invType = type;
  2768. #endif
  2769. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2770. }
  2771. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2772. clif_inventoryEnd( sd, type );
  2773. #endif
  2774. }
  2775. /// Removes cart (ZC_CARTOFF).
  2776. /// 012b
  2777. /// Client behaviour:
  2778. /// Closes the cart storage and removes all it's items from memory.
  2779. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2780. void clif_clearcart(int fd)
  2781. {
  2782. WFIFOHEAD(fd, packet_len(0x12b));
  2783. WFIFOW(fd,0) = 0x12b;
  2784. WFIFOSET(fd, packet_len(0x12b));
  2785. }
  2786. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2787. /// 01eb <account id>.L <x>.W <y>.W
  2788. void clif_guild_xy(struct map_session_data *sd)
  2789. {
  2790. unsigned char buf[10];
  2791. nullpo_retv(sd);
  2792. WBUFW(buf,0)=0x1eb;
  2793. WBUFL(buf,2)=sd->status.account_id;
  2794. WBUFW(buf,6)=sd->bl.x;
  2795. WBUFW(buf,8)=sd->bl.y;
  2796. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2797. }
  2798. /*==========================================
  2799. * Sends x/y dot to a single fd. [Skotlex]
  2800. *------------------------------------------*/
  2801. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2802. {
  2803. if( sd->bg_id )
  2804. return;
  2805. WFIFOHEAD(fd,packet_len(0x1eb));
  2806. WFIFOW(fd,0)=0x1eb;
  2807. WFIFOL(fd,2)=sd->status.account_id;
  2808. WFIFOW(fd,6)=sd->bl.x;
  2809. WFIFOW(fd,8)=sd->bl.y;
  2810. WFIFOSET(fd,packet_len(0x1eb));
  2811. }
  2812. // Guild XY locators [Valaris]
  2813. void clif_guild_xy_remove(struct map_session_data *sd)
  2814. {
  2815. unsigned char buf[10];
  2816. nullpo_retv(sd);
  2817. WBUFW(buf,0)=0x1eb;
  2818. WBUFL(buf,2)=sd->status.account_id;
  2819. WBUFW(buf,6)=-1;
  2820. WBUFW(buf,8)=-1;
  2821. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2822. }
  2823. /*==========================================
  2824. *
  2825. *------------------------------------------*/
  2826. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2827. {
  2828. struct map_session_data *sd, *tsd;
  2829. #if PACKETVER < 20100126
  2830. const int cmd = 0x106;
  2831. #else
  2832. const int cmd = 0x80e;
  2833. #endif
  2834. sd = va_arg(ap, struct map_session_data *);
  2835. tsd = (TBL_PC *)bl;
  2836. nullpo_ret(sd);
  2837. nullpo_ret(tsd);
  2838. if( !session_isActive(tsd->fd) || tsd == sd )
  2839. return 0;
  2840. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2841. return 0;
  2842. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2843. WFIFOW(tsd->fd,0) = cmd;
  2844. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2845. #if PACKETVER < 20100126
  2846. if( sd->battle_status.max_hp > INT16_MAX )
  2847. { //To correctly display the %hp bar. [Skotlex]
  2848. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2849. WFIFOW(tsd->fd,8) = 100;
  2850. } else {
  2851. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2852. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2853. }
  2854. #else
  2855. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2856. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2857. #endif
  2858. WFIFOSET(tsd->fd,packet_len(cmd));
  2859. return 0;
  2860. }
  2861. /*==========================================
  2862. * Server tells all players that are allowed to view HP bars
  2863. * and are nearby 'sd' that 'sd' hp bar was updated.
  2864. *------------------------------------------*/
  2865. static int clif_hpmeter(struct map_session_data *sd)
  2866. {
  2867. nullpo_ret(sd);
  2868. 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);
  2869. return 0;
  2870. }
  2871. /// Notifies client of a character parameter change.
  2872. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2873. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2874. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2875. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2876. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2877. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2878. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2879. /// TODO: Extract individual packets.
  2880. /// FIXME: Packet lengths from packet_len(cmd)
  2881. void clif_updatestatus(struct map_session_data *sd,int type)
  2882. {
  2883. int fd,len=8;
  2884. nullpo_retv(sd);
  2885. fd=sd->fd;
  2886. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2887. return;
  2888. WFIFOHEAD(fd, 14);
  2889. WFIFOW(fd,0)=0xb0;
  2890. WFIFOW(fd,2)=type;
  2891. switch(type){
  2892. // 00b0
  2893. case SP_WEIGHT:
  2894. pc_updateweightstatus(sd);
  2895. WFIFOHEAD(fd,14);
  2896. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2897. WFIFOW(fd,2)=type;
  2898. WFIFOL(fd,4)=sd->weight;
  2899. break;
  2900. case SP_MAXWEIGHT:
  2901. WFIFOL(fd,4)=sd->max_weight;
  2902. break;
  2903. case SP_SPEED:
  2904. WFIFOL(fd,4)=sd->battle_status.speed;
  2905. break;
  2906. case SP_BASELEVEL:
  2907. WFIFOL(fd,4)=sd->status.base_level;
  2908. break;
  2909. case SP_JOBLEVEL:
  2910. WFIFOL(fd,4)=sd->status.job_level;
  2911. break;
  2912. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2913. WFIFOL(fd,4)=sd->status.karma;
  2914. break;
  2915. case SP_MANNER:
  2916. WFIFOL(fd,4)=sd->status.manner;
  2917. break;
  2918. case SP_STATUSPOINT:
  2919. WFIFOL(fd,4)=sd->status.status_point;
  2920. break;
  2921. case SP_SKILLPOINT:
  2922. WFIFOL(fd,4)=sd->status.skill_point;
  2923. break;
  2924. case SP_HIT:
  2925. WFIFOL(fd,4)=sd->battle_status.hit;
  2926. break;
  2927. case SP_FLEE1:
  2928. WFIFOL(fd,4)=sd->battle_status.flee;
  2929. break;
  2930. case SP_FLEE2:
  2931. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2932. break;
  2933. case SP_MAXHP:
  2934. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2935. break;
  2936. case SP_MAXSP:
  2937. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2938. break;
  2939. case SP_HP:
  2940. // On officials the HP never go below 1, even if you die [Lemongrass]
  2941. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2942. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2943. break;
  2944. case SP_SP:
  2945. WFIFOL(fd,4)=sd->battle_status.sp;
  2946. break;
  2947. case SP_ASPD:
  2948. WFIFOL(fd,4)=sd->battle_status.amotion;
  2949. break;
  2950. case SP_ATK1:
  2951. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2952. break;
  2953. case SP_DEF1:
  2954. WFIFOL(fd,4)=pc_leftside_def(sd);
  2955. break;
  2956. case SP_MDEF1:
  2957. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2958. break;
  2959. case SP_ATK2:
  2960. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2961. break;
  2962. case SP_DEF2:
  2963. WFIFOL(fd,4)=pc_rightside_def(sd);
  2964. break;
  2965. case SP_MDEF2: {
  2966. //negative check (in case you have something like Berserk active)
  2967. int mdef2 = pc_rightside_mdef(sd);
  2968. WFIFOL(fd,4)=
  2969. #ifndef RENEWAL
  2970. ( mdef2 < 0 ) ? 0 :
  2971. #endif
  2972. mdef2;
  2973. }
  2974. break;
  2975. case SP_CRITICAL:
  2976. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2977. break;
  2978. case SP_MATK1:
  2979. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2980. break;
  2981. case SP_MATK2:
  2982. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2983. break;
  2984. case SP_ZENY:
  2985. WFIFOW(fd,0)=0xb1;
  2986. WFIFOL(fd,4)=sd->status.zeny;
  2987. break;
  2988. #if PACKETVER >= 20170830
  2989. case SP_BASEEXP:
  2990. WFIFOW(fd,0)=0xacb;
  2991. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2992. len = packet_len(0xacb);
  2993. break;
  2994. case SP_JOBEXP:
  2995. WFIFOW(fd,0)=0xacb;
  2996. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2997. len = packet_len(0xacb);
  2998. break;
  2999. case SP_NEXTBASEEXP:
  3000. WFIFOW(fd,0)=0xacb;
  3001. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  3002. len = packet_len(0xacb);
  3003. break;
  3004. case SP_NEXTJOBEXP:
  3005. WFIFOW(fd,0)=0xacb;
  3006. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3007. len = packet_len(0xacb);
  3008. break;
  3009. #else
  3010. case SP_BASEEXP:
  3011. WFIFOW(fd,0)=0xb1;
  3012. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3013. break;
  3014. case SP_JOBEXP:
  3015. WFIFOW(fd,0)=0xb1;
  3016. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3017. break;
  3018. case SP_NEXTBASEEXP:
  3019. WFIFOW(fd,0)=0xb1;
  3020. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3021. break;
  3022. case SP_NEXTJOBEXP:
  3023. WFIFOW(fd,0)=0xb1;
  3024. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3025. break;
  3026. #endif
  3027. /**
  3028. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3029. **/
  3030. case SP_USTR:
  3031. case SP_UAGI:
  3032. case SP_UVIT:
  3033. case SP_UINT:
  3034. case SP_UDEX:
  3035. case SP_ULUK:
  3036. WFIFOW(fd,0)=0xbe;
  3037. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3038. len=5;
  3039. break;
  3040. /**
  3041. * Tells the client how far it is allowed to attack (weapon range)
  3042. **/
  3043. case SP_ATTACKRANGE:
  3044. WFIFOW(fd,0)=0x13a;
  3045. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3046. len=4;
  3047. break;
  3048. case SP_STR:
  3049. WFIFOW(fd,0)=0x141;
  3050. WFIFOL(fd,2)=type;
  3051. WFIFOL(fd,6)=sd->status.str;
  3052. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3053. len=14;
  3054. break;
  3055. case SP_AGI:
  3056. WFIFOW(fd,0)=0x141;
  3057. WFIFOL(fd,2)=type;
  3058. WFIFOL(fd,6)=sd->status.agi;
  3059. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3060. len=14;
  3061. break;
  3062. case SP_VIT:
  3063. WFIFOW(fd,0)=0x141;
  3064. WFIFOL(fd,2)=type;
  3065. WFIFOL(fd,6)=sd->status.vit;
  3066. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3067. len=14;
  3068. break;
  3069. case SP_INT:
  3070. WFIFOW(fd,0)=0x141;
  3071. WFIFOL(fd,2)=type;
  3072. WFIFOL(fd,6)=sd->status.int_;
  3073. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3074. len=14;
  3075. break;
  3076. case SP_DEX:
  3077. WFIFOW(fd,0)=0x141;
  3078. WFIFOL(fd,2)=type;
  3079. WFIFOL(fd,6)=sd->status.dex;
  3080. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3081. len=14;
  3082. break;
  3083. case SP_LUK:
  3084. WFIFOW(fd,0)=0x141;
  3085. WFIFOL(fd,2)=type;
  3086. WFIFOL(fd,6)=sd->status.luk;
  3087. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3088. len=14;
  3089. break;
  3090. case SP_CARTINFO:
  3091. WFIFOW(fd,0)=0x121;
  3092. WFIFOW(fd,2)=sd->cart_num;
  3093. WFIFOW(fd,4)=MAX_CART;
  3094. WFIFOL(fd,6)=sd->cart_weight;
  3095. WFIFOL(fd,10)=sd->cart_weight_max;
  3096. len=14;
  3097. break;
  3098. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3099. case SP_AP:
  3100. WFIFOL(fd, 4) = sd->battle_status.ap;
  3101. break;
  3102. case SP_TRAITPOINT:
  3103. WFIFOL(fd, 4) = sd->status.trait_point;
  3104. break;
  3105. case SP_MAXAP:
  3106. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3107. break;
  3108. case SP_POW:
  3109. WFIFOW(fd, 0) = 0x141;
  3110. WFIFOL(fd, 2) = type;
  3111. WFIFOL(fd, 6) = sd->status.pow;
  3112. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3113. len = 14;
  3114. break;
  3115. case SP_STA:
  3116. WFIFOW(fd, 0) = 0x141;
  3117. WFIFOL(fd, 2) = type;
  3118. WFIFOL(fd, 6) = sd->status.sta;
  3119. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3120. len = 14;
  3121. break;
  3122. case SP_WIS:
  3123. WFIFOW(fd, 0) = 0x141;
  3124. WFIFOL(fd, 2) = type;
  3125. WFIFOL(fd, 6) = sd->status.wis;
  3126. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3127. len = 14;
  3128. break;
  3129. case SP_SPL:
  3130. WFIFOW(fd, 0) = 0x141;
  3131. WFIFOL(fd, 2) = type;
  3132. WFIFOL(fd, 6) = sd->status.spl;
  3133. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3134. len = 14;
  3135. break;
  3136. case SP_CON:
  3137. WFIFOW(fd, 0) = 0x141;
  3138. WFIFOL(fd, 2) = type;
  3139. WFIFOL(fd, 6) = sd->status.con;
  3140. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3141. len = 14;
  3142. break;
  3143. case SP_CRT:
  3144. WFIFOW(fd, 0) = 0x141;
  3145. WFIFOL(fd, 2) = type;
  3146. WFIFOL(fd, 6) = sd->status.crt;
  3147. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3148. len = 14;
  3149. break;
  3150. case SP_UPOW:
  3151. case SP_USTA:
  3152. case SP_UWIS:
  3153. case SP_USPL:
  3154. case SP_UCON:
  3155. case SP_UCRT:
  3156. WFIFOW(fd, 0) = 0xbe;
  3157. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3158. len = 5;
  3159. break;
  3160. case SP_PATK:
  3161. WFIFOL(fd, 4) = sd->battle_status.patk;
  3162. break;
  3163. case SP_SMATK:
  3164. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3165. break;
  3166. case SP_RES:
  3167. WFIFOL(fd, 4) = sd->battle_status.res;
  3168. break;
  3169. case SP_MRES:
  3170. WFIFOL(fd, 4) = sd->battle_status.mres;
  3171. break;
  3172. case SP_HPLUS:
  3173. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3174. break;
  3175. case SP_CRATE:
  3176. WFIFOL(fd, 4) = sd->battle_status.crate;
  3177. break;
  3178. #else
  3179. case SP_AP:
  3180. case SP_TRAITPOINT:
  3181. case SP_MAXAP:
  3182. case SP_POW:
  3183. case SP_STA:
  3184. case SP_WIS:
  3185. case SP_SPL:
  3186. case SP_CON:
  3187. case SP_CRT:
  3188. case SP_UPOW:
  3189. case SP_USTA:
  3190. case SP_UWIS:
  3191. case SP_USPL:
  3192. case SP_UCON:
  3193. case SP_UCRT:
  3194. case SP_PATK:
  3195. case SP_SMATK:
  3196. case SP_RES:
  3197. case SP_MRES:
  3198. case SP_HPLUS:
  3199. case SP_CRATE:
  3200. // 4th job status are not supported by older clients
  3201. return;
  3202. #endif
  3203. default:
  3204. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3205. return;
  3206. }
  3207. WFIFOSET(fd,len);
  3208. // Additional update packets that should be sent right after
  3209. switch( type ){
  3210. case SP_BASELEVEL:
  3211. if( sd->status.party_id ){
  3212. struct party_data* p;
  3213. int i;
  3214. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3215. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3216. if( i < MAX_PARTY ){
  3217. p->party.member[i].lv = sd->status.base_level;
  3218. clif_party_job_and_level(sd);
  3219. }
  3220. }
  3221. }
  3222. break;
  3223. case SP_HP:
  3224. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3225. clif_hpmeter(sd);
  3226. }
  3227. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3228. clif_party_hp(sd);
  3229. }
  3230. if( sd->bg_id ){
  3231. clif_bg_hp(sd);
  3232. }
  3233. break;
  3234. }
  3235. }
  3236. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3237. /// 01ab <account id>.L <var id>.W <value>.L
  3238. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3239. {
  3240. unsigned char buf[12];
  3241. nullpo_retv(sd);
  3242. WBUFW(buf,0)=0x1ab;
  3243. WBUFL(buf,2)=sd->bl.id;
  3244. WBUFW(buf,6)=type;
  3245. switch(type)
  3246. {
  3247. case SP_MANNER:
  3248. WBUFL(buf,8)=val;
  3249. break;
  3250. default:
  3251. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3252. return;
  3253. }
  3254. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3255. }
  3256. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3257. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3258. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3259. struct PACKET_ZC_SPRITE_CHANGE p;
  3260. p.packetType = sendLookType;
  3261. p.AID = id;
  3262. p.type = type;
  3263. p.val = val;
  3264. #if PACKETVER >= 4
  3265. p.val2 = val2;
  3266. #endif
  3267. clif_send( &p, sizeof( p ), bl, target );
  3268. }
  3269. /// Updates sprite/style properties of an object.
  3270. void clif_changelook(struct block_list *bl, int type, int val) {
  3271. struct map_session_data* sd;
  3272. struct status_change* sc;
  3273. struct view_data* vd;
  3274. enum send_target target = AREA;
  3275. int val2 = 0;
  3276. nullpo_retv(bl);
  3277. sd = BL_CAST(BL_PC, bl);
  3278. sc = status_get_sc(bl);
  3279. vd = status_get_viewdata(bl);
  3280. if( vd ) //temp hack to let Warp Portal change appearance
  3281. switch(type) {
  3282. case LOOK_WEAPON:
  3283. if (sd) {
  3284. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3285. val = vd->weapon;
  3286. }
  3287. else
  3288. vd->weapon = val;
  3289. break;
  3290. case LOOK_SHIELD:
  3291. if (sd) {
  3292. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3293. val = vd->shield;
  3294. }
  3295. else
  3296. vd->shield = val;
  3297. break;
  3298. case LOOK_BASE:
  3299. if (!sd)
  3300. break;
  3301. if ( val == JT_INVISIBLE )
  3302. return;
  3303. if (sd->sc.option&OPTION_COSTUME)
  3304. vd->weapon = vd->shield = 0;
  3305. if (!vd->cloth_color)
  3306. break;
  3307. if (sd) {
  3308. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3309. vd->cloth_color = 0;
  3310. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3311. vd->cloth_color = 0;
  3312. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3313. vd->cloth_color = 0;
  3314. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3315. vd->cloth_color = 0;
  3316. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3317. vd->cloth_color = 0;
  3318. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3319. vd->body_style = 0;
  3320. }
  3321. break;
  3322. case LOOK_HAIR:
  3323. vd->hair_style = val;
  3324. break;
  3325. case LOOK_HEAD_BOTTOM:
  3326. vd->head_bottom = val;
  3327. break;
  3328. case LOOK_HEAD_TOP:
  3329. vd->head_top = val;
  3330. break;
  3331. case LOOK_HEAD_MID:
  3332. vd->head_mid = val;
  3333. break;
  3334. case LOOK_HAIR_COLOR:
  3335. vd->hair_color = val;
  3336. break;
  3337. case LOOK_CLOTHES_COLOR:
  3338. if (val && sd) {
  3339. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3340. val = 0;
  3341. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3342. val = 0;
  3343. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3344. val = 0;
  3345. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3346. val = 0;
  3347. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3348. val = 0;
  3349. }
  3350. vd->cloth_color = val;
  3351. break;
  3352. case LOOK_SHOES:
  3353. #if PACKETVER > 3
  3354. if (sd) {
  3355. int n;
  3356. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3357. if(sd->inventory_data[n]->view_id > 0)
  3358. val = sd->inventory_data[n]->view_id;
  3359. else
  3360. val = sd->inventory.u.items_inventory[n].nameid;
  3361. } else
  3362. val = 0;
  3363. }
  3364. #endif
  3365. //Shoes? No packet uses this....
  3366. break;
  3367. case LOOK_BODY:
  3368. // unknown purpose
  3369. break;
  3370. case LOOK_ROBE:
  3371. #if PACKETVER < 20110111
  3372. return;
  3373. #else
  3374. vd->robe = val;
  3375. #endif
  3376. break;
  3377. case LOOK_BODY2:
  3378. #if PACKETVER < 20150513
  3379. return;
  3380. #else
  3381. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3382. val = 0;
  3383. vd->body_style = val;
  3384. #endif
  3385. break;
  3386. }
  3387. // prevent leaking the presence of GM-hidden objects
  3388. if( sc && sc->option&OPTION_INVISIBLE )
  3389. target = SELF;
  3390. #if PACKETVER < 4
  3391. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3392. #else
  3393. if (bl->type != BL_NPC) {
  3394. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3395. type = LOOK_WEAPON;
  3396. val = (vd ? vd->weapon : 0);
  3397. val2 = (vd ? vd->shield : 0);
  3398. }
  3399. if (disguised(bl)) {
  3400. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3401. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3402. } else
  3403. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3404. } else
  3405. unit_refresh(bl);
  3406. #endif
  3407. }
  3408. //Sends a change-base-look packet required for traps as they are triggered.
  3409. void clif_changetraplook(struct block_list *bl,int val) {
  3410. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3411. }
  3412. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3413. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3414. clif_sprite_change(bl, id, type, val, 0, target);
  3415. }
  3416. /// Character status (ZC_STATUS).
  3417. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3418. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3419. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3420. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3421. void clif_initialstatus(struct map_session_data *sd) {
  3422. int fd, mdef2;
  3423. unsigned char *buf;
  3424. nullpo_retv(sd);
  3425. fd=sd->fd;
  3426. WFIFOHEAD(fd, packet_len(0xbd));
  3427. buf = WFIFOP(fd,0);
  3428. WBUFW(buf,0) = 0xbd;
  3429. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3430. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3431. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3432. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3433. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3434. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3435. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3436. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3437. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3438. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3439. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3440. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3441. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3442. WBUFW(buf,16) = pc_leftside_atk(sd);
  3443. WBUFW(buf,18) = pc_rightside_atk(sd);
  3444. WBUFW(buf,20) = pc_rightside_matk(sd);
  3445. WBUFW(buf,22) = pc_leftside_matk(sd);
  3446. WBUFW(buf,24) = pc_leftside_def(sd);
  3447. WBUFW(buf,26) = pc_rightside_def(sd);
  3448. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3449. mdef2 = pc_rightside_mdef(sd);
  3450. WBUFW(buf,30) =
  3451. #ifndef RENEWAL
  3452. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3453. #endif
  3454. mdef2;
  3455. WBUFW(buf,32) = sd->battle_status.hit;
  3456. WBUFW(buf,34) = sd->battle_status.flee;
  3457. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3458. WBUFW(buf,38) = sd->battle_status.cri/10;
  3459. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3460. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3461. WFIFOSET(fd, packet_len(0xbd));
  3462. clif_updatestatus(sd, SP_STR);
  3463. clif_updatestatus(sd, SP_AGI);
  3464. clif_updatestatus(sd, SP_VIT);
  3465. clif_updatestatus(sd, SP_INT);
  3466. clif_updatestatus(sd, SP_DEX);
  3467. clif_updatestatus(sd, SP_LUK);
  3468. clif_updatestatus(sd, SP_ATTACKRANGE);
  3469. clif_updatestatus(sd, SP_ASPD);
  3470. #ifdef RENEWAL
  3471. clif_updatestatus(sd, SP_POW);
  3472. clif_updatestatus(sd, SP_STA);
  3473. clif_updatestatus(sd, SP_WIS);
  3474. clif_updatestatus(sd, SP_SPL);
  3475. clif_updatestatus(sd, SP_CON);
  3476. clif_updatestatus(sd, SP_CRT);
  3477. clif_updatestatus(sd, SP_PATK);
  3478. clif_updatestatus(sd, SP_SMATK);
  3479. clif_updatestatus(sd, SP_RES);
  3480. clif_updatestatus(sd, SP_MRES);
  3481. clif_updatestatus(sd, SP_HPLUS);
  3482. clif_updatestatus(sd, SP_CRATE);
  3483. clif_updatestatus(sd, SP_TRAITPOINT);
  3484. clif_updatestatus(sd, SP_AP);
  3485. clif_updatestatus(sd, SP_MAXAP);
  3486. clif_updatestatus(sd, SP_UPOW);
  3487. clif_updatestatus(sd, SP_USTA);
  3488. clif_updatestatus(sd, SP_UWIS);
  3489. clif_updatestatus(sd, SP_USPL);
  3490. clif_updatestatus(sd, SP_UCON);
  3491. clif_updatestatus(sd, SP_UCRT);
  3492. #endif
  3493. }
  3494. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3495. /// 013c <index>.W
  3496. void clif_arrowequip(struct map_session_data *sd,int val) {
  3497. int fd;
  3498. nullpo_retv(sd);
  3499. #if PACKETVER >= 20121128
  3500. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3501. #endif
  3502. fd=sd->fd;
  3503. WFIFOHEAD(fd, packet_len(0x013c));
  3504. WFIFOW(fd,0) = 0x013c;
  3505. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3506. WFIFOSET(fd, packet_len(0x013c));
  3507. }
  3508. /// Ammunition action message (ZC_ACTION_FAILURE).
  3509. /// 013b <type>.W
  3510. /// type:
  3511. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3512. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3513. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3514. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3515. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3516. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3517. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3518. int fd;
  3519. nullpo_retv(sd);
  3520. fd=sd->fd;
  3521. WFIFOHEAD(fd, packet_len(0x013b));
  3522. WFIFOW(fd,0) = 0x013b;
  3523. WFIFOW(fd,2) = type;
  3524. WFIFOSET(fd, packet_len(0x013b));
  3525. }
  3526. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3527. /// 01ad <packet len>.W { <name id>.W }*
  3528. void clif_arrow_create_list( struct map_session_data *sd ){
  3529. nullpo_retv( sd );
  3530. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3531. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3532. int count = 0;
  3533. for (const auto &it : skill_arrow_db) {
  3534. t_itemid nameid = it.second->nameid;
  3535. if( !item_db.exists( nameid ) ){
  3536. continue;
  3537. }
  3538. int index = pc_search_inventory( sd, nameid );
  3539. if( index < 0 ){
  3540. continue;
  3541. }
  3542. if( sd->inventory.u.items_inventory[index].equip ){
  3543. continue;
  3544. }
  3545. if( !sd->inventory.u.items_inventory[index].identify ){
  3546. continue;
  3547. }
  3548. p->items[count].itemId = client_nameid( nameid );
  3549. count++;
  3550. }
  3551. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3552. clif_send( p, p->packetLength, &sd->bl, SELF );
  3553. if( count > 0 ){
  3554. sd->menuskill_id = AC_MAKINGARROW;
  3555. sd->menuskill_val = count;
  3556. }
  3557. }
  3558. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3559. /// 00bc <status id>.W <result>.B <value>.B
  3560. /// status id:
  3561. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3562. /// result:
  3563. /// 0 = failure
  3564. /// 1 = success
  3565. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3566. int fd;
  3567. nullpo_retv(sd);
  3568. fd=sd->fd;
  3569. WFIFOHEAD(fd, packet_len(0xbc));
  3570. WFIFOW(fd,0) = 0xbc;
  3571. WFIFOW(fd,2) = type;
  3572. WFIFOB(fd,4) = ok;
  3573. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3574. WFIFOSET(fd, packet_len(0xbc));
  3575. }
  3576. /// Notifies the client about the result of a request to equip an item.
  3577. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3578. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3579. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3580. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3581. /// @ok: //inversed forv2 v5
  3582. /// 0 = failure
  3583. /// 1 = success
  3584. /// 2 = failure due to low level
  3585. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3586. {
  3587. int fd = 0, cmd = 0, look = 0;
  3588. struct s_packet_db *info = NULL;
  3589. nullpo_retv(sd);
  3590. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3591. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3592. return;
  3593. fd = sd->fd;
  3594. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3595. look = sd->inventory_data[n]->look;
  3596. WFIFOHEAD(fd, info->len);
  3597. WFIFOW(fd, 0) = cmd;
  3598. WFIFOW(fd, info->pos[0]) = n+2;
  3599. switch (cmd) {
  3600. case 0xaa:
  3601. WFIFOW(fd, info->pos[1]) = pos;
  3602. #if PACKETVER < 20100629
  3603. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3604. #else
  3605. WFIFOL(fd, info->pos[2]) = look;
  3606. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3607. #endif
  3608. break;
  3609. case 0x8d0:
  3610. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3611. flag = 1;
  3612. case 0x999:
  3613. if (cmd == 0x999)
  3614. WFIFOL(fd, info->pos[1]) = pos;
  3615. else
  3616. WFIFOW(fd, info->pos[1]) = pos;
  3617. WFIFOL(fd, info->pos[2]) = look;
  3618. WFIFOW(fd, info->pos[3]) = flag;
  3619. break;
  3620. }
  3621. WFIFOSET(fd, info->len);
  3622. }
  3623. /// Notifies the client about the result of a request to take off an item.
  3624. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3625. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3626. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3627. /// @ok : //inversed for v2 v5
  3628. /// 0 = failure
  3629. /// 1 = success
  3630. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3631. {
  3632. int fd, header, offs = 0;
  3633. #if PACKETVER >= 20130000
  3634. header = 0x99a;
  3635. ok = ok ? 0 : 1;
  3636. #elif PACKETVER >= 20110824
  3637. header = 0x8d1;
  3638. ok = ok ? 0 : 1;
  3639. #else
  3640. header = 0xac;
  3641. #endif
  3642. nullpo_retv(sd);
  3643. fd=sd->fd;
  3644. WFIFOHEAD(fd, packet_len(header));
  3645. WFIFOW(fd,offs+0) = header;
  3646. WFIFOW(fd,offs+2) = n+2;
  3647. #if PACKETVER >= 20130000
  3648. WFIFOL(fd,offs+4) = pos;
  3649. offs += 2;
  3650. #else
  3651. WFIFOW(fd,offs+4) = pos;
  3652. #endif
  3653. WFIFOB(fd,offs+6) = ok;
  3654. WFIFOSET(fd, packet_len(header));
  3655. }
  3656. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3657. /// 019b <id>.L <effect id>.L
  3658. /// effect id:
  3659. /// 0 = base level up
  3660. /// 1 = job level up
  3661. /// 2 = refine failure
  3662. /// 3 = refine success
  3663. /// 4 = game over
  3664. /// 5 = pharmacy success
  3665. /// 6 = pharmacy failure
  3666. /// 7 = base level up (super novice)
  3667. /// 8 = job level up (super novice)
  3668. /// 9 = base level up (taekwon)
  3669. void clif_misceffect(struct block_list* bl,int type)
  3670. {
  3671. unsigned char buf[32];
  3672. nullpo_retv(bl);
  3673. WBUFW(buf,0) = 0x19b;
  3674. WBUFL(buf,2) = bl->id;
  3675. WBUFL(buf,6) = type;
  3676. clif_send(buf,packet_len(0x19b),bl,AREA);
  3677. }
  3678. /// Notifies clients in the area of a state change.
  3679. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3680. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3681. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3682. nullpo_retv( bl );
  3683. struct status_change* sc = status_get_sc( bl );
  3684. //How can an option change if there's no sc?
  3685. if( sc == nullptr ){
  3686. return;
  3687. }
  3688. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3689. struct PACKET_ZC_STATE_CHANGE p;
  3690. p.packetType = HEADER_ZC_STATE_CHANGE;
  3691. p.AID = bl->id;
  3692. p.bodyState = sc->opt1;
  3693. p.healthState = sc->opt2;
  3694. p.effectState = sc->option;
  3695. p.isPKModeON = sd ? sd->status.karma : false;
  3696. if( target == nullptr ){
  3697. if( disguised( bl ) ){
  3698. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3699. p.AID = disguised_bl_id( p.AID );
  3700. clif_send( &p, sizeof( p ), bl, SELF );
  3701. p.AID = disguised_bl_id( p.AID );
  3702. p.effectState = OPTION_INVISIBLE;
  3703. clif_send( &p, sizeof( p ), bl, SELF );
  3704. }else{
  3705. clif_send( &p, sizeof( p ), bl, AREA );
  3706. }
  3707. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3708. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3709. if( sc->data[SC_PROVOKE] ){
  3710. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3711. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3712. }
  3713. }else{
  3714. if( disguised( bl ) ){
  3715. p.AID = disguised_bl_id( p.AID );
  3716. clif_send( &p, sizeof( p ), target, SELF );
  3717. p.AID = disguised_bl_id( p.AID );
  3718. p.effectState = OPTION_INVISIBLE;
  3719. clif_send( &p, sizeof( p ), target, SELF );
  3720. }else{
  3721. clif_send( &p, sizeof( p ), target, SELF );
  3722. }
  3723. }
  3724. }
  3725. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3726. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3727. void clif_changeoption2(struct block_list* bl)
  3728. {
  3729. unsigned char buf[20];
  3730. struct status_change *sc;
  3731. sc = status_get_sc(bl);
  3732. if (!sc) return; //How can an option change if there's no sc?
  3733. WBUFW(buf,0) = 0x28a;
  3734. WBUFL(buf,2) = bl->id;
  3735. WBUFL(buf,6) = sc->option;
  3736. WBUFL(buf,10) = clif_setlevel(bl);
  3737. WBUFL(buf,14) = sc->opt3;
  3738. if(disguised(bl)) {
  3739. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3740. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3741. clif_send(buf,packet_len(0x28a),bl,SELF);
  3742. WBUFL(buf,2) = bl->id;
  3743. WBUFL(buf,6) = OPTION_INVISIBLE;
  3744. clif_send(buf,packet_len(0x28a),bl,SELF);
  3745. } else
  3746. clif_send(buf,packet_len(0x28a),bl,AREA);
  3747. }
  3748. /// Notifies the client about the result of an item use request.
  3749. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3750. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3751. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3752. nullpo_retv( sd );
  3753. int fd = sd->fd;
  3754. if( !session_isActive( fd ) ){
  3755. return;
  3756. }
  3757. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3758. return;
  3759. }
  3760. struct PACKET_ZC_USE_ITEM_ACK p;
  3761. p.packetType = useItemAckType;
  3762. p.index = index + 2;
  3763. #if PACKETVER > 3
  3764. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3765. p.AID = sd->bl.id;
  3766. #endif
  3767. p.amount = amount;
  3768. p.result = ok;
  3769. if( !ok ){
  3770. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3771. }else{
  3772. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3773. }
  3774. }
  3775. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3776. /// 00d6 <flag>.B
  3777. /// flag:
  3778. /// 0 = Room has been successfully created (opens chat room)
  3779. /// 1 = Room limit exceeded
  3780. /// 2 = Same room already exists
  3781. void clif_createchat(struct map_session_data* sd, int flag)
  3782. {
  3783. int fd;
  3784. nullpo_retv(sd);
  3785. fd = sd->fd;
  3786. WFIFOHEAD(fd,packet_len(0xd6));
  3787. WFIFOW(fd,0) = 0xd6;
  3788. WFIFOB(fd,2) = flag;
  3789. WFIFOSET(fd,packet_len(0xd6));
  3790. }
  3791. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3792. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3793. /// type:
  3794. /// 0 = private (password protected)
  3795. /// 1 = public
  3796. /// 2 = arena (npc waiting room)
  3797. /// 3 = PK zone (non-clickable)
  3798. void clif_dispchat(struct chat_data* cd, int fd)
  3799. {
  3800. unsigned char buf[128];
  3801. uint8 type;
  3802. if( cd == NULL || cd->owner == NULL )
  3803. return;
  3804. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3805. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3806. : 1;
  3807. WBUFW(buf, 0) = 0xd7;
  3808. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3809. WBUFL(buf, 4) = cd->owner->id;
  3810. WBUFL(buf, 8) = cd->bl.id;
  3811. WBUFW(buf,12) = cd->limit;
  3812. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3813. WBUFB(buf,16) = type;
  3814. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3815. if( session_isActive(fd) ) {
  3816. WFIFOHEAD(fd,WBUFW(buf,2));
  3817. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3818. WFIFOSET(fd,WBUFW(buf,2));
  3819. } else {
  3820. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3821. }
  3822. }
  3823. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3824. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3825. /// type:
  3826. /// 0 = private (password protected)
  3827. /// 1 = public
  3828. /// 2 = arena (npc waiting room)
  3829. /// 3 = PK zone (non-clickable)
  3830. void clif_changechatstatus(struct chat_data* cd)
  3831. {
  3832. unsigned char buf[128];
  3833. uint8 type;
  3834. if( cd == NULL || cd->usersd[0] == NULL )
  3835. return;
  3836. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3837. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3838. : 1;
  3839. WBUFW(buf, 0) = 0xdf;
  3840. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3841. WBUFL(buf, 4) = cd->owner->id;
  3842. WBUFL(buf, 8) = cd->bl.id;
  3843. WBUFW(buf,12) = cd->limit;
  3844. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3845. WBUFB(buf,16) = type;
  3846. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3847. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3848. }
  3849. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3850. /// 00d8 <chat id>.L
  3851. void clif_clearchat(struct chat_data *cd,int fd)
  3852. {
  3853. unsigned char buf[32];
  3854. nullpo_retv(cd);
  3855. WBUFW(buf,0) = 0xd8;
  3856. WBUFL(buf,2) = cd->bl.id;
  3857. if( session_isActive(fd) ) {
  3858. WFIFOHEAD(fd,packet_len(0xd8));
  3859. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3860. WFIFOSET(fd,packet_len(0xd8));
  3861. } else {
  3862. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3863. }
  3864. }
  3865. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3866. /// 00da <result>.B
  3867. /// result:
  3868. /// 0 = room full
  3869. /// 1 = wrong password
  3870. /// 2 = kicked
  3871. /// 3 = success (no message)
  3872. /// 4 = no enough zeny
  3873. /// 5 = too low level
  3874. /// 6 = too high level
  3875. /// 7 = unsuitable job class
  3876. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3877. {
  3878. int fd;
  3879. nullpo_retv(sd);
  3880. fd = sd->fd;
  3881. WFIFOHEAD(fd,packet_len(0xda));
  3882. WFIFOW(fd,0) = 0xda;
  3883. WFIFOB(fd,2) = flag;
  3884. WFIFOSET(fd,packet_len(0xda));
  3885. }
  3886. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3887. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3888. /// role:
  3889. /// 0 = owner (menu)
  3890. /// 1 = normal
  3891. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3892. {
  3893. int fd;
  3894. int i,t;
  3895. nullpo_retv(sd);
  3896. nullpo_retv(cd);
  3897. fd = sd->fd;
  3898. if (!session_isActive(fd))
  3899. return;
  3900. t = (int)(cd->owner->type == BL_NPC);
  3901. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3902. WFIFOW(fd, 0) = 0xdb;
  3903. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3904. WFIFOL(fd, 4) = cd->bl.id;
  3905. if(cd->owner->type == BL_NPC){
  3906. WFIFOL(fd, 30) = 1;
  3907. WFIFOL(fd, 8) = 0;
  3908. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3909. for (i = 0; i < cd->users; i++) {
  3910. WFIFOL(fd, 8+(i+1)*28) = 1;
  3911. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3912. }
  3913. }else{
  3914. for (i = 0; i < cd->users; i++) {
  3915. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3916. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3917. }
  3918. }
  3919. WFIFOSET(fd, WFIFOW(fd, 2));
  3920. }
  3921. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3922. /// 00dc <users>.W <name>.24B
  3923. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3924. {
  3925. unsigned char buf[29];
  3926. nullpo_retv(sd);
  3927. nullpo_retv(cd);
  3928. WBUFW(buf, 0) = 0xdc;
  3929. WBUFW(buf, 2) = cd->users;
  3930. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3931. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3932. }
  3933. /// Announce the new owner (ZC_ROLE_CHANGE).
  3934. /// 00e1 <role>.L <nick>.24B
  3935. /// role:
  3936. /// 0 = owner (menu)
  3937. /// 1 = normal
  3938. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3939. {
  3940. unsigned char buf[64];
  3941. nullpo_retv(sd);
  3942. nullpo_retv(cd);
  3943. WBUFW(buf, 0) = 0xe1;
  3944. WBUFL(buf, 2) = 1;
  3945. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3946. WBUFW(buf,30) = 0xe1;
  3947. WBUFL(buf,32) = 0;
  3948. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3949. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3950. }
  3951. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3952. /// 00dd <users>.W <nick>.24B <flag>.B
  3953. /// flag:
  3954. /// 0 = left
  3955. /// 1 = kicked
  3956. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3957. {
  3958. unsigned char buf[32];
  3959. nullpo_retv(sd);
  3960. nullpo_retv(cd);
  3961. WBUFW(buf, 0) = 0xdd;
  3962. WBUFW(buf, 2) = cd->users-1;
  3963. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3964. WBUFB(buf,28) = flag;
  3965. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3966. }
  3967. /// Opens a trade request window from char 'name'.
  3968. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3969. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3970. void clif_traderequest(struct map_session_data* sd, const char* name)
  3971. {
  3972. int fd = sd->fd;
  3973. #if PACKETVER < 6
  3974. WFIFOHEAD(fd,packet_len(0xe5));
  3975. WFIFOW(fd,0) = 0xe5;
  3976. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3977. WFIFOSET(fd,packet_len(0xe5));
  3978. #else
  3979. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3980. if( !tsd ) return;
  3981. WFIFOHEAD(fd,packet_len(0x1f4));
  3982. WFIFOW(fd,0) = 0x1f4;
  3983. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3984. WFIFOL(fd,26) = tsd->status.char_id;
  3985. WFIFOW(fd,30) = tsd->status.base_level;
  3986. WFIFOSET(fd,packet_len(0x1f4));
  3987. #endif
  3988. }
  3989. /// Reply to a trade-request.
  3990. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3991. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3992. /// result:
  3993. /// 0 = Char is too far
  3994. /// 1 = Character does not exist
  3995. /// 2 = Trade failed
  3996. /// 3 = Accept
  3997. /// 4 = Cancel
  3998. /// 5 = Busy
  3999. void clif_tradestart(struct map_session_data* sd, uint8 type)
  4000. {
  4001. int fd = sd->fd;
  4002. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  4003. if( PACKETVER < 6 || !tsd ) {
  4004. WFIFOHEAD(fd,packet_len(0xe7));
  4005. WFIFOW(fd,0) = 0xe7;
  4006. WFIFOB(fd,2) = type;
  4007. WFIFOSET(fd,packet_len(0xe7));
  4008. } else {
  4009. WFIFOHEAD(fd,packet_len(0x1f5));
  4010. WFIFOW(fd,0) = 0x1f5;
  4011. WFIFOB(fd,2) = type;
  4012. WFIFOL(fd,3) = tsd->status.char_id;
  4013. WFIFOW(fd,7) = tsd->status.base_level;
  4014. WFIFOSET(fd,packet_len(0x1f5));
  4015. }
  4016. }
  4017. /// Notifies the client about an item from other player in current trade.
  4018. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4019. /// 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)
  4020. /// 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)
  4021. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  4022. nullpo_retv( sd );
  4023. nullpo_retv( tsd );
  4024. int fd = tsd->fd;
  4025. if( !session_isActive( fd ) ){
  4026. return;
  4027. }
  4028. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4029. if( index ){
  4030. index = server_index( index );
  4031. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4032. return;
  4033. }
  4034. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4035. #if PACKETVER >= 20100223
  4036. p.itemType = sd->inventory_data[index]->type;
  4037. #endif
  4038. p.identified = sd->inventory.u.items_inventory[index].identify;
  4039. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4040. p.refine = sd->inventory.u.items_inventory[index].refine;
  4041. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4042. #if PACKETVER >= 20150226
  4043. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  4044. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4045. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4046. p.look = sd->inventory_data[index]->look;
  4047. p.enchantgrade = sd->inventory.u.items_inventory[index].enchantgrade;
  4048. #endif
  4049. #endif
  4050. }else{
  4051. p = {};
  4052. }
  4053. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4054. p.amount = amount;
  4055. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4056. }
  4057. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4058. /// 00ea <index>.W <result>.B
  4059. /// result:
  4060. /// 0 = success
  4061. /// 1 = overweight
  4062. /// 2 = trade canceled
  4063. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  4064. {
  4065. int fd;
  4066. nullpo_retv(sd);
  4067. fd = sd->fd;
  4068. WFIFOHEAD(fd,packet_len(0xea));
  4069. WFIFOW(fd,0) = 0xea;
  4070. WFIFOW(fd,2) = index;
  4071. WFIFOB(fd,4) = fail;
  4072. WFIFOSET(fd,packet_len(0xea));
  4073. }
  4074. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4075. /// 00ec <who>.B
  4076. /// who:
  4077. /// 0 = self
  4078. /// 1 = other player
  4079. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  4080. {
  4081. int fd;
  4082. nullpo_retv(sd);
  4083. fd = sd->fd;
  4084. WFIFOHEAD(fd,packet_len(0xec));
  4085. WFIFOW(fd,0) = 0xec;
  4086. WFIFOB(fd,2) = fail;
  4087. WFIFOSET(fd,packet_len(0xec));
  4088. }
  4089. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4090. /// 00ee
  4091. void clif_tradecancelled(struct map_session_data* sd)
  4092. {
  4093. int fd;
  4094. nullpo_retv(sd);
  4095. fd = sd->fd;
  4096. WFIFOHEAD(fd,packet_len(0xee));
  4097. WFIFOW(fd,0) = 0xee;
  4098. WFIFOSET(fd,packet_len(0xee));
  4099. }
  4100. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4101. /// 00f0 <result>.B
  4102. /// result:
  4103. /// 0 = success
  4104. /// 1 = failure
  4105. void clif_tradecompleted(struct map_session_data* sd, int fail)
  4106. {
  4107. int fd;
  4108. nullpo_retv(sd);
  4109. fd = sd->fd;
  4110. WFIFOHEAD(fd,packet_len(0xf0));
  4111. WFIFOW(fd,0) = 0xf0;
  4112. WFIFOB(fd,2) = fail;
  4113. WFIFOSET(fd,packet_len(0xf0));
  4114. }
  4115. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4116. /// 00f1
  4117. /// NOTE: Unknown purpose. Items are not removed until the window is
  4118. /// refreshed (ex. by putting another item in there).
  4119. void clif_tradeundo(struct map_session_data* sd)
  4120. {
  4121. int fd = sd->fd;
  4122. WFIFOHEAD(fd,packet_len(0xf1));
  4123. WFIFOW(fd,0) = 0xf1;
  4124. WFIFOSET(fd,packet_len(0xf1));
  4125. }
  4126. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4127. /// 00f2 <current count>.W <max count>.W
  4128. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  4129. {
  4130. int fd;
  4131. nullpo_retv(sd);
  4132. fd=sd->fd;
  4133. WFIFOHEAD(fd,packet_len(0xf2));
  4134. WFIFOW(fd,0) = 0xf2;
  4135. WFIFOW(fd,2) = amount;
  4136. WFIFOW(fd,4) = max_amount;
  4137. WFIFOSET(fd,packet_len(0xf2));
  4138. }
  4139. /// Notifies the client of an item being added to the storage.
  4140. /// 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)
  4141. /// 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)
  4142. /// 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)
  4143. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  4144. nullpo_retv( sd );
  4145. nullpo_retv( i );
  4146. int fd = sd->fd;
  4147. if( !session_isActive( fd ) ){
  4148. return;
  4149. }
  4150. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4151. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4152. p.index = client_storage_index( index ); // index
  4153. p.amount = amount; // amount
  4154. p.itemId = client_nameid( i->nameid ); // id
  4155. #if PACKETVER >= 5
  4156. p.itemType = itemtype( i->nameid ); //type
  4157. #endif
  4158. p.identified = i->identify; //identify flag
  4159. p.damaged = i->attribute; // attribute
  4160. p.refine = i->refine; //refine
  4161. clif_addcards( &p.slot, i );
  4162. #if PACKETVER >= 20150226
  4163. clif_add_random_options( p.option_data, i );
  4164. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4165. p.enchantgrade = i->enchantgrade;
  4166. #endif
  4167. #endif
  4168. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4169. }
  4170. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4171. /// 00f6 <index>.W <amount>.L
  4172. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4173. {
  4174. int fd;
  4175. nullpo_retv(sd);
  4176. fd=sd->fd;
  4177. WFIFOHEAD(fd,packet_len(0xf6));
  4178. WFIFOW(fd,0)=0xf6; // Storage item removed
  4179. WFIFOW(fd,2)=client_storage_index(index);
  4180. WFIFOL(fd,4)=amount;
  4181. WFIFOSET(fd,packet_len(0xf6));
  4182. }
  4183. /// Closes storage (ZC_CLOSE_STORE).
  4184. /// 00f8
  4185. void clif_storageclose(struct map_session_data* sd)
  4186. {
  4187. int fd;
  4188. nullpo_retv(sd);
  4189. fd=sd->fd;
  4190. WFIFOHEAD(fd,packet_len(0xf8));
  4191. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4192. WFIFOSET(fd,packet_len(0xf8));
  4193. }
  4194. /// Notifies clients in an area of a player's souls.
  4195. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4196. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4197. /// 0b73 <id>.L <amount>.W
  4198. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4199. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4200. struct PACKET_ZC_UNCONFIRMED_SPIRITS3 p = {};
  4201. p.packetType = HEADER_ZC_UNCONFIRMED_SPIRITS3;
  4202. #else
  4203. struct PACKET_ZC_SPIRITS p = {};
  4204. p.packetType = HEADER_ZC_SPIRITS;
  4205. #endif
  4206. p.GID = sd->bl.id;
  4207. p.amount = sd->soulball;
  4208. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4209. }
  4210. /*==========================================
  4211. * Server tells 'sd' player client the abouts of 'dstsd' player
  4212. *------------------------------------------*/
  4213. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4214. {
  4215. struct block_list *d_bl;
  4216. int i;
  4217. if( dstsd->chatID ) {
  4218. struct chat_data *cd = NULL;
  4219. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4220. clif_dispchat(cd,sd->fd);
  4221. } else if( dstsd->state.vending )
  4222. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4223. else if( dstsd->state.buyingstore )
  4224. clif_buyingstore_entry_single(sd, dstsd);
  4225. if(dstsd->spiritball > 0)
  4226. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4227. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4228. clif_millenniumshield_single(sd->fd, dstsd);
  4229. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4230. clif_spiritcharm_single(sd->fd, dstsd);
  4231. if (dstsd->soulball > 0)
  4232. clif_soulball( dstsd, &sd->bl, SELF );
  4233. if (dstsd->servantball > 0)
  4234. clif_servantball( *dstsd, &sd->bl, SELF );
  4235. if (dstsd->abyssball > 0)
  4236. clif_abyssball( *dstsd, &sd->bl, SELF );
  4237. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4238. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4239. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4240. )
  4241. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4242. // display link (sd - dstsd) to sd
  4243. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4244. if( i < MAX_DEVOTION )
  4245. clif_devotion(&sd->bl, sd);
  4246. // display links (dstsd - devotees) to sd
  4247. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4248. if( i < MAX_DEVOTION )
  4249. clif_devotion(&dstsd->bl, sd);
  4250. // display link (dstsd - crusader) to sd
  4251. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4252. clif_devotion(d_bl, sd);
  4253. }
  4254. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4255. struct unit_data *ud;
  4256. struct view_data *vd;
  4257. bool option = false;
  4258. unsigned int option_val = 0;
  4259. vd = status_get_viewdata(bl);
  4260. if (!vd || vd->class_ == JT_INVISIBLE)
  4261. return;
  4262. // Hide NPC from Maya Purple card
  4263. if (clif_npc_mayapurple(bl))
  4264. return;
  4265. ud = unit_bl2ud(bl);
  4266. if( ud && ud->walktimer != INVALID_TIMER ){
  4267. clif_set_unit_walking( bl, sd, ud, SELF );
  4268. }else{
  4269. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4270. }
  4271. if (vd->cloth_color)
  4272. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4273. if (vd->body_style)
  4274. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4275. switch (bl->type)
  4276. {
  4277. case BL_PC:
  4278. {
  4279. TBL_PC* tsd = (TBL_PC*)bl;
  4280. clif_getareachar_pc(sd, tsd);
  4281. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4282. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4283. else if(tsd->state.size==SZ_MEDIUM)
  4284. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4285. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4286. clif_sendbgemblem_single(sd->fd,tsd);
  4287. if ( tsd->status.robe )
  4288. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4289. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4290. clif_hat_effects(sd,bl,SELF);
  4291. }
  4292. break;
  4293. case BL_MER: // Devotion Effects
  4294. if( ((TBL_MER*)bl)->devotion_flag )
  4295. clif_devotion(bl, sd);
  4296. break;
  4297. case BL_NPC:
  4298. {
  4299. TBL_NPC* nd = (TBL_NPC*)bl;
  4300. if( nd->chat_id )
  4301. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4302. if( nd->size == SZ_BIG )
  4303. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4304. else if( nd->size == SZ_MEDIUM )
  4305. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4306. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4307. clif_progressbar_npc(nd, sd);
  4308. }
  4309. break;
  4310. case BL_MOB:
  4311. {
  4312. TBL_MOB* md = (TBL_MOB*)bl;
  4313. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4314. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4315. else if(md->special_state.size==SZ_MEDIUM)
  4316. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4317. #if PACKETVER >= 20120404
  4318. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4319. int i;
  4320. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4321. if( md->dmglog[i].id == sd->status.char_id )
  4322. clif_monster_hp_bar(md, sd->fd);
  4323. }
  4324. #endif
  4325. }
  4326. break;
  4327. case BL_PET:
  4328. if (vd->head_bottom)
  4329. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4330. break;
  4331. }
  4332. }
  4333. //Modifies the type of damage according to status changes [Skotlex]
  4334. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4335. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4336. {
  4337. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4338. }
  4339. /*==========================================
  4340. * Estimates walk delay based on the damage criteria. [Skotlex]
  4341. *------------------------------------------*/
  4342. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4343. {
  4344. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4345. return 0;
  4346. if (bl->type == BL_PC) {
  4347. if (battle_config.pc_walk_delay_rate != 100)
  4348. delay = delay*battle_config.pc_walk_delay_rate/100;
  4349. } else
  4350. if (battle_config.walk_delay_rate != 100)
  4351. delay = delay*battle_config.walk_delay_rate/100;
  4352. if (div_ > 1) //Multi-hit skills mean higher delays.
  4353. delay += battle_config.multihit_delay*(div_-1);
  4354. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4355. }
  4356. /*========================================== [Playtester]
  4357. * Returns hallucination damage the client displays
  4358. *------------------------------------------*/
  4359. static int clif_hallucination_damage()
  4360. {
  4361. int digit = rnd() % 5 + 1;
  4362. switch (digit)
  4363. {
  4364. case 1:
  4365. return (rnd() % 10);
  4366. case 2:
  4367. return (rnd() % 100);
  4368. case 3:
  4369. return (rnd() % 1000);
  4370. case 4:
  4371. return (rnd() % 10000);
  4372. }
  4373. return (rnd() % 32767);
  4374. }
  4375. /// Sends a 'damage' packet (src performs action on dst)
  4376. /// 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)
  4377. /// 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)
  4378. /// 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)
  4379. /// type:
  4380. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4381. /// 1 = pick up item
  4382. /// 2 = sit down
  4383. /// 3 = stand up
  4384. /// 4 = damage (endure)
  4385. /// 5 = (splash?)
  4386. /// 6 = (skill?)
  4387. /// 7 = (repeat damage?)
  4388. /// 8 = multi-hit damage
  4389. /// 9 = multi-hit damage (endure)
  4390. /// 10 = critical hit
  4391. /// 11 = lucky dodge
  4392. /// 12 = (touch skill?)
  4393. /// 13 = multi-hit critical
  4394. 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)
  4395. {
  4396. unsigned char buf[34];
  4397. struct status_change *sc;
  4398. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4399. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4400. #if PACKETVER < 20071113
  4401. const int cmd = 0x8a;
  4402. int offset = 0;
  4403. #elif PACKETVER < 20131223
  4404. const int cmd = 0x2e1;
  4405. int offset = 2;
  4406. #else
  4407. const int cmd = 0x8c8;
  4408. int offset = 3;
  4409. #endif
  4410. nullpo_ret(src);
  4411. nullpo_ret(dst);
  4412. if (type != DMG_MULTI_HIT_CRITICAL)
  4413. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4414. sc = status_get_sc(dst);
  4415. if(sc && sc->count) {
  4416. if(sc->data[SC_HALLUCINATION]) {
  4417. damage = clif_hallucination_damage();
  4418. if(damage2) damage2 = clif_hallucination_damage();
  4419. }
  4420. }
  4421. WBUFW(buf,0) = cmd;
  4422. WBUFL(buf,2) = src->id;
  4423. WBUFL(buf,6) = dst->id;
  4424. WBUFL(buf,10) = client_tick(tick);
  4425. WBUFL(buf,14) = sdelay;
  4426. WBUFL(buf,18) = ddelay;
  4427. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4428. #if PACKETVER < 20071113
  4429. WBUFW(buf,22) = damage ? div : 0;
  4430. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4431. #else
  4432. WBUFL(buf, 22) = damage ? div : 0;
  4433. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4434. #endif
  4435. } else {
  4436. #if PACKETVER < 20071113
  4437. WBUFW(buf,22) = min(damage, INT16_MAX);
  4438. WBUFW(buf,27+offset) = damage2;
  4439. #else
  4440. WBUFL(buf,22) = damage;
  4441. WBUFL(buf,27+offset) = damage2;
  4442. #endif
  4443. }
  4444. #if PACKETVER >= 20131223
  4445. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4446. #endif
  4447. WBUFW(buf,24+offset) = div;
  4448. WBUFB(buf,26+offset) = type;
  4449. if(disguised(dst)) {
  4450. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4451. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4452. clif_send(buf, packet_len(cmd), dst, SELF);
  4453. } else
  4454. clif_send(buf, packet_len(cmd), dst, AREA);
  4455. if(disguised(src)) {
  4456. WBUFL(buf,2) = disguised_bl_id( src->id );
  4457. if (disguised(dst))
  4458. WBUFL(buf,6) = dst->id;
  4459. #if PACKETVER < 20071113
  4460. if(damage > 0) WBUFW(buf,22) = -1;
  4461. if(damage2 > 0) WBUFW(buf,27) = -1;
  4462. #else
  4463. if(damage > 0) WBUFL(buf,22) = -1;
  4464. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4465. #endif
  4466. clif_send(buf,packet_len(cmd),src,SELF);
  4467. }
  4468. if(src == dst) {
  4469. unit_setdir(src, unit_getdir(src));
  4470. }
  4471. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4472. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4473. //Return adjusted can't walk delay for further processing.
  4474. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4475. }
  4476. /*==========================================
  4477. * src picks up dst
  4478. *------------------------------------------*/
  4479. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4480. {
  4481. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4482. unsigned char buf[32];
  4483. nullpo_retv(src);
  4484. nullpo_retv(dst);
  4485. WBUFW(buf, 0) = 0x8a;
  4486. WBUFL(buf, 2) = src->id;
  4487. WBUFL(buf, 6) = dst->id;
  4488. WBUFB(buf,26) = 1;
  4489. clif_send(buf, packet_len(0x8a), src, AREA);
  4490. }
  4491. /*==========================================
  4492. * inform clients in area that `bl` is sitting
  4493. *------------------------------------------*/
  4494. void clif_sitting(struct block_list* bl)
  4495. {
  4496. unsigned char buf[32];
  4497. nullpo_retv(bl);
  4498. WBUFW(buf, 0) = 0x8a;
  4499. WBUFL(buf, 2) = bl->id;
  4500. WBUFB(buf,26) = 2;
  4501. clif_send(buf, packet_len(0x8a), bl, AREA);
  4502. if(disguised(bl)) {
  4503. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4504. clif_send(buf, packet_len(0x8a), bl, SELF);
  4505. }
  4506. }
  4507. /*==========================================
  4508. * inform clients in area that `bl` is standing
  4509. *------------------------------------------*/
  4510. void clif_standing(struct block_list* bl)
  4511. {
  4512. unsigned char buf[32];
  4513. nullpo_retv(bl);
  4514. WBUFW(buf, 0) = 0x8a;
  4515. WBUFL(buf, 2) = bl->id;
  4516. WBUFB(buf,26) = 3;
  4517. clif_send(buf, packet_len(0x8a), bl, AREA);
  4518. if(disguised(bl)) {
  4519. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4520. clif_send(buf, packet_len(0x8a), bl, SELF);
  4521. }
  4522. }
  4523. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4524. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4525. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4526. {
  4527. unsigned char buf[32];
  4528. WBUFW(buf,0) = 0x192;
  4529. WBUFW(buf,2) = x;
  4530. WBUFW(buf,4) = y;
  4531. WBUFW(buf,6) = type;
  4532. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4533. if( session_isActive(fd) )
  4534. {
  4535. WFIFOHEAD(fd,packet_len(0x192));
  4536. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4537. WFIFOSET(fd,packet_len(0x192));
  4538. }
  4539. else
  4540. {
  4541. struct block_list dummy_bl;
  4542. dummy_bl.type = BL_NUL;
  4543. dummy_bl.x = x;
  4544. dummy_bl.y = y;
  4545. dummy_bl.m = m;
  4546. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4547. }
  4548. }
  4549. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4550. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4551. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4552. nullpo_retv( sd );
  4553. nullpo_retv( fitem );
  4554. struct PACKET_ZC_ITEM_ENTRY p;
  4555. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4556. p.AID = fitem->bl.id;
  4557. p.itemId = client_nameid( fitem->item.nameid );
  4558. p.identify = fitem->item.identify;
  4559. p.x = fitem->bl.x;
  4560. p.y = fitem->bl.y;
  4561. p.amount = fitem->item.amount;
  4562. p.subX = fitem->subx;
  4563. p.subY = fitem->suby;
  4564. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4565. }
  4566. /// Notifes client about Graffiti
  4567. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4568. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4569. unsigned char buf[128];
  4570. nullpo_retv(bl);
  4571. nullpo_retv(unit);
  4572. WBUFW(buf, 0) = 0x1c9;
  4573. WBUFL(buf, 2) = unit->bl.id;
  4574. WBUFL(buf, 6) = unit->group->src_id;
  4575. WBUFW(buf,10) = unit->bl.x;
  4576. WBUFW(buf,12) = unit->bl.y;
  4577. WBUFB(buf,14) = unit->group->unit_id;
  4578. WBUFB(buf,15) = 1;
  4579. WBUFB(buf,16) = 1;
  4580. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4581. clif_send(buf,packet_len(0x1c9),bl,target);
  4582. }
  4583. /// Notifies the client of a skill unit.
  4584. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4585. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4586. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4587. /// 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)
  4588. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4589. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4590. unsigned char buf[128];
  4591. nullpo_retv(bl);
  4592. nullpo_retv(unit);
  4593. if (bl->type == BL_PC)
  4594. fd = ((TBL_PC*)bl)->fd;
  4595. if (unit->group->state.guildaura)
  4596. return;
  4597. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4598. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4599. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4600. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4601. else
  4602. unit_id = unit->group->unit_id;
  4603. if (!visible)
  4604. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4605. #if PACKETVER >= 3
  4606. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4607. clif_graffiti(bl, unit, target);
  4608. return;
  4609. }
  4610. #endif
  4611. #if PACKETVER <= 20120702
  4612. header = 0x011f;
  4613. //#if PACKETVER < 20110718
  4614. // header = 0x011f;
  4615. //#elif PACKETVER < 20121212
  4616. // header = 0x08c7;
  4617. #elif PACKETVER < 20130731
  4618. header = 0x099f;
  4619. #else
  4620. header = 0x09ca;
  4621. #endif
  4622. len = packet_len(header);
  4623. WBUFW(buf,pos) = header;
  4624. if (header != 0x011f) {
  4625. WBUFW(buf, pos+2) = len;
  4626. pos += 2;
  4627. }
  4628. WBUFL(buf,pos+2) = unit->bl.id;
  4629. WBUFL(buf,pos+6) = unit->group->src_id;
  4630. WBUFW(buf,pos+10) = unit->bl.x;
  4631. WBUFW(buf,pos+12) = unit->bl.y;
  4632. switch (header) {
  4633. case 0x011f:
  4634. WBUFB(buf,pos+14) = unit_id;
  4635. WBUFB(buf,pos+15) = visible;
  4636. break;
  4637. case 0x08c7:
  4638. WBUFB(buf,pos+14) = unit_id;
  4639. WBUFW(buf,pos+15) = unit->range;
  4640. WBUFB(buf,pos+17) = visible;
  4641. break;
  4642. case 0x099f:
  4643. WBUFL(buf,pos+14) = unit_id;
  4644. WBUFW(buf,pos+18) = unit->range;
  4645. WBUFB(buf,pos+20) = visible;
  4646. break;
  4647. case 0x09ca:
  4648. WBUFL(buf,pos+14) = unit_id;
  4649. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4650. WBUFB(buf,pos+19) = visible;
  4651. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4652. break;
  4653. }
  4654. clif_send(buf, len, bl, target);
  4655. if (unit->group->skill_id == WZ_ICEWALL)
  4656. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4657. }
  4658. /// 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)
  4659. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4660. unsigned char buf[128];
  4661. nullpo_retv(bl);
  4662. WBUFW(buf, 0) = 0x09ca;
  4663. WBUFW(buf, 2) = packet_len(0x09ca);
  4664. WBUFL(buf, 4) = 1000;
  4665. WBUFL(buf, 8) = 2000;
  4666. WBUFW(buf, 12) = x;
  4667. WBUFW(buf, 14) = y;
  4668. WBUFL(buf, 16) = unit_id;
  4669. WBUFB(buf, 20) = (unsigned char)range;
  4670. WBUFB(buf, 21) = 1;
  4671. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4672. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4673. }
  4674. /*==========================================
  4675. * Server tells client to remove unit of id 'unit->bl.id'
  4676. *------------------------------------------*/
  4677. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4678. {
  4679. nullpo_retv(unit);
  4680. WFIFOHEAD(fd,packet_len(0x120));
  4681. WFIFOW(fd, 0)=0x120;
  4682. WFIFOL(fd, 2)=unit->bl.id;
  4683. WFIFOSET(fd,packet_len(0x120));
  4684. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4685. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4686. }
  4687. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4688. /// 0120 <id>.L
  4689. void clif_skill_delunit(struct skill_unit *unit)
  4690. {
  4691. unsigned char buf[16];
  4692. nullpo_retv(unit);
  4693. WBUFW(buf, 0)=0x120;
  4694. WBUFL(buf, 2)=unit->bl.id;
  4695. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4696. }
  4697. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4698. /// 01ac <id>.L
  4699. /// Only affects units with class [139,153] client-side.
  4700. void clif_skillunit_update(struct block_list* bl)
  4701. {
  4702. unsigned char buf[6];
  4703. nullpo_retv(bl);
  4704. WBUFW(buf,0) = 0x1ac;
  4705. WBUFL(buf,2) = bl->id;
  4706. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4707. }
  4708. /*==========================================
  4709. *
  4710. *------------------------------------------*/
  4711. static int clif_getareachar(struct block_list* bl,va_list ap)
  4712. {
  4713. struct map_session_data *sd;
  4714. nullpo_ret(bl);
  4715. sd=va_arg(ap,struct map_session_data*);
  4716. if (!clif_session_isValid(sd))
  4717. return 0;
  4718. switch(bl->type){
  4719. case BL_ITEM:
  4720. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4721. break;
  4722. case BL_SKILL:
  4723. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4724. break;
  4725. default:
  4726. if(&sd->bl == bl)
  4727. break;
  4728. clif_getareachar_unit(sd,bl);
  4729. break;
  4730. }
  4731. return 0;
  4732. }
  4733. /*==========================================
  4734. * tbl has gone out of view-size of bl
  4735. *------------------------------------------*/
  4736. int clif_outsight(struct block_list *bl,va_list ap)
  4737. {
  4738. struct block_list *tbl;
  4739. struct view_data *vd;
  4740. TBL_PC *sd, *tsd;
  4741. tbl=va_arg(ap,struct block_list*);
  4742. if(bl == tbl) return 0;
  4743. sd = BL_CAST(BL_PC, bl);
  4744. tsd = BL_CAST(BL_PC, tbl);
  4745. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4746. nullpo_ret(bl);
  4747. switch(bl->type){
  4748. case BL_PC:
  4749. if(sd->vd.class_ != JT_INVISIBLE)
  4750. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4751. if(sd->chatID){
  4752. struct chat_data *cd;
  4753. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4754. if(cd->usersd[0]==sd)
  4755. clif_dispchat(cd,tsd->fd);
  4756. }
  4757. if(sd->state.vending)
  4758. clif_closevendingboard(bl,tsd->fd);
  4759. if(sd->state.buyingstore)
  4760. clif_buyingstore_disappear_entry_single(tsd, sd);
  4761. break;
  4762. case BL_ITEM:
  4763. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4764. break;
  4765. case BL_SKILL:
  4766. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4767. break;
  4768. case BL_NPC:
  4769. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4770. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4771. break;
  4772. default:
  4773. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4774. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4775. break;
  4776. }
  4777. }
  4778. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4779. nullpo_ret(tbl);
  4780. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4781. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4782. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4783. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4784. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4785. }
  4786. return 0;
  4787. }
  4788. /*==========================================
  4789. * tbl has come into view of bl
  4790. *------------------------------------------*/
  4791. int clif_insight(struct block_list *bl,va_list ap)
  4792. {
  4793. struct block_list *tbl;
  4794. TBL_PC *sd, *tsd;
  4795. tbl=va_arg(ap,struct block_list*);
  4796. if (bl == tbl) return 0;
  4797. sd = BL_CAST(BL_PC, bl);
  4798. tsd = BL_CAST(BL_PC, tbl);
  4799. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4800. switch(bl->type){
  4801. case BL_ITEM:
  4802. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4803. break;
  4804. case BL_SKILL:
  4805. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4806. break;
  4807. default:
  4808. clif_getareachar_unit(tsd,bl);
  4809. break;
  4810. }
  4811. }
  4812. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4813. clif_getareachar_unit(sd,tbl);
  4814. }
  4815. return 0;
  4816. }
  4817. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4818. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4819. void clif_skillinfoblock(struct map_session_data *sd)
  4820. {
  4821. int fd;
  4822. int i,len,id;
  4823. nullpo_retv(sd);
  4824. fd = sd->fd;
  4825. if (!session_isActive(fd))
  4826. return;
  4827. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4828. WFIFOW(fd,0) = 0x10f;
  4829. bool haveCallPartnerSkill = false;
  4830. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4831. {
  4832. if( (id = sd->status.skill[i].id) != 0 )
  4833. {
  4834. // workaround for bugreport:5348
  4835. if (len + 37 > 8192)
  4836. break;
  4837. // skip WE_CALLPARTNER and send it in special way
  4838. if (id == WE_CALLPARTNER) {
  4839. haveCallPartnerSkill = true;
  4840. continue;
  4841. }
  4842. WFIFOW(fd,len) = id;
  4843. WFIFOL(fd,len+2) = skill_get_inf(id);
  4844. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4845. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4846. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4847. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4848. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4849. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4850. else
  4851. WFIFOB(fd,len+36) = 0;
  4852. len += 37;
  4853. }
  4854. }
  4855. WFIFOW(fd,2)=len;
  4856. WFIFOSET(fd,len);
  4857. // adoption fix
  4858. if (haveCallPartnerSkill) {
  4859. clif_addskill(sd, WE_CALLPARTNER);
  4860. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4861. }
  4862. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4863. for ( ; i < MAX_SKILL; i++)
  4864. {
  4865. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4866. {
  4867. clif_addskill(sd, id);
  4868. clif_skillinfo(sd, id, 0);
  4869. }
  4870. }
  4871. }
  4872. /**
  4873. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4874. **/
  4875. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4876. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4877. void clif_addskill(struct map_session_data *sd, int skill_id)
  4878. {
  4879. nullpo_retv(sd);
  4880. int fd = sd->fd;
  4881. uint16 idx = skill_get_index(skill_id);
  4882. if (!session_isActive(fd) || !idx)
  4883. return;
  4884. if( sd->status.skill[idx].id <= 0 )
  4885. return;
  4886. WFIFOHEAD(fd, packet_len(0x111));
  4887. WFIFOW(fd,0) = 0x111;
  4888. WFIFOW(fd,2) = skill_id;
  4889. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4890. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4891. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4892. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4893. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4894. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4895. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4896. else
  4897. WFIFOB(fd,38) = 0;
  4898. WFIFOSET(fd,packet_len(0x111));
  4899. }
  4900. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4901. /// 0441 <skill id>.W
  4902. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4903. {
  4904. #if PACKETVER >= 20081217
  4905. nullpo_retv(sd);
  4906. int fd = sd->fd;
  4907. uint16 idx = skill_get_index(skill_id);
  4908. if (!session_isActive(fd) || !idx)
  4909. return;
  4910. WFIFOHEAD(fd,packet_len(0x441));
  4911. WFIFOW(fd,0) = 0x441;
  4912. WFIFOW(fd,2) = skill_id;
  4913. WFIFOSET(fd,packet_len(0x441));
  4914. #endif
  4915. clif_skillinfoblock(sd);
  4916. }
  4917. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4918. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4919. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4920. nullpo_retv(sd);
  4921. int fd = sd->fd;
  4922. uint16 idx = skill_get_index(skill_id);
  4923. if (!session_isActive(fd) || !idx)
  4924. return;
  4925. WFIFOHEAD(fd, packet_len(0x10e));
  4926. WFIFOW(fd, 0) = 0x10e;
  4927. WFIFOW(fd, 2) = skill_id;
  4928. WFIFOW(fd, 4) = lv;
  4929. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4930. WFIFOW(fd, 8) = range;
  4931. WFIFOB(fd, 10) = upgradable;
  4932. WFIFOSET(fd, packet_len(0x10e));
  4933. }
  4934. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4935. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4936. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4937. {
  4938. nullpo_retv(sd);
  4939. const int fd = sd->fd;
  4940. uint16 idx = skill_get_index(skill_id);
  4941. if (!session_isActive(fd) || !idx)
  4942. return;
  4943. WFIFOHEAD(fd,packet_len(0x7e1));
  4944. WFIFOW(fd,0) = 0x7e1;
  4945. WFIFOW(fd,2) = skill_id;
  4946. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4947. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4948. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4949. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4950. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4951. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4952. else
  4953. WFIFOB(fd,14) = 0;
  4954. WFIFOSET(fd,packet_len(0x7e1));
  4955. }
  4956. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4957. #if PACKETVER >= 20151223
  4958. if( !battle_config.show_skill_scale ){
  4959. return;
  4960. }
  4961. struct PACKET_ZC_SKILL_SCALE p;
  4962. p.PacketType = skillscale;
  4963. p.AID = src_id;
  4964. p.skill_id = skill_id;
  4965. p.skill_lv = skill_lv;
  4966. p.x = x;
  4967. p.y = y;
  4968. p.casttime = casttime;
  4969. if( disguised( bl ) ){
  4970. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4971. p.AID = disguised_bl_id( bl->id );
  4972. clif_send( &p, sizeof( p ), bl, SELF );
  4973. }else{
  4974. clif_send( &p, sizeof( p ), bl, AREA );
  4975. }
  4976. #endif
  4977. }
  4978. /// Notifies clients in area, that an object is about to use a skill.
  4979. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4980. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4981. /// property:
  4982. /// 0 = Yellow cast aura
  4983. /// 1 = Water elemental cast aura
  4984. /// 2 = Earth elemental cast aura
  4985. /// 3 = Fire elemental cast aura
  4986. /// 4 = Wind elemental cast aura
  4987. /// 5 = Poison elemental cast aura
  4988. /// 6 = Holy elemental cast aura
  4989. /// ? = like 0
  4990. /// is disposable:
  4991. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4992. /// 1 = no text
  4993. 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)
  4994. {
  4995. #if PACKETVER < 20091124
  4996. const int cmd = 0x13e;
  4997. #else
  4998. const int cmd = 0x7fb;
  4999. #endif
  5000. unsigned char buf[32];
  5001. WBUFW(buf,0) = cmd;
  5002. WBUFL(buf,2) = src_id;
  5003. WBUFL(buf,6) = dst_id;
  5004. WBUFW(buf,10) = dst_x;
  5005. WBUFW(buf,12) = dst_y;
  5006. WBUFW(buf,14) = skill_id;
  5007. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5008. WBUFL(buf,20) = casttime;
  5009. #if PACKETVER >= 20091124
  5010. WBUFB(buf,24) = 0; // isDisposable
  5011. #endif
  5012. if (disguised(bl)) {
  5013. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5014. WBUFL(buf,2) = disguised_bl_id( src_id );
  5015. clif_send(buf,packet_len(cmd), bl, SELF);
  5016. } else
  5017. clif_send(buf,packet_len(cmd), bl, AREA);
  5018. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5019. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5020. }
  5021. }
  5022. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5023. /// 01b9 <id>.L
  5024. void clif_skillcastcancel(struct block_list* bl)
  5025. {
  5026. unsigned char buf[16];
  5027. nullpo_retv(bl);
  5028. WBUFW(buf,0) = 0x1b9;
  5029. WBUFL(buf,2) = bl->id;
  5030. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5031. }
  5032. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5033. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5034. /// num (only used when skill id = NV_BASIC and cause = 0):
  5035. /// 0 = "skill failed" MsgStringTable[159]
  5036. /// 1 = "no emotions" MsgStringTable[160]
  5037. /// 2 = "no sit" MsgStringTable[161]
  5038. /// 3 = "no chat" MsgStringTable[162]
  5039. /// 4 = "no party" MsgStringTable[163]
  5040. /// 5 = "no shout" MsgStringTable[164]
  5041. /// 6 = "no PKing" MsgStringTable[165]
  5042. /// 7 = "no alligning" MsgStringTable[383]
  5043. /// ? = ignored
  5044. /// cause:
  5045. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5046. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5047. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5048. /// "skill failed" MsgStringTable[204] (otherwise)
  5049. /// ... = @see enum useskill_fail_cause
  5050. /// ? = ignored
  5051. ///
  5052. /// if(result!=0) doesn't display any of the previous messages
  5053. /// Note: when this packet is received an unknown flag is always set to 0,
  5054. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5055. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5056. nullpo_retv( sd );
  5057. int fd = sd->fd;
  5058. if( !session_isActive( fd ) ){
  5059. return;
  5060. }
  5061. if(battle_config.display_skill_fail&1)
  5062. return; //Disable all skill failed messages
  5063. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5064. return; //Disable delay failed messages
  5065. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5066. return;
  5067. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5068. return;
  5069. struct PACKET_ZC_ACK_TOUSESKILL p;
  5070. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5071. p.skillId = skill_id;
  5072. p.btype = btype;
  5073. p.itemId = itemId;
  5074. p.flag = 0; // 0 - failed
  5075. p.cause = cause;
  5076. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5077. }
  5078. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5079. /// 043d <skill ID>.W <tick>.L
  5080. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  5081. {
  5082. #if PACKETVER>=20081112
  5083. int fd;
  5084. nullpo_retv(sd);
  5085. fd=sd->fd;
  5086. WFIFOHEAD(fd,packet_len(0x43d));
  5087. WFIFOW(fd,0) = 0x43d;
  5088. WFIFOW(fd,2) = skill_id;
  5089. WFIFOL(fd,4) = client_tick(tick);
  5090. WFIFOSET(fd,packet_len(0x43d));
  5091. #endif
  5092. }
  5093. /// Skill attack effect and damage.
  5094. /// 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)
  5095. /// 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)
  5096. 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)
  5097. {
  5098. unsigned char buf[64];
  5099. struct status_change *sc;
  5100. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5101. nullpo_ret(src);
  5102. nullpo_ret(dst);
  5103. type = clif_calc_delay(type,div,damage,ddelay);
  5104. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5105. if(sc->data[SC_HALLUCINATION] && damage)
  5106. damage = clif_hallucination_damage();
  5107. }
  5108. #if PACKETVER < 3
  5109. WBUFW(buf,0)=0x114;
  5110. WBUFW(buf,2)=skill_id;
  5111. WBUFL(buf,4)=src->id;
  5112. WBUFL(buf,8)=dst->id;
  5113. WBUFL(buf,12)=client_tick(tick);
  5114. WBUFL(buf,16)=sdelay;
  5115. WBUFL(buf,20)=ddelay;
  5116. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5117. WBUFW(buf,24)=damage?div:0;
  5118. } else {
  5119. WBUFW(buf,24)=damage;
  5120. }
  5121. WBUFW(buf,26)=skill_lv;
  5122. WBUFW(buf,28)=div;
  5123. WBUFB(buf,30)=type;
  5124. if (disguised(dst)) {
  5125. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5126. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5127. clif_send(buf,packet_len(0x114),dst,SELF);
  5128. } else
  5129. clif_send(buf,packet_len(0x114),dst,AREA);
  5130. if(disguised(src)) {
  5131. WBUFL(buf,4)=disguised_bl_id(src->id);
  5132. if (disguised(dst))
  5133. WBUFL(buf,8)=dst->id;
  5134. if(damage > 0)
  5135. WBUFW(buf,24)=-1;
  5136. clif_send(buf,packet_len(0x114),src,SELF);
  5137. }
  5138. #else
  5139. WBUFW(buf,0)=0x1de;
  5140. WBUFW(buf,2)=skill_id;
  5141. WBUFL(buf,4)=src->id;
  5142. WBUFL(buf,8)=dst->id;
  5143. WBUFL(buf,12)=client_tick(tick);
  5144. WBUFL(buf,16)=sdelay;
  5145. WBUFL(buf,20)=ddelay;
  5146. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5147. WBUFL(buf,24)=damage?div:0;
  5148. } else {
  5149. WBUFL(buf,24)=damage;
  5150. }
  5151. WBUFW(buf,28)=skill_lv;
  5152. WBUFW(buf,30)=div;
  5153. // For some reason, late 2013 and newer clients have
  5154. // a issue that causes players and monsters to endure
  5155. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5156. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5157. #if PACKETVER < 20131223
  5158. WBUFB(buf,32)=type;
  5159. #else
  5160. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5161. #endif
  5162. if (disguised(dst)) {
  5163. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5164. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5165. clif_send(buf,packet_len(0x1de),dst,SELF);
  5166. } else
  5167. clif_send(buf,packet_len(0x1de),dst,AREA);
  5168. if(disguised(src)) {
  5169. WBUFL(buf,4)=disguised_bl_id(src->id);
  5170. if (disguised(dst))
  5171. WBUFL(buf,8)=dst->id;
  5172. if(damage > 0)
  5173. WBUFL(buf,24)=-1;
  5174. clif_send(buf,packet_len(0x1de),src,SELF);
  5175. }
  5176. #endif
  5177. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5178. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5179. }
  5180. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5181. /// 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
  5182. /*
  5183. 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)
  5184. {
  5185. unsigned char buf[64];
  5186. struct status_change *sc;
  5187. nullpo_ret(src);
  5188. nullpo_ret(dst);
  5189. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5190. type = clif_calc_delay(type,div,damage,ddelay);
  5191. sc = status_get_sc(dst);
  5192. if(sc && sc->count) {
  5193. if(sc->data[SC_HALLUCINATION] && damage)
  5194. damage = clif_hallucination_damage();
  5195. }
  5196. WBUFW(buf,0)=0x115;
  5197. WBUFW(buf,2)=skill_id;
  5198. WBUFL(buf,4)=src->id;
  5199. WBUFL(buf,8)=dst->id;
  5200. WBUFL(buf,12)=client_tick(tick);
  5201. WBUFL(buf,16)=sdelay;
  5202. WBUFL(buf,20)=ddelay;
  5203. WBUFW(buf,24)=dst->x;
  5204. WBUFW(buf,26)=dst->y;
  5205. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5206. WBUFW(buf,28)=damage?div:0;
  5207. } else {
  5208. WBUFW(buf,28)=damage;
  5209. }
  5210. WBUFW(buf,30)=skill_lv;
  5211. WBUFW(buf,32)=div;
  5212. WBUFB(buf,34)=type;
  5213. clif_send(buf,packet_len(0x115),src,AREA);
  5214. if(disguised(src)) {
  5215. WBUFL(buf,4)=disguised_bl_id(src->id);
  5216. if(damage > 0)
  5217. WBUFW(buf,28)=-1;
  5218. clif_send(buf,packet_len(0x115),src,SELF);
  5219. }
  5220. if (disguised(dst)) {
  5221. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5222. if (disguised(src))
  5223. WBUFL(buf,4)=src->id;
  5224. else if(damage > 0)
  5225. WBUFW(buf,28)=-1;
  5226. clif_send(buf,packet_len(0x115),dst,SELF);
  5227. }
  5228. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5229. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5230. }
  5231. */
  5232. /// Non-damaging skill effect
  5233. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5234. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5235. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5236. {
  5237. unsigned char buf[17];
  5238. #if PACKETVER < 20130731
  5239. const int cmd = 0x11a;
  5240. #else
  5241. const int cmd = 0x9cb;
  5242. #endif
  5243. int offset = 0;
  5244. bool success = ( tick != 0 );
  5245. nullpo_ret(dst);
  5246. WBUFW(buf,0) = cmd;
  5247. WBUFW(buf,2) = skill_id;
  5248. #if PACKETVER < 20130731
  5249. WBUFW(buf,4) = min(heal, INT16_MAX);
  5250. #else
  5251. WBUFL(buf,4) = min(heal, INT32_MAX);
  5252. offset += 2;
  5253. #endif
  5254. WBUFL(buf,6+offset) = dst->id;
  5255. WBUFL(buf,10+offset) = src ? src->id : 0;
  5256. WBUFB(buf,14+offset) = success;
  5257. if (disguised(dst)) {
  5258. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5259. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5260. clif_send(buf, packet_len(cmd), dst, SELF);
  5261. } else
  5262. clif_send(buf, packet_len(cmd), dst, AREA);
  5263. if(src && disguised(src)) {
  5264. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5265. if (disguised(dst))
  5266. WBUFL(buf,6+offset) = dst->id;
  5267. clif_send(buf, packet_len(cmd), src, SELF);
  5268. }
  5269. return success;
  5270. }
  5271. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5272. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5273. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5274. {
  5275. unsigned char buf[32];
  5276. nullpo_retv(src);
  5277. WBUFW(buf,0)=0x117;
  5278. WBUFW(buf,2)=skill_id;
  5279. WBUFL(buf,4)=src->id;
  5280. WBUFW(buf,8)=val;
  5281. WBUFW(buf,10)=x;
  5282. WBUFW(buf,12)=y;
  5283. WBUFL(buf,14)=client_tick(tick);
  5284. if(disguised(src)) {
  5285. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5286. WBUFL(buf,4)=disguised_bl_id(src->id);
  5287. clif_send(buf,packet_len(0x117),src,SELF);
  5288. } else
  5289. clif_send(buf,packet_len(0x117),src,AREA);
  5290. }
  5291. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5292. /// 011c <skill id>.W { <map name>.16B }*4
  5293. 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)
  5294. {
  5295. int fd;
  5296. nullpo_retv(sd);
  5297. fd = sd->fd;
  5298. WFIFOHEAD(fd,packet_len(0x11c));
  5299. WFIFOW(fd,0) = 0x11c;
  5300. WFIFOW(fd,2) = skill_id;
  5301. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5302. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5303. else // normal map name
  5304. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5305. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5306. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5307. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5308. WFIFOSET(fd,packet_len(0x11c));
  5309. sd->menuskill_id = skill_id;
  5310. if (skill_id == AL_WARP) {
  5311. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5312. sd->state.workinprogress = WIP_DISABLE_ALL;
  5313. } else
  5314. sd->menuskill_val = skill_lv;
  5315. }
  5316. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5317. /// 011e <type>.B
  5318. /// type:
  5319. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5320. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5321. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5322. ///
  5323. /// @param sd Who receives the message
  5324. /// @param type What message
  5325. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5326. {
  5327. int fd;
  5328. nullpo_retv(sd);
  5329. fd=sd->fd;
  5330. WFIFOHEAD(fd,packet_len(0x11e));
  5331. WFIFOW(fd,0)=0x11e;
  5332. WFIFOB(fd,2)=type;
  5333. WFIFOSET(fd,packet_len(0x11e));
  5334. }
  5335. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5336. /// 0189 <type>.W
  5337. /// type:
  5338. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5339. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5340. ///
  5341. /// @param sd Who receives the message
  5342. /// @param type What message
  5343. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5344. {
  5345. int fd;
  5346. nullpo_retv(sd);
  5347. fd=sd->fd;
  5348. WFIFOHEAD(fd,packet_len(0x189));
  5349. WFIFOW(fd,0)=0x189;
  5350. WFIFOW(fd,2)=type;
  5351. WFIFOSET(fd,packet_len(0x189));
  5352. }
  5353. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5354. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5355. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5356. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5357. {
  5358. struct status_data *status;
  5359. unsigned char buf[64];
  5360. int i, fix;
  5361. nullpo_retv(sd);
  5362. nullpo_retv(dst);
  5363. if( dst->type != BL_MOB )
  5364. return;
  5365. status = status_get_status_data(dst);
  5366. WBUFW(buf, 0)=0x18c;
  5367. WBUFW(buf, 2)=status_get_class(dst);
  5368. WBUFW(buf, 4)=status_get_lv(dst);
  5369. WBUFW(buf, 6)=status->size;
  5370. WBUFL(buf, 8)=status->hp;
  5371. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5372. +(battle_config.estimation_type&2?status->def2:0);
  5373. WBUFW(buf,14)=status->race;
  5374. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5375. +(battle_config.estimation_type&2?status->mdef2:0);
  5376. WBUFW(buf,18)= status->def_ele;
  5377. for(i=0;i<9;i++)
  5378. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5379. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5380. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5381. }
  5382. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5383. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5384. /// material id:
  5385. /// unused by the client
  5386. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5387. nullpo_retv(sd);
  5388. int fd = sd->fd;
  5389. if( !session_isActive( fd ) ){
  5390. return;
  5391. }
  5392. if (sd->menuskill_id == skill_id)
  5393. return; //Avoid resending the menu twice or more times...
  5394. if (skill_id == GC_CREATENEWPOISON)
  5395. skill_id = GC_RESEARCHNEWPOISON;
  5396. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5397. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5398. p->packetType = 0x18d;
  5399. int count = 0;
  5400. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5401. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5402. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5403. )
  5404. {
  5405. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5406. p->items[count].material[0] = 0;
  5407. p->items[count].material[1] = 0;
  5408. p->items[count].material[2] = 0;
  5409. count++;
  5410. }
  5411. }
  5412. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5413. WFIFOSET( fd, p->packetLength );
  5414. if( count > 0 ){
  5415. sd->menuskill_id = skill_id;
  5416. sd->menuskill_val = trigger;
  5417. return;
  5418. }
  5419. }
  5420. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5421. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5422. /// mk type:
  5423. /// 1 = cooking
  5424. /// 2 = arrow
  5425. /// 3 = elemental
  5426. /// 4 = GN_MIX_COOKING
  5427. /// 5 = GN_MAKEBOMB
  5428. /// 6 = GN_S_PHARMACY
  5429. /// 7 = MT_M_MACHINE - Unconfirmed
  5430. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5431. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5432. nullpo_retv( sd );
  5433. // Avoid resending the menu twice or more times...
  5434. if( sd->menuskill_id == skill_id ){
  5435. return;
  5436. }
  5437. int fd = sd->fd;
  5438. if( !session_isActive( fd ) ){
  5439. return;
  5440. }
  5441. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5442. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5443. p->packetType = 0x25a;
  5444. p->makeItem = list_type; // list type
  5445. int count = 0;
  5446. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5447. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5448. continue;
  5449. }
  5450. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5451. count++;
  5452. }
  5453. if( count > 0 || skill_id == AM_PHARMACY ){
  5454. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5455. WFIFOSET( fd, p->packetLength );
  5456. sd->menuskill_id = skill_id;
  5457. sd->menuskill_val = trigger;
  5458. sd->menuskill_val2 = qty; // amount.
  5459. }else{
  5460. clif_menuskill_clear(sd);
  5461. #if PACKETVER >= 20090922
  5462. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5463. #else
  5464. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5465. WFIFOSET( fd, p->packetLength );
  5466. #endif
  5467. }
  5468. }
  5469. /// Notifies clients of a status change.
  5470. /// 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)]
  5471. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5472. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5473. /// @param bl Sends packet to clients around this object
  5474. /// @param id ID of object that has this effect
  5475. /// @param type Status icon see enum efst_type
  5476. /// @param flag 1:Active, 0:Deactive
  5477. /// @param tick Duration in ms
  5478. /// @param val1
  5479. /// @param val2
  5480. /// @param val3
  5481. 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)
  5482. {
  5483. unsigned char buf[32];
  5484. if (type == EFST_BLANK) //It shows nothing on the client...
  5485. return;
  5486. if (type == EFST_POSTDELAY && tick == 0)
  5487. return;
  5488. nullpo_retv(bl);
  5489. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5490. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5491. tick = 200;
  5492. #if PACKETVER >= 20120618
  5493. if (flag && battle_config.display_status_timers)
  5494. WBUFW(buf,0) = 0x983;
  5495. else
  5496. #elif PACKETVER >= 20090121
  5497. if (flag && battle_config.display_status_timers)
  5498. WBUFW(buf,0) = 0x43f;
  5499. else
  5500. #endif
  5501. WBUFW(buf,0) = 0x196;
  5502. WBUFW(buf,2) = type;
  5503. WBUFL(buf,4) = id;
  5504. WBUFB(buf,8) = flag;
  5505. #if PACKETVER >= 20120618
  5506. if (flag && battle_config.display_status_timers) {
  5507. if (tick <= 0)
  5508. tick = 9999; // this is indeed what official servers do
  5509. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5510. WBUFL(buf,13) = client_tick(tick);
  5511. WBUFL(buf,17) = val1;
  5512. WBUFL(buf,21) = val2;
  5513. WBUFL(buf,25) = val3;
  5514. }
  5515. #elif PACKETVER >= 20090121
  5516. if (flag && battle_config.display_status_timers) {
  5517. if (tick <= 0)
  5518. tick = 9999; // this is indeed what official servers do
  5519. WBUFL(buf,9) = client_tick(tick);
  5520. WBUFL(buf,13) = val1;
  5521. WBUFL(buf,17) = val2;
  5522. WBUFL(buf,21) = val3;
  5523. }
  5524. #endif
  5525. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5526. }
  5527. /* Sends status effect to clients around the bl
  5528. * @param bl Object that has the effect
  5529. * @param type Status icon see enum efst_type
  5530. * @param flag 1:Active, 0:Deactive
  5531. * @param tick Duration in ms
  5532. * @param val1
  5533. * @param val2
  5534. * @param val3
  5535. */
  5536. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5537. struct map_session_data *sd = NULL;
  5538. if (type == EFST_BLANK) //It shows nothing on the client...
  5539. return;
  5540. if (type == EFST_POSTDELAY && tick == 0)
  5541. return;
  5542. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5543. return;
  5544. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5545. // Older clients display normal riding icon.
  5546. if (type == EFST_MADOGEAR)
  5547. type = EFST_RIDING;
  5548. #endif
  5549. nullpo_retv(bl);
  5550. sd = BL_CAST(BL_PC, bl);
  5551. if (!(status_efst_get_bl_type((efst_type)type)&bl->type)) // only send status changes that actually matter to the client
  5552. return;
  5553. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5554. }
  5555. /**
  5556. * Send any active EFST to those around.
  5557. * @param tbl: Unit to send the packet to
  5558. * @param bl: Objects walking into view
  5559. * @param target: Client send type
  5560. */
  5561. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5562. unsigned char i;
  5563. struct sc_display_entry **sc_display;
  5564. unsigned char sc_display_count;
  5565. bool spheres_sent;
  5566. nullpo_retv(bl);
  5567. switch( bl->type ){
  5568. case BL_PC: {
  5569. struct map_session_data* sd = (struct map_session_data*)bl;
  5570. sc_display = sd->sc_display;
  5571. sc_display_count = sd->sc_display_count;
  5572. spheres_sent = !sd->state.connect_new;
  5573. }
  5574. break;
  5575. case BL_NPC: {
  5576. struct npc_data* nd = (struct npc_data*)bl;
  5577. sc_display = nd->sc_display;
  5578. sc_display_count = nd->sc_display_count;
  5579. spheres_sent = true;
  5580. }
  5581. break;
  5582. default:
  5583. return;
  5584. }
  5585. for (i = 0; i < sc_display_count; i++) {
  5586. enum sc_type type = sc_display[i]->type;
  5587. struct status_change *sc = status_get_sc(bl);
  5588. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5589. t_tick tick = 0;
  5590. if (td)
  5591. tick = DIFF_TICK(td->tick, gettick());
  5592. // Status changes that need special handling
  5593. switch( type ){
  5594. case SC_SPHERE_1:
  5595. case SC_SPHERE_2:
  5596. case SC_SPHERE_3:
  5597. case SC_SPHERE_4:
  5598. case SC_SPHERE_5:
  5599. if( spheres_sent ){
  5600. target = AREA_WOS;
  5601. }
  5602. break;
  5603. case SC_HELLS_PLANT:
  5604. if( sc && sc->data[type] ){
  5605. tick = sc->data[type]->val4;
  5606. }
  5607. break;
  5608. }
  5609. #if PACKETVER > 20120418
  5610. clif_efst_status_change(tbl, bl->id, target, status_db.getIcon(type), tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5611. #else
  5612. clif_status_change_sub(tbl, bl->id, status_db.getIcon(type), 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5613. #endif
  5614. }
  5615. }
  5616. /// Notifies the client when a player enters the screen with an active EFST.
  5617. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5618. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5619. 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) {
  5620. #if PACKETVER >= 20111108
  5621. unsigned char buf[32];
  5622. #if PACKETVER >= 20120618
  5623. const int cmd = 0x984;
  5624. #elif PACKETVER >= 20111108
  5625. const int cmd = 0x8ff;
  5626. #endif
  5627. int offset = 0;
  5628. if (type == EFST_BLANK)
  5629. return;
  5630. nullpo_retv(bl);
  5631. if (tick <= 0)
  5632. tick = 9999;
  5633. WBUFW(buf,offset + 0) = cmd;
  5634. WBUFL(buf,offset + 2) = tid;
  5635. WBUFW(buf,offset + 6) = type;
  5636. #if PACKETVER >= 20111108
  5637. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5638. #if PACKETVER >= 20120618
  5639. WBUFL(buf,offset + 12) = client_tick(tick);
  5640. offset += 4;
  5641. #endif
  5642. WBUFL(buf,offset + 12) = val1;
  5643. WBUFL(buf,offset + 16) = val2;
  5644. WBUFL(buf,offset + 20) = val3;
  5645. #endif
  5646. clif_send(buf,packet_len(cmd),bl,target);
  5647. #endif
  5648. }
  5649. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5650. /// 008e <packet len>.W <message>.?B
  5651. void clif_displaymessage(const int fd, const char* mes)
  5652. {
  5653. nullpo_retv(mes);
  5654. if( session_isActive( fd ) ){
  5655. char *message, *line;
  5656. message = aStrdup(mes);
  5657. line = strtok(message, "\n");
  5658. while(line != NULL) {
  5659. #if PACKETVER == 20141022
  5660. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5661. /** so we redirect to ZC_NPC_CHAT **/
  5662. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5663. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5664. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5665. if (len > 0) {
  5666. WFIFOHEAD(fd, 13 + len);
  5667. WFIFOW(fd, 0) = 0x2C1;
  5668. WFIFOW(fd, 2) = 13 + len;
  5669. WFIFOL(fd, 4) = 0;
  5670. WFIFOL(fd, 8) = color;
  5671. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5672. WFIFOSET(fd, WFIFOW(fd, 2));
  5673. }
  5674. #else
  5675. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5676. int len = strnlen(line, CHAT_SIZE_MAX);
  5677. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5678. WFIFOHEAD(fd, 5 + len);
  5679. WFIFOW(fd,0) = 0x8e;
  5680. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5681. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5682. WFIFOSET(fd, 5 + len);
  5683. }
  5684. #endif
  5685. line = strtok(NULL, "\n");
  5686. }
  5687. aFree(message);
  5688. }
  5689. }
  5690. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5691. /// 009a <packet len>.W <message>.?B
  5692. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5693. {
  5694. nullpo_retv(mes);
  5695. if (len < 2)
  5696. return;
  5697. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5698. p->packetType = HEADER_ZC_BROADCAST;
  5699. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5700. if( ( type&BC_BLUE ) != 0 ){
  5701. const char* color = "blue";
  5702. int16 length = (int16)strlen( color );
  5703. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5704. strcpy( p->message, color );
  5705. strncpy( &p->message[length], mes, len );
  5706. p->PacketLength += length;
  5707. }else if( ( type&BC_WOE ) != 0 ){
  5708. const char* color = "ssss";
  5709. int16 length = (int16)strlen( color );
  5710. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5711. strcpy( p->message, color );
  5712. strncpy( &p->message[length], mes, len );
  5713. p->PacketLength += length;
  5714. }else{
  5715. strncpy( p->message, mes, len );
  5716. }
  5717. clif_send( p, p->PacketLength, bl, target );
  5718. }
  5719. /*==========================================
  5720. * Displays a message on a 'bl' to all it's nearby clients
  5721. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5722. *------------------------------------------*/
  5723. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5724. nullpo_retv(bl);
  5725. nullpo_retv(message);
  5726. int16 len = (int16)( strlen( message ) + 1 );
  5727. if( len > CHAT_SIZE_MAX ) {
  5728. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5729. len = CHAT_SIZE_MAX;
  5730. }
  5731. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5732. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5733. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5734. p->GID = bl->id;
  5735. safestrncpy( p->Message, message, len );
  5736. clif_send( p, p->PacketLength, bl, target );
  5737. }
  5738. /// Send broadcast message with font formatting.
  5739. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5740. 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)
  5741. {
  5742. nullpo_retv(mes);
  5743. if (len < 2)
  5744. return;
  5745. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5746. p->packetType = HEADER_ZC_BROADCAST2;
  5747. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5748. p->fontColor = fontColor;
  5749. p->fontType = fontType;
  5750. p->fontSize = fontSize;
  5751. p->fontAlign = fontAlign;
  5752. p->fontY = fontY;
  5753. strncpy( p->message, mes, len );
  5754. clif_send( p, p->PacketLength, bl, target );
  5755. }
  5756. /*
  5757. * Display *msg to all *users in channel
  5758. */
  5759. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5760. DBIterator *iter;
  5761. struct map_session_data *user;
  5762. unsigned short msg_len = 0, len = 0;
  5763. unsigned char buf[CHAT_SIZE_MAX];
  5764. if (!channel || !msg)
  5765. return;
  5766. msg_len = (unsigned short)(strlen(msg) + 1);
  5767. if( msg_len > sizeof(buf)-12 ) {
  5768. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5769. msg_len = sizeof(buf)-12;
  5770. }
  5771. WBUFW(buf,0) = 0x2C1;
  5772. WBUFW(buf,2) = (len = msg_len + 12);
  5773. WBUFL(buf,4) = 0;
  5774. WBUFL(buf,8) = color;
  5775. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5776. iter = db_iterator(channel->users);
  5777. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5778. clif_send(buf, len, &user->bl, SELF);
  5779. }
  5780. dbi_destroy(iter);
  5781. }
  5782. /// Displays heal effect.
  5783. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5784. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5785. /// var id:
  5786. /// 5 = HP (SP_HP)
  5787. /// 7 = SP (SP_SP)
  5788. /// ? = ignored
  5789. void clif_heal(int fd,int type,int val) {
  5790. #if PACKETVER < 20141022
  5791. const int cmd = 0x13d;
  5792. #else
  5793. const int cmd = 0xa27;
  5794. #endif
  5795. WFIFOHEAD(fd, packet_len(cmd));
  5796. WFIFOW(fd,0) = cmd;
  5797. WFIFOW(fd,2) = type;
  5798. #if PACKETVER < 20141022
  5799. WFIFOW(fd,4) = min(val, INT16_MAX);
  5800. #else
  5801. WFIFOL(fd,4) = min(val, INT32_MAX);
  5802. #endif
  5803. WFIFOSET(fd, packet_len(cmd));
  5804. }
  5805. /// Displays resurrection effect (ZC_RESURRECTION).
  5806. /// 0148 <id>.L <type>.W
  5807. /// type:
  5808. /// ignored
  5809. void clif_resurrection(struct block_list *bl,int type)
  5810. {
  5811. unsigned char buf[16];
  5812. nullpo_retv(bl);
  5813. WBUFW(buf,0)=0x148;
  5814. WBUFL(buf,2)=bl->id;
  5815. WBUFW(buf,6)=0;
  5816. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5817. if (disguised(bl))
  5818. clif_spawn(bl);
  5819. }
  5820. /// Sets the map property
  5821. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5822. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5823. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5824. {
  5825. #if PACKETVER >= 20121010
  5826. short cmd = 0x99b;
  5827. unsigned char buf[8];
  5828. #else
  5829. short cmd = 0x199;
  5830. unsigned char buf[4];
  5831. #endif
  5832. WBUFW(buf,0)=cmd;
  5833. WBUFW(buf,2)=property;
  5834. #if PACKETVER >= 20121010
  5835. struct map_data *mapdata = map_getmapdata(bl->m);
  5836. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  5837. WBUFL(buf,4) = ((mapdata->flag[MF_PVP] || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5838. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5839. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5840. ((mapdata->flag[MF_FORCEMINEFFECT] || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5841. ((mapdata->flag[MF_NOLOCKON] || mapdata_flag_vs(mapdata) || (sd && sd->duel_group > 0))<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5842. ((mapdata->flag[MF_PVP])<<5)| // COUNT_PK - Show the PvP counter
  5843. ((mapdata->flag[MF_PARTYLOCK])<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5844. ((mapdata->flag[MF_BATTLEGROUND])<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5845. ((mapdata->flag[MF_NOCOSTUME])<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5846. ((!mapdata->flag[MF_NOUSECART])<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5847. ((!mapdata->flag[MF_NOSUNMOONSTARMIRACLE])<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5848. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5849. #endif
  5850. clif_send(buf,packet_len(cmd),bl,t);
  5851. }
  5852. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5853. /// 01d6 <type>.W
  5854. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5855. {
  5856. int fd;
  5857. nullpo_retv(sd);
  5858. fd=sd->fd;
  5859. WFIFOHEAD(fd,packet_len(0x1D6));
  5860. WFIFOW(fd,0)=0x1D6;
  5861. WFIFOW(fd,2)=type;
  5862. WFIFOSET(fd,packet_len(0x1D6));
  5863. }
  5864. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5865. /// 019a <id>.L <ranking>.L <total>.L
  5866. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5867. {
  5868. if(type == 2) {
  5869. int fd = sd->fd;
  5870. WFIFOHEAD(fd,packet_len(0x19a));
  5871. WFIFOW(fd,0) = 0x19a;
  5872. WFIFOL(fd,2) = sd->bl.id;
  5873. WFIFOL(fd,6) = pvprank;
  5874. WFIFOL(fd,10) = pvpnum;
  5875. WFIFOSET(fd,packet_len(0x19a));
  5876. } else {
  5877. unsigned char buf[32];
  5878. WBUFW(buf,0) = 0x19a;
  5879. WBUFL(buf,2) = sd->bl.id;
  5880. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5881. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5882. else
  5883. WBUFL(buf,6) = pvprank;
  5884. WBUFL(buf,10) = pvpnum;
  5885. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5886. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5887. else if(!type)
  5888. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5889. else
  5890. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5891. }
  5892. }
  5893. /*==========================================
  5894. *
  5895. *------------------------------------------*/
  5896. void clif_map_property_mapall(int map_idx, enum map_property property)
  5897. {
  5898. struct block_list bl;
  5899. bl.id = 0;
  5900. bl.type = BL_NUL;
  5901. bl.m = map_idx;
  5902. clif_map_property( &bl, property, ALL_SAMEMAP );
  5903. }
  5904. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5905. /// 0188 <result>.W <index>.W <refine>.W
  5906. /// result:
  5907. /// 0 = success
  5908. /// 1 = failure
  5909. /// 2 = downgrade
  5910. void clif_refine(int fd, int fail, int index, int val)
  5911. {
  5912. WFIFOHEAD(fd,packet_len(0x188));
  5913. WFIFOW(fd,0)=0x188;
  5914. WFIFOW(fd,2)=fail;
  5915. WFIFOW(fd,4)=index+2;
  5916. WFIFOW(fd,6)=val;
  5917. WFIFOSET(fd,packet_len(0x188));
  5918. }
  5919. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5920. /// 0223 <result>.L <nameid>.W
  5921. /// result:
  5922. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5923. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5924. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5925. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5926. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5927. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5928. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5929. p.result = result;
  5930. p.itemId = client_nameid( item_id );
  5931. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5932. }
  5933. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5934. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5935. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5936. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5937. int fd;
  5938. nullpo_retv(sd);
  5939. fd = sd->fd;
  5940. #if PACKETVER < 20091104
  5941. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5942. WFIFOW(fd,0) = 0x97;
  5943. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5944. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5945. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5946. WFIFOSET(fd,WFIFOW(fd,2));
  5947. #else
  5948. struct map_session_data *ssd = map_nick2sd(nick,false);
  5949. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5950. WFIFOW(fd,0) = 0x97;
  5951. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5952. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5953. // If it is not a message from the server or a player from another map-server
  5954. if( ssd ){
  5955. gmlvl = pc_get_group_level(ssd);
  5956. }
  5957. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5958. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5959. WFIFOSET(fd,WFIFOW(fd,2));
  5960. #endif
  5961. }
  5962. /// Inform the player about the result of his whisper action
  5963. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5964. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5965. /// result:
  5966. /// 0 = success to send wisper
  5967. /// 1 = target character is not loged in
  5968. /// 2 = ignored by target
  5969. /// 3 = everyone ignored by target
  5970. void clif_wis_end(int fd, int result)
  5971. {
  5972. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5973. #if PACKETVER < 20131223
  5974. const int cmd = 0x98;
  5975. #else
  5976. const int cmd = 0x9df;
  5977. #endif
  5978. if (!sd)
  5979. return;
  5980. WFIFOHEAD(fd,packet_len(cmd));
  5981. WFIFOW(fd,0) = cmd;
  5982. WFIFOB(fd,2) = (char)result;
  5983. #if PACKETVER >= 20131223
  5984. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5985. #endif
  5986. WFIFOSET(fd,packet_len(cmd));
  5987. }
  5988. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5989. /// 0194 <char id>.L <name>.24B
  5990. /// 0af7 <flag>.W <char id>.L <name>.24B
  5991. void clif_solved_charname(int fd, int charid, const char* name)
  5992. {
  5993. #if PACKETVER >= 20180221
  5994. WFIFOHEAD(fd,packet_len(0xaf7));
  5995. WFIFOW(fd,0) = 0xaf7;
  5996. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5997. WFIFOL(fd,4) = charid;
  5998. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5999. WFIFOSET(fd,packet_len(0x0af7));
  6000. #else
  6001. WFIFOHEAD(fd,packet_len(0x194));
  6002. WFIFOW(fd,0)=0x194;
  6003. WFIFOL(fd,2)=charid;
  6004. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  6005. WFIFOSET(fd,packet_len(0x194));
  6006. #endif
  6007. }
  6008. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  6009. /// 017b <packet len>.W { <name id>.W }*
  6010. void clif_use_card(struct map_session_data *sd,int idx)
  6011. {
  6012. int i,c,ep;
  6013. int fd=sd->fd;
  6014. nullpo_retv(sd);
  6015. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6016. return;
  6017. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6018. return; //Avoid parsing invalid item indexes (no card/no item)
  6019. ep=sd->inventory_data[idx]->equip;
  6020. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6021. WFIFOW(fd,0)=0x17b;
  6022. for(i=c=0;i<MAX_INVENTORY;i++){
  6023. int j;
  6024. if(sd->inventory_data[i] == NULL)
  6025. continue;
  6026. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6027. continue;
  6028. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6029. continue;
  6030. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6031. continue;
  6032. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6033. continue;
  6034. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6035. continue;
  6036. 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.
  6037. continue;
  6038. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6039. if( j == sd->inventory_data[i]->slots ) // No room
  6040. continue;
  6041. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6042. continue;
  6043. WFIFOW(fd,4+c*2)=i+2;
  6044. c++;
  6045. }
  6046. if( !c ) return; // no item is available for card insertion
  6047. WFIFOW(fd,2)=4+c*2;
  6048. WFIFOSET(fd,WFIFOW(fd,2));
  6049. }
  6050. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6051. /// 017d <equip index>.W <card index>.W <result>.B
  6052. /// result:
  6053. /// 0 = success
  6054. /// 1 = failure
  6055. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  6056. {
  6057. int fd;
  6058. nullpo_retv(sd);
  6059. fd=sd->fd;
  6060. WFIFOHEAD(fd,packet_len(0x17d));
  6061. WFIFOW(fd,0)=0x17d;
  6062. WFIFOW(fd,2)=idx_equip+2;
  6063. WFIFOW(fd,4)=idx_card+2;
  6064. WFIFOB(fd,6)=flag;
  6065. WFIFOSET(fd,packet_len(0x17d));
  6066. }
  6067. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6068. /// 0177 <packet len>.W { <index>.W }*
  6069. void clif_item_identify_list(struct map_session_data *sd)
  6070. {
  6071. int i,c;
  6072. int fd;
  6073. nullpo_retv(sd);
  6074. fd=sd->fd;
  6075. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6076. WFIFOW(fd,0)=0x177;
  6077. for(i=c=0;i<MAX_INVENTORY;i++){
  6078. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6079. WFIFOW(fd,c*2+4)=client_index(i);
  6080. c++;
  6081. }
  6082. }
  6083. if(c > 0) {
  6084. WFIFOW(fd,2)=c*2+4;
  6085. WFIFOSET(fd,WFIFOW(fd,2));
  6086. sd->menuskill_id = MC_IDENTIFY;
  6087. sd->menuskill_val = c;
  6088. sd->state.workinprogress = WIP_DISABLE_ALL;
  6089. }
  6090. }
  6091. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6092. /// 0179 <index>.W <result>.B
  6093. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  6094. {
  6095. int fd;
  6096. nullpo_retv(sd);
  6097. fd=sd->fd;
  6098. WFIFOHEAD(fd,packet_len(0x179));
  6099. WFIFOW(fd, 0)=0x179;
  6100. WFIFOW(fd, 2)=idx+2;
  6101. WFIFOB(fd, 4)=flag;
  6102. WFIFOSET(fd,packet_len(0x179));
  6103. }
  6104. /// Presents a list of items that can be repaired.
  6105. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6106. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  6107. nullpo_retv( sd );
  6108. nullpo_retv( dstsd );
  6109. int fd = sd->fd;
  6110. if( !session_isActive( fd ) ){
  6111. return;
  6112. }
  6113. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6114. // Preallocate the maximum size
  6115. WFIFOHEAD( fd, len );
  6116. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6117. int c = 0;
  6118. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6119. 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)){
  6120. p->items[c].index = i;
  6121. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6122. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6123. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6124. c++;
  6125. }
  6126. }
  6127. if( c > 0 ){
  6128. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6129. // Recalculate real length
  6130. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6131. p->packetLength = len;
  6132. WFIFOSET( fd, len );
  6133. sd->menuskill_id = BS_REPAIRWEAPON;
  6134. sd->menuskill_val = dstsd->bl.id;
  6135. sd->menuskill_val2 = lv;
  6136. }else{
  6137. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6138. }
  6139. }
  6140. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6141. /// 01fe <index>.W <result>.B
  6142. /// index:
  6143. /// ignored (inventory index)
  6144. /// result:
  6145. /// 0 = Item repair success.
  6146. /// 1 = Item repair failure.
  6147. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  6148. {
  6149. int fd;
  6150. nullpo_retv(sd);
  6151. fd = sd->fd;
  6152. WFIFOHEAD(fd,packet_len(0x1fe));
  6153. WFIFOW(fd, 0)=0x1fe;
  6154. WFIFOW(fd, 2)=idx+2;
  6155. WFIFOB(fd, 4)=flag;
  6156. WFIFOSET(fd,packet_len(0x1fe));
  6157. }
  6158. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6159. /// 02bb <equip location>.W <account id>.L
  6160. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  6161. {
  6162. int fd = sd->fd;
  6163. WFIFOHEAD(fd,packet_len(0x2bb));
  6164. WFIFOW(fd,0) = 0x2bb;
  6165. WFIFOW(fd,2) = position;
  6166. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6167. WFIFOSET(fd,packet_len(0x2bb));
  6168. }
  6169. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6170. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6171. void clif_item_refine_list( struct map_session_data *sd ){
  6172. nullpo_retv( sd );
  6173. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6174. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6175. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6176. int refine_item[MAX_WEAPON_LEVEL];
  6177. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6178. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6179. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6180. #ifdef RENEWAL
  6181. refine_item[4] = -1;
  6182. #endif
  6183. int count = 0;
  6184. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6185. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6186. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6187. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6188. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6189. p->items[count].index = client_index( i );
  6190. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6191. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6192. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6193. count++;
  6194. }
  6195. }
  6196. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6197. clif_send( p, p->packetLength, &sd->bl, SELF );
  6198. if( count > 0 ){
  6199. sd->menuskill_id = WS_WEAPONREFINE;
  6200. sd->menuskill_val = skill_lv;
  6201. }
  6202. }
  6203. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6204. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6205. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6206. nullpo_retv( sd );
  6207. struct PACKET_ZC_AUTORUN_SKILL p;
  6208. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6209. p.skill_id = skill_id;
  6210. p.skill_type = skill_get_inf( skill_id );
  6211. p.skill_lv = skill_lv;
  6212. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6213. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6214. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6215. p.up_flag = false;
  6216. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6217. }
  6218. /// Adds an item to character's cart.
  6219. /// 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)
  6220. /// 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)
  6221. /// 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)
  6222. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6223. nullpo_retv( sd );
  6224. int fd = sd->fd;
  6225. if( !session_isActive( fd ) ){
  6226. return;
  6227. }
  6228. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6229. return;
  6230. }
  6231. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6232. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6233. p.index = client_index( n );
  6234. p.amount = amount;
  6235. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6236. #if PACKETVER >= 5
  6237. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6238. #endif
  6239. p.identified = sd->cart.u.items_cart[n].identify;
  6240. p.damaged = sd->cart.u.items_cart[n].attribute;
  6241. p.refine = sd->cart.u.items_cart[n].refine;
  6242. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6243. #if PACKETVER >= 20150226
  6244. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6245. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6246. p.enchantgrade = sd->cart.u.items_cart[n].enchantgrade;
  6247. #endif
  6248. #endif
  6249. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6250. }
  6251. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6252. /* Acknowledge an item have been added to cart
  6253. * 012c <result>B
  6254. * result :
  6255. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6256. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6257. */
  6258. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6259. {
  6260. int fd;
  6261. unsigned char *buf;
  6262. nullpo_retv(sd);
  6263. fd = sd->fd;
  6264. buf = WFIFOP(fd,0);
  6265. WBUFW(buf,0) = 0x12c;
  6266. WBUFB(buf,2) = flag;
  6267. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6268. }
  6269. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6270. void clif_bank_open(struct map_session_data *sd){
  6271. int fd;
  6272. nullpo_retv(sd);
  6273. fd = sd->fd;
  6274. WFIFOHEAD(fd,4);
  6275. WFIFOW(fd,0) = 0x09b7;
  6276. WFIFOW(fd,2) = 0;
  6277. WFIFOSET(fd,4);
  6278. }
  6279. /*
  6280. * Request to Open the banking system
  6281. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6282. */
  6283. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6284. //TODO check if preventing trade or stuff like that
  6285. //also mark something in case char ain't available for saving, should we check now ?
  6286. nullpo_retv(sd);
  6287. if( !battle_config.feature_banking ) {
  6288. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6289. return;
  6290. }
  6291. else {
  6292. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6293. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6294. if(sd->status.account_id == aid){
  6295. sd->state.banking = 1;
  6296. //request save ?
  6297. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6298. //on succes open bank ?
  6299. clif_bank_open(sd);
  6300. }
  6301. }
  6302. }
  6303. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6304. void clif_bank_close(struct map_session_data *sd){
  6305. int fd;
  6306. nullpo_retv(sd);
  6307. fd = sd->fd;
  6308. WFIFOHEAD(fd,4);
  6309. WFIFOW(fd,0) = 0x09B9;
  6310. WFIFOW(fd,2) = 0;
  6311. WFIFOSET(fd,4);
  6312. }
  6313. /*
  6314. * Request to close the banking system
  6315. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6316. */
  6317. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6318. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6319. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6320. nullpo_retv(sd);
  6321. if( !battle_config.feature_banking ) {
  6322. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6323. //still allow to go trough to not stuck player if we have disable it while they was in
  6324. }
  6325. if(sd->status.account_id == aid){
  6326. sd->state.banking = 0;
  6327. clif_bank_close(sd);
  6328. }
  6329. }
  6330. /*
  6331. * Display how much we got in bank (I suppose)
  6332. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6333. */
  6334. void clif_Bank_Check(struct map_session_data* sd) {
  6335. unsigned char buf[13];
  6336. struct s_packet_db* info;
  6337. int16 len;
  6338. int cmd = 0;
  6339. nullpo_retv(sd);
  6340. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6341. if(!cmd) cmd = 0x09A6; //default
  6342. info = &packet_db[cmd];
  6343. len = info->len;
  6344. if(!len) return; //version as packet disable
  6345. // sd->state.banking = 1; //mark opening and closing
  6346. WBUFW(buf,0) = cmd;
  6347. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6348. WBUFW(buf,info->pos[1]) = 0; //reason
  6349. clif_send(buf,len,&sd->bl,SELF);
  6350. }
  6351. /*
  6352. * Requesting the data in bank
  6353. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6354. */
  6355. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6356. nullpo_retv(sd);
  6357. if( !battle_config.feature_banking ) {
  6358. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6359. return;
  6360. }
  6361. else {
  6362. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6363. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6364. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6365. clif_Bank_Check(sd);
  6366. }
  6367. }
  6368. /*
  6369. * Acknowledge of deposit some money in bank
  6370. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6371. */
  6372. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6373. unsigned char buf[17];
  6374. struct s_packet_db* info;
  6375. int16 len;
  6376. int cmd =0;
  6377. nullpo_retv(sd);
  6378. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6379. if(!cmd) cmd = 0x09A8;
  6380. info = &packet_db[cmd];
  6381. len = info->len;
  6382. if(!len) return; //version as packet disable
  6383. WBUFW(buf,0) = cmd;
  6384. WBUFW(buf,info->pos[0]) = (short)reason;
  6385. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6386. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6387. clif_send(buf,len,&sd->bl,SELF);
  6388. }
  6389. /*
  6390. * Request saving some money in bank
  6391. * @author : original [Yommy/Hercules]
  6392. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6393. */
  6394. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6395. nullpo_retv(sd);
  6396. if( !battle_config.feature_banking ) {
  6397. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6398. return;
  6399. }
  6400. else {
  6401. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6402. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6403. int money = RFIFOL(fd,info->pos[1]);
  6404. if(sd->status.account_id == aid){
  6405. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6406. clif_bank_deposit(sd,reason);
  6407. }
  6408. }
  6409. }
  6410. /*
  6411. * Acknowledge of withdrawing some money from bank
  6412. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6413. */
  6414. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6415. unsigned char buf[17];
  6416. struct s_packet_db* info;
  6417. int16 len;
  6418. int cmd;
  6419. nullpo_retv(sd);
  6420. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6421. if(!cmd) cmd = 0x09AA;
  6422. info = &packet_db[cmd];
  6423. len = info->len;
  6424. if(!len) return; //version as packet disable
  6425. WBUFW(buf,0) = cmd;
  6426. WBUFW(buf,info->pos[0]) = (short)reason;
  6427. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6428. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6429. clif_send(buf,len,&sd->bl,SELF);
  6430. }
  6431. /*
  6432. * Request Withdrawing some money from bank
  6433. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6434. */
  6435. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6436. nullpo_retv(sd);
  6437. if( !battle_config.feature_banking ) {
  6438. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6439. return;
  6440. }
  6441. else {
  6442. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6443. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6444. int money = RFIFOL(fd,info->pos[1]);
  6445. if(sd->status.account_id == aid){
  6446. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6447. clif_bank_withdraw(sd,reason);
  6448. }
  6449. }
  6450. }
  6451. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6452. /// 0125 <index>.W <amount>.L
  6453. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6454. {
  6455. int fd;
  6456. nullpo_retv(sd);
  6457. fd=sd->fd;
  6458. WFIFOHEAD(fd,packet_len(0x125));
  6459. WFIFOW(fd,0)=0x125;
  6460. WFIFOW(fd,2)=n+2;
  6461. WFIFOL(fd,4)=amount;
  6462. WFIFOSET(fd,packet_len(0x125));
  6463. }
  6464. /// Opens the shop creation menu (ZC_OPENSTORE).
  6465. /// 012d <num>.W
  6466. /// num:
  6467. /// number of allowed item slots
  6468. void clif_openvendingreq(struct map_session_data* sd, int num)
  6469. {
  6470. int fd;
  6471. nullpo_retv(sd);
  6472. fd = sd->fd;
  6473. WFIFOHEAD(fd,packet_len(0x12d));
  6474. WFIFOW(fd,0) = 0x12d;
  6475. WFIFOW(fd,2) = num;
  6476. WFIFOSET(fd,packet_len(0x12d));
  6477. }
  6478. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6479. /// 0131 <owner id>.L <message>.80B
  6480. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6481. {
  6482. unsigned char buf[128];
  6483. nullpo_retv(bl);
  6484. WBUFW(buf,0) = 0x131;
  6485. WBUFL(buf,2) = bl->id;
  6486. safestrncpy(WBUFCP(buf,6), message, 80);
  6487. if( session_isActive(fd) ) {
  6488. WFIFOHEAD(fd,packet_len(0x131));
  6489. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6490. WFIFOSET(fd,packet_len(0x131));
  6491. } else {
  6492. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6493. }
  6494. }
  6495. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6496. /// 0132 <owner id>.L
  6497. void clif_closevendingboard(struct block_list* bl, int fd)
  6498. {
  6499. unsigned char buf[16];
  6500. nullpo_retv(bl);
  6501. WBUFW(buf,0) = 0x132;
  6502. WBUFL(buf,2) = bl->id;
  6503. if( session_isActive(fd) ) {
  6504. WFIFOHEAD(fd,packet_len(0x132));
  6505. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6506. WFIFOSET(fd,packet_len(0x132));
  6507. } else {
  6508. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6509. }
  6510. }
  6511. /// Sends a list of items in a shop.
  6512. /// 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)
  6513. /// 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)
  6514. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6515. nullpo_retv( sd );
  6516. nullpo_retv( vsd );
  6517. nullpo_retv( vsd->vending );
  6518. int fd = sd->fd;
  6519. if( !session_isActive( fd ) ){
  6520. return;
  6521. }
  6522. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6523. WFIFOHEAD( fd, len );
  6524. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6525. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6526. p->packetLength = len;
  6527. p->AID = vsd->status.account_id;
  6528. #if PACKETVER >= 20100105
  6529. p->venderId = vsd->vender_id;
  6530. #endif
  6531. for( int i = 0; i < vsd->vend_num; i++ ){
  6532. int index = vsd->vending[i].index;
  6533. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6534. p->items[i].price = vsd->vending[i].value;
  6535. p->items[i].amount = vsd->vending[i].amount;
  6536. p->items[i].index = client_index( index );
  6537. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6538. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6539. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6540. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6541. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6542. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6543. #if PACKETVER >= 20150226
  6544. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6545. #if PACKETVER >= 20160921
  6546. p->items[i].location = pc_equippoint_sub( sd, data );
  6547. p->items[i].viewSprite = data->look;
  6548. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6549. p->items[i].enchantgrade = vsd->cart.u.items_cart[index].enchantgrade;
  6550. #endif
  6551. #endif
  6552. #endif
  6553. }
  6554. WFIFOSET( fd, len );
  6555. }
  6556. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6557. /// 0135 <index>.W <amount>.W <result>.B
  6558. /// result:
  6559. /// 0 = success
  6560. /// 1 = not enough zeny
  6561. /// 2 = overweight
  6562. /// 4 = out of stock
  6563. /// 5 = "cannot use an npc shop while in a trade"
  6564. /// 6 = Because the store information was incorrect the item was not purchased.
  6565. /// 7 = No sales information.
  6566. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6567. {
  6568. int fd;
  6569. nullpo_retv(sd);
  6570. fd = sd->fd;
  6571. WFIFOHEAD(fd,packet_len(0x135));
  6572. WFIFOW(fd,0) = 0x135;
  6573. WFIFOW(fd,2) = index+2;
  6574. WFIFOW(fd,4) = amount;
  6575. WFIFOB(fd,6) = fail;
  6576. WFIFOSET(fd,packet_len(0x135));
  6577. }
  6578. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6579. /// 0a28 <Result>.B
  6580. /// result:
  6581. /// 0 = Successed
  6582. /// 1 = Failed
  6583. void clif_openvending_ack(struct map_session_data* sd, int result)
  6584. {
  6585. int fd;
  6586. nullpo_retv(sd);
  6587. fd = sd->fd;
  6588. WFIFOHEAD(fd, 3);
  6589. WFIFOW(fd,0) = 0xa28;
  6590. WFIFOB(fd,2) = result;
  6591. WFIFOSET(fd, 3);
  6592. }
  6593. /// Shop creation success.
  6594. /// 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)
  6595. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6596. nullpo_retv( sd );
  6597. nullpo_retv( vending );
  6598. int fd = sd->fd;
  6599. if( !session_isActive( fd ) ){
  6600. return;
  6601. }
  6602. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6603. WFIFOHEAD( fd, len );
  6604. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6605. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6606. p->packetLength = len;
  6607. p->AID = id;
  6608. for( int i = 0; i < sd->vend_num; i++ ) {
  6609. int index = vending[i].index;
  6610. p->items[i].price = vending[i].value;
  6611. p->items[i].index = client_index( index );
  6612. p->items[i].amount = vending[i].amount;
  6613. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6614. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6615. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6616. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6617. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6618. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6619. #if PACKETVER >= 20150226
  6620. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6621. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6622. p->items[i].enchantgrade = sd->cart.u.items_cart[index].enchantgrade;
  6623. #endif
  6624. #endif
  6625. }
  6626. WFIFOSET( fd, len );
  6627. #if PACKETVER >= 20141022
  6628. /// 0 = Successed
  6629. /// 1 = Failed
  6630. clif_openvending_ack( sd, 0 );
  6631. #endif
  6632. }
  6633. /// Inform merchant that someone has bought an item.
  6634. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6635. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6636. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6637. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6638. const int cmd = 0x137;
  6639. #else
  6640. const int cmd = 0x9e5;
  6641. #endif
  6642. int fd = sd->fd;
  6643. nullpo_retv(sd);
  6644. WFIFOHEAD(fd,packet_len(cmd));
  6645. WFIFOW(fd,0) = cmd;
  6646. WFIFOW(fd,2) = index+2;
  6647. WFIFOW(fd,4) = amount;
  6648. #if PACKETVER >= 20141016
  6649. WFIFOL(fd,6) = char_id; // GID
  6650. WFIFOL(fd,10) = (int)time(NULL); // Date
  6651. WFIFOL(fd,14) = zeny; // zeny
  6652. #endif
  6653. WFIFOSET(fd,packet_len(cmd));
  6654. }
  6655. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6656. /// 00fa <result>.B
  6657. /// result:
  6658. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6659. /// 1 = MsgStringTable[78]="party name already exists"
  6660. /// 2 = MsgStringTable[79]="already in a party"
  6661. /// 3 = cannot organize parties on this map
  6662. /// ? = nothing
  6663. void clif_party_created(struct map_session_data *sd,int result)
  6664. {
  6665. int fd;
  6666. nullpo_retv(sd);
  6667. fd=sd->fd;
  6668. WFIFOHEAD(fd,packet_len(0xfa));
  6669. WFIFOW(fd,0)=0xfa;
  6670. WFIFOB(fd,2)=result;
  6671. WFIFOSET(fd,packet_len(0xfa));
  6672. }
  6673. /// Adds new member to a party.
  6674. /// 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)
  6675. /// 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)
  6676. /// 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)
  6677. /// role:
  6678. /// 0 = leader
  6679. /// 1 = normal
  6680. /// state:
  6681. /// 0 = connected
  6682. /// 1 = disconnected
  6683. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6684. {
  6685. int i;
  6686. #if PACKETVER < 20170502
  6687. unsigned char buf[81];
  6688. int cmd = 0x1e9;
  6689. int offset = 0;
  6690. #else
  6691. unsigned char buf[85];
  6692. int cmd = 0xa43;
  6693. int offset = 4;
  6694. #endif
  6695. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6696. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6697. } else {
  6698. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6699. }
  6700. if (i >= MAX_PARTY) return; //Should never happen...
  6701. sd = p->data[i].sd;
  6702. WBUFW(buf, 0) = cmd;
  6703. WBUFL(buf, 2) = sd->status.account_id;
  6704. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6705. #if PACKETVER >= 20170502
  6706. WBUFW(buf,10) = sd->status.class_;
  6707. WBUFW(buf,12) = sd->status.base_level;
  6708. #endif
  6709. WBUFW(buf,offset+10) = sd->bl.x;
  6710. WBUFW(buf,offset+12) = sd->bl.y;
  6711. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6712. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6713. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6714. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6715. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6716. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6717. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6718. }
  6719. /// Sends party information (ZC_GROUP_LIST).
  6720. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6721. /// role:
  6722. /// 0 = leader
  6723. /// 1 = normal
  6724. /// state:
  6725. /// 0 = connected
  6726. /// 1 = disconnected
  6727. /// 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
  6728. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6729. {
  6730. struct map_session_data* party_sd = NULL;
  6731. int i, c;
  6732. #if PACKETVER < 20170502
  6733. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6734. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6735. int cmd = 0xfb;
  6736. #else
  6737. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6738. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6739. int cmd = 0xa44;
  6740. #endif
  6741. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6742. nullpo_retv(p);
  6743. WBUFW(buf,0) = cmd;
  6744. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6745. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6746. {
  6747. struct party_member* m = &p->party.member[i];
  6748. if(!m->account_id) continue;
  6749. if(party_sd == NULL) party_sd = p->data[i].sd;
  6750. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6751. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6752. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6753. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6754. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6755. #if PACKETVER >= 20170502
  6756. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6757. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6758. #endif
  6759. c++;
  6760. }
  6761. #if PACKETVER < 20170502
  6762. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6763. #else
  6764. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6765. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6766. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6767. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6768. #endif
  6769. if(sd) { // send only to self
  6770. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6771. } else if (party_sd) { // send to whole party
  6772. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6773. }
  6774. }
  6775. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6776. /// 02c9 <flag>.B
  6777. /// flag:
  6778. /// 0 = allow party invites
  6779. /// 1 = auto-deny party invites
  6780. void clif_partyinvitationstate(struct map_session_data* sd)
  6781. {
  6782. int fd;
  6783. nullpo_retv(sd);
  6784. fd = sd->fd;
  6785. WFIFOHEAD(fd, packet_len(0x2c9));
  6786. WFIFOW(fd, 0) = 0x2c9;
  6787. WFIFOB(fd, 2) = 0; // not implemented
  6788. WFIFOSET(fd, packet_len(0x2c9));
  6789. }
  6790. /// Party invitation request.
  6791. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6792. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6793. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6794. {
  6795. #if PACKETVER < 20070821
  6796. const int cmd = 0xfe;
  6797. #else
  6798. const int cmd = 0x2c6;
  6799. #endif
  6800. int fd;
  6801. struct party_data *p;
  6802. nullpo_retv(sd);
  6803. nullpo_retv(tsd);
  6804. fd=tsd->fd;
  6805. if( (p=party_search(sd->status.party_id))==NULL )
  6806. return;
  6807. WFIFOHEAD(fd,packet_len(cmd));
  6808. WFIFOW(fd,0)=cmd;
  6809. WFIFOL(fd,2)=sd->status.party_id;
  6810. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6811. WFIFOSET(fd,packet_len(cmd));
  6812. }
  6813. /// Party invite result.
  6814. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6815. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6816. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6817. {
  6818. int fd;
  6819. nullpo_retv(sd);
  6820. fd=sd->fd;
  6821. #if PACKETVER < 20070904
  6822. if( reply == PARTY_REPLY_OFFLINE ) {
  6823. clif_displaymessage(fd, msg_txt(sd,3));
  6824. return;
  6825. }
  6826. #endif
  6827. #if PACKETVER < 20070821
  6828. WFIFOHEAD(fd,packet_len(0xfd));
  6829. WFIFOW(fd,0) = 0xfd;
  6830. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6831. WFIFOB(fd,26) = reply;
  6832. WFIFOSET(fd,packet_len(0xfd));
  6833. #else
  6834. WFIFOHEAD(fd,packet_len(0x2c5));
  6835. WFIFOW(fd,0) = 0x2c5;
  6836. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6837. WFIFOL(fd,26) = reply;
  6838. WFIFOSET(fd,packet_len(0x2c5));
  6839. #endif
  6840. }
  6841. /// Updates party settings.
  6842. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6843. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6844. /// exp option:
  6845. /// 0 = exp sharing disabled
  6846. /// 1 = exp sharing enabled
  6847. /// 2 = cannot change exp sharing
  6848. ///
  6849. /// flag:
  6850. /// 0 = send to party
  6851. /// 1 = send to sd
  6852. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6853. {
  6854. unsigned char buf[16];
  6855. #if PACKETVER < 20090603
  6856. const int cmd = 0x101;
  6857. #else
  6858. const int cmd = 0x7d8;
  6859. #endif
  6860. nullpo_retv(p);
  6861. if(!sd && flag==0){
  6862. int i;
  6863. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6864. if (i < MAX_PARTY)
  6865. sd = p->data[i].sd;
  6866. }
  6867. if(!sd) return;
  6868. WBUFW(buf,0)=cmd;
  6869. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6870. #if PACKETVER >= 20090603
  6871. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6872. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6873. #endif
  6874. if(flag==0)
  6875. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6876. else
  6877. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6878. }
  6879. /**
  6880. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6881. * @param sd Send the notification for this player
  6882. * @param account_id Account ID of kicked member
  6883. * @param name Name of kicked member
  6884. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6885. * @param target Send target
  6886. **/
  6887. 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) {
  6888. unsigned char buf[2+4+NAME_LENGTH+1];
  6889. if (!sd)
  6890. return;
  6891. WBUFW(buf,0) = 0x0105;
  6892. WBUFL(buf,2) = account_id;
  6893. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6894. WBUFB(buf,6+NAME_LENGTH) = result;
  6895. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6896. }
  6897. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6898. /// 0109 <packet len>.W <account id>.L <message>.?B
  6899. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6900. {
  6901. struct map_session_data *sd;
  6902. int i;
  6903. nullpo_retv(p);
  6904. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6905. if(i < MAX_PARTY){
  6906. unsigned char buf[1024];
  6907. if( len > sizeof(buf)-8 )
  6908. {
  6909. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6910. len = sizeof(buf)-8;
  6911. }
  6912. sd = p->data[i].sd;
  6913. WBUFW(buf,0)=0x109;
  6914. WBUFW(buf,2)=len+8;
  6915. WBUFL(buf,4)=account_id;
  6916. safestrncpy(WBUFCP(buf,8), mes, len);
  6917. clif_send(buf,len+8,&sd->bl,PARTY);
  6918. }
  6919. }
  6920. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6921. /// 0107 <account id>.L <x>.W <y>.W
  6922. void clif_party_xy(struct map_session_data *sd)
  6923. {
  6924. unsigned char buf[16];
  6925. nullpo_retv(sd);
  6926. WBUFW(buf,0)=0x107;
  6927. WBUFL(buf,2)=sd->status.account_id;
  6928. WBUFW(buf,6)=sd->bl.x;
  6929. WBUFW(buf,8)=sd->bl.y;
  6930. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6931. }
  6932. /*==========================================
  6933. * Sends x/y dot to a single fd. [Skotlex]
  6934. *------------------------------------------*/
  6935. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6936. {
  6937. WFIFOHEAD(fd,packet_len(0x107));
  6938. WFIFOW(fd,0)=0x107;
  6939. WFIFOL(fd,2)=sd->status.account_id;
  6940. WFIFOW(fd,6)=sd->bl.x;
  6941. WFIFOW(fd,8)=sd->bl.y;
  6942. WFIFOSET(fd,packet_len(0x107));
  6943. }
  6944. /// Updates HP bar of a party member.
  6945. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6946. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6947. void clif_party_hp(struct map_session_data *sd)
  6948. {
  6949. unsigned char buf[16];
  6950. #if PACKETVER < 20100126
  6951. const int cmd = 0x106;
  6952. #else
  6953. const int cmd = 0x80e;
  6954. #endif
  6955. nullpo_retv(sd);
  6956. WBUFW(buf,0)=cmd;
  6957. WBUFL(buf,2)=sd->status.account_id;
  6958. #if PACKETVER < 20100126
  6959. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6960. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6961. WBUFW(buf,8) = 100;
  6962. } else {
  6963. WBUFW(buf,6) = sd->battle_status.hp;
  6964. WBUFW(buf,8) = sd->battle_status.max_hp;
  6965. }
  6966. #else
  6967. WBUFL(buf,6) = sd->battle_status.hp;
  6968. WBUFL(buf,10) = sd->battle_status.max_hp;
  6969. #endif
  6970. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6971. }
  6972. /// Notifies the party members of a character's death or revival.
  6973. /// 0AB2 <GID>.L <dead>.B
  6974. void clif_party_dead( struct map_session_data *sd ){
  6975. #if PACKETVER >= 20170502
  6976. unsigned char buf[7];
  6977. nullpo_retv(sd);
  6978. WBUFW(buf, 0) = 0xab2;
  6979. WBUFL(buf, 2) = sd->status.account_id;
  6980. WBUFB(buf, 6) = pc_isdead(sd);
  6981. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6982. #endif
  6983. }
  6984. /// Updates the job and level of a party member
  6985. /// 0abd <account id>.L <job>.W <level>.W
  6986. void clif_party_job_and_level(struct map_session_data *sd){
  6987. #if PACKETVER >= 20170502
  6988. unsigned char buf[10];
  6989. nullpo_retv(sd);
  6990. WBUFW(buf, 0) = 0xabd;
  6991. WBUFL(buf, 2) = sd->status.account_id;
  6992. WBUFW(buf, 6) = sd->status.class_;
  6993. WBUFW(buf, 8) = sd->status.base_level;
  6994. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6995. #endif
  6996. }
  6997. /*==========================================
  6998. * Sends HP bar to a single fd. [Skotlex]
  6999. *------------------------------------------*/
  7000. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  7001. {
  7002. #if PACKETVER < 20100126
  7003. const int cmd = 0x106;
  7004. #else
  7005. const int cmd = 0x80e;
  7006. #endif
  7007. WFIFOHEAD(fd,packet_len(cmd));
  7008. WFIFOW(fd,0) = cmd;
  7009. WFIFOL(fd,2) = id;
  7010. #if PACKETVER < 20100126
  7011. if( maxhp > INT16_MAX )
  7012. {// To correctly display the %hp bar. [Skotlex]
  7013. WFIFOW(fd,6) = hp/(maxhp/100);
  7014. WFIFOW(fd,8) = 100;
  7015. } else {
  7016. WFIFOW(fd,6) = hp;
  7017. WFIFOW(fd,8) = maxhp;
  7018. }
  7019. #else
  7020. WFIFOL(fd,6) = hp;
  7021. WFIFOL(fd,10) = maxhp;
  7022. #endif
  7023. WFIFOSET(fd, packet_len(cmd));
  7024. }
  7025. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  7026. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  7027. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  7028. {
  7029. int fd;
  7030. nullpo_retv(sd);
  7031. nullpo_retv(bl);
  7032. fd=sd->fd;
  7033. WFIFOHEAD(fd,packet_len(0x139));
  7034. WFIFOW(fd, 0)=0x139;
  7035. WFIFOL(fd, 2)=bl->id;
  7036. WFIFOW(fd, 6)=bl->x;
  7037. WFIFOW(fd, 8)=bl->y;
  7038. WFIFOW(fd,10)=sd->bl.x;
  7039. WFIFOW(fd,12)=sd->bl.y;
  7040. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  7041. WFIFOSET(fd,packet_len(0x139));
  7042. }
  7043. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  7044. /// 018f <result>.W <name id>.W
  7045. /// result:
  7046. /// 0 = success
  7047. /// 1 = failure
  7048. /// 2 = success (alchemist)
  7049. /// 3 = failure (alchemist)
  7050. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  7051. nullpo_retv( sd );
  7052. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  7053. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  7054. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  7055. p.result = flag;
  7056. p.itemId = client_nameid( nameid );
  7057. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7058. }
  7059. /// Initiates the pet taming process (ZC_START_CAPTURE).
  7060. /// 019e
  7061. void clif_catch_process(struct map_session_data *sd)
  7062. {
  7063. int fd;
  7064. nullpo_retv(sd);
  7065. fd=sd->fd;
  7066. WFIFOHEAD(fd,packet_len(0x19e));
  7067. WFIFOW(fd,0)=0x19e;
  7068. WFIFOSET(fd,packet_len(0x19e));
  7069. }
  7070. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  7071. /// 01a0 <result>.B
  7072. /// 0 = failure
  7073. /// 1 = success
  7074. void clif_pet_roulette(struct map_session_data *sd,int data)
  7075. {
  7076. int fd;
  7077. nullpo_retv(sd);
  7078. fd=sd->fd;
  7079. WFIFOHEAD(fd,packet_len(0x1a0));
  7080. WFIFOW(fd,0)=0x1a0;
  7081. WFIFOB(fd,2)=data;
  7082. WFIFOSET(fd,packet_len(0x1a0));
  7083. }
  7084. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7085. /// 01a6 <packet len>.W { <index>.W }*
  7086. void clif_sendegg(struct map_session_data *sd)
  7087. {
  7088. int i,n=0,fd;
  7089. nullpo_retv(sd);
  7090. fd=sd->fd;
  7091. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7092. clif_displaymessage(fd, msg_txt(sd,666));
  7093. return;
  7094. }
  7095. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7096. WFIFOW(fd,0)=0x1a6;
  7097. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7098. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7099. sd->inventory_data[i]->type != IT_PETEGG ||
  7100. sd->inventory.u.items_inventory[i].amount <= 0)
  7101. continue;
  7102. WFIFOW(fd,n*2+4)=client_index(i);
  7103. n++;
  7104. }
  7105. WFIFOW(fd,2)=4+n*2;
  7106. WFIFOSET(fd,WFIFOW(fd,2));
  7107. sd->menuskill_id = SA_TAMINGMONSTER;
  7108. sd->menuskill_val = -1;
  7109. }
  7110. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7111. /// 01a4 <type>.B <id>.L <data>.L
  7112. /// type:
  7113. /// 0 = pre-init (data = 0)
  7114. /// 1 = intimacy (data = 0~4)
  7115. /// 2 = hunger (data = 0~4)
  7116. /// 3 = accessory
  7117. /// 4 = performance (data = 1~3: normal, 4: special)
  7118. /// 5 = hairstyle
  7119. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7120. ///
  7121. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7122. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  7123. {
  7124. uint8 buf[16];
  7125. nullpo_retv(pd);
  7126. WBUFW(buf,0) = 0x1a4;
  7127. WBUFB(buf,2) = type;
  7128. WBUFL(buf,3) = pd->bl.id;
  7129. WBUFL(buf,7) = param;
  7130. if (sd)
  7131. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7132. else
  7133. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7134. }
  7135. /// Pet's base data (ZC_PROPERTY_PET).
  7136. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7137. void clif_send_petstatus(struct map_session_data *sd)
  7138. {
  7139. int fd;
  7140. struct s_pet *pet;
  7141. nullpo_retv(sd);
  7142. nullpo_retv(sd->pd);
  7143. fd=sd->fd;
  7144. pet = &sd->pd->pet;
  7145. WFIFOHEAD(fd,packet_len(0x1a2));
  7146. WFIFOW(fd,0)=0x1a2;
  7147. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7148. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7149. WFIFOW(fd,27)=pet->level;
  7150. WFIFOW(fd,29)=pet->hungry;
  7151. WFIFOW(fd,31)=pet->intimate;
  7152. WFIFOW(fd,33)=pet->equip;
  7153. #if PACKETVER >= 20081126
  7154. WFIFOW(fd,35)=pet->class_;
  7155. #endif
  7156. WFIFOSET(fd,packet_len(0x1a2));
  7157. }
  7158. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7159. /// 01aa <id>.L <data>.L
  7160. /// data:
  7161. /// @see CZ_PET_ACT.
  7162. void clif_pet_emotion(struct pet_data *pd,int param)
  7163. {
  7164. unsigned char buf[16];
  7165. nullpo_retv(pd);
  7166. memset(buf,0,packet_len(0x1aa));
  7167. WBUFW(buf,0)=0x1aa;
  7168. WBUFL(buf,2)=pd->bl.id;
  7169. WBUFL(buf,6)=param;
  7170. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7171. }
  7172. /// Result of request to feed a pet (ZC_FEED_PET).
  7173. /// 01a3 <result>.B <name id>.W
  7174. /// result:
  7175. /// 0 = failure
  7176. /// 1 = success
  7177. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  7178. nullpo_retv( sd );
  7179. struct PACKET_ZC_FEED_PET p;
  7180. p.packetType = 0x1a3;
  7181. p.result = fail;
  7182. p.itemId = client_nameid( foodid );
  7183. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7184. }
  7185. /// Send pet auto feed info.
  7186. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  7187. #if PACKETVER >= 20141008
  7188. nullpo_retv(sd);
  7189. if (force || battle_config.pet_autofeed_always) {
  7190. // Always send ON or OFF
  7191. if (sd->pd && battle_config.feature_pet_autofeed) {
  7192. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7193. }
  7194. else {
  7195. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7196. }
  7197. }
  7198. else {
  7199. // Only send when enabled
  7200. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7201. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7202. }
  7203. }
  7204. #endif
  7205. }
  7206. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7207. /// 01cd { <skill id>.L }*7
  7208. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  7209. {
  7210. nullpo_retv(sd);
  7211. int fd = sd->fd;
  7212. #ifdef RENEWAL
  7213. uint16 autospell_skill[][2] = {
  7214. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7215. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7216. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7217. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7218. };
  7219. int count = 0;
  7220. WFIFOHEAD(fd, 2 * 6 + 4);
  7221. WFIFOW(fd, 0) = 0x442;
  7222. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7223. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7224. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7225. count++;
  7226. }
  7227. }
  7228. WFIFOW(fd, 2) = 8 + count * 2;
  7229. WFIFOL(fd, 4) = count;
  7230. WFIFOSET(fd, WFIFOW(fd, 2));
  7231. #else
  7232. WFIFOHEAD(fd,packet_len(0x1cd));
  7233. WFIFOW(fd, 0)=0x1cd;
  7234. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7235. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7236. else
  7237. WFIFOL(fd,2)= 0x00000000;
  7238. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7239. WFIFOL(fd,6)= MG_COLDBOLT;
  7240. else
  7241. WFIFOL(fd,6)= 0x00000000;
  7242. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7243. WFIFOL(fd,10)= MG_FIREBOLT;
  7244. else
  7245. WFIFOL(fd,10)= 0x00000000;
  7246. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7247. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7248. else
  7249. WFIFOL(fd,14)= 0x00000000;
  7250. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7251. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7252. else
  7253. WFIFOL(fd,18)= 0x00000000;
  7254. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7255. WFIFOL(fd,22)= MG_FIREBALL;
  7256. else
  7257. WFIFOL(fd,22)= 0x00000000;
  7258. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7259. WFIFOL(fd,26)= MG_FROSTDIVER;
  7260. else
  7261. WFIFOL(fd,26)= 0x00000000;
  7262. WFIFOSET(fd,packet_len(0x1cd));
  7263. #endif
  7264. sd->menuskill_id = SA_AUTOSPELL;
  7265. sd->menuskill_val = skill_lv;
  7266. }
  7267. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7268. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7269. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7270. {
  7271. unsigned char buf[56];
  7272. nullpo_retv(src);
  7273. memset(buf,0,packet_len(0x1cf));
  7274. WBUFW(buf,0) = 0x1cf;
  7275. WBUFL(buf,2) = src->id;
  7276. if( src->type == BL_MER )
  7277. {
  7278. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7279. if( md && md->master && md->devotion_flag )
  7280. WBUFL(buf,6) = md->master->bl.id;
  7281. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7282. }
  7283. else
  7284. {
  7285. int i;
  7286. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7287. if( sd == NULL )
  7288. return;
  7289. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7290. WBUFL(buf,6+4*i) = sd->devotion[i];
  7291. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7292. }
  7293. if( tsd )
  7294. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7295. else
  7296. clif_send(buf, packet_len(0x1cf), src, AREA);
  7297. }
  7298. /// Notifies the client of an object's spirits.
  7299. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7300. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7301. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7302. nullpo_retv( bl );
  7303. struct PACKET_ZC_SPIRITS p = {};
  7304. p.packetType = HEADER_ZC_SPIRITS;
  7305. p.GID = bl->id;
  7306. switch( bl->type ){
  7307. case BL_PC:
  7308. p.amount = ( (struct map_session_data*)bl )->spiritball;
  7309. break;
  7310. case BL_HOM:
  7311. p.amount = ( (struct homun_data*)bl )->homunculus.spiritball;
  7312. break;
  7313. }
  7314. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7315. }
  7316. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7317. /// 01d2 <account id>.L <delay>.L
  7318. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7319. {
  7320. unsigned char buf[32];
  7321. nullpo_retv(bl);
  7322. WBUFW(buf,0)=0x1d2;
  7323. WBUFL(buf,2)=bl->id;
  7324. WBUFL(buf,6)=client_tick(wait);
  7325. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7326. }
  7327. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7328. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7329. /// flag:
  7330. /// 0 = inactive
  7331. /// 1 = active
  7332. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7333. {
  7334. unsigned char buf[32];
  7335. nullpo_retv(src);
  7336. WBUFW(buf,0)=0x1d1;
  7337. WBUFL(buf,2)=src->id;
  7338. WBUFL(buf,6)=dst_id;
  7339. WBUFL(buf,10)=active;
  7340. clif_send(buf,packet_len(0x1d1),src,AREA);
  7341. }
  7342. /// MVP effect (ZC_MVP).
  7343. /// 010c <account id>.L
  7344. void clif_mvp_effect(struct map_session_data *sd)
  7345. {
  7346. unsigned char buf[16];
  7347. nullpo_retv(sd);
  7348. WBUFW(buf,0)=0x10c;
  7349. WBUFL(buf,2)=sd->bl.id;
  7350. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7351. }
  7352. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7353. /// 010a <name id>.W
  7354. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7355. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7356. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7357. p.itemId = client_nameid( nameid );
  7358. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7359. }
  7360. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7361. /// 010b <exp>.L
  7362. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7363. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7364. if (battle_config.mvp_exp_reward_message) {
  7365. char e_msg[CHAT_SIZE_MAX];
  7366. sprintf(e_msg, msg_txt(sd, 717), exp);
  7367. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7368. }
  7369. #else
  7370. int fd;
  7371. nullpo_retv(sd);
  7372. fd = sd->fd;
  7373. WFIFOHEAD(fd, packet_len(0x10b));
  7374. WFIFOW(fd,0) = 0x10b;
  7375. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7376. WFIFOSET(fd, packet_len(0x10b));
  7377. #endif
  7378. }
  7379. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7380. /// 010d
  7381. ///
  7382. /// "You are the MVP, but cannot obtain the reward because
  7383. /// you are overweight."
  7384. void clif_mvp_noitem(struct map_session_data* sd)
  7385. {
  7386. int fd = sd->fd;
  7387. WFIFOHEAD(fd,packet_len(0x10d));
  7388. WFIFOW(fd,0) = 0x10d;
  7389. WFIFOSET(fd,packet_len(0x10d));
  7390. }
  7391. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7392. /// 0167 <result>.B
  7393. /// result:
  7394. /// 0 = "Guild has been created."
  7395. /// 1 = "You are already in a Guild."
  7396. /// 2 = "That Guild Name already exists."
  7397. /// 3 = "You need the neccessary item to create a Guild."
  7398. void clif_guild_created(struct map_session_data *sd,int flag)
  7399. {
  7400. int fd;
  7401. nullpo_retv(sd);
  7402. fd=sd->fd;
  7403. WFIFOHEAD(fd,packet_len(0x167));
  7404. WFIFOW(fd,0)=0x167;
  7405. WFIFOB(fd,2)=flag;
  7406. WFIFOSET(fd,packet_len(0x167));
  7407. }
  7408. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7409. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7410. /// mode:
  7411. /// &0x01 = allow invite
  7412. /// &0x10 = allow expel
  7413. void clif_guild_belonginfo(struct map_session_data *sd)
  7414. {
  7415. int ps,fd;
  7416. struct guild* g;
  7417. nullpo_retv(sd);
  7418. nullpo_retv(g = sd->guild);
  7419. fd=sd->fd;
  7420. ps=guild_getposition(sd);
  7421. WFIFOHEAD(fd,packet_len(0x16c));
  7422. WFIFOW(fd,0)=0x16c;
  7423. WFIFOL(fd,2)=g->guild_id;
  7424. WFIFOL(fd,6)=g->emblem_id;
  7425. WFIFOL(fd,10)=g->position[ps].mode;
  7426. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7427. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7428. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7429. WFIFOSET(fd,packet_len(0x16c));
  7430. }
  7431. /// Guild member login notice.
  7432. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7433. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7434. /// status:
  7435. /// 0 = offline
  7436. /// 1 = online
  7437. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7438. {
  7439. unsigned char buf[64];
  7440. struct map_session_data* sd;
  7441. nullpo_retv(g);
  7442. WBUFW(buf, 0)=0x1f2;
  7443. WBUFL(buf, 2)=g->member[idx].account_id;
  7444. WBUFL(buf, 6)=g->member[idx].char_id;
  7445. WBUFL(buf,10)=flag;
  7446. if( ( sd = g->member[idx].sd ) != NULL )
  7447. {
  7448. WBUFW(buf,14) = sd->status.sex;
  7449. WBUFW(buf,16) = sd->status.hair;
  7450. WBUFW(buf,18) = sd->status.hair_color;
  7451. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7452. }
  7453. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7454. {
  7455. WBUFW(buf,14) = 0;
  7456. WBUFW(buf,16) = 0;
  7457. WBUFW(buf,18) = 0;
  7458. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7459. }
  7460. }
  7461. // Function `clif_guild_memberlogin_notice` sends info about
  7462. // logins and logouts of a guild member to the rest members.
  7463. // But at the 1st time (after a player login or map changing)
  7464. // the client won't show the message.
  7465. // So I suggest use this function for sending "first-time-info"
  7466. // to some player on entering the game or changing location.
  7467. // At next time the client would always show the message.
  7468. // The function sends all the statuses in the single packet
  7469. // to economize traffic. [LuzZza]
  7470. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7471. {
  7472. struct guild *g;
  7473. unsigned char buf[14*128];
  7474. int i, count=0, p_len;
  7475. nullpo_retv(sd);
  7476. p_len = packet_len(0x16d);
  7477. if(!(g = sd->guild))
  7478. return;
  7479. for(i=0; i<g->max_member; i++) {
  7480. if(g->member[i].account_id > 0 &&
  7481. g->member[i].account_id != sd->status.account_id) {
  7482. WBUFW(buf,count*p_len) = 0x16d;
  7483. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7484. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7485. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7486. count++;
  7487. }
  7488. }
  7489. clif_send(buf, p_len*count, &sd->bl, SELF);
  7490. }
  7491. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7492. /// 014e <menu flag>.L
  7493. /// menu flag:
  7494. /// 0x00 = Basic Info (always on)
  7495. /// &0x01 = Member manager
  7496. /// &0x02 = Positions
  7497. /// &0x04 = Skills
  7498. /// &0x10 = Expulsion list
  7499. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7500. /// &0x80 = Notice
  7501. void clif_guild_masterormember(struct map_session_data *sd)
  7502. {
  7503. int fd;
  7504. nullpo_retv(sd);
  7505. fd=sd->fd;
  7506. WFIFOHEAD(fd,packet_len(0x14e));
  7507. WFIFOW(fd,0) = 0x14e;
  7508. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7509. WFIFOSET(fd,packet_len(0x14e));
  7510. }
  7511. /// Guild basic information (Territories [Valaris])
  7512. /// 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)
  7513. /// 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)
  7514. /// 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)
  7515. void clif_guild_basicinfo(struct map_session_data *sd) {
  7516. int fd;
  7517. struct guild *g;
  7518. #if PACKETVER < 20160622
  7519. int cmd = 0x1b6;
  7520. int offset = NAME_LENGTH;
  7521. #else
  7522. int cmd = 0xa84;
  7523. int offset = 0;
  7524. #endif
  7525. nullpo_retv(sd);
  7526. fd = sd->fd;
  7527. if( (g = sd->guild) == NULL )
  7528. return;
  7529. WFIFOHEAD(fd,packet_len(cmd));
  7530. WFIFOW(fd, 0)=cmd;
  7531. WFIFOL(fd, 2)=g->guild_id;
  7532. WFIFOL(fd, 6)=g->guild_lv;
  7533. WFIFOL(fd,10)=g->connect_member;
  7534. WFIFOL(fd,14)=g->max_member;
  7535. WFIFOL(fd,18)=g->average_lv;
  7536. WFIFOL(fd,22)=(uint32)cap_value(g->exp, 0, MAX_GUILD_EXP);
  7537. WFIFOL(fd,26)=(uint32)cap_value(g->next_exp, 0, MAX_GUILD_EXP);
  7538. WFIFOL(fd,30)=0; // Tax Points
  7539. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7540. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7541. WFIFOL(fd,42)=g->emblem_id;
  7542. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7543. #if PACKETVER < 20160622
  7544. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7545. #endif
  7546. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7547. WFIFOL(fd,70+offset+16) = 0; // zeny
  7548. #if PACKETVER >= 20160622
  7549. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7550. #endif
  7551. WFIFOSET(fd,packet_len(cmd));
  7552. }
  7553. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7554. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7555. void clif_guild_allianceinfo(struct map_session_data *sd)
  7556. {
  7557. int fd,i,c;
  7558. struct guild *g;
  7559. nullpo_retv(sd);
  7560. if( (g = sd->guild) == NULL )
  7561. return;
  7562. fd = sd->fd;
  7563. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7564. WFIFOW(fd, 0)=0x14c;
  7565. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7566. struct guild_alliance *a=&g->alliance[i];
  7567. if(a->guild_id>0){
  7568. WFIFOL(fd,c*32+4)=a->opposition;
  7569. WFIFOL(fd,c*32+8)=a->guild_id;
  7570. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7571. c++;
  7572. }
  7573. }
  7574. WFIFOW(fd, 2)=c*32+4;
  7575. WFIFOSET(fd,WFIFOW(fd,2));
  7576. }
  7577. /// Guild member manager information
  7578. /// 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)
  7579. /// state:
  7580. /// 0 = offline
  7581. /// 1 = online
  7582. /// memo:
  7583. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7584. /// 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)
  7585. void clif_guild_memberlist(struct map_session_data *sd)
  7586. {
  7587. int fd;
  7588. int i,c;
  7589. struct guild *g;
  7590. #if PACKETVER < 20161026
  7591. int cmd = 0x154;
  7592. int size = 104;
  7593. #else
  7594. int cmd = 0xaa5;
  7595. int size = 34;
  7596. #endif
  7597. nullpo_retv(sd);
  7598. if( !session_isActive(fd = sd->fd) )
  7599. return;
  7600. if( (g = sd->guild) == NULL )
  7601. return;
  7602. WFIFOHEAD(fd, g->max_member * size + 4);
  7603. WFIFOW(fd, 0)=cmd;
  7604. for(i=0,c=0;i<g->max_member;i++){
  7605. struct guild_member *m=&g->member[i];
  7606. if(m->account_id==0)
  7607. continue;
  7608. WFIFOL(fd,c*size+ 4)=m->account_id;
  7609. WFIFOL(fd,c*size+ 8)=m->char_id;
  7610. WFIFOW(fd,c*size+12)=m->hair;
  7611. WFIFOW(fd,c*size+14)=m->hair_color;
  7612. WFIFOW(fd,c*size+16)=m->gender;
  7613. WFIFOW(fd,c*size+18)=m->class_;
  7614. WFIFOW(fd,c*size+20)=m->lv;
  7615. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7616. WFIFOL(fd,c*size+26)=m->online;
  7617. WFIFOL(fd,c*size+30)=m->position;
  7618. #if PACKETVER < 20161026
  7619. 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.
  7620. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7621. #else
  7622. WFIFOL(fd,c*size+34)=m->last_login;
  7623. #endif
  7624. c++;
  7625. }
  7626. WFIFOW(fd, 2)=c*size+4;
  7627. WFIFOSET(fd,WFIFOW(fd,2));
  7628. }
  7629. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7630. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7631. void clif_guild_positionnamelist(struct map_session_data *sd)
  7632. {
  7633. int i,fd;
  7634. struct guild *g;
  7635. nullpo_retv(sd);
  7636. if( (g = sd->guild) == NULL )
  7637. return;
  7638. fd = sd->fd;
  7639. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7640. WFIFOW(fd, 0)=0x166;
  7641. for(i=0;i<MAX_GUILDPOSITION;i++){
  7642. WFIFOL(fd,i*28+4)=i;
  7643. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7644. }
  7645. WFIFOW(fd,2)=i*28+4;
  7646. WFIFOSET(fd,WFIFOW(fd,2));
  7647. }
  7648. /// Guild position information (ZC_POSITION_INFO).
  7649. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7650. /// mode:
  7651. /// &0x01 = allow invite
  7652. /// &0x10 = allow expel
  7653. /// ranking:
  7654. /// TODO
  7655. void clif_guild_positioninfolist(struct map_session_data *sd)
  7656. {
  7657. int i,fd;
  7658. struct guild *g;
  7659. nullpo_retv(sd);
  7660. if( (g = sd->guild) == NULL )
  7661. return;
  7662. fd = sd->fd;
  7663. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7664. WFIFOW(fd, 0)=0x160;
  7665. for(i=0;i<MAX_GUILDPOSITION;i++){
  7666. struct guild_position *p=&g->position[i];
  7667. WFIFOL(fd,i*16+ 4)=i;
  7668. WFIFOL(fd,i*16+ 8)=p->mode;
  7669. WFIFOL(fd,i*16+12)=i;
  7670. WFIFOL(fd,i*16+16)=p->exp_mode;
  7671. }
  7672. WFIFOW(fd, 2)=i*16+4;
  7673. WFIFOSET(fd,WFIFOW(fd,2));
  7674. }
  7675. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7676. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7677. /// mode:
  7678. /// &0x01 = allow invite
  7679. /// &0x10 = allow expel
  7680. /// ranking:
  7681. /// TODO
  7682. void clif_guild_positionchanged(struct guild *g,int idx)
  7683. {
  7684. // FIXME: This packet is intended to update the clients after a
  7685. // commit of position info changes, not sending one packet per
  7686. // position.
  7687. struct map_session_data *sd;
  7688. unsigned char buf[128];
  7689. nullpo_retv(g);
  7690. WBUFW(buf, 0)=0x174;
  7691. WBUFW(buf, 2)=44; // packet len
  7692. // GUILD_REG_POSITION_INFO{
  7693. WBUFL(buf, 4)=idx;
  7694. WBUFL(buf, 8)=g->position[idx].mode;
  7695. WBUFL(buf,12)=idx;
  7696. WBUFL(buf,16)=g->position[idx].exp_mode;
  7697. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7698. // }*
  7699. if( (sd=guild_getavailablesd(g))!=NULL )
  7700. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7701. }
  7702. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7703. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7704. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7705. {
  7706. // FIXME: This packet is intended to update the clients after a
  7707. // commit of member position assignment changes, not sending one
  7708. // packet per position.
  7709. struct map_session_data *sd;
  7710. unsigned char buf[64];
  7711. nullpo_retv(g);
  7712. WBUFW(buf, 0)=0x156;
  7713. WBUFW(buf, 2)=16; // packet len
  7714. // MEMBER_POSITION_INFO{
  7715. WBUFL(buf, 4)=g->member[idx].account_id;
  7716. WBUFL(buf, 8)=g->member[idx].char_id;
  7717. WBUFL(buf,12)=g->member[idx].position;
  7718. // }*
  7719. if( (sd=guild_getavailablesd(g))!=NULL )
  7720. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7721. }
  7722. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7723. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7724. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7725. {
  7726. int fd;
  7727. nullpo_retv(sd);
  7728. nullpo_retv(g);
  7729. fd = sd->fd;
  7730. if( g->emblem_len <= 0 )
  7731. return;
  7732. WFIFOHEAD(fd,g->emblem_len+12);
  7733. WFIFOW(fd,0)=0x152;
  7734. WFIFOW(fd,2)=g->emblem_len+12;
  7735. WFIFOL(fd,4)=g->guild_id;
  7736. WFIFOL(fd,8)=g->emblem_id;
  7737. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7738. WFIFOSET(fd,WFIFOW(fd,2));
  7739. }
  7740. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7741. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7742. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7743. void clif_guild_emblem_area(struct block_list* bl)
  7744. {
  7745. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7746. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7747. PACKET_ZC_CHANGE_GUILD p{};
  7748. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7749. p.guild_id = status_get_guild_id(bl);
  7750. p.emblem_id = status_get_emblem_id(bl);
  7751. #if PACKETVER < 20190724
  7752. p.aid = bl->id;
  7753. #else
  7754. p.unknown = 0;
  7755. #endif
  7756. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7757. }
  7758. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7759. /// 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 }*
  7760. void clif_guild_skillinfo(struct map_session_data* sd)
  7761. {
  7762. int fd;
  7763. struct guild* g;
  7764. int i,c;
  7765. nullpo_retv(sd);
  7766. if( (g = sd->guild) == NULL )
  7767. return;
  7768. fd = sd->fd;
  7769. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7770. WFIFOW(fd,0) = 0x0162;
  7771. WFIFOW(fd,4) = g->skill_point;
  7772. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7773. {
  7774. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7775. {
  7776. int id = g->skill[i].id;
  7777. int p = 6 + c*37;
  7778. WFIFOW(fd,p+0) = id;
  7779. WFIFOL(fd,p+2) = skill_get_inf(id);
  7780. WFIFOW(fd,p+6) = g->skill[i].lv;
  7781. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7782. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7783. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7784. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7785. c++;
  7786. }
  7787. }
  7788. WFIFOW(fd,2) = 6 + c*37;
  7789. WFIFOSET(fd,WFIFOW(fd,2));
  7790. }
  7791. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7792. /// 016f <subject>.60B <notice>.120B
  7793. void clif_guild_notice(struct map_session_data* sd)
  7794. {
  7795. struct guild* g;
  7796. nullpo_retv(sd);
  7797. nullpo_retv(g = sd->guild);
  7798. int fd = sd->fd;
  7799. if ( !session_isActive(fd) )
  7800. return;
  7801. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7802. return;
  7803. WFIFOHEAD(fd,packet_len(0x16f));
  7804. WFIFOW(fd,0) = 0x16f;
  7805. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7806. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7807. WFIFOSET(fd,packet_len(0x16f));
  7808. }
  7809. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7810. /// 016a <guild id>.L <guild name>.24B
  7811. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7812. {
  7813. int fd;
  7814. nullpo_retv(sd);
  7815. nullpo_retv(g);
  7816. fd=sd->fd;
  7817. WFIFOHEAD(fd,packet_len(0x16a));
  7818. WFIFOW(fd,0)=0x16a;
  7819. WFIFOL(fd,2)=g->guild_id;
  7820. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7821. WFIFOSET(fd,packet_len(0x16a));
  7822. }
  7823. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7824. /// 0169 <answer>.B
  7825. /// answer:
  7826. /// 0 = Already in guild.
  7827. /// 1 = Offer rejected.
  7828. /// 2 = Offer accepted.
  7829. /// 3 = Guild full.
  7830. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7831. {
  7832. int fd;
  7833. nullpo_retv(sd);
  7834. fd=sd->fd;
  7835. WFIFOHEAD(fd,packet_len(0x169));
  7836. WFIFOW(fd,0)=0x169;
  7837. WFIFOB(fd,2)=flag;
  7838. WFIFOSET(fd,packet_len(0x169));
  7839. }
  7840. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7841. /// 015a <char name>.24B <reason>.40B
  7842. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7843. {
  7844. unsigned char buf[128];
  7845. nullpo_retv(sd);
  7846. WBUFW(buf, 0)=0x15a;
  7847. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7848. memcpy(WBUFP(buf,26),mes,40);
  7849. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7850. }
  7851. /// Notifies clients of a guild of an expelled member.
  7852. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7853. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7854. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7855. {
  7856. unsigned char buf[128];
  7857. #if PACKETVER < 20100803
  7858. const unsigned short cmd = 0x15c;
  7859. #else
  7860. const unsigned short cmd = 0x839;
  7861. #endif
  7862. nullpo_retv(sd);
  7863. WBUFW(buf,0) = cmd;
  7864. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7865. safestrncpy(WBUFCP(buf,26), mes, 40);
  7866. #if PACKETVER < 20100803
  7867. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7868. #endif
  7869. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7870. }
  7871. /// Guild expulsion list (ZC_BAN_LIST).
  7872. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7873. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7874. void clif_guild_expulsionlist(struct map_session_data* sd)
  7875. {
  7876. #if PACKETVER < 20100803
  7877. const int offset = NAME_LENGTH*2+40;
  7878. #else
  7879. const int offset = NAME_LENGTH+40;
  7880. #endif
  7881. int fd, i, c = 0;
  7882. struct guild* g;
  7883. nullpo_retv(sd);
  7884. if( (g = sd->guild) == NULL )
  7885. return;
  7886. fd = sd->fd;
  7887. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7888. WFIFOW(fd,0) = 0x163;
  7889. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7890. {
  7891. struct guild_expulsion* e = &g->expulsion[i];
  7892. if( e->account_id > 0 )
  7893. {
  7894. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7895. #if PACKETVER < 20100803
  7896. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7897. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7898. #else
  7899. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7900. #endif
  7901. c++;
  7902. }
  7903. }
  7904. WFIFOW(fd,2) = 4 + c*offset;
  7905. WFIFOSET(fd,WFIFOW(fd,2));
  7906. }
  7907. /// Guild chat message (ZC_GUILD_CHAT).
  7908. /// 017f <packet len>.W <message>.?B
  7909. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7910. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7911. struct map_session_data *sd;
  7912. uint8 buf[256];
  7913. if( len == 0 )
  7914. {
  7915. return;
  7916. }
  7917. else if( len > sizeof(buf)-5 )
  7918. {
  7919. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7920. len = sizeof(buf)-5;
  7921. }
  7922. WBUFW(buf, 0) = 0x17f;
  7923. WBUFW(buf, 2) = len + 5;
  7924. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7925. if ((sd = guild_getavailablesd(g)) != NULL)
  7926. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7927. }
  7928. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7929. /// 0171 <inviter account id>.L <guild name>.24B
  7930. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7931. {
  7932. int fd;
  7933. nullpo_retv(sd);
  7934. fd=sd->fd;
  7935. WFIFOHEAD(fd,packet_len(0x171));
  7936. WFIFOW(fd,0)=0x171;
  7937. WFIFOL(fd,2)=account_id;
  7938. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7939. WFIFOSET(fd,packet_len(0x171));
  7940. }
  7941. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7942. /// 0173 <answer>.B
  7943. /// answer:
  7944. /// 0 = Already allied.
  7945. /// 1 = You rejected the offer.
  7946. /// 2 = You accepted the offer.
  7947. /// 3 = They have too any alliances.
  7948. /// 4 = You have too many alliances.
  7949. /// 5 = Alliances are disabled.
  7950. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7951. {
  7952. int fd;
  7953. nullpo_retv(sd);
  7954. fd=sd->fd;
  7955. WFIFOHEAD(fd,packet_len(0x173));
  7956. WFIFOW(fd,0)=0x173;
  7957. WFIFOL(fd,2)=flag;
  7958. WFIFOSET(fd,packet_len(0x173));
  7959. }
  7960. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7961. /// 0184 <other guild id>.L <relation>.L
  7962. /// relation:
  7963. /// 0 = Ally
  7964. /// 1 = Enemy
  7965. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7966. {
  7967. nullpo_retv(sd);
  7968. int fd = sd->fd;
  7969. if ( !session_isActive(fd) )
  7970. return;
  7971. WFIFOHEAD(fd,packet_len(0x184));
  7972. WFIFOW(fd,0)=0x184;
  7973. WFIFOL(fd,2)=guild_id;
  7974. WFIFOL(fd,6)=flag;
  7975. WFIFOSET(fd,packet_len(0x184));
  7976. }
  7977. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7978. /// 0181 <result>.B
  7979. /// result:
  7980. /// 0 = Antagonist has been set.
  7981. /// 1 = Guild has too many Antagonists.
  7982. /// 2 = Already set as an Antagonist.
  7983. /// 3 = Antagonists are disabled.
  7984. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7985. {
  7986. int fd;
  7987. nullpo_retv(sd);
  7988. fd=sd->fd;
  7989. WFIFOHEAD(fd,packet_len(0x181));
  7990. WFIFOW(fd,0)=0x181;
  7991. WFIFOB(fd,2)=flag;
  7992. WFIFOSET(fd,packet_len(0x181));
  7993. }
  7994. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7995. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7996. /*
  7997. void clif_guild_allianceadded(struct guild *g,int idx)
  7998. {
  7999. unsigned char buf[64];
  8000. WBUFW(buf,0)=0x185;
  8001. WBUFL(buf,2)=g->alliance[idx].opposition;
  8002. WBUFL(buf,6)=g->alliance[idx].guild_id;
  8003. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  8004. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  8005. }
  8006. */
  8007. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  8008. /// 015e <reason>.L
  8009. /// 0 = success
  8010. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  8011. /// 2 = there are still members in the guild
  8012. void clif_guild_broken(struct map_session_data *sd,int flag)
  8013. {
  8014. int fd;
  8015. nullpo_retv(sd);
  8016. fd=sd->fd;
  8017. WFIFOHEAD(fd,packet_len(0x15e));
  8018. WFIFOW(fd,0)=0x15e;
  8019. WFIFOL(fd,2)=flag;
  8020. WFIFOSET(fd,packet_len(0x15e));
  8021. }
  8022. /// Displays emotion on an object (ZC_EMOTION).
  8023. /// 00c0 <id>.L <type>.B
  8024. /// type:
  8025. /// enum emotion_type
  8026. void clif_emotion(struct block_list *bl,int type)
  8027. {
  8028. unsigned char buf[8];
  8029. nullpo_retv(bl);
  8030. WBUFW(buf,0)=0xc0;
  8031. WBUFL(buf,2)=bl->id;
  8032. WBUFB(buf,6)=type;
  8033. clif_send(buf,packet_len(0xc0),bl,AREA);
  8034. }
  8035. /// Displays the contents of a talkiebox trap.
  8036. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  8037. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  8038. nullpo_retv( bl );
  8039. nullpo_retv( talkie );
  8040. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  8041. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  8042. p.aid = bl->id;
  8043. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  8044. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  8045. }
  8046. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  8047. /// 01ea <id>.L
  8048. void clif_wedding_effect(struct block_list *bl)
  8049. {
  8050. unsigned char buf[6];
  8051. nullpo_retv(bl);
  8052. WBUFW(buf,0) = 0x1ea;
  8053. WBUFL(buf,2) = bl->id;
  8054. clif_send(buf, packet_len(0x1ea), bl, AREA);
  8055. }
  8056. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  8057. /// 01e6 <partner name>.24B
  8058. void clif_callpartner(struct map_session_data *sd)
  8059. {
  8060. unsigned char buf[26];
  8061. nullpo_retv(sd);
  8062. WBUFW(buf,0) = 0x1e6;
  8063. if( sd->status.partner_id ) {
  8064. const char *p = map_charid2nick(sd->status.partner_id);
  8065. struct map_session_data *p_sd = pc_get_partner(sd);
  8066. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  8067. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  8068. else
  8069. WBUFB(buf,2) = 0;
  8070. } else {// Send zero-length name if no partner, to initialize the client buffer.
  8071. WBUFB(buf,2) = 0;
  8072. }
  8073. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  8074. }
  8075. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  8076. /// 01e4
  8077. /// This packet while still implemented by the client is no longer being officially used.
  8078. /*
  8079. void clif_marriage_process(struct map_session_data *sd)
  8080. {
  8081. int fd;
  8082. nullpo_retv(sd);
  8083. fd=sd->fd;
  8084. WFIFOHEAD(fd,packet_len(0x1e4));
  8085. WFIFOW(fd,0)=0x1e4;
  8086. WFIFOSET(fd,packet_len(0x1e4));
  8087. }
  8088. */
  8089. /// Notice of divorce (ZC_DIVORCE).
  8090. /// 0205 <partner name>.24B
  8091. void clif_divorced(struct map_session_data* sd, const char* name)
  8092. {
  8093. int fd;
  8094. nullpo_retv(sd);
  8095. fd=sd->fd;
  8096. WFIFOHEAD(fd,packet_len(0x205));
  8097. WFIFOW(fd,0)=0x205;
  8098. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8099. WFIFOSET(fd, packet_len(0x205));
  8100. }
  8101. /// Marriage proposal (ZC_REQ_COUPLE).
  8102. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8103. /// This packet while still implemented by the client is no longer being officially used.
  8104. /*
  8105. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  8106. {
  8107. nullpo_retv(sd);
  8108. WFIFOHEAD(fd,packet_len(0x1e2));
  8109. WFIFOW(fd,0) = 0x1e2;
  8110. WFIFOL(fd,2) = ssd->status.account_id;
  8111. WFIFOL(fd,6) = ssd->status.char_id;
  8112. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8113. WFIFOSET(fd, packet_len(0x1e2));
  8114. }
  8115. */
  8116. /*==========================================
  8117. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8118. *------------------------------------------*/
  8119. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8120. {
  8121. unsigned char buf[256];
  8122. if( len == 0 ) {
  8123. return;
  8124. } else if( len > sizeof(buf)-5 ) {
  8125. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8126. len = sizeof(buf)-5;
  8127. }
  8128. WBUFW(buf, 0) = 0x17f;
  8129. WBUFW(buf, 2) = len + 5;
  8130. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8131. clif_send(buf, WBUFW(buf,2), src, target);
  8132. }
  8133. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8134. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8135. /// 00cd <result>.B
  8136. /// result:
  8137. /// 0 = failure
  8138. /// 1 = success
  8139. void clif_GM_kickack(struct map_session_data *sd, int id)
  8140. {
  8141. int fd;
  8142. nullpo_retv(sd);
  8143. fd = sd->fd;
  8144. WFIFOHEAD(fd,packet_len(0xcd));
  8145. WFIFOW(fd,0) = 0xcd;
  8146. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8147. WFIFOSET(fd, packet_len(0xcd));
  8148. }
  8149. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  8150. {
  8151. nullpo_retv(tsd);
  8152. if (sd == NULL)
  8153. tsd->state.keepshop = true;
  8154. if (session_isActive(tsd->fd))
  8155. clif_authfail_fd(tsd->fd, 15);
  8156. else
  8157. map_quit(tsd);
  8158. if (sd)
  8159. clif_GM_kickack(sd, tsd->status.account_id);
  8160. }
  8161. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8162. /// 014a <result>.L
  8163. /// result:
  8164. /// 0 = "A manner point has been successfully aligned."
  8165. /// 1 = MP_FAILURE_EXHAUST
  8166. /// 2 = MP_FAILURE_ALREADY_GIVING
  8167. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8168. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8169. /// 5 = "You got a good point from %s."
  8170. void clif_manner_message(struct map_session_data* sd, uint32 type)
  8171. {
  8172. int fd;
  8173. nullpo_retv(sd);
  8174. fd = sd->fd;
  8175. WFIFOHEAD(fd,packet_len(0x14a));
  8176. WFIFOW(fd,0) = 0x14a;
  8177. WFIFOL(fd,2) = type;
  8178. WFIFOSET(fd, packet_len(0x14a));
  8179. }
  8180. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8181. /// 014b <type>.B <GM name>.24B
  8182. /// type:
  8183. /// 0 = positive (unmute)
  8184. /// 1 = negative (mute)
  8185. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  8186. {
  8187. int fd;
  8188. nullpo_retv(sd);
  8189. nullpo_retv(tsd);
  8190. fd = tsd->fd;
  8191. WFIFOHEAD(fd,packet_len(0x14b));
  8192. WFIFOW(fd,0) = 0x14b;
  8193. WFIFOB(fd,2) = type;
  8194. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8195. WFIFOSET(fd, packet_len(0x14b));
  8196. }
  8197. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8198. /// 00d1 <type>.B <result>.B
  8199. /// type:
  8200. /// 0 = /ex (deny)
  8201. /// 1 = /in (allow)
  8202. /// result:
  8203. /// 0 = success
  8204. /// 1 = failure
  8205. /// 2 = too many blocks
  8206. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  8207. {
  8208. int fd;
  8209. nullpo_retv(sd);
  8210. fd=sd->fd;
  8211. WFIFOHEAD(fd,packet_len(0xd1));
  8212. WFIFOW(fd,0)=0xd1;
  8213. WFIFOB(fd,2)=type;
  8214. WFIFOB(fd,3)=flag;
  8215. WFIFOSET(fd,packet_len(0xd1));
  8216. }
  8217. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8218. /// 00d2 <type>.B <result>.B
  8219. /// type:
  8220. /// 0 = /exall (deny)
  8221. /// 1 = /inall (allow)
  8222. /// result:
  8223. /// 0 = success
  8224. /// 1 = failure
  8225. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8226. {
  8227. int fd;
  8228. nullpo_retv(sd);
  8229. fd=sd->fd;
  8230. WFIFOHEAD(fd,packet_len(0xd2));
  8231. WFIFOW(fd,0)=0xd2;
  8232. WFIFOB(fd,2)=type;
  8233. WFIFOB(fd,3)=flag;
  8234. WFIFOSET(fd,packet_len(0xd2));
  8235. }
  8236. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8237. /// 07fe <bgm>.24B
  8238. void clif_playBGM(struct map_session_data* sd, const char* name)
  8239. {
  8240. int fd;
  8241. nullpo_retv(sd);
  8242. fd = sd->fd;
  8243. WFIFOHEAD(fd,packet_len(0x7fe));
  8244. WFIFOW(fd,0) = 0x7fe;
  8245. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8246. WFIFOSET(fd,packet_len(0x7fe));
  8247. }
  8248. /// Plays/stops a wave sound (ZC_SOUND).
  8249. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8250. /// file name:
  8251. /// relative to data\wav
  8252. /// act:
  8253. /// 0 = play (once)
  8254. /// 1 = play (repeat, does not work)
  8255. /// 2 = stops all sound instances of file name (does not work)
  8256. /// term:
  8257. /// unknown purpose, only relevant to act = 1
  8258. /// npc id:
  8259. /// The accustic direction of the sound is determined by the
  8260. /// relative position of the NPC to the player (3D sound).
  8261. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8262. {
  8263. int fd;
  8264. nullpo_retv(sd);
  8265. nullpo_retv(bl);
  8266. fd = sd->fd;
  8267. WFIFOHEAD(fd,packet_len(0x1d3));
  8268. WFIFOW(fd,0) = 0x1d3;
  8269. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8270. WFIFOB(fd,26) = type;
  8271. WFIFOL(fd,27) = 0;
  8272. WFIFOL(fd,31) = bl->id;
  8273. WFIFOSET(fd,packet_len(0x1d3));
  8274. }
  8275. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8276. {
  8277. unsigned char buf[40];
  8278. nullpo_retv(bl);
  8279. WBUFW(buf,0) = 0x1d3;
  8280. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8281. WBUFB(buf,26) = type;
  8282. WBUFL(buf,27) = 0;
  8283. WBUFL(buf,31) = bl->id;
  8284. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8285. }
  8286. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8287. /// 01f3 <id>.L <effect id>.L
  8288. /// effect id:
  8289. /// @see doc/effect_list.txt
  8290. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8291. {
  8292. unsigned char buf[24];
  8293. nullpo_retv(bl);
  8294. memset(buf, 0, packet_len(0x1f3));
  8295. WBUFW(buf,0) = 0x1f3;
  8296. WBUFL(buf,2) = bl->id;
  8297. WBUFL(buf,6) = type;
  8298. clif_send(buf, packet_len(0x1f3), bl, target);
  8299. if (disguised(bl)) {
  8300. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8301. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8302. }
  8303. }
  8304. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8305. {
  8306. WFIFOHEAD(fd,10);
  8307. WFIFOW(fd,0) = 0x1f3;
  8308. WFIFOL(fd,2) = bl->id;
  8309. WFIFOL(fd,6) = type;
  8310. WFIFOSET(fd,10);
  8311. }
  8312. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8313. /// 0284 <id>.L <effect id>.L <num data>.L
  8314. /// effect id:
  8315. /// @see doc/effect_list.txt
  8316. /// num data:
  8317. /// effect-dependent value
  8318. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8319. {
  8320. uint8 buf[14];
  8321. WBUFW(buf,0) = 0x284;
  8322. WBUFL(buf,2) = bl->id;
  8323. WBUFL(buf,6) = effect_id;
  8324. WBUFL(buf,10) = num;
  8325. clif_send(buf, packet_len(0x284), bl, target);
  8326. if( disguised(bl) )
  8327. {
  8328. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8329. clif_send(buf, packet_len(0x284), bl, SELF);
  8330. }
  8331. }
  8332. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8333. {
  8334. #if PACKETVER >= 20181002
  8335. nullpo_retv( bl_src );
  8336. nullpo_retv( bl_target );
  8337. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8338. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8339. p.aid = bl_src->id;
  8340. p.effectId = effect;
  8341. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8342. if( disguised(bl_src) )
  8343. {
  8344. p.aid = disguised_bl_id( bl_src->id );
  8345. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8346. }
  8347. #endif
  8348. }
  8349. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8350. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8351. 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) {
  8352. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8353. uint8 buf[CHAT_SIZE_MAX];
  8354. nullpo_retv(bl);
  8355. if (msg_len > sizeof(buf) - 12) {
  8356. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8357. msg_len = sizeof(buf) - 12;
  8358. }
  8359. if (rgb2bgr)
  8360. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8361. WBUFW(buf,0) = 0x2C1;
  8362. WBUFW(buf,2) = msg_len + 12;
  8363. WBUFL(buf,4) = bl->id;
  8364. WBUFL(buf,8) = color;
  8365. memcpy(WBUFCP(buf,12), msg, msg_len);
  8366. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8367. }
  8368. /**
  8369. * Notifies the client that the storage window is still open
  8370. *
  8371. * Should only be used in cases where the client closed the
  8372. * storage window without server's consent
  8373. */
  8374. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8375. // Notify the client that the storage is open
  8376. if( sd->state.storage_flag == 1 ) {
  8377. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8378. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8379. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8380. }
  8381. // Notify the client that the gstorage is open otherwise it will
  8382. // remain locked forever and nobody will be able to access it
  8383. if( sd->state.storage_flag == 2 ) {
  8384. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8385. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8386. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8387. else {
  8388. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8389. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8390. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8391. }
  8392. }
  8393. // Notify the client that the premium storage is open
  8394. if (sd->state.storage_flag == 3) {
  8395. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8396. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8397. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8398. }
  8399. }
  8400. // refresh the client's screen, getting rid of any effects
  8401. void clif_refresh(struct map_session_data *sd)
  8402. {
  8403. nullpo_retv(sd);
  8404. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8405. clif_inventorylist(sd);
  8406. clif_equipswitch_list(sd);
  8407. if(pc_iscarton(sd)) {
  8408. clif_cartlist(sd);
  8409. clif_updatestatus(sd,SP_CARTINFO);
  8410. }
  8411. clif_updatestatus(sd,SP_WEIGHT);
  8412. clif_updatestatus(sd,SP_MAXWEIGHT);
  8413. clif_updatestatus(sd,SP_STR);
  8414. clif_updatestatus(sd,SP_AGI);
  8415. clif_updatestatus(sd,SP_VIT);
  8416. clif_updatestatus(sd,SP_INT);
  8417. clif_updatestatus(sd,SP_DEX);
  8418. clif_updatestatus(sd,SP_LUK);
  8419. #ifdef RENEWAL
  8420. clif_updatestatus(sd,SP_POW);
  8421. clif_updatestatus(sd,SP_STA);
  8422. clif_updatestatus(sd,SP_WIS);
  8423. clif_updatestatus(sd,SP_SPL);
  8424. clif_updatestatus(sd,SP_CON);
  8425. clif_updatestatus(sd,SP_CRT);
  8426. #endif
  8427. if (sd->spiritball)
  8428. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8429. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8430. clif_millenniumshield_single(sd->fd, sd);
  8431. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8432. clif_spiritcharm_single(sd->fd, sd);
  8433. if (sd->soulball)
  8434. clif_soulball( sd, &sd->bl, SELF );
  8435. if (sd->servantball)
  8436. clif_servantball( *sd, &sd->bl, SELF );
  8437. if (sd->abyssball)
  8438. clif_abyssball( *sd, &sd->bl, SELF );
  8439. if (sd->vd.cloth_color)
  8440. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8441. if (sd->vd.body_style)
  8442. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8443. if(hom_is_active(sd->hd))
  8444. clif_send_homdata(sd,SP_ACK,0);
  8445. if( sd->md ) {
  8446. clif_mercenary_info(sd);
  8447. clif_mercenary_skillblock(sd);
  8448. }
  8449. if( sd->ed )
  8450. clif_elemental_info(sd);
  8451. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8452. clif_weather_check(sd);
  8453. if( sd->chatID )
  8454. chat_leavechat(sd,0);
  8455. if( sd->state.vending )
  8456. clif_openvending(sd, sd->bl.id, sd->vending);
  8457. if( pc_issit(sd) )
  8458. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8459. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8460. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8461. else
  8462. clif_changed_dir(&sd->bl, SELF);
  8463. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8464. //Issue #2143
  8465. //Cancel Trading State
  8466. if (sd->state.trading)
  8467. trade_tradecancel(sd);
  8468. //Cancel Buying/Selling State
  8469. if (sd->state.buyingstore)
  8470. buyingstore_close(sd);
  8471. mail_clear(sd);
  8472. clif_loadConfirm( sd );
  8473. if( disguised(&sd->bl) ) {/* refresh-da */
  8474. short disguise = sd->disguise;
  8475. pc_disguise(sd, 0);
  8476. pc_disguise(sd, disguise);
  8477. }
  8478. clif_refresh_storagewindow(sd);
  8479. }
  8480. /// Updates the object's (bl) name on client.
  8481. /// Used to update when a char leaves a party/guild. [Skotlex]
  8482. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8483. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8484. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8485. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8486. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8487. nullpo_retv( src );
  8488. nullpo_retv( bl );
  8489. switch( bl->type ){
  8490. case BL_PC: {
  8491. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8492. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8493. packet.gid = bl->id;
  8494. map_session_data *sd = (map_session_data *)bl;
  8495. //Requesting your own "shadow" name. [Skotlex]
  8496. if( src == bl && target == SELF && sd->disguise ){
  8497. packet.gid = -bl->id;
  8498. }
  8499. if( sd->fakename[0] ) {
  8500. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8501. clif_send( &packet, sizeof(packet), src, target );
  8502. return;
  8503. }
  8504. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8505. party_data *p = nullptr;
  8506. if( sd->status.party_id ){
  8507. p = party_search( sd->status.party_id );
  8508. }
  8509. // do not display party unless the player is also in a guild
  8510. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8511. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8512. }
  8513. if( sd->guild ){
  8514. int position;
  8515. // Will get the position of the guild the player is in
  8516. position = guild_getposition( sd );
  8517. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8518. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8519. }else if( sd->clan ){
  8520. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8521. }
  8522. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8523. packet.title_id = sd->status.title_id; // Title ID
  8524. #endif
  8525. clif_send(&packet, sizeof(packet), src, target);
  8526. }
  8527. break;
  8528. //[blackhole89]
  8529. case BL_HOM:
  8530. case BL_MER:
  8531. case BL_PET:
  8532. case BL_NPC:
  8533. case BL_ELEM: {
  8534. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8535. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8536. packet.gid = bl->id;
  8537. switch (bl->type) {
  8538. case BL_HOM:
  8539. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8540. break;
  8541. case BL_MER:
  8542. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8543. break;
  8544. case BL_PET:
  8545. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8546. break;
  8547. case BL_NPC:
  8548. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8549. break;
  8550. case BL_ELEM:
  8551. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8552. break;
  8553. }
  8554. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8555. unit_data *ud = unit_bl2ud(bl);
  8556. if (ud != nullptr) {
  8557. memcpy(packet.title, ud->title, NAME_LENGTH);
  8558. packet.groupId = ud->group_id;
  8559. }
  8560. #endif
  8561. clif_send(&packet, sizeof(packet), src, target);
  8562. }
  8563. break;
  8564. case BL_MOB: {
  8565. mob_data *md = (mob_data *)bl;
  8566. if( md->guardian_data && md->guardian_data->guild_id ){
  8567. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8568. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8569. packet.gid = bl->id;
  8570. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8571. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8572. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8573. clif_send(&packet, sizeof(packet), src, target);
  8574. }else if( battle_config.show_mob_info ){
  8575. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8576. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8577. packet.gid = bl->id;
  8578. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8579. char mobhp[50], *str_p = mobhp;
  8580. if( battle_config.show_mob_info&4 ){
  8581. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8582. }
  8583. if( battle_config.show_mob_info&1 ){
  8584. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8585. }
  8586. if( battle_config.show_mob_info&2 ){
  8587. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8588. }
  8589. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8590. if( str_p != mobhp ){
  8591. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8592. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8593. }
  8594. clif_send(&packet, sizeof(packet), src, target);
  8595. } else {
  8596. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8597. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8598. packet.gid = bl->id;
  8599. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8600. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8601. unit_data *ud = unit_bl2ud(bl);
  8602. if (ud != nullptr) {
  8603. memcpy(packet.title, ud->title, NAME_LENGTH);
  8604. packet.groupId = ud->group_id;
  8605. }
  8606. #endif
  8607. clif_send(&packet, sizeof(packet), src, target);
  8608. }
  8609. }
  8610. break;
  8611. case BL_CHAT:
  8612. case BL_SKILL:
  8613. // Newer clients request this, but do not need an answer
  8614. return;
  8615. default:
  8616. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8617. return;
  8618. }
  8619. }
  8620. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8621. /// 01ff <id>.L <x>.W <y>.W
  8622. ///
  8623. /// Visually moves(instant) a character to x,y. The char moves even
  8624. /// when the target cell isn't walkable. If the char is sitting it
  8625. /// stays that way.
  8626. void clif_slide(struct block_list *bl, int x, int y)
  8627. {
  8628. unsigned char buf[10];
  8629. nullpo_retv(bl);
  8630. WBUFW(buf, 0) = 0x01ff;
  8631. WBUFL(buf, 2) = bl->id;
  8632. WBUFW(buf, 6) = x;
  8633. WBUFW(buf, 8) = y;
  8634. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8635. if( disguised(bl) )
  8636. {
  8637. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8638. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8639. }
  8640. }
  8641. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8642. /// 008d <packet len>.W <id>.L <message>.?B
  8643. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8644. {
  8645. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8646. int len_mes = strlen(mes)+1; //Account for \0
  8647. if (len_mes > sizeof(buf)-8) {
  8648. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8649. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8650. }
  8651. // send message to others
  8652. if (flag == AREA) {
  8653. WBUFW(buf,0) = 0x8d;
  8654. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8655. WBUFL(buf,4) = bl->id;
  8656. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8657. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8658. }
  8659. // send back message to the speaker
  8660. if( bl->type == BL_PC ) {
  8661. WBUFW(buf,0) = 0x8e;
  8662. WBUFW(buf, 2) = len_mes + 4;
  8663. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8664. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8665. }
  8666. }
  8667. /*==========================
  8668. * Minimap fix [Kevin]
  8669. * Remove dot from minimap
  8670. *--------------------------*/
  8671. void clif_party_xy_remove(struct map_session_data *sd)
  8672. {
  8673. unsigned char buf[16];
  8674. nullpo_retv(sd);
  8675. WBUFW(buf,0)=0x107;
  8676. WBUFL(buf,2)=sd->status.account_id;
  8677. WBUFW(buf,6)=-1;
  8678. WBUFW(buf,8)=-1;
  8679. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8680. }
  8681. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8682. /// 0215 <msg id>.L
  8683. /// msg id:
  8684. /// 0x15 = End all negative status (PA_GOSPEL)
  8685. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8686. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8687. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8688. /// 0x19 = All stats +20 (PA_GOSPEL)
  8689. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8690. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8691. /// 0x1e = DEF +25% (PA_GOSPEL)
  8692. /// 0x1f = ATK +100% (PA_GOSPEL)
  8693. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8694. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8695. /// ? = nothing
  8696. void clif_gospel_info(struct map_session_data *sd, int type)
  8697. {
  8698. int fd=sd->fd;
  8699. WFIFOHEAD(fd,packet_len(0x215));
  8700. WFIFOW(fd,0)=0x215;
  8701. WFIFOL(fd,2)=type;
  8702. WFIFOSET(fd, packet_len(0x215));
  8703. }
  8704. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8705. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8706. /// result:
  8707. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8708. /// star:
  8709. /// 0 = Place of the Sun
  8710. /// 1 = Place of the Moon
  8711. /// 2 = Place of the Stars
  8712. /// 1 = Star Gladiator %s's %s: <mapname>
  8713. /// star:
  8714. /// 0 = Place of the Sun
  8715. /// 1 = Place of the Moon
  8716. /// 2 = Place of the Stars
  8717. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8718. /// star:
  8719. /// 0 = Target of the Sun
  8720. /// 1 = Target of the Moon
  8721. /// 2 = Target of the Stars
  8722. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8723. /// star:
  8724. /// 0 = Monster of the Sun
  8725. /// 1 = Monster of the Moon
  8726. /// 2 = Monster of the Stars
  8727. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8728. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8729. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8730. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8731. /// 40 = Target HP : <monster_id used as HP>
  8732. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8733. {
  8734. int fd = sd->fd;
  8735. WFIFOHEAD(fd,packet_len(0x20e));
  8736. WFIFOW(fd,0) = 0x20e;
  8737. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8738. WFIFOL(fd,26) = monster_id;
  8739. WFIFOB(fd,30) = star;
  8740. WFIFOB(fd,31) = result;
  8741. WFIFOSET(fd,packet_len(0x20e));
  8742. }
  8743. /*==========================================
  8744. * Info about Star Glaldiator save map [Komurka]
  8745. * type: 1: Information, 0: Map registered
  8746. *------------------------------------------*/
  8747. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8748. {
  8749. char mapname[MAP_NAME_LENGTH_EXT];
  8750. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8751. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8752. }
  8753. /*==========================================
  8754. * Info about Star Glaldiator hate mob [Komurka]
  8755. * type: 1: Register mob, 0: Information.
  8756. *------------------------------------------*/
  8757. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8758. {
  8759. if( pcdb_checkid(class_) ) {
  8760. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8761. } else if( mobdb_checkid(class_) ) {
  8762. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8763. } else {
  8764. 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);
  8765. }
  8766. }
  8767. /*==========================================
  8768. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8769. *------------------------------------------*/
  8770. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8771. {
  8772. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8773. }
  8774. /*==========================================
  8775. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8776. *------------------------------------------*/
  8777. void clif_feel_hate_reset(struct map_session_data *sd)
  8778. {
  8779. clif_starskill(sd, "", 0, 0, 30);
  8780. }
  8781. /// Send out reply to configuration change
  8782. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8783. /// type: see enum e_config_type
  8784. /// value:
  8785. /// false = disabled
  8786. /// true = enabled
  8787. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8788. int fd;
  8789. nullpo_retv(sd);
  8790. fd = sd->fd;
  8791. WFIFOHEAD(fd, packet_len(0x2d9));
  8792. WFIFOW(fd, 0) = 0x2d9;
  8793. WFIFOL(fd, 2) = type;
  8794. WFIFOL(fd, 6) = enabled;
  8795. WFIFOSET(fd, packet_len(0x2d9));
  8796. }
  8797. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8798. /// 02da <open equip window>.B
  8799. /// open equip window:
  8800. /// 0 = disabled
  8801. /// 1 = enabled
  8802. void clif_equipcheckbox(struct map_session_data* sd)
  8803. {
  8804. int fd;
  8805. nullpo_retv(sd);
  8806. fd = sd->fd;
  8807. WFIFOHEAD(fd, packet_len(0x2da));
  8808. WFIFOW(fd, 0) = 0x2da;
  8809. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8810. WFIFOSET(fd, packet_len(0x2da));
  8811. }
  8812. /// Sends info about a player's equipped items.
  8813. /// 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)
  8814. /// 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)
  8815. /// 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)
  8816. /// 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)
  8817. /// 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)
  8818. /// 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)
  8819. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8820. nullpo_retv( sd );
  8821. nullpo_retv( tsd );
  8822. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8823. int equip = 0;
  8824. for( int i = 0; i < EQI_MAX; i++ ){
  8825. int k = tsd->equip_index[i];
  8826. if( k >= 0 ){
  8827. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8828. continue;
  8829. }
  8830. if( !tsd->inventory.u.items_inventory[k].equip ){
  8831. continue;
  8832. }
  8833. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8834. continue;
  8835. }
  8836. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8837. }
  8838. }
  8839. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8840. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8841. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8842. p->job = tsd->status.class_;
  8843. p->head = tsd->vd.hair_style;
  8844. p->accessory = tsd->vd.head_bottom;
  8845. p->accessory2 = tsd->vd.head_mid;
  8846. p->accessory3 = tsd->vd.head_top;
  8847. #if PACKETVER >= 20110111
  8848. p->robe = tsd->vd.robe;
  8849. #endif
  8850. p->headpalette = tsd->vd.hair_color;
  8851. p->bodypalette = tsd->vd.cloth_color;
  8852. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8853. p->body2 = tsd->vd.body_style;
  8854. #endif
  8855. p->sex = tsd->vd.sex;
  8856. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8857. }
  8858. /// Display msgstringtable.txt string (ZC_MSG).
  8859. /// 0291 <message>.W
  8860. void clif_msg(struct map_session_data* sd, unsigned short id)
  8861. {
  8862. int fd;
  8863. nullpo_retv(sd);
  8864. fd = sd->fd;
  8865. WFIFOHEAD(fd, packet_len(0x291));
  8866. WFIFOW(fd, 0) = 0x291;
  8867. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8868. WFIFOSET(fd, packet_len(0x291));
  8869. }
  8870. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8871. /// 0x7e2 <message>.W <value>.L
  8872. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8873. {
  8874. int fd = sd->fd;
  8875. WFIFOHEAD(fd, packet_len(0x7e2));
  8876. WFIFOW(fd,0) = 0x7e2;
  8877. WFIFOW(fd,2) = id;
  8878. WFIFOL(fd,4) = value;
  8879. WFIFOSET(fd, packet_len(0x7e2));
  8880. }
  8881. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8882. /// 07e6 <skill id>.W <msg id>.L
  8883. ///
  8884. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8885. /// "[SkillName] Message"
  8886. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8887. {
  8888. int fd = sd->fd;
  8889. WFIFOHEAD(fd, packet_len(0x7e6));
  8890. WFIFOW(fd,0) = 0x7e6;
  8891. WFIFOW(fd,2) = skill_id;
  8892. WFIFOL(fd,4) = msg_id;
  8893. WFIFOSET(fd, packet_len(0x7e6));
  8894. }
  8895. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8896. /// 09cd <msg id>.W <color>.L
  8897. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8898. nullpo_retv(sd);
  8899. int fd = sd->fd;
  8900. WFIFOHEAD(fd, packet_len(0x9cd));
  8901. WFIFOW(fd, 0) = 0x9cd;
  8902. WFIFOW(fd, 2) = msg_id;
  8903. WFIFOL(fd, 4) = color;
  8904. WFIFOSET(fd, packet_len(0x9cd));
  8905. }
  8906. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8907. /// Returns true if the packet was parsed successfully.
  8908. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8909. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8910. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8911. const char* seperator = " : ";
  8912. int fd;
  8913. struct s_packet_db* info;
  8914. uint16 packetLength, inputLength;
  8915. const char *input, *name, *message;
  8916. size_t nameLength, messageLength;
  8917. fd = sd->fd;
  8918. info = &packet_db[RFIFOW(fd,0)];
  8919. packetLength = RFIFOW(fd,info->pos[0]);
  8920. input = RFIFOCP(fd,info->pos[1]);
  8921. // basic structure check for the 4-byte header
  8922. if( packetLength < 4 ){
  8923. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8924. return false;
  8925. }else{
  8926. inputLength = packetLength - 4;
  8927. }
  8928. // process <name> part of the packet
  8929. if( whisperFormat ) {
  8930. // name has fixed width
  8931. if( inputLength < NAME_LENGTH + 1 ) {
  8932. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8933. return false;
  8934. }
  8935. name = input;
  8936. // validate name
  8937. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8938. // only restriction is that the name must be zero-terminated
  8939. if( name[nameLength] != '\0' ) {
  8940. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8941. return false;
  8942. }
  8943. message = input + NAME_LENGTH;
  8944. messageLength = inputLength - NAME_LENGTH;
  8945. }else{
  8946. // name and message are separated by ' : '
  8947. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8948. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8949. // check if there's enough data provided
  8950. if( inputLength < nameLength + seperatorLength + 1 ){
  8951. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8952. return false;
  8953. }
  8954. name = input;
  8955. // validate name
  8956. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8957. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8958. {
  8959. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8960. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8961. set_eof(sd->fd); // Just kick them out to correct it.
  8962. return false;
  8963. }
  8964. message = input + nameLength + seperatorLength;
  8965. messageLength = inputLength - nameLength - seperatorLength;
  8966. }
  8967. #if PACKETVER < 20151001
  8968. // the declared length must match real length
  8969. if( messageLength != strnlen(message, messageLength)+1 ) {
  8970. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8971. return false;
  8972. }
  8973. // verify <message> part of the packet
  8974. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8975. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8976. return false;
  8977. }
  8978. #else
  8979. // No zero termination anymore
  8980. messageLength += 1;
  8981. #endif
  8982. // messages mustn't be too long
  8983. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8984. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8985. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8986. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8987. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8988. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8989. return false;
  8990. }
  8991. // If it is not a whisper message, set the name to the fakename of the player
  8992. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8993. strcpy( out_name, sd->fakename );
  8994. }else{
  8995. safestrncpy( out_name, name, nameLength + 1 );
  8996. }
  8997. safestrncpy( out_message, message, messageLength );
  8998. if( whisperFormat ){
  8999. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  9000. out_full_message[nameLength] = '\0';
  9001. }else{
  9002. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  9003. }
  9004. if( is_atcommand( fd, sd, out_message, 1 ) )
  9005. return false;
  9006. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  9007. return false; //no "chatting" while muted.
  9008. if( battle_config.min_chat_delay ) { //[Skotlex]
  9009. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9010. return false;
  9011. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9012. }
  9013. if (battle_config.idletime_option&IDLE_CHAT)
  9014. sd->idletime = last_tick;
  9015. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  9016. sd->idletime_hom = last_tick;
  9017. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  9018. sd->idletime_mer = last_tick;
  9019. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  9020. return true;
  9021. }
  9022. /**
  9023. * Displays a message if the player enters a PK Zone (during pk_mode)
  9024. * @param sd: Player data
  9025. */
  9026. inline void clif_pk_mode_message(struct map_session_data * sd)
  9027. {
  9028. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  9029. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  9030. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  9031. char output[CHAT_SIZE_MAX];
  9032. // 1504: You've entered a PK Zone (safe until level %d).
  9033. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  9034. battle_config.pk_min_level);
  9035. clif_showscript(&sd->bl, output, SELF);
  9036. } else {
  9037. // 1503: You've entered a PK Zone.
  9038. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  9039. }
  9040. }
  9041. return;
  9042. }
  9043. // ---------------------
  9044. // clif_parse_wanttoconnect
  9045. // ---------------------
  9046. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  9047. // error codes:
  9048. // 0 - Success
  9049. // 1 - Unknown packet_ver
  9050. // 2 - Invalid account_id
  9051. // 3 - Invalid char_id
  9052. // 4 - Invalid login_id1 (reserved)
  9053. // 5 - Invalid client_tick (reserved)
  9054. // 6 - Invalid sex
  9055. // Only the first 'invalid' error that appears is used.
  9056. static int clif_parse_WantToConnection_sub(int fd)
  9057. {
  9058. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  9059. unsigned short cmd;
  9060. //By default, start searching on the default one.
  9061. cmd = RFIFOW(fd, 0);
  9062. packet_len = RFIFOREST(fd);
  9063. // FIXME: If the packet is not received at once, this will FAIL.
  9064. // Figure out, when it happens, that only part of the packet is
  9065. // received, or fix the function to be able to deal with that
  9066. // case.
  9067. if( packet_len != packet_db[cmd].len )
  9068. return 1; /* wrong length */
  9069. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  9070. return 2; /* invalid account_id */
  9071. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  9072. return 3; /* invalid char_id */
  9073. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  9074. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  9075. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  9076. return 6; /* invalid sex */
  9077. else
  9078. return 0;
  9079. }
  9080. /// Request to connect to map-server.
  9081. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  9082. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  9083. /// There are various variants of this packet, some of them have padding between fields.
  9084. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  9085. {
  9086. struct block_list* bl;
  9087. struct auth_node* node;
  9088. int cmd, account_id, char_id, login_id1, sex, err;
  9089. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  9090. if (sd) {
  9091. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9092. return;
  9093. }
  9094. cmd = RFIFOW(fd, 0);
  9095. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9096. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9097. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9098. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9099. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9100. err = clif_parse_WantToConnection_sub(fd);
  9101. if( err ){ // connection rejected
  9102. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9103. err == 1 ? "." :
  9104. err == 2 ? ", possibly for having an invalid account_id." :
  9105. err == 3 ? ", possibly for having an invalid char_id." :
  9106. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9107. err == 4 ? ", possibly for having an invalid login_id1." :
  9108. err == 5 ? ", possibly for having an invalid client_tick." :
  9109. */
  9110. err == 6 ? ", possibly for having an invalid sex." :
  9111. ". ERROR invalid error code"));
  9112. WFIFOHEAD(fd,packet_len(0x6a));
  9113. WFIFOW(fd,0) = 0x6a;
  9114. WFIFOB(fd,2) = err;
  9115. WFIFOSET(fd,packet_len(0x6a));
  9116. #ifdef DUMP_INVALID_PACKET
  9117. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9118. #endif
  9119. RFIFOSKIP(fd, RFIFOREST(fd));
  9120. set_eof(fd);
  9121. return;
  9122. }
  9123. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  9124. clif_authfail_fd(fd,1);// server closed
  9125. return;
  9126. }
  9127. //Check for double login.
  9128. bl = map_id2bl(account_id);
  9129. if(bl && bl->type != BL_PC) {
  9130. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9131. WFIFOHEAD(fd,packet_len(0x6a));
  9132. WFIFOW(fd,0) = 0x6a;
  9133. WFIFOB(fd,2) = 3; // Rejected by server
  9134. WFIFOSET(fd,packet_len(0x6a));
  9135. set_eof(fd);
  9136. return;
  9137. }
  9138. if (bl ||
  9139. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9140. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9141. {
  9142. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9143. return;
  9144. }
  9145. CREATE(sd, TBL_PC, 1);
  9146. sd->fd = fd;
  9147. #ifdef PACKET_OBFUSCATION
  9148. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9149. #endif
  9150. session[fd]->session_data = sd;
  9151. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9152. #if PACKETVER < 20070521
  9153. WFIFOHEAD(fd,4);
  9154. WFIFOL(fd,0) = sd->bl.id;
  9155. WFIFOSET(fd,4);
  9156. #else
  9157. WFIFOHEAD(fd,packet_len(0x283));
  9158. WFIFOW(fd,0) = 0x283;
  9159. WFIFOL(fd,2) = sd->bl.id;
  9160. WFIFOSET(fd,packet_len(0x283));
  9161. #endif
  9162. chrif_authreq(sd,false);
  9163. }
  9164. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9165. /// 007d
  9166. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  9167. {
  9168. bool guild_notice = false;
  9169. if(sd->bl.prev != NULL)
  9170. return;
  9171. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9172. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9173. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9174. sd->state.connect_new = 0;
  9175. return;
  9176. }
  9177. if (sd->state.rewarp) { //Rewarp player.
  9178. sd->state.rewarp = 0;
  9179. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9180. return;
  9181. }
  9182. sd->state.warping = 0;
  9183. // look
  9184. #if PACKETVER < 4
  9185. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9186. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9187. #else
  9188. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9189. #endif
  9190. pc_set_costume_view(sd);
  9191. if(sd->vd.cloth_color)
  9192. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9193. if(sd->vd.body_style)
  9194. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9195. // item
  9196. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9197. pc_checkitem(sd);
  9198. clif_equipswitch_list(sd);
  9199. // cart
  9200. if(pc_iscarton(sd)) {
  9201. clif_cartlist(sd);
  9202. clif_updatestatus(sd,SP_CARTINFO);
  9203. }
  9204. // weight
  9205. clif_updatestatus(sd,SP_WEIGHT);
  9206. clif_updatestatus(sd,SP_MAXWEIGHT);
  9207. // guild
  9208. // (needs to go before clif_spawn() to show guild emblems correctly)
  9209. if(sd->status.guild_id)
  9210. guild_send_memberinfoshort(sd,1);
  9211. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9212. if(battle_config.pc_invincible_time > 0) {
  9213. if(mapdata_flag_gvg(mapdata))
  9214. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9215. else
  9216. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9217. }
  9218. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9219. map_spawnmobs(sd->bl.m);
  9220. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9221. mapdata->users_pvp++;
  9222. }
  9223. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9224. // reset the callshop flag if the player changes map
  9225. sd->state.callshop = 0;
  9226. if(map_addblock(&sd->bl))
  9227. return;
  9228. clif_spawn(&sd->bl);
  9229. // Party
  9230. // (needs to go after clif_spawn() to show hp bars correctly)
  9231. if(sd->status.party_id) {
  9232. party_send_movemap(sd);
  9233. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  9234. }
  9235. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9236. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9237. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9238. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9239. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9240. sd->pvp_rank = 0;
  9241. sd->pvp_lastusers = 0;
  9242. sd->pvp_point = 5;
  9243. sd->pvp_won = 0;
  9244. sd->pvp_lost = 0;
  9245. }
  9246. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9247. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9248. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9249. else if (mapdata->flag[MF_GVG_DUNGEON])
  9250. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9251. else if( mapdata_flag_gvg(mapdata) )
  9252. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9253. else
  9254. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9255. // info about nearby objects
  9256. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9257. 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);
  9258. // pet
  9259. if( sd->pd ) {
  9260. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9261. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9262. pet_return_egg( sd, sd->pd );
  9263. } else {
  9264. if(map_addblock(&sd->pd->bl))
  9265. return;
  9266. clif_spawn(&sd->pd->bl);
  9267. clif_send_petdata(sd,sd->pd,0,0);
  9268. clif_send_petstatus(sd);
  9269. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9270. }
  9271. }
  9272. //homunculus [blackhole89]
  9273. if( hom_is_active(sd->hd) ) {
  9274. if(map_addblock(&sd->hd->bl))
  9275. return;
  9276. clif_spawn(&sd->hd->bl);
  9277. clif_send_homdata(sd,SP_ACK,0);
  9278. clif_hominfo(sd,sd->hd,1);
  9279. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9280. clif_homskillinfoblock(sd);
  9281. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9282. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9283. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9284. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9285. }
  9286. if( sd->md ) {
  9287. if(map_addblock(&sd->md->bl))
  9288. return;
  9289. clif_spawn(&sd->md->bl);
  9290. clif_mercenary_info(sd);
  9291. clif_mercenary_skillblock(sd);
  9292. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9293. }
  9294. if( sd->ed ) {
  9295. if (map_addblock(&sd->ed->bl))
  9296. return;
  9297. clif_spawn(&sd->ed->bl);
  9298. clif_elemental_info(sd);
  9299. clif_elemental_updatestatus(sd,SP_HP);
  9300. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9301. clif_elemental_updatestatus(sd,SP_SP);
  9302. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9303. }
  9304. if(sd->state.connect_new) {
  9305. int lv;
  9306. guild_notice = true;
  9307. clif_skillinfoblock(sd);
  9308. clif_hotkeys_send(sd,0);
  9309. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9310. clif_hotkeys_send(sd,1);
  9311. #endif
  9312. clif_updatestatus(sd,SP_BASEEXP);
  9313. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9314. clif_updatestatus(sd,SP_JOBEXP);
  9315. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9316. clif_updatestatus(sd,SP_SKILLPOINT);
  9317. clif_initialstatus(sd);
  9318. if (sd->sc.option&OPTION_FALCON)
  9319. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9320. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9321. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9322. else if (sd->sc.option&OPTION_WUGRIDER)
  9323. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9324. else if (sd->sc.data[SC_ALL_RIDING])
  9325. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9326. if(sd->status.manner < 0)
  9327. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9328. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9329. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9330. if(sd->bl.m == sd->feel_map[0].m
  9331. || sd->bl.m == sd->feel_map[1].m
  9332. || sd->bl.m == sd->feel_map[2].m)
  9333. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9334. }
  9335. if(sd->pd && sd->pd->pet.intimate > 900)
  9336. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9337. if(hom_is_active(sd->hd))
  9338. hom_init_timers(sd->hd);
  9339. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9340. sd->state.night = 1;
  9341. clif_status_load(&sd->bl, EFST_SKE, 1);
  9342. }
  9343. // Notify everyone that this char logged in [Skotlex].
  9344. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9345. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9346. //Login Event
  9347. npc_script_event(sd, NPCE_LOGIN);
  9348. }
  9349. } else {
  9350. //For some reason the client "loses" these on warp/map-change.
  9351. clif_updatestatus(sd,SP_STR);
  9352. clif_updatestatus(sd,SP_AGI);
  9353. clif_updatestatus(sd,SP_VIT);
  9354. clif_updatestatus(sd,SP_INT);
  9355. clif_updatestatus(sd,SP_DEX);
  9356. clif_updatestatus(sd,SP_LUK);
  9357. #ifdef RENEWAL
  9358. clif_updatestatus(sd,SP_POW);
  9359. clif_updatestatus(sd,SP_STA);
  9360. clif_updatestatus(sd,SP_WIS);
  9361. clif_updatestatus(sd,SP_SPL);
  9362. clif_updatestatus(sd,SP_CON);
  9363. clif_updatestatus(sd,SP_CRT);
  9364. #endif
  9365. // abort currently running script
  9366. sd->state.using_fake_npc = 0;
  9367. sd->state.menu_or_input = 0;
  9368. sd->npc_menu = 0;
  9369. if(sd->npc_id)
  9370. npc_event_dequeue(sd);
  9371. }
  9372. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9373. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9374. #if PACKETVER >= 20070918
  9375. clif_partyinvitationstate(sd);
  9376. clif_equipcheckbox(sd);
  9377. #endif
  9378. clif_pet_autofeed_status(sd,false);
  9379. #if PACKETVER >= 20170920
  9380. if( battle_config.homunculus_autofeed_always ){
  9381. // Always send ON or OFF
  9382. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9383. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9384. }else{
  9385. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9386. }
  9387. }else{
  9388. // Only send when enabled
  9389. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9390. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9391. }
  9392. }
  9393. #endif
  9394. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9395. clif_guild_notice(sd); // Displays after VIP
  9396. guild_notice = false; // Do not display it twice
  9397. }
  9398. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9399. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9400. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9401. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9402. }
  9403. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9404. { //Display night.
  9405. if( !sd->state.night )
  9406. {
  9407. sd->state.night = 1;
  9408. clif_status_load(&sd->bl, EFST_SKE, 1);
  9409. }
  9410. }
  9411. else if( sd->state.night )
  9412. { //Clear night display.
  9413. sd->state.night = 0;
  9414. clif_status_load(&sd->bl, EFST_SKE, 0);
  9415. }
  9416. if( mapdata->flag[MF_BATTLEGROUND] )
  9417. {
  9418. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9419. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9420. clif_bg_updatescore_single(sd);
  9421. }
  9422. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9423. {
  9424. char output[128];
  9425. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9426. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9427. }
  9428. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9429. mapdata->hpmeter_visible++;
  9430. sd->state.hpmeter_visible = 1;
  9431. }
  9432. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9433. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9434. #ifdef VIP_ENABLE
  9435. if (!sd->state.connect_new &&
  9436. !sd->vip.disableshowrate &&
  9437. sd->state.pmap != sd->bl.m &&
  9438. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9439. )
  9440. {
  9441. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9442. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9443. }
  9444. #endif
  9445. // Instances do not need their own channels
  9446. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9447. channel_mjoin(sd); //join new map
  9448. clif_pk_mode_message(sd);
  9449. }
  9450. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9451. clif_guild_notice(sd); // Displays at end
  9452. }
  9453. mail_clear(sd);
  9454. /* Guild Aura Init */
  9455. if( sd->guild && sd->state.gmaster_flag ) {
  9456. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9457. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9458. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9459. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9460. }
  9461. if( sd->state.vending ) { /* show we have a vending */
  9462. clif_openvending(sd,sd->bl.id,sd->vending);
  9463. clif_showvendingboard(&sd->bl,sd->message,0);
  9464. }
  9465. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9466. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9467. npc_script_event(sd, NPCE_LOADMAP);
  9468. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9469. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9470. if (sd->sc.opt2) //Client loses these on warp.
  9471. clif_changeoption(&sd->bl);
  9472. 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)) {
  9473. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9474. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9475. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9476. }
  9477. clif_weather_check(sd);
  9478. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9479. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9480. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9481. else
  9482. sd->areanpc.clear();
  9483. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9484. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9485. pc_setdead(sd);
  9486. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9487. if(pc_isdead(sd))
  9488. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9489. else {
  9490. skill_usave_trigger(sd);
  9491. if (battle_config.spawn_direction)
  9492. clif_changed_dir(&sd->bl, SELF);
  9493. }
  9494. // Trigger skill effects if you appear standing on them
  9495. if(!battle_config.pc_invincible_time)
  9496. skill_unit_move(&sd->bl,gettick(),1);
  9497. pc_show_questinfo_reinit(sd);
  9498. pc_show_questinfo(sd);
  9499. #if PACKETVER >= 20150513
  9500. if( sd->mail.inbox.unread ){
  9501. clif_Mail_new(sd, 0, NULL, NULL);
  9502. }
  9503. #endif
  9504. sd->state.connect_new = 0;
  9505. sd->state.changemap = false;
  9506. }
  9507. /// Server's tick (ZC_NOTIFY_TIME).
  9508. /// 007f <time>.L
  9509. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9510. {
  9511. int fd = sd->fd;
  9512. WFIFOHEAD(fd,packet_len(0x7f));
  9513. WFIFOW(fd,0) = 0x7f;
  9514. WFIFOL(fd,2) = client_tick(time);
  9515. WFIFOSET(fd,packet_len(0x7f));
  9516. }
  9517. /// Request for server's tick.
  9518. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9519. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9520. /// There are various variants of this packet, some of them have padding between fields.
  9521. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9522. {
  9523. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9524. clif_notify_time(sd, gettick());
  9525. }
  9526. /// Sends hotkey bar.
  9527. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9528. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9529. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9530. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9531. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9532. #ifdef HOTKEY_SAVING
  9533. nullpo_retv( sd );
  9534. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9535. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9536. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9537. if( tab == 0 ){
  9538. p.rotate = sd->status.hotkey_rowshift;
  9539. }else{
  9540. p.rotate = sd->status.hotkey_rowshift2;
  9541. }
  9542. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9543. p.tab = tab;
  9544. #endif
  9545. #endif
  9546. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9547. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9548. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9549. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9550. }
  9551. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9552. #endif
  9553. }
  9554. /// Request to update a position on the hotkey row bar
  9555. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9556. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9557. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9558. if( p->tab == 0 ){
  9559. sd->status.hotkey_rowshift = p->rowshift;
  9560. }else{
  9561. sd->status.hotkey_rowshift2 = p->rowshift;
  9562. }
  9563. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9564. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9565. sd->status.hotkey_rowshift = p->rowshift;
  9566. #endif
  9567. }
  9568. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9569. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9570. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9571. #ifdef HOTKEY_SAVING
  9572. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9573. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9574. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9575. if( idx >= MAX_HOTKEYS_DB ){
  9576. return;
  9577. }
  9578. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9579. sd->status.hotkeys[idx].id = p->hotkey.id;
  9580. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9581. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9582. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9583. const unsigned short idx = p->index;
  9584. if( idx >= MAX_HOTKEYS_DB ){
  9585. return;
  9586. }
  9587. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9588. sd->status.hotkeys[idx].id = p->hotkey.id;
  9589. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9590. #endif
  9591. #endif
  9592. }
  9593. /// Displays cast-like progress bar (ZC_PROGRESS).
  9594. /// 02f0 <color>.L <time>.L
  9595. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9596. {
  9597. int fd = sd->fd;
  9598. WFIFOHEAD(fd,packet_len(0x2f0));
  9599. WFIFOW(fd,0) = 0x2f0;
  9600. WFIFOL(fd,2) = color;
  9601. WFIFOL(fd,6) = second;
  9602. WFIFOSET(fd,packet_len(0x2f0));
  9603. }
  9604. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9605. /// 02f2
  9606. void clif_progressbar_abort(struct map_session_data * sd)
  9607. {
  9608. int fd = sd->fd;
  9609. WFIFOHEAD(fd,packet_len(0x2f2));
  9610. WFIFOW(fd,0) = 0x2f2;
  9611. WFIFOSET(fd,packet_len(0x2f2));
  9612. }
  9613. /// Notification from the client, that the progress bar has reached 100%.
  9614. /// 02f1 (CZ_PROGRESS)
  9615. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9616. // No progressbar active, ignore it
  9617. if( !sd->progressbar.npc_id ){
  9618. return;
  9619. }
  9620. int npc_id = sd->progressbar.npc_id;
  9621. bool closing = false;
  9622. // Check if the progress was canceled
  9623. if( gettick() < sd->progressbar.timeout && sd->st ){
  9624. closing = true;
  9625. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9626. // If a message window was open, offer a close button to the user
  9627. if( sd->st->mes_active ){
  9628. clif_scriptclose( sd, npc_id );
  9629. }
  9630. }
  9631. sd->progressbar.npc_id = 0;
  9632. sd->progressbar.timeout = 0;
  9633. sd->state.workinprogress = WIP_DISABLE_NONE;
  9634. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9635. sd->idletime = last_tick;
  9636. }
  9637. npc_scriptcont(sd, npc_id, closing);
  9638. }
  9639. /// Displays cast-like progress bar on a NPC
  9640. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9641. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9642. #if PACKETVER >= 20130821
  9643. unsigned char buf[14];
  9644. if( nd->progressbar.timeout > 0 ){
  9645. WBUFW(buf,0) = 0x9d1;
  9646. WBUFL(buf,2) = nd->bl.id;
  9647. WBUFL(buf,6) = nd->progressbar.color;
  9648. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9649. if( sd ){
  9650. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9651. }else{
  9652. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9653. }
  9654. }
  9655. #endif
  9656. }
  9657. /// Request to walk to a certain position on the current map.
  9658. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9659. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9660. /// There are various variants of this packet, some of them have padding between fields.
  9661. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9662. {
  9663. short x, y;
  9664. if (pc_isdead(sd)) {
  9665. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9666. return;
  9667. }
  9668. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9669. ; //You CAN walk on this OPT1 value.
  9670. else if (sd->progressbar.npc_id) {
  9671. clif_progressbar_abort(sd);
  9672. return; // First walk attempt cancels the progress bar
  9673. } else if (pc_cant_act(sd))
  9674. return;
  9675. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9676. return;
  9677. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9678. //A move command one cell west is only valid if the target cell is free
  9679. if(battle_config.official_cell_stack_limit > 0
  9680. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9681. return;
  9682. // Cloaking wall check is actually updated when you click to process next movement
  9683. // not when you move each cell. This is official behaviour.
  9684. if (sd->sc.data[SC_CLOAKING])
  9685. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9686. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9687. status_change_end(&sd->bl, SC_CRESCIVEBOLT, INVALID_TIMER);
  9688. pc_delinvincibletimer(sd);
  9689. //Set last idle time... [Skotlex]
  9690. if (battle_config.idletime_option&IDLE_WALK)
  9691. sd->idletime = last_tick;
  9692. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9693. sd->idletime_hom = last_tick;
  9694. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9695. sd->idletime_mer = last_tick;
  9696. unit_walktoxy(&sd->bl, x, y, 4);
  9697. }
  9698. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9699. /// 018b <result>.W
  9700. /// result:
  9701. /// 0 = disconnect (quit)
  9702. /// 1 = cannot disconnect (wait 10 seconds)
  9703. /// ? = ignored
  9704. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9705. {
  9706. int fd = sd->fd;
  9707. WFIFOHEAD(fd,packet_len(0x18b));
  9708. WFIFOW(fd,0) = 0x18b;
  9709. WFIFOW(fd,2) = result;
  9710. WFIFOSET(fd,packet_len(0x18b));
  9711. }
  9712. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9713. /// 018a <type>.W
  9714. /// type:
  9715. /// 0 = quit
  9716. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9717. {
  9718. /* Rovert's prevent logout option fixed [Valaris] */
  9719. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9720. 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] &&
  9721. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9722. {
  9723. pc_damage_log_clear(sd,0);
  9724. clif_disconnect_ack(sd, 0);
  9725. flush_fifo( fd );
  9726. if( battle_config.drop_connection_on_quit ){
  9727. set_eof( fd );
  9728. }
  9729. } else {
  9730. clif_disconnect_ack(sd, 1);
  9731. }
  9732. }
  9733. /// Requesting unit's name.
  9734. /// 0094 <id>.L (CZ_REQNAME)
  9735. /// 0368 <id>.L (CZ_REQNAME2)
  9736. /// There are various variants of this packet, some of them have padding between fields.
  9737. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9738. {
  9739. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9740. struct block_list* bl;
  9741. //struct status_change *sc;
  9742. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9743. id = sd->bl.id;
  9744. bl = map_id2bl(id);
  9745. if( bl == NULL )
  9746. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9747. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9748. return; // Block namerequests past view range
  9749. // 'see people in GM hide' cheat detection
  9750. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9751. sc = status_get_sc(bl);
  9752. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9753. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9754. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9755. ) {
  9756. char gm_msg[256];
  9757. 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);
  9758. ShowWarning(gm_msg);
  9759. // information is sent to all online GMs
  9760. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9761. return;
  9762. }
  9763. */
  9764. clif_name(&sd->bl,bl,SELF);
  9765. }
  9766. /// Validates and processes global messages
  9767. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9768. /// There are various variants of this packet.
  9769. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9770. {
  9771. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9772. size_t length;
  9773. // validate packet and retrieve name and message
  9774. if( !clif_process_message(sd, false, name, message, output ) )
  9775. return;
  9776. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9777. channel_send(sd->gcbind,sd,message);
  9778. return;
  9779. }
  9780. // send message to others (using the send buffer for temp. storage)
  9781. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9782. length = strlen(output) + 1;
  9783. // send back message to the speaker
  9784. WFIFOHEAD(fd,4+length);
  9785. WFIFOW(fd,0) = 0x8e;
  9786. WFIFOW(fd,2) = (uint16)(4+length);
  9787. safestrncpy(WFIFOCP(fd,4), output, length );
  9788. WFIFOSET(fd, WFIFOW(fd,2));
  9789. #ifdef PCRE_SUPPORT
  9790. // trigger listening npcs
  9791. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9792. #endif
  9793. // Chat logging type 'O' / Global Chat
  9794. 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);
  9795. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9796. }
  9797. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9798. /// Request to warp to a map on given coordinates.
  9799. /// 0140 <map name>.16B <x>.W <y>.W
  9800. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9801. {
  9802. char command[MAP_NAME_LENGTH_EXT+25];
  9803. char* map_name;
  9804. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9805. map_name = RFIFOCP(fd,info->pos[0]);
  9806. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9807. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9808. RFIFOW(fd,info->pos[1]), //x
  9809. RFIFOW(fd,info->pos[2])); //y
  9810. is_atcommand(fd, sd, command, 1);
  9811. }
  9812. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9813. /// 009c <id>.L <head dir>.W <dir>.B
  9814. /// head dir:
  9815. /// 0 = straight
  9816. /// 1 = turned CW
  9817. /// 2 = turned CCW
  9818. /// dir:
  9819. /// 0 = north
  9820. /// 1 = northwest
  9821. /// 2 = west
  9822. /// 3 = southwest
  9823. /// 4 = south
  9824. /// 5 = southeast
  9825. /// 6 = east
  9826. /// 7 = northeast
  9827. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9828. {
  9829. unsigned char buf[64];
  9830. WBUFW(buf,0) = 0x9c;
  9831. WBUFL(buf,2) = bl->id;
  9832. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9833. WBUFB(buf,8) = unit_getdir(bl);
  9834. clif_send(buf, packet_len(0x9c), bl, target);
  9835. if (disguised(bl)) {
  9836. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9837. WBUFW(buf,6) = 0;
  9838. clif_send(buf, packet_len(0x9c), bl, SELF);
  9839. }
  9840. }
  9841. /// Request to change own body and head direction.
  9842. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9843. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9844. /// There are various variants of this packet, some of them have padding between fields.
  9845. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9846. {
  9847. unsigned char headdir, dir;
  9848. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9849. headdir = RFIFOB(fd,info->pos[0]);
  9850. dir = RFIFOB(fd,info->pos[1]);
  9851. pc_setdir(sd, dir, headdir);
  9852. clif_changed_dir(&sd->bl, AREA_WOS);
  9853. }
  9854. /// Request to show an emotion (CZ_REQ_EMOTION).
  9855. /// 00bf <type>.B
  9856. /// type:
  9857. /// @see enum emotion_type
  9858. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9859. {
  9860. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9861. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9862. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9863. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9864. return;
  9865. }
  9866. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9867. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9868. sd->emotionlasttime = time(NULL);
  9869. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9870. return;
  9871. }
  9872. sd->emotionlasttime = time(NULL);
  9873. if (battle_config.idletime_option&IDLE_EMOTION)
  9874. sd->idletime = last_tick;
  9875. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9876. sd->idletime_hom = last_tick;
  9877. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9878. sd->idletime_mer = last_tick;
  9879. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9880. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9881. return;
  9882. }
  9883. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9884. emoticon = rnd()%6+ET_DICE1;
  9885. }
  9886. clif_emotion(&sd->bl, emoticon);
  9887. } else
  9888. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9889. }
  9890. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9891. /// 00c2 <count>.L
  9892. void clif_user_count(struct map_session_data* sd, int count)
  9893. {
  9894. int fd = sd->fd;
  9895. WFIFOHEAD(fd,packet_len(0xc2));
  9896. WFIFOW(fd,0) = 0xc2;
  9897. WFIFOL(fd,2) = count;
  9898. WFIFOSET(fd,packet_len(0xc2));
  9899. }
  9900. /// /w /who (CZ_REQ_USER_COUNT).
  9901. /// Request to display amount of currently connected players.
  9902. /// 00c1
  9903. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9904. {
  9905. clif_user_count(sd, map_getusers());
  9906. }
  9907. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9908. {
  9909. if (pc_isdead(sd)) {
  9910. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9911. return;
  9912. }
  9913. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9914. if (action_type != 0x00 && action_type != 0x07) {
  9915. if (sd->sc.cant.interact)
  9916. return;
  9917. pc_stop_walking(sd, 1);
  9918. }
  9919. pc_stop_attack(sd);
  9920. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9921. target_id = sd->bl.id;
  9922. switch(action_type)
  9923. {
  9924. case 0x00: // once attack
  9925. case 0x07: // continuous attack
  9926. if( pc_cant_act(sd) )
  9927. return;
  9928. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9929. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9930. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9931. return;
  9932. }
  9933. }
  9934. pc_delinvincibletimer(sd);
  9935. if (battle_config.idletime_option&IDLE_ATTACK)
  9936. sd->idletime = last_tick;
  9937. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9938. sd->idletime_hom = last_tick;
  9939. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9940. sd->idletime_mer = last_tick;
  9941. unit_attack(&sd->bl, target_id, action_type != 0);
  9942. break;
  9943. case 0x02: // sitdown
  9944. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9945. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9946. break;
  9947. }
  9948. if(pc_issit(sd)) {
  9949. //Bugged client? Just refresh them.
  9950. clif_sitting(&sd->bl);
  9951. return;
  9952. }
  9953. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9954. break;
  9955. if (sd->sc.count && (
  9956. sd->sc.data[SC_DANCING] ||
  9957. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9958. )) //No sitting during these states either.
  9959. break;
  9960. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9961. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9962. break;
  9963. }
  9964. if (battle_config.idletime_option&IDLE_SIT)
  9965. sd->idletime = last_tick;
  9966. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9967. sd->idletime_hom = last_tick;
  9968. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9969. sd->idletime_mer = last_tick;
  9970. pc_setsit(sd);
  9971. skill_sit(sd, true);
  9972. clif_sitting(&sd->bl);
  9973. break;
  9974. case 0x03: // standup
  9975. if (!pc_issit(sd)) {
  9976. //Bugged client? Just refresh them.
  9977. clif_standing(&sd->bl);
  9978. return;
  9979. }
  9980. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9981. break;
  9982. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9983. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9984. break;
  9985. }
  9986. if (pc_setstand(sd, false)) {
  9987. if (battle_config.idletime_option&IDLE_SIT)
  9988. sd->idletime = last_tick;
  9989. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9990. sd->idletime_hom = last_tick;
  9991. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9992. sd->idletime_mer = last_tick;
  9993. skill_sit(sd, false);
  9994. clif_standing(&sd->bl);
  9995. }
  9996. break;
  9997. }
  9998. }
  9999. /// Request for an action.
  10000. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  10001. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  10002. /// action:
  10003. /// 0 = attack
  10004. /// 1 = pick up item
  10005. /// 2 = sit down
  10006. /// 3 = stand up
  10007. /// 7 = continous attack
  10008. /// 12 = (touch skill?)
  10009. /// There are various variants of this packet, some of them have padding between fields.
  10010. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  10011. {
  10012. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10013. clif_parse_ActionRequest_sub(sd,
  10014. RFIFOB(fd,info->pos[1]),
  10015. RFIFOL(fd,info->pos[0]),
  10016. gettick()
  10017. );
  10018. }
  10019. /// Response to the death/system menu (CZ_RESTART).
  10020. /// 00b2 <type>.B
  10021. /// type:
  10022. /// 0 = restart (respawn)
  10023. /// 1 = char-select (disconnect)
  10024. void clif_parse_Restart(int fd, struct map_session_data *sd)
  10025. {
  10026. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  10027. case 0x00:
  10028. pc_respawn(sd,CLR_OUTSIGHT);
  10029. break;
  10030. case 0x01:
  10031. /* Rovert's Prevent logout option - Fixed [Valaris] */
  10032. 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] &&
  10033. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  10034. { //Send to char-server for character selection.
  10035. pc_damage_log_clear(sd,0);
  10036. chrif_charselectreq(sd, session[fd]->client_addr);
  10037. } else {
  10038. clif_disconnect_ack(sd, 1);
  10039. }
  10040. break;
  10041. }
  10042. }
  10043. /// Validates and processes whispered messages (CZ_WHISPER).
  10044. /// 0096 <packet len>.W <nick>.24B <message>.?B
  10045. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  10046. {
  10047. struct map_session_data* dstsd;
  10048. int i;
  10049. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10050. // validate packet and retrieve name and message
  10051. if( !clif_process_message( sd, true, target, message, output ) )
  10052. return;
  10053. // Chat logging type 'W' / Whisper
  10054. 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);
  10055. //-------------------------------------------------------//
  10056. // Lordalfa - Paperboy - To whisper NPC commands //
  10057. //-------------------------------------------------------//
  10058. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  10059. {
  10060. char* str = target+4; //Skip the NPC: string part.
  10061. struct npc_data* npc;
  10062. if ((npc = npc_name2id(str))) {
  10063. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  10064. char *split;
  10065. char event[EVENT_NAME_LENGTH];
  10066. str = message;
  10067. // skip codepage indicator, if detected
  10068. if( str[0] == '|' && strlen(str) >= 4 )
  10069. str += 3;
  10070. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  10071. split = strchr(str,'#');
  10072. if( split == NULL ) { // use the remaining string
  10073. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10074. for( ++i; i < NUM_WHISPER_VAR; ++i )
  10075. split_data[i][0] = '\0';
  10076. break;
  10077. }
  10078. *split = '\0';
  10079. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10080. str = split+1;
  10081. }
  10082. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  10083. char variablename[CHAT_SIZE_MAX];
  10084. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  10085. set_var_str( sd, variablename, split_data[i] );
  10086. }
  10087. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  10088. npc_event(sd,event,0); // Calls the NPC label
  10089. return;
  10090. }
  10091. } else if( target[0] == '#' ) {
  10092. struct Channel *channel = NULL;
  10093. char* chname = target;
  10094. channel = channel_name2channel(chname,sd,3);
  10095. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  10096. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  10097. channel_send(channel,sd,message);
  10098. }
  10099. else if( channel->pass[0] == '\0') { //no pass needed
  10100. if (channel_join(channel,sd)==0)
  10101. channel_send(channel,sd,message); //join success
  10102. }
  10103. else {
  10104. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  10105. }
  10106. return;
  10107. }
  10108. }
  10109. // searching destination character
  10110. dstsd = map_nick2sd(target,false);
  10111. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  10112. // player is not on this map-server
  10113. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  10114. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  10115. // and if we ask for 'Test', we must not contact 'test' player
  10116. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  10117. intif_wis_message(sd, target, message, strlen(message) + 1);
  10118. return;
  10119. }
  10120. // if player ignores everyone
  10121. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10122. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  10123. clif_wis_end(fd, 1); // 1: target character is not logged in
  10124. else
  10125. clif_wis_end(fd, 3); // 3: everyone ignored by target
  10126. return;
  10127. }
  10128. // if player is autotrading
  10129. if (dstsd->state.autotrade == 1){
  10130. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  10131. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  10132. return;
  10133. }
  10134. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10135. // if player ignores the source character
  10136. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  10137. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  10138. clif_wis_end(fd, 2); // 2: ignored by target
  10139. return;
  10140. }
  10141. }
  10142. // notify sender of success
  10143. clif_wis_end(fd, 0); // 0: success to send wisper
  10144. // Normal message
  10145. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10146. }
  10147. /// /b /nb (CZ_BROADCAST).
  10148. /// Request to broadcast a message on whole server.
  10149. /// 0099 <packet len>.W <text>.?B 00
  10150. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  10151. char command[CHAT_SIZE_MAX+11];
  10152. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10153. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10154. char* msg = RFIFOCP(fd,info->pos[1]);
  10155. // as the length varies depending on the command used, just block unreasonably long strings
  10156. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10157. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10158. is_atcommand(fd, sd, command, 1);
  10159. }
  10160. /// Request to pick up an item.
  10161. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10162. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10163. /// There are various variants of this packet, some of them have padding between fields.
  10164. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  10165. {
  10166. struct flooritem_data *fitem;
  10167. int map_object_id;
  10168. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10169. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10170. do {
  10171. if (pc_isdead(sd)) {
  10172. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10173. break;
  10174. }
  10175. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10176. break;
  10177. if (pc_cant_act(sd))
  10178. break;
  10179. if (!pc_takeitem(sd, fitem))
  10180. break;
  10181. return;
  10182. } while (0);
  10183. // Client REQUIRES a fail packet or you can no longer pick items.
  10184. clif_additem(sd,0,0,6);
  10185. }
  10186. /// Request to drop an item.
  10187. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10188. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10189. /// There are various variants of this packet, some of them have padding between fields.
  10190. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  10191. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10192. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10193. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10194. for(;;) {
  10195. if (pc_isdead(sd))
  10196. break;
  10197. if (pc_cant_act2(sd) || sd->npc_id)
  10198. break;
  10199. if (sd->sc.cant.drop)
  10200. break;
  10201. if (!pc_dropitem(sd, item_index, item_amount))
  10202. break;
  10203. if (battle_config.idletime_option&IDLE_DROPITEM)
  10204. sd->idletime = last_tick;
  10205. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10206. sd->idletime_hom = last_tick;
  10207. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10208. sd->idletime_mer = last_tick;
  10209. return;
  10210. }
  10211. //Because the client does not like being ignored.
  10212. clif_dropitem(sd, item_index,0);
  10213. }
  10214. /// Request to use an item.
  10215. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10216. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10217. /// There are various variants of this packet, some of them have padding between fields.
  10218. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  10219. {
  10220. int n;
  10221. if (pc_isdead(sd)) {
  10222. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10223. return;
  10224. }
  10225. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10226. clif_msg(sd, WORK_IN_PROGRESS);
  10227. return;
  10228. }
  10229. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10230. if (battle_config.idletime_option&IDLE_USEITEM)
  10231. sd->idletime = last_tick;
  10232. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10233. sd->idletime_hom = last_tick;
  10234. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10235. sd->idletime_mer = last_tick;
  10236. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10237. if(n <0 || n >= MAX_INVENTORY)
  10238. return;
  10239. if (!pc_useitem(sd,n))
  10240. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10241. }
  10242. /// Request to equip an item
  10243. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10244. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10245. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10246. {
  10247. int index;
  10248. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10249. if(pc_isdead(sd)) {
  10250. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10251. return;
  10252. }
  10253. index = RFIFOW(fd,info->pos[0])-2;
  10254. if (index < 0 || index >= MAX_INVENTORY)
  10255. return; //Out of bounds check.
  10256. if(sd->npc_id && !sd->npc_item_flag) {
  10257. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10258. return;
  10259. } else if (sd->state.storage_flag || sd->sc.opt1)
  10260. ; //You can equip/unequip stuff while storage is open/under status changes
  10261. else if (pc_cant_act2(sd))
  10262. return;
  10263. if(!sd->inventory.u.items_inventory[index].identify) {
  10264. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  10265. return;
  10266. }
  10267. if(!sd->inventory_data[index])
  10268. return;
  10269. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10270. pet_equipitem(sd,index);
  10271. return;
  10272. }
  10273. if (battle_config.idletime_option&IDLE_USEITEM)
  10274. sd->idletime = last_tick;
  10275. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10276. sd->idletime_hom = last_tick;
  10277. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10278. sd->idletime_mer = last_tick;
  10279. //Client doesn't send the position for ammo.
  10280. if(sd->inventory_data[index]->type == IT_AMMO)
  10281. pc_equipitem(sd,index,EQP_AMMO);
  10282. else {
  10283. int req_pos;
  10284. #if PACKETVER >= 20120925
  10285. req_pos = RFIFOL(fd,info->pos[1]);
  10286. #else
  10287. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10288. #endif
  10289. pc_equipitem(sd,index,req_pos);
  10290. }
  10291. }
  10292. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10293. /// 00ab <index>.W
  10294. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10295. {
  10296. int index;
  10297. if(pc_isdead(sd)) {
  10298. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10299. return;
  10300. }
  10301. if (sd->npc_id && !sd->npc_item_flag) {
  10302. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10303. return;
  10304. } else if (sd->state.storage_flag || sd->sc.opt1)
  10305. ; //You can equip/unequip stuff while storage is open/under status changes
  10306. else if (pc_cant_act2(sd))
  10307. return;
  10308. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10309. if (battle_config.idletime_option&IDLE_USEITEM)
  10310. sd->idletime = last_tick;
  10311. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10312. sd->idletime_hom = last_tick;
  10313. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10314. sd->idletime_mer = last_tick;
  10315. pc_unequipitem(sd,index,1);
  10316. }
  10317. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10318. /// 0090 <id>.L <type>.B
  10319. /// type:
  10320. /// 1 = click
  10321. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10322. {
  10323. struct block_list *bl;
  10324. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10325. if(pc_isdead(sd)) {
  10326. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10327. return;
  10328. }
  10329. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10330. #ifdef RENEWAL
  10331. clif_msg( sd, WORK_IN_PROGRESS );
  10332. #endif
  10333. return;
  10334. }
  10335. if( sd->state.mail_writing )
  10336. return;
  10337. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10338. //type = RFIFOB(fd,info->pos[1]);
  10339. if (!bl) return;
  10340. switch (bl->type) {
  10341. case BL_MOB:
  10342. case BL_PC:
  10343. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10344. break;
  10345. case BL_NPC:
  10346. #ifdef RENEWAL
  10347. 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
  10348. clif_msg(sd, WORK_IN_PROGRESS);
  10349. break;
  10350. }
  10351. #endif
  10352. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10353. struct npc_data* nd = (struct npc_data*)bl;
  10354. // Progressbar is running
  10355. if( nd->progressbar.timeout > 0 ){
  10356. return;
  10357. }
  10358. npc_click(sd,nd);
  10359. }
  10360. break;
  10361. }
  10362. }
  10363. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10364. /// 00c5 <id>.L <type>.B
  10365. /// type:
  10366. /// 0 = buy
  10367. /// 1 = sell
  10368. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10369. {
  10370. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10371. if (sd->state.trading)
  10372. return;
  10373. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10374. }
  10375. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10376. /// 00ca <result>.B
  10377. /// result:
  10378. /// 0 = "The deal has successfully completed."
  10379. /// 1 = "You do not have enough zeny."
  10380. /// 2 = "You are over your Weight Limit."
  10381. /// 3 = "Out of the maximum capacity, you have too many items."
  10382. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10383. /// 10 = "Props open-air store sales will be traded in RODEX"
  10384. /// 11 = "The exchange failed."
  10385. /// 12 = "The exchange was well done."
  10386. /// 13 = "The item is already sold and out of stock."
  10387. /// 14 = "There is not enough goods to exchange."
  10388. void clif_npc_buy_result( struct map_session_data* sd, e_purchase_result result ){
  10389. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10390. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10391. p.result = (uint8)result;
  10392. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10393. }
  10394. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10395. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10396. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10397. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10398. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10399. e_purchase_result result;
  10400. if( sd->state.trading || !sd->npc_shopid )
  10401. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10402. else{
  10403. std::vector<s_npc_buy_list> items = {};
  10404. items.reserve( n );
  10405. for( uint16 i = 0; i < n; i++ ){
  10406. s_npc_buy_list item = {};
  10407. item.nameid = p->items[i].itemId;
  10408. item.qty = p->items[i].amount;
  10409. items.push_back( item );
  10410. }
  10411. result = npc_buylist( sd, items );
  10412. }
  10413. sd->npc_shopid = 0; //Clear shop data.
  10414. clif_npc_buy_result(sd, result);
  10415. }
  10416. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10417. /// 00cb <result>.B
  10418. /// result:
  10419. /// 0 = "The deal has successfully completed."
  10420. /// 1 = "The deal has failed."
  10421. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10422. {
  10423. int fd = sd->fd;
  10424. WFIFOHEAD(fd,packet_len(0xcb));
  10425. WFIFOW(fd,0) = 0xcb;
  10426. WFIFOB(fd,2) = result;
  10427. WFIFOSET(fd,packet_len(0xcb));
  10428. }
  10429. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10430. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10431. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10432. {
  10433. int fail=0,n;
  10434. unsigned short *item_list;
  10435. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10436. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10437. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10438. if (sd->state.trading || !sd->npc_shopid)
  10439. fail = 1;
  10440. else
  10441. fail = npc_selllist(sd,n,item_list);
  10442. sd->npc_shopid = 0; //Clear shop data.
  10443. clif_npc_sell_result(sd, fail);
  10444. }
  10445. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10446. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10447. /// type:
  10448. /// 0 = private
  10449. /// 1 = public
  10450. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10451. {
  10452. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10453. int len = RFIFOW(fd,info->pos[0])-15;
  10454. int limit = RFIFOW(fd,info->pos[1]);
  10455. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10456. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10457. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10458. char s_password[CHATROOM_PASS_SIZE];
  10459. char s_title[CHATROOM_TITLE_SIZE];
  10460. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10461. return;
  10462. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10463. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10464. return;
  10465. }
  10466. if( npc_isnear(&sd->bl) ) {
  10467. // uncomment to send msg_txt.
  10468. //char output[150];
  10469. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10470. //clif_displaymessage(sd->fd, output);
  10471. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10472. return;
  10473. }
  10474. if( len <= 0 )
  10475. return; // invalid input
  10476. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10477. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10478. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10479. }
  10480. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10481. /// 00d9 <chat ID>.L <passwd>.8B
  10482. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10483. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10484. int chatid = RFIFOL(fd,info->pos[0]);
  10485. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10486. chat_joinchat(sd,chatid,password);
  10487. }
  10488. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10489. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10490. /// type:
  10491. /// 0 = private
  10492. /// 1 = public
  10493. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10494. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10495. int len = RFIFOW(fd,info->pos[0])-15;
  10496. int limit = RFIFOW(fd,info->pos[1]);
  10497. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10498. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10499. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10500. char s_password[CHATROOM_PASS_SIZE];
  10501. char s_title[CHATROOM_TITLE_SIZE];
  10502. if( len <= 0 )
  10503. return; // invalid input
  10504. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10505. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10506. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10507. }
  10508. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10509. /// 00e0 <role>.L <nick>.24B
  10510. /// role:
  10511. /// 0 = owner
  10512. /// 1 = normal
  10513. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10514. {
  10515. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10516. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10517. }
  10518. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10519. /// 00e2 <name>.24B
  10520. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10521. {
  10522. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10523. }
  10524. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10525. /// 00e3
  10526. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10527. {
  10528. chat_leavechat(sd,0);
  10529. }
  10530. //Handles notifying asker and rejecter of what has just ocurred.
  10531. //Type is used to determine the correct msg_txt to use:
  10532. //0:
  10533. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10534. {
  10535. const char* msg;
  10536. char output[256];
  10537. // Your request has been rejected by autoreject option.
  10538. msg = msg_txt(sd,392);
  10539. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10540. //Notice that a request was rejected.
  10541. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10542. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10543. }
  10544. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10545. /// 00e4 <account id>.L
  10546. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10547. {
  10548. struct map_session_data *t_sd;
  10549. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10550. if(!sd->chatID && pc_cant_act(sd))
  10551. return; //You can trade while in a chatroom.
  10552. if(t_sd){
  10553. // @noask [LuzZza]
  10554. if(t_sd->state.noask) {
  10555. clif_noask_sub(sd, t_sd, 0);
  10556. return;
  10557. }
  10558. if (t_sd->state.mail_writing) {
  10559. int old = sd->trade_partner;
  10560. // Fake trading
  10561. sd->trade_partner = t_sd->status.account_id;
  10562. clif_tradestart(sd, 5);
  10563. // Restore old state
  10564. sd->trade_partner = old;
  10565. return;
  10566. }
  10567. }
  10568. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10569. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10570. return;
  10571. }
  10572. trade_traderequest(sd,t_sd);
  10573. }
  10574. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10575. /// 00e6 <result>.B
  10576. /// result:
  10577. /// 3 = accepted
  10578. /// 4 = rejected
  10579. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10580. {
  10581. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10582. }
  10583. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10584. /// 00e8 <index>.W <amount>.L
  10585. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10586. {
  10587. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10588. short index = RFIFOW(fd,info->pos[0]);
  10589. int amount = RFIFOL(fd,info->pos[1]);
  10590. if( index == 0 )
  10591. trade_tradeaddzeny(sd, amount);
  10592. else
  10593. trade_tradeadditem(sd, index, (short)amount);
  10594. }
  10595. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10596. /// 00eb
  10597. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10598. {
  10599. trade_tradeok(sd);
  10600. }
  10601. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10602. /// 00ed
  10603. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10604. {
  10605. trade_tradecancel(sd);
  10606. }
  10607. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10608. /// 00ef
  10609. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10610. {
  10611. trade_tradecommit(sd);
  10612. }
  10613. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10614. /// 0118
  10615. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10616. {
  10617. pc_stop_attack(sd);
  10618. if (sd) sd->ud.state.attack_continue = 0;
  10619. }
  10620. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10621. /// 0126 <index>.W <amount>.L
  10622. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10623. {
  10624. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10625. if (pc_istrading(sd))
  10626. return;
  10627. if (!pc_iscarton(sd))
  10628. return;
  10629. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10630. }
  10631. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10632. /// 0127 <index>.W <amount>.L
  10633. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10634. {
  10635. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10636. if (!pc_iscarton(sd))
  10637. return;
  10638. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10639. }
  10640. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10641. /// 012a
  10642. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10643. {
  10644. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10645. #ifdef NEW_CARTS
  10646. && sd->sc.data[SC_PUSH_CART] )
  10647. pc_setcart(sd,0);
  10648. #else
  10649. )
  10650. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10651. #endif
  10652. else // priority to remove this option before we can clear cart
  10653. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10654. }
  10655. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10656. /// 097f <Length>.W <identity>.L <type>.B
  10657. void clif_SelectCart(struct map_session_data *sd) {
  10658. #if PACKETVER >= 20150826
  10659. int i = 0, carts = 3;
  10660. int fd = sd->fd;
  10661. WFIFOHEAD(fd,8 + carts);
  10662. WFIFOW(fd,0) = 0x97f;
  10663. WFIFOW(fd,2) = 8 + carts;
  10664. WFIFOL(fd,4) = sd->status.account_id;
  10665. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10666. for( i = 0; i < carts; i++ ) {
  10667. WFIFOB(fd,8 + i) = 10 + i;
  10668. }
  10669. WFIFOSET(fd,8 + carts);
  10670. #endif
  10671. }
  10672. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10673. /// 0980 <identity>.L <type>.B
  10674. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10675. #if PACKETVER >= 20150826
  10676. int type;
  10677. // Check identity
  10678. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10679. return;
  10680. type = (int)RFIFOB(fd,6);
  10681. // Check type
  10682. if( type < 10 || type > 12 )
  10683. return;
  10684. pc_setcart(sd, type);
  10685. #endif
  10686. }
  10687. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10688. /// 01af <num>.W
  10689. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10690. {// TODO: State tracking?
  10691. int type;
  10692. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10693. return;
  10694. #ifdef RENEWAL
  10695. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10696. clif_msg(sd, WORK_IN_PROGRESS);
  10697. return;
  10698. }
  10699. #endif
  10700. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10701. if(
  10702. #ifdef NEW_CARTS
  10703. #if PACKETVER >= 20191106
  10704. (type == 13 && sd->status.base_level > 100) ||
  10705. #endif
  10706. (type == 9 && sd->status.base_level > 130) ||
  10707. (type == 8 && sd->status.base_level > 120) ||
  10708. (type == 7 && sd->status.base_level > 110) ||
  10709. (type == 6 && sd->status.base_level > 100) ||
  10710. #endif
  10711. (type == 5 && sd->status.base_level > 90) ||
  10712. (type == 4 && sd->status.base_level > 80) ||
  10713. (type == 3 && sd->status.base_level > 65) ||
  10714. (type == 2 && sd->status.base_level > 40) ||
  10715. (type == 1))
  10716. pc_setcart(sd, type);
  10717. }
  10718. /// Request to increase status (CZ_STATUS_CHANGE).
  10719. /// 00bb <status id>.W <amount>.B
  10720. /// status id:
  10721. /// SP_STR ~ SP_LUK
  10722. /// amount:
  10723. /// Old clients always send 1 for this, even when using /str+ and the like.
  10724. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10725. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10726. {
  10727. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10728. if( increase_amount < 0 ) {
  10729. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10730. fd, increase_amount);
  10731. }
  10732. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10733. }
  10734. /// Request to increase trait status.
  10735. /// 0b24 <status id>.W <amount>.W
  10736. /// status id:
  10737. /// SP_POW ~ SP_CON
  10738. /// amount:
  10739. /// The amount to increase the trait status
  10740. void clif_parse_traitstatus_up( int fd, struct map_session_data *sd ){
  10741. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10742. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10743. if( p->amount < 0 ){
  10744. ShowDebug( "clif_parse_traitstatus_up: Negative 'increase' value sent by client! %s (AID: %d, CID: %d, value: %d)\n", sd->status.name, sd->status.account_id, sd->status.char_id, p->amount );
  10745. return;
  10746. }
  10747. pc_traitstatusup( sd, p->type, p->amount );
  10748. #endif
  10749. }
  10750. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10751. /// 0112 <skill id>.W
  10752. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10753. {
  10754. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10755. }
  10756. 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)
  10757. {
  10758. int lv;
  10759. if( !hd )
  10760. return;
  10761. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10762. clif_emotion(&hd->bl, ET_THINK);
  10763. return;
  10764. }
  10765. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10766. target_id = hd->bl.id;
  10767. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10768. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10769. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10770. clif_emotion(&hd->bl, ET_THINK);
  10771. if (hd->master)
  10772. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10773. return;
  10774. }
  10775. lv = hom_checkskill(hd, skill_id);
  10776. if( skill_lv > lv )
  10777. skill_lv = lv;
  10778. if( skill_lv )
  10779. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10780. }
  10781. 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)
  10782. {
  10783. int lv;
  10784. if( !hd )
  10785. return;
  10786. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10787. clif_emotion(&hd->bl, ET_THINK);
  10788. return;
  10789. }
  10790. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10791. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10792. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10793. clif_emotion(&hd->bl, ET_THINK);
  10794. if (hd->master)
  10795. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10796. return;
  10797. }
  10798. #ifdef RENEWAL
  10799. if (hd->sc.data[SC_BASILICA_CELL])
  10800. #else
  10801. if (hd->sc.data[SC_BASILICA])
  10802. #endif
  10803. return;
  10804. lv = hom_checkskill(hd, skill_id);
  10805. if( skill_lv > lv )
  10806. skill_lv = lv;
  10807. if( skill_lv )
  10808. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10809. }
  10810. static void clif_parse_UseSkillToId_mercenary(s_mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10811. {
  10812. int lv;
  10813. if( !md )
  10814. return;
  10815. if( skill_isNotOk_mercenary(skill_id, md) )
  10816. return;
  10817. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10818. target_id = md->bl.id;
  10819. if( md->ud.skilltimer != INVALID_TIMER )
  10820. {
  10821. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10822. }
  10823. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10824. return;
  10825. lv = mercenary_checkskill(md, skill_id);
  10826. if( skill_lv > lv )
  10827. skill_lv = lv;
  10828. if( skill_lv )
  10829. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10830. }
  10831. static void clif_parse_UseSkillToPos_mercenary(s_mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10832. {
  10833. int lv;
  10834. if( !md )
  10835. return;
  10836. if( skill_isNotOk_mercenary(skill_id, md) )
  10837. return;
  10838. if( md->ud.skilltimer != INVALID_TIMER )
  10839. return;
  10840. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10841. {
  10842. if (md->master)
  10843. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10844. return;
  10845. }
  10846. #ifdef RENEWAL
  10847. if (md->sc.data[SC_BASILICA_CELL])
  10848. #else
  10849. if (md->sc.data[SC_BASILICA])
  10850. #endif
  10851. return;
  10852. lv = mercenary_checkskill(md, skill_id);
  10853. if( skill_lv > lv )
  10854. skill_lv = lv;
  10855. if( skill_lv )
  10856. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10857. }
  10858. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10859. t_tick tick = gettick();
  10860. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10861. int inf = skill_get_inf(skill_id);
  10862. if (inf&INF_GROUND_SKILL || !inf)
  10863. return; //Using a ground/passive skill on a target? WRONG.
  10864. if (sd->state.block_action & PCBLOCK_SKILL) {
  10865. clif_msg(sd, WORK_IN_PROGRESS);
  10866. return;
  10867. }
  10868. if( SKILL_CHK_HOMUN(skill_id) ) {
  10869. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10870. return;
  10871. }
  10872. if( SKILL_CHK_MERC(skill_id) ) {
  10873. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10874. return;
  10875. }
  10876. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10877. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10878. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10879. sd->idletime = last_tick;
  10880. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10881. sd->idletime_hom = last_tick;
  10882. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10883. sd->idletime_mer = last_tick;
  10884. if( sd->npc_id ){
  10885. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10886. #ifdef RENEWAL
  10887. clif_msg( sd, WORK_IN_PROGRESS );
  10888. #endif
  10889. return;
  10890. }
  10891. }
  10892. if ((pc_cant_act2(sd) || sd->chatID) &&
  10893. skill_id != RK_REFRESH &&
  10894. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10895. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10896. return;
  10897. if( pc_issit(sd) )
  10898. return;
  10899. if( skill_isNotOk(skill_id, sd) )
  10900. return;
  10901. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10902. target_id = sd->bl.id; // never trust the client
  10903. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10904. target_id = sd->bl.id;
  10905. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10906. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10907. return;
  10908. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10909. if( sd->skillitem != skill_id ) {
  10910. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10911. return;
  10912. }
  10913. }
  10914. if( sd->sc.option&OPTION_COSTUME )
  10915. return;
  10916. #ifndef RENEWAL
  10917. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10918. return; // On basilica only caster can use Basilica again to stop it.
  10919. #endif
  10920. if( sd->menuskill_id ) {
  10921. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10922. clif_menuskill_clear(sd); //Cancel pet capture.
  10923. }else if( sd->menuskill_id == SG_FEEL ){
  10924. clif_menuskill_clear( sd ); // Cancel selection
  10925. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10926. return; //Can't use skills while a menu is open.
  10927. }
  10928. if( sd->skillitem == skill_id ) {
  10929. if( skill_lv != sd->skillitemlv )
  10930. skill_lv = sd->skillitemlv;
  10931. if( !(inf&INF_SELF_SKILL) )
  10932. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10933. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10934. return;
  10935. }
  10936. sd->skillitem = sd->skillitemlv = 0;
  10937. if( SKILL_CHK_GUILD(skill_id) ) {
  10938. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10939. skill_lv = guild_checkskill(sd->guild, skill_id);
  10940. else
  10941. skill_lv = 0;
  10942. } else {
  10943. if( skill_id != ALL_EQSWITCH ){
  10944. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10945. }
  10946. }
  10947. pc_delinvincibletimer(sd);
  10948. if( skill_lv )
  10949. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10950. }
  10951. /// Request to use a targeted skill.
  10952. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10953. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10954. /// There are various variants of this packet, some of them have padding between fields.
  10955. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10956. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10957. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10958. }
  10959. /*==========================================
  10960. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10961. *------------------------------------------*/
  10962. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10963. {
  10964. t_tick tick = gettick();
  10965. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10966. return; //Using a target skill on the ground? WRONG.
  10967. if (sd->state.block_action & PCBLOCK_SKILL) {
  10968. clif_msg(sd, WORK_IN_PROGRESS);
  10969. return;
  10970. }
  10971. if( SKILL_CHK_HOMUN(skill_id) ) {
  10972. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10973. return;
  10974. }
  10975. if( SKILL_CHK_MERC(skill_id) ) {
  10976. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10977. return;
  10978. }
  10979. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10980. #ifdef RENEWAL
  10981. clif_msg( sd, WORK_IN_PROGRESS );
  10982. #endif
  10983. return;
  10984. }
  10985. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10986. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10987. sd->idletime = last_tick;
  10988. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10989. sd->idletime_hom = last_tick;
  10990. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10991. sd->idletime_mer = last_tick;
  10992. if( skill_isNotOk(skill_id, sd) )
  10993. return;
  10994. if( skillmoreinfo != -1 ) {
  10995. if( pc_issit(sd) ) {
  10996. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10997. return;
  10998. }
  10999. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  11000. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  11001. }
  11002. if( sd->ud.skilltimer != INVALID_TIMER )
  11003. return;
  11004. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  11005. if( sd->skillitem != skill_id ) {
  11006. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  11007. return;
  11008. }
  11009. }
  11010. if( sd->sc.option&OPTION_COSTUME )
  11011. return;
  11012. #ifndef RENEWAL
  11013. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  11014. return; // On basilica only caster can use Basilica again to stop it.
  11015. #endif
  11016. if( sd->menuskill_id ) {
  11017. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  11018. clif_menuskill_clear(sd); //Cancel pet capture.
  11019. }else if( sd->menuskill_id == SG_FEEL ){
  11020. clif_menuskill_clear( sd ); // Cancel selection
  11021. } else if( sd->menuskill_id != SA_AUTOSPELL )
  11022. return; //Can't use skills while a menu is open.
  11023. }
  11024. pc_delinvincibletimer(sd);
  11025. if( sd->skillitem == skill_id ) {
  11026. if( skill_lv != sd->skillitemlv )
  11027. skill_lv = sd->skillitemlv;
  11028. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  11029. } else {
  11030. int lv;
  11031. sd->skillitem = sd->skillitemlv = 0;
  11032. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  11033. if( skill_lv > lv )
  11034. skill_lv = lv;
  11035. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  11036. }
  11037. }
  11038. }
  11039. /// Request to use a ground skill.
  11040. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  11041. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  11042. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  11043. /// There are various variants of this packet, some of them have padding between fields.
  11044. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  11045. {
  11046. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11047. if (pc_cant_act(sd))
  11048. return;
  11049. if (pc_issit(sd))
  11050. return;
  11051. clif_parse_UseSkillToPosSub(fd, sd,
  11052. RFIFOW(fd,info->pos[0]), //skill lv
  11053. RFIFOW(fd,info->pos[1]), //skill num
  11054. RFIFOW(fd,info->pos[2]), //pos x
  11055. RFIFOW(fd,info->pos[3]), //pos y
  11056. // TODO: find out what this is intended to do
  11057. //RFIFOB(fd, info->pos[4])
  11058. -1 //Skill more info.
  11059. );
  11060. }
  11061. /// Request to use a ground skill with text.
  11062. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  11063. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  11064. /// There are various variants of this packet, some of them have padding between fields.
  11065. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  11066. {
  11067. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11068. if (pc_cant_act(sd))
  11069. return;
  11070. if (pc_issit(sd))
  11071. return;
  11072. clif_parse_UseSkillToPosSub(fd, sd,
  11073. RFIFOW(fd,info->pos[0]), //Skill lv
  11074. RFIFOW(fd,info->pos[1]), //Skill num
  11075. RFIFOW(fd,info->pos[2]), //pos x
  11076. RFIFOW(fd,info->pos[3]), //pos y
  11077. info->pos[4] //skill more info
  11078. );
  11079. }
  11080. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  11081. /// 011b <skill id>.W <map name>.16B
  11082. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  11083. {
  11084. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11085. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11086. char map_name[MAP_NAME_LENGTH];
  11087. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11088. sd->state.workinprogress = WIP_DISABLE_NONE;
  11089. if(skill_id != sd->menuskill_id)
  11090. return;
  11091. //It is possible to use teleport with the storage window open bugreport:8027
  11092. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11093. clif_menuskill_clear(sd);
  11094. return;
  11095. }
  11096. pc_delinvincibletimer(sd);
  11097. skill_castend_map(sd,skill_id,map_name);
  11098. }
  11099. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11100. /// 011d
  11101. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  11102. {
  11103. if (!pc_isdead(sd))
  11104. pc_memo(sd,-1);
  11105. }
  11106. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11107. /// 018e <name id>.W { <material id>.W }*3
  11108. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  11109. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11110. switch( sd->menuskill_id ) {
  11111. case -1:
  11112. case AM_PHARMACY:
  11113. case RK_RUNEMASTERY:
  11114. case GC_RESEARCHNEWPOISON:
  11115. break;
  11116. default:
  11117. return;
  11118. }
  11119. if (pc_istrading(sd)) {
  11120. //Make it fail to avoid shop exploits where you sell something different than you see.
  11121. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11122. clif_menuskill_clear(sd);
  11123. return;
  11124. }
  11125. int produce_idx;
  11126. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11127. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11128. clif_menuskill_clear(sd);
  11129. }
  11130. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11131. /// 025b <mk type>.W <name id>.W
  11132. /// mk type:
  11133. /// 1 = cooking
  11134. /// 2 = arrow
  11135. /// 3 = elemental
  11136. /// 4 = GN_MIX_COOKING
  11137. /// 5 = GN_MAKEBOMB
  11138. /// 6 = GN_S_PHARMACY
  11139. /// 7 = MT_M_MACHINE - Unconfirmed
  11140. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11141. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  11142. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11143. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11144. short food_idx = -1;
  11145. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11146. return;
  11147. if (pc_istrading(sd)) {
  11148. //Make it fail to avoid shop exploits where you sell something different than you see.
  11149. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11150. clif_menuskill_clear(sd);
  11151. return;
  11152. }
  11153. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11154. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11155. clif_menuskill_clear(sd);
  11156. }
  11157. /// Answer to repair weapon item selection dialog
  11158. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11159. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11160. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  11161. // Hercules has wrong date -> use correct one here
  11162. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11163. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11164. #else
  11165. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11166. #endif
  11167. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11168. return;
  11169. if (pc_istrading(sd)) {
  11170. //Make it fail to avoid shop exploits where you sell something different than you see.
  11171. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11172. clif_menuskill_clear(sd);
  11173. return;
  11174. }
  11175. skill_repairweapon( sd, p->item.index );
  11176. clif_menuskill_clear(sd);
  11177. }
  11178. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11179. /// 0222 <index>.L
  11180. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  11181. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11182. return;
  11183. if (pc_istrading(sd)) {
  11184. //Make it fail to avoid shop exploits where you sell something different than you see.
  11185. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11186. clif_menuskill_clear(sd);
  11187. return;
  11188. }
  11189. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11190. clif_menuskill_clear(sd);
  11191. }
  11192. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11193. /// 00b8 <npc id>.L <choice>.B
  11194. /// choice:
  11195. /// 1~254 = menu item
  11196. /// 255 = cancel
  11197. /// NOTE: If there were more than 254 items in the list, choice
  11198. /// overflows to choice%256.
  11199. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  11200. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11201. int npc_id = RFIFOL(fd,info->pos[0]);
  11202. uint8 select = RFIFOB(fd,info->pos[1]);
  11203. #ifdef SECURE_NPCTIMEOUT
  11204. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11205. return;
  11206. #endif
  11207. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11208. TBL_NPC* nd = map_id2nd(npc_id);
  11209. 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);
  11210. clif_GM_kick(NULL,sd);
  11211. return;
  11212. }
  11213. sd->npc_menu = select;
  11214. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11215. sd->idletime = last_tick;
  11216. }
  11217. npc_scriptcont(sd,npc_id, false);
  11218. }
  11219. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11220. /// 00b9 <npc id>.L
  11221. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  11222. {
  11223. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11224. sd->idletime = last_tick;
  11225. }
  11226. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11227. }
  11228. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11229. /// 0143 <npc id>.L <value>.L
  11230. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  11231. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11232. int npcid = RFIFOL(fd,info->pos[0]);
  11233. int amount = (int)RFIFOL(fd,info->pos[1]);
  11234. sd->npc_amount = amount;
  11235. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11236. sd->idletime = last_tick;
  11237. }
  11238. npc_scriptcont(sd, npcid, false);
  11239. }
  11240. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11241. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11242. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  11243. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11244. int message_len = RFIFOW(fd,info->pos[0])-8;
  11245. int npcid = RFIFOL(fd,info->pos[1]);
  11246. const char* message = RFIFOCP(fd,info->pos[2]);
  11247. if( message_len <= 0 )
  11248. return; // invalid input
  11249. #if PACKETVER >= 20151001
  11250. message_len++;
  11251. #endif
  11252. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11253. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11254. sd->idletime = last_tick;
  11255. }
  11256. npc_scriptcont(sd, npcid, false);
  11257. }
  11258. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11259. /// 0146 <npc id>.L
  11260. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11261. {
  11262. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11263. return;
  11264. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11265. sd->idletime = last_tick;
  11266. }
  11267. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11268. }
  11269. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11270. /// 0178 <index>.W
  11271. /// index:
  11272. /// -1 = cancel
  11273. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11274. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11275. if (sd->menuskill_id != MC_IDENTIFY)
  11276. return;
  11277. // Ignore the request
  11278. // - Invalid item index
  11279. // - Invalid item ID or item doesn't exist
  11280. // - Item is already identified
  11281. if (idx < 0 || idx >= MAX_INVENTORY ||
  11282. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11283. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11284. sd->state.workinprogress = WIP_DISABLE_NONE;
  11285. clif_menuskill_clear(sd);
  11286. return;
  11287. }
  11288. skill_identify(sd, idx);
  11289. clif_menuskill_clear(sd);
  11290. }
  11291. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11292. /// 01ae <name id>.W
  11293. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11294. if (pc_istrading(sd)) {
  11295. //Make it fail to avoid shop exploits where you sell something different than you see.
  11296. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11297. clif_menuskill_clear(sd);
  11298. return;
  11299. }
  11300. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11301. switch (sd->menuskill_id) {
  11302. case AC_MAKINGARROW:
  11303. skill_arrow_create(sd,p->itemId);
  11304. break;
  11305. case SA_CREATECON:
  11306. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11307. break;
  11308. case GC_POISONINGWEAPON:
  11309. skill_poisoningweapon(sd,p->itemId);
  11310. break;
  11311. case NC_MAGICDECOY:
  11312. skill_magicdecoy(sd,p->itemId);
  11313. break;
  11314. }
  11315. clif_menuskill_clear(sd);
  11316. }
  11317. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11318. /// 01ce <skill id>.L
  11319. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11320. {
  11321. if (sd->menuskill_id != SA_AUTOSPELL)
  11322. return;
  11323. sd->state.workinprogress = WIP_DISABLE_NONE;
  11324. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11325. clif_menuskill_clear(sd);
  11326. }
  11327. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11328. /// 017a <card index>.W
  11329. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11330. {
  11331. if (sd->state.trading != 0)
  11332. return;
  11333. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11334. }
  11335. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11336. /// 017c <card index>.W <equip index>.W
  11337. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11338. {
  11339. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11340. if (sd->state.trading != 0)
  11341. return;
  11342. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11343. }
  11344. /// Request of character's name by char ID.
  11345. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11346. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11347. /// There are various variants of this packet, some of them have padding between fields.
  11348. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11349. {
  11350. int charid;
  11351. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11352. map_reqnickdb(sd, charid);
  11353. }
  11354. /// /resetskill /resetstate (CZ_RESET).
  11355. /// Request to reset stats or skills.
  11356. /// 0197 <type>.W
  11357. /// type:
  11358. /// 0 = state
  11359. /// 1 = skill
  11360. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11361. char cmd[15];
  11362. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11363. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11364. else
  11365. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11366. is_atcommand(fd, sd, cmd, 1);
  11367. }
  11368. /// /lb /nlb (CZ_LOCALBROADCAST).
  11369. /// Request to broadcast a message on current map.
  11370. /// 019c <packet len>.W <text>.?B
  11371. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11372. {
  11373. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11374. char command[CHAT_SIZE_MAX+16];
  11375. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11376. char* msg = RFIFOCP(fd,info->pos[1]);
  11377. // as the length varies depending on the command used, just block unreasonably long strings
  11378. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11379. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11380. is_atcommand(fd, sd, command, 1);
  11381. }
  11382. /// Request to move an item from inventory to storage.
  11383. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11384. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11385. /// There are various variants of this packet, some of them have padding between fields.
  11386. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11387. {
  11388. int item_index, item_amount;
  11389. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11390. if (pc_istrading(sd))
  11391. return;
  11392. item_index = RFIFOW(fd,info->pos[0])-2;
  11393. item_amount = RFIFOL(fd,info->pos[1]);
  11394. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11395. return;
  11396. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11397. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11398. return;
  11399. }
  11400. if (sd->state.storage_flag == 1)
  11401. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11402. else
  11403. if (sd->state.storage_flag == 2)
  11404. storage_guild_storageadd(sd, item_index, item_amount);
  11405. else if (sd->state.storage_flag == 3)
  11406. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11407. }
  11408. /// Request to move an item from storage to inventory.
  11409. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11410. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11411. /// There are various variants of this packet, some of them have padding between fields.
  11412. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11413. {
  11414. int item_index, item_amount;
  11415. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11416. item_index = RFIFOW(fd,info->pos[0])-1;
  11417. item_amount = RFIFOL(fd,info->pos[1]);
  11418. if (sd->state.storage_flag == 1)
  11419. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11420. else if(sd->state.storage_flag == 2)
  11421. storage_guild_storageget(sd, item_index, item_amount);
  11422. else if(sd->state.storage_flag == 3)
  11423. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11424. }
  11425. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11426. /// 0129 <index>.W <amount>.L
  11427. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11428. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11429. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11430. int amount = RFIFOL(fd,info->pos[1]);
  11431. if( sd->state.vending )
  11432. return;
  11433. if (!pc_iscarton(sd))
  11434. return;
  11435. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11436. return;
  11437. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11438. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11439. return;
  11440. }
  11441. if (sd->state.storage_flag == 1)
  11442. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11443. else if (sd->state.storage_flag == 2)
  11444. storage_guild_storageaddfromcart(sd, idx, amount);
  11445. else if (sd->state.storage_flag == 3)
  11446. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11447. }
  11448. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11449. /// 0128 <index>.W <amount>.L
  11450. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11451. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11452. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11453. int amount = RFIFOL(fd,info->pos[1]);
  11454. if( sd->state.vending )
  11455. return;
  11456. if (!pc_iscarton(sd))
  11457. return;
  11458. if (sd->state.storage_flag == 1)
  11459. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11460. else
  11461. if (sd->state.storage_flag == 2)
  11462. storage_guild_storagegettocart(sd, idx, amount);
  11463. else if (sd->state.storage_flag == 3)
  11464. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11465. }
  11466. /// Request to close storage (CZ_CLOSE_STORE).
  11467. /// 00f7
  11468. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11469. {
  11470. if( sd->state.storage_flag == 1 )
  11471. storage_storageclose(sd);
  11472. else
  11473. if( sd->state.storage_flag == 2 )
  11474. storage_guild_storageclose(sd);
  11475. else if( sd->state.storage_flag == 3 )
  11476. storage_premiumStorage_close(sd);
  11477. }
  11478. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11479. /// 023a <info>.W
  11480. /// info:
  11481. /// 0 = password has not been set yet
  11482. /// 1 = storage is password-protected
  11483. /// 8 = too many wrong passwords
  11484. /// ? = ignored
  11485. /// NOTE: This packet is only available on certain non-kRO clients.
  11486. void clif_storagepassword(struct map_session_data* sd, short info)
  11487. {
  11488. int fd = sd->fd;
  11489. WFIFOHEAD(fd,packet_len(0x23a));
  11490. WFIFOW(fd,0) = 0x23a;
  11491. WFIFOW(fd,2) = info;
  11492. WFIFOSET(fd,packet_len(0x23a));
  11493. }
  11494. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11495. /// 023b <type>.W <password>.16B <new password>.16B
  11496. /// type:
  11497. /// 2 = change password
  11498. /// 3 = check password
  11499. /// NOTE: This packet is only available on certain non-kRO clients.
  11500. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11501. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11502. // int type = RFIFOW(fd,info->pos[0]);
  11503. // char* password = RFIFOP(fd,info->pos[1]);
  11504. // char* new_password = RFIFOP(fd,info->pos[2]);
  11505. // storage_changepass(sd,password,new_password);
  11506. }
  11507. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11508. /// 023c <result>.W <error count>.W
  11509. /// result:
  11510. /// 4 = password change success
  11511. /// 5 = password change failure
  11512. /// 6 = password check success
  11513. /// 7 = password check failure
  11514. /// 8 = too many wrong passwords
  11515. /// ? = ignored
  11516. /// NOTE: This packet is only available on certain non-kRO clients.
  11517. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11518. {
  11519. int fd = sd->fd;
  11520. WFIFOHEAD(fd,packet_len(0x23c));
  11521. WFIFOW(fd,0) = 0x23c;
  11522. WFIFOW(fd,2) = result;
  11523. WFIFOW(fd,4) = error_count;
  11524. WFIFOSET(fd,packet_len(0x23c));
  11525. }
  11526. /// Party creation request
  11527. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11528. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11529. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11530. name[NAME_LENGTH-1] = '\0';
  11531. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11532. clif_displaymessage(fd, msg_txt(sd,227));
  11533. return;
  11534. }
  11535. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11536. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11537. return;
  11538. }
  11539. party_create(sd,name,0,0);
  11540. }
  11541. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11542. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11543. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11544. char* name = RFIFOCP(fd,info->pos[0]);
  11545. int item1 = RFIFOB(fd,info->pos[1]);
  11546. int item2 = RFIFOB(fd,info->pos[2]);
  11547. name[NAME_LENGTH-1] = '\0';
  11548. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11549. clif_displaymessage(fd, msg_txt(sd,227));
  11550. return;
  11551. }
  11552. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11553. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11554. return;
  11555. }
  11556. party_create(sd,name,item1,item2);
  11557. }
  11558. /// Party invitation request
  11559. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11560. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11561. {
  11562. struct map_session_data *t_sd;
  11563. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11564. clif_displaymessage(fd, msg_txt(sd,227));
  11565. return;
  11566. }
  11567. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11568. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11569. clif_noask_sub(sd, t_sd, 1);
  11570. return;
  11571. }
  11572. party_invite(sd, t_sd);
  11573. }
  11574. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11575. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11576. struct map_session_data *t_sd;
  11577. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11578. name[NAME_LENGTH-1] = '\0';
  11579. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11580. clif_displaymessage(fd, msg_txt(sd,227));
  11581. return;
  11582. }
  11583. t_sd = map_nick2sd(name,false);
  11584. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11585. clif_noask_sub(sd, t_sd, 1);
  11586. return;
  11587. }
  11588. party_invite(sd, t_sd);
  11589. }
  11590. /// Party invitation reply
  11591. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11592. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11593. /// flag:
  11594. /// 0 = reject
  11595. /// 1 = accept
  11596. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11597. {
  11598. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11599. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11600. RFIFOL(fd,info->pos[1]));
  11601. }
  11602. //(CZ_PARTY_JOIN_REQ_ACK)
  11603. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11604. {
  11605. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11606. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11607. RFIFOB(fd,info->pos[1]));
  11608. }
  11609. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11610. /// 0100
  11611. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11612. {
  11613. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11614. clif_displaymessage(fd, msg_txt(sd,227));
  11615. return;
  11616. }
  11617. party_leave(sd);
  11618. }
  11619. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11620. /// 0103 <account id>.L <char name>.24B
  11621. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11622. {
  11623. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11624. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11625. clif_displaymessage(fd, msg_txt(sd,227));
  11626. return;
  11627. }
  11628. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11629. RFIFOCP(fd,info->pos[1]));
  11630. }
  11631. /// Request to change party options.
  11632. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11633. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11634. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11635. {
  11636. struct party_data *p;
  11637. int i,expflag;
  11638. int cmd = RFIFOW(fd,0);
  11639. struct s_packet_db* info = &packet_db[cmd];
  11640. if( !sd->status.party_id )
  11641. return;
  11642. p = party_search(sd->status.party_id);
  11643. if( p == NULL )
  11644. return;
  11645. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11646. if( i == MAX_PARTY )
  11647. return; //Shouldn't happen
  11648. if( !p->party.member[i].leader )
  11649. return;
  11650. expflag = RFIFOL(fd,info->pos[0]);
  11651. if(cmd == 0x0102){ //Client can't change the item-field
  11652. party_changeoption(sd, expflag, p->party.item);
  11653. }
  11654. else {
  11655. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11656. party_changeoption(sd, expflag, itemflag);
  11657. }
  11658. }
  11659. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11660. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11661. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11662. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11663. // validate packet and retrieve name and message
  11664. if( !clif_process_message( sd, false, name, message, output ) )
  11665. return;
  11666. party_send_message(sd, output, strlen(output) + 1 );
  11667. }
  11668. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11669. /// 07da <account id>.L
  11670. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11671. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11672. }
  11673. /// Party Booking in KRO [Spiria]
  11674. ///
  11675. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11676. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11677. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11678. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11679. short level = RFIFOW(fd,info->pos[0]);
  11680. short mapid = RFIFOW(fd,info->pos[1]);
  11681. int idxpbj = info->pos[2];
  11682. short job[MAX_PARTY_BOOKING_JOBS];
  11683. int i;
  11684. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11685. job[i] = RFIFOB(fd,idxpbj+i*2);
  11686. party_booking_register(sd, level, mapid, job);
  11687. }
  11688. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11689. /// 0803 <result>.W
  11690. /// result:
  11691. /// 0 = success
  11692. /// 1 = failure
  11693. /// 2 = already registered
  11694. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11695. {
  11696. int fd = sd->fd;
  11697. WFIFOHEAD(fd,packet_len(0x803));
  11698. WFIFOW(fd,0) = 0x803;
  11699. WFIFOW(fd,2) = flag;
  11700. WFIFOSET(fd,packet_len(0x803));
  11701. }
  11702. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11703. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11704. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11705. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11706. short level = RFIFOW(fd,info->pos[0]);
  11707. short mapid = RFIFOW(fd,info->pos[1]);
  11708. short job = RFIFOW(fd,info->pos[2]);
  11709. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11710. short resultcount = RFIFOW(fd,info->pos[4]);
  11711. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11712. }
  11713. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11714. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11715. /// more results:
  11716. /// 0 = no
  11717. /// 1 = yes
  11718. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11719. {
  11720. int i, j;
  11721. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11722. struct party_booking_ad_info *pb_ad;
  11723. WFIFOHEAD(fd,size*count + 5);
  11724. WFIFOW(fd,0) = 0x805;
  11725. WFIFOW(fd,2) = size*count + 5;
  11726. WFIFOB(fd,4) = more_result;
  11727. for(i=0; i<count; i++)
  11728. {
  11729. pb_ad = results[i];
  11730. WFIFOL(fd,i*size+5) = pb_ad->index;
  11731. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11732. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11733. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11734. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11735. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11736. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11737. }
  11738. WFIFOSET(fd,WFIFOW(fd,2));
  11739. }
  11740. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11741. /// 0806
  11742. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11743. {
  11744. if(party_booking_delete(sd))
  11745. clif_PartyBookingDeleteAck(sd, 0);
  11746. }
  11747. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11748. /// 0807 <result>.W
  11749. /// result:
  11750. /// 0 = success
  11751. /// 1 = success (auto-removed expired ad)
  11752. /// 2 = failure
  11753. /// 3 = nothing registered
  11754. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11755. {
  11756. int fd = sd->fd;
  11757. WFIFOHEAD(fd,packet_len(0x807));
  11758. WFIFOW(fd,0) = 0x807;
  11759. WFIFOW(fd,2) = flag;
  11760. WFIFOSET(fd,packet_len(0x807));
  11761. }
  11762. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11763. /// 0808 { <job>.W }*6
  11764. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11765. {
  11766. short job[MAX_PARTY_BOOKING_JOBS];
  11767. int i;
  11768. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11769. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11770. job[i] = RFIFOW(fd,idxpbu+i*2);
  11771. party_booking_update(sd, job);
  11772. }
  11773. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11774. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11775. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11776. {
  11777. int i;
  11778. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11779. if(pb_ad == NULL) return;
  11780. WBUFW(buf,0) = 0x809;
  11781. WBUFL(buf,2) = pb_ad->index;
  11782. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11783. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11784. WBUFW(buf,34) = pb_ad->p_detail.level;
  11785. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11786. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11787. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11788. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11789. }
  11790. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11791. /// 080a <index>.L { <job>.W }*6
  11792. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11793. {
  11794. int i;
  11795. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11796. if(pb_ad == NULL) return;
  11797. WBUFW(buf,0) = 0x80a;
  11798. WBUFL(buf,2) = pb_ad->index;
  11799. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11800. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11801. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11802. }
  11803. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11804. /// 080b <index>.L
  11805. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11806. {
  11807. uint8 buf[6];
  11808. WBUFW(buf,0) = 0x80b;
  11809. WBUFL(buf,2) = index;
  11810. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11811. }
  11812. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11813. /// 012e
  11814. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11815. {
  11816. vending_closevending(sd);
  11817. }
  11818. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11819. /// 0130 <account id>.L
  11820. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11821. {
  11822. if( sd->npc_id ) {// using an NPC
  11823. return;
  11824. }
  11825. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11826. }
  11827. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11828. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11829. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11830. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11831. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11832. int id = (int)RFIFOL(fd,info->pos[1]);
  11833. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11834. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11835. // whether it fails or not, the buy window is closed
  11836. sd->vended_id = 0;
  11837. }
  11838. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11839. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11840. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11841. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11842. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11843. int aid = (int)RFIFOL(fd,info->pos[1]);
  11844. int uid = (int)RFIFOL(fd,info->pos[2]);
  11845. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11846. vending_purchasereq(sd, aid, uid, data, len/4);
  11847. // whether it fails or not, the buy window is closed
  11848. sd->vended_id = 0;
  11849. }
  11850. /// Confirm or cancel the shop preparation window.
  11851. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11852. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11853. /// result:
  11854. /// 0 = canceled
  11855. /// 1 = open
  11856. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11857. int cmd = RFIFOW(fd,0);
  11858. struct s_packet_db* info = &packet_db[cmd];
  11859. short len = (short)RFIFOW(fd,info->pos[0]);
  11860. const char* message = RFIFOCP(fd,info->pos[1]);
  11861. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11862. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11863. len -= 84;
  11864. }
  11865. else { //(CZ_REQ_OPENSTORE2)
  11866. bool flag;
  11867. len -= 85;
  11868. flag = RFIFOB(fd,info->pos[2]) != 0;
  11869. if (!flag) {
  11870. sd->state.prevend = 0;
  11871. sd->state.workinprogress = WIP_DISABLE_NONE;
  11872. }
  11873. }
  11874. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11875. return;
  11876. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11877. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11878. return;
  11879. }
  11880. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11881. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11882. return;
  11883. }
  11884. if( message[0] == '\0' ) // invalid input
  11885. return;
  11886. vending_openvending(sd, message, data, len/8, NULL);
  11887. }
  11888. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11889. /// 0165 <char id>.L <guild name>.24B
  11890. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11891. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11892. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11893. name[NAME_LENGTH-1] = '\0';
  11894. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11895. clif_displaymessage(fd, msg_txt(sd,228));
  11896. return;
  11897. }
  11898. if(sd->clan){
  11899. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11900. return;
  11901. }
  11902. guild_create(sd, name);
  11903. }
  11904. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11905. /// 014d
  11906. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11907. {
  11908. clif_guild_masterormember(sd);
  11909. }
  11910. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11911. /// 014f <type>.L
  11912. /// type:
  11913. /// 0 = basic info
  11914. /// 1 = member manager
  11915. /// 2 = positions
  11916. /// 3 = skills
  11917. /// 4 = expulsion list
  11918. /// 5 = unknown (GM_ALLGUILDLIST)
  11919. /// 6 = notice
  11920. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11921. {
  11922. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11923. if( !sd->status.guild_id && !sd->bg_id )
  11924. return;
  11925. switch( type )
  11926. {
  11927. case 0: // Basic Information Guild, hostile alliance information
  11928. clif_guild_basicinfo(sd);
  11929. clif_guild_allianceinfo(sd);
  11930. break;
  11931. case 1: // Members list, list job title
  11932. clif_guild_positionnamelist(sd);
  11933. clif_guild_memberlist(sd);
  11934. break;
  11935. case 2: // List job title, title information list
  11936. clif_guild_positionnamelist(sd);
  11937. clif_guild_positioninfolist(sd);
  11938. break;
  11939. case 3: // Skill list
  11940. clif_guild_skillinfo(sd);
  11941. break;
  11942. case 4: // Expulsion list
  11943. clif_guild_expulsionlist(sd);
  11944. break;
  11945. default:
  11946. ShowError("clif: guild request info: unknown type %d\n", type);
  11947. break;
  11948. }
  11949. }
  11950. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11951. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11952. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11953. {
  11954. int i;
  11955. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11956. int len = RFIFOW(fd,info->pos[0]);
  11957. int idxgpos = info->pos[1];
  11958. if(!sd->state.gmaster_flag)
  11959. return;
  11960. for(i = idxgpos; i < len; i += 40 ){
  11961. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11962. }
  11963. }
  11964. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11965. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11966. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11967. {
  11968. int i;
  11969. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11970. int len = RFIFOW(fd,info->pos[0]);
  11971. int idxgpos = info->pos[1];
  11972. if(!sd->state.gmaster_flag)
  11973. return;
  11974. // Guild leadership change
  11975. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11976. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11977. clif_msg(sd, GUILD_MASTER_WOE);
  11978. return;
  11979. }
  11980. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11981. clif_msg(sd, GUILD_MASTER_DELAY);
  11982. return;
  11983. }
  11984. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11985. return;
  11986. }
  11987. for(i=idxgpos;i<len;i+=12){
  11988. int position = RFIFOL(fd,i+8);
  11989. if( position > 0 ){
  11990. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11991. }
  11992. }
  11993. }
  11994. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11995. /// 0151 <guild id>.L
  11996. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11997. {
  11998. struct guild* g;
  11999. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12000. if( (g = guild_search(guild_id)) != NULL )
  12001. clif_guild_emblem(sd,g);
  12002. }
  12003. /// Validates data of a guild emblem (compressed bitmap)
  12004. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  12005. EMBVALIDATE_SUCCESS = 0,
  12006. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  12007. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  12008. };
  12009. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  12010. {
  12011. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  12012. unsigned long buf_len = sizeof(buf);
  12013. int offset = 0;
  12014. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  12015. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  12016. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  12017. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  12018. ))
  12019. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  12020. if(battle_config.emblem_transparency_limit != 100) {
  12021. int i, transcount = 1, tmp[3];
  12022. for(i = offset; i < buf_len-1; i++) {
  12023. int j = i%3;
  12024. tmp[j] = RBUFL(buf,i);
  12025. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  12026. transcount++;
  12027. }
  12028. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  12029. return EMBVALIDATE_ERR_TRANSPARENCY;
  12030. }
  12031. return EMBVALIDATE_SUCCESS;
  12032. }
  12033. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  12034. /// 0153 <packet len>.W <emblem data>.?B
  12035. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  12036. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12037. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  12038. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  12039. int emb_val=0;
  12040. if( !emblem_len || !sd->state.gmaster_flag )
  12041. return;
  12042. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  12043. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  12044. return;
  12045. }
  12046. emb_val = clif_validate_emblem(emblem, emblem_len);
  12047. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  12048. 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);
  12049. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  12050. return;
  12051. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  12052. char output[128];
  12053. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  12054. 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"
  12055. return;
  12056. }
  12057. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  12058. }
  12059. /// Request to update the guild emblem id (version, according to Gravity)
  12060. /// 0b46 <guild id>.L <version>.L
  12061. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  12062. nullpo_retv(sd);
  12063. #if PACKETVER >= 20190724
  12064. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  12065. guild* g = sd->guild;
  12066. if (g == nullptr || g->guild_id != p->guild_id)
  12067. return;
  12068. if (!sd->state.gmaster_flag)
  12069. return;
  12070. if (!battle_config.emblem_woe_change && is_agit_start()) {
  12071. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  12072. return;
  12073. }
  12074. guild_change_emblem_version(sd, p->version);
  12075. #endif
  12076. }
  12077. /// Guild notice update request (CZ_GUILD_NOTICE).
  12078. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  12079. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  12080. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12081. int guild_id = RFIFOL(fd,info->pos[0]);
  12082. char* msg1 = RFIFOCP(fd,info->pos[1]);
  12083. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12084. if(!sd->state.gmaster_flag)
  12085. return;
  12086. // compensate for some client defects when using multilanguage mode
  12087. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12088. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12089. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12090. guild_change_notice(sd, guild_id, msg1, msg2);
  12091. }
  12092. // Helper function for guild invite functions
  12093. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  12094. {
  12095. if (t_sd == NULL) // not online or does not exist
  12096. return 1;
  12097. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12098. clif_displaymessage(fd, msg_txt(sd,228));
  12099. return 1;
  12100. }
  12101. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12102. clif_noask_sub(sd, t_sd, 2);
  12103. return 1;
  12104. }
  12105. // Players in a clan can not join a guild
  12106. if(t_sd && t_sd->clan){
  12107. return 1;
  12108. }
  12109. guild_invite(sd, t_sd);
  12110. return 0;
  12111. }
  12112. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12113. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12114. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  12115. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12116. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12117. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12118. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12119. if (clif_sub_guild_invite(fd, sd, t_sd))
  12120. return;
  12121. }
  12122. /// Guild invite request (/guildinvite)
  12123. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12124. void
  12125. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  12126. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12127. if (clif_sub_guild_invite(fd, sd, t_sd))
  12128. return;
  12129. }
  12130. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12131. /// 016b <guild id>.L <answer>.L
  12132. /// answer:
  12133. /// 0 = refuse
  12134. /// 1 = accept
  12135. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  12136. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12137. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12138. RFIFOL(fd,info->pos[1]));
  12139. }
  12140. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12141. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12142. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  12143. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12144. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12145. clif_displaymessage(fd, msg_txt(sd,228));
  12146. return;
  12147. }
  12148. if( sd->bg_id ) {
  12149. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12150. return;
  12151. }
  12152. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12153. RFIFOL(fd,info->pos[1]),
  12154. RFIFOL(fd,info->pos[2]),
  12155. RFIFOCP(fd,info->pos[3]));
  12156. }
  12157. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12158. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12159. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  12160. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12161. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12162. { // Guild locked.
  12163. clif_displaymessage(fd, msg_txt(sd,228));
  12164. return;
  12165. }
  12166. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12167. RFIFOL(fd,info->pos[1]),
  12168. RFIFOL(fd,info->pos[2]),
  12169. RFIFOCP(fd,info->pos[3]));
  12170. }
  12171. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12172. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12173. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  12174. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12175. // validate packet and retrieve name and message
  12176. if( !clif_process_message( sd, false, name, message, output ) )
  12177. return;
  12178. if( sd->bg_id )
  12179. bg_send_message(sd, output, strlen(output) );
  12180. else
  12181. guild_send_message(sd, output, strlen(output) );
  12182. }
  12183. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12184. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12185. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  12186. {
  12187. struct map_session_data *t_sd;
  12188. if(!sd->state.gmaster_flag)
  12189. return;
  12190. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12191. clif_displaymessage(fd, msg_txt(sd,228));
  12192. return;
  12193. }
  12194. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12195. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12196. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12197. // @noask [LuzZza]
  12198. if(t_sd && t_sd->state.noask) {
  12199. clif_noask_sub(sd, t_sd, 3);
  12200. return;
  12201. }
  12202. guild_reqalliance(sd,t_sd);
  12203. }
  12204. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12205. /// 0172 <inviter account id>.L <answer>.L
  12206. /// answer:
  12207. /// 0 = refuse
  12208. /// 1 = accept
  12209. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  12210. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12211. guild_reply_reqalliance(sd,
  12212. RFIFOL(fd,info->pos[0]),
  12213. RFIFOL(fd,info->pos[1]));
  12214. }
  12215. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12216. /// 0183 <opponent guild id>.L <relation>.L
  12217. /// relation:
  12218. /// 0 = Ally
  12219. /// 1 = Enemy
  12220. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  12221. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12222. if(!sd->state.gmaster_flag)
  12223. return;
  12224. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12225. clif_displaymessage(fd, msg_txt(sd,228));
  12226. return;
  12227. }
  12228. guild_delalliance(sd,
  12229. RFIFOL(fd,info->pos[0]),
  12230. RFIFOL(fd,info->pos[1]));
  12231. }
  12232. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12233. /// 0180 <account id>.L
  12234. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  12235. {
  12236. struct map_session_data *t_sd;
  12237. if(!sd->state.gmaster_flag)
  12238. return;
  12239. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12240. clif_displaymessage(fd, msg_txt(sd,228));
  12241. return;
  12242. }
  12243. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12244. // @noask [LuzZza]
  12245. if(t_sd && t_sd->state.noask) {
  12246. clif_noask_sub(sd, t_sd, 4);
  12247. return;
  12248. }
  12249. guild_opposition(sd,t_sd);
  12250. }
  12251. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12252. /// 015d <key>.40B
  12253. /// key:
  12254. /// now guild name; might have been (intended) email, since the
  12255. /// field name and size is same as the one in CH_DELETE_CHAR.
  12256. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  12257. {
  12258. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12259. clif_displaymessage(fd, msg_txt(sd,228));
  12260. return;
  12261. }
  12262. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12263. }
  12264. /// Pet
  12265. ///
  12266. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12267. /// 01a1 <type>.B
  12268. /// type:
  12269. /// 0 = pet information
  12270. /// 1 = feed
  12271. /// 2 = performance
  12272. /// 3 = return to egg
  12273. /// 4 = unequip accessory
  12274. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12275. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12276. }
  12277. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12278. /// 019f <id>.L
  12279. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12280. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12281. }
  12282. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12283. /// 01a7 <index>.W
  12284. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12285. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12286. return;
  12287. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12288. clif_menuskill_clear(sd);
  12289. }
  12290. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12291. /// 01a9 <data>.L
  12292. /// data:
  12293. /// is either emotion (@see enum emotion_type) or a compound value
  12294. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12295. /// entry (given in parentheses) in data\pettalktable.xml
  12296. /// act id:
  12297. /// 0 = feeding
  12298. /// 1 = hunting
  12299. /// 2 = danger
  12300. /// 3 = dead
  12301. /// 4 = normal (stand)
  12302. /// 5 = special performance (perfor_s)
  12303. /// 6 = level up (levelup)
  12304. /// 7 = performance 1 (perfor_1)
  12305. /// 8 = performance 2 (perfor_2)
  12306. /// 9 = performance 3 (perfor_3)
  12307. /// 10 = log-in greeting (connect)
  12308. /// hungry value:
  12309. /// 0 = very hungry (hungry)
  12310. /// 1 = hungry (bit_hungry)
  12311. /// 2 = satisfied (noting)
  12312. /// 3 = stuffed (full)
  12313. /// 4 = full (so_full)
  12314. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12315. {
  12316. if(sd->pd)
  12317. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12318. }
  12319. /// Request to change pet's name (CZ_RENAME_PET).
  12320. /// 01a5 <name>.24B
  12321. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12322. {
  12323. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12324. }
  12325. /// /kill (CZ_DISCONNECT_CHARACTER).
  12326. /// Request to disconnect a character.
  12327. /// 00cc <account id>.L
  12328. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12329. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12330. {
  12331. struct block_list *target;
  12332. int tid;
  12333. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12334. target = map_id2bl(tid);
  12335. if (!target) {
  12336. clif_GM_kickack(sd, 0);
  12337. return;
  12338. }
  12339. switch (target->type) {
  12340. case BL_PC:
  12341. {
  12342. char command[NAME_LENGTH+6];
  12343. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12344. is_atcommand(fd, sd, command, 1);
  12345. }
  12346. break;
  12347. /**
  12348. * This one does not invoke any atcommand, so we need to check for permissions.
  12349. */
  12350. case BL_MOB:
  12351. {
  12352. char command[100];
  12353. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12354. clif_GM_kickack(sd, 0);
  12355. return;
  12356. }
  12357. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12358. log_atcommand(sd, command);
  12359. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12360. }
  12361. break;
  12362. case BL_NPC:
  12363. {
  12364. struct npc_data* nd = (struct npc_data *)target;
  12365. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12366. npc_unload_duplicates(nd);
  12367. npc_unload(nd,true);
  12368. npc_read_event_script();
  12369. }
  12370. }
  12371. break;
  12372. default:
  12373. clif_GM_kickack(sd, 0);
  12374. }
  12375. }
  12376. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12377. /// Request to disconnect all characters.
  12378. /// 00ce
  12379. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12380. char cmd[15];
  12381. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12382. is_atcommand(fd, sd, cmd, 1);
  12383. }
  12384. /// /remove (CZ_REMOVE_AID).
  12385. /// Request to warp to a character with given login ID.
  12386. /// 01ba <account name>.24B
  12387. /// /shift (CZ_SHIFT).
  12388. /// Request to warp to a character with given name.
  12389. /// 01bb <char name>.24B
  12390. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12391. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12392. char *player_name;
  12393. char command[NAME_LENGTH+8];
  12394. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12395. player_name[NAME_LENGTH-1] = '\0';
  12396. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12397. is_atcommand(fd, sd, command, 1);
  12398. }
  12399. /// /remove (CZ_REMOVE_AID_SSO).
  12400. /// Request to warp to a character with given account ID.
  12401. /// 0843 <account id>.L
  12402. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12403. {
  12404. uint32 account_id;
  12405. struct map_session_data* pl_sd;
  12406. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12407. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12408. char command[NAME_LENGTH+8];
  12409. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12410. is_atcommand(fd, sd, command, 1);
  12411. }
  12412. }
  12413. /// /recall (CZ_RECALL).
  12414. /// Request to summon a player with given login ID to own position.
  12415. /// 01bc <account name>.24B
  12416. /// /summon (CZ_RECALL_GID).
  12417. /// Request to summon a player with given name to own position.
  12418. /// 01bd <char name>.24B
  12419. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12420. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12421. char *player_name;
  12422. char command [NAME_LENGTH+8];
  12423. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12424. player_name[NAME_LENGTH-1] = '\0';
  12425. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12426. is_atcommand(fd, sd, command, 1);
  12427. }
  12428. /// /recall (CZ_RECALL_SSO).
  12429. /// Request to summon a player with given account ID to own position.
  12430. /// 0842 <account id>.L
  12431. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12432. {
  12433. uint32 account_id;
  12434. struct map_session_data* pl_sd;
  12435. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12436. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12437. char command[NAME_LENGTH+8];
  12438. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12439. is_atcommand(fd, sd, command, 1);
  12440. }
  12441. }
  12442. /// /item /monster (CZ_ITEM_CREATE).
  12443. /// Request to execute GM commands.
  12444. /// Usage:
  12445. /// /item n - summon n monster or acquire n item/s
  12446. /// /item money - grants 2147483647 zenies
  12447. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12448. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12449. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12450. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12451. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12452. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12453. /// 013f <item/mob name>.24B
  12454. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12455. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12456. {
  12457. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12458. int mob_id = 0;
  12459. StringBuf command;
  12460. char *str;
  12461. //#if PACKETVER >= 20131218
  12462. // char str[100];
  12463. //#else
  12464. // char str[24];
  12465. //#endif
  12466. str = RFIFOCP(fd,info->pos[0]);
  12467. if (!str || str[0] == '\0')
  12468. return;
  12469. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12470. return;
  12471. trim(str);
  12472. // Zeny
  12473. if( strcmpi(str, "money") == 0 ) {
  12474. StringBuf_Init(&command);
  12475. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12476. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12477. StringBuf_Destroy(&command);
  12478. return;
  12479. }
  12480. std::shared_ptr<item_data> id = item_db.searchname( str );
  12481. // Item
  12482. if( id ){
  12483. StringBuf_Init(&command);
  12484. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12485. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12486. }else{
  12487. if (id->flag.guid)
  12488. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12489. else
  12490. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12491. }
  12492. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12493. StringBuf_Destroy(&command);
  12494. return;
  12495. }
  12496. // Monster
  12497. if ((mob_id = mobdb_searchname(str)) == 0)
  12498. mob_id = mobdb_checkid(atoi(str));
  12499. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12500. if( mob != nullptr ) {
  12501. StringBuf_Init(&command);
  12502. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12503. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12504. StringBuf_Destroy(&command);
  12505. return;
  12506. }
  12507. }
  12508. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12509. /// 019d <effect state>.L
  12510. /// effect state:
  12511. /// TODO: Any OPTION_* ?
  12512. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12513. char cmd[6];
  12514. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12515. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12516. is_atcommand(fd, sd, cmd, 1);
  12517. }
  12518. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12519. /// 0149 <account id>.L <type>.B <value>.W
  12520. /// type:
  12521. /// 0 = positive points
  12522. /// 1 = negative points
  12523. /// 2 = self mute (+10 minutes)
  12524. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12525. {
  12526. int id, type, value;
  12527. struct map_session_data *dstsd;
  12528. char command[NAME_LENGTH+15];
  12529. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12530. id = RFIFOL(fd,info->pos[0]);
  12531. type = RFIFOB(fd,info->pos[1]);
  12532. value = RFIFOW(fd,info->pos[2]);
  12533. if( type == 0 )
  12534. value = -value;
  12535. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12536. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12537. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12538. return;
  12539. dstsd = map_id2sd(id);
  12540. if( dstsd == NULL )
  12541. return;
  12542. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12543. is_atcommand(fd, sd, command, 1);
  12544. }
  12545. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12546. /// GM adjustment of a player's manner value by -60.
  12547. /// 0212 <char name>.24B
  12548. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12549. {
  12550. char command[NAME_LENGTH+15];
  12551. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12552. name[NAME_LENGTH-1] = '\0';
  12553. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12554. is_atcommand(fd, sd, command, 1);
  12555. }
  12556. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12557. /// 01e0 <account id>.L <account name>.24B
  12558. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12559. {
  12560. WFIFOHEAD(fd,packet_len(0x1e0));
  12561. WFIFOW(fd,0) = 0x1e0;
  12562. WFIFOL(fd,2) = account_id;
  12563. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12564. WFIFOSET(fd,packet_len(0x1e0));
  12565. }
  12566. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12567. /// 01df <account id>.L
  12568. //! TODO: Figure out how does this actually work
  12569. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12570. {
  12571. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12572. /*
  12573. char query[30];
  12574. safesnprintf(query,sizeof(query),"%d", account_id);
  12575. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12576. */
  12577. clif_account_name(fd, account_id, "");
  12578. }
  12579. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12580. /// GM single cell type change request.
  12581. /// 0198 <x>.W <y>.W <type>.W
  12582. /// type:
  12583. /// 0 = not walkable
  12584. /// 1 = walkable
  12585. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12586. {
  12587. int x,y,type;
  12588. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12589. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12590. return;
  12591. x = RFIFOW(fd,info->pos[0]);
  12592. y = RFIFOW(fd,info->pos[1]);
  12593. type = RFIFOW(fd,info->pos[2]);
  12594. map_setgatcell(sd->bl.m,x,y,type);
  12595. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12596. //FIXME: once players leave the map, the client 'forgets' this information.
  12597. }
  12598. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12599. /// Request to allow/deny whispers from a nick.
  12600. /// 00cf <nick>.24B <type>.B
  12601. /// type:
  12602. /// 0 = (/ex nick) deny speech from nick
  12603. /// 1 = (/in nick) allow speech from nick
  12604. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12605. {
  12606. char* nick;
  12607. uint8 type;
  12608. int i;
  12609. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12610. nick = RFIFOCP(fd,info->pos[0]);
  12611. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12612. type = RFIFOB(fd,info->pos[1]);
  12613. if( type == 0 ) { // Add name to ignore list (block)
  12614. if (strcmp(wisp_server_name, nick) == 0) {
  12615. clif_wisexin(sd, type, 1); // fail
  12616. return;
  12617. }
  12618. // try to find a free spot, while checking for duplicates at the same time
  12619. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12620. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12621. clif_wisexin(sd, type, 2); // too many blocks
  12622. return;
  12623. }
  12624. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12625. clif_wisexin(sd, type, 0); // Aegis reports success.
  12626. return;
  12627. }
  12628. //Insert in position i
  12629. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12630. } else { // Remove name from ignore list (unblock)
  12631. // find entry
  12632. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12633. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12634. clif_wisexin(sd, type, 1); // fail
  12635. return;
  12636. }
  12637. // move everything one place down to overwrite removed entry
  12638. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12639. // wipe last entry
  12640. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12641. }
  12642. clif_wisexin(sd, type, 0); // success
  12643. }
  12644. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12645. /// Request to allow/deny all whispers.
  12646. /// 00d0 <type>.B
  12647. /// type:
  12648. /// 0 = (/exall) deny all speech
  12649. /// 1 = (/inall) allow all speech
  12650. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12651. {
  12652. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12653. if( type == 0 ) {// Deny all
  12654. if( sd->state.ignoreAll ) {
  12655. flag = 1; // fail
  12656. } else {
  12657. sd->state.ignoreAll = 1;
  12658. flag = 0; // success
  12659. }
  12660. } else {//Unblock everyone
  12661. if( sd->state.ignoreAll ) {
  12662. sd->state.ignoreAll = 0;
  12663. flag = 0; // success
  12664. } else {
  12665. if (sd->ignore[0].name[0] != '\0')
  12666. { //Wipe the ignore list.
  12667. memset(sd->ignore, 0, sizeof(sd->ignore));
  12668. flag = 0; // success
  12669. } else {
  12670. flag = 1; // fail
  12671. }
  12672. }
  12673. }
  12674. clif_wisall(sd, type, flag);
  12675. }
  12676. /// Whisper ignore list (ZC_WHISPER_LIST).
  12677. /// 00d4 <packet len>.W { <char name>.24B }*
  12678. void clif_PMIgnoreList(struct map_session_data* sd)
  12679. {
  12680. int i, fd = sd->fd;
  12681. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12682. WFIFOW(fd,0) = 0xd4;
  12683. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12684. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12685. }
  12686. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12687. WFIFOSET(fd,WFIFOW(fd,2));
  12688. }
  12689. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12690. /// 00d3
  12691. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12692. {
  12693. clif_PMIgnoreList(sd);
  12694. }
  12695. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12696. /// 01e7
  12697. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12698. {
  12699. if (sd->state.doridori) return;
  12700. switch (sd->class_&MAPID_UPPERMASK) {
  12701. case MAPID_SOUL_LINKER:
  12702. case MAPID_STAR_GLADIATOR:
  12703. case MAPID_TAEKWON:
  12704. if (!sd->state.rest)
  12705. break;
  12706. case MAPID_SUPER_NOVICE:
  12707. case MAPID_SUPER_BABY:
  12708. case MAPID_SUPER_NOVICE_E:
  12709. case MAPID_SUPER_BABY_E:
  12710. sd->state.doridori=1;
  12711. break;
  12712. }
  12713. }
  12714. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12715. /// 01ed
  12716. /// Note: This packet is caused by 7 lines of any text, followed by
  12717. /// the prayer and an another line of any text. The prayer is
  12718. /// defined by lines 790~793 in data\msgstringtable.txt
  12719. /// "Dear angel, can you hear my voice?"
  12720. /// "I am" (space separated player name) "Super Novice~"
  12721. /// "Help me out~ Please~ T_T"
  12722. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12723. {
  12724. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12725. t_exp next = pc_nextbaseexp(sd);
  12726. if( next ) {
  12727. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12728. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12729. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12730. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12731. }
  12732. }
  12733. }
  12734. }
  12735. /// Friends List
  12736. ///
  12737. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12738. /// 0206 <account id>.L <char id>.L <state>.B
  12739. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12740. /// state:
  12741. /// 0 = online
  12742. /// 1 = offline
  12743. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12744. {
  12745. int i, fd = sd->fd;
  12746. //Seek friend.
  12747. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12748. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12749. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12750. return; //Not found
  12751. WFIFOHEAD(fd,packet_len(0x206));
  12752. WFIFOW(fd, 0) = 0x206;
  12753. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12754. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12755. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12756. #if PACKETVER >= 20180221
  12757. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12758. #endif
  12759. WFIFOSET(fd, packet_len(0x206));
  12760. }
  12761. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12762. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12763. {
  12764. uint32 account_id, char_id, online;
  12765. account_id = va_arg(ap, int);
  12766. char_id = va_arg(ap, int);
  12767. online = va_arg(ap, int);
  12768. clif_friendslist_toggle(sd, account_id, char_id, online);
  12769. return 0;
  12770. }
  12771. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12772. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12773. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12774. void clif_friendslist_send(struct map_session_data *sd)
  12775. {
  12776. int i = 0, n, fd = sd->fd;
  12777. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12778. const int size = 8 + NAME_LENGTH;
  12779. #else
  12780. const int size = 8;
  12781. #endif
  12782. // Send friends list
  12783. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12784. WFIFOW(fd, 0) = 0x201;
  12785. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12786. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12787. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12788. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12789. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12790. #endif
  12791. }
  12792. if (i) {
  12793. WFIFOW(fd,2) = 4 + size * i;
  12794. WFIFOSET(fd, WFIFOW(fd,2));
  12795. }
  12796. for (n = 0; n < i; n++) { //Sending the online players
  12797. if (map_charid2sd(sd->status.friends[n].char_id))
  12798. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12799. }
  12800. }
  12801. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12802. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12803. /// result:
  12804. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12805. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12806. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12807. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12808. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12809. {
  12810. int fd;
  12811. nullpo_retv(sd);
  12812. fd = sd->fd;
  12813. WFIFOHEAD(fd,packet_len(0x209));
  12814. WFIFOW(fd,0) = 0x209;
  12815. WFIFOW(fd,2) = type;
  12816. if (f_sd) {
  12817. WFIFOL(fd,4) = f_sd->status.account_id;
  12818. WFIFOL(fd,8) = f_sd->status.char_id;
  12819. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12820. }
  12821. WFIFOSET(fd, packet_len(0x209));
  12822. }
  12823. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12824. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12825. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12826. {
  12827. int fd = sd->fd;
  12828. WFIFOHEAD(fd,packet_len(0x207));
  12829. WFIFOW(fd,0) = 0x207;
  12830. WFIFOL(fd,2) = account_id;
  12831. WFIFOL(fd,6) = char_id;
  12832. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12833. WFIFOSET(fd,packet_len(0x207));
  12834. }
  12835. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12836. /// 0202 <name>.24B
  12837. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12838. {
  12839. struct map_session_data *f_sd;
  12840. int i;
  12841. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12842. // Friend doesn't exist (no player with this name)
  12843. if (f_sd == NULL) {
  12844. clif_displaymessage(fd, msg_txt(sd,3));
  12845. return;
  12846. }
  12847. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12848. return;
  12849. }
  12850. // ensure that the request player's friend list is not full
  12851. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12852. if( i == MAX_FRIENDS ){
  12853. clif_friendslist_reqack(sd, f_sd, 2);
  12854. return;
  12855. }
  12856. // @noask [LuzZza]
  12857. if(f_sd->state.noask) {
  12858. clif_noask_sub(sd, f_sd, 5);
  12859. return;
  12860. }
  12861. // Friend already exists
  12862. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12863. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12864. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12865. return;
  12866. }
  12867. }
  12868. f_sd->friend_req = sd->status.char_id;
  12869. sd->friend_req = f_sd->status.char_id;
  12870. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12871. }
  12872. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12873. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12874. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12875. /// reply:
  12876. /// 0 = rejected
  12877. /// 1 = accepted
  12878. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12879. {
  12880. struct map_session_data *f_sd;
  12881. uint32 account_id;
  12882. char reply;
  12883. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12884. account_id = RFIFOL(fd,info->pos[0]);
  12885. //char_id = RFIFOL(fd,info->pos[1]);
  12886. #if PACKETVER < 6
  12887. reply = RFIFOB(fd,info->pos[2]);
  12888. #else
  12889. reply = RFIFOL(fd,info->pos[2]);
  12890. #endif
  12891. if( sd->bl.id == account_id ) {// adding oneself as friend
  12892. return;
  12893. }
  12894. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12895. if (f_sd == NULL)
  12896. return;
  12897. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12898. clif_friendslist_reqack(f_sd, sd, 1);
  12899. else {
  12900. int i;
  12901. // Find an empty slot
  12902. for (i = 0; i < MAX_FRIENDS; i++)
  12903. if (f_sd->status.friends[i].char_id == 0)
  12904. break;
  12905. if (i == MAX_FRIENDS) {
  12906. clif_friendslist_reqack(f_sd, sd, 2);
  12907. return;
  12908. }
  12909. f_sd->status.friends[i].account_id = sd->status.account_id;
  12910. f_sd->status.friends[i].char_id = sd->status.char_id;
  12911. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12912. clif_friendslist_reqack(f_sd, sd, 0);
  12913. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12914. if (battle_config.friend_auto_add) {
  12915. // Also add f_sd to sd's friendlist.
  12916. for (i = 0; i < MAX_FRIENDS; i++) {
  12917. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12918. return; //No need to add anything.
  12919. if (sd->status.friends[i].char_id == 0)
  12920. break;
  12921. }
  12922. if (i == MAX_FRIENDS) {
  12923. clif_friendslist_reqack(sd, f_sd, 2);
  12924. return;
  12925. }
  12926. sd->status.friends[i].account_id = f_sd->status.account_id;
  12927. sd->status.friends[i].char_id = f_sd->status.char_id;
  12928. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12929. clif_friendslist_reqack(sd, f_sd, 0);
  12930. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12931. }
  12932. }
  12933. }
  12934. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12935. /// 0203 <account id>.L <char id>.L
  12936. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12937. {
  12938. struct map_session_data *f_sd = NULL;
  12939. uint32 account_id, char_id;
  12940. int i, j;
  12941. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12942. account_id = RFIFOL(fd,info->pos[0]);
  12943. char_id = RFIFOL(fd,info->pos[1]);
  12944. // Search friend
  12945. for (i = 0; i < MAX_FRIENDS &&
  12946. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12947. if (i == MAX_FRIENDS) {
  12948. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12949. return;
  12950. }
  12951. //remove from friend's list first
  12952. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12953. for (i = 0; i < MAX_FRIENDS &&
  12954. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12955. if (i != MAX_FRIENDS) {
  12956. // move all chars up
  12957. for(j = i + 1; j < MAX_FRIENDS; j++)
  12958. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12959. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12960. //should the guy be notified of some message? we should add it here if so
  12961. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12962. WFIFOW(f_sd->fd,0) = 0x20a;
  12963. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12964. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12965. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12966. }
  12967. } else { //friend not online -- ask char server to delete from his friendlist
  12968. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12969. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12970. return;
  12971. }
  12972. }
  12973. // We can now delete from original requester
  12974. for (i = 0; i < MAX_FRIENDS &&
  12975. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12976. // move all chars up
  12977. for(j = i + 1; j < MAX_FRIENDS; j++)
  12978. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12979. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12980. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12981. WFIFOHEAD(fd,packet_len(0x20a));
  12982. WFIFOW(fd,0) = 0x20a;
  12983. WFIFOL(fd,2) = account_id;
  12984. WFIFOL(fd,6) = char_id;
  12985. WFIFOSET(fd, packet_len(0x20a));
  12986. }
  12987. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12988. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12989. void clif_PVPInfo(struct map_session_data* sd)
  12990. {
  12991. int fd = sd->fd;
  12992. WFIFOHEAD(fd,packet_len(0x210));
  12993. WFIFOW(fd,0) = 0x210;
  12994. WFIFOL(fd,2) = sd->status.char_id;
  12995. WFIFOL(fd,6) = sd->status.account_id;
  12996. WFIFOL(fd,10) = sd->pvp_won; // times won
  12997. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12998. WFIFOL(fd,18) = sd->pvp_point;
  12999. WFIFOSET(fd, packet_len(0x210));
  13000. }
  13001. /// /pvpinfo (CZ_REQ_PVPPOINT).
  13002. /// 020f <char id>.L <account id>.L
  13003. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  13004. {
  13005. // TODO: Is there a way to use this on an another player (char/acc id)?
  13006. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13007. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13008. clif_PVPInfo(sd);
  13009. }
  13010. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  13011. /// 0254 <which>.B
  13012. /// which: (unused atm for security purpose)
  13013. /// 0 = sun
  13014. /// 1 = moon
  13015. /// 2 = star
  13016. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  13017. {
  13018. int i;
  13019. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13020. if (sd->menuskill_id != SG_FEEL)
  13021. return;
  13022. i = sd->menuskill_val-1;
  13023. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  13024. sd->feel_map[i].index = map_id2index(sd->bl.m);
  13025. sd->feel_map[i].m = sd->bl.m;
  13026. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  13027. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  13028. // clif_misceffect2(&sd->bl, 0x1b0);
  13029. // clif_misceffect2(&sd->bl, 0x21f);
  13030. clif_feel_info(sd, i, 0);
  13031. clif_menuskill_clear(sd);
  13032. }
  13033. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  13034. /// 0253 <which>.B
  13035. /// which:
  13036. /// 0 = sun
  13037. /// 1 = moon
  13038. /// 2 = star
  13039. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  13040. {
  13041. WFIFOHEAD(fd,packet_len(0x253));
  13042. WFIFOW(fd,0)=0x253;
  13043. WFIFOB(fd,2)=TOB(skill_lv-1);
  13044. WFIFOSET(fd, packet_len(0x253));
  13045. sd->menuskill_id = SG_FEEL;
  13046. sd->menuskill_val = skill_lv;
  13047. }
  13048. /// Request to change homunculus' name (CZ_RENAME_MER).
  13049. /// 0231 <name>.24B
  13050. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  13051. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13052. }
  13053. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  13054. /// 0234 <id>.L
  13055. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  13056. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  13057. struct block_list *bl = NULL;
  13058. struct unit_data *ud = NULL;
  13059. if( sd->md && sd->md->bl.id == id )
  13060. bl = &sd->md->bl;
  13061. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13062. bl = &sd->hd->bl; // Moving Homunculus
  13063. else
  13064. return;
  13065. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  13066. ud = unit_bl2ud(bl);
  13067. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  13068. }
  13069. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  13070. /// 0232 <id>.L <position data>.3B
  13071. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  13072. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13073. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  13074. struct block_list *bl = NULL;
  13075. short x, y;
  13076. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  13077. if( sd->md && sd->md->bl.id == id )
  13078. bl = &sd->md->bl; // Moving Mercenary
  13079. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13080. bl = &sd->hd->bl; // Moving Homunculus
  13081. else
  13082. return;
  13083. unit_walktoxy(bl, x, y, 4);
  13084. }
  13085. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  13086. /// 0233 <id>.L <target id>.L <action>.B
  13087. /// action:
  13088. /// always 0
  13089. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  13090. {
  13091. struct block_list *bl = NULL;
  13092. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13093. int id = RFIFOL(fd,info->pos[0]);
  13094. int target_id = RFIFOL(fd,info->pos[1]);
  13095. int action_type = RFIFOB(fd,info->pos[2]);
  13096. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13097. bl = &sd->hd->bl;
  13098. else if( sd->md && sd->md->bl.id == id )
  13099. bl = &sd->md->bl;
  13100. else return;
  13101. unit_stop_attack(bl);
  13102. unit_attack(bl, target_id, action_type != 0);
  13103. }
  13104. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13105. /// 022d <type>.W <command>.B
  13106. /// type:
  13107. /// always 0
  13108. /// command:
  13109. /// 0 = homunculus information
  13110. /// 1 = feed
  13111. /// 2 = delete
  13112. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  13113. { //[orn]
  13114. int cmd = RFIFOW(fd,0);
  13115. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13116. if(!hom_is_active(sd->hd))
  13117. return;
  13118. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13119. }
  13120. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13121. /// 0292
  13122. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  13123. {
  13124. pc_revive_item(sd);
  13125. }
  13126. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13127. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13128. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13129. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13130. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13131. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13132. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13133. void clif_check(int fd, struct map_session_data* pl_sd)
  13134. {
  13135. WFIFOHEAD(fd,packet_len(0x214));
  13136. WFIFOW(fd, 0) = 0x214;
  13137. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13138. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13139. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13140. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13141. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13142. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13143. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13144. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13145. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13146. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13147. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13148. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13149. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13150. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13151. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13152. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13153. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13154. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13155. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13156. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13157. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13158. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13159. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13160. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13161. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13162. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13163. WFIFOSET(fd,packet_len(0x214));
  13164. }
  13165. /// /check (CZ_REQ_STATUS_GM).
  13166. /// Request character's status values.
  13167. /// 0213 <char name>.24B
  13168. void clif_parse_Check(int fd, struct map_session_data *sd)
  13169. {
  13170. char charname[NAME_LENGTH];
  13171. struct map_session_data* pl_sd;
  13172. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13173. return;
  13174. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13175. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13176. {
  13177. return;
  13178. }
  13179. clif_check(fd, pl_sd);
  13180. }
  13181. /// MAIL SYSTEM
  13182. /// By Zephyrus
  13183. ///
  13184. /// Notification about the result of adding an item to mail
  13185. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13186. /// result:
  13187. /// 0 = success
  13188. /// 1 = failure
  13189. /// 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)
  13190. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13191. /// result:
  13192. /// 0 = success
  13193. /// 1 = over weight
  13194. /// 2 = fatal error
  13195. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  13196. int fd = sd->fd;
  13197. #if PACKETVER < 20150513
  13198. WFIFOHEAD(fd,packet_len(0x255));
  13199. WFIFOW(fd,0) = 0x255;
  13200. WFIFOW(fd,2) = index;
  13201. WFIFOB(fd,4) = flag;
  13202. WFIFOSET(fd,packet_len(0x255));
  13203. #else
  13204. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13205. if( flag ){
  13206. memset( &p, 0, sizeof( p ) );
  13207. }else{
  13208. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13209. p.index = index;
  13210. p.count = amount;
  13211. p.itemId = client_nameid( item->nameid );
  13212. p.type = itemtype( item->nameid );
  13213. p.IsIdentified = item->identify ? 1 : 0;
  13214. p.IsDamaged = item->attribute ? 1 : 0;
  13215. p.refiningLevel = item->refine;
  13216. clif_addcards( &p.slot, item );
  13217. clif_add_random_options( p.optionData, item );
  13218. p.weight = 0;
  13219. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13220. if( sd->mail.item[i].nameid == 0 ){
  13221. continue;
  13222. }
  13223. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13224. }
  13225. p.favorite = item->favorite;
  13226. p.location = pc_equippoint( sd, server_index( index ) );
  13227. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13228. p.enchantgrade = item->enchantgrade;
  13229. #endif
  13230. }
  13231. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13232. p.result = flag;
  13233. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13234. #endif
  13235. }
  13236. /// Notification about the result of retrieving a mail attachment
  13237. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13238. /// result:
  13239. /// 0 = success
  13240. /// 1 = failure
  13241. /// 2 = too many items
  13242. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13243. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13244. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13245. #if PACKETVER < 20150513
  13246. int fd = sd->fd;
  13247. WFIFOHEAD(fd,packet_len(0x245));
  13248. WFIFOW(fd,0) = 0x245;
  13249. WFIFOB(fd,2) = result;
  13250. WFIFOSET(fd,packet_len(0x245));
  13251. #else
  13252. switch( type ){
  13253. case MAIL_ATT_ITEM:
  13254. case MAIL_ATT_ZENY:
  13255. break;
  13256. default:
  13257. return;
  13258. }
  13259. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13260. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13261. p.MailID = msg->id;
  13262. p.opentype = msg->type;
  13263. p.result = result;
  13264. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13265. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13266. #endif
  13267. }
  13268. /// Notification about the result of sending a mail
  13269. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13270. /// result:
  13271. /// 0 = success
  13272. /// 1 = recipinent does not exist
  13273. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13274. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13275. #if PACKETVER < 20150513
  13276. int fd = sd->fd;
  13277. WFIFOHEAD(fd,packet_len(0x249));
  13278. WFIFOW(fd,0) = 0x249;
  13279. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13280. WFIFOSET(fd,packet_len(0x249));
  13281. #else
  13282. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13283. p.PacketType = rodexwriteresult;
  13284. p.result = result;
  13285. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13286. #endif
  13287. }
  13288. /// Notification about the result of deleting a mail.
  13289. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13290. /// result:
  13291. /// 0 = success
  13292. /// 1 = failure
  13293. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13294. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13295. #if PACKETVER < 20150513
  13296. int fd = sd->fd;
  13297. WFIFOHEAD(fd, packet_len(0x257));
  13298. WFIFOW(fd,0) = 0x257;
  13299. WFIFOL(fd,2) = msg->id;
  13300. WFIFOW(fd,6) = !success;
  13301. WFIFOSET(fd, packet_len(0x257));
  13302. #else
  13303. // This is only a success notification
  13304. if( success ){
  13305. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13306. p.PacketType = rodexdelete;
  13307. p.opentype = msg->type;
  13308. p.MailID = msg->id;
  13309. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13310. }
  13311. #endif
  13312. }
  13313. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13314. /// 0274 <mail id>.L <result>.W
  13315. /// result:
  13316. /// 0 = success
  13317. /// 1 = failure
  13318. void clif_Mail_return(int fd, int mail_id, short fail)
  13319. {
  13320. WFIFOHEAD(fd,packet_len(0x274));
  13321. WFIFOW(fd,0) = 0x274;
  13322. WFIFOL(fd,2) = mail_id;
  13323. WFIFOW(fd,6) = fail;
  13324. WFIFOSET(fd,packet_len(0x274));
  13325. }
  13326. /// Notification about new mail.
  13327. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13328. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13329. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13330. #if PACKETVER < 20150513
  13331. int fd = sd->fd;
  13332. WFIFOHEAD(fd,packet_len(0x24a));
  13333. WFIFOW(fd,0) = 0x24a;
  13334. WFIFOL(fd,2) = mail_id;
  13335. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13336. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13337. WFIFOSET(fd,packet_len(0x24a));
  13338. #else
  13339. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13340. p.PacketType = rodexicon;
  13341. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13342. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13343. #endif
  13344. }
  13345. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13346. /// 0260 <type>.L
  13347. /// type:
  13348. /// 0 = open
  13349. /// 1 = close
  13350. void clif_Mail_window(int fd, int flag)
  13351. {
  13352. WFIFOHEAD(fd,packet_len(0x260));
  13353. WFIFOW(fd,0) = 0x260;
  13354. WFIFOL(fd,2) = flag;
  13355. WFIFOSET(fd,packet_len(0x260));
  13356. }
  13357. /// Lists mails stored in inbox.
  13358. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13359. /// read:
  13360. /// 0 = unread
  13361. /// 1 = read
  13362. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13363. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13364. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13365. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13366. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13367. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13368. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13369. #if PACKETVER < 20150513
  13370. int fd = sd->fd;
  13371. struct mail_data *md = &sd->mail.inbox;
  13372. struct mail_message *msg;
  13373. int len, i, j;
  13374. len = 8 + (73 * md->amount);
  13375. WFIFOHEAD(fd,len);
  13376. WFIFOW(fd,0) = 0x240;
  13377. WFIFOW(fd,2) = len;
  13378. WFIFOL(fd,4) = md->amount;
  13379. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13380. {
  13381. msg = &md->msg[i];
  13382. if (msg->id < 1)
  13383. continue;
  13384. WFIFOL(fd,8+73*j) = msg->id;
  13385. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13386. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13387. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13388. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13389. j++;
  13390. }
  13391. WFIFOSET(fd,len);
  13392. if( md->full ) {// TODO: is this official?
  13393. char output[100];
  13394. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13395. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13396. }
  13397. #else
  13398. int fd = sd->fd;
  13399. struct mail_data *md = &sd->mail.inbox;
  13400. struct mail_message *msg;
  13401. int i, j, k, offset, titleLength;
  13402. uint8 mailType, amount, remaining;
  13403. uint32 now = (uint32)time(NULL);
  13404. #if PACKETVER >= 20170419
  13405. int cmd = 0xac2;
  13406. #elif PACKETVER >= 20160601
  13407. int cmd = 0xa7d;
  13408. #else
  13409. int cmd = 0x9f0;
  13410. #endif
  13411. if( battle_config.mail_daily_count ){
  13412. mail_refresh_remaining_amount(sd);
  13413. }
  13414. #if PACKETVER >= 20170419
  13415. // Always send all
  13416. i = md->amount;
  13417. #else
  13418. // If a starting mail id was sent
  13419. if( mailID != 0 ){
  13420. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13421. // Unknown mail
  13422. if( i == md->amount ){
  13423. // Ignore the request for now
  13424. return; // TODO: Should we just show the first page instead?
  13425. }
  13426. // It was actually the oldest/first mail, there is no further page
  13427. if( i == 0 ){
  13428. return;
  13429. }
  13430. // We actually want the next/older mail
  13431. i -= 1;
  13432. }else{
  13433. i = md->amount;
  13434. }
  13435. #endif
  13436. // Count the remaining mails from the starting mail or the beginning
  13437. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13438. for( j = i, remaining = 0; j >= 0; j-- ){
  13439. msg = &md->msg[j];
  13440. if (msg->id < 1)
  13441. continue;
  13442. #if PACKETVER < 20170419
  13443. if (msg->type != type)
  13444. continue;
  13445. #endif
  13446. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13447. continue;
  13448. remaining++;
  13449. }
  13450. #if PACKETVER >= 20170419
  13451. // Always send all
  13452. amount = remaining;
  13453. #else
  13454. if( remaining > MAIL_PAGE_SIZE ){
  13455. amount = MAIL_PAGE_SIZE;
  13456. }else{
  13457. amount = remaining;
  13458. }
  13459. #endif
  13460. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13461. WFIFOW(fd, 0) = cmd;
  13462. #if PACKETVER >= 20170419
  13463. WFIFOB(fd, 4) = 1; // Unknown
  13464. offset = 5;
  13465. #else
  13466. WFIFOB(fd, 4) = type;
  13467. WFIFOB(fd, 5) = amount;
  13468. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13469. offset = 7;
  13470. #endif
  13471. for( amount = 0; i >= 0; i-- ){
  13472. msg = &md->msg[i];
  13473. if (msg->id < 1)
  13474. continue;
  13475. #if PACKETVER < 20170419
  13476. if (msg->type != type)
  13477. continue;
  13478. #endif
  13479. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13480. continue;
  13481. #if PACKETVER >= 20170419
  13482. WFIFOB(fd, offset) = msg->type;
  13483. offset += 1;
  13484. #endif
  13485. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13486. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13487. mailType = MAIL_TYPE_TEXT; // Normal letter
  13488. if( msg->zeny > 0 ){
  13489. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13490. }
  13491. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13492. if( msg->item[k].nameid > 0 ){
  13493. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13494. break;
  13495. }
  13496. }
  13497. #if PACKETVER >= 20170419
  13498. // If it came from an npc?
  13499. if( !msg->send_id ){
  13500. mailType |= MAIL_TYPE_NPC;
  13501. }
  13502. #endif
  13503. WFIFOB(fd, offset + 9) = mailType;
  13504. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13505. #if PACKETVER < 20170419
  13506. // How much time has passed since you received the mail
  13507. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13508. offset += 4;
  13509. #endif
  13510. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13511. if( msg->scheduled_deletion > 0 ){
  13512. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13513. }else{
  13514. // Fake the scheduled deletion to one year in the future
  13515. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13516. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13517. }
  13518. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13519. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13520. offset += 40 + titleLength;
  13521. }
  13522. WFIFOW(fd, 2) = (int16)offset;
  13523. WFIFOSET(fd, offset);
  13524. #endif
  13525. }
  13526. /// Mail inbox list request.
  13527. /// 023f (CZ_MAIL_GET_LIST)
  13528. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13529. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13530. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13531. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13532. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13533. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13534. if( mail_invalid_operation( sd ) ){
  13535. return;
  13536. }
  13537. #if PACKETVER < 20150513
  13538. struct mail_data* md = &sd->mail.inbox;
  13539. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13540. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13541. else
  13542. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13543. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13544. mail_removezeny(sd, false);
  13545. #else
  13546. int cmd = RFIFOW(fd, 0);
  13547. #if PACKETVER < 20170419
  13548. uint8 openType = RFIFOB(fd, 2);
  13549. uint64 mailId = RFIFOQ(fd, 3);
  13550. #else
  13551. uint8 openType;
  13552. uint64 mailId = RFIFOQ(fd, 2);
  13553. int i;
  13554. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13555. if( i == MAIL_MAX_INBOX ){
  13556. openType = MAIL_INBOX_NORMAL;
  13557. mailId = 0;
  13558. }else{
  13559. openType = sd->mail.inbox.msg[i].type;
  13560. mailId = 0;
  13561. }
  13562. #endif
  13563. switch( openType ){
  13564. case MAIL_INBOX_NORMAL:
  13565. case MAIL_INBOX_ACCOUNT:
  13566. case MAIL_INBOX_RETURNED:
  13567. break;
  13568. default:
  13569. // Unknown type: ignore request
  13570. return;
  13571. }
  13572. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13573. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13574. return;
  13575. }
  13576. // If it is not a next page request
  13577. if( cmd != 0x9ee ){
  13578. mailId = 0;
  13579. }
  13580. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13581. #endif
  13582. }
  13583. /// Opens a mail
  13584. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13585. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13586. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13587. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13588. /// { }*n
  13589. // TODO: Packet description => for repeated block
  13590. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13591. int i, fd = sd->fd;
  13592. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13593. if( i == MAIL_MAX_INBOX ) {
  13594. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13595. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13596. return;
  13597. } else {
  13598. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13599. struct item *item;
  13600. struct item_data *data;
  13601. int msg_len = strlen(msg->body);
  13602. if( msg_len == 0 ) {
  13603. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13604. msg_len = strlen(msg->body);
  13605. }
  13606. #if PACKETVER < 20150513
  13607. item = &msg->item[0];
  13608. int len = 101 + msg_len;
  13609. WFIFOHEAD(fd,len);
  13610. WFIFOW(fd,0) = 0x242;
  13611. WFIFOW(fd,2) = len;
  13612. WFIFOL(fd,4) = msg->id;
  13613. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13614. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13615. WFIFOL(fd,72) = 0;
  13616. WFIFOL(fd,76) = msg->zeny;
  13617. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13618. WFIFOL(fd,80) = item->amount;
  13619. WFIFOW(fd,84) = client_nameid( item->nameid );
  13620. WFIFOW(fd,86) = itemtype( item->nameid );
  13621. WFIFOB(fd,88) = item->identify;
  13622. WFIFOB(fd,89) = item->attribute;
  13623. WFIFOB(fd,90) = item->refine;
  13624. WFIFOW(fd,91) = item->card[0];
  13625. WFIFOW(fd,93) = item->card[1];
  13626. WFIFOW(fd,95) = item->card[2];
  13627. WFIFOW(fd,97) = item->card[3];
  13628. } else // no item, set all to zero
  13629. memset(WFIFOP(fd,80), 0x00, 19);
  13630. WFIFOB(fd,99) = (unsigned char)msg_len;
  13631. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13632. WFIFOSET(fd,len);
  13633. #else
  13634. msg_len += 1; // Zero Termination
  13635. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13636. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13637. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13638. p->opentype = msg->type;
  13639. p->MailID = msg->id;
  13640. p->TextcontentsLength = msg_len;
  13641. p->zeny = msg->zeny;
  13642. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13643. p->PacketLength += p->TextcontentsLength;
  13644. p->ItemCnt = 0;
  13645. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13646. item = &msg->item[j];
  13647. if( item->nameid > 0 && item->amount > 0 && ( data = itemdb_exists( item->nameid ) ) != NULL ){
  13648. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13649. mailitem->ITID = client_nameid( item->nameid );
  13650. mailitem->count = item->amount;
  13651. mailitem->type = itemtype( item->nameid );
  13652. mailitem->IsIdentified = item->identify ? 1 : 0;
  13653. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13654. mailitem->refiningLevel = item->refine;
  13655. mailitem->location = pc_equippoint_sub( sd, data );
  13656. mailitem->viewSprite = data->look;
  13657. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13658. clif_addcards( &mailitem->slot, item );
  13659. clif_add_random_options( mailitem->option_data, item );
  13660. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13661. mailitem->enchantgrade = item->enchantgrade;
  13662. #endif
  13663. p->PacketLength += sizeof( *mailitem );
  13664. p->ItemCnt++;
  13665. }
  13666. }
  13667. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13668. #endif
  13669. if (msg->status == MAIL_UNREAD) {
  13670. msg->status = MAIL_READ;
  13671. intif_Mail_read(mail_id);
  13672. clif_parse_Mail_refreshinbox(fd, sd);
  13673. sd->mail.inbox.unread--;
  13674. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13675. }
  13676. }
  13677. }
  13678. /// Request to open a mail.
  13679. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13680. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13681. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13682. #if PACKETVER < 20150513
  13683. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13684. #else
  13685. //uint8 openType = RFIFOB(fd, 2);
  13686. int mail_id = (int)RFIFOQ(fd, 3);
  13687. #endif
  13688. if( mail_id <= 0 )
  13689. return;
  13690. if( mail_invalid_operation(sd) )
  13691. return;
  13692. clif_Mail_read(sd, mail_id);
  13693. }
  13694. /// Allow a player to begin writing a mail
  13695. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13696. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13697. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13698. p.PacketType = rodexopenwrite;
  13699. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13700. p.result = success;
  13701. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13702. }
  13703. /// Request to start writing a mail
  13704. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13705. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13706. char name[NAME_LENGTH];
  13707. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13708. if( mail_invalid_operation( sd ) ){
  13709. return;
  13710. }
  13711. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13712. clif_send_Mail_beginwrite_ack(sd, name, false);
  13713. return;
  13714. }
  13715. mail_clear(sd);
  13716. sd->state.mail_writing = true;
  13717. clif_send_Mail_beginwrite_ack(sd, name,true);
  13718. }
  13719. /// Notification that the client cancelled writing a mail
  13720. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13721. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13722. sd->state.mail_writing = false;
  13723. }
  13724. /// Give the client information about the recipient, if available
  13725. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13726. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13727. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13728. #if PACKETVER >= 20141119
  13729. PACKET_ZC_CHECKNAME p = { 0 };
  13730. p.PacketType = HEADER_ZC_CHECKNAME;
  13731. p.CharId = char_id;
  13732. p.Class = class_;
  13733. p.BaseLevel = level;
  13734. #if PACKETVER >= 20160302
  13735. strncpy(p.Name, name, NAME_LENGTH);
  13736. #endif
  13737. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13738. #endif
  13739. }
  13740. /// Request information about the recipient
  13741. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13742. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13743. #if PACKETVER >= 20140423
  13744. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13745. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13746. #else
  13747. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13748. #endif
  13749. static char name[NAME_LENGTH];
  13750. if( mail_invalid_operation( sd ) ){
  13751. return;
  13752. }
  13753. safestrncpy(name, p->Name, NAME_LENGTH);
  13754. intif_mail_checkreceiver(sd, name);
  13755. #endif
  13756. }
  13757. /// Request to receive mail's attachment.
  13758. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13759. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13760. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13761. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13762. int i;
  13763. struct mail_message* msg;
  13764. #if PACKETVER < 20150513
  13765. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13766. int attachment = MAIL_ATT_ALL;
  13767. #else
  13768. uint16 packet_id = RFIFOW(fd, 0);
  13769. int mail_id = (int)RFIFOQ(fd, 2);
  13770. //int openType = RFIFOB(fd, 10);
  13771. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13772. #endif
  13773. if( !chrif_isconnected() )
  13774. return;
  13775. if( mail_id <= 0 )
  13776. return;
  13777. if( mail_invalid_operation(sd) )
  13778. return;
  13779. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13780. if( i == MAIL_MAX_INBOX )
  13781. return;
  13782. msg = &sd->mail.inbox.msg[i];
  13783. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13784. attachment &= ~MAIL_ATT_ZENY;
  13785. }
  13786. if( attachment&MAIL_ATT_ITEM ){
  13787. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13788. // No items were found
  13789. if( i == MAIL_MAX_ITEM ){
  13790. attachment &= ~MAIL_ATT_ITEM;
  13791. }
  13792. }
  13793. // Either no attachment requested at all or there are no zeny or items in the mail
  13794. if( attachment == MAIL_ATT_NONE ){
  13795. return;
  13796. }
  13797. if( attachment&MAIL_ATT_ZENY ){
  13798. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13799. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13800. return;
  13801. }else{
  13802. // Store the pending zeny (required for the "retrieve all" feature)
  13803. sd->mail.pending_zeny += msg->zeny;
  13804. // To make sure another request fails
  13805. msg->zeny = 0;
  13806. }
  13807. }
  13808. if( attachment&MAIL_ATT_ITEM ){
  13809. int slots = 0, totalweight = 0;
  13810. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13811. struct item* item = &msg->item[i];
  13812. if( item->nameid > 0 && item->amount > 0 ){
  13813. struct item_data *data;
  13814. if((data = itemdb_exists(item->nameid)) == NULL)
  13815. continue;
  13816. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13817. case CHKADDITEM_NEW:
  13818. slots += data->inventorySlotNeeded( item->amount );
  13819. break;
  13820. case CHKADDITEM_OVERAMOUNT:
  13821. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13822. return;
  13823. }
  13824. totalweight += data->weight * item->amount;
  13825. }
  13826. }
  13827. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13828. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13829. return;
  13830. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13831. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13832. return;
  13833. }
  13834. // To make sure another request fails
  13835. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13836. // Store the pending weight (required for the "retrieve all" feature)
  13837. sd->mail.pending_weight += totalweight;
  13838. // Store the pending slots (required for the "retrieve all" feature)
  13839. sd->mail.pending_slots += slots;
  13840. }
  13841. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13842. }
  13843. /// Request to delete a mail.
  13844. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13845. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13846. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13847. #if PACKETVER < 20150513
  13848. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13849. #else
  13850. //int openType = RFIFOB(fd, 2);
  13851. int mail_id = (int)RFIFOQ(fd, 3);
  13852. #endif
  13853. int i, j;
  13854. if( !chrif_isconnected() )
  13855. return;
  13856. if( mail_id <= 0 )
  13857. return;
  13858. if( mail_invalid_operation(sd) )
  13859. return;
  13860. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13861. if (i < MAIL_MAX_INBOX) {
  13862. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13863. // can't delete mail without removing zeny first
  13864. if( msg->zeny > 0 ){
  13865. clif_mail_delete(sd, msg, false);
  13866. return;
  13867. }
  13868. // can't delete mail without removing attachment(s) first
  13869. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13870. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13871. clif_mail_delete(sd, msg, false);
  13872. return;
  13873. }
  13874. }
  13875. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13876. sd->mail.inbox.unread--;
  13877. clif_Mail_new(sd,0,NULL,NULL);
  13878. }
  13879. }
  13880. }
  13881. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13882. /// 0273 <mail id>.L <receive name>.24B
  13883. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13884. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13885. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13886. //ShowDump( p, sizeof( p ) );
  13887. int mail_id = p->msgId;
  13888. // not supported for now
  13889. return;
  13890. #else
  13891. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13892. #endif
  13893. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13894. int i;
  13895. if( mail_id <= 0 )
  13896. return;
  13897. if( mail_invalid_operation(sd) )
  13898. return;
  13899. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13900. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13901. intif_Mail_return(sd->status.char_id, mail_id);
  13902. else
  13903. clif_Mail_return(sd->fd, mail_id, 1);
  13904. }
  13905. /// Request to add an item or Zeny to mail.
  13906. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13907. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13908. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13909. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13910. uint16 idx = RFIFOW(fd,info->pos[0]);
  13911. #if PACKETVER < 20150513
  13912. int amount = RFIFOL(fd,info->pos[1]);
  13913. #else
  13914. int amount = RFIFOW(fd,info->pos[1]);
  13915. #endif
  13916. unsigned char flag;
  13917. if( !chrif_isconnected() )
  13918. return;
  13919. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13920. return;
  13921. if (sd->inventory_data[server_index(idx)] == nullptr)
  13922. return;
  13923. if( mail_invalid_operation( sd ) ){
  13924. return;
  13925. }
  13926. flag = mail_setitem(sd, idx, amount);
  13927. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13928. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13929. }else{
  13930. clif_Mail_setattachment(sd,idx,amount,flag);
  13931. }
  13932. }
  13933. /// Remove an item from a mail
  13934. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13935. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13936. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13937. p.PacketType = rodexremoveitem;
  13938. p.result = success;
  13939. p.index = index;
  13940. p.cnt = amount;
  13941. int total = 0;
  13942. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13943. if( sd->mail.item[i].nameid == 0 ){
  13944. break;
  13945. }
  13946. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13947. }
  13948. p.weight = total;
  13949. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13950. }
  13951. /// Request to reset mail item and/or Zeny
  13952. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13953. /// type:
  13954. /// 0 = reset all
  13955. /// 1 = remove item
  13956. /// 2 = remove zeny
  13957. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13958. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13959. {
  13960. #if PACKETVER < 20150513
  13961. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13962. if (type == 0 || type == 1)
  13963. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13964. if (type == 0 || type == 2)
  13965. mail_removezeny(sd, false);
  13966. #else
  13967. uint16 index = RFIFOW(fd, 2);
  13968. uint16 count = RFIFOW(fd, 4);
  13969. mail_removeitem(sd,0,index,count);
  13970. #endif
  13971. }
  13972. /// Request to send mail
  13973. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13974. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13975. /// 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)
  13976. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13977. #if PACKETVER < 20150513
  13978. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13979. if( !chrif_isconnected() )
  13980. return;
  13981. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13982. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13983. return;
  13984. }
  13985. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13986. #else
  13987. uint16 length = RFIFOW(fd, 2);
  13988. if( length < 0x3e ){
  13989. ShowWarning("Too short...\n");
  13990. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13991. return;
  13992. }
  13993. if( mail_invalid_operation( sd ) ){
  13994. return;
  13995. }
  13996. // Forged request without a begin writing packet?
  13997. if( !sd->state.mail_writing ){
  13998. return; // Ignore it
  13999. }
  14000. char receiver[NAME_LENGTH];
  14001. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  14002. // char sender[NAME_LENGTH];
  14003. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  14004. uint64 zeny = RFIFOQ(fd, 52);
  14005. uint16 titleLength = RFIFOW(fd, 60);
  14006. uint16 textLength = RFIFOW(fd, 62);
  14007. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  14008. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  14009. char title[MAIL_TITLE_LENGTH];
  14010. char text[MAIL_BODY_LENGTH];
  14011. #if PACKETVER <= 20160330
  14012. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  14013. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  14014. #else
  14015. // 64 = <char id>.L
  14016. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  14017. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  14018. #endif
  14019. if( zeny > 0 ){
  14020. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  14021. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  14022. return;
  14023. }
  14024. }
  14025. mail_send(sd, receiver, title, text, realTextLength);
  14026. #endif
  14027. }
  14028. /// AUCTION SYSTEM
  14029. /// By Zephyrus
  14030. ///
  14031. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  14032. /// 025f <type>.L
  14033. /// type:
  14034. /// 0 = open
  14035. /// 1 = close
  14036. void clif_Auction_openwindow(struct map_session_data *sd)
  14037. {
  14038. int fd = sd->fd;
  14039. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  14040. return;
  14041. if( !battle_config.feature_auction )
  14042. return;
  14043. WFIFOHEAD(fd,packet_len(0x25f));
  14044. WFIFOW(fd,0) = 0x25f;
  14045. WFIFOL(fd,2) = 0;
  14046. WFIFOSET(fd,packet_len(0x25f));
  14047. }
  14048. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  14049. /// 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 }*
  14050. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  14051. {
  14052. int i, fd = sd->fd, len = sizeof(struct auction_data);
  14053. struct auction_data auction;
  14054. WFIFOHEAD(fd,12 + (count * 83));
  14055. WFIFOW(fd,0) = 0x252;
  14056. WFIFOW(fd,2) = 12 + (count * 83);
  14057. WFIFOL(fd,4) = pages;
  14058. WFIFOL(fd,8) = count;
  14059. for( i = 0; i < count; i++ ) {
  14060. int k = 12 + (i * 83);
  14061. memcpy(&auction, RBUFP(buf,i * len), len);
  14062. WFIFOL(fd,k) = auction.auction_id;
  14063. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  14064. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  14065. WFIFOL(fd,30+k) = auction.type;
  14066. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  14067. WFIFOB(fd,36+k) = auction.item.identify;
  14068. WFIFOB(fd,37+k) = auction.item.attribute;
  14069. WFIFOB(fd,38+k) = auction.item.refine;
  14070. WFIFOW(fd,39+k) = auction.item.card[0];
  14071. WFIFOW(fd,41+k) = auction.item.card[1];
  14072. WFIFOW(fd,43+k) = auction.item.card[2];
  14073. WFIFOW(fd,45+k) = auction.item.card[3];
  14074. WFIFOL(fd,47+k) = auction.price;
  14075. WFIFOL(fd,51+k) = auction.buynow;
  14076. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  14077. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  14078. }
  14079. WFIFOSET(fd,WFIFOW(fd,2));
  14080. }
  14081. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  14082. /// 0256 <index>.W <result>.B
  14083. /// result:
  14084. /// 0 = success
  14085. /// 1 = failure
  14086. static void clif_Auction_setitem(int fd, int index, bool fail)
  14087. {
  14088. WFIFOHEAD(fd,packet_len(0x256));
  14089. WFIFOW(fd,0) = 0x256;
  14090. WFIFOW(fd,2) = index;
  14091. WFIFOB(fd,4) = fail;
  14092. WFIFOSET(fd,packet_len(0x256));
  14093. }
  14094. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  14095. /// 024b <type>.W
  14096. /// type:
  14097. /// 0 = create (any other action in auction window)
  14098. /// 1 = cancel (cancel pressed on register tab)
  14099. /// ? = junk, uninitialized value (ex. when switching between list filters)
  14100. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  14101. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14102. if( sd->auction.amount > 0 )
  14103. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  14104. sd->auction.amount = 0;
  14105. }
  14106. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  14107. /// 024c <index>.W <count>.L
  14108. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  14109. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14110. int idx = RFIFOW(fd,info->pos[0]) - 2;
  14111. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  14112. struct item_data *item;
  14113. if( !battle_config.feature_auction )
  14114. return;
  14115. if( sd->auction.amount > 0 )
  14116. sd->auction.amount = 0;
  14117. if( idx < 0 || idx >= MAX_INVENTORY ) {
  14118. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  14119. return;
  14120. }
  14121. 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.
  14122. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  14123. return;
  14124. }
  14125. 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) )
  14126. { // Consumable or pets are not allowed
  14127. clif_Auction_setitem(sd->fd, idx, true);
  14128. return;
  14129. }
  14130. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  14131. !sd->inventory.u.items_inventory[idx].identify ||
  14132. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  14133. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  14134. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  14135. clif_Auction_setitem(sd->fd, idx, true);
  14136. return;
  14137. }
  14138. sd->auction.index = idx;
  14139. sd->auction.amount = amount;
  14140. clif_Auction_setitem(fd, idx + 2, false);
  14141. }
  14142. /// Result from an auction action (ZC_AUCTION_RESULT).
  14143. /// 0250 <result>.B
  14144. /// result:
  14145. /// 0 = You have failed to bid into the auction
  14146. /// 1 = You have successfully bid in the auction
  14147. /// 2 = The auction has been canceled
  14148. /// 3 = An auction with at least one bidder cannot be canceled
  14149. /// 4 = You cannot register more than 5 items in an auction at a time
  14150. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14151. /// 6 = You have won the auction
  14152. /// 7 = You have failed to win the auction
  14153. /// 8 = You do not have enough Zeny
  14154. /// 9 = You cannot place more than 5 bids at a time
  14155. void clif_Auction_message(int fd, unsigned char flag)
  14156. {
  14157. WFIFOHEAD(fd,packet_len(0x250));
  14158. WFIFOW(fd,0) = 0x250;
  14159. WFIFOB(fd,2) = flag;
  14160. WFIFOSET(fd,packet_len(0x250));
  14161. }
  14162. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14163. /// 025e <result>.W
  14164. /// result:
  14165. /// 0 = You have ended the auction
  14166. /// 1 = You cannot end the auction
  14167. /// 2 = Auction ID is incorrect
  14168. void clif_Auction_close(int fd, unsigned char flag)
  14169. {
  14170. WFIFOHEAD(fd,packet_len(0x25e));
  14171. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14172. WFIFOW(fd,2) = flag;
  14173. WFIFOSET(fd,packet_len(0x25e));
  14174. }
  14175. /// Request to add an auction (CZ_AUCTION_ADD).
  14176. /// 024d <now money>.L <max money>.L <delete hour>.W
  14177. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  14178. {
  14179. struct auction_data auction;
  14180. struct item_data *item;
  14181. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14182. if( !battle_config.feature_auction )
  14183. return;
  14184. auction.price = RFIFOL(fd,info->pos[0]);
  14185. auction.buynow = RFIFOL(fd,info->pos[1]);
  14186. auction.hours = RFIFOW(fd,info->pos[2]);
  14187. // Invalid Situations...
  14188. if( sd->auction.amount < 1 ) {
  14189. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14190. return;
  14191. }
  14192. if( auction.price >= auction.buynow ) {
  14193. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14194. return;
  14195. }
  14196. if( auction.hours < 1 || auction.hours > 48 ) {
  14197. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14198. return;
  14199. }
  14200. // Auction checks...
  14201. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14202. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14203. clif_Auction_message(fd, 2); // The auction has been canceled
  14204. return;
  14205. }
  14206. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14207. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14208. return;
  14209. }
  14210. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14211. auction.buynow = battle_config.auction_maximumprice;
  14212. if( auction.price >= auction.buynow )
  14213. auction.price = auction.buynow - 1;
  14214. }
  14215. auction.auction_id = 0;
  14216. auction.seller_id = sd->status.char_id;
  14217. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14218. auction.buyer_id = 0;
  14219. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14220. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14221. {
  14222. clif_Auction_message(fd, 2); // The auction has been canceled
  14223. return;
  14224. }
  14225. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  14226. { // Just in case
  14227. clif_Auction_message(fd, 2); // The auction has been canceled
  14228. return;
  14229. }
  14230. safestrncpy(auction.item_name, item->ename.c_str(), sizeof(auction.item_name));
  14231. auction.type = item->type;
  14232. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14233. auction.item.amount = 1;
  14234. auction.timestamp = 0;
  14235. if( !intif_Auction_register(&auction) )
  14236. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14237. else
  14238. {
  14239. int zeny = auction.hours*battle_config.auction_feeperhour;
  14240. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14241. sd->auction.amount = 0;
  14242. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  14243. }
  14244. }
  14245. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14246. /// 024e <auction id>.L
  14247. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  14248. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14249. intif_Auction_cancel(sd->status.char_id, auction_id);
  14250. }
  14251. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14252. /// 025d <auction id>.L
  14253. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  14254. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14255. intif_Auction_close(sd->status.char_id, auction_id);
  14256. }
  14257. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14258. /// 024f <auction id>.L <money>.L
  14259. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  14260. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14261. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14262. int bid = RFIFOL(fd,info->pos[1]);
  14263. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14264. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14265. return;
  14266. }
  14267. if( bid <= 0 )
  14268. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14269. else if( bid > sd->status.zeny )
  14270. clif_Auction_message(fd, 8); // You do not have enough zeny
  14271. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14272. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14273. else {
  14274. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14275. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14276. }
  14277. }
  14278. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14279. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14280. /// search type:
  14281. /// 0 = armor
  14282. /// 1 = weapon
  14283. /// 2 = card
  14284. /// 3 = misc
  14285. /// 4 = name search
  14286. /// 5 = auction id search
  14287. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  14288. char search_text[NAME_LENGTH];
  14289. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14290. short type = RFIFOW(fd,info->pos[0]);
  14291. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14292. int page = RFIFOW(fd,info->pos[3]);
  14293. if( !battle_config.feature_auction )
  14294. return;
  14295. clif_parse_Auction_cancelreg(fd, sd);
  14296. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14297. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14298. }
  14299. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14300. /// 025c <type>.W
  14301. /// type:
  14302. /// 0 = sell (own auctions)
  14303. /// 1 = buy (own bids)
  14304. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  14305. {
  14306. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14307. if( !battle_config.feature_auction )
  14308. return;
  14309. clif_parse_Auction_cancelreg(fd, sd);
  14310. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14311. }
  14312. /// CASH/POINT SHOP
  14313. ///
  14314. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  14315. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14316. nullpo_retv( sd );
  14317. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14318. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14319. p.cashPoints = sd->cashPoints;
  14320. p.kafraPoints = sd->kafraPoints;
  14321. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14322. p.tab = tab;
  14323. #endif
  14324. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14325. #endif
  14326. }
  14327. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  14328. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14329. nullpo_retv( sd );
  14330. int tab = 0;
  14331. #if PACKETVER >= 20191224
  14332. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14333. tab = p->tab;
  14334. #endif
  14335. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14336. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14337. return;
  14338. }
  14339. sd->state.cashshop_open = true;
  14340. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14341. clif_cashshop_open( sd, tab );
  14342. #endif
  14343. }
  14344. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14345. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14346. sd->state.cashshop_open = false;
  14347. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14348. // No need to do anything here
  14349. #endif
  14350. }
  14351. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14352. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14353. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14354. // [4144] packet exists only in 2011 and was dropped after
  14355. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14356. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14357. int j;
  14358. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14359. return;
  14360. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14361. WFIFOW(fd, 0) = 0x8c0;
  14362. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14363. WFIFOL(fd, 4) = tab;
  14364. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14365. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14366. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14367. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14368. }
  14369. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14370. #endif
  14371. }
  14372. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14373. void clif_cashshop_list( struct map_session_data* sd ){
  14374. nullpo_retv( sd );
  14375. int fd = sd->fd;
  14376. if( !session_isActive( fd ) ){
  14377. return;
  14378. }
  14379. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14380. // Skip empty tabs, the client only expects filled ones
  14381. if( cash_shop_items[tab].count == 0 ){
  14382. continue;
  14383. }
  14384. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14385. WFIFOHEAD( fd, len );
  14386. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14387. p->packetType = 0x8ca;
  14388. p->packetLength = len;
  14389. p->count = cash_shop_items[tab].count;
  14390. p->tabNum = tab;
  14391. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14392. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14393. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14394. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14395. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14396. if( id == nullptr ){
  14397. p->items[i].location = 0;
  14398. p->items[i].viewSprite = 0;
  14399. }else{
  14400. p->items[i].location = pc_equippoint_sub( sd, id );
  14401. p->items[i].viewSprite = id->look;
  14402. }
  14403. #endif
  14404. }
  14405. WFIFOSET( fd, len );
  14406. }
  14407. }
  14408. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14409. if( !sd->status.cashshop_sent ) {
  14410. clif_cashshop_list( sd );
  14411. #if PACKETVER_SUPPORTS_SALES
  14412. sale_notify_login(sd);
  14413. #endif
  14414. sd->status.cashshop_sent = true;
  14415. }
  14416. }
  14417. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14418. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14419. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14420. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14421. nullpo_retv( sd );
  14422. nullpo_retv( nd );
  14423. int fd = sd->fd;
  14424. if( !session_isActive( fd ) ){
  14425. return;
  14426. }
  14427. sd->npc_shopid = nd->bl.id;
  14428. int cost[2] = { 0, 0 };
  14429. npc_shop_currency_type( sd, nd, cost, true );
  14430. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14431. WFIFOHEAD( fd, len );
  14432. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14433. p->packetType = 0x287;
  14434. p->packetLength = len;
  14435. p->cashPoints = cost[0];
  14436. #if PACKETVER >= 20070711
  14437. p->kafraPoints = cost[1];
  14438. #endif
  14439. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14440. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14441. p->items[i].price = nd->u.shop.shop_item[i].value;
  14442. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14443. p->items[i].itemType = itemtype( id->nameid );
  14444. p->items[i].itemId = client_nameid( id->nameid );
  14445. }
  14446. WFIFOSET( fd, len );
  14447. }
  14448. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14449. /// 0289 <cash point>.L <error>.W
  14450. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14451. /// error:
  14452. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14453. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14454. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14455. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14456. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14457. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14458. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14459. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14460. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14461. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14462. {
  14463. int fd, cost[2] = { 0, 0 };
  14464. struct npc_data *nd;
  14465. nullpo_retv(sd);
  14466. fd = sd->fd;
  14467. nd = map_id2nd(sd->npc_shopid);
  14468. npc_shop_currency_type(sd, nd, cost, false);
  14469. WFIFOHEAD(fd, packet_len(0x289));
  14470. WFIFOW(fd,0) = 0x289;
  14471. WFIFOL(fd,2) = cost[0];
  14472. #if PACKETVER < 20070711
  14473. WFIFOW(fd,6) = TOW(error);
  14474. #else
  14475. WFIFOL(fd,6) = cost[1];
  14476. WFIFOW(fd,10) = TOW(error);
  14477. #endif
  14478. WFIFOSET(fd, packet_len(0x289));
  14479. }
  14480. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14481. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14482. nullpo_retv( sd );
  14483. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14484. packet.packetType = 0x849;
  14485. if( item_id != 0 ){
  14486. packet.itemId = client_nameid( item_id );
  14487. }else{
  14488. packet.itemId = 0;
  14489. }
  14490. packet.result = result;
  14491. packet.cashPoints = sd->cashPoints;
  14492. packet.kafraPoints = sd->kafraPoints;
  14493. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14494. #endif
  14495. }
  14496. /// Request to buy item(s) from cash shop.
  14497. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14498. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14499. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14500. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14501. nullpo_retv( sd );
  14502. if( sd->state.trading || !sd->npc_shopid ){
  14503. clif_cashshop_ack( sd, 1 );
  14504. return;
  14505. }
  14506. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14507. #if PACKETVER < 20070711
  14508. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14509. #elif PACKETVER < 20101116
  14510. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14511. #else
  14512. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14513. 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 ){
  14514. 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 );
  14515. return;
  14516. }
  14517. std::vector<s_npc_buy_list> item_list = {};
  14518. item_list.reserve( p->count );
  14519. for( int i = 0; i < p->count; i++ ){
  14520. s_npc_buy_list item = {};
  14521. item.nameid = p->items[i].itemId;
  14522. item.qty = p->items[i].amount;
  14523. item_list.push_back( item );
  14524. }
  14525. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14526. #endif
  14527. }
  14528. /// Request to buy item(s) from cash shop.
  14529. /// 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)
  14530. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14531. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14532. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14533. 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 ){
  14534. 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 );
  14535. return;
  14536. }
  14537. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14538. }
  14539. /// Adoption System
  14540. ///
  14541. /// Adoption message (ZC_BABYMSG).
  14542. /// 0216 <msg>.L
  14543. /// msg:
  14544. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14545. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14546. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14547. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14548. {
  14549. int fd = sd->fd;
  14550. WFIFOHEAD(fd,6);
  14551. WFIFOW(fd,0) = 0x216;
  14552. WFIFOL(fd,2) = type;
  14553. WFIFOSET(fd,6);
  14554. }
  14555. /// Adoption confirmation (ZC_REQ_BABY).
  14556. /// 01f6 <account id>.L <char id>.L <name>.B
  14557. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14558. {
  14559. int fd = sd->fd;
  14560. WFIFOHEAD(fd,34);
  14561. WFIFOW(fd,0) = 0x1f6;
  14562. WFIFOL(fd,2) = src->status.account_id;
  14563. WFIFOL(fd,6) = p_id;
  14564. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14565. WFIFOSET(fd,34);
  14566. }
  14567. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14568. /// 01f9 <account id>.L
  14569. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14570. {
  14571. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14572. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14573. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14574. {
  14575. tsd->adopt_invite = sd->status.account_id;
  14576. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14577. }
  14578. }
  14579. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14580. /// 01f7 <account id>.L <char id>.L <answer>.L
  14581. /// answer:
  14582. /// 0 = rejected
  14583. /// 1 = accepted
  14584. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14585. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14586. int p1_id = RFIFOL(fd,info->pos[0]);
  14587. int p2_id = RFIFOL(fd,info->pos[1]);
  14588. int result = RFIFOL(fd,info->pos[2]);
  14589. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14590. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14591. int pid = sd->adopt_invite;
  14592. sd->adopt_invite = 0;
  14593. if( p1_sd == NULL || p2_sd == NULL )
  14594. return; // Both players need to be online
  14595. if( pid != p1_sd->status.account_id )
  14596. return; // Incorrect values
  14597. if( result == 0 )
  14598. return; // Rejected
  14599. pc_adoption(p1_sd, p2_sd, sd);
  14600. }
  14601. /// Convex Mirror (ZC_BOSS_INFO).
  14602. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14603. /// infoType:
  14604. /// BOSS_INFO_NOT = No boss on this map.
  14605. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14606. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14607. /// BOSS_INFO_DEAD = Boss is dead.
  14608. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14609. {
  14610. int fd = sd->fd;
  14611. WFIFOHEAD(fd,70);
  14612. memset(WFIFOP(fd,0),0,70);
  14613. WFIFOW(fd,0) = 0x293;
  14614. switch (flag) {
  14615. case BOSS_INFO_NOT:
  14616. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14617. // No data required
  14618. break;
  14619. case BOSS_INFO_ALIVE:
  14620. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14621. // Update X/Y
  14622. WFIFOL(fd,3) = md->bl.x;
  14623. WFIFOL(fd,7) = md->bl.y;
  14624. break;
  14625. case BOSS_INFO_ALIVE_WITHMSG:
  14626. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14627. // Current X/Y
  14628. WFIFOL(fd,3) = md->bl.x;
  14629. WFIFOL(fd,7) = md->bl.y;
  14630. break;
  14631. case BOSS_INFO_DEAD:
  14632. {
  14633. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14634. unsigned int seconds;
  14635. int hours, minutes;
  14636. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14637. hours = seconds / (60 * 60);
  14638. seconds = seconds - (60 * 60 * hours);
  14639. minutes = seconds / 60;
  14640. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14641. // Add respawn info
  14642. WFIFOW(fd,11) = hours; // Hours
  14643. WFIFOW(fd,13) = minutes; // Minutes
  14644. }
  14645. break;
  14646. }
  14647. if (md != NULL)
  14648. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14649. WFIFOSET(fd,70);
  14650. }
  14651. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14652. /// 02d6 <account id>.L
  14653. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14654. {
  14655. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14656. struct map_session_data* tsd = map_id2sd(aid);
  14657. if (!tsd)
  14658. return;
  14659. if (sd->bl.m != tsd->bl.m)
  14660. return;
  14661. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14662. clif_viewequip_ack(sd, tsd);
  14663. else
  14664. clif_msg(sd, VIEW_EQUIP_FAIL);
  14665. }
  14666. /// Request to a configuration.
  14667. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14668. /// type: see enum e_config_type
  14669. /// flag:
  14670. /// false = disabled
  14671. /// true = enabled
  14672. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14673. int cmd = RFIFOW(fd,0);
  14674. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14675. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14676. switch( type ){
  14677. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14678. sd->status.show_equip = flag;
  14679. break;
  14680. case CONFIG_PET_AUTOFEED:
  14681. // Player can not click this if he does not have a pet
  14682. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14683. return;
  14684. }
  14685. sd->pd->pet.autofeed = flag;
  14686. break;
  14687. case CONFIG_HOMUNCULUS_AUTOFEED:
  14688. // Player can not click this if he does not have a homunculus or it is vaporized
  14689. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14690. return;
  14691. }
  14692. sd->hd->homunculus.autofeed = flag;
  14693. break;
  14694. default:
  14695. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14696. return;
  14697. }
  14698. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14699. }
  14700. /// Request to change party invitation tick.
  14701. /// value:
  14702. /// 0 = disabled
  14703. /// 1 = enabled
  14704. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14705. {
  14706. bool flag = RFIFOB(fd,6) ? true : false;
  14707. sd->status.allow_party = flag;
  14708. clif_partytickack(sd, flag);
  14709. }
  14710. /// Questlog System [Kevin] [Inkfish]
  14711. ///
  14712. /**
  14713. * Safe check to init packet len & quest num for player.
  14714. * @param def_len
  14715. * @param info_len Length of each quest info.
  14716. * @param avail_quests Avail quests that player has.
  14717. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14718. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14719. **/
  14720. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14721. (*limit_out) = (0xFFFF - def_len) / info_len;
  14722. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14723. (*len_out) = ((*limit_out) * info_len) + def_len;
  14724. }
  14725. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14726. std::string race_name;
  14727. switch( objective->race ){
  14728. case RC_FORMLESS: race_name = "Formless"; break;
  14729. case RC_UNDEAD: race_name = "Undead"; break;
  14730. case RC_BRUTE: race_name = "Brute"; break;
  14731. case RC_PLANT: race_name = "Plant"; break;
  14732. case RC_INSECT: race_name = "Insect"; break;
  14733. case RC_FISH: race_name = "Fish"; break;
  14734. case RC_DEMON: race_name = "Demon"; break;
  14735. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14736. case RC_ANGEL: race_name = "Angel"; break;
  14737. case RC_DRAGON: race_name = "Dragon"; break;
  14738. default:
  14739. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14740. // Fallthrough
  14741. case RC_ALL: race_name = ""; break;
  14742. }
  14743. std::string size_name;
  14744. switch( objective->size ){
  14745. case SZ_SMALL: size_name = "Small"; break;
  14746. case SZ_MEDIUM: size_name = "Medium"; break;
  14747. case SZ_BIG: size_name = "Large"; break;
  14748. default:
  14749. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14750. // Fallthrough
  14751. case SZ_ALL: size_name = ""; break;
  14752. }
  14753. std::string ele_name;
  14754. switch( objective->element ){
  14755. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14756. case ELE_WATER: ele_name = "Water Element"; break;
  14757. case ELE_EARTH: ele_name = "Earth Element"; break;
  14758. case ELE_FIRE: ele_name = "Fire Element"; break;
  14759. case ELE_WIND: ele_name = "Wind Element"; break;
  14760. case ELE_POISON: ele_name = "Poison Element"; break;
  14761. case ELE_HOLY: ele_name = "Holy Element"; break;
  14762. case ELE_DARK: ele_name = "Shadow Element"; break;
  14763. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14764. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14765. default:
  14766. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14767. // Fallthrough
  14768. case ELE_ALL: ele_name = ""; break;
  14769. }
  14770. std::string str;
  14771. if( !objective->map_name.empty() ){
  14772. str += objective->map_name;
  14773. }
  14774. if( !race_name.empty() ){
  14775. if( !str.empty() ){
  14776. str += ", ";
  14777. }
  14778. str += race_name;
  14779. }
  14780. if( !size_name.empty() ){
  14781. if( !str.empty() ){
  14782. str += ", ";
  14783. }
  14784. str += size_name;
  14785. }
  14786. if( !ele_name.empty() ){
  14787. if( !str.empty() ){
  14788. str += ", ";
  14789. }
  14790. str += ele_name;
  14791. }
  14792. return str;
  14793. }
  14794. /// Sends list of all quest states
  14795. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14796. /// 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)
  14797. /// 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)
  14798. void clif_quest_send_list(struct map_session_data *sd)
  14799. {
  14800. nullpo_retv(sd);
  14801. int fd = sd->fd;
  14802. int i;
  14803. int offset = 8;
  14804. int limit = 0;
  14805. #if PACKETVER >= 20141022
  14806. #if PACKETVER >= 20150513
  14807. int size = 22 + NAME_LENGTH;
  14808. #else
  14809. int size = 10 + NAME_LENGTH;
  14810. #endif
  14811. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14812. WFIFOHEAD(fd,i);
  14813. #if PACKETVER >= 20150513
  14814. WFIFOW(fd, 0) = 0x9f8;
  14815. #else
  14816. WFIFOW(fd, 0) = 0x97a;
  14817. #endif
  14818. WFIFOL(fd, 4) = limit;
  14819. for (i = 0; i < limit; i++) {
  14820. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14821. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14822. offset += 4;
  14823. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14824. offset++;
  14825. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14826. offset += 4;
  14827. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14828. offset += 4;
  14829. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14830. offset += 2;
  14831. if (!qi->objectives.empty()) {
  14832. std::shared_ptr<s_mob_db> mob;
  14833. for (int j = 0; j < qi->objectives.size(); j++) {
  14834. mob = mob_db.find(qi->objectives[j]->mob_id);
  14835. e_race race = qi->objectives[j]->race;
  14836. e_size size = qi->objectives[j]->size;
  14837. e_element element = qi->objectives[j]->element;
  14838. #if PACKETVER >= 20150513
  14839. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14840. offset += 4;
  14841. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14842. offset += 4;
  14843. #endif
  14844. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14845. offset += 4;
  14846. #if PACKETVER >= 20150513
  14847. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14848. offset += 2;
  14849. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14850. offset += 2;
  14851. #endif
  14852. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14853. offset += 2;
  14854. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14855. offset += 2;
  14856. if (mob && qi->objectives[j]->mob_id > 0)
  14857. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14858. else
  14859. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14860. offset += NAME_LENGTH;
  14861. }
  14862. }
  14863. }
  14864. WFIFOW(fd, 2) = offset;
  14865. WFIFOSET(fd, offset);
  14866. #else
  14867. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14868. WFIFOHEAD(fd,i);
  14869. WFIFOW(fd, 0) = 0x2b1;
  14870. WFIFOL(fd, 4) = limit;
  14871. for (i = 0; i < limit; i++) {
  14872. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14873. offset += 4;
  14874. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14875. offset += 1;
  14876. }
  14877. WFIFOW(fd, 2) = offset;
  14878. WFIFOSET(fd, offset);
  14879. #endif
  14880. }
  14881. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14882. /// 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
  14883. void clif_quest_send_mission(struct map_session_data *sd)
  14884. {
  14885. nullpo_retv(sd);
  14886. int fd = sd->fd;
  14887. int limit = 0;
  14888. int len = sd->avail_quests*104+8;
  14889. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14890. WFIFOHEAD(fd, len);
  14891. WFIFOW(fd, 0) = 0x2b2;
  14892. WFIFOW(fd, 2) = len;
  14893. WFIFOL(fd, 4) = limit;
  14894. for (int i = 0; i < limit; i++) {
  14895. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14896. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14897. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14898. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14899. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14900. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14901. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14902. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14903. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14904. if (mob && qi->objectives[j]->mob_id > 0)
  14905. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14906. else
  14907. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14908. }
  14909. }
  14910. WFIFOSET(fd, len);
  14911. }
  14912. /// Notification about a new quest
  14913. /// 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)
  14914. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14915. /// 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)
  14916. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14917. {
  14918. nullpo_retv(sd);
  14919. nullpo_retv(qd);
  14920. int fd = sd->fd;
  14921. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14922. if (!qi)
  14923. return;
  14924. #if PACKETVER >= 20150513
  14925. int cmd = 0x9f9;
  14926. #else
  14927. int cmd = 0x2b3;
  14928. #endif
  14929. WFIFOHEAD(fd, packet_len(cmd));
  14930. WFIFOW(fd, 0) = cmd;
  14931. WFIFOL(fd, 2) = qd->quest_id;
  14932. WFIFOB(fd, 6) = qd->state;
  14933. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14934. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14935. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14936. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14937. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14938. e_race race = qi->objectives[i]->race;
  14939. e_size size = qi->objectives[i]->size;
  14940. e_element element = qi->objectives[i]->element;
  14941. #if PACKETVER >= 20150513
  14942. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14943. offset += 4;
  14944. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14945. offset += 4;
  14946. #endif
  14947. 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
  14948. offset += 4;
  14949. #if PACKETVER >= 20150513
  14950. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14951. offset += 2;
  14952. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14953. offset += 2;
  14954. #endif
  14955. WFIFOW(fd, offset) = qd->count[i];
  14956. offset += 2;
  14957. if (mob && qi->objectives[i]->mob_id > 0)
  14958. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14959. else
  14960. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14961. offset += NAME_LENGTH;
  14962. }
  14963. WFIFOSET(fd, packet_len(cmd));
  14964. #if PACKETVER >= 20150513
  14965. int len = 4 + qi->objectives.size() * 12;
  14966. WFIFOHEAD(fd, len);
  14967. WFIFOW(fd, 0) = 0x8fe;
  14968. WFIFOW(fd, 2) = len;
  14969. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14970. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14971. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14972. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14973. WFIFOW(fd, offset + 10) = qd->count[i];
  14974. }
  14975. WFIFOSET(fd, len);
  14976. #endif
  14977. }
  14978. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14979. /// 02b4 <quest id>.L
  14980. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14981. {
  14982. int fd = sd->fd;
  14983. WFIFOHEAD(fd, packet_len(0x2b4));
  14984. WFIFOW(fd, 0) = 0x2b4;
  14985. WFIFOL(fd, 2) = quest_id;
  14986. WFIFOSET(fd, packet_len(0x2b4));
  14987. }
  14988. /// Notification of an update to the hunting mission counter
  14989. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14990. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14991. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  14992. {
  14993. int fd = sd->fd;
  14994. int offset = 6;
  14995. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14996. int len = qi->objectives.size() * 12 + 6;
  14997. #if PACKETVER >= 20150513
  14998. int cmd = 0x9fa;
  14999. #else
  15000. int cmd = 0x2b5;
  15001. #endif
  15002. WFIFOHEAD(fd, len);
  15003. WFIFOW(fd, 0) = cmd;
  15004. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  15005. for (int i = 0; i < qi->objectives.size(); i++) {
  15006. WFIFOL(fd, offset) = qd->quest_id;
  15007. offset += 4;
  15008. #if PACKETVER >= 20150513
  15009. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15010. offset += 4;
  15011. #else
  15012. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  15013. offset += 4;
  15014. #endif
  15015. WFIFOW(fd, offset) = qi->objectives[i]->count;
  15016. offset += 2;
  15017. WFIFOW(fd, offset) = qd->count[i];
  15018. offset += 2;
  15019. }
  15020. WFIFOW(fd, 2) = offset;
  15021. WFIFOSET(fd, offset);
  15022. }
  15023. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  15024. /// 02b6 <quest id>.L <active>.B
  15025. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  15026. {
  15027. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15028. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  15029. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  15030. }
  15031. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  15032. /// 02b7 <quest id>.L <active>.B
  15033. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  15034. {
  15035. int fd = sd->fd;
  15036. WFIFOHEAD(fd, packet_len(0x2b7));
  15037. WFIFOW(fd, 0) = 0x2b7;
  15038. WFIFOL(fd, 2) = quest_id;
  15039. WFIFOB(fd, 6) = active;
  15040. WFIFOSET(fd, packet_len(0x2b7));
  15041. }
  15042. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  15043. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  15044. /// effect:
  15045. /// 0 = none
  15046. /// 1 = exclamation mark icon
  15047. /// 2 = question mark icon
  15048. /// color:
  15049. /// 0 = yellow
  15050. /// 1 = orange
  15051. /// 2 = green
  15052. /// 3 = purple
  15053. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  15054. {
  15055. #if PACKETVER >= 20090218
  15056. nullpo_retv(sd);
  15057. nullpo_retv(bl);
  15058. int fd = sd->fd;
  15059. WFIFOHEAD(fd, packet_len(0x446));
  15060. WFIFOW(fd, 0) = 0x446;
  15061. WFIFOL(fd, 2) = bl->id;
  15062. WFIFOW(fd, 6) = bl->x;
  15063. WFIFOW(fd, 8) = bl->y;
  15064. WFIFOW(fd, 10) = effect;
  15065. WFIFOW(fd, 12) = color;
  15066. WFIFOSET(fd, packet_len(0x446));
  15067. #endif
  15068. }
  15069. /// Mercenary System
  15070. ///
  15071. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  15072. /// 02a2 <var id>.W <value>.L
  15073. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  15074. {
  15075. s_mercenary_data *md;
  15076. struct status_data *status;
  15077. int fd;
  15078. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15079. return;
  15080. fd = sd->fd;
  15081. status = &md->battle_status;
  15082. WFIFOHEAD(fd,packet_len(0x2a2));
  15083. WFIFOW(fd,0) = 0x2a2;
  15084. WFIFOW(fd,2) = type;
  15085. switch( type ) {
  15086. case SP_ATK1:
  15087. {
  15088. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15089. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  15090. }
  15091. break;
  15092. case SP_MATK1:
  15093. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  15094. break;
  15095. case SP_HIT:
  15096. WFIFOL(fd,4) = status->hit;
  15097. break;
  15098. case SP_CRITICAL:
  15099. WFIFOL(fd,4) = status->cri/10;
  15100. break;
  15101. case SP_DEF1:
  15102. WFIFOL(fd,4) = status->def;
  15103. break;
  15104. case SP_MDEF1:
  15105. WFIFOL(fd,4) = status->mdef;
  15106. break;
  15107. case SP_MERCFLEE:
  15108. WFIFOL(fd,4) = status->flee;
  15109. break;
  15110. case SP_ASPD:
  15111. WFIFOL(fd,4) = status->amotion;
  15112. break;
  15113. case SP_HP:
  15114. WFIFOL(fd,4) = status->hp;
  15115. break;
  15116. case SP_MAXHP:
  15117. WFIFOL(fd,4) = status->max_hp;
  15118. break;
  15119. case SP_SP:
  15120. WFIFOL(fd,4) = status->sp;
  15121. break;
  15122. case SP_MAXSP:
  15123. WFIFOL(fd,4) = status->max_sp;
  15124. break;
  15125. case SP_MERCKILLS:
  15126. WFIFOL(fd,4) = md->mercenary.kill_count;
  15127. break;
  15128. case SP_MERCFAITH:
  15129. WFIFOL(fd,4) = mercenary_get_faith(md);
  15130. break;
  15131. }
  15132. WFIFOSET(fd,packet_len(0x2a2));
  15133. }
  15134. /// Mercenary base status data (ZC_MER_INIT).
  15135. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  15136. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  15137. /// <calls>.L <kills>.L <atk range>.W
  15138. void clif_mercenary_info(struct map_session_data *sd)
  15139. {
  15140. int fd;
  15141. s_mercenary_data *md;
  15142. struct status_data *status;
  15143. int atk;
  15144. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15145. return;
  15146. fd = sd->fd;
  15147. status = &md->battle_status;
  15148. WFIFOHEAD(fd,packet_len(0x29b));
  15149. WFIFOW(fd,0) = 0x29b;
  15150. WFIFOL(fd,2) = md->bl.id;
  15151. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15152. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15153. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15154. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15155. WFIFOW(fd,10) = status->hit;
  15156. WFIFOW(fd,12) = status->cri/10;
  15157. WFIFOW(fd,14) = status->def;
  15158. WFIFOW(fd,16) = status->mdef;
  15159. WFIFOW(fd,18) = status->flee;
  15160. WFIFOW(fd,20) = status->amotion;
  15161. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15162. WFIFOW(fd,46) = md->db->lv;
  15163. WFIFOL(fd,48) = status->hp;
  15164. WFIFOL(fd,52) = status->max_hp;
  15165. WFIFOL(fd,56) = status->sp;
  15166. WFIFOL(fd,60) = status->max_sp;
  15167. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15168. WFIFOW(fd,68) = mercenary_get_faith(md);
  15169. WFIFOL(fd,70) = mercenary_get_calls(md);
  15170. WFIFOL(fd,74) = md->mercenary.kill_count;
  15171. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15172. WFIFOSET(fd,packet_len(0x29b));
  15173. }
  15174. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15175. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15176. void clif_mercenary_skillblock(struct map_session_data *sd)
  15177. {
  15178. s_mercenary_data *md;
  15179. int fd, len = 4;
  15180. if( sd == NULL || (md = sd->md) == NULL )
  15181. return;
  15182. fd = sd->fd;
  15183. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15184. WFIFOW(fd,0) = 0x29d;
  15185. for (const auto &it : md->db->skill) {
  15186. uint16 id = it.first;
  15187. if (!SKILL_CHK_MERC(id))
  15188. continue;
  15189. uint16 lv = it.second;
  15190. WFIFOW(fd,len) = id;
  15191. WFIFOL(fd,len+2) = skill_get_inf(id);
  15192. WFIFOW(fd,len+6) = lv;
  15193. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15194. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15195. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15196. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15197. len += 37;
  15198. }
  15199. WFIFOW(fd,2) = len;
  15200. WFIFOSET(fd,len);
  15201. }
  15202. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15203. /// 029f <command>.B
  15204. /// 1 = mercenary information
  15205. /// 2 = delete
  15206. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  15207. {
  15208. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15209. if( sd->md == NULL )
  15210. return;
  15211. if( option == 2 ) mercenary_delete(sd->md, 2);
  15212. }
  15213. /// Mercenary Message
  15214. /// message:
  15215. /// 0 = Mercenary soldier's duty hour is over.
  15216. /// 1 = Your mercenary soldier has been killed.
  15217. /// 2 = Your mercenary soldier has been fired.
  15218. /// 3 = Your mercenary soldier has ran away.
  15219. void clif_mercenary_message(struct map_session_data* sd, int message){
  15220. clif_msg(sd, MERC_MSG_BASE + message);
  15221. }
  15222. /// Notification about the remaining time of a rental item.
  15223. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15224. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  15225. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15226. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15227. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15228. p.itemId = client_nameid( nameid );
  15229. p.seconds = seconds;
  15230. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15231. }
  15232. /// Deletes a rental item from client's inventory.
  15233. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15234. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  15235. // '<ItemName>' item has been deleted from the Inventory
  15236. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15237. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15238. p.index = client_index( index );
  15239. p.itemId = client_nameid( nameid );
  15240. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15241. }
  15242. /// Book Reading (ZC_READ_BOOK).
  15243. /// 0294 <book id>.L <page>.L
  15244. void clif_readbook(int fd, int book_id, int page)
  15245. {
  15246. WFIFOHEAD(fd,packet_len(0x294));
  15247. WFIFOW(fd,0) = 0x294;
  15248. WFIFOL(fd,2) = book_id;
  15249. WFIFOL(fd,6) = page;
  15250. WFIFOSET(fd,packet_len(0x294));
  15251. }
  15252. /// Battlegrounds
  15253. ///
  15254. /// Updates HP bar of a camp member.
  15255. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15256. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15257. void clif_bg_hp(struct map_session_data *sd) {
  15258. #if PACKETVER < 20140613
  15259. unsigned char buf[34];
  15260. const int cmd = 0x2e0;
  15261. #else
  15262. unsigned char buf[14];
  15263. const int cmd = 0xa0e;
  15264. #endif
  15265. nullpo_retv(sd);
  15266. WBUFW(buf,0) = cmd;
  15267. WBUFL(buf,2) = sd->status.account_id;
  15268. #if PACKETVER < 20140613
  15269. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15270. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15271. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15272. WBUFW(buf,32) = 100;
  15273. } else {
  15274. WBUFW(buf,30) = sd->battle_status.hp;
  15275. WBUFW(buf,32) = sd->battle_status.max_hp;
  15276. }
  15277. #else
  15278. if( sd->battle_status.max_hp > INT32_MAX ) {
  15279. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15280. WBUFL(buf,10) = 100;
  15281. } else {
  15282. WBUFL(buf,6) = sd->battle_status.hp;
  15283. WBUFL(buf,10) = sd->battle_status.max_hp;
  15284. }
  15285. #endif
  15286. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15287. }
  15288. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15289. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15290. void clif_bg_xy(struct map_session_data *sd)
  15291. {
  15292. unsigned char buf[36];
  15293. nullpo_retv(sd);
  15294. WBUFW(buf,0)=0x2df;
  15295. WBUFL(buf,2)=sd->status.account_id;
  15296. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15297. WBUFW(buf,30)=sd->status.class_;
  15298. WBUFW(buf,32)=sd->bl.x;
  15299. WBUFW(buf,34)=sd->bl.y;
  15300. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15301. }
  15302. void clif_bg_xy_remove(struct map_session_data *sd)
  15303. {
  15304. unsigned char buf[36];
  15305. nullpo_retv(sd);
  15306. WBUFW(buf,0)=0x2df;
  15307. WBUFL(buf,2)=sd->status.account_id;
  15308. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15309. WBUFW(buf,30)=0;
  15310. WBUFW(buf,32)=-1;
  15311. WBUFW(buf,34)=-1;
  15312. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15313. }
  15314. /// Notifies clients of a battleground message.
  15315. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15316. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15317. struct map_session_data *sd = bg_getavailablesd( bg );
  15318. if( sd == nullptr ){
  15319. return;
  15320. }
  15321. // limit length
  15322. len = min( len + 1, CHAT_SIZE_MAX );
  15323. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15324. WBUFW(buf,0) = 0x2dc;
  15325. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15326. WBUFL(buf,4) = src_id;
  15327. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15328. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15329. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15330. }
  15331. /// Validates and processes battlechat messages.
  15332. /// All messages that are sent after enabling battleground chat with /battlechat.
  15333. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15334. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  15335. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15336. if( !clif_process_message( sd, false, name, message, output ) )
  15337. return;
  15338. bg_send_message(sd, output, strlen(output) );
  15339. }
  15340. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15341. /// 02de <camp A points>.W <camp B points>.W
  15342. void clif_bg_updatescore(int16 m)
  15343. {
  15344. struct block_list bl;
  15345. unsigned char buf[6];
  15346. struct map_data *mapdata = map_getmapdata(m);
  15347. bl.id = 0;
  15348. bl.type = BL_NUL;
  15349. bl.m = m;
  15350. WBUFW(buf,0) = 0x2de;
  15351. WBUFW(buf,2) = mapdata->bgscore_lion;
  15352. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15353. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15354. }
  15355. void clif_bg_updatescore_single(struct map_session_data *sd)
  15356. {
  15357. int fd;
  15358. nullpo_retv(sd);
  15359. fd = sd->fd;
  15360. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15361. WFIFOHEAD(fd,packet_len(0x2de));
  15362. WFIFOW(fd,0) = 0x2de;
  15363. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15364. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15365. WFIFOSET(fd,packet_len(0x2de));
  15366. }
  15367. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15368. /// 02dd <account id>.L <name>.24B <camp>.W
  15369. void clif_sendbgemblem_area(struct map_session_data *sd)
  15370. {
  15371. unsigned char buf[33];
  15372. nullpo_retv(sd);
  15373. WBUFW(buf, 0) = 0x2dd;
  15374. WBUFL(buf,2) = sd->bl.id;
  15375. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15376. WBUFW(buf,30) = sd->bg_id;
  15377. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15378. }
  15379. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15380. {
  15381. nullpo_retv(sd);
  15382. WFIFOHEAD(fd,32);
  15383. WFIFOW(fd,0) = 0x2dd;
  15384. WFIFOL(fd,2) = sd->bl.id;
  15385. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15386. WFIFOW(fd,30) = sd->bg_id;
  15387. WFIFOSET(fd,packet_len(0x2dd));
  15388. }
  15389. /// Battlegrounds queue incoming apply request from client.
  15390. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15391. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15392. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15393. {
  15394. if (!battle_config.feature_bgqueue)
  15395. return;
  15396. nullpo_retv(sd);
  15397. short type = RFIFOW(fd,2);
  15398. char name[NAME_LENGTH];
  15399. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15400. if (sd->bg_queue_id > 0) {
  15401. //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);
  15402. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15403. return;
  15404. } else if (type == 1) // Solo
  15405. bg_queue_join_solo(name, sd);
  15406. else if (type == 2) // Party
  15407. bg_queue_join_party(name, sd);
  15408. else if (type == 4) // Guild
  15409. bg_queue_join_guild(name, sd);
  15410. else {
  15411. 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);
  15412. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15413. return;
  15414. }
  15415. }
  15416. /// Outgoing battlegrounds queue apply result.
  15417. /// Result types: @see e_bg_queue_apply_ack
  15418. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15419. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15420. {
  15421. nullpo_retv(sd);
  15422. int fd = sd->fd;
  15423. WFIFOHEAD(fd, packet_len(0x8d8));
  15424. WFIFOW(fd,0) = 0x8d8;
  15425. WFIFOB(fd,2) = result;
  15426. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15427. WFIFOSET(fd, packet_len(0x8d8));
  15428. }
  15429. /// Outgoing battlegrounds queue apply notification.
  15430. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15431. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15432. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15433. {
  15434. nullpo_retv(sd);
  15435. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15436. if (queue == nullptr) {
  15437. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15438. return;
  15439. }
  15440. int fd = sd->fd;
  15441. WFIFOHEAD(fd, packet_len(0x8d9));
  15442. WFIFOW(fd,0) = 0x8d9;
  15443. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15444. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15445. WFIFOSET(fd, packet_len(0x8d9));
  15446. }
  15447. /// Battlegrounds queue outgoing cancel result.
  15448. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15449. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15450. {
  15451. nullpo_retv(sd);
  15452. int fd = sd->fd;
  15453. WFIFOHEAD(fd, packet_len(0x8d8));
  15454. WFIFOW(fd,0) = 0x8db;
  15455. WFIFOB(fd,2) = success;
  15456. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15457. WFIFOSET(fd, packet_len(0x8d8));
  15458. }
  15459. /// Battlegrounds queue incoming cancel request from client.
  15460. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15461. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15462. {
  15463. if (!battle_config.feature_bgqueue)
  15464. return;
  15465. nullpo_retv(sd);
  15466. bool success;
  15467. if (sd->bg_queue_id > 0) {
  15468. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15469. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15470. 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.
  15471. else
  15472. success = bg_queue_leave(sd);
  15473. } else {
  15474. 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);
  15475. success = false;
  15476. }
  15477. char name[NAME_LENGTH];
  15478. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15479. clif_bg_queue_cancel_result(success, name, sd);
  15480. }
  15481. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15482. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15483. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15484. {
  15485. nullpo_retv(sd);
  15486. int fd = sd->fd;
  15487. WFIFOHEAD(fd, packet_len(0x8df));
  15488. WFIFOW(fd,0) = 0x8df;
  15489. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15490. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15491. WFIFOSET(fd, packet_len(0x8df));
  15492. }
  15493. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15494. /// Result types: 1(Accept), 2(Decline).
  15495. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15496. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15497. {
  15498. nullpo_retv(sd);
  15499. if(sd->bg_queue_id > 0) {
  15500. uint8 result = RFIFOB(fd, 2);
  15501. if(result == 1) { // Accept
  15502. bg_queue_on_accept_invite(sd);
  15503. } else if(result == 2) { // Decline
  15504. bg_queue_leave(sd);
  15505. clif_bg_queue_entry_init(sd);
  15506. }
  15507. }
  15508. }
  15509. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15510. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15511. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15512. {
  15513. nullpo_retv(sd);
  15514. int fd = sd->fd;
  15515. WFIFOHEAD(fd, packet_len(0x8e1));
  15516. WFIFOW(fd,0) = 0x8e1;
  15517. WFIFOB(fd,2) = result;
  15518. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15519. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15520. WFIFOSET(fd, packet_len(0x8e1));
  15521. }
  15522. /// Battlegrounds queue incoming queue number request from client.
  15523. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15524. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15525. {
  15526. nullpo_retv(sd);
  15527. char name[NAME_LENGTH];
  15528. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15529. clif_bg_queue_apply_notify(name, sd);
  15530. }
  15531. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15532. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15533. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15534. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15535. {
  15536. nullpo_retv(sd);
  15537. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15538. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15539. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15540. }
  15541. /// Custom Fonts (ZC_NOTIFY_FONT).
  15542. /// 02ef <account_id>.L <font id>.W
  15543. void clif_font(struct map_session_data *sd)
  15544. {
  15545. #if PACKETVER >= 20080102
  15546. unsigned char buf[8];
  15547. nullpo_retv(sd);
  15548. WBUFW(buf,0) = 0x2ef;
  15549. WBUFL(buf,2) = sd->bl.id;
  15550. WBUFW(buf,6) = sd->status.font;
  15551. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15552. #endif
  15553. }
  15554. /// Required to start the instancing information window on Client
  15555. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15556. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15557. void clif_instance_create(int instance_id, int num)
  15558. {
  15559. #if PACKETVER >= 20071128
  15560. struct map_session_data *sd = NULL;
  15561. enum send_target target = PARTY;
  15562. unsigned char buf[65];
  15563. instance_getsd(instance_id, sd, &target);
  15564. if (!sd)
  15565. return;
  15566. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15567. if (!db)
  15568. return;
  15569. WBUFW(buf,0) = 0x2cb;
  15570. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15571. WBUFW(buf,63) = num;
  15572. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15573. #endif
  15574. return;
  15575. }
  15576. /// To announce Instancing queue creation if no maps available
  15577. /// S 0x2cc <Standby Position>.W
  15578. void clif_instance_changewait(int instance_id, int num)
  15579. {
  15580. #if PACKETVER >= 20071128
  15581. struct map_session_data *sd = NULL;
  15582. enum send_target target = PARTY;
  15583. unsigned char buf[4];
  15584. instance_getsd(instance_id, sd, &target);
  15585. if (!sd)
  15586. return;
  15587. WBUFW(buf,0) = 0x2cc;
  15588. WBUFW(buf,2) = num;
  15589. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15590. #endif
  15591. return;
  15592. }
  15593. /// Notify the current status to members
  15594. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15595. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15596. {
  15597. #if PACKETVER >= 20071128
  15598. struct map_session_data *sd = NULL;
  15599. enum send_target target = PARTY;
  15600. unsigned char buf[71];
  15601. instance_getsd(instance_id, sd, &target);
  15602. if (!sd)
  15603. return;
  15604. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15605. if (!db)
  15606. return;
  15607. WBUFW(buf,0) = 0x2cd;
  15608. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15609. WBUFL(buf,63) = limit1;
  15610. WBUFL(buf,67) = limit2;
  15611. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15612. #endif
  15613. return;
  15614. }
  15615. /// Notify a status change to members
  15616. /// S 0x2ce <Message ID>.L
  15617. /// 0 = Notification (EnterLimitDate update?)
  15618. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15619. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15620. /// 3 = The Memorial Dungeon has been removed.
  15621. /// 4 = Create failure (removes the instance window)
  15622. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15623. {
  15624. #if PACKETVER >= 20071128
  15625. struct map_session_data *sd = NULL;
  15626. enum send_target target = PARTY;
  15627. unsigned char buf[10];
  15628. instance_getsd(instance_id, sd, &target);
  15629. if (!sd)
  15630. return;
  15631. WBUFW(buf,0) = 0x2ce;
  15632. WBUFL(buf,2) = type;
  15633. WBUFL(buf,6) = limit;
  15634. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15635. #endif
  15636. return;
  15637. }
  15638. /// Destroy an instance from the status window
  15639. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15640. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15641. {
  15642. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15643. return;
  15644. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15645. switch (p->command) {
  15646. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15647. instance_destroy_command(sd);
  15648. break;
  15649. }
  15650. }
  15651. /// Notifies clients about item picked up by a party member.
  15652. /// 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)
  15653. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15654. #if PACKETVER >= 20071002
  15655. nullpo_retv( sd );
  15656. nullpo_retv( item_data );
  15657. struct item_data* id = itemdb_search( item_data->nameid );
  15658. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15659. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15660. p.AID = sd->status.account_id;
  15661. p.itemId = client_nameid( item_data->nameid );
  15662. p.identified = item_data->identify;
  15663. p.damaged = item_data->attribute;
  15664. p.refine = item_data->refine;
  15665. clif_addcards( &p.slot, item_data );
  15666. p.location = id->equip; // equip location
  15667. p.itemType = itemtype( id->nameid ); // item type
  15668. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15669. p.enchantgrade = item_data->enchantgrade;
  15670. #endif
  15671. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15672. #endif
  15673. }
  15674. /** Display gained exp.
  15675. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15676. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15677. * amount: INT32_MIN ~ INT32_MAX
  15678. * var id:
  15679. * SP_BASEEXP, SP_JOBEXP
  15680. * exp type:
  15681. * 0 = normal exp gained/lost
  15682. * 1 = quest exp gained/lost
  15683. * @param sd Player
  15684. * @param exp EXP value gained/loss
  15685. * @param type SP_BASEEXP, SP_JOBEXP
  15686. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15687. * @param lost True:if losing EXP
  15688. */
  15689. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15690. {
  15691. int fd;
  15692. int offset;
  15693. #if PACKETVER >= 20170830
  15694. int cmd = 0xacc;
  15695. #else
  15696. int cmd = 0x7f6;
  15697. #endif
  15698. nullpo_retv(sd);
  15699. fd = sd->fd;
  15700. WFIFOHEAD(fd, packet_len(cmd));
  15701. WFIFOW(fd,0) = cmd;
  15702. WFIFOL(fd,2) = sd->bl.id;
  15703. #if PACKETVER >= 20170830
  15704. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15705. offset = 4;
  15706. #else
  15707. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15708. offset = 0;
  15709. #endif
  15710. WFIFOW(fd,10+offset) = type;
  15711. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15712. WFIFOSET(fd,packet_len(cmd));
  15713. }
  15714. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15715. /// type:
  15716. /// 0 = Displays 'value' for 5 seconds.
  15717. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15718. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15719. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15720. /// value:
  15721. /// 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).
  15722. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15723. {
  15724. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15725. WFIFOW(sd->fd,0) = 0x1b1;
  15726. WFIFOB(sd->fd,2) = type;
  15727. WFIFOL(sd->fd,3) = value;
  15728. WFIFOSET(sd->fd, packet_len(0x1b1));
  15729. }
  15730. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15731. /// 021d <state>.L
  15732. /// state:
  15733. /// 0 = Full effects
  15734. /// 1 = Reduced effects
  15735. ///
  15736. /// NOTE: The state is used on Aegis for sending skill unit packet
  15737. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15738. /// whenever possible. Due to the way the decision check is
  15739. /// constructed, this state tracking was rendered useless,
  15740. /// as the only skill unit, that is sent with 0x1c9 is
  15741. /// Graffiti.
  15742. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15743. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15744. sd->state.lesseffect = ( isLess != 0 );
  15745. }
  15746. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15747. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15748. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15749. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15750. int type = RFIFOL(fd,info->pos[1]);
  15751. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15752. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15753. if( sd->state.trading || sd->npc_shopid )
  15754. return;
  15755. if( flag == 0 || n == 0) {
  15756. clif_menuskill_clear(sd);
  15757. return; // Canceled by player.
  15758. }
  15759. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15760. clif_menuskill_clear(sd);
  15761. return; // Prevent hacking.
  15762. }
  15763. switch( type ) {
  15764. case 0: // Change Material
  15765. skill_changematerial(sd,n,item_list);
  15766. break;
  15767. case 1: // Level 1: Pure to Rough
  15768. case 2: // Level 2: Rough to Pure
  15769. skill_elementalanalysis(sd,n,type,item_list);
  15770. break;
  15771. }
  15772. clif_menuskill_clear(sd);
  15773. return;
  15774. }
  15775. /*==========================================
  15776. * Elemental System
  15777. *==========================================*/
  15778. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15779. s_elemental_data *ed;
  15780. struct status_data *status;
  15781. int fd;
  15782. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15783. return;
  15784. fd = sd->fd;
  15785. status = &ed->battle_status;
  15786. WFIFOHEAD(fd,8);
  15787. WFIFOW(fd,0) = 0x81e;
  15788. WFIFOW(fd,2) = type;
  15789. switch( type ) {
  15790. case SP_HP:
  15791. WFIFOL(fd,4) = status->hp;
  15792. break;
  15793. case SP_MAXHP:
  15794. WFIFOL(fd,4) = status->max_hp;
  15795. break;
  15796. case SP_SP:
  15797. WFIFOL(fd,4) = status->sp;
  15798. break;
  15799. case SP_MAXSP:
  15800. WFIFOL(fd,4) = status->max_sp;
  15801. break;
  15802. }
  15803. WFIFOSET(fd,8);
  15804. }
  15805. void clif_elemental_info(struct map_session_data *sd) {
  15806. int fd;
  15807. s_elemental_data *ed;
  15808. struct status_data *status;
  15809. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15810. return;
  15811. fd = sd->fd;
  15812. status = &ed->battle_status;
  15813. WFIFOHEAD(fd,22);
  15814. WFIFOW(fd, 0) = 0x81d;
  15815. WFIFOL(fd, 2) = ed->bl.id;
  15816. WFIFOL(fd, 6) = status->hp;
  15817. WFIFOL(fd,10) = status->max_hp;
  15818. WFIFOL(fd,14) = status->sp;
  15819. WFIFOL(fd,18) = status->max_sp;
  15820. WFIFOSET(fd,22);
  15821. }
  15822. /// Buying Store System
  15823. ///
  15824. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15825. /// 0810 <slots>.B
  15826. void clif_buyingstore_open(struct map_session_data* sd)
  15827. {
  15828. int fd = sd->fd;
  15829. WFIFOHEAD(fd,packet_len(0x810));
  15830. WFIFOW(fd,0) = 0x810;
  15831. WFIFOB(fd,2) = sd->buyingstore.slots;
  15832. WFIFOSET(fd,packet_len(0x810));
  15833. }
  15834. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15835. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15836. /// result:
  15837. /// 0 = cancel
  15838. /// 1 = open
  15839. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15840. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15841. // TODO: Make this check global for all variable length packets.
  15842. // minimum packet length
  15843. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15844. 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 );
  15845. return;
  15846. }
  15847. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15848. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15849. return;
  15850. }
  15851. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15852. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15853. return;
  15854. }
  15855. char storename[MESSAGE_SIZE];
  15856. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15857. // so that buyingstore_create knows, how many elements it has access to
  15858. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15859. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15860. 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 ) );
  15861. return;
  15862. }
  15863. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15864. }
  15865. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15866. /// 0812 <result>.W <total weight>.L
  15867. /// result:
  15868. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15869. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15870. /// 8 = "No sale (purchase) information available." (0x705)
  15871. /// ? = nothing
  15872. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15873. {
  15874. int fd = sd->fd;
  15875. WFIFOHEAD(fd,packet_len(0x812));
  15876. WFIFOW(fd,0) = 0x812;
  15877. WFIFOW(fd,2) = result;
  15878. WFIFOL(fd,4) = weight;
  15879. WFIFOSET(fd,packet_len(0x812));
  15880. }
  15881. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15882. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15883. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15884. nullpo_retv( sd );
  15885. int fd = sd->fd;
  15886. if( !session_isActive( fd ) ){
  15887. return;
  15888. }
  15889. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15890. WFIFOHEAD( fd, length );
  15891. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15892. p->packetType = 0x813;
  15893. p->packetLength = length;
  15894. p->AID = sd->bl.id;
  15895. p->zenyLimit = sd->buyingstore.zenylimit;
  15896. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15897. p->items[i].price = sd->buyingstore.items[i].price;
  15898. p->items[i].amount = sd->buyingstore.items[i].amount;
  15899. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15900. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15901. }
  15902. WFIFOSET( fd, p->packetLength );
  15903. }
  15904. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15905. /// 0814 <account id>.L <store name>.80B
  15906. void clif_buyingstore_entry(struct map_session_data* sd)
  15907. {
  15908. uint8 buf[MESSAGE_SIZE+6];
  15909. WBUFW(buf,0) = 0x814;
  15910. WBUFL(buf,2) = sd->bl.id;
  15911. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15912. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15913. }
  15914. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15915. {
  15916. int fd = sd->fd;
  15917. WFIFOHEAD(fd,packet_len(0x814));
  15918. WFIFOW(fd,0) = 0x814;
  15919. WFIFOL(fd,2) = pl_sd->bl.id;
  15920. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15921. WFIFOSET(fd,packet_len(0x814));
  15922. }
  15923. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15924. /// 0815
  15925. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15926. {
  15927. buyingstore_close(sd);
  15928. }
  15929. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15930. /// 0816 <account id>.L
  15931. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15932. {
  15933. uint8 buf[6];
  15934. WBUFW(buf,0) = 0x816;
  15935. WBUFL(buf,2) = sd->bl.id;
  15936. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15937. }
  15938. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15939. {
  15940. int fd = sd->fd;
  15941. WFIFOHEAD(fd,packet_len(0x816));
  15942. WFIFOW(fd,0) = 0x816;
  15943. WFIFOL(fd,2) = pl_sd->bl.id;
  15944. WFIFOSET(fd,packet_len(0x816));
  15945. }
  15946. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15947. /// 0817 <account id>.L
  15948. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15949. {
  15950. uint32 account_id;
  15951. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15952. buyingstore_open(sd, account_id);
  15953. }
  15954. /// Sends buying store item list.
  15955. /// 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)
  15956. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15957. nullpo_retv( sd );
  15958. nullpo_retv( pl_sd );
  15959. int fd = sd->fd;
  15960. if( !session_isActive( fd ) ){
  15961. return;
  15962. }
  15963. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15964. WFIFOHEAD( fd, length );
  15965. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15966. p->packetType = 0x818;
  15967. p->packetLength = length;
  15968. p->AID = pl_sd->bl.id;
  15969. p->storeId = pl_sd->buyer_id;
  15970. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15971. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15972. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15973. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15974. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15975. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15976. }
  15977. WFIFOSET( fd, p->packetLength );
  15978. }
  15979. /// Request to sell items to a buying store.
  15980. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15981. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15982. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15983. // minimum packet length
  15984. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15985. 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 );
  15986. return;
  15987. }
  15988. // so that buyingstore_trade knows, how many elements it has access to
  15989. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15990. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15991. 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 ) );
  15992. return;
  15993. }
  15994. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15995. }
  15996. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15997. /// 081a <result>.W
  15998. /// result:
  15999. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  16000. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  16001. /// ? = nothing
  16002. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  16003. {
  16004. int fd = sd->fd;
  16005. WFIFOHEAD(fd,packet_len(0x81a));
  16006. WFIFOW(fd,0) = 0x81a;
  16007. WFIFOW(fd,2) = result;
  16008. WFIFOSET(fd,packet_len(0x81a));
  16009. }
  16010. /// Updates the zeny limit and an item in the buying store item list.
  16011. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  16012. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  16013. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  16014. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  16015. p.packetType = buyingStoreUpdateItemType;
  16016. p.itemId = client_nameid( nameid );
  16017. p.amount = amount;
  16018. p.zenyLimit = sd->buyingstore.zenylimit;
  16019. #if PACKETVER >= 20141016
  16020. p.zeny = zeny;
  16021. p.charId = char_id; // GID
  16022. p.updateTime = (int)time(NULL);
  16023. #endif
  16024. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16025. }
  16026. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  16027. /// 081c <index>.W <amount>.W <price>.L
  16028. /// message:
  16029. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  16030. ///
  16031. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  16032. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  16033. {
  16034. int fd = sd->fd;
  16035. WFIFOHEAD(fd,packet_len(0x81c));
  16036. WFIFOW(fd,0) = 0x81c;
  16037. WFIFOW(fd,2) = client_index( index );
  16038. WFIFOW(fd,4) = amount;
  16039. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  16040. WFIFOSET(fd,packet_len(0x81c));
  16041. }
  16042. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  16043. /// 0824 <result>.W <name id>.W
  16044. /// result:
  16045. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  16046. /// 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)
  16047. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  16048. /// ? = nothing
  16049. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  16050. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  16051. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  16052. p.result = result;
  16053. p.itemId = client_nameid( nameid );
  16054. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16055. }
  16056. /// Search Store Info System
  16057. ///
  16058. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  16059. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  16060. /// type:
  16061. /// 0 = Vending
  16062. /// 1 = Buying Store
  16063. ///
  16064. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16065. /// amount of card slots. If the client does not know about the item it
  16066. /// cannot be searched.
  16067. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  16068. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16069. // minimum packet length
  16070. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16071. 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 );
  16072. return;
  16073. }
  16074. // check, if there is enough data for the claimed count of items
  16075. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16076. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16077. 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 ) );
  16078. return;
  16079. }
  16080. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16081. if( count < p->itemsCount + p->cardsCount ){
  16082. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16083. return;
  16084. }
  16085. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16086. }
  16087. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16088. /// 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 }*
  16089. /// is first page:
  16090. /// 0 = appends to existing results
  16091. /// 1 = clears previous results before displaying this result set
  16092. /// is next page:
  16093. /// 0 = no "next" label
  16094. /// 1 = "next" label to retrieve more results
  16095. void clif_search_store_info_ack( struct map_session_data* sd ){
  16096. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  16097. nullpo_retv( sd );
  16098. int fd = sd->fd;
  16099. if( !session_isActive( fd ) ){
  16100. return;
  16101. }
  16102. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16103. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16104. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16105. WFIFOHEAD( fd, len );
  16106. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16107. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16108. p->packetLength = len;
  16109. p->firstPage = !sd->searchstore.pages;
  16110. p->nextPage = searchstore_querynext( sd );
  16111. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16112. for( int i = 0; i < end - start; i++ ) {
  16113. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16114. p->items[i].storeId = ssitem->store_id;
  16115. p->items[i].AID = ssitem->account_id;
  16116. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16117. p->items[i].itemId = client_nameid( ssitem->nameid );
  16118. p->items[i].itemType = itemtype( ssitem->nameid );
  16119. p->items[i].price = ssitem->price;
  16120. p->items[i].amount = ssitem->amount;
  16121. p->items[i].refine = ssitem->refine;
  16122. // make-up an item for clif_addcards
  16123. struct item it = {};
  16124. for( int j = 0; j < MAX_SLOTS; j++ ){
  16125. it.card[j] = ssitem->card[j];
  16126. }
  16127. it.nameid = ssitem->nameid;
  16128. it.amount = ssitem->amount;
  16129. clif_addcards( &p->items[i].slot, &it );
  16130. #if PACKETVER >= 20150226
  16131. clif_add_random_options( p->items[i].option_data, &it );
  16132. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16133. p->items[i].enchantgrade = ssitem->enchantgrade;
  16134. #endif
  16135. #endif
  16136. }
  16137. WFIFOSET( fd, len );
  16138. #endif
  16139. }
  16140. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16141. /// 0837 <reason>.B
  16142. /// reason:
  16143. /// 0 = "No matching stores were found." (0x70b)
  16144. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16145. /// 2 = "You cannot search anymore." (0x706)
  16146. /// 3 = "You cannot search yet." (0x708)
  16147. /// 4 = "No sale (purchase) information available." (0x705)
  16148. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  16149. {
  16150. int fd = sd->fd;
  16151. WFIFOHEAD(fd,packet_len(0x837));
  16152. WFIFOW(fd,0) = 0x837;
  16153. WFIFOB(fd,2) = reason;
  16154. WFIFOSET(fd,packet_len(0x837));
  16155. }
  16156. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16157. /// 0838
  16158. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  16159. {
  16160. searchstore_next(sd);
  16161. }
  16162. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16163. /// 083a <type>.W <remaining uses>.B
  16164. /// type:
  16165. /// 0 = Search Stores
  16166. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16167. void clif_open_search_store_info(struct map_session_data* sd)
  16168. {
  16169. int fd = sd->fd;
  16170. WFIFOHEAD(fd,packet_len(0x83a));
  16171. WFIFOW(fd,0) = 0x83a;
  16172. WFIFOW(fd,2) = sd->searchstore.effect;
  16173. #if PACKETVER > 20100701
  16174. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16175. #endif
  16176. WFIFOSET(fd,packet_len(0x83a));
  16177. }
  16178. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16179. /// 083b
  16180. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  16181. {
  16182. searchstore_close(sd);
  16183. }
  16184. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16185. /// 083c <account id>.L <store id>.L <nameid>.W
  16186. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  16187. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16188. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16189. }
  16190. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16191. /// 083d <xPos>.W <yPos>.W
  16192. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  16193. {
  16194. int fd = sd->fd;
  16195. WFIFOHEAD(fd,packet_len(0x83d));
  16196. WFIFOW(fd,0) = 0x83d;
  16197. WFIFOW(fd,2) = x;
  16198. WFIFOW(fd,4) = y;
  16199. WFIFOSET(fd,packet_len(0x83d));
  16200. }
  16201. /// Parse function for packet debugging.
  16202. void clif_parse_debug(int fd,struct map_session_data *sd)
  16203. {
  16204. int cmd, packet_len;
  16205. // clif_parse ensures, that there is at least 2 bytes of data
  16206. cmd = RFIFOW(fd,0);
  16207. if( sd ) {
  16208. packet_len = packet_db[cmd].len;
  16209. if( packet_len == 0 )
  16210. {// unknown
  16211. packet_len = RFIFOREST(fd);
  16212. }
  16213. else if( packet_len == -1 )
  16214. {// variable length
  16215. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16216. }
  16217. 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);
  16218. }
  16219. else
  16220. {
  16221. packet_len = RFIFOREST(fd);
  16222. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16223. }
  16224. ShowDump(RFIFOP(fd,0), packet_len);
  16225. }
  16226. /*==========================================
  16227. * Server tells client to display a window similar to Magnifier (item) one
  16228. * Server populates the window with avilable elemental converter options according to player's inventory
  16229. *------------------------------------------*/
  16230. void clif_elementalconverter_list( struct map_session_data *sd ){
  16231. nullpo_retv( sd );
  16232. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16233. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16234. int count = 0;
  16235. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16236. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16237. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16238. count++;
  16239. }
  16240. }
  16241. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16242. clif_send( p, p->packetLength, &sd->bl, SELF );
  16243. if( count > 0 ){
  16244. sd->menuskill_id = SA_CREATECON;
  16245. sd->menuskill_val = count;
  16246. }
  16247. }
  16248. /**
  16249. * Rune Knight
  16250. **/
  16251. void clif_millenniumshield(struct block_list *bl, short shields) {
  16252. #if PACKETVER >= 20081217
  16253. unsigned char buf[10];
  16254. WBUFW(buf,0) = 0x440;
  16255. WBUFL(buf,2) = bl->id;
  16256. WBUFW(buf,6) = shields;
  16257. WBUFW(buf,8) = 0;
  16258. clif_send(buf,packet_len(0x440),bl,AREA);
  16259. #endif
  16260. }
  16261. /**
  16262. * Mechanic
  16263. **/
  16264. /*==========================================
  16265. * Magic Decoy Material List
  16266. *------------------------------------------*/
  16267. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  16268. nullpo_retv( sd );
  16269. int fd = sd->fd;
  16270. if( !session_isActive( fd ) ){
  16271. return;
  16272. }
  16273. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16274. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16275. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16276. int count = 0;
  16277. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16278. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16279. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16280. count++;
  16281. }
  16282. }
  16283. if( count > 0 ) {
  16284. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16285. WFIFOSET( fd, p->packetLength );
  16286. sd->menuskill_id = NC_MAGICDECOY;
  16287. sd->menuskill_val = skill_lv;
  16288. sd->sc.comet_x = x;
  16289. sd->sc.comet_y = y;
  16290. }else{
  16291. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16292. }
  16293. }
  16294. /*==========================================
  16295. * Guillotine Cross Poisons List
  16296. *------------------------------------------*/
  16297. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16298. nullpo_retv( sd );
  16299. int fd = sd->fd;
  16300. if( !session_isActive( fd ) ){
  16301. return;
  16302. }
  16303. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16304. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16305. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16306. int count = 0;
  16307. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16308. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16309. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16310. count++;
  16311. }
  16312. }
  16313. if( count > 0 ){
  16314. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16315. WFIFOSET( fd, p->packetLength );
  16316. sd->menuskill_id = GC_POISONINGWEAPON;
  16317. sd->menuskill_val = skill_lv;
  16318. }else{
  16319. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16320. }
  16321. }
  16322. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16323. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16324. int fd, i, c;
  16325. nullpo_ret(sd);
  16326. fd = sd->fd;
  16327. if( !session_isActive(fd) )
  16328. return 0;
  16329. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16330. return 0;
  16331. WFIFOHEAD(fd, 2 * 6 + 4);
  16332. WFIFOW(fd,0) = 0x442;
  16333. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16334. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16335. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16336. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16337. {
  16338. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16339. c++;
  16340. }
  16341. if( c > 0 ) {
  16342. WFIFOW(fd,2) = 8 + c * 2;
  16343. WFIFOL(fd,4) = c;
  16344. WFIFOSET(fd,WFIFOW(fd,2));
  16345. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16346. sd->menuskill_val = c;
  16347. } else {
  16348. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  16349. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16350. }
  16351. return 1;
  16352. }
  16353. /*===========================================
  16354. * Skill list for Four Elemental Analysis
  16355. * and Change Material skills.
  16356. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16357. *------------------------------------------*/
  16358. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16359. #if PACKETVER >= 20090922
  16360. int fd = sd->fd;
  16361. nullpo_ret(sd);
  16362. sd->menuskill_id = skill_id; // To prevent hacking.
  16363. sd->menuskill_val = skill_lv;
  16364. if( skill_id == GN_CHANGEMATERIAL )
  16365. skill_lv = 0; // Changematerial
  16366. WFIFOHEAD(fd, packet_len(0x7e3));
  16367. WFIFOW(fd,0) = 0x7e3;
  16368. WFIFOL(fd,2) = skill_lv;
  16369. WFIFOL(fd,4) = 0;
  16370. WFIFOSET(fd, packet_len(0x7e3));
  16371. #endif
  16372. return 1;
  16373. }
  16374. /*==========================================
  16375. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16376. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16377. * RFIFOL(fd,2) - type (currently not used)
  16378. *------------------------------------------*/
  16379. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16380. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16381. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16382. if (sd->menuskill_id == SA_AUTOSPELL) {
  16383. sd->state.workinprogress = WIP_DISABLE_NONE;
  16384. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16385. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16386. if (pc_istrading(sd)) {
  16387. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16388. clif_menuskill_clear(sd);
  16389. return;
  16390. }
  16391. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16392. } else
  16393. return;
  16394. clif_menuskill_clear(sd);
  16395. }
  16396. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16397. /// 08cf <id>.L <type>.W <num>.W
  16398. void clif_spiritcharm(struct map_session_data *sd) {
  16399. unsigned char buf[10];
  16400. nullpo_retv(sd);
  16401. WBUFW(buf,0) = 0x08cf;
  16402. WBUFL(buf,2) = sd->bl.id;
  16403. WBUFW(buf,6) = sd->spiritcharm_type;
  16404. WBUFW(buf,8) = sd->spiritcharm;
  16405. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16406. }
  16407. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16408. /// 0907 <index>.W
  16409. ///
  16410. /// R 0908 <index>.w <type>.b
  16411. /// type:
  16412. /// 0 = move item to personal tab
  16413. /// 1 = move item to normal tab
  16414. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16415. #if PACKETVER >= 20111122
  16416. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16417. int index = RFIFOW(fd,info->pos[0]) - 2;
  16418. int type = RFIFOB(fd, info->pos[1]);
  16419. /* can't move while dead. */
  16420. if(pc_isdead(sd)) {
  16421. return;
  16422. }
  16423. if (index < 0 || index >= MAX_INVENTORY)
  16424. return;
  16425. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16426. sd->inventory.u.items_inventory[index].favorite = 0;
  16427. else if( type == 0 )
  16428. sd->inventory.u.items_inventory[index].favorite = 1;
  16429. else
  16430. return;/* nothing to do. */
  16431. clif_favorite_item(sd, index);
  16432. #endif
  16433. }
  16434. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16435. /// 0900 <index>.W <favorite>.B
  16436. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16437. int fd = sd->fd;
  16438. WFIFOHEAD(fd,packet_len(0x908));
  16439. WFIFOW(fd,0) = 0x908;
  16440. WFIFOW(fd,2) = index+2;
  16441. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16442. WFIFOSET(fd,packet_len(0x908));
  16443. }
  16444. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16445. void clif_snap( struct block_list *bl, short x, short y ) {
  16446. unsigned char buf[10];
  16447. WBUFW(buf,0) = 0x8d2;
  16448. WBUFL(buf,2) = bl->id;
  16449. WBUFW(buf,6) = x;
  16450. WBUFW(buf,8) = y;
  16451. if( disguised(bl) )
  16452. {
  16453. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16454. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16455. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16456. } else
  16457. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16458. }
  16459. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16460. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16461. #if PACKETVER >= 20120404
  16462. WFIFOHEAD(fd,packet_len(0x977));
  16463. WFIFOW(fd,0) = 0x977;
  16464. WFIFOL(fd,2) = md->bl.id;
  16465. WFIFOL(fd,6) = md->status.hp;
  16466. WFIFOL(fd,10) = md->status.max_hp;
  16467. WFIFOSET(fd,packet_len(0x977));
  16468. #endif
  16469. }
  16470. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16471. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16472. return;
  16473. }
  16474. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16475. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16476. WFIFOW(sd->fd,0) = 0x2c9;
  16477. WFIFOB(sd->fd,2) = flag;
  16478. WFIFOSET(sd->fd, packet_len(0x2c9));
  16479. }
  16480. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16481. /// 0979 <world name>.24B <char name>.24B
  16482. void clif_ackworldinfo(struct map_session_data* sd) {
  16483. int fd;
  16484. nullpo_retv(sd);
  16485. fd = sd->fd;
  16486. WFIFOHEAD(fd,packet_len(0x979));
  16487. WFIFOW(fd,0)=0x979;
  16488. //AID -> world name ?
  16489. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16490. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16491. WFIFOSET(fd,packet_len(0x979));
  16492. }
  16493. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16494. /// 0978 <AID>.L
  16495. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16496. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16497. if(sd)
  16498. clif_ackworldinfo(sd);
  16499. }
  16500. static void clif_loadConfirm( struct map_session_data *sd ){
  16501. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16502. nullpo_retv( sd );
  16503. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16504. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16505. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16506. if (sd->instance_id > 0)
  16507. instance_reqinfo(sd, sd->instance_id);
  16508. if (sd->status.party_id > 0)
  16509. party_member_joined(sd);
  16510. if (sd->status.guild_id > 0)
  16511. guild_member_joined(sd);
  16512. if (sd->status.clan_id > 0)
  16513. clan_member_joined(sd);
  16514. #endif
  16515. }
  16516. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16517. /// 0447
  16518. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16519. clif_loadConfirm( sd );
  16520. }
  16521. /// req world info (CZ_CLIENT_VERSION)
  16522. /// 044A <version>.L
  16523. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16524. //if(sd)
  16525. ;
  16526. }
  16527. /// Ranking list
  16528. /// ranking pointlist { <name>.24B <point>.L }*10
  16529. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16530. struct fame_list* list;
  16531. int i, size = MAX_FAME_LIST;
  16532. switch(rankingtype) {
  16533. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16534. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16535. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16536. // PK currently unsupported
  16537. case RANK_KILLER: list = NULL; size = 0; break;
  16538. default:
  16539. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16540. return;
  16541. }
  16542. //Packet size limits this list to 10 elements. [Skotlex]
  16543. for (i = 0; i < min(10,size); i++) {
  16544. if (list[i].id > 0) {
  16545. const char* name;
  16546. if (strcmp(list[i].name, "-") == 0 &&
  16547. (name = map_charid2nick(list[i].id)) != NULL)
  16548. {
  16549. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16550. } else {
  16551. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16552. }
  16553. } else {
  16554. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16555. }
  16556. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16557. }
  16558. for(;i < 10; i++) { //In case the MAX is less than 10.
  16559. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16560. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16561. }
  16562. }
  16563. /// Request for the blacksmith ranklist.
  16564. /// /blacksmith command sends this packet to the server.
  16565. /// 0217 (CZ_BLACKSMITH_RANK)
  16566. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16567. clif_ranklist(sd,RANK_BLACKSMITH);
  16568. }
  16569. /// Request for the alchemist ranklist.
  16570. /// /alchemist command sends this packet to the server.
  16571. /// 0218 (CZ_ALCHEMIST_RANK)
  16572. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16573. clif_ranklist(sd,RANK_ALCHEMIST);
  16574. }
  16575. /// Request for the taekwon ranklist.
  16576. /// /taekwon command sends this packet to the server.
  16577. /// 0225 (CZ_TAEKWON_RANK)
  16578. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16579. clif_ranklist(sd,RANK_TAEKWON);
  16580. }
  16581. /// Request for the killer ranklist.
  16582. /// /pk command sends this packet to the server.
  16583. /// 0237 (CZ_KILLER_RANK)
  16584. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16585. clif_ranklist(sd,RANK_KILLER);
  16586. }
  16587. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16588. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16589. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16590. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16591. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16592. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16593. enum e_rank rank;
  16594. #if PACKETVER < 20130710
  16595. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16596. short cmd;
  16597. switch( rankingType ){
  16598. case RANK_BLACKSMITH: cmd = 0x219; break;
  16599. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16600. case RANK_TAEKWON: cmd = 0x226; break;
  16601. case RANK_KILLER: cmd = 0x238; break;
  16602. default:
  16603. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16604. return;
  16605. }
  16606. // Can be safely casted here, since we validated it before
  16607. rank = (enum e_rank)rankingType;
  16608. WBUFW(buf,0) = cmd;
  16609. clif_sub_ranklist(buf,2,sd,rank);
  16610. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16611. #else
  16612. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16613. int mypoint = 0;
  16614. switch( rankingType ){
  16615. case RANK_BLACKSMITH:
  16616. case RANK_ALCHEMIST:
  16617. case RANK_TAEKWON:
  16618. case RANK_KILLER:
  16619. break;
  16620. default:
  16621. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16622. return;
  16623. }
  16624. // Can be safely casted here, since we validated it before
  16625. rank = (enum e_rank)rankingType;
  16626. WBUFW(buf,0) = 0x97d;
  16627. WBUFW(buf,2) = rank;
  16628. clif_sub_ranklist(buf,4,sd,rank);
  16629. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16630. case MAPID_BLACKSMITH:
  16631. case MAPID_ALCHEMIST:
  16632. case MAPID_TAEKWON:
  16633. mypoint = sd->status.fame;
  16634. }
  16635. WBUFL(buf,284) = mypoint; //mypoint
  16636. clif_send(buf, 288, &sd->bl, SELF);
  16637. #endif
  16638. }
  16639. /*
  16640. * 097c <type> (CZ_REQ_RANKING)
  16641. * type
  16642. * 0: /blacksmith
  16643. * 1: /alchemist
  16644. * 2: /taekwon
  16645. * 3: /pk
  16646. * */
  16647. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16648. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16649. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16650. clif_ranklist(sd,rankingtype);
  16651. }
  16652. /// Updates the fame rank points for the given ranking.
  16653. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16654. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16655. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16656. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16657. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16658. int fd = sd.fd;
  16659. #if PACKETVER < 20130710
  16660. short cmd;
  16661. switch(rankingtype){
  16662. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16663. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16664. case RANK_TAEKWON: cmd = 0x224; break;
  16665. default:
  16666. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16667. return;
  16668. }
  16669. WFIFOHEAD(fd,packet_len(cmd));
  16670. WFIFOW(fd,0) = cmd;
  16671. WFIFOL(fd,2) = point;
  16672. WFIFOL(fd,6) = sd.status.fame;
  16673. WFIFOSET(fd, packet_len(cmd));
  16674. #else
  16675. WFIFOHEAD(fd,packet_len(0x97e));
  16676. WFIFOW(fd,0) = 0x97e;
  16677. WFIFOW(fd,2) = rankingtype;
  16678. WFIFOL(fd,4) = point;
  16679. WFIFOL(fd,8) = sd.status.fame;
  16680. WFIFOSET(fd,packet_len(0x97e));
  16681. #endif
  16682. }
  16683. /**
  16684. * Transmit personal information to player. (rates)
  16685. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16686. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16687. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16688. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16689. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16690. * FIXME!
  16691. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16692. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16693. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16694. */
  16695. #ifdef VIP_ENABLE
  16696. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16697. if (sd) {
  16698. struct s_packet_db* info;
  16699. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16700. int cmd = 0, fd, i = 0;
  16701. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16702. int details_bexp[PINFO_MAX];
  16703. int details_drop[PINFO_MAX];
  16704. int details_penalty[PINFO_MAX];
  16705. /**
  16706. * Set for EXP
  16707. */
  16708. //0:PCRoom
  16709. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16710. if (details_bexp[0] == 100 || !details_bexp[0])
  16711. details_bexp[0] = 0;
  16712. else {
  16713. if (details_bexp[0] < 100) {
  16714. details_bexp[0] = 100 - details_bexp[0];
  16715. details_bexp[0] = 0 - details_bexp[0];
  16716. }
  16717. else
  16718. details_bexp[0] = details_bexp[0] - 100;
  16719. }
  16720. //1:Premium
  16721. if (pc_isvip(sd)) {
  16722. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16723. if (details_bexp[1] < 0)
  16724. details_bexp[1] = 0 - details_bexp[1];
  16725. }
  16726. else
  16727. details_bexp[1] = 0;
  16728. //2:Server
  16729. details_bexp[2] = battle_config.base_exp_rate;
  16730. if (details_bexp[2] == 100)
  16731. details_bexp[2] = 0;
  16732. else {
  16733. if (details_bexp[2] < 100) {
  16734. details_bexp[2] = 100 - details_bexp[2];
  16735. details_bexp[2] = 0 - details_bexp[2];
  16736. }
  16737. else
  16738. details_bexp[2] = details_bexp[2] - 100;
  16739. }
  16740. //3:TPLUS
  16741. details_bexp[3] = 0;
  16742. /* End - EXP set*/
  16743. /**
  16744. * Set for Drop rate
  16745. */
  16746. //0:PCRoom
  16747. details_drop[0] = 0;
  16748. //1:Premium
  16749. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16750. if (pc_isvip(sd)) {
  16751. if (details_drop[1] < 0)
  16752. details_drop[1] = 0 - details_drop[1];
  16753. }
  16754. else
  16755. details_drop[1] = 0;
  16756. //2:Server
  16757. details_drop[2] = battle_config.item_rate_common;
  16758. if (details_drop[2] == 100)
  16759. details_drop[2] = 0;
  16760. else {
  16761. if (details_drop[2] < 100) {
  16762. details_drop[2] = 100 - details_drop[2];
  16763. details_drop[2] = 0 - details_drop[2];
  16764. }
  16765. else
  16766. details_drop[2] = details_drop[2] - 100;
  16767. }
  16768. //3:TPLUS
  16769. details_drop[3] = 0;
  16770. /* End - Drop set*/
  16771. /**
  16772. * Set for Penalty rate
  16773. */
  16774. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16775. //0:PCRoom
  16776. details_penalty[0] = 0;
  16777. //1:Premium
  16778. if (pc_isvip(sd)) {
  16779. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16780. if (details_penalty[1] == 100)
  16781. details_penalty[1] = 0;
  16782. else {
  16783. if (details_penalty[1] < 100) {
  16784. details_penalty[1] = 100 - details_penalty[1];
  16785. details_penalty[1] = 0 - details_penalty[1];
  16786. }
  16787. else
  16788. details_penalty[1] = details_penalty[1] - 100;
  16789. }
  16790. }
  16791. else
  16792. details_penalty[1] = 0;
  16793. //2:Server
  16794. details_penalty[2] = battle_config.death_penalty_base;
  16795. if (details_penalty[2] == 100)
  16796. details_penalty[2] = 0;
  16797. else {
  16798. if (details_penalty[2] < 100) {
  16799. details_penalty[2] = 100 - details_penalty[2];
  16800. details_penalty[2] = 0 - details_penalty[2];
  16801. }
  16802. else
  16803. details_penalty[2] = details_penalty[2] - 100;
  16804. }
  16805. //3:TPLUS
  16806. details_penalty[3] = 0;
  16807. /* End - Penalty set*/
  16808. cmd = packet_db_ack[cmdtype];
  16809. info = &packet_db[cmd];
  16810. len = info->len; //this is the base len without details
  16811. if(!len) return; //version as packet disable
  16812. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16813. szdetails = 7;
  16814. factor = 1;
  16815. }
  16816. else if (cmd == 0x097b) {
  16817. tot_baseexp *= factor;
  16818. tot_drop *= factor;
  16819. tot_penalty *= factor;
  16820. }
  16821. fd = sd->fd;
  16822. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16823. WFIFOW(fd,0) = cmd;
  16824. for (i = 0; i < maxinfotype; i++) {
  16825. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16826. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16827. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16828. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16829. tot_baseexp += details_bexp[i]*factor;
  16830. tot_drop += details_penalty[i]*factor;
  16831. tot_penalty += details_drop[i]*factor;
  16832. len += szdetails;
  16833. }
  16834. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16835. if (cmd == 0x08cb) { //0x08cb version
  16836. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16837. WFIFOW(fd,info->pos[2]) = tot_drop;
  16838. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16839. }
  16840. else { //2013-08-07aRagexe uses 0x097b
  16841. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16842. WFIFOL(fd,info->pos[2]) = tot_drop;
  16843. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16844. }
  16845. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16846. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16847. WFIFOSET(fd,len);
  16848. }
  16849. }
  16850. #endif
  16851. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16852. char cmd[30];
  16853. int t_aid = RFIFOL(fd,2);
  16854. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16855. is_atcommand(fd, sd, cmd, 1);
  16856. }
  16857. /**
  16858. * Marks Crimson Marker target on mini-map to the caster
  16859. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16860. * @param fd
  16861. * @param bl Crimson Marker target
  16862. **/
  16863. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16864. struct s_packet_db* info;
  16865. int cmd = 0;
  16866. int16 len;
  16867. unsigned char buf[11];
  16868. nullpo_retv(sd);
  16869. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16870. if (!cmd)
  16871. cmd = 0x09C1; //default
  16872. info = &packet_db[cmd];
  16873. if (!(len = info->len))
  16874. return;
  16875. WBUFW(buf, 0) = cmd;
  16876. WBUFL(buf, info->pos[0]) = bl->id;
  16877. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16878. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16879. clif_send(buf, len, &sd->bl, SELF);
  16880. }
  16881. /**
  16882. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16883. **/
  16884. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16885. struct s_packet_db *info = NULL;
  16886. int cmd = 0;
  16887. nullpo_retv(sd);
  16888. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16889. info = &packet_db[cmd];
  16890. if (!cmd || !info->len)
  16891. return;
  16892. WFIFOHEAD(sd->fd, info->len);
  16893. WFIFOW(sd->fd, 0) = cmd;
  16894. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16895. WFIFOSET(sd->fd, info->len);
  16896. }
  16897. /**
  16898. * [Ind/Hercules]
  16899. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16900. **/
  16901. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16902. char buf[256];
  16903. size_t len;
  16904. nullpo_retv(bl);
  16905. if(!message)
  16906. return;
  16907. len = strlen(message)+1;
  16908. if( len > sizeof(buf)-8 ) {
  16909. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16910. len = sizeof(buf)-8;
  16911. }
  16912. WBUFW(buf,0) = 0x8b3;
  16913. WBUFW(buf,2) = (uint16)(len+8);
  16914. WBUFL(buf,4) = bl->id;
  16915. safestrncpy(WBUFCP(buf,8), message, len);
  16916. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16917. }
  16918. /**
  16919. * [Ind/Hercules]
  16920. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16921. **/
  16922. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16923. unsigned char buf[10];
  16924. nullpo_retv(sd);
  16925. WBUFW(buf,0) = 0x7fc;
  16926. WBUFL(buf,2) = prev_leader_aid;
  16927. WBUFL(buf,6) = new_leader_aid;
  16928. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16929. }
  16930. /**
  16931. * Sends a clan message to a player
  16932. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16933. **/
  16934. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16935. #if PACKETVER >= 20131223
  16936. struct map_session_data *sd;
  16937. uint8 buf[256];
  16938. if( len == 0 ){
  16939. return;
  16940. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16941. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16942. len = sizeof(buf)-5-NAME_LENGTH;
  16943. }
  16944. WBUFW(buf, 0) = 0x98e;
  16945. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16946. // 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
  16947. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16948. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16949. if((sd = clan_getavailablesd(clan)) != NULL)
  16950. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16951. #endif
  16952. }
  16953. /**
  16954. * Parses a clan message from a player.
  16955. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16956. **/
  16957. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16958. #if PACKETVER >= 20131223
  16959. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16960. // validate packet and retrieve name and message
  16961. if( !clif_process_message(sd, false, name, message, output ) )
  16962. return;
  16963. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16964. #endif
  16965. }
  16966. /**
  16967. * Sends the basic clan informations to the client.
  16968. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16969. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16970. **/
  16971. void clif_clan_basicinfo( struct map_session_data *sd ){
  16972. #if PACKETVER >= 20131223
  16973. int fd, offset, length, i, flag;
  16974. struct clan* clan;
  16975. char mapname[MAP_NAME_LENGTH_EXT];
  16976. nullpo_retv( sd );
  16977. nullpo_retv( clan = sd->clan );
  16978. // Check if the player has a valid session and is not autotrading
  16979. if( !clif_session_isValid( sd ) ){
  16980. return;
  16981. }
  16982. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16983. fd = sd->fd;
  16984. WFIFOHEAD(fd,length);
  16985. memset( WFIFOP(fd, 0), 0, length );
  16986. WFIFOW( fd, 0 ) = 0x98a;
  16987. WFIFOL( fd, 4 ) = clan->id;
  16988. offset = 8;
  16989. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16990. offset += NAME_LENGTH;
  16991. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16992. offset += NAME_LENGTH;
  16993. mapindex_getmapname_ext( clan->map, mapname );
  16994. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16995. offset += MAP_NAME_LENGTH_EXT;
  16996. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16997. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16998. for( flag = 0; flag < 2; flag++ ){
  16999. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  17000. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  17001. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  17002. offset += NAME_LENGTH;
  17003. }
  17004. }
  17005. }
  17006. WFIFOW( fd, 2 ) = offset;
  17007. WFIFOSET(fd,offset);
  17008. #endif
  17009. }
  17010. /**
  17011. * Updates the online and maximum player count of a clan.
  17012. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  17013. **/
  17014. void clif_clan_onlinecount( struct clan* clan ){
  17015. #if PACKETVER >= 20131223
  17016. uint8 buf[6];
  17017. struct map_session_data *sd;
  17018. WBUFW(buf,0) = 0x988;
  17019. WBUFW(buf,2) = clan->connect_member;
  17020. WBUFW(buf,4) = clan->max_member;
  17021. if((sd = clan_getavailablesd(clan)) != NULL)
  17022. clif_send(buf, 6, &sd->bl, CLAN);
  17023. #endif
  17024. }
  17025. /**
  17026. * Notifies the client that the player has left his clan.
  17027. * 0989 (ZC_ACK_CLAN_LEAVE)
  17028. **/
  17029. void clif_clan_leave( struct map_session_data* sd ){
  17030. #if PACKETVER >= 20131223
  17031. int fd;
  17032. nullpo_retv( sd );
  17033. if( !clif_session_isValid( sd ) ){
  17034. return;
  17035. }
  17036. fd = sd->fd;
  17037. WFIFOHEAD(fd,2);
  17038. WFIFOW(fd,0) = 0x989;
  17039. WFIFOSET(fd,2);
  17040. #endif
  17041. }
  17042. /**
  17043. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  17044. * 0A2F <result>.B <title_id>.L
  17045. */
  17046. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  17047. {
  17048. #if PACKETVER >= 20150513
  17049. int fd;
  17050. nullpo_retv(sd);
  17051. if (!clif_session_isValid(sd))
  17052. return;
  17053. fd = sd->fd;
  17054. WFIFOHEAD(fd, packet_len(0xa2f));
  17055. WFIFOW(fd, 0) = 0xa2f;
  17056. WFIFOB(fd, 2) = result;
  17057. WFIFOL(fd, 3) = title_id;
  17058. WFIFOSET(fd, packet_len(0xa2f));
  17059. #endif
  17060. }
  17061. /**
  17062. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  17063. * 0A2E <title_id>.L
  17064. */
  17065. void clif_parse_change_title(int fd, struct map_session_data *sd)
  17066. {
  17067. int title_id;
  17068. nullpo_retv(sd);
  17069. title_id = RFIFOL(fd, 2);
  17070. if( title_id == sd->status.title_id ){
  17071. // It is exactly the same as the old one
  17072. return;
  17073. }else if( title_id <= 0 ){
  17074. sd->status.title_id = 0;
  17075. }else{
  17076. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17077. clif_change_title_ack(sd, 1, title_id);
  17078. return;
  17079. }
  17080. sd->status.title_id = title_id;
  17081. }
  17082. clif_name_area(&sd->bl);
  17083. clif_change_title_ack(sd, 0, title_id);
  17084. }
  17085. #ifdef DUMP_UNKNOWN_PACKET
  17086. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17087. {
  17088. const char* packet_txt = "save/packet.txt";
  17089. FILE* fp;
  17090. time_t time_server;
  17091. struct tm *datetime;
  17092. char datestr[512];
  17093. time(&time_server); // get time in seconds since 1/1/1970
  17094. datetime = localtime(&time_server); // convert seconds in structure
  17095. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17096. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17097. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17098. if( sd ) {
  17099. 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);
  17100. } else {
  17101. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17102. }
  17103. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17104. fprintf(fp, "\n");
  17105. fclose(fp);
  17106. } else {
  17107. ShowError("Failed to write '%s'.\n", packet_txt);
  17108. // Dump on console instead
  17109. if( sd ) {
  17110. 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);
  17111. } else {
  17112. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17113. }
  17114. ShowDump(RFIFOP(fd,0), packet_len);
  17115. }
  17116. }
  17117. #endif
  17118. /// Roulette System
  17119. /// Author: Yommy
  17120. /// Opens the roulette window
  17121. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17122. void clif_roulette_open( struct map_session_data* sd ){
  17123. nullpo_retv( sd );
  17124. struct packet_roulette_open_ack p;
  17125. p.PacketType = 0xa1a;
  17126. p.Result = 0; // result
  17127. p.Serial = 0; // serial
  17128. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17129. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17130. p.AdditionItemID = -1; //! TODO: Display bonus item
  17131. p.GoldPoint = sd->roulette_point.gold;
  17132. p.SilverPoint = sd->roulette_point.silver;
  17133. p.BronzePoint = sd->roulette_point.bronze;
  17134. sd->state.roulette_open = true;
  17135. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17136. }
  17137. /// Request to open the roulette window
  17138. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17139. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  17140. nullpo_retv(sd);
  17141. if (!battle_config.feature_roulette) {
  17142. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17143. return;
  17144. }
  17145. clif_roulette_open(sd);
  17146. }
  17147. /// Sends the info about the available roulette rewards to the client
  17148. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17149. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17150. void clif_roulette_info( struct map_session_data* sd ){
  17151. nullpo_retv(sd);
  17152. struct packet_roulette_info_ack p;
  17153. p.PacketType = rouletteinfoackType;
  17154. p.PacketLength = sizeof(p);
  17155. p.RouletteSerial = 1;
  17156. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17157. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17158. p.ItemInfo[count].Row = i;
  17159. p.ItemInfo[count].Position = j;
  17160. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17161. p.ItemInfo[count].Count = rd.qty[i][j];
  17162. #if PACKETVER >= 20180511
  17163. p.ItemInfo[count].unused = 0;
  17164. #endif
  17165. count++;
  17166. }
  17167. }
  17168. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17169. }
  17170. /// Request the roulette reward data
  17171. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17172. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  17173. nullpo_retv(sd);
  17174. if (!battle_config.feature_roulette) {
  17175. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17176. return;
  17177. }
  17178. clif_roulette_info(sd);
  17179. }
  17180. /// Notification of the client that the roulette window was closed
  17181. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17182. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  17183. nullpo_retv(sd);
  17184. if (!battle_config.feature_roulette) {
  17185. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17186. return;
  17187. }
  17188. sd->state.roulette_open = false;
  17189. }
  17190. /// Response to a item reward request
  17191. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17192. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17193. #if PACKETVER >= 20141016
  17194. nullpo_retv(sd);
  17195. struct packet_roulette_itemrecv_ack p;
  17196. p.PacketType = roulettercvitemackType;
  17197. p.Result = type;
  17198. p.AdditionItemID = 0; //! TODO: Additional item
  17199. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17200. #endif
  17201. }
  17202. /**
  17203. * Claim roulette reward
  17204. * @param sd Player
  17205. * @return 0:Success
  17206. **/
  17207. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  17208. struct item it;
  17209. uint8 res = 1;
  17210. nullpo_retr(1, sd);
  17211. if (sd->roulette.prizeIdx < 0)
  17212. return RECV_ITEM_FAILED;
  17213. memset(&it, 0, sizeof(it));
  17214. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17215. it.identify = 1;
  17216. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  17217. ; // onSuccess
  17218. }
  17219. sd->roulette.claimPrize = false;
  17220. sd->roulette.prizeStage = 0;
  17221. sd->roulette.prizeIdx = -1;
  17222. sd->roulette.stage = 0;
  17223. return res;
  17224. }
  17225. /// Update Roulette window with current stats
  17226. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17227. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17228. nullpo_retv( sd );
  17229. struct packet_roulette_generate_ack p;
  17230. p.PacketType = roulettgenerateackType;
  17231. p.Result = result;
  17232. p.Step = stage;
  17233. p.Idx = prizeIdx;
  17234. p.AdditionItemID = bonusItemID;
  17235. p.RemainGold = sd->roulette_point.gold;
  17236. p.RemainSilver = sd->roulette_point.silver;
  17237. p.RemainBronze = sd->roulette_point.bronze;
  17238. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17239. }
  17240. /// Request to start the roulette
  17241. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17242. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  17243. enum GENERATE_ROULETTE_ACK result;
  17244. nullpo_retv(sd);
  17245. if (!battle_config.feature_roulette) {
  17246. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17247. return;
  17248. }
  17249. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17250. return;
  17251. }
  17252. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17253. sd->roulette.stage = 0;
  17254. sd->roulette.claimPrize = false;
  17255. sd->roulette.prizeStage = 0;
  17256. sd->roulette.prizeIdx = -1;
  17257. }
  17258. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17259. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17260. }else{
  17261. if (!sd->roulette.stage) {
  17262. if (sd->roulette_point.bronze > 0) {
  17263. sd->roulette_point.bronze -= 1;
  17264. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17265. } else if (sd->roulette_point.silver > 9) {
  17266. sd->roulette_point.silver -= 10;
  17267. sd->roulette.stage = 2;
  17268. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17269. } else if (sd->roulette_point.gold > 9) {
  17270. sd->roulette_point.gold -= 10;
  17271. sd->roulette.stage = 4;
  17272. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17273. }
  17274. }
  17275. sd->roulette.prizeStage = sd->roulette.stage;
  17276. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17277. sd->roulette.claimPrize = true;
  17278. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17279. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17280. result = GENERATE_ROULETTE_LOSING;
  17281. sd->roulette.stage = 0;
  17282. }else{
  17283. result = GENERATE_ROULETTE_SUCCESS;
  17284. sd->roulette.stage++;
  17285. }
  17286. }
  17287. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17288. }
  17289. /// Request to claim a prize
  17290. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17291. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17292. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17293. nullpo_retv(sd);
  17294. if (!battle_config.feature_roulette) {
  17295. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17296. return;
  17297. }
  17298. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17299. return;
  17300. }
  17301. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17302. switch (clif_roulette_getitem(sd)) {
  17303. case ADDITEM_SUCCESS:
  17304. type = RECV_ITEM_SUCCESS;
  17305. break;
  17306. case ADDITEM_INVALID:
  17307. case ADDITEM_OVERITEM:
  17308. case ADDITEM_OVERAMOUNT:
  17309. type = RECV_ITEM_OVERCOUNT;
  17310. break;
  17311. case ADDITEM_OVERWEIGHT:
  17312. type = RECV_ITEM_OVERWEIGHT;
  17313. break;
  17314. case ADDITEM_STACKLIMIT:
  17315. default:
  17316. type = RECV_ITEM_FAILED;
  17317. break;
  17318. }
  17319. }
  17320. clif_roulette_recvitem_ack(sd,type);
  17321. }
  17322. /// MERGE ITEM
  17323. /**
  17324. * Acknowledge the client about item merger result
  17325. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17326. * @param fd
  17327. * @param sd
  17328. **/
  17329. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  17330. unsigned char buf[9];
  17331. struct s_packet_db *info = NULL;
  17332. short cmd = 0;
  17333. nullpo_retv(sd);
  17334. if (!clif_session_isValid(sd))
  17335. return;
  17336. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  17337. return;
  17338. if (!(info = &packet_db[cmd]) || info->len == 0)
  17339. return;
  17340. WBUFW(buf, 0) = cmd;
  17341. WBUFW(buf, info->pos[0]) = index;
  17342. WBUFW(buf, info->pos[1]) = count;
  17343. WBUFB(buf, info->pos[2]) = type;
  17344. clif_send(buf, info->len, &sd->bl, SELF);
  17345. }
  17346. /**
  17347. * Check if item has the pair to be merged
  17348. * @param sd
  17349. * @param it Item
  17350. * @return True if has pair, False if not
  17351. **/
  17352. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17353. struct item *it_;
  17354. unsigned short i;
  17355. nullpo_retr(false, sd);
  17356. 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);
  17357. if (i < MAX_INVENTORY)
  17358. return true;
  17359. return false;
  17360. }
  17361. /**
  17362. * Check if item can be merged
  17363. * @param id Item Data
  17364. * @param it Item
  17365. * @return True if can be merged, False if not
  17366. **/
  17367. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17368. if (!id || !it)
  17369. return false;
  17370. if (id->type == IT_CASH)
  17371. return false;
  17372. if (!itemdb_isstackable2(id))
  17373. return false;
  17374. if (itemdb_isspecial(it->card[0]))
  17375. return false;
  17376. if (!it->unique_id)
  17377. return false;
  17378. return true;
  17379. }
  17380. /**
  17381. * Open available item to be merged.
  17382. * Only show 1 item in 1 process.
  17383. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17384. * @param sd
  17385. **/
  17386. void clif_merge_item_open(struct map_session_data *sd) {
  17387. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  17388. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  17389. int len = 0;
  17390. struct s_packet_db *info = NULL;
  17391. struct item *it;
  17392. nullpo_retv(sd);
  17393. if (!clif_session_isValid(sd))
  17394. return;
  17395. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  17396. return;
  17397. if (!(info = &packet_db[cmd]) || info->len == 0)
  17398. return;
  17399. // Get entries
  17400. for (i = 0; i < MAX_INVENTORY; i++) {
  17401. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  17402. continue;
  17403. if (clif_merge_item_has_pair(sd, it))
  17404. indexes[n++] = i;
  17405. }
  17406. if (n < 2) { // No item need to be merged
  17407. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17408. return;
  17409. }
  17410. WBUFW(buf, 0) = cmd;
  17411. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  17412. for (i = 0; i < n; i++) {
  17413. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  17414. }
  17415. clif_send(buf, len, &sd->bl, SELF);
  17416. }
  17417. /**
  17418. * Process item merger
  17419. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17420. * @param fd
  17421. * @param sd
  17422. **/
  17423. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17424. struct s_packet_db *info = NULL;
  17425. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17426. unsigned int count = 0;
  17427. struct item_data *id = NULL;
  17428. nullpo_retv(sd);
  17429. if (!clif_session_isValid(sd))
  17430. return;
  17431. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17432. return;
  17433. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17434. if (n < 2) { // No item need to be merged
  17435. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17436. return;
  17437. }
  17438. for (i = 0, j = 0; i < n; i++) {
  17439. uint16 idx = server_index( RFIFOW( fd, info->pos[1] + i * 2 ) );
  17440. if( idx >= MAX_INVENTORY ){
  17441. return;
  17442. }
  17443. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17444. continue;
  17445. indexes[j] = idx;
  17446. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17447. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17448. return;
  17449. }
  17450. count += sd->inventory.u.items_inventory[idx].amount;
  17451. j++;
  17452. }
  17453. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17454. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17455. return;
  17456. }
  17457. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17458. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17459. return;
  17460. }
  17461. // Merrrrge!!!!
  17462. for (i = 1; i < n; i++) {
  17463. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17464. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17465. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17466. sd->inventory_data[idx] = NULL;
  17467. clif_delitem(sd, idx, amt, 0);
  17468. }
  17469. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17470. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17471. }
  17472. /**
  17473. * Cancel item merge
  17474. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17475. * @param fd
  17476. * @param sd
  17477. **/
  17478. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17479. return; // Nothing todo yet
  17480. }
  17481. /**
  17482. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17483. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17484. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17485. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17486. **/
  17487. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17488. char name[NAME_LENGTH];
  17489. if( battle_config.broadcast_hide_name ){
  17490. std::string dispname = std::string( char_name );
  17491. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  17492. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  17493. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  17494. }else{
  17495. safestrncpy( name, char_name, sizeof( name ) );
  17496. }
  17497. switch( type ){
  17498. case ITEMOBTAIN_TYPE_BOXITEM:
  17499. {
  17500. struct packet_package_item_announce p;
  17501. p.PacketType = package_item_announceType;
  17502. p.type = type;
  17503. p.ItemID = client_nameid( nameid );
  17504. p.len = NAME_LENGTH;
  17505. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17506. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  17507. p.BoxItemID = client_nameid( container );
  17508. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17509. p.PacketLength = 15 + p.len;
  17510. #else
  17511. p.PacketLength = 11 + p.len;
  17512. #endif
  17513. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17514. }
  17515. break;
  17516. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17517. case ITEMOBTAIN_TYPE_NPC:
  17518. {
  17519. struct packet_item_drop_announce p;
  17520. p.PacketType = item_drop_announceType;
  17521. p.type = type;
  17522. p.ItemID = client_nameid( nameid );
  17523. p.len = NAME_LENGTH;
  17524. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17525. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17526. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17527. p.monsterNameLen = NAME_LENGTH;
  17528. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17529. }else{
  17530. p.monsterNameLen = 0;
  17531. p.monsterName[0] = '\0';
  17532. }
  17533. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17534. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17535. #else
  17536. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17537. #endif
  17538. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17539. }
  17540. break;
  17541. }
  17542. }
  17543. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17544. /// 0A02 <view>.W
  17545. /// Value <flag> has the following effects:
  17546. /// 1: Open a Dress Room window.
  17547. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17548. #if PACKETVER >= 20150513
  17549. int fd = sd->fd;
  17550. nullpo_retv(sd);
  17551. WFIFOHEAD(fd, packet_len(0xa02));
  17552. WFIFOW(fd,0) = 0xa02;
  17553. WFIFOW(fd,2) = flag;
  17554. WFIFOSET(fd, packet_len(0xa02));
  17555. #endif
  17556. }
  17557. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17558. /// 0A35 <result>.W
  17559. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17560. #if PACKETVER >= 20150513
  17561. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17562. // Ignore the request
  17563. // - Invalid item index
  17564. // - Invalid item ID or item doesn't exist
  17565. // - Item is already identified
  17566. if (idx < 0 || idx >= MAX_INVENTORY ||
  17567. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17568. sd->inventory.u.items_inventory[idx].identify)
  17569. return;
  17570. // Ignore the request - No magnifiers in inventory
  17571. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17572. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17573. return;
  17574. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17575. return;
  17576. skill_identify(sd, idx);
  17577. #endif
  17578. }
  17579. /// Starts navigation to the given target on client side
  17580. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17581. #if PACKETVER >= 20111010
  17582. int fd = sd->fd;
  17583. WFIFOHEAD(fd,27);
  17584. WFIFOW(fd,0) = 0x08e2;
  17585. // How detailed will our navigation be?
  17586. if( mob_id > 0 ){
  17587. x = 0;
  17588. y = 0;
  17589. WFIFOB(fd,2) = 3; // monster with destination field
  17590. }else if( x > 0 && y > 0 ){
  17591. WFIFOB(fd,2) = 0; // with coordinates
  17592. }else{
  17593. x = 0;
  17594. y = 0;
  17595. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17596. }
  17597. // Which services can be used for transportation?
  17598. WFIFOB(fd,3) = flag;
  17599. // If this flag is set, the navigation window will not be opened up
  17600. WFIFOB(fd,4) = hideWindow;
  17601. // Target map
  17602. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17603. // Target x
  17604. WFIFOW(fd,21) = x;
  17605. // Target y
  17606. WFIFOW(fd,23) = y;
  17607. // Target monster ID
  17608. WFIFOW(fd,25) = mob_id;
  17609. WFIFOSET(fd,27);
  17610. #endif
  17611. }
  17612. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17613. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17614. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17615. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17616. struct map_session_data *tsd;
  17617. struct block_list* tbl;
  17618. if( target == SELF ){
  17619. tsd = BL_CAST(BL_PC,bl);
  17620. tbl = &sd->bl;
  17621. }else{
  17622. tsd = sd;
  17623. tbl = bl;
  17624. }
  17625. nullpo_retv( tsd );
  17626. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17627. return;
  17628. }
  17629. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17630. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17631. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17632. p->aid = tsd->bl.id;
  17633. p->status = 1;
  17634. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17635. p->effects[i] = tsd->hatEffects[i];
  17636. }
  17637. clif_send( p, p->packetLength, tbl, target );
  17638. #endif
  17639. }
  17640. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17641. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17642. nullpo_retv( sd );
  17643. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17644. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17645. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17646. p->aid = sd->bl.id;
  17647. p->status = enable;
  17648. p->effects[0] = effectId;
  17649. clif_send( p, p->packetLength, &sd->bl, AREA );
  17650. #endif
  17651. }
  17652. /// Notify the client that a sale has started
  17653. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17654. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17655. #if PACKETVER_SUPPORTS_SALES
  17656. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17657. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17658. p.itemId = client_nameid( sale_item->nameid );
  17659. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17660. clif_send( &p, sizeof( p ), bl, target );
  17661. #endif
  17662. }
  17663. /// Notify the client that a sale has ended
  17664. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17665. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17666. #if PACKETVER_SUPPORTS_SALES
  17667. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17668. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17669. p.itemId = client_nameid( sale_item->nameid );
  17670. clif_send( &p, sizeof( p ), bl, target );
  17671. #endif
  17672. }
  17673. /// Update the remaining amount of a sale item.
  17674. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17675. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17676. #if PACKETVER_SUPPORTS_SALES
  17677. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17678. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17679. p.itemId = client_nameid( sale_item->nameid );
  17680. p.amount = sale_item->amount;
  17681. clif_send( &p, sizeof( p ), bl, target );
  17682. #endif
  17683. }
  17684. /// The client requested a refresh of the current remaining count of a sale item
  17685. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17686. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17687. #if PACKETVER_SUPPORTS_SALES
  17688. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17689. struct sale_item_data* sale;
  17690. if( p->AID != sd->status.account_id ){
  17691. return;
  17692. }
  17693. sale = sale_find_item( p->itemId, true );
  17694. if( sale == NULL ){
  17695. return;
  17696. }
  17697. clif_sale_amount(sale, &sd->bl, SELF);
  17698. #endif
  17699. }
  17700. /// Opens the sale administration window on the client
  17701. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17702. void clif_sale_open( struct map_session_data* sd ){
  17703. #if PACKETVER_SUPPORTS_SALES
  17704. nullpo_retv(sd);
  17705. if( sd->state.sale_open ){
  17706. return;
  17707. }
  17708. sd->state.sale_open = true;
  17709. int fd = sd->fd;
  17710. WFIFOHEAD(fd, 2);
  17711. WFIFOW(fd, 0) = 0x9b5;
  17712. WFIFOSET(fd, 2);
  17713. #endif
  17714. }
  17715. /// Client request to open the sale administration window.
  17716. /// This is sent by /limitedsale
  17717. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17718. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17719. #if PACKETVER_SUPPORTS_SALES
  17720. nullpo_retv(sd);
  17721. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17722. return;
  17723. }
  17724. char command[CHAT_SIZE_MAX];
  17725. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17726. is_atcommand(fd, sd, command, 1);
  17727. #endif
  17728. }
  17729. /// Closes the sale administration window on the client.
  17730. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17731. void clif_sale_close(struct map_session_data* sd) {
  17732. #if PACKETVER_SUPPORTS_SALES
  17733. nullpo_retv(sd);
  17734. if( !sd->state.sale_open ){
  17735. return;
  17736. }
  17737. sd->state.sale_open = false;
  17738. int fd = sd->fd;
  17739. WFIFOHEAD(fd, 2);
  17740. WFIFOW(fd, 0) = 0x9bd;
  17741. WFIFOSET(fd, 2);
  17742. #endif
  17743. }
  17744. /// Client request to close the sale administration window.
  17745. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17746. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17747. #if PACKETVER_SUPPORTS_SALES
  17748. nullpo_retv(sd);
  17749. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17750. return;
  17751. }
  17752. clif_sale_close(sd);
  17753. #endif
  17754. }
  17755. /// Reply to a item search request for item sale administration.
  17756. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17757. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17758. #if PACKETVER_SUPPORTS_SALES
  17759. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17760. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17761. if( item != NULL ){
  17762. p.result = 0;
  17763. p.itemId = client_nameid( item->nameid );
  17764. p.price = item->price;
  17765. }else{
  17766. p.result = 1;
  17767. p.itemId = 0;
  17768. p.price = 0;
  17769. }
  17770. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17771. #endif
  17772. }
  17773. /// Search request for an item sale administration.
  17774. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17775. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17776. #if PACKETVER_SUPPORTS_SALES
  17777. char item_name[ITEM_NAME_LENGTH];
  17778. nullpo_retv(sd);
  17779. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17780. return;
  17781. }
  17782. if( !sd->state.sale_open ){
  17783. return;
  17784. }
  17785. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17786. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17787. if( id ){
  17788. int i;
  17789. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17790. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17791. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17792. return;
  17793. }
  17794. }
  17795. }
  17796. // not found
  17797. clif_sale_search_reply( sd, NULL );
  17798. #endif
  17799. }
  17800. /// Reply if an item was successfully put on sale or not.
  17801. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17802. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17803. #if PACKETVER_SUPPORTS_SALES
  17804. int fd = sd->fd;
  17805. WFIFOHEAD(fd, 4);
  17806. WFIFOW(fd, 0) = 0x9af;
  17807. WFIFOW(fd, 2) = (uint16)result;
  17808. WFIFOSET(fd, 4);
  17809. #endif
  17810. }
  17811. /// A client request to put an item on sale.
  17812. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17813. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17814. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17815. #if PACKETVER_SUPPORTS_SALES
  17816. nullpo_retv( sd );
  17817. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17818. if( p->AID != sd->status.account_id ){
  17819. return;
  17820. }
  17821. if( !sd->state.sale_open ){
  17822. return;
  17823. }
  17824. time_t endTime = p->startTime + p->hours * 60 * 60;
  17825. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17826. #endif
  17827. }
  17828. /// Reply to an item removal from sale.
  17829. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17830. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17831. #if PACKETVER_SUPPORTS_SALES
  17832. int fd = sd->fd;
  17833. WFIFOHEAD(fd, 4);
  17834. WFIFOW(fd, 0) = 0x9b1;
  17835. WFIFOW(fd, 2) = failed;
  17836. WFIFOSET(fd, 4);
  17837. #endif
  17838. }
  17839. /// Request to remove an item from sale.
  17840. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17841. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17842. #if PACKETVER_SUPPORTS_SALES
  17843. nullpo_retv( sd );
  17844. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17845. if( p->AID != sd->status.account_id ){
  17846. return;
  17847. }
  17848. if( !sd->state.sale_open ){
  17849. return;
  17850. }
  17851. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17852. #endif
  17853. }
  17854. /// Achievement System
  17855. /// Author: Luxuri, Aleos
  17856. /**
  17857. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17858. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17859. */
  17860. void clif_achievement_list_all(struct map_session_data *sd)
  17861. {
  17862. nullpo_retv(sd);
  17863. if (!battle_config.feature_achievement) {
  17864. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17865. return;
  17866. }
  17867. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17868. if (count == 0)
  17869. return;
  17870. int len = (50 * count) + 22;
  17871. int fd = sd->fd;
  17872. int *info = achievement_level(sd, true);
  17873. WFIFOHEAD(fd,len);
  17874. WFIFOW(fd, 0) = 0xa23;
  17875. WFIFOW(fd, 2) = len;
  17876. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17877. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17878. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17879. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17880. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17881. for (int i = 0; i < count; i++) {
  17882. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17883. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17884. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17885. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17886. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17887. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17888. }
  17889. WFIFOSET(fd, len);
  17890. }
  17891. /**
  17892. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17893. * 0a24 <ACHPoint>.L
  17894. */
  17895. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17896. {
  17897. nullpo_retv(sd);
  17898. if (!battle_config.feature_achievement) {
  17899. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17900. return;
  17901. }
  17902. int fd = sd->fd;
  17903. int *info = achievement_level(sd, true);
  17904. WFIFOHEAD(fd, packet_len(0xa24));
  17905. WFIFOW(fd, 0) = 0xa24;
  17906. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17907. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17908. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17909. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17910. if (ach) {
  17911. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17912. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17913. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17914. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17915. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17916. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17917. } else
  17918. memset(WFIFOP(fd, 16), 0, 40);
  17919. WFIFOSET(fd, packet_len(0xa24));
  17920. }
  17921. /**
  17922. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17923. * 0a25 <achievementID>.L
  17924. */
  17925. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17926. {
  17927. nullpo_retv(sd);
  17928. if( sd->achievement_data.save )
  17929. intif_achievement_save(sd);
  17930. achievement_check_reward(sd, RFIFOL(fd,2));
  17931. }
  17932. /**
  17933. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17934. * 0a26 <result>.W <achievementID>.L
  17935. */
  17936. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17937. {
  17938. WFIFOHEAD(fd, packet_len(0xa26));
  17939. WFIFOW(fd, 0) = 0xa26;
  17940. WFIFOB(fd, 2) = result;
  17941. WFIFOL(fd, 3) = achievement_id;
  17942. WFIFOSET(fd, packet_len(0xa26));
  17943. }
  17944. /// Process the pet evolution request
  17945. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17946. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17947. #if PACKETVER >= 20141008
  17948. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17949. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17950. if (!pet) {
  17951. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17952. return;
  17953. }
  17954. pet_evolution(sd, pet->class_);
  17955. #endif
  17956. }
  17957. /// Sends the result of the evolution to the client.
  17958. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17959. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17960. #if PACKETVER >= 20141008
  17961. int fd = sd->fd;
  17962. WFIFOHEAD(fd, packet_len(0x9fc));
  17963. WFIFOW(fd, 0) = 0x9fc;
  17964. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17965. WFIFOSET(fd, packet_len(0x9fc));
  17966. #endif
  17967. }
  17968. /*
  17969. * This packet is sent by /changedress or /nocosplay
  17970. *
  17971. * 0ae8
  17972. */
  17973. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17974. #if PACKETVER >= 20180103
  17975. char command[CHAT_SIZE_MAX];
  17976. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17977. is_atcommand( fd, sd, command, 1 );
  17978. #endif
  17979. }
  17980. /// Opens an UI window of the given type and initializes it with the given data
  17981. /// 0AE2 <type>.B <data>.L
  17982. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17983. nullpo_retv(sd);
  17984. // If the UI requires state tracking
  17985. switch( ui_type ){
  17986. case OUT_UI_STYLIST:
  17987. sd->state.stylist_open = true;
  17988. break;
  17989. }
  17990. int fd = sd->fd;
  17991. WFIFOHEAD(fd,packet_len(0xae2));
  17992. WFIFOW(fd,0) = 0xae2;
  17993. WFIFOB(fd,2) = ui_type;
  17994. WFIFOL(fd,3) = data;
  17995. WFIFOSET(fd,packet_len(0xae2));
  17996. }
  17997. /// Request to open an UI window of the given type
  17998. /// 0A68 <type>.B
  17999. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  18000. switch( RFIFOB(fd,2) ){
  18001. case IN_UI_ATTENDANCE:
  18002. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  18003. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  18004. }else if( pc_attendance_enabled() ){
  18005. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  18006. }else{
  18007. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  18008. }
  18009. break;
  18010. }
  18011. }
  18012. /// Response for attedance request
  18013. /// 0AF0 <unknown>.L <data>.L
  18014. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  18015. nullpo_retv(sd);
  18016. int fd = sd->fd;
  18017. WFIFOHEAD(fd,packet_len(0xAF0));
  18018. WFIFOW(fd,0) = 0xAF0;
  18019. WFIFOL(fd,2) = 0;
  18020. WFIFOL(fd,6) = data;
  18021. WFIFOSET(fd,packet_len(0xAF0));
  18022. }
  18023. /// Request from the client to retrieve today's attendance reward
  18024. /// 0AEF
  18025. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  18026. pc_attendance_claim_reward(sd);
  18027. }
  18028. /// Send out the percentage of weight that causes it to be displayed in red.
  18029. /// 0ADE <percentage>.L
  18030. void clif_weight_limit( struct map_session_data* sd ){
  18031. #if PACKETVER >= 20171025
  18032. nullpo_retv(sd);
  18033. int fd = sd->fd;
  18034. WFIFOHEAD(fd, packet_len(0xADE));
  18035. WFIFOW(fd, 0) = 0xADE;
  18036. #ifdef RENEWAL
  18037. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18038. #else
  18039. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18040. #endif
  18041. WFIFOSET(fd, packet_len(0xADE));
  18042. #endif
  18043. }
  18044. enum e_private_airship_response : uint32{
  18045. PRIVATEAIRSHIP_OK,
  18046. PRIVATEAIRSHIP_RETRY,
  18047. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18048. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18049. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18050. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18051. };
  18052. /// Send out the response to a private airship request
  18053. /// 0A4A <response>.L
  18054. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  18055. #if PACKETVER >= 20180321
  18056. nullpo_retv( sd );
  18057. int fd = sd->fd;
  18058. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18059. WFIFOW( fd, 0 ) = 0xA4A;
  18060. WFIFOL( fd, 2 ) = response;
  18061. WFIFOSET( fd, packet_len( 0xA4A ) );
  18062. #endif
  18063. }
  18064. /// Parses a request for a private airship
  18065. /// 0A49 <mapname>.16B <itemid>.W
  18066. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  18067. #if PACKETVER >= 20180321
  18068. // Check if the feature is enabled
  18069. if( !battle_config.feature_privateairship ){
  18070. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18071. return;
  18072. }
  18073. // Check if the player is allowed to warp from the source map
  18074. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18075. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18076. return;
  18077. }
  18078. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18079. char mapname[MAP_NAME_LENGTH_EXT];
  18080. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18081. int16 mapindex = mapindex_name2id( mapname );
  18082. // Check if we know the mapname
  18083. if( mapindex < 0 ){
  18084. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18085. return;
  18086. }
  18087. int16 mapid = map_mapindex2mapid( mapindex );
  18088. // Check if the map is available on this server
  18089. if( mapid < 0 ){
  18090. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18091. return;
  18092. }
  18093. // Check if the player tried to warp to the map he is on
  18094. if( sd->bl.m == mapid ){
  18095. // This is blocked by the client, but just to be sure
  18096. return;
  18097. }
  18098. // This can only be a hack, so we prevent it
  18099. if( map_getmapdata( mapid )->instance_id ){
  18100. // Ignore requests to warp directly into a running instance
  18101. return;
  18102. }
  18103. // Check if the player is allowed to warp to the target map
  18104. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18105. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18106. return;
  18107. }
  18108. t_itemid item_id = p->ItemID;
  18109. // Check if the item sent by the client is known to us
  18110. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18111. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18112. return;
  18113. }
  18114. int idx = pc_search_inventory( sd, item_id );
  18115. // Check if the player has the item at all
  18116. if( idx < 0 ){
  18117. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18118. return;
  18119. }
  18120. // Delete the chosen item
  18121. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18122. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18123. return;
  18124. }
  18125. // Warp the player to a random spot on the destination map
  18126. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18127. #endif
  18128. }
  18129. /// Sends out the usage history of the guild storage
  18130. /// 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
  18131. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18132. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18133. #if PACKETVER >= 20140205
  18134. nullpo_retv( sd );
  18135. int fd = sd->fd;
  18136. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18137. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18138. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18139. }else{
  18140. log.clear();
  18141. }
  18142. WFIFOHEAD( fd, size );
  18143. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18144. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18145. p->PacketLength = size;
  18146. p->result = result;
  18147. p->amount = (uint16)log.size();
  18148. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18149. for( int i = 0; i < log.size(); i++ ){
  18150. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18151. struct guild_log_entry& entry = log[i];
  18152. item->id = entry.id;
  18153. item->itemId = client_nameid( entry.item.nameid );
  18154. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18155. item->action = entry.amount > 0; // action = true(put), false(get)
  18156. item->refine = entry.item.refine;
  18157. item->uniqueId = entry.item.unique_id;
  18158. item->IsIdentified = entry.item.identify;
  18159. item->itemType = itemtype( entry.item.nameid );
  18160. clif_addcards( &item->slot, &entry.item );
  18161. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18162. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18163. item->attribute = entry.item.attribute;
  18164. }
  18165. }
  18166. WFIFOSET( fd, p->PacketLength );
  18167. #endif
  18168. }
  18169. /// Activates the client camera info or updates the client camera with the given values.
  18170. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18171. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18172. #if PACKETVER >= 20160525
  18173. int fd = sd->fd;
  18174. WFIFOHEAD(fd, packet_len(0xa78));
  18175. WFIFOW(fd, 0) = 0xa78;
  18176. WFIFOB(fd, 2) = show;
  18177. WFIFOF(fd, 3) = range;
  18178. WFIFOF(fd, 7) = rotation;
  18179. WFIFOF(fd, 11) = latitude;
  18180. WFIFOSET(fd, packet_len(0xa78));
  18181. #endif
  18182. }
  18183. /// Activates or deactives the client camera info or updates the camera settings.
  18184. /// This packet is triggered by /viewpointvalue or /setcamera
  18185. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18186. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  18187. char command[CHAT_SIZE_MAX];
  18188. // /viewpointvalue
  18189. if( RFIFOB( fd, 2 ) == 1 ){
  18190. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18191. // /setcamera
  18192. }else{
  18193. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18194. }
  18195. is_atcommand( fd, sd, command, 1 );
  18196. }
  18197. /// Send the full list of items in the equip switch window
  18198. /// 0a9b <length>.W { <index>.W <position>.L }*
  18199. void clif_equipswitch_list( struct map_session_data* sd ){
  18200. #if PACKETVER >= 20170208
  18201. int fd = sd->fd;
  18202. int offset, i, position;
  18203. WFIFOW(fd, 0) = 0xa9b;
  18204. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18205. short index = sd->equip_switch_index[i];
  18206. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18207. WFIFOW(fd, offset) = index + 2;
  18208. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18209. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18210. offset += 6;
  18211. }
  18212. }
  18213. WFIFOW(fd, 2) = offset;
  18214. WFIFOSET(fd, offset);
  18215. #endif
  18216. }
  18217. /// Acknowledgement for removing an equip to the equip switch window
  18218. /// 0a9a <index>.W <position.>.L <failure>.W
  18219. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18220. #if PACKETVER >= 20170208
  18221. int fd = sd->fd;
  18222. WFIFOHEAD(fd, packet_len(0xa9a));
  18223. WFIFOW(fd, 0) = 0xa9a;
  18224. WFIFOW(fd, 2) = index + 2;
  18225. WFIFOL(fd, 4) = pos;
  18226. WFIFOW(fd, 8) = failed;
  18227. WFIFOSET(fd, packet_len(0xa9a));
  18228. #endif
  18229. }
  18230. /// Request to remove an equip from the equip switch window
  18231. /// 0a99 <index>.W <position>.L <= 20170502
  18232. /// 0a99 <index>.W
  18233. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  18234. #if PACKETVER >= 20170208
  18235. uint16 index = RFIFOW(fd, 2) - 2;
  18236. bool removed = false;
  18237. if( !battle_config.feature_equipswitch ){
  18238. return;
  18239. }
  18240. // Check if the index is valid
  18241. if( index >= MAX_INVENTORY ){
  18242. return;
  18243. }
  18244. pc_equipswitch_remove( sd, index );
  18245. #endif
  18246. }
  18247. /// Acknowledgement for adding an equip to the equip switch window
  18248. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18249. /// 0a98 <index>.W <position.>.L <flag>.W
  18250. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18251. #if PACKETVER >= 20170208
  18252. int fd = sd->fd;
  18253. WFIFOHEAD(fd, packet_len(0xa98));
  18254. WFIFOW(fd, 0) = 0xa98;
  18255. WFIFOW(fd, 2) = index + 2;
  18256. WFIFOL(fd, 4) = pos;
  18257. #if PACKETVER <= 20170502
  18258. WFIFOL(fd, 8) = flag;
  18259. #else
  18260. WFIFOW(fd, 8) = flag;
  18261. #endif
  18262. WFIFOSET(fd,packet_len(0xa98));
  18263. #endif
  18264. }
  18265. /// Request to add an equip to the equip switch window
  18266. /// 0a97 <index>.W <position>.L
  18267. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  18268. #if PACKETVER >= 20170208
  18269. uint16 index = RFIFOW(fd, 2) - 2;
  18270. uint32 position = RFIFOL(fd, 4);
  18271. if( !battle_config.feature_equipswitch ){
  18272. return;
  18273. }
  18274. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18275. return;
  18276. }
  18277. if( sd->state.trading || sd->npc_shopid ){
  18278. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18279. return;
  18280. }
  18281. if( sd->inventory_data[index]->type == IT_AMMO ){
  18282. position = EQP_AMMO;
  18283. }
  18284. pc_equipitem( sd, index, position, true );
  18285. #endif
  18286. }
  18287. /// Acknowledgement packet for the full equip switch
  18288. /// 0a9d <failed>.W
  18289. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  18290. #if PACKETVER >= 20170208
  18291. int fd = sd->fd;
  18292. WFIFOHEAD(fd, packet_len(0xa9d));
  18293. WFIFOW(fd, 0) = 0xa9d;
  18294. WFIFOW(fd, 2) = failed;
  18295. WFIFOSET(fd, packet_len(0xa9d));
  18296. #endif
  18297. }
  18298. /// Request to do a full equip switch
  18299. /// 0a9c
  18300. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18301. #if PACKETVER >= 20170208
  18302. int i;
  18303. t_tick tick = gettick();
  18304. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18305. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18306. // Client will not let you send a request
  18307. return;
  18308. }
  18309. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18310. if( !battle_config.feature_equipswitch ){
  18311. return;
  18312. }
  18313. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18314. if( i == EQI_MAX ){
  18315. // client will show: "There is no item to replace." and should not even come here
  18316. clif_equipswitch_reply( sd, false );
  18317. return;
  18318. }
  18319. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18320. return;
  18321. }
  18322. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18323. #endif
  18324. }
  18325. /// Request to do a single equip switch
  18326. /// 0ace <index>.W
  18327. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18328. #if PACKETVER >= 20170502
  18329. uint16 index = RFIFOW(fd, 2) - 2;
  18330. if( !battle_config.feature_equipswitch ){
  18331. return;
  18332. }
  18333. // Check if the index is valid
  18334. if( index >= MAX_INVENTORY ){
  18335. return;
  18336. }
  18337. // Check if the item exists
  18338. if (sd->inventory_data[index] == nullptr)
  18339. return;
  18340. // Check if the item was already added to equip switch
  18341. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18342. if( sd->npc_id ){
  18343. #ifdef RENEWAL
  18344. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18345. clif_msg( sd, WORK_IN_PROGRESS );
  18346. return;
  18347. }
  18348. #endif
  18349. if( !sd->npc_item_flag ){
  18350. return;
  18351. }
  18352. }
  18353. pc_equipswitch( sd, index );
  18354. return;
  18355. }
  18356. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18357. #endif
  18358. }
  18359. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18360. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18361. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18362. // Only rolling cutter is supported for now
  18363. if( p->skillId != GC_ROLLINGCUTTER ){
  18364. return;
  18365. }
  18366. // Already running - cant happen on officials, since only one skill is supported
  18367. if( sd->skill_keep_using.skill_id != 0 ){
  18368. return;
  18369. }
  18370. sd->skill_keep_using.tid = INVALID_TIMER;
  18371. sd->skill_keep_using.skill_id = p->skillId;
  18372. sd->skill_keep_using.level = p->skillLv;
  18373. sd->skill_keep_using.target = p->targetId;
  18374. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18375. #endif
  18376. }
  18377. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18378. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18379. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18380. // Not running
  18381. if( sd->skill_keep_using.skill_id == 0 ){
  18382. return;
  18383. }
  18384. #if 0
  18385. // Hack
  18386. if( p->skillId != sd->skill_keep_using.skill_id ){
  18387. return;
  18388. }
  18389. #endif
  18390. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18391. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18392. sd->skill_keep_using.tid = INVALID_TIMER;
  18393. }
  18394. sd->skill_keep_using.skill_id = 0;
  18395. sd->skill_keep_using.level = 0;
  18396. sd->skill_keep_using.target = 0;
  18397. #endif
  18398. }
  18399. void clif_ping( struct map_session_data* sd ){
  18400. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18401. nullpo_retv( sd );
  18402. int fd = sd->fd;
  18403. if( !session_isActive( fd ) ){
  18404. return;
  18405. }
  18406. struct PACKET_ZC_PING_LIVE p = {};
  18407. p.packetType = HEADER_ZC_PING_LIVE;
  18408. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18409. #endif
  18410. }
  18411. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18412. nullpo_ret( sd );
  18413. int fd = sd->fd;
  18414. if( !session_isActive( fd ) ){
  18415. return 0;
  18416. }
  18417. t_tick tick = va_arg( ap, t_tick );
  18418. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18419. clif_ping( sd );
  18420. }
  18421. return 0;
  18422. }
  18423. TIMER_FUNC( clif_ping_timer ){
  18424. map_foreachpc( clif_ping_timer_sub, gettick() );
  18425. return 0;
  18426. }
  18427. /**
  18428. * Opens the refine UI on the designated client.
  18429. * 0aa0
  18430. */
  18431. void clif_refineui_open( struct map_session_data* sd ){
  18432. #if PACKETVER >= 20161012
  18433. nullpo_retv( sd );
  18434. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18435. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18436. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18437. sd->state.refineui_open = true;
  18438. #endif
  18439. }
  18440. /**
  18441. * Parses cancel/close of the refine UI on client side.
  18442. * 0aa4
  18443. */
  18444. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18445. #if PACKETVER >= 20161012
  18446. sd->state.refineui_open = false;
  18447. #endif
  18448. }
  18449. /**
  18450. * Adds the selected item into the refine UI and sends the possible materials
  18451. * to the client.
  18452. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18453. */
  18454. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18455. #if PACKETVER >= 20161012
  18456. int fd = sd->fd;
  18457. // Get the item db reference
  18458. struct item_data* id = sd->inventory_data[index];
  18459. // No item data was found
  18460. if( id == NULL ){
  18461. return;
  18462. }
  18463. // Check the inventory
  18464. struct item* item = &sd->inventory.u.items_inventory[index];
  18465. // No item was found at the given index
  18466. if( item == NULL ){
  18467. return;
  18468. }
  18469. // Check if the item is identified
  18470. if( !item->identify ){
  18471. return;
  18472. }
  18473. // Check if the item is broken
  18474. if( item->attribute ){
  18475. return;
  18476. }
  18477. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18478. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18479. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18480. p->itemIndex = client_index( index );
  18481. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18482. // No possibilities were found
  18483. if( info == nullptr ){
  18484. p->blacksmithBlessing = 0;
  18485. }else{
  18486. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18487. uint16 count = 0;
  18488. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18489. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18490. if( cost != nullptr ){
  18491. p->req[count].itemId = client_nameid( cost->nameid );
  18492. p->req[count].chance = (uint8)( cost->chance / 100 );
  18493. p->req[count].zeny = cost->zeny;
  18494. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18495. count++;
  18496. }
  18497. }
  18498. }
  18499. clif_send( p, p->packetLength, &sd->bl, SELF );
  18500. #endif
  18501. }
  18502. /**
  18503. * Client request to add an item to the refine UI.
  18504. * 0aa1 <index>.W
  18505. */
  18506. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18507. #if PACKETVER >= 20161012
  18508. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18509. uint16 index = server_index( p->index );
  18510. // Check if the refine UI is open
  18511. if( !sd->state.refineui_open ){
  18512. return;
  18513. }
  18514. // Check if the index is valid
  18515. if( index >= MAX_INVENTORY ){
  18516. return;
  18517. }
  18518. // Send out the requirements for the refine process
  18519. clif_refineui_info( sd, index );
  18520. #endif
  18521. }
  18522. /**
  18523. * Client requests to try to refine an item.
  18524. * 0aa3 <index>.W <material>.W <catalyst>.B
  18525. */
  18526. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18527. #if PACKETVER >= 20161012
  18528. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18529. uint16 index = server_index( p->index );
  18530. t_itemid material = p->itemId;
  18531. int16 j;
  18532. // Check if the refine UI is open
  18533. if( !sd->state.refineui_open ){
  18534. return;
  18535. }
  18536. // Check if the index is valid
  18537. if( index >= MAX_INVENTORY ){
  18538. return;
  18539. }
  18540. // Get the item db reference
  18541. struct item_data* id = sd->inventory_data[index];
  18542. // No item data was found
  18543. if( id == NULL ){
  18544. return;
  18545. }
  18546. // Check the inventory
  18547. struct item* item = &sd->inventory.u.items_inventory[index];
  18548. // No item was found at the given index
  18549. if( item == NULL ){
  18550. return;
  18551. }
  18552. // Check if the item is identified
  18553. if( !item->identify ){
  18554. return;
  18555. }
  18556. // Check if the item is broken
  18557. if( item->attribute ){
  18558. return;
  18559. }
  18560. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18561. // No refine possible
  18562. if( info == nullptr ){
  18563. return;
  18564. }
  18565. // No possibilities were found
  18566. if( info->costs.empty() ){
  18567. return;
  18568. }
  18569. // Check if the player has the selected material
  18570. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18571. return;
  18572. }
  18573. int16 blacksmith_index = -1;
  18574. uint16 blacksmith_amount = 0;
  18575. // Check if the player has enough blacksmith blessings
  18576. if( p->blacksmithBlessing != 0 ){
  18577. blacksmith_amount = info->blessing_amount;
  18578. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18579. if( blacksmith_amount == 0 ){
  18580. return;
  18581. }
  18582. // Check if the player has blacksmith blessings
  18583. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18584. return;
  18585. }
  18586. // Check if the player has enough blacksmith blessings
  18587. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18588. return;
  18589. }
  18590. }
  18591. std::shared_ptr<s_refine_cost> cost = nullptr;
  18592. for( const auto& pair : info->costs ){
  18593. if( pair.second->nameid == material ){
  18594. cost = pair.second;
  18595. break;
  18596. }
  18597. }
  18598. // The material was not in the list of possible materials
  18599. if( cost == nullptr ){
  18600. return;
  18601. }
  18602. // Try to pay for the refine
  18603. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18604. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18605. return;
  18606. }
  18607. // Delete the required material
  18608. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18609. return;
  18610. }
  18611. // Delete the required blacksmith blessings
  18612. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18613. return;
  18614. }
  18615. // Try to refine the item
  18616. if( cost->chance >= ( rnd() % 10000 ) ){
  18617. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18618. // Success
  18619. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18620. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18621. clif_misceffect( &sd->bl, 3 );
  18622. clif_refine( fd, 0, index, item->refine );
  18623. if( id->type == IT_WEAPON ){
  18624. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18625. }
  18626. clif_refineui_info( sd, index );
  18627. }else{
  18628. // Failure
  18629. // Blacksmith blessings were used to prevent breaking and downgrading
  18630. if( blacksmith_amount > 0 ){
  18631. clif_refine( fd, 3, index, item->refine );
  18632. clif_refineui_info( sd, index );
  18633. // Delete the item if it is breakable
  18634. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18635. clif_refine( fd, 1, index, item->refine );
  18636. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18637. // Downgrade the item if necessary
  18638. }else if( cost->downgrade_amount > 0 ){
  18639. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18640. clif_refine( fd, 2, index, item->refine );
  18641. clif_refineui_info(sd, index);
  18642. // Only show failure, but dont do anything
  18643. }else{
  18644. clif_refine( fd, 3, index, item->refine );
  18645. clif_refineui_info( sd, index );
  18646. }
  18647. clif_misceffect( &sd->bl, 2 );
  18648. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18649. }
  18650. #endif
  18651. }
  18652. void clif_unequipall_reply( struct map_session_data* sd, bool failed ){
  18653. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18654. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18655. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18656. p.result = failed;
  18657. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18658. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18659. }
  18660. void clif_parse_unequipall( int fd, struct map_session_data* sd ){
  18661. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18662. if( pc_cant_act( sd ) ){
  18663. clif_unequipall_reply( sd, true );
  18664. return;
  18665. }
  18666. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18667. if( sd->equip_index[i] >= 0 ){
  18668. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18669. }
  18670. }
  18671. clif_unequipall_reply( sd, false );
  18672. #endif
  18673. }
  18674. void clif_stylist_response( struct map_session_data* sd, bool failed ){
  18675. #if PACKETVER >= 20151104
  18676. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18677. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18678. p.flag = failed;
  18679. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18680. if( !failed ){
  18681. sd->state.stylist_open = false;
  18682. }
  18683. #endif
  18684. }
  18685. bool clif_parse_stylist_buy_sub( struct map_session_data* sd, _look look, int16 index ){
  18686. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18687. if( list == nullptr ){
  18688. return false;
  18689. }
  18690. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18691. if( entry == nullptr ){
  18692. return false;
  18693. }
  18694. std::shared_ptr<s_stylist_costs> costs;
  18695. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18696. costs = entry->doram;
  18697. }else{
  18698. costs = entry->human;
  18699. }
  18700. if( costs == nullptr ){
  18701. return false;
  18702. }
  18703. if( sd->status.zeny < costs->price ){
  18704. return false;
  18705. }
  18706. int16 inventoryIndex = -1;
  18707. if( costs->requiredItem != 0 ){
  18708. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18709. if( inventoryIndex < 0 ){
  18710. // No other option
  18711. if( costs->requiredItemBox == 0 ){
  18712. return false;
  18713. }
  18714. // Check if the box that contains the item is in the inventory
  18715. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18716. // The box containing the item also does not exist
  18717. if( inventoryIndex < 0 ){
  18718. return false;
  18719. }
  18720. }
  18721. }else if( costs->requiredItemBox != 0 ){
  18722. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18723. if( inventoryIndex < 0 ){
  18724. return false;
  18725. }
  18726. }
  18727. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18728. return false;
  18729. }
  18730. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18731. return false;
  18732. }
  18733. switch( look ){
  18734. case LOOK_HAIR:
  18735. case LOOK_HAIR_COLOR:
  18736. case LOOK_CLOTHES_COLOR:
  18737. case LOOK_BODY2:
  18738. pc_changelook( sd, look, entry->value );
  18739. break;
  18740. case LOOK_HEAD_BOTTOM:
  18741. case LOOK_HEAD_MID:
  18742. case LOOK_HEAD_TOP: {
  18743. struct mail_message msg = {};
  18744. msg.dest_id = sd->status.char_id;
  18745. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18746. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18747. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18748. msg.item[0].nameid = entry->value;
  18749. msg.item[0].identify = 1;
  18750. msg.item[0].amount = 1;
  18751. msg.status = MAIL_NEW;
  18752. msg.type = MAIL_INBOX_NORMAL;
  18753. msg.timestamp = time( nullptr );
  18754. intif_Mail_send( 0, &msg );
  18755. } break;
  18756. }
  18757. return true;
  18758. }
  18759. void clif_parse_stylist_buy( int fd, struct map_session_data* sd ){
  18760. #if PACKETVER >= 20151104
  18761. #if PACKETVER >= 20180516
  18762. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18763. #else
  18764. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18765. #endif
  18766. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18767. clif_stylist_response( sd, true );
  18768. return;
  18769. }
  18770. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18771. clif_stylist_response( sd, true );
  18772. return;
  18773. }
  18774. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18775. clif_stylist_response( sd, true );
  18776. return;
  18777. }
  18778. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18779. clif_stylist_response( sd, true );
  18780. return;
  18781. }
  18782. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18783. clif_stylist_response( sd, true );
  18784. return;
  18785. }
  18786. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18787. clif_stylist_response( sd, true );
  18788. return;
  18789. }
  18790. #if PACKETVER >= 20180516
  18791. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18792. clif_stylist_response( sd, true );
  18793. return;
  18794. }
  18795. #endif
  18796. clif_stylist_response( sd, false );
  18797. #endif
  18798. }
  18799. void clif_parse_stylist_close( int fd, struct map_session_data* sd ){
  18800. #if PACKETVER >= 20151104
  18801. sd->state.stylist_open = false;
  18802. #endif
  18803. }
  18804. void clif_inventory_expansion_info( struct map_session_data* sd ){
  18805. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18806. nullpo_retv( sd );
  18807. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18808. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18809. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18810. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18811. #endif
  18812. }
  18813. enum class e_inventory_expansion_response : uint8{
  18814. ASK_CONFIRMATION = 0,
  18815. FAILED,
  18816. BUSY,
  18817. MISSING_ITEM,
  18818. MAXIMUM_REACHED
  18819. };
  18820. void clif_inventory_expansion_response( struct map_session_data* sd, e_inventory_expansion_response response ){
  18821. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18822. nullpo_retv( sd );
  18823. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18824. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18825. p.result = (uint8)response;
  18826. p.itemId = sd->state.inventory_expansion_confirmation;
  18827. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18828. #endif
  18829. }
  18830. void clif_parse_inventory_expansion_request( int fd, struct map_session_data* sd ){
  18831. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18832. // Check if player is dead or busy with other stuff
  18833. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18834. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18835. return;
  18836. }
  18837. // Check if the player already reached the maximum
  18838. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18839. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18840. return;
  18841. }
  18842. static std::map<t_itemid, uint16> items = {
  18843. // The order of entries in this list defines which will be used first
  18844. // This order and the usable items are hardcoded into the client
  18845. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18846. { ITEMID_INVENTORY_EX_EVT, 10 },
  18847. { ITEMID_INVENTORY_EX_DIS, 10 },
  18848. { ITEMID_INVENTORY_EX, 10 },
  18849. };
  18850. int16 index = -1;
  18851. bool found_over_limit = false;
  18852. for( const auto& entry : items ){
  18853. // Check if the player has the required item
  18854. index = pc_search_inventory( sd, entry.first );
  18855. // Found an item
  18856. if( index >= 0 ){
  18857. // Check if the player would exceed the maximum
  18858. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18859. found_over_limit = true;
  18860. }else{
  18861. found_over_limit = false;
  18862. sd->state.inventory_expansion_confirmation = entry.first;
  18863. sd->state.inventory_expansion_amount = entry.second;
  18864. break;
  18865. }
  18866. }
  18867. }
  18868. // Check if an item was found
  18869. if( sd->state.inventory_expansion_confirmation == 0 ){
  18870. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18871. return;
  18872. }
  18873. // Check if an item would have been found, but the player would exceed the maximum
  18874. if( found_over_limit ){
  18875. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18876. return;
  18877. }
  18878. // The player met all requirements => ask him for confirmation
  18879. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18880. #endif
  18881. }
  18882. enum class e_inventory_expansion_result : uint8{
  18883. SUCCESS = 0,
  18884. FAILED,
  18885. BUSY,
  18886. MISSING_ITEM,
  18887. MAXIMUM_REACHED
  18888. };
  18889. void clif_inventory_expansion_result( struct map_session_data* sd, e_inventory_expansion_result result ){
  18890. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18891. nullpo_retv( sd );
  18892. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18893. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18894. p.result = (uint8)result;
  18895. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18896. // Reset the state tracking
  18897. sd->state.inventory_expansion_confirmation = 0;
  18898. sd->state.inventory_expansion_amount = 0;
  18899. #endif
  18900. }
  18901. void clif_parse_inventory_expansion_confirm( int fd, struct map_session_data* sd ){
  18902. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18903. if( sd->state.inventory_expansion_confirmation == 0 ){
  18904. return;
  18905. }
  18906. // Check if player is dead
  18907. if( pc_isdead( sd ) ){
  18908. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18909. return;
  18910. }
  18911. // Check if the player already reached the maximum
  18912. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18913. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18914. return;
  18915. }
  18916. // Check if the player has the required item
  18917. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18918. // The player did not have the item anymore
  18919. if( index < 0 ){
  18920. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18921. return;
  18922. }
  18923. // Check if the player would exceed the maximum
  18924. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18925. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18926. return;
  18927. }
  18928. // Delete the required item
  18929. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18930. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18931. return;
  18932. }
  18933. // Increase the slots
  18934. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18935. // Save player data (slots) and inventory data (removed item)
  18936. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18937. // Inform the player of success
  18938. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18939. clif_inventory_expansion_info( sd );
  18940. #endif
  18941. }
  18942. void clif_parse_inventory_expansion_reject( int fd, struct map_session_data* sd ){
  18943. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18944. sd->state.inventory_expansion_confirmation = 0;
  18945. sd->state.inventory_expansion_amount = 0;
  18946. #endif
  18947. }
  18948. void clif_barter_open( struct map_session_data& sd, struct npc_data& nd ){
  18949. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18950. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18951. return;
  18952. }
  18953. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18954. if( barter == nullptr ){
  18955. return;
  18956. }
  18957. sd.state.barter_open = true;
  18958. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18959. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18960. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  18961. int16 count = 0;
  18962. for( const auto& itemPair : barter->items ){
  18963. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  18964. struct item_data* id = itemdb_exists( itemPair.second->nameid );
  18965. item->nameid = client_nameid( id->nameid );
  18966. item->type = itemtype( id->nameid );
  18967. if( itemPair.second->stockLimited ){
  18968. item->amount = itemPair.second->stock;
  18969. }else{
  18970. item->amount = -1;
  18971. }
  18972. item->weight = id->weight;
  18973. item->index = itemPair.second->index;
  18974. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18975. item->viewSprite = id->look;
  18976. item->location = pc_equippoint_sub( &sd, id );
  18977. #endif
  18978. // Use a loop if someone did not start with index 0
  18979. for( const auto& requirementPair : itemPair.second->requirements ){
  18980. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18981. item->currencyNameid = client_nameid( requirement->nameid );
  18982. item->currencyAmount = requirement->amount;
  18983. // It is a normal barter, cancel after first entry
  18984. break;
  18985. }
  18986. p->packetLength += (int16)( sizeof( *item ) );
  18987. count++;
  18988. }
  18989. clif_send( p, p->packetLength, &sd.bl, SELF );
  18990. #endif
  18991. }
  18992. void clif_parse_barter_close( int fd, struct map_session_data* sd ){
  18993. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18994. if( sd->state.barter_open ){
  18995. sd->npc_shopid = 0;
  18996. sd->state.barter_open = false;
  18997. }
  18998. #endif
  18999. }
  19000. void clif_parse_barter_buy( int fd, struct map_session_data* sd ){
  19001. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19002. // No shop open
  19003. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  19004. return;
  19005. }
  19006. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19007. // Unknown shop
  19008. if( nd == nullptr ){
  19009. return;
  19010. }
  19011. // Not a barter
  19012. if( nd->subtype != NPCTYPE_BARTER ){
  19013. return;
  19014. }
  19015. // It is an extended barter
  19016. if( nd->u.barter.extended ){
  19017. return;
  19018. }
  19019. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19020. if( barter == nullptr ){
  19021. return;
  19022. }
  19023. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19024. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  19025. // Empty purchase list
  19026. if( entries == 0 ){
  19027. return;
  19028. }
  19029. std::vector<s_barter_purchase> purchases;
  19030. purchases.reserve( entries );
  19031. // Make sure each shop index and target item id is only used once
  19032. for( int i = 0; i < entries; i++ ){
  19033. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19034. // Invalid shop index
  19035. if( item == nullptr ){
  19036. return;
  19037. }
  19038. for( int j = i + 1; j < entries; j++ ){
  19039. // Same shop index
  19040. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19041. return;
  19042. }
  19043. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19044. // Invalid shop index
  19045. if( item2 == nullptr ){
  19046. return;
  19047. }
  19048. // Same target item id
  19049. if( item->nameid == item2->nameid ){
  19050. return;
  19051. }
  19052. }
  19053. s_barter_purchase purchase = {};
  19054. purchase.item = item;
  19055. purchase.amount = p->list[i].amount;
  19056. purchases.push_back( purchase );
  19057. }
  19058. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19059. #endif
  19060. }
  19061. void clif_barter_extended_open( struct map_session_data& sd, struct npc_data& nd ){
  19062. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19063. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19064. return;
  19065. }
  19066. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19067. if( barter == nullptr ){
  19068. return;
  19069. }
  19070. sd.state.barter_extended_open = true;
  19071. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19072. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19073. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  19074. p->items_count = 0;
  19075. for( const auto& itemPair : barter->items ){
  19076. // Needs dynamic calculation, because of variable currencies
  19077. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  19078. struct item_data* id = itemdb_exists( itemPair.second->nameid );
  19079. item->nameid = client_nameid( id->nameid );
  19080. item->type = itemtype( id->nameid );
  19081. if( itemPair.second->stockLimited ){
  19082. item->amount = itemPair.second->stock;
  19083. }else{
  19084. item->amount = -1;
  19085. }
  19086. item->weight = id->weight;
  19087. item->index = itemPair.second->index;
  19088. item->zeny = itemPair.second->price;
  19089. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19090. item->viewSprite = id->look;
  19091. item->location = pc_equippoint_sub( &sd, id );
  19092. #endif
  19093. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19094. p->items_count++;
  19095. item->currency_count = 0;
  19096. for( const auto& requirementPair : itemPair.second->requirements ){
  19097. // Needs dynamic calculation, because of variable currencies
  19098. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19099. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19100. req->nameid = requirement->nameid;
  19101. if( requirement->refine >= 0 ){
  19102. req->refine_level = requirement->refine;
  19103. }else{
  19104. req->refine_level = 0;
  19105. }
  19106. req->amount = requirement->amount;
  19107. req->type = itemtype( requirement->nameid );
  19108. p->packetLength += (int16)( sizeof( *req ) );
  19109. item->currency_count++;
  19110. }
  19111. }
  19112. clif_send( p, p->packetLength, &sd.bl, SELF );
  19113. #endif
  19114. }
  19115. void clif_parse_barter_extended_close( int fd, struct map_session_data* sd ){
  19116. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19117. if( sd->state.barter_extended_open ){
  19118. sd->npc_shopid = 0;
  19119. sd->state.barter_extended_open = false;
  19120. }
  19121. #endif
  19122. }
  19123. void clif_parse_barter_extended_buy( int fd, struct map_session_data* sd ){
  19124. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19125. // No shop open
  19126. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19127. return;
  19128. }
  19129. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19130. // Unknown shop
  19131. if( nd == nullptr ){
  19132. return;
  19133. }
  19134. // Not a barter
  19135. if( nd->subtype != NPCTYPE_BARTER ){
  19136. return;
  19137. }
  19138. // Not an extended barter
  19139. if( !nd->u.barter.extended ){
  19140. return;
  19141. }
  19142. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19143. if( barter == nullptr ){
  19144. return;
  19145. }
  19146. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19147. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19148. // Empty purchase list
  19149. if( entries == 0 ){
  19150. return;
  19151. }
  19152. std::vector<s_barter_purchase> purchases;
  19153. purchases.reserve( entries );
  19154. // Make sure each shop index and target item id is only used once
  19155. for( int i = 0; i < entries; i++ ){
  19156. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19157. // Invalid shop index
  19158. if( item == nullptr ){
  19159. return;
  19160. }
  19161. for( int j = i + 1; j < entries; j++ ){
  19162. // Same shop index
  19163. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19164. return;
  19165. }
  19166. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19167. // Invalid shop index
  19168. if( item2 == nullptr ){
  19169. return;
  19170. }
  19171. // Same target item id
  19172. if( item->nameid == item2->nameid ){
  19173. return;
  19174. }
  19175. }
  19176. s_barter_purchase purchase = {};
  19177. purchase.item = item;
  19178. purchase.amount = p->list[i].amount;
  19179. purchases.push_back( purchase );
  19180. }
  19181. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19182. #endif
  19183. }
  19184. void clif_summon_init(struct mob_data& md) {
  19185. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19186. struct block_list* master_bl = battle_get_master(&md.bl);
  19187. if( master_bl == nullptr ){
  19188. return;
  19189. }
  19190. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19191. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19192. p.summonAID = md.bl.id;
  19193. p.CurrentHP = md.status.hp;
  19194. p.MaxHP = md.status.max_hp;
  19195. clif_send( &p, sizeof( p ), master_bl, SELF );
  19196. #endif
  19197. }
  19198. void clif_summon_hp_bar(struct mob_data& md) {
  19199. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19200. struct block_list* master_bl = battle_get_master(&md.bl);
  19201. if( master_bl == nullptr ){
  19202. return;
  19203. }
  19204. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19205. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19206. p.summonAID = md.bl.id;
  19207. p.VarId = SP_HP; // HP parameter
  19208. p.Value = md.status.hp;
  19209. clif_send( &p, sizeof( p ), master_bl, SELF );
  19210. #endif
  19211. }
  19212. void clif_laphine_synthesis_open( struct map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19213. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19214. nullpo_retv( sd );
  19215. sd->state.laphine_synthesis = synthesis->item_id;
  19216. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19217. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19218. p.itemId = client_nameid( synthesis->item_id );
  19219. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19220. #endif
  19221. }
  19222. void clif_parse_laphine_synthesis_close( int fd, struct map_session_data* sd ){
  19223. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19224. sd->state.laphine_synthesis = 0;
  19225. #endif
  19226. }
  19227. enum e_laphine_synthesis_result : int16{
  19228. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19229. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19230. LAPHINE_SYNTHESIS_ITEM = 7
  19231. };
  19232. void clif_laphine_synthesis_result( struct map_session_data* sd, enum e_laphine_synthesis_result result ){
  19233. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19234. nullpo_retv( sd );
  19235. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19236. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19237. p.result = result;
  19238. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19239. #endif
  19240. }
  19241. void clif_parse_laphine_synthesis( int fd, struct map_session_data* sd ){
  19242. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19243. if( sd->state.laphine_synthesis == 0 ){
  19244. return;
  19245. }
  19246. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19247. if( sd->state.laphine_synthesis != p->itemId ){
  19248. return;
  19249. }
  19250. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19251. if( synthesis == nullptr ){
  19252. return;
  19253. }
  19254. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19255. // Player sent more or less than actually required
  19256. if( count != synthesis->requiredRequirements ){
  19257. return;
  19258. }
  19259. // Check for duplicates
  19260. for( size_t i = 0; i < count; i++ ){
  19261. for( size_t j = i + 1; j < count; j++ ){
  19262. if( p->items[i].index == p->items[j].index ){
  19263. return;
  19264. }
  19265. }
  19266. }
  19267. for( size_t i = 0; i < count; i++ ){
  19268. int16 index = server_index( p->items[i].index );
  19269. if( index >= MAX_INVENTORY ){
  19270. return;
  19271. }
  19272. if( sd->inventory_data[i] == nullptr ){
  19273. return;
  19274. }
  19275. struct item* item = &sd->inventory.u.items_inventory[index];
  19276. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19277. if( requirement == nullptr ){
  19278. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19279. return;
  19280. }
  19281. if( p->items[i].count != requirement->amount ){
  19282. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19283. return;
  19284. }
  19285. if( item->amount < requirement->amount ){
  19286. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19287. return;
  19288. }
  19289. if( item->refine < synthesis->minimumRefine ){
  19290. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19291. return;
  19292. }
  19293. if( item->refine > synthesis->maximumRefine ){
  19294. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19295. return;
  19296. }
  19297. if( item->equip != 0 ){
  19298. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19299. return;
  19300. }
  19301. if( item->equipSwitch != 0 ){
  19302. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19303. return;
  19304. }
  19305. }
  19306. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19307. if( index < 0 ){
  19308. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19309. return;
  19310. }
  19311. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19312. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19313. return;
  19314. }
  19315. }
  19316. for( size_t i = 0; i < count; i++ ){
  19317. index = server_index( p->items[i].index );
  19318. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19319. return;
  19320. }
  19321. }
  19322. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19323. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19324. #endif
  19325. }
  19326. void clif_laphine_upgrade_open( struct map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19327. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19328. nullpo_retv( sd );
  19329. sd->state.laphine_upgrade = upgrade->item_id;
  19330. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19331. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19332. p.itemId = client_nameid( upgrade->item_id );
  19333. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19334. #endif
  19335. }
  19336. void clif_parse_laphine_upgrade_close( int fd, struct map_session_data* sd ){
  19337. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19338. sd->state.laphine_upgrade = 0;
  19339. #endif
  19340. }
  19341. void clif_laphine_upgrade_result( struct map_session_data *sd, bool failed ){
  19342. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19343. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19344. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19345. p.result = failed;
  19346. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19347. #endif
  19348. }
  19349. static void clif_item_preview( struct map_session_data *sd, int16 index ){
  19350. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19351. nullpo_retv( sd );
  19352. struct item* item = &sd->inventory.u.items_inventory[index];
  19353. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19354. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19355. p.index = client_index( index );
  19356. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19357. p.isDamaged = item->attribute != 0;
  19358. #endif
  19359. p.refiningLevel = item->refine;
  19360. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19361. p.enchantgrade = item->enchantgrade;
  19362. #endif
  19363. clif_addcards( &p.slot, item );
  19364. clif_add_random_options( p.option_data, item );
  19365. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19366. #endif
  19367. }
  19368. void clif_parse_laphine_upgrade( int fd, struct map_session_data* sd ){
  19369. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19370. if( sd->state.laphine_upgrade == 0 ){
  19371. return;
  19372. }
  19373. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19374. if( sd->state.laphine_upgrade != p->itemId ){
  19375. return;
  19376. }
  19377. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19378. if( upgrade == nullptr ){
  19379. return;
  19380. }
  19381. uint16 index = server_index( p->index );
  19382. if( index >= MAX_INVENTORY ){
  19383. return;
  19384. }
  19385. if( sd->inventory_data[index] == nullptr ){
  19386. return;
  19387. }
  19388. struct item* item = &sd->inventory.u.items_inventory[index];
  19389. // Not a valid target item
  19390. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19391. clif_laphine_upgrade_result( sd, true );
  19392. return;
  19393. }
  19394. // If target item is not identified
  19395. if( item->identify == 0 ){
  19396. clif_laphine_upgrade_result( sd, true );
  19397. return;
  19398. }
  19399. // If target item is equipped
  19400. if( item->equip != 0 ){
  19401. clif_laphine_upgrade_result( sd, true );
  19402. return;
  19403. }
  19404. // If target item is in equipswitch
  19405. if( item->equipSwitch != 0 ){
  19406. clif_laphine_upgrade_result( sd, true );
  19407. return;
  19408. }
  19409. // Check minimum refine requirement
  19410. if( item->refine < upgrade->minimumRefine ){
  19411. clif_laphine_upgrade_result( sd, true );
  19412. return;
  19413. }
  19414. // Check maximum refine requirement
  19415. if( item->refine > upgrade->maximumRefine ){
  19416. clif_laphine_upgrade_result( sd, true );
  19417. return;
  19418. }
  19419. // If no cards are allowed
  19420. if( !upgrade->cardsAllowed ){
  19421. for( int i = 0; i < MAX_SLOTS; i++ ){
  19422. if( item->card[i] != 0 ){
  19423. clif_laphine_upgrade_result( sd, true );
  19424. return;
  19425. }
  19426. }
  19427. }
  19428. // If random options are required
  19429. if( upgrade->requiredRandomOptions > 0 ){
  19430. int i;
  19431. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19432. if( item->option[i].id != 0 ){
  19433. break;
  19434. }
  19435. }
  19436. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19437. clif_laphine_upgrade_result( sd, true );
  19438. return;
  19439. }
  19440. }
  19441. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19442. if( index2 < 0 ){
  19443. clif_laphine_upgrade_result( sd, true );
  19444. return;
  19445. }
  19446. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19447. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19448. return;
  19449. }
  19450. }
  19451. // Log removal of item
  19452. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19453. // Visually remove it from the client
  19454. clif_delitem( sd, index, 1, 0 );
  19455. // Apply the random options
  19456. if( upgrade->randomOptionGroup != nullptr ){
  19457. upgrade->randomOptionGroup->apply( *item );
  19458. }
  19459. // Change the refine rate if needed
  19460. if( upgrade->resultRefine > 0 ){
  19461. // Absolute refine level change
  19462. item->refine = max( item->refine, upgrade->resultRefine );
  19463. }else if( upgrade->resultRefineMaximum > 0 ){
  19464. // If a minimum is specified it can also downgrade
  19465. if( upgrade->resultRefineMinimum ){
  19466. item->refine = rnd_value( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum );
  19467. }else{
  19468. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19469. item->refine = rnd_value( item->refine, upgrade->resultRefineMaximum );
  19470. }
  19471. }else if( upgrade->resultRefineMinimum > 0 ){
  19472. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19473. item->refine = rnd_value( upgrade->resultRefineMinimum, MAX_REFINE );
  19474. }
  19475. // Log retrieving the item again -> with the new options
  19476. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19477. // Make it visible for the client again
  19478. clif_additem( sd, index, 1, 0 );
  19479. // Open a preview of the item
  19480. clif_item_preview( sd, index );
  19481. // Tell the client we are done
  19482. clif_laphine_upgrade_result( sd, false );
  19483. #endif
  19484. }
  19485. /*==========================================
  19486. * Main client packet processing function
  19487. *------------------------------------------*/
  19488. static int clif_parse(int fd)
  19489. {
  19490. int cmd, packet_len;
  19491. TBL_PC* sd;
  19492. int pnum;
  19493. #ifdef PACKET_OBFUSCATION
  19494. int cmd2;
  19495. #endif
  19496. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  19497. // Note: "click masters" can do 80+ clicks in 10 seconds
  19498. 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]
  19499. { // begin main client packet processing loop
  19500. sd = (TBL_PC *)session[fd]->session_data;
  19501. if (session[fd]->flag.eof) {
  19502. if (sd) {
  19503. if (sd->state.autotrade) {
  19504. //Disassociate character from the socket connection.
  19505. session[fd]->session_data = NULL;
  19506. sd->fd = 0;
  19507. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  19508. } else
  19509. if (sd->state.active) {
  19510. // Player logout display [Valaris]
  19511. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  19512. clif_quitsave(fd, sd);
  19513. } else {
  19514. //Unusual logout (during log on/off/map-changer procedure)
  19515. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  19516. map_quit(sd);
  19517. }
  19518. } else {
  19519. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  19520. }
  19521. do_close(fd);
  19522. return 0;
  19523. }
  19524. if (RFIFOREST(fd) < 2)
  19525. return 0;
  19526. cmd = RFIFOW(fd, 0);
  19527. #ifdef PACKET_OBFUSCATION
  19528. // Check if it is a player that tries to connect to the map server.
  19529. if( sd ){
  19530. // Decrypt the current packet ID with the last key stored in the session.
  19531. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  19532. }else{
  19533. // Store the original value for checking
  19534. cmd2 = cmd;
  19535. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  19536. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  19537. }
  19538. #endif
  19539. // filter out invalid / unsupported packets
  19540. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  19541. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  19542. #ifdef DUMP_INVALID_PACKET
  19543. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  19544. #endif
  19545. #ifdef PACKET_OBFUSCATION_WARN
  19546. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  19547. if( !sd ){
  19548. #ifdef PACKET_OBFUSCATION
  19549. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  19550. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  19551. }
  19552. #else
  19553. // Try to use the initial keys for the decryption of the packet ID.
  19554. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  19555. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  19556. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  19557. }
  19558. #endif
  19559. }
  19560. #endif
  19561. set_eof(fd);
  19562. return 0;
  19563. }
  19564. // determine real packet length
  19565. packet_len = packet_db[cmd].len;
  19566. if (packet_len == -1) { // variable-length packet
  19567. if (RFIFOREST(fd) < 4)
  19568. return 0;
  19569. packet_len = RFIFOW(fd,2);
  19570. if (packet_len < 4 || packet_len > 32768) {
  19571. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  19572. #ifdef DUMP_INVALID_PACKET
  19573. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  19574. #endif
  19575. set_eof(fd);
  19576. return 0;
  19577. }
  19578. }
  19579. if ((int)RFIFOREST(fd) < packet_len){
  19580. 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 );
  19581. #ifdef DUMP_INVALID_PACKET
  19582. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  19583. #endif
  19584. set_eof( fd );
  19585. return 0; // not enough data received to form the packet
  19586. }
  19587. #ifdef PACKET_OBFUSCATION
  19588. RFIFOW(fd, 0) = cmd;
  19589. if (sd)
  19590. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  19591. #endif
  19592. if( packet_db[cmd].func == clif_parse_debug )
  19593. packet_db[cmd].func(fd, sd);
  19594. else if( packet_db[cmd].func != NULL ) {
  19595. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  19596. ; //Only valid packet when there is no session
  19597. else
  19598. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  19599. ; //Only valid packet when player is not on a map
  19600. else
  19601. packet_db[cmd].func(fd, sd);
  19602. }
  19603. #ifdef DUMP_UNKNOWN_PACKET
  19604. else DumpUnknown(fd,sd,cmd,packet_len);
  19605. #endif
  19606. RFIFOSKIP(fd, packet_len);
  19607. }; // main loop end
  19608. return 0;
  19609. }
  19610. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  19611. va_list argp;
  19612. int i;
  19613. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  19614. return;
  19615. packet_db[cmd].len = length;
  19616. packet_db[cmd].func = func;
  19617. va_start(argp, func);
  19618. for( i = 0; i < MAX_PACKET_POS; i++ ){
  19619. int offset = va_arg(argp, int);
  19620. if( offset == 0 ){
  19621. break;
  19622. }
  19623. packet_db[cmd].pos[i] = offset;
  19624. }
  19625. if( i == MAX_PACKET_POS ){
  19626. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  19627. }
  19628. va_end(argp);
  19629. }
  19630. /*==========================================
  19631. * Reads packets and setups its array reference
  19632. *------------------------------------------*/
  19633. void packetdb_readdb(){
  19634. memset(packet_db,0,sizeof(packet_db));
  19635. memset(packet_db_ack,0,sizeof(packet_db_ack));
  19636. #include "clif_packetdb.hpp"
  19637. #include "clif_shuffle.hpp"
  19638. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  19639. #ifdef PACKET_OBFUSCATION
  19640. 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]);
  19641. #else
  19642. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  19643. #endif
  19644. }
  19645. /*==========================================
  19646. *
  19647. *------------------------------------------*/
  19648. void do_init_clif(void) {
  19649. const char* colors[COLOR_MAX] = {
  19650. "0x00FF00",
  19651. "0xFF0000",
  19652. "0xFFFFFF",
  19653. "0xFFFF00",
  19654. "0x00FFFF",
  19655. "0xB5FFB5",
  19656. };
  19657. int i;
  19658. /**
  19659. * Setup Color Table (saves unnecessary load of strtoul on every call)
  19660. **/
  19661. for(i = 0; i < COLOR_MAX; i++) {
  19662. color_table[i] = strtoul(colors[i],NULL,0);
  19663. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  19664. }
  19665. packetdb_readdb();
  19666. set_defaultparse(clif_parse);
  19667. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  19668. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  19669. exit(EXIT_FAILURE);
  19670. }
  19671. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  19672. add_timer_func_list(clif_delayquit, "clif_delayquit");
  19673. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  19674. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  19675. if( battle_config.ping_timer_interval > 0 ){
  19676. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  19677. }
  19678. #endif
  19679. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  19680. }
  19681. void do_final_clif(void) {
  19682. ers_destroy(delay_clearunit_ers);
  19683. }